@antelopejs/tooling-configs 0.5.5 → 0.5.6
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 +16 -4
- package/dist/bin/check-interface-ranges.mjs +3 -112
- package/dist/bin/sync.mjs +109 -18
- package/dist/interface-ranges-CcVSr59f.mjs +116 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
<a href="https://github.com/AntelopeJS/antelopejs"><img data-illustration src="./.github/readme/strip.svg" width="100%" alt="TOOLING · TOOLING CONFIGS: part of AntelopeJS, hexagonal architecture beyond your own code. A glowing button reads Star AntelopeJS."></a>
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
|
|
5
|
+
# @antelopejs/tooling-configs
|
|
6
|
+
|
|
7
|
+
<a href="https://www.npmjs.com/package/@antelopejs/tooling-configs"><img data-illustration alt="npm" src="https://img.shields.io/npm/v/@antelopejs/tooling-configs?style=for-the-badge&labelColor=000000&color=000000"></a> <a href="./LICENSE"><img data-illustration alt="License" src="https://img.shields.io/npm/l/@antelopejs/tooling-configs?style=for-the-badge&labelColor=000000&color=000000"></a> <a href="https://discord.gg/g4pFt6eXqu"><img data-illustration alt="Discord" src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000"></a> <a href="./docs"><img data-illustration alt="Documentation" src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"></a> <a href="https://github.com/AntelopeJS/antelopejs"><img data-illustration alt="Star AntelopeJS" src="https://img.shields.io/github/stars/AntelopeJS/antelopejs?label=Star%20AntelopeJS&style=for-the-badge&labelColor=000000&color=000000&logo=github"></a>
|
|
8
|
+
|
|
9
|
+
**Shared oxlint, oxfmt and Knip presets for AntelopeJS projects, with a command that installs them and fails CI when they drift.**
|
|
10
|
+
|
|
11
|
+
[Documentation](./docs) · [All interfaces and providers](https://github.com/AntelopeJS/antelopejs#ecosystem)
|
|
12
|
+
|
|
7
13
|
</div>
|
|
8
14
|
|
|
9
15
|
The AntelopeJS guardrail pack: shared lint, format and dead-code presets, the commands that install and enforce them in a repository, and a check for the version ranges of interface dependencies.
|
|
@@ -463,6 +469,8 @@ The defaults declare what Knip cannot infer for an AntelopeJS module:
|
|
|
463
469
|
|
|
464
470
|
An implementer must never be handed a breaking minor it does not implement. `workspace:`, `file:` and `link:` specs are skipped. Pass paths to check only those manifests.
|
|
465
471
|
|
|
472
|
+
When the interface sits in the same repository, as in a DMS monorepo, `antelopejs-sync` moves the implementer's range for you: a minor interface release from `0.6.1` to `0.7.0` moves `>=0.6.0 <0.7.0` to `>=0.7.0 <0.8.0`, then sync runs `pnpm install --lockfile-only` so the lockfile follows. The interface is not on npm yet when the release hook runs, so the workspace must link it: set `link-workspace-packages=true` in `.npmrc` or `linkWorkspacePackages: true` in `pnpm-workspace.yaml`. When the relock fails, sync leaves the ranges unmoved and exits 1. An interface `.release-it.json` whose `after:bump` hook runs `pnpm --dir ../.. run sync` and `git add -u ../..` commits both with the release. `antelopejs-sync --check` reports the stale range as drift.
|
|
473
|
+
|
|
466
474
|
```jsonc
|
|
467
475
|
// package.json
|
|
468
476
|
{
|
|
@@ -493,6 +501,10 @@ checks that remain the author's responsibility.
|
|
|
493
501
|
|
|
494
502
|
See [CONTRIBUTING.md](./CONTRIBUTING.md). `pnpm install`, then `pnpm checks` runs the typecheck, lint, format check, Knip, tests, size and sync checks. Repositories with recorded debt also run the ratchet.
|
|
495
503
|
|
|
504
|
+
## Part of AntelopeJS
|
|
505
|
+
|
|
506
|
+
This package belongs to [AntelopeJS](https://github.com/AntelopeJS/antelopejs), the TypeScript framework where modules depend on contracts and the application chooses the provider. The open-source back office [AntelopeJS DMS](https://github.com/AntelopeJS/dms) is built on it.
|
|
507
|
+
|
|
496
508
|
## License
|
|
497
509
|
|
|
498
510
|
[Apache-2.0](./LICENSE), except the vendored anti-slop rules (MIT).
|
|
@@ -1,116 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { n as describeViolation, r as localVersions, t as checkInterfaceRanges } from "../interface-ranges-CcVSr59f.mjs";
|
|
2
3
|
import { readFileSync } from "node:fs";
|
|
3
4
|
import { join, relative } from "node:path";
|
|
4
5
|
import { execFileSync } from "node:child_process";
|
|
5
|
-
//#region src/interface-ranges.ts
|
|
6
|
-
/**
|
|
7
|
-
* At startup `@antelopejs/core` keeps one copy of each interface package, the
|
|
8
|
-
* one its implementing module installed, and refuses to start when any loaded
|
|
9
|
-
* module declares a range that copy falls outside. An exact pin (`0.1.7`) or a
|
|
10
|
-
* 0.x caret (`^0.1.2` means `<0.2.0`) therefore stops a module from starting
|
|
11
|
-
* as soon as the implementer resolves the next interface release, with no
|
|
12
|
-
* change to the module itself.
|
|
13
|
-
*
|
|
14
|
-
* A consumer accepts every release from its floor up to the next breaking one
|
|
15
|
-
* (`>=0.1.7 <1.0.0`). The module that implements an interface is the opposite
|
|
16
|
-
* case: it must never be handed a breaking minor it does not implement, so it
|
|
17
|
-
* caps the range below the next minor (`>=0.3.0 <0.4.0`) while the interface
|
|
18
|
-
* is 0.x.
|
|
19
|
-
*/
|
|
20
|
-
const INTERFACE_PACKAGE_PREFIX = "@antelopejs/interface-";
|
|
21
|
-
/** A module's own interface linked from the workspace is the copy it builds against, not a release it resolves. */
|
|
22
|
-
const LOCAL_SPEC_PREFIXES = [
|
|
23
|
-
"workspace:",
|
|
24
|
-
"file:",
|
|
25
|
-
"link:"
|
|
26
|
-
];
|
|
27
|
-
/** The fields `@antelopejs/core` checks at startup. */
|
|
28
|
-
const CHECKED_FIELDS = ["dependencies", "optionalDependencies"];
|
|
29
|
-
const BOUNDED_RANGE = /^>=(\d+)\.(\d+)\.(\d+) <(\d+)\.(\d+)\.(\d+)$/;
|
|
30
|
-
const SINGLE_VERSION = /^[\^~=]?v?(\d+)\.(\d+)\.(\d+)$/;
|
|
31
|
-
const formatVersion = ([major, minor, patch]) => `${major}.${minor}.${patch}`;
|
|
32
|
-
const sameVersion = (a, b) => a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
|
|
33
|
-
/** The first release a module declaring `floor` must not be handed. */
|
|
34
|
-
function rangeCeiling(floor, role) {
|
|
35
|
-
const [major, minor] = floor;
|
|
36
|
-
if (major > 0) return [
|
|
37
|
-
major + 1,
|
|
38
|
-
0,
|
|
39
|
-
0
|
|
40
|
-
];
|
|
41
|
-
return role === "implementer" ? [
|
|
42
|
-
0,
|
|
43
|
-
minor + 1,
|
|
44
|
-
0
|
|
45
|
-
] : [
|
|
46
|
-
1,
|
|
47
|
-
0,
|
|
48
|
-
0
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
function expectedRange(floor, role) {
|
|
52
|
-
return `>=${formatVersion(floor)} <${formatVersion(rangeCeiling(floor, role))}`;
|
|
53
|
-
}
|
|
54
|
-
function toVersion(match, offset) {
|
|
55
|
-
return [
|
|
56
|
-
Number(match[offset]),
|
|
57
|
-
Number(match[offset + 1]),
|
|
58
|
-
Number(match[offset + 2])
|
|
59
|
-
];
|
|
60
|
-
}
|
|
61
|
-
/** The lowest release `spec` accepts, when it is a shape this check reads. */
|
|
62
|
-
function readFloor(spec) {
|
|
63
|
-
const bounded = BOUNDED_RANGE.exec(spec);
|
|
64
|
-
if (bounded) return toVersion(bounded, 1);
|
|
65
|
-
const single = SINGLE_VERSION.exec(spec);
|
|
66
|
-
return single ? toVersion(single, 1) : void 0;
|
|
67
|
-
}
|
|
68
|
-
function compareVersions(a, b) {
|
|
69
|
-
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
70
|
-
}
|
|
71
|
-
/** A range is accepted when it is bounded for its role and admits the interface this package builds against. */
|
|
72
|
-
function isAcceptedRange(spec, role, local) {
|
|
73
|
-
const bounded = BOUNDED_RANGE.exec(spec);
|
|
74
|
-
if (!bounded) return false;
|
|
75
|
-
const floor = toVersion(bounded, 1);
|
|
76
|
-
const ceiling = toVersion(bounded, 4);
|
|
77
|
-
if (!sameVersion(ceiling, rangeCeiling(floor, role))) return false;
|
|
78
|
-
return local === void 0 || compareVersions(local, floor) >= 0 && compareVersions(local, ceiling) < 0;
|
|
79
|
-
}
|
|
80
|
-
function isLocalSpec(spec) {
|
|
81
|
-
return LOCAL_SPEC_PREFIXES.some((prefix) => spec.startsWith(prefix));
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* `localVersions` holds the versions of the packages that sit in the same
|
|
85
|
-
* repository. An implemented interface is usually one of them, and its
|
|
86
|
-
* version, rather than the declared floor, decides the minor to stop below.
|
|
87
|
-
*/
|
|
88
|
-
function checkInterfaceRanges(manifest, localVersions = /* @__PURE__ */ new Map()) {
|
|
89
|
-
const implemented = new Set(manifest.antelopeJs?.implements ?? []);
|
|
90
|
-
const violations = [];
|
|
91
|
-
for (const field of CHECKED_FIELDS) for (const [name, spec] of Object.entries(manifest[field] ?? {})) {
|
|
92
|
-
if (!name.startsWith(INTERFACE_PACKAGE_PREFIX) || isLocalSpec(spec)) continue;
|
|
93
|
-
const role = implemented.has(name) ? "implementer" : "consumer";
|
|
94
|
-
const localVersion = localVersions.get(name);
|
|
95
|
-
const local = role === "implementer" && localVersion !== void 0 ? readFloor(localVersion) : void 0;
|
|
96
|
-
if (isAcceptedRange(spec, role, local)) continue;
|
|
97
|
-
const floor = local ?? readFloor(spec);
|
|
98
|
-
violations.push({
|
|
99
|
-
field,
|
|
100
|
-
name,
|
|
101
|
-
spec,
|
|
102
|
-
role,
|
|
103
|
-
expected: floor ? expectedRange(floor, role) : void 0
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return violations;
|
|
107
|
-
}
|
|
108
|
-
function describeViolation(violation) {
|
|
109
|
-
const { field, name, spec, role, expected } = violation;
|
|
110
|
-
const fix = expected ? `use "${expected}"` : role === "implementer" ? "declare it as >=<floor> <next minor>" : "declare it as >=<floor> <1.0.0";
|
|
111
|
-
return `${field}["${name}"] is "${spec}": ${role === "implementer" ? "this package implements it, so it must stop below the next minor" : "it must accept every release up to the next breaking one"}; ${fix}`;
|
|
112
|
-
}
|
|
113
|
-
//#endregion
|
|
114
6
|
//#region src/bin/check-interface-ranges.ts
|
|
115
7
|
/**
|
|
116
8
|
* Every manifest in the repository by default, whatever directory the lint
|
|
@@ -135,10 +27,9 @@ function main() {
|
|
|
135
27
|
path,
|
|
136
28
|
manifest: JSON.parse(readFileSync(path, "utf8"))
|
|
137
29
|
}));
|
|
138
|
-
const
|
|
139
|
-
for (const { manifest } of manifests) if (manifest.name && manifest.version) localVersions.set(manifest.name, manifest.version);
|
|
30
|
+
const versions = localVersions(manifests.map(({ manifest }) => manifest));
|
|
140
31
|
let failures = 0;
|
|
141
|
-
for (const { path, manifest } of manifests) for (const violation of checkInterfaceRanges(manifest,
|
|
32
|
+
for (const { path, manifest } of manifests) for (const violation of checkInterfaceRanges(manifest, versions)) {
|
|
142
33
|
console.error(`${path}: ${describeViolation(violation)}`);
|
|
143
34
|
failures += 1;
|
|
144
35
|
}
|
package/dist/bin/sync.mjs
CHANGED
|
@@ -4,9 +4,10 @@ import { a as managedPackage, c as repositoryTools, f as toolingVersions, l as s
|
|
|
4
4
|
import { t as admits } from "../semver-BDxeEcP_.mjs";
|
|
5
5
|
import { i as presetConfig, n as SETUP_SCRIPT, r as lefthook, t as PRESET_CONFIGS } from "../templates-Dg188oRC.mjs";
|
|
6
6
|
import { a as VERIFY_KINDS, c as isVerifyKind, i as SYNCED_SKILL_FILES, l as skillFolder, o as claudeLink, s as claudeLinkTarget, u as planDocsSkills } from "../shared-igPpEDpS.mjs";
|
|
7
|
+
import { r as localVersions, t as checkInterfaceRanges } from "../interface-ranges-CcVSr59f.mjs";
|
|
7
8
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
8
9
|
import { c as CI_CONTEXT, f as ciWorkflow, i as hasChecksWorkflow, n as ciNodeCallers, p as placeholderTestScript, r as ciRenovateSyncCallers, s as renovateArtifacts, t as MISSING_CHECKS_WORKFLOW, u as CI_PATH } from "../workflow-CPcNc8KL.mjs";
|
|
9
|
-
import { a as gitFiles, c as repositoryRoot } from "../files-DJ0TeaTU.mjs";
|
|
10
|
+
import { a as gitFiles, c as repositoryRoot, u as trackedManifests } from "../files-DJ0TeaTU.mjs";
|
|
10
11
|
import { a as stepsOf, c as workspacePatterns, i as matchingScripts, n as droppedChecksSteps, o as planDocs, s as workspaceDirectories } from "../checks-DqTjyKCC.mjs";
|
|
11
12
|
import { i as recordedRelease, t as measureBaseline } from "../ratchet-1O8k4Dxu.mjs";
|
|
12
13
|
import { n as SUPPRESSIONS_FILE, r as adoptedBudget } from "../suppression-budget-DgYdu6JK.mjs";
|
|
@@ -87,6 +88,19 @@ function untypedDocsFiles(root) {
|
|
|
87
88
|
return [...found];
|
|
88
89
|
}
|
|
89
90
|
//#endregion
|
|
91
|
+
//#region src/guardrails/run-pnpm.ts
|
|
92
|
+
/** Runs pnpm, the only manager the pack's CI installs with, with `args` quietly; returns its output only when it failed. */
|
|
93
|
+
function runPnpm(root, args) {
|
|
94
|
+
const command = ["pnpm", ...args].join(" ");
|
|
95
|
+
const result = spawnSync("pnpm", args, {
|
|
96
|
+
cwd: root,
|
|
97
|
+
encoding: "utf8"
|
|
98
|
+
});
|
|
99
|
+
if (result.error) return `${command} failed: ${result.error.message}`;
|
|
100
|
+
if (result.status === 0) return void 0;
|
|
101
|
+
return `${command} failed (exit ${result.status}).\n${result.stdout}${result.stderr}`.trimEnd();
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
90
104
|
//#region src/guardrails/agents-block.ts
|
|
91
105
|
const AGENTS_BLOCK_START = "<!-- antelopejs-guardrails:start -->";
|
|
92
106
|
const AGENTS_BLOCK_END = "<!-- antelopejs-guardrails:end -->";
|
|
@@ -1923,19 +1937,8 @@ function ensureBranchCleanup(root) {
|
|
|
1923
1937
|
reason: failureText(write)
|
|
1924
1938
|
} : { kind: "enabled" };
|
|
1925
1939
|
}
|
|
1926
|
-
/** Runs pnpm, the only manager the pack's CI installs with, with `args` quietly; returns its output only when it failed. */
|
|
1927
|
-
function run(root, args) {
|
|
1928
|
-
const command = ["pnpm", ...args].join(" ");
|
|
1929
|
-
const result = spawnSync("pnpm", args, {
|
|
1930
|
-
cwd: root,
|
|
1931
|
-
encoding: "utf8"
|
|
1932
|
-
});
|
|
1933
|
-
if (result.error) return `${command} failed: ${result.error.message}`;
|
|
1934
|
-
if (result.status === 0) return void 0;
|
|
1935
|
-
return `${command} failed (exit ${result.status}).\n${result.stdout}${result.stderr}`.trimEnd();
|
|
1936
|
-
}
|
|
1937
1940
|
function install(root) {
|
|
1938
|
-
return
|
|
1941
|
+
return runPnpm(root, ["install"]);
|
|
1939
1942
|
}
|
|
1940
1943
|
function resolveOxfmt(root) {
|
|
1941
1944
|
const require = createRequire(join(root, "package.json"));
|
|
@@ -2087,7 +2090,7 @@ function bootstrap(root) {
|
|
|
2087
2090
|
};
|
|
2088
2091
|
const foreign = FOREIGN_INSTALL_FILES.filter(({ file }) => existsSync(join(root, file)));
|
|
2089
2092
|
paths.push(...ensurePnpmWorkspace(root, foreign.length > 0));
|
|
2090
|
-
const imported = foreign.some(({ importable }) => importable) && !existsSync(join(root, "pnpm-lock.yaml")) ?
|
|
2093
|
+
const imported = foreign.some(({ importable }) => importable) && !existsSync(join(root, "pnpm-lock.yaml")) ? runPnpm(root, ["import"]) : void 0;
|
|
2091
2094
|
if (imported !== void 0) return {
|
|
2092
2095
|
paths,
|
|
2093
2096
|
removed: [],
|
|
@@ -2141,7 +2144,92 @@ function initRepository(root, options = {}) {
|
|
|
2141
2144
|
};
|
|
2142
2145
|
}
|
|
2143
2146
|
//#endregion
|
|
2147
|
+
//#region src/guardrails/interface-ranges-sync.ts
|
|
2148
|
+
/** Each tracked manifest that parses; a fixture that is not JSON is not a package this repository releases. */
|
|
2149
|
+
function tracked(root) {
|
|
2150
|
+
return trackedManifests(root).flatMap((path) => {
|
|
2151
|
+
try {
|
|
2152
|
+
const text = readFileSync(join(root, path), "utf8");
|
|
2153
|
+
return [{
|
|
2154
|
+
path,
|
|
2155
|
+
text,
|
|
2156
|
+
manifest: parseManifest(text)
|
|
2157
|
+
}];
|
|
2158
|
+
} catch {
|
|
2159
|
+
return [];
|
|
2160
|
+
}
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
function movedNote(path, violation) {
|
|
2164
|
+
return `${path}: moved ${violation.field}["${violation.name}"] from "${violation.spec}" to "${violation.expected}", the range of the interface version this repository holds.`;
|
|
2165
|
+
}
|
|
2166
|
+
/** The relock failure, after which the moved manifests are back as they were so the next sync moves them again. */
|
|
2167
|
+
function writeAndRelock(root, manifests, moved) {
|
|
2168
|
+
const rootManifest = manifests.find(({ path }) => path === "package.json");
|
|
2169
|
+
const manager = packageManager(rootManifest?.manifest ?? {});
|
|
2170
|
+
if (manager !== "pnpm") return `${manager} is not pnpm, so sync cannot relock them.`;
|
|
2171
|
+
for (const [path, { after }] of moved) writeFileSync(join(root, path), after);
|
|
2172
|
+
const failure = runPnpm(root, ["install", "--lockfile-only"]);
|
|
2173
|
+
if (failure !== void 0) for (const [path, { before }] of moved) writeFileSync(join(root, path), before);
|
|
2174
|
+
return failure;
|
|
2175
|
+
}
|
|
2176
|
+
/**
|
|
2177
|
+
* Moves each tracked manifest's range for an interface it implements from
|
|
2178
|
+
* this repository to the range `antelopejs-check-interface-ranges` expects,
|
|
2179
|
+
* then relocks, or leaves every manifest as it was when the relock fails. A
|
|
2180
|
+
* minor release of that interface otherwise leaves its module's range below
|
|
2181
|
+
* the new version and fails the check on the release commit. It runs before
|
|
2182
|
+
* the rest of sync, which then plans the docs-compat READMEs from the moved
|
|
2183
|
+
* ranges and the new lockfile. `check` reports the moves without writing.
|
|
2184
|
+
*/
|
|
2185
|
+
function moveInterfaceRanges(root, check) {
|
|
2186
|
+
const manifests = tracked(root);
|
|
2187
|
+
const versions = localVersions(manifests.map(({ manifest }) => manifest));
|
|
2188
|
+
const moves = {
|
|
2189
|
+
paths: [],
|
|
2190
|
+
notes: [],
|
|
2191
|
+
errors: []
|
|
2192
|
+
};
|
|
2193
|
+
const moved = /* @__PURE__ */ new Map();
|
|
2194
|
+
for (const { path, text, manifest } of manifests) {
|
|
2195
|
+
const fixes = checkInterfaceRanges(manifest, versions).filter((violation) => violation.role === "implementer" && violation.expected !== void 0 && versions.has(violation.name));
|
|
2196
|
+
if (!fixes.length) continue;
|
|
2197
|
+
for (const { field, name, expected } of fixes) {
|
|
2198
|
+
const dependencies = manifest[field];
|
|
2199
|
+
if (dependencies && expected) dependencies[name] = expected;
|
|
2200
|
+
}
|
|
2201
|
+
moved.set(path, {
|
|
2202
|
+
before: text,
|
|
2203
|
+
after: serializeManifest(manifest, text)
|
|
2204
|
+
});
|
|
2205
|
+
moves.paths.push(path);
|
|
2206
|
+
moves.notes.push(...fixes.map((fix) => movedNote(path, fix)));
|
|
2207
|
+
}
|
|
2208
|
+
if (check || !moved.size) return moves;
|
|
2209
|
+
const failure = writeAndRelock(root, manifests, moved);
|
|
2210
|
+
if (failure !== void 0) moves.errors.push(`Left the interface ranges in ${moves.paths.join(", ")} unmoved: the lockfile could not follow them. ${failure}`);
|
|
2211
|
+
return moves;
|
|
2212
|
+
}
|
|
2213
|
+
//#endregion
|
|
2144
2214
|
//#region src/bin/sync.ts
|
|
2215
|
+
/** The sync result with the interface range moves that ran before it, or the moves alone when relocking them failed. */
|
|
2216
|
+
function withRangeMoves(ranges, result) {
|
|
2217
|
+
if (!result) return {
|
|
2218
|
+
artifacts: [],
|
|
2219
|
+
paths: [],
|
|
2220
|
+
removed: [],
|
|
2221
|
+
errors: ranges.errors,
|
|
2222
|
+
notes: ranges.notes,
|
|
2223
|
+
verifyNotes: [],
|
|
2224
|
+
advisories: [],
|
|
2225
|
+
dependenciesAdded: false
|
|
2226
|
+
};
|
|
2227
|
+
return {
|
|
2228
|
+
...result,
|
|
2229
|
+
paths: result.errors.length ? [] : [.../* @__PURE__ */ new Set([...ranges.paths, ...result.paths])],
|
|
2230
|
+
notes: [...ranges.notes, ...result.notes]
|
|
2231
|
+
};
|
|
2232
|
+
}
|
|
2145
2233
|
function printSync(result, { check, installed }) {
|
|
2146
2234
|
for (const note of result.notes) process.stdout.write(`Note: ${check || result.errors.length ? "Planned migration. " : ""}${note}\n`);
|
|
2147
2235
|
for (const note of result.verifyNotes) process.stdout.write(`Note: ${note}\n`);
|
|
@@ -2186,12 +2274,15 @@ runCli(() => {
|
|
|
2186
2274
|
if (values.verify !== void 0 && !isVerifyChoice(values.verify)) throw new Error("--verify must be interface, module, template, or custom.");
|
|
2187
2275
|
if (values.init && (values.check || values.profile === "template")) throw new Error("--init sets up a full-profile repository; it cannot be combined with --check or --profile template.");
|
|
2188
2276
|
if (values.init) return init(values.verify);
|
|
2189
|
-
|
|
2190
|
-
|
|
2277
|
+
const root = repositoryRoot();
|
|
2278
|
+
const check = Boolean(values.check);
|
|
2279
|
+
const ranges = moveInterfaceRanges(root, check);
|
|
2280
|
+
return printSync(withRangeMoves(ranges, ranges.errors.length ? void 0 : syncRepository(root, {
|
|
2281
|
+
check,
|
|
2191
2282
|
profile: values.profile,
|
|
2192
2283
|
verify: values.verify
|
|
2193
|
-
}), {
|
|
2194
|
-
check
|
|
2284
|
+
})), {
|
|
2285
|
+
check,
|
|
2195
2286
|
installed: false
|
|
2196
2287
|
});
|
|
2197
2288
|
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
//#region src/interface-ranges.ts
|
|
2
|
+
/**
|
|
3
|
+
* At startup `@antelopejs/core` keeps one copy of each interface package, the
|
|
4
|
+
* one its implementing module installed, and refuses to start when any loaded
|
|
5
|
+
* module declares a range that copy falls outside. An exact pin (`0.1.7`) or a
|
|
6
|
+
* 0.x caret (`^0.1.2` means `<0.2.0`) therefore stops a module from starting
|
|
7
|
+
* as soon as the implementer resolves the next interface release, with no
|
|
8
|
+
* change to the module itself.
|
|
9
|
+
*
|
|
10
|
+
* A consumer accepts every release from its floor up to the next breaking one
|
|
11
|
+
* (`>=0.1.7 <1.0.0`). The module that implements an interface is the opposite
|
|
12
|
+
* case: it must never be handed a breaking minor it does not implement, so it
|
|
13
|
+
* caps the range below the next minor (`>=0.3.0 <0.4.0`) while the interface
|
|
14
|
+
* is 0.x.
|
|
15
|
+
*/
|
|
16
|
+
const INTERFACE_PACKAGE_PREFIX = "@antelopejs/interface-";
|
|
17
|
+
/** A module's own interface linked from the workspace is the copy it builds against, not a release it resolves. */
|
|
18
|
+
const LOCAL_SPEC_PREFIXES = [
|
|
19
|
+
"workspace:",
|
|
20
|
+
"file:",
|
|
21
|
+
"link:"
|
|
22
|
+
];
|
|
23
|
+
/** The fields `@antelopejs/core` checks at startup. */
|
|
24
|
+
const CHECKED_FIELDS = ["dependencies", "optionalDependencies"];
|
|
25
|
+
const BOUNDED_RANGE = /^>=(\d+)\.(\d+)\.(\d+) <(\d+)\.(\d+)\.(\d+)$/;
|
|
26
|
+
const SINGLE_VERSION = /^[\^~=]?v?(\d+)\.(\d+)\.(\d+)$/;
|
|
27
|
+
const formatVersion = ([major, minor, patch]) => `${major}.${minor}.${patch}`;
|
|
28
|
+
const sameVersion = (a, b) => a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
|
|
29
|
+
/** The first release a module declaring `floor` must not be handed. */
|
|
30
|
+
function rangeCeiling(floor, role) {
|
|
31
|
+
const [major, minor] = floor;
|
|
32
|
+
if (major > 0) return [
|
|
33
|
+
major + 1,
|
|
34
|
+
0,
|
|
35
|
+
0
|
|
36
|
+
];
|
|
37
|
+
return role === "implementer" ? [
|
|
38
|
+
0,
|
|
39
|
+
minor + 1,
|
|
40
|
+
0
|
|
41
|
+
] : [
|
|
42
|
+
1,
|
|
43
|
+
0,
|
|
44
|
+
0
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
function expectedRange(floor, role) {
|
|
48
|
+
return `>=${formatVersion(floor)} <${formatVersion(rangeCeiling(floor, role))}`;
|
|
49
|
+
}
|
|
50
|
+
function toVersion(match, offset) {
|
|
51
|
+
return [
|
|
52
|
+
Number(match[offset]),
|
|
53
|
+
Number(match[offset + 1]),
|
|
54
|
+
Number(match[offset + 2])
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
/** The lowest release `spec` accepts, when it is a shape this check reads. */
|
|
58
|
+
function readFloor(spec) {
|
|
59
|
+
const bounded = BOUNDED_RANGE.exec(spec);
|
|
60
|
+
if (bounded) return toVersion(bounded, 1);
|
|
61
|
+
const single = SINGLE_VERSION.exec(spec);
|
|
62
|
+
return single ? toVersion(single, 1) : void 0;
|
|
63
|
+
}
|
|
64
|
+
function compareVersions(a, b) {
|
|
65
|
+
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
66
|
+
}
|
|
67
|
+
/** A range is accepted when it is bounded for its role and admits the interface this package builds against. */
|
|
68
|
+
function isAcceptedRange(spec, role, local) {
|
|
69
|
+
const bounded = BOUNDED_RANGE.exec(spec);
|
|
70
|
+
if (!bounded) return false;
|
|
71
|
+
const floor = toVersion(bounded, 1);
|
|
72
|
+
const ceiling = toVersion(bounded, 4);
|
|
73
|
+
if (!sameVersion(ceiling, rangeCeiling(floor, role))) return false;
|
|
74
|
+
return local === void 0 || compareVersions(local, floor) >= 0 && compareVersions(local, ceiling) < 0;
|
|
75
|
+
}
|
|
76
|
+
function isLocalSpec(spec) {
|
|
77
|
+
return LOCAL_SPEC_PREFIXES.some((prefix) => spec.startsWith(prefix));
|
|
78
|
+
}
|
|
79
|
+
/** The version of each named package among `manifests`, the packages that sit in the same repository. */
|
|
80
|
+
function localVersions(manifests) {
|
|
81
|
+
const versions = /* @__PURE__ */ new Map();
|
|
82
|
+
for (const { name, version } of manifests) if (name && version) versions.set(name, version);
|
|
83
|
+
return versions;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `localVersions` holds the versions of the packages that sit in the same
|
|
87
|
+
* repository. An implemented interface is usually one of them, and its
|
|
88
|
+
* version, rather than the declared floor, decides the minor to stop below.
|
|
89
|
+
*/
|
|
90
|
+
function checkInterfaceRanges(manifest, localVersions = /* @__PURE__ */ new Map()) {
|
|
91
|
+
const implemented = new Set(manifest.antelopeJs?.implements ?? []);
|
|
92
|
+
const violations = [];
|
|
93
|
+
for (const field of CHECKED_FIELDS) for (const [name, spec] of Object.entries(manifest[field] ?? {})) {
|
|
94
|
+
if (!name.startsWith(INTERFACE_PACKAGE_PREFIX) || isLocalSpec(spec)) continue;
|
|
95
|
+
const role = implemented.has(name) ? "implementer" : "consumer";
|
|
96
|
+
const localVersion = localVersions.get(name);
|
|
97
|
+
const local = role === "implementer" && localVersion !== void 0 ? readFloor(localVersion) : void 0;
|
|
98
|
+
if (isAcceptedRange(spec, role, local)) continue;
|
|
99
|
+
const floor = local ?? readFloor(spec);
|
|
100
|
+
violations.push({
|
|
101
|
+
field,
|
|
102
|
+
name,
|
|
103
|
+
spec,
|
|
104
|
+
role,
|
|
105
|
+
expected: floor ? expectedRange(floor, role) : void 0
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return violations;
|
|
109
|
+
}
|
|
110
|
+
function describeViolation(violation) {
|
|
111
|
+
const { field, name, spec, role, expected } = violation;
|
|
112
|
+
const fix = expected ? `use "${expected}"` : role === "implementer" ? "declare it as >=<floor> <next minor>" : "declare it as >=<floor> <1.0.0";
|
|
113
|
+
return `${field}["${name}"] is "${spec}": ${role === "implementer" ? "this package implements it, so it must stop below the next minor" : "it must accept every release up to the next breaking one"}; ${fix}`;
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export { describeViolation as n, localVersions as r, checkInterfaceRanges as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/tooling-configs",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
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",
|