@telorun/analyzer 0.59.0 → 0.61.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/dist/analyzer.d.ts +9 -2
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +38 -10
- package/dist/artifact-layer-index.d.ts +13 -5
- package/dist/artifact-layer-index.d.ts.map +1 -1
- package/dist/artifact-layer-index.js +37 -13
- package/dist/artifact-selector.d.ts +10 -3
- package/dist/artifact-selector.d.ts.map +1 -1
- package/dist/artifact-selector.js +10 -1
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +44 -43
- package/dist/cel-environment.d.ts.map +1 -1
- package/dist/cel-environment.js +35 -0
- package/dist/flatten-for-analyzer.d.ts +4 -0
- package/dist/flatten-for-analyzer.d.ts.map +1 -1
- package/dist/flatten-for-analyzer.js +8 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/kernel-globals.d.ts +1 -1
- package/dist/kernel-globals.d.ts.map +1 -1
- package/dist/kernel-globals.js +15 -1
- package/dist/manifest-schemas.d.ts +407 -0
- package/dist/manifest-schemas.d.ts.map +1 -0
- package/dist/manifest-schemas.js +396 -0
- package/dist/module-file-claims.d.ts +13 -0
- package/dist/module-file-claims.d.ts.map +1 -1
- package/dist/module-file-claims.js +26 -2
- package/dist/module-library.d.ts +97 -0
- package/dist/module-library.d.ts.map +1 -0
- package/dist/module-library.js +162 -0
- package/dist/module-metadata-scope.d.ts +44 -0
- package/dist/module-metadata-scope.d.ts.map +1 -0
- package/dist/module-metadata-scope.js +82 -0
- package/dist/parse-loaded-file.d.ts.map +1 -1
- package/dist/parse-loaded-file.js +16 -0
- package/dist/release/bump-level.d.ts +46 -0
- package/dist/release/bump-level.d.ts.map +1 -0
- package/dist/release/bump-level.js +80 -0
- package/dist/release/changelog.d.ts +36 -0
- package/dist/release/changelog.d.ts.map +1 -0
- package/dist/release/changelog.js +53 -0
- package/dist/release/fragment.d.ts +48 -0
- package/dist/release/fragment.d.ts.map +1 -0
- package/dist/release/fragment.js +84 -0
- package/dist/release/index.d.ts +26 -0
- package/dist/release/index.d.ts.map +1 -0
- package/dist/release/index.js +18 -0
- package/dist/release/ledger.d.ts +53 -0
- package/dist/release/ledger.d.ts.map +1 -0
- package/dist/release/ledger.js +109 -0
- package/dist/release/payload-digest.d.ts +63 -0
- package/dist/release/payload-digest.d.ts.map +1 -0
- package/dist/release/payload-digest.js +65 -0
- package/dist/release/release-plan.d.ts +128 -0
- package/dist/release/release-plan.d.ts.map +1 -0
- package/dist/release/release-plan.js +277 -0
- package/dist/release/version-stamp.d.ts +50 -0
- package/dist/release/version-stamp.d.ts.map +1 -0
- package/dist/release/version-stamp.js +119 -0
- package/dist/release/workspace-config.d.ts +41 -0
- package/dist/release/workspace-config.d.ts.map +1 -0
- package/dist/release/workspace-config.js +60 -0
- package/dist/schema-compat.js +2 -1
- package/dist/validate-module-artifact.d.ts.map +1 -1
- package/dist/validate-module-artifact.js +53 -1
- package/dist/validate-step-inputs.d.ts +1 -1
- package/dist/validate-step-inputs.d.ts.map +1 -1
- package/dist/validate-step-inputs.js +99 -8
- package/package.json +3 -3
- package/src/analyzer.ts +41 -10
- package/src/artifact-layer-index.ts +47 -14
- package/src/artifact-selector.ts +15 -4
- package/src/builtins.ts +45 -43
- package/src/cel-environment.ts +37 -0
- package/src/flatten-for-analyzer.ts +12 -0
- package/src/index.ts +19 -2
- package/src/kernel-globals.ts +23 -1
- package/src/manifest-schemas.ts +408 -0
- package/src/module-file-claims.ts +42 -2
- package/src/module-library.ts +208 -0
- package/src/module-metadata-scope.ts +88 -0
- package/src/parse-loaded-file.ts +16 -0
- package/src/release/bump-level.ts +95 -0
- package/src/release/changelog.ts +62 -0
- package/src/release/fragment.ts +130 -0
- package/src/release/index.ts +66 -0
- package/src/release/ledger.ts +142 -0
- package/src/release/payload-digest.ts +83 -0
- package/src/release/release-plan.ts +392 -0
- package/src/release/version-stamp.ts +142 -0
- package/src/release/workspace-config.ts +81 -0
- package/src/schema-compat.ts +1 -1
- package/src/validate-module-artifact.ts +56 -0
- package/src/validate-step-inputs.ts +109 -9
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `.changes/ledger.yaml` — what each module looks like **as published**.
|
|
3
|
+
*
|
|
4
|
+
* It exists so a gate can answer "does my payload differ from what is published
|
|
5
|
+
* at my current version?" with no network call, no merge base and no
|
|
6
|
+
* credentials: a fork's PR runs the identical computation the release job runs.
|
|
7
|
+
* That is the load-bearing property — the PR gate and the publish gate compute
|
|
8
|
+
* the same number.
|
|
9
|
+
*
|
|
10
|
+
* **It is a cache, never the authority.** A committed digest can disagree with
|
|
11
|
+
* the registry — a hand edit, an `apply` whose publish then failed, a push made
|
|
12
|
+
* outside the pipeline — so `telo publish` still reads the registry, and
|
|
13
|
+
* `telo release verify` reconciles the two on demand. A *missing* entry is not
|
|
14
|
+
* drift: it means nothing is published, which is the correct reading for a
|
|
15
|
+
* module that has never shipped.
|
|
16
|
+
*
|
|
17
|
+
* **It records the registry base**, because canonicalizing a relative `imports:`
|
|
18
|
+
* source writes the destination into the manifest layer — so the digests below
|
|
19
|
+
* are digests *against that base*, and comparing them to digests taken against
|
|
20
|
+
* another one would be comparing two different artifacts.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { Document, parseDocument } from "yaml";
|
|
24
|
+
import { isReleaseVersion } from "./bump-level.js";
|
|
25
|
+
import { normalizeModuleKey, type ModuleKey } from "./fragment.js";
|
|
26
|
+
import type { LayerDigests } from "./payload-digest.js";
|
|
27
|
+
|
|
28
|
+
export const LEDGER_PATH = ".changes/ledger.yaml";
|
|
29
|
+
|
|
30
|
+
export interface LedgerEntry {
|
|
31
|
+
/** The version these digests were taken at — the tag the artifact published
|
|
32
|
+
* under. */
|
|
33
|
+
readonly version: string;
|
|
34
|
+
readonly layers: LayerDigests;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Ledger {
|
|
38
|
+
/**
|
|
39
|
+
* The publish destination base the digests were taken against
|
|
40
|
+
* (`oci://ghcr.io/telorun`). Absent in a workspace that has published nothing
|
|
41
|
+
* yet, which is why it is optional rather than required — but a `check` that
|
|
42
|
+
* has entries and no base cannot reproduce them, and says so.
|
|
43
|
+
*/
|
|
44
|
+
readonly registry?: string;
|
|
45
|
+
readonly modules: ReadonlyMap<ModuleKey, LedgerEntry>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class LedgerError extends Error {}
|
|
49
|
+
|
|
50
|
+
export const EMPTY_LEDGER: Ledger = { modules: new Map() };
|
|
51
|
+
|
|
52
|
+
export function parseLedger(text: string, where: string): Ledger {
|
|
53
|
+
let value: unknown;
|
|
54
|
+
try {
|
|
55
|
+
value = parseDocument(text).toJSON();
|
|
56
|
+
} catch (err) {
|
|
57
|
+
throw new LedgerError(
|
|
58
|
+
`${where} is not valid YAML: ${err instanceof Error ? err.message : String(err)}`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
if (value === null) return EMPTY_LEDGER;
|
|
62
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
63
|
+
throw new LedgerError(`${where} must be a YAML mapping.`);
|
|
64
|
+
}
|
|
65
|
+
const record = value as Record<string, unknown>;
|
|
66
|
+
|
|
67
|
+
for (const key of Object.keys(record)) {
|
|
68
|
+
if (key !== "registry" && key !== "modules") {
|
|
69
|
+
throw new LedgerError(
|
|
70
|
+
`${where}: unknown field '${key}'. The ledger carries 'registry:' and 'modules:'.`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const registry = record.registry;
|
|
76
|
+
if (registry !== undefined && typeof registry !== "string") {
|
|
77
|
+
throw new LedgerError(`${where}: 'registry' must be the publish destination base, as a string.`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const rawModules = record.modules;
|
|
81
|
+
if (rawModules === undefined || rawModules === null) return { ...(registry ? { registry } : {}), modules: new Map() };
|
|
82
|
+
if (typeof rawModules !== "object" || Array.isArray(rawModules)) {
|
|
83
|
+
throw new LedgerError(`${where}: 'modules' must be a mapping of module path to entry.`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const modules = new Map<ModuleKey, LedgerEntry>();
|
|
87
|
+
for (const [key, raw] of Object.entries(rawModules as Record<string, unknown>)) {
|
|
88
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
89
|
+
throw new LedgerError(`${where}: entry '${key}' must be a mapping.`);
|
|
90
|
+
}
|
|
91
|
+
const entry = raw as Record<string, unknown>;
|
|
92
|
+
if (!isReleaseVersion(entry.version)) {
|
|
93
|
+
throw new LedgerError(
|
|
94
|
+
`${where}: entry '${key}' has no major.minor.patch 'version'. The ledger records the ` +
|
|
95
|
+
`version each digest was taken at; without it the digest says nothing.`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
const layers: Record<string, string> = {};
|
|
99
|
+
const rawLayers = entry.layers;
|
|
100
|
+
if (rawLayers !== undefined && rawLayers !== null) {
|
|
101
|
+
if (typeof rawLayers !== "object" || Array.isArray(rawLayers)) {
|
|
102
|
+
throw new LedgerError(`${where}: entry '${key}' has a non-mapping 'layers'.`);
|
|
103
|
+
}
|
|
104
|
+
for (const [layer, digest] of Object.entries(rawLayers as Record<string, unknown>)) {
|
|
105
|
+
if (typeof digest !== "string") {
|
|
106
|
+
throw new LedgerError(`${where}: entry '${key}' layer '${layer}' is not a digest string.`);
|
|
107
|
+
}
|
|
108
|
+
layers[layer] = digest;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
modules.set(normalizeModuleKey(key), { version: entry.version, layers });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return { ...(registry ? { registry } : {}), modules };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Render the ledger.
|
|
119
|
+
*
|
|
120
|
+
* Keys are sorted so a release's ledger diff shows only the modules that moved
|
|
121
|
+
* — the file is committed and reviewed, and a map whose order followed insertion
|
|
122
|
+
* would reorder wholesale on every run.
|
|
123
|
+
*/
|
|
124
|
+
export function serializeLedger(ledger: Ledger): string {
|
|
125
|
+
const modules: Record<string, unknown> = {};
|
|
126
|
+
for (const key of [...ledger.modules.keys()].sort()) {
|
|
127
|
+
const entry = ledger.modules.get(key)!;
|
|
128
|
+
const layers: Record<string, string> = {};
|
|
129
|
+
for (const layer of Object.keys(entry.layers).sort()) layers[layer] = entry.layers[layer];
|
|
130
|
+
modules[key] = { version: entry.version, layers };
|
|
131
|
+
}
|
|
132
|
+
const doc = new Document({
|
|
133
|
+
...(ledger.registry ? { registry: ledger.registry } : {}),
|
|
134
|
+
modules,
|
|
135
|
+
});
|
|
136
|
+
return (
|
|
137
|
+
"# Generated by `telo release apply` — what each module looks like as published.\n" +
|
|
138
|
+
"# A cache of the registry's answer, so a PR gate needs no credentials.\n" +
|
|
139
|
+
"# `telo release verify` reconciles it against the registry.\n" +
|
|
140
|
+
doc.toString({ lineWidth: 0 })
|
|
141
|
+
);
|
|
142
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A module's payload, reduced to one digest per layer — the exact answer to
|
|
3
|
+
* "did this module's artifact change?".
|
|
4
|
+
*
|
|
5
|
+
* It is exact because it is taken from the bytes: it fires for an inlined
|
|
6
|
+
* sibling's edit, for a shared-library fix, and for a transitive bump the
|
|
7
|
+
* lockfile alone moved, none of which touch a file under the module's own
|
|
8
|
+
* directory. No path-scoped rule and no declared-dependency graph can see any of
|
|
9
|
+
* them.
|
|
10
|
+
*
|
|
11
|
+
* The digest itself is `computeFilesIntegrity`, the same framing-independent
|
|
12
|
+
* content digest the published `layers:` index carries — which is what makes the
|
|
13
|
+
* ledger's recorded number and the registry's the same number, comparable
|
|
14
|
+
* without fetching a blob.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { PLATFORM_AXES, type ArtifactSelector, type LayerRole } from "../artifact-selector.js";
|
|
18
|
+
|
|
19
|
+
/** Per-layer integrity, keyed by `layerDigestKey`. */
|
|
20
|
+
export type LayerDigests = Readonly<Record<string, string>>;
|
|
21
|
+
|
|
22
|
+
/** The ledger key for the module's `telo.yaml` layer. */
|
|
23
|
+
export const MANIFEST_LAYER = "manifest";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Ledger keys the registry cannot answer for, and so the ones `telo release
|
|
27
|
+
* verify` reconciles nothing about and must preserve.
|
|
28
|
+
*
|
|
29
|
+
* Exactly one today, and for a structural reason rather than an omission: the
|
|
30
|
+
* published `layers:` index lives *inside* `telo.yaml`, so it cannot carry that
|
|
31
|
+
* file's own digest — the entry would have to be computed over bytes containing
|
|
32
|
+
* it. Nor can the digest be recovered by hashing what the registry serves, since
|
|
33
|
+
* the transport injects the index at push time and the published text is
|
|
34
|
+
* therefore not the text the payload builder produced.
|
|
35
|
+
*
|
|
36
|
+
* It stays in the ledger regardless, because it is the only thing that sees a
|
|
37
|
+
* **manifest-only change**: a schema edit, a new kind, a description, a
|
|
38
|
+
* dependency's version moving into a pin. None of those touch a controller byte,
|
|
39
|
+
* so without this key such a module would report no drift and its fix would ship
|
|
40
|
+
* to nobody — the exact failure the digest exists to prevent.
|
|
41
|
+
*/
|
|
42
|
+
export const LOCALLY_DERIVED_LAYERS: ReadonlySet<string> = new Set([MANIFEST_LAYER]);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A layer's identity within an artifact, as a stable, readable, YAML-plain key.
|
|
46
|
+
*
|
|
47
|
+
* A role alone is not the identity — there is one controller layer per selector
|
|
48
|
+
* — so a selector's axes join the key. Rendered as `controller/js` and
|
|
49
|
+
* `controller/napi+linux+amd64+gnu` rather than through `selectorKey`'s
|
|
50
|
+
* `axis=value;…` form, because this string is read by a human in a ledger diff
|
|
51
|
+
* and written into a plain YAML key; the axis order is `PLATFORM_AXES`, so the
|
|
52
|
+
* rendering is deterministic rather than dependent on how the selector was
|
|
53
|
+
* built.
|
|
54
|
+
*/
|
|
55
|
+
export function layerDigestKey(role: LayerRole | string, selector?: ArtifactSelector): string {
|
|
56
|
+
if (!selector) return role;
|
|
57
|
+
const parts = [selector.format, ...PLATFORM_AXES.map((axis) => selector[axis])].filter(
|
|
58
|
+
(value): value is string => value !== undefined,
|
|
59
|
+
);
|
|
60
|
+
return `${role}/${parts.join("+")}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A layer whose digest differs between two readings, or that exists in only
|
|
64
|
+
* one of them. `before` / `after` are absent when the layer is absent there —
|
|
65
|
+
* a payload that gained or lost a layer changed just as much as one whose
|
|
66
|
+
* bytes moved. */
|
|
67
|
+
export interface LayerChange {
|
|
68
|
+
readonly layer: string;
|
|
69
|
+
readonly before?: string;
|
|
70
|
+
readonly after?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Every layer on which two readings disagree, in key order. Empty means the
|
|
74
|
+
* payloads are byte-identical. */
|
|
75
|
+
export function diffLayerDigests(before: LayerDigests, after: LayerDigests): LayerChange[] {
|
|
76
|
+
const changes: LayerChange[] = [];
|
|
77
|
+
for (const layer of [...new Set([...Object.keys(before), ...Object.keys(after)])].sort()) {
|
|
78
|
+
const a = before[layer];
|
|
79
|
+
const b = after[layer];
|
|
80
|
+
if (a !== b) changes.push({ layer, ...(a ? { before: a } : {}), ...(b ? { after: b } : {}) });
|
|
81
|
+
}
|
|
82
|
+
return changes;
|
|
83
|
+
}
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning evidence into a release plan: which modules bump, to what, and why.
|
|
3
|
+
*
|
|
4
|
+
* Three questions, three mechanisms, and keeping them apart is the whole design:
|
|
5
|
+
*
|
|
6
|
+
* - **Whether** a module bumps is decided by the **payload digest** — exact,
|
|
7
|
+
* from the bytes, so it sees an inlined sibling and a lockfile-only transitive
|
|
8
|
+
* bump that no path-scoped rule can.
|
|
9
|
+
* - **At what level** is decided by the **edge graph** — a declared fragment is a
|
|
10
|
+
* root, and a dependent mirrors its dependency's level, joined as the maximum
|
|
11
|
+
* over paths, because a module that inlines a breaking change is breaking for
|
|
12
|
+
* its own consumers.
|
|
13
|
+
* - **Whether a changelog line is requested** is decided by the path-scoped
|
|
14
|
+
* changed-files rule, which used to decide the version. Demoted, its guesswork
|
|
15
|
+
* costs one sentence rather than a spurious republish.
|
|
16
|
+
*
|
|
17
|
+
* The seam between digest and graph is *reported*, never papered over: a payload
|
|
18
|
+
* that moved with nothing to attribute it to — a third-party dependency, a
|
|
19
|
+
* changesets-owned package inlined into a module, a toolchain bump — resolves to
|
|
20
|
+
* `patch` and says so.
|
|
21
|
+
*
|
|
22
|
+
* Pure data in, plan out. Everything Node-shaped — building payloads, running
|
|
23
|
+
* the controller builder, reading git — is the CLI's half, so the editor can
|
|
24
|
+
* answer "what does changing this library bump?" from the same model.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
applyBump,
|
|
29
|
+
maxLevel,
|
|
30
|
+
type BumpLevel,
|
|
31
|
+
type FragmentKind,
|
|
32
|
+
levelOfKind,
|
|
33
|
+
} from "./bump-level.js";
|
|
34
|
+
import type { ModuleKey, ReleaseFragment } from "./fragment.js";
|
|
35
|
+
import type { Ledger } from "./ledger.js";
|
|
36
|
+
import { diffLayerDigests, type LayerChange, type LayerDigests } from "./payload-digest.js";
|
|
37
|
+
|
|
38
|
+
/** What a module ships. A `Dockerfile` beside the manifest makes it an image
|
|
39
|
+
* module; its absence, a registry artifact module. Derived rather than
|
|
40
|
+
* declared, so discovery stays configuration-free. */
|
|
41
|
+
export type ArtifactKind = "registry" | "image";
|
|
42
|
+
|
|
43
|
+
export interface ModuleEvidence {
|
|
44
|
+
/** Workspace-relative directory path — the module's key everywhere. */
|
|
45
|
+
readonly key: ModuleKey;
|
|
46
|
+
/** `metadata.name`, for display only. */
|
|
47
|
+
readonly name: string;
|
|
48
|
+
/** `metadata.version` as it stands in the working copy. */
|
|
49
|
+
readonly version: string;
|
|
50
|
+
readonly artifactKind: ArtifactKind;
|
|
51
|
+
/** Per-layer integrity of the payload built from the working copy. */
|
|
52
|
+
readonly layers: LayerDigests;
|
|
53
|
+
/**
|
|
54
|
+
* Files this module's build inlined that belong to ANOTHER workspace module,
|
|
55
|
+
* grouped by owner. From the build's own metafile: a declared-dependency graph
|
|
56
|
+
* cannot see `--external`, so `@telorun/sdk` — declared by 54 modules, inlined
|
|
57
|
+
* by none — would otherwise bump the whole standard library on every SDK
|
|
58
|
+
* change.
|
|
59
|
+
*/
|
|
60
|
+
readonly inlines: ReadonlyMap<ModuleKey, readonly string[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Modules reached by an in-repo **relative** `imports:` source. A pinned
|
|
63
|
+
* registry ref is deliberately not an edge: pinning is the statement "I am not
|
|
64
|
+
* affected until I choose to be", and moving it is `telo upgrade`'s job.
|
|
65
|
+
*/
|
|
66
|
+
readonly imports: readonly ModuleKey[];
|
|
67
|
+
/** Whether a file under this module's own directory that reaches the artifact
|
|
68
|
+
* changed. Decides only whether a changelog line is requested. */
|
|
69
|
+
readonly ownFilesChanged: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface ReleaseEvidence {
|
|
73
|
+
readonly modules: readonly ModuleEvidence[];
|
|
74
|
+
readonly ledger: Ledger;
|
|
75
|
+
readonly fragments: readonly ReleaseFragment[];
|
|
76
|
+
/** The publish destination base the digests above were built against. */
|
|
77
|
+
readonly registry?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Why a module is in the plan. A module usually carries several. */
|
|
81
|
+
export type BumpReason =
|
|
82
|
+
| { readonly kind: "declared"; readonly fragment: string; readonly as: FragmentKind }
|
|
83
|
+
| { readonly kind: "inlines"; readonly module: ModuleKey; readonly files: readonly string[] }
|
|
84
|
+
| { readonly kind: "imports"; readonly module: ModuleKey }
|
|
85
|
+
| { readonly kind: "unattributed" };
|
|
86
|
+
|
|
87
|
+
export interface ChangelogEntry {
|
|
88
|
+
readonly kind: FragmentKind;
|
|
89
|
+
readonly body: string;
|
|
90
|
+
/** The fragment this line came from, so `apply` can report what it consumed. */
|
|
91
|
+
readonly fragment: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface PlannedModule {
|
|
95
|
+
readonly key: ModuleKey;
|
|
96
|
+
readonly name: string;
|
|
97
|
+
readonly from: string;
|
|
98
|
+
readonly to: string;
|
|
99
|
+
readonly level: BumpLevel;
|
|
100
|
+
readonly reasons: readonly BumpReason[];
|
|
101
|
+
/** Layers whose digest differs from the ledger's reading. Empty for a module
|
|
102
|
+
* bumping purely because a dependency's version moves into its manifest. */
|
|
103
|
+
readonly changed: readonly LayerChange[];
|
|
104
|
+
readonly entries: readonly ChangelogEntry[];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface ReleaseDiagnostic {
|
|
108
|
+
readonly severity: "error" | "warning";
|
|
109
|
+
readonly code: string;
|
|
110
|
+
readonly message: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface ReleasePlan {
|
|
114
|
+
/** Bumping modules in dependency order — a dependency precedes its
|
|
115
|
+
* dependents, which is also the order `telo publish` must push them. */
|
|
116
|
+
readonly modules: readonly PlannedModule[];
|
|
117
|
+
/** Fragments this plan consumes, for `apply` to delete. */
|
|
118
|
+
readonly fragments: readonly string[];
|
|
119
|
+
readonly diagnostics: readonly ReleaseDiagnostic[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function planRelease(evidence: ReleaseEvidence): ReleasePlan {
|
|
123
|
+
const diagnostics: ReleaseDiagnostic[] = [];
|
|
124
|
+
const byKey = new Map(evidence.modules.map((module) => [module.key, module]));
|
|
125
|
+
|
|
126
|
+
checkRegistryAgreement(evidence, diagnostics);
|
|
127
|
+
|
|
128
|
+
// What the digest says, per module. A module with no ledger entry has never
|
|
129
|
+
// been published, which is not drift — there is nothing to differ from.
|
|
130
|
+
const drift = new Map<ModuleKey, LayerChange[]>();
|
|
131
|
+
for (const module of evidence.modules) {
|
|
132
|
+
const recorded = evidence.ledger.modules.get(module.key);
|
|
133
|
+
if (!recorded) continue;
|
|
134
|
+
if (recorded.version !== module.version) {
|
|
135
|
+
diagnostics.push({
|
|
136
|
+
severity: "error",
|
|
137
|
+
code: "LEDGER_VERSION_MISMATCH",
|
|
138
|
+
message:
|
|
139
|
+
`${module.key} declares version ${module.version} but the ledger records ` +
|
|
140
|
+
`${recorded.version} as published. The digests beside it were taken at that version, ` +
|
|
141
|
+
`so nothing here can be compared. Reconcile with \`telo release verify\` — or, if the ` +
|
|
142
|
+
`version was moved by hand, restore it and let \`telo release apply\` move it.`,
|
|
143
|
+
});
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const changes = diffLayerDigests(recorded.layers, module.layers);
|
|
147
|
+
if (changes.length > 0) drift.set(module.key, changes);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const levels = new Map<ModuleKey, BumpLevel>();
|
|
151
|
+
const reasons = new Map<ModuleKey, BumpReason[]>();
|
|
152
|
+
const addReason = (key: ModuleKey, reason: BumpReason) => {
|
|
153
|
+
const list = reasons.get(key);
|
|
154
|
+
if (list) list.push(reason);
|
|
155
|
+
else reasons.set(key, [reason]);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// Declared roots.
|
|
159
|
+
const consumed = new Set<string>();
|
|
160
|
+
for (const fragment of evidence.fragments) {
|
|
161
|
+
for (const [key, kind] of fragment.modules) {
|
|
162
|
+
if (!byKey.has(key)) {
|
|
163
|
+
diagnostics.push({
|
|
164
|
+
severity: "error",
|
|
165
|
+
code: "FRAGMENT_UNKNOWN_MODULE",
|
|
166
|
+
message:
|
|
167
|
+
`${fragment.source} names '${key}', which is not a module in this workspace. ` +
|
|
168
|
+
`A fragment names a module by its workspace-relative directory path.`,
|
|
169
|
+
});
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const level = levelOfKind(kind);
|
|
173
|
+
if (level === "major") {
|
|
174
|
+
diagnostics.push({
|
|
175
|
+
severity: "error",
|
|
176
|
+
code: "MAJOR_BUMP_REJECTED",
|
|
177
|
+
message:
|
|
178
|
+
`${fragment.source} declares '${key}: ${kind}', which induces a major bump. ` +
|
|
179
|
+
`Modules are intentionally pre-1.0 — a breaking change ships as a minor. ` +
|
|
180
|
+
`Use Added and describe the break in the body.`,
|
|
181
|
+
});
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
consumed.add(fragment.source);
|
|
185
|
+
levels.set(key, maxLevel(levels.get(key) ?? level, level));
|
|
186
|
+
addReason(key, { kind: "declared", fragment: fragment.source, as: kind });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Edges already credited, so a second propagation pass does not repeat an
|
|
191
|
+
// explanation the author has already been given.
|
|
192
|
+
const credited = new Set<string>();
|
|
193
|
+
propagateToFixedPoint(evidence.modules, drift, levels, credited, addReason);
|
|
194
|
+
|
|
195
|
+
// The seam. A payload that moved with nothing to attribute it to still has to
|
|
196
|
+
// ship — the fix would otherwise reach nobody — so it takes a patch and is
|
|
197
|
+
// named. Seeded after propagation and then propagated again, because an
|
|
198
|
+
// unattributed bump is itself a dependency move for anything importing it.
|
|
199
|
+
for (;;) {
|
|
200
|
+
let seeded = false;
|
|
201
|
+
for (const module of evidence.modules) {
|
|
202
|
+
if (levels.has(module.key) || !drift.has(module.key)) continue;
|
|
203
|
+
levels.set(module.key, "patch");
|
|
204
|
+
addReason(module.key, { kind: "unattributed" });
|
|
205
|
+
seeded = true;
|
|
206
|
+
}
|
|
207
|
+
if (!seeded) break;
|
|
208
|
+
propagateToFixedPoint(evidence.modules, drift, levels, credited, addReason);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const entriesByModule = collectChangelogEntries(evidence.fragments, byKey);
|
|
212
|
+
requestMissingChangelogEntries(evidence.modules, entriesByModule, diagnostics);
|
|
213
|
+
|
|
214
|
+
const planned: PlannedModule[] = [];
|
|
215
|
+
for (const module of orderByImports(evidence.modules)) {
|
|
216
|
+
const level = levels.get(module.key);
|
|
217
|
+
if (!level) continue;
|
|
218
|
+
planned.push({
|
|
219
|
+
key: module.key,
|
|
220
|
+
name: module.name,
|
|
221
|
+
from: module.version,
|
|
222
|
+
to: applyBump(module.version, level),
|
|
223
|
+
level,
|
|
224
|
+
reasons: reasons.get(module.key) ?? [],
|
|
225
|
+
changed: drift.get(module.key) ?? [],
|
|
226
|
+
entries: entriesByModule.get(module.key) ?? [],
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return { modules: planned, fragments: [...consumed].sort(), diagnostics };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Raise levels along release edges until nothing moves.
|
|
235
|
+
*
|
|
236
|
+
* The two edge kinds answer different questions and so are gated differently:
|
|
237
|
+
*
|
|
238
|
+
* - An **import** edge bumps unconditionally. Publishing rewrites a relative
|
|
239
|
+
* `imports:` source to `<base>/<sibling>@<version>`, so when the sibling's
|
|
240
|
+
* version moves this module's manifest layer provably changes — a fact about
|
|
241
|
+
* the plan, which the current digest cannot yet show because it was taken
|
|
242
|
+
* against the sibling's *current* version.
|
|
243
|
+
* - An **inline** edge only explains drift that already showed up. The inlined
|
|
244
|
+
* bytes are in this payload, so if they had changed the digest would say so;
|
|
245
|
+
* attributing without that check would bump every dependent of a module whose
|
|
246
|
+
* fragment covers a docs-only change.
|
|
247
|
+
*/
|
|
248
|
+
function propagateToFixedPoint(
|
|
249
|
+
modules: readonly ModuleEvidence[],
|
|
250
|
+
drift: ReadonlyMap<ModuleKey, LayerChange[]>,
|
|
251
|
+
levels: Map<ModuleKey, BumpLevel>,
|
|
252
|
+
credited: Set<string>,
|
|
253
|
+
addReason: (key: ModuleKey, reason: BumpReason) => void,
|
|
254
|
+
): void {
|
|
255
|
+
for (let moved = true; moved; ) {
|
|
256
|
+
moved = false;
|
|
257
|
+
for (const module of modules) {
|
|
258
|
+
for (const dependency of module.imports) {
|
|
259
|
+
moved = raise(module, dependency, { kind: "imports", module: dependency }) || moved;
|
|
260
|
+
}
|
|
261
|
+
if (!drift.has(module.key)) continue;
|
|
262
|
+
for (const [dependency, files] of module.inlines) {
|
|
263
|
+
moved =
|
|
264
|
+
raise(module, dependency, { kind: "inlines", module: dependency, files }) || moved;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function raise(module: ModuleEvidence, dependency: ModuleKey, reason: BumpReason): boolean {
|
|
270
|
+
const from = levels.get(dependency);
|
|
271
|
+
if (!from) return false;
|
|
272
|
+
const current = levels.get(module.key);
|
|
273
|
+
const next = current ? maxLevel(current, from) : from;
|
|
274
|
+
// The reason is recorded the first time this edge carries anything, even
|
|
275
|
+
// when it does not raise the level: it is the explanation the author reads,
|
|
276
|
+
// and an edge that merely agrees with another still says why this module is
|
|
277
|
+
// in the plan.
|
|
278
|
+
const edge = `${module.key}\0${dependency}\0${reason.kind}`;
|
|
279
|
+
if (!credited.has(edge)) {
|
|
280
|
+
credited.add(edge);
|
|
281
|
+
addReason(module.key, reason);
|
|
282
|
+
}
|
|
283
|
+
if (current === next) return false;
|
|
284
|
+
levels.set(module.key, next);
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function collectChangelogEntries(
|
|
290
|
+
fragments: readonly ReleaseFragment[],
|
|
291
|
+
byKey: ReadonlyMap<ModuleKey, ModuleEvidence>,
|
|
292
|
+
): Map<ModuleKey, ChangelogEntry[]> {
|
|
293
|
+
const entries = new Map<ModuleKey, ChangelogEntry[]>();
|
|
294
|
+
for (const fragment of fragments) {
|
|
295
|
+
for (const [key, kind] of fragment.modules) {
|
|
296
|
+
if (!byKey.has(key)) continue;
|
|
297
|
+
const list = entries.get(key);
|
|
298
|
+
const entry: ChangelogEntry = { kind, body: fragment.body, fragment: fragment.source };
|
|
299
|
+
if (list) list.push(entry);
|
|
300
|
+
else entries.set(key, [entry]);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return entries;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Ask for prose where a human made a semantic change.
|
|
308
|
+
*
|
|
309
|
+
* A warning, not an error: `check`'s job is "can a complete, consistent plan be
|
|
310
|
+
* formed", and a module that drifted through propagation or a toolchain bump is
|
|
311
|
+
* planned and released without anyone writing a word. This fires only for a
|
|
312
|
+
* module whose OWN files moved, which is the case where the changelog would
|
|
313
|
+
* otherwise be silent about a real change.
|
|
314
|
+
*/
|
|
315
|
+
function requestMissingChangelogEntries(
|
|
316
|
+
modules: readonly ModuleEvidence[],
|
|
317
|
+
entries: ReadonlyMap<ModuleKey, ChangelogEntry[]>,
|
|
318
|
+
diagnostics: ReleaseDiagnostic[],
|
|
319
|
+
): void {
|
|
320
|
+
const missing = modules
|
|
321
|
+
.filter((module) => module.ownFilesChanged && !entries.has(module.key))
|
|
322
|
+
.map((module) => module.key);
|
|
323
|
+
if (missing.length === 0) return;
|
|
324
|
+
|
|
325
|
+
// ONE diagnostic listing the modules, not one per module. A change that
|
|
326
|
+
// touches every module's build script or a shared config asks the same
|
|
327
|
+
// question about forty of them at once, and forty copies of one sentence bury
|
|
328
|
+
// the plan they are printed beside — the more so because they go to stderr
|
|
329
|
+
// while the plan goes to stdout, so a piped run interleaves them.
|
|
330
|
+
//
|
|
331
|
+
// The fix for all of them is also one fragment, since a fragment names as many
|
|
332
|
+
// modules as it likes.
|
|
333
|
+
diagnostics.push({
|
|
334
|
+
severity: "warning",
|
|
335
|
+
code: "CHANGELOG_ENTRY_REQUESTED",
|
|
336
|
+
message:
|
|
337
|
+
`${missing.length} module(s) have their own changes but no fragment describes them, so ` +
|
|
338
|
+
`their changelogs will not mention this release: ${missing.join(", ")}. ` +
|
|
339
|
+
`One \`telo release add\` can name them all.`,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The base the digests were built against has to be the base they were recorded
|
|
345
|
+
* against, or the manifest layers are not comparable: canonicalization writes
|
|
346
|
+
* the destination into them.
|
|
347
|
+
*/
|
|
348
|
+
function checkRegistryAgreement(
|
|
349
|
+
evidence: ReleaseEvidence,
|
|
350
|
+
diagnostics: ReleaseDiagnostic[],
|
|
351
|
+
): void {
|
|
352
|
+
const recorded = evidence.ledger.registry;
|
|
353
|
+
if (!recorded || !evidence.registry || recorded === evidence.registry) return;
|
|
354
|
+
diagnostics.push({
|
|
355
|
+
severity: "error",
|
|
356
|
+
code: "LEDGER_REGISTRY_MISMATCH",
|
|
357
|
+
message:
|
|
358
|
+
`The ledger's digests were taken against '${recorded}', but this run built against ` +
|
|
359
|
+
`'${evidence.registry}'. Publishing rewrites each relative import to ` +
|
|
360
|
+
`'<base>/<sibling>@<version>', so the manifest layers of the two are different bytes ` +
|
|
361
|
+
`and comparing them would report every module as changed.`,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Dependency order over in-repo imports — a dependency before its dependents.
|
|
367
|
+
*
|
|
368
|
+
* This is also the publish order, and it is not optional there: publishing
|
|
369
|
+
* canonicalizes a relative import and then hard-fails when the derived ref does
|
|
370
|
+
* not already resolve, so a sibling has to be pushed first.
|
|
371
|
+
*
|
|
372
|
+
* A cycle keeps its members in key order rather than throwing. A module graph
|
|
373
|
+
* should not have one, but a release is the wrong moment to discover it, and the
|
|
374
|
+
* ordering degrades to "arbitrary among the cycle" rather than to nothing.
|
|
375
|
+
*/
|
|
376
|
+
export function orderByImports(modules: readonly ModuleEvidence[]): ModuleEvidence[] {
|
|
377
|
+
const byKey = new Map(modules.map((module) => [module.key, module]));
|
|
378
|
+
const ordered: ModuleEvidence[] = [];
|
|
379
|
+
const state = new Map<ModuleKey, "visiting" | "done">();
|
|
380
|
+
|
|
381
|
+
const visit = (key: ModuleKey): void => {
|
|
382
|
+
const module = byKey.get(key);
|
|
383
|
+
if (!module || state.get(key)) return;
|
|
384
|
+
state.set(key, "visiting");
|
|
385
|
+
for (const dependency of [...module.imports].sort()) visit(dependency);
|
|
386
|
+
state.set(key, "done");
|
|
387
|
+
ordered.push(module);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
for (const key of [...byKey.keys()].sort()) visit(key);
|
|
391
|
+
return ordered;
|
|
392
|
+
}
|