Skip to content

Commit 8e3afb3

Browse files
fix(ci): handle missing rg in verify turbo conventions
1 parent 6a8c61d commit 8e3afb3

File tree

1 file changed

+67
-3
lines changed

1 file changed

+67
-3
lines changed

tools/scripts/verify-turbo-conventions.mjs

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,45 @@ function listPackageJsonPaths() {
8585
},
8686
);
8787

88-
if (result.status !== 0) {
88+
if (!result.error && result.status === 0) {
89+
return normalizePackageJsonPaths(result.stdout);
90+
}
91+
92+
if (isCommandNotFound(result)) {
93+
return listPackageJsonPathsFromGit();
94+
}
95+
96+
throw new Error(
97+
`[verify-turbo-conventions] Failed to list package.json files with rg: ${formatSpawnFailure(result)}`,
98+
);
99+
}
100+
101+
function listPackageJsonPathsFromGit() {
102+
const result = spawnSync('git', ['ls-files'], {
103+
cwd: ROOT,
104+
encoding: 'utf-8',
105+
stdio: 'pipe',
106+
});
107+
108+
if (result.error || result.status !== 0) {
89109
throw new Error(
90-
`[verify-turbo-conventions] Failed to list package.json files: ${result.stderr || result.stdout}`,
110+
`[verify-turbo-conventions] Failed to list package.json files with git ls-files fallback: ${formatSpawnFailure(result)}`,
91111
);
92112
}
93113

94-
return result.stdout
114+
return normalizePackageJsonPaths(
115+
result.stdout
116+
.split('\n')
117+
.map((entry) => entry.trim())
118+
.filter(Boolean)
119+
.filter((entry) => entry === 'package.json' || entry.endsWith('/package.json'))
120+
.filter((entry) => !isExcludedPackageJsonPath(entry))
121+
.join('\n'),
122+
);
123+
}
124+
125+
function normalizePackageJsonPaths(stdout) {
126+
return stdout
95127
.split('\n')
96128
.map((entry) => entry.trim())
97129
.filter(Boolean)
@@ -278,6 +310,38 @@ function normalizeFilterTarget(filterTarget) {
278310
return filterTarget;
279311
}
280312

313+
function isExcludedPackageJsonPath(path) {
314+
return (
315+
path.includes('/node_modules/') ||
316+
path.includes('/dist/') ||
317+
path.includes('/build/') ||
318+
path.includes('/.next/')
319+
);
320+
}
321+
322+
function isCommandNotFound(result) {
323+
return result.error?.code === 'ENOENT';
324+
}
325+
326+
function formatSpawnFailure(result) {
327+
if (result.error?.message) {
328+
return result.error.message;
329+
}
330+
if (typeof result.stderr === 'string' && result.stderr.trim()) {
331+
return result.stderr.trim();
332+
}
333+
if (typeof result.stdout === 'string' && result.stdout.trim()) {
334+
return result.stdout.trim();
335+
}
336+
if (typeof result.status === 'number') {
337+
return `exit code ${result.status}`;
338+
}
339+
if (result.signal) {
340+
return `terminated by signal ${result.signal}`;
341+
}
342+
return 'unknown error';
343+
}
344+
281345
function hasWildcard(filterTarget) {
282346
return filterTarget.includes('*') || filterTarget.includes('?');
283347
}

0 commit comments

Comments
 (0)