@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,625 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `release-changed` read (#5134, design #5132 decisions 3 and 4): the
|
|
3
|
+
* members of a workspace whose members release separately, that a release at
|
|
4
|
+
* one commit has to cut, in the order to publish them.
|
|
5
|
+
*
|
|
6
|
+
* `chant release changed [--at <sha>] [--bump-member <member>=<level>]... [--json]`
|
|
7
|
+
* prints this document. It runs in the root of the workspace whose `chant`
|
|
8
|
+
* members are the releasable units (the nested `release/` workspace of a
|
|
9
|
+
* repository that publishes many packages), reads local refs and tags only,
|
|
10
|
+
* and never fetches.
|
|
11
|
+
*
|
|
12
|
+
* For each `chant` member it finds the commit of its last release: the newest
|
|
13
|
+
* cut in the member's ledger, else the newest legacy tag, one of the
|
|
14
|
+
* `release.legacyTags` prefixes of the root's `chant.config.ts` or the
|
|
15
|
+
* member's own followed by a version (`release/npm/0.124.44`,
|
|
16
|
+
* `chant-v0.124.44`). It then lists the
|
|
17
|
+
* paths changed from there to the commit, takes the outer member that holds
|
|
18
|
+
* each (`memberHolding`, the outermost workspace's members, one of which has
|
|
19
|
+
* the member's own name), and drops the paths `changes.ignore` matches and
|
|
20
|
+
* the generated files. A member with paths left, or with no release yet, is
|
|
21
|
+
* `changed`.
|
|
22
|
+
*
|
|
23
|
+
* The closure then runs to a fixed point:
|
|
24
|
+
*
|
|
25
|
+
* - upward: a member of the release also releases each workspace dependency
|
|
26
|
+
* of it, direct or transitive, that is `changed` (`needed-by <member>`; a
|
|
27
|
+
* changed member no other member needs keeps `paths-changed`).
|
|
28
|
+
* Dependencies are the `dependencies`, `peerDependencies` and
|
|
29
|
+
* `optionalDependencies` of the member's package.json at the commit, as
|
|
30
|
+
* `publish_layers` reads them.
|
|
31
|
+
* - downward: a dependent the release does not already take is added when
|
|
32
|
+
* the range its last release's package.json gives a dependency does not
|
|
33
|
+
* admit that dependency's next label (`range-broken-by <member>`). The next
|
|
34
|
+
* label is the last label bumped by `--bump-member` (default patch).
|
|
35
|
+
*
|
|
36
|
+
* Members come in dependency layers, each layer sorted by name.
|
|
37
|
+
*/
|
|
38
|
+
import { execFileSync } from "node:child_process";
|
|
39
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
40
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
41
|
+
// @ts-ignore — picomatch has no types declaration
|
|
42
|
+
import picomatch from "picomatch";
|
|
43
|
+
import { findWorkspaceRoot } from "../project-root.js";
|
|
44
|
+
import { readAllReleases, readCuts } from "../lifecycle/release-store.js";
|
|
45
|
+
import { resolveMemberLedger } from "../lifecycle/member-ledger.js";
|
|
46
|
+
import { readDeclaration, readerVersion } from "./declaration.js";
|
|
47
|
+
import { isGeneratedPath } from "./generated-files.js";
|
|
48
|
+
import { memberHolding } from "./record-assets.js";
|
|
49
|
+
import { workingTree } from "./tree.js";
|
|
50
|
+
import { changelogBump } from "../lifecycle/release-changelog.js";
|
|
51
|
+
export const RELEASE_CHANGED_CONTRACT_VERSION = 1;
|
|
52
|
+
export const RELEASE_CHANGED_SCHEMA_ID = "https://intentius.io/chant/schemas/workspace/release-changed/v1/release-changed.schema.json";
|
|
53
|
+
/** Why the read stopped. Closed; each code is in `reason-codes.ts`. */
|
|
54
|
+
export const RELEASE_CHANGED_ERROR_CODES = ["not-a-git-repository", "declaration-missing", "revision-unknown", "bump-invalid", "ledger-unreadable", "intent-invalid"];
|
|
55
|
+
/** Why a member is in the release. Closed; each code is in `reason-codes.ts`. */
|
|
56
|
+
export const RELEASE_CHANGED_REASON_CODES = ["paths-changed", "needed-by", "range-broken-by", "intent-pending"];
|
|
57
|
+
export const RELEASE_BUMPS = ["major", "minor", "patch"];
|
|
58
|
+
class ReadFailure extends Error {
|
|
59
|
+
constructor(code, message) {
|
|
60
|
+
super(message);
|
|
61
|
+
this.code = code;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function git(top, args) {
|
|
65
|
+
return execFileSync("git", args, { cwd: top, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 256 * 1024 * 1024 }).trim();
|
|
66
|
+
}
|
|
67
|
+
function tryGit(top, args) {
|
|
68
|
+
try {
|
|
69
|
+
return git(top, args);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
76
|
+
/** `1.2.3` (a leading `v` allowed) as numbers, or null. */
|
|
77
|
+
export function parseVersion(text) {
|
|
78
|
+
const m = VERSION.exec(text.trim());
|
|
79
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
80
|
+
}
|
|
81
|
+
const compare = (a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
82
|
+
/** The label `bump` makes of `label`, or null when `label` is not a version. */
|
|
83
|
+
export function bumpLabel(label, bump) {
|
|
84
|
+
const v = parseVersion(label);
|
|
85
|
+
if (!v)
|
|
86
|
+
return null;
|
|
87
|
+
if (bump === "major")
|
|
88
|
+
return `${v[0] + 1}.0.0`;
|
|
89
|
+
if (bump === "minor")
|
|
90
|
+
return `${v[0]}.${v[1] + 1}.0`;
|
|
91
|
+
return `${v[0]}.${v[1]}.${v[2] + 1}`;
|
|
92
|
+
}
|
|
93
|
+
/** The version a partial like `1`, `1.2` or `1.x` stands for, with the position of its first wildcard. */
|
|
94
|
+
function partial(text) {
|
|
95
|
+
const parts = text.replace(/^v/, "").split(/[-+]/)[0].split(".");
|
|
96
|
+
if (parts.length === 0 || parts.length > 3)
|
|
97
|
+
return null;
|
|
98
|
+
const nums = [];
|
|
99
|
+
let given = 0;
|
|
100
|
+
for (const p of parts) {
|
|
101
|
+
if (/^[xX*]$/.test(p) || p === "")
|
|
102
|
+
break;
|
|
103
|
+
if (!/^\d+$/.test(p))
|
|
104
|
+
return null;
|
|
105
|
+
nums.push(Number(p));
|
|
106
|
+
given++;
|
|
107
|
+
}
|
|
108
|
+
while (nums.length < 3)
|
|
109
|
+
nums.push(0);
|
|
110
|
+
return { v: [nums[0], nums[1], nums[2]], given };
|
|
111
|
+
}
|
|
112
|
+
/** Whether one space-separated comparator set admits `v`. Null when it is not a range chant reads. */
|
|
113
|
+
function setAdmits(set, v) {
|
|
114
|
+
const tokens = set
|
|
115
|
+
.replace(/(>=|<=|>|<|=|\^|~)\s+/g, "$1")
|
|
116
|
+
.split(/\s+/)
|
|
117
|
+
.filter(Boolean);
|
|
118
|
+
if (tokens.length === 0)
|
|
119
|
+
return true;
|
|
120
|
+
for (const token of tokens) {
|
|
121
|
+
const m = /^(>=|<=|>|<|=|\^|~)?(.*)$/.exec(token);
|
|
122
|
+
const op = m[1] ?? "";
|
|
123
|
+
const p = partial(m[2]);
|
|
124
|
+
if (!p)
|
|
125
|
+
return null;
|
|
126
|
+
const lo = p.v;
|
|
127
|
+
let ok;
|
|
128
|
+
if (op === "^") {
|
|
129
|
+
// ^1.2.3 is <2.0.0; ^0.2.3 is <0.3.0; ^0.0.3 is <0.0.4.
|
|
130
|
+
let hi;
|
|
131
|
+
if (lo[0] > 0 || p.given <= 1)
|
|
132
|
+
hi = [lo[0] + 1, 0, 0];
|
|
133
|
+
else if (lo[1] > 0 || p.given <= 2)
|
|
134
|
+
hi = [0, lo[1] + 1, 0];
|
|
135
|
+
else
|
|
136
|
+
hi = [0, 0, lo[2] + 1];
|
|
137
|
+
ok = compare(v, lo) >= 0 && compare(v, hi) < 0;
|
|
138
|
+
}
|
|
139
|
+
else if (op === "~") {
|
|
140
|
+
const hi = p.given <= 1 ? [lo[0] + 1, 0, 0] : [lo[0], lo[1] + 1, 0];
|
|
141
|
+
ok = compare(v, lo) >= 0 && compare(v, hi) < 0;
|
|
142
|
+
}
|
|
143
|
+
else if (op === ">=")
|
|
144
|
+
ok = compare(v, lo) >= 0;
|
|
145
|
+
else if (op === ">")
|
|
146
|
+
ok = p.given >= 3 ? compare(v, lo) > 0 : compare(v, [lo[0], lo[1], lo[2]]) >= 0 && !(p.given === 0) && compare(v, p.given === 1 ? [lo[0] + 1, 0, 0] : [lo[0], lo[1] + 1, 0]) >= 0;
|
|
147
|
+
else if (op === "<=")
|
|
148
|
+
ok = p.given >= 3 ? compare(v, lo) <= 0 : compare(v, p.given === 1 ? [lo[0] + 1, 0, 0] : [lo[0], lo[1] + 1, 0]) < 0;
|
|
149
|
+
else if (op === "<")
|
|
150
|
+
ok = compare(v, lo) < 0;
|
|
151
|
+
else if (p.given >= 3)
|
|
152
|
+
ok = compare(v, lo) === 0;
|
|
153
|
+
else if (p.given === 0)
|
|
154
|
+
ok = true;
|
|
155
|
+
else
|
|
156
|
+
ok = compare(v, lo) >= 0 && compare(v, p.given === 1 ? [lo[0] + 1, 0, 0] : [lo[0], lo[1] + 1, 0]) < 0;
|
|
157
|
+
if (!ok)
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Whether the npm range `range` admits `label`. A range chant does not read
|
|
164
|
+
* (`workspace:*`, a URL, a tag) admits everything: it forces no release.
|
|
165
|
+
*/
|
|
166
|
+
export function rangeAdmits(range, label) {
|
|
167
|
+
const v = parseVersion(label);
|
|
168
|
+
if (!v)
|
|
169
|
+
return true;
|
|
170
|
+
const sets = range.split("||").map((s) => s.trim());
|
|
171
|
+
let unread = false;
|
|
172
|
+
for (const set of sets) {
|
|
173
|
+
const hit = setAdmits(set, v);
|
|
174
|
+
if (hit === null)
|
|
175
|
+
unread = true;
|
|
176
|
+
else if (hit)
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return unread;
|
|
180
|
+
}
|
|
181
|
+
/** The higher of two bumps; null is lower than any. */
|
|
182
|
+
function maxBump(a, b) {
|
|
183
|
+
if (a === null)
|
|
184
|
+
return b;
|
|
185
|
+
if (b === null)
|
|
186
|
+
return a;
|
|
187
|
+
const order = ["patch", "minor", "major"];
|
|
188
|
+
return order.indexOf(a) >= order.indexOf(b) ? a : b;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The bump the conventional commits in `from..to` that touch `paths` (from
|
|
192
|
+
* the repository root) give, as `changelogBump` decides it (#5159), or null
|
|
193
|
+
* when none does. The paths go to git on its standard input, literally.
|
|
194
|
+
*/
|
|
195
|
+
function commitBumpOver(top, from, to, paths) {
|
|
196
|
+
let out;
|
|
197
|
+
try {
|
|
198
|
+
out = execFileSync("git", ["log", "--no-merges", "--format=%B%x1e", `${from}..${to}`, "--stdin"], {
|
|
199
|
+
cwd: top,
|
|
200
|
+
encoding: "utf-8",
|
|
201
|
+
input: `--\n${paths.join("\n")}\n`,
|
|
202
|
+
env: { ...process.env, GIT_LITERAL_PATHSPECS: "1" },
|
|
203
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
204
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
const messages = out.split("\x1e").map((m) => m.trim()).filter(Boolean);
|
|
211
|
+
return messages.length > 0 ? changelogBump(messages) : null;
|
|
212
|
+
}
|
|
213
|
+
function readPackage(top, rev, path) {
|
|
214
|
+
const text = tryGit(top, ["show", `${rev}:${path}`]);
|
|
215
|
+
if (text === null)
|
|
216
|
+
return { name: null, ranges: new Map() };
|
|
217
|
+
let json;
|
|
218
|
+
try {
|
|
219
|
+
json = JSON.parse(text);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return { name: null, ranges: new Map() };
|
|
223
|
+
}
|
|
224
|
+
const ranges = new Map();
|
|
225
|
+
for (const key of ["dependencies", "peerDependencies", "optionalDependencies"]) {
|
|
226
|
+
const block = json[key];
|
|
227
|
+
if (block && typeof block === "object")
|
|
228
|
+
for (const [n, r] of Object.entries(block))
|
|
229
|
+
if (typeof r === "string" && !ranges.has(n))
|
|
230
|
+
ranges.set(n, r);
|
|
231
|
+
}
|
|
232
|
+
return { name: typeof json.name === "string" ? json.name : null, ranges };
|
|
233
|
+
}
|
|
234
|
+
/** The outermost workspace root at or above `dir`. */
|
|
235
|
+
function outermostRoot(dir) {
|
|
236
|
+
let root = dir;
|
|
237
|
+
for (;;) {
|
|
238
|
+
const up = findWorkspaceRoot(dirname(root));
|
|
239
|
+
if (!up || up.dir === root)
|
|
240
|
+
return root;
|
|
241
|
+
root = up.dir;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const posix = (p) => (sep === "/" ? p : p.split(sep).join("/"));
|
|
245
|
+
/**
|
|
246
|
+
* The directory whose commits count for the member at `memberDir` (#5159):
|
|
247
|
+
* as `release changed` maps paths, the directory of the outermost
|
|
248
|
+
* workspace's member of the same name when there is one (a release member
|
|
249
|
+
* under `release/<name>` releases the package at `packages/<name>`), else
|
|
250
|
+
* the member's own directory.
|
|
251
|
+
*/
|
|
252
|
+
export function memberSourcePath(memberDir) {
|
|
253
|
+
const dir = resolve(memberDir);
|
|
254
|
+
try {
|
|
255
|
+
const found = findWorkspaceRoot(dir);
|
|
256
|
+
if (!found)
|
|
257
|
+
return dir;
|
|
258
|
+
const rootDir = realpathSync(found.dir);
|
|
259
|
+
const real = realpathSync(dir);
|
|
260
|
+
const own = readDeclaration(workingTree(rootDir)).members.find((m) => m.dir !== "." && realpathSync(join(rootDir, m.dir)) === real);
|
|
261
|
+
if (!own)
|
|
262
|
+
return dir;
|
|
263
|
+
const outerDir = realpathSync(outermostRoot(rootDir));
|
|
264
|
+
if (outerDir === rootDir)
|
|
265
|
+
return dir;
|
|
266
|
+
const outer = readDeclaration(workingTree(outerDir)).members.find((m) => m.name === own.name && m.kind !== "workspace");
|
|
267
|
+
return outer ? join(outerDir, outer.dir) : dir;
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return dir;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/** The member's last release from its ledger, or null, and its cuts. */
|
|
274
|
+
async function ledgerRelease(memberDir) {
|
|
275
|
+
const loc = { cwd: memberDir };
|
|
276
|
+
await resolveMemberLedger(memberDir);
|
|
277
|
+
const { releases } = await readAllReleases(loc);
|
|
278
|
+
const { cuts } = await readCuts(loc);
|
|
279
|
+
const commitOf = new Map(releases.map((r) => [r.releaseDigest, r.commit]));
|
|
280
|
+
let best = null;
|
|
281
|
+
for (const c of cuts) {
|
|
282
|
+
const commit = commitOf.get(c.releaseDigest);
|
|
283
|
+
if (commit === undefined)
|
|
284
|
+
continue;
|
|
285
|
+
if (!best || c.timestamp > best.at)
|
|
286
|
+
best = { at: c.timestamp, label: c.label, commit };
|
|
287
|
+
}
|
|
288
|
+
return { last: best ? { label: best.label, commit: best.commit, source: "ledger" } : null, cuts };
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* The newest tag of `shapes` that names a version, as a release, or null.
|
|
292
|
+
* The version between prefix and suffix holds no `/`: `release/npm/core/0.125.0`
|
|
293
|
+
* is a member's tag, not one of the prefix `release/`. The label drops a
|
|
294
|
+
* leading `v`, unless the shape's `render` only gives the tag back with it.
|
|
295
|
+
* With `at`, only a tag on that commit or an ancestor of it counts; with
|
|
296
|
+
* `stable`, only a version with no prerelease part; with `skip`, no
|
|
297
|
+
* version it lists (written without a leading `v`).
|
|
298
|
+
*/
|
|
299
|
+
export function tagHistoryRelease(top, shapes, opts = {}) {
|
|
300
|
+
const found = [];
|
|
301
|
+
for (const shape of shapes) {
|
|
302
|
+
const tags = tryGit(top, ["tag", "-l", `${shape.prefix}*${shape.suffix}`]) ?? "";
|
|
303
|
+
for (const tag of tags.split("\n").filter(Boolean)) {
|
|
304
|
+
if (!tag.startsWith(shape.prefix) || !tag.endsWith(shape.suffix) || tag.length <= shape.prefix.length + shape.suffix.length)
|
|
305
|
+
continue;
|
|
306
|
+
const rest = tag.slice(shape.prefix.length, tag.length - shape.suffix.length);
|
|
307
|
+
const v = parseVersion(rest);
|
|
308
|
+
if (!v || rest.includes("/") || !/^v?\d/.test(rest))
|
|
309
|
+
continue;
|
|
310
|
+
if (opts.stable && /[-+]/.test(rest))
|
|
311
|
+
continue;
|
|
312
|
+
if (opts.skip?.includes(rest.replace(/^v/, "")))
|
|
313
|
+
continue;
|
|
314
|
+
const label = [rest.replace(/^v/, ""), rest].find((l) => {
|
|
315
|
+
if (!shape.render)
|
|
316
|
+
return true;
|
|
317
|
+
try {
|
|
318
|
+
return shape.render(l) === tag;
|
|
319
|
+
}
|
|
320
|
+
catch {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
if (label !== undefined)
|
|
325
|
+
found.push({ v, label, tag });
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
found.sort((a, b) => compare(b.v, a.v));
|
|
329
|
+
for (const best of found) {
|
|
330
|
+
const commit = tryGit(top, ["rev-list", "-n", "1", best.tag]);
|
|
331
|
+
if (!commit)
|
|
332
|
+
continue;
|
|
333
|
+
if (opts.at !== undefined && commit !== opts.at && tryGit(top, ["merge-base", "--is-ancestor", commit, opts.at]) === null)
|
|
334
|
+
continue;
|
|
335
|
+
return { label: best.label, commit, source: "legacy", tag: best.tag };
|
|
336
|
+
}
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
/** The newest legacy tag of `prefixes` that names a version, as a release, or null. */
|
|
340
|
+
function legacyRelease(top, prefixes) {
|
|
341
|
+
const hit = tagHistoryRelease(top, prefixes.map((prefix) => ({ prefix, suffix: "" })));
|
|
342
|
+
return hit ? { label: hit.label, commit: hit.commit, source: hit.source } : null;
|
|
343
|
+
}
|
|
344
|
+
/** The `release` settings of the `chant.config.ts` (or `.json`) in `dir` that pick a next label; empty when it has none or can't be read. */
|
|
345
|
+
export async function releaseSettingsAt(dir) {
|
|
346
|
+
if (!existsSync(join(dir, "chant.config.ts")) && !existsSync(join(dir, "chant.config.json")))
|
|
347
|
+
return { legacyTags: [] };
|
|
348
|
+
try {
|
|
349
|
+
const { loadChantConfig } = await import("../config.js");
|
|
350
|
+
const release = (await loadChantConfig(dir)).config.release;
|
|
351
|
+
return { legacyTags: [...(release?.legacyTags ?? [])], ...(release?.breakingOnZero ? { breakingOnZero: release.breakingOnZero } : {}) };
|
|
352
|
+
}
|
|
353
|
+
catch {
|
|
354
|
+
return { legacyTags: [] };
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* The settings for the member at `memberDir` (#5200, #5191): its own
|
|
359
|
+
* `release.legacyTags` with those of the workspace root it sits in, and its
|
|
360
|
+
* own `release.breakingOnZero`, else the root's. A project with no
|
|
361
|
+
* workspace reads its own config alone.
|
|
362
|
+
*/
|
|
363
|
+
export async function memberReleaseSettings(memberDir, root) {
|
|
364
|
+
const own = await releaseSettingsAt(memberDir);
|
|
365
|
+
let outer = root;
|
|
366
|
+
if (outer === undefined) {
|
|
367
|
+
const found = findWorkspaceRoot(memberDir);
|
|
368
|
+
if (found && resolve(found.dir) !== resolve(memberDir))
|
|
369
|
+
outer = { dir: found.dir, settings: await releaseSettingsAt(found.dir) };
|
|
370
|
+
}
|
|
371
|
+
const same = outer !== undefined && realpathOr(outer.dir) === realpathOr(memberDir);
|
|
372
|
+
const rootSettings = outer && !same ? outer.settings : { legacyTags: [] };
|
|
373
|
+
return {
|
|
374
|
+
legacyTags: [...new Set([...own.legacyTags, ...rootSettings.legacyTags])],
|
|
375
|
+
breakingOnZero: own.breakingOnZero ?? rootSettings.breakingOnZero ?? "minor",
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function realpathOr(p) {
|
|
379
|
+
try {
|
|
380
|
+
return realpathSync(p);
|
|
381
|
+
}
|
|
382
|
+
catch {
|
|
383
|
+
return resolve(p);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* The bump a commit gives on the version `label` (#5191): on 0.x, unless
|
|
388
|
+
* `breakingOnZero` is `major`, a breaking change bumps minor and a feature
|
|
389
|
+
* patch, since a 0.x project moves to 1.0.0 by choice (an intent file or a
|
|
390
|
+
* typed level of `major`). Any other version, or a null bump, is as given.
|
|
391
|
+
*/
|
|
392
|
+
export function zeroShift(bump, label, breakingOnZero) {
|
|
393
|
+
if (bump === null || breakingOnZero === "major" || label === null)
|
|
394
|
+
return bump;
|
|
395
|
+
const v = parseVersion(label);
|
|
396
|
+
if (!v || v[0] !== 0)
|
|
397
|
+
return bump;
|
|
398
|
+
return bump === "major" ? "minor" : "patch";
|
|
399
|
+
}
|
|
400
|
+
/** Read what a release at a commit of the workspace at `query.cwd` has to cut. */
|
|
401
|
+
export async function releaseChangedDocument(query) {
|
|
402
|
+
const head = { $schema: RELEASE_CHANGED_SCHEMA_ID, contract: RELEASE_CHANGED_CONTRACT_VERSION, chant: readerVersion() };
|
|
403
|
+
try {
|
|
404
|
+
return { ...head, ...(await read(query)) };
|
|
405
|
+
}
|
|
406
|
+
catch (err) {
|
|
407
|
+
if (err instanceof ReadFailure)
|
|
408
|
+
return { ...head, error: { code: err.code, message: err.message } };
|
|
409
|
+
return { ...head, error: { code: "ledger-unreadable", message: `reading the changed members failed: ${err instanceof Error ? err.message : String(err)}` } };
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
async function read(query) {
|
|
413
|
+
const cwd = resolve(query.cwd);
|
|
414
|
+
const top = tryGit(cwd, ["rev-parse", "--show-toplevel"]);
|
|
415
|
+
if (!top)
|
|
416
|
+
throw new ReadFailure("not-a-git-repository", "the changed members are read from commits and tags, and this directory is not in a git repository");
|
|
417
|
+
const found = findWorkspaceRoot(cwd);
|
|
418
|
+
if (!found)
|
|
419
|
+
throw new ReadFailure("declaration-missing", "release changed reads a workspace of release members, and there is no chant.workspace.json between this directory and the git root");
|
|
420
|
+
const rootDir = realpathSync(found.dir);
|
|
421
|
+
const declaration = readDeclaration(workingTree(rootDir));
|
|
422
|
+
const outerDir = realpathSync(outermostRoot(rootDir));
|
|
423
|
+
const outer = outerDir === rootDir ? declaration : readDeclaration(workingTree(outerDir));
|
|
424
|
+
const outerFromTop = posix(relative(top, outerDir));
|
|
425
|
+
// The commit.
|
|
426
|
+
let at;
|
|
427
|
+
if (query.at !== undefined) {
|
|
428
|
+
at = tryGit(top, ["rev-parse", "--verify", "--quiet", `${query.at}^{commit}`]);
|
|
429
|
+
if (!at)
|
|
430
|
+
throw new ReadFailure("revision-unknown", `--at ${query.at} names no commit in this clone`);
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
const { resolveTrunk } = await import("../lifecycle/release-workstation.js");
|
|
434
|
+
const trunk = resolveTrunk(top, declaration.ci?.green?.branch ?? null);
|
|
435
|
+
at =
|
|
436
|
+
tryGit(top, ["rev-parse", "--verify", "--quiet", `refs/remotes/${trunk.remote}/${trunk.branch}^{commit}`]) ??
|
|
437
|
+
tryGit(top, ["rev-parse", "--verify", "--quiet", `refs/heads/${trunk.branch}^{commit}`]);
|
|
438
|
+
if (!at)
|
|
439
|
+
throw new ReadFailure("revision-unknown", `this clone knows no ${trunk.branch}; fetch it, or name a commit with --at`);
|
|
440
|
+
}
|
|
441
|
+
const members = declaration.members.filter((m) => m.kind === "chant" && m.dir !== ".").map((m) => ({ name: m.name, dir: m.dir }));
|
|
442
|
+
const names = new Set(members.map((m) => m.name));
|
|
443
|
+
const bumps = new Map();
|
|
444
|
+
for (const entry of query.bump ?? []) {
|
|
445
|
+
const [member, level, ...extra] = entry.split("=");
|
|
446
|
+
if (!member || !level || extra.length > 0 || !RELEASE_BUMPS.includes(level))
|
|
447
|
+
throw new ReadFailure("bump-invalid", `--bump-member ${entry} is not <member>=major|minor|patch`);
|
|
448
|
+
if (!names.has(member))
|
|
449
|
+
throw new ReadFailure("bump-invalid", `--bump-member names ${member}, which is not a chant member of this declaration (${[...names].sort().join(", ") || "none"})`);
|
|
450
|
+
bumps.set(member, level);
|
|
451
|
+
}
|
|
452
|
+
// #5159: the intent files at the commit, each naming members of this declaration.
|
|
453
|
+
const { readIntents, consumedIntents, pendingIntents, ReleaseIntentError } = await import("../lifecycle/release-intents.js");
|
|
454
|
+
let intentFiles;
|
|
455
|
+
try {
|
|
456
|
+
intentFiles = readIntents(top, at);
|
|
457
|
+
}
|
|
458
|
+
catch (err) {
|
|
459
|
+
if (err instanceof ReleaseIntentError)
|
|
460
|
+
throw new ReadFailure("intent-invalid", err.message);
|
|
461
|
+
throw err;
|
|
462
|
+
}
|
|
463
|
+
for (const f of intentFiles) {
|
|
464
|
+
for (const name of f.members.keys()) {
|
|
465
|
+
if (name !== "*" && !names.has(name))
|
|
466
|
+
throw new ReadFailure("intent-invalid", `the intent file ${f.path} names ${name}, which is not a chant member of this declaration (${[...names].sort().join(", ") || "none"})`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
// Each member's package, last release and the paths changed since.
|
|
470
|
+
const outerMemberOf = (name) => outer.members.find((m) => m.name === name);
|
|
471
|
+
const pkgDir = (name) => {
|
|
472
|
+
const holder = outerMemberOf(name) ?? declaration.members.find((m) => m.name === name);
|
|
473
|
+
return holder === outerMemberOf(name) ? holder.dir : posix(relative(outerDir, join(rootDir, holder.dir)));
|
|
474
|
+
};
|
|
475
|
+
const rootSettings = await releaseSettingsAt(rootDir);
|
|
476
|
+
const legacyLast = rootSettings.legacyTags.length > 0 ? legacyRelease(top, rootSettings.legacyTags) : null;
|
|
477
|
+
const ignore = (outer.changes?.ignore ?? []).map((g) => picomatch(g, { dot: true }));
|
|
478
|
+
const info = new Map();
|
|
479
|
+
for (const m of members) {
|
|
480
|
+
const dir = pkgDir(m.name);
|
|
481
|
+
const memberDir = join(rootDir, m.dir);
|
|
482
|
+
if (!existsSync(memberDir))
|
|
483
|
+
throw new ReadFailure("ledger-unreadable", `member ${m.name} has no directory ${m.dir}`);
|
|
484
|
+
const ledger = await ledgerRelease(memberDir);
|
|
485
|
+
// #5200: a member's own legacyTags count beside the root's; #5191: its breakingOnZero, else the root's.
|
|
486
|
+
const settings = await memberReleaseSettings(memberDir, { dir: rootDir, settings: rootSettings });
|
|
487
|
+
const last = ledger.last ?? (settings.legacyTags.length > rootSettings.legacyTags.length ? legacyRelease(top, settings.legacyTags) : legacyLast);
|
|
488
|
+
let paths = [];
|
|
489
|
+
if (last) {
|
|
490
|
+
if (tryGit(top, ["cat-file", "-e", `${last.commit}^{commit}`]) === null)
|
|
491
|
+
throw new ReadFailure("ledger-unreadable", `the last release of ${m.name} is at ${last.commit.slice(0, 12)}, which this clone does not have`);
|
|
492
|
+
const diff = tryGit(top, ["diff", "--name-only", "--no-renames", last.commit, at]) ?? "";
|
|
493
|
+
for (const file of diff.split("\n").filter(Boolean)) {
|
|
494
|
+
const path = outerFromTop === "." || outerFromTop === "" ? file : file.startsWith(`${outerFromTop}/`) ? file.slice(outerFromTop.length + 1) : null;
|
|
495
|
+
if (path === null)
|
|
496
|
+
continue;
|
|
497
|
+
if (memberHolding(path, outer.members) !== m.name && !(outerMemberOf(m.name) === undefined && memberHolding(path, declaration.members) === m.name))
|
|
498
|
+
continue;
|
|
499
|
+
if (ignore.some((match) => match(path)))
|
|
500
|
+
continue;
|
|
501
|
+
if (isGeneratedPath(outer, path))
|
|
502
|
+
continue;
|
|
503
|
+
paths.push(path);
|
|
504
|
+
}
|
|
505
|
+
paths = [...new Set(paths)].sort();
|
|
506
|
+
}
|
|
507
|
+
const prefix = outerFromTop === "." || outerFromTop === "" ? "" : `${outerFromTop}/`;
|
|
508
|
+
const intents = pendingIntents(intentFiles, [m.name], consumedIntents(ledger.cuts)).map((i) => ({ path: i.path, bump: i.bump }));
|
|
509
|
+
info.set(m.name, {
|
|
510
|
+
name: m.name,
|
|
511
|
+
dir,
|
|
512
|
+
pkg: readPackage(top, at, `${prefix}${dir}/package.json`),
|
|
513
|
+
last,
|
|
514
|
+
paths,
|
|
515
|
+
changed: last === null || paths.length > 0 || intents.length > 0,
|
|
516
|
+
commitBump: last && paths.length > 0 ? zeroShift(commitBumpOver(top, last.commit, at, paths.map((p) => `${prefix}${p}`)), last.label, settings.breakingOnZero) : null,
|
|
517
|
+
intents,
|
|
518
|
+
published: last ? readPackage(top, last.commit, `${prefix}${dir}/package.json`) : null,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
// Dependencies among members, by package name.
|
|
522
|
+
const memberOfPackage = new Map();
|
|
523
|
+
for (const i of info.values())
|
|
524
|
+
if (i.pkg.name)
|
|
525
|
+
memberOfPackage.set(i.pkg.name, i.name);
|
|
526
|
+
const needs = new Map();
|
|
527
|
+
for (const i of info.values())
|
|
528
|
+
needs.set(i.name, [...new Set([...i.pkg.ranges.keys()].map((n) => memberOfPackage.get(n)).filter((n) => n !== undefined && n !== i.name))].sort());
|
|
529
|
+
const nextOf = (name) => {
|
|
530
|
+
const i = info.get(name);
|
|
531
|
+
const flag = bumps.get(name);
|
|
532
|
+
const fromIntents = i.intents.reduce((b, x) => maxBump(b, x.bump), null);
|
|
533
|
+
const computed = maxBump(i.commitBump, fromIntents);
|
|
534
|
+
const bump = flag ?? computed ?? "patch";
|
|
535
|
+
const bumpFrom = flag ? "flag" : computed === null ? "default" : i.commitBump === computed ? "commits" : "intents";
|
|
536
|
+
const label = i.last?.label;
|
|
537
|
+
return { bump, bumpFrom, next: label ? bumpLabel(label, bump) : null };
|
|
538
|
+
};
|
|
539
|
+
// The closure.
|
|
540
|
+
const chosen = new Map();
|
|
541
|
+
const queue = [];
|
|
542
|
+
for (const i of [...info.values()].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
543
|
+
if (i.changed) {
|
|
544
|
+
chosen.set(i.name, { code: i.last !== null && i.paths.length === 0 ? "intent-pending" : "paths-changed", member: null });
|
|
545
|
+
queue.push(i.name);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
const take = (name, reason) => {
|
|
549
|
+
if (chosen.has(name))
|
|
550
|
+
return;
|
|
551
|
+
chosen.set(name, reason);
|
|
552
|
+
queue.push(name);
|
|
553
|
+
};
|
|
554
|
+
while (queue.length > 0) {
|
|
555
|
+
const m = queue.shift();
|
|
556
|
+
// Upward: a changed dependency, direct or through members that did not change.
|
|
557
|
+
const seen = new Set([m]);
|
|
558
|
+
const walk = [...(needs.get(m) ?? [])];
|
|
559
|
+
while (walk.length > 0) {
|
|
560
|
+
const d = walk.shift();
|
|
561
|
+
if (seen.has(d))
|
|
562
|
+
continue;
|
|
563
|
+
seen.add(d);
|
|
564
|
+
if (info.get(d).changed)
|
|
565
|
+
take(d, { code: "needed-by", member: m });
|
|
566
|
+
walk.push(...(needs.get(d) ?? []));
|
|
567
|
+
}
|
|
568
|
+
// Downward: a dependent whose published range does not admit the next label.
|
|
569
|
+
const { next } = nextOf(m);
|
|
570
|
+
if (next === null)
|
|
571
|
+
continue;
|
|
572
|
+
const pkgName = info.get(m).pkg.name;
|
|
573
|
+
if (pkgName === null)
|
|
574
|
+
continue;
|
|
575
|
+
for (const p of [...info.values()].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
576
|
+
if (chosen.has(p.name) || !(needs.get(p.name) ?? []).includes(m))
|
|
577
|
+
continue;
|
|
578
|
+
const range = p.published?.ranges.get(pkgName);
|
|
579
|
+
if (range !== undefined && !rangeAdmits(range, next))
|
|
580
|
+
take(p.name, { code: "range-broken-by", member: m });
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
// Layers: Kahn over the chosen members, with an edge for each dependency reachable through the whole graph.
|
|
584
|
+
const reach = (from) => {
|
|
585
|
+
const out = new Set();
|
|
586
|
+
const stack = [...(needs.get(from) ?? [])];
|
|
587
|
+
while (stack.length > 0) {
|
|
588
|
+
const d = stack.pop();
|
|
589
|
+
if (out.has(d))
|
|
590
|
+
continue;
|
|
591
|
+
out.add(d);
|
|
592
|
+
stack.push(...(needs.get(d) ?? []));
|
|
593
|
+
}
|
|
594
|
+
return out;
|
|
595
|
+
};
|
|
596
|
+
// A changed member another member of the release depends on is there because that member needs it.
|
|
597
|
+
for (const [name, reason] of chosen) {
|
|
598
|
+
if (reason.code !== "paths-changed" && reason.code !== "intent-pending")
|
|
599
|
+
continue;
|
|
600
|
+
const needer = [...chosen.keys()].sort().find((m) => m !== name && chosen.get(m).code !== "range-broken-by" && reach(m).has(name));
|
|
601
|
+
if (needer !== undefined)
|
|
602
|
+
chosen.set(name, { code: "needed-by", member: needer });
|
|
603
|
+
}
|
|
604
|
+
const before = new Map([...chosen.keys()].map((m) => [m, [...reach(m)].filter((d) => chosen.has(d) && d !== m)]));
|
|
605
|
+
const layerOf = new Map();
|
|
606
|
+
const left = new Set(chosen.keys());
|
|
607
|
+
for (let layer = 0; left.size > 0; layer++) {
|
|
608
|
+
let ready = [...left].filter((m) => !before.get(m).some((d) => left.has(d))).sort();
|
|
609
|
+
// A dependency cycle cannot be ordered; its members share the layer.
|
|
610
|
+
if (ready.length === 0)
|
|
611
|
+
ready = [...left].sort();
|
|
612
|
+
for (const m of ready) {
|
|
613
|
+
layerOf.set(m, layer);
|
|
614
|
+
left.delete(m);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
const out = [...chosen.keys()]
|
|
618
|
+
.sort((a, b) => layerOf.get(a) - layerOf.get(b) || a.localeCompare(b))
|
|
619
|
+
.map((name) => {
|
|
620
|
+
const i = info.get(name);
|
|
621
|
+
const { bump, bumpFrom, next } = nextOf(name);
|
|
622
|
+
return { member: name, layer: layerOf.get(name), reason: chosen.get(name), last: i.last, bump, bumpFrom, next, paths: i.paths, intents: i.intents.map((x) => x.path) };
|
|
623
|
+
});
|
|
624
|
+
return { at, members: out };
|
|
625
|
+
}
|