@mark1russell7/conventions 0.9.0 → 0.10.1
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 +2 -0
- package/build/cli.js +1 -1
- package/build/index.d.ts +5 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/{run-CRjXzR_6.js → run-c3bySjnK.js} +184 -2
- package/build/run-c3bySjnK.js.map +1 -0
- package/package.json +1 -1
- package/build/run-CRjXzR_6.js.map +0 -1
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ Each break shows the file, the line, the rule and the fix. In GitHub Actions, th
|
|
|
26
26
|
- `tests-required`: the option `passWithNoTests` in a config or a script, in a package with test files. A package with no tests needs a person, who removes its test script.
|
|
27
27
|
- `typed-files`: a config file at the root of a package (`vitest.config.ts`). The fix adds `*.config.ts` and `rootDir: "."` to the `tsconfig.test.json` of the package, when that file has no comments.
|
|
28
28
|
- `trust-policy`: the settings `trustPolicy`, `trustPolicyIgnoreAfter` and `trustPolicyExclude` of `pnpm-workspace.yaml`. The fix makes the file when the repository has none.
|
|
29
|
+
- `main-check`: a compare of `process.argv[1]` with the path of the script. The fix writes `import.meta.main` when each Node version of `engines.node` has it (`^22.18`, `>=24.2`). Else it writes a compare of the two real paths, and it adds the imports. It removes the imports that only the old compare used.
|
|
29
30
|
|
|
30
31
|
The text output marks each break that has a fix. In the JSON output, such a break has `fixable: true`. The release train starts `conventions fix` in its update pull requests. Thus a break that a script can fix does not block a repository.
|
|
31
32
|
|
|
@@ -47,6 +48,7 @@ The rules come from the invariants audit of 2026-10-26 (strategy item s38). The
|
|
|
47
48
|
| `release-files` | A pull request changes `.github/workflows/release.yml` or `scripts/release/` only with a line `Release-Edit: <reason>` in a commit message or in the body of the pull request. The commits of the release bot (the sync of the template) need no reason. | coeval `no-release-edit`, `no-release-edits`. crawler `no-release-edit`, `no-release-edits`. headroom `no-release-edits`, `release-files-frozen`. |
|
|
48
49
|
| `typed-scripts` | Git keeps no JavaScript source (`.js`, `.mjs`, `.cjs`, `.jsx`, or a file with a `#!` line of `node`) and no shell script (`.sh`, `.bash`, `.zsh`, `.ps1`, or a `#!` line of a shell) of more than one line of code. Each script is TypeScript, which Node 22.18 and later starts directly. A file that must stay (generated output, vendored code, a configuration that a tool reads only as JavaScript) goes in `ignore` with its reason, so the list of exceptions can only get shorter. | fleet `typed-everything` (STRATEGY.md, direction 15). |
|
|
49
50
|
| `typed-files` | Each TypeScript file that git keeps (`.ts`, `.tsx`, `.mts`, `.cts`, not `.d.ts`) is in the program of a tsconfig that a `typecheck` script names: the tests, the e2e specs, the scripts, the benches and the configs too. The rule reads the configs of each `tsc`, `tsgo` or `vue-tsc` (`-p`, `--project`, `-b`, or `tsconfig.json`) and of `svelte-check --tsconfig`, follows their `references`, and lists the files with `tsc --listFilesOnly`. A file that a covered file imports is covered. A config that does not exist, and a repository where no typecheck names a config, are a break. | fleet `fail-closed` (STRATEGY.md, 2026-10-30). |
|
|
51
|
+
| `main-check` | No script finds out that it is the main module by a compare of `process.argv[1]` with its own path. Through a link (for example `~/git` to `D:/git`), the two paths differ: the script does nothing, and it ends with exit code 0. A script uses `import.meta.main`, or `realpathSync` on each side. | fleet `main-check` (STRATEGY.md, 2026-11-02). |
|
|
50
52
|
| `tests-required` | No test runner passes when it finds no test: no `passWithNoTests: true` in a config of vitest, vite, jest or Playwright, and no `--passWithNoTests` in `package.json`. With the option, a broken include pattern turns the test gate green with no test run. | fleet `fail-closed` (STRATEGY.md, 2026-10-30). |
|
|
51
53
|
| `roadmap-parses` | Each call of the Pages workflow of the template (`reusable-pages.yml`) gives a `roadmap`, or `site-pages: false`. Without it, the Status page shows no item of the plan. Each roadmap that a workflow gives to the Status page (a `roadmap:` key) parses as `@mark1russell7/site-pages` reads it. The rule uses the parser of site-pages. Thus a pull request finds a bad row, and the Pages job on `main` does not stop on it. | fleet `fail-closed` (STRATEGY.md, 2026-10-30). |
|
|
52
54
|
| `runner-budget` | All repositories of the account share 40 runners. Each `strategy` with a `matrix` has a `max-parallel` of 3 or less. Each workflow has a concurrency group at the top or in each job. A job that calls a shared workflow of the option `grouped` gets its group from that workflow, and each job of that workflow has a group. The minute of each `cron` comes from a hash of the repository and the file (1 to 59), so the schedules of the repositories do not start together. The repository comes from `GITHUB_REPOSITORY` or from the remote `origin`. | fleet `runner-slots` (STRATEGY.md, 2026-10-30). |
|
package/build/cli.js
CHANGED
package/build/index.d.ts
CHANGED
|
@@ -152,6 +152,11 @@ export declare function parseConfig(value: unknown, rules: readonly Rule[]): Con
|
|
|
152
152
|
/** The compiler options that make the type check strict. A package does not turn them off. */
|
|
153
153
|
export declare const STRICT_OPTIONS: readonly ["strict", "noImplicitAny", "strictNullChecks", "strictFunctionTypes", "strictBindCallApply", "strictPropertyInitialization", "strictBuiltinIteratorReturn", "noImplicitThis", "useUnknownInCatchVariables", "alwaysStrict", "noUncheckedIndexedAccess", "exactOptionalPropertyTypes", "noImplicitOverride", "noImplicitReturns", "noFallthroughCasesInSwitch", "noPropertyAccessFromIndexSignature"];
|
|
154
154
|
export declare const cuePreset: Rule;
|
|
155
|
+
/** The compare of two real paths. It is true through a link too, and it works on each Node version. */
|
|
156
|
+
export declare const REAL_COMPARE = "process.argv[1] !== undefined && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))";
|
|
157
|
+
/** This function tells if each Node version of the range has `import.meta.main`: 22.18 and later in 22, and 24.2 and later. Node 23 does not have it. */
|
|
158
|
+
export declare function hasImportMetaMain(range: unknown): boolean;
|
|
159
|
+
export declare const mainCheck: Rule;
|
|
155
160
|
export declare const noBuildOutput: Rule;
|
|
156
161
|
/** The names in a home path that do not identify a person: CI users, container users and placeholders. */
|
|
157
162
|
export declare const DEFAULT_ALLOWED: readonly string[];
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/rule.ts","../src/config.ts","../src/rules/cue-preset.ts","../src/rules/no-build-output.ts","../src/rules/no-local-paths.ts","../src/rules/pinned-git-deps.ts","../src/rules/release-files.ts","../src/rules/required-scripts.ts","../src/rules/roadmap-parses.ts","../src/rules/runner-budget.ts","../src/rules/source-main.ts","../src/rules/tests-required.ts","../src/rules/tsconfig-test.ts","../src/rules/typed-files.ts","../src/rules/typed-scripts.ts","../src/rules/trust-policy.ts","../src/rules/workspace-protocol.ts","../src/rules/index.ts","../src/run.ts","../src/workspace.ts"],"mappings":";UASiB;WACN;WACA;WACA;;;UAIM;;WAEN;;WAEA;WACA;;WAEA;;WAEA,iBAAiB;;;;;;UAOX;;WAEN;;WAEA;;WAEA;;;wBAIK,YAAY,cAAc,cAAc;;KAQ5C;;KAGA,UAAU,SAAS,eAAe;;UAG7B;WACN;WACA,SAAS;WACT;;;KAIC,WAAW,SAAS;;UAGf;;WAEN;;WAEA;;WAEA;;WAEA;WACA,UAAU;;;UAIJ;;WAEN;;WAEA,aAAa;;WAEb,mBAAmB;;WAEnB,KAAK,SAAS;;WAEd;;EAET;;EAEA,IAAI;;;KAIM,uBAAuB;WAAqB;;;UAGvC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,kBAAkB;;WAElB,SAAS,SAAS,eAAe;EAC1C,MAAM,SAAS,aAAa,SAAS,UAAU;;;qBAIpC;;wBAGG,aAAa,UAAU,UAAU;;wBAOjC,OAAO,cAAc,gBAAgB;;wBAOrC,QAAQ,cAAc,eAAe;;qBAMxC,WAAY,gBAAgB;;qBAG5B,YAAa;;wBAGV,WAAW,cAAc;;;;;;wBASzB,WAAW;;wBA2BX,UAAU;;wBAUV,OAAO,cAAc;;qBAOxB,UAAW,aAAa;;;;;wBAMrB,aAAa,SAAS,KAAK,oDAAoD;;UCrM9E;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;;UAIH;;WAEN;;WAEA,OAAO,SAAS,eAAe;;;wBAW1B,eAAe,MAAM,OAAO;;;;;;;wBAU5B,YAAY,gBAAgB,gBAAgB,SAAS;;qBCnCxD;qBA2FA,WAAW;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/rule.ts","../src/config.ts","../src/rules/cue-preset.ts","../src/rules/main-check.ts","../src/rules/no-build-output.ts","../src/rules/no-local-paths.ts","../src/rules/pinned-git-deps.ts","../src/rules/release-files.ts","../src/rules/required-scripts.ts","../src/rules/roadmap-parses.ts","../src/rules/runner-budget.ts","../src/rules/source-main.ts","../src/rules/tests-required.ts","../src/rules/tsconfig-test.ts","../src/rules/typed-files.ts","../src/rules/typed-scripts.ts","../src/rules/trust-policy.ts","../src/rules/workspace-protocol.ts","../src/rules/index.ts","../src/run.ts","../src/workspace.ts"],"mappings":";UASiB;WACN;WACA;WACA;;;UAIM;;WAEN;;WAEA;WACA;;WAEA;;WAEA,iBAAiB;;;;;;UAOX;;WAEN;;WAEA;;WAEA;;;wBAIK,YAAY,cAAc,cAAc;;KAQ5C;;KAGA,UAAU,SAAS,eAAe;;UAG7B;WACN;WACA,SAAS;WACT;;;KAIC,WAAW,SAAS;;UAGf;;WAEN;;WAEA;;WAEA;;WAEA;WACA,UAAU;;;UAIJ;;WAEN;;WAEA,aAAa;;WAEb,mBAAmB;;WAEnB,KAAK,SAAS;;WAEd;;EAET;;EAEA,IAAI;;;KAIM,uBAAuB;WAAqB;;;UAGvC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,kBAAkB;;WAElB,SAAS,SAAS,eAAe;EAC1C,MAAM,SAAS,aAAa,SAAS,UAAU;;;qBAIpC;;wBAGG,aAAa,UAAU,UAAU;;wBAOjC,OAAO,cAAc,gBAAgB;;wBAOrC,QAAQ,cAAc,eAAe;;qBAMxC,WAAY,gBAAgB;;qBAG5B,YAAa;;wBAGV,WAAW,cAAc;;;;;;wBASzB,WAAW;;wBA2BX,UAAU;;wBAUV,OAAO,cAAc;;qBAOxB,UAAW,aAAa;;;;;wBAMrB,aAAa,SAAS,KAAK,oDAAoD;;UCrM9E;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;;UAIH;;WAEN;;WAEA,OAAO,SAAS,eAAe;;;wBAW1B,eAAe,MAAM,OAAO;;;;;;;wBAU5B,YAAY,gBAAgB,gBAAgB,SAAS;;qBCnCxD;qBA2FA,WAAW;;qBCrFX;;wBA6BG,kBAAkB;qBAiFrB,WAAW;qBCxHX,eAAe;;qBCYf;;qBAGA,wBAAwB;qBAOxB,cAAc;;wBCnBX,eAAe;;;;;wBAaf,SAAS,cAAc;qBAqB1B,eAAe;qBCEf,cAAc;qBCrBd,iBAAiB;;wBCqCd,cAAc;qBAajB,eAAe;;;;;;wBCnBZ,eAAe,oBAAoB;;wBAUnC,mBAAmB;qBAsJtB,cAAc;;wBC7MX,QAAQ;;wBAQR,aAAa;qBAKhB,YAAY;qBCkBZ,eAAe;;wBCpBZ,SAAS,0BAA0B;qBAKtC,cAAc;;wBCiCX,gBAAgB;;;;;wBA4BhB,UAAU,SAAS,SAAS,0BAA0B,cAAc,OAAM;qBAgG7E,YAAY;qBCjJZ,cAAc;;qBC3Bd;;qBAGA;qBA6DA,aAAa;qBCnEb,mBAAmB;;qBCcnB,gBAAgB;;UCVZ;WACN;WACA;WACA;;WAEA;WACA,iBAAiB;;WAEjB;;WAEA;;;UAIM;WACN,gBAAgB;;WAEhB;;;UAIM;;WAEN;;WAEA;;WAEA;WACA,MAAM,SAAS;;WAEf,iBAAiB;;;wBAaZ,WAAW,cAAc,iBAAgB,SAAiB;;wBAO1D,cAAc,cAAc,QAAQ,mBAAmB,UAAS,KAAK,gCAAqC;;wBAwB1G,UAAU,SAAS,eAAe;;UAoCjC;;WAEN;;WAEA;;WAEA,QAAQ;;;;;;;wBAWH,OAAO,SAAS,eAAe;;wBAyC/B,aAAa,QAAQ;;wBA0BrB,gBAAgB,QAAQ;;wBAsBxB,YAAY,QAAQ;;wBAYpB,UAAU,QAAQ,+BAA+B,iBAAgB;;UAkBhE;WACN;WACA,KAAK,SAAS;WACd,SAAS;WACT,SAAS;;;qBAIP;;wBA0BG,OAAO,yBAAyB,IAAI;;;;;;wBC9QpC,aAAa,eAAe;;;;;wBAsD5B,YAAY,cAAc;;;;;;wBA8B1B,eAAe;;;;;;;wBAwCf,eAAe,cAAc"}
|
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { I as DEFAULT_ALLOWED,
|
|
1
|
+
export { I as DEFAULT_ALLOWED, G as DEPENDENCY_FIELDS, L as HOME_PATTERNS, p as IGNORE_AFTER, B as REAL_COMPARE, d as RULES, U as STRICT_OPTIONS, m as TRAIN_SCOPES, t as USAGE, n as annotations, K as cleanPath, q as codePackages, _ as configsOfScript, r as createContext, W as cuePreset, ct as defaultOptions, i as formatResult, it as globFolders, at as globToRegExp, J as hasFile, V as hasImportMetaMain, x as hasTests, Y as inFolder, N as isGitSpecifier, P as isPinned, C as isSourcePath, X as keyLine, Z as lineOf, a as listRules, H as mainCheck, Q as matchesAny, z as noBuildOutput, R as noLocalPaths, ot as packageFolders, lt as parseConfig, $ as parseJsonc, w as pathsOf, F as pinnedGitDeps, o as readConfig, et as readJsonc, M as releaseFiles, tt as replaceLine, E as repositoryOfRemote, j as requiredScripts, k as roadmapOfLine, A as roadmapParses, s as runChecks, c as runCli, l as runFix, nt as runGit, D as runnerBudget, O as scheduleMinute, v as scriptsOf, T as sourceMain, rt as specifiersOf, u as summaryMarkdown, b as testsRequired, h as trustPolicy, S as tsconfigTest, y as typedFiles, g as typedScripts, st as workspaceGlobs, f as workspaceProtocol } from "./run-c3bySjnK.js";
|
|
@@ -503,6 +503,187 @@ const cuePreset = {
|
|
|
503
503
|
return breaks;
|
|
504
504
|
}
|
|
505
505
|
};
|
|
506
|
+
// src/rules/main-check.ts
|
|
507
|
+
/**
|
|
508
|
+
* The rule `main-check`: a script does not find out that it is the main module by a compare of `process.argv[1]` with
|
|
509
|
+
* its own path. Through a link (a junction, a symbolic link, `~/git` to `D:/git`), the two paths differ. Then the
|
|
510
|
+
* script does nothing, and it ends with exit code 0.
|
|
511
|
+
*/
|
|
512
|
+
/** The extensions of the files that the rule reads. */
|
|
513
|
+
const SCRIPT = /* @__PURE__ */ new Set([
|
|
514
|
+
".ts",
|
|
515
|
+
".mts",
|
|
516
|
+
".cts",
|
|
517
|
+
".js",
|
|
518
|
+
".mjs"
|
|
519
|
+
]);
|
|
520
|
+
/** The largest file that the rule reads, in bytes. */
|
|
521
|
+
const MAX_BYTES$1 = 1048576;
|
|
522
|
+
/** The compare of two real paths. It is true through a link too, and it works on each Node version. */
|
|
523
|
+
const REAL_COMPARE = "process.argv[1] !== undefined && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))";
|
|
524
|
+
/** The imports that the compare of two real paths uses. */
|
|
525
|
+
const REAL_IMPORTS = [["realpathSync", "node:fs"], ["fileURLToPath", "node:url"]];
|
|
526
|
+
/** The names of the imports that only a path compare uses. The fix removes the ones that become unused. */
|
|
527
|
+
const PATH_NAMES = [
|
|
528
|
+
"fileURLToPath",
|
|
529
|
+
"pathToFileURL",
|
|
530
|
+
"resolve",
|
|
531
|
+
"realpathSync"
|
|
532
|
+
];
|
|
533
|
+
/** This function tells if a text compares `process.argv[1]` with the path of the module, without a real path of each side. */
|
|
534
|
+
function isPathCompare(text) {
|
|
535
|
+
if (!text.includes("process.argv[1]") || !/import\.meta\.(url|filename|dirname)\b/.test(text)) return false;
|
|
536
|
+
if (!/[!=]=|\.(?:endsWith|startsWith|includes)\(/.test(text)) return false;
|
|
537
|
+
return (text.match(/realpathSync\s*\(/g) ?? []).length < 2;
|
|
538
|
+
}
|
|
539
|
+
/** The lowest version of a range of `engines.node` (for example `>=22.19` or `^24.2.0`). It is undefined when the range has no single lower bound. */
|
|
540
|
+
function lowestNode(range) {
|
|
541
|
+
if (typeof range !== "string" || range.includes("||")) return void 0;
|
|
542
|
+
const found = /^(?:>=|\^|~)?\s*v?(\d+)(?:\.(\d+))?/.exec(range.trim());
|
|
543
|
+
return found ? [Number(found[1]), Number(found[2] ?? 0)] : void 0;
|
|
544
|
+
}
|
|
545
|
+
/** This function tells if each Node version of the range has `import.meta.main`: 22.18 and later in 22, and 24.2 and later. Node 23 does not have it. */
|
|
546
|
+
function hasImportMetaMain(range) {
|
|
547
|
+
const lowest = lowestNode(range);
|
|
548
|
+
if (lowest === void 0) return false;
|
|
549
|
+
const [major, minor] = lowest;
|
|
550
|
+
if (major === 22) return minor >= 18 && typeof range === "string" && /^[\^~]/.test(range.trim());
|
|
551
|
+
return major > 24 || major === 24 && minor >= 2;
|
|
552
|
+
}
|
|
553
|
+
/** This function gives the line with `condition` in place of the condition of its `if (...)`. It gives undefined when no `if` has only the main check. */
|
|
554
|
+
function fixLine(line, condition) {
|
|
555
|
+
const start = line.indexOf("if (");
|
|
556
|
+
if (start < 0) return void 0;
|
|
557
|
+
let depth = 0;
|
|
558
|
+
let end = -1;
|
|
559
|
+
for (let index = start + 3; index < line.length; index++) {
|
|
560
|
+
if (line[index] === "(") depth++;
|
|
561
|
+
if (line[index] === ")" && --depth === 0) {
|
|
562
|
+
end = index;
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (end < 0) return void 0;
|
|
567
|
+
const old = line.slice(start + 4, end);
|
|
568
|
+
if (!old.split("&&").every((part) => part.includes("process.argv[1]")) || !isPathCompare(old)) return void 0;
|
|
569
|
+
return `${line.slice(0, start)}if (${condition})${line.slice(end + 1)}`;
|
|
570
|
+
}
|
|
571
|
+
/** The import line of `module` with named imports, as `[index, prefix, names, suffix]`. */
|
|
572
|
+
function namedImport(lines, module) {
|
|
573
|
+
const pattern = new RegExp(`^(\\s*import\\s*\\{)([^}]*)(\\}\\s*from\\s*["']${module}["'];?\\s*)$`);
|
|
574
|
+
for (let index = 0; index < lines.length; index++) {
|
|
575
|
+
const found = pattern.exec(lines[index] ?? "");
|
|
576
|
+
if (found) return [
|
|
577
|
+
index,
|
|
578
|
+
found[1] ?? "",
|
|
579
|
+
(found[2] ?? "").split(",").map((part) => part.trim()).filter((part) => part !== ""),
|
|
580
|
+
found[3] ?? ""
|
|
581
|
+
];
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const importLine = (prefix, names, suffix) => `${prefix.trimEnd()} ${names.join(", ")} ${suffix.trimStart()}`;
|
|
585
|
+
/** The local name of an import part, for example `type A`, `A as B` or `A`. */
|
|
586
|
+
const imported = (part) => part.replace(/^type\s+/, "").split(/\s+as\s+/)[0] ?? "";
|
|
587
|
+
/** This function adds the imports in `needs` that the text does not have. Then it removes the named imports of PATH_NAMES that the text does not use. */
|
|
588
|
+
function fixImports(text, needs) {
|
|
589
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
590
|
+
let lines = text.split(/\r?\n/);
|
|
591
|
+
const isImport = (line) => /^\s*import\b/.test(line);
|
|
592
|
+
for (const [name, module] of needs) {
|
|
593
|
+
if (lines.some((line) => isImport(line) && new RegExp(`\\b${name}\\b`).test(line))) continue;
|
|
594
|
+
const found = namedImport(lines, module) ?? namedImport(lines, module.replace(/^node:/, ""));
|
|
595
|
+
if (found) {
|
|
596
|
+
lines = lines.map((line, index) => index === found[0] ? importLine(found[1], [...found[2], name], found[3]) : line);
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
let last = -1;
|
|
600
|
+
lines.forEach((line, index) => {
|
|
601
|
+
if (isImport(line) && /from\s*["'][^"']+["'];?\s*$/.test(line)) last = index;
|
|
602
|
+
});
|
|
603
|
+
const at = last >= 0 ? last + 1 : lines[0]?.startsWith("#!") ? 1 : 0;
|
|
604
|
+
const style = lines.find((line) => isImport(line) && /from\s*["']/.test(line)) ?? "";
|
|
605
|
+
const quote = /from\s*'/.test(style) ? "'" : "\"";
|
|
606
|
+
const semi = style === "" || /;\s*$/.test(style) ? ";" : "";
|
|
607
|
+
lines = [
|
|
608
|
+
...lines.slice(0, at),
|
|
609
|
+
`import { ${name} } from ${quote}${module}${quote}${semi}`,
|
|
610
|
+
...lines.slice(at)
|
|
611
|
+
];
|
|
612
|
+
}
|
|
613
|
+
for (const name of PATH_NAMES) {
|
|
614
|
+
if (lines.some((line) => !isImport(line) && new RegExp(`\\b${name}\\b`).test(line))) continue;
|
|
615
|
+
for (const module of [
|
|
616
|
+
"node:url",
|
|
617
|
+
"node:path",
|
|
618
|
+
"node:fs",
|
|
619
|
+
"url",
|
|
620
|
+
"path",
|
|
621
|
+
"fs"
|
|
622
|
+
]) {
|
|
623
|
+
const found = namedImport(lines, module);
|
|
624
|
+
if (!found || !found[2].some((part) => imported(part) === name)) continue;
|
|
625
|
+
const kept = found[2].filter((part) => imported(part) !== name);
|
|
626
|
+
lines = kept.length === 0 ? lines.filter((_, index) => index !== found[0]) : lines.map((line, index) => index === found[0] ? importLine(found[1], kept, found[3]) : line);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return lines.join(eol);
|
|
630
|
+
}
|
|
631
|
+
const mainCheck = {
|
|
632
|
+
id: "main-check",
|
|
633
|
+
title: "A script finds out that it is the main module with `import.meta.main`, or with a real path of each side, not by a compare of `process.argv[1]` with its path.",
|
|
634
|
+
reason: "Through a link, `process.argv[1]` has the path of the link, and the module has the real path. The compare is false, so the script does nothing and ends with exit code 0: a check that looks done but did not start.",
|
|
635
|
+
fix: "Write `if (import.meta.main)` when `engines.node` allows only versions that have it (`^22.18`, `>=24.2`). Else compare `realpathSync(process.argv[1])` with `realpathSync(fileURLToPath(import.meta.url))`. `conventions fix` writes the one that fits.",
|
|
636
|
+
sources: [{
|
|
637
|
+
repo: "fleet",
|
|
638
|
+
rule: "main-check",
|
|
639
|
+
doc: "docs/STRATEGY.md (2026-11-02, the main check through a link)"
|
|
640
|
+
}],
|
|
641
|
+
options: {},
|
|
642
|
+
check(context) {
|
|
643
|
+
const files = context.gitFiles();
|
|
644
|
+
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
645
|
+
const packages = [...codePackages(context), context.rootPackage].sort((a, b) => b.folder.length - a.folder.length);
|
|
646
|
+
const breaks = [];
|
|
647
|
+
for (const file of files) {
|
|
648
|
+
if (!SCRIPT.has(extname(file).toLowerCase()) || /(^|\/)(node_modules|dist)\//.test(file)) continue;
|
|
649
|
+
const path = join(context.root, file);
|
|
650
|
+
let text;
|
|
651
|
+
try {
|
|
652
|
+
if (statSync(path).size > MAX_BYTES$1) continue;
|
|
653
|
+
text = readFileSync(path, "utf8");
|
|
654
|
+
} catch {
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
if (!text.includes("process.argv[1]")) continue;
|
|
658
|
+
const engines = (packages.find((p) => p.folder === "" || file.startsWith(`${p.folder}/`))?.manifest)?.engines?.node;
|
|
659
|
+
const main = hasImportMetaMain(engines);
|
|
660
|
+
const lines = text.split(/\r?\n/);
|
|
661
|
+
for (let index = 0; index < lines.length; index++) {
|
|
662
|
+
const line = lines[index] ?? "";
|
|
663
|
+
const next = lines[index + 1] ?? "";
|
|
664
|
+
if (!(isPathCompare(line) || line.includes("process.argv[1]") && !/import\.meta/.test(line) && !isPathCompare(next) && isPathCompare(`${line} ${next}`))) continue;
|
|
665
|
+
const fixed = fixLine(line, main ? "import.meta.main" : REAL_COMPARE);
|
|
666
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
667
|
+
const after = fixed === void 0 ? void 0 : fixImports([
|
|
668
|
+
...lines.slice(0, index),
|
|
669
|
+
fixed,
|
|
670
|
+
...lines.slice(index + 1)
|
|
671
|
+
].join(eol), main ? [] : REAL_IMPORTS);
|
|
672
|
+
breaks.push({
|
|
673
|
+
file,
|
|
674
|
+
line: index + 1,
|
|
675
|
+
message: "The script compares process.argv[1] with its own path, which is false through a link.",
|
|
676
|
+
...after === void 0 ? { fix: "Change the condition by hand: it has more than the main check, or it is on more than one line." } : { edits: [{
|
|
677
|
+
file,
|
|
678
|
+
before: text,
|
|
679
|
+
after
|
|
680
|
+
}] }
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
return breaks;
|
|
685
|
+
}
|
|
686
|
+
};
|
|
506
687
|
// src/rules/no-build-output.ts
|
|
507
688
|
/**
|
|
508
689
|
* The rule `no-build-output`: git does not keep build output.
|
|
@@ -2968,6 +3149,7 @@ const RULES = [
|
|
|
2968
3149
|
releaseFiles,
|
|
2969
3150
|
typedScripts,
|
|
2970
3151
|
typedFiles,
|
|
3152
|
+
mainCheck,
|
|
2971
3153
|
testsRequired,
|
|
2972
3154
|
roadmapParses,
|
|
2973
3155
|
runnerBudget
|
|
@@ -3324,6 +3506,6 @@ function runCli(args, io) {
|
|
|
3324
3506
|
if (summary) appendFileSync(summary, summaryMarkdown(result));
|
|
3325
3507
|
return result.failed ? 1 : 0;
|
|
3326
3508
|
}
|
|
3327
|
-
export {
|
|
3509
|
+
export { parseJsonc as $, roadmapParses as A, REAL_COMPARE as B, isSourcePath as C, runnerBudget as D, repositoryOfRemote as E, pinnedGitDeps as F, DEPENDENCY_FIELDS as G, mainCheck as H, DEFAULT_ALLOWED as I, hasFile as J, cleanPath as K, HOME_PATTERNS as L, releaseFiles as M, isGitSpecifier as N, scheduleMinute as O, isPinned as P, matchesAny as Q, noLocalPaths as R, tsconfigTest as S, sourceMain as T, STRICT_OPTIONS as U, hasImportMetaMain as V, cuePreset as W, keyLine as X, inFolder as Y, lineOf as Z, configsOfScript as _, listRules as a, globToRegExp as at, testsRequired as b, runCli as c, defaultOptions as ct, RULES as d, readJsonc as et, workspaceProtocol as f, typedScripts as g, trustPolicy as h, formatResult as i, globFolders as it, requiredScripts as j, roadmapOfLine as k, runFix as l, parseConfig as lt, TRAIN_SCOPES as m, annotations as n, runGit as nt, readConfig as o, packageFolders as ot, IGNORE_AFTER as p, codePackages as q, createContext as r, specifiersOf as rt, runChecks as s, workspaceGlobs as st, USAGE as t, replaceLine as tt, summaryMarkdown as u, scriptsOf as v, pathsOf as w, hasTests as x, typedFiles as y, noBuildOutput as z };
|
|
3328
3510
|
|
|
3329
|
-
//# sourceMappingURL=run-
|
|
3511
|
+
//# sourceMappingURL=run-c3bySjnK.js.map
|