@zuke-build/cli 2.6.0 → 2.7.0
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/README.md +11 -1
- package/mod.d.ts +3 -0
- package/mod.js +39 -1
- package/package.json +1 -1
- package/src/binary_launcher.js +1 -3
- package/src/build_file.js +3 -10
- package/src/dispatch.d.ts +10 -1
- package/src/dispatch.js +12 -1
- package/src/launcher.js +3 -62
- package/src/launcher_shared.d.ts +25 -0
- package/src/launcher_shared.js +91 -0
- package/src/mcp_config.d.ts +8 -0
- package/src/mcp_config.js +10 -0
- package/src/node_launcher.d.ts +19 -0
- package/src/node_launcher.js +416 -0
- package/src/node_pin.d.ts +25 -0
- package/src/node_pin.js +30 -0
- package/src/records.d.ts +12 -3
- package/src/records.js +21 -3
- package/src/runtime_field.d.ts +15 -0
- package/src/runtime_field.js +29 -0
- package/src/setup.d.ts +8 -0
- package/src/setup.js +121 -29
- package/src/starter.d.ts +11 -2
- package/src/starter.js +15 -3
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ The `zuke` command-line tool — scaffold
|
|
|
6
6
|
```sh
|
|
7
7
|
deno install -A -g -n zuke jsr:@zuke/cli
|
|
8
8
|
zuke setup
|
|
9
|
+
zuke setup --runtime node # a Node project: package.json and Node launchers, no Deno
|
|
9
10
|
zuke setup --sdk python # a build.py, with launchers that run the zuke binary: no Deno
|
|
10
11
|
zuke upgrade # later: move the installed CLI to the latest release
|
|
11
12
|
zuke upgrade --engine # or move a Python project to the latest zuke release
|
|
@@ -95,6 +96,9 @@ interface BuildLocation
|
|
|
95
96
|
build: string
|
|
96
97
|
The build file's name: the one the root's `zuke.json` names in its
|
|
97
98
|
`build` field, `zuke.ts` when it names none.
|
|
99
|
+
runtime: ProjectRuntime
|
|
100
|
+
The runtime the build file runs on: the `runtime` field of the root's
|
|
101
|
+
`zuke.json`, `deno` when it names none.
|
|
98
102
|
engine: string | null
|
|
99
103
|
The `@zuke/engine` release that runs the build when the root has no
|
|
100
104
|
build file: the `engine` field of its `zuke.json`, which then describes a
|
|
@@ -238,6 +242,8 @@ interface SetupFlags
|
|
|
238
242
|
sdk?: string
|
|
239
243
|
The SDK whose build to scaffold (`--sdk python`): a `build.py` the engine
|
|
240
244
|
runs, in place of a `zuke.ts`. Unset: a TypeScript build.
|
|
245
|
+
runtime?: string
|
|
246
|
+
The runtime of a TypeScript build (`--runtime deno|node`). Unset: Deno, asked when interactive.
|
|
241
247
|
zuke?: string
|
|
242
248
|
The `zuke` release an SDK build's launchers run (`--zuke`), whose engine
|
|
243
249
|
`zuke.json` pins. Unset: this zuke's own release.
|
|
@@ -327,7 +333,8 @@ type BinaryTarget = "aarch64-apple-darwin" | "x86_64-apple-darwin" | "aarch64-un
|
|
|
327
333
|
|
|
328
334
|
type BuildRunner = (root: string, args: string[], program?: string, env?: Readonly<Record<string, string>>) => Promise<number>
|
|
329
335
|
Runs `program <args>` from `root` — Deno when `program` is omitted, else the
|
|
330
|
-
project's launcher at that path
|
|
336
|
+
project's launcher at that path, or {@link NODE} for a build file on Node —
|
|
337
|
+
and resolves to its exit code: the
|
|
331
338
|
injectable subprocess seam, so the forwarding is testable without a build.
|
|
332
339
|
`env` adds variables to the environment the child inherits.
|
|
333
340
|
|
|
@@ -337,6 +344,9 @@ type DocRunner = (denoArgs: string[]) => Promise<number>
|
|
|
337
344
|
|
|
338
345
|
type ImportSource = "package.json" | "Makefile" | "pyproject.toml"
|
|
339
346
|
The kinds of project `zuke import` can read.
|
|
347
|
+
|
|
348
|
+
type ProjectRuntime = "deno" | "node"
|
|
349
|
+
A runtime a project's build file can run on.
|
|
340
350
|
````
|
|
341
351
|
|
|
342
352
|
</details>
|
package/mod.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type { EnginePinHost } from "./src/engine_pin.ts";
|
|
|
15
15
|
export type { SdkSetupOptions } from "./src/setup.ts";
|
|
16
16
|
export type { BinaryPin, BinaryTarget } from "./src/binary_pin.ts";
|
|
17
17
|
export type { ProjectHost } from "./src/project.ts";
|
|
18
|
+
export type { ProjectRuntime } from "./src/runtime_field.ts";
|
|
18
19
|
export type { BuildLocation, BuildProbe, BuildRunner, Ownership, } from "./src/dispatch.ts";
|
|
19
20
|
export { FORWARDED_ENV } from "./src/dispatch.ts";
|
|
20
21
|
/**
|
|
@@ -61,6 +62,8 @@ export interface SetupFlags {
|
|
|
61
62
|
* runs, in place of a `zuke.ts`. Unset: a TypeScript build.
|
|
62
63
|
*/
|
|
63
64
|
sdk?: string;
|
|
65
|
+
/** The runtime of a TypeScript build (`--runtime deno|node`). Unset: Deno, asked when interactive. */
|
|
66
|
+
runtime?: string;
|
|
64
67
|
/**
|
|
65
68
|
* The `zuke` release an SDK build's launchers run (`--zuke`), whose engine
|
|
66
69
|
* `zuke.json` pins. Unset: this zuke's own release.
|
package/mod.js
CHANGED
|
@@ -137,6 +137,15 @@ export function parseSetupFlags(args) {
|
|
|
137
137
|
else if (arg.startsWith("--sdk=")) {
|
|
138
138
|
flags.sdk = arg.slice("--sdk=".length);
|
|
139
139
|
}
|
|
140
|
+
else if (arg === "--runtime") {
|
|
141
|
+
if (i + 1 < args.length) {
|
|
142
|
+
i++;
|
|
143
|
+
flags.runtime = args[i];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else if (arg.startsWith("--runtime=")) {
|
|
147
|
+
flags.runtime = arg.slice("--runtime=".length);
|
|
148
|
+
}
|
|
140
149
|
else if (arg === "--zuke") {
|
|
141
150
|
if (i + 1 < args.length) {
|
|
142
151
|
i++;
|
|
@@ -149,6 +158,24 @@ export function parseSetupFlags(args) {
|
|
|
149
158
|
}
|
|
150
159
|
return flags;
|
|
151
160
|
}
|
|
161
|
+
/** Whether `value` names a runtime `--runtime` accepts. */
|
|
162
|
+
function isRuntime(value) {
|
|
163
|
+
return value === "deno" || value === "node";
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The runtime `--runtime` asks for, `undefined` without it.
|
|
167
|
+
*
|
|
168
|
+
* @throws {Error} naming a value that is not a runtime.
|
|
169
|
+
*/
|
|
170
|
+
function runtimeOption(runtime) {
|
|
171
|
+
if (runtime === undefined)
|
|
172
|
+
return undefined;
|
|
173
|
+
if (!isRuntime(runtime)) {
|
|
174
|
+
throw new Error(`zuke setup: unknown --runtime "${runtime}" — a TypeScript ` +
|
|
175
|
+
"build runs on deno or node.");
|
|
176
|
+
}
|
|
177
|
+
return runtime;
|
|
178
|
+
}
|
|
152
179
|
/** The SDKs `--sdk` accepts: the ones whose build `@zuke/engine` can host. */
|
|
153
180
|
const SDKS = new Set(["python"]);
|
|
154
181
|
/**
|
|
@@ -293,6 +320,7 @@ Setup options:
|
|
|
293
320
|
--name <Class> Build class name (default: MyBuild)
|
|
294
321
|
--build-file <name> TypeScript build file name (default: build.ts, or the project's own)
|
|
295
322
|
--launcher-name <name> Launcher base name when a zuke/ directory is in the way
|
|
323
|
+
--runtime deno|node Runtime of a TypeScript build (default: deno); node scaffolds a package.json and Node launchers
|
|
296
324
|
--sdk python Scaffold a build.py and launchers that run the zuke binary (no Deno)
|
|
297
325
|
--zuke <version> The zuke release those launchers run (default: this one)
|
|
298
326
|
--mcp Also write .mcp.json registering the build's MCP server
|
|
@@ -410,6 +438,7 @@ async function commandSetup(args, host, prompter, starActions, paint, upgradeHos
|
|
|
410
438
|
const flags = parseSetupFlags(args);
|
|
411
439
|
// Resolved before any question is asked, so an unknown SDK or an
|
|
412
440
|
// unreachable registry stops the run before the wizard starts.
|
|
441
|
+
let runtime = runtimeOption(flags.runtime);
|
|
413
442
|
const sdk = await sdkOption(flags, upgradeHost);
|
|
414
443
|
let name = flags.name ?? "MyBuild";
|
|
415
444
|
let force = flags.force;
|
|
@@ -428,8 +457,16 @@ async function commandSetup(args, host, prompter, starActions, paint, upgradeHos
|
|
|
428
457
|
if (!force) {
|
|
429
458
|
force = prompter.confirm("Overwrite existing files if present?");
|
|
430
459
|
}
|
|
460
|
+
if (sdk === undefined && runtime === undefined) {
|
|
461
|
+
const answer = prompter.ask("Runtime (deno or node)", "deno").trim();
|
|
462
|
+
if (!isRuntime(answer)) {
|
|
463
|
+
throw new Error(`zuke setup: unknown runtime "${answer}" — answer deno or node.`);
|
|
464
|
+
}
|
|
465
|
+
runtime = answer;
|
|
466
|
+
}
|
|
431
467
|
}
|
|
432
|
-
|
|
468
|
+
// A Node launcher always bootstraps and names no Deno, so it is not asked.
|
|
469
|
+
const bootstrapDeno = runtime === "node" ? undefined : resolveBootstrapDeno(flags, prompter, interactive, sdk === undefined ? BOOTSTRAP_QUESTION : SDK_BOOTSTRAP_QUESTION);
|
|
433
470
|
const where = dir === "." ? "the current directory" : dir;
|
|
434
471
|
host.log(`Scaffolding Zuke into ${where}:`);
|
|
435
472
|
const launcherName = flags.launcherName;
|
|
@@ -442,6 +479,7 @@ async function commandSetup(args, host, prompter, starActions, paint, upgradeHos
|
|
|
442
479
|
mcp: mcpOption(flags),
|
|
443
480
|
bootstrapDeno,
|
|
444
481
|
sdk,
|
|
482
|
+
runtime,
|
|
445
483
|
}, host);
|
|
446
484
|
const written = result.files.filter((f) => f.status !== "skipped").length;
|
|
447
485
|
reportNotes(host, result);
|
package/package.json
CHANGED
package/src/binary_launcher.js
CHANGED
|
@@ -25,14 +25,12 @@
|
|
|
25
25
|
* @module
|
|
26
26
|
*/
|
|
27
27
|
import { BINARY_INSTALL_DOCS, BINARY_POSIX_TARGETS, BINARY_RELEASES_URL, BINARY_WINDOWS_TARGET, binaryReleaseTag, } from "./binary_pin.js";
|
|
28
|
+
import { LICENSE_HEADER } from "./launcher_shared.js";
|
|
28
29
|
import { FORWARDED_ENV, LAUNCHER_ROOT_ENV } from "./dispatch.js";
|
|
29
30
|
/** The line every binary launcher opens its description with. */
|
|
30
31
|
export const BINARY_LAUNCHER_MARKER = "# Zuke launcher for a build another SDK hosts";
|
|
31
32
|
/** The line a plain binary launcher carries, which `zuke upgrade --engine` keeps it plain by. */
|
|
32
33
|
export const PLAIN_BINARY_LAUNCHER = "# Runs the zuke on PATH:";
|
|
33
|
-
/** The MIT notice every generated launcher opens with (after its shebang). */
|
|
34
|
-
const LICENSE_HEADER = `# Copyright (c) 2026 the Zuke contributors
|
|
35
|
-
# SPDX-License-Identifier: MIT`;
|
|
36
34
|
/* cspell:disable */
|
|
37
35
|
/** The usage lines both scripts open with, for `./zuke` or `.\zuke.ps1`. */
|
|
38
36
|
function usage(command) {
|
package/src/build_file.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @module
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
13
|
+
import { forgivingField } from "./records.js";
|
|
14
14
|
/** The build file of a project whose `zuke.json` names none. */
|
|
15
15
|
export const BUILD_FILE = "zuke.ts";
|
|
16
16
|
/** The build file `zuke setup` gives a new project, recorded in its `zuke.json`. */
|
|
@@ -49,16 +49,9 @@ export function assertBuildFileName(name) {
|
|
|
49
49
|
* {@link assertBuildFileName}.
|
|
50
50
|
*/
|
|
51
51
|
export function buildFileNamed(text) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
config = JSON.parse(text);
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
return BUILD_FILE;
|
|
58
|
-
}
|
|
59
|
-
if (!isRecord(config) || !(BUILD_FIELD in config))
|
|
52
|
+
const name = forgivingField(text, BUILD_FIELD);
|
|
53
|
+
if (name === undefined)
|
|
60
54
|
return BUILD_FILE;
|
|
61
|
-
const name = config[BUILD_FIELD];
|
|
62
55
|
// Anything but a string is refused as written: String() would turn the
|
|
63
56
|
// array ["build.ts"] into a name that passes.
|
|
64
57
|
return assertBuildFileName(typeof name === "string" ? name : JSON.stringify(name));
|
package/src/dispatch.d.ts
CHANGED
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
* @module
|
|
43
43
|
*/
|
|
44
44
|
import { type RuntimeFacts } from "@zuke/core";
|
|
45
|
+
import { type ProjectRuntime } from "./runtime_field.ts";
|
|
45
46
|
import { type EmbeddedEngine } from "./embedded_engine.ts";
|
|
46
47
|
/**
|
|
47
48
|
* Deno's own config files, in the order it prefers them: a `deno.json` wins
|
|
@@ -80,6 +81,11 @@ export interface BuildLocation {
|
|
|
80
81
|
* `build` field, `zuke.ts` when it names none.
|
|
81
82
|
*/
|
|
82
83
|
build: string;
|
|
84
|
+
/**
|
|
85
|
+
* The runtime the build file runs on: the `runtime` field of the root's
|
|
86
|
+
* `zuke.json`, `deno` when it names none.
|
|
87
|
+
*/
|
|
88
|
+
runtime: ProjectRuntime;
|
|
83
89
|
/**
|
|
84
90
|
* The `@zuke/engine` release that runs the build when the root has no
|
|
85
91
|
* build file: the `engine` field of its `zuke.json`, which then describes a
|
|
@@ -186,6 +192,8 @@ export declare function servingEngine(location: BuildLocation, engine: EmbeddedE
|
|
|
186
192
|
* zuke that does.
|
|
187
193
|
*/
|
|
188
194
|
export declare function runBuild(runner: BuildRunner, location: BuildLocation, args: string[], env?: Readonly<Record<string, string>>, engine?: EmbeddedEngine, runtime?: RuntimeFacts["name"]): Promise<number>;
|
|
195
|
+
/** The program a build file on Node runs with, found on `PATH`. */
|
|
196
|
+
export declare const NODE = "node";
|
|
189
197
|
/**
|
|
190
198
|
* The stderr line for a hosted build the binary's own `engine` cannot serve,
|
|
191
199
|
* which then goes to the project's launcher; `undefined` when there is
|
|
@@ -203,7 +211,8 @@ export declare const NO_LOCK_NOTICE: string;
|
|
|
203
211
|
export declare function runningNotice(location: BuildLocation, engine?: EmbeddedEngine): string;
|
|
204
212
|
/**
|
|
205
213
|
* Runs `program <args>` from `root` — Deno when `program` is omitted, else the
|
|
206
|
-
* project's launcher at that path
|
|
214
|
+
* project's launcher at that path, or {@link NODE} for a build file on Node —
|
|
215
|
+
* and resolves to its exit code: the
|
|
207
216
|
* injectable subprocess seam, so the forwarding is testable without a build.
|
|
208
217
|
* `env` adds variables to the environment the child inherits.
|
|
209
218
|
*/
|
package/src/dispatch.js
CHANGED
|
@@ -47,6 +47,7 @@ import { absolutePath, CONFIG_FILE, EnvTasks, FileTasks, ProcessTasks, RuntimeTa
|
|
|
47
47
|
import { noLockNotice } from "./launcher.js";
|
|
48
48
|
import { BINARY_INSTALL_DOCS } from "./binary_pin.js";
|
|
49
49
|
import { BUILD_FILE, buildFileNamed } from "./build_file.js";
|
|
50
|
+
import { runtimeNamed } from "./runtime_field.js";
|
|
50
51
|
import { QUIET_DENO_ENV, spawnDeno } from "./deno_path.js";
|
|
51
52
|
import { EMBEDDED_ENGINE_ENV } from "./embedded_engine.js";
|
|
52
53
|
/**
|
|
@@ -247,7 +248,9 @@ export async function locateBuild(cwd, probe, vouched = EnvTasks.get(LAUNCHER_RO
|
|
|
247
248
|
await assertTrusted(dir, probe);
|
|
248
249
|
// Read only once the marker passed the gate, and then hold the file it
|
|
249
250
|
// names to the same gate: it is the one that runs.
|
|
250
|
-
const
|
|
251
|
+
const config = await probe.readText(dir(CONFIG_FILE).path);
|
|
252
|
+
const build = buildFileNamed(config);
|
|
253
|
+
const runtime = runtimeNamed(config);
|
|
251
254
|
const uid = probe.uid();
|
|
252
255
|
if (!named && uid !== null && build !== BUILD_FILE) {
|
|
253
256
|
await assertFilesOwned(dir, [build], uid, probe, dir);
|
|
@@ -255,6 +258,7 @@ export async function locateBuild(cwd, probe, vouched = EnvTasks.get(LAUNCHER_RO
|
|
|
255
258
|
return {
|
|
256
259
|
root: dir.path,
|
|
257
260
|
build,
|
|
261
|
+
runtime,
|
|
258
262
|
frozen: await probe.exists(dir(LOCK_FILE).path),
|
|
259
263
|
launcher: named ? null : await launcherAt(dir, probe),
|
|
260
264
|
engine: await probe.exists(dir(build).path)
|
|
@@ -437,8 +441,15 @@ export function runBuild(runner, location, args, env, engine, runtime = RuntimeT
|
|
|
437
441
|
"launcher (./zuke, or .\\zuke.ps1 on Windows), which fetches the " +
|
|
438
442
|
"release it pins, or move the project with `zuke upgrade --engine`.");
|
|
439
443
|
}
|
|
444
|
+
// A build file on Node runs as `node <build>`: Node strips the types of a
|
|
445
|
+
// TypeScript file itself, and resolves its imports from node_modules.
|
|
446
|
+
if (location.engine === null && location.runtime === "node") {
|
|
447
|
+
return runner(location.root, [location.build, ...args], NODE, env);
|
|
448
|
+
}
|
|
440
449
|
return runner(location.root, buildRunArgs(location, args), undefined, env);
|
|
441
450
|
}
|
|
451
|
+
/** The program a build file on Node runs with, found on `PATH`. */
|
|
452
|
+
export const NODE = "node";
|
|
442
453
|
/**
|
|
443
454
|
* The stderr line for a hosted build the binary's own `engine` cannot serve,
|
|
444
455
|
* which then goes to the project's launcher; `undefined` when there is
|
package/src/launcher.js
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
* @module
|
|
34
34
|
*/
|
|
35
35
|
import { assertBuildFileName, BUILD_FILE } from "./build_file.js";
|
|
36
|
+
import { bashFetchVerified, LICENSE_HEADER, pwshFetchVerified, } from "./launcher_shared.js";
|
|
36
37
|
import { DENO_PIN, denoReleaseTag, POSIX_TARGETS, WINDOWS_TARGETS, } from "./deno_pin.js";
|
|
37
38
|
/** Which launcher variant to render. */
|
|
38
39
|
/**
|
|
@@ -55,9 +56,6 @@ function buildFileOf(options) {
|
|
|
55
56
|
export const PLAIN_DENO_LAUNCHER = "# Requires Deno:";
|
|
56
57
|
/** The URL the plain launchers point at when Deno is missing. */
|
|
57
58
|
export const DENO_INSTALL_DOCS = "https://docs.deno.com/runtime/getting_started/installation/";
|
|
58
|
-
/** The MIT notice every generated launcher opens with (after its shebang). */
|
|
59
|
-
const LICENSE_HEADER = `# Copyright (c) 2026 the Zuke contributors
|
|
60
|
-
# SPDX-License-Identifier: MIT`;
|
|
61
59
|
/* cspell:disable */
|
|
62
60
|
/**
|
|
63
61
|
* The `DENO_VERSION` / `DENO_SHA256` / `DENO_INSTALL` contract, as the comment
|
|
@@ -169,43 +167,7 @@ else
|
|
|
169
167
|
|
|
170
168
|
asset="deno-\${target}.zip"
|
|
171
169
|
download_url="https://github.com/denoland/deno/releases/download/\${deno_version}/\${asset}"
|
|
172
|
-
|
|
173
|
-
trap 'rm -rf "$work_dir"' EXIT
|
|
174
|
-
archive="$work_dir/$asset"
|
|
175
|
-
|
|
176
|
-
# The download fetches over the network, which is occasionally flaky (e.g. a
|
|
177
|
-
# transient 5xx from the CDN). Retry a few times with backoff so a blip
|
|
178
|
-
# doesn't fail the whole run.
|
|
179
|
-
download_deno() {
|
|
180
|
-
curl -fsSL -o "$archive" "$download_url"
|
|
181
|
-
}
|
|
182
|
-
attempt=1
|
|
183
|
-
max_attempts=4
|
|
184
|
-
until download_deno; do
|
|
185
|
-
if [ "$attempt" -ge "$max_attempts" ]; then
|
|
186
|
-
echo "zuke: failed to download Deno after $max_attempts attempts." >&2
|
|
187
|
-
exit 1
|
|
188
|
-
fi
|
|
189
|
-
delay=$((attempt * 3))
|
|
190
|
-
echo "zuke: Deno download failed (attempt $attempt/$max_attempts); retrying in \${delay}s..." >&2
|
|
191
|
-
sleep "$delay"
|
|
192
|
-
attempt=$((attempt + 1))
|
|
193
|
-
done
|
|
194
|
-
|
|
195
|
-
if command -v sha256sum >/dev/null 2>&1; then
|
|
196
|
-
actual_sha256="$(sha256sum "$archive" | awk '{print $1}')"
|
|
197
|
-
elif command -v shasum >/dev/null 2>&1; then
|
|
198
|
-
actual_sha256="$(shasum -a 256 "$archive" | awk '{print $1}')"
|
|
199
|
-
else
|
|
200
|
-
echo "zuke: neither sha256sum nor shasum is available to verify the download." >&2
|
|
201
|
-
exit 1
|
|
202
|
-
fi
|
|
203
|
-
if [ "$actual_sha256" != "$expected_sha256" ]; then
|
|
204
|
-
echo "zuke: checksum mismatch for $asset:" >&2
|
|
205
|
-
echo " expected $expected_sha256" >&2
|
|
206
|
-
echo " got $actual_sha256" >&2
|
|
207
|
-
exit 1
|
|
208
|
-
fi
|
|
170
|
+
${bashFetchVerified("Deno")}
|
|
209
171
|
|
|
210
172
|
mkdir -p "$deno_install/bin"
|
|
211
173
|
unzip -oq "$archive" -d "$deno_install/bin"
|
|
@@ -355,28 +317,7 @@ if (-not $deno) {
|
|
|
355
317
|
New-Item -ItemType Directory -Path $workDir | Out-Null
|
|
356
318
|
$archive = Join-Path $workDir $asset
|
|
357
319
|
try {
|
|
358
|
-
|
|
359
|
-
# a transient 5xx from the CDN). Retry a few times with backoff so a blip
|
|
360
|
-
# doesn't fail the whole run.
|
|
361
|
-
$maxAttempts = 4
|
|
362
|
-
for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) {
|
|
363
|
-
try {
|
|
364
|
-
Invoke-WebRequest -Uri $downloadUrl -OutFile $archive
|
|
365
|
-
break
|
|
366
|
-
} catch {
|
|
367
|
-
if ($attempt -ge $maxAttempts) {
|
|
368
|
-
throw "zuke: failed to download Deno after $maxAttempts attempts: $_"
|
|
369
|
-
}
|
|
370
|
-
$delay = $attempt * 3
|
|
371
|
-
Write-Host "zuke: Deno download failed (attempt $attempt/$maxAttempts); retrying in \${delay}s..."
|
|
372
|
-
Start-Sleep -Seconds $delay
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
$actualSha256 = (Get-FileHash -Path $archive -Algorithm SHA256).Hash.ToLowerInvariant()
|
|
377
|
-
if ($actualSha256 -ne $expectedSha256.ToLowerInvariant()) {
|
|
378
|
-
throw "zuke: checksum mismatch for \${asset}: expected $expectedSha256, got $actualSha256"
|
|
379
|
-
}
|
|
320
|
+
${pwshFetchVerified("Deno")}
|
|
380
321
|
|
|
381
322
|
$binDir = Join-Path $env:DENO_INSTALL "bin"
|
|
382
323
|
New-Item -ItemType Directory -Force -Path $binDir | Out-Null
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pieces the bootstrapping launchers share: the license header, and the
|
|
3
|
+
* download-with-retry and SHA-256 verification of a pinned archive. One
|
|
4
|
+
* implementation, so the Deno and Node launchers cannot drift on how a
|
|
5
|
+
* download is retried or verified.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** The MIT notice every generated launcher opens with (after its shebang). */
|
|
10
|
+
export declare const LICENSE_HEADER = "# Copyright (c) 2026 the Zuke contributors\n# SPDX-License-Identifier: MIT";
|
|
11
|
+
/**
|
|
12
|
+
* The bash steps that fetch `$download_url` into `$archive` (inside a fresh
|
|
13
|
+
* `$work_dir`, removed on exit) with retries, then check its SHA-256 against
|
|
14
|
+
* `$expected_sha256`, exiting 1 on a mismatch. Expects `asset`,
|
|
15
|
+
* `download_url` and `expected_sha256` to be set, and is indented for use
|
|
16
|
+
* inside an `if` block. `name` is the tool, for messages.
|
|
17
|
+
*/
|
|
18
|
+
export declare function bashFetchVerified(name: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* The PowerShell steps that fetch `$downloadUrl` into `$archive` with
|
|
21
|
+
* retries, then check its SHA-256 against `$expectedSha256`, throwing on a
|
|
22
|
+
* mismatch. Indented for use inside a `try` block; `name` is the tool, for
|
|
23
|
+
* messages.
|
|
24
|
+
*/
|
|
25
|
+
export declare function pwshFetchVerified(name: string): string;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The pieces the bootstrapping launchers share: the license header, and the
|
|
5
|
+
* download-with-retry and SHA-256 verification of a pinned archive. One
|
|
6
|
+
* implementation, so the Deno and Node launchers cannot drift on how a
|
|
7
|
+
* download is retried or verified.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
/** The MIT notice every generated launcher opens with (after its shebang). */
|
|
12
|
+
export const LICENSE_HEADER = `# Copyright (c) 2026 the Zuke contributors
|
|
13
|
+
# SPDX-License-Identifier: MIT`;
|
|
14
|
+
/* cspell:disable */
|
|
15
|
+
/**
|
|
16
|
+
* The bash steps that fetch `$download_url` into `$archive` (inside a fresh
|
|
17
|
+
* `$work_dir`, removed on exit) with retries, then check its SHA-256 against
|
|
18
|
+
* `$expected_sha256`, exiting 1 on a mismatch. Expects `asset`,
|
|
19
|
+
* `download_url` and `expected_sha256` to be set, and is indented for use
|
|
20
|
+
* inside an `if` block. `name` is the tool, for messages.
|
|
21
|
+
*/
|
|
22
|
+
export function bashFetchVerified(name) {
|
|
23
|
+
return ` work_dir="$(mktemp -d)"
|
|
24
|
+
trap 'rm -rf "$work_dir"' EXIT
|
|
25
|
+
archive="$work_dir/$asset"
|
|
26
|
+
|
|
27
|
+
# The download fetches over the network, which is occasionally flaky (e.g. a
|
|
28
|
+
# transient 5xx from the CDN). Retry a few times with backoff so a blip
|
|
29
|
+
# doesn't fail the whole run.
|
|
30
|
+
download_${name.toLowerCase()}() {
|
|
31
|
+
curl -fsSL -o "$archive" "$download_url"
|
|
32
|
+
}
|
|
33
|
+
attempt=1
|
|
34
|
+
max_attempts=4
|
|
35
|
+
until download_${name.toLowerCase()}; do
|
|
36
|
+
if [ "$attempt" -ge "$max_attempts" ]; then
|
|
37
|
+
echo "zuke: failed to download ${name} after $max_attempts attempts." >&2
|
|
38
|
+
exit 1
|
|
39
|
+
fi
|
|
40
|
+
delay=$((attempt * 3))
|
|
41
|
+
echo "zuke: ${name} download failed (attempt $attempt/$max_attempts); retrying in \${delay}s..." >&2
|
|
42
|
+
sleep "$delay"
|
|
43
|
+
attempt=$((attempt + 1))
|
|
44
|
+
done
|
|
45
|
+
|
|
46
|
+
if command -v sha256sum >/dev/null 2>&1; then
|
|
47
|
+
actual_sha256="$(sha256sum "$archive" | awk '{print $1}')"
|
|
48
|
+
elif command -v shasum >/dev/null 2>&1; then
|
|
49
|
+
actual_sha256="$(shasum -a 256 "$archive" | awk '{print $1}')"
|
|
50
|
+
else
|
|
51
|
+
echo "zuke: neither sha256sum nor shasum is available to verify the download." >&2
|
|
52
|
+
exit 1
|
|
53
|
+
fi
|
|
54
|
+
if [ "$actual_sha256" != "$expected_sha256" ]; then
|
|
55
|
+
echo "zuke: checksum mismatch for $asset:" >&2
|
|
56
|
+
echo " expected $expected_sha256" >&2
|
|
57
|
+
echo " got $actual_sha256" >&2
|
|
58
|
+
exit 1
|
|
59
|
+
fi`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The PowerShell steps that fetch `$downloadUrl` into `$archive` with
|
|
63
|
+
* retries, then check its SHA-256 against `$expectedSha256`, throwing on a
|
|
64
|
+
* mismatch. Indented for use inside a `try` block; `name` is the tool, for
|
|
65
|
+
* messages.
|
|
66
|
+
*/
|
|
67
|
+
export function pwshFetchVerified(name) {
|
|
68
|
+
return ` # The download fetches over the network, which is occasionally flaky (e.g.
|
|
69
|
+
# a transient 5xx from the CDN). Retry a few times with backoff so a blip
|
|
70
|
+
# doesn't fail the whole run.
|
|
71
|
+
$maxAttempts = 4
|
|
72
|
+
for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) {
|
|
73
|
+
try {
|
|
74
|
+
Invoke-WebRequest -Uri $downloadUrl -OutFile $archive
|
|
75
|
+
break
|
|
76
|
+
} catch {
|
|
77
|
+
if ($attempt -ge $maxAttempts) {
|
|
78
|
+
throw "zuke: failed to download ${name} after $maxAttempts attempts: $_"
|
|
79
|
+
}
|
|
80
|
+
$delay = $attempt * 3
|
|
81
|
+
Write-Host "zuke: ${name} download failed (attempt $attempt/$maxAttempts); retrying in \${delay}s..."
|
|
82
|
+
Start-Sleep -Seconds $delay
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
$actualSha256 = (Get-FileHash -Path $archive -Algorithm SHA256).Hash.ToLowerInvariant()
|
|
87
|
+
if ($actualSha256 -ne $expectedSha256.ToLowerInvariant()) {
|
|
88
|
+
throw "zuke: checksum mismatch for \${asset}: expected $expectedSha256, got $actualSha256"
|
|
89
|
+
}`;
|
|
90
|
+
}
|
|
91
|
+
/* cspell:enable */
|
package/src/mcp_config.d.ts
CHANGED
|
@@ -28,6 +28,14 @@ export declare function mcpServerEntry(allowRun: boolean, buildFile: string): Mc
|
|
|
28
28
|
* standalone binary runs on the engine it carries, with no Deno.
|
|
29
29
|
*/
|
|
30
30
|
export declare function binaryMcpEntry(allowRun: boolean): McpServerEntry;
|
|
31
|
+
/**
|
|
32
|
+
* The entry a Node project is registered with: `node zuke.ts mcp`, the Node
|
|
33
|
+
* counterpart of {@link mcpServerEntry}. `.mcp.json` is committed and shared,
|
|
34
|
+
* so it names the runtime rather than a launcher script, which a Windows MCP
|
|
35
|
+
* client could not start. It needs Node 26 or newer on `PATH` and the
|
|
36
|
+
* project's dependencies installed, which a first `./zuke` run does.
|
|
37
|
+
*/
|
|
38
|
+
export declare function nodeMcpEntry(allowRun: boolean, buildFile: string): McpServerEntry;
|
|
31
39
|
/**
|
|
32
40
|
* A parsed `.mcp.json`, ready to merge. `present` means a well-formed
|
|
33
41
|
* {@link McpServerEntry} is registered as `zuke` (whatever its arguments — a
|
package/src/mcp_config.js
CHANGED
|
@@ -44,6 +44,16 @@ export function mcpServerEntry(allowRun, buildFile) {
|
|
|
44
44
|
export function binaryMcpEntry(allowRun) {
|
|
45
45
|
return { command: "zuke", args: mcpArgs(allowRun) };
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* The entry a Node project is registered with: `node zuke.ts mcp`, the Node
|
|
49
|
+
* counterpart of {@link mcpServerEntry}. `.mcp.json` is committed and shared,
|
|
50
|
+
* so it names the runtime rather than a launcher script, which a Windows MCP
|
|
51
|
+
* client could not start. It needs Node 26 or newer on `PATH` and the
|
|
52
|
+
* project's dependencies installed, which a first `./zuke` run does.
|
|
53
|
+
*/
|
|
54
|
+
export function nodeMcpEntry(allowRun, buildFile) {
|
|
55
|
+
return { command: "node", args: [buildFile, ...mcpArgs(allowRun)] };
|
|
56
|
+
}
|
|
47
57
|
/** Whether `value` is a well-formed server entry: a command and its arguments. */
|
|
48
58
|
function isServerEntry(value) {
|
|
49
59
|
return isRecord(value) && typeof value.command === "string" &&
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type NodePin } from "./node_pin.ts";
|
|
2
|
+
/** What a Node launcher is rendered for. */
|
|
3
|
+
export interface NodeLauncherOptions {
|
|
4
|
+
/** The build file the launcher runs. Omitted: `zuke.ts`. */
|
|
5
|
+
buildFile?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The bash launcher (`./zuke`) of a Node project.
|
|
9
|
+
*
|
|
10
|
+
* @throws {Error} when the build file name is not a plain file name.
|
|
11
|
+
*/
|
|
12
|
+
export declare function nodeLauncherBash(options?: NodeLauncherOptions, pin?: NodePin): string;
|
|
13
|
+
/**
|
|
14
|
+
* The PowerShell launcher (`.\zuke.ps1`) of a Node project, mirroring
|
|
15
|
+
* {@link nodeLauncherBash}.
|
|
16
|
+
*
|
|
17
|
+
* @throws {Error} when the build file name is not a plain file name.
|
|
18
|
+
*/
|
|
19
|
+
export declare function nodeLauncherPowerShell(options?: NodeLauncherOptions, pin?: NodePin): string;
|