@antelopejs/tooling-configs 0.2.10 → 0.2.12
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 +21 -9
- package/dist/bin/api-diff.mjs +74 -41
- package/dist/bin/garden.mjs +13 -71
- package/dist/bin/ratchet.mjs +2 -2
- package/dist/bin/suppressions.mjs +33 -21
- package/dist/bin/sync.mjs +369 -24
- package/dist/bin/verify.d.mts +1 -0
- package/dist/bin/verify.mjs +3000 -0
- package/dist/checks-BlWDFYio.mjs +94 -0
- package/dist/json-BqvuCkqr.mjs +67 -0
- package/dist/kinds-Bzyyi9yk.mjs +25 -0
- package/dist/oxc/guardrails/index.mjs +119 -0
- package/dist/oxc/lint.d.mts +4 -0
- package/dist/oxc/lint.mjs +1 -0
- package/dist/{ratchet-B2qYUs51.mjs → ratchet-DRdIYwmv.mjs} +1 -1
- package/dist/staged-ratchet-CjoRfZaM.mjs +236 -0
- package/dist/{suppression-budget-Bq30tJDS.mjs → suppression-budget-Yyf5_J5l.mjs} +2 -1
- package/dist/verify/index.d.mts +262 -0
- package/dist/verify/index.mjs +2 -0
- package/package.json +5 -3
- package/dist/staged-ratchet-BNfjcbih.mjs +0 -119
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ The AntelopeJS guardrail pack: shared lint, format and dead-code presets, the co
|
|
|
25
25
|
| `./knip` | `import { antelopeKnipConfig } from "@antelopejs/tooling-configs/knip"` | Knip for AntelopeJS modules |
|
|
26
26
|
| `./oxc/anti-slop` | Loaded by the oxlint preset as a JS plugin | The vendored [anti-slop](https://github.com/dmmulroy/anti-slop) rules |
|
|
27
27
|
| `./oxc/guardrails` | Loaded by the oxlint preset as a JS plugin | The `antelopejs` comment and test-quality rules |
|
|
28
|
+
| `./verify` | `import type { VerifyConfig } from "@antelopejs/tooling-configs/verify"` | Types and check helpers for a shared verification skill's `verify.config.ts` |
|
|
28
29
|
| bin | `antelopejs-sync` | Writes the guardrail pack into a repository; `--check` reports drift |
|
|
29
30
|
| bin | `antelopejs-checks` | Runs every check and prints only the failures |
|
|
30
31
|
| bin | `antelopejs-ratchet` | Fails when recorded debt grows; `--update` lowers the record |
|
|
@@ -34,6 +35,7 @@ The AntelopeJS guardrail pack: shared lint, format and dead-code presets, the co
|
|
|
34
35
|
| bin | `antelopejs-comment-proof <base-ref>` | Compares comment-free JavaScript emit against committed HEAD |
|
|
35
36
|
| bin | `antelopejs-check-interface-ranges` | Fails on interface ranges that break module startup |
|
|
36
37
|
| bin | `antelopejs-garden [--json] [--apply-pauses]` | The Gardener's scans of the organization through the GitHub API and npm |
|
|
38
|
+
| bin | `antelopejs-verify <command>` | The harness of the shared `verify-interface`, `verify-module` and `verify-template` skills |
|
|
37
39
|
|
|
38
40
|
## antelopejs-garden
|
|
39
41
|
|
|
@@ -45,6 +47,12 @@ The AntelopeJS guardrail pack: shared lint, format and dead-code presets, the co
|
|
|
45
47
|
|
|
46
48
|
`antelopejs-sync` (full profile) writes the weekly mutation caller `.github/workflows/mutation.yml`, and both profiles keep the shared CI caller on the job id `ci`, so the check is reported as `ci / checks`.
|
|
47
49
|
|
|
50
|
+
## Shared verification skills
|
|
51
|
+
|
|
52
|
+
`antelopejs-sync` writes one shared verification skill into a repository: `verify-interface` for an interface, `verify-module` for an implementation module (inferred from `antelopeJs.implements`) and `verify-template` under `--profile template`. Pass `--verify interface|module|template` to choose, or `--verify custom` for a repository that keeps its own `.agents/skills/verify-<repo>/`. Sync writes `SKILL.md` and `package.json` in `.agents/skills/verify-<kind>/` with a `.claude/skills/verify-<kind>` link, and `--check` reports them as drift. It never touches the repository's own layer beside them: `verify.config.ts`, `features/`, `seeded-breaks/` and `seeded-doors/`.
|
|
53
|
+
|
|
54
|
+
Every deterministic step of a verification is an `antelopejs-verify` command: `map`, `plan`, `new`, `doctor`, `journey`, `formal`, `doors`, `seeded`, `seeded-doors`, `clean`, `verdict` and `publish`. The synced `SKILL.md` documents each one for the agent that verifies.
|
|
55
|
+
|
|
48
56
|
## Install
|
|
49
57
|
|
|
50
58
|
Node.js 24, or at least 22.18: oxlint reads `oxlint.config.ts` and loads JS plugins by executing TypeScript.
|
|
@@ -98,20 +106,21 @@ export default defineConfig({
|
|
|
98
106
|
| Type-aware | `typescript/no-floating-promises` and eight more type-aware rules | error |
|
|
99
107
|
| Complexity | `max-params` 5, `max-lines-per-function` 120, `max-lines` 500, `max-depth` 4, `complexity` 20 | error |
|
|
100
108
|
| Anti-slop | all 15 vendored rules; `no-runtime-typeof` with `allowInTypeGuards`, so a `typeof` inside a type predicate or assertion function passes | error |
|
|
101
|
-
| Guardrails | `antelopejs/no-comments`; in test files `antelopejs/no-fs-read-in-tests`, `antelopejs/no-constant-value-assertion`, `antelopejs/no-typeof-function-only-test` and `antelopejs/require-assertion`
|
|
109
|
+
| Guardrails | `antelopejs/no-comments`; in test files `antelopejs/no-fs-read-in-tests`, `antelopejs/no-self-import-in-tests`, `antelopejs/no-constant-value-assertion`, `antelopejs/no-typeof-function-only-test` and `antelopejs/require-assertion` | error |
|
|
102
110
|
| Import sorting | `perfectionist/sort-imports`, autofixed by `oxlint --fix` | off |
|
|
103
111
|
|
|
104
112
|
No rule warns. oxlint reports `correctness` as warnings by default, and warnings never fail the command, so the preset raises it to error. A repository with existing findings records them in `guardrails.ratchet.json` instead of lowering a severity (see [Guardrail pack](#guardrail-pack)).
|
|
105
113
|
|
|
106
114
|
The guardrail rules:
|
|
107
115
|
|
|
108
|
-
| Rule | Fails on
|
|
109
|
-
| ----------------------------------------- |
|
|
110
|
-
| `antelopejs/no-comments` | `//` and `/* */` comments. Allowed: TSDoc `/** */`, `SAFETY: <reason>` (one block, or a run of `//` lines), `/*!` license headers, `@ts-expect-error <reason>`, oxlint/eslint directives that name their rules, `/// <reference />`, `#__PURE__`/`@__PURE__`, `@vite-ignore` and webpack magic comments, `prettier-ignore`/`oxfmt-ignore`
|
|
111
|
-
| `antelopejs/no-fs-read-in-tests` | `readFileSync` or `readdirSync` from `fs` in a test file. Files under `fixtures/`, `helpers/` and `locales/` may read
|
|
112
|
-
| `antelopejs/
|
|
113
|
-
| `antelopejs/
|
|
114
|
-
| `antelopejs/no-
|
|
116
|
+
| Rule | Fails on |
|
|
117
|
+
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
118
|
+
| `antelopejs/no-comments` | `//` and `/* */` comments. Allowed: TSDoc `/** */`, `SAFETY: <reason>` (one block, or a run of `//` lines), `/*!` license headers, `@ts-expect-error <reason>`, oxlint/eslint directives that name their rules, `/// <reference />`, `#__PURE__`/`@__PURE__`, `@vite-ignore` and webpack magic comments, `prettier-ignore`/`oxfmt-ignore` |
|
|
119
|
+
| `antelopejs/no-fs-read-in-tests` | `readFileSync` or `readdirSync` from `fs` in a test file. Files under `fixtures/`, `helpers/` and `locales/` may read |
|
|
120
|
+
| `antelopejs/no-self-import-in-tests` | a test file that imports its own package name (`@antelopejs/<self>`, a subpath, `require`, dynamic `import()` or a re-export; `import type` is fine) unless that resolves to local code: the `exports` map publishes the subpath and `node_modules/<name>` is a link back to the package (a workspace self-link such as `link:.`). Otherwise the import resolves to the installed published copy and the test never runs local code. Import the module by relative path instead |
|
|
121
|
+
| `antelopejs/require-assertion` | a test with no assertion. Counts: calls named `expect*` or `assert*`, `sinon.assert.*`, supertest `.expect(...)`, and should-style `x.should…` or `should(x)` |
|
|
122
|
+
| `antelopejs/no-constant-value-assertion` | `expect(X).toBe(literal)` where the root of `X` is an UPPER_SNAKE constant (`MAX_ITEMS`, `NAMES.if`, not `process.env.NODE_ENV`); also `.toEqual`, `.to.equal`, `.to.eq`, `.eql` and synonyms |
|
|
123
|
+
| `antelopejs/no-typeof-function-only-test` | a test whose only assertions are `toBeTypeOf("function")`, `to.be.a("function")` or equivalents |
|
|
115
124
|
|
|
116
125
|
Test files are `*.test.*`, `*.spec.*`, and files under `test/`, `tests/` and `__tests__/`, whatever the framework. The preset keeps four framework-neutral Jest-plugin rules: `no-disabled-tests`, `no-focused-tests`, `valid-describe-callback` and `valid-title`.
|
|
117
126
|
|
|
@@ -187,6 +196,7 @@ pnpm install
|
|
|
187
196
|
|
|
188
197
|
- A rule listed under `rules` is off for `oxlint`, so editors, hooks and `lint` stay green. `antelopejs-ratchet` counts it with every rule on, and fails when a count rises. It prints the findings in the files the change touched.
|
|
189
198
|
- A file listed under `oversizeFiles` may exceed 20,000 bytes and `max-lines`, up to its recorded size. Any other file over either limit fails. When git sees a listed file renamed (`git mv`, or a staged delete and add), the allowance moves to the new path and never exceeds the old one; a copy or a new file inherits nothing. `antelopejs-ratchet --base <ref>` detects renames against that revision instead of `HEAD`, for a rename that was committed before the file was updated.
|
|
199
|
+
- The pre-commit hook runs `antelopejs-ratchet --staged`: for each rule under `rules` it compares the findings in the staged files with those files at HEAD (rename sources and deleted files included, linted under the staged configuration) and fails a rule whose net count rises. Code moved between staged files, or a legacy line that is reformatted or edited, nets out; a new finding does not, even next to a moved block.
|
|
190
200
|
- `antelopejs-ratchet --update` lowers each number to the current count and removes what reached zero. It never raises a number or adds an entry. Commit the lowered file.
|
|
191
201
|
|
|
192
202
|
When every rule count is zero and `oversizeFiles` is empty, the ratchet is retired. `antelopejs-ratchet --update` deletes the file and asks you to run `antelopejs-sync`. Sync then removes `ratchet`, `ratchet:update`, the ratchet hook and the Debt instructions. Commit those changes together. An empty baseline on first adoption creates no file. Later syncs never recreate it because the `sync:check` script marks adoption.
|
|
@@ -213,7 +223,7 @@ When every rule count is zero and `oversizeFiles` is empty, the ratchet is retir
|
|
|
213
223
|
- `antelopejs-suppressions` also compares the budget with the one on the pull request base: `--base <ref>` when given, else the `GITHUB_BASE_REF` branch in CI (fetched from `origin` into a shallow checkout), else `origin/HEAD`. It fails when a ceiling is higher than on the base or a rule the base lists is removed, so a raise merges only through the operator's ruleset bypass. A base without a budget, a first adoption, passes. Without a base the comparison is skipped.
|
|
214
224
|
- The pre-commit hook runs `antelopejs-suppressions --staged`: it compares the suppressions in the staged files with those files at HEAD, following renames and counting deleted files, and fails a kind that rises by more than the staged budget raises its ceiling. A suppression moved between staged files nets out.
|
|
215
225
|
- `@ts-ignore` is also a lint error (`typescript/ban-ts-comment`); `@ts-expect-error` fails once its error is gone.
|
|
216
|
-
- Both modes also judge what the change adds, whatever the budget allows: the full check against the same base (HEAD when there is none), the staged check against HEAD. A suppression counts as added when its kind, rule and reason occur more often than on the base, so one moved to another file with its reason is not added, and one whose reason a comment pass rewrote or stripped is. An added directive fails when it names a rule no directive may name (`anti-slop/require-safety-comment-for-type-assertion`, `antelopejs/no-comments`, the
|
|
226
|
+
- Both modes also judge what the change adds, whatever the budget allows: the full check against the same base (HEAD when there is none), the staged check against HEAD. A suppression counts as added when its kind, rule and reason occur more often than on the base, so one moved to another file with its reason is not added, and one whose reason a comment pass rewrote or stripped is. An added directive fails when it names a rule no directive may name (`anti-slop/require-safety-comment-for-type-assertion`, `antelopejs/no-comments`, the five `antelopejs` test rules, `typescript/ban-ts-comment`); the failure names what to do instead. An added directive naming its rules, `@ts-expect-error` or `SAFETY:` comment fails when its reason has fewer than three words, or only words like "safe", "intentional", "legacy" and the rule's own name. A block `oxlint-disable` or `eslint-disable` that no `-enable` closes before the end of its file fails when the change adds it. Suppressions already on the base stay under the budget until a burn-down removes them.
|
|
217
227
|
|
|
218
228
|
### Size
|
|
219
229
|
|
|
@@ -227,6 +237,8 @@ A behaviour-preserving cleanup PR shows `antelopejs-api-diff <base-ref>` passing
|
|
|
227
237
|
|
|
228
238
|
A comment-only PR shows `antelopejs-comment-proof <base-ref>` passing instead of a verifier. It includes private packages, ignores type diagnostics and compares comment-free JavaScript emit byte for byte. Both commands exclude test sources, fail on added or removed outputs, and print unified diffs for changes.
|
|
229
239
|
|
|
240
|
+
Test-helper entries are outside both halves. A published entry whose built file is test output relative to `outDir` (under `test/`, `tests/` or `__tests__/`, or named `*.test.*` or `*.spec.*`) is neither bundled nor loaded, because helpers such as `./tests/*` import a test runner that the proof does not run. This applies the same way to the declaration and the runtime half, to wildcard and plain targets, and to files a general wildcard such as `./*` matches. Each half prints `API: skipped test-helper entry <target> in <directory>` or `Runtime API: skipped test-helper entry <target> in <directory>`; a package whose only wildcard export is `./tests/*` still has its other entries compared in both halves.
|
|
241
|
+
|
|
230
242
|
Pass `--allow-added <glob>` (repeatable) to `antelopejs-api-diff` when a refactor adds helper files that a wildcard export publishes, such as an `internal/` directory under `"./*"`. An added entry passes, in both the declaration and the runtime half, when its published subpath matches a glob (for example `--allow-added '**/internal/**'`, matched against `base/table-view/internal/helper` for `./base/table-view/internal/helper`) and its source module is marked `@internal`: a leading `/** @internal @packageDocumentation */` comment on the module (`@module` and `@fileoverview` also qualify), or an `@internal` tag on every exported declaration. Allowed entries are printed under `Added (allowed): <count>`; nothing is printed when no entry was added. An added entry that matches but is not marked `@internal` fails with the file and the fix. Added entries matching no glob, removed entries and changed entries still fail, matching or not. Without the flag nothing changes.
|
|
231
243
|
|
|
232
244
|
```bash
|
package/dist/bin/api-diff.mjs
CHANGED
|
@@ -178,6 +178,12 @@ function normalizeBundle(compiler, text) {
|
|
|
178
178
|
}).printFile(normalized);
|
|
179
179
|
}
|
|
180
180
|
//#endregion
|
|
181
|
+
//#region src/guardrails/test-entries.ts
|
|
182
|
+
/** The line a proof half prints for a published test-helper entry it leaves out, so a skip is reported rather than silent. */
|
|
183
|
+
function testEntryNotice(half, directory, target) {
|
|
184
|
+
return `${half}: skipped test-helper entry ${target} in ${directory}; test helpers need a test runner and are outside both proof halves.\n`;
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
181
187
|
//#region src/guardrails/runtime-diff.ts
|
|
182
188
|
const DESCRIBE = `
|
|
183
189
|
const { readFileSync, existsSync } = require("node:fs");
|
|
@@ -242,35 +248,45 @@ function builtEntries(directory, manifest) {
|
|
|
242
248
|
subpath: "main"
|
|
243
249
|
});
|
|
244
250
|
if (!targets.length) throw new Error(`${directory}: no published runtime entry.`);
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
251
|
+
const output = outputRoot(directory);
|
|
252
|
+
const skipped = [];
|
|
253
|
+
return {
|
|
254
|
+
entries: targets.filter(({ target }) => !target.endsWith(".json")).filter(({ target }) => {
|
|
255
|
+
if (!isTestSource(output, resolve(directory, target))) return true;
|
|
256
|
+
skipped.push(target);
|
|
257
|
+
return false;
|
|
258
|
+
}).flatMap(({ entry, target, subpath }) => {
|
|
259
|
+
if (!target.includes("*")) {
|
|
260
|
+
const file = resolve(directory, target);
|
|
261
|
+
if (!existsSync(file)) throw new Error(`${directory}: missing built runtime entry ${target}.`);
|
|
262
|
+
return [{
|
|
263
|
+
entry,
|
|
264
|
+
file,
|
|
265
|
+
subpath
|
|
266
|
+
}];
|
|
267
|
+
}
|
|
268
|
+
const prefix = resolve(directory, target.slice(0, target.indexOf("*")));
|
|
269
|
+
const parent = dirname(prefix);
|
|
270
|
+
const pattern = new RegExp(`^${resolve(directory, target).split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")).join("(.*)")}$`, "u");
|
|
271
|
+
if (!existsSync(parent)) throw new Error(`${directory}: missing build output for ${target}.`);
|
|
272
|
+
const found = readdirSync(parent, {
|
|
273
|
+
recursive: true,
|
|
274
|
+
withFileTypes: true
|
|
275
|
+
}).filter((file) => file.isFile()).map((file) => join(file.parentPath, file.name)).filter((file) => pattern.test(file));
|
|
276
|
+
if (!found.length) throw new Error(`${directory}: missing built runtime entry ${target}.`);
|
|
277
|
+
const matches = found.filter((file) => !isTestSource(output, file));
|
|
278
|
+
if (matches.length < found.length) skipped.push(target);
|
|
279
|
+
return matches.sort().map((file) => {
|
|
280
|
+
const capture = pattern.exec(file)?.[1] ?? relative(directory, file);
|
|
281
|
+
return {
|
|
282
|
+
entry: entry.replaceAll("*", capture),
|
|
283
|
+
file,
|
|
284
|
+
subpath: fillStars(subpath, [capture])
|
|
285
|
+
};
|
|
286
|
+
});
|
|
287
|
+
}),
|
|
288
|
+
skipped
|
|
289
|
+
};
|
|
274
290
|
}
|
|
275
291
|
function childJson(args, cwd) {
|
|
276
292
|
const result = spawnSync(process.execPath, args, {
|
|
@@ -305,13 +321,14 @@ function buildPackage(directory, output, manifest) {
|
|
|
305
321
|
"pipe"
|
|
306
322
|
]
|
|
307
323
|
});
|
|
308
|
-
let
|
|
324
|
+
let built;
|
|
309
325
|
try {
|
|
310
|
-
|
|
326
|
+
built = builtEntries(directory, manifest);
|
|
311
327
|
} catch (error) {
|
|
312
328
|
if (buildManifest.scripts?.build) throw error;
|
|
313
329
|
return;
|
|
314
330
|
}
|
|
331
|
+
const { entries, skipped } = built;
|
|
315
332
|
for (const { entry, file } of entries) {
|
|
316
333
|
const destination = join(output, `${encodeURIComponent(entry)}.json`);
|
|
317
334
|
const metadata = childJson([
|
|
@@ -324,7 +341,8 @@ function buildPackage(directory, output, manifest) {
|
|
|
324
341
|
}
|
|
325
342
|
return {
|
|
326
343
|
count: entries.length,
|
|
327
|
-
entries
|
|
344
|
+
entries,
|
|
345
|
+
skipped
|
|
328
346
|
};
|
|
329
347
|
}
|
|
330
348
|
/** Builds both committed revisions and compares published runtime metadata and one captured optional probe. */
|
|
@@ -332,6 +350,7 @@ function runtimeDiff(root, baseRef, probe, policy) {
|
|
|
332
350
|
const errors = [];
|
|
333
351
|
const failedPackages = /* @__PURE__ */ new Set();
|
|
334
352
|
const skippedPackages = /* @__PURE__ */ new Set();
|
|
353
|
+
const skippedTests = /* @__PURE__ */ new Set();
|
|
335
354
|
const result = compareRevisions(root, baseRef, "Runtime API", (worktree, output, scratch) => {
|
|
336
355
|
const packages = packagesAt(worktree, true);
|
|
337
356
|
const published = [];
|
|
@@ -343,6 +362,7 @@ function runtimeDiff(root, baseRef, probe, policy) {
|
|
|
343
362
|
if (built === void 0) skippedPackages.add(directory);
|
|
344
363
|
else {
|
|
345
364
|
entries += built.count;
|
|
365
|
+
for (const target of built.skipped) skippedTests.add(testEntryNotice("Runtime API", directory, target));
|
|
346
366
|
published.push(...built.entries.map(({ entry, subpath }) => ({
|
|
347
367
|
path: `${folder}/${encodeURIComponent(entry)}.json`,
|
|
348
368
|
directory,
|
|
@@ -372,7 +392,7 @@ function runtimeDiff(root, baseRef, probe, policy) {
|
|
|
372
392
|
}, policy);
|
|
373
393
|
return {
|
|
374
394
|
different: result.different || errors.length > 0,
|
|
375
|
-
output: (errors.length && !result.different ? result.output.replace(/^Runtime API:[^\n]*\n/u, "Runtime API: comparison incomplete due to execution errors.\n") : result.output) + [...skippedPackages].map((directory) => `Runtime API: skipped ${directory}, which has no build script and no committed runtime entry.\n`).join("") + errors.join("")
|
|
395
|
+
output: (errors.length && !result.different ? result.output.replace(/^Runtime API:[^\n]*\n/u, "Runtime API: comparison incomplete due to execution errors.\n") : result.output) + [...skippedPackages].map((directory) => `Runtime API: skipped ${directory}, which has no build script and no committed runtime entry.\n`).join("") + [...skippedTests].sort().join("") + errors.join("")
|
|
376
396
|
};
|
|
377
397
|
}
|
|
378
398
|
//#endregion
|
|
@@ -435,12 +455,18 @@ function publishedEntries(directory, manifest, emitted, scratch) {
|
|
|
435
455
|
const outputRoot = resolve(directory, emitted.options.outDir ?? ".");
|
|
436
456
|
const files = emitted.files.map((file) => relative(scratch, file).split("\\").join("/"));
|
|
437
457
|
const entries = [];
|
|
458
|
+
const skipped = [];
|
|
438
459
|
for (const { entry, target, subpath } of entryPatterns(manifest)) {
|
|
439
|
-
if (isTestSource(outputRoot, resolve(directory, target)))
|
|
460
|
+
if (isTestSource(outputRoot, resolve(directory, target))) {
|
|
461
|
+
skipped.push(target);
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
440
464
|
const path = relative(outputRoot, resolve(directory, target)).split("\\").join("/");
|
|
441
465
|
const pattern = targetPattern(path);
|
|
442
|
-
const
|
|
443
|
-
if (!
|
|
466
|
+
const found = files.filter((file) => pattern.test(file));
|
|
467
|
+
if (!found.length && !path.includes("*")) throw new Error(`${directory}: published target ${target} has no emitted declaration.`);
|
|
468
|
+
const matches = found.filter((file) => !isTestSource(outputRoot, join(outputRoot, file)));
|
|
469
|
+
if (matches.length < found.length) skipped.push(target);
|
|
444
470
|
for (const file of matches) {
|
|
445
471
|
const captures = pattern.exec(file)?.slice(1) ?? [];
|
|
446
472
|
const name = entry.includes("*") ? fillStars(entry, captures, entrySegment) : `${entry}${captures.length ? `/file/${entrySegment(file)}` : ""}`;
|
|
@@ -451,7 +477,10 @@ function publishedEntries(directory, manifest, emitted, scratch) {
|
|
|
451
477
|
});
|
|
452
478
|
}
|
|
453
479
|
}
|
|
454
|
-
return
|
|
480
|
+
return {
|
|
481
|
+
entries: entries.sort((a, b) => a.entry.localeCompare(b.entry)),
|
|
482
|
+
skipped
|
|
483
|
+
};
|
|
455
484
|
}
|
|
456
485
|
function bundleDependencies(directory, scratch) {
|
|
457
486
|
let current = directory;
|
|
@@ -472,10 +501,11 @@ function bundlePackage(paths, manifest, policy, notices) {
|
|
|
472
501
|
const { directory, output, scratch } = paths;
|
|
473
502
|
const emitted = emitPackage(directory, scratch, true);
|
|
474
503
|
if (emitted.notice !== void 0) notices?.add(emitted.notice);
|
|
475
|
-
const entries = publishedEntries(directory, manifest, emitted, scratch);
|
|
504
|
+
const { entries, skipped } = publishedEntries(directory, manifest, emitted, scratch);
|
|
476
505
|
if (!entries.length) return {
|
|
477
506
|
count: 0,
|
|
478
|
-
published: []
|
|
507
|
+
published: [],
|
|
508
|
+
skipped
|
|
479
509
|
};
|
|
480
510
|
bundleDependencies(directory, scratch);
|
|
481
511
|
writeFileSync(join(scratch, "package.json"), readFileSync(join(directory, "package.json")));
|
|
@@ -521,7 +551,8 @@ function bundlePackage(paths, manifest, policy, notices) {
|
|
|
521
551
|
path: `${paths.name === "." ? "_root" : paths.name}/${entry}`,
|
|
522
552
|
directory: paths.name,
|
|
523
553
|
subpath
|
|
524
|
-
}))
|
|
554
|
+
})),
|
|
555
|
+
skipped
|
|
525
556
|
};
|
|
526
557
|
}
|
|
527
558
|
function declarationDiff(root, baseRef, policy) {
|
|
@@ -529,6 +560,7 @@ function declarationDiff(root, baseRef, policy) {
|
|
|
529
560
|
const notices = /* @__PURE__ */ new Set();
|
|
530
561
|
const failedPackages = /* @__PURE__ */ new Set();
|
|
531
562
|
const unpublished = /* @__PURE__ */ new Map();
|
|
563
|
+
const skippedTests = /* @__PURE__ */ new Set();
|
|
532
564
|
const result = compareRevisions(root, baseRef, "API", (worktree, output, scratch) => {
|
|
533
565
|
const packages = packagesAt(worktree, true);
|
|
534
566
|
for (const { directory, reason } of unpublishedAt(worktree)) unpublished.set(directory, reason);
|
|
@@ -545,6 +577,7 @@ function declarationDiff(root, baseRef, policy) {
|
|
|
545
577
|
scratch: join(scratch, key)
|
|
546
578
|
}, manifest, policy, notices);
|
|
547
579
|
entries += bundled.count;
|
|
580
|
+
for (const target of bundled.skipped) skippedTests.add(testEntryNotice("API", directory, target));
|
|
548
581
|
published.push(...bundled.published);
|
|
549
582
|
} catch (error) {
|
|
550
583
|
failedPackages.add(directory);
|
|
@@ -563,7 +596,7 @@ function declarationDiff(root, baseRef, policy) {
|
|
|
563
596
|
}, policy);
|
|
564
597
|
return {
|
|
565
598
|
different: result.different || errors.size > 0,
|
|
566
|
-
output: (errors.size > 0 && !result.different ? result.output.replace(/^API:[^\n]*\n/u, "API: comparison incomplete due to execution errors.\n") : result.output) + [...unpublished].sort(([a], [b]) => a.localeCompare(b)).map(([directory, reason]) => `API: skipped ${directory}, ${reason}.\n`).join("") + [...notices].sort().join("") + [...errors].join("")
|
|
599
|
+
output: (errors.size > 0 && !result.different ? result.output.replace(/^API:[^\n]*\n/u, "API: comparison incomplete due to execution errors.\n") : result.output) + [...unpublished].sort(([a], [b]) => a.localeCompare(b)).map(([directory, reason]) => `API: skipped ${directory}, ${reason}.\n`).join("") + [...skippedTests].sort().join("") + [...notices].sort().join("") + [...errors].join("")
|
|
567
600
|
};
|
|
568
601
|
}
|
|
569
602
|
/** Compares declarations and built runtime exports, with an optional behavioral probe captured before either build. Added entries whose subpath matches an `allowAdded` glob pass when their module is `@internal`. */
|
package/dist/bin/garden.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { a as isString, c as object, d as optTime, f as parseJson, h as time, i as isObject, l as optNum, m as strings, n as children, o as list, p as str, r as flag, s as num, t as child, u as optStr } from "../json-BqvuCkqr.mjs";
|
|
2
3
|
import { n as runCliAsync } from "../cli-4Tv71vYk.mjs";
|
|
3
4
|
import { c as ciNodeCallers, n as CI_NODE_REF, r as CI_PATH, t as CI_CONTEXT } from "../ci-workflow-BDy6hQJ6.mjs";
|
|
4
5
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
@@ -7,72 +8,6 @@ import { execFileSync, spawnSync } from "node:child_process";
|
|
|
7
8
|
import { parseArgs } from "node:util";
|
|
8
9
|
import { homedir, tmpdir } from "node:os";
|
|
9
10
|
import { inflateRawSync } from "node:zlib";
|
|
10
|
-
//#region src/garden/json.ts
|
|
11
|
-
/** Raised when an API payload lacks a field the Gardener relies on. */
|
|
12
|
-
var DecodeError = class extends Error {};
|
|
13
|
-
function isString(value) {
|
|
14
|
-
return String(value) === value;
|
|
15
|
-
}
|
|
16
|
-
function isNumber(value) {
|
|
17
|
-
return Number.isFinite(value);
|
|
18
|
-
}
|
|
19
|
-
function isObject(value) {
|
|
20
|
-
return Object(value) === value && !Array.isArray(value);
|
|
21
|
-
}
|
|
22
|
-
function parseJson(text) {
|
|
23
|
-
return JSON.parse(text);
|
|
24
|
-
}
|
|
25
|
-
function object(value, path) {
|
|
26
|
-
if (!isObject(value)) throw new DecodeError(`${path}: expected an object`);
|
|
27
|
-
return value;
|
|
28
|
-
}
|
|
29
|
-
function list(value, path) {
|
|
30
|
-
if (!Array.isArray(value)) throw new DecodeError(`${path}: expected a list`);
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
function str(source, key) {
|
|
34
|
-
const value = source[key];
|
|
35
|
-
if (value === void 0 || !isString(value)) throw new DecodeError(`${key}: expected a string`);
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
function optStr(source, key) {
|
|
39
|
-
const value = source[key];
|
|
40
|
-
return value !== void 0 && isString(value) ? value : void 0;
|
|
41
|
-
}
|
|
42
|
-
function num(source, key) {
|
|
43
|
-
const value = source[key];
|
|
44
|
-
if (value === void 0 || !isNumber(value)) throw new DecodeError(`${key}: expected a number`);
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
function optNum(source, key) {
|
|
48
|
-
const value = source[key];
|
|
49
|
-
return value !== void 0 && isNumber(value) ? value : void 0;
|
|
50
|
-
}
|
|
51
|
-
function flag(source, key) {
|
|
52
|
-
return source[key] === true;
|
|
53
|
-
}
|
|
54
|
-
function child(source, key) {
|
|
55
|
-
const value = source[key];
|
|
56
|
-
return value === void 0 ? {} : object(value, key);
|
|
57
|
-
}
|
|
58
|
-
function children(source, key) {
|
|
59
|
-
const value = source[key];
|
|
60
|
-
return value === void 0 ? [] : list(value, key).map((entry) => object(entry, key));
|
|
61
|
-
}
|
|
62
|
-
function strings(source, key) {
|
|
63
|
-
const value = source[key];
|
|
64
|
-
return value === void 0 ? [] : list(value, key).filter((entry) => isString(entry));
|
|
65
|
-
}
|
|
66
|
-
function time(source, key) {
|
|
67
|
-
const value = Date.parse(str(source, key));
|
|
68
|
-
if (Number.isNaN(value)) throw new DecodeError(`${key}: expected a date`);
|
|
69
|
-
return value;
|
|
70
|
-
}
|
|
71
|
-
function optTime(source, key) {
|
|
72
|
-
const value = optStr(source, key);
|
|
73
|
-
return value === void 0 ? void 0 : Date.parse(value);
|
|
74
|
-
}
|
|
75
|
-
//#endregion
|
|
76
11
|
//#region src/garden/api.ts
|
|
77
12
|
/** A GitHub or npm answer that is not a success. */
|
|
78
13
|
var ApiError = class extends Error {
|
|
@@ -427,7 +362,8 @@ var GardenContext = class {
|
|
|
427
362
|
}
|
|
428
363
|
tree(repo) {
|
|
429
364
|
return this.trees.get(repo.name, async () => {
|
|
430
|
-
|
|
365
|
+
const body = object(await this.api.json(`/repos/${ORG}/${repo.name}/git/trees/${repo.defaultBranch}?recursive=1`), "tree");
|
|
366
|
+
return children(body, "tree").map((entry) => str(entry, "path"));
|
|
431
367
|
});
|
|
432
368
|
}
|
|
433
369
|
file(repo, path, ref = repo.defaultBranch) {
|
|
@@ -457,7 +393,8 @@ var GardenContext = class {
|
|
|
457
393
|
return this.runs.get(`${repo.name}:${workflow}:${branch}:${event}`, async () => {
|
|
458
394
|
try {
|
|
459
395
|
const filter = event === "" ? "" : `&event=${event}`;
|
|
460
|
-
|
|
396
|
+
const body = await this.api.json(`/repos/${ORG}/${repo.name}/actions/workflows/${workflow}/runs?branch=${branch}${filter}&status=completed&per_page=100`);
|
|
397
|
+
return children(object(body, "runs"), "workflow_runs").map((run) => workflowRun(run));
|
|
461
398
|
} catch (error) {
|
|
462
399
|
if (error instanceof Error && isMissing(error)) return void 0;
|
|
463
400
|
throw error;
|
|
@@ -494,7 +431,8 @@ var GardenContext = class {
|
|
|
494
431
|
variable(repo, name) {
|
|
495
432
|
return this.variables.get(`${repo.name}:${name}`, async () => {
|
|
496
433
|
try {
|
|
497
|
-
|
|
434
|
+
const body = await this.api.json(`/repos/${ORG}/${repo.name}/actions/variables/${name}`);
|
|
435
|
+
return str(object(body, "variable"), "value");
|
|
498
436
|
} catch (error) {
|
|
499
437
|
if (error instanceof Error && isMissing(error)) return void 0;
|
|
500
438
|
throw error;
|
|
@@ -505,7 +443,10 @@ var GardenContext = class {
|
|
|
505
443
|
removedInHistory(repo, path) {
|
|
506
444
|
return this.removals.get(`${repo.name}:${path}`, async () => {
|
|
507
445
|
const commits = list(await this.api.json(`/repos/${ORG}/${repo.name}/commits?path=${path}&sha=${repo.defaultBranch}&per_page=30`), "commits");
|
|
508
|
-
for (const commit of commits)
|
|
446
|
+
for (const commit of commits) {
|
|
447
|
+
const detail = object(await this.api.json(`/repos/${ORG}/${repo.name}/commits/${str(object(commit, "commit"), "sha")}`), "commit");
|
|
448
|
+
if (children(detail, "files").some((file) => str(file, "filename") === path && optStr(file, "status") === "removed")) return true;
|
|
449
|
+
}
|
|
509
450
|
return false;
|
|
510
451
|
});
|
|
511
452
|
}
|
|
@@ -650,7 +591,8 @@ const WORKFLOWS_REPO = ".github";
|
|
|
650
591
|
async function latestReport(context, repo, name) {
|
|
651
592
|
const [latest] = await context.artifactsNamed(repo, name);
|
|
652
593
|
if (latest === void 0) return void 0;
|
|
653
|
-
|
|
594
|
+
const archive = await context.api.bytes(`/repos/${ORG}/${repo}/actions/artifacts/${latest.id}/zip`);
|
|
595
|
+
return object(parseJson(firstZipEntry(archive)), name);
|
|
654
596
|
}
|
|
655
597
|
function survivors(report) {
|
|
656
598
|
const files = object(report.files ?? {}, "files");
|
package/dist/bin/ratchet.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { t as CEILINGS_FILE } from "../ceilings-BSw9p4YB.mjs";
|
|
3
3
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
4
4
|
import { a as repositoryPath, o as repositoryRoot, s as resolveRevision } from "../files-2FikHZ9F.mjs";
|
|
5
|
-
import { n as stagedRatchet } from "../staged-ratchet-
|
|
6
|
-
import { n as ratchet } from "../ratchet-
|
|
5
|
+
import { n as stagedRatchet } from "../staged-ratchet-CjoRfZaM.mjs";
|
|
6
|
+
import { n as ratchet } from "../ratchet-DRdIYwmv.mjs";
|
|
7
7
|
import { resolve } from "node:path";
|
|
8
8
|
import { parseArgs } from "node:util";
|
|
9
9
|
//#region src/bin/ratchet.ts
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
3
3
|
import { o as repositoryRoot, s as resolveRevision } from "../files-2FikHZ9F.mjs";
|
|
4
|
-
import { a as parseBudget, c as checkPolicy, i as checkSuppressions, n as SUPPRESSIONS_FILE, o as safetyCeiling, s as stagedSuppressions } from "../suppression-budget-
|
|
4
|
+
import { a as parseBudget, c as checkPolicy, i as checkSuppressions, n as SUPPRESSIONS_FILE, o as safetyCeiling, s as stagedSuppressions } from "../suppression-budget-Yyf5_J5l.mjs";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
|
-
import {
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
8
|
import { parseArgs } from "node:util";
|
|
9
9
|
//#region src/guardrails/suppression-base.ts
|
|
10
10
|
function verified(root, ref) {
|
|
@@ -20,33 +20,45 @@ function verified(root, ref) {
|
|
|
20
20
|
});
|
|
21
21
|
return result.status === 0 ? result.stdout.trim() : void 0;
|
|
22
22
|
}
|
|
23
|
+
function fetchBase(root, branch, remote) {
|
|
24
|
+
const result = spawnSync("git", [
|
|
25
|
+
"fetch",
|
|
26
|
+
"--quiet",
|
|
27
|
+
"--no-tags",
|
|
28
|
+
"--depth=1",
|
|
29
|
+
"origin",
|
|
30
|
+
`+refs/heads/${branch}:${remote}`
|
|
31
|
+
], {
|
|
32
|
+
cwd: root,
|
|
33
|
+
encoding: "utf8",
|
|
34
|
+
env: {
|
|
35
|
+
...process.env,
|
|
36
|
+
GIT_TERMINAL_PROMPT: "0"
|
|
37
|
+
},
|
|
38
|
+
stdio: [
|
|
39
|
+
"ignore",
|
|
40
|
+
"ignore",
|
|
41
|
+
"pipe"
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
if (result.status === 0) return;
|
|
45
|
+
const detail = result.error?.message ?? result.stderr.trim();
|
|
46
|
+
throw new Error(`Cannot compare with the pull request base: ${remote} is missing and fetching ${branch} from origin failed${detail ? ` (${detail})` : ""}. In CI, fetch the base branch before this check with credentials, or pass --base.`);
|
|
47
|
+
}
|
|
23
48
|
/**
|
|
24
49
|
* The commit a pull request merges into: `base` when given; in CI the
|
|
25
|
-
* `GITHUB_BASE_REF` branch,
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
50
|
+
* `GITHUB_BASE_REF` branch, taken from the local `origin/<branch>` ref when
|
|
51
|
+
* present and otherwise fetched from `origin`, an error naming the missing ref
|
|
52
|
+
* when the fetch fails; otherwise `origin/HEAD`, the remote's default branch.
|
|
53
|
+
* A requested base that cannot be resolved is an error; without one, a
|
|
54
|
+
* repository with no `origin/HEAD` has no base.
|
|
29
55
|
*/
|
|
30
56
|
function suppressionBase(root, base) {
|
|
31
57
|
if (base !== void 0) return resolveRevision(root, base);
|
|
32
58
|
const branch = process.env.GITHUB_BASE_REF;
|
|
33
59
|
if (branch) {
|
|
34
60
|
const remote = `refs/remotes/origin/${branch}`;
|
|
35
|
-
if (verified(root, remote) === void 0)
|
|
36
|
-
"fetch",
|
|
37
|
-
"--quiet",
|
|
38
|
-
"--no-tags",
|
|
39
|
-
"--depth=1",
|
|
40
|
-
"origin",
|
|
41
|
-
`+refs/heads/${branch}:${remote}`
|
|
42
|
-
], {
|
|
43
|
-
cwd: root,
|
|
44
|
-
stdio: [
|
|
45
|
-
"ignore",
|
|
46
|
-
"ignore",
|
|
47
|
-
"pipe"
|
|
48
|
-
]
|
|
49
|
-
});
|
|
61
|
+
if (verified(root, remote) === void 0) fetchBase(root, branch, remote);
|
|
50
62
|
return resolveRevision(root, remote);
|
|
51
63
|
}
|
|
52
64
|
return verified(root, "refs/remotes/origin/HEAD");
|