Skip to content

Commit 9fd585d

Browse files
committed
[DX] Reconfigure lint/format tasks to not run the command for each workspace, since Biome is super fast (also include bin and test JS files)
1 parent 86c31f1 commit 9fd585d

File tree

5 files changed

+48
-39
lines changed

5 files changed

+48
-39
lines changed

bin/build_package.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ async function main() {
3838
const srcDir = path.join(packageRoot, 'src');
3939
const distDir = path.join(packageRoot, 'dist');
4040

41-
4241
if (!fs.existsSync(srcDir)) {
4342
console.error(`The package directory "${packageRoot}" does not contain a "src" directory.`);
4443
process.exit(1);
4544
}
46-
45+
4746
if (fs.existsSync(distDir)) {
4847
console.log(`Cleaning up the "${distDir}" directory...`);
4948
await fs.promises.rm(distDir, { recursive: true });
@@ -53,41 +52,42 @@ async function main() {
5352
const inputScriptFiles = [
5453
...glob.sync(path.join(srcDir, '*controller.ts')),
5554
...(['@symfony/ux-react', '@symfony/ux-vue', '@symfony/ux-svelte'].includes(packageName)
56-
? [
57-
path.join(srcDir, 'loader.ts'),
58-
path.join(srcDir, 'components.ts'),
59-
]
55+
? [path.join(srcDir, 'loader.ts'), path.join(srcDir, 'components.ts')]
6056
: []),
6157
...(packageName === '@symfony/stimulus-bundle'
62-
? [
63-
path.join(srcDir, 'loader.ts'),
64-
path.join(srcDir, 'controllers.ts'),
65-
] : []),
58+
? [path.join(srcDir, 'loader.ts'), path.join(srcDir, 'controllers.ts')]
59+
: []),
6660
];
67-
68-
const inputStyleFile = packageData.config && packageData.config.css_source;
61+
62+
const inputStyleFile = packageData.config?.css_source;
6963
const buildCss = async () => {
70-
const inputStyleFileDist = inputStyleFile ? path.resolve(distDir, `${path.basename(inputStyleFile, '.css')}.min.css`) : undefined;
64+
const inputStyleFileDist = inputStyleFile
65+
? path.resolve(distDir, `${path.basename(inputStyleFile, '.css')}.min.css`)
66+
: undefined;
7167
if (!inputStyleFile) {
7268
return;
7369
}
74-
70+
7571
console.log('Minifying CSS...');
7672
const css = await fs.promises.readFile(inputStyleFile, 'utf-8');
7773
const minified = new CleanCSS().minify(css).styles;
7874
await fs.promises.writeFile(inputStyleFileDist, minified);
79-
}
75+
};
8076

8177
if (inputScriptFiles.length === 0) {
82-
console.error(`No input files found for package "${packageName}" (directory "${packageRoot}").\nEnsure you have at least a file matching the pattern "src/*_controller.ts", or manually specify input files in "${__filename}" file.`);
78+
console.error(
79+
`No input files found for package "${packageName}" (directory "${packageRoot}").\nEnsure you have at least a file matching the pattern "src/*_controller.ts", or manually specify input files in "${__filename}" file.`
80+
);
8381
process.exit(1);
8482
}
8583

8684
const rollupConfig = getRollupConfiguration({ packageRoot, inputFiles: inputScriptFiles });
8785

8886
if (args.values.watch) {
89-
console.log(`Watching for JavaScript${inputStyleFile ? ' and CSS' : ''} files modifications in "${srcDir}" directory...`);
90-
87+
console.log(
88+
`Watching for JavaScript${inputStyleFile ? ' and CSS' : ''} files modifications in "${srcDir}" directory...`
89+
);
90+
9191
if (inputStyleFile) {
9292
rollupConfig.plugins = (rollupConfig.plugins || []).concat({
9393
name: 'watcher',
@@ -96,7 +96,7 @@ async function main() {
9696
},
9797
});
9898
}
99-
99+
100100
const watcher = rollup.watch(rollupConfig);
101101
watcher.on('event', ({ result }) => {
102102
if (result) {
@@ -105,7 +105,7 @@ async function main() {
105105
});
106106
watcher.on('change', async (id, { event }) => {
107107
if (event === 'update') {
108-
console.log(`Files were modified, rebuilding...`);
108+
console.log('Files were modified, rebuilding...');
109109
}
110110

111111
if (inputStyleFile && id === inputStyleFile) {
@@ -115,12 +115,12 @@ async function main() {
115115
} else {
116116
console.log(`Building JavaScript files from ${packageName} package...`);
117117
const start = Date.now();
118-
118+
119119
const bundle = await rollup.rollup(rollupConfig);
120120
await bundle.write(rollupConfig.output);
121-
121+
122122
await buildCss();
123-
123+
124124
console.log(`Done in ${((Date.now() - start) / 1000).toFixed(3)} seconds.`);
125125
}
126126
}

bin/rollup.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
const fs = require('node:fs');
2+
const path = require('node:path');
13
const resolve = require('@rollup/plugin-node-resolve');
24
const commonjs = require('@rollup/plugin-commonjs');
35
const typescript = require('@rollup/plugin-typescript');
4-
const fs = require('fs');
56
const glob = require('glob');
6-
const path = require('path');
77

88
/**
99
* Guarantees that any files imported from a peer dependency are treated as an external.
@@ -53,11 +53,20 @@ const moveTypescriptDeclarationsPlugin = (packageRoot) => ({
5353
files.forEach((file) => {
5454
// a bit odd, but remove first 8 or 11 directories, which will leave
5555
// only the relative path to the file
56-
const relativePath = file.split('/').slice(isBridge ? 11 : 8).join('/');
57-
const targetFile = relativePath.replace(relativePath.split('/').slice(1, isBridge ? 7 : 4).join('/') + '/', '');
58-
56+
const relativePath = file
57+
.split('/')
58+
.slice(isBridge ? 11 : 8)
59+
.join('/');
60+
const targetFile = relativePath.replace(
61+
`${relativePath
62+
.split('/')
63+
.slice(1, isBridge ? 7 : 4)
64+
.join('/')}/`,
65+
''
66+
);
67+
5968
if (!fs.existsSync(path.dirname(targetFile))) {
60-
fs.mkdirSync(path.dirname(targetFile), { recursive: true });
69+
fs.mkdirSync(path.dirname(targetFile), { recursive: true });
6170
}
6271
fs.renameSync(file, targetFile);
6372
});
@@ -81,15 +90,15 @@ function getRollupConfiguration({ packageRoot, inputFiles }) {
8190
if (file.includes('StimulusBundle/assets/src/loader.ts')) {
8291
peerDependencies.push('./controllers.js');
8392
}
84-
93+
8594
// React, Vue
8695
if (file.includes('assets/src/loader.ts')) {
8796
peerDependencies.push('./components.js');
8897
}
8998
});
90-
99+
91100
const outDir = path.join(packageRoot, 'dist');
92-
101+
93102
return {
94103
input: inputFiles,
95104
output: {
@@ -106,7 +115,7 @@ function getRollupConfiguration({ packageRoot, inputFiles }) {
106115
include: [
107116
'src/**/*.ts',
108117
// TODO: Remove for the next major release
109-
// "@rollup/plugin-typescript" v11.0.0 fixed an issue (https://github.com/rollup/plugins/pull/1310) that
118+
// "@rollup/plugin-typescript" v11.0.0 fixed an issue (https://github.com/rollup/plugins/pull/1310) that
110119
// cause a breaking change for UX React users, the dist file requires "react-dom/client" instead of "react-dom"
111120
// and it will break for users using the Symfony AssetMapper without Symfony Flex (for automatic "importmap.php" upgrade).
112121
'**/node_modules/react-dom/client.js',

biome.json

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"include": [
55
"*.json",
66
"*.md",
7+
"bin/*.js",
8+
"test/*.js",
79
"src/*/*.json",
810
"src/*/*/md",
911
"src/*/assets/src/**",

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"scripts": {
99
"build": "yarn workspaces foreach -Apt run build",
1010
"test": "bin/run-vitest-all.sh",
11-
"lint": "yarn workspaces foreach -Apt run lint",
12-
"format": "yarn workspaces foreach -Apt run format",
13-
"check-lint": "yarn workspaces foreach -Apt run check-lint",
14-
"check-format": "yarn workspaces foreach -Apt run check-format"
11+
"lint": "biome lint --write",
12+
"format": "biome format --write",
13+
"check-lint": "biome lint",
14+
"check-format": "biome format"
1515
},
1616
"devDependencies": {
1717
"@babel/core": "^7.25.2",

test/setup.js

-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* file that was distributed with this source code.
88
*/
99

10-
'use strict';
11-
1210
import '@symfony/stimulus-testing/setup';

0 commit comments

Comments
 (0)