@rtorcato/repo-tooling 3.8.0 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -923,17 +923,74 @@ export function decidedBuilds(yaml) {
|
|
|
923
923
|
return decided;
|
|
924
924
|
}
|
|
925
925
|
/**
|
|
926
|
-
*
|
|
926
|
+
* Package name encoded in a `node_modules/.pnpm` directory name (#373).
|
|
927
|
+
*
|
|
928
|
+
* Entries read `<name>@<version>` with `/` written as `+`, and the version may
|
|
929
|
+
* carry a peer suffix that contains further `@`s
|
|
930
|
+
* (`@babel+core@7.0.0_supports-color@8.0.0`), so the separator is the *first*
|
|
931
|
+
* `@` after index 0 — never the last.
|
|
932
|
+
*/
|
|
933
|
+
export function pnpmStoreDirToName(entry) {
|
|
934
|
+
const at = entry.indexOf('@', 1);
|
|
935
|
+
if (at < 1)
|
|
936
|
+
return null;
|
|
937
|
+
return entry.slice(0, at).replace('+', '/');
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Transitive packages that ship a build script and have no decision (#373).
|
|
941
|
+
*
|
|
942
|
+
* One `package.json` read per unique name — never a recursive walk — and the
|
|
943
|
+
* whole pass is skipped when `.pnpm` is absent (npm/yarn repos, or nothing
|
|
944
|
+
* installed). `skip` drops the names the direct pass already owns.
|
|
945
|
+
*/
|
|
946
|
+
async function undecidedTransitiveBuilds(modulesDir, skip) {
|
|
947
|
+
const store = path.join(modulesDir, '.pnpm');
|
|
948
|
+
if (!(await fs.pathExists(store)))
|
|
949
|
+
return [];
|
|
950
|
+
const seen = new Set();
|
|
951
|
+
const undecided = new Set();
|
|
952
|
+
for (const entry of await fs.readdir(store)) {
|
|
953
|
+
const name = pnpmStoreDirToName(entry);
|
|
954
|
+
// A package present at two versions has two store dirs; report it once.
|
|
955
|
+
if (!name || seen.has(name) || skip(name))
|
|
956
|
+
continue;
|
|
957
|
+
seen.add(name);
|
|
958
|
+
// Store directory names come from registry metadata, and only the *first*
|
|
959
|
+
// `+` is decoded — the rest of the entry passes through literally, so a
|
|
960
|
+
// hostile name (`..+..@1.0.0` → `../..`) would climb out of the package
|
|
961
|
+
// directory and have `fs.readJson` read an unrelated file, whose `name`
|
|
962
|
+
// then lands in the report. Confirm the resolved path stays under this
|
|
963
|
+
// entry's `node_modules` before reading it.
|
|
964
|
+
const root = path.resolve(store, entry, 'node_modules');
|
|
965
|
+
const target = path.join(root, name, 'package.json');
|
|
966
|
+
if (!target.startsWith(root + path.sep))
|
|
967
|
+
continue;
|
|
968
|
+
let depPkg;
|
|
969
|
+
try {
|
|
970
|
+
depPkg = await fs.readJson(target);
|
|
971
|
+
}
|
|
972
|
+
catch {
|
|
973
|
+
continue;
|
|
974
|
+
}
|
|
975
|
+
const scripts = depPkg.scripts ?? {};
|
|
976
|
+
// `name` from the manifest is exact; the decoded dir name is the fallback.
|
|
977
|
+
if (BUILD_LIFECYCLE_SCRIPTS.some((s) => scripts[s]))
|
|
978
|
+
undecided.add(depPkg.name ?? name);
|
|
979
|
+
}
|
|
980
|
+
return [...undecided].filter((n) => !skip(n)).sort();
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Dependencies whose install would run a build script (#364, #373).
|
|
927
984
|
*
|
|
928
985
|
* pnpm 11 turned undecided build scripts into a hard error, so
|
|
929
986
|
* `pnpm install --frozen-lockfile` exits non-zero with ERR_PNPM_IGNORED_BUILDS
|
|
930
987
|
* — a guaranteed CI failure. Locally the same message reads as advisory, which
|
|
931
988
|
* is exactly why it gets missed until the pipeline goes red.
|
|
932
989
|
*
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
*
|
|
936
|
-
*
|
|
990
|
+
* Direct and transitive offenders are graded apart. A direct one is `drift`:
|
|
991
|
+
* the repo asked for the package by name and can answer for it. A transitive
|
|
992
|
+
* one is `optional-missing` — still worth recording, but common enough that
|
|
993
|
+
* grading it as drift would drown the report in noise.
|
|
937
994
|
*/
|
|
938
995
|
export async function checkBuildApprovals(dir, pkg) {
|
|
939
996
|
const check = 'pnpm build approvals';
|
|
@@ -964,13 +1021,19 @@ export async function checkBuildApprovals(dir, pkg) {
|
|
|
964
1021
|
if (BUILD_LIFECYCLE_SCRIPTS.some((s) => scripts[s]))
|
|
965
1022
|
undecided.push(name);
|
|
966
1023
|
}
|
|
967
|
-
|
|
1024
|
+
const transitive = await undecidedTransitiveBuilds(modulesDir, (name) => decided.has(name) || name in deps);
|
|
1025
|
+
if (undecided.length === 0 && transitive.length === 0) {
|
|
968
1026
|
return { check, status: 'ok', detail: 'every dependency with a build script has a decision' };
|
|
969
1027
|
}
|
|
1028
|
+
const parts = [];
|
|
1029
|
+
if (undecided.length)
|
|
1030
|
+
parts.push(`${undecided.length} dependenc${undecided.length === 1 ? 'y' : 'ies'} with undecided build scripts: ${undecided.join(', ')}`);
|
|
1031
|
+
if (transitive.length)
|
|
1032
|
+
parts.push(`${transitive.length} transitive dependenc${transitive.length === 1 ? 'y' : 'ies'} with undecided build scripts: ${transitive.join(', ')}`);
|
|
970
1033
|
return {
|
|
971
1034
|
check,
|
|
972
|
-
status: 'drift',
|
|
973
|
-
detail:
|
|
1035
|
+
status: undecided.length ? 'drift' : 'optional-missing',
|
|
1036
|
+
detail: parts.join('; '),
|
|
974
1037
|
hint: `Record a decision per package under \`allowBuilds:\` in ${WORKSPACE_FILE} (\`name: true\` to run it, \`false\` to skip). pnpm 11 fails \`pnpm install --frozen-lockfile\` outright while any is undecided, so CI cannot pass until each is answered.`,
|
|
975
1038
|
};
|
|
976
1039
|
}
|
|
@@ -28,6 +28,22 @@ const ESLINT_SCRIPTS = {
|
|
|
28
28
|
const PRETTIER_SCRIPTS = {
|
|
29
29
|
format: 'prettier --write .',
|
|
30
30
|
};
|
|
31
|
+
/** Kept in step with the knip line of getScripts() in package-json.ts. */
|
|
32
|
+
const KNIP_SCRIPTS = {
|
|
33
|
+
knip: 'knip',
|
|
34
|
+
};
|
|
35
|
+
/** Kept in step with the typescript branch of getScripts() in package-json.ts. */
|
|
36
|
+
const TSCONFIG_SCRIPTS = {
|
|
37
|
+
typecheck: 'tsc --noEmit',
|
|
38
|
+
};
|
|
39
|
+
// getScripts() also emits `test:ui`, but only the browser/both environments
|
|
40
|
+
// install @vitest/ui, so a fixed-up repo would get a script it can't run.
|
|
41
|
+
/** Kept in step with the vitest branch of getScripts() in package-json.ts. */
|
|
42
|
+
const VITEST_SCRIPTS = {
|
|
43
|
+
test: 'vitest',
|
|
44
|
+
'test:watch': 'vitest --watch',
|
|
45
|
+
coverage: 'vitest run --coverage',
|
|
46
|
+
};
|
|
31
47
|
import { WORKSPACE_FILE, dependsOnEsbuild, ensurePnpmSettings, familyGlob, } from '../../cli/generators/pnpm-workspace.js';
|
|
32
48
|
import { generatePostcss } from '../../cli/generators/postcss.js';
|
|
33
49
|
import { generateCypressConfig, generateVitestConfig } from '../../cli/generators/testing.js';
|
|
@@ -150,13 +166,19 @@ export const FIXERS = [
|
|
|
150
166
|
},
|
|
151
167
|
{
|
|
152
168
|
target: 'tsconfig',
|
|
153
|
-
description: 'Scaffold tsconfig.json extending the @rtorcato/repo-tooling preset',
|
|
169
|
+
description: 'Scaffold tsconfig.json extending the @rtorcato/repo-tooling preset, plus the `typecheck` script',
|
|
154
170
|
appliesTo: ['TypeScript'],
|
|
155
|
-
outputs: ['tsconfig.json'],
|
|
171
|
+
outputs: ['tsconfig.json', 'package.json (scripts)'],
|
|
156
172
|
canFixDrift: true,
|
|
157
173
|
async run({ targetDir }) {
|
|
158
174
|
const result = await copyPreset('tsconfig', targetDir);
|
|
159
|
-
|
|
175
|
+
const filesWritten = [result.target];
|
|
176
|
+
// Without `typecheck` the generated CI drops its typecheck job entirely
|
|
177
|
+
// (#377). Shared with non-JS paths, so this is a no-op when there's no
|
|
178
|
+
// package.json to add it to.
|
|
179
|
+
if (await ensureScripts(targetDir, TSCONFIG_SCRIPTS))
|
|
180
|
+
filesWritten.push('package.json');
|
|
181
|
+
return { filesWritten };
|
|
160
182
|
},
|
|
161
183
|
},
|
|
162
184
|
{
|
|
@@ -191,9 +213,9 @@ export const FIXERS = [
|
|
|
191
213
|
},
|
|
192
214
|
{
|
|
193
215
|
target: 'vitest',
|
|
194
|
-
description: 'Scaffold vitest.config.ts (preserves vitest.setup.ts if present)',
|
|
216
|
+
description: 'Scaffold vitest.config.ts (preserves vitest.setup.ts if present), plus the scripts that run it',
|
|
195
217
|
appliesTo: ['Vitest'],
|
|
196
|
-
outputs: ['vitest.config.ts'],
|
|
218
|
+
outputs: ['vitest.config.ts', 'package.json (scripts)'],
|
|
197
219
|
canFixDrift: true,
|
|
198
220
|
async run({ targetDir, pkg }) {
|
|
199
221
|
const setupPath = path.join(targetDir, 'vitest.setup.ts');
|
|
@@ -203,7 +225,12 @@ export const FIXERS = [
|
|
|
203
225
|
if (hadSetup && savedSetup !== null) {
|
|
204
226
|
await fs.writeFile(setupPath, savedSetup);
|
|
205
227
|
}
|
|
206
|
-
|
|
228
|
+
const filesWritten = ['vitest.config.ts'];
|
|
229
|
+
// Without `coverage`/`test` the generated CI drops the whole test job,
|
|
230
|
+
// Codecov upload included (#377).
|
|
231
|
+
if (await ensureScripts(targetDir, VITEST_SCRIPTS))
|
|
232
|
+
filesWritten.push('package.json');
|
|
233
|
+
return { filesWritten };
|
|
207
234
|
},
|
|
208
235
|
},
|
|
209
236
|
{
|
|
@@ -497,13 +524,18 @@ export const FIXERS = [
|
|
|
497
524
|
},
|
|
498
525
|
{
|
|
499
526
|
target: 'knip',
|
|
500
|
-
description: 'Scaffold knip.json (entry globs matched to the package.json build model)',
|
|
527
|
+
description: 'Scaffold knip.json (entry globs matched to the package.json build model), plus the `knip` script',
|
|
501
528
|
appliesTo: ['knip'],
|
|
502
|
-
outputs: ['knip.json'],
|
|
529
|
+
outputs: ['knip.json', 'package.json (scripts)'],
|
|
503
530
|
canFixDrift: true,
|
|
504
531
|
async run({ targetDir }) {
|
|
505
532
|
await generateKnipConfig(targetDir);
|
|
506
|
-
|
|
533
|
+
const filesWritten = ['knip.json'];
|
|
534
|
+
// Without `knip` the generated CI drops its unused-code step, and with no
|
|
535
|
+
// check/lint script either the whole lint job disappears (#377).
|
|
536
|
+
if (await ensureScripts(targetDir, KNIP_SCRIPTS))
|
|
537
|
+
filesWritten.push('package.json');
|
|
538
|
+
return { filesWritten };
|
|
507
539
|
},
|
|
508
540
|
},
|
|
509
541
|
{
|
package/package.json
CHANGED