@antelopejs/tooling-configs 0.2.2 → 0.2.4
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 +9 -3
- package/dist/bin/api-diff.mjs +413 -33
- package/dist/bin/check-size.mjs +2 -2
- package/dist/bin/checks.mjs +2 -1
- package/dist/bin/comment-proof.mjs +7 -3
- package/dist/bin/ratchet.mjs +10 -5
- package/dist/bin/sync.mjs +96 -6
- package/dist/files-CaMy-5ne.mjs +382 -0
- package/dist/oxc/fmt.mjs +1 -1
- package/dist/oxc/lint.mjs +4 -3
- package/dist/{ratchet-B2_QUucT.mjs → ratchet-Bz4Rl3_r.mjs} +7 -6
- package/dist/renames-BGO4dWJ8.mjs +59 -0
- package/dist/{shared-NC0T8ykm.mjs → shared-CsXIMK3I.mjs} +4 -2
- package/dist/{size-D7JJp_W4.mjs → size-DYVe2pXo.mjs} +4 -3
- package/dist/typescript-BlNlyAhQ.mjs +169 -0
- package/package.json +1 -1
- package/dist/files-DAD5OtfV.mjs +0 -129
- package/dist/typescript-CHOlkIXa.mjs +0 -202
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { s as readCeilings } from "./ceilings-BSw9p4YB.mjs";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
//#region src/guardrails/renames.ts
|
|
4
|
+
/**
|
|
5
|
+
* Renames git detects, as new path to old path. Without `revisions` it
|
|
6
|
+
* compares the index with HEAD when `staged`, otherwise the working tree with
|
|
7
|
+
* HEAD; with revisions it compares those. Copies are never reported, and a
|
|
8
|
+
* repository without HEAD has no renames.
|
|
9
|
+
*/
|
|
10
|
+
function renamedPaths(root, staged = false, revisions = staged ? [] : ["HEAD"]) {
|
|
11
|
+
const result = spawnSync("git", [
|
|
12
|
+
"diff",
|
|
13
|
+
"--find-renames",
|
|
14
|
+
"--diff-filter=R",
|
|
15
|
+
"--name-status",
|
|
16
|
+
"-z",
|
|
17
|
+
"--no-ext-diff",
|
|
18
|
+
...staged ? ["--cached"] : [],
|
|
19
|
+
...revisions,
|
|
20
|
+
"--"
|
|
21
|
+
], {
|
|
22
|
+
cwd: root,
|
|
23
|
+
encoding: "utf8",
|
|
24
|
+
maxBuffer: 67108864
|
|
25
|
+
});
|
|
26
|
+
const renames = /* @__PURE__ */ new Map();
|
|
27
|
+
if (result.error || result.status !== 0) return renames;
|
|
28
|
+
const fields = result.stdout.split("\0");
|
|
29
|
+
for (let index = 0; index + 2 < fields.length; index += 3) renames.set(fields[index + 2], fields[index + 1]);
|
|
30
|
+
return renames;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Moves the oversize allowance of each renamed file to its new path. The new
|
|
34
|
+
* path never gets more than the old allowance; a copy or a new file has no
|
|
35
|
+
* rename entry and so inherits nothing.
|
|
36
|
+
*/
|
|
37
|
+
function carryAllowances(ceilings, renames) {
|
|
38
|
+
const oversizeFiles = { ...ceilings.oversizeFiles };
|
|
39
|
+
const moved = [];
|
|
40
|
+
for (const [file, previous] of renames) {
|
|
41
|
+
const allowance = ceilings.oversizeFiles[previous];
|
|
42
|
+
if (allowance === void 0) continue;
|
|
43
|
+
delete oversizeFiles[previous];
|
|
44
|
+
moved.push([file, Math.min(allowance, ceilings.oversizeFiles[file] ?? allowance)]);
|
|
45
|
+
}
|
|
46
|
+
for (const [file, allowance] of moved) oversizeFiles[file] = allowance;
|
|
47
|
+
return {
|
|
48
|
+
rules: ceilings.rules,
|
|
49
|
+
oversizeFiles
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** The ceilings at `root` with allowances carried across the renames in `staged` or working-tree scope. */
|
|
53
|
+
function readCarriedCeilings(root, staged = false, revisions) {
|
|
54
|
+
const ceilings = readCeilings(root);
|
|
55
|
+
if (Object.keys(ceilings.oversizeFiles).length === 0) return ceilings;
|
|
56
|
+
return carryAllowances(ceilings, renamedPaths(root, staged, revisions));
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { renamedPaths as n, readCarriedCeilings as t };
|
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
* Paths every AntelopeJS project generates or vendors, and that no linter should read.
|
|
4
4
|
* `.github/ISSUE_TEMPLATE/**` holds GitHub's legacy issue templates: Markdown with
|
|
5
5
|
* YAML frontmatter saved under a .yml extension, which a YAML formatter cannot parse.
|
|
6
|
+
* `build/**` and `output/**` match only at the repository root: a directory with
|
|
7
|
+
* either name under `src/` or another authored root is source, not build output.
|
|
6
8
|
*/
|
|
7
9
|
const IGNORE_PATTERNS = [
|
|
8
10
|
"**/node_modules/**",
|
|
9
11
|
"**/dist/**",
|
|
10
|
-
"**/build/**",
|
|
11
12
|
"**/coverage/**",
|
|
12
13
|
"**/.antelope/**",
|
|
13
14
|
"**/.nuxt/**",
|
|
14
15
|
"**/.output/**",
|
|
15
|
-
"
|
|
16
|
+
"build/**",
|
|
17
|
+
"output/**",
|
|
16
18
|
"**/i18n-registry.generated.ts",
|
|
17
19
|
".github/ISSUE_TEMPLATE/**"
|
|
18
20
|
];
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { t as
|
|
1
|
+
import "./ceilings-BSw9p4YB.mjs";
|
|
2
|
+
import { t as readCarriedCeilings } from "./renames-BGO4dWJ8.mjs";
|
|
3
|
+
import { t as authoredSizes } from "./files-CaMy-5ne.mjs";
|
|
3
4
|
//#region src/guardrails/size.ts
|
|
4
5
|
function sizeFailure(file, size, limit) {
|
|
5
6
|
return `${file}: ${size} bytes, ${size - limit} bytes over the ${limit}-byte ceiling. Split by responsibility into sibling modules, one cohesive group of exports each; keep the original path re-exporting only if it is a public entry point. Split a test file by behaviour under test, one file per describe. Do not minify, strip whitespace, or move code under an excluded path to pass.`;
|
|
6
7
|
}
|
|
7
8
|
function checkSize(root, files, staged = false) {
|
|
8
|
-
const ceilings =
|
|
9
|
+
const ceilings = readCarriedCeilings(root, staged);
|
|
9
10
|
const failures = [];
|
|
10
11
|
for (const [file, size] of authoredSizes(root, files, staged)) {
|
|
11
12
|
const limit = ceilings.oversizeFiles[file] ?? 2e4;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { l as trackedManifests } from "./files-CaMy-5ne.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join, matchesGlob, relative, resolve, sep } from "node:path";
|
|
5
|
+
//#region src/guardrails/typescript.ts
|
|
6
|
+
/** A proof analyses only packages that publish something: not private, and declaring at least one of `exports`, `main`, `types`, `typings` or `typesVersions`. */
|
|
7
|
+
function unpublishedReason(manifest) {
|
|
8
|
+
if (manifest.private === true) return "private";
|
|
9
|
+
return [
|
|
10
|
+
manifest.exports,
|
|
11
|
+
manifest.main,
|
|
12
|
+
manifest.types,
|
|
13
|
+
manifest.typings,
|
|
14
|
+
manifest.typesVersions
|
|
15
|
+
].some((field) => field != null) ? void 0 : "no exports, main or types";
|
|
16
|
+
}
|
|
17
|
+
function trackedPackages(root) {
|
|
18
|
+
return trackedManifests(root).flatMap((file) => {
|
|
19
|
+
const directory = dirname(file);
|
|
20
|
+
if (!existsSync(join(root, directory, "tsconfig.json"))) return [];
|
|
21
|
+
return [{
|
|
22
|
+
directory,
|
|
23
|
+
manifest: JSON.parse(readFileSync(join(root, file), "utf8"))
|
|
24
|
+
}];
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function packagesAt(root, publishedOnly) {
|
|
28
|
+
return trackedPackages(root).filter(({ manifest }) => !publishedOnly || unpublishedReason(manifest) === void 0);
|
|
29
|
+
}
|
|
30
|
+
/** The packages a published-only proof leaves out, each with the reason, so a skip is reported rather than silent. */
|
|
31
|
+
function unpublishedAt(root) {
|
|
32
|
+
return trackedPackages(root).flatMap(({ directory, manifest }) => {
|
|
33
|
+
const reason = unpublishedReason(manifest);
|
|
34
|
+
return reason === void 0 ? [] : [{
|
|
35
|
+
directory,
|
|
36
|
+
reason
|
|
37
|
+
}];
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function packageRoot(file) {
|
|
41
|
+
let directory = dirname(file);
|
|
42
|
+
while (!existsSync(join(directory, "package.json"))) {
|
|
43
|
+
const parent = dirname(directory);
|
|
44
|
+
if (parent === directory) return dirname(file);
|
|
45
|
+
directory = parent;
|
|
46
|
+
}
|
|
47
|
+
return directory;
|
|
48
|
+
}
|
|
49
|
+
/** Loads the compiler a package builds with, including a package-local installation in a workspace, falling back to the one `dts-bundle-generator` brings. A TypeScript without the programmatic API (7 and later) is an error rather than a crash. */
|
|
50
|
+
function loadTypeScript(directory) {
|
|
51
|
+
const own = createRequire(import.meta.url);
|
|
52
|
+
let file;
|
|
53
|
+
try {
|
|
54
|
+
file = createRequire(join(directory, "package.json")).resolve("typescript");
|
|
55
|
+
} catch {
|
|
56
|
+
file = createRequire(own.resolve("dts-bundle-generator")).resolve("typescript");
|
|
57
|
+
}
|
|
58
|
+
const compiler = createRequire(file)("typescript");
|
|
59
|
+
const root = packageRoot(file);
|
|
60
|
+
if (compiler.sys === void 0 || !("createProgram" in compiler)) throw new Error(`TypeScript ${compiler.version} at ${root} has no programmatic compiler API (sys, createProgram), so this package cannot be analysed. Build it with a TypeScript that has one, or mark the package private.`);
|
|
61
|
+
return {
|
|
62
|
+
compiler,
|
|
63
|
+
root
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const TEST_SOURCE_GLOBS = [
|
|
67
|
+
"**/*.test.*",
|
|
68
|
+
"**/*.spec.*",
|
|
69
|
+
"**/__tests__/**",
|
|
70
|
+
"test/**",
|
|
71
|
+
"tests/**"
|
|
72
|
+
];
|
|
73
|
+
function isTestSource(root, file) {
|
|
74
|
+
const path = relative(root, file).split("\\").join("/");
|
|
75
|
+
return TEST_SOURCE_GLOBS.some((pattern) => matchesGlob(path, pattern));
|
|
76
|
+
}
|
|
77
|
+
function failDiagnostics(compiler, diagnostics) {
|
|
78
|
+
const errors = diagnostics.filter((item) => item.category === compiler.DiagnosticCategory.Error);
|
|
79
|
+
if (errors.length) throw new Error(compiler.formatDiagnostics(errors, {
|
|
80
|
+
getCanonicalFileName: (file) => file,
|
|
81
|
+
getCurrentDirectory: () => process.cwd(),
|
|
82
|
+
getNewLine: () => "\n"
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
/** Declaration inputs are part of the local closure but TypeScript does not emit copies of them. */
|
|
86
|
+
function copyDeclarations(program, directory, output) {
|
|
87
|
+
const sources = program.getSourceFiles().filter((source) => !program.isSourceFileDefaultLibrary(source) && !program.isSourceFileFromExternalLibrary(source) && !relative(directory, source.fileName).startsWith(`..${sep}`) && !isTestSource(directory, source.fileName));
|
|
88
|
+
const authored = sources.filter((source) => !source.isDeclarationFile);
|
|
89
|
+
let root = dirname((authored[0] ?? sources[0])?.fileName ?? join(directory, "index.ts"));
|
|
90
|
+
for (const source of authored.length ? authored : sources) while (relative(root, source.fileName).startsWith(`..${sep}`)) root = dirname(root);
|
|
91
|
+
root = program.getCompilerOptions().rootDir ?? root;
|
|
92
|
+
const files = [];
|
|
93
|
+
for (const source of sources) {
|
|
94
|
+
if (!source.isDeclarationFile) continue;
|
|
95
|
+
const path = relative(root, source.fileName);
|
|
96
|
+
if (path.startsWith(`..${sep}`)) continue;
|
|
97
|
+
const target = join(output, path);
|
|
98
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
99
|
+
writeFileSync(target, source.text);
|
|
100
|
+
files.push(target);
|
|
101
|
+
}
|
|
102
|
+
return files;
|
|
103
|
+
}
|
|
104
|
+
function parseConfig(directory) {
|
|
105
|
+
const { compiler, root } = loadTypeScript(directory);
|
|
106
|
+
const config = compiler.readConfigFile(join(directory, "tsconfig.json"), compiler.sys.readFile);
|
|
107
|
+
if (config.error) failDiagnostics(compiler, [config.error]);
|
|
108
|
+
const parsed = compiler.parseJsonConfigFileContent(config.config, compiler.sys, directory);
|
|
109
|
+
failDiagnostics(compiler, parsed.errors);
|
|
110
|
+
return {
|
|
111
|
+
compiler,
|
|
112
|
+
root,
|
|
113
|
+
parsed
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** The configured `outDir`, the root under which the declaration half already judges a built path as test output. */
|
|
117
|
+
function outputRoot(directory) {
|
|
118
|
+
return resolve(directory, parseConfig(directory).parsed.options.outDir ?? ".");
|
|
119
|
+
}
|
|
120
|
+
/** Emits with the package's compiler and config; test roots and outputs never enter either proof. `modules` maps each emitted file to its source module. */
|
|
121
|
+
function emitPackage(directory, output, declarations) {
|
|
122
|
+
const { compiler, root, parsed } = parseConfig(directory);
|
|
123
|
+
const options = {
|
|
124
|
+
...parsed.options,
|
|
125
|
+
rootDir: parsed.options.rootDir ?? (parsed.options.outDir ? void 0 : directory),
|
|
126
|
+
outDir: output,
|
|
127
|
+
declarationDir: declarations ? output : void 0,
|
|
128
|
+
declaration: declarations,
|
|
129
|
+
emitDeclarationOnly: declarations,
|
|
130
|
+
removeComments: true,
|
|
131
|
+
declarationMap: false,
|
|
132
|
+
sourceMap: false,
|
|
133
|
+
inlineSourceMap: false,
|
|
134
|
+
noEmit: false,
|
|
135
|
+
noEmitOnError: false,
|
|
136
|
+
composite: false,
|
|
137
|
+
incremental: false,
|
|
138
|
+
tsBuildInfoFile: void 0,
|
|
139
|
+
outFile: void 0,
|
|
140
|
+
allowImportingTsExtensions: declarations ? parsed.options.allowImportingTsExtensions : false
|
|
141
|
+
};
|
|
142
|
+
const program = compiler.createProgram({
|
|
143
|
+
rootNames: parsed.fileNames.filter((file) => !isTestSource(directory, file)),
|
|
144
|
+
options,
|
|
145
|
+
projectReferences: parsed.projectReferences
|
|
146
|
+
});
|
|
147
|
+
if (declarations) failDiagnostics(compiler, compiler.getPreEmitDiagnostics(program));
|
|
148
|
+
const files = [];
|
|
149
|
+
const modules = /* @__PURE__ */ new Map();
|
|
150
|
+
const result = program.emit(void 0, (file, text, _bom, _onError, sources) => {
|
|
151
|
+
if (sources?.some((source) => isTestSource(directory, source.fileName))) return;
|
|
152
|
+
if (declarations ? !/\.d\.[cm]?ts$/.test(file) : !/\.[cm]?jsx?$/.test(file)) return;
|
|
153
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
154
|
+
writeFileSync(file, text);
|
|
155
|
+
files.push(file);
|
|
156
|
+
if (sources?.[0] !== void 0) modules.set(resolve(file), sources[0].fileName);
|
|
157
|
+
});
|
|
158
|
+
if (declarations) failDiagnostics(compiler, result.diagnostics);
|
|
159
|
+
if (declarations) files.push(...copyDeclarations(program, directory, output));
|
|
160
|
+
return {
|
|
161
|
+
compiler,
|
|
162
|
+
compilerRoot: root,
|
|
163
|
+
files,
|
|
164
|
+
modules,
|
|
165
|
+
options: parsed.options
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
169
|
+
export { unpublishedAt as a, packagesAt as i, isTestSource as n, outputRoot as r, emitPackage as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/tooling-configs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Shared tooling presets for AntelopeJS repositories: oxlint (with the vendored anti-slop rules), oxfmt, ESLint for Nuxt layers, Knip, and an interface range check",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
package/dist/files-DAD5OtfV.mjs
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import "./ceilings-BSw9p4YB.mjs";
|
|
2
|
-
import { n as IGNORE_PATTERNS, t as AGENT_IGNORE_PATTERNS } from "./shared-NC0T8ykm.mjs";
|
|
3
|
-
import { closeSync, existsSync, lstatSync, openSync, readSync } from "node:fs";
|
|
4
|
-
import { join, matchesGlob, relative, resolve } from "node:path";
|
|
5
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
6
|
-
//#region src/guardrails/cli.ts
|
|
7
|
-
function runCli(main) {
|
|
8
|
-
try {
|
|
9
|
-
process.exitCode = main();
|
|
10
|
-
} catch (error) {
|
|
11
|
-
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
12
|
-
process.exitCode = 1;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/guardrails/files.ts
|
|
17
|
-
const SIZE_EXCLUSIONS = [
|
|
18
|
-
{
|
|
19
|
-
kind: "generated",
|
|
20
|
-
patterns: [
|
|
21
|
-
...IGNORE_PATTERNS,
|
|
22
|
-
...AGENT_IGNORE_PATTERNS,
|
|
23
|
-
"**/*.generated.*",
|
|
24
|
-
"**/generated/**",
|
|
25
|
-
"**/__snapshots__/**"
|
|
26
|
-
]
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
kind: "fixtures",
|
|
30
|
-
patterns: ["**/fixtures/**", "**/__fixtures__/**"]
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
kind: "data",
|
|
34
|
-
patterns: [
|
|
35
|
-
"**/locales/**/*.json",
|
|
36
|
-
"**/i18n/**/*.json",
|
|
37
|
-
"**/blocks.json",
|
|
38
|
-
"**/schema.json",
|
|
39
|
-
"**/evals/**/cases.json"
|
|
40
|
-
]
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
kind: "lockfiles",
|
|
44
|
-
patterns: [
|
|
45
|
-
"**/{pnpm-lock.yaml,package-lock.json,npm-shrinkwrap.json,yarn.lock,bun.lock,bun.lockb,Cargo.lock,poetry.lock,uv.lock,Gemfile.lock,composer.lock,go.sum}",
|
|
46
|
-
"**/*.lock",
|
|
47
|
-
"**/*.lockb"
|
|
48
|
-
]
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
kind: "documentation",
|
|
52
|
-
patterns: ["**/CHANGELOG.md", "**/*.{md,mdx,markdown,MD}"]
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
kind: "assets",
|
|
56
|
-
patterns: ["**/*.{png,jpg,jpeg,gif,webp,avif,ico,svg,bmp,tiff,pdf,mp3,wav,ogg,flac,mp4,webm,mov,avi,woff,woff2,ttf,otf,eot,zip,gz,tgz,bz2,xz,7z,tar,rar,wasm,bin,exe,dll,so,dylib,db,sqlite,sqlite3,icns}"]
|
|
57
|
-
}
|
|
58
|
-
];
|
|
59
|
-
function gitFiles(root) {
|
|
60
|
-
return [...new Set(execFileSync("git", [
|
|
61
|
-
"ls-files",
|
|
62
|
-
"--cached",
|
|
63
|
-
"--others",
|
|
64
|
-
"--exclude-standard",
|
|
65
|
-
"-z"
|
|
66
|
-
], {
|
|
67
|
-
cwd: root,
|
|
68
|
-
encoding: "utf8"
|
|
69
|
-
}).split("\0").filter(Boolean))];
|
|
70
|
-
}
|
|
71
|
-
function repositoryRoot(cwd = process.cwd()) {
|
|
72
|
-
return execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
73
|
-
cwd,
|
|
74
|
-
encoding: "utf8"
|
|
75
|
-
}).trim();
|
|
76
|
-
}
|
|
77
|
-
function repositoryPath(root, file) {
|
|
78
|
-
return relative(root, resolve(root, file)).split("\\").join("/");
|
|
79
|
-
}
|
|
80
|
-
function fileBytes(root, file, staged = false) {
|
|
81
|
-
if (staged) {
|
|
82
|
-
const result = spawnSync("git", [
|
|
83
|
-
"cat-file",
|
|
84
|
-
"-s",
|
|
85
|
-
`:${file}`
|
|
86
|
-
], {
|
|
87
|
-
cwd: root,
|
|
88
|
-
encoding: "utf8"
|
|
89
|
-
});
|
|
90
|
-
if (result.error) throw result.error;
|
|
91
|
-
return result.status === 0 ? Number(result.stdout.trim()) : void 0;
|
|
92
|
-
}
|
|
93
|
-
const path = join(root, file);
|
|
94
|
-
if (!existsSync(path)) return void 0;
|
|
95
|
-
const stat = lstatSync(path);
|
|
96
|
-
return stat.isFile() ? stat.size : void 0;
|
|
97
|
-
}
|
|
98
|
-
/** `path.matchesGlob` never lets `*` or `**` cross a segment starting with a dot, so each path is also tried with those dots removed. */
|
|
99
|
-
function isExcluded(file) {
|
|
100
|
-
const undotted = file.replace(/(^|\/)\./gu, "$1");
|
|
101
|
-
return SIZE_EXCLUSIONS.some(({ patterns }) => patterns.some((pattern) => matchesGlob(file, pattern) || matchesGlob(undotted, pattern)));
|
|
102
|
-
}
|
|
103
|
-
function isBinary(root, file, staged) {
|
|
104
|
-
if (staged) return execFileSync("git", ["show", `:${file}`], {
|
|
105
|
-
cwd: root,
|
|
106
|
-
maxBuffer: fileBytes(root, file, true)
|
|
107
|
-
}).subarray(0, 8e3).includes(0);
|
|
108
|
-
const descriptor = openSync(join(root, file), "r");
|
|
109
|
-
try {
|
|
110
|
-
const prefix = Buffer.alloc(8e3);
|
|
111
|
-
const length = readSync(descriptor, prefix, 0, prefix.length, 0);
|
|
112
|
-
return prefix.subarray(0, length).includes(0);
|
|
113
|
-
} finally {
|
|
114
|
-
closeSync(descriptor);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function authoredSizes(root, files = gitFiles(root), staged = false) {
|
|
118
|
-
const sizes = /* @__PURE__ */ new Map();
|
|
119
|
-
for (const input of files) {
|
|
120
|
-
const file = repositoryPath(root, input);
|
|
121
|
-
if (isExcluded(file)) continue;
|
|
122
|
-
const size = fileBytes(root, file, staged);
|
|
123
|
-
if (size !== void 0 && size > 2e4 && isBinary(root, file, staged)) continue;
|
|
124
|
-
if (size !== void 0) sizes.set(file, size);
|
|
125
|
-
}
|
|
126
|
-
return sizes;
|
|
127
|
-
}
|
|
128
|
-
//#endregion
|
|
129
|
-
export { runCli as a, repositoryRoot as i, gitFiles as n, repositoryPath as r, authoredSizes as t };
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { n as TEST_FILE_GLOBS } from "./shared-WC0z3y9F.mjs";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { dirname, join, matchesGlob, relative, sep } from "node:path";
|
|
5
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
//#region src/guardrails/revisions.ts
|
|
8
|
-
function trackedManifests(root) {
|
|
9
|
-
return execFileSync("git", ["ls-files", "-z"], {
|
|
10
|
-
cwd: root,
|
|
11
|
-
encoding: "utf8"
|
|
12
|
-
}).split("\0").filter((file) => file === "package.json" || file.endsWith("/package.json"));
|
|
13
|
-
}
|
|
14
|
-
function linkDependencies(root, worktree) {
|
|
15
|
-
const directories = /* @__PURE__ */ new Set([".", ...trackedManifests(root).map(dirname)]);
|
|
16
|
-
for (const directory of directories) {
|
|
17
|
-
const source = join(root, directory, "node_modules");
|
|
18
|
-
const target = join(worktree, directory, "node_modules");
|
|
19
|
-
if (existsSync(source) && existsSync(dirname(target)) && !existsSync(target)) symlinkSync(source, target, "dir");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/** Compares isolated committed revisions and removes both worktrees even when compilation fails. */
|
|
23
|
-
function compareRevisions(root, baseRef, label, emit) {
|
|
24
|
-
const temporary = mkdtempSync(join(tmpdir(), "antelope-proof-"));
|
|
25
|
-
const worktrees = [];
|
|
26
|
-
const results = [];
|
|
27
|
-
try {
|
|
28
|
-
for (const [side, ref] of [["base", baseRef], ["head", "HEAD"]]) {
|
|
29
|
-
const revision = execFileSync("git", [
|
|
30
|
-
"rev-parse",
|
|
31
|
-
"--verify",
|
|
32
|
-
"--end-of-options",
|
|
33
|
-
`${ref}^{commit}`
|
|
34
|
-
], {
|
|
35
|
-
cwd: root,
|
|
36
|
-
encoding: "utf8",
|
|
37
|
-
stdio: [
|
|
38
|
-
"ignore",
|
|
39
|
-
"pipe",
|
|
40
|
-
"pipe"
|
|
41
|
-
]
|
|
42
|
-
}).trim();
|
|
43
|
-
const worktree = join(temporary, "worktrees", side);
|
|
44
|
-
execFileSync("git", [
|
|
45
|
-
"worktree",
|
|
46
|
-
"add",
|
|
47
|
-
"--quiet",
|
|
48
|
-
"--detach",
|
|
49
|
-
worktree,
|
|
50
|
-
revision
|
|
51
|
-
], {
|
|
52
|
-
cwd: root,
|
|
53
|
-
stdio: [
|
|
54
|
-
"ignore",
|
|
55
|
-
"pipe",
|
|
56
|
-
"pipe"
|
|
57
|
-
]
|
|
58
|
-
});
|
|
59
|
-
worktrees.push(worktree);
|
|
60
|
-
linkDependencies(root, worktree);
|
|
61
|
-
const output = join(temporary, side);
|
|
62
|
-
mkdirSync(output, { recursive: true });
|
|
63
|
-
results.push(emit(worktree, output, join(temporary, "emit", side)));
|
|
64
|
-
}
|
|
65
|
-
const diff = spawnSync("git", [
|
|
66
|
-
"diff",
|
|
67
|
-
"--no-index",
|
|
68
|
-
"--no-color",
|
|
69
|
-
"--no-renames",
|
|
70
|
-
"--no-ext-diff",
|
|
71
|
-
"--no-textconv",
|
|
72
|
-
"--",
|
|
73
|
-
"base",
|
|
74
|
-
"head"
|
|
75
|
-
], {
|
|
76
|
-
cwd: temporary,
|
|
77
|
-
encoding: "utf8",
|
|
78
|
-
maxBuffer: 67108864
|
|
79
|
-
});
|
|
80
|
-
if (diff.error) throw diff.error;
|
|
81
|
-
if (diff.status !== 0 && diff.status !== 1) throw new Error(diff.stderr || "Could not compare revision outputs.");
|
|
82
|
-
const packages = new Set(results.flatMap((result) => result.packages)).size;
|
|
83
|
-
return {
|
|
84
|
-
different: diff.status === 1,
|
|
85
|
-
output: diff.status === 1 ? `${label}: differences against ${baseRef} (committed HEAD).\n${diff.stdout}` : `${label}: ${packages} packages, ${results[1].entries} entries unchanged against ${baseRef} (committed HEAD).\n`
|
|
86
|
-
};
|
|
87
|
-
} finally {
|
|
88
|
-
for (const worktree of worktrees.reverse()) execFileSync("git", [
|
|
89
|
-
"worktree",
|
|
90
|
-
"remove",
|
|
91
|
-
"--force",
|
|
92
|
-
worktree
|
|
93
|
-
], {
|
|
94
|
-
cwd: root,
|
|
95
|
-
stdio: "pipe"
|
|
96
|
-
});
|
|
97
|
-
rmSync(temporary, {
|
|
98
|
-
recursive: true,
|
|
99
|
-
force: true
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
//#endregion
|
|
104
|
-
//#region src/guardrails/typescript.ts
|
|
105
|
-
function packagesAt(root, publishedOnly) {
|
|
106
|
-
return trackedManifests(root).flatMap((file) => {
|
|
107
|
-
const directory = dirname(file);
|
|
108
|
-
if (!existsSync(join(root, directory, "tsconfig.json"))) return [];
|
|
109
|
-
const manifest = JSON.parse(readFileSync(join(root, file), "utf8"));
|
|
110
|
-
if (publishedOnly && manifest.private === true) return [];
|
|
111
|
-
return [{
|
|
112
|
-
directory,
|
|
113
|
-
manifest
|
|
114
|
-
}];
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
/** Loads the consumer's compiler, including a package-local installation in a workspace. */
|
|
118
|
-
function loadTypeScript(directory) {
|
|
119
|
-
return createRequire(join(directory, "package.json"))("typescript");
|
|
120
|
-
}
|
|
121
|
-
function isTestSource(root, file) {
|
|
122
|
-
const path = relative(root, file).split("\\").join("/");
|
|
123
|
-
return TEST_FILE_GLOBS.some((pattern) => matchesGlob(path, pattern));
|
|
124
|
-
}
|
|
125
|
-
function failDiagnostics(compiler, diagnostics) {
|
|
126
|
-
const errors = diagnostics.filter((item) => item.category === compiler.DiagnosticCategory.Error);
|
|
127
|
-
if (errors.length) throw new Error(compiler.formatDiagnostics(errors, {
|
|
128
|
-
getCanonicalFileName: (file) => file,
|
|
129
|
-
getCurrentDirectory: () => process.cwd(),
|
|
130
|
-
getNewLine: () => "\n"
|
|
131
|
-
}));
|
|
132
|
-
}
|
|
133
|
-
/** Declaration inputs are part of the local closure but TypeScript does not emit copies of them. */
|
|
134
|
-
function copyDeclarations(program, directory, output) {
|
|
135
|
-
const sources = program.getSourceFiles().filter((source) => !program.isSourceFileDefaultLibrary(source) && !program.isSourceFileFromExternalLibrary(source) && !relative(directory, source.fileName).startsWith(`..${sep}`) && !isTestSource(directory, source.fileName));
|
|
136
|
-
const authored = sources.filter((source) => !source.isDeclarationFile);
|
|
137
|
-
let root = dirname((authored[0] ?? sources[0])?.fileName ?? join(directory, "index.ts"));
|
|
138
|
-
for (const source of authored.length ? authored : sources) while (relative(root, source.fileName).startsWith(`..${sep}`)) root = dirname(root);
|
|
139
|
-
root = program.getCompilerOptions().rootDir ?? root;
|
|
140
|
-
const files = [];
|
|
141
|
-
for (const source of sources) {
|
|
142
|
-
if (!source.isDeclarationFile) continue;
|
|
143
|
-
const path = relative(root, source.fileName);
|
|
144
|
-
if (path.startsWith(`..${sep}`)) continue;
|
|
145
|
-
const target = join(output, path);
|
|
146
|
-
mkdirSync(dirname(target), { recursive: true });
|
|
147
|
-
writeFileSync(target, source.text);
|
|
148
|
-
files.push(target);
|
|
149
|
-
}
|
|
150
|
-
return files;
|
|
151
|
-
}
|
|
152
|
-
/** Emits with the package's compiler and config; test roots and outputs never enter either proof. */
|
|
153
|
-
function emitPackage(directory, output, declarations) {
|
|
154
|
-
const compiler = loadTypeScript(directory);
|
|
155
|
-
const configPath = join(directory, "tsconfig.json");
|
|
156
|
-
const config = compiler.readConfigFile(configPath, compiler.sys.readFile);
|
|
157
|
-
if (config.error) failDiagnostics(compiler, [config.error]);
|
|
158
|
-
const parsed = compiler.parseJsonConfigFileContent(config.config, compiler.sys, directory);
|
|
159
|
-
failDiagnostics(compiler, parsed.errors);
|
|
160
|
-
const options = {
|
|
161
|
-
...parsed.options,
|
|
162
|
-
rootDir: parsed.options.rootDir ?? (parsed.options.outDir ? void 0 : directory),
|
|
163
|
-
outDir: output,
|
|
164
|
-
declarationDir: declarations ? output : void 0,
|
|
165
|
-
declaration: declarations,
|
|
166
|
-
emitDeclarationOnly: declarations,
|
|
167
|
-
removeComments: true,
|
|
168
|
-
declarationMap: false,
|
|
169
|
-
sourceMap: false,
|
|
170
|
-
inlineSourceMap: false,
|
|
171
|
-
noEmit: false,
|
|
172
|
-
noEmitOnError: false,
|
|
173
|
-
composite: false,
|
|
174
|
-
incremental: false,
|
|
175
|
-
tsBuildInfoFile: void 0,
|
|
176
|
-
outFile: void 0,
|
|
177
|
-
allowImportingTsExtensions: declarations ? parsed.options.allowImportingTsExtensions : false
|
|
178
|
-
};
|
|
179
|
-
const program = compiler.createProgram({
|
|
180
|
-
rootNames: parsed.fileNames.filter((file) => !isTestSource(directory, file)),
|
|
181
|
-
options,
|
|
182
|
-
projectReferences: parsed.projectReferences
|
|
183
|
-
});
|
|
184
|
-
if (declarations) failDiagnostics(compiler, compiler.getPreEmitDiagnostics(program));
|
|
185
|
-
const files = [];
|
|
186
|
-
const result = program.emit(void 0, (file, text, _bom, _onError, sources) => {
|
|
187
|
-
if (sources?.some((source) => isTestSource(directory, source.fileName))) return;
|
|
188
|
-
if (declarations ? !/\.d\.[cm]?ts$/.test(file) : !/\.[cm]?jsx?$/.test(file)) return;
|
|
189
|
-
mkdirSync(dirname(file), { recursive: true });
|
|
190
|
-
writeFileSync(file, text);
|
|
191
|
-
files.push(file);
|
|
192
|
-
});
|
|
193
|
-
if (declarations) failDiagnostics(compiler, result.diagnostics);
|
|
194
|
-
if (declarations) files.push(...copyDeclarations(program, directory, output));
|
|
195
|
-
return {
|
|
196
|
-
compiler,
|
|
197
|
-
files,
|
|
198
|
-
options: parsed.options
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
//#endregion
|
|
202
|
-
export { compareRevisions as i, isTestSource as n, packagesAt as r, emitPackage as t };
|