@workerstack/clients 1.0.0-rc.24 → 1.0.0-rc.25

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 (93) hide show
  1. package/README.md +56 -0
  2. package/assets/installers/examples/github.config.ts +21 -0
  3. package/assets/installers/examples/goreleaser.config.ts +21 -0
  4. package/assets/installers/examples/raw.config.ts +17 -0
  5. package/assets/installers/templates/install.ps1 +426 -0
  6. package/assets/installers/templates/install.sh +412 -0
  7. package/bin/installgen.js +19 -0
  8. package/dist/cli.js +4 -0
  9. package/dist/emit/cli/install.d.ts +8 -5
  10. package/dist/emit/cli/install.js +14 -7
  11. package/dist/emit/cli/release.js +8 -7
  12. package/dist/gen/args.js +4 -0
  13. package/dist/installers/cli.d.ts +21 -0
  14. package/dist/installers/cli.js +170 -0
  15. package/dist/installers/commands/build.d.ts +15 -0
  16. package/dist/installers/commands/build.js +34 -0
  17. package/dist/installers/commands/check.d.ts +10 -0
  18. package/dist/installers/commands/check.js +161 -0
  19. package/dist/installers/commands/init.d.ts +9 -0
  20. package/dist/installers/commands/init.js +32 -0
  21. package/dist/installers/config/define-config.d.ts +100 -0
  22. package/dist/installers/config/define-config.js +10 -0
  23. package/dist/installers/config/hooks/bun.d.ts +21 -0
  24. package/dist/installers/config/hooks/bun.js +21 -0
  25. package/dist/installers/config/hooks/node.d.ts +9 -0
  26. package/dist/installers/config/hooks/node.js +16 -0
  27. package/dist/installers/config/load.d.ts +35 -0
  28. package/dist/installers/config/load.js +97 -0
  29. package/dist/installers/config/resolve.d.ts +4 -0
  30. package/dist/installers/config/resolve.js +281 -0
  31. package/dist/installers/config/types.d.ts +45 -0
  32. package/dist/installers/config/types.js +1 -0
  33. package/dist/installers/errors.d.ts +5 -0
  34. package/dist/installers/errors.js +5 -0
  35. package/dist/installers/index.d.ts +11 -0
  36. package/dist/installers/index.js +11 -0
  37. package/dist/installers/render/quote.d.ts +7 -0
  38. package/dist/installers/render/quote.js +34 -0
  39. package/dist/installers/render/render.d.ts +24 -0
  40. package/dist/installers/render/render.js +133 -0
  41. package/dist/installers/ui.d.ts +15 -0
  42. package/dist/installers/ui.js +14 -0
  43. package/dist/release/bootstrap.d.ts +61 -0
  44. package/dist/release/bootstrap.js +191 -0
  45. package/dist/release/bump-args.d.ts +17 -0
  46. package/dist/release/bump-args.js +35 -0
  47. package/dist/release/bump-command.d.ts +18 -0
  48. package/dist/release/bump-command.js +186 -0
  49. package/dist/release/bump.d.ts +33 -0
  50. package/dist/release/bump.js +72 -0
  51. package/dist/release/cli.d.ts +23 -0
  52. package/dist/release/cli.js +85 -0
  53. package/dist/release/codegen.d.ts +6 -0
  54. package/dist/release/codegen.js +25 -0
  55. package/dist/release/constants.d.ts +39 -0
  56. package/dist/release/constants.js +35 -0
  57. package/dist/release/context.d.ts +33 -0
  58. package/dist/release/context.js +31 -0
  59. package/dist/release/digest.d.ts +11 -0
  60. package/dist/release/digest.js +59 -0
  61. package/dist/release/git.d.ts +10 -0
  62. package/dist/release/git.js +64 -0
  63. package/dist/release/index.d.ts +7 -0
  64. package/dist/release/index.js +6 -0
  65. package/dist/release/load.d.ts +30 -0
  66. package/dist/release/load.js +78 -0
  67. package/dist/release/manifest.d.ts +15 -0
  68. package/dist/release/manifest.js +164 -0
  69. package/dist/release/oasdiff.d.ts +20 -0
  70. package/dist/release/oasdiff.js +36 -0
  71. package/dist/release/registries.d.ts +46 -0
  72. package/dist/release/registries.js +243 -0
  73. package/dist/release/release-state.d.ts +15 -0
  74. package/dist/release/release-state.js +21 -0
  75. package/dist/release/release-workflow.d.ts +5 -0
  76. package/dist/release/release-workflow.js +72 -0
  77. package/dist/release/repo-settings.d.ts +22 -0
  78. package/dist/release/repo-settings.js +53 -0
  79. package/dist/release/spec-gate.d.ts +28 -0
  80. package/dist/release/spec-gate.js +107 -0
  81. package/dist/release/sync-command.d.ts +31 -0
  82. package/dist/release/sync-command.js +122 -0
  83. package/dist/release/sync-tree.d.ts +30 -0
  84. package/dist/release/sync-tree.js +123 -0
  85. package/dist/release/sync.d.ts +46 -0
  86. package/dist/release/sync.js +172 -0
  87. package/dist/release/types.d.ts +149 -0
  88. package/dist/release/types.js +1 -0
  89. package/dist/release/version-files.d.ts +16 -0
  90. package/dist/release/version-files.js +74 -0
  91. package/dist/version.d.ts +5 -0
  92. package/dist/version.js +8 -0
  93. package/package.json +19 -9
@@ -0,0 +1,133 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { InstallgenError } from "../errors.js";
3
+ import { psLiteral, psString, shLiteral, shWord } from "./quote.js";
4
+ /* The scripts validate the same pattern at install time, after stripping the tag prefix */
5
+ const VERSION = /^[A-Za-z0-9._+-]+$/;
6
+ /* in non-unicode mode an astral character is two surrogates, both in this range */
7
+ const NON_ASCII = /[\u0080-\uffff]/;
8
+ const PLACEHOLDER = /@@([A-Z0-9_]+)@@/g;
9
+ const readTemplate = (file) => readFileSync(new URL(`../../../assets/installers/templates/${file}`, import.meta.url), "utf8");
10
+ export function readTemplates() {
11
+ return { sh: readTemplate("install.sh"), ps1: readTemplate("install.ps1") };
12
+ }
13
+ function ascii(field, value) {
14
+ if (value !== undefined && NON_ASCII.test(value)) {
15
+ throw new InstallgenError(`${field} has a non-ASCII character (${JSON.stringify(value)}); the scripts must stay ASCII for Windows PowerShell 5.1`);
16
+ }
17
+ }
18
+ const literals = (segments) => (segments ?? []).map((s) => (s.kind === "literal" ? s.value : "")).join("");
19
+ function checkAscii(resolved) {
20
+ ascii("config.message", resolved.message);
21
+ ascii("config.baseUrl", resolved.baseUrl);
22
+ ascii("config.latestPath", resolved.latestPath);
23
+ ascii("config.scriptUrls.sh", resolved.scriptUrls.sh);
24
+ ascii("config.scriptUrls.ps1", resolved.scriptUrls.ps1);
25
+ for (const p of resolved.platforms) {
26
+ ascii(`config.assetPath for ${p.platform}`, literals(p.asset));
27
+ ascii(`config.checksumsPath for ${p.platform}`, literals(p.checksums));
28
+ ascii(`config.binaryInArchive for ${p.platform}`, literals(p.binaryInArchive));
29
+ ascii(`config.signature.bundlePath for ${p.platform}`, literals(p.signature?.bundle));
30
+ ascii(`config.signature.identity for ${p.platform}`, literals(p.signature?.identity));
31
+ ascii(`config.signature.issuer for ${p.platform}`, p.signature?.issuer);
32
+ }
33
+ }
34
+ function shCase(p) {
35
+ return [
36
+ `\t\t'${p.platform}')`,
37
+ `\t\t\tasset_path=${shWord(p.asset)}`,
38
+ `\t\t\tformat=${shLiteral(p.format)}`,
39
+ `\t\t\tchecksums_path=${shWord(p.checksums ?? [])}`,
40
+ `\t\t\tbundle_path=${shWord(p.signature?.bundle ?? [])}`,
41
+ `\t\t\tidentity=${shWord(p.signature?.identity ?? [])}`,
42
+ `\t\t\tissuer=${shLiteral(p.signature?.issuer ?? "")}`,
43
+ `\t\t\tbinary_in_archive=${shWord(p.binaryInArchive ?? [])}`,
44
+ "\t\t\t;;",
45
+ ].join("\n");
46
+ }
47
+ function psCase(p) {
48
+ return [
49
+ `\t\t'${p.platform}' {`,
50
+ `\t\t\t$assetPath = ${psString(p.asset)}`,
51
+ `\t\t\t$format = ${psLiteral(p.format)}`,
52
+ `\t\t\t$checksumsPath = ${psString(p.checksums ?? [])}`,
53
+ `\t\t\t$bundlePath = ${psString(p.signature?.bundle ?? [])}`,
54
+ `\t\t\t$identity = ${psString(p.signature?.identity ?? [])}`,
55
+ `\t\t\t$issuer = ${psLiteral(p.signature?.issuer ?? "")}`,
56
+ `\t\t\t$binaryInArchive = ${psString(p.binaryInArchive ?? [])}`,
57
+ "\t\t}",
58
+ ].join("\n");
59
+ }
60
+ /** The value of each `@@KEY@@` in install.sh and install.ps1, already quoted for its shell. */
61
+ export function placeholders(resolved, options) {
62
+ const unix = resolved.platforms.filter((p) => p.os !== "windows");
63
+ const windows = resolved.platforms.filter((p) => p.os === "windows");
64
+ const latestUrl = `${resolved.baseUrl}/${resolved.latestPath}`;
65
+ const defaultVersion = options.defaultVersion ?? "";
66
+ const message = resolved.message ?? "";
67
+ return {
68
+ sh: {
69
+ NAME: shLiteral(resolved.name),
70
+ ENV_PREFIX: resolved.envPrefix,
71
+ BASE_URL: shLiteral(resolved.baseUrl),
72
+ LATEST_URL: shLiteral(latestUrl),
73
+ DEFAULT_VERSION: shLiteral(defaultVersion),
74
+ TAG_PREFIX: shLiteral(resolved.tagPrefix),
75
+ INSTALL_DIR: `"$HOME"${shLiteral(`/${resolved.installDir}`)}`,
76
+ INSTALL_DIR_DISPLAY: shLiteral(`~/${resolved.installDir}`),
77
+ MODIFY_PATH: resolved.modifyPath ? "1" : "0",
78
+ MESSAGE: shLiteral(message),
79
+ SH_URL: shLiteral(resolved.scriptUrls.sh),
80
+ /* with no Windows build there is no install.ps1 to point Git Bash users at */
81
+ PS1_URL: shLiteral(windows.length > 0 ? resolved.scriptUrls.ps1 : ""),
82
+ CURL_FLAGS: resolved.https ? "--proto '=https' --tlsv1.2" : "",
83
+ WGET_FLAGS: shLiteral(resolved.https ? "--https-only" : ""),
84
+ /* a case pattern list */
85
+ PLATFORMS: unix.map((p) => shLiteral(p.platform)).join(" | "),
86
+ PLATFORM_CASES: unix.map(shCase).join("\n"),
87
+ },
88
+ ps1: {
89
+ NAME: psLiteral(resolved.name),
90
+ ENV_PREFIX: resolved.envPrefix,
91
+ BASE_URL: psLiteral(resolved.baseUrl),
92
+ LATEST_URL: psLiteral(latestUrl),
93
+ DEFAULT_VERSION: psLiteral(defaultVersion),
94
+ TAG_PREFIX: psLiteral(resolved.tagPrefix),
95
+ /* $env:USERPROFILE is unset on non-Windows pwsh and in some service contexts, and a literal \ is a filename
96
+ * character off Windows: Combine(params string[]) (.NET 4, so 5.1 too) joins with the native separator */
97
+ INSTALL_DIR: `[IO.Path]::Combine([string[]](@([Environment]::GetFolderPath('UserProfile')) + @(${resolved.installDir
98
+ .split("/")
99
+ .map(psLiteral)
100
+ .join(", ")})))`,
101
+ INSTALL_DIR_DISPLAY: psLiteral(`~\\${resolved.installDir.replaceAll("/", "\\")}`),
102
+ MODIFY_PATH: resolved.modifyPath ? "$true" : "$false",
103
+ MESSAGE: psLiteral(message),
104
+ SH_URL: psLiteral(unix.length > 0 ? resolved.scriptUrls.sh : ""),
105
+ PS1_URL: psLiteral(resolved.scriptUrls.ps1),
106
+ PLATFORMS: `@(${windows.map((p) => psLiteral(p.platform)).join(", ")})`,
107
+ PLATFORM_CASES: windows.map(psCase).join("\n"),
108
+ },
109
+ };
110
+ }
111
+ function fill(file, template, values) {
112
+ const out = template.replace(PLACEHOLDER, (_match, key) => {
113
+ const value = values[key];
114
+ if (value === undefined)
115
+ throw new InstallgenError(`unknown placeholder @@${key}@@ in ${file}`);
116
+ return value;
117
+ });
118
+ ascii(file, out);
119
+ return out;
120
+ }
121
+ export function render(resolved, options, templates = readTemplates()) {
122
+ if (options.defaultVersion !== undefined && !VERSION.test(options.defaultVersion)) {
123
+ throw new InstallgenError(`the default version must match ${VERSION.source}, got ${JSON.stringify(options.defaultVersion)}`);
124
+ }
125
+ checkAscii(resolved);
126
+ const values = placeholders(resolved, options);
127
+ const out = {};
128
+ if (resolved.platforms.some((p) => p.os !== "windows"))
129
+ out.sh = fill("install.sh", templates.sh, values.sh);
130
+ if (resolved.platforms.some((p) => p.os === "windows"))
131
+ out.ps1 = fill("install.ps1", templates.ps1, values.ps1);
132
+ return out;
133
+ }
@@ -0,0 +1,15 @@
1
+ /** Rows like the installers': a mark, a label, a value. Marks and color on a TTY; plain `+`, `x`, `!` otherwise. */
2
+ export interface Ui {
3
+ ok(label: string, value: string): void;
4
+ bad(label: string, value: string): void;
5
+ info(text: string): void;
6
+ warn(text: string): void;
7
+ error(text: string): void;
8
+ }
9
+ export interface UiIo {
10
+ stdout(text: string): void;
11
+ stderr(text: string): void;
12
+ isTTY: boolean;
13
+ env: Record<string, string | undefined>;
14
+ }
15
+ export declare function createUi(io: UiIo): Ui;
@@ -0,0 +1,14 @@
1
+ const ESC = "\u001b";
2
+ const row = (glyph, label, value) => `${glyph} ${label.padEnd(13)} ${value}\n`;
3
+ export function createUi(io) {
4
+ const color = io.isTTY && !io.env.NO_COLOR;
5
+ const paint = (code, text) => (color ? `${ESC}[${code}m${text}${ESC}[0m` : text);
6
+ const mark = { ok: io.isTTY ? "✓" : "+", bad: io.isTTY ? "✗" : "x" };
7
+ return {
8
+ ok: (label, value) => io.stdout(row(paint(32, mark.ok), label, value)),
9
+ bad: (label, value) => io.stdout(row(paint(31, mark.bad), label, value)),
10
+ info: (text) => io.stdout(`${text}\n`),
11
+ warn: (text) => io.stderr(`${paint(33, "warning:")} ${text}\n`),
12
+ error: (text) => io.stderr(`${paint(31, io.isTTY ? `${mark.bad} error:` : "error:")} ${text}\n`),
13
+ };
14
+ }
@@ -0,0 +1,61 @@
1
+ import { type ReleaseContext } from "./context.ts";
2
+ /** The most commits a public repo's branch may hold for `--force-bootstrap` to overwrite it: a stub, not history. */
3
+ export declare const FORCE_COMMIT_LIMIT = 2;
4
+ /** What `release bootstrap` prints when it is not told what to target. */
5
+ export declare const USAGE: string[];
6
+ /**
7
+ * Returns commit count on the remote branch, capped at FORCE_COMMIT_LIMIT + 1.
8
+ * Used to gate --force-bootstrap: only mirrors with ≤FORCE_COMMIT_LIMIT commits
9
+ * may be overwritten. Refuses to blast real history.
10
+ */
11
+ export declare function countRemoteCommits(httpsUrl: string, branch: string): Promise<number>;
12
+ /** What `release bootstrap` was asked for. */
13
+ export interface BootstrapOptions {
14
+ /** Every package of the release. */
15
+ all: boolean;
16
+ /** The release config's path; required. */
17
+ config: string | undefined;
18
+ /** Overwrite a stub branch of at most `FORCE_COMMIT_LIMIT` commits. */
19
+ forceBootstrap: boolean;
20
+ /** The packages to bootstrap, by `name` or `project/name`. */
21
+ only: string[] | undefined;
22
+ }
23
+ /** A parse that succeeded with `options`, or failed with an `error` to show the caller. */
24
+ export type ParsedArgs = {
25
+ error: string;
26
+ ok: false;
27
+ } | {
28
+ ok: true;
29
+ options: BootstrapOptions;
30
+ };
31
+ /** `release bootstrap`'s flags; a value flag with no value is an error naming it, any unknown argument is ignored. */
32
+ export declare function parseArgs(argv: readonly string[]): ParsedArgs;
33
+ /** Bootstrap must be told what to target; an empty argv would mean "every mirror". */
34
+ export declare function hasTarget(options: BootstrapOptions): boolean;
35
+ /** Whether bootstrap may overwrite a public repo's branch, and why not when it may not. */
36
+ export type MirrorVerdict = {
37
+ proceed: false;
38
+ reason: string;
39
+ } | {
40
+ proceed: true;
41
+ reason?: undefined;
42
+ };
43
+ /**
44
+ * Whether bootstrap may overwrite this mirror branch.
45
+ *
46
+ * - empty branch → proceed
47
+ * - ≤FORCE_COMMIT_LIMIT + --force-bootstrap → proceed (stub README + initial commit)
48
+ * - ≤FORCE_COMMIT_LIMIT, no force → refuse (require explicit force)
49
+ * - >FORCE_COMMIT_LIMIT → refuse always (cannot blast real history)
50
+ */
51
+ export declare function judgeMirror(input: {
52
+ branch: string;
53
+ commitCount: number;
54
+ forceBootstrap: boolean;
55
+ tip: string | undefined;
56
+ }): MirrorVerdict;
57
+ /**
58
+ * Runs `release bootstrap <argv>`: the target is checked before the token, and both before the config loads, so the
59
+ * first mistake is the one reported. The exit code it ends with.
60
+ */
61
+ export declare function bootstrap(argv: readonly string[], ctx: ReleaseContext): Promise<number>;
@@ -0,0 +1,191 @@
1
+ /**
2
+ * `release bootstrap`: the first push to an empty public repo, or over the stub README a new GitHub repo starts with.
3
+ * It overwrites the branch, so it is told exactly what to target and never blasts a repo with real history.
4
+ */
5
+ import { mkdtempSync, rmSync } from "node:fs";
6
+ import { tmpdir } from "node:os";
7
+ import { join } from "node:path";
8
+ import { SHORT_SHA_LENGTH } from "./constants.js";
9
+ import { ReleaseUsageError, requireConfig } from "./context.js";
10
+ import { getRemoteTip, gitOutput, gitRun, sshToHttps } from "./git.js";
11
+ import { packageKey } from "./manifest.js";
12
+ import { repoSettingsSyncer } from "./repo-settings.js";
13
+ import { memoizedSpecGate } from "./spec-gate.js";
14
+ import { filterPackages, syncPackage } from "./sync.js";
15
+ const DECIMAL_RADIX = 10;
16
+ /** The most commits a public repo's branch may hold for `--force-bootstrap` to overwrite it: a stub, not history. */
17
+ export const FORCE_COMMIT_LIMIT = 2;
18
+ /** What `release bootstrap` prints when it is not told what to target. */
19
+ export const USAGE = [
20
+ "Usage: honey-clients release bootstrap --config <path> (--all | --only <names>) [--force-bootstrap]",
21
+ "",
22
+ "Tip: get a token via: gh auth token",
23
+ ];
24
+ /**
25
+ * Returns commit count on the remote branch, capped at FORCE_COMMIT_LIMIT + 1.
26
+ * Used to gate --force-bootstrap: only mirrors with ≤FORCE_COMMIT_LIMIT commits
27
+ * may be overwritten. Refuses to blast real history.
28
+ */
29
+ export async function countRemoteCommits(httpsUrl, branch) {
30
+ const tmpDir = mkdtempSync(join(tmpdir(), "public-sync-count-"));
31
+ try {
32
+ await gitRun(["init", "--quiet", tmpDir], tmpDir);
33
+ await gitRun(["-C", tmpDir, "remote", "add", "origin", httpsUrl], tmpDir);
34
+ try {
35
+ await gitRun(["-C", tmpDir, "fetch", `--depth=${FORCE_COMMIT_LIMIT + 1}`, "origin", branch], tmpDir);
36
+ }
37
+ catch {
38
+ return 0;
39
+ }
40
+ const count = await gitOutput(["-C", tmpDir, "rev-list", "--count", "FETCH_HEAD"], tmpDir);
41
+ return Number.parseInt(count, DECIMAL_RADIX);
42
+ }
43
+ finally {
44
+ rmSync(tmpDir, { force: true, recursive: true });
45
+ }
46
+ }
47
+ /* Unknown arguments are ignored. */
48
+ const SWITCHES = { "--all": "all", "--force-bootstrap": "forceBootstrap" };
49
+ const VALUE_FLAGS = { "--config": "config", "--name": "only", "--only": "only" };
50
+ const isSwitch = (arg) => Object.hasOwn(SWITCHES, arg);
51
+ const isValueFlag = (arg) => Object.hasOwn(VALUE_FLAGS, arg);
52
+ /** `release bootstrap`'s flags; a value flag with no value is an error naming it, any unknown argument is ignored. */
53
+ export function parseArgs(argv) {
54
+ const options = { all: false, config: undefined, forceBootstrap: false, only: undefined };
55
+ for (let i = 0; i < argv.length; i++) {
56
+ const arg = argv[i];
57
+ if (isSwitch(arg)) {
58
+ options[SWITCHES[arg]] = true;
59
+ continue;
60
+ }
61
+ if (!isValueFlag(arg))
62
+ continue;
63
+ const next = argv[i + 1];
64
+ if (!next || next.startsWith("--"))
65
+ return { error: `${arg} requires a value`, ok: false };
66
+ if (VALUE_FLAGS[arg] === "only") {
67
+ options.only = next
68
+ .split(",")
69
+ .map((name) => name.trim())
70
+ .filter(Boolean);
71
+ }
72
+ else {
73
+ options.config = next;
74
+ }
75
+ i++;
76
+ }
77
+ return { ok: true, options };
78
+ }
79
+ /** Bootstrap must be told what to target; an empty argv would mean "every mirror". */
80
+ export function hasTarget(options) {
81
+ return options.all || options.only !== undefined;
82
+ }
83
+ /**
84
+ * Whether bootstrap may overwrite this mirror branch.
85
+ *
86
+ * - empty branch → proceed
87
+ * - ≤FORCE_COMMIT_LIMIT + --force-bootstrap → proceed (stub README + initial commit)
88
+ * - ≤FORCE_COMMIT_LIMIT, no force → refuse (require explicit force)
89
+ * - >FORCE_COMMIT_LIMIT → refuse always (cannot blast real history)
90
+ */
91
+ export function judgeMirror(input) {
92
+ if (!input.tip)
93
+ return { proceed: true };
94
+ const shortTip = input.tip.slice(0, SHORT_SHA_LENGTH);
95
+ if (input.commitCount > FORCE_COMMIT_LIMIT) {
96
+ return {
97
+ proceed: false,
98
+ reason: `mirror branch ${input.branch} has ${input.commitCount}+ commits (tip=${shortTip}…). Bootstrap refuses to overwrite real history.\n Bootstrap is for a new repo; release sync keeps one with history current. To start over, delete the repo and recreate it empty.`,
99
+ };
100
+ }
101
+ if (!input.forceBootstrap) {
102
+ return {
103
+ proceed: false,
104
+ reason: `mirror branch ${input.branch} is non-empty (${input.commitCount} commit(s), tip=${shortTip}…). Pass --force-bootstrap to overwrite the stub.`,
105
+ };
106
+ }
107
+ return { proceed: true };
108
+ }
109
+ /* one package bootstrapped: its outcome, reported as it goes */
110
+ async function bootstrapOne(entry, run, ctx) {
111
+ ctx.out(`\n→ ${packageKey(entry)} → ${entry.mirror}\n`);
112
+ const httpsUrl = sshToHttps(entry.mirror, run.token);
113
+ const tip = await getRemoteTip(httpsUrl, entry.branch, run.root);
114
+ const verdict = judgeMirror({
115
+ branch: entry.branch,
116
+ commitCount: tip ? await countRemoteCommits(httpsUrl, entry.branch) : 0,
117
+ forceBootstrap: run.forceBootstrap,
118
+ tip,
119
+ });
120
+ if (!verdict.proceed) {
121
+ ctx.err(` fail: ${verdict.reason}\n`);
122
+ return "failed";
123
+ }
124
+ /* Bootstrap commits force-overwrite the mirror with a fresh "initial release" snapshot. bootstrapExclude globs
125
+ skip generated source on the initial push, so the next sync adds it cleanly. A repo bootstrap creates is exactly
126
+ one whose description, website and topics are empty, so the settings step fills them. */
127
+ const result = await syncPackage(entry, {
128
+ applyBootstrapExclude: true,
129
+ dryRun: false,
130
+ initialMessage: "chore: initial release",
131
+ overwriteForeignTip: true,
132
+ repoRoot: run.root,
133
+ repoSettings: run.repoSettings,
134
+ specGate: run.specGate,
135
+ token: run.token,
136
+ });
137
+ if (result.status === "failed") {
138
+ ctx.err(` fail: ${result.reason}\n`);
139
+ return "failed";
140
+ }
141
+ if (result.status === "skipped") {
142
+ ctx.out(` skip: ${result.reason}\n`);
143
+ return "skipped";
144
+ }
145
+ /* a push that is no dry run always reports both shas */
146
+ const [source, mirror] = [result.sourceSha, result.mirrorSha];
147
+ ctx.out(` ok: source=${source.slice(0, SHORT_SHA_LENGTH)} mirror=${mirror.slice(0, SHORT_SHA_LENGTH)}\n`);
148
+ return "synced";
149
+ }
150
+ /* the packages a bootstrap targets, bootstrapped one after another; the exit code it ends with */
151
+ async function bootstrapAll(release, options, token, ctx) {
152
+ const targets = filterPackages(release.packages, { only: options.only });
153
+ if (targets.length === 0) {
154
+ ctx.err(`No packages match. Available: ${release.packages.map((entry) => packageKey(entry)).join(", ")}\n`);
155
+ return 1;
156
+ }
157
+ const run = {
158
+ forceBootstrap: options.forceBootstrap,
159
+ repoSettings: repoSettingsSyncer({ dryRun: false, fetch: ctx.fetch, token }),
160
+ root: release.root,
161
+ specGate: memoizedSpecGate(ctx.fetch),
162
+ token,
163
+ };
164
+ const outcomes = { failed: 0, skipped: 0, synced: 0 };
165
+ for (const entry of targets)
166
+ outcomes[await bootstrapOne(entry, run, ctx)]++;
167
+ ctx.out(`\nBootstrap done: ${outcomes.synced} synced, ${outcomes.skipped} skipped, ${outcomes.failed} failed.\n`);
168
+ return outcomes.failed > 0 ? 1 : 0;
169
+ }
170
+ /**
171
+ * Runs `release bootstrap <argv>`: the target is checked before the token, and both before the config loads, so the
172
+ * first mistake is the one reported. The exit code it ends with.
173
+ */
174
+ export async function bootstrap(argv, ctx) {
175
+ const parsed = parseArgs(argv);
176
+ if (!parsed.ok)
177
+ throw new ReleaseUsageError(parsed.error);
178
+ const { options } = parsed;
179
+ const config = requireConfig(options.config);
180
+ if (!hasTarget(options)) {
181
+ for (const line of USAGE)
182
+ ctx.err(`${line}\n`);
183
+ return 1;
184
+ }
185
+ const token = ctx.env.GH_TOKEN;
186
+ if (!token) {
187
+ ctx.err("GH_TOKEN env is required. Get one via: GH_TOKEN=$(gh auth token)\n");
188
+ return 1;
189
+ }
190
+ return bootstrapAll(await ctx.load(config), options, token, ctx);
191
+ }
@@ -0,0 +1,17 @@
1
+ /** What `release bump` was asked for: the release config, and whether every release is a major. */
2
+ export type BumpArgs = {
3
+ /** The release config's path, relative to the working directory. */
4
+ readonly config: string;
5
+ /** Make every package that releases a major, whatever changed. */
6
+ readonly major: boolean;
7
+ };
8
+ /** A parse that succeeded with `value`, or failed with an `error` to show the caller. */
9
+ export type Parsed<T> = {
10
+ error: string;
11
+ ok: false;
12
+ } | {
13
+ ok: true;
14
+ value: T;
15
+ };
16
+ /** `release bump`'s flags: `--config <path>` (required) and `--major`; any other argument is an error naming it. */
17
+ export declare function parseBumpArgs(argv: readonly string[]): Parsed<BumpArgs>;
@@ -0,0 +1,35 @@
1
+ /* Each flag takes the next argument as its value, unless that argument is a switch. */
2
+ const BUMP_FLAGS = { "--config": "config" };
3
+ /* Bare flags: present or not. */
4
+ const BUMP_SWITCHES = { "--major": "major" };
5
+ /* The value of every `flags` entry and the presence of every `switches` entry in `argv`, or the first argument that
6
+ * is neither. */
7
+ function readFlags(flags, switches, argv) {
8
+ const values = {};
9
+ const set = {};
10
+ for (let i = 0; i < argv.length; i++) {
11
+ const flag = argv[i];
12
+ if (Object.hasOwn(switches, flag)) {
13
+ set[switches[flag]] = true;
14
+ continue;
15
+ }
16
+ if (!Object.hasOwn(flags, flag))
17
+ return { unknown: flag };
18
+ const value = argv[i + 1];
19
+ if (value === undefined || Object.hasOwn(switches, value))
20
+ continue;
21
+ values[flags[flag]] = value;
22
+ i++;
23
+ }
24
+ return { set, values };
25
+ }
26
+ /** `release bump`'s flags: `--config <path>` (required) and `--major`; any other argument is an error naming it. */
27
+ export function parseBumpArgs(argv) {
28
+ const read = readFlags(BUMP_FLAGS, BUMP_SWITCHES, argv);
29
+ if ("unknown" in read)
30
+ return { error: `unknown flag: ${read.unknown}`, ok: false };
31
+ const { config } = read.values;
32
+ if (!config)
33
+ return { error: "--config <path> is required", ok: false };
34
+ return { ok: true, value: { config, major: read.set.major === true } };
35
+ }
@@ -0,0 +1,18 @@
1
+ import type { ReleaseContext } from "./context.ts";
2
+ import type { Release } from "./types.ts";
3
+ import { type ReleaseState } from "./release-state.ts";
4
+ /** The header every CHANGELOG bump writes starts with; entries go directly under it, newest first. */
5
+ export declare const CHANGELOG_HEADER = "# Changelog\n\n";
6
+ /**
7
+ * `existing` with `entry` directly under the `# Changelog` header, which it gains when it had none; one blank line
8
+ * between the entry and the previous one, none after the last, so a markdown formatter leaves the file as written.
9
+ */
10
+ export declare function prependEntry(existing: string, entry: string): string;
11
+ /** The release `stateFile` records; undefined before a package's first release. Throws on a state that does not parse. */
12
+ export declare function readPrevious(stateFile: string): Promise<ReleaseState | undefined>;
13
+ /**
14
+ * Releases each package of `release` whose output or hand files changed since its last release, `major` making each
15
+ * release a major; the exit code it ends with. Prints a `bumped: <name> <version> <kind>` line per release and a
16
+ * `wrote: <path>` line per file it touched, which the bump workflow parses.
17
+ */
18
+ export declare function runBump(release: Release, major: boolean, ctx: ReleaseContext): Promise<number>;