@intentius/chant 0.124.100 → 0.124.102

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 (270) hide show
  1. package/dist/action-pins.d.ts +2 -0
  2. package/dist/action-pins.js +3 -0
  3. package/dist/ci-detect.d.ts +13 -0
  4. package/dist/ci-detect.js +12 -0
  5. package/dist/ci-evidence-claims.d.ts +12 -0
  6. package/dist/ci-evidence-claims.js +12 -0
  7. package/dist/ci-system.d.ts +66 -0
  8. package/dist/ci-system.js +61 -0
  9. package/dist/cli/handlers/build.js +27 -0
  10. package/dist/cli/handlers/release-doctor.d.ts +12 -0
  11. package/dist/cli/handlers/release-doctor.js +118 -0
  12. package/dist/cli/handlers/release-init.d.ts +10 -0
  13. package/dist/cli/handlers/release-init.js +374 -0
  14. package/dist/cli/handlers/release.d.ts +43 -2
  15. package/dist/cli/handlers/release.js +667 -39
  16. package/dist/cli/handlers/run-generate.js +11 -0
  17. package/dist/cli/main.d.ts +2 -0
  18. package/dist/cli/main.js +44 -101
  19. package/dist/cli/parse-args.js +48 -0
  20. package/dist/cli/registry.d.ts +16 -0
  21. package/dist/cli/release-commands/artifacts.d.ts +3 -0
  22. package/dist/cli/release-commands/artifacts.js +14 -0
  23. package/dist/cli/release-commands/candidates.d.ts +3 -0
  24. package/dist/cli/release-commands/candidates.js +16 -0
  25. package/dist/cli/release-commands/changed.d.ts +3 -0
  26. package/dist/cli/release-commands/changed.js +14 -0
  27. package/dist/cli/release-commands/compose.d.ts +3 -0
  28. package/dist/cli/release-commands/compose.js +16 -0
  29. package/dist/cli/release-commands/cut.d.ts +3 -0
  30. package/dist/cli/release-commands/cut.js +50 -0
  31. package/dist/cli/release-commands/doctor.d.ts +3 -0
  32. package/dist/cli/release-commands/doctor.js +14 -0
  33. package/dist/cli/release-commands/export.d.ts +3 -0
  34. package/dist/cli/release-commands/export.js +12 -0
  35. package/dist/cli/release-commands/images.d.ts +3 -0
  36. package/dist/cli/release-commands/images.js +13 -0
  37. package/dist/cli/release-commands/index.d.ts +8 -0
  38. package/dist/cli/release-commands/index.js +52 -0
  39. package/dist/cli/release-commands/init.d.ts +3 -0
  40. package/dist/cli/release-commands/init.js +19 -0
  41. package/dist/cli/release-commands/list.d.ts +3 -0
  42. package/dist/cli/release-commands/list.js +10 -0
  43. package/dist/cli/release-commands/next.d.ts +3 -0
  44. package/dist/cli/release-commands/next.js +13 -0
  45. package/dist/cli/release-commands/publish.d.ts +3 -0
  46. package/dist/cli/release-commands/publish.js +22 -0
  47. package/dist/cli/release-commands/stamp.d.ts +3 -0
  48. package/dist/cli/release-commands/stamp.js +15 -0
  49. package/dist/cli/release-commands/status.d.ts +3 -0
  50. package/dist/cli/release-commands/status.js +17 -0
  51. package/dist/cli/release-commands/tag.d.ts +3 -0
  52. package/dist/cli/release-commands/tag.js +12 -0
  53. package/dist/cli/release-commands/types.d.ts +20 -0
  54. package/dist/cli/release-commands/types.js +1 -0
  55. package/dist/cli/release-commands/verify.d.ts +3 -0
  56. package/dist/cli/release-commands/verify.js +15 -0
  57. package/dist/cli/release-commands/workflow.d.ts +3 -0
  58. package/dist/cli/release-commands/workflow.js +15 -0
  59. package/dist/cloud-lister/index.d.ts +4 -1
  60. package/dist/cloud-lister/index.js +2 -1
  61. package/dist/cloud-lister/kubernetes-components.d.ts +56 -0
  62. package/dist/cloud-lister/kubernetes-components.js +642 -0
  63. package/dist/cloud-lister/kubernetes.d.ts +18 -0
  64. package/dist/cloud-lister/kubernetes.js +26 -1
  65. package/dist/cloud-lister/mask.d.ts +5 -1
  66. package/dist/cloud-lister/mask.js +14 -5
  67. package/dist/components/cli-support.d.ts +1 -1
  68. package/dist/components/cli-support.js +1 -1
  69. package/dist/config-environments.d.ts +8 -1
  70. package/dist/config-environments.js +2 -0
  71. package/dist/config-import.d.ts +1 -1
  72. package/dist/config-import.js +6 -2
  73. package/dist/config-sandbox.d.ts +1 -1
  74. package/dist/config-sandbox.js +3 -3
  75. package/dist/config.d.ts +369 -10
  76. package/dist/config.js +127 -7
  77. package/dist/deep-observation.js +9 -3
  78. package/dist/floor-table.data.js +21 -1
  79. package/dist/forge-remote.d.ts +13 -0
  80. package/dist/forge-remote.js +15 -0
  81. package/dist/lexicon.d.ts +45 -4
  82. package/dist/lifecycle/__fixtures__/package-files.d.ts +32 -0
  83. package/dist/lifecycle/__fixtures__/package-files.js +72 -0
  84. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
  85. package/dist/lifecycle/__fixtures__/publish-fakes.js +275 -3
  86. package/dist/lifecycle/publish-attachments.d.ts +2 -1
  87. package/dist/lifecycle/publish-attachments.js +19 -2
  88. package/dist/lifecycle/publish-cargo.d.ts +99 -0
  89. package/dist/lifecycle/publish-cargo.js +412 -0
  90. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  91. package/dist/lifecycle/publish-credentials.js +13 -0
  92. package/dist/lifecycle/publish-declaration.d.ts +322 -4
  93. package/dist/lifecycle/publish-declaration.js +340 -9
  94. package/dist/lifecycle/publish-forge.d.ts +45 -2
  95. package/dist/lifecycle/publish-forge.js +434 -34
  96. package/dist/lifecycle/publish-git-ssh.d.ts +15 -0
  97. package/dist/lifecycle/publish-git-ssh.js +30 -4
  98. package/dist/lifecycle/publish-github.d.ts +40 -2
  99. package/dist/lifecycle/publish-github.js +100 -3
  100. package/dist/lifecycle/publish-helm.d.ts +83 -0
  101. package/dist/lifecycle/publish-helm.js +452 -0
  102. package/dist/lifecycle/publish-homebrew.d.ts +7 -9
  103. package/dist/lifecycle/publish-homebrew.js +34 -197
  104. package/dist/lifecycle/publish-index.d.ts +141 -0
  105. package/dist/lifecycle/publish-index.js +719 -0
  106. package/dist/lifecycle/publish-marketplace.js +77 -0
  107. package/dist/lifecycle/publish-maven.d.ts +79 -0
  108. package/dist/lifecycle/publish-maven.js +364 -0
  109. package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
  110. package/dist/lifecycle/publish-mcp-registry.js +305 -0
  111. package/dist/lifecycle/publish-npm.d.ts +27 -1
  112. package/dist/lifecycle/publish-npm.js +216 -3
  113. package/dist/lifecycle/publish-nuget.d.ts +93 -0
  114. package/dist/lifecycle/publish-nuget.js +377 -0
  115. package/dist/lifecycle/publish-oci.d.ts +91 -2
  116. package/dist/lifecycle/publish-oci.js +247 -8
  117. package/dist/lifecycle/publish-package-files.d.ts +16 -0
  118. package/dist/lifecycle/publish-package-files.js +39 -0
  119. package/dist/lifecycle/publish-pypi.d.ts +138 -0
  120. package/dist/lifecycle/publish-pypi.js +657 -0
  121. package/dist/lifecycle/publish-record.d.ts +6 -3
  122. package/dist/lifecycle/publish-record.js +6 -3
  123. package/dist/lifecycle/publish-rubygems.d.ts +84 -0
  124. package/dist/lifecycle/publish-rubygems.js +366 -0
  125. package/dist/lifecycle/publish-signing.d.ts +147 -0
  126. package/dist/lifecycle/publish-signing.js +257 -0
  127. package/dist/lifecycle/publish-targets.d.ts +37 -1
  128. package/dist/lifecycle/publish-targets.js +102 -0
  129. package/dist/lifecycle/publish-tauri.js +43 -0
  130. package/dist/lifecycle/publish-train-names.d.ts +57 -0
  131. package/dist/lifecycle/publish-train-names.js +123 -0
  132. package/dist/lifecycle/publish-verify.d.ts +121 -0
  133. package/dist/lifecycle/publish-verify.js +130 -0
  134. package/dist/lifecycle/query.js +8 -0
  135. package/dist/lifecycle/release-artifacts.d.ts +290 -0
  136. package/dist/lifecycle/release-artifacts.js +808 -0
  137. package/dist/lifecycle/release-changelog.d.ts +13 -1
  138. package/dist/lifecycle/release-changelog.js +35 -2
  139. package/dist/lifecycle/release-cut.d.ts +64 -4
  140. package/dist/lifecycle/release-cut.js +147 -34
  141. package/dist/lifecycle/release-doctor.d.ts +113 -0
  142. package/dist/lifecycle/release-doctor.js +1198 -0
  143. package/dist/lifecycle/release-green.d.ts +86 -0
  144. package/dist/lifecycle/release-green.js +286 -0
  145. package/dist/lifecycle/release-init-registries.d.ts +48 -0
  146. package/dist/lifecycle/release-init-registries.js +97 -0
  147. package/dist/lifecycle/release-init.d.ts +275 -0
  148. package/dist/lifecycle/release-init.js +984 -0
  149. package/dist/lifecycle/release-intents.d.ts +73 -0
  150. package/dist/lifecycle/release-intents.js +128 -0
  151. package/dist/lifecycle/release-next.d.ts +111 -0
  152. package/dist/lifecycle/release-next.js +251 -0
  153. package/dist/lifecycle/release-prerelease.d.ts +19 -0
  154. package/dist/lifecycle/release-prerelease.js +30 -0
  155. package/dist/lifecycle/release-publish.d.ts +256 -10
  156. package/dist/lifecycle/release-publish.js +247 -35
  157. package/dist/lifecycle/release-status-change.d.ts +226 -0
  158. package/dist/lifecycle/release-status-change.js +478 -0
  159. package/dist/lifecycle/release-status.d.ts +11 -0
  160. package/dist/lifecycle/release-status.js +1 -1
  161. package/dist/lifecycle/release-store.d.ts +73 -2
  162. package/dist/lifecycle/release-store.js +32 -1
  163. package/dist/lifecycle/release-tag.d.ts +142 -0
  164. package/dist/lifecycle/release-tag.js +322 -0
  165. package/dist/lifecycle/release-verify.d.ts +73 -1
  166. package/dist/lifecycle/release-verify.js +117 -2
  167. package/dist/lifecycle/release-version-formats.d.ts +73 -0
  168. package/dist/lifecycle/release-version-formats.js +570 -0
  169. package/dist/lifecycle/release-version.d.ts +58 -10
  170. package/dist/lifecycle/release-version.js +164 -36
  171. package/dist/lifecycle/release-workstation.d.ts +3 -2
  172. package/dist/lifecycle/release-workstation.js +3 -2
  173. package/dist/op/generate-pipeline.js +1 -1
  174. package/dist/op/local-executor.d.ts +1 -1
  175. package/dist/op/local-executor.js +2 -2
  176. package/dist/op/op-waves-evidence.js +9 -2
  177. package/dist/pr-forge-base.js +4 -2
  178. package/dist/pr-forge.d.ts +20 -2
  179. package/dist/pr-forge.js +46 -10
  180. package/dist/release-floors.d.ts +8 -1
  181. package/dist/release-floors.js +9 -2
  182. package/dist/sensitive-key.d.ts +12 -0
  183. package/dist/sensitive-key.js +52 -0
  184. package/dist/tool-pins.d.ts +40 -0
  185. package/dist/tool-pins.js +66 -0
  186. package/dist/ts-loader.d.ts +8 -0
  187. package/dist/ts-loader.js +19 -0
  188. package/dist/wave-runtime.mjs +345 -342
  189. package/dist/workspace/ci-forge.d.ts +17 -0
  190. package/dist/workspace/ci-forge.js +17 -0
  191. package/dist/workspace/ci-init.js +1 -1
  192. package/dist/workspace/composites.schema.json +1 -0
  193. package/dist/workspace/declaration.d.ts +8 -0
  194. package/dist/workspace/declaration.js +12 -0
  195. package/dist/workspace/declaration.schema.json +8 -0
  196. package/dist/workspace/environments.d.ts +2 -0
  197. package/dist/workspace/environments.js +1 -1
  198. package/dist/workspace/identity-gate-rule.d.ts +61 -5
  199. package/dist/workspace/identity-gate-rule.js +81 -12
  200. package/dist/workspace/lexicon-outputs.d.ts +1 -1
  201. package/dist/workspace/lexicon-outputs.js +1 -1
  202. package/dist/workspace/member-pipeline.d.ts +2 -1
  203. package/dist/workspace/member-pipeline.js +5 -2
  204. package/dist/workspace/reason-codes.d.ts +2 -0
  205. package/dist/workspace/reason-codes.js +3 -1
  206. package/dist/workspace/release-changed.d.ts +75 -4
  207. package/dist/workspace/release-changed.js +205 -34
  208. package/dist/workspace/release-changed.schema.json +20 -2
  209. package/dist/workspace/release-steps/artifacts.d.ts +7 -0
  210. package/dist/workspace/release-steps/artifacts.js +45 -0
  211. package/dist/workspace/release-steps/builds.d.ts +12 -0
  212. package/dist/workspace/release-steps/builds.js +38 -0
  213. package/dist/workspace/release-steps/doctor.d.ts +8 -0
  214. package/dist/workspace/release-steps/doctor.js +14 -0
  215. package/dist/workspace/release-steps/goreleaser.d.ts +16 -0
  216. package/dist/workspace/release-steps/goreleaser.js +36 -0
  217. package/dist/workspace/release-steps/green.d.ts +3 -0
  218. package/dist/workspace/release-steps/green.js +6 -0
  219. package/dist/workspace/release-steps/images.d.ts +22 -0
  220. package/dist/workspace/release-steps/images.js +59 -0
  221. package/dist/workspace/release-steps/index.d.ts +9 -0
  222. package/dist/workspace/release-steps/index.js +50 -0
  223. package/dist/workspace/release-steps/nfpm.d.ts +13 -0
  224. package/dist/workspace/release-steps/nfpm.js +29 -0
  225. package/dist/workspace/release-steps/nuget.d.ts +14 -0
  226. package/dist/workspace/release-steps/nuget.js +16 -0
  227. package/dist/workspace/release-steps/pypi.d.ts +15 -0
  228. package/dist/workspace/release-steps/pypi.js +21 -0
  229. package/dist/workspace/release-steps/qemu.d.ts +21 -0
  230. package/dist/workspace/release-steps/qemu.js +35 -0
  231. package/dist/workspace/release-steps/signing.d.ts +18 -0
  232. package/dist/workspace/release-steps/signing.js +30 -0
  233. package/dist/workspace/release-steps/stamp.d.ts +3 -0
  234. package/dist/workspace/release-steps/stamp.js +4 -0
  235. package/dist/workspace/release-steps/targets.d.ts +31 -0
  236. package/dist/workspace/release-steps/targets.js +40 -0
  237. package/dist/workspace/release-steps/types.d.ts +104 -0
  238. package/dist/workspace/release-steps/types.js +2 -0
  239. package/dist/workspace/release-steps/verify.d.ts +3 -0
  240. package/dist/workspace/release-steps/verify.js +4 -0
  241. package/dist/workspace/release-toolchains.d.ts +59 -0
  242. package/dist/workspace/release-toolchains.js +133 -0
  243. package/dist/workspace/release-train-workflow.d.ts +36 -0
  244. package/dist/workspace/release-train-workflow.js +121 -0
  245. package/dist/workspace/release-train.d.ts +3 -1
  246. package/dist/workspace/release-train.js +20 -3
  247. package/dist/workspace/release-workflow.d.ts +183 -59
  248. package/dist/workspace/release-workflow.js +570 -201
  249. package/dist/workspace/releases.schema.json +70 -1
  250. package/dist/workspace/search-contract.d.ts +1 -1
  251. package/dist/workspace/security.js +9 -2
  252. package/dist/workspace/train-cut.d.ts +182 -0
  253. package/dist/workspace/train-cut.js +504 -0
  254. package/dist/workspace/train-prepare.d.ts +64 -0
  255. package/dist/workspace/train-prepare.js +313 -0
  256. package/dist/workspace/train-publish.d.ts +177 -0
  257. package/dist/workspace/train-publish.js +574 -0
  258. package/dist/workspace/train-range-labels.d.ts +33 -0
  259. package/dist/workspace/train-range-labels.js +109 -0
  260. package/dist/workspace/train-shell.d.ts +5 -0
  261. package/dist/workspace/train-shell.js +17 -0
  262. package/dist/workspace/trust/check-evidence-report.d.ts +3 -7
  263. package/dist/workspace/trust/check-evidence-report.js +3 -7
  264. package/dist/workspace/trust/seal.d.ts +13 -3
  265. package/dist/workspace/trust/seal.js +14 -4
  266. package/dist/workspace/work-cli.d.ts +3 -2
  267. package/dist/workspace/work-cli.js +3 -2
  268. package/dist/workspace/workspace-ledger.d.ts +14 -1
  269. package/dist/workspace/workspace-ledger.js +33 -7
  270. package/package.json +1 -1
@@ -0,0 +1,313 @@
1
+ /**
2
+ * Preparing a checkout to publish a release train (#5154): `chant workspace
3
+ * train prepare <env> [<train id|digest>] [--json]`, run in a checkout of the
4
+ * commit the train's new releases were cut from, before `chant workspace
5
+ * train publish`.
6
+ *
7
+ * For each member the train cut from this commit:
8
+ *
9
+ * - its `release.version` files take the member's label, and under `ranges:
10
+ * "train"` each workspace dependency's range takes `^` and the label the
11
+ * train gives the member that owns it (what `chant release stamp <label>
12
+ * --train <id>` does for one member). The publish takes each such file as
13
+ * the commit's.
14
+ * - the workspace packages it depends on, directly or not, that this run
15
+ * does not publish are built once each, dependencies first, so a package
16
+ * that builds against another's output finds it. The members this run
17
+ * publishes build when npm packs them, in the train's layer order. A
18
+ * member cut here whose package an earlier run of the publish already
19
+ * revealed is not packed again, so it builds here like any other
20
+ * dependency (#5222): a resumed publish finds what it left built. The
21
+ * command is `release.train.buildDependencies`, else the package's
22
+ * `prepack` script, else its `build` script.
23
+ *
24
+ * A workspace package here is one a `chant` member of the train's workspace
25
+ * names in its `release.version.packages` or as a directory of an `npm`
26
+ * target; its dependencies are its `dependencies`, `peerDependencies` and
27
+ * `optionalDependencies` that name another such package.
28
+ */
29
+ import { execFileSync } from "node:child_process";
30
+ import { existsSync, readdirSync, readFileSync, realpathSync } from "node:fs";
31
+ // @ts-ignore — picomatch has no types declaration
32
+ import picomatch from "picomatch";
33
+ import { resolve } from "node:path";
34
+ import { readDeclaration } from "./declaration.js";
35
+ import { findTrain, readReleaseTrains } from "./release-train.js";
36
+ import { TrainCutError, trainConfigAt } from "./train-cut.js";
37
+ import { runToStderr } from "./train-shell.js";
38
+ import { locateWorkspace } from "./which-chant.js";
39
+ // A build's stdout goes to stderr: under --json, stdout is the prepare's JSON document alone.
40
+ const defaultRun = (command, cwd) => runToStderr(command, { cwd });
41
+ /** Stamp and build what the train's members cut from this commit need before `train publish` (#5154). */
42
+ export async function prepareTrain(q) {
43
+ const located = locateWorkspace(q.cwd);
44
+ const root = located.rootOnDisk;
45
+ const config = await trainConfigAt(root, q.env);
46
+ const say = q.say ?? (() => undefined);
47
+ const train = findTrain((await readReleaseTrains(root, q.env)).records, q.train);
48
+ if (!train)
49
+ throw new TrainCutError("train-unknown", q.train ? `no release train ${q.train} is recorded for ${q.env}` : `no release train is recorded for ${q.env}`, `List them with chant workspace train list ${q.env}.`);
50
+ let head;
51
+ try {
52
+ head = execFileSync("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
53
+ }
54
+ catch {
55
+ throw new TrainCutError("not-a-git-repository", "a train is prepared in a checkout of its commit, and this directory is not in a git repository");
56
+ }
57
+ const members = readDeclaration(located.tree, "", { rootChant: true }).members.filter((m) => m.kind === "chant" && m.dir !== ".");
58
+ const here = train.members.filter((m) => m.commit === head);
59
+ if (here.length === 0)
60
+ throw new TrainCutError("train-nothing-cut-here", `release train ${train.id} has no release cut from this checkout's commit ${head.slice(0, 12)}`, "Check out the commit the train's release-train tag names.");
61
+ const { loadChantConfig } = await import("../config.js");
62
+ const { stampReleaseVersion } = await import("../lifecycle/release-version.js");
63
+ const { trainPackageLabels } = await import("./train-range-labels.js");
64
+ const labels = await trainPackageLabels(train, root);
65
+ // Every workspace package the members name, by name.
66
+ const packages = new Map();
67
+ const ownedBy = new Map();
68
+ // Per member, each package it owns and the npm targets that pack it (none for a package only release.version names).
69
+ const packedBy = new Map();
70
+ const declsOf = new Map();
71
+ for (const m of members) {
72
+ const dir = resolve(root, m.dir);
73
+ if (!existsSync(dir))
74
+ continue;
75
+ const release = (await loadChantConfig(dir)).config.release;
76
+ declsOf.set(m.name, (release?.publish ?? []));
77
+ const dirs = [
78
+ ...(release?.version?.packages ?? []).map((p) => ({ p, decl: null })),
79
+ ...(release?.publish ?? []).flatMap((t) => (t.type === "npm" ? (t.packages ?? []).map((p) => ({ p, decl: t })) : [])),
80
+ ];
81
+ for (const { p, decl } of dirs) {
82
+ const file = resolve(dir, p, "package.json");
83
+ if (!existsSync(file))
84
+ continue;
85
+ const abs = realpathSync(resolve(dir, p));
86
+ let pkg;
87
+ try {
88
+ pkg = JSON.parse(readFileSync(file, "utf-8"));
89
+ }
90
+ catch {
91
+ continue;
92
+ }
93
+ if (typeof pkg.name !== "string")
94
+ continue;
95
+ packages.set(pkg.name, { dir: abs, name: pkg.name, needs: Object.keys({ ...pkg.dependencies, ...pkg.peerDependencies, ...pkg.optionalDependencies }), scripts: pkg.scripts ?? {} });
96
+ if (!(ownedBy.get(m.name) ?? []).includes(pkg.name))
97
+ ownedBy.set(m.name, [...(ownedBy.get(m.name) ?? []), pkg.name]);
98
+ const by = packedBy.get(m.name) ?? new Map();
99
+ by.set(pkg.name, [...(by.get(pkg.name) ?? []), ...(decl ? [decl] : [])]);
100
+ packedBy.set(m.name, by);
101
+ }
102
+ }
103
+ // The repository's other workspace packages (npm, yarn and pnpm workspaces), which a member's package may build against.
104
+ for (const dir of workspacePackageDirs(located.top ?? root)) {
105
+ try {
106
+ const p = JSON.parse(readFileSync(resolve(dir, "package.json"), "utf-8"));
107
+ if (typeof p.name !== "string" || packages.has(p.name))
108
+ continue;
109
+ packages.set(p.name, { dir: realpathSync(dir), name: p.name, needs: Object.keys({ ...p.dependencies, ...p.peerDependencies, ...p.optionalDependencies }), scripts: p.scripts ?? {} });
110
+ }
111
+ catch {
112
+ // Not a package chant can read; nothing builds against it.
113
+ }
114
+ }
115
+ // Stamp each member cut here.
116
+ const stamped = [];
117
+ for (const t of here) {
118
+ const m = members.find((x) => x.name === t.member);
119
+ if (!m)
120
+ continue;
121
+ const dir = resolve(root, m.dir);
122
+ const version = (await loadChantConfig(dir)).config.release?.version;
123
+ if (!version)
124
+ continue;
125
+ if (t.label === null)
126
+ throw new TrainCutError("train-member-unlabelled", `release train ${train.id} pins ${t.member} at a release with no label, which has no version to stamp`);
127
+ const { ReleaseVersionError } = await import("../lifecycle/release-version.js");
128
+ try {
129
+ const s = stampReleaseVersion({ cwd: dir, config: version, label: t.label, train: labels });
130
+ stamped.push({ member: t.member, label: t.label, files: s.files });
131
+ say(`stamped ${t.member} ${t.label}: ${s.files.join(", ")}`);
132
+ }
133
+ catch (err) {
134
+ if (err instanceof ReleaseVersionError)
135
+ throw new TrainCutError(err.code, `${t.member}: ${err.message}`, err.fix);
136
+ throw err;
137
+ }
138
+ }
139
+ // Build, once each and dependencies first, the packages the published ones need and this run does not publish.
140
+ const built = [];
141
+ if (config.buildDependencies !== false) {
142
+ const published = await packedThisRun(here, members, root, ownedBy, packedBy, declsOf);
143
+ const order = [];
144
+ const seen = new Set();
145
+ const visit = (name) => {
146
+ for (const d of [...(packages.get(name)?.needs ?? [])].sort()) {
147
+ if (d === name || !packages.has(d) || seen.has(d))
148
+ continue;
149
+ seen.add(d);
150
+ visit(d);
151
+ order.push(d);
152
+ }
153
+ };
154
+ for (const name of [...published].sort())
155
+ visit(name);
156
+ for (const name of order.filter((n) => !published.has(n))) {
157
+ const p = packages.get(name);
158
+ const command = config.buildDependencies ?? (typeof p.scripts.prepack === "string" ? "npm run prepack" : typeof p.scripts.build === "string" ? "npm run build" : null);
159
+ if (command === null)
160
+ continue;
161
+ const shown = p.dir.startsWith(`${realpathSync(located.top ?? root)}/`) ? p.dir.slice(realpathSync(located.top ?? root).length + 1) : p.dir;
162
+ say(`build ${name} (${shown}), which ${[...published].filter((x) => dependsOn(packages, x, name)).join(", ")} builds against: ${command}`);
163
+ const code = await (q.run ?? defaultRun)(command, p.dir);
164
+ if (code !== 0)
165
+ throw new TrainCutError("train-build-failed", `building ${name} in ${shown} failed (exit ${code}): ${command}`, "Fix the build and run the prepare again in a clean checkout of the train's commit.");
166
+ built.push({ dir: shown, command });
167
+ }
168
+ }
169
+ return { train, stamped, built };
170
+ }
171
+ /**
172
+ * The packages the publish packs in this run: those of each member cut here,
173
+ * less the ones an earlier run already revealed (#5222). A package is
174
+ * revealed when every npm target that packs it is; a package no npm target
175
+ * packs, when every target of its member is.
176
+ */
177
+ async function packedThisRun(here, members, root, ownedBy, packedBy, declsOf) {
178
+ const { publishProgress, readPublishRecords } = await import("../lifecycle/publish-record.js");
179
+ const { publishTargetKey } = await import("../lifecycle/publish-targets.js");
180
+ const out = new Set();
181
+ for (const t of here) {
182
+ const m = members.find((x) => x.name === t.member);
183
+ const owned = ownedBy.get(t.member) ?? [];
184
+ if (!m) {
185
+ owned.forEach((n) => out.add(n));
186
+ continue;
187
+ }
188
+ const progress = publishProgress(await readPublishRecords(t.releaseDigest, { cwd: resolve(root, m.dir) }).catch(() => []));
189
+ const revealed = (d) => progress.revealed.has(publishTargetKey(d));
190
+ const decls = declsOf.get(t.member) ?? [];
191
+ const memberRevealed = decls.length > 0 && decls.every(revealed);
192
+ for (const name of owned) {
193
+ const by = packedBy.get(t.member)?.get(name) ?? [];
194
+ const done = by.length > 0 ? by.every(revealed) : memberRevealed;
195
+ if (!done)
196
+ out.add(name);
197
+ }
198
+ }
199
+ return out;
200
+ }
201
+ /**
202
+ * The package directories the repository's root declares as workspaces:
203
+ * `workspaces` in its package.json (an array, or `{ packages }` as yarn
204
+ * writes it) and `packages:` in pnpm-workspace.yaml. A pattern is matched
205
+ * against directories up to four levels deep, leaving out node_modules and
206
+ * dot directories; a `!` pattern excludes.
207
+ */
208
+ export function workspacePackageDirs(top) {
209
+ const patterns = [];
210
+ try {
211
+ const w = JSON.parse(readFileSync(resolve(top, "package.json"), "utf-8")).workspaces;
212
+ const list = Array.isArray(w) ? w : w && typeof w === "object" && Array.isArray(w.packages) ? w.packages : [];
213
+ patterns.push(...list.filter((p) => typeof p === "string"));
214
+ }
215
+ catch {
216
+ // No package.json, or not JSON.
217
+ }
218
+ try {
219
+ const yaml = readFileSync(resolve(top, "pnpm-workspace.yaml"), "utf-8");
220
+ let inPackages = false;
221
+ for (const line of yaml.split("\n")) {
222
+ if (/^packages:\s*$/.test(line)) {
223
+ inPackages = true;
224
+ continue;
225
+ }
226
+ if (inPackages && /^\S/.test(line))
227
+ inPackages = false;
228
+ const m = inPackages ? /^\s*-\s*['"]?([^'"#]+?)['"]?\s*(?:#.*)?$/.exec(line) : null;
229
+ if (m)
230
+ patterns.push(m[1]);
231
+ }
232
+ }
233
+ catch {
234
+ // No pnpm-workspace.yaml.
235
+ }
236
+ if (patterns.length === 0)
237
+ return [];
238
+ const include = patterns.filter((p) => !p.startsWith("!")).map((p) => picomatch(p.replace(/^\.\//, "").replace(/\/$/, "")));
239
+ const exclude = patterns.filter((p) => p.startsWith("!")).map((p) => picomatch(p.slice(1).replace(/^\.\//, "").replace(/\/$/, "")));
240
+ const out = [];
241
+ const walk = (rel, depth) => {
242
+ if (depth > 4)
243
+ return;
244
+ let entries;
245
+ try {
246
+ entries = readdirSync(resolve(top, rel), { withFileTypes: true });
247
+ }
248
+ catch {
249
+ return;
250
+ }
251
+ for (const e of entries) {
252
+ if (!e.isDirectory() || e.name === "node_modules" || e.name.startsWith("."))
253
+ continue;
254
+ const sub = rel ? `${rel}/${e.name}` : e.name;
255
+ if (include.some((m) => m(sub)) && !exclude.some((m) => m(sub)) && existsSync(resolve(top, sub, "package.json")))
256
+ out.push(resolve(top, sub));
257
+ walk(sub, depth + 1);
258
+ }
259
+ };
260
+ walk("", 1);
261
+ return out;
262
+ }
263
+ /** Whether `from` needs `to`, directly or not, among `packages`. */
264
+ function dependsOn(packages, from, to, seen = new Set()) {
265
+ for (const d of packages.get(from)?.needs ?? []) {
266
+ if (d === to)
267
+ return true;
268
+ if (seen.has(d) || !packages.has(d))
269
+ continue;
270
+ seen.add(d);
271
+ if (dependsOn(packages, d, to, seen))
272
+ return true;
273
+ }
274
+ return false;
275
+ }
276
+ const PREPARE_USAGE = "chant workspace train prepare <env> [<train id|digest>] [--json]";
277
+ /** `chant workspace train prepare <env> [<train>]` (#5154). */
278
+ export async function runTrainPrepare(ctx, words) {
279
+ const { formatError, formatSuccess } = await import("../cli/format.js");
280
+ const { WorkspaceReadError } = await import("./declaration.js");
281
+ const [env, ref] = words;
282
+ if (!env) {
283
+ console.error(formatError({ message: "chant workspace train prepare needs an environment", hint: PREPARE_USAGE }));
284
+ return 1;
285
+ }
286
+ const json = ctx.args.json === true;
287
+ const cwd = resolve(".");
288
+ const { fetchLifecycle } = await import("../lifecycle/git.js");
289
+ await fetchLifecycle({ cwd }).catch(() => false);
290
+ let outcome;
291
+ try {
292
+ outcome = await prepareTrain({ cwd, env, ...(ref !== undefined ? { train: ref } : {}), say: (line) => (json ? undefined : console.error(line)) });
293
+ }
294
+ catch (err) {
295
+ if (err instanceof TrainCutError) {
296
+ if (json)
297
+ console.log(JSON.stringify({ status: "refused", code: err.code, message: err.message }, null, 2));
298
+ console.error(formatError({ message: `${err.message} [${err.code}]`, hint: err.fix ?? PREPARE_USAGE }));
299
+ return 1;
300
+ }
301
+ if (err instanceof WorkspaceReadError) {
302
+ console.error(formatError({ message: `${err.code}: ${err.describe()}`, hint: PREPARE_USAGE }));
303
+ return 1;
304
+ }
305
+ throw err;
306
+ }
307
+ if (json) {
308
+ console.log(JSON.stringify({ train: outcome.train.id, trainDigest: outcome.train.trainDigest, env, stamped: outcome.stamped, built: outcome.built }, null, 2));
309
+ return 0;
310
+ }
311
+ console.error(formatSuccess(`Prepared release train ${outcome.train.id}: ${outcome.stamped.length} member(s) stamped, ${outcome.built.length} dependency package(s) built. Next: chant workspace train publish ${env} ${outcome.train.id} --yes`));
312
+ return 0;
313
+ }
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Publishing a release train as one set (#5136, design #5132 decision 5):
3
+ * `chant workspace train publish <env> [<train>] [--yes]`.
4
+ *
5
+ * A train pins one release of every `chant` member. Its publish runs in a
6
+ * checkout of the commit the train's new releases were cut from, and splits
7
+ * the members in two:
8
+ *
9
+ * - a member whose release was cut from this commit is published by this run;
10
+ * - a member pinned at a release cut from another commit must already be
11
+ * published: its publish record (`_releases/publishes.jsonl`) shows every
12
+ * target revealed, or each target that is not says its destination already
13
+ * serves the release's label (`PublishTarget.published`). Otherwise the
14
+ * publish refuses before anything stages.
15
+ *
16
+ * Every member it publishes is prepared as `chant release publish` prepares
17
+ * one (`preparePublish`: revocation, signatures, provenance, a clean checkout
18
+ * of the release's commit), and every target is planned, before anything
19
+ * stages. The members are put in dependency layers from the names their
20
+ * targets publish and need (`PublishTarget.names`, #5165), each qualified by
21
+ * its kind (./lifecycle/publish-train-names.ts): npm package names and their
22
+ * dependency, peer and optional keys; an image's repository; PyPI projects and
23
+ * their `Requires-Dist`; crates and their dependencies; an extension and its
24
+ * `extensionDependencies`; an MCP Registry entry and the packages and images
25
+ * its `server.json` lists. A member's `release.dependsOn` adds the members a
26
+ * manifest doesn't show. Members of one layer go in name order, so core
27
+ * comes first.
28
+ *
29
+ * Then two passes, as `runPublish` does for one release (#4048), across the
30
+ * whole train:
31
+ *
32
+ * 1. Stage every member's targets, layer by layer, so a failure leaves no
33
+ * member visible to a consumer.
34
+ * 2. Run each member's `release.verify` commands (#5157), in layer order,
35
+ * with the whole train's staged references, unless a record shows a
36
+ * reveal. A failure is recorded in the member's record and stops the
37
+ * publish before the first layer reveals.
38
+ * 3. Reveal layer by layer. Before the next layer, wait until each revealed
39
+ * target of this one resolves for a consumer (`PublishTarget.visible`:
40
+ * npm's `dist-tags.latest` names the version, an image's tags name its
41
+ * digest, an index or registry lists the version), so nothing is visible
42
+ * before what it needs is.
43
+ *
44
+ * Within a member, targets reveal in `revealOrder`: uploads at reveal after
45
+ * the rest, and the MCP Registry last.
46
+ *
47
+ * A target whose stage is already visible (npm under `stage: false`) is not
48
+ * staged up front: it publishes in pass 2, in its layer's turn, after the
49
+ * layers before it are visible.
50
+ *
51
+ * Every step is recorded in the member's own publish record, so running the
52
+ * same command after a failure resumes across members without publishing
53
+ * again what went out, and `chant release publish` in one member reads the
54
+ * same record.
55
+ */
56
+ import type { PublishItem, PublishedTarget, PublishDeps } from "../lifecycle/release-publish.js";
57
+ import { PublishTargetError } from "../lifecycle/release-publish.js";
58
+ import type { Redactor } from "../lifecycle/publish-credentials.js";
59
+ import { type ReadTrain } from "./release-train.js";
60
+ /** The first chant whose `chant workspace train publish` orders and resumes members of every target kind (#5165): the oci, forge, homebrew, index, marketplace, pypi, cargo, mcp-registry and tauri-updater targets name what they publish and need, say whether a pinned release is published, and wait until a reveal is served before the next layer; a member's `release.dependsOn` names members a manifest doesn't show. */
61
+ export declare const TRAIN_PUBLISH_TARGETS_FLOOR = "0.124.101";
62
+ /** One target of a member, as planned. */
63
+ export interface TrainPlannedTarget {
64
+ name: string;
65
+ kind: string;
66
+ destination: string;
67
+ /** What an earlier run of the publish did for it. */
68
+ progress: "none" | "staged" | "revealed";
69
+ items: PublishItem[];
70
+ }
71
+ /** One member of the train, as the publish sees it. */
72
+ export interface TrainPublishMember {
73
+ member: string;
74
+ label: string | null;
75
+ releaseDigest: string;
76
+ commit: string;
77
+ /** `publish`: cut from this checkout's commit, published by this run. `pinned`: an earlier release, already published. */
78
+ role: "publish" | "pinned";
79
+ /** The dependency layer, 0 first; null for a pinned member. */
80
+ layer: number | null;
81
+ /** The members of this run it reveals after (#5165), from its targets' names and `release.dependsOn`. */
82
+ after?: string[];
83
+ targets: TrainPlannedTarget[];
84
+ }
85
+ /** A member's `release.verify` commands (#5157), and the targets of the train they can't see. */
86
+ export interface TrainVerifyPlan {
87
+ member: string;
88
+ steps: import("../lifecycle/publish-verify.js").VerifyStep[];
89
+ }
90
+ export interface TrainPublishRefusal {
91
+ kind: "refused";
92
+ code: string;
93
+ message: string;
94
+ fix?: string;
95
+ }
96
+ export type TrainPublishOutcome = TrainPublishRefusal | {
97
+ kind: "planned";
98
+ train: ReadTrain;
99
+ members: TrainPublishMember[];
100
+ warnings: string[];
101
+ redactor: Redactor;
102
+ verify: TrainVerifyPlan[];
103
+ } | {
104
+ kind: "published";
105
+ train: ReadTrain;
106
+ members: TrainPublishMember[];
107
+ warnings: string[];
108
+ redactor: Redactor;
109
+ /** Each member this run published, with its targets revealed. */
110
+ published: Array<{
111
+ member: string;
112
+ targets: PublishedTarget[];
113
+ }>;
114
+ /** The targets an earlier run had staged or revealed, so this one did not stage them again. */
115
+ resumed: Array<{
116
+ member: string;
117
+ target: string;
118
+ step: "staged" | "revealed";
119
+ }>;
120
+ recordWarning: string | null;
121
+ verify: TrainVerifyPlan[];
122
+ /** How the verify commands went: `passed`, or `skipped` when a reveal was already recorded; absent with none. */
123
+ verified?: "passed" | "skipped";
124
+ /** Why a member's floating tag (#5150) was not moved, one line each. */
125
+ floatingWarnings?: string[];
126
+ };
127
+ /** A train publish that stopped, with what it left staged and revealed (`<member>: <target>`), so a run of the same command resumes. */
128
+ export declare class TrainPublishRunError extends PublishTargetError {
129
+ readonly member: string;
130
+ readonly step: "stage" | "verify" | "reveal" | "wait";
131
+ readonly staged: string[];
132
+ readonly revealed: string[];
133
+ constructor(code: string, message: string, fix: string | undefined, member: string, step: "stage" | "verify" | "reveal" | "wait", staged: string[], revealed: string[]);
134
+ }
135
+ export interface TrainPublishQuery {
136
+ /** Any directory in the workspace whose train it publishes. */
137
+ cwd: string;
138
+ env: string;
139
+ /** The train, by id or digest; the newest for `env` when absent. */
140
+ train?: string;
141
+ /** Publish; without it the publish is planned and nothing is sent. */
142
+ yes?: boolean;
143
+ allowUnsigned?: boolean;
144
+ requireProvenance?: boolean;
145
+ /** The environment credentials are read from. Default: `process.env`. */
146
+ processEnv?: NodeJS.ProcessEnv;
147
+ deps?: PublishDeps;
148
+ /** A line of progress. Redacted. */
149
+ say?: (line: string) => void;
150
+ /** A line a target logs. Redacted. */
151
+ log?: (line: string) => void;
152
+ /** Write the publish records. Default true. */
153
+ record?: boolean;
154
+ now?: () => Date;
155
+ /** Runs one `release.verify` command; the default runs it through the shell. */
156
+ runVerify?: import("../lifecycle/publish-verify.js").VerifyRunner;
157
+ }
158
+ /**
159
+ * Dependency layers over `members` (pure): a member needs another when one
160
+ * of the names it needs is one the other provides. Members of a cycle share
161
+ * a layer. Each layer is sorted by name.
162
+ */
163
+ export declare function trainLayers(members: ReadonlyArray<{
164
+ member: string;
165
+ provides: readonly string[];
166
+ needs: readonly string[];
167
+ }>): string[][];
168
+ /** Each member's direct dependencies among `members` (pure), by the same rule as {@link trainLayers}. */
169
+ export declare function trainDependencies(members: ReadonlyArray<{
170
+ member: string;
171
+ provides: readonly string[];
172
+ needs: readonly string[];
173
+ }>): Map<string, string[]>;
174
+ /** Plan, and with `yes` publish, a release train (#5136). */
175
+ export declare function publishTrain(query: TrainPublishQuery): Promise<TrainPublishOutcome>;
176
+ /** `chant workspace train publish <env> [<train>] [--yes]` (#5136). */
177
+ export declare function runTrainPublish(ctx: import("../cli/registry.js").CommandContext, words: string[]): Promise<number>;