@workerstack/clients 1.0.0-rc.23 → 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 (99) hide show
  1. package/README.md +67 -11
  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/emit/shared/status-keys.d.ts +2 -2
  13. package/dist/emit/shared/status-keys.js +2 -2
  14. package/dist/gen/args.js +4 -0
  15. package/dist/gen/formatters.d.ts +1 -1
  16. package/dist/gen/formatters.js +1 -1
  17. package/dist/gen/targets.d.ts +1 -1
  18. package/dist/gen/targets.js +1 -1
  19. package/dist/installers/cli.d.ts +21 -0
  20. package/dist/installers/cli.js +170 -0
  21. package/dist/installers/commands/build.d.ts +15 -0
  22. package/dist/installers/commands/build.js +34 -0
  23. package/dist/installers/commands/check.d.ts +10 -0
  24. package/dist/installers/commands/check.js +161 -0
  25. package/dist/installers/commands/init.d.ts +9 -0
  26. package/dist/installers/commands/init.js +32 -0
  27. package/dist/installers/config/define-config.d.ts +100 -0
  28. package/dist/installers/config/define-config.js +10 -0
  29. package/dist/installers/config/hooks/bun.d.ts +21 -0
  30. package/dist/installers/config/hooks/bun.js +21 -0
  31. package/dist/installers/config/hooks/node.d.ts +9 -0
  32. package/dist/installers/config/hooks/node.js +16 -0
  33. package/dist/installers/config/load.d.ts +35 -0
  34. package/dist/installers/config/load.js +97 -0
  35. package/dist/installers/config/resolve.d.ts +4 -0
  36. package/dist/installers/config/resolve.js +281 -0
  37. package/dist/installers/config/types.d.ts +45 -0
  38. package/dist/installers/config/types.js +1 -0
  39. package/dist/installers/errors.d.ts +5 -0
  40. package/dist/installers/errors.js +5 -0
  41. package/dist/installers/index.d.ts +11 -0
  42. package/dist/installers/index.js +11 -0
  43. package/dist/installers/render/quote.d.ts +7 -0
  44. package/dist/installers/render/quote.js +34 -0
  45. package/dist/installers/render/render.d.ts +24 -0
  46. package/dist/installers/render/render.js +133 -0
  47. package/dist/installers/ui.d.ts +15 -0
  48. package/dist/installers/ui.js +14 -0
  49. package/dist/release/bootstrap.d.ts +61 -0
  50. package/dist/release/bootstrap.js +191 -0
  51. package/dist/release/bump-args.d.ts +17 -0
  52. package/dist/release/bump-args.js +35 -0
  53. package/dist/release/bump-command.d.ts +18 -0
  54. package/dist/release/bump-command.js +186 -0
  55. package/dist/release/bump.d.ts +33 -0
  56. package/dist/release/bump.js +72 -0
  57. package/dist/release/cli.d.ts +23 -0
  58. package/dist/release/cli.js +85 -0
  59. package/dist/release/codegen.d.ts +6 -0
  60. package/dist/release/codegen.js +25 -0
  61. package/dist/release/constants.d.ts +39 -0
  62. package/dist/release/constants.js +35 -0
  63. package/dist/release/context.d.ts +33 -0
  64. package/dist/release/context.js +31 -0
  65. package/dist/release/digest.d.ts +11 -0
  66. package/dist/release/digest.js +59 -0
  67. package/dist/release/git.d.ts +10 -0
  68. package/dist/release/git.js +64 -0
  69. package/dist/release/index.d.ts +7 -0
  70. package/dist/release/index.js +6 -0
  71. package/dist/release/load.d.ts +30 -0
  72. package/dist/release/load.js +78 -0
  73. package/dist/release/manifest.d.ts +15 -0
  74. package/dist/release/manifest.js +164 -0
  75. package/dist/release/oasdiff.d.ts +20 -0
  76. package/dist/release/oasdiff.js +36 -0
  77. package/dist/release/registries.d.ts +46 -0
  78. package/dist/release/registries.js +243 -0
  79. package/dist/release/release-state.d.ts +15 -0
  80. package/dist/release/release-state.js +21 -0
  81. package/dist/release/release-workflow.d.ts +5 -0
  82. package/dist/release/release-workflow.js +72 -0
  83. package/dist/release/repo-settings.d.ts +22 -0
  84. package/dist/release/repo-settings.js +53 -0
  85. package/dist/release/spec-gate.d.ts +28 -0
  86. package/dist/release/spec-gate.js +107 -0
  87. package/dist/release/sync-command.d.ts +31 -0
  88. package/dist/release/sync-command.js +122 -0
  89. package/dist/release/sync-tree.d.ts +30 -0
  90. package/dist/release/sync-tree.js +123 -0
  91. package/dist/release/sync.d.ts +46 -0
  92. package/dist/release/sync.js +172 -0
  93. package/dist/release/types.d.ts +149 -0
  94. package/dist/release/types.js +1 -0
  95. package/dist/release/version-files.d.ts +16 -0
  96. package/dist/release/version-files.js +74 -0
  97. package/dist/version.d.ts +5 -0
  98. package/dist/version.js +8 -0
  99. package/package.json +72 -11
@@ -0,0 +1,21 @@
1
+ import { type RuntimeInfo } from "./config/load.ts";
2
+ import { type UiIo } from "./ui.ts";
3
+ export interface Io extends UiIo {
4
+ cwd: string;
5
+ runtime?: RuntimeInfo;
6
+ fetch?: typeof fetch;
7
+ }
8
+ /** The whole CLI, in-process: every effect goes through `io`, so tests run it without spawning. Returns the exit code. */
9
+ export declare function run(argv: readonly string[], io: Io): Promise<number>;
10
+ /** The slice of `process` that `start` touches. */
11
+ export interface Proc {
12
+ stdout: NodeJS.WritableStream & {
13
+ isTTY?: boolean;
14
+ };
15
+ stderr: NodeJS.WritableStream;
16
+ cwd(): string;
17
+ env: Record<string, string | undefined>;
18
+ exitCode?: number | string | null | undefined;
19
+ exit(code?: number): void;
20
+ }
21
+ export declare function start(argv?: readonly string[], proc?: Proc): Promise<void>;
@@ -0,0 +1,170 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { parseArgs } from "node:util";
3
+ import { build } from "./commands/build.js";
4
+ import { check } from "./commands/check.js";
5
+ import { init, PRESETS } from "./commands/init.js";
6
+ import { detectRuntime } from "./config/load.js";
7
+ import { createUi } from "./ui.js";
8
+ const HELP = `Usage: installgen <command> [options]
9
+
10
+ Generate curl | sh and irm | iex installers for prebuilt CLI binaries.
11
+
12
+ Commands:
13
+ init write installgen.config.ts from a preset
14
+ build write install.sh and install.ps1
15
+ check confirm a release's assets and checksum entries are published
16
+
17
+ Options:
18
+ -h, --help show this help
19
+ --version show the installgen version
20
+
21
+ Run \`installgen <command> --help\` for a command's options.
22
+ `;
23
+ const COMMANDS = {
24
+ init: {
25
+ usage: `Usage: installgen init [--preset ${ /* @__PURE__ */PRESETS.join("|")}] [--force]
26
+
27
+ --preset <name> the example to start from (default: raw)
28
+ --force overwrite an existing config
29
+ `,
30
+ options: { preset: { type: "string" }, force: { type: "boolean" } },
31
+ },
32
+ build: {
33
+ usage: `Usage: installgen build [-c <path>] [--out <dir>] [--default-version <version>]
34
+
35
+ -c, --config <path> the config (default: installgen.config.{ts,mts,js,mjs} in this directory)
36
+ --out <dir> where to write the scripts (default: the config's outDir, installers)
37
+ --default-version <version> install this version when the user names none (default: the latest file)
38
+ `,
39
+ options: { config: { type: "string", short: "c" }, out: { type: "string" }, "default-version": { type: "string" } },
40
+ },
41
+ check: {
42
+ usage: `Usage: installgen check [-c <path>] [--default-version <version>] [--list]
43
+
44
+ -c, --config <path> the config (default: installgen.config.{ts,mts,js,mjs} in this directory)
45
+ --default-version <version> check this version (default: read the latest file)
46
+ --list print the URLs the installers fetch, without fetching
47
+ `,
48
+ options: {
49
+ config: { type: "string", short: "c" },
50
+ "default-version": { type: "string" },
51
+ list: { type: "boolean" },
52
+ },
53
+ },
54
+ };
55
+ class UsageError extends Error {
56
+ }
57
+ const isCommand = (name) => Object.hasOwn(COMMANDS, name);
58
+ function version() {
59
+ return JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"))
60
+ .version;
61
+ }
62
+ /** The exit code of a top-level flag; undefined for anything else. */
63
+ function topLevel(command, io) {
64
+ if (command === "--help" || command === "-h") {
65
+ io.stdout(HELP);
66
+ return 0;
67
+ }
68
+ if (command === "--version") {
69
+ io.stdout(`${version()}\n`);
70
+ return 0;
71
+ }
72
+ return undefined;
73
+ }
74
+ function parse(command, rest) {
75
+ try {
76
+ return parseArgs({
77
+ args: [...rest],
78
+ options: { ...COMMANDS[command].options, help: { type: "boolean", short: "h" } },
79
+ strict: true,
80
+ allowPositionals: false,
81
+ }).values;
82
+ }
83
+ catch (error) {
84
+ throw new UsageError(error.message);
85
+ }
86
+ }
87
+ function presetOf(values) {
88
+ const preset = values.preset ?? "raw";
89
+ if (!PRESETS.includes(preset)) {
90
+ throw new UsageError(`unknown preset ${JSON.stringify(preset)}; use ${PRESETS.slice(0, -1).join(", ")} or ${PRESETS.at(-1)}`);
91
+ }
92
+ return preset;
93
+ }
94
+ async function dispatch(command, values, io, ui) {
95
+ const runtime = io.runtime ?? detectRuntime();
96
+ const configPath = values.config;
97
+ const defaultVersion = values["default-version"];
98
+ if (command === "init") {
99
+ init({ cwd: io.cwd, preset: presetOf(values), force: values.force === true }, ui);
100
+ return 0;
101
+ }
102
+ if (command === "build") {
103
+ await build({ cwd: io.cwd, configPath, runtime, out: values.out, defaultVersion }, ui);
104
+ return 0;
105
+ }
106
+ const problems = await check({
107
+ cwd: io.cwd,
108
+ configPath,
109
+ runtime,
110
+ defaultVersion,
111
+ list: values.list === true,
112
+ ...(io.fetch ? { fetch: io.fetch } : {}),
113
+ }, ui);
114
+ return problems === 0 ? 0 : 1;
115
+ }
116
+ /** The whole CLI, in-process: every effect goes through `io`, so tests run it without spawning. Returns the exit code. */
117
+ export async function run(argv, io) {
118
+ const ui = createUi(io);
119
+ const [command, ...rest] = argv;
120
+ try {
121
+ if (command === undefined) {
122
+ io.stderr(HELP);
123
+ return 2;
124
+ }
125
+ const early = topLevel(command, io);
126
+ if (early !== undefined)
127
+ return early;
128
+ if (!isCommand(command))
129
+ throw new UsageError(`unknown command ${JSON.stringify(command)}`);
130
+ const values = parse(command, rest);
131
+ if (values.help) {
132
+ io.stdout(COMMANDS[command].usage);
133
+ return 0;
134
+ }
135
+ return await dispatch(command, values, io, ui);
136
+ }
137
+ catch (error) {
138
+ if (error instanceof UsageError) {
139
+ ui.error(error.message);
140
+ io.stderr("Run `installgen --help` for usage.\n");
141
+ return 2;
142
+ }
143
+ ui.error(error.message);
144
+ return 1;
145
+ }
146
+ }
147
+ export async function start(argv = process.argv.slice(2), proc = process) {
148
+ /* a reader that closes early (`| head`, `| grep -q`) is done listening: stop writing and leave quietly */
149
+ let closed = false;
150
+ /* EPIPE, or EOF where Windows reports a closed pipe that way */
151
+ const onError = (error) => {
152
+ if (error.code !== "EPIPE" && error.code !== "EOF")
153
+ throw error;
154
+ closed = true;
155
+ proc.exit(Number(proc.exitCode ?? 0));
156
+ };
157
+ proc.stdout.on("error", onError);
158
+ proc.stderr.on("error", onError);
159
+ const write = (stream) => (text) => {
160
+ if (!closed)
161
+ stream.write(text);
162
+ };
163
+ proc.exitCode = await run(argv, {
164
+ cwd: proc.cwd(),
165
+ env: proc.env,
166
+ stdout: write(proc.stdout),
167
+ stderr: write(proc.stderr),
168
+ isTTY: proc.stdout.isTTY === true,
169
+ });
170
+ }
@@ -0,0 +1,15 @@
1
+ import { type RuntimeInfo } from "../config/load.ts";
2
+ import type { ResolvedConfig } from "../config/types.ts";
3
+ import type { Ui } from "../ui.ts";
4
+ export interface ConfigOptions {
5
+ cwd: string;
6
+ configPath: string | undefined;
7
+ runtime: RuntimeInfo;
8
+ }
9
+ export declare function loadResolved(options: ConfigOptions): Promise<ResolvedConfig>;
10
+ export declare function warnUnverified(resolved: ResolvedConfig, ui: Ui): void;
11
+ export interface BuildOptions extends ConfigOptions {
12
+ out: string | undefined;
13
+ defaultVersion: string | undefined;
14
+ }
15
+ export declare function build(options: BuildOptions, ui: Ui): Promise<void>;
@@ -0,0 +1,34 @@
1
+ import { chmodSync, mkdirSync, writeFileSync } from "node:fs";
2
+ import { join, relative, resolve } from "node:path";
3
+ import { loadConfig } from "../config/load.js";
4
+ import { resolveConfig } from "../config/resolve.js";
5
+ import { render } from "../render/render.js";
6
+ export async function loadResolved(options) {
7
+ const { config } = await loadConfig({ cwd: options.cwd, configPath: options.configPath, runtime: options.runtime });
8
+ return resolveConfig(config);
9
+ }
10
+ export function warnUnverified(resolved, ui) {
11
+ if (resolved.platforms.every((p) => p.checksums === undefined)) {
12
+ ui.warn("no checksumsPath; the installers will not verify downloads (they show a warning row instead)");
13
+ }
14
+ }
15
+ export async function build(options, ui) {
16
+ const resolved = await loadResolved(options);
17
+ const out = render(resolved, { defaultVersion: options.defaultVersion });
18
+ const dir = resolve(options.cwd, options.out ?? resolved.outDir);
19
+ mkdirSync(dir, { recursive: true });
20
+ for (const [file, content, mode, reason] of [
21
+ ["install.sh", out.sh, 0o755, "no linux or darwin platforms"],
22
+ ["install.ps1", out.ps1, 0o644, "no windows platforms"],
23
+ ]) {
24
+ if (content === undefined) {
25
+ ui.info(` ${file} skipped: ${reason}`);
26
+ continue;
27
+ }
28
+ const path = join(dir, file);
29
+ writeFileSync(path, content);
30
+ chmodSync(path, mode);
31
+ ui.ok("wrote", relative(options.cwd, path));
32
+ }
33
+ warnUnverified(resolved, ui);
34
+ }
@@ -0,0 +1,10 @@
1
+ import type { Ui } from "../ui.ts";
2
+ import { type ConfigOptions } from "./build.ts";
3
+ export interface CheckOptions extends ConfigOptions {
4
+ defaultVersion: string | undefined;
5
+ list: boolean;
6
+ fetch?: typeof fetch;
7
+ }
8
+ /** `hash file`, `hash *file`, BSD `SHA256 (file) = hash`, or a file holding one bare hash. */
9
+ export declare function findChecksum(text: string, file: string): string | undefined;
10
+ export declare function check(options: CheckOptions, ui: Ui): Promise<number>;
@@ -0,0 +1,161 @@
1
+ import { InstallgenError } from "../errors.js";
2
+ import { loadResolved, warnUnverified } from "./build.js";
3
+ /* the same rules the scripts apply at install time */
4
+ const VERSION = /^[A-Za-z0-9._+-]+$/;
5
+ const TIMEOUT_MS = 15_000;
6
+ function expand(segments, version, tag) {
7
+ return segments.map((s) => (s.kind === "literal" ? s.value : s.kind === "version" ? version : tag)).join("");
8
+ }
9
+ /** `hash file`, `hash *file`, BSD `SHA256 (file) = hash`, or a file holding one bare hash. */
10
+ export function findChecksum(text, file) {
11
+ const lines = text.split(/\r?\n/).filter((l) => l.trim() !== "");
12
+ for (const line of lines) {
13
+ const fields = line.trim().split(/\s+/);
14
+ if (fields[0] === "SHA256" && fields[1] === `(${file})` && fields[2] === "=")
15
+ return fields[3];
16
+ if (fields.length >= 2 && fields[1]?.replace(/^\*/, "") === file)
17
+ return fields[0];
18
+ }
19
+ const only = lines.length === 1 ? lines[0]?.trim().split(/\s+/) : undefined;
20
+ return only?.length === 1 ? only[0] : undefined;
21
+ }
22
+ /* fetch rejects with a TypeError whose cause says why (ECONNREFUSED, a timeout) */
23
+ function failure(error) {
24
+ const e = error;
25
+ return e.cause instanceof Error ? `${e.message}: ${e.cause.message}` : e.message;
26
+ }
27
+ /** Strip whitespace and the tag prefix, then validate, as the scripts do. */
28
+ function normalize(raw, tagPrefix, what) {
29
+ let version = raw.replaceAll(/\s/g, "");
30
+ if (version.startsWith(tagPrefix))
31
+ version = version.slice(tagPrefix.length);
32
+ if (!VERSION.test(version))
33
+ throw new InstallgenError(`invalid ${what} version ${JSON.stringify(version)}`);
34
+ return version;
35
+ }
36
+ function probesFor(get) {
37
+ const sums = new Map();
38
+ return {
39
+ /* HEAD first; hosts that refuse it get a one-byte ranged GET */
40
+ async exists(url) {
41
+ try {
42
+ const head = await get(url, { method: "HEAD" });
43
+ if (head.ok)
44
+ return undefined;
45
+ const ranged = await get(url, { headers: { range: "bytes=0-0" } });
46
+ await ranged.arrayBuffer();
47
+ return ranged.ok ? undefined : `missing ${url} (${ranged.status})`;
48
+ }
49
+ catch (error) {
50
+ return `unreachable ${url}: ${failure(error)}`;
51
+ }
52
+ },
53
+ checksums(url) {
54
+ let probe = sums.get(url);
55
+ if (probe === undefined) {
56
+ probe = get(url).then(async (res) => res.ok ? { ok: true, body: await res.text() } : { ok: false, reason: `missing ${url} (${res.status})` }, (error) => ({ ok: false, reason: `unreachable ${url}: ${failure(error)}` }));
57
+ sums.set(url, probe);
58
+ }
59
+ return probe;
60
+ },
61
+ };
62
+ }
63
+ /** The checksum row of one platform: what it found, or undefined after reporting the problem. */
64
+ async function checksumRow(platform, checksums, asset, run) {
65
+ const { resolved, version, tag, probes, ui } = run;
66
+ const sumsUrl = `${resolved.baseUrl}/${expand(checksums, version, tag)}`;
67
+ const file = asset.slice(asset.lastIndexOf("/") + 1);
68
+ const probe = await probes.checksums(sumsUrl);
69
+ if (!probe.ok)
70
+ ui.bad(platform, probe.reason);
71
+ else if (findChecksum(probe.body, file) === undefined)
72
+ ui.bad(platform, `no checksum for ${file} in ${sumsUrl}`);
73
+ else
74
+ return "sha256 listed";
75
+ return undefined;
76
+ }
77
+ /** Checks one platform's files, reports each problem as a row, and returns how many there were. */
78
+ async function checkPlatform(p, run) {
79
+ const { resolved, version, tag, probes, ui } = run;
80
+ const asset = expand(p.asset, version, tag);
81
+ const assetUrl = `${resolved.baseUrl}/${asset}`;
82
+ const found = [];
83
+ let problems = 0;
84
+ const missing = await probes.exists(assetUrl);
85
+ if (missing === undefined)
86
+ found.push(assetUrl);
87
+ else {
88
+ problems++;
89
+ ui.bad(p.platform, missing);
90
+ }
91
+ if (p.checksums !== undefined) {
92
+ const row = await checksumRow(p.platform, p.checksums, asset, run);
93
+ if (row === undefined)
94
+ problems++;
95
+ else
96
+ found.push(row);
97
+ }
98
+ if (p.signature !== undefined) {
99
+ const missingBundle = await probes.exists(`${resolved.baseUrl}/${expand(p.signature.bundle, version, tag)}`);
100
+ if (missingBundle === undefined)
101
+ found.push("signature bundle");
102
+ else {
103
+ problems++;
104
+ ui.bad(p.platform, missingBundle);
105
+ }
106
+ }
107
+ const expected = 1 + (p.checksums === undefined ? 0 : 1) + (p.signature === undefined ? 0 : 1);
108
+ if (found.length === expected)
109
+ ui.ok(p.platform, found.join(", "));
110
+ return problems;
111
+ }
112
+ export async function check(options, ui) {
113
+ const resolved = await loadResolved(options);
114
+ const doFetch = options.fetch ?? fetch;
115
+ const get = (url, init = {}) => doFetch(url, { redirect: "follow", signal: AbortSignal.timeout(TIMEOUT_MS), ...init });
116
+ if (options.list) {
117
+ list(resolved, options.defaultVersion, ui);
118
+ return 0;
119
+ }
120
+ warnUnverified(resolved, ui);
121
+ const version = await resolveVersion(resolved, options.defaultVersion, get, ui);
122
+ const run = { resolved, version, tag: resolved.tagPrefix + version, probes: probesFor(get), ui };
123
+ let problems = 0;
124
+ for (const p of resolved.platforms)
125
+ problems += await checkPlatform(p, run);
126
+ if (problems === 0)
127
+ ui.info(`all ${resolved.platforms.length} platforms ok for ${version}`);
128
+ else
129
+ ui.info(`${problems} problem${problems === 1 ? "" : "s"}`);
130
+ return problems;
131
+ }
132
+ async function resolveVersion(resolved, defaultVersion, get, ui) {
133
+ if (defaultVersion !== undefined)
134
+ return normalize(defaultVersion, resolved.tagPrefix, "default");
135
+ const latestUrl = `${resolved.baseUrl}/${resolved.latestPath}`;
136
+ let res;
137
+ try {
138
+ res = await get(latestUrl);
139
+ }
140
+ catch (error) {
141
+ throw new InstallgenError(`could not read the latest version from ${latestUrl}: ${failure(error)}`);
142
+ }
143
+ if (!res.ok)
144
+ throw new InstallgenError(`could not read the latest version from ${latestUrl} (${res.status})`);
145
+ const version = normalize(await res.text(), resolved.tagPrefix, "latest");
146
+ ui.ok("latest", `${version} (${latestUrl})`);
147
+ return version;
148
+ }
149
+ function list(resolved, defaultVersion, ui) {
150
+ const version = defaultVersion === undefined ? "{version}" : normalize(defaultVersion, resolved.tagPrefix, "default");
151
+ const tag = defaultVersion === undefined ? "{tag}" : resolved.tagPrefix + version;
152
+ ui.info(`latest ${resolved.baseUrl}/${resolved.latestPath}`);
153
+ for (const p of resolved.platforms) {
154
+ ui.info(`${p.platform} ${resolved.baseUrl}/${expand(p.asset, version, tag)}`);
155
+ if (p.checksums !== undefined)
156
+ ui.info(`${p.platform} ${resolved.baseUrl}/${expand(p.checksums, version, tag)}`);
157
+ if (p.signature !== undefined) {
158
+ ui.info(`${p.platform} ${resolved.baseUrl}/${expand(p.signature.bundle, version, tag)}`);
159
+ }
160
+ }
161
+ }
@@ -0,0 +1,9 @@
1
+ import type { Ui } from "../ui.ts";
2
+ export declare const PRESETS: readonly ["raw", "goreleaser", "github"];
3
+ export type Preset = (typeof PRESETS)[number];
4
+ export interface InitOptions {
5
+ cwd: string;
6
+ preset: Preset;
7
+ force: boolean;
8
+ }
9
+ export declare function init(options: InitOptions, ui: Ui): void;
@@ -0,0 +1,32 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { CONFIG_FILES } from "../config/load.js";
4
+ import { InstallgenError } from "../errors.js";
5
+ export const PRESETS = ["raw", "goreleaser", "github"];
6
+ /** Node runs a .ts as CommonJS unless the nearest package.json says `"type": "module"`; .mts is always ESM. */
7
+ function isModuleProject(cwd) {
8
+ for (let dir = cwd;; dir = dirname(dir)) {
9
+ const pkg = join(dir, "package.json");
10
+ if (existsSync(pkg)) {
11
+ try {
12
+ return JSON.parse(readFileSync(pkg, "utf8")).type === "module";
13
+ }
14
+ catch {
15
+ return false;
16
+ }
17
+ }
18
+ if (dirname(dir) === dir)
19
+ return false;
20
+ }
21
+ }
22
+ export function init(options, ui) {
23
+ const existing = CONFIG_FILES.find((name) => existsSync(join(options.cwd, name)));
24
+ if (existing !== undefined && !options.force) {
25
+ throw new InstallgenError(`${existing} already exists; pass --force to overwrite it`);
26
+ }
27
+ const file = isModuleProject(options.cwd) ? "installgen.config.ts" : "installgen.config.mts";
28
+ const example = readFileSync(new URL(`../../../assets/installers/examples/${options.preset}.config.ts`, import.meta.url), "utf8");
29
+ writeFileSync(join(options.cwd, file), example);
30
+ ui.ok("wrote", `${file} (preset ${options.preset})`);
31
+ ui.info(`Set baseUrl and assetPath for your releases, then run \`installgen build\`.`);
32
+ }
@@ -0,0 +1,100 @@
1
+ /** An operating system the scripts install for, in Go's GOOS spelling. */
2
+ export type Os = "linux" | "darwin" | "windows";
3
+ /** A CPU architecture the scripts install for, in Go's GOARCH spelling. */
4
+ export type Arch = "amd64" | "arm64";
5
+ /** An `os/arch` pair, as `platforms` lists them (`"linux/amd64"`). */
6
+ export type Platform = `${Os}/${Arch}`;
7
+ export declare const VERSION_SENTINEL = "__InstallGen_Version__";
8
+ export declare const TAG_SENTINEL = "__InstallGen_Tag__";
9
+ declare const versionBrand: unique symbol;
10
+ declare const tagBrand: unique symbol;
11
+ /** The release version without the tag prefix (`1.2.3`). Interpolate it; the script fills it in at install time. */
12
+ export interface VersionToken {
13
+ /** Yields a placeholder the build swaps for the script's version variable; a string method on it is refused. */
14
+ readonly [Symbol.toPrimitive]: (hint: string) => string;
15
+ readonly [versionBrand]: true;
16
+ }
17
+ /** The release tag, `tagPrefix` + version (`v1.2.3`). Interpolate it; the script fills it in at install time. */
18
+ export interface TagToken {
19
+ /** Yields a placeholder the build swaps for the script's tag variable; a string method on it is refused. */
20
+ readonly [Symbol.toPrimitive]: (hint: string) => string;
21
+ readonly [tagBrand]: true;
22
+ }
23
+ /** What a path function gets: the tokens to interpolate, and the platform it is called for (once per platform). */
24
+ export interface PathContext {
25
+ /** The version being installed, filled in at install time. */
26
+ readonly version: VersionToken;
27
+ /** The tag being installed, filled in at install time. */
28
+ readonly tag: TagToken;
29
+ /** The platform's operating system. */
30
+ readonly os: Os;
31
+ /** The platform's architecture. */
32
+ readonly arch: Arch;
33
+ }
34
+ /** What `checksumsPath` gets: the path context plus the asset it lists. */
35
+ export interface ChecksumsContext extends PathContext {
36
+ /** The asset path `assetPath` returned for this platform. */
37
+ readonly asset: string;
38
+ }
39
+ /** What `signature.bundlePath` gets: the checksums context plus the checksums file it signs. */
40
+ export interface BundleContext extends ChecksumsContext {
41
+ /** The checksums path `checksumsPath` returned for this platform. */
42
+ readonly checksums: string;
43
+ }
44
+ /** A keyless sigstore signature on the checksums file, checked by `cosign verify-blob` when cosign is on PATH. */
45
+ export interface SignatureConfig {
46
+ /**
47
+ * The certificate identity the bundle must carry, matched exactly: an https URL. Interpolate `tag` to bind it to the
48
+ * release, e.g. `https://github.com/o/r/.github/workflows/release.yml@refs/tags/${tag}`.
49
+ */
50
+ identity: (ctx: PathContext) => string;
51
+ /** The OIDC issuer the certificate must carry. Default `"https://token.actions.githubusercontent.com"`. */
52
+ issuer?: string;
53
+ /** The sigstore bundle of the checksums file, per platform. Default: the checksums path + `.sigstore.json`. */
54
+ bundlePath?: (ctx: BundleContext) => string;
55
+ }
56
+ /** Where the two scripts are served: https, or http on loopback. The scripts print these in their hints. */
57
+ export interface ScriptUrls {
58
+ /** The URL users pipe to `sh`. */
59
+ sh: string;
60
+ /** The URL users pipe to `iex`. */
61
+ ps1: string;
62
+ }
63
+ /** An `installgen.config.ts` default export: where a release's files live and how the scripts install them. */
64
+ export interface InstallgenConfig {
65
+ /** The binary name, `^[A-Za-z0-9][A-Za-z0-9._-]*$`. */
66
+ name: string;
67
+ /** Where the files live. https only; loopback http is allowed for tests. */
68
+ baseUrl: string;
69
+ /** The asset path under `baseUrl`, per platform. Must contain `version` or `tag`. */
70
+ assetPath: (ctx: PathContext) => string;
71
+ /** Default: all six. */
72
+ platforms?: readonly Platform[];
73
+ /** A shared `checksums.txt` or a per-asset `<asset>.sha256`, per platform. Unset: no verification. */
74
+ checksumsPath?: (ctx: ChecksumsContext) => string;
75
+ /** Verify the checksums file's signature before its hashes. Needs `checksumsPath`. Unset: no signature check. */
76
+ signature?: SignatureConfig;
77
+ /** The file holding the latest version. Default `"latest"`. */
78
+ latestPath?: string;
79
+ /** The binary's path inside an archive. Default: search the extracted tree. */
80
+ binaryInArchive?: (ctx: PathContext) => string;
81
+ /** Default `"v"`. */
82
+ tagPrefix?: string;
83
+ /** Must start with `~/`. Default `"~/.<name>/bin"`. */
84
+ installDir?: string;
85
+ /** Prefix of the end-user overrides. Default: `name` uppercased, non-alphanumerics → `_`. */
86
+ envPrefix?: string;
87
+ /** Default `true`. */
88
+ modifyPath?: boolean;
89
+ /** Printed after a successful install. */
90
+ message?: string;
91
+ /** Where the scripts are served. Default `baseUrl/install.sh` and `baseUrl/install.ps1`. */
92
+ scriptUrls?: ScriptUrls;
93
+ /** Default `"installers"`. */
94
+ outDir?: string;
95
+ }
96
+ /** Returns `config` unchanged; it is there so an untyped config file still gets the config's types. */
97
+ export declare function defineConfig(config: InstallgenConfig): InstallgenConfig;
98
+ export declare const versionToken: VersionToken;
99
+ export declare const tagToken: TagToken;
100
+ export {};
@@ -0,0 +1,10 @@
1
+ /* Mixed case, so toUpperCase and toLowerCase both change it and the build reports the call as mangled. */
2
+ export const VERSION_SENTINEL = "__InstallGen_Version__";
3
+ export const TAG_SENTINEL = "__InstallGen_Tag__";
4
+ /** Returns `config` unchanged; it is there so an untyped config file still gets the config's types. */
5
+ export function defineConfig(config) {
6
+ return config;
7
+ }
8
+ const token = (sentinel) => Object.freeze({ [Symbol.toPrimitive]: () => sentinel });
9
+ export const versionToken = /* @__PURE__ */ token(VERSION_SENTINEL);
10
+ export const tagToken = /* @__PURE__ */ token(TAG_SENTINEL);
@@ -0,0 +1,21 @@
1
+ export interface BunBuild {
2
+ module(specifier: string, load: () => {
3
+ exports: Record<string, unknown>;
4
+ loader: "object";
5
+ }): void;
6
+ }
7
+ export interface BunPlugin {
8
+ name: string;
9
+ setup(build: BunBuild): void | Promise<void>;
10
+ }
11
+ /** The slice of the `Bun` global the loader uses. */
12
+ export interface BunLike {
13
+ plugin(plugin: BunPlugin): void;
14
+ }
15
+ type Importer = (url: string) => Promise<Record<string, unknown>>;
16
+ /**
17
+ * Bun's `onResolve` never sees the imports a runtime-loaded config makes; `build.module` does. The config's import of
18
+ * `specifier` becomes a virtual module holding the exports of the running package's entry `selfUrl`.
19
+ */
20
+ export declare function registerBunHook(bun: BunLike, specifier: string, selfUrl: string, importModule?: Importer): Promise<void>;
21
+ export {};
@@ -0,0 +1,21 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ /**
10
+ * Bun's `onResolve` never sees the imports a runtime-loaded config makes; `build.module` does. The config's import of
11
+ * `specifier` becomes a virtual module holding the exports of the running package's entry `selfUrl`.
12
+ */
13
+ export async function registerBunHook(bun, specifier, selfUrl, importModule = (url) => import(__rewriteRelativeImportExtension(url))) {
14
+ const exports = await importModule(selfUrl);
15
+ bun.plugin({
16
+ name: `self:${specifier}`,
17
+ setup(build) {
18
+ build.module(specifier, () => ({ exports, loader: "object" }));
19
+ },
20
+ });
21
+ }
@@ -0,0 +1,9 @@
1
+ import module from "node:module";
2
+ export type RegisterHooks = typeof module.registerHooks;
3
+ /**
4
+ * Maps a config's import of `specifier` (`@workerstack/clients/installers`, `@workerstack/clients/release`) to the
5
+ * running package's entry `selfUrl`, so a config in a project without a local install (zero-install `bunx`) still
6
+ * resolves. `module.register` is deprecated on Node 26 (DEP0205).
7
+ * Reached through the default export: Bun's `node:module` has no `registerHooks`, and a named import would fail to link.
8
+ */
9
+ export declare function registerNodeHook(specifier: string, selfUrl: string, register?: RegisterHooks): ReturnType<RegisterHooks>;
@@ -0,0 +1,16 @@
1
+ import module from "node:module";
2
+ /**
3
+ * Maps a config's import of `specifier` (`@workerstack/clients/installers`, `@workerstack/clients/release`) to the
4
+ * running package's entry `selfUrl`, so a config in a project without a local install (zero-install `bunx`) still
5
+ * resolves. `module.register` is deprecated on Node 26 (DEP0205).
6
+ * Reached through the default export: Bun's `node:module` has no `registerHooks`, and a named import would fail to link.
7
+ */
8
+ export function registerNodeHook(specifier, selfUrl, register = module.registerHooks) {
9
+ return register({
10
+ resolve(imported, context, nextResolve) {
11
+ if (imported === specifier)
12
+ return { url: selfUrl, shortCircuit: true };
13
+ return nextResolve(imported, context);
14
+ },
15
+ });
16
+ }