@antelopejs/tooling-configs 0.4.0 → 0.5.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 +38 -26
- package/dist/bin/api-diff.mjs +235 -37
- package/dist/bin/body-check.mjs +14 -11
- package/dist/bin/capture.mjs +173 -54
- package/dist/bin/check-size.mjs +1 -1
- package/dist/bin/checks.mjs +141 -14
- package/dist/bin/comment-proof.mjs +29 -7
- package/dist/bin/garden.mjs +2 -57
- package/dist/bin/ratchet.mjs +48 -14
- package/dist/bin/suppressions.mjs +3 -3
- package/dist/bin/sync.mjs +74 -41
- package/dist/bin/verify.mjs +898 -366
- package/dist/capture/index.d.mts +6 -1
- package/dist/capture/index.mjs +1 -1
- package/dist/{ci-workflow-37qJa9LX.mjs → ci-workflow-COJUT12b.mjs} +121 -1
- package/dist/eslint.d.mts +16 -3
- package/dist/eslint.mjs +21 -6
- package/dist/formal/index.d.mts +20 -4
- package/dist/formal/index.mjs +71 -19
- package/dist/{map-B23_WMGE.mjs → map-DRyYz_Fw.mjs} +20 -1
- package/dist/oxc/anti-slop/index.mjs +50 -55
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +520 -103
- package/dist/oxc/lint.d.mts +7 -15
- package/dist/oxc/lint.mjs +16 -28
- package/dist/{package-CqqBgE8Y.mjs → package-Dn7VTFUW.mjs} +71 -17
- package/dist/{proof-stamp-DDDC0J6l.mjs → proof-stamp-DLWpPwQE.mjs} +72 -10
- package/dist/{ratchet-Q-JXuZIX.mjs → ratchet-BTiPMqam.mjs} +17 -15
- package/dist/require-safety-comment-for-type-assertion-mnb0CIxa.mjs +181 -0
- package/dist/{scenes-DZVXkcxS.mjs → scenes-d-VQ0LOm.mjs} +4 -1
- package/dist/semver-BDxeEcP_.mjs +57 -0
- package/dist/{suppression-base-9L8dlMQK.mjs → suppression-base-Drnl6Y7F.mjs} +2 -2
- package/dist/{suppression-budget-C0SkPO5R.mjs → suppression-budget-Dvb_IqBo.mjs} +1 -1
- package/dist/{suppressions-DM60NkvL.mjs → suppressions-BroaaGJ_.mjs} +1 -1
- package/dist/{templates-BKZv-BRw.mjs → templates-lJBZFskp.mjs} +8 -3
- package/dist/type-aware-rules-DMuN6sHb.mjs +30 -0
- package/dist/{typescript-DAgQIAAR.mjs → typescript-BBbry7uU.mjs} +123 -27
- package/dist/verify/index.d.mts +60 -15
- package/package.json +3 -1
- package/dist/require-safety-comment-for-type-assertion-BBQ669kj.mjs +0 -83
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//#region src/garden/semver.ts
|
|
2
|
+
const VERSION = /^v?(\d+)\.(\d+)\.(\d+)/;
|
|
3
|
+
function parse(text) {
|
|
4
|
+
const match = VERSION.exec(text.trim());
|
|
5
|
+
return match ? [
|
|
6
|
+
Number(match[1]),
|
|
7
|
+
Number(match[2]),
|
|
8
|
+
Number(match[3])
|
|
9
|
+
] : void 0;
|
|
10
|
+
}
|
|
11
|
+
function compare(a, b) {
|
|
12
|
+
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
13
|
+
}
|
|
14
|
+
function caret(floor) {
|
|
15
|
+
if (floor[0] > 0) return [
|
|
16
|
+
floor[0] + 1,
|
|
17
|
+
0,
|
|
18
|
+
0
|
|
19
|
+
];
|
|
20
|
+
return floor[1] > 0 ? [
|
|
21
|
+
0,
|
|
22
|
+
floor[1] + 1,
|
|
23
|
+
0
|
|
24
|
+
] : [
|
|
25
|
+
0,
|
|
26
|
+
0,
|
|
27
|
+
floor[2] + 1
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
function comparator(term, version) {
|
|
31
|
+
const operator = /^(>=|<=|>|<|=|\^|~)?\s*(.*)$/.exec(term.trim());
|
|
32
|
+
const bound = parse(operator?.[2] ?? "");
|
|
33
|
+
if (!operator || !bound) return true;
|
|
34
|
+
switch (operator[1]) {
|
|
35
|
+
case ">=": return compare(version, bound) >= 0;
|
|
36
|
+
case ">": return compare(version, bound) > 0;
|
|
37
|
+
case "<=": return compare(version, bound) <= 0;
|
|
38
|
+
case "<": return compare(version, bound) < 0;
|
|
39
|
+
case "^": return compare(version, bound) >= 0 && compare(version, caret(bound)) < 0;
|
|
40
|
+
case "~": return compare(version, bound) >= 0 && compare(version, [
|
|
41
|
+
bound[0],
|
|
42
|
+
bound[1] + 1,
|
|
43
|
+
0
|
|
44
|
+
]) < 0;
|
|
45
|
+
default: return compare(version, bound) === 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Whether a plain npm range (`^`, `~`, comparators, `||`, `*`) admits a release; wildcards and tags admit everything. */
|
|
49
|
+
function admits(range, release) {
|
|
50
|
+
const version = parse(release);
|
|
51
|
+
if (!version) return true;
|
|
52
|
+
return range.split("||").some((alternative) => {
|
|
53
|
+
return alternative.replace(/(>=|<=|>|<|=|\^|~)\s+/g, "$1").trim().split(/\s+/).every((term) => comparator(term, version));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { admits as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { l as resolveRevision, o as isAgentFile } from "./files-DJ0TeaTU.mjs";
|
|
2
|
-
import { a as parseBudget, n as SUPPRESSIONS_FILE, o as safetyCeiling, p as coveredLimits } from "./suppression-budget-
|
|
3
|
-
import { o as revisionSuppressions, r as countSuppressions } from "./suppressions-
|
|
2
|
+
import { a as parseBudget, n as SUPPRESSIONS_FILE, o as safetyCeiling, p as coveredLimits } from "./suppression-budget-Dvb_IqBo.mjs";
|
|
3
|
+
import { o as revisionSuppressions, r as countSuppressions } from "./suppressions-BroaaGJ_.mjs";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { spawnSync } from "node:child_process";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as renamedPaths } from "./renames-L2owF5GD.mjs";
|
|
2
2
|
import { o as isAgentFile, r as changedFiles } from "./files-DJ0TeaTU.mjs";
|
|
3
|
-
import { a as openDisablesIn, i as inWorktree, l as worktreeSuppressions, n as configKey, o as revisionSuppressions, r as countSuppressions, s as sortedKeys, t as atRevision } from "./suppressions-
|
|
3
|
+
import { a as openDisablesIn, i as inWorktree, l as worktreeSuppressions, n as configKey, o as revisionSuppressions, r as countSuppressions, s as sortedKeys, t as atRevision } from "./suppressions-BroaaGJ_.mjs";
|
|
4
4
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { join, matchesGlob } from "node:path";
|
|
6
6
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as markerPattern, t as DEFAULT_SAFETY_MARKERS } from "./require-safety-comment-for-type-assertion-
|
|
1
|
+
import { n as markerPattern, t as DEFAULT_SAFETY_MARKERS } from "./require-safety-comment-for-type-assertion-mnb0CIxa.mjs";
|
|
2
2
|
import { a as gitFiles, i as generatedOutput } from "./files-DJ0TeaTU.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { existsSync, lstatSync, readFileSync } from "node:fs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as execCommand } from "./package-Dn7VTFUW.mjs";
|
|
2
2
|
import { isMap, parseDocument } from "yaml";
|
|
3
3
|
//#region src/guardrails/templates.ts
|
|
4
4
|
const PRESET_CONFIGS = [
|
|
@@ -56,7 +56,7 @@ function lefthook(current, manager, tools, ratchet = true) {
|
|
|
56
56
|
"antelopejs-size": { run: `${tools.hookPrefix}${tools.commands.size} --staged {staged_files}` },
|
|
57
57
|
"antelopejs-ratchet": {
|
|
58
58
|
glob,
|
|
59
|
-
run: `${tools.hookPrefix}${tools.commands.ratchet} --staged
|
|
59
|
+
run: `${tools.hookPrefix}${tools.commands.ratchet} --staged`
|
|
60
60
|
},
|
|
61
61
|
"antelopejs-suppressions": {
|
|
62
62
|
glob,
|
|
@@ -105,7 +105,12 @@ if [[ "$(node -p 'process.versions.node.split(".")[0]')" != "$major" ]]; then
|
|
|
105
105
|
fi
|
|
106
106
|
pin="$(node -p 'JSON.parse(require("node:fs").readFileSync("package.json", "utf8")).packageManager || "pnpm"')"
|
|
107
107
|
manager="\${pin%%@*}"
|
|
108
|
-
corepack enable
|
|
108
|
+
if ! corepack enable >/dev/null 2>&1; then
|
|
109
|
+
shims="$HOME/.local/bin"
|
|
110
|
+
mkdir -p "$shims"
|
|
111
|
+
corepack enable --install-directory "$shims"
|
|
112
|
+
export PATH="$shims:$PATH"
|
|
113
|
+
fi
|
|
109
114
|
if [[ "$pin" == *@* ]]; then
|
|
110
115
|
corepack prepare "$pin" --activate
|
|
111
116
|
fi
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/type-aware-rules.ts
|
|
2
|
+
/**
|
|
3
|
+
* The typescript-eslint rules the preset runs with type information, by their
|
|
4
|
+
* name without a plugin prefix. oxlint runs them as `typescript/<rule>` through
|
|
5
|
+
* oxlint-tsgolint, which reads only TypeScript files; the Nuxt ESLint config
|
|
6
|
+
* runs them as `@typescript-eslint/<rule>` on the script blocks of `.vue` files.
|
|
7
|
+
*
|
|
8
|
+
* Five reject an `any` or a type parameter that stands in for `unknown`, which
|
|
9
|
+
* the anti-slop `unknown` and assertion rules never see: a once-used type
|
|
10
|
+
* parameter, `any` passed as a typed argument, assigned to a typed binding or
|
|
11
|
+
* returned as a typed result, and an untyped `.catch` callback variable.
|
|
12
|
+
*/
|
|
13
|
+
const TYPE_AWARE_RULES = [
|
|
14
|
+
"no-unnecessary-type-parameters",
|
|
15
|
+
"no-unsafe-argument",
|
|
16
|
+
"no-unsafe-assignment",
|
|
17
|
+
"no-unsafe-return",
|
|
18
|
+
"use-unknown-in-catch-callback-variable",
|
|
19
|
+
"no-floating-promises",
|
|
20
|
+
"await-thenable",
|
|
21
|
+
"unbound-method",
|
|
22
|
+
"no-meaningless-void-operator",
|
|
23
|
+
"no-misused-spread",
|
|
24
|
+
"no-base-to-string",
|
|
25
|
+
"no-redundant-type-constituents",
|
|
26
|
+
"restrict-template-expressions",
|
|
27
|
+
"require-array-sort-compare"
|
|
28
|
+
];
|
|
29
|
+
//#endregion
|
|
30
|
+
export { TYPE_AWARE_RULES as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as parseManifest } from "./package-Dn7VTFUW.mjs";
|
|
2
2
|
import { u as trackedManifests } from "./files-DJ0TeaTU.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
@@ -97,21 +97,43 @@ function resolveTypeScript(directory) {
|
|
|
97
97
|
} catch (error) {
|
|
98
98
|
if (declaresTypeScript(directory)) throw new Error(`${describePackage(directory)} declares typescript but it cannot be resolved from the package directory, so the compiler it builds with is not available. Install dependencies (run pnpm install) and retry.`, { cause: error });
|
|
99
99
|
return {
|
|
100
|
-
file:
|
|
100
|
+
file: packTypeScript(),
|
|
101
101
|
fallback: true
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
/**
|
|
106
|
-
function
|
|
107
|
-
|
|
105
|
+
/** The TypeScript `dts-bundle-generator` brings, which the pack falls back to. */
|
|
106
|
+
function packTypeScript() {
|
|
107
|
+
return createRequire(createRequire(import.meta.url).resolve("dts-bundle-generator")).resolve("typescript");
|
|
108
|
+
}
|
|
109
|
+
/** Loads the TypeScript at `file`; one without the programmatic API (7 and later) yields only its `version`, so the caller reports it rather than crashing. */
|
|
110
|
+
function requireTypeScript(file) {
|
|
108
111
|
const compiler = createRequire(file)("typescript");
|
|
109
112
|
const root = packageRoot(file);
|
|
110
|
-
if (compiler.sys === void 0 || !("createProgram" in compiler))
|
|
113
|
+
if (compiler.sys === void 0 || !("createProgram" in compiler)) return {
|
|
114
|
+
root,
|
|
115
|
+
version: compiler.version
|
|
116
|
+
};
|
|
111
117
|
return {
|
|
112
|
-
compiler,
|
|
113
118
|
root,
|
|
114
|
-
|
|
119
|
+
compiler
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/** Loads the compiler a package builds with, including a package-local installation in a workspace. A package that declares `typescript` (itself or through its workspace root) but cannot resolve it is an error; only a package that declares none falls back to the one `dts-bundle-generator` brings, with a `notice`. A TypeScript without the programmatic API (7 and later) is an error, unless `javascriptOnly` says the caller only strips comments and emits JavaScript, so the pack's TypeScript emits both revisions instead, with a `notice`. */
|
|
123
|
+
function loadTypeScript(directory, javascriptOnly = false) {
|
|
124
|
+
const { file, fallback } = resolveTypeScript(directory);
|
|
125
|
+
const loaded = requireTypeScript(file);
|
|
126
|
+
if (loaded.compiler !== void 0) return {
|
|
127
|
+
compiler: loaded.compiler,
|
|
128
|
+
root: loaded.root,
|
|
129
|
+
notice: fallback ? `${repositoryDirectory(directory)}: declares no typescript; using the pack's TypeScript ${loaded.compiler.version}\n` : void 0
|
|
130
|
+
};
|
|
131
|
+
const pack = javascriptOnly && !fallback ? requireTypeScript(packTypeScript()) : loaded;
|
|
132
|
+
if (pack.compiler === void 0) throw new Error(`TypeScript ${loaded.version} at ${loaded.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.`);
|
|
133
|
+
return {
|
|
134
|
+
compiler: pack.compiler,
|
|
135
|
+
root: pack.root,
|
|
136
|
+
notice: `${repositoryDirectory(directory)}: TypeScript ${loaded.version} has no programmatic compiler API; emitting JavaScript with the pack's TypeScript ${pack.compiler.version}\n`
|
|
115
137
|
};
|
|
116
138
|
}
|
|
117
139
|
const TEST_SOURCE_GLOBS = [
|
|
@@ -125,16 +147,19 @@ function isTestSource(root, file) {
|
|
|
125
147
|
const path = relative(root, file).split("\\").join("/");
|
|
126
148
|
return TEST_SOURCE_GLOBS.some((pattern) => matchesGlob(path, pattern));
|
|
127
149
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
130
|
-
if (errors.length) throw new Error(compiler.formatDiagnostics(errors, {
|
|
150
|
+
function formatErrors(compiler, diagnostics) {
|
|
151
|
+
return compiler.formatDiagnostics(diagnostics.filter((item) => item.category === compiler.DiagnosticCategory.Error), {
|
|
131
152
|
getCanonicalFileName: (file) => file,
|
|
132
153
|
getCurrentDirectory: () => process.cwd(),
|
|
133
154
|
getNewLine: () => "\n"
|
|
134
|
-
})
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function failDiagnostics(compiler, diagnostics) {
|
|
158
|
+
const errors = formatErrors(compiler, diagnostics);
|
|
159
|
+
if (errors) throw new Error(errors);
|
|
135
160
|
}
|
|
136
161
|
/** Declaration inputs are part of the local closure but TypeScript does not emit copies of them. */
|
|
137
|
-
function copyDeclarations(program, directory, output) {
|
|
162
|
+
function copyDeclarations(program, directory, output, modules) {
|
|
138
163
|
const sources = program.getSourceFiles().filter((source) => !program.isSourceFileDefaultLibrary(source) && !program.isSourceFileFromExternalLibrary(source) && !relative(directory, source.fileName).startsWith(`..${sep}`) && !isTestSource(directory, source.fileName));
|
|
139
164
|
const authored = sources.filter((source) => !source.isDeclarationFile);
|
|
140
165
|
let root = dirname((authored[0] ?? sources[0])?.fileName ?? join(directory, "index.ts"));
|
|
@@ -149,29 +174,79 @@ function copyDeclarations(program, directory, output) {
|
|
|
149
174
|
mkdirSync(dirname(target), { recursive: true });
|
|
150
175
|
writeFileSync(target, source.text);
|
|
151
176
|
files.push(target);
|
|
177
|
+
modules.set(resolve(target), source.fileName);
|
|
152
178
|
}
|
|
153
179
|
return files;
|
|
154
180
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
181
|
+
/** TS18002: `"files": []` without references. */
|
|
182
|
+
const EMPTY_FILES_LIST = 18002;
|
|
183
|
+
function readConfig(directory, javascriptOnly = false) {
|
|
184
|
+
const { compiler, root, notice } = loadTypeScript(directory, javascriptOnly);
|
|
185
|
+
const file = join(directory, "tsconfig.json");
|
|
186
|
+
const config = compiler.readConfigFile(file, compiler.sys.readFile);
|
|
158
187
|
if (config.error) failDiagnostics(compiler, [config.error]);
|
|
159
|
-
const parsed = compiler.parseJsonConfigFileContent(config.config, compiler.sys, directory);
|
|
160
|
-
failDiagnostics(compiler, parsed.errors);
|
|
161
188
|
return {
|
|
162
189
|
compiler,
|
|
163
190
|
root,
|
|
164
191
|
notice,
|
|
165
|
-
parsed
|
|
192
|
+
parsed: compiler.parseJsonConfigFileContent(config.config, compiler.sys, directory, void 0, file)
|
|
166
193
|
};
|
|
167
194
|
}
|
|
195
|
+
/** Parses `tsconfig.json` as `tsc -p` would from the package directory, failing on any configuration error. */
|
|
196
|
+
function parseConfig(directory, javascriptOnly = false) {
|
|
197
|
+
const config = readConfig(directory, javascriptOnly);
|
|
198
|
+
failDiagnostics(config.compiler, config.parsed.errors);
|
|
199
|
+
return config;
|
|
200
|
+
}
|
|
201
|
+
/** Whether `tsconfig.json` has an empty `files` list, references nothing, and so parses to no inputs; read for a JavaScript-only emit, so a compiler without the API falls back as `emitPackage` does. */
|
|
202
|
+
function listsNoFiles(directory) {
|
|
203
|
+
const { parsed } = readConfig(directory, true);
|
|
204
|
+
return parsed.fileNames.length === 0 && parsed.errors.some((error) => error.code === EMPTY_FILES_LIST);
|
|
205
|
+
}
|
|
206
|
+
/** The absolute paths of the configs `tsconfig.json` extends, directly or through another config; read for a JavaScript-only emit, as `listsNoFiles` is. */
|
|
207
|
+
function extendedConfigs(directory) {
|
|
208
|
+
const { compiler } = loadTypeScript(directory, true);
|
|
209
|
+
const file = join(directory, "tsconfig.json");
|
|
210
|
+
const source = compiler.readJsonConfigFile(file, compiler.sys.readFile);
|
|
211
|
+
compiler.parseJsonSourceFileConfigFileContent(source, compiler.sys, directory, void 0, file);
|
|
212
|
+
return (source.extendedSourceFiles ?? []).map((path) => resolve(path));
|
|
213
|
+
}
|
|
214
|
+
/** TypeScript records on parsed options, untyped, the directory of the config that declares `paths`, which its targets resolve against when no `baseUrl` is set. */
|
|
215
|
+
function isRecordedDirectory(value) {
|
|
216
|
+
return typeof value === "string";
|
|
217
|
+
}
|
|
218
|
+
/** The configured `paths`, each target made absolute against `baseUrl`, else the directory of the config that declares `paths`. */
|
|
219
|
+
function absolutePaths(options) {
|
|
220
|
+
const { paths, baseUrl, pathsBasePath } = options;
|
|
221
|
+
if (paths === void 0 || !isRecordedDirectory(pathsBasePath)) return void 0;
|
|
222
|
+
const base = baseUrl ?? pathsBasePath;
|
|
223
|
+
return Object.fromEntries(Object.entries(paths).map(([key, targets]) => [key, targets.map((target) => resolve(base, target))]));
|
|
224
|
+
}
|
|
168
225
|
/** The configured `outDir`, the root under which the declaration half already judges a built path as test output. */
|
|
169
226
|
function outputRoot(directory) {
|
|
170
227
|
return resolve(directory, parseConfig(directory).parsed.options.outDir ?? ".");
|
|
171
228
|
}
|
|
172
|
-
/**
|
|
229
|
+
/** The root TypeScript lays its emit out under: `rootDir`, else the common directory of every authored source in `program`, wherever it sits. */
|
|
230
|
+
function emitRoot(program) {
|
|
231
|
+
const authored = program.getSourceFiles().filter((source) => !source.isDeclarationFile && !program.isSourceFileFromExternalLibrary(source)).map((source) => source.fileName);
|
|
232
|
+
let root = dirname(authored[0] ?? ".");
|
|
233
|
+
for (const file of authored) while (relative(root, file).startsWith(`..${sep}`)) root = dirname(root);
|
|
234
|
+
return program.getCompilerOptions().rootDir ?? root;
|
|
235
|
+
}
|
|
236
|
+
/** The declaration TypeScript withheld for each module with a declaration error, at the path its emit would have used, mapped to that module. */
|
|
237
|
+
function withheldDeclarations(program, diagnostics, output, directory) {
|
|
238
|
+
const root = emitRoot(program);
|
|
239
|
+
const withheld = /* @__PURE__ */ new Map();
|
|
240
|
+
for (const { file } of diagnostics) {
|
|
241
|
+
if (file === void 0 || isTestSource(directory, file.fileName)) continue;
|
|
242
|
+
const path = resolve(output, relative(root, file.fileName)).replace(/\.([cm]?)[jt]sx?$/u, ".d.$1ts");
|
|
243
|
+
withheld.set(path, file.fileName);
|
|
244
|
+
}
|
|
245
|
+
return withheld;
|
|
246
|
+
}
|
|
247
|
+
/** Emits with the package's compiler and config, or for JavaScript alone with the pack's when the package's has no compiler API; test roots and outputs never enter either proof. `modules` maps each emitted, copied or `withheld` file to its source module; `paths` is the configured `paths` with absolute targets. */
|
|
173
248
|
function emitPackage(directory, output, declarations) {
|
|
174
|
-
const { compiler, root, notice, parsed } = parseConfig(directory);
|
|
249
|
+
const { compiler, root, notice, parsed } = parseConfig(directory, !declarations);
|
|
175
250
|
const options = {
|
|
176
251
|
...parsed.options,
|
|
177
252
|
rootDir: parsed.options.rootDir ?? (parsed.options.outDir ? void 0 : directory),
|
|
@@ -196,10 +271,17 @@ function emitPackage(directory, output, declarations) {
|
|
|
196
271
|
options,
|
|
197
272
|
projectReferences: parsed.projectReferences
|
|
198
273
|
});
|
|
199
|
-
if (declarations) failDiagnostics(compiler,
|
|
274
|
+
if (declarations) failDiagnostics(compiler, [
|
|
275
|
+
...program.getConfigFileParsingDiagnostics(),
|
|
276
|
+
...program.getOptionsDiagnostics(),
|
|
277
|
+
...program.getSyntacticDiagnostics(),
|
|
278
|
+
...program.getGlobalDiagnostics(),
|
|
279
|
+
...program.getSemanticDiagnostics()
|
|
280
|
+
]);
|
|
281
|
+
const declarationDiagnostics = declarations ? program.getDeclarationDiagnostics() : [];
|
|
200
282
|
const files = [];
|
|
201
283
|
const modules = /* @__PURE__ */ new Map();
|
|
202
|
-
|
|
284
|
+
program.emit(void 0, (file, text, _bom, _onError, sources) => {
|
|
203
285
|
if (sources?.some((source) => isTestSource(directory, source.fileName))) return;
|
|
204
286
|
if (declarations ? !/\.d\.[cm]?ts$/.test(file) : !/\.[cm]?jsx?$/.test(file)) return;
|
|
205
287
|
mkdirSync(dirname(file), { recursive: true });
|
|
@@ -207,16 +289,30 @@ function emitPackage(directory, output, declarations) {
|
|
|
207
289
|
files.push(file);
|
|
208
290
|
if (sources?.[0] !== void 0) modules.set(resolve(file), sources[0].fileName);
|
|
209
291
|
});
|
|
210
|
-
|
|
211
|
-
if (declarations) files.push(...copyDeclarations(program, directory, output));
|
|
292
|
+
const withheld = withheldDeclarations(program, declarationDiagnostics, output, directory);
|
|
293
|
+
if (declarations) files.push(...copyDeclarations(program, directory, output, modules));
|
|
294
|
+
for (const [file, source] of withheld) modules.set(file, source);
|
|
212
295
|
return {
|
|
213
296
|
compiler,
|
|
214
297
|
compilerRoot: root,
|
|
215
298
|
notice,
|
|
216
299
|
files,
|
|
300
|
+
withheld: [...withheld.keys()],
|
|
217
301
|
modules,
|
|
218
|
-
options: parsed.options
|
|
302
|
+
options: parsed.options,
|
|
303
|
+
paths: absolutePaths(parsed.options),
|
|
304
|
+
/** The formatted declaration errors of the modules `sources` reach; empty when there are none. A declaration error in a module no published entry reaches never fails the proof. */
|
|
305
|
+
declarationErrors(sources) {
|
|
306
|
+
if (!declarationDiagnostics.length) return "";
|
|
307
|
+
const reached = new Set(compiler.createProgram({
|
|
308
|
+
rootNames: sources,
|
|
309
|
+
options,
|
|
310
|
+
projectReferences: parsed.projectReferences,
|
|
311
|
+
oldProgram: program
|
|
312
|
+
}).getSourceFiles().map((source) => source.fileName));
|
|
313
|
+
return formatErrors(compiler, declarationDiagnostics.filter((item) => item.file !== void 0 && reached.has(item.file.fileName)));
|
|
314
|
+
}
|
|
219
315
|
};
|
|
220
316
|
}
|
|
221
317
|
//#endregion
|
|
222
|
-
export {
|
|
318
|
+
export { listsNoFiles as a, packagesAt as c, isTestSource as i, unpublishedAt as l, extendedConfigs as n, loadTypeScript as o, isExportPath as r, outputRoot as s, emitPackage as t };
|
package/dist/verify/index.d.mts
CHANGED
|
@@ -83,11 +83,23 @@ interface CommandResult {
|
|
|
83
83
|
stdout: string;
|
|
84
84
|
stderr: string;
|
|
85
85
|
}
|
|
86
|
+
/** A journey's HTTP request. `headers` win over the `content-type: application/json` a `body` gets by default. */
|
|
87
|
+
interface HttpInit {
|
|
88
|
+
method?: string;
|
|
89
|
+
body?: string;
|
|
90
|
+
headers?: {
|
|
91
|
+
[name: string]: string;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
86
94
|
/** The answer of an HTTP request, or the network error when nothing answered. */
|
|
87
95
|
interface HttpResult {
|
|
88
96
|
folder: string;
|
|
89
97
|
url: string;
|
|
90
98
|
status: number | null;
|
|
99
|
+
/** The response headers, names lower-cased; empty when nothing answered. */
|
|
100
|
+
headers: {
|
|
101
|
+
[name: string]: string;
|
|
102
|
+
};
|
|
91
103
|
body: string;
|
|
92
104
|
json: JsonValue | undefined;
|
|
93
105
|
error: string | null;
|
|
@@ -97,12 +109,16 @@ interface TreeRecord {
|
|
|
97
109
|
folder: string;
|
|
98
110
|
lines: string[];
|
|
99
111
|
}
|
|
100
|
-
/** Options of `
|
|
112
|
+
/** Options of `context.dev`: extra environment and extra flags such as `--watch`. */
|
|
101
113
|
interface DevOptions {
|
|
102
114
|
env?: {
|
|
103
115
|
[name: string]: string;
|
|
104
116
|
};
|
|
105
117
|
args?: string[];
|
|
118
|
+
/**
|
|
119
|
+
* The program and arguments that start the project in place of `ajs project dev`, for a project that is not an `ajs` project, such as `["node", "ace", "serve"]`. `args` follow it.
|
|
120
|
+
*/
|
|
121
|
+
command?: [program: string, ...args: string[]];
|
|
106
122
|
}
|
|
107
123
|
/** Options of a driven command. */
|
|
108
124
|
interface DriveOptions {
|
|
@@ -116,7 +132,7 @@ interface DriveOptions {
|
|
|
116
132
|
interface CallRequest {
|
|
117
133
|
/** The interface package; defaults to the interface under verification, or the module's only implemented interface. */
|
|
118
134
|
interface?: string;
|
|
119
|
-
/** The export subpath,
|
|
135
|
+
/** The export subpath; defaults to the interface's only entry, else `.`. */
|
|
120
136
|
entry?: string;
|
|
121
137
|
/** The member path inside the entry, for example `["GetClient"]`. */
|
|
122
138
|
path: string[];
|
|
@@ -154,13 +170,12 @@ interface JourneyContext {
|
|
|
154
170
|
readonly work: string;
|
|
155
171
|
/** The journey's own HOME. */
|
|
156
172
|
readonly home: string;
|
|
173
|
+
/** Runs a program. A project whose `.antelope/cache` gains more than one module during it keeps no cache for later journeys; run `ajs` through `ajs` to keep one. */
|
|
157
174
|
command(name: string, program: string, args: string[], options?: DriveOptions): Promise<CommandResult>;
|
|
175
|
+
/** Writes `content` to `file` in a new step and returns the step folder; a file with other hard links gets a new inode, so the write reaches no other path. */
|
|
158
176
|
edit(name: string, file: string, content: string): string;
|
|
159
177
|
tree(name: string, root: string): TreeRecord;
|
|
160
|
-
http(name: string, url: string, init?:
|
|
161
|
-
method?: string;
|
|
162
|
-
body?: string;
|
|
163
|
-
}): Promise<HttpResult>;
|
|
178
|
+
http(name: string, url: string, init?: HttpInit): Promise<HttpResult>;
|
|
164
179
|
/** Records the checks of a step. A failing `critical` step ends the journey. */
|
|
165
180
|
expect(folder: string, checks: Check[], options?: {
|
|
166
181
|
critical?: boolean;
|
|
@@ -182,14 +197,14 @@ interface JourneyContext {
|
|
|
182
197
|
fixture(options?: {
|
|
183
198
|
moduleConfig?: JsonObject;
|
|
184
199
|
}): string;
|
|
185
|
-
/** Starts `ajs project dev` in a project and waits until it is ready. */
|
|
200
|
+
/** Starts `ajs project dev`, or `options.command`, in a project, records its PID for `stop` and `clean`, and waits until it is ready. */
|
|
186
201
|
dev(name: string, project: string, options?: DevOptions): Promise<App>;
|
|
187
202
|
call(name: string, app: App, request: CallRequest): Promise<CallResult>;
|
|
188
203
|
/** Stops an app with SIGINT by recorded PID. */
|
|
189
204
|
stop(name: string, app: App): Promise<StopResult>;
|
|
190
205
|
/**
|
|
191
|
-
* Creates a project from the template under verification with `ajs project init
|
|
192
|
-
* Once init succeeds, the project's `.antelope/cache` starts as a copy of a cache of registry modules an earlier passing journey of the run left exactly as a fresh `ajs` install leaves it, none installed from a lock record.
|
|
206
|
+
* Creates a project from the template under verification with `ajs project init`, or a module with `ajs module init` when `template.module` is set.
|
|
207
|
+
* Once a project init succeeds, the project's `.antelope/cache` starts as a copy of a cache of registry modules an earlier passing journey of the run left exactly as a fresh `ajs` install leaves it, none installed from a lock record.
|
|
193
208
|
*/
|
|
194
209
|
scaffold(name: string, project: string, flags?: string[]): Promise<CommandResult>;
|
|
195
210
|
/**
|
|
@@ -207,12 +222,20 @@ interface JourneyContext {
|
|
|
207
222
|
* that build's evidence under `build/`. A build that is not kept is built
|
|
208
223
|
* again by the next journey. Rerunning the journey that built builds again.
|
|
209
224
|
* In a copy, an absolute symlink into the built folder points to the same
|
|
210
|
-
* path in the copy; every other symlink keeps its target.
|
|
225
|
+
* path in the copy; every other symlink keeps its target. A file with a hard
|
|
226
|
+
* link outside the built folder, such as a package file pnpm links from its
|
|
227
|
+
* store, is linked into each copy rather than copied: `edit` gives it a new
|
|
228
|
+
* inode, and a journey that writes it another way replaces it instead of
|
|
229
|
+
* writing it in place. `build` writes
|
|
211
230
|
* only inside the folder it is given: what it writes elsewhere, such as a
|
|
212
231
|
* sibling in the journey's work folder or the repository, stays with the
|
|
213
232
|
* journey that built. Two journeys that ask for the same key at once, in
|
|
214
233
|
* concurrent `journey` commands, both build, and the first to finish is
|
|
215
|
-
* kept.
|
|
234
|
+
* kept. A project `build` creates with `scaffold` starts each copy as
|
|
235
|
+
* `scaffold` starts one: a copy whose `.antelope/cache` holds no module
|
|
236
|
+
* gets a cache an earlier passing journey kept, and a passing journey keeps
|
|
237
|
+
* the registry modules installed into its copy for later journeys.
|
|
238
|
+
* The commands `build` runs get a HOME of their own, deleted when
|
|
216
239
|
* `build` ends, so what they write there (`ajs config set git`, caches) is
|
|
217
240
|
* never kept and every journey continues with its own HOME. Every journey
|
|
218
241
|
* passes the same `build` for a key. `key` is lowercase letters and digits
|
|
@@ -256,6 +279,25 @@ interface TemplateProbe {
|
|
|
256
279
|
/** How long the process must keep running after `log` matches, 3000 ms by default: core prints nothing once modules start. */
|
|
257
280
|
settleMs?: number;
|
|
258
281
|
}
|
|
282
|
+
/** A module the fixture project loads next to the module under verification: its `antelope.config.ts` source and config. */
|
|
283
|
+
type CompanionModule = {
|
|
284
|
+
source: JsonObject;
|
|
285
|
+
config?: JsonObject;
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* How `ajs` creates from a template. A project template (`project`) is listed
|
|
289
|
+
* under `projectTemplates` and created with `ajs project init`; a module
|
|
290
|
+
* template (`module`) is listed under `templates` and created with
|
|
291
|
+
* `ajs module init`; any other template is listed under `templates` and
|
|
292
|
+
* created as the app module of a project with `ajs project init`.
|
|
293
|
+
*/
|
|
294
|
+
type TemplateInit = {
|
|
295
|
+
project?: boolean;
|
|
296
|
+
module?: false;
|
|
297
|
+
} | {
|
|
298
|
+
module: true;
|
|
299
|
+
project?: false;
|
|
300
|
+
};
|
|
259
301
|
/** The repo-owned layer of a shared verification skill: `.agents/skills/verify-<kind>/verify.config.ts`. */
|
|
260
302
|
interface VerifyConfig<Api = never> {
|
|
261
303
|
doors: DoorRules;
|
|
@@ -283,13 +325,16 @@ interface VerifyConfig<Api = never> {
|
|
|
283
325
|
};
|
|
284
326
|
/** The module kind's configuration of the module under verification. */
|
|
285
327
|
moduleConfig?(services: ServiceEndpoint[]): JsonObject;
|
|
328
|
+
/** Other modules every fixture project loads, keyed by module name, such as the provider of an interface the module imports that nothing else implements. */
|
|
329
|
+
companions?(services: ServiceEndpoint[]): {
|
|
330
|
+
[name: string]: CompanionModule;
|
|
331
|
+
};
|
|
286
332
|
interface?: InterfaceHooks<Api>;
|
|
287
|
-
/** The template kind: its name in the offline manifest,
|
|
333
|
+
/** The template kind: its name in the offline manifest, how `ajs` creates from it, and its readiness probe. */
|
|
288
334
|
template?: {
|
|
289
335
|
name?: string;
|
|
290
|
-
project?: boolean;
|
|
291
336
|
probe: TemplateProbe;
|
|
292
|
-
};
|
|
337
|
+
} & TemplateInit;
|
|
293
338
|
}
|
|
294
339
|
//#endregion
|
|
295
340
|
//#region src/verify/checks.d.ts
|
|
@@ -320,4 +365,4 @@ declare function answers(result: HttpResult, key: string, expected: JsonValue):
|
|
|
320
365
|
/** Nothing answered the request. */
|
|
321
366
|
declare function refused(result: HttpResult): Check;
|
|
322
367
|
//#endregion
|
|
323
|
-
export { type App, type BehaviourMethod, type CallRequest, type CallResult, type Check, type CommandResult, type DevOptions, type DoorKind, type DoorRule, type DoorRules, type DriveOptions, type FormalCheck, type HttpResult, type InterfaceCall, type InterfaceHooks, type Journey, type JourneyContext, type ServiceDefinition, type ServiceEndpoint, type StopResult, type TemplateProbe, type VerifyConfig, answered, answers, equal, exists, exitIs, fileHas, has, interrupted, lacks, refused };
|
|
368
|
+
export { type App, type BehaviourMethod, type CallRequest, type CallResult, type Check, type CommandResult, type CompanionModule, type DevOptions, type DoorKind, type DoorRule, type DoorRules, type DriveOptions, type FormalCheck, type HttpInit, type HttpResult, type InterfaceCall, type InterfaceHooks, type Journey, type JourneyContext, type ServiceDefinition, type ServiceEndpoint, type StopResult, type TemplateInit, type TemplateProbe, type VerifyConfig, answered, answers, equal, exists, exitIs, fileHas, has, interrupted, lacks, refused };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/tooling-configs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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",
|
|
@@ -88,6 +88,8 @@
|
|
|
88
88
|
"@nuxt/eslint-config": "^1.17.0",
|
|
89
89
|
"@types/node": "^24.13.3",
|
|
90
90
|
"@types/semver": "^7.8.0",
|
|
91
|
+
"@typescript-eslint/parser": "8.69.0",
|
|
92
|
+
"eslint": "10.9.1",
|
|
91
93
|
"eslint-plugin-perfectionist": "^5.11.0",
|
|
92
94
|
"knip": "^6.34.0",
|
|
93
95
|
"lefthook": "^2.2.2",
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
//#region src/oxc/anti-slop/rules/require-safety-comment-for-type-assertion.ts
|
|
3
|
-
const DEFAULT_SAFETY_MARKERS = ["SAFETY"];
|
|
4
|
-
const commentOwnerKinds = /* @__PURE__ */ new Set([
|
|
5
|
-
"ExpressionStatement",
|
|
6
|
-
"PropertyDefinition",
|
|
7
|
-
"ReturnStatement",
|
|
8
|
-
"ThrowStatement",
|
|
9
|
-
"VariableDeclaration"
|
|
10
|
-
]);
|
|
11
|
-
function isConstAssertion(node) {
|
|
12
|
-
return node.typeAnnotation.type === "TSTypeReference" && node.typeAnnotation.typeName.type === "Identifier" && node.typeAnnotation.typeName.name === "const";
|
|
13
|
-
}
|
|
14
|
-
function configuredSafetyMarkers(option) {
|
|
15
|
-
if (typeof option !== "object" || option === null || !("markers" in option)) return DEFAULT_SAFETY_MARKERS;
|
|
16
|
-
const configured = option.markers;
|
|
17
|
-
if (!Array.isArray(configured)) return DEFAULT_SAFETY_MARKERS;
|
|
18
|
-
const markers = configured.flatMap((marker) => typeof marker === "string" && marker.trim().length > 0 ? [marker.trim()] : []);
|
|
19
|
-
return markers.length > 0 ? markers : DEFAULT_SAFETY_MARKERS;
|
|
20
|
-
}
|
|
21
|
-
function markerPattern(markers) {
|
|
22
|
-
const alternation = markers.map((marker) => marker.replaceAll(/[.*+?^${}()|[\]\\]/gu, String.raw`\$&`)).join("|");
|
|
23
|
-
return new RegExp(String.raw`(?:^|[^\p{L}\p{N}_])(?:${alternation})\s*:\s*\S`, "u");
|
|
24
|
-
}
|
|
25
|
-
function hasSafetyJustificationBefore(sourceCode, owner, assertion, pattern) {
|
|
26
|
-
return sourceCode.getCommentsBefore(owner).some((comment) => comment.end <= assertion.start && pattern.test(comment.value));
|
|
27
|
-
}
|
|
28
|
-
function hasSafetyComment(sourceCode, node, pattern) {
|
|
29
|
-
let current = node;
|
|
30
|
-
while (true) {
|
|
31
|
-
if (hasSafetyJustificationBefore(sourceCode, current, node, pattern)) return true;
|
|
32
|
-
if (commentOwnerKinds.has(current.type)) {
|
|
33
|
-
const exportDeclaration = current.parent;
|
|
34
|
-
return exportDeclaration.type === "ExportNamedDeclaration" && exportDeclaration.declaration === current && hasSafetyJustificationBefore(sourceCode, exportDeclaration, node, pattern);
|
|
35
|
-
}
|
|
36
|
-
if (current.parent.type === "Program") return false;
|
|
37
|
-
current = current.parent;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/** Require every non-const type assertion to state the invariant TypeScript cannot express. */
|
|
41
|
-
const requireSafetyCommentForTypeAssertionRule = defineRule({
|
|
42
|
-
meta: {
|
|
43
|
-
type: "problem",
|
|
44
|
-
docs: { description: "Require a nearby SAFETY comment for every TypeScript type assertion except const assertions." },
|
|
45
|
-
messages: { missingSafetyComment: "This type assertion has no `{{marker}}:` justification. State the checked invariant immediately before the assertion or its containing statement." },
|
|
46
|
-
schema: [{
|
|
47
|
-
type: "object",
|
|
48
|
-
properties: { markers: {
|
|
49
|
-
type: "array",
|
|
50
|
-
items: {
|
|
51
|
-
type: "string",
|
|
52
|
-
minLength: 1
|
|
53
|
-
},
|
|
54
|
-
minItems: 1,
|
|
55
|
-
uniqueItems: true
|
|
56
|
-
} },
|
|
57
|
-
additionalProperties: false
|
|
58
|
-
}],
|
|
59
|
-
defaultOptions: [{ markers: ["SAFETY"] }]
|
|
60
|
-
},
|
|
61
|
-
createOnce(context) {
|
|
62
|
-
const patterns = /* @__PURE__ */ new Map();
|
|
63
|
-
const checkAssertion = (node) => {
|
|
64
|
-
if (isConstAssertion(node)) return;
|
|
65
|
-
const markers = configuredSafetyMarkers(context.options?.[0]);
|
|
66
|
-
const patternKey = markers.join("\0");
|
|
67
|
-
const pattern = patterns.get(patternKey) ?? markerPattern(markers);
|
|
68
|
-
patterns.set(patternKey, pattern);
|
|
69
|
-
if (hasSafetyComment(context.sourceCode, node, pattern)) return;
|
|
70
|
-
context.report({
|
|
71
|
-
node,
|
|
72
|
-
messageId: "missingSafetyComment",
|
|
73
|
-
data: { marker: markers[0] ?? DEFAULT_SAFETY_MARKERS[0] }
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
return {
|
|
77
|
-
TSAsExpression: checkAssertion,
|
|
78
|
-
TSTypeAssertion: checkAssertion
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
//#endregion
|
|
83
|
-
export { markerPattern as n, requireSafetyCommentForTypeAssertionRule as r, DEFAULT_SAFETY_MARKERS as t };
|