@antelopejs/tooling-configs 0.2.15 → 0.2.17
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 +88 -48
- package/dist/bin/api-diff.mjs +409 -97
- package/dist/bin/body-check.d.mts +1 -0
- package/dist/bin/body-check.mjs +344 -0
- package/dist/bin/check-size.mjs +3 -3
- package/dist/bin/checks.mjs +3 -3
- package/dist/bin/comment-proof.mjs +4 -3
- package/dist/bin/garden.mjs +5 -5
- package/dist/bin/ratchet.mjs +267 -7
- package/dist/bin/suppressions.mjs +118 -80
- package/dist/bin/sync.mjs +490 -35
- package/dist/bin/verify.mjs +48 -26
- package/dist/{ceilings-BSw9p4YB.mjs → ceilings-B7KayYIG.mjs} +11 -3
- package/dist/{checks-BlWDFYio.mjs → checks-CxkSu2E6.mjs} +1 -1
- package/dist/{ci-workflow-C0nT5SnX.mjs → ci-workflow-ChW4He0r.mjs} +103 -3
- package/dist/{files-2FikHZ9F.mjs → files-Bc036sJW.mjs} +2 -2
- package/dist/{json-BqvuCkqr.mjs → json-CG2L7YFl.mjs} +12 -8
- package/dist/oxc/anti-slop/index.mjs +160 -13
- package/dist/oxc/fmt.mjs +1 -1
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +645 -1
- package/dist/oxc/lint.d.mts +11 -3
- package/dist/oxc/lint.mjs +21 -8
- package/dist/oxlint-Bltmk8-6.mjs +94 -0
- package/dist/{package-Dtjt_lSa.mjs → package-DTxLPNDu.mjs} +3 -2
- package/dist/proof-stamp-w-3j47A-.mjs +279 -0
- package/dist/ratchet-DwRj9h4L.mjs +275 -0
- package/dist/{renames-BGO4dWJ8.mjs → renames-L2owF5GD.mjs} +2 -2
- package/dist/shared-CoUt4GUm.mjs +73 -0
- package/dist/{size-BVgNbLO6.mjs → size-DNtWruCO.mjs} +3 -3
- package/dist/suppression-base-DAfCXwjL.mjs +95 -0
- package/dist/{suppression-budget-Yyf5_J5l.mjs → suppression-budget-Bd2GqMYb.mjs} +248 -33
- package/dist/{suppressions-BJAngUxo.mjs → suppressions-BD_f8f7L.mjs} +180 -18
- package/dist/typescript-BmS5BmrS.mjs +222 -0
- package/dist/verify/index.mjs +1 -1
- package/package.json +4 -2
- package/dist/kinds-Bzyyi9yk.mjs +0 -25
- package/dist/ratchet-DRdIYwmv.mjs +0 -80
- package/dist/shared-CsXIMK3I.mjs +0 -34
- package/dist/staged-ratchet-CjoRfZaM.mjs +0 -236
- package/dist/typescript-C54ONh9m.mjs +0 -433
package/dist/bin/api-diff.mjs
CHANGED
|
@@ -1,102 +1,121 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
3
|
-
import { o as repositoryRoot } from "../files-
|
|
4
|
-
import { i as parseManifest, r as packageManager } from "../package-
|
|
5
|
-
import { a as
|
|
3
|
+
import { o as repositoryRoot, s as resolveRevision } from "../files-Bc036sJW.mjs";
|
|
4
|
+
import { i as parseManifest, r as packageManager } from "../package-DTxLPNDu.mjs";
|
|
5
|
+
import { a as DIRECTORY_LINK, c as revisionCounts, d as describeAllowance, f as fillStars, i as stampProof, l as allowedByGlob, o as compareRevisions, p as recordVerdict, u as createAddedPolicy } from "../proof-stamp-w-3j47A-.mjs";
|
|
6
|
+
import { a as outputRoot, i as loadTypeScript, n as isExportPath, o as packagesAt, r as isTestSource, s as unpublishedAt, t as emitPackage } from "../typescript-BmS5BmrS.mjs";
|
|
6
7
|
import { createRequire } from "node:module";
|
|
7
|
-
import { copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
8
|
-
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
8
|
+
import { copyFileSync, cpSync, existsSync, globSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { basename, dirname, isAbsolute, join, parse, posix, relative, resolve } from "node:path";
|
|
9
10
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
10
11
|
import { parseArgs } from "node:util";
|
|
11
12
|
import { availableParallelism, freemem } from "node:os";
|
|
12
|
-
//#region src/guardrails/
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
31
|
-
const DRIVER = `
|
|
32
|
-
const { spawn } = require("node:child_process");
|
|
33
|
-
const [flags, worker, ...jobs] = process.argv.slice(1);
|
|
34
|
-
let failed = false;
|
|
35
|
-
let pending = jobs.length;
|
|
36
|
-
for (const job of jobs) {
|
|
37
|
-
spawn(process.execPath, [...JSON.parse(flags), worker, job], { stdio: ["ignore", "inherit", "inherit"] }).on("exit", (code) => {
|
|
38
|
-
failed ||= code !== 0;
|
|
39
|
-
pending -= 1;
|
|
40
|
-
if (pending === 0) process.exit(failed ? 1 : 0);
|
|
41
|
-
});
|
|
13
|
+
//#region src/guardrails/auto-import-globals.ts
|
|
14
|
+
/** Where the generated Vite config takes the dms-frontend auto-imports from, relative to the `@antelopejs/dms-frontend` package. */
|
|
15
|
+
const FRONTEND_MODULE = join("node_modules", "@antelopejs", "dms-frontend", "templates", "vue", "frontend-module.ts");
|
|
16
|
+
const NAME_SEPARATOR = /[-_.]/u;
|
|
17
|
+
const SOURCE_EXTENSION = /(?:\.d)?\.[cm]?[jt]sx?$/u;
|
|
18
|
+
/** The name unimport gives a default export: the file name, or its directory's for an index file, in camel case when it has a separator. */
|
|
19
|
+
function defaultExportName(file) {
|
|
20
|
+
const own = parse(file).name;
|
|
21
|
+
const name = own === "index" ? parse(dirname(file)).name : own;
|
|
22
|
+
if (!NAME_SEPARATOR.test(name)) return name;
|
|
23
|
+
return name.split(/[-_.]+/u).filter(Boolean).map((word, index) => index === 0 ? `${word.charAt(0).toLowerCase()}${word.slice(1)}` : `${word.charAt(0).toUpperCase()}${word.slice(1)}`).join("");
|
|
24
|
+
}
|
|
25
|
+
function frontendModule(moduleRoot) {
|
|
26
|
+
for (let directory = moduleRoot;; directory = dirname(directory)) {
|
|
27
|
+
if (existsSync(join(directory, FRONTEND_MODULE))) return join(directory, FRONTEND_MODULE);
|
|
28
|
+
if (dirname(directory) === directory) return void 0;
|
|
29
|
+
}
|
|
42
30
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
recursive: true,
|
|
51
|
-
filter: (path) => basename(path) !== "node_modules"
|
|
31
|
+
/** The modules besides the scanned files whose exports the frontend build auto-imports: dms-frontend's `frontend-module.ts` and the `vue` preset, each with the specifier a scanned file imports it by. */
|
|
32
|
+
function presetModules(compiler, moduleRoot, options) {
|
|
33
|
+
const presets = [];
|
|
34
|
+
const frontend = frontendModule(moduleRoot);
|
|
35
|
+
if (frontend !== void 0) presets.push({
|
|
36
|
+
file: frontend,
|
|
37
|
+
specifier: frontend.replace(SOURCE_EXTENSION, "")
|
|
52
38
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
39
|
+
const vue = compiler.resolveModuleName("vue", join(moduleRoot, "auto-imports.ts"), options, compiler.sys).resolvedModule?.resolvedFileName;
|
|
40
|
+
if (vue !== void 0) presets.push({
|
|
41
|
+
file: vue,
|
|
42
|
+
specifier: "vue"
|
|
43
|
+
});
|
|
44
|
+
return presets;
|
|
45
|
+
}
|
|
46
|
+
/** The names a file exports, as unimport names them. */
|
|
47
|
+
function exportedNames(checker, source) {
|
|
48
|
+
const owner = checker.getSymbolAtLocation(source);
|
|
49
|
+
if (owner === void 0) return [];
|
|
50
|
+
return checker.getExportsOfModule(owner).map((symbol) => ({
|
|
51
|
+
name: symbol.name === "default" ? defaultExportName(source.fileName) : symbol.name,
|
|
52
|
+
symbol
|
|
65
53
|
}));
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
}
|
|
55
|
+
function bindingNames(compiler, name) {
|
|
56
|
+
if (compiler.isIdentifier(name)) return [name.text];
|
|
57
|
+
return name.elements.flatMap((element) => compiler.isOmittedExpression(element) ? [] : bindingNames(compiler, element.name));
|
|
58
|
+
}
|
|
59
|
+
function importedNames(compiler, statement) {
|
|
60
|
+
const clause = statement.importClause;
|
|
61
|
+
const bindings = clause?.namedBindings;
|
|
62
|
+
return [
|
|
63
|
+
...clause?.name === void 0 ? [] : [clause.name.text],
|
|
64
|
+
...bindings !== void 0 && compiler.isNamespaceImport(bindings) ? [bindings.name.text] : [],
|
|
65
|
+
...bindings !== void 0 && compiler.isNamedImports(bindings) ? bindings.elements.map((element) => element.name.text) : []
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
function declaredName(compiler, statement) {
|
|
69
|
+
if (!(compiler.isFunctionDeclaration(statement) || compiler.isClassDeclaration(statement) || compiler.isInterfaceDeclaration(statement) || compiler.isTypeAliasDeclaration(statement) || compiler.isEnumDeclaration(statement) || compiler.isModuleDeclaration(statement) || compiler.isImportEqualsDeclaration(statement)) || statement.name === void 0 || !compiler.isIdentifier(statement.name)) return void 0;
|
|
70
|
+
return statement.name.text;
|
|
71
|
+
}
|
|
72
|
+
/** The names a file binds at its top level, which an auto-import never shadows. */
|
|
73
|
+
function localNames(compiler, source) {
|
|
74
|
+
return new Set(source.statements.flatMap((statement) => {
|
|
75
|
+
if (compiler.isImportDeclaration(statement)) return importedNames(compiler, statement);
|
|
76
|
+
if (compiler.isVariableStatement(statement)) return statement.declarationList.declarations.flatMap((declaration) => bindingNames(compiler, declaration.name));
|
|
77
|
+
const name = declaredName(compiler, statement);
|
|
78
|
+
return name === void 0 ? [] : [name];
|
|
71
79
|
}));
|
|
72
|
-
const worker = join(directory, "worker.cjs");
|
|
73
|
-
writeFileSync(worker, WORKER);
|
|
74
|
-
const run = spawnSync(process.execPath, [
|
|
75
|
-
"-e",
|
|
76
|
-
DRIVER,
|
|
77
|
-
JSON.stringify(WORKER_NODE_ARGS),
|
|
78
|
-
worker,
|
|
79
|
-
...jobs.map(({ file }) => file)
|
|
80
|
-
], {
|
|
81
|
-
encoding: "utf8",
|
|
82
|
-
stdio: [
|
|
83
|
-
"ignore",
|
|
84
|
-
"ignore",
|
|
85
|
-
"pipe"
|
|
86
|
-
]
|
|
87
|
-
});
|
|
88
|
-
if (run.error) throw run.error;
|
|
89
|
-
if (run.status !== 0) throw new Error(run.stderr || "A declaration bundling worker failed.");
|
|
90
|
-
const bundles = [];
|
|
91
|
-
for (const { indices, result } of jobs) for (const [position, bundle] of JSON.parse(readFileSync(result, "utf8")).entries()) bundles[indices[position]] = bundle;
|
|
92
|
-
return bundles;
|
|
93
80
|
}
|
|
94
|
-
/**
|
|
95
|
-
function
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
/** Every auto-import a scanned file may use without importing it: dms-frontend's composables, then vue's exports, then the module's own scanned exports; the first module to offer a name keeps it. */
|
|
82
|
+
function autoImports(checker, sources) {
|
|
83
|
+
const imports = /* @__PURE__ */ new Map();
|
|
84
|
+
for (const { source, specifier } of sources) for (const { name, symbol } of exportedNames(checker, source)) if (!imports.has(name)) imports.set(name, {
|
|
85
|
+
name,
|
|
86
|
+
imported: symbol.name,
|
|
87
|
+
specifier
|
|
88
|
+
});
|
|
89
|
+
return [...imports.values()];
|
|
90
|
+
}
|
|
91
|
+
/** The specifier a scanned file is imported by: its path without the source extension. */
|
|
92
|
+
function sourceSpecifier(file) {
|
|
93
|
+
return file.replace(SOURCE_EXTENSION, "");
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A compiler host that prepends to each scanned module the imports unimport
|
|
97
|
+
* would inject, so names a file uses without importing them type as they do
|
|
98
|
+
* in the frontend build instead of as `any`. Only names the file does not bind
|
|
99
|
+
* itself are injected, and scripts and declaration files are left as they are.
|
|
100
|
+
*/
|
|
101
|
+
function injectingHost(compiler, options, scanned, imports) {
|
|
102
|
+
const host = compiler.createCompilerHost(options, true);
|
|
103
|
+
const read = host.getSourceFile.bind(host);
|
|
104
|
+
host.getSourceFile = (fileName, language, onError, create) => {
|
|
105
|
+
const source = scanned.get(fileName);
|
|
106
|
+
if (source === void 0 || source.isDeclarationFile || !compiler.isExternalModule(source)) return read(fileName, language, onError, create);
|
|
107
|
+
const own = localNames(compiler, source);
|
|
108
|
+
const bySpecifier = /* @__PURE__ */ new Map();
|
|
109
|
+
for (const { name, imported, specifier } of imports) {
|
|
110
|
+
if (own.has(name) || specifier === sourceSpecifier(fileName)) continue;
|
|
111
|
+
const list = bySpecifier.get(specifier) ?? [];
|
|
112
|
+
list.push(imported === name ? name : `${imported} as ${name}`);
|
|
113
|
+
bySpecifier.set(specifier, list);
|
|
114
|
+
}
|
|
115
|
+
const prefix = [...bySpecifier].map(([specifier, names]) => `import { ${names.join(", ")} } from ${JSON.stringify(specifier)};\n`).join("");
|
|
116
|
+
return compiler.createSourceFile(fileName, `${prefix}${source.text}`, language, true);
|
|
117
|
+
};
|
|
118
|
+
return host;
|
|
100
119
|
}
|
|
101
120
|
//#endregion
|
|
102
121
|
//#region src/guardrails/declaration-order.ts
|
|
@@ -189,6 +208,289 @@ function normalizeBundle(compiler, text) {
|
|
|
189
208
|
}).printFile(normalized);
|
|
190
209
|
}
|
|
191
210
|
//#endregion
|
|
211
|
+
//#region src/guardrails/auto-imports.ts
|
|
212
|
+
/** The file in which a DMS frontend module declares the directories the generated Vite config auto-imports. */
|
|
213
|
+
const BUILD_FILE = "dms.frontend.build.ts";
|
|
214
|
+
/** A module's private code, which the frontend build never auto-imports, whatever its declaration says. */
|
|
215
|
+
const PRIVATE_DIRECTORY = /(?:^|\/)app\/build(?:\/|$)/u;
|
|
216
|
+
/** The extensions unimport's directory scan reads exports from. */
|
|
217
|
+
const SCANNED_FILE = /\.(?:mts|cts|ts|tsx|mjs|cjs|js|jsx)$/u;
|
|
218
|
+
const HINT = "Auto-imports: every export of a file under a directory that dms.frontend.build.ts passes to registerAutoImports is auto-imported into every frontend module, so a removed, added or changed name above changes what those modules compile against. @internal does not hide an auto-import and --allow-added does not apply to one. Keep removed and changed names (or release the change as breaking), and move a helper that must stay private under app/build/, which is never auto-imported.\n";
|
|
219
|
+
function moduleRoots(root, revision) {
|
|
220
|
+
return execFileSync("git", [
|
|
221
|
+
"ls-tree",
|
|
222
|
+
"-r",
|
|
223
|
+
"-z",
|
|
224
|
+
"--name-only",
|
|
225
|
+
revision
|
|
226
|
+
], {
|
|
227
|
+
cwd: root,
|
|
228
|
+
encoding: "utf8",
|
|
229
|
+
maxBuffer: 67108864
|
|
230
|
+
}).split("\0").filter((file) => (file === BUILD_FILE || file.endsWith(`/${BUILD_FILE}`)) && !file.split("/").includes("node_modules")).map((file) => dirname(file)).sort();
|
|
231
|
+
}
|
|
232
|
+
/** The directories a build declaration passes to `registerAutoImports`, read without running it; only string literals can be read. */
|
|
233
|
+
function declaredDirectories(compiler, file, label) {
|
|
234
|
+
const source = compiler.createSourceFile(file, readFileSync(file, "utf8"), compiler.ScriptTarget.Latest, true);
|
|
235
|
+
const directories = [];
|
|
236
|
+
const visit = (node) => {
|
|
237
|
+
if (compiler.isCallExpression(node) && compiler.isPropertyAccessExpression(node.expression) && node.expression.name.text === "registerAutoImports") {
|
|
238
|
+
const [entries] = node.arguments;
|
|
239
|
+
const elements = entries !== void 0 && compiler.isArrayLiteralExpression(entries) ? entries.elements : void 0;
|
|
240
|
+
if (elements === void 0 || !elements.every((element) => compiler.isStringLiteralLike(element))) throw new Error(`${label}: registerAutoImports is not given an array of string literals, so api-diff cannot read which directories are auto-imported. Write the directories inline, as in registerAutoImports(["app/composables", ...]).`);
|
|
241
|
+
for (const element of elements) if (compiler.isStringLiteralLike(element)) directories.push(element.text);
|
|
242
|
+
}
|
|
243
|
+
compiler.forEachChild(node, visit);
|
|
244
|
+
};
|
|
245
|
+
visit(source);
|
|
246
|
+
return directories;
|
|
247
|
+
}
|
|
248
|
+
/** Whether the frontend build scans a declared directory: inside the module and outside `app/build/`, as `@antelopejs/dms-frontend` decides. */
|
|
249
|
+
function isScanned(directory) {
|
|
250
|
+
const path = posix.normalize(directory.split("\\").join("/"));
|
|
251
|
+
return !isAbsolute(directory) && path !== ".." && !path.startsWith("../") && !PRIVATE_DIRECTORY.test(path);
|
|
252
|
+
}
|
|
253
|
+
function scannedFiles(moduleRoot, directories) {
|
|
254
|
+
const files = /* @__PURE__ */ new Set();
|
|
255
|
+
for (const directory of directories.filter(isScanned)) for (const file of globSync(`${directory}/**/*`, { cwd: moduleRoot })) {
|
|
256
|
+
const path = file.split("\\").join("/");
|
|
257
|
+
if (SCANNED_FILE.test(path) && !PRIVATE_DIRECTORY.test(path) && !path.split("/").includes("node_modules") && statSync(join(moduleRoot, path)).isFile()) files.add(join(moduleRoot, path));
|
|
258
|
+
}
|
|
259
|
+
return [...files].sort();
|
|
260
|
+
}
|
|
261
|
+
/** The `#<layer>/*` specifiers the frontend workspace maps to each `layers/<layer>` directory. */
|
|
262
|
+
function layerPaths(moduleRoot) {
|
|
263
|
+
const layers = join(moduleRoot, "layers");
|
|
264
|
+
if (!existsSync(layers)) return {};
|
|
265
|
+
return Object.fromEntries(readdirSync(layers, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => [`#${entry.name}/*`, [join(layers, entry.name, "*")]]));
|
|
266
|
+
}
|
|
267
|
+
function compilerOptions(compiler, moduleRoot) {
|
|
268
|
+
const paths = layerPaths(moduleRoot);
|
|
269
|
+
const config = join(moduleRoot, "tsconfig.json");
|
|
270
|
+
const scan = {
|
|
271
|
+
noEmit: true,
|
|
272
|
+
allowJs: true,
|
|
273
|
+
skipLibCheck: true
|
|
274
|
+
};
|
|
275
|
+
if (existsSync(config)) {
|
|
276
|
+
const read = compiler.readConfigFile(config, compiler.sys.readFile);
|
|
277
|
+
const parsed = compiler.parseJsonConfigFileContent(read.config ?? {}, compiler.sys, moduleRoot);
|
|
278
|
+
return {
|
|
279
|
+
...parsed.options,
|
|
280
|
+
...scan,
|
|
281
|
+
paths: parsed.options.paths ?? paths
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
...scan,
|
|
286
|
+
target: compiler.ScriptTarget.ESNext,
|
|
287
|
+
module: compiler.ModuleKind.ESNext,
|
|
288
|
+
moduleResolution: compiler.ModuleResolutionKind.Bundler,
|
|
289
|
+
strict: true,
|
|
290
|
+
allowImportingTsExtensions: true,
|
|
291
|
+
resolveJsonModule: true,
|
|
292
|
+
types: [],
|
|
293
|
+
paths
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
const FORMAT_FLAGS = (compiler) => compiler.TypeFormatFlags.NoTruncation | compiler.TypeFormatFlags.UseStructuralFallback | compiler.TypeFormatFlags.WriteTypeArgumentsOfSignature;
|
|
297
|
+
/** Prints a type the way the declaration half compares bundles: members and union constituents in canonical order, on one line. */
|
|
298
|
+
function canonical(compiler, text) {
|
|
299
|
+
return normalizeBundle(compiler, `type Surface = ${text};`).replace(/^type Surface = /u, "").replace(/;\s*$/u, "").replace(/\s+/gu, " ").replaceAll("[ ", "[").replaceAll(" ]", "]");
|
|
300
|
+
}
|
|
301
|
+
function memberList(compiler, checker, type, location) {
|
|
302
|
+
const flags = FORMAT_FLAGS(compiler);
|
|
303
|
+
const print = (value) => checker.typeToString(value, void 0, flags);
|
|
304
|
+
return `{ ${[
|
|
305
|
+
...checker.getSignaturesOfType(type, compiler.SignatureKind.Call).map((signature) => checker.signatureToString(signature, void 0, flags, compiler.SignatureKind.Call)),
|
|
306
|
+
...checker.getSignaturesOfType(type, compiler.SignatureKind.Construct).map((signature) => checker.signatureToString(signature, void 0, flags, compiler.SignatureKind.Construct)),
|
|
307
|
+
...checker.getIndexInfosOfType(type).map((info) => `${info.isReadonly ? "readonly " : ""}[key: ${print(info.keyType)}]: ${print(info.type)}`),
|
|
308
|
+
...checker.getPropertiesOfType(type).map((property) => {
|
|
309
|
+
const declaration = property.valueDeclaration;
|
|
310
|
+
const readonly = declaration !== void 0 && (compiler.getCombinedModifierFlags(declaration) & compiler.ModifierFlags.Readonly) !== 0;
|
|
311
|
+
const optional = (property.flags & compiler.SymbolFlags.Optional) !== 0;
|
|
312
|
+
return `${readonly ? "readonly " : ""}${JSON.stringify(property.name)}${optional ? "?" : ""}: ${print(checker.getTypeOfSymbolAtLocation(property, location))}`;
|
|
313
|
+
})
|
|
314
|
+
].join("; ")} }`;
|
|
315
|
+
}
|
|
316
|
+
function typeParameters(compiler, checker, declaration) {
|
|
317
|
+
if (declaration === void 0 || !(compiler.isTypeAliasDeclaration(declaration) || compiler.isInterfaceDeclaration(declaration) || compiler.isClassDeclaration(declaration)) || declaration.typeParameters === void 0) return "";
|
|
318
|
+
const flags = FORMAT_FLAGS(compiler);
|
|
319
|
+
const print = (node) => checker.typeToString(checker.getTypeFromTypeNode(node), void 0, flags);
|
|
320
|
+
return `<${declaration.typeParameters.map((parameter) => `${parameter.name.text}${parameter.constraint === void 0 ? "" : ` extends ${print(parameter.constraint)}`}${parameter.default === void 0 ? "" : ` = ${print(parameter.default)}`}`).join(", ")}>`;
|
|
321
|
+
}
|
|
322
|
+
/** One line per meaning of an auto-imported name: its value's type and, for a type, its declared structure. */
|
|
323
|
+
function describe(compiler, checker, name, exported, source) {
|
|
324
|
+
const symbol = (exported.flags & compiler.SymbolFlags.Alias) !== 0 ? checker.getAliasedSymbol(exported) : exported;
|
|
325
|
+
const declaration = symbol.valueDeclaration ?? symbol.declarations?.[0];
|
|
326
|
+
const location = declaration ?? source;
|
|
327
|
+
const flags = FORMAT_FLAGS(compiler);
|
|
328
|
+
const lines = [];
|
|
329
|
+
const structured = compiler.SymbolFlags.Class | compiler.SymbolFlags.Enum | compiler.SymbolFlags.ValueModule;
|
|
330
|
+
if ((symbol.flags & compiler.SymbolFlags.Value) !== 0) {
|
|
331
|
+
const type = checker.getTypeOfSymbolAtLocation(symbol, location);
|
|
332
|
+
const text = (symbol.flags & structured) !== 0 ? memberList(compiler, checker, type, location) : checker.typeToString(type, void 0, flags);
|
|
333
|
+
lines.push(`${name} (value): ${canonical(compiler, text)}`);
|
|
334
|
+
}
|
|
335
|
+
if ((symbol.flags & compiler.SymbolFlags.Type) !== 0 && (symbol.flags & compiler.SymbolFlags.Enum) === 0) {
|
|
336
|
+
const type = checker.getDeclaredTypeOfSymbol(symbol);
|
|
337
|
+
const text = (symbol.flags & compiler.SymbolFlags.TypeAlias) !== 0 ? checker.typeToString(type, void 0, flags | compiler.TypeFormatFlags.InTypeAlias) : memberList(compiler, checker, type, location);
|
|
338
|
+
lines.push(`${name} (type)${typeParameters(compiler, checker, declaration)}: ${canonical(compiler, text)}`);
|
|
339
|
+
}
|
|
340
|
+
return lines;
|
|
341
|
+
}
|
|
342
|
+
/** The auto-import surface of one frontend module: one sorted line per name and meaning that unimport would expose from its scanned files. Exports are read with the module's compiler, so `export *` and inferred types resolve as the frontend workspace types them. */
|
|
343
|
+
function moduleSurface(worktree, directory) {
|
|
344
|
+
const moduleRoot = join(worktree, directory);
|
|
345
|
+
const { compiler, notice } = loadTypeScript(moduleRoot);
|
|
346
|
+
const files = scannedFiles(moduleRoot, declaredDirectories(compiler, join(moduleRoot, BUILD_FILE), posix.join(directory, BUILD_FILE)));
|
|
347
|
+
const options = compilerOptions(compiler, moduleRoot);
|
|
348
|
+
const presets = presetModules(compiler, moduleRoot, options);
|
|
349
|
+
const plain = compiler.createProgram([...files, ...presets.map(({ file }) => file)], options);
|
|
350
|
+
const scanned = new Map(files.flatMap((file) => {
|
|
351
|
+
const source = plain.getSourceFile(file);
|
|
352
|
+
return source === void 0 ? [] : [[source.fileName, source]];
|
|
353
|
+
}));
|
|
354
|
+
const sources = [...presets.flatMap(({ file, specifier }) => {
|
|
355
|
+
const source = plain.getSourceFile(file);
|
|
356
|
+
return source === void 0 ? [] : [{
|
|
357
|
+
source,
|
|
358
|
+
specifier
|
|
359
|
+
}];
|
|
360
|
+
}), ...[...scanned.values()].map((source) => ({
|
|
361
|
+
source,
|
|
362
|
+
specifier: sourceSpecifier(source.fileName)
|
|
363
|
+
}))];
|
|
364
|
+
const imports = autoImports(plain.getTypeChecker(), sources);
|
|
365
|
+
const program = compiler.createProgram(files, options, injectingHost(compiler, options, scanned, imports));
|
|
366
|
+
const checker = program.getTypeChecker();
|
|
367
|
+
const lines = /* @__PURE__ */ new Set();
|
|
368
|
+
for (const file of files) {
|
|
369
|
+
const source = program.getSourceFile(file);
|
|
370
|
+
if (source === void 0) continue;
|
|
371
|
+
for (const { name, symbol } of exportedNames(checker, source)) for (const line of describe(compiler, checker, name, symbol, source)) lines.add(line.split(worktree).join("<root>"));
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
lines: [...lines].sort(),
|
|
375
|
+
notice
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
/** Compares the names and signatures each DMS frontend module auto-imports (the exports of the directories its `dms.frontend.build.ts` declares, without `app/build/`) at the base and at committed HEAD. Undefined when neither revision has a frontend module. */
|
|
379
|
+
function autoImportDiff(root, baseRef) {
|
|
380
|
+
if ([baseRef, "HEAD"].every((ref) => moduleRoots(root, resolveRevision(root, ref)).length === 0)) return void 0;
|
|
381
|
+
const notices = /* @__PURE__ */ new Set();
|
|
382
|
+
const result = compareRevisions(root, baseRef, "Auto-imports", (worktree, output) => {
|
|
383
|
+
const directories = moduleRoots(worktree, "HEAD");
|
|
384
|
+
let entries = 0;
|
|
385
|
+
for (const directory of directories) {
|
|
386
|
+
const { lines, notice } = moduleSurface(worktree, directory);
|
|
387
|
+
if (notice !== void 0) notices.add(notice);
|
|
388
|
+
const path = join(output, directory === "." ? "_root" : directory, "auto-imports.txt");
|
|
389
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
390
|
+
writeFileSync(path, lines.map((line) => `${line}\n`).join(""));
|
|
391
|
+
entries += lines.length;
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
packages: directories,
|
|
395
|
+
entries
|
|
396
|
+
};
|
|
397
|
+
});
|
|
398
|
+
return {
|
|
399
|
+
different: result.different,
|
|
400
|
+
output: `${result.output}${result.different ? HINT : ""}${[...notices].sort().join("")}`
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/guardrails/declaration-bundle.ts
|
|
405
|
+
const ENTRIES_PER_WORKER = 16;
|
|
406
|
+
const MAX_WORKERS = 8;
|
|
407
|
+
const MIB = 1024 ** 2;
|
|
408
|
+
const WORKER_MEMORY = 1536 * MIB;
|
|
409
|
+
/** Node options that keep a worker inside `WORKER_MEMORY`: the old-space cap leaves room for the memory V8 holds outside the heap, so a worker's resident size stays under the budget that `workerCount` assumes. */
|
|
410
|
+
const WORKER_NODE_ARGS = [`--max-old-space-size=${(WORKER_MEMORY - 256 * MIB) / MIB}`];
|
|
411
|
+
const WORKER = `
|
|
412
|
+
const { readFileSync, writeFileSync } = require("node:fs");
|
|
413
|
+
const { createRequire } = require("node:module");
|
|
414
|
+
try {
|
|
415
|
+
const job = JSON.parse(readFileSync(process.argv[2], "utf8"));
|
|
416
|
+
const generate = createRequire(job.loader)("dts-bundle-generator").generateDtsBundle;
|
|
417
|
+
writeFileSync(job.result, JSON.stringify(generate(job.entries, job.options)));
|
|
418
|
+
} catch (error) {
|
|
419
|
+
process.stderr.write(String(error instanceof Error ? error.message : error));
|
|
420
|
+
process.exit(1);
|
|
421
|
+
}
|
|
422
|
+
`;
|
|
423
|
+
const DRIVER = `
|
|
424
|
+
const { spawn } = require("node:child_process");
|
|
425
|
+
const [flags, worker, ...jobs] = process.argv.slice(1);
|
|
426
|
+
let failed = false;
|
|
427
|
+
let pending = jobs.length;
|
|
428
|
+
for (const job of jobs) {
|
|
429
|
+
spawn(process.execPath, [...JSON.parse(flags), worker, job], { stdio: ["ignore", "inherit", "inherit"] }).on("exit", (code) => {
|
|
430
|
+
failed ||= code !== 0;
|
|
431
|
+
pending -= 1;
|
|
432
|
+
if (pending === 0) process.exit(failed ? 1 : 0);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
`;
|
|
436
|
+
/** Places a copy of `dts-bundle-generator` beside a `typescript` link to the package at `compilerRoot`, the compiler the target repository builds with. The generator requires `typescript` by name, so this makes it drive that compiler instead of the one it was installed with. Returns a path to require the copy from. */
|
|
437
|
+
function installGenerator(compilerRoot, scratch) {
|
|
438
|
+
const source = dirname(createRequire(import.meta.url).resolve("dts-bundle-generator/package.json"));
|
|
439
|
+
const modules = join(scratch, "generator", "node_modules");
|
|
440
|
+
mkdirSync(modules, { recursive: true });
|
|
441
|
+
cpSync(source, join(modules, "dts-bundle-generator"), {
|
|
442
|
+
recursive: true,
|
|
443
|
+
filter: (path) => basename(path) !== "node_modules"
|
|
444
|
+
});
|
|
445
|
+
symlinkSync(compilerRoot, join(modules, "typescript"), DIRECTORY_LINK);
|
|
446
|
+
return join(modules, "index.js");
|
|
447
|
+
}
|
|
448
|
+
/** Workers for `count` entries: each builds its own program, so a worker needs enough entries to repay that, and the bound keeps their combined heap inside the memory that is free. */
|
|
449
|
+
function workerCount(count, cpus = availableParallelism(), free = freemem()) {
|
|
450
|
+
return Math.max(1, Math.min(Math.floor(count / ENTRIES_PER_WORKER), cpus, MAX_WORKERS, Math.floor(free / WORKER_MEMORY)));
|
|
451
|
+
}
|
|
452
|
+
function generateInWorkers(loader, directory, entries, options, workers) {
|
|
453
|
+
const jobs = Array.from({ length: workers }, (_, worker) => ({
|
|
454
|
+
indices: entries.flatMap((_entry, index) => index % workers === worker ? [index] : []),
|
|
455
|
+
file: join(directory, `job-${worker}.json`),
|
|
456
|
+
result: join(directory, `result-${worker}.json`)
|
|
457
|
+
}));
|
|
458
|
+
for (const { indices, file, result } of jobs) writeFileSync(file, JSON.stringify({
|
|
459
|
+
loader,
|
|
460
|
+
result,
|
|
461
|
+
options,
|
|
462
|
+
entries: indices.map((index) => entries[index])
|
|
463
|
+
}));
|
|
464
|
+
const worker = join(directory, "worker.cjs");
|
|
465
|
+
writeFileSync(worker, WORKER);
|
|
466
|
+
const run = spawnSync(process.execPath, [
|
|
467
|
+
"-e",
|
|
468
|
+
DRIVER,
|
|
469
|
+
JSON.stringify(WORKER_NODE_ARGS),
|
|
470
|
+
worker,
|
|
471
|
+
...jobs.map(({ file }) => file)
|
|
472
|
+
], {
|
|
473
|
+
encoding: "utf8",
|
|
474
|
+
stdio: [
|
|
475
|
+
"ignore",
|
|
476
|
+
"ignore",
|
|
477
|
+
"pipe"
|
|
478
|
+
]
|
|
479
|
+
});
|
|
480
|
+
if (run.error) throw run.error;
|
|
481
|
+
if (run.status !== 0) throw new Error(run.stderr || "A declaration bundling worker failed.");
|
|
482
|
+
const bundles = [];
|
|
483
|
+
for (const { indices, result } of jobs) for (const [position, bundle] of JSON.parse(readFileSync(result, "utf8")).entries()) bundles[indices[position]] = bundle;
|
|
484
|
+
return bundles;
|
|
485
|
+
}
|
|
486
|
+
/** Bundles every entry's declarations with the compiler at `compilerRoot`. Large packages are split across worker processes by entry; each bundle depends only on its own entry, so the output is the same as one sequential call. */
|
|
487
|
+
function bundleDeclarations(compilerRoot, scratch, entries, options, workers = workerCount(entries.length)) {
|
|
488
|
+
const loader = installGenerator(compilerRoot, scratch);
|
|
489
|
+
if (workers > 1) return generateInWorkers(loader, join(scratch, "generator"), entries, options, workers);
|
|
490
|
+
const generate = createRequire(loader)("dts-bundle-generator").generateDtsBundle;
|
|
491
|
+
return generate(entries, options);
|
|
492
|
+
}
|
|
493
|
+
//#endregion
|
|
192
494
|
//#region src/guardrails/test-entries.ts
|
|
193
495
|
/** The line a proof half prints for a published test-helper entry it leaves out, so a skip is reported rather than silent. */
|
|
194
496
|
function testEntryNotice(half, directory, target) {
|
|
@@ -236,9 +538,9 @@ function properties(object, observe) {
|
|
|
236
538
|
function runtimeTargets(target, entry = "exports", subpath = ".") {
|
|
237
539
|
if (target == null) return [];
|
|
238
540
|
if (Array.isArray(target)) return target.flatMap((value, index) => runtimeTargets(value, `${entry}/${index}`, subpath));
|
|
239
|
-
if (target
|
|
541
|
+
if (isExportPath(target)) return [{
|
|
240
542
|
entry,
|
|
241
|
-
target
|
|
543
|
+
target,
|
|
242
544
|
subpath
|
|
243
545
|
}];
|
|
244
546
|
return Object.entries(target).flatMap(([key, value]) => {
|
|
@@ -415,7 +717,7 @@ function entryPattern(value) {
|
|
|
415
717
|
return value.split("*").map(entrySegment).join("*");
|
|
416
718
|
}
|
|
417
719
|
function exportTargets(target, entry = "exports/root", subpath = ".") {
|
|
418
|
-
if (
|
|
720
|
+
if (isExportPath(target)) return [{
|
|
419
721
|
entry,
|
|
420
722
|
target,
|
|
421
723
|
subpath
|
|
@@ -610,26 +912,36 @@ function declarationDiff(root, baseRef, policy) {
|
|
|
610
912
|
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("")
|
|
611
913
|
};
|
|
612
914
|
}
|
|
613
|
-
/** Compares declarations
|
|
915
|
+
/** Compares declarations, built runtime exports and the auto-import surface of DMS frontend modules, with an optional behavioral probe captured before either build. Added entries whose subpath matches an `allowAdded` glob pass when their module is `@internal`. */
|
|
614
916
|
function apiDiff(root, baseRef, probeFile, allowAdded = []) {
|
|
615
917
|
const policy = allowAdded.length ? createAddedPolicy(allowAdded) : void 0;
|
|
616
918
|
const probe = probeFile === void 0 ? void 0 : readFileSync(resolve(root, probeFile));
|
|
617
919
|
const results = [];
|
|
618
920
|
const errors = [];
|
|
619
|
-
for (const compare of [
|
|
620
|
-
|
|
921
|
+
for (const compare of [
|
|
922
|
+
() => declarationDiff(root, baseRef, policy),
|
|
923
|
+
() => runtimeDiff(root, baseRef, probe, policy),
|
|
924
|
+
() => autoImportDiff(root, baseRef)
|
|
925
|
+
]) try {
|
|
926
|
+
const result = compare();
|
|
927
|
+
if (result !== void 0) results.push(result);
|
|
621
928
|
} catch (error) {
|
|
622
929
|
errors.push(`Execution error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
623
930
|
}
|
|
931
|
+
const command = [
|
|
932
|
+
`antelopejs-api-diff ${baseRef}`,
|
|
933
|
+
...probeFile === void 0 ? [] : [`--probe ${probeFile}`],
|
|
934
|
+
...allowAdded.map((glob) => `--allow-added '${glob}'`)
|
|
935
|
+
].join(" ");
|
|
624
936
|
return {
|
|
625
937
|
different: errors.length > 0 || results.some((result) => result.different) || (policy?.problems.size ?? 0) > 0,
|
|
626
|
-
output: results.map((result) => result.output).join("") + (policy === void 0 ? "" : describeAllowance(policy)) + errors.join("") + (probe === void 0 ? "No behavioural probe ran.\n" : "Behavioural probe supplied.\n") + revisionCounts(root, baseRef)
|
|
938
|
+
output: stampProof(root, command, baseRef, results.map((result) => result.output).join("") + (policy === void 0 ? "" : describeAllowance(policy)) + errors.join("") + (probe === void 0 ? "No behavioural probe ran.\n" : "Behavioural probe supplied.\n") + revisionCounts(root, baseRef))
|
|
627
939
|
};
|
|
628
940
|
}
|
|
629
941
|
//#endregion
|
|
630
942
|
//#region src/bin/api-diff.ts
|
|
631
943
|
const USAGE = "Usage: antelopejs-api-diff <base-ref> [--probe <file.cjs>] [--allow-added <glob>]...";
|
|
632
|
-
function parse(args) {
|
|
944
|
+
function parse$1(args) {
|
|
633
945
|
try {
|
|
634
946
|
const { positionals, values } = parseArgs({
|
|
635
947
|
args,
|
|
@@ -652,7 +964,7 @@ function parse(args) {
|
|
|
652
964
|
}
|
|
653
965
|
}
|
|
654
966
|
runCli(() => {
|
|
655
|
-
const { baseRef, probe, "allow-added": allowAdded } = parse(process.argv.slice(2));
|
|
967
|
+
const { baseRef, probe, "allow-added": allowAdded } = parse$1(process.argv.slice(2));
|
|
656
968
|
const result = apiDiff(repositoryRoot(), baseRef, probe, allowAdded);
|
|
657
969
|
process.stdout.write(result.output);
|
|
658
970
|
return result.different ? 1 : 0;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|