@rtorcato/repo-tooling 3.7.3 → 3.8.0
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.
- package/README.md +14 -0
- package/dist/cli/commands/doctor.js +2 -1
- package/dist/cli/commands/fix-targets.js +1 -0
- package/dist/cli/generators/linting.js +42 -1
- package/dist/languages/js/checks.js +33 -4
- package/dist/languages/js/fixers.js +38 -12
- package/package.json +1 -1
- package/tooling/biome/biome.json +1 -1
package/README.md
CHANGED
|
@@ -53,6 +53,20 @@ npx @rtorcato/repo-tooling copy oxlint # → .oxlintrc.json
|
|
|
53
53
|
npx @rtorcato/repo-tooling copy claude-skill # → .claude/skills/repo-tooling.md
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
The Biome preset honours your `.gitignore`, so build output stays unlinted. One
|
|
57
|
+
known gap: Biome cannot parse Tailwind CSS v4 stylesheets (`@theme`, `@source`,
|
|
58
|
+
`@custom-variant`, `@apply`) and reports a parse error on them. If you use
|
|
59
|
+
Tailwind v4, exclude your stylesheet in `biome.json`:
|
|
60
|
+
|
|
61
|
+
```jsonc
|
|
62
|
+
{
|
|
63
|
+
"extends": ["@rtorcato/repo-tooling/biome"],
|
|
64
|
+
// `includes` replaces the preset's list rather than extending it — restate
|
|
65
|
+
// the exclusions you still want alongside the CSS one.
|
|
66
|
+
"files": { "includes": ["**", "!**/node_modules", "!**/dist", "!**/*.css"] }
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
56
70
|
**Already have a project?** Don't rerun `setup` — use `doctor` + `fix`:
|
|
57
71
|
|
|
58
72
|
```bash
|
|
@@ -17,7 +17,7 @@ import { checkGitIdentity } from '../../base/git-identity.js';
|
|
|
17
17
|
import { LOCKFILE_VERSION, readLockfile } from '../utils/lockfile.js';
|
|
18
18
|
import { declinedInLock, getFixTargetForCheck } from './fix-targets.js';
|
|
19
19
|
import { checkAiSetup, checkCodeowners, checkCodeQL, checkCommunityHealth, checkCoverageUpload, checkDependabot, checkEditorConfig, checkFile, checkGitHooks, checkGitHubActions, checkGitLabCI, checkNestedLanguages, checkPrePushHook, checkReadmeBadges, COMMITLINT_FILE_CHECK, } from '../../base/checks.js';
|
|
20
|
-
import { allDeps, checkAreTheTypesWrong, checkConfigSchemaVersions, checkDocsSite, checkEnginesNode, checkGitDependencies, checkKnip, checkLintStaged, checkNodeVersionConsistency, checkNodeVersionPin, checkPackageJson, checkPublint, checkSemanticRelease, checkSizeLimit, checkTailwind, checkBuildApprovals, checkPnpmWorkspace, checkTreeshakeSetup, checkTurborepo, checkTypedoc, checkVerifyScript, checkVscodeExtensions, evaluateNodeVersion, FILE_CHECKS, findDocsAppDir, jsBadgeAudience, jsGitHooksProfile, readPackageJson, } from '../../languages/js/checks.js';
|
|
20
|
+
import { allDeps, checkAreTheTypesWrong, checkConfigSchemaVersions, checkDocsSite, checkEnginesNode, checkGitDependencies, checkKnip, checkLintStaged, checkNodeVersionConsistency, checkNodeVersionPin, checkPackageJson, checkPackageManager, checkPublint, checkSemanticRelease, checkSizeLimit, checkTailwind, checkBuildApprovals, checkPnpmWorkspace, checkTreeshakeSetup, checkTurborepo, checkTypedoc, checkVerifyScript, checkVscodeExtensions, evaluateNodeVersion, FILE_CHECKS, findDocsAppDir, jsBadgeAudience, jsGitHooksProfile, readPackageJson, } from '../../languages/js/checks.js';
|
|
21
21
|
export { evaluateNodeVersion };
|
|
22
22
|
const PACKAGE = '@rtorcato/repo-tooling';
|
|
23
23
|
// Detects the broken-release-on-protected-main footgun: a workflow that runs
|
|
@@ -282,6 +282,7 @@ export async function runDoctor(dir) {
|
|
|
282
282
|
results.push(evaluateNodeVersion(process.version));
|
|
283
283
|
results.push(checkPackageJson(pkg));
|
|
284
284
|
results.push(checkEnginesNode(pkg));
|
|
285
|
+
results.push(await checkPackageManager(targetDir, pkg));
|
|
285
286
|
results.push(await checkConfigSchemaVersions(targetDir, pkg));
|
|
286
287
|
results.push(checkGitDependencies(pkg));
|
|
287
288
|
results.push(await checkVscodeExtensions(targetDir));
|
|
@@ -34,6 +34,46 @@ export const BIOME_CONFIG = 'biome.json';
|
|
|
34
34
|
* BIOME_CONFIG and delete this on the way past, so the ambiguity can't persist.
|
|
35
35
|
*/
|
|
36
36
|
export const BIOME_LEGACY_CONFIG = 'biome.jsonc';
|
|
37
|
+
/**
|
|
38
|
+
* Used when nothing in the target repo says which Biome will read the config —
|
|
39
|
+
* a bare directory mid-`setup`, before `pnpm install` has run. Matches the
|
|
40
|
+
* `$schema` the shipped preset carries.
|
|
41
|
+
*/
|
|
42
|
+
const BIOME_SCHEMA_FALLBACK = '2.5.0';
|
|
43
|
+
async function readJsonOrNull(filepath) {
|
|
44
|
+
try {
|
|
45
|
+
return (await fs.readJson(filepath));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The Biome version the scaffolded `$schema` URL should name (#363).
|
|
53
|
+
*
|
|
54
|
+
* A hardcoded version drifts the moment the consumer's Biome moves, and Biome
|
|
55
|
+
* reports the mismatch on *every* invocation ("The configuration schema version
|
|
56
|
+
* does not match the CLI version 2.5.7") — noise on a file the consumer never
|
|
57
|
+
* wrote. The installed package wins because it is literally the binary that
|
|
58
|
+
* will parse the file and emit that warning; the declared range is the next
|
|
59
|
+
* best statement of intent when node_modules isn't populated yet.
|
|
60
|
+
*/
|
|
61
|
+
export async function resolveBiomeSchemaVersion(targetDir) {
|
|
62
|
+
const installed = await readJsonOrNull(path.join(targetDir, 'node_modules', '@biomejs', 'biome', 'package.json'));
|
|
63
|
+
const pkg = await readJsonOrNull(path.join(targetDir, 'package.json'));
|
|
64
|
+
const deps = {
|
|
65
|
+
...(pkg?.dependencies ?? {}),
|
|
66
|
+
...(pkg?.devDependencies ?? {}),
|
|
67
|
+
};
|
|
68
|
+
// Both an exact version ("2.5.7") and a range ("^2.5.0") carry the x.y.z we
|
|
69
|
+
// need, so one pattern covers every source.
|
|
70
|
+
for (const candidate of [installed?.version, deps['@biomejs/biome']]) {
|
|
71
|
+
const match = typeof candidate === 'string' ? /(\d+\.\d+\.\d+)/.exec(candidate) : null;
|
|
72
|
+
if (match?.[1])
|
|
73
|
+
return match[1];
|
|
74
|
+
}
|
|
75
|
+
return BIOME_SCHEMA_FALLBACK;
|
|
76
|
+
}
|
|
37
77
|
/**
|
|
38
78
|
* The thin pointer config — the same shape this repo dogfoods. `fix biome` used
|
|
39
79
|
* to copy the whole preset inline instead, which meant the scaffolded file
|
|
@@ -45,8 +85,9 @@ export async function generateBiomeConfig(targetDir) {
|
|
|
45
85
|
// file globs via `files.includes`; emitting the old 1.x `include`/`ignore`
|
|
46
86
|
// keys here forced consumers to run `biome migrate` before `biome check`
|
|
47
87
|
// would run at all.
|
|
88
|
+
const version = await resolveBiomeSchemaVersion(targetDir);
|
|
48
89
|
const biomeConfig = {
|
|
49
|
-
$schema:
|
|
90
|
+
$schema: `https://biomejs.dev/schemas/${version}/schema.json`,
|
|
50
91
|
extends: ['@rtorcato/repo-tooling/biome'],
|
|
51
92
|
};
|
|
52
93
|
await fs.writeJson(path.join(targetDir, BIOME_CONFIG), biomeConfig, { spaces: 2 });
|
|
@@ -156,6 +156,38 @@ export function checkPackageJson(pkg) {
|
|
|
156
156
|
hint: `Run \`pnpm add -D ${PACKAGE}\``,
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Whether the repo installs with pnpm. Three independent signals, any of which
|
|
161
|
+
* is enough: the workspace file, the lockfile, or a `packageManager` that
|
|
162
|
+
* already names pnpm. Shared so `packageManager` and `pnpm settings` agree on
|
|
163
|
+
* what "a pnpm repo" means.
|
|
164
|
+
*/
|
|
165
|
+
export async function usesPnpm(dir, pkg) {
|
|
166
|
+
return ((await fs.pathExists(path.join(dir, WORKSPACE_FILE))) ||
|
|
167
|
+
(await fs.pathExists(path.join(dir, 'pnpm-lock.yaml'))) ||
|
|
168
|
+
(pkg?.packageManager ?? '').startsWith('pnpm'));
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* `packageManager` pins the pnpm that `pnpm/action-setup` resolves (#364). The
|
|
172
|
+
* generated workflow passes no `version:` input, so a pnpm repo without this
|
|
173
|
+
* field fails CI at setup — before a single check runs (#372).
|
|
174
|
+
*/
|
|
175
|
+
export async function checkPackageManager(dir, pkg) {
|
|
176
|
+
const check = 'packageManager';
|
|
177
|
+
if (!(await usesPnpm(dir, pkg))) {
|
|
178
|
+
return { check, status: 'ok', detail: 'not a pnpm repo' };
|
|
179
|
+
}
|
|
180
|
+
const declared = pkg?.packageManager ?? '';
|
|
181
|
+
if (declared.trim() !== '') {
|
|
182
|
+
return { check, status: 'ok', detail: `packageManager = ${declared}` };
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
check,
|
|
186
|
+
status: 'drift',
|
|
187
|
+
detail: 'packageManager not set in package.json',
|
|
188
|
+
hint: `Run \`npx ${PACKAGE} fix engines\` to pin the pnpm version CI resolves`,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
159
191
|
export function checkEnginesNode(pkg) {
|
|
160
192
|
if (!pkg) {
|
|
161
193
|
return {
|
|
@@ -844,10 +876,7 @@ export async function checkPnpmWorkspace(dir, pkg) {
|
|
|
844
876
|
const hint = `Run \`npx ${PACKAGE} fix pnpm-workspace\` to merge them in`;
|
|
845
877
|
const file = path.join(dir, WORKSPACE_FILE);
|
|
846
878
|
const exists = await fs.pathExists(file);
|
|
847
|
-
|
|
848
|
-
(await fs.pathExists(path.join(dir, 'pnpm-lock.yaml'))) ||
|
|
849
|
-
(pkg?.packageManager ?? '').startsWith('pnpm');
|
|
850
|
-
if (!usesPnpm) {
|
|
879
|
+
if (!(await usesPnpm(dir, pkg))) {
|
|
851
880
|
return { check, status: 'ok', detail: 'not a pnpm repo' };
|
|
852
881
|
}
|
|
853
882
|
const yaml = exists ? await fs.readFile(file, 'utf-8') : '';
|
|
@@ -10,6 +10,7 @@ import { GH_WORKFLOWS, generateGhWorkflow } from '../../cli/generators/github-wo
|
|
|
10
10
|
import { BIOME_CONFIG, generateBiomeConfig, generateESLintConfig, generatePrettierConfig, } from '../../cli/generators/linting.js';
|
|
11
11
|
import { alignNodeVersion, ensureEnginesNode, ensurePackageManager, generateKnipConfig, generateNvmrc, generateSizeLimitConfig, generateVscodeExtensions, } from '../../cli/generators/misc.js';
|
|
12
12
|
import { scriptsOf } from './ci.js';
|
|
13
|
+
import { usesPnpm } from './checks.js';
|
|
13
14
|
import { composeVerifyScriptFromPkg, ensureScripts } from '../../cli/generators/package-json.js';
|
|
14
15
|
/** Kept in step with the biome branch of getScripts() in package-json.ts. */
|
|
15
16
|
const BIOME_SCRIPTS = {
|
|
@@ -18,6 +19,15 @@ const BIOME_SCRIPTS = {
|
|
|
18
19
|
check: 'biome check .',
|
|
19
20
|
'check:fix': 'biome check --fix .',
|
|
20
21
|
};
|
|
22
|
+
/** Kept in step with the eslint branch of getScripts() in package-json.ts. */
|
|
23
|
+
const ESLINT_SCRIPTS = {
|
|
24
|
+
lint: 'eslint .',
|
|
25
|
+
'lint:fix': 'eslint . --fix',
|
|
26
|
+
};
|
|
27
|
+
/** Kept in step with the eslint branch of getScripts() in package-json.ts. */
|
|
28
|
+
const PRETTIER_SCRIPTS = {
|
|
29
|
+
format: 'prettier --write .',
|
|
30
|
+
};
|
|
21
31
|
import { WORKSPACE_FILE, dependsOnEsbuild, ensurePnpmSettings, familyGlob, } from '../../cli/generators/pnpm-workspace.js';
|
|
22
32
|
import { generatePostcss } from '../../cli/generators/postcss.js';
|
|
23
33
|
import { generateCypressConfig, generateVitestConfig } from '../../cli/generators/testing.js';
|
|
@@ -151,24 +161,32 @@ export const FIXERS = [
|
|
|
151
161
|
},
|
|
152
162
|
{
|
|
153
163
|
target: 'eslint',
|
|
154
|
-
description: 'Scaffold eslint.config.mjs importing the @rtorcato/repo-tooling preset',
|
|
164
|
+
description: 'Scaffold eslint.config.mjs importing the @rtorcato/repo-tooling preset, plus the scripts that run it',
|
|
155
165
|
appliesTo: ['ESLint'],
|
|
156
|
-
outputs: ['eslint.config.mjs'],
|
|
166
|
+
outputs: ['eslint.config.mjs', 'package.json (scripts)'],
|
|
157
167
|
canFixDrift: true,
|
|
158
168
|
async run({ targetDir, pkg }) {
|
|
159
169
|
await generateESLintConfig(inferProjectConfig(pkg), targetDir);
|
|
160
|
-
|
|
170
|
+
const filesWritten = ['eslint.config.mjs'];
|
|
171
|
+
// Without `lint` the generated CI drops its lint step and `fix verify`
|
|
172
|
+
// composes a chain with no linting in it at all (#371).
|
|
173
|
+
if (await ensureScripts(targetDir, ESLINT_SCRIPTS))
|
|
174
|
+
filesWritten.push('package.json');
|
|
175
|
+
return { filesWritten };
|
|
161
176
|
},
|
|
162
177
|
},
|
|
163
178
|
{
|
|
164
179
|
target: 'prettier',
|
|
165
|
-
description: 'Scaffold prettier.config.mjs re-exporting the preset',
|
|
180
|
+
description: 'Scaffold prettier.config.mjs re-exporting the preset, plus the `format` script',
|
|
166
181
|
appliesTo: ['Prettier'],
|
|
167
|
-
outputs: ['prettier.config.mjs'],
|
|
182
|
+
outputs: ['prettier.config.mjs', 'package.json (scripts)'],
|
|
168
183
|
canFixDrift: true,
|
|
169
184
|
async run({ targetDir }) {
|
|
170
185
|
await generatePrettierConfig(targetDir);
|
|
171
|
-
|
|
186
|
+
const filesWritten = ['prettier.config.mjs'];
|
|
187
|
+
if (await ensureScripts(targetDir, PRETTIER_SCRIPTS))
|
|
188
|
+
filesWritten.push('package.json');
|
|
189
|
+
return { filesWritten };
|
|
172
190
|
},
|
|
173
191
|
},
|
|
174
192
|
{
|
|
@@ -459,14 +477,22 @@ export const FIXERS = [
|
|
|
459
477
|
},
|
|
460
478
|
{
|
|
461
479
|
target: 'engines',
|
|
462
|
-
description: 'Add engines.node to package.json',
|
|
463
|
-
appliesTo: ['engines.node'],
|
|
464
|
-
outputs: ['package.json (engines.node
|
|
480
|
+
description: 'Add engines.node and packageManager to package.json',
|
|
481
|
+
appliesTo: ['engines.node', 'packageManager'],
|
|
482
|
+
outputs: ['package.json (engines.node + packageManager fields)'],
|
|
465
483
|
riskLevel: 'safe-merge',
|
|
466
484
|
canFixDrift: true,
|
|
467
|
-
async run({ targetDir }) {
|
|
468
|
-
|
|
469
|
-
|
|
485
|
+
async run({ targetDir, pkg }) {
|
|
486
|
+
// Same concern as engines.node — declaring the toolchain the repo
|
|
487
|
+
// expects. `fix github-actions` also pins it, but only reaches repos
|
|
488
|
+
// whose ci.yml is already drifted (#372). Guarded on pnpm because the
|
|
489
|
+
// value we write is a pnpm range; an npm or yarn repo must not get one.
|
|
490
|
+
const engines = await ensureEnginesNode(targetDir);
|
|
491
|
+
const manager = (await usesPnpm(targetDir, pkg))
|
|
492
|
+
? await ensurePackageManager(targetDir)
|
|
493
|
+
: 'already-set';
|
|
494
|
+
const changed = engines === 'added' || manager === 'added';
|
|
495
|
+
return { filesWritten: changed ? ['package.json'] : [] };
|
|
470
496
|
},
|
|
471
497
|
},
|
|
472
498
|
{
|
package/package.json
CHANGED