@antelopejs/tooling-configs 0.2.16 → 0.2.18

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.
Files changed (51) hide show
  1. package/README.md +101 -52
  2. package/dist/bin/api-diff.mjs +430 -107
  3. package/dist/bin/body-check.d.mts +1 -0
  4. package/dist/bin/body-check.mjs +344 -0
  5. package/dist/bin/capture.d.mts +1 -0
  6. package/dist/bin/capture.mjs +559 -0
  7. package/dist/bin/check-size.mjs +3 -3
  8. package/dist/bin/checks.mjs +3 -3
  9. package/dist/bin/comment-proof.mjs +4 -3
  10. package/dist/bin/garden.mjs +6 -6
  11. package/dist/bin/ratchet.mjs +316 -10
  12. package/dist/bin/suppressions.mjs +118 -80
  13. package/dist/bin/sync.mjs +554 -153
  14. package/dist/bin/verify.mjs +240 -127
  15. package/dist/capture/index.d.mts +50 -0
  16. package/dist/capture/index.mjs +2 -0
  17. package/dist/{ceilings-BSw9p4YB.mjs → ceilings-B7KayYIG.mjs} +11 -3
  18. package/dist/{checks-BlWDFYio.mjs → checks-CxkSu2E6.mjs} +1 -1
  19. package/dist/{ci-workflow-DIsoEgMd.mjs → ci-workflow-ChW4He0r.mjs} +84 -3
  20. package/dist/{files-2FikHZ9F.mjs → files-DJ0TeaTU.mjs} +11 -5
  21. package/dist/formal/index.d.mts +40 -0
  22. package/dist/formal/index.mjs +205 -0
  23. package/dist/{json-BqvuCkqr.mjs → json-CG2L7YFl.mjs} +12 -8
  24. package/dist/oxc/anti-slop/index.mjs +869 -21
  25. package/dist/oxc/fmt.mjs +1 -1
  26. package/dist/oxc/guardrails/index.d.mts +1 -1
  27. package/dist/oxc/guardrails/index.mjs +736 -4
  28. package/dist/oxc/lint.d.mts +20 -3
  29. package/dist/oxc/lint.mjs +34 -10
  30. package/dist/oxlint-DIV-lLSS.mjs +98 -0
  31. package/dist/{package-Dtjt_lSa.mjs → package-BRTjkzt5.mjs} +29 -3
  32. package/dist/proof-stamp-DDDC0J6l.mjs +279 -0
  33. package/dist/ratchet-BAcLRYuM.mjs +448 -0
  34. package/dist/{renames-BGO4dWJ8.mjs → renames-L2owF5GD.mjs} +2 -2
  35. package/dist/scenes-DZVXkcxS.mjs +104 -0
  36. package/dist/shared-igPpEDpS.mjs +622 -0
  37. package/dist/{size-BVgNbLO6.mjs → size-DBatLT-F.mjs} +4 -4
  38. package/dist/suppression-base-9L8dlMQK.mjs +120 -0
  39. package/dist/suppression-budget-C0SkPO5R.mjs +535 -0
  40. package/dist/{suppressions-BJAngUxo.mjs → suppressions-DM60NkvL.mjs} +180 -18
  41. package/dist/templates-CypDm-j9.mjs +121 -0
  42. package/dist/typescript-CM0LrVP7.mjs +222 -0
  43. package/dist/verify/index.d.mts +6 -1
  44. package/dist/verify/index.mjs +1 -1
  45. package/package.json +31 -5
  46. package/dist/kinds-Bzyyi9yk.mjs +0 -25
  47. package/dist/ratchet-DRdIYwmv.mjs +0 -80
  48. package/dist/shared-CsXIMK3I.mjs +0 -34
  49. package/dist/staged-ratchet-CjoRfZaM.mjs +0 -236
  50. package/dist/suppression-budget-Yyf5_J5l.mjs +0 -283
  51. package/dist/typescript-C54ONh9m.mjs +0 -433
@@ -1,9 +1,155 @@
1
1
  import { n as markerPattern, t as DEFAULT_SAFETY_MARKERS } from "./require-safety-comment-for-type-assertion-BBQ669kj.mjs";
2
- import { i as gitFiles, r as generatedOutput } from "./files-2FikHZ9F.mjs";
2
+ import { a as gitFiles, i as generatedOutput } from "./files-DJ0TeaTU.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { existsSync, lstatSync, readFileSync } from "node:fs";
5
5
  import { join } from "node:path";
6
6
  import { execFileSync } from "node:child_process";
7
+ //#region src/guardrails/parser.ts
8
+ let compiler;
9
+ /** This package's own TypeScript 5, loaded on first use, so the count never depends on the compiler a repository installs (TypeScript 7 has no parser API). */
10
+ function typescript() {
11
+ compiler ??= createRequire(import.meta.url)("typescript");
12
+ return compiler;
13
+ }
14
+ //#endregion
15
+ //#region src/guardrails/config-suppressions.ts
16
+ /** The lint configs a repository writes, at any depth: `oxlint.config.*`, `.oxlintrc.json`, `.oxlintrc.jsonc` and `eslint.config.*`. */
17
+ const LINT_CONFIG_FILE = /(?:^|\/)(?:(?:oxlint|eslint)\.config\.[cm]?[jt]s|\.oxlintrc\.jsonc?)$/u;
18
+ const WEAK_SEVERITIES = /* @__PURE__ */ new Set([
19
+ "off",
20
+ "allow",
21
+ "warn"
22
+ ]);
23
+ const WEAK_LEVELS = /* @__PURE__ */ new Set(["0", "1"]);
24
+ function unwrapped(node) {
25
+ const compiler = typescript();
26
+ let current = node;
27
+ while (compiler.isParenthesizedExpression(current) || compiler.isAsExpression(current) || compiler.isSatisfiesExpression(current) || compiler.isTypeAssertionExpression(current) || compiler.isNonNullExpression(current)) current = current.expression;
28
+ return current;
29
+ }
30
+ /** The expression `node` stands for: itself, or the initializer of the same-file variable it names. */
31
+ function resolved(node, declarations, seen = /* @__PURE__ */ new Set()) {
32
+ const compiler = typescript();
33
+ const value = unwrapped(node);
34
+ if (!compiler.isIdentifier(value) || seen.has(value.text)) return value;
35
+ const initializer = declarations.get(value.text);
36
+ if (initializer === void 0) return value;
37
+ seen.add(value.text);
38
+ return resolved(initializer, declarations, seen);
39
+ }
40
+ function propertyName(name) {
41
+ const compiler = typescript();
42
+ return compiler.isIdentifier(name) || compiler.isStringLiteralLike(name) || compiler.isNumericLiteral(name) ? name.text : void 0;
43
+ }
44
+ function weakens(node, declarations) {
45
+ const compiler = typescript();
46
+ const value = resolved(node, declarations);
47
+ if (compiler.isStringLiteralLike(value)) return WEAK_SEVERITIES.has(value.text);
48
+ if (compiler.isNumericLiteral(value)) return WEAK_LEVELS.has(value.text);
49
+ if (compiler.isArrayLiteralExpression(value)) {
50
+ const [severity] = value.elements;
51
+ return severity !== void 0 && weakens(severity, declarations);
52
+ }
53
+ return false;
54
+ }
55
+ /** The entries of a rule map that weaken their rule, spreads of same-file maps included. */
56
+ function weakEntries(node, declarations, source, depth = 0) {
57
+ const compiler = typescript();
58
+ const value = resolved(node, declarations);
59
+ if (!compiler.isObjectLiteralExpression(value) || depth > 8) return [];
60
+ return value.properties.flatMap((property) => {
61
+ if (compiler.isSpreadAssignment(property)) return weakEntries(property.expression, declarations, source, depth + 1);
62
+ if (!compiler.isPropertyAssignment(property)) return [];
63
+ const name = propertyName(property.name);
64
+ if (name === void 0 || !weakens(property.initializer, declarations)) return [];
65
+ const start = property.getStart(source);
66
+ return [{
67
+ name,
68
+ line: source.getLineAndCharacterOfPosition(start).line + 1
69
+ }];
70
+ });
71
+ }
72
+ /** The globs of a `files` value, each spread of a same-file array expanded; anything else counts as one scope. */
73
+ function globs(node, declarations, source) {
74
+ const compiler = typescript();
75
+ const value = resolved(node, declarations);
76
+ if (compiler.isStringLiteralLike(value)) return [value.text];
77
+ if (!compiler.isArrayLiteralExpression(value)) return [value.getText(source)];
78
+ return value.elements.flatMap((element) => globs(compiler.isSpreadElement(element) ? element.expression : element, declarations, source));
79
+ }
80
+ function member(object, key) {
81
+ const compiler = typescript();
82
+ for (const property of object.properties) {
83
+ if (compiler.isPropertyAssignment(property) && propertyName(property.name) === key) return property.initializer;
84
+ if (compiler.isShorthandPropertyAssignment(property) && property.name.text === key) return property.name;
85
+ }
86
+ }
87
+ function sourceOf(file, text) {
88
+ const compiler = typescript();
89
+ if (/\.jsonc?$/u.test(file)) return compiler.parseJsonText(file, text);
90
+ return compiler.createSourceFile(file, text, compiler.ScriptTarget.Latest, false, /\.[cm]?ts$/u.test(file) ? compiler.ScriptKind.TS : compiler.ScriptKind.JS);
91
+ }
92
+ function declarationsIn(source) {
93
+ const compiler = typescript();
94
+ const declarations = /* @__PURE__ */ new Map();
95
+ const visit = (node) => {
96
+ if (compiler.isVariableDeclaration(node) && compiler.isIdentifier(node.name) && node.initializer !== void 0) declarations.set(node.name.text, node.initializer);
97
+ compiler.forEachChild(node, visit);
98
+ };
99
+ visit(source);
100
+ return declarations;
101
+ }
102
+ /**
103
+ * A glob of the config in `directory` as a path from the repository root;
104
+ * the whole directory when `glob` is undefined. Root globs stay as written,
105
+ * and a root block without `files` is `*`.
106
+ */
107
+ function anchored(directory, glob) {
108
+ if (glob === void 0) return directory === "" ? "*" : `${directory}/**`;
109
+ if (directory === "") return glob;
110
+ const negated = glob.startsWith("!");
111
+ const path = (negated ? glob.slice(1) : glob).replace(/^(?:\.\/|\/)+/u, "");
112
+ return `${negated ? "!" : ""}${directory}/${path}`;
113
+ }
114
+ /**
115
+ * Each rule and category a lint config file switches off, to `allow` or to
116
+ * a warning: in every object's `rules` and `categories`, and in the argument
117
+ * of an ESLint composer's `overrideRules`, once per glob of the object's
118
+ * `files`, each glob anchored at the config's directory so a scope never
119
+ * reaches past it. Rule maps and globs held in same-file variables or spread from
120
+ * them count where they are used; configs the pack's presets return are
121
+ * not in the file, so they never count.
122
+ */
123
+ function configRuleOffs(file, text) {
124
+ if (!LINT_CONFIG_FILE.test(file)) return [];
125
+ const compiler = typescript();
126
+ const source = sourceOf(file, text);
127
+ const declarations = declarationsIn(source);
128
+ const directory = file.includes("/") ? file.slice(0, file.lastIndexOf("/")) : "";
129
+ const whole = [anchored(directory)];
130
+ const found = [];
131
+ const add = (map, scopes, prefix) => {
132
+ if (map === void 0) return;
133
+ for (const { name, line } of weakEntries(map, declarations, source)) for (const scope of scopes) found.push({
134
+ rule: `${prefix}${name}`,
135
+ scope,
136
+ line
137
+ });
138
+ };
139
+ const visit = (node) => {
140
+ if (compiler.isObjectLiteralExpression(node)) {
141
+ const files = member(node, "files");
142
+ const scopes = files === void 0 ? whole : globs(files, declarations, source).map((glob) => anchored(directory, glob));
143
+ add(member(node, "rules"), scopes, "");
144
+ add(member(node, "categories"), scopes, "category:");
145
+ }
146
+ if (compiler.isCallExpression(node) && compiler.isPropertyAccessExpression(node.expression) && node.expression.name.text === "overrideRules") add(node.arguments[0], whole, "");
147
+ compiler.forEachChild(node, visit);
148
+ };
149
+ visit(source);
150
+ return found;
151
+ }
152
+ //#endregion
7
153
  //#region src/guardrails/suppressions.ts
8
154
  const CODE_FILE = /\.(?:[cm]?[jt]sx?|vue)$/u;
9
155
  const CANDIDATE = /(?:oxlint|eslint)-disable|@ts-(?:expect-error|ignore)/u;
@@ -14,12 +160,6 @@ const SAFETY_COMMENT = markerPattern(DEFAULT_SAFETY_MARKERS);
14
160
  const TS_DIRECTIVE = /^[/*\s]*@ts-(expect-error|ignore)(?![\w-])/u;
15
161
  const SAFETY_REASON = /SAFETY\s*:([\s\S]*)$/u;
16
162
  const ENABLE_DIRECTIVE = /^((?:oxlint|eslint)-enable)(?=\s|$)([\s\S]*)$/u;
17
- let compiler;
18
- /** This package's own TypeScript 5, loaded on first use, so the count never depends on the compiler a repository installs (TypeScript 7 has no parser API). */
19
- function typescript() {
20
- compiler ??= createRequire(import.meta.url)("typescript");
21
- return compiler;
22
- }
23
163
  function scriptKind(lang) {
24
164
  const kinds = typescript().ScriptKind;
25
165
  if (/^[cm]?tsx$/u.test(lang)) return kinds.TSX;
@@ -114,10 +254,16 @@ function fileComments(file, text) {
114
254
  function lineOf(text, offset) {
115
255
  return text.slice(0, offset).split("\n").length;
116
256
  }
117
- /** The suppressions in one code file's text; `file` decides the language and labels each entry. */
257
+ /** The suppressions in one code file's or lint config's text; `file` decides the language and labels each entry. */
118
258
  function suppressionsIn(file, text) {
119
- if (!CODE_FILE.test(file) || !(CANDIDATE.test(text) || SAFETY_COMMENT.test(text))) return [];
120
- const found = [];
259
+ const found = configRuleOffs(file, text).map(({ rule, scope, line }) => ({
260
+ kind: "config",
261
+ rule,
262
+ scope,
263
+ file,
264
+ line
265
+ }));
266
+ if (!CODE_FILE.test(file) || !(CANDIDATE.test(text) || SAFETY_COMMENT.test(text))) return found;
121
267
  for (const comment of fileComments(file, text)) {
122
268
  const line = lineOf(text, comment.start);
123
269
  for (const { directive, rule, reason } of lintDirective(comment.value)) found.push({
@@ -189,9 +335,9 @@ function generatedIn(root) {
189
335
  }
190
336
  function authoredCode(root, files) {
191
337
  const generated = generatedIn(root);
192
- return files.filter((file) => CODE_FILE.test(file) && !generated(file));
338
+ return files.filter((file) => (CODE_FILE.test(file) || LINT_CONFIG_FILE.test(file)) && !generated(file));
193
339
  }
194
- /** What `read` finds in the working tree's authored code files: tracked and untracked, ignored files and generated output left out. */
340
+ /** What `read` finds in the working tree's authored code files and lint configs: tracked and untracked, ignored files and generated output left out. */
195
341
  function inWorktree(root, read, files = gitFiles(root)) {
196
342
  return authoredCode(root, files).flatMap((file) => {
197
343
  const path = join(root, file);
@@ -253,7 +399,15 @@ function atRevision(root, revision, read, files) {
253
399
  function revisionSuppressions(root, revision, files) {
254
400
  return atRevision(root, revision, suppressionsIn, files);
255
401
  }
256
- /** Totals by budget key, rules sorted by id. */
402
+ /** The budget key of a config rule-off: its rule and the glob it is switched off for, so a wider or moved scope is a new key at ceiling 0. */
403
+ function configKey(rule, scope) {
404
+ return `${rule} for ${scope}`;
405
+ }
406
+ /** A count map with its keys sorted, so serialising it is stable. */
407
+ function sortedKeys(counts) {
408
+ return Object.fromEntries(Object.entries(counts).sort(([a], [b]) => a.localeCompare(b)));
409
+ }
410
+ /** Totals by budget key, rules and config rule-offs sorted by id. */
257
411
  function countSuppressions(suppressions) {
258
412
  const counts = {
259
413
  rules: {},
@@ -261,10 +415,18 @@ function countSuppressions(suppressions) {
261
415
  tsIgnore: 0,
262
416
  safety: 0
263
417
  };
264
- for (const suppression of suppressions) if (suppression.kind === "rule") counts.rules[suppression.rule] = (counts.rules[suppression.rule] ?? 0) + 1;
265
- else counts[suppression.kind]++;
266
- counts.rules = Object.fromEntries(Object.entries(counts.rules).sort(([a], [b]) => a.localeCompare(b)));
267
- return counts;
418
+ const rules = /* @__PURE__ */ new Map();
419
+ const config = /* @__PURE__ */ new Map();
420
+ for (const suppression of suppressions) if (suppression.kind === "rule") rules.set(suppression.rule, (rules.get(suppression.rule) ?? 0) + 1);
421
+ else if (suppression.kind === "config") {
422
+ const key = configKey(suppression.rule, suppression.scope);
423
+ config.set(key, (config.get(key) ?? 0) + 1);
424
+ } else counts[suppression.kind]++;
425
+ return {
426
+ ...counts,
427
+ rules: sortedKeys(Object.fromEntries(rules)),
428
+ config: sortedKeys(Object.fromEntries(config))
429
+ };
268
430
  }
269
431
  //#endregion
270
- export { revisionSuppressions as a, openDisablesIn as i, countSuppressions as n, worktreeSuppressions as o, inWorktree as r, atRevision as t };
432
+ export { openDisablesIn as a, suppressionsIn as c, inWorktree as i, worktreeSuppressions as l, configKey as n, revisionSuppressions as o, countSuppressions as r, sortedKeys as s, atRevision as t };
@@ -0,0 +1,121 @@
1
+ import { t as execCommand } from "./package-BRTjkzt5.mjs";
2
+ import { isMap, parseDocument } from "yaml";
3
+ //#region src/guardrails/templates.ts
4
+ const PRESET_CONFIGS = [
5
+ {
6
+ path: "oxlint.config.ts",
7
+ legacy: [".oxlintrc.json"],
8
+ specifier: "@antelopejs/tooling-configs/oxc/lint",
9
+ content: "import { defineConfig } from \"oxlint\";\nimport {\n ANTELOPE_IGNORE_PATTERNS,\n antelopePreset,\n} from \"@antelopejs/tooling-configs/oxc/lint\";\n\nexport default defineConfig({\n extends: [antelopePreset()],\n ignorePatterns: ANTELOPE_IGNORE_PATTERNS,\n options: { typeAware: true },\n});\n",
10
+ previous: ["import { defineConfig } from \"oxlint\";\nimport { antelopePreset } from \"@antelopejs/tooling-configs/oxc/lint\";\n\nexport default defineConfig({\n extends: [antelopePreset()],\n options: { typeAware: true },\n});\n"]
11
+ },
12
+ {
13
+ path: "oxfmt.config.ts",
14
+ legacy: [".oxfmtrc.json"],
15
+ specifier: "@antelopejs/tooling-configs/oxc/fmt",
16
+ content: "import { antelopeFmtPreset } from \"@antelopejs/tooling-configs/oxc/fmt\";\n\nexport default antelopeFmtPreset();\n"
17
+ },
18
+ {
19
+ path: "knip.config.ts",
20
+ legacy: [
21
+ "knip.json",
22
+ "knip.jsonc",
23
+ ".knip.json"
24
+ ],
25
+ specifier: "@antelopejs/tooling-configs/knip",
26
+ content: "import { antelopeKnipConfig } from \"@antelopejs/tooling-configs/knip\";\n\nexport default antelopeKnipConfig();\n"
27
+ }
28
+ ];
29
+ function presetConfig(current, preset, tools) {
30
+ const target = tools.presets[preset.path];
31
+ const specifier = target.replaceAll("/", "\\/").replaceAll(".", "\\.");
32
+ const imported = new RegExp(`(?:\\bfrom\\s*|\\bimport\\s*\\(?\\s*)["']${specifier}["']`);
33
+ const fresh = preset.content.replace(preset.specifier, target);
34
+ if (current === void 0 || preset.previous?.some((previous) => previous.replace(preset.specifier, target) === current)) return fresh;
35
+ if (imported.test(current)) return current;
36
+ const importLine = preset.content.split("\n").filter((line) => line.includes(preset.specifier)).join("\n").replace(preset.specifier, target);
37
+ throw new Error(`${preset.path} does not import its preset. Add \`${importLine}\` and extend that preset, then rerun antelopejs-sync. The file was not replaced.`);
38
+ }
39
+ function lefthook(current, manager, tools, ratchet = true) {
40
+ const exec = execCommand(manager);
41
+ const document = parseDocument(current ?? "{}\n");
42
+ if (document.errors.length) throw new Error(`lefthook.yml: ${document.errors.map(({ message }) => message).join("; ")}`);
43
+ if (!isMap(document.contents)) throw new Error("lefthook.yml must contain a YAML mapping. Merge the guardrail hooks manually and rerun antelopejs-sync.");
44
+ if (current === void 0) document.contents.flow = false;
45
+ const glob = "*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,vue}";
46
+ const hooks = {
47
+ "pre-commit": {
48
+ "antelopejs-format": {
49
+ run: `${exec} oxfmt --no-error-on-unmatched-pattern {staged_files}`,
50
+ stage_fixed: true
51
+ },
52
+ "antelopejs-lint": {
53
+ glob,
54
+ run: `${exec} oxlint --no-error-on-unmatched-pattern {staged_files}`
55
+ },
56
+ "antelopejs-size": { run: `${tools.hookPrefix}${tools.commands.size} --staged {staged_files}` },
57
+ "antelopejs-ratchet": {
58
+ glob,
59
+ run: `${tools.hookPrefix}${tools.commands.ratchet} --staged {staged_files}`
60
+ },
61
+ "antelopejs-suppressions": {
62
+ glob,
63
+ run: `${tools.hookPrefix}${tools.commands.suppressions} --staged`
64
+ }
65
+ },
66
+ "pre-push": { "antelopejs-typecheck": { run: `${manager} run typecheck` } }
67
+ };
68
+ for (const [hook, commands] of Object.entries(hooks)) {
69
+ for (const path of [[hook], [hook, "commands"]]) {
70
+ if (!document.hasIn(path)) document.setIn(path, document.createNode({}));
71
+ if (!isMap(document.getIn(path))) throw new Error(`lefthook.yml: ${path.join(".")} must be a mapping. Preserve the existing hook and merge its commands before rerunning antelopejs-sync.`);
72
+ }
73
+ for (const [key, command] of Object.entries(commands)) document.setIn([
74
+ hook,
75
+ "commands",
76
+ key
77
+ ], document.createNode(command));
78
+ }
79
+ if (!ratchet) document.deleteIn([
80
+ "pre-commit",
81
+ "commands",
82
+ "antelopejs-ratchet"
83
+ ]);
84
+ return document.toString({ lineWidth: 0 });
85
+ }
86
+ const SETUP_SCRIPT = `#!/usr/bin/env bash
87
+ set -euo pipefail
88
+ cd "$(dirname "$BASH_SOURCE")/.."
89
+ export CI=1 COREPACK_ENABLE_DOWNLOAD_PROMPT=0
90
+ major="$(tr -d 'v[:space:]' < .nvmrc)"
91
+ if [[ "$(node -p 'process.versions.node.split(".")[0]')" != "$major" ]]; then
92
+ if command -v fnm >/dev/null 2>&1; then
93
+ eval "$(fnm env --shell bash)"
94
+ fnm install "$major"
95
+ fnm use "$major"
96
+ else
97
+ export NVM_DIR="\${NVM_DIR:-$HOME/.nvm}"
98
+ if [[ ! -s "$NVM_DIR/nvm.sh" ]]; then
99
+ git clone --quiet --depth 1 --branch v0.40.3 https://github.com/nvm-sh/nvm.git "$NVM_DIR"
100
+ fi
101
+ source "$NVM_DIR/nvm.sh" --no-use
102
+ nvm install "$major"
103
+ nvm use "$major"
104
+ fi
105
+ fi
106
+ pin="$(node -p 'JSON.parse(require("node:fs").readFileSync("package.json", "utf8")).packageManager || "pnpm"')"
107
+ manager="\${pin%%@*}"
108
+ corepack enable
109
+ if [[ "$pin" == *@* ]]; then
110
+ corepack prepare "$pin" --activate
111
+ fi
112
+ case "$manager" in
113
+ pnpm) pnpm install --frozen-lockfile ;;
114
+ yarn) YARN_ENABLE_IMMUTABLE_INSTALLS=true yarn install --frozen-lockfile ;;
115
+ npm) npm ci ;;
116
+ bun) bun install --frozen-lockfile ;;
117
+ *) printf 'Unsupported package manager %s\\n' "$manager" >&2; exit 1 ;;
118
+ esac
119
+ `;
120
+ //#endregion
121
+ export { presetConfig as i, SETUP_SCRIPT as n, lefthook as r, PRESET_CONFIGS as t };
@@ -0,0 +1,222 @@
1
+ import { i as parseManifest } from "./package-BRTjkzt5.mjs";
2
+ import { u as trackedManifests } from "./files-DJ0TeaTU.mjs";
3
+ import { createRequire } from "node:module";
4
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
+ import { dirname, join, matchesGlob, relative, resolve, sep } from "node:path";
6
+ //#region src/guardrails/declared-typescript.ts
7
+ const DEPENDENCY_FIELDS = [
8
+ "dependencies",
9
+ "devDependencies",
10
+ "peerDependencies",
11
+ "optionalDependencies"
12
+ ];
13
+ function readManifest(directory) {
14
+ const file = join(directory, "package.json");
15
+ return existsSync(file) ? parseManifest(readFileSync(file, "utf8")) : void 0;
16
+ }
17
+ function declares(manifest) {
18
+ return DEPENDENCY_FIELDS.some((field) => manifest?.[field]?.typescript !== void 0);
19
+ }
20
+ /** The nearest manifest at or above `directory` that configures a workspace, never leaving the repository that contains it. */
21
+ function workspaceManifest(directory) {
22
+ for (let current = directory;; current = dirname(current)) {
23
+ const manifest = readManifest(current);
24
+ if (manifest !== void 0 && (manifest.workspaces !== void 0 || existsSync(join(current, "pnpm-workspace.yaml")))) return manifest;
25
+ if (existsSync(join(current, ".git")) || dirname(current) === current) return void 0;
26
+ }
27
+ }
28
+ /** Whether the package at `directory`, or the workspace root above it, declares `typescript` as a dependency of any kind. */
29
+ function declaresTypeScript(directory) {
30
+ return declares(readManifest(directory)) || declares(workspaceManifest(directory));
31
+ }
32
+ /** The directory of the package relative to the repository that contains it, `.` for the repository root; the same for every revision of the repository. */
33
+ function repositoryDirectory(directory) {
34
+ for (let current = directory;; current = dirname(current)) if (existsSync(join(current, ".git")) || dirname(current) === current) return relative(current, directory).split("\\").join("/") || ".";
35
+ }
36
+ /** The package as an error names it: its `name` when it has one, and its directory. */
37
+ function describePackage(directory) {
38
+ const name = readManifest(directory)?.name;
39
+ const where = repositoryDirectory(directory);
40
+ return name === void 0 ? where : `${name} (${where})`;
41
+ }
42
+ //#endregion
43
+ //#region src/guardrails/typescript.ts
44
+ /** A package `exports` leaf: a path rather than a fallback list or a condition map. */
45
+ function isExportPath(target) {
46
+ return typeof target === "string";
47
+ }
48
+ /** A proof analyses only packages that publish something: not private, and declaring at least one of `exports`, `main`, `types`, `typings` or `typesVersions`. */
49
+ function unpublishedReason(manifest) {
50
+ if (manifest.private === true) return "private";
51
+ return [
52
+ manifest.exports,
53
+ manifest.main,
54
+ manifest.types,
55
+ manifest.typings,
56
+ manifest.typesVersions
57
+ ].some((field) => field != null) ? void 0 : "no exports, main or types";
58
+ }
59
+ function trackedPackages(root) {
60
+ return trackedManifests(root).flatMap((file) => {
61
+ const directory = dirname(file);
62
+ if (!existsSync(join(root, directory, "tsconfig.json"))) return [];
63
+ return [{
64
+ directory,
65
+ manifest: JSON.parse(readFileSync(join(root, file), "utf8"))
66
+ }];
67
+ });
68
+ }
69
+ function packagesAt(root, publishedOnly) {
70
+ return trackedPackages(root).filter(({ manifest }) => !publishedOnly || unpublishedReason(manifest) === void 0);
71
+ }
72
+ /** The packages a published-only proof leaves out, each with the reason, so a skip is reported rather than silent. */
73
+ function unpublishedAt(root) {
74
+ return trackedPackages(root).flatMap(({ directory, manifest }) => {
75
+ const reason = unpublishedReason(manifest);
76
+ return reason === void 0 ? [] : [{
77
+ directory,
78
+ reason
79
+ }];
80
+ });
81
+ }
82
+ function packageRoot(file) {
83
+ let directory = dirname(file);
84
+ while (!existsSync(join(directory, "package.json"))) {
85
+ const parent = dirname(directory);
86
+ if (parent === directory) return dirname(file);
87
+ directory = parent;
88
+ }
89
+ return directory;
90
+ }
91
+ function resolveTypeScript(directory) {
92
+ try {
93
+ return {
94
+ file: createRequire(join(directory, "package.json")).resolve("typescript"),
95
+ fallback: false
96
+ };
97
+ } catch (error) {
98
+ if (declaresTypeScript(directory)) throw new Error(`${describePackage(directory)} declares typescript but it cannot be resolved from the package directory, so the compiler it builds with is not available. Install dependencies (run pnpm install) and retry.`, { cause: error });
99
+ return {
100
+ file: createRequire(createRequire(import.meta.url).resolve("dts-bundle-generator")).resolve("typescript"),
101
+ fallback: true
102
+ };
103
+ }
104
+ }
105
+ /** Loads the compiler a package builds with, including a package-local installation in a workspace. A package that declares `typescript` (itself or through its workspace root) but cannot resolve it is an error; only a package that declares none falls back to the one `dts-bundle-generator` brings, with a `notice`. A TypeScript without the programmatic API (7 and later) is an error rather than a crash. */
106
+ function loadTypeScript(directory) {
107
+ const { file, fallback } = resolveTypeScript(directory);
108
+ const compiler = createRequire(file)("typescript");
109
+ const root = packageRoot(file);
110
+ if (compiler.sys === void 0 || !("createProgram" in compiler)) throw new Error(`TypeScript ${compiler.version} at ${root} has no programmatic compiler API (sys, createProgram), so this package cannot be analysed. Build it with a TypeScript that has one, or mark the package private.`);
111
+ return {
112
+ compiler,
113
+ root,
114
+ notice: fallback ? `${repositoryDirectory(directory)}: declares no typescript; using the pack's TypeScript ${compiler.version}\n` : void 0
115
+ };
116
+ }
117
+ const TEST_SOURCE_GLOBS = [
118
+ "**/*.test.*",
119
+ "**/*.spec.*",
120
+ "**/__tests__/**",
121
+ "test/**",
122
+ "tests/**"
123
+ ];
124
+ function isTestSource(root, file) {
125
+ const path = relative(root, file).split("\\").join("/");
126
+ return TEST_SOURCE_GLOBS.some((pattern) => matchesGlob(path, pattern));
127
+ }
128
+ function failDiagnostics(compiler, diagnostics) {
129
+ const errors = diagnostics.filter((item) => item.category === compiler.DiagnosticCategory.Error);
130
+ if (errors.length) throw new Error(compiler.formatDiagnostics(errors, {
131
+ getCanonicalFileName: (file) => file,
132
+ getCurrentDirectory: () => process.cwd(),
133
+ getNewLine: () => "\n"
134
+ }));
135
+ }
136
+ /** Declaration inputs are part of the local closure but TypeScript does not emit copies of them. */
137
+ function copyDeclarations(program, directory, output) {
138
+ const sources = program.getSourceFiles().filter((source) => !program.isSourceFileDefaultLibrary(source) && !program.isSourceFileFromExternalLibrary(source) && !relative(directory, source.fileName).startsWith(`..${sep}`) && !isTestSource(directory, source.fileName));
139
+ const authored = sources.filter((source) => !source.isDeclarationFile);
140
+ let root = dirname((authored[0] ?? sources[0])?.fileName ?? join(directory, "index.ts"));
141
+ for (const source of authored.length ? authored : sources) while (relative(root, source.fileName).startsWith(`..${sep}`)) root = dirname(root);
142
+ root = program.getCompilerOptions().rootDir ?? root;
143
+ const files = [];
144
+ for (const source of sources) {
145
+ if (!source.isDeclarationFile) continue;
146
+ const path = relative(root, source.fileName);
147
+ if (path.startsWith(`..${sep}`)) continue;
148
+ const target = join(output, path);
149
+ mkdirSync(dirname(target), { recursive: true });
150
+ writeFileSync(target, source.text);
151
+ files.push(target);
152
+ }
153
+ return files;
154
+ }
155
+ function parseConfig(directory) {
156
+ const { compiler, root, notice } = loadTypeScript(directory);
157
+ const config = compiler.readConfigFile(join(directory, "tsconfig.json"), compiler.sys.readFile);
158
+ if (config.error) failDiagnostics(compiler, [config.error]);
159
+ const parsed = compiler.parseJsonConfigFileContent(config.config, compiler.sys, directory);
160
+ failDiagnostics(compiler, parsed.errors);
161
+ return {
162
+ compiler,
163
+ root,
164
+ notice,
165
+ parsed
166
+ };
167
+ }
168
+ /** The configured `outDir`, the root under which the declaration half already judges a built path as test output. */
169
+ function outputRoot(directory) {
170
+ return resolve(directory, parseConfig(directory).parsed.options.outDir ?? ".");
171
+ }
172
+ /** Emits with the package's compiler and config; test roots and outputs never enter either proof. `modules` maps each emitted file to its source module. */
173
+ function emitPackage(directory, output, declarations) {
174
+ const { compiler, root, notice, parsed } = parseConfig(directory);
175
+ const options = {
176
+ ...parsed.options,
177
+ rootDir: parsed.options.rootDir ?? (parsed.options.outDir ? void 0 : directory),
178
+ outDir: output,
179
+ declarationDir: declarations ? output : void 0,
180
+ declaration: declarations,
181
+ emitDeclarationOnly: declarations,
182
+ removeComments: true,
183
+ declarationMap: false,
184
+ sourceMap: false,
185
+ inlineSourceMap: false,
186
+ noEmit: false,
187
+ noEmitOnError: false,
188
+ composite: false,
189
+ incremental: false,
190
+ tsBuildInfoFile: void 0,
191
+ outFile: void 0,
192
+ allowImportingTsExtensions: declarations ? parsed.options.allowImportingTsExtensions : false
193
+ };
194
+ const program = compiler.createProgram({
195
+ rootNames: parsed.fileNames.filter((file) => !isTestSource(directory, file)),
196
+ options,
197
+ projectReferences: parsed.projectReferences
198
+ });
199
+ if (declarations) failDiagnostics(compiler, compiler.getPreEmitDiagnostics(program));
200
+ const files = [];
201
+ const modules = /* @__PURE__ */ new Map();
202
+ const result = program.emit(void 0, (file, text, _bom, _onError, sources) => {
203
+ if (sources?.some((source) => isTestSource(directory, source.fileName))) return;
204
+ if (declarations ? !/\.d\.[cm]?ts$/.test(file) : !/\.[cm]?jsx?$/.test(file)) return;
205
+ mkdirSync(dirname(file), { recursive: true });
206
+ writeFileSync(file, text);
207
+ files.push(file);
208
+ if (sources?.[0] !== void 0) modules.set(resolve(file), sources[0].fileName);
209
+ });
210
+ if (declarations) failDiagnostics(compiler, result.diagnostics);
211
+ if (declarations) files.push(...copyDeclarations(program, directory, output));
212
+ return {
213
+ compiler,
214
+ compilerRoot: root,
215
+ notice,
216
+ files,
217
+ modules,
218
+ options: parsed.options
219
+ };
220
+ }
221
+ //#endregion
222
+ export { outputRoot as a, loadTypeScript as i, isExportPath as n, packagesAt as o, isTestSource as r, unpublishedAt as s, emitPackage as t };
@@ -166,7 +166,12 @@ interface JourneyContext {
166
166
  expect(folder: string, checks: Check[], options?: {
167
167
  critical?: boolean;
168
168
  }): boolean;
169
- /** Ends the journey as not verified, for example when provider sandbox keys are missing. */
169
+ /**
170
+ * Ends the journey as not verified, for example when provider sandbox keys
171
+ * are missing or something the journey depends on outside the harness's
172
+ * services and apps stopped answering. An environment failure is never a
173
+ * failing check: `seeded` counts only failing checks as catches.
174
+ */
170
175
  notVerified(reason: string): never;
171
176
  service(name: string): ServiceEndpoint;
172
177
  /** Runs a command inside a service's container: the read-back through the native client. */
@@ -1,2 +1,2 @@
1
- import { a as exitIs, c as interrupted, i as exists, l as lacks, n as answers, o as fileHas, r as equal, s as has, t as answered, u as refused } from "../checks-BlWDFYio.mjs";
1
+ import { a as exitIs, c as interrupted, i as exists, l as lacks, n as answers, o as fileHas, r as equal, s as has, t as answered, u as refused } from "../checks-CxkSu2E6.mjs";
2
2
  export { answered, answers, equal, exists, exitIs, fileHas, has, interrupted, lacks, refused };