@telorun/analyzer 0.59.0 → 0.60.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.
Files changed (80) hide show
  1. package/dist/analyzer.d.ts +9 -2
  2. package/dist/analyzer.d.ts.map +1 -1
  3. package/dist/analyzer.js +38 -10
  4. package/dist/builtins.d.ts.map +1 -1
  5. package/dist/builtins.js +16 -42
  6. package/dist/cel-environment.d.ts.map +1 -1
  7. package/dist/cel-environment.js +35 -0
  8. package/dist/flatten-for-analyzer.d.ts +4 -0
  9. package/dist/flatten-for-analyzer.d.ts.map +1 -1
  10. package/dist/flatten-for-analyzer.js +8 -0
  11. package/dist/index.d.ts +3 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +6 -0
  14. package/dist/kernel-globals.d.ts +1 -1
  15. package/dist/kernel-globals.d.ts.map +1 -1
  16. package/dist/kernel-globals.js +15 -1
  17. package/dist/manifest-schemas.d.ts +407 -0
  18. package/dist/manifest-schemas.d.ts.map +1 -0
  19. package/dist/manifest-schemas.js +396 -0
  20. package/dist/module-file-claims.d.ts +6 -0
  21. package/dist/module-file-claims.d.ts.map +1 -1
  22. package/dist/module-file-claims.js +4 -0
  23. package/dist/module-metadata-scope.d.ts +44 -0
  24. package/dist/module-metadata-scope.d.ts.map +1 -0
  25. package/dist/module-metadata-scope.js +82 -0
  26. package/dist/parse-loaded-file.d.ts.map +1 -1
  27. package/dist/parse-loaded-file.js +16 -0
  28. package/dist/release/bump-level.d.ts +46 -0
  29. package/dist/release/bump-level.d.ts.map +1 -0
  30. package/dist/release/bump-level.js +80 -0
  31. package/dist/release/changelog.d.ts +36 -0
  32. package/dist/release/changelog.d.ts.map +1 -0
  33. package/dist/release/changelog.js +53 -0
  34. package/dist/release/fragment.d.ts +48 -0
  35. package/dist/release/fragment.d.ts.map +1 -0
  36. package/dist/release/fragment.js +84 -0
  37. package/dist/release/index.d.ts +26 -0
  38. package/dist/release/index.d.ts.map +1 -0
  39. package/dist/release/index.js +18 -0
  40. package/dist/release/ledger.d.ts +53 -0
  41. package/dist/release/ledger.d.ts.map +1 -0
  42. package/dist/release/ledger.js +109 -0
  43. package/dist/release/payload-digest.d.ts +63 -0
  44. package/dist/release/payload-digest.d.ts.map +1 -0
  45. package/dist/release/payload-digest.js +65 -0
  46. package/dist/release/release-plan.d.ts +128 -0
  47. package/dist/release/release-plan.d.ts.map +1 -0
  48. package/dist/release/release-plan.js +277 -0
  49. package/dist/release/version-stamp.d.ts +50 -0
  50. package/dist/release/version-stamp.d.ts.map +1 -0
  51. package/dist/release/version-stamp.js +119 -0
  52. package/dist/release/workspace-config.d.ts +41 -0
  53. package/dist/release/workspace-config.d.ts.map +1 -0
  54. package/dist/release/workspace-config.js +60 -0
  55. package/dist/schema-compat.js +2 -1
  56. package/dist/validate-step-inputs.d.ts +1 -1
  57. package/dist/validate-step-inputs.d.ts.map +1 -1
  58. package/dist/validate-step-inputs.js +99 -8
  59. package/package.json +3 -3
  60. package/src/analyzer.ts +41 -10
  61. package/src/builtins.ts +16 -42
  62. package/src/cel-environment.ts +37 -0
  63. package/src/flatten-for-analyzer.ts +12 -0
  64. package/src/index.ts +9 -1
  65. package/src/kernel-globals.ts +23 -1
  66. package/src/manifest-schemas.ts +408 -0
  67. package/src/module-file-claims.ts +10 -0
  68. package/src/module-metadata-scope.ts +88 -0
  69. package/src/parse-loaded-file.ts +16 -0
  70. package/src/release/bump-level.ts +95 -0
  71. package/src/release/changelog.ts +62 -0
  72. package/src/release/fragment.ts +130 -0
  73. package/src/release/index.ts +66 -0
  74. package/src/release/ledger.ts +142 -0
  75. package/src/release/payload-digest.ts +83 -0
  76. package/src/release/release-plan.ts +392 -0
  77. package/src/release/version-stamp.ts +142 -0
  78. package/src/release/workspace-config.ts +81 -0
  79. package/src/schema-compat.ts +1 -1
  80. package/src/validate-step-inputs.ts +109 -9
@@ -0,0 +1,65 @@
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
+ import { PLATFORM_AXES } from "../artifact-selector.js";
17
+ /** The ledger key for the module's `telo.yaml` layer. */
18
+ export const MANIFEST_LAYER = "manifest";
19
+ /**
20
+ * Ledger keys the registry cannot answer for, and so the ones `telo release
21
+ * verify` reconciles nothing about and must preserve.
22
+ *
23
+ * Exactly one today, and for a structural reason rather than an omission: the
24
+ * published `layers:` index lives *inside* `telo.yaml`, so it cannot carry that
25
+ * file's own digest — the entry would have to be computed over bytes containing
26
+ * it. Nor can the digest be recovered by hashing what the registry serves, since
27
+ * the transport injects the index at push time and the published text is
28
+ * therefore not the text the payload builder produced.
29
+ *
30
+ * It stays in the ledger regardless, because it is the only thing that sees a
31
+ * **manifest-only change**: a schema edit, a new kind, a description, a
32
+ * dependency's version moving into a pin. None of those touch a controller byte,
33
+ * so without this key such a module would report no drift and its fix would ship
34
+ * to nobody — the exact failure the digest exists to prevent.
35
+ */
36
+ export const LOCALLY_DERIVED_LAYERS = new Set([MANIFEST_LAYER]);
37
+ /**
38
+ * A layer's identity within an artifact, as a stable, readable, YAML-plain key.
39
+ *
40
+ * A role alone is not the identity — there is one controller layer per selector
41
+ * — so a selector's axes join the key. Rendered as `controller/js` and
42
+ * `controller/napi+linux+amd64+gnu` rather than through `selectorKey`'s
43
+ * `axis=value;…` form, because this string is read by a human in a ledger diff
44
+ * and written into a plain YAML key; the axis order is `PLATFORM_AXES`, so the
45
+ * rendering is deterministic rather than dependent on how the selector was
46
+ * built.
47
+ */
48
+ export function layerDigestKey(role, selector) {
49
+ if (!selector)
50
+ return role;
51
+ const parts = [selector.format, ...PLATFORM_AXES.map((axis) => selector[axis])].filter((value) => value !== undefined);
52
+ return `${role}/${parts.join("+")}`;
53
+ }
54
+ /** Every layer on which two readings disagree, in key order. Empty means the
55
+ * payloads are byte-identical. */
56
+ export function diffLayerDigests(before, after) {
57
+ const changes = [];
58
+ for (const layer of [...new Set([...Object.keys(before), ...Object.keys(after)])].sort()) {
59
+ const a = before[layer];
60
+ const b = after[layer];
61
+ if (a !== b)
62
+ changes.push({ layer, ...(a ? { before: a } : {}), ...(b ? { after: b } : {}) });
63
+ }
64
+ return changes;
65
+ }
@@ -0,0 +1,128 @@
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
+ import { type BumpLevel, type FragmentKind } from "./bump-level.js";
27
+ import type { ModuleKey, ReleaseFragment } from "./fragment.js";
28
+ import type { Ledger } from "./ledger.js";
29
+ import { type LayerChange, type LayerDigests } from "./payload-digest.js";
30
+ /** What a module ships. A `Dockerfile` beside the manifest makes it an image
31
+ * module; its absence, a registry artifact module. Derived rather than
32
+ * declared, so discovery stays configuration-free. */
33
+ export type ArtifactKind = "registry" | "image";
34
+ export interface ModuleEvidence {
35
+ /** Workspace-relative directory path — the module's key everywhere. */
36
+ readonly key: ModuleKey;
37
+ /** `metadata.name`, for display only. */
38
+ readonly name: string;
39
+ /** `metadata.version` as it stands in the working copy. */
40
+ readonly version: string;
41
+ readonly artifactKind: ArtifactKind;
42
+ /** Per-layer integrity of the payload built from the working copy. */
43
+ readonly layers: LayerDigests;
44
+ /**
45
+ * Files this module's build inlined that belong to ANOTHER workspace module,
46
+ * grouped by owner. From the build's own metafile: a declared-dependency graph
47
+ * cannot see `--external`, so `@telorun/sdk` — declared by 54 modules, inlined
48
+ * by none — would otherwise bump the whole standard library on every SDK
49
+ * change.
50
+ */
51
+ readonly inlines: ReadonlyMap<ModuleKey, readonly string[]>;
52
+ /**
53
+ * Modules reached by an in-repo **relative** `imports:` source. A pinned
54
+ * registry ref is deliberately not an edge: pinning is the statement "I am not
55
+ * affected until I choose to be", and moving it is `telo upgrade`'s job.
56
+ */
57
+ readonly imports: readonly ModuleKey[];
58
+ /** Whether a file under this module's own directory that reaches the artifact
59
+ * changed. Decides only whether a changelog line is requested. */
60
+ readonly ownFilesChanged: boolean;
61
+ }
62
+ export interface ReleaseEvidence {
63
+ readonly modules: readonly ModuleEvidence[];
64
+ readonly ledger: Ledger;
65
+ readonly fragments: readonly ReleaseFragment[];
66
+ /** The publish destination base the digests above were built against. */
67
+ readonly registry?: string;
68
+ }
69
+ /** Why a module is in the plan. A module usually carries several. */
70
+ export type BumpReason = {
71
+ readonly kind: "declared";
72
+ readonly fragment: string;
73
+ readonly as: FragmentKind;
74
+ } | {
75
+ readonly kind: "inlines";
76
+ readonly module: ModuleKey;
77
+ readonly files: readonly string[];
78
+ } | {
79
+ readonly kind: "imports";
80
+ readonly module: ModuleKey;
81
+ } | {
82
+ readonly kind: "unattributed";
83
+ };
84
+ export interface ChangelogEntry {
85
+ readonly kind: FragmentKind;
86
+ readonly body: string;
87
+ /** The fragment this line came from, so `apply` can report what it consumed. */
88
+ readonly fragment: string;
89
+ }
90
+ export interface PlannedModule {
91
+ readonly key: ModuleKey;
92
+ readonly name: string;
93
+ readonly from: string;
94
+ readonly to: string;
95
+ readonly level: BumpLevel;
96
+ readonly reasons: readonly BumpReason[];
97
+ /** Layers whose digest differs from the ledger's reading. Empty for a module
98
+ * bumping purely because a dependency's version moves into its manifest. */
99
+ readonly changed: readonly LayerChange[];
100
+ readonly entries: readonly ChangelogEntry[];
101
+ }
102
+ export interface ReleaseDiagnostic {
103
+ readonly severity: "error" | "warning";
104
+ readonly code: string;
105
+ readonly message: string;
106
+ }
107
+ export interface ReleasePlan {
108
+ /** Bumping modules in dependency order — a dependency precedes its
109
+ * dependents, which is also the order `telo publish` must push them. */
110
+ readonly modules: readonly PlannedModule[];
111
+ /** Fragments this plan consumes, for `apply` to delete. */
112
+ readonly fragments: readonly string[];
113
+ readonly diagnostics: readonly ReleaseDiagnostic[];
114
+ }
115
+ export declare function planRelease(evidence: ReleaseEvidence): ReleasePlan;
116
+ /**
117
+ * Dependency order over in-repo imports — a dependency before its dependents.
118
+ *
119
+ * This is also the publish order, and it is not optional there: publishing
120
+ * canonicalizes a relative import and then hard-fails when the derived ref does
121
+ * not already resolve, so a sibling has to be pushed first.
122
+ *
123
+ * A cycle keeps its members in key order rather than throwing. A module graph
124
+ * should not have one, but a release is the wrong moment to discover it, and the
125
+ * ordering degrades to "arbitrary among the cycle" rather than to nothing.
126
+ */
127
+ export declare function orderByImports(modules: readonly ModuleEvidence[]): ModuleEvidence[];
128
+ //# sourceMappingURL=release-plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release-plan.d.ts","sourceRoot":"","sources":["../../src/release/release-plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAG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AAE,SAAS,aAAa,EAAE,CAAC;IAC3C,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,SAAS,iBAAiB,EAAE,CAAC;CACpD;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,WAAW,CA6GlE;AAsID;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,cAAc,EAAE,CAgBnF"}
@@ -0,0 +1,277 @@
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
+ import { applyBump, maxLevel, levelOfKind, } from "./bump-level.js";
27
+ import { diffLayerDigests } from "./payload-digest.js";
28
+ export function planRelease(evidence) {
29
+ const diagnostics = [];
30
+ const byKey = new Map(evidence.modules.map((module) => [module.key, module]));
31
+ checkRegistryAgreement(evidence, diagnostics);
32
+ // What the digest says, per module. A module with no ledger entry has never
33
+ // been published, which is not drift — there is nothing to differ from.
34
+ const drift = new Map();
35
+ for (const module of evidence.modules) {
36
+ const recorded = evidence.ledger.modules.get(module.key);
37
+ if (!recorded)
38
+ continue;
39
+ if (recorded.version !== module.version) {
40
+ diagnostics.push({
41
+ severity: "error",
42
+ code: "LEDGER_VERSION_MISMATCH",
43
+ message: `${module.key} declares version ${module.version} but the ledger records ` +
44
+ `${recorded.version} as published. The digests beside it were taken at that version, ` +
45
+ `so nothing here can be compared. Reconcile with \`telo release verify\` — or, if the ` +
46
+ `version was moved by hand, restore it and let \`telo release apply\` move it.`,
47
+ });
48
+ continue;
49
+ }
50
+ const changes = diffLayerDigests(recorded.layers, module.layers);
51
+ if (changes.length > 0)
52
+ drift.set(module.key, changes);
53
+ }
54
+ const levels = new Map();
55
+ const reasons = new Map();
56
+ const addReason = (key, reason) => {
57
+ const list = reasons.get(key);
58
+ if (list)
59
+ list.push(reason);
60
+ else
61
+ reasons.set(key, [reason]);
62
+ };
63
+ // Declared roots.
64
+ const consumed = new Set();
65
+ for (const fragment of evidence.fragments) {
66
+ for (const [key, kind] of fragment.modules) {
67
+ if (!byKey.has(key)) {
68
+ diagnostics.push({
69
+ severity: "error",
70
+ code: "FRAGMENT_UNKNOWN_MODULE",
71
+ message: `${fragment.source} names '${key}', which is not a module in this workspace. ` +
72
+ `A fragment names a module by its workspace-relative directory path.`,
73
+ });
74
+ continue;
75
+ }
76
+ const level = levelOfKind(kind);
77
+ if (level === "major") {
78
+ diagnostics.push({
79
+ severity: "error",
80
+ code: "MAJOR_BUMP_REJECTED",
81
+ message: `${fragment.source} declares '${key}: ${kind}', which induces a major bump. ` +
82
+ `Modules are intentionally pre-1.0 — a breaking change ships as a minor. ` +
83
+ `Use Added and describe the break in the body.`,
84
+ });
85
+ continue;
86
+ }
87
+ consumed.add(fragment.source);
88
+ levels.set(key, maxLevel(levels.get(key) ?? level, level));
89
+ addReason(key, { kind: "declared", fragment: fragment.source, as: kind });
90
+ }
91
+ }
92
+ // Edges already credited, so a second propagation pass does not repeat an
93
+ // explanation the author has already been given.
94
+ const credited = new Set();
95
+ propagateToFixedPoint(evidence.modules, drift, levels, credited, addReason);
96
+ // The seam. A payload that moved with nothing to attribute it to still has to
97
+ // ship — the fix would otherwise reach nobody — so it takes a patch and is
98
+ // named. Seeded after propagation and then propagated again, because an
99
+ // unattributed bump is itself a dependency move for anything importing it.
100
+ for (;;) {
101
+ let seeded = false;
102
+ for (const module of evidence.modules) {
103
+ if (levels.has(module.key) || !drift.has(module.key))
104
+ continue;
105
+ levels.set(module.key, "patch");
106
+ addReason(module.key, { kind: "unattributed" });
107
+ seeded = true;
108
+ }
109
+ if (!seeded)
110
+ break;
111
+ propagateToFixedPoint(evidence.modules, drift, levels, credited, addReason);
112
+ }
113
+ const entriesByModule = collectChangelogEntries(evidence.fragments, byKey);
114
+ requestMissingChangelogEntries(evidence.modules, entriesByModule, diagnostics);
115
+ const planned = [];
116
+ for (const module of orderByImports(evidence.modules)) {
117
+ const level = levels.get(module.key);
118
+ if (!level)
119
+ continue;
120
+ planned.push({
121
+ key: module.key,
122
+ name: module.name,
123
+ from: module.version,
124
+ to: applyBump(module.version, level),
125
+ level,
126
+ reasons: reasons.get(module.key) ?? [],
127
+ changed: drift.get(module.key) ?? [],
128
+ entries: entriesByModule.get(module.key) ?? [],
129
+ });
130
+ }
131
+ return { modules: planned, fragments: [...consumed].sort(), diagnostics };
132
+ }
133
+ /**
134
+ * Raise levels along release edges until nothing moves.
135
+ *
136
+ * The two edge kinds answer different questions and so are gated differently:
137
+ *
138
+ * - An **import** edge bumps unconditionally. Publishing rewrites a relative
139
+ * `imports:` source to `<base>/<sibling>@<version>`, so when the sibling's
140
+ * version moves this module's manifest layer provably changes — a fact about
141
+ * the plan, which the current digest cannot yet show because it was taken
142
+ * against the sibling's *current* version.
143
+ * - An **inline** edge only explains drift that already showed up. The inlined
144
+ * bytes are in this payload, so if they had changed the digest would say so;
145
+ * attributing without that check would bump every dependent of a module whose
146
+ * fragment covers a docs-only change.
147
+ */
148
+ function propagateToFixedPoint(modules, drift, levels, credited, addReason) {
149
+ for (let moved = true; moved;) {
150
+ moved = false;
151
+ for (const module of modules) {
152
+ for (const dependency of module.imports) {
153
+ moved = raise(module, dependency, { kind: "imports", module: dependency }) || moved;
154
+ }
155
+ if (!drift.has(module.key))
156
+ continue;
157
+ for (const [dependency, files] of module.inlines) {
158
+ moved =
159
+ raise(module, dependency, { kind: "inlines", module: dependency, files }) || moved;
160
+ }
161
+ }
162
+ }
163
+ function raise(module, dependency, reason) {
164
+ const from = levels.get(dependency);
165
+ if (!from)
166
+ return false;
167
+ const current = levels.get(module.key);
168
+ const next = current ? maxLevel(current, from) : from;
169
+ // The reason is recorded the first time this edge carries anything, even
170
+ // when it does not raise the level: it is the explanation the author reads,
171
+ // and an edge that merely agrees with another still says why this module is
172
+ // in the plan.
173
+ const edge = `${module.key}\0${dependency}\0${reason.kind}`;
174
+ if (!credited.has(edge)) {
175
+ credited.add(edge);
176
+ addReason(module.key, reason);
177
+ }
178
+ if (current === next)
179
+ return false;
180
+ levels.set(module.key, next);
181
+ return true;
182
+ }
183
+ }
184
+ function collectChangelogEntries(fragments, byKey) {
185
+ const entries = new Map();
186
+ for (const fragment of fragments) {
187
+ for (const [key, kind] of fragment.modules) {
188
+ if (!byKey.has(key))
189
+ continue;
190
+ const list = entries.get(key);
191
+ const entry = { kind, body: fragment.body, fragment: fragment.source };
192
+ if (list)
193
+ list.push(entry);
194
+ else
195
+ entries.set(key, [entry]);
196
+ }
197
+ }
198
+ return entries;
199
+ }
200
+ /**
201
+ * Ask for prose where a human made a semantic change.
202
+ *
203
+ * A warning, not an error: `check`'s job is "can a complete, consistent plan be
204
+ * formed", and a module that drifted through propagation or a toolchain bump is
205
+ * planned and released without anyone writing a word. This fires only for a
206
+ * module whose OWN files moved, which is the case where the changelog would
207
+ * otherwise be silent about a real change.
208
+ */
209
+ function requestMissingChangelogEntries(modules, entries, diagnostics) {
210
+ const missing = modules
211
+ .filter((module) => module.ownFilesChanged && !entries.has(module.key))
212
+ .map((module) => module.key);
213
+ if (missing.length === 0)
214
+ return;
215
+ // ONE diagnostic listing the modules, not one per module. A change that
216
+ // touches every module's build script or a shared config asks the same
217
+ // question about forty of them at once, and forty copies of one sentence bury
218
+ // the plan they are printed beside — the more so because they go to stderr
219
+ // while the plan goes to stdout, so a piped run interleaves them.
220
+ //
221
+ // The fix for all of them is also one fragment, since a fragment names as many
222
+ // modules as it likes.
223
+ diagnostics.push({
224
+ severity: "warning",
225
+ code: "CHANGELOG_ENTRY_REQUESTED",
226
+ message: `${missing.length} module(s) have their own changes but no fragment describes them, so ` +
227
+ `their changelogs will not mention this release: ${missing.join(", ")}. ` +
228
+ `One \`telo release add\` can name them all.`,
229
+ });
230
+ }
231
+ /**
232
+ * The base the digests were built against has to be the base they were recorded
233
+ * against, or the manifest layers are not comparable: canonicalization writes
234
+ * the destination into them.
235
+ */
236
+ function checkRegistryAgreement(evidence, diagnostics) {
237
+ const recorded = evidence.ledger.registry;
238
+ if (!recorded || !evidence.registry || recorded === evidence.registry)
239
+ return;
240
+ diagnostics.push({
241
+ severity: "error",
242
+ code: "LEDGER_REGISTRY_MISMATCH",
243
+ message: `The ledger's digests were taken against '${recorded}', but this run built against ` +
244
+ `'${evidence.registry}'. Publishing rewrites each relative import to ` +
245
+ `'<base>/<sibling>@<version>', so the manifest layers of the two are different bytes ` +
246
+ `and comparing them would report every module as changed.`,
247
+ });
248
+ }
249
+ /**
250
+ * Dependency order over in-repo imports — a dependency before its dependents.
251
+ *
252
+ * This is also the publish order, and it is not optional there: publishing
253
+ * canonicalizes a relative import and then hard-fails when the derived ref does
254
+ * not already resolve, so a sibling has to be pushed first.
255
+ *
256
+ * A cycle keeps its members in key order rather than throwing. A module graph
257
+ * should not have one, but a release is the wrong moment to discover it, and the
258
+ * ordering degrades to "arbitrary among the cycle" rather than to nothing.
259
+ */
260
+ export function orderByImports(modules) {
261
+ const byKey = new Map(modules.map((module) => [module.key, module]));
262
+ const ordered = [];
263
+ const state = new Map();
264
+ const visit = (key) => {
265
+ const module = byKey.get(key);
266
+ if (!module || state.get(key))
267
+ return;
268
+ state.set(key, "visiting");
269
+ for (const dependency of [...module.imports].sort())
270
+ visit(dependency);
271
+ state.set(key, "done");
272
+ ordered.push(module);
273
+ };
274
+ for (const key of [...byKey.keys()].sort())
275
+ visit(key);
276
+ return ordered;
277
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Writing a module's one version into every manifest it owns.
3
+ *
4
+ * A module has a single version across `telo.yaml`, `nodejs/package.json` and
5
+ * `rust/Cargo.toml`. Three formats, one rule: find the scalar, splice over its
6
+ * span, touch nothing else. That is `yaml-source-edit.ts`'s primitive — the same
7
+ * one the quick fix, `telo migrate` and `telo upgrade`'s pin rewrite use — so a
8
+ * bump lands as a one-line diff instead of a re-serialized file that re-folds
9
+ * every block scalar in a 900-line manifest.
10
+ *
11
+ * Each stamp returns `undefined` when the file carries no version to write,
12
+ * which is not an error: a module may own only a `telo.yaml`, and 42 of the
13
+ * standard library's packages have no Rust crate. A file that *has* a version in
14
+ * a shape this cannot address is a hard error instead, because silently skipping
15
+ * it would publish an artifact whose manifests disagree about what it is.
16
+ */
17
+ export declare class VersionStampError extends Error {
18
+ }
19
+ /**
20
+ * `metadata.version` on the **module doc** — the first document, the one whose
21
+ * kind is `Telo.Application` or `Telo.Library`. Deliberately not "any
22
+ * `metadata.version` in the file": a `Telo.Definition` further down may carry
23
+ * one, and the regex-replacement changie was configured with matched by line
24
+ * shape rather than by position, which is why it needed a hand-maintained count
25
+ * of how many lines it was allowed to hit.
26
+ */
27
+ export declare function stampManifestVersion(text: string, version: string, where: string): string | undefined;
28
+ /** Read the module doc's `metadata.version` without rewriting it. */
29
+ export declare function readManifestVersion(text: string): string | undefined;
30
+ /**
31
+ * The top-level `"version"` of a `package.json`.
32
+ *
33
+ * Parsed with the YAML reader rather than `JSON.parse`, because JSON is a YAML
34
+ * subset and this one needs the node's *source range* — `JSON.parse` discards it,
35
+ * and re-serializing with `JSON.stringify` would reformat a file whose
36
+ * indentation, key order and trailing newline are all conventions someone chose.
37
+ */
38
+ export declare function stampPackageVersion(text: string, version: string, where: string): string | undefined;
39
+ /**
40
+ * `version` in a `Cargo.toml`'s `[package]` table.
41
+ *
42
+ * Scanned rather than parsed: TOML is not YAML, adding a TOML parser to the
43
+ * browser-safe analyzer for one scalar is not a trade worth making, and the
44
+ * shape being addressed is the canonical one cargo itself writes. The scan is
45
+ * bounded to the `[package]` table so a `version` under `[dependencies.x]`
46
+ * cannot be hit, and a `[package]` whose version is not a simple quoted scalar
47
+ * is refused rather than guessed at.
48
+ */
49
+ export declare function stampCrateVersion(text: string, version: string, where: string): string | undefined;
50
+ //# sourceMappingURL=version-stamp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version-stamp.d.ts","sourceRoot":"","sources":["../../src/release/version-stamp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;AAqB/C;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,MAAM,GAAG,SAAS,CAYpB;AAED,qEAAqE;AACrE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMpE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,MAAM,GAAG,SAAS,CAKpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,MAAM,GAAG,SAAS,CA+BpB"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Writing a module's one version into every manifest it owns.
3
+ *
4
+ * A module has a single version across `telo.yaml`, `nodejs/package.json` and
5
+ * `rust/Cargo.toml`. Three formats, one rule: find the scalar, splice over its
6
+ * span, touch nothing else. That is `yaml-source-edit.ts`'s primitive — the same
7
+ * one the quick fix, `telo migrate` and `telo upgrade`'s pin rewrite use — so a
8
+ * bump lands as a one-line diff instead of a re-serialized file that re-folds
9
+ * every block scalar in a 900-line manifest.
10
+ *
11
+ * Each stamp returns `undefined` when the file carries no version to write,
12
+ * which is not an error: a module may own only a `telo.yaml`, and 42 of the
13
+ * standard library's packages have no Rust crate. A file that *has* a version in
14
+ * a shape this cannot address is a hard error instead, because silently skipping
15
+ * it would publish an artifact whose manifests disagree about what it is.
16
+ */
17
+ import { defaultCustomTags } from "@telorun/templating";
18
+ import { isScalar, parseAllDocuments, parseDocument } from "yaml";
19
+ import { applyTextEdits, renderFixReplacement } from "../yaml-source-edit.js";
20
+ export class VersionStampError extends Error {
21
+ }
22
+ /** Replace the scalar at `[start, end)` with `version`, re-quoted in the
23
+ * author's own style. */
24
+ function spliceScalar(text, node, version, where) {
25
+ const range = node.range;
26
+ if (!range) {
27
+ throw new VersionStampError(`${where}: the version scalar carries no source range.`);
28
+ }
29
+ const [start, end] = range;
30
+ const source = text.slice(start, end);
31
+ const replacement = renderFixReplacement(source, version);
32
+ if (replacement === undefined) {
33
+ throw new VersionStampError(`${where}: the version is written as '${source}', which cannot be rewritten in place. ` +
34
+ `Write it as a plain or quoted scalar on one line.`);
35
+ }
36
+ return applyTextEdits(text, [{ start, end, newText: replacement }]);
37
+ }
38
+ /**
39
+ * `metadata.version` on the **module doc** — the first document, the one whose
40
+ * kind is `Telo.Application` or `Telo.Library`. Deliberately not "any
41
+ * `metadata.version` in the file": a `Telo.Definition` further down may carry
42
+ * one, and the regex-replacement changie was configured with matched by line
43
+ * shape rather than by position, which is why it needed a hand-maintained count
44
+ * of how many lines it was allowed to hit.
45
+ */
46
+ export function stampManifestVersion(text, version, where) {
47
+ const docs = parseAllDocuments(text, { customTags: defaultCustomTags() });
48
+ const doc = docs[0];
49
+ if (!doc)
50
+ return undefined;
51
+ const metadata = doc.get("metadata", true);
52
+ if (!metadata || typeof metadata.get !== "function")
53
+ return undefined;
54
+ const node = metadata.get("version", true);
55
+ if (!isScalar(node))
56
+ return undefined;
57
+ return spliceScalar(text, node, version, where);
58
+ }
59
+ /** Read the module doc's `metadata.version` without rewriting it. */
60
+ export function readManifestVersion(text) {
61
+ const docs = parseAllDocuments(text, { customTags: defaultCustomTags() });
62
+ const first = docs[0]?.toJSON();
63
+ if (first?.kind !== "Telo.Application" && first?.kind !== "Telo.Library")
64
+ return undefined;
65
+ const version = first.metadata?.version;
66
+ return typeof version === "string" ? version : undefined;
67
+ }
68
+ /**
69
+ * The top-level `"version"` of a `package.json`.
70
+ *
71
+ * Parsed with the YAML reader rather than `JSON.parse`, because JSON is a YAML
72
+ * subset and this one needs the node's *source range* — `JSON.parse` discards it,
73
+ * and re-serializing with `JSON.stringify` would reformat a file whose
74
+ * indentation, key order and trailing newline are all conventions someone chose.
75
+ */
76
+ export function stampPackageVersion(text, version, where) {
77
+ const doc = parseDocument(text);
78
+ const node = doc.get("version", true);
79
+ if (!isScalar(node))
80
+ return undefined;
81
+ return spliceScalar(text, node, version, where);
82
+ }
83
+ /**
84
+ * `version` in a `Cargo.toml`'s `[package]` table.
85
+ *
86
+ * Scanned rather than parsed: TOML is not YAML, adding a TOML parser to the
87
+ * browser-safe analyzer for one scalar is not a trade worth making, and the
88
+ * shape being addressed is the canonical one cargo itself writes. The scan is
89
+ * bounded to the `[package]` table so a `version` under `[dependencies.x]`
90
+ * cannot be hit, and a `[package]` whose version is not a simple quoted scalar
91
+ * is refused rather than guessed at.
92
+ */
93
+ export function stampCrateVersion(text, version, where) {
94
+ const table = /^[ \t]*\[package\][ \t]*$/m.exec(text);
95
+ if (!table)
96
+ return undefined;
97
+ const bodyStart = table.index + table[0].length;
98
+ const next = /^[ \t]*\[/m.exec(text.slice(bodyStart));
99
+ const bodyEnd = next ? bodyStart + next.index : text.length;
100
+ const entry = /^([ \t]*version[ \t]*=[ \t]*)(".*?"|'.*?')[ \t]*$/m.exec(text.slice(bodyStart, bodyEnd));
101
+ if (!entry) {
102
+ // A `[package]` with `version.workspace = true` inherits from the workspace
103
+ // and genuinely has nothing here to stamp; anything else is a shape this
104
+ // cannot address, and writing nothing would leave the crate behind.
105
+ if (/^[ \t]*version[ \t]*\.[ \t]*workspace[ \t]*=/m.test(text.slice(bodyStart, bodyEnd))) {
106
+ return undefined;
107
+ }
108
+ if (/^[ \t]*version[ \t]*=/m.test(text.slice(bodyStart, bodyEnd))) {
109
+ throw new VersionStampError(`${where}: [package].version is not a quoted scalar on one line, so it cannot be ` +
110
+ `rewritten in place.`);
111
+ }
112
+ return undefined;
113
+ }
114
+ const start = bodyStart + entry.index + entry[1].length;
115
+ const quote = entry[2][0];
116
+ return applyTextEdits(text, [
117
+ { start, end: start + entry[2].length, newText: `${quote}${version}${quote}` },
118
+ ]);
119
+ }