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

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 +48 -0
  72. package/dist/release/registries.js +246 -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,97 @@
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
+ import { existsSync } from "node:fs";
10
+ import { basename, extname, join, resolve } from "node:path";
11
+ import { pathToFileURL } from "node:url";
12
+ import { InstallgenError } from "../errors.js";
13
+ import { registerBunHook } from "./hooks/bun.js";
14
+ import { registerNodeHook } from "./hooks/node.js";
15
+ /** The specifier an installgen config imports `defineConfig` from, resolved to the running package. */
16
+ export const INSTALLERS_SPECIFIER = "@workerstack/clients/installers";
17
+ export const CONFIG_FILES = [
18
+ "installgen.config.ts",
19
+ "installgen.config.mts",
20
+ "installgen.config.js",
21
+ "installgen.config.mjs",
22
+ ];
23
+ export function detectRuntime(scope = globalThis, nodeVersion = process.versions.node) {
24
+ return scope.Bun ? { runtime: "bun", nodeVersion, bun: scope.Bun } : { runtime: "node", nodeVersion };
25
+ }
26
+ /* Node strips types from .ts without a flag from 22.18, and on 23 from 23.6 */
27
+ const CJS_SYNTAX = /Unexpected token 'export'|Cannot use import statement outside a module/;
28
+ function find(cwd, configPath) {
29
+ if (configPath !== undefined) {
30
+ const path = resolve(cwd, configPath);
31
+ if (!existsSync(path))
32
+ throw new InstallgenError(`config file not found: ${path}`);
33
+ return path;
34
+ }
35
+ for (const name of CONFIG_FILES) {
36
+ const path = join(cwd, name);
37
+ if (existsSync(path))
38
+ return path;
39
+ }
40
+ throw new InstallgenError(`no installgen.config.{ts,mts,js,mjs} in ${cwd}; run \`installgen init\`, or pass -c <path>`);
41
+ }
42
+ /** Whether Node `version` imports a `.ts` module natively: from 22.18, and on 23 from 23.6. */
43
+ export function stripsTypes(version) {
44
+ const [major = 0, minor = 0] = version.split(".").map(Number);
45
+ if (major === 22)
46
+ return minor >= 18;
47
+ if (major === 23)
48
+ return minor >= 6;
49
+ return major > 23;
50
+ }
51
+ /** Node before 22.18 (23.6 on 23) cannot import a .ts config: say so before the import fails obscurely. */
52
+ function assertStripsTypes(runtime, ext) {
53
+ if (runtime.runtime === "node" && (ext === ".ts" || ext === ".mts") && !stripsTypes(runtime.nodeVersion)) {
54
+ throw new InstallgenError(`a TypeScript config needs Node >= 22.18 (23.6 on Node 23; this is ${runtime.nodeVersion}); ` +
55
+ "run `bunx --bun --package @workerstack/clients installgen` instead, or upgrade Node");
56
+ }
57
+ }
58
+ /** The error a failed config import becomes: a rename hint when Node read an ESM config as CommonJS. */
59
+ function loadError(path, error) {
60
+ const ext = extname(path);
61
+ const message = error instanceof Error ? error.message : String(error);
62
+ if (CJS_SYNTAX.test(message) && (ext === ".ts" || ext === ".js")) {
63
+ const rename = `${basename(path, ext)}.m${ext.slice(1)}`;
64
+ return new InstallgenError(`${path} was loaded as CommonJS: the nearest package.json has no "type": "module"; rename it to ${rename}`, { cause: error });
65
+ }
66
+ return new InstallgenError(`failed to load ${path}: ${message}`, { cause: error });
67
+ }
68
+ export async function loadConfig(options) {
69
+ const path = find(options.cwd, options.configPath);
70
+ const ext = extname(path);
71
+ const { runtime } = options;
72
+ const importModule = options.importModule ?? ((url) => import(__rewriteRelativeImportExtension(url)));
73
+ /* the sibling entry in this module's own form: index.ts from a checkout's source, index.js from an install */
74
+ const selfUrl = options.selfUrl ?? new URL(`../index${extname(new URL(import.meta.url).pathname)}`, import.meta.url).href;
75
+ assertStripsTypes(runtime, ext);
76
+ /* Bun's plugin stays for the process; Node's hook goes once the config is imported */
77
+ let hook;
78
+ if (runtime.bun)
79
+ await registerBunHook(runtime.bun, INSTALLERS_SPECIFIER, selfUrl, importModule);
80
+ else
81
+ hook = registerNodeHook(INSTALLERS_SPECIFIER, selfUrl, options.registerHooks);
82
+ let mod;
83
+ try {
84
+ mod = await importModule(pathToFileURL(path).href);
85
+ }
86
+ catch (error) {
87
+ throw loadError(path, error);
88
+ }
89
+ finally {
90
+ hook?.deregister();
91
+ }
92
+ const config = mod.default;
93
+ if (typeof config !== "object" || config === null) {
94
+ throw new InstallgenError(`${path} has no default export; write \`export default defineConfig({ ... })\``);
95
+ }
96
+ return { path, config: config };
97
+ }
@@ -0,0 +1,4 @@
1
+ import { type InstallgenConfig, type Platform } from "./define-config.ts";
2
+ import type { ResolvedConfig } from "./types.ts";
3
+ export declare const ALL_PLATFORMS: readonly Platform[];
4
+ export declare function resolveConfig(input: InstallgenConfig): ResolvedConfig;
@@ -0,0 +1,281 @@
1
+ import { InstallgenError } from "../errors.js";
2
+ import { TAG_SENTINEL, VERSION_SENTINEL, tagToken, versionToken, } from "./define-config.js";
3
+ export const ALL_PLATFORMS = [
4
+ "linux/amd64",
5
+ "linux/arm64",
6
+ "darwin/amd64",
7
+ "darwin/arm64",
8
+ "windows/amd64",
9
+ "windows/arm64",
10
+ ];
11
+ const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
12
+ const ENV_PREFIX = /^[A-Z_][A-Z0-9_]*$/;
13
+ const TAG_PREFIX = /^[A-Za-z0-9._-]*$/;
14
+ /* Each segment of installDir after ~/: rendered into sh and ps1 paths and shell profile lines */
15
+ const DIR_SEGMENT = /^[A-Za-z0-9._ -]+$/;
16
+ const SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*:/;
17
+ const LOOPBACK = ["127.0.0.1", "localhost", "[::1]"];
18
+ const MANGLED = /installgen(version|tag)/;
19
+ /* the issuer of the OIDC token a GitHub Actions run signs with */
20
+ const GITHUB_ACTIONS_ISSUER = "https://token.actions.githubusercontent.com";
21
+ const fail = (message) => {
22
+ throw new InstallgenError(message);
23
+ };
24
+ function string(config, key, scope = "config") {
25
+ const value = config[key];
26
+ if (value === undefined)
27
+ return undefined;
28
+ return typeof value === "string" ? value : fail(`${scope}.${key} must be a string`);
29
+ }
30
+ function required(value, key, kind) {
31
+ return value ?? fail(`config.${key} must be ${kind}`);
32
+ }
33
+ function func(config, key, scope = "config") {
34
+ const value = config[key];
35
+ if (value === undefined)
36
+ return undefined;
37
+ return typeof value === "function" ? value : fail(`${scope}.${key} must be a function`);
38
+ }
39
+ /** https, or http on loopback; returns whether it is https. */
40
+ function checkUrl(field, url) {
41
+ let parsed;
42
+ try {
43
+ parsed = new URL(url);
44
+ }
45
+ catch {
46
+ // reported below
47
+ }
48
+ if (parsed?.protocol === "https:" && parsed.host !== "")
49
+ return true;
50
+ if (parsed?.protocol === "http:" && LOOPBACK.includes(parsed.hostname))
51
+ return false;
52
+ return fail(`config.${field} must be an https URL (http is allowed only on loopback), got ${JSON.stringify(url)}`);
53
+ }
54
+ function checkRelative(field, path) {
55
+ if (path === "" || path.startsWith("/") || SCHEME.test(path)) {
56
+ fail(`config.${field} must be a path relative to baseUrl, got ${JSON.stringify(path)}`);
57
+ }
58
+ }
59
+ function noSentinel(field, value) {
60
+ if (value?.includes(VERSION_SENTINEL) || value?.includes(TAG_SENTINEL)) {
61
+ fail(`config.${field} cannot hold a version or tag token; only path functions can`);
62
+ }
63
+ }
64
+ /** Splits on the exact sentinels; a sentinel a string method rewrote is still recognizable in a literal piece. */
65
+ function split(field, platform, path) {
66
+ const segments = [];
67
+ for (const piece of path.split(new RegExp(`(${VERSION_SENTINEL}|${TAG_SENTINEL})`))) {
68
+ if (piece === VERSION_SENTINEL)
69
+ segments.push({ kind: "version" });
70
+ else if (piece === TAG_SENTINEL)
71
+ segments.push({ kind: "tag" });
72
+ else if (piece !== "") {
73
+ if (MANGLED.test(piece.toLowerCase().replace(/[^a-z0-9]/g, ""))) {
74
+ fail(`config.${field} for ${platform} returned a mangled version or tag token (${JSON.stringify(path)}); ` +
75
+ "interpolate it as-is, without string methods");
76
+ }
77
+ segments.push({ kind: "literal", value: piece });
78
+ }
79
+ }
80
+ return segments;
81
+ }
82
+ /* A certificate identity is matched, never fetched: https only, loopback included */
83
+ function checkIdentity(field, identity) {
84
+ let parsed;
85
+ try {
86
+ parsed = new URL(identity);
87
+ }
88
+ catch {
89
+ // reported below
90
+ }
91
+ if (parsed?.protocol !== "https:" || parsed.host === "") {
92
+ fail(`config.${field} must return an https URL, got ${JSON.stringify(identity)}`);
93
+ }
94
+ }
95
+ function evaluate(field, fn, ctx, check = checkRelative) {
96
+ const out = fn(ctx);
97
+ if (typeof out !== "string")
98
+ return fail(`config.${field} must return a string, got ${typeof out} for ${ctx.os}/${ctx.arch}`);
99
+ check(field, out);
100
+ return out;
101
+ }
102
+ function signatureOf(config, signed) {
103
+ const value = config.signature;
104
+ if (value === undefined)
105
+ return undefined;
106
+ if (typeof value !== "object" || value === null)
107
+ return fail("config.signature must be an object");
108
+ if (!signed)
109
+ fail("config.signature needs config.checksumsPath: the signature is on the checksums file");
110
+ const raw = value;
111
+ const scope = "config.signature";
112
+ const identity = required(func(raw, "identity", scope), "signature.identity", "a function");
113
+ const bundlePath = func(raw, "bundlePath", scope);
114
+ const issuer = string(raw, "issuer", scope) ?? GITHUB_ACTIONS_ISSUER;
115
+ noSentinel("signature.issuer", issuer);
116
+ if (!checkUrl("signature.issuer", issuer))
117
+ fail(`config.signature.issuer must be an https URL, got ${JSON.stringify(issuer)}`);
118
+ return { identity, bundlePath, issuer };
119
+ }
120
+ function formatOf(asset) {
121
+ const tail = asset.toLowerCase();
122
+ if (tail.endsWith(".tar.gz") || tail.endsWith(".tgz"))
123
+ return "tar.gz";
124
+ if (tail.endsWith(".zip"))
125
+ return "zip";
126
+ return "raw";
127
+ }
128
+ function platformsOf(config) {
129
+ const value = config.platforms;
130
+ if (value === undefined)
131
+ return ALL_PLATFORMS;
132
+ if (!Array.isArray(value))
133
+ return fail("config.platforms must be an array");
134
+ if (value.length === 0)
135
+ fail("config.platforms must list at least one platform");
136
+ const seen = new Set();
137
+ for (const p of value) {
138
+ if (!ALL_PLATFORMS.includes(p)) {
139
+ fail(`config.platforms has unknown platform ${JSON.stringify(p)}; use one of ${ALL_PLATFORMS.join(", ")}`);
140
+ }
141
+ if (seen.has(p))
142
+ fail(`config.platforms lists ${p} twice`);
143
+ seen.add(p);
144
+ }
145
+ return value;
146
+ }
147
+ const key = (segments) => segments.map((s) => (s.kind === "literal" ? `L${s.value}` : s.kind)).join("\0");
148
+ const osOf = (platform) => platform.split("/")[0];
149
+ /* GoReleaser universal_binaries: one asset serves both macOS architectures */
150
+ const universal = (a, b) => osOf(a) === "darwin" && osOf(b) === "darwin";
151
+ function pathFunctionsOf(config) {
152
+ const assetPath = required(func(config, "assetPath"), "assetPath", "a function");
153
+ const checksumsPath = func(config, "checksumsPath");
154
+ const signature = signatureOf(config, checksumsPath !== undefined);
155
+ const binaryInArchive = func(config, "binaryInArchive");
156
+ return { assetPath, checksumsPath, signature, binaryInArchive };
157
+ }
158
+ function tagPrefixOf(config) {
159
+ const tagPrefix = string(config, "tagPrefix") ?? "v";
160
+ if (!TAG_PREFIX.test(tagPrefix))
161
+ fail(`config.tagPrefix must match ${TAG_PREFIX.source}, got ${JSON.stringify(tagPrefix)}`);
162
+ return tagPrefix;
163
+ }
164
+ function installDirOf(config, name) {
165
+ const installDir = string(config, "installDir") ?? `~/.${name}/bin`;
166
+ const dirSegments = installDir.split("/").slice(1);
167
+ if (!installDir.startsWith("~/") ||
168
+ !dirSegments.every((seg) => DIR_SEGMENT.test(seg) && seg !== "." && seg !== "..")) {
169
+ fail(`config.installDir must be ~/ followed by directory names of letters, digits, space, ".", "_" or "-" ` +
170
+ `(no "." or ".." segments), got ${JSON.stringify(installDir)}`);
171
+ }
172
+ return installDir;
173
+ }
174
+ function envPrefixOf(config, name) {
175
+ const derived = name.toUpperCase().replace(/[^A-Z0-9]/g, "_");
176
+ const envPrefix = string(config, "envPrefix") ?? (/^[0-9]/.test(derived) ? `_${derived}` : derived);
177
+ if (!ENV_PREFIX.test(envPrefix))
178
+ fail(`config.envPrefix must match ${ENV_PREFIX.source}, got ${JSON.stringify(envPrefix)}`);
179
+ return envPrefix;
180
+ }
181
+ function outDirOf(config) {
182
+ const outDir = string(config, "outDir") ?? "installers";
183
+ if (outDir === "")
184
+ fail("config.outDir must not be empty");
185
+ return outDir;
186
+ }
187
+ function scriptUrlsOf(config, baseUrl) {
188
+ if (config.scriptUrls === undefined)
189
+ return { sh: `${baseUrl}/install.sh`, ps1: `${baseUrl}/install.ps1` };
190
+ if (typeof config.scriptUrls !== "object" || config.scriptUrls === null)
191
+ fail("config.scriptUrls must be an object");
192
+ const urls = config.scriptUrls;
193
+ const sh = required(string(urls, "sh"), "scriptUrls.sh", "a string");
194
+ const ps1 = required(string(urls, "ps1"), "scriptUrls.ps1", "a string");
195
+ checkUrl("scriptUrls.sh", sh);
196
+ checkUrl("scriptUrls.ps1", ps1);
197
+ return { sh, ps1 };
198
+ }
199
+ /** The settings after the path functions, validated in the order a config's errors are reported. */
200
+ function settingsOf(config, name, baseUrl) {
201
+ const latestPath = string(config, "latestPath") ?? "latest";
202
+ checkRelative("latestPath", latestPath);
203
+ const tagPrefix = tagPrefixOf(config);
204
+ const installDir = installDirOf(config, name);
205
+ const envPrefix = envPrefixOf(config, name);
206
+ const modifyPathRaw = config.modifyPath ?? true;
207
+ const modifyPath = typeof modifyPathRaw === "boolean" ? modifyPathRaw : fail("config.modifyPath must be a boolean");
208
+ const message = string(config, "message");
209
+ const outDir = outDirOf(config);
210
+ const scriptUrls = scriptUrlsOf(config, baseUrl);
211
+ for (const [field, value] of [
212
+ ["name", name],
213
+ ["baseUrl", baseUrl],
214
+ ["latestPath", latestPath],
215
+ ["tagPrefix", tagPrefix],
216
+ ["installDir", installDir],
217
+ ["envPrefix", envPrefix],
218
+ ["message", message],
219
+ ["outDir", outDir],
220
+ ["scriptUrls.sh", scriptUrls.sh],
221
+ ["scriptUrls.ps1", scriptUrls.ps1],
222
+ ]) {
223
+ noSentinel(field, value);
224
+ }
225
+ return { latestPath, tagPrefix, installDir, envPrefix, modifyPath, message, outDir, scriptUrls };
226
+ }
227
+ function resolveSignature(signature, ctx, checksumsRaw) {
228
+ const platform = `${ctx.os}/${ctx.arch}`;
229
+ const bundleRaw = signature.bundlePath
230
+ ? evaluate("signature.bundlePath", signature.bundlePath, { ...ctx, checksums: checksumsRaw })
231
+ : `${checksumsRaw}.sigstore.json`;
232
+ const { asset: _, ...pathCtx } = ctx;
233
+ return {
234
+ bundle: split("signature.bundlePath", platform, bundleRaw),
235
+ identity: split("signature.identity", platform, evaluate("signature.identity", signature.identity, pathCtx, checkIdentity)),
236
+ issuer: signature.issuer,
237
+ };
238
+ }
239
+ function resolvePlatform(platform, fns, assets) {
240
+ const [os, arch] = platform.split("/");
241
+ const ctx = { version: versionToken, tag: tagToken, os, arch };
242
+ const assetRaw = evaluate("assetPath", fns.assetPath, ctx);
243
+ const asset = split("assetPath", platform, assetRaw);
244
+ if (asset.every((s) => s.kind === "literal")) {
245
+ fail(`config.assetPath for ${platform} must contain the version or tag token, got ${JSON.stringify(assetRaw)}`);
246
+ }
247
+ const prior = assets.get(key(asset));
248
+ if (prior !== undefined && !universal(prior, platform)) {
249
+ fail(`config.assetPath gives ${prior} and ${platform} the same asset ${JSON.stringify(assetRaw)}`);
250
+ }
251
+ assets.set(key(asset), platform);
252
+ const checksumsRaw = fns.checksumsPath && evaluate("checksumsPath", fns.checksumsPath, { ...ctx, asset: assetRaw });
253
+ const signature = fns.signature && checksumsRaw !== undefined
254
+ ? resolveSignature(fns.signature, { ...ctx, asset: assetRaw }, checksumsRaw)
255
+ : undefined;
256
+ return {
257
+ platform,
258
+ os,
259
+ arch,
260
+ asset,
261
+ format: formatOf(assetRaw),
262
+ checksums: checksumsRaw === undefined ? undefined : split("checksumsPath", platform, checksumsRaw),
263
+ signature,
264
+ binaryInArchive: fns.binaryInArchive && split("binaryInArchive", platform, evaluate("binaryInArchive", fns.binaryInArchive, ctx)),
265
+ };
266
+ }
267
+ export function resolveConfig(input) {
268
+ if (typeof input !== "object" || input === null)
269
+ return fail("config must be an object");
270
+ const config = input;
271
+ const name = required(string(config, "name"), "name", "a string");
272
+ if (!NAME.test(name))
273
+ fail(`config.name must match ${NAME.source}, got ${JSON.stringify(name)}`);
274
+ const baseUrl = required(string(config, "baseUrl"), "baseUrl", "a string").replace(/\/+$/, "");
275
+ const https = checkUrl("baseUrl", baseUrl);
276
+ const fns = pathFunctionsOf(config);
277
+ const settings = settingsOf(config, name, baseUrl);
278
+ const assets = new Map();
279
+ const platforms = platformsOf(config).map((platform) => resolvePlatform(platform, fns, assets));
280
+ return { name, baseUrl, https, ...settings, installDir: settings.installDir.slice(2), platforms };
281
+ }
@@ -0,0 +1,45 @@
1
+ import type { Arch, Os, Platform } from "./define-config.ts";
2
+ /** A path split on the sentinels: literal text, and the places the script puts the version or the tag. */
3
+ export type Segment = {
4
+ readonly kind: "literal";
5
+ readonly value: string;
6
+ } | {
7
+ readonly kind: "version";
8
+ } | {
9
+ readonly kind: "tag";
10
+ };
11
+ export type Format = "tar.gz" | "zip" | "raw";
12
+ export interface ResolvedSignature {
13
+ readonly bundle: readonly Segment[];
14
+ readonly identity: readonly Segment[];
15
+ readonly issuer: string;
16
+ }
17
+ export interface ResolvedPlatform {
18
+ readonly platform: Platform;
19
+ readonly os: Os;
20
+ readonly arch: Arch;
21
+ readonly asset: readonly Segment[];
22
+ readonly format: Format;
23
+ readonly checksums: readonly Segment[] | undefined;
24
+ readonly signature: ResolvedSignature | undefined;
25
+ readonly binaryInArchive: readonly Segment[] | undefined;
26
+ }
27
+ export interface ResolvedConfig {
28
+ readonly name: string;
29
+ /** No trailing slash. */
30
+ readonly baseUrl: string;
31
+ readonly https: boolean;
32
+ readonly latestPath: string;
33
+ readonly tagPrefix: string;
34
+ /** Relative to the home directory: `~/` is stripped. */
35
+ readonly installDir: string;
36
+ readonly envPrefix: string;
37
+ readonly modifyPath: boolean;
38
+ readonly message: string | undefined;
39
+ readonly scriptUrls: {
40
+ readonly sh: string;
41
+ readonly ps1: string;
42
+ };
43
+ readonly outDir: string;
44
+ readonly platforms: readonly ResolvedPlatform[];
45
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ /** A user-facing error: the CLI prints its message without a stack. */
2
+ export declare class InstallgenError extends Error {
3
+ /** Always `"InstallgenError"`, so a caught error is told apart from any other by name across realms. */
4
+ name: string;
5
+ }
@@ -0,0 +1,5 @@
1
+ /** A user-facing error: the CLI prints its message without a stack. */
2
+ export class InstallgenError extends Error {
3
+ /** Always `"InstallgenError"`, so a caught error is told apart from any other by name across realms. */
4
+ name = "InstallgenError";
5
+ }
@@ -0,0 +1,11 @@
1
+ import type { InstallgenConfig } from "./config/define-config.ts";
2
+ import { type Rendered, type RenderOptions } from "./render/render.ts";
3
+ export { defineConfig } from "./config/define-config.ts";
4
+ export type { Arch, BundleContext, ChecksumsContext, InstallgenConfig, Os, PathContext, Platform, ScriptUrls, SignatureConfig, TagToken, VersionToken, } from "./config/define-config.ts";
5
+ export { InstallgenError } from "./errors.ts";
6
+ export type { Rendered, RenderOptions } from "./render/render.ts";
7
+ /**
8
+ * `install.sh` and `install.ps1` for `config`, exactly as `installgen build` writes them, for a tool that places the
9
+ * files itself; a script is absent when no platform needs it. Throws `InstallgenError` on a config `build` refuses.
10
+ */
11
+ export declare function generateInstallers(config: InstallgenConfig, options?: RenderOptions): Rendered;
@@ -0,0 +1,11 @@
1
+ import { resolveConfig } from "./config/resolve.js";
2
+ import { render } from "./render/render.js";
3
+ export { defineConfig } from "./config/define-config.js";
4
+ export { InstallgenError } from "./errors.js";
5
+ /**
6
+ * `install.sh` and `install.ps1` for `config`, exactly as `installgen build` writes them, for a tool that places the
7
+ * files itself; a script is absent when no platform needs it. Throws `InstallgenError` on a config `build` refuses.
8
+ */
9
+ export function generateInstallers(config, options = {}) {
10
+ return render(resolveConfig(config), options);
11
+ }
@@ -0,0 +1,7 @@
1
+ import type { Segment } from "../config/types.ts";
2
+ /** One sh word: adjacent quoted pieces, so no separator is needed. */
3
+ export declare function shWord(segments: readonly Segment[]): string;
4
+ /** One PowerShell expression of type string. */
5
+ export declare function psString(segments: readonly Segment[]): string;
6
+ export declare const shLiteral: (value: string) => string;
7
+ export declare const psLiteral: (value: string) => string;
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Literals are single-quoted, where neither shell expands anything; the tokens become the scripts' own variables.
3
+ * sh: `$version` / `$tag`. ps1: `$ver` / `$tag` (PowerShell names are case-insensitive, so `$version` would be the
4
+ * `-Version` parameter).
5
+ */
6
+ /** One sh word: adjacent quoted pieces, so no separator is needed. */
7
+ export function shWord(segments) {
8
+ if (segments.length === 0)
9
+ return "''";
10
+ return segments
11
+ .map((s) => {
12
+ if (s.kind === "version")
13
+ return '"$version"';
14
+ if (s.kind === "tag")
15
+ return '"$tag"';
16
+ return `'${s.value.replaceAll("'", "'\\''")}'`;
17
+ })
18
+ .join("");
19
+ }
20
+ /** One PowerShell expression of type string. */
21
+ export function psString(segments) {
22
+ if (segments.length === 0)
23
+ return "''";
24
+ const parts = segments.map((s) => {
25
+ if (s.kind === "version")
26
+ return "$ver";
27
+ if (s.kind === "tag")
28
+ return "$tag";
29
+ return `'${s.value.replaceAll("'", "''")}'`;
30
+ });
31
+ return parts.length === 1 ? parts[0] : `(${parts.join(" + ")})`;
32
+ }
33
+ export const shLiteral = (value) => shWord([{ kind: "literal", value }]);
34
+ export const psLiteral = (value) => psString([{ kind: "literal", value }]);
@@ -0,0 +1,24 @@
1
+ import type { ResolvedConfig } from "../config/types.ts";
2
+ /** How `generateInstallers` renders beyond the config itself. */
3
+ export interface RenderOptions {
4
+ /** Baked in as the version to install when neither the argument nor `<PREFIX>_VERSION` names one. */
5
+ defaultVersion?: string | undefined;
6
+ }
7
+ export interface Templates {
8
+ sh: string;
9
+ ps1: string;
10
+ }
11
+ /** The scripts a config needs: each is absent when none of its platforms needs that script. */
12
+ export interface Rendered {
13
+ /** `install.sh`, for the linux and darwin platforms; served for `curl -fsSL <url> | sh`. */
14
+ sh?: string;
15
+ /** `install.ps1`, for the windows platforms; served for `irm <url> | iex`. */
16
+ ps1?: string;
17
+ }
18
+ export declare function readTemplates(): Templates;
19
+ /** The value of each `@@KEY@@` in install.sh and install.ps1, already quoted for its shell. */
20
+ export declare function placeholders(resolved: ResolvedConfig, options: RenderOptions): {
21
+ sh: Record<string, string>;
22
+ ps1: Record<string, string>;
23
+ };
24
+ export declare function render(resolved: ResolvedConfig, options: RenderOptions, templates?: Templates): Rendered;