@antelopejs/tooling-configs 0.5.8 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -49
- package/dist/{api-CCOiLN3w.mjs → api-BQLrI_S1.mjs} +19 -2
- package/dist/bin/api-diff.mjs +155 -37
- package/dist/bin/body-check.mjs +6 -3
- package/dist/bin/check-size.mjs +1 -1
- package/dist/bin/checks.mjs +1 -1
- package/dist/bin/comment-proof.mjs +3 -5
- package/dist/bin/garden.mjs +86 -34
- package/dist/bin/lease.mjs +314 -26
- package/dist/bin/ratchet.mjs +4 -4
- package/dist/bin/readme-strip.mjs +1 -1
- package/dist/bin/suppressions.mjs +10 -6
- package/dist/bin/sync.mjs +23 -98
- package/dist/bin/triage.mjs +1 -1
- package/dist/bin/verify.mjs +1 -1
- package/dist/{checks-BC-F8bsv.mjs → checks-BefrkjiT.mjs} +729 -25
- package/dist/{docs-compat-Ft1r2sf0.mjs → docs-compat-CSljVi3O.mjs} +13 -8
- package/dist/eslint.d.mts +13 -4
- package/dist/eslint.mjs +48 -6
- package/dist/guardrails-BfGwehVj.mjs +2414 -0
- package/dist/installed-typescript-6MtIWlE4.mjs +84 -0
- package/dist/oxc/anti-slop/index.mjs +541 -34
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +2 -1854
- package/dist/oxc/lint.d.mts +10 -1
- package/dist/oxc/lint.mjs +13 -5
- package/dist/{oxlint-CCOJqj3d.mjs → oxlint-CkHhK5K_.mjs} +33 -11
- package/dist/{package-DnxZ2CXZ.mjs → package-DDG3YH7W.mjs} +10 -5
- package/dist/{ports-DGP6bPJy.mjs → ports-DAeEJsYh.mjs} +22 -0
- package/dist/{proof-stamp-lyD84zmj.mjs → proof-stamp-BFV7JTZT.mjs} +5 -4
- package/dist/{ratchet-SQ7vTR0i.mjs → ratchet-2FeMs1kh.mjs} +4 -3
- package/dist/{suppression-base-whhvw-IJ.mjs → suppression-base-CYaLZAq7.mjs} +2 -2
- package/dist/{suppression-budget-CtIYSoDO.mjs → suppression-budget-CPDSFg4X.mjs} +1 -1
- package/dist/{suppressions-C79kRvYI.mjs → suppressions-CxPnh4sC.mjs} +2 -2
- package/dist/{templates-Dg188oRC.mjs → templates-HG0fel2S.mjs} +1 -1
- package/dist/{type-aware-rules-DMuN6sHb.mjs → type-aware-rules-Da3769fI.mjs} +9 -1
- package/dist/{typescript--_8og8AM.mjs → typescript-CxfNxyr2.mjs} +59 -98
- package/dist/{workflow-CPcNc8KL.mjs → workflow-C-oBwL2H.mjs} +25 -1
- package/package.json +9 -5
- package/dist/bin/check-interface-ranges.d.mts +0 -1
- package/dist/bin/check-interface-ranges.mjs +0 -44
- package/dist/interface-ranges-CcVSr59f.mjs +0 -116
|
@@ -1,17 +1,301 @@
|
|
|
1
1
|
import { t as CEILINGS_FILE } from "./ceilings-B7KayYIG.mjs";
|
|
2
|
-
import { o as packageManager, s as parseManifest } from "./package-
|
|
3
|
-
import { a as gitFiles } from "./files-C-JJhExM.mjs";
|
|
4
|
-
import { n as workspaceDirectories } from "./docs-compat-
|
|
5
|
-
import { t as runCommand } from "./run-command-BlFRPORx.mjs";
|
|
6
|
-
import { t as accepting } from "./ports-
|
|
7
|
-
import {
|
|
8
|
-
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { l as serializeManifest, o as packageManager, s as parseManifest } from "./package-DDG3YH7W.mjs";
|
|
3
|
+
import { a as gitFiles, u as trackedManifests } from "./files-C-JJhExM.mjs";
|
|
4
|
+
import { n as workspaceDirectories } from "./docs-compat-CSljVi3O.mjs";
|
|
5
|
+
import { n as shimInvocation, t as runCommand } from "./run-command-BlFRPORx.mjs";
|
|
6
|
+
import { t as accepting } from "./ports-DAeEJsYh.mjs";
|
|
7
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
9
8
|
import { basename, dirname, join, posix, relative, resolve, sep } from "node:path";
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
import { isMap, isScalar, isSeq, parseAllDocuments, parseDocument, stringify } from "yaml";
|
|
11
|
+
import ts from "@typescript/typescript6";
|
|
12
12
|
import { createHash } from "node:crypto";
|
|
13
13
|
import { tmpdir } from "node:os";
|
|
14
|
+
import { gunzipSync } from "node:zlib";
|
|
15
|
+
import { satisfies, validRange } from "semver";
|
|
14
16
|
import { minimatch } from "minimatch";
|
|
17
|
+
//#region src/guardrails/run-pnpm.ts
|
|
18
|
+
/** Runs pnpm, the only manager the pack's CI installs with, with `args` quietly; returns its output only when it failed. */
|
|
19
|
+
function runPnpm(root, args) {
|
|
20
|
+
const command = ["pnpm", ...args].join(" ");
|
|
21
|
+
const pnpm = shimInvocation("pnpm", args);
|
|
22
|
+
const result = spawnSync(pnpm.command, pnpm.args, {
|
|
23
|
+
cwd: root,
|
|
24
|
+
encoding: "utf8",
|
|
25
|
+
shell: pnpm.shell
|
|
26
|
+
});
|
|
27
|
+
if (result.error) return `${command} failed: ${result.error.message}`;
|
|
28
|
+
if (result.status === 0) return void 0;
|
|
29
|
+
return `${command} failed (exit ${result.status}).\n${result.stdout}${result.stderr}`.trimEnd();
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/guardrails/dependency-ranges.ts
|
|
33
|
+
/**
|
|
34
|
+
* An `@antelopejs/*` package ships breaking changes in minor releases, on 0.x
|
|
35
|
+
* and from 1.0 alike, so a range open past the next minor of its floor lets an
|
|
36
|
+
* install resolve a breaking release its dependent was never built against.
|
|
37
|
+
* Every range on one stops below that minor: `>=0.4.0 <0.5.0` on 0.x,
|
|
38
|
+
* `~1.2.0` from 1.0. A narrower range, such as an exact pin, fails too:
|
|
39
|
+
* `@antelopejs/core` keeps one copy of each interface and refuses to start a
|
|
40
|
+
* module whose range that copy falls outside, so a pin breaks startup at the
|
|
41
|
+
* next patch release.
|
|
42
|
+
*/
|
|
43
|
+
const ANTELOPEJS_SCOPE = "@antelopejs/";
|
|
44
|
+
/** A linked folder is the copy the dependent builds against, not a release it resolves. */
|
|
45
|
+
const LINK_SPEC_PREFIXES = ["file:", "link:"];
|
|
46
|
+
/** pnpm replaces a `workspace:` spec with a range on the sibling's version when it publishes the package. */
|
|
47
|
+
const WORKSPACE_PREFIX = "workspace:";
|
|
48
|
+
/** The `workspace:` spec that publishes as a range stopping below the next minor, on 0.x and from 1.0 alike. */
|
|
49
|
+
const CAPPED_WORKSPACE_SPEC = "workspace:~";
|
|
50
|
+
const CHECKED_FIELDS = [
|
|
51
|
+
"dependencies",
|
|
52
|
+
"devDependencies",
|
|
53
|
+
"peerDependencies",
|
|
54
|
+
"optionalDependencies"
|
|
55
|
+
];
|
|
56
|
+
const VERSION = String.raw`v?(\d+)\.(\d+)\.(\d+)`;
|
|
57
|
+
const LEADING_VERSION = new RegExp(String.raw`^(?:>=|[~^=])?\s*${VERSION}`);
|
|
58
|
+
const nextMinor = ([major, minor]) => [
|
|
59
|
+
major,
|
|
60
|
+
minor + 1,
|
|
61
|
+
0
|
|
62
|
+
];
|
|
63
|
+
/** The first release a caret excludes: the next major from 1.0, the next minor on 0.x, the next patch on 0.0.x. */
|
|
64
|
+
function caretCeiling([major, minor, patch]) {
|
|
65
|
+
if (major > 0) return [
|
|
66
|
+
major + 1,
|
|
67
|
+
0,
|
|
68
|
+
0
|
|
69
|
+
];
|
|
70
|
+
return minor > 0 ? [
|
|
71
|
+
0,
|
|
72
|
+
minor + 1,
|
|
73
|
+
0
|
|
74
|
+
] : [
|
|
75
|
+
0,
|
|
76
|
+
0,
|
|
77
|
+
patch + 1
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
/** Each range syntax this check reads, matched whole, with the ceiling it puts on the floor its first three groups hold. */
|
|
81
|
+
const RANGE_SYNTAXES = [
|
|
82
|
+
{
|
|
83
|
+
pattern: new RegExp(String.raw`^>=\s*${VERSION}\s+<\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?$`),
|
|
84
|
+
ceiling: (_floor, match) => [
|
|
85
|
+
Number(match[4]),
|
|
86
|
+
Number(match[5] ?? 0),
|
|
87
|
+
Number(match[6] ?? 0)
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
pattern: new RegExp(String.raw`^~${VERSION}$`),
|
|
92
|
+
ceiling: nextMinor
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
pattern: new RegExp(String.raw`^\^${VERSION}$`),
|
|
96
|
+
ceiling: caretCeiling
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
pattern: new RegExp(String.raw`^=?${VERSION}$`),
|
|
100
|
+
ceiling: ([major, minor, patch]) => [
|
|
101
|
+
major,
|
|
102
|
+
minor,
|
|
103
|
+
patch + 1
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
const toVersion = (match) => [
|
|
108
|
+
Number(match[1]),
|
|
109
|
+
Number(match[2]),
|
|
110
|
+
Number(match[3])
|
|
111
|
+
];
|
|
112
|
+
function readBounds(spec) {
|
|
113
|
+
for (const { pattern, ceiling } of RANGE_SYNTAXES) {
|
|
114
|
+
const match = pattern.exec(spec);
|
|
115
|
+
if (!match) continue;
|
|
116
|
+
const floor = toVersion(match);
|
|
117
|
+
return {
|
|
118
|
+
floor,
|
|
119
|
+
ceiling: ceiling(floor, match)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** The lowest release `spec` names, read from its start even when the rest is a shape this check does not read. */
|
|
124
|
+
function readFloor(spec) {
|
|
125
|
+
const match = LEADING_VERSION.exec(spec.trim());
|
|
126
|
+
return match ? toVersion(match) : void 0;
|
|
127
|
+
}
|
|
128
|
+
const formatVersion = ([major, minor, patch]) => `${major}.${minor}.${patch}`;
|
|
129
|
+
function compareVersions(a, b) {
|
|
130
|
+
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
131
|
+
}
|
|
132
|
+
/** The range to declare for releases from `floor`: a bounded range on 0.x, a tilde from 1.0. */
|
|
133
|
+
function cappedRange(floor) {
|
|
134
|
+
return floor[0] === 0 ? `>=${formatVersion(floor)} <${formatVersion(nextMinor(floor))}` : `~${formatVersion(floor)}`;
|
|
135
|
+
}
|
|
136
|
+
function isCapped(bounds, local) {
|
|
137
|
+
if (!bounds) return false;
|
|
138
|
+
const { floor, ceiling } = bounds;
|
|
139
|
+
if (compareVersions(ceiling, nextMinor(floor)) !== 0) return false;
|
|
140
|
+
return local === void 0 || compareVersions(local, floor) >= 0 && compareVersions(local, ceiling) < 0;
|
|
141
|
+
}
|
|
142
|
+
function isLinkSpec(spec) {
|
|
143
|
+
return LINK_SPEC_PREFIXES.some((prefix) => spec.startsWith(prefix));
|
|
144
|
+
}
|
|
145
|
+
/** The spec pnpm publishes in place of the `workspace:` spec `spec` on a sibling at `local`, without its prerelease or build suffix. */
|
|
146
|
+
function publishedSpec(spec, local) {
|
|
147
|
+
const range = spec.slice(10);
|
|
148
|
+
const version = formatVersion(local);
|
|
149
|
+
if (range === "*") return version;
|
|
150
|
+
if (range === "^" || range === "~") return `${range}${version}`;
|
|
151
|
+
return range;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The violation of one `@antelopejs/*` entry, if any. A `workspace:` spec is
|
|
155
|
+
* judged as pnpm publishes it, and skipped in a private manifest, which is
|
|
156
|
+
* never published, or when the sibling's version is not known.
|
|
157
|
+
*/
|
|
158
|
+
function checkEntry(manifest, field, [name, spec], local) {
|
|
159
|
+
const workspace = spec.startsWith(WORKSPACE_PREFIX);
|
|
160
|
+
const localVersion = local === void 0 ? void 0 : readFloor(local);
|
|
161
|
+
let published = spec;
|
|
162
|
+
if (workspace) {
|
|
163
|
+
if (manifest.private === true || localVersion === void 0) return void 0;
|
|
164
|
+
published = publishedSpec(spec, localVersion);
|
|
165
|
+
}
|
|
166
|
+
const bounds = readBounds(published.trim());
|
|
167
|
+
if (isCapped(bounds, localVersion)) return void 0;
|
|
168
|
+
const floor = localVersion ?? bounds?.floor ?? readFloor(published);
|
|
169
|
+
const expected = workspace ? CAPPED_WORKSPACE_SPEC : floor && cappedRange(floor);
|
|
170
|
+
return {
|
|
171
|
+
field,
|
|
172
|
+
name,
|
|
173
|
+
spec,
|
|
174
|
+
...local !== void 0 && { local },
|
|
175
|
+
...expected && { expected }
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** Whether `manifest` declares an `@antelopejs/*` package in a field this check reads. */
|
|
179
|
+
function declaresAntelopePackage(manifest) {
|
|
180
|
+
return CHECKED_FIELDS.some((field) => Object.keys(manifest[field] ?? {}).some((name) => name.startsWith(ANTELOPEJS_SCOPE)));
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The version of each named package among `manifests`, the packages that sit
|
|
184
|
+
* in the same repository. A name tracked at two versions, such as a test
|
|
185
|
+
* fixture that copies a real package's name, has no one local version and is
|
|
186
|
+
* left out.
|
|
187
|
+
*/
|
|
188
|
+
function localVersions(manifests) {
|
|
189
|
+
const versions = /* @__PURE__ */ new Map();
|
|
190
|
+
const ambiguous = /* @__PURE__ */ new Set();
|
|
191
|
+
for (const { name, version } of manifests) {
|
|
192
|
+
if (!name || !version) continue;
|
|
193
|
+
const seen = versions.get(name);
|
|
194
|
+
if (seen !== void 0 && seen !== version) ambiguous.add(name);
|
|
195
|
+
versions.set(name, version);
|
|
196
|
+
}
|
|
197
|
+
for (const name of ambiguous) versions.delete(name);
|
|
198
|
+
return versions;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The `@antelopejs/*` ranges of `manifest` that do not stop at the next minor
|
|
202
|
+
* of their floor. `localVersions` holds the versions of the packages that sit
|
|
203
|
+
* in the same repository: a range on one of them must also admit that
|
|
204
|
+
* version, which then decides the minor to stop below.
|
|
205
|
+
*/
|
|
206
|
+
function checkDependencyRanges(manifest, localVersions = /* @__PURE__ */ new Map()) {
|
|
207
|
+
const violations = [];
|
|
208
|
+
for (const field of CHECKED_FIELDS) for (const entry of Object.entries(manifest[field] ?? {})) {
|
|
209
|
+
const [name, spec] = entry;
|
|
210
|
+
if (!name.startsWith(ANTELOPEJS_SCOPE) || isLinkSpec(spec)) continue;
|
|
211
|
+
const violation = checkEntry(manifest, field, entry, localVersions.get(name));
|
|
212
|
+
if (violation) violations.push(violation);
|
|
213
|
+
}
|
|
214
|
+
return violations;
|
|
215
|
+
}
|
|
216
|
+
function describeViolation(violation) {
|
|
217
|
+
const { field, name, spec, local, expected } = violation;
|
|
218
|
+
return `${field}["${name}"] is "${spec}": AntelopeJS packages ship breaking changes in minor releases, so it must stop below the next minor${local === void 0 ? "" : ` and admit ${local}, the version in this repository`}; ${expected ? `use "${expected}"` : "declare it as >=<floor> <next minor> on 0.x or ~<floor> from 1.0"}`;
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/guardrails/dependency-ranges-sync.ts
|
|
222
|
+
/** Each tracked manifest that parses; a fixture that is not JSON is not a package this repository releases. */
|
|
223
|
+
function tracked(root) {
|
|
224
|
+
return trackedManifests(root).flatMap((path) => {
|
|
225
|
+
try {
|
|
226
|
+
const text = readFileSync(join(root, path), "utf8");
|
|
227
|
+
return [{
|
|
228
|
+
path,
|
|
229
|
+
text,
|
|
230
|
+
manifest: parseManifest(text)
|
|
231
|
+
}];
|
|
232
|
+
} catch {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function movedNote(path, violation) {
|
|
238
|
+
return `${path}: moved ${violation.field}["${violation.name}"] from "${violation.spec}" to "${violation.expected}", the range of the version this repository holds.`;
|
|
239
|
+
}
|
|
240
|
+
/** The relock failure, after which the moved manifests are back as they were so the next sync moves them again. */
|
|
241
|
+
function writeAndRelock(root, manifests, moved) {
|
|
242
|
+
const rootManifest = manifests.find(({ path }) => path === "package.json");
|
|
243
|
+
const manager = packageManager(rootManifest?.manifest ?? {});
|
|
244
|
+
if (manager !== "pnpm") return `${manager} is not pnpm, so sync cannot relock them.`;
|
|
245
|
+
for (const [path, { after }] of moved) writeFileSync(join(root, path), after);
|
|
246
|
+
const failure = runPnpm(root, ["install", "--lockfile-only"]);
|
|
247
|
+
if (failure !== void 0) for (const [path, { before }] of moved) writeFileSync(join(root, path), before);
|
|
248
|
+
return failure;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Moves each tracked manifest's range on a package that sits in this
|
|
252
|
+
* repository to the range `checkDependencyRanges` expects, then relocks, or
|
|
253
|
+
* leaves every manifest as it was when the relock fails. A minor release of
|
|
254
|
+
* that package otherwise leaves its dependents' ranges below the new version
|
|
255
|
+
* and fails the `dependency:ranges` check on the release commit. It runs
|
|
256
|
+
* before the rest of sync, which then plans the docs-compat READMEs from the
|
|
257
|
+
* moved ranges and the new lockfile. `check` reports the moves without
|
|
258
|
+
* writing.
|
|
259
|
+
*/
|
|
260
|
+
function moveDependencyRanges(root, check) {
|
|
261
|
+
const manifests = tracked(root);
|
|
262
|
+
const versions = localVersions(manifests.map(({ manifest }) => manifest));
|
|
263
|
+
const moves = {
|
|
264
|
+
paths: [],
|
|
265
|
+
notes: [],
|
|
266
|
+
errors: []
|
|
267
|
+
};
|
|
268
|
+
const moved = /* @__PURE__ */ new Map();
|
|
269
|
+
for (const { path, text, manifest } of manifests) {
|
|
270
|
+
const fixes = checkDependencyRanges(manifest, versions).filter((violation) => violation.local !== void 0 && violation.expected !== void 0);
|
|
271
|
+
if (!fixes.length) continue;
|
|
272
|
+
for (const { field, name, expected } of fixes) {
|
|
273
|
+
const dependencies = manifest[field];
|
|
274
|
+
if (dependencies && expected) dependencies[name] = expected;
|
|
275
|
+
}
|
|
276
|
+
moved.set(path, {
|
|
277
|
+
before: text,
|
|
278
|
+
after: serializeManifest(manifest, text)
|
|
279
|
+
});
|
|
280
|
+
moves.paths.push(path);
|
|
281
|
+
moves.notes.push(...fixes.map((fix) => movedNote(path, fix)));
|
|
282
|
+
}
|
|
283
|
+
if (check || !moved.size) return moves;
|
|
284
|
+
const failure = writeAndRelock(root, manifests, moved);
|
|
285
|
+
if (failure !== void 0) moves.errors.push(`Left the dependency ranges in ${moves.paths.join(", ")} unmoved: the lockfile could not follow them. ${failure}`);
|
|
286
|
+
return moves;
|
|
287
|
+
}
|
|
288
|
+
/** Whether a tracked manifest declares an `@antelopejs/*` package, so `checkRepositoryRanges` has a range to read. */
|
|
289
|
+
function hasDependencyRanges(root) {
|
|
290
|
+
return tracked(root).some(({ manifest }) => declaresAntelopePackage(manifest));
|
|
291
|
+
}
|
|
292
|
+
/** Each `@antelopejs/*` range in a tracked manifest that does not stop below the next minor, one line each; empty when every range does. */
|
|
293
|
+
function checkRepositoryRanges(root) {
|
|
294
|
+
const manifests = tracked(root);
|
|
295
|
+
const versions = localVersions(manifests.map(({ manifest }) => manifest));
|
|
296
|
+
return manifests.flatMap(({ path, manifest }) => checkDependencyRanges(manifest, versions).map((violation) => `${path}: ${describeViolation(violation)}\n`)).join("");
|
|
297
|
+
}
|
|
298
|
+
//#endregion
|
|
15
299
|
//#region src/guardrails/git-identity.ts
|
|
16
300
|
/** Config scopes stored inside the repository, which every checkout and agent sharing it commits under. */
|
|
17
301
|
const SHARED_SCOPES = /* @__PURE__ */ new Set(["local", "worktree"]);
|
|
@@ -43,6 +327,396 @@ async function checkGitIdentity(root, signal) {
|
|
|
43
327
|
return `The repository's git config sets a commit identity, so every checkout and agent sharing it commits as that identity:\n${shared.map((line) => ` ${line.split(" ").slice(1).join(" ")}\n`).join("")}Remove it with git config --local --unset-all user.name and git config --local --unset-all user.email (--worktree for a config.worktree), and set an identity with --global or per command with git -c.\n`;
|
|
44
328
|
}
|
|
45
329
|
//#endregion
|
|
330
|
+
//#region src/guardrails/published-entries.ts
|
|
331
|
+
/** The compiler options of the consumer: the strictest a consumer commonly sets, with every declaration file it loads checked. */
|
|
332
|
+
const CONSUMER_OPTIONS = {
|
|
333
|
+
module: "nodenext",
|
|
334
|
+
moduleResolution: "nodenext",
|
|
335
|
+
target: "esnext",
|
|
336
|
+
strict: true,
|
|
337
|
+
skipLibCheck: false,
|
|
338
|
+
noEmit: true,
|
|
339
|
+
types: ["node"]
|
|
340
|
+
};
|
|
341
|
+
/** The consumer files, an ES module that imports each entry and a CommonJS module that requires it, with the resolution mode TypeScript gives each. */
|
|
342
|
+
const CONSUMER_FILES = {
|
|
343
|
+
import: {
|
|
344
|
+
file: "consumer.mts",
|
|
345
|
+
mode: ts.ModuleKind.ESNext
|
|
346
|
+
},
|
|
347
|
+
require: {
|
|
348
|
+
file: "consumer.cts",
|
|
349
|
+
mode: ts.ModuleKind.CommonJS
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
const DECLARATION_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
353
|
+
ts.Extension.Dts,
|
|
354
|
+
ts.Extension.Dmts,
|
|
355
|
+
ts.Extension.Dcts
|
|
356
|
+
]);
|
|
357
|
+
const DECLARATION_FILE$1 = /\.d\.[cm]?ts$/;
|
|
358
|
+
/** An `exports` value that names declarations: a `types` condition or a `.d.ts`, `.d.mts` or `.d.cts` target. */
|
|
359
|
+
const NAMES_DECLARATIONS = /"types"\s*:|\.d\.[cm]?ts"/;
|
|
360
|
+
function isPath(target) {
|
|
361
|
+
return typeof target === "string";
|
|
362
|
+
}
|
|
363
|
+
/** Every path a subpath's value lists, under any condition. */
|
|
364
|
+
function targetPaths(target) {
|
|
365
|
+
if (target === null) return [];
|
|
366
|
+
if (isPath(target)) return [target];
|
|
367
|
+
return (Array.isArray(target) ? target : Object.values(target)).flatMap(targetPaths);
|
|
368
|
+
}
|
|
369
|
+
/** `exports` as a map of subpaths: a path, a list or a map of conditions stands for the `.` subpath. */
|
|
370
|
+
function subpaths(exports) {
|
|
371
|
+
if (exports === null || isPath(exports) || Array.isArray(exports)) return [[".", exports]];
|
|
372
|
+
const entries = Object.entries(exports);
|
|
373
|
+
return entries.every(([key]) => key.startsWith(".")) ? entries : [[".", exports]];
|
|
374
|
+
}
|
|
375
|
+
function patternMatcher(pattern) {
|
|
376
|
+
const [before = "", after = ""] = pattern.split("*");
|
|
377
|
+
const escape = (text) => text.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
378
|
+
return new RegExp(`^${escape(before)}(.+)${escape(after)}$`);
|
|
379
|
+
}
|
|
380
|
+
/** The subpaths a key stands for: itself, or, for a `*` key, one per shipped file a target of its value matches. */
|
|
381
|
+
function expanded(key, value, files) {
|
|
382
|
+
if (!key.includes("*")) return [key];
|
|
383
|
+
return targetPaths(value).flatMap((target) => {
|
|
384
|
+
const matcher = patternMatcher(target.replace(/^\.\//, ""));
|
|
385
|
+
return files.flatMap((file) => {
|
|
386
|
+
const star = matcher.exec(file)?.[1];
|
|
387
|
+
return star === void 0 ? [] : [key.replace("*", star)];
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
/** A specifier for each subpath of `exports`, with whether its value names declarations; a subpath naming a declaration file is left out, since no consumer imports one by name. */
|
|
392
|
+
function candidates(name, exports, files) {
|
|
393
|
+
const found = /* @__PURE__ */ new Map();
|
|
394
|
+
for (const [key, value] of subpaths(exports)) for (const subpath of expanded(key, value, files)) if (!DECLARATION_FILE$1.test(subpath)) found.set(`${name}${subpath.slice(1)}`, (found.get(`${name}${subpath.slice(1)}`) ?? false) || NAMES_DECLARATIONS.test(JSON.stringify(value)));
|
|
395
|
+
return found;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* The specifiers the consumer in `consumer` imports and requires from the package `name`, given the `files` it ships
|
|
399
|
+
* relative to its folder. Each `exports` subpath, a `*` subpath once per shipped file a target of it matches, is kept
|
|
400
|
+
* for a mode when TypeScript resolves it in that mode to a declaration file, or to JavaScript while its value names
|
|
401
|
+
* declarations, so a declaration file missing from the tarball fails. A subpath TypeScript does not resolve, such as one
|
|
402
|
+
* a `null` key hides or a stylesheet, is left out. A package without `exports` is imported by its bare name.
|
|
403
|
+
*/
|
|
404
|
+
function entrySpecifiers(name, exports, files, consumer) {
|
|
405
|
+
if (exports === void 0) return {
|
|
406
|
+
import: [name],
|
|
407
|
+
require: []
|
|
408
|
+
};
|
|
409
|
+
const { options } = ts.convertCompilerOptionsFromJson(CONSUMER_OPTIONS, consumer);
|
|
410
|
+
const found = [...candidates(name, exports, files)];
|
|
411
|
+
const kept = (mode) => found.flatMap(([specifier, namesDeclarations]) => {
|
|
412
|
+
const { resolvedModule } = ts.resolveModuleName(specifier, join(consumer, CONSUMER_FILES[mode].file), options, ts.sys, void 0, void 0, CONSUMER_FILES[mode].mode);
|
|
413
|
+
if (!resolvedModule) return [];
|
|
414
|
+
return DECLARATION_EXTENSIONS.has(resolvedModule.extension) || namesDeclarations ? [specifier] : [];
|
|
415
|
+
});
|
|
416
|
+
return {
|
|
417
|
+
import: kept("import"),
|
|
418
|
+
require: kept("require")
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/guardrails/published-types.ts
|
|
423
|
+
const DECLARATION_FILE = /\.d\.[cm]?ts$/;
|
|
424
|
+
/** An `exports` map that names declarations: a `types` condition or a `.d.ts`, `.d.mts` or `.d.cts` target. */
|
|
425
|
+
const TYPED_EXPORTS = /"types"\s*:|\.d\.[cm]?ts"/;
|
|
426
|
+
function declaresTypes(manifest) {
|
|
427
|
+
return manifest.types !== void 0 || manifest.typings !== void 0 || TYPED_EXPORTS.test(JSON.stringify(manifest.exports ?? null));
|
|
428
|
+
}
|
|
429
|
+
/** The root and workspace packages that are not `private`, with their manifests. */
|
|
430
|
+
function publicPackages(root) {
|
|
431
|
+
return ["", ...workspaceDirectories(root)].flatMap((directory) => {
|
|
432
|
+
const manifest = parseManifest(readFileSync(join(root, directory, "package.json"), "utf8"));
|
|
433
|
+
const { name } = manifest;
|
|
434
|
+
return name && manifest.private !== true ? [{
|
|
435
|
+
directory,
|
|
436
|
+
name,
|
|
437
|
+
manifest
|
|
438
|
+
}] : [];
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/** The root and workspace packages that are not `private` and declare declarations through `types`, `typings` or `exports`. */
|
|
442
|
+
function typedPackages(root) {
|
|
443
|
+
return publicPackages(root).filter(({ manifest }) => declaresTypes(manifest)).map(({ directory, name }) => ({
|
|
444
|
+
directory,
|
|
445
|
+
name
|
|
446
|
+
}));
|
|
447
|
+
}
|
|
448
|
+
/** The arguments that install a consumer's dependencies without a lockfile and without running install scripts. */
|
|
449
|
+
const INSTALL_ARGUMENTS = {
|
|
450
|
+
pnpm: [
|
|
451
|
+
"install",
|
|
452
|
+
"--ignore-scripts",
|
|
453
|
+
"--prefer-offline",
|
|
454
|
+
"--no-frozen-lockfile"
|
|
455
|
+
],
|
|
456
|
+
npm: [
|
|
457
|
+
"install",
|
|
458
|
+
"--ignore-scripts",
|
|
459
|
+
"--prefer-offline",
|
|
460
|
+
"--no-audit",
|
|
461
|
+
"--no-fund"
|
|
462
|
+
]
|
|
463
|
+
};
|
|
464
|
+
/** The files under `directory`, relative to it with `/` separators, its `node_modules` left out. */
|
|
465
|
+
function shippedFiles(directory, prefix = "") {
|
|
466
|
+
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
467
|
+
const path = `${prefix}${entry.name}`;
|
|
468
|
+
if (entry.isDirectory()) return entry.name === "node_modules" ? [] : shippedFiles(join(directory, entry.name), `${path}/`);
|
|
469
|
+
return entry.isFile() ? [path] : [];
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
/** `output` with the consumer's own path and the package manager's store path before the package removed, so each error names the file as `<name>/<path>`. */
|
|
473
|
+
function readable(output, consumer, name) {
|
|
474
|
+
const store = new RegExp(String.raw`(?:node_modules/\.pnpm/[^/\s]+/)?node_modules/${name.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")}/`, "g");
|
|
475
|
+
return [consumer, consumer.replaceAll("\\", "/")].reduce((text, path) => text.split(`${path}/`).join(""), output).replace(store, `${name}/`);
|
|
476
|
+
}
|
|
477
|
+
const TAR_BLOCK = 512;
|
|
478
|
+
/** The text of the entry `path` in the gzipped tar archive `tarball`, read in Node so no `tar` binary, which differs across platforms, is needed. */
|
|
479
|
+
function tarEntry(tarball, path) {
|
|
480
|
+
const archive = gunzipSync(readFileSync(tarball));
|
|
481
|
+
for (let offset = 0; offset + TAR_BLOCK <= archive.length;) {
|
|
482
|
+
const header = archive.subarray(offset, offset + TAR_BLOCK);
|
|
483
|
+
const name = header.toString("utf8", 0, 100).replace(/\0.*$/s, "");
|
|
484
|
+
if (!name) return void 0;
|
|
485
|
+
const size = Number.parseInt(header.toString("utf8", 124, 136), 8) || 0;
|
|
486
|
+
const start = offset + TAR_BLOCK;
|
|
487
|
+
if (name === path) return archive.toString("utf8", start, start + size);
|
|
488
|
+
offset = start + Math.ceil(size / TAR_BLOCK) * TAR_BLOCK;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
function packedManifest(destination) {
|
|
492
|
+
const [file = ""] = readdirSync(destination);
|
|
493
|
+
const tarball = join(destination, file);
|
|
494
|
+
const text = tarEntry(tarball, "package/package.json");
|
|
495
|
+
return text === void 0 ? { failure: `${file} holds no package/package.json.\n` } : {
|
|
496
|
+
failure: "",
|
|
497
|
+
tarball,
|
|
498
|
+
manifest: parseManifest(text)
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
/** Packs the package `name` once per run, running its `prepack`, and reads the manifest its tarball holds. */
|
|
502
|
+
async function pack(run, name) {
|
|
503
|
+
const cached = run.packs.get(name);
|
|
504
|
+
if (cached) return cached;
|
|
505
|
+
const slot = String(run.packs.size);
|
|
506
|
+
const destination = join(run.scratch, "tarballs", slot);
|
|
507
|
+
mkdirSync(destination, { recursive: true });
|
|
508
|
+
const result = await runCommand(run.manager, [
|
|
509
|
+
"pack",
|
|
510
|
+
"--pack-destination",
|
|
511
|
+
destination
|
|
512
|
+
], {
|
|
513
|
+
cwd: join(run.root, run.members.get(name) ?? ""),
|
|
514
|
+
signal: run.signal
|
|
515
|
+
});
|
|
516
|
+
const packed = result.status === 0 ? packedManifest(destination) : { failure: `Packing ${name} failed:\n${result.output}` };
|
|
517
|
+
run.packs.set(name, packed);
|
|
518
|
+
return packed;
|
|
519
|
+
}
|
|
520
|
+
function dependencyNames(manifest) {
|
|
521
|
+
return [
|
|
522
|
+
manifest.dependencies,
|
|
523
|
+
manifest.optionalDependencies,
|
|
524
|
+
manifest.peerDependencies
|
|
525
|
+
].flatMap((ranges) => Object.keys(ranges ?? {}));
|
|
526
|
+
}
|
|
527
|
+
/** The tarball of each package of the repository that `name`'s packed manifest depends on, directly or through another such package, by name. */
|
|
528
|
+
async function siblingTarballs(run, name, manifest) {
|
|
529
|
+
const tarballs = /* @__PURE__ */ new Map();
|
|
530
|
+
const pending = [manifest];
|
|
531
|
+
for (let next = pending.pop(); next; next = pending.pop()) for (const dependency of dependencyNames(next)) {
|
|
532
|
+
if (dependency === name || tarballs.has(dependency)) continue;
|
|
533
|
+
if (!run.members.has(dependency)) continue;
|
|
534
|
+
const sibling = await pack(run, dependency);
|
|
535
|
+
if (!("tarball" in sibling)) return {
|
|
536
|
+
failure: sibling.failure,
|
|
537
|
+
tarballs
|
|
538
|
+
};
|
|
539
|
+
tarballs.set(dependency, `file:${sibling.tarball}`);
|
|
540
|
+
pending.push(sibling.manifest);
|
|
541
|
+
}
|
|
542
|
+
return {
|
|
543
|
+
failure: "",
|
|
544
|
+
tarballs
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
/** Writes the consumer's `package.json`, and for pnpm its `pnpm-workspace.yaml` in block style, which pnpm edits when it records a setting, so each sibling resolves to its tarball wherever it is required. */
|
|
548
|
+
function writeConsumer(consumer, manager, dependencies, overrides) {
|
|
549
|
+
const manifest = {
|
|
550
|
+
name: "published-types-consumer",
|
|
551
|
+
private: true,
|
|
552
|
+
dependencies
|
|
553
|
+
};
|
|
554
|
+
writeFileSync(join(consumer, "package.json"), JSON.stringify(manager === "npm" ? {
|
|
555
|
+
...manifest,
|
|
556
|
+
overrides
|
|
557
|
+
} : {
|
|
558
|
+
...manifest,
|
|
559
|
+
pnpm: { overrides }
|
|
560
|
+
}));
|
|
561
|
+
if (manager === "pnpm") writeFileSync(join(consumer, "pnpm-workspace.yaml"), stringify({
|
|
562
|
+
packages: ["."],
|
|
563
|
+
overrides
|
|
564
|
+
}));
|
|
565
|
+
}
|
|
566
|
+
async function typecheck(run, consumer, typed, manifest) {
|
|
567
|
+
const installed = realpathSync(join(consumer, "node_modules", typed.name));
|
|
568
|
+
const files = shippedFiles(installed);
|
|
569
|
+
const entries = entrySpecifiers(typed.name, manifest.exports, files, consumer);
|
|
570
|
+
const lines = {
|
|
571
|
+
import: entries.import.map((specifier, index) => `import type * as entry${index} from ${JSON.stringify(specifier)};\n`),
|
|
572
|
+
require: entries.require.map((specifier, index) => `import entry${index} = require(${JSON.stringify(specifier)});\n`)
|
|
573
|
+
};
|
|
574
|
+
const written = ["import", "require"].flatMap((mode) => {
|
|
575
|
+
if (!lines[mode].length) return [];
|
|
576
|
+
const { file } = CONSUMER_FILES[mode];
|
|
577
|
+
writeFileSync(join(consumer, file), lines[mode].join(""));
|
|
578
|
+
return [file];
|
|
579
|
+
});
|
|
580
|
+
const deep = manifest.exports === void 0 ? files.filter((file) => DECLARATION_FILE.test(file)).map((file) => relative(consumer, join(installed, file))) : [];
|
|
581
|
+
writeFileSync(join(consumer, "tsconfig.json"), JSON.stringify({
|
|
582
|
+
compilerOptions: CONSUMER_OPTIONS,
|
|
583
|
+
files: [...written, ...deep]
|
|
584
|
+
}));
|
|
585
|
+
const typescript = join(consumer, "node_modules", "typescript");
|
|
586
|
+
const { bin } = parseManifest(readFileSync(join(typescript, "package.json"), "utf8"));
|
|
587
|
+
const tsc = await runCommand(process.execPath, [
|
|
588
|
+
join(typescript, bin?.tsc ?? "bin/tsc"),
|
|
589
|
+
"-p",
|
|
590
|
+
".",
|
|
591
|
+
"--pretty",
|
|
592
|
+
"false"
|
|
593
|
+
], {
|
|
594
|
+
cwd: consumer,
|
|
595
|
+
signal: run.signal,
|
|
596
|
+
shell: false
|
|
597
|
+
});
|
|
598
|
+
return tsc.status === 0 ? "" : readable(tsc.output, consumer, typed.name);
|
|
599
|
+
}
|
|
600
|
+
async function consumerErrors(run, typed, slot) {
|
|
601
|
+
const packed = await pack(run, typed.name);
|
|
602
|
+
if (!("tarball" in packed)) return packed.failure;
|
|
603
|
+
const siblings = await siblingTarballs(run, typed.name, packed.manifest);
|
|
604
|
+
if (siblings.failure) return siblings.failure;
|
|
605
|
+
const consumer = join(run.scratch, `consumer-${slot}`);
|
|
606
|
+
mkdirSync(consumer);
|
|
607
|
+
const overrides = {
|
|
608
|
+
...Object.fromEntries(siblings.tarballs),
|
|
609
|
+
[typed.name]: `file:${packed.tarball}`
|
|
610
|
+
};
|
|
611
|
+
writeConsumer(consumer, run.manager, {
|
|
612
|
+
typescript: "latest",
|
|
613
|
+
"@types/node": "latest",
|
|
614
|
+
...packed.manifest.peerDependencies,
|
|
615
|
+
...overrides
|
|
616
|
+
}, overrides);
|
|
617
|
+
const install = await runCommand(run.manager, INSTALL_ARGUMENTS[run.manager], {
|
|
618
|
+
cwd: consumer,
|
|
619
|
+
signal: run.signal
|
|
620
|
+
});
|
|
621
|
+
if (install.status !== 0) return `Installing the tarball failed:\n${install.output}`;
|
|
622
|
+
return typecheck(run, consumer, typed, packed.manifest);
|
|
623
|
+
}
|
|
624
|
+
function packsWithPnpmOrNpm(manager) {
|
|
625
|
+
return manager === "pnpm" || manager === "npm";
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Packs each package `typedPackages` finds, running its `prepack`, and installs the tarball alone in a scratch
|
|
629
|
+
* directory with its peers, optional ones included, `typescript` and `@types/node` at the latest version unless it
|
|
630
|
+
* names them as peers, and the tarball of each package of the repository it depends on in place of the registry's.
|
|
631
|
+
* Then runs `tsc` with `skipLibCheck` off over a consumer file importing each entry its `exports` names, or, without
|
|
632
|
+
* `exports`, the package itself and every declaration file it ships. Returns what failed, each package's errors under
|
|
633
|
+
* its `package.json`, empty when every package passed.
|
|
634
|
+
*/
|
|
635
|
+
async function checkPublishedTypes(root, signal) {
|
|
636
|
+
const manager = packageManager(parseManifest(readFileSync(join(root, "package.json"), "utf8")));
|
|
637
|
+
if (!packsWithPnpmOrNpm(manager)) return `This check packs with pnpm or npm, not ${manager}.\n`;
|
|
638
|
+
const scratch = realpathSync.native(mkdtempSync(join(tmpdir(), "published-types-")));
|
|
639
|
+
const run = {
|
|
640
|
+
root,
|
|
641
|
+
manager,
|
|
642
|
+
scratch,
|
|
643
|
+
signal,
|
|
644
|
+
members: new Map(publicPackages(root).map(({ name, directory }) => [name, directory])),
|
|
645
|
+
packs: /* @__PURE__ */ new Map()
|
|
646
|
+
};
|
|
647
|
+
let failures = "";
|
|
648
|
+
try {
|
|
649
|
+
for (const [slot, typed] of typedPackages(root).entries()) {
|
|
650
|
+
if (signal?.aborted) break;
|
|
651
|
+
const failure = await consumerErrors(run, typed, slot);
|
|
652
|
+
if (failure) failures += `${join(typed.directory, "package.json")}: ${typed.name} as a consumer installs it, checked by tsc with skipLibCheck off:\n${failure}`;
|
|
653
|
+
}
|
|
654
|
+
} finally {
|
|
655
|
+
rmSync(scratch, {
|
|
656
|
+
recursive: true,
|
|
657
|
+
force: true
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
return failures;
|
|
661
|
+
}
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/guardrails/readme-version.ts
|
|
664
|
+
/** An object literal holding no other, such as a config example's `source: { package, version }`. */
|
|
665
|
+
const FLAT_OBJECT = /\{[^{}]*\}/g;
|
|
666
|
+
function stringField(body, key) {
|
|
667
|
+
return new RegExp(String.raw`(?<![\w$-])["']?${key}["']?\s*:\s*["']([^"'\n]+)["']`).exec(body);
|
|
668
|
+
}
|
|
669
|
+
function relative$1(directory, file) {
|
|
670
|
+
return directory ? `${directory}/${file}` : file;
|
|
671
|
+
}
|
|
672
|
+
/** The repository root and its workspace package directories, relative to `root`, the root as `""`. */
|
|
673
|
+
function packageDirectories(root) {
|
|
674
|
+
return ["", ...workspaceDirectories(root)];
|
|
675
|
+
}
|
|
676
|
+
function ownPackages(root) {
|
|
677
|
+
const packages = /* @__PURE__ */ new Map();
|
|
678
|
+
for (const directory of packageDirectories(root)) {
|
|
679
|
+
const manifest = relative$1(directory, "package.json");
|
|
680
|
+
const { name, version } = parseManifest(readFileSync(join(root, manifest), "utf8"));
|
|
681
|
+
if (name && version) packages.set(name, {
|
|
682
|
+
version,
|
|
683
|
+
manifest
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
return packages;
|
|
687
|
+
}
|
|
688
|
+
function examplesIn(readme, text, packages) {
|
|
689
|
+
return [...text.matchAll(FLAT_OBJECT)].flatMap((object) => {
|
|
690
|
+
const name = stringField(object[0], "package")?.[1];
|
|
691
|
+
const owner = name === void 0 ? void 0 : packages.get(name);
|
|
692
|
+
const field = stringField(object[0], "version");
|
|
693
|
+
const range = field?.[1];
|
|
694
|
+
if (!name || !owner || !field || range === void 0) return [];
|
|
695
|
+
return [{
|
|
696
|
+
readme,
|
|
697
|
+
line: text.slice(0, object.index + field.index).split("\n").length,
|
|
698
|
+
name,
|
|
699
|
+
range,
|
|
700
|
+
owner
|
|
701
|
+
}];
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
/** The config examples in the `README.md` of the root and of each workspace package that give one of the repository's own packages, by its `package.json` `name`, a `version`. */
|
|
705
|
+
function readmeExamples(root) {
|
|
706
|
+
const readmes = packageDirectories(root).map((directory) => relative$1(directory, "README.md")).filter((readme) => existsSync(join(root, readme)));
|
|
707
|
+
if (!readmes.length) return [];
|
|
708
|
+
const packages = ownPackages(root);
|
|
709
|
+
return readmes.flatMap((readme) => examplesIn(readme, readFileSync(join(root, readme), "utf8"), packages));
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Fails for each README config example whose `version` range, read as npm reads it, does not admit the `version` in
|
|
713
|
+
* the named package's `package.json`, naming the README line; empty when every one does. A value that is not a range,
|
|
714
|
+
* such as a dist-tag, passes.
|
|
715
|
+
*/
|
|
716
|
+
function checkReadmeVersion(root) {
|
|
717
|
+
return readmeExamples(root).filter(({ range, owner }) => validRange(range) !== null && !satisfies(owner.version, range)).map(({ readme, line, name, range, owner }) => `${readme}:${line} gives ${name} the version range "${range}", which does not admit ${owner.version}, the version in ${owner.manifest}. Set a range that admits it.\n`).join("");
|
|
718
|
+
}
|
|
719
|
+
//#endregion
|
|
46
720
|
//#region src/guardrails/services.ts
|
|
47
721
|
/** The compose file the shared CI starts through its `services-compose-file` input, relative to the repository root. */
|
|
48
722
|
const COMPOSE_FILE = ".github/compose.yml";
|
|
@@ -190,24 +864,42 @@ function isLayerCode(layer, file) {
|
|
|
190
864
|
const segments = relative(layer, file).split(sep);
|
|
191
865
|
return segments[0] !== LAYER_PLAYGROUND && !segments.some((segment) => NOT_LAYER_CODE.has(segment));
|
|
192
866
|
}
|
|
867
|
+
/** The packages whose `tsc` a repository runs, in order: `typescript`, else `@typescript/native` when `typescript` is the TypeScript 6 API (`@typescript/typescript6`, whose only bin is `tsc6`) installed beside TypeScript 7 for tools that need that API. */
|
|
868
|
+
const COMPILER_PACKAGES = ["typescript", "@typescript/native"];
|
|
193
869
|
/**
|
|
194
|
-
* The
|
|
195
|
-
*
|
|
196
|
-
*
|
|
870
|
+
* The `package.json` of the package `name` in the nearest `node_modules` from `root` up, where a workspace may hoist it.
|
|
871
|
+
* Node's resolution is not used: it falls back to `NODE_PATH`, where a package manager's bin shim lists the pack's own
|
|
872
|
+
* dependencies, so a repository without TypeScript would be checked with the pack's.
|
|
197
873
|
*/
|
|
198
|
-
function
|
|
874
|
+
function manifestOf(root, name) {
|
|
875
|
+
for (let folder = resolve(root);; folder = dirname(folder)) {
|
|
876
|
+
const manifestPath = join(folder, "node_modules", name, "package.json");
|
|
877
|
+
if (existsSync(manifestPath)) return manifestPath;
|
|
878
|
+
if (dirname(folder) === folder) return void 0;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
/** The `bin.tsc` entry of the package `name` that `root` installs, read from its `package.json`, a file every TypeScript version ships, because TypeScript 7 declares an `exports` map that leaves `typescript/bin/tsc` out. */
|
|
882
|
+
function binTsc(root, name) {
|
|
883
|
+
const manifestPath = manifestOf(root, name);
|
|
884
|
+
if (manifestPath === void 0) return void 0;
|
|
199
885
|
try {
|
|
200
|
-
const manifestPath = createRequire(join(root, "package.json")).resolve("typescript/package.json");
|
|
201
886
|
const tsc = parseManifest(readFileSync(manifestPath, "utf8")).bin?.tsc;
|
|
202
887
|
return tsc === void 0 ? void 0 : join(dirname(manifestPath), tsc);
|
|
203
888
|
} catch {
|
|
204
889
|
return;
|
|
205
890
|
}
|
|
206
891
|
}
|
|
892
|
+
/** The repository's own `tsc` entry, run with Node so no shell parses its path. */
|
|
893
|
+
function compilerOf(root) {
|
|
894
|
+
for (const name of COMPILER_PACKAGES) {
|
|
895
|
+
const tsc = binTsc(root, name);
|
|
896
|
+
if (tsc !== void 0) return tsc;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
207
899
|
async function typecheckLayer(root, compiler, layer, signal) {
|
|
208
900
|
const configPath = join(root, layer, TSCONFIG);
|
|
209
901
|
if (!existsSync(configPath)) return `${layer}: has a verify.config.ts and no tsconfig.json. Add a tsconfig.json that includes its TypeScript files; antelopejs-sync writes one for the shared kinds.\n`;
|
|
210
|
-
const ts = (await import("typescript")).default;
|
|
902
|
+
const ts = (await import("@typescript/typescript6")).default;
|
|
211
903
|
const parsed = ts.getParsedCommandLineOfConfigFile(configPath, void 0, {
|
|
212
904
|
...ts.sys,
|
|
213
905
|
onUnRecoverableConfigFileDiagnostic: () => void 0
|
|
@@ -263,7 +955,7 @@ async function typecheckLayers(root, signal) {
|
|
|
263
955
|
const layers = verifyLayers(root);
|
|
264
956
|
if (layers.length === 0) return "";
|
|
265
957
|
const compiler = compilerOf(root);
|
|
266
|
-
if (compiler === void 0) return "TypeScript is not installed in the repository root: run the package manager's install
|
|
958
|
+
if (compiler === void 0) return "TypeScript is not installed in the repository root: add typescript to its devDependencies and run the package manager's install.\n";
|
|
267
959
|
return (await Promise.all(layers.map((layer) => typecheckLayer(root, compiler, layer, signal)))).join("");
|
|
268
960
|
}
|
|
269
961
|
//#endregion
|
|
@@ -917,21 +1609,30 @@ const CHECK_STEPS = [
|
|
|
917
1609
|
"verify:types",
|
|
918
1610
|
"verify:lockfiles",
|
|
919
1611
|
"lockfile:singletons",
|
|
920
|
-
"
|
|
1612
|
+
"dependency:ranges",
|
|
1613
|
+
"git:identity",
|
|
1614
|
+
"readme:version",
|
|
1615
|
+
"published:types"
|
|
921
1616
|
];
|
|
922
1617
|
/** Steps `antelopejs-checks` runs itself, no package.json script behind them: each returns what failed, empty when it passed. */
|
|
923
1618
|
const OWN_STEPS = /* @__PURE__ */ new Map([
|
|
924
1619
|
["verify:types", typecheckLayers],
|
|
925
1620
|
["verify:lockfiles", (root) => Promise.resolve(checkLockfiles(root))],
|
|
926
1621
|
["lockfile:singletons", (root) => Promise.resolve(checkSingletonPackages(root))],
|
|
927
|
-
["
|
|
1622
|
+
["dependency:ranges", (root) => Promise.resolve(checkRepositoryRanges(root))],
|
|
1623
|
+
["git:identity", checkGitIdentity],
|
|
1624
|
+
["readme:version", (root) => Promise.resolve(checkReadmeVersion(root))],
|
|
1625
|
+
["published:types", checkPublishedTypes]
|
|
928
1626
|
]);
|
|
929
1627
|
function hasWork(root, step) {
|
|
930
1628
|
if (step === "ratchet") return existsSync(join(root, CEILINGS_FILE));
|
|
931
1629
|
if (step === "verify:types") return verifyLayers(root).length > 0;
|
|
932
1630
|
if (step === "verify:lockfiles") return verifyInstallFolders(root).length > 0;
|
|
933
1631
|
if (step === "lockfile:singletons") return pnpmLockfiles(root).length > 0;
|
|
1632
|
+
if (step === "dependency:ranges") return isGitCheckout(root) && hasDependencyRanges(root);
|
|
934
1633
|
if (step === "git:identity") return isGitCheckout(root);
|
|
1634
|
+
if (step === "readme:version") return readmeExamples(root).length > 0;
|
|
1635
|
+
if (step === "published:types") return typedPackages(root).length > 0;
|
|
935
1636
|
return true;
|
|
936
1637
|
}
|
|
937
1638
|
/** A command that runs a package script: the package manager, an optional `run`, then the script name. */
|
|
@@ -961,18 +1662,21 @@ function droppedChecksSteps(current, synced) {
|
|
|
961
1662
|
if (!dropped.length) return [];
|
|
962
1663
|
return [`package.json: the checks script now runs ${command}, which does not run ${dropped.map((step) => `"${step}"`).join(", ")} from the replaced script. Call each from one of its steps, such as test or lint, or it no longer runs in checks.`];
|
|
963
1664
|
}
|
|
964
|
-
/**
|
|
965
|
-
|
|
1665
|
+
/**
|
|
1666
|
+
* The steps that run after the others, each alone and in this order: tests often hold time limits that CPU contention
|
|
1667
|
+
* would break, and `published:types` packs each package, whose `prepack` rebuilds the output other steps and tests read.
|
|
1668
|
+
*/
|
|
1669
|
+
const RUNS_ALONE = ["test", "published:types"];
|
|
966
1670
|
/** The step that runs before the others when it writes files, such as a workspace package's `dist`, that they read. */
|
|
967
1671
|
const RUNS_FIRST = "typecheck";
|
|
968
1672
|
/** The groups of steps that run one after another, the steps of a group at the same time. */
|
|
969
1673
|
function phases(root, steps) {
|
|
970
1674
|
const first = steps.includes(RUNS_FIRST) && typecheckWrites(root) ? [RUNS_FIRST] : [];
|
|
971
|
-
const
|
|
1675
|
+
const alone = RUNS_ALONE.filter((step) => steps.includes(step));
|
|
972
1676
|
return [
|
|
973
1677
|
first,
|
|
974
|
-
steps.filter((step) => !first.includes(step) && !
|
|
975
|
-
|
|
1678
|
+
steps.filter((step) => !first.includes(step) && !alone.includes(step)),
|
|
1679
|
+
...alone.map((step) => [step])
|
|
976
1680
|
].filter((phase) => phase.length > 0);
|
|
977
1681
|
}
|
|
978
1682
|
/** The environment variable naming, comma-separated, the steps `runChecks` leaves to another CI job. */
|
|
@@ -1035,7 +1739,7 @@ function summary(failures, passed, skipped) {
|
|
|
1035
1739
|
/**
|
|
1036
1740
|
* Runs the `checks:prepare` package script first when it exists and a step will run, and stops there if it fails.
|
|
1037
1741
|
* Then runs `typecheck` first when it writes files the other steps read (see `typecheckWrites`), every other check step
|
|
1038
|
-
* except `test` at the same time, then
|
|
1742
|
+
* except `test` and `published:types` at the same time, then each of those alone, and reports only what failed, each step's
|
|
1039
1743
|
* output buffered and listed in step order whichever step finishes first. `skipSetting` is the comma-separated value of
|
|
1040
1744
|
* `ANTELOPEJS_CHECKS_SKIP`: the steps it names are not run and are counted as skipped, never as passed, and a name that
|
|
1041
1745
|
* is not a step fails the run before any step starts so a typo cannot skip nothing. Unless `services` is false, the
|
|
@@ -1084,4 +1788,4 @@ async function runChecks(root, options = {}) {
|
|
|
1084
1788
|
};
|
|
1085
1789
|
}
|
|
1086
1790
|
//#endregion
|
|
1087
|
-
export { stepsOf as a, matchingScripts as i, droppedChecksSteps as n, runChecks as r, CHECKS_SKIP_ENV as t };
|
|
1791
|
+
export { stepsOf as a, matchingScripts as i, droppedChecksSteps as n, moveDependencyRanges as o, runChecks as r, runPnpm as s, CHECKS_SKIP_ENV as t };
|