@zuke-build/cli 2.6.0 → 2.8.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 +14 -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/cache.d.ts +4 -0
- package/src/cache.js +18 -2
- package/src/deno_isolated.js +1 -1
- package/src/deno_path.d.ts +1 -1
- package/src/deno_path.js +7 -2
- package/src/dependencies.d.ts +17 -0
- package/src/dependencies.js +60 -11
- package/src/dispatch.d.ts +10 -1
- package/src/dispatch.js +13 -2
- 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/npm_path.d.ts +16 -0
- package/src/npm_path.js +78 -0
- package/src/project.d.ts +14 -1
- package/src/project.js +21 -4
- package/src/records.d.ts +12 -3
- package/src/records.js +21 -3
- package/src/relock.js +116 -59
- 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 +126 -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
|
|
@@ -190,6 +194,9 @@ interface ProjectHost
|
|
|
190
194
|
Remove a file.
|
|
191
195
|
deno(denoArgs: string[], cwd: string): Promise<number>
|
|
192
196
|
Run `deno <denoArgs>` in `cwd`, returning its exit code.
|
|
197
|
+
npm(npmArgs: string[], cwd: string): Promise<number>
|
|
198
|
+
Run `npm <npmArgs>` in `cwd`, a Node project's root, returning its exit
|
|
199
|
+
code.
|
|
193
200
|
denoVersion(): string
|
|
194
201
|
The version of the Deno that runs the command.
|
|
195
202
|
|
|
@@ -238,6 +245,8 @@ interface SetupFlags
|
|
|
238
245
|
sdk?: string
|
|
239
246
|
The SDK whose build to scaffold (`--sdk python`): a `build.py` the engine
|
|
240
247
|
runs, in place of a `zuke.ts`. Unset: a TypeScript build.
|
|
248
|
+
runtime?: string
|
|
249
|
+
The runtime of a TypeScript build (`--runtime deno|node`). Unset: Deno, asked when interactive.
|
|
241
250
|
zuke?: string
|
|
242
251
|
The `zuke` release an SDK build's launchers run (`--zuke`), whose engine
|
|
243
252
|
`zuke.json` pins. Unset: this zuke's own release.
|
|
@@ -327,7 +336,8 @@ type BinaryTarget = "aarch64-apple-darwin" | "x86_64-apple-darwin" | "aarch64-un
|
|
|
327
336
|
|
|
328
337
|
type BuildRunner = (root: string, args: string[], program?: string, env?: Readonly<Record<string, string>>) => Promise<number>
|
|
329
338
|
Runs `program <args>` from `root` — Deno when `program` is omitted, else the
|
|
330
|
-
project's launcher at that path
|
|
339
|
+
project's launcher at that path, or {@link NODE} for a build file on Node —
|
|
340
|
+
and resolves to its exit code: the
|
|
331
341
|
injectable subprocess seam, so the forwarding is testable without a build.
|
|
332
342
|
`env` adds variables to the environment the child inherits.
|
|
333
343
|
|
|
@@ -337,6 +347,9 @@ type DocRunner = (denoArgs: string[]) => Promise<number>
|
|
|
337
347
|
|
|
338
348
|
type ImportSource = "package.json" | "Makefile" | "pyproject.toml"
|
|
339
349
|
The kinds of project `zuke import` can read.
|
|
350
|
+
|
|
351
|
+
type ProjectRuntime = "deno" | "node"
|
|
352
|
+
A runtime a project's build file can run on.
|
|
340
353
|
````
|
|
341
354
|
|
|
342
355
|
</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/cache.d.ts
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
* moved. `--min-dep-age` passes Deno's `--minimum-dependency-age` through,
|
|
9
9
|
* and only matters for a resolution the lock does not have yet.
|
|
10
10
|
*
|
|
11
|
+
* In a project whose build runs on Node it runs `npm ci --ignore-scripts`,
|
|
12
|
+
* which installs exactly what `package-lock.json` pins, or `npm install
|
|
13
|
+
* --ignore-scripts` to write the first lock when there is none.
|
|
14
|
+
*
|
|
11
15
|
* @module
|
|
12
16
|
*/
|
|
13
17
|
import type { BuildProbe } from "./dispatch.ts";
|
package/src/cache.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) 2026 the Zuke contributors
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
import { installArgs, parseInstallFlags, projectLocation, } from "./project.js";
|
|
3
|
+
import { installArgs, nodeInstallFlags, parseInstallFlags, projectLocation, } from "./project.js";
|
|
4
4
|
/**
|
|
5
5
|
* Run `zuke cache <args>` from `cwd`, reporting through `log`, and return the
|
|
6
6
|
* exit code.
|
|
@@ -10,7 +10,23 @@ import { installArgs, parseInstallFlags, projectLocation, } from "./project.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export async function runCache(args, log, host, paint, cwd, probe) {
|
|
12
12
|
const flags = parseInstallFlags("cache", args);
|
|
13
|
-
const { root, build } = await projectLocation(cwd, probe, "cache");
|
|
13
|
+
const { root, build, runtime } = await projectLocation(cwd, probe, "cache");
|
|
14
|
+
if (runtime === "node") {
|
|
15
|
+
nodeInstallFlags("cache", flags);
|
|
16
|
+
const locked = (await host.entry(`${root}/package-lock.json`)) !== "missing";
|
|
17
|
+
const npmArgs = [locked ? "ci" : "install", "--ignore-scripts"];
|
|
18
|
+
if (flags.dryRun) {
|
|
19
|
+
log(`Would cache the build's dependencies: npm ${npmArgs.join(" ")}`);
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
const code = await host.npm(npmArgs, root);
|
|
23
|
+
if (code !== 0) {
|
|
24
|
+
log(paint.fail(`zuke cache: npm ${npmArgs[0]} exited ${code}.`));
|
|
25
|
+
return code;
|
|
26
|
+
}
|
|
27
|
+
log(paint.ok("Installed everything the build imports."));
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
14
30
|
const denoArgs = installArgs("cache", flags, host.denoVersion(), build);
|
|
15
31
|
if (flags.dryRun) {
|
|
16
32
|
log(`Would cache the build's dependencies: deno ${denoArgs.join(" ")}`);
|
package/src/deno_isolated.js
CHANGED
|
@@ -43,7 +43,7 @@ export async function runDenoIsolated(denoArgs, prefix) {
|
|
|
43
43
|
const cwd = await FileTasks.makeTempDirectory((s) => s.prefix(prefix));
|
|
44
44
|
try {
|
|
45
45
|
await FileTasks.writeText(`${cwd}/deno.json`, ISOLATED_DENO_CONFIG);
|
|
46
|
-
const child = spawnDeno(denoArgs, {
|
|
46
|
+
const child = await spawnDeno(denoArgs, {
|
|
47
47
|
cwd,
|
|
48
48
|
stdin: "null",
|
|
49
49
|
stdout: "piped",
|
package/src/deno_path.d.ts
CHANGED
|
@@ -112,4 +112,4 @@ export interface DenoSpawnOptions {
|
|
|
112
112
|
*
|
|
113
113
|
* @throws {DenoNotFoundError} when every candidate is missing.
|
|
114
114
|
*/
|
|
115
|
-
export declare function spawnDeno(args: string[], options?: DenoSpawnOptions, candidates?: readonly string[]): ChildProcess
|
|
115
|
+
export declare function spawnDeno(args: string[], options?: DenoSpawnOptions, candidates?: readonly string[]): Promise<ChildProcess>;
|
package/src/deno_path.js
CHANGED
|
@@ -163,12 +163,12 @@ function cwdUsable(cwd) {
|
|
|
163
163
|
*
|
|
164
164
|
* @throws {DenoNotFoundError} when every candidate is missing.
|
|
165
165
|
*/
|
|
166
|
-
export function spawnDeno(args, options = {}, candidates = denoCandidates()) {
|
|
166
|
+
export async function spawnDeno(args, options = {}, candidates = denoCandidates()) {
|
|
167
167
|
const tried = [];
|
|
168
168
|
for (const command of candidates) {
|
|
169
169
|
tried.push(command);
|
|
170
170
|
try {
|
|
171
|
-
|
|
171
|
+
const child = ProcessTasks.spawn(command, (s) => {
|
|
172
172
|
s.args(...args);
|
|
173
173
|
if (options.cwd !== undefined)
|
|
174
174
|
s.cwd(options.cwd);
|
|
@@ -187,6 +187,11 @@ export function spawnDeno(args, options = {}, candidates = denoCandidates()) {
|
|
|
187
187
|
s.env(name, value);
|
|
188
188
|
return s;
|
|
189
189
|
});
|
|
190
|
+
// On Node a command that cannot start throws nothing: the child has no
|
|
191
|
+
// process, and its status rejects with why.
|
|
192
|
+
if (child.pid === -1)
|
|
193
|
+
await child.status;
|
|
194
|
+
return child;
|
|
190
195
|
}
|
|
191
196
|
catch (error) {
|
|
192
197
|
// Not installed here; the next candidate may be. Anything else — a
|
package/src/dependencies.d.ts
CHANGED
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
* `--minimum-dependency-age` flag. Both honour the project's own
|
|
12
12
|
* `minimumDependencyAge` in `deno.json`, which Deno reads for them.
|
|
13
13
|
*
|
|
14
|
+
* In a project whose build runs on Node they run `npm install` and
|
|
15
|
+
* `npm uninstall` instead, with `--ignore-scripts`, and change `package.json`:
|
|
16
|
+
* a bare name becomes the alias `@zuke/<name>` for `npm:@zuke-build/<name>@^1`,
|
|
17
|
+
* as `zuke setup --runtime node` writes it, and an `npm:` specifier passes
|
|
18
|
+
* through. A JSR package has no npm install, so it is refused there.
|
|
19
|
+
*
|
|
14
20
|
* @module
|
|
15
21
|
*/
|
|
16
22
|
import type { BuildProbe } from "./dispatch.ts";
|
|
@@ -27,6 +33,17 @@ export type DependencyCommand = "add" | "remove";
|
|
|
27
33
|
* read, or a name no registry accepts — rather than handing it to Deno.
|
|
28
34
|
*/
|
|
29
35
|
export declare function dependencySpecifier(command: DependencyCommand, name: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* The `npm install` / `npm uninstall` operand for `specifier`, one
|
|
38
|
+
* {@link dependencySpecifier} returned: a Zuke package becomes its
|
|
39
|
+
* `@zuke/<name>` alias (to add) or that alias (to remove), and an `npm:`
|
|
40
|
+
* specifier is npm's own, without the prefix. A removal names the package
|
|
41
|
+
* alone, as `npm uninstall` takes it.
|
|
42
|
+
*
|
|
43
|
+
* @throws {Error} naming `command` on any other JSR package, which npm
|
|
44
|
+
* cannot install.
|
|
45
|
+
*/
|
|
46
|
+
export declare function npmOperand(command: DependencyCommand, specifier: string): string;
|
|
30
47
|
/**
|
|
31
48
|
* Parse `zuke add`'s or `zuke remove`'s arguments: one or more packages, and
|
|
32
49
|
* `--dry-run`.
|
package/src/dependencies.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright (c) 2026 the Zuke contributors
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { projectLocation } from "./project.js";
|
|
4
|
+
import { zukeNpmDependency } from "./starter.js";
|
|
4
5
|
import { projectConfigText } from "./version_report.js";
|
|
5
6
|
/** A bare Zuke package name, as `zuke add docker` takes it. */
|
|
6
7
|
const BARE_NAME = /^[a-z0-9][a-z0-9-]*$/;
|
|
@@ -27,6 +28,37 @@ export function dependencySpecifier(command, name) {
|
|
|
27
28
|
"(docker), a scoped JSR name (@scope/name), or a jsr: or npm: " +
|
|
28
29
|
"specifier.");
|
|
29
30
|
}
|
|
31
|
+
/** The `@zuke/<name>` a Zuke package's specifier names, if it is one. */
|
|
32
|
+
const ZUKE_JSR = /^jsr:@zuke\/([a-z0-9][a-z0-9-]*)$/;
|
|
33
|
+
/**
|
|
34
|
+
* The `npm install` / `npm uninstall` operand for `specifier`, one
|
|
35
|
+
* {@link dependencySpecifier} returned: a Zuke package becomes its
|
|
36
|
+
* `@zuke/<name>` alias (to add) or that alias (to remove), and an `npm:`
|
|
37
|
+
* specifier is npm's own, without the prefix. A removal names the package
|
|
38
|
+
* alone, as `npm uninstall` takes it.
|
|
39
|
+
*
|
|
40
|
+
* @throws {Error} naming `command` on any other JSR package, which npm
|
|
41
|
+
* cannot install.
|
|
42
|
+
*/
|
|
43
|
+
export function npmOperand(command, specifier) {
|
|
44
|
+
const zuke = ZUKE_JSR.exec(specifier)?.[1];
|
|
45
|
+
if (zuke !== undefined) {
|
|
46
|
+
return command === "add"
|
|
47
|
+
? `@zuke/${zuke}@${zukeNpmDependency(zuke)}`
|
|
48
|
+
: `@zuke/${zuke}`;
|
|
49
|
+
}
|
|
50
|
+
if (specifier.startsWith("npm:")) {
|
|
51
|
+
const spec = specifier.slice("npm:".length);
|
|
52
|
+
if (command === "add")
|
|
53
|
+
return spec;
|
|
54
|
+
// `name@range` names `name`; a scoped name's own `@` comes first.
|
|
55
|
+
const at = spec.indexOf("@", 1);
|
|
56
|
+
return at === -1 ? spec : spec.slice(0, at);
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`zuke ${command}: ${specifier} is a JSR package, and this project's build ` +
|
|
59
|
+
"runs on Node, which installs from npm. Pass its npm name as " +
|
|
60
|
+
"npm:<name>.");
|
|
61
|
+
}
|
|
30
62
|
/**
|
|
31
63
|
* Parse `zuke add`'s or `zuke remove`'s arguments: one or more packages, and
|
|
32
64
|
* `--dry-run`.
|
|
@@ -55,26 +87,43 @@ export function parseDependencyArgs(command, args) {
|
|
|
55
87
|
*/
|
|
56
88
|
export async function runDependencies(command, args, log, host, paint, cwd, probe) {
|
|
57
89
|
const { specifiers, dryRun } = parseDependencyArgs(command, args);
|
|
58
|
-
const { root } = await projectLocation(cwd, probe, command);
|
|
59
|
-
const
|
|
90
|
+
const { root, runtime } = await projectLocation(cwd, probe, command);
|
|
91
|
+
const node = runtime === "node";
|
|
92
|
+
const tool = node ? "npm" : "deno";
|
|
93
|
+
const toolArgs = node
|
|
94
|
+
? [
|
|
95
|
+
command === "add" ? "install" : "uninstall",
|
|
96
|
+
"--ignore-scripts",
|
|
97
|
+
...specifiers.map((specifier) => npmOperand(command, specifier)),
|
|
98
|
+
]
|
|
99
|
+
: [command, ...specifiers];
|
|
60
100
|
if (dryRun) {
|
|
61
|
-
log(`Would run in ${root}:
|
|
101
|
+
log(`Would run in ${root}: ${tool} ${toolArgs.join(" ")}`);
|
|
62
102
|
return 0;
|
|
63
103
|
}
|
|
64
|
-
const
|
|
104
|
+
const manifest = node ? "package.json" : "deno.json";
|
|
105
|
+
// What the report names: the packages as the manifest spells them.
|
|
106
|
+
const named = (node
|
|
107
|
+
? specifiers.map((specifier) => npmOperand("remove", specifier))
|
|
108
|
+
: specifiers).join(", ");
|
|
109
|
+
const config = node
|
|
110
|
+
? () => host.readText(`${root}/package.json`).catch(() => undefined)
|
|
111
|
+
: () => projectConfigText((path) => host.readText(path), root);
|
|
65
112
|
const before = await config();
|
|
66
|
-
const code =
|
|
113
|
+
const code = node
|
|
114
|
+
? await host.npm(toolArgs, root)
|
|
115
|
+
: await host.deno(toolArgs, root);
|
|
67
116
|
if (code !== 0) {
|
|
68
|
-
log(paint.fail(`zuke ${command}:
|
|
117
|
+
log(paint.fail(`zuke ${command}: ${tool} ${toolArgs[0]} exited ${code}.`));
|
|
69
118
|
return code;
|
|
70
119
|
}
|
|
71
|
-
// `deno remove`
|
|
72
|
-
//
|
|
120
|
+
// `deno remove` and `npm uninstall` exit 0 when they find nothing to
|
|
121
|
+
// remove; an unchanged manifest is how that shows.
|
|
73
122
|
if (command === "remove" && (await config()) === before) {
|
|
74
|
-
log(paint.fail(`zuke remove: nothing was removed; this project's
|
|
75
|
-
`${
|
|
123
|
+
log(paint.fail(`zuke remove: nothing was removed; this project's ${manifest} has no ` +
|
|
124
|
+
`${named}.`));
|
|
76
125
|
return 1;
|
|
77
126
|
}
|
|
78
|
-
log(paint.ok(`${command === "add" ? "Added" : "Removed"} ${
|
|
127
|
+
log(paint.ok(`${command === "add" ? "Added" : "Removed"} ${named}.`));
|
|
79
128
|
return 0;
|
|
80
129
|
}
|
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
|
|
@@ -507,7 +518,7 @@ function signalPlan(child) {
|
|
|
507
518
|
*/
|
|
508
519
|
export const defaultBuildRunner = async (root, args, program, env) => {
|
|
509
520
|
const child = program === undefined
|
|
510
|
-
? spawnDeno(args, {
|
|
521
|
+
? await spawnDeno(args, {
|
|
511
522
|
cwd: root,
|
|
512
523
|
stdin: "inherit",
|
|
513
524
|
stdout: "inherit",
|
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;
|