Skip to content

Commit bd261d6

Browse files
fix(lint): pass file lists to lint scripts as separate arguments (#128363)
`scripts/lint.ts` (#127203) runs root and package lint scripts through `pnpm run`, which joins every path into one shell string, so a change to a widely imported file makes the impacted-files oxlint step crash before linting starts. This brings back the fix from #126758 by running each script's command through `pnpm exec` so paths stay separate arguments.
1 parent d19dbf7 commit bd261d6

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎scripts/lint.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ function run(options: string[], cwd = process.cwd()) {
2525
return result.status ?? 1;
2626
}
2727

28+
// `pnpm run` joins arguments into one shell string, which overflows on large file lists.
29+
function scriptCommand(directory: string, name: string) {
30+
const manifest = JSON.parse(readFileSync(path.join(directory, 'package.json'), 'utf8'));
31+
const script: unknown = manifest?.scripts?.[name];
32+
assert(
33+
typeof script === 'string' && /^[\w@./:=-]+( [\w@./:=-]+)*$/.test(script),
34+
`Expected ${name} in ${directory} to be a plain command`
35+
);
36+
return ['exec', ...script.split(' ')];
37+
}
38+
2839
const {positionals, tokens} = parseArgs({
2940
args: inspect ? [] : args,
3041
strict: false,
@@ -141,7 +152,10 @@ if (inspect) {
141152
let status = 0;
142153
const rootFiles = selected.get(process.cwd());
143154
if (rootFiles) {
144-
status = run(['run', `lint:${language}:root`, ...lintArgs(rootFiles)]);
155+
status = run([
156+
...scriptCommand(process.cwd(), `lint:${language}:root`),
157+
...lintArgs(rootFiles),
158+
]);
145159
selected.delete(process.cwd());
146160
}
147161
if (status === 0) {
@@ -151,7 +165,7 @@ if (inspect) {
151165
const command =
152166
language === 'css'
153167
? ['exec', 'stylelint', '--allow-empty-input']
154-
: ['run', 'lint:js'];
168+
: scriptCommand(project, 'lint:js');
155169
const result = run([...command, ...lintArgs(files)], project);
156170
status ||= result;
157171
}

0 commit comments

Comments
 (0)