Skip to content

Commit fb37ee3

Browse files
chore: upgrade prettier to v3 (#6725)
1 parent bc73919 commit fb37ee3

File tree

21 files changed

+659
-342
lines changed

21 files changed

+659
-342
lines changed
Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`prebuild should read out component folders 1`] = `
4-
"{
5-
"componentNames": [
6-
"folder_name_with_different_notation",
7-
"post-123-component",
8-
"post-accordion",
9-
"post-avatar",
10-
"post-back-to-tlop",
11-
"post-breadcrumbs",
12-
"post-breadcrumbs-item",
13-
"some-other-folder"
14-
]
15-
}
16-
"
17-
`;
3+
exports[`prebuild should read out component folders 1`] = `"{ componentNames: ['folder_name_with_different_notation','post-123-component','post-accordion','post-avatar','post-back-to-tlop','post-breadcrumbs','post-breadcrumbs-item','some-other-folder'] }"`;
184

19-
exports[`prebuild should read out component folders 2`] = `
20-
"$component-names: (
21-
"folder_name_with_different_notation",
22-
"post-123-component",
23-
"post-accordion",
24-
"post-avatar",
25-
"post-back-to-tlop",
26-
"post-breadcrumbs",
27-
"post-breadcrumbs-item",
28-
"some-other-folder"
29-
);
30-
"
31-
`;
5+
exports[`prebuild should read out component folders 2`] = `"$component-names: ('folder_name_with_different_notation','post-123-component','post-accordion','post-avatar','post-back-to-tlop','post-breadcrumbs','post-breadcrumbs-item','some-other-folder');"`;

packages/components/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
"@stencil/sass": "3.0.12",
108108
"@swisspost/design-system-eslint": "workspace:10.0.0-next.55",
109109
"@types/jest": "29.5.14",
110-
"@types/mock-fs": "4.13.4",
111110
"@types/node": "22.10.5",
112111
"@typescript-eslint/parser": "7.18.0",
113112
"copyfiles": "2.4.1",
@@ -118,8 +117,8 @@
118117
"eslint-plugin-cypress": "4.2.0",
119118
"eslint-plugin-react": "7.37.5",
120119
"globals": "16.0.0",
121-
"mock-fs": "5.5.0",
122-
"prettier": "2.8.8",
120+
"memfs": "4.51.0",
121+
"prettier": "3.6.2",
123122
"replace": "1.2.2",
124123
"rimraf": "6.0.1",
125124
"rollup-plugin-postcss": "4.0.2",

packages/components/prebuild.spec.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
import fs from 'fs';
2-
import mockFs from 'mock-fs';
1+
import { vol, fs as memfs } from 'memfs';
2+
3+
// Mock the built-in 'fs' module so all fs calls inside prebuild use memfs
4+
jest.mock('fs', () => memfs);
5+
6+
// Mock prettier to avoid triggering dynamic import inside Jest VM (Prettier v3 ESM)
7+
jest.mock('prettier', () => ({
8+
format: (code: string) => code,
9+
}));
10+
311
import { createComponentNameOutput, componentNameOutputOptions } from './prebuild';
412

513
describe('prebuild', () => {
6-
it('should read out component folders', async () => {
7-
mockFs({
8-
'src/components': {
9-
'post-accordion': {},
10-
'post-avatar': {},
11-
'post-back-to-tlop': {},
12-
'post-breadcrumbs': {},
13-
'post-breadcrumbs-item': {},
14-
'post-123-component': {},
15-
'some-other-folder': {},
16-
'folder_name_with_different_notation': {},
14+
beforeEach(() => {
15+
vol.reset();
16+
// Create directory structure; null values create directories in vol.fromJSON
17+
vol.fromJSON(
18+
{
19+
'folder_name_with_different_notation': '',
20+
'post-123-component': '',
21+
'post-accordion': '',
22+
'post-avatar': '',
23+
'post-back-to-tlop': '',
24+
'post-breadcrumbs': '',
25+
'post-breadcrumbs-item': '',
26+
'some-other-folder': ''
1727
},
18-
'src/_generated': {},
19-
});
28+
'src/components/',
29+
);
30+
});
2031

21-
await createComponentNameOutput(componentNameOutputOptions);
32+
afterEach(() => {
33+
vol.reset();
34+
});
2235

23-
const componentNamesJson = fs.readFileSync('src/_generated/component-names.json', 'utf8');
24-
const componentNamesScss = fs.readFileSync('src/_generated/component-names.scss', 'utf8');
36+
it('should read out component folders', async () => {
37+
await createComponentNameOutput(componentNameOutputOptions);
2538

26-
mockFs.restore();
39+
const componentNamesJson = memfs.readFileSync('src/_generated/component-names.json', 'utf8');
40+
const componentNamesScss = memfs.readFileSync('src/_generated/component-names.scss', 'utf8');
2741

2842
expect(componentNamesJson).toMatchSnapshot();
2943
expect(componentNamesScss).toMatchSnapshot();

packages/components/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"include": ["prebuild.ts", "prebuild.spec.ts"]
88
},
99
"compilerOptions": {
10-
"types": ["node", "jest", "mock-fs"],
10+
"types": ["node", "jest"],
1111
"paths": {
1212
"@/*": ["./src/*"],
1313
"@root/*": ["./*"]
@@ -28,6 +28,6 @@
2828
"resolveJsonModule": true,
2929
"skipLibCheck": true
3030
},
31-
"include": [".config/*", "src", "types"],
31+
"include": [".config/*", "src", "types", "prebuild.spec.ts"],
3232
"exclude": ["node_modules"]
3333
}

packages/documentation/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"globals": "16.0.0",
6565
"lit": "3.3.1",
6666
"lit-html": "3.3.1",
67-
"prettier": "2.8.8",
67+
"prettier": "3.6.2",
6868
"react": "18.3.1",
6969
"react-dom": "18.3.1",
7070
"react-syntax-highlighter": "15.6.6",

packages/icons/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"@types/mock-fs": "4.13.4",
4141
"@types/node": "22.10.5",
4242
"@types/node-fetch": "2.6.13",
43-
"@types/prettier": "2.7.3",
4443
"@typescript-eslint/eslint-plugin": "7.18.0",
4544
"@typescript-eslint/parser": "7.18.0",
4645
"dotenv": "17.2.3",
@@ -54,7 +53,7 @@
5453
"node-fetch": "2.7.0",
5554
"node-html-parser": "7.0.1",
5655
"nodemon": "3.1.10",
57-
"prettier": "2.8.8",
56+
"prettier": "3.6.2",
5857
"rimraf": "6.0.1",
5958
"svgo": "3.3.2",
6059
"ts-jest": "29.2.5",

packages/icons/src/utilities/build/createCssFiles.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,36 @@ function removeExistingCssFiles(dir: string): number {
2020
return existingFiles.length;
2121
}
2222

23-
export function createCssFiles(
23+
export async function createCssFiles(
2424
iconOutputDirectory: string,
25-
cssOutputDirectory: string
26-
): void {
25+
cssOutputDirectory: string,
26+
): Promise<void> {
2727
fs.mkdirSync(cssOutputDirectory, { recursive: true });
2828

2929
const removedCount = removeExistingCssFiles(cssOutputDirectory);
3030

31-
const svgFiles = fs
32-
.readdirSync(iconOutputDirectory)
33-
.filter(f => f.endsWith('.svg'));
31+
const svgFiles = fs.readdirSync(iconOutputDirectory).filter(f => f.endsWith('.svg'));
3432

3533
let createdCount = 0;
3634

37-
svgFiles.forEach(file => {
38-
const filePath = path.join(iconOutputDirectory, file);
39-
const baseName = sanitizeForCSSVariable(path.parse(file).name);
40-
const svgContent = fs.readFileSync(filePath, 'utf8');
35+
await Promise.all(
36+
svgFiles.map(async file => {
37+
const filePath = path.join(iconOutputDirectory, file);
38+
const baseName = sanitizeForCSSVariable(path.parse(file).name);
39+
const svgContent = fs.readFileSync(filePath, 'utf8');
4140

42-
let cssContent = `:root { --post-icon-${baseName}: url("${svgToDataUrl(svgContent)}"); }`;
41+
let cssContent = `:root { --post-icon-${baseName}: url("${svgToDataUrl(svgContent)}"); }`;
4342

44-
cssContent = format(cssContent, { parser: 'css' });
43+
cssContent = await format(cssContent, { parser: 'css' });
4544

46-
fs.writeFileSync(
47-
path.join(cssOutputDirectory, `${baseName}.css`),
48-
cssContent
49-
);
50-
createdCount++;
51-
});
45+
fs.writeFileSync(path.join(cssOutputDirectory, `${baseName}.css`), cssContent);
46+
createdCount++;
47+
}),
48+
);
5249

5350
console.log(
5451
coloredLogMessage(
55-
`<green>[createCSSFiles]</green> Created ${createdCount} CSS files (removed <red>${removedCount}</red> old files)`
56-
)
52+
`<green>[createCSSFiles]</green> Created ${createdCount} CSS files (removed <red>${removedCount}</red> old files)`,
53+
),
5754
);
5855
}

packages/icons/src/utilities/build/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const iconOutputDirectory = path.resolve(OUTPUT_PATH_ICONS);
1111
const reportOutputDirectory = path.resolve(OUTPUT_PATH);
1212
const cssOutputDirectory = path.resolve(OUTPUT_PATH_CSS);
1313

14-
export default function buildSVGs() {
14+
export default async function buildSVGs() {
1515
console.log(coloredLogMessage('<blue>Building icons...</blue>'));
1616

1717
setup(iconOutputDirectory, reportOutputDirectory);
1818

1919
const iconSetGroups = getIconSetGroups();
2020
createSvgs(iconOutputDirectory, iconSetGroups);
21-
createCssFiles(iconOutputDirectory, cssOutputDirectory);
21+
await createCssFiles(iconOutputDirectory, cssOutputDirectory);
2222
const report = writeReport(reportOutputDirectory, iconSetGroups);
2323

2424
console.log(

packages/styles/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"unit": "gulp sass:tests",
2828
"lint": "stylelint src/**/*.scss !src/tokens/temp/**",
2929
"lint:fix": "stylelint src/**/*.scss !src/tokens/temp/** --fix",
30-
"format": "prettier src/**/*.scss --write"
30+
"format": "prettier src/**/*.scss --config ../../.prettierrc --write"
3131
},
3232
"dependencies": {
3333
"@popperjs/core": "2.11.8",
@@ -47,13 +47,13 @@
4747
"jest": "29.7.0",
4848
"postcss": "8.5.6",
4949
"postcss-scss": "4.0.9",
50-
"prettier": "3.3.3",
50+
"prettier": "3.6.2",
5151
"rimraf": "6.0.1",
5252
"sass-embedded": "1.78.0",
53-
"stylelint": "16.12.0",
5453
"stylelint-config-sass-guidelines": "11.1.0",
54+
"stylelint": "16.26.0",
5555
"stylelint-prettier": "5.0.3",
56-
"stylelint-scss": "6.10.0",
56+
"stylelint-scss": "6.12.1",
5757
"typescript": "5.8.3",
5858
"vite": "7.1.12"
5959
},

packages/styles/src/components/card-control.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ fieldset {
253253
}
254254

255255
&:where(
256-
:has(input:invalid),
257-
:has(input[aria-invalid]),
258-
:has(input.is-invalid),
259-
.is-invalid
260-
) {
256+
:has(input:invalid),
257+
:has(input[aria-invalid]),
258+
:has(input.is-invalid),
259+
.is-invalid
260+
) {
261261
--post-card-control-border-color: #{color.$error};
262262
--post-card-control-bg: #{color.$error-background};
263263
--post-card-control-color: #{color.$error};

0 commit comments

Comments
 (0)