@intentius/chant 0.124.99 → 0.124.101
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/bin/chant +3 -3
- package/dist/action-pins.d.ts +2 -0
- package/dist/action-pins.js +3 -0
- package/dist/ci-detect.d.ts +13 -0
- package/dist/ci-detect.js +12 -0
- package/dist/ci-system.d.ts +66 -0
- package/dist/ci-system.js +61 -0
- package/dist/cli/commands/carve-emit.js +2 -2
- package/dist/cli/commands/check-lexicon-plugin.d.ts +2 -2
- package/dist/cli/commands/check-lexicon-plugin.js +3 -3
- package/dist/cli/commands/check-lexicon.js +4 -4
- package/dist/cli/commands/init-lexicon/templates/project.d.ts +1 -1
- package/dist/cli/commands/init-lexicon/templates/project.js +4 -4
- package/dist/cli/commands/init.d.ts +13 -0
- package/dist/cli/commands/init.js +30 -2
- package/dist/cli/handlers/build.js +27 -0
- package/dist/cli/handlers/release-doctor.d.ts +12 -0
- package/dist/cli/handlers/release-doctor.js +118 -0
- package/dist/cli/handlers/release-init.d.ts +10 -0
- package/dist/cli/handlers/release-init.js +342 -0
- package/dist/cli/handlers/release.d.ts +50 -1
- package/dist/cli/handlers/release.js +688 -30
- package/dist/cli/handlers/run-generate.js +11 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +45 -97
- package/dist/cli/parse-args.js +55 -0
- package/dist/cli/registry.d.ts +18 -0
- package/dist/cli/release-commands/artifacts.d.ts +3 -0
- package/dist/cli/release-commands/artifacts.js +14 -0
- package/dist/cli/release-commands/candidates.d.ts +3 -0
- package/dist/cli/release-commands/candidates.js +16 -0
- package/dist/cli/release-commands/changed.d.ts +3 -0
- package/dist/cli/release-commands/changed.js +14 -0
- package/dist/cli/release-commands/compose.d.ts +3 -0
- package/dist/cli/release-commands/compose.js +16 -0
- package/dist/cli/release-commands/cut.d.ts +3 -0
- package/dist/cli/release-commands/cut.js +49 -0
- package/dist/cli/release-commands/doctor.d.ts +3 -0
- package/dist/cli/release-commands/doctor.js +14 -0
- package/dist/cli/release-commands/export.d.ts +3 -0
- package/dist/cli/release-commands/export.js +12 -0
- package/dist/cli/release-commands/images.d.ts +3 -0
- package/dist/cli/release-commands/images.js +13 -0
- package/dist/cli/release-commands/index.d.ts +8 -0
- package/dist/cli/release-commands/index.js +52 -0
- package/dist/cli/release-commands/init.d.ts +3 -0
- package/dist/cli/release-commands/init.js +16 -0
- package/dist/cli/release-commands/list.d.ts +3 -0
- package/dist/cli/release-commands/list.js +10 -0
- package/dist/cli/release-commands/next.d.ts +3 -0
- package/dist/cli/release-commands/next.js +13 -0
- package/dist/cli/release-commands/publish.d.ts +3 -0
- package/dist/cli/release-commands/publish.js +22 -0
- package/dist/cli/release-commands/stamp.d.ts +3 -0
- package/dist/cli/release-commands/stamp.js +15 -0
- package/dist/cli/release-commands/status.d.ts +3 -0
- package/dist/cli/release-commands/status.js +17 -0
- package/dist/cli/release-commands/tag.d.ts +3 -0
- package/dist/cli/release-commands/tag.js +12 -0
- package/dist/cli/release-commands/types.d.ts +20 -0
- package/dist/cli/release-commands/types.js +1 -0
- package/dist/cli/release-commands/verify.d.ts +3 -0
- package/dist/cli/release-commands/verify.js +15 -0
- package/dist/cli/release-commands/workflow.d.ts +3 -0
- package/dist/cli/release-commands/workflow.js +13 -0
- package/dist/codegen/pinned-upgrade.js +1 -1
- package/dist/components/capability-plugin.d.ts +1 -1
- package/dist/components/capability-plugin.js +1 -1
- package/dist/components/cli-support.d.ts +1 -1
- package/dist/components/cli-support.js +1 -1
- package/dist/config-environments.d.ts +8 -1
- package/dist/config-environments.js +2 -0
- package/dist/config.d.ts +299 -6
- package/dist/config.js +102 -5
- package/dist/dead-guards.d.ts +5 -1
- package/dist/dead-guards.js +34 -23
- package/dist/discovery/sandbox/driver.js +1 -1
- package/dist/discovery/specifier-resolve.js +1 -1
- package/dist/floor-table.d.ts +3 -1
- package/dist/floor-table.data.js +23 -3
- package/dist/floor-table.js +4 -3
- package/dist/forge-remote.d.ts +13 -0
- package/dist/forge-remote.js +15 -0
- package/dist/lexicon.d.ts +41 -2
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.js +270 -3
- package/dist/lifecycle/publish-attachments.d.ts +2 -1
- package/dist/lifecycle/publish-attachments.js +19 -2
- package/dist/lifecycle/publish-cargo.d.ts +99 -0
- package/dist/lifecycle/publish-cargo.js +412 -0
- package/dist/lifecycle/publish-credentials.d.ts +1 -1
- package/dist/lifecycle/publish-credentials.js +8 -0
- package/dist/lifecycle/publish-declaration.d.ts +199 -4
- package/dist/lifecycle/publish-declaration.js +200 -9
- package/dist/lifecycle/publish-forge.d.ts +45 -2
- package/dist/lifecycle/publish-forge.js +434 -34
- package/dist/lifecycle/publish-git-ssh.d.ts +15 -0
- package/dist/lifecycle/publish-git-ssh.js +30 -4
- package/dist/lifecycle/publish-github.d.ts +40 -2
- package/dist/lifecycle/publish-github.js +100 -3
- package/dist/lifecycle/publish-homebrew.d.ts +7 -9
- package/dist/lifecycle/publish-homebrew.js +34 -197
- package/dist/lifecycle/publish-index.d.ts +141 -0
- package/dist/lifecycle/publish-index.js +719 -0
- package/dist/lifecycle/publish-marketplace.js +77 -0
- package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
- package/dist/lifecycle/publish-mcp-registry.js +306 -0
- package/dist/lifecycle/publish-npm.js +165 -2
- package/dist/lifecycle/publish-oci.d.ts +34 -1
- package/dist/lifecycle/publish-oci.js +246 -7
- package/dist/lifecycle/publish-pypi.d.ts +136 -0
- package/dist/lifecycle/publish-pypi.js +657 -0
- package/dist/lifecycle/publish-record.d.ts +6 -3
- package/dist/lifecycle/publish-record.js +6 -3
- package/dist/lifecycle/publish-signing.d.ts +147 -0
- package/dist/lifecycle/publish-signing.js +257 -0
- package/dist/lifecycle/publish-targets.d.ts +27 -1
- package/dist/lifecycle/publish-targets.js +80 -0
- package/dist/lifecycle/publish-tauri.js +43 -0
- package/dist/lifecycle/publish-train-names.d.ts +54 -0
- package/dist/lifecycle/publish-train-names.js +118 -0
- package/dist/lifecycle/publish-verify.d.ts +121 -0
- package/dist/lifecycle/publish-verify.js +130 -0
- package/dist/lifecycle/query.js +8 -0
- package/dist/lifecycle/release-artifacts.d.ts +212 -0
- package/dist/lifecycle/release-artifacts.js +571 -0
- package/dist/lifecycle/release-changelog.d.ts +13 -1
- package/dist/lifecycle/release-changelog.js +35 -2
- package/dist/lifecycle/release-cut.d.ts +58 -3
- package/dist/lifecycle/release-cut.js +132 -34
- package/dist/lifecycle/release-doctor.d.ts +113 -0
- package/dist/lifecycle/release-doctor.js +996 -0
- package/dist/lifecycle/release-green.d.ts +86 -0
- package/dist/lifecycle/release-green.js +286 -0
- package/dist/lifecycle/release-init.d.ts +255 -0
- package/dist/lifecycle/release-init.js +859 -0
- package/dist/lifecycle/release-intents.d.ts +73 -0
- package/dist/lifecycle/release-intents.js +128 -0
- package/dist/lifecycle/release-next.d.ts +111 -0
- package/dist/lifecycle/release-next.js +252 -0
- package/dist/lifecycle/release-prerelease.d.ts +19 -0
- package/dist/lifecycle/release-prerelease.js +30 -0
- package/dist/lifecycle/release-publish.d.ts +256 -10
- package/dist/lifecycle/release-publish.js +246 -34
- package/dist/lifecycle/release-status-change.d.ts +226 -0
- package/dist/lifecycle/release-status-change.js +478 -0
- package/dist/lifecycle/release-status.d.ts +11 -0
- package/dist/lifecycle/release-status.js +1 -1
- package/dist/lifecycle/release-store.d.ts +73 -2
- package/dist/lifecycle/release-store.js +32 -1
- package/dist/lifecycle/release-tag.d.ts +142 -0
- package/dist/lifecycle/release-tag.js +323 -0
- package/dist/lifecycle/release-verify.d.ts +73 -1
- package/dist/lifecycle/release-verify.js +117 -2
- package/dist/lifecycle/release-version-formats.d.ts +73 -0
- package/dist/lifecycle/release-version-formats.js +570 -0
- package/dist/lifecycle/release-version.d.ts +58 -10
- package/dist/lifecycle/release-version.js +164 -36
- package/dist/lifecycle/release-workstation.d.ts +3 -2
- package/dist/lifecycle/release-workstation.js +3 -2
- package/dist/module-source.d.ts +2 -2
- package/dist/module-source.js +8 -8
- package/dist/op/generate-pipeline.js +1 -1
- package/dist/pr-forge-base.js +4 -2
- package/dist/pr-forge.d.ts +20 -2
- package/dist/pr-forge.js +46 -10
- package/dist/release-floors.d.ts +10 -1
- package/dist/release-floors.js +10 -1
- package/dist/tool-pins.d.ts +38 -0
- package/dist/tool-pins.js +54 -0
- package/dist/ts-loader.d.ts +1 -1
- package/dist/ts-loader.js +6 -6
- package/dist/wave-runtime.mjs +337 -334
- package/dist/workspace/ci-forge.d.ts +17 -0
- package/dist/workspace/ci-forge.js +17 -0
- package/dist/workspace/ci-init.js +1 -1
- package/dist/workspace/composites.schema.json +1 -0
- package/dist/workspace/declaration.d.ts +8 -0
- package/dist/workspace/declaration.js +12 -0
- package/dist/workspace/declaration.schema.json +8 -0
- package/dist/workspace/environments.d.ts +2 -0
- package/dist/workspace/environments.js +1 -1
- package/dist/workspace/identity-gate-rule.d.ts +61 -5
- package/dist/workspace/identity-gate-rule.js +81 -12
- package/dist/workspace/member-pipeline.d.ts +2 -1
- package/dist/workspace/member-pipeline.js +5 -2
- package/dist/workspace/reason-codes.d.ts +6 -0
- package/dist/workspace/reason-codes.js +8 -1
- package/dist/workspace/release-changed.d.ts +179 -0
- package/dist/workspace/release-changed.js +625 -0
- package/dist/workspace/release-changed.schema.json +206 -0
- package/dist/workspace/release-steps/artifacts.d.ts +7 -0
- package/dist/workspace/release-steps/artifacts.js +45 -0
- package/dist/workspace/release-steps/builds.d.ts +12 -0
- package/dist/workspace/release-steps/builds.js +38 -0
- package/dist/workspace/release-steps/doctor.d.ts +8 -0
- package/dist/workspace/release-steps/doctor.js +14 -0
- package/dist/workspace/release-steps/goreleaser.d.ts +16 -0
- package/dist/workspace/release-steps/goreleaser.js +36 -0
- package/dist/workspace/release-steps/green.d.ts +3 -0
- package/dist/workspace/release-steps/green.js +6 -0
- package/dist/workspace/release-steps/images.d.ts +22 -0
- package/dist/workspace/release-steps/images.js +59 -0
- package/dist/workspace/release-steps/index.d.ts +9 -0
- package/dist/workspace/release-steps/index.js +46 -0
- package/dist/workspace/release-steps/pypi.d.ts +15 -0
- package/dist/workspace/release-steps/pypi.js +21 -0
- package/dist/workspace/release-steps/qemu.d.ts +21 -0
- package/dist/workspace/release-steps/qemu.js +35 -0
- package/dist/workspace/release-steps/signing.d.ts +18 -0
- package/dist/workspace/release-steps/signing.js +30 -0
- package/dist/workspace/release-steps/stamp.d.ts +3 -0
- package/dist/workspace/release-steps/stamp.js +4 -0
- package/dist/workspace/release-steps/targets.d.ts +31 -0
- package/dist/workspace/release-steps/targets.js +40 -0
- package/dist/workspace/release-steps/types.d.ts +104 -0
- package/dist/workspace/release-steps/types.js +2 -0
- package/dist/workspace/release-steps/verify.d.ts +3 -0
- package/dist/workspace/release-steps/verify.js +4 -0
- package/dist/workspace/release-toolchains.d.ts +59 -0
- package/dist/workspace/release-toolchains.js +133 -0
- package/dist/workspace/release-train-workflow.d.ts +29 -0
- package/dist/workspace/release-train-workflow.js +85 -0
- package/dist/workspace/release-train.d.ts +3 -1
- package/dist/workspace/release-train.js +20 -3
- package/dist/workspace/release-workflow.d.ts +160 -61
- package/dist/workspace/release-workflow.js +539 -193
- package/dist/workspace/releases.schema.json +70 -1
- package/dist/workspace/search-contract.d.ts +1 -1
- package/dist/workspace/security.js +9 -2
- package/dist/workspace/train-cut.d.ts +182 -0
- package/dist/workspace/train-cut.js +482 -0
- package/dist/workspace/train-prepare.d.ts +61 -0
- package/dist/workspace/train-prepare.js +267 -0
- package/dist/workspace/train-publish.d.ts +177 -0
- package/dist/workspace/train-publish.js +575 -0
- package/dist/workspace/train-range-labels.d.ts +33 -0
- package/dist/workspace/train-range-labels.js +109 -0
- package/dist/workspace/trust/seal.d.ts +13 -3
- package/dist/workspace/trust/seal.js +14 -4
- package/dist/workspace/work-cli.d.ts +3 -2
- package/dist/workspace/work-cli.js +3 -2
- package/dist/workspace/workspace-ledger.d.ts +14 -1
- package/dist/workspace/workspace-ledger.js +33 -7
- package/package.json +26 -26
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cutting a release train (#5154): `chant workspace train cut <env> [--at
|
|
3
|
+
* <sha>] [--levels <levels>] [--yes] [--no-push] [--json]`, run in the root of
|
|
4
|
+
* a workspace whose `chant` members are the releasable units (each package
|
|
5
|
+
* of a monorepo, say), with `release.train` in the root's `chant.config.ts`.
|
|
6
|
+
*
|
|
7
|
+
* One command does what a hand-written release script did:
|
|
8
|
+
*
|
|
9
|
+
* 1. The commit: `--at` (the trunk's tip without it). A commit a
|
|
10
|
+
* `release-train/<env>/<id>` tag already names is released, and nothing
|
|
11
|
+
* more happens.
|
|
12
|
+
* 2. The members: those `chant release changed` lists at the commit, with
|
|
13
|
+
* its dependency closure, each at the level `--levels` types for it or,
|
|
14
|
+
* without one, the level its conventional commits and intent files give.
|
|
15
|
+
* A member already cut from this commit (a run that stopped part way) is
|
|
16
|
+
* taken at the label it was cut with, and is not cut again.
|
|
17
|
+
* 3. The labels: each member's next label is floored past every version it
|
|
18
|
+
* already has: the labels in its ledger, its release tags (`release.tag`,
|
|
19
|
+
* or `release/<member>/<label>`), the `release.legacyTags` tags, the
|
|
20
|
+
* `version` of each package its `release.version` names at the commit,
|
|
21
|
+
* and every version the npm registry lists for the packages it publishes.
|
|
22
|
+
* So a label is never one a registry already holds. Under `first:
|
|
23
|
+
* "together"` the first train of the environment cuts every member at one
|
|
24
|
+
* label, one past the highest of all of them and of the root member's
|
|
25
|
+
* own ledger.
|
|
26
|
+
* 4. `release.train.check`: shell lines run once the labels are known and
|
|
27
|
+
* before anything is cut, with `CHANT_RELEASE_COMMIT`, `CHANT_TRAIN_ENV`
|
|
28
|
+
* and `CHANT_TRAIN_PLAN` (a JSON file of the members and labels).
|
|
29
|
+
* 5. `chant release cut <label> --at <commit> --yes` in each member's
|
|
30
|
+
* directory, in publish order. Each cut pushes its record and tags the
|
|
31
|
+
* commit locally.
|
|
32
|
+
* 6. The train: every member at the release this run cut, the rest at their
|
|
33
|
+
* newest, written to `chant/lifecycle` and pushed.
|
|
34
|
+
* 7. One atomic push of every member's tag and `release-train/<env>/<id>` on
|
|
35
|
+
* the commit. A workflow on that tag publishes the train.
|
|
36
|
+
*
|
|
37
|
+
* Without `--yes` it plans: it prints the members and labels, runs each
|
|
38
|
+
* cut's dry run, and cuts, records, tags and pushes nothing.
|
|
39
|
+
*/
|
|
40
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
41
|
+
import { randomUUID } from "node:crypto";
|
|
42
|
+
import { existsSync, mkdtempSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
43
|
+
import { tmpdir } from "node:os";
|
|
44
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
45
|
+
import { readCuts } from "../lifecycle/release-store.js";
|
|
46
|
+
import { readDeclaration } from "./declaration.js";
|
|
47
|
+
import { bumpLabel, parseVersion, RELEASE_BUMPS } from "./release-changed.js";
|
|
48
|
+
import { appendReleaseTrain, pickTrain, readMemberReleases, readReleaseTrains, trainDigest } from "./release-train.js";
|
|
49
|
+
import { locateWorkspace } from "./which-chant.js";
|
|
50
|
+
/** Why a train cut stopped. */
|
|
51
|
+
export class TrainCutError extends Error {
|
|
52
|
+
constructor(code, message, fix) {
|
|
53
|
+
super(message);
|
|
54
|
+
this.code = code;
|
|
55
|
+
this.fix = fix;
|
|
56
|
+
this.name = "TrainCutError";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parse `--levels`: words separated by spaces or commas, each `major`,
|
|
61
|
+
* `minor` or `patch` (every member), `<member>=<level>`, or `auto` (the
|
|
62
|
+
* levels the commits and intent files give; the same as nothing).
|
|
63
|
+
*/
|
|
64
|
+
export function parseTrainLevels(text) {
|
|
65
|
+
const out = { members: {} };
|
|
66
|
+
for (const word of (text ?? "").split(/[\s,]+/).filter(Boolean)) {
|
|
67
|
+
if (word === "auto")
|
|
68
|
+
continue;
|
|
69
|
+
const at = word.indexOf("=");
|
|
70
|
+
const level = at < 0 ? word : word.slice(at + 1);
|
|
71
|
+
if (!RELEASE_BUMPS.includes(level)) {
|
|
72
|
+
throw new TrainCutError("train-levels-invalid", `--levels ${JSON.stringify(word)}: a level is major, minor or patch`, "Give auto, a level for every member, <member>=<level>, or several of them separated by spaces.");
|
|
73
|
+
}
|
|
74
|
+
if (at < 0) {
|
|
75
|
+
if (out.all !== undefined && out.all !== level)
|
|
76
|
+
throw new TrainCutError("train-levels-invalid", `--levels gives two levels for every member (${out.all}, ${level})`);
|
|
77
|
+
out.all = level;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const m = word.slice(0, at);
|
|
81
|
+
if (m === "")
|
|
82
|
+
throw new TrainCutError("train-levels-invalid", `--levels ${JSON.stringify(word)} names no member`);
|
|
83
|
+
out.members[m] = level;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
const cmp = (a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
89
|
+
const show = (v) => v.join(".");
|
|
90
|
+
/** The highest of `versions`, or null. */
|
|
91
|
+
export function highestVersion(versions) {
|
|
92
|
+
let best = null;
|
|
93
|
+
for (const t of versions) {
|
|
94
|
+
const v = parseVersion(t);
|
|
95
|
+
if (v && (best === null || cmp(v, best) > 0))
|
|
96
|
+
best = v;
|
|
97
|
+
}
|
|
98
|
+
return best ? show(best) : null;
|
|
99
|
+
}
|
|
100
|
+
function git(top, args) {
|
|
101
|
+
return execFileSync("git", args, { cwd: top, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 256 * 1024 * 1024 }).trim();
|
|
102
|
+
}
|
|
103
|
+
function tryGit(top, args) {
|
|
104
|
+
try {
|
|
105
|
+
return git(top, args);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** `npm view <name> versions --json`, as npm prints it: a string for one version, an array for several. */
|
|
112
|
+
export function npmVersions(npm = "npm", env = process.env) {
|
|
113
|
+
return (name, registry) => {
|
|
114
|
+
const r = spawnSync(npm, ["view", name, "versions", "--json", ...(registry ? ["--registry", registry] : [])], { encoding: "utf-8", env, maxBuffer: 64 * 1024 * 1024 });
|
|
115
|
+
const out = `${r.stdout ?? ""}\n${r.stderr ?? ""}`;
|
|
116
|
+
if (r.status !== 0) {
|
|
117
|
+
if (/E404|404 Not Found/.test(out))
|
|
118
|
+
return null;
|
|
119
|
+
throw new TrainCutError("train-registry-unreadable", `npm view ${name} versions failed, so the version floor of ${name} is unknown: ${(r.error?.message ?? out).trim().split("\n").at(-1)}`, "Check that npm can reach the registry, and run the train again.");
|
|
120
|
+
}
|
|
121
|
+
// npm's notices ("npm notice ...", "npm warn ...") can share stdout with the JSON.
|
|
122
|
+
const text = (r.stdout ?? "")
|
|
123
|
+
.split("\n")
|
|
124
|
+
.filter((l) => !/^npm (notice|warn|WARN)\b/.test(l))
|
|
125
|
+
.join("\n")
|
|
126
|
+
.trim();
|
|
127
|
+
if (text === "")
|
|
128
|
+
return [];
|
|
129
|
+
try {
|
|
130
|
+
const parsed = JSON.parse(text);
|
|
131
|
+
return (Array.isArray(parsed) ? parsed : [parsed]).filter((v) => typeof v === "string");
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
throw new TrainCutError("train-registry-unreadable", `npm view ${name} versions printed something that is not JSON`);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** Every version the member at `memberDir` has anywhere (#5154): ledger labels, release tags, legacy tags, package versions at the commit, registry versions. */
|
|
139
|
+
export async function memberVersions(s) {
|
|
140
|
+
const out = [];
|
|
141
|
+
const { cuts } = await readCuts({ cwd: s.memberDir });
|
|
142
|
+
for (const c of cuts)
|
|
143
|
+
if (c.label !== null)
|
|
144
|
+
out.push(c.label);
|
|
145
|
+
// Its own release tags, as release.tag (or the default) renders them.
|
|
146
|
+
const { memberTags, tagShape } = await import("../lifecycle/release-tag.js");
|
|
147
|
+
const { loadChantConfig } = await import("../config.js");
|
|
148
|
+
const config = (await loadChantConfig(s.memberDir)).config;
|
|
149
|
+
const tags = await memberTags(s.memberDir, { config: config.release?.tag, top: s.top });
|
|
150
|
+
try {
|
|
151
|
+
const shape = tagShape(tags.template.name, tags.place);
|
|
152
|
+
for (const t of (tryGit(s.top, ["tag", "-l", `${shape.prefix}*${shape.suffix}`]) ?? "").split("\n").filter(Boolean)) {
|
|
153
|
+
if (!t.startsWith(shape.prefix) || !t.endsWith(shape.suffix))
|
|
154
|
+
continue;
|
|
155
|
+
const v = t.slice(shape.prefix.length, t.length - shape.suffix.length);
|
|
156
|
+
if (parseVersion(v))
|
|
157
|
+
out.push(v);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// A template with no version in it has no versions to read.
|
|
162
|
+
}
|
|
163
|
+
// Tags of releases cut before the member had a ledger.
|
|
164
|
+
const { memberReleaseSettings } = await import("./release-changed.js");
|
|
165
|
+
for (const prefix of (await memberReleaseSettings(s.memberDir)).legacyTags) {
|
|
166
|
+
for (const t of (tryGit(s.top, ["tag", "-l", `${prefix}*`]) ?? "").split("\n").filter(Boolean)) {
|
|
167
|
+
const v = t.slice(prefix.length);
|
|
168
|
+
if (/^v?\d+\.\d+\.\d+$/.test(v))
|
|
169
|
+
out.push(v);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// The packages it stamps and publishes: their committed versions, and what the registry holds.
|
|
173
|
+
const names = new Map();
|
|
174
|
+
const readName = (dir) => {
|
|
175
|
+
const file = resolve(s.memberDir, dir, "package.json");
|
|
176
|
+
const rel = relative(realpathSync(s.top), resolve(realpathSync(s.memberDir), dir)).split(sep).join("/");
|
|
177
|
+
const committed = rel.startsWith("..") ? null : tryGit(s.top, ["show", `${s.commit}:${rel ? `${rel}/` : ""}package.json`]);
|
|
178
|
+
const text = committed ?? (existsSync(file) ? readFileSync(file, "utf-8") : null);
|
|
179
|
+
if (text === null)
|
|
180
|
+
return null;
|
|
181
|
+
try {
|
|
182
|
+
const pkg = JSON.parse(text);
|
|
183
|
+
if (typeof pkg.version === "string")
|
|
184
|
+
out.push(pkg.version);
|
|
185
|
+
return typeof pkg.name === "string" && pkg.private !== true ? pkg.name : null;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
for (const p of config.release?.version?.packages ?? []) {
|
|
192
|
+
const name = readName(p);
|
|
193
|
+
if (name && !names.has(name))
|
|
194
|
+
names.set(name, undefined);
|
|
195
|
+
}
|
|
196
|
+
for (const t of config.release?.publish ?? []) {
|
|
197
|
+
if (t.type !== "npm")
|
|
198
|
+
continue;
|
|
199
|
+
const npm = t;
|
|
200
|
+
for (const p of npm.packages ?? []) {
|
|
201
|
+
if (!existsSync(resolve(s.memberDir, p, "package.json")))
|
|
202
|
+
continue;
|
|
203
|
+
const name = readName(p);
|
|
204
|
+
if (name)
|
|
205
|
+
names.set(name, npm.registry);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
for (const [name, registry] of names)
|
|
209
|
+
out.push(...(s.registry(name, registry) ?? []));
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
/** The members of the workspace root at `root`, with their directories. */
|
|
213
|
+
function chantMembers(root) {
|
|
214
|
+
const located = locateWorkspace(root);
|
|
215
|
+
return readDeclaration(located.tree, "", { rootChant: true })
|
|
216
|
+
.members.filter((m) => m.kind === "chant" && m.dir !== ".")
|
|
217
|
+
.map((m) => ({ name: m.name, dir: m.dir }));
|
|
218
|
+
}
|
|
219
|
+
/** The release config of the workspace root, with `release.train` checked. */
|
|
220
|
+
export async function trainConfigAt(root, env) {
|
|
221
|
+
const { loadChantConfig } = await import("../config.js");
|
|
222
|
+
let train;
|
|
223
|
+
try {
|
|
224
|
+
train = (await loadChantConfig(root)).config.release?.train;
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
throw new TrainCutError("train-config-unreadable", `the workspace root's chant.config.ts could not be read: ${err instanceof Error ? err.message : String(err)}`);
|
|
228
|
+
}
|
|
229
|
+
if (!train)
|
|
230
|
+
throw new TrainCutError("train-not-declared", "the workspace root's chant.config.ts declares no release.train", 'Declare the train: release: { train: { env: "npm" } }.');
|
|
231
|
+
if (train.env !== env)
|
|
232
|
+
throw new TrainCutError("train-env-mismatch", `release.train records trains for ${train.env}, not ${env}`, `Run chant workspace train cut ${train.env}.`);
|
|
233
|
+
return train;
|
|
234
|
+
}
|
|
235
|
+
/** Plan a train: the commit, the members and their labels (#5154). Writes nothing. */
|
|
236
|
+
export async function planTrainCut(q) {
|
|
237
|
+
const located = locateWorkspace(q.cwd);
|
|
238
|
+
const root = located.rootOnDisk;
|
|
239
|
+
const top = tryGit(root, ["rev-parse", "--show-toplevel"]);
|
|
240
|
+
if (!top)
|
|
241
|
+
throw new TrainCutError("not-a-git-repository", "a train is cut from a commit, and this directory is not in a git repository");
|
|
242
|
+
const config = await trainConfigAt(root, q.env);
|
|
243
|
+
const levels = q.levels ?? { members: {} };
|
|
244
|
+
const members = chantMembers(root);
|
|
245
|
+
if (members.length === 0)
|
|
246
|
+
throw new TrainCutError("train-no-members", "the workspace declares no chant member to release", "Declare one member per releasable unit in chant.workspace.json.");
|
|
247
|
+
for (const m of Object.keys(levels.members)) {
|
|
248
|
+
if (!members.some((x) => x.name === m))
|
|
249
|
+
throw new TrainCutError("train-levels-invalid", `--levels names ${m}, which is not a chant member of this workspace (${members.map((x) => x.name).join(", ")})`);
|
|
250
|
+
}
|
|
251
|
+
const { releaseChangedDocument } = await import("./release-changed.js");
|
|
252
|
+
const flags = members.flatMap((m) => {
|
|
253
|
+
const level = levels.members[m.name] ?? levels.all;
|
|
254
|
+
return level ? [`${m.name}=${level}`] : [];
|
|
255
|
+
});
|
|
256
|
+
const changed = await releaseChangedDocument({ cwd: root, ...(q.at !== undefined ? { at: q.at } : {}), bump: flags });
|
|
257
|
+
if ("error" in changed)
|
|
258
|
+
throw new TrainCutError(changed.error.code, changed.error.message);
|
|
259
|
+
const commit = changed.at;
|
|
260
|
+
const released = (tryGit(top, ["tag", "--points-at", commit, "-l", `release-train/${q.env}/*`]) ?? "").split("\n").filter(Boolean)[0] ?? null;
|
|
261
|
+
if (released)
|
|
262
|
+
return { env: q.env, commit, first: false, released, members: [] };
|
|
263
|
+
const registry = q.registry ?? npmVersions();
|
|
264
|
+
const dirOf = (name) => members.find((m) => m.name === name).dir;
|
|
265
|
+
// Each member's releases, newest first, to find one already cut from this commit.
|
|
266
|
+
const releases = new Map((await readMemberReleases(root)).map((m) => [m.member, m.releases]));
|
|
267
|
+
const cutAt = async (name) => (releases.get(name) ?? []).find((r) => r.commit === commit && r.label !== null)?.label ?? null;
|
|
268
|
+
const floorOf = async (name) => highestVersion(await memberVersions({ top, commit, memberDir: resolve(root, dirOf(name)), registry }));
|
|
269
|
+
const vPrefix = (m) => ((m?.next ?? m?.last?.label ?? "").startsWith("v") ? "v" : "");
|
|
270
|
+
const { records } = await readReleaseTrains(root, q.env);
|
|
271
|
+
const together = records.length === 0 && config.first === "together";
|
|
272
|
+
const out = [];
|
|
273
|
+
if (together) {
|
|
274
|
+
if (Object.keys(levels.members).length > 0)
|
|
275
|
+
throw new TrainCutError("train-levels-invalid", "the first train cuts every member at one label, so it takes one level for all of them, not one per member");
|
|
276
|
+
let label = null;
|
|
277
|
+
for (const m of members) {
|
|
278
|
+
const l = await cutAt(m.name);
|
|
279
|
+
if (l !== null)
|
|
280
|
+
label = highestVersion([...(label ? [label] : []), l]);
|
|
281
|
+
}
|
|
282
|
+
const floors = new Map();
|
|
283
|
+
for (const m of members)
|
|
284
|
+
floors.set(m.name, await floorOf(m.name));
|
|
285
|
+
if (label === null) {
|
|
286
|
+
// The root member's own ledger: labels it spent before the members had their own.
|
|
287
|
+
const own = (await readCuts({ cwd: root })).cuts.map((c) => c.label).filter((l) => l !== null);
|
|
288
|
+
const highest = highestVersion([...[...floors.values()].filter((v) => v !== null), ...own]) ?? "0.0.0";
|
|
289
|
+
label = bumpLabel(highest, levels.all ?? "patch");
|
|
290
|
+
}
|
|
291
|
+
const order = [...changed.members.map((m) => m.member), ...members.map((m) => m.name)].filter((n, i, a) => a.indexOf(n) === i);
|
|
292
|
+
for (const name of order)
|
|
293
|
+
out.push({ member: name, dir: dirOf(name), label, why: "first-train", bump: levels.all ?? "patch", bumpFrom: "first-train", floor: floors.get(name) ?? null, resumed: (await cutAt(name)) === label });
|
|
294
|
+
return { env: q.env, commit, first: true, released: null, members: out };
|
|
295
|
+
}
|
|
296
|
+
for (const m of changed.members) {
|
|
297
|
+
const resumed = await cutAt(m.member);
|
|
298
|
+
const floor = await floorOf(m.member);
|
|
299
|
+
const why = m.reason.member !== null ? `${m.reason.code} ${m.reason.member}` : m.reason.code;
|
|
300
|
+
if (resumed !== null) {
|
|
301
|
+
out.push({ member: m.member, dir: dirOf(m.member), label: resumed, why, bump: null, bumpFrom: "already-cut", floor, resumed: true });
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
const fromFloor = bumpLabel(floor ?? "0.0.0", m.bump);
|
|
305
|
+
const label = `${vPrefix(m)}${highestVersion([fromFloor, ...(m.next ? [m.next] : [])])}`;
|
|
306
|
+
out.push({ member: m.member, dir: dirOf(m.member), label, why, bump: m.bump, bumpFrom: m.bumpFrom === "flag" ? "typed" : m.bumpFrom, floor, resumed: false });
|
|
307
|
+
}
|
|
308
|
+
// A run that stopped after some cuts and before its train tag: those members have no change since, so release changed leaves them out.
|
|
309
|
+
for (const m of members) {
|
|
310
|
+
if (out.some((x) => x.member === m.name))
|
|
311
|
+
continue;
|
|
312
|
+
const resumed = await cutAt(m.name);
|
|
313
|
+
if (resumed !== null)
|
|
314
|
+
out.push({ member: m.name, dir: m.dir, label: resumed, why: "already-cut", bump: null, bumpFrom: "already-cut", floor: null, resumed: true });
|
|
315
|
+
}
|
|
316
|
+
return { env: q.env, commit, first: false, released: null, members: out };
|
|
317
|
+
}
|
|
318
|
+
/** The chant this process runs, as a command line. */
|
|
319
|
+
function ownChant() {
|
|
320
|
+
return [process.execPath, ...process.execArgv, process.argv[1]];
|
|
321
|
+
}
|
|
322
|
+
/** The default {@link MemberCutter}: this chant's `release cut` in the member's directory. */
|
|
323
|
+
export const spawnMemberCut = async (m, commit, o) => {
|
|
324
|
+
const [bin, ...pre] = ownChant();
|
|
325
|
+
const args = [...pre, "release", "cut", m.label, "--at", commit, ...(o.yes ? ["--yes", "--json"] : [])];
|
|
326
|
+
const r = spawnSync(bin, args, { cwd: resolve(o.root, m.dir), encoding: "utf-8", stdio: ["ignore", "pipe", o.yes ? "pipe" : "inherit"], maxBuffer: 256 * 1024 * 1024 });
|
|
327
|
+
if (r.status !== 0) {
|
|
328
|
+
const why = `${r.stderr ?? ""}`.trim().split("\n").filter(Boolean).slice(-3).join(" ");
|
|
329
|
+
throw new TrainCutError("train-cut-failed", `the cut of ${m.member} at ${m.label} failed${why ? `: ${why}` : ""}`, "Fix the cause and run the train again: members already cut from this commit are taken as they are.");
|
|
330
|
+
}
|
|
331
|
+
if (!o.yes) {
|
|
332
|
+
if (r.stdout)
|
|
333
|
+
process.stderr.write(r.stdout);
|
|
334
|
+
return { tag: null };
|
|
335
|
+
}
|
|
336
|
+
try {
|
|
337
|
+
const doc = JSON.parse(r.stdout);
|
|
338
|
+
return { tag: doc.tag?.name ?? null };
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
throw new TrainCutError("train-cut-failed", `the cut of ${m.member} printed no JSON`);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
const defaultCheck = (line, o) => spawnSync("sh", ["-c", line], { cwd: o.cwd, env: o.env, stdio: ["ignore", "inherit", "inherit"] }).status ?? 1;
|
|
345
|
+
/** Plan, and with `yes` cut, record, tag and push, a release train (#5154). */
|
|
346
|
+
export async function cutTrain(q) {
|
|
347
|
+
const root = locateWorkspace(q.cwd).rootOnDisk;
|
|
348
|
+
const plan = await planTrainCut(q);
|
|
349
|
+
const say = q.say ?? (() => undefined);
|
|
350
|
+
const base = { ...plan, tags: {}, train: null, trainTag: null, pushed: false };
|
|
351
|
+
if (plan.released !== null || plan.members.length === 0)
|
|
352
|
+
return base;
|
|
353
|
+
const top = git(root, ["rev-parse", "--show-toplevel"]);
|
|
354
|
+
const config = await trainConfigAt(root, q.env);
|
|
355
|
+
if (q.yes && (config.check ?? []).length > 0) {
|
|
356
|
+
const file = join(mkdtempSync(join(tmpdir(), "chant-train-")), "plan.json");
|
|
357
|
+
writeFileSync(file, `${JSON.stringify({ env: plan.env, commit: plan.commit, members: plan.members.map((m) => ({ member: m.member, label: m.label })) }, null, 2)}\n`);
|
|
358
|
+
const env = { ...process.env, CHANT_RELEASE_COMMIT: plan.commit, CHANT_TRAIN_ENV: plan.env, CHANT_TRAIN_PLAN: file };
|
|
359
|
+
for (const line of config.check ?? []) {
|
|
360
|
+
say(`check: ${line}`);
|
|
361
|
+
const code = (q.runCheck ?? defaultCheck)(line, { cwd: root, env });
|
|
362
|
+
if (code !== 0)
|
|
363
|
+
throw new TrainCutError("train-check-failed", `release.train.check failed (exit ${code}): ${line}`, "Nothing was cut. Fix what the check reports and run the train again.");
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const cutter = q.cutter ?? spawnMemberCut;
|
|
367
|
+
const tags = {};
|
|
368
|
+
for (const m of plan.members) {
|
|
369
|
+
say(`${q.yes ? "cut" : "plan"} ${m.member} ${m.label}${m.resumed ? " (already cut from this commit)" : ""}`);
|
|
370
|
+
const r = await cutter(m, plan.commit, { root, yes: q.yes === true });
|
|
371
|
+
if (r.tag)
|
|
372
|
+
tags[m.member] = r.tag;
|
|
373
|
+
}
|
|
374
|
+
if (!q.yes)
|
|
375
|
+
return { ...base, tags };
|
|
376
|
+
// The train: these members at the releases just cut, the rest at their newest.
|
|
377
|
+
const pins = new Map(plan.members.map((m) => [m.member, m.label]));
|
|
378
|
+
const picked = pickTrain(await readMemberReleases(root), pins);
|
|
379
|
+
if ("problems" in picked)
|
|
380
|
+
throw new TrainCutError("train-member-unreleased", `the members were cut, and the train can't be recorded: ${picked.problems.join("; ")}`, "Cut a release of each member listed, then run the train again.");
|
|
381
|
+
const record = {
|
|
382
|
+
version: 1,
|
|
383
|
+
id: `train-${randomUUID()}`,
|
|
384
|
+
env: q.env,
|
|
385
|
+
timestamp: (q.now ?? (() => new Date()))().toISOString(),
|
|
386
|
+
actor: q.actor ?? (await import("../actor.js")).actorFromEnv(),
|
|
387
|
+
members: picked.members,
|
|
388
|
+
trainDigest: trainDigest(picked.members),
|
|
389
|
+
};
|
|
390
|
+
await appendReleaseTrain(root, record);
|
|
391
|
+
const trainTag = `release-train/${q.env}/${record.id}`;
|
|
392
|
+
git(top, ["tag", trainTag, plan.commit]);
|
|
393
|
+
const out = { ...base, tags, train: { id: record.id, trainDigest: record.trainDigest }, trainTag };
|
|
394
|
+
if (q.noPush)
|
|
395
|
+
return out;
|
|
396
|
+
// The record must be on the remote before the tag that starts the publish.
|
|
397
|
+
const { pushLifecycleRebasing } = await import("../lifecycle/git.js");
|
|
398
|
+
try {
|
|
399
|
+
const pushed = await pushLifecycleRebasing({ cwd: root, requireLanded: true });
|
|
400
|
+
if (pushed.pushWarning)
|
|
401
|
+
out.pushWarning = pushed.pushWarning;
|
|
402
|
+
}
|
|
403
|
+
catch (err) {
|
|
404
|
+
throw new TrainCutError("train-record-not-pushed", `the train ${record.id} was recorded and its record did not reach the remote, so no tag was pushed: ${err instanceof Error ? err.message : String(err)}`, "Run the train again once the remote takes pushes to chant/lifecycle: the members are cut and are taken as they are.");
|
|
405
|
+
}
|
|
406
|
+
const refs = [...Object.values(tags), trainTag].map((t) => `refs/tags/${t}`);
|
|
407
|
+
try {
|
|
408
|
+
git(top, ["push", "--atomic", q.remote ?? "origin", ...refs]);
|
|
409
|
+
}
|
|
410
|
+
catch (err) {
|
|
411
|
+
throw new TrainCutError("train-tags-not-pushed", `the train ${record.id} was recorded, and pushing its tags failed: ${err instanceof Error ? err.stderr?.toString().trim() || err.message : String(err)}`, `Push them by hand: git push --atomic ${q.remote ?? "origin"} ${refs.join(" ")}`);
|
|
412
|
+
}
|
|
413
|
+
return { ...out, pushed: true };
|
|
414
|
+
}
|
|
415
|
+
const CUT_USAGE = "chant workspace train cut <env> [--at <sha>] [--levels <levels>] [--yes] [--no-push] [--json]";
|
|
416
|
+
/** `chant workspace train cut <env>` (#5154). */
|
|
417
|
+
export async function runTrainCut(ctx, words) {
|
|
418
|
+
const { formatError, formatSuccess, formatWarning } = await import("../cli/format.js");
|
|
419
|
+
const { WorkspaceReadError } = await import("./declaration.js");
|
|
420
|
+
const { args } = ctx;
|
|
421
|
+
const env = words[0];
|
|
422
|
+
if (!env || words.length > 1) {
|
|
423
|
+
console.error(formatError({ message: env ? `chant workspace train cut takes one environment, not ${words.join(" ")}` : "chant workspace train cut needs an environment", hint: CUT_USAGE }));
|
|
424
|
+
return 1;
|
|
425
|
+
}
|
|
426
|
+
const json = args.json === true;
|
|
427
|
+
const cwd = resolve(".");
|
|
428
|
+
// The ledger and the tags the floors read, as the remote has them. Offline, what is here is read.
|
|
429
|
+
const { fetchLifecycle } = await import("../lifecycle/git.js");
|
|
430
|
+
await fetchLifecycle({ cwd }).catch(() => false);
|
|
431
|
+
spawnSync("git", ["fetch", "--quiet", "origin", "refs/tags/*:refs/tags/*"], { cwd, stdio: "ignore" });
|
|
432
|
+
let outcome;
|
|
433
|
+
try {
|
|
434
|
+
outcome = await cutTrain({
|
|
435
|
+
cwd,
|
|
436
|
+
env,
|
|
437
|
+
...(args.at ? { at: args.at } : {}),
|
|
438
|
+
levels: parseTrainLevels(args.levels),
|
|
439
|
+
yes: args.yes === true,
|
|
440
|
+
noPush: args.noPush === true,
|
|
441
|
+
...(args.actor ? { actor: args.actor } : {}),
|
|
442
|
+
say: (line) => (json ? undefined : console.error(line)),
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
catch (err) {
|
|
446
|
+
if (err instanceof TrainCutError) {
|
|
447
|
+
if (json)
|
|
448
|
+
console.log(JSON.stringify({ status: "refused", code: err.code, message: err.message }, null, 2));
|
|
449
|
+
console.error(formatError({ message: `${err.message} [${err.code}]`, hint: err.fix ?? CUT_USAGE }));
|
|
450
|
+
return 1;
|
|
451
|
+
}
|
|
452
|
+
if (err instanceof WorkspaceReadError) {
|
|
453
|
+
console.error(formatError({ message: `${err.code}: ${err.describe()}`, hint: CUT_USAGE }));
|
|
454
|
+
return 1;
|
|
455
|
+
}
|
|
456
|
+
throw err;
|
|
457
|
+
}
|
|
458
|
+
if (json) {
|
|
459
|
+
console.log(JSON.stringify({ dryRun: args.yes !== true, ...outcome }, null, 2));
|
|
460
|
+
return 0;
|
|
461
|
+
}
|
|
462
|
+
const short = outcome.commit.slice(0, 12);
|
|
463
|
+
if (outcome.released) {
|
|
464
|
+
console.log(`${short} is already released as ${outcome.released}.`);
|
|
465
|
+
return 0;
|
|
466
|
+
}
|
|
467
|
+
if (outcome.members.length === 0) {
|
|
468
|
+
console.log(`Nothing to release at ${short}: no member changed since its last release.`);
|
|
469
|
+
return 0;
|
|
470
|
+
}
|
|
471
|
+
console.log(`Release train for ${env} from ${short}${outcome.first ? " (the first: every member at one label)" : ""}:`);
|
|
472
|
+
for (const m of outcome.members)
|
|
473
|
+
console.log(` ${m.member.padEnd(24)} ${m.label.padEnd(12)} ${m.why}${m.bump ? `; ${m.bump} from ${m.bumpFrom}` : ""}${m.floor ? `; floor ${m.floor}` : ""}`);
|
|
474
|
+
if (args.yes !== true) {
|
|
475
|
+
console.error("Dry run: nothing was cut, recorded, tagged or pushed. Run again with --yes to cut the train.");
|
|
476
|
+
return 0;
|
|
477
|
+
}
|
|
478
|
+
if (outcome.pushWarning)
|
|
479
|
+
console.error(formatWarning({ message: outcome.pushWarning }));
|
|
480
|
+
console.error(formatSuccess(`Cut release train ${outcome.train.id} (${outcome.members.length} member(s))${outcome.pushed ? `, and pushed ${outcome.trainTag} with the member tags` : `; tagged ${outcome.trainTag} here, and pushed nothing`}`));
|
|
481
|
+
return 0;
|
|
482
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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. The
|
|
18
|
+
* command is `release.train.buildDependencies`, else the package's
|
|
19
|
+
* `prepack` script, else its `build` script.
|
|
20
|
+
*
|
|
21
|
+
* A workspace package here is one a `chant` member of the train's workspace
|
|
22
|
+
* names in its `release.version.packages` or as a directory of an `npm`
|
|
23
|
+
* target; its dependencies are its `dependencies`, `peerDependencies` and
|
|
24
|
+
* `optionalDependencies` that name another such package.
|
|
25
|
+
*/
|
|
26
|
+
import { type ReadTrain } from "./release-train.js";
|
|
27
|
+
export interface TrainPrepareQuery {
|
|
28
|
+
cwd: string;
|
|
29
|
+
env: string;
|
|
30
|
+
/** The train by id or digest; the newest for `env` when absent. */
|
|
31
|
+
train?: string;
|
|
32
|
+
/** Runs one build command in a package directory and returns its exit code. Default: `sh -c`. */
|
|
33
|
+
run?: (command: string, cwd: string) => number;
|
|
34
|
+
say?: (line: string) => void;
|
|
35
|
+
}
|
|
36
|
+
export interface TrainPrepareOutcome {
|
|
37
|
+
train: ReadTrain;
|
|
38
|
+
/** Each member stamped here, with its label and the files stamped (relative to the member). */
|
|
39
|
+
stamped: Array<{
|
|
40
|
+
member: string;
|
|
41
|
+
label: string;
|
|
42
|
+
files: string[];
|
|
43
|
+
}>;
|
|
44
|
+
/** The package directories built, from the workspace root, in the order they were built. */
|
|
45
|
+
built: Array<{
|
|
46
|
+
dir: string;
|
|
47
|
+
command: string;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
/** Stamp and build what the train's members cut from this commit need before `train publish` (#5154). */
|
|
51
|
+
export declare function prepareTrain(q: TrainPrepareQuery): Promise<TrainPrepareOutcome>;
|
|
52
|
+
/**
|
|
53
|
+
* The package directories the repository's root declares as workspaces:
|
|
54
|
+
* `workspaces` in its package.json (an array, or `{ packages }` as yarn
|
|
55
|
+
* writes it) and `packages:` in pnpm-workspace.yaml. A pattern is matched
|
|
56
|
+
* against directories up to four levels deep, leaving out node_modules and
|
|
57
|
+
* dot directories; a `!` pattern excludes.
|
|
58
|
+
*/
|
|
59
|
+
export declare function workspacePackageDirs(top: string): string[];
|
|
60
|
+
/** `chant workspace train prepare <env> [<train>]` (#5154). */
|
|
61
|
+
export declare function runTrainPrepare(ctx: import("../cli/registry.js").CommandContext, words: string[]): Promise<number>;
|