@zuke-build/cli 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +353 -2
- package/mod.d.ts +102 -0
- package/mod.js +931 -0
- package/package.json +35 -4
- package/src/binary_launcher.d.ts +49 -0
- package/src/binary_launcher.js +325 -0
- package/src/binary_pin.d.ts +47 -0
- package/src/binary_pin.js +117 -0
- package/src/build_file.d.ts +25 -0
- package/src/build_file.js +58 -0
- package/src/cache.d.ts +23 -0
- package/src/cache.js +26 -0
- package/src/deno_isolated.d.ts +14 -0
- package/src/deno_isolated.js +70 -0
- package/src/deno_path.d.ts +115 -0
- package/src/deno_path.js +205 -0
- package/src/deno_pin.d.ts +37 -0
- package/src/deno_pin.js +32 -0
- package/src/dependencies.d.ts +48 -0
- package/src/dependencies.js +80 -0
- package/src/dispatch.d.ts +229 -0
- package/src/dispatch.js +549 -0
- package/src/embedded_engine.d.ts +28 -0
- package/src/embedded_engine.js +21 -0
- package/src/engine_pin.d.ts +56 -0
- package/src/engine_pin.js +196 -0
- package/src/fs.d.ts +14 -0
- package/src/fs.js +25 -0
- package/src/import.d.ts +132 -0
- package/src/import.js +289 -0
- package/src/install_source.d.ts +79 -0
- package/src/install_source.js +104 -0
- package/src/launcher.d.ts +37 -0
- package/src/launcher.js +405 -0
- package/src/launcher_shared.d.ts +25 -0
- package/src/launcher_shared.js +91 -0
- package/src/mcp_config.d.ts +71 -0
- package/src/mcp_config.js +96 -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/output.d.ts +38 -0
- package/src/output.js +43 -0
- package/src/paint.d.ts +42 -0
- package/src/paint.js +38 -0
- package/src/project.d.ts +69 -0
- package/src/project.js +132 -0
- package/src/pyproject.d.ts +30 -0
- package/src/pyproject.js +156 -0
- package/src/python_build.d.ts +27 -0
- package/src/python_build.js +197 -0
- package/src/records.d.ts +18 -0
- package/src/records.js +31 -0
- package/src/relock.d.ts +11 -0
- package/src/relock.js +182 -0
- package/src/runtime_field.d.ts +15 -0
- package/src/runtime_field.js +29 -0
- package/src/setup.d.ts +259 -0
- package/src/setup.js +693 -0
- package/src/star.d.ts +44 -0
- package/src/star.js +100 -0
- package/src/starter.d.ts +64 -0
- package/src/starter.js +138 -0
- package/src/toml.d.ts +32 -0
- package/src/toml.js +354 -0
- package/src/translate.d.ts +69 -0
- package/src/translate.js +198 -0
- package/src/upgrade.d.ts +113 -0
- package/src/upgrade.js +344 -0
- package/src/version.d.ts +11 -0
- package/src/version.js +13 -0
- package/src/version_report.d.ts +55 -0
- package/src/version_report.js +187 -0
- package/zuke.js +8 -0
package/src/cache.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `zuke cache`: fetch everything the build imports, keeping the lock.
|
|
3
|
+
*
|
|
4
|
+
* It runs `deno install --entrypoint zuke.ts` in the project root, which
|
|
5
|
+
* downloads whatever the module graph needs into Deno's cache and records any
|
|
6
|
+
* resolution the lock is missing — a warm-up for CI or for going offline.
|
|
7
|
+
* Unlike `zuke relock`, the existing lock stays: what it already pins is not
|
|
8
|
+
* moved. `--min-dep-age` passes Deno's `--minimum-dependency-age` through,
|
|
9
|
+
* and only matters for a resolution the lock does not have yet.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import type { BuildProbe } from "./dispatch.ts";
|
|
14
|
+
import type { CliPaint } from "./paint.ts";
|
|
15
|
+
import { type ProjectHost } from "./project.ts";
|
|
16
|
+
/**
|
|
17
|
+
* Run `zuke cache <args>` from `cwd`, reporting through `log`, and return the
|
|
18
|
+
* exit code.
|
|
19
|
+
*
|
|
20
|
+
* @throws {Error} with a message for the user when the request cannot be
|
|
21
|
+
* carried out. `main` prints the message and exits 1.
|
|
22
|
+
*/
|
|
23
|
+
export declare function runCache(args: string[], log: (line: string) => void, host: ProjectHost, paint: CliPaint, cwd: string, probe: BuildProbe): Promise<number>;
|
package/src/cache.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { installArgs, parseInstallFlags, projectLocation, } from "./project.js";
|
|
4
|
+
/**
|
|
5
|
+
* Run `zuke cache <args>` from `cwd`, reporting through `log`, and return the
|
|
6
|
+
* exit code.
|
|
7
|
+
*
|
|
8
|
+
* @throws {Error} with a message for the user when the request cannot be
|
|
9
|
+
* carried out. `main` prints the message and exits 1.
|
|
10
|
+
*/
|
|
11
|
+
export async function runCache(args, log, host, paint, cwd, probe) {
|
|
12
|
+
const flags = parseInstallFlags("cache", args);
|
|
13
|
+
const { root, build } = await projectLocation(cwd, probe, "cache");
|
|
14
|
+
const denoArgs = installArgs("cache", flags, host.denoVersion(), build);
|
|
15
|
+
if (flags.dryRun) {
|
|
16
|
+
log(`Would cache the build's dependencies: deno ${denoArgs.join(" ")}`);
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
const code = await host.deno(denoArgs, root);
|
|
20
|
+
if (code !== 0) {
|
|
21
|
+
log(paint.fail(`zuke cache: deno install exited ${code}.`));
|
|
22
|
+
return code;
|
|
23
|
+
}
|
|
24
|
+
log(paint.ok("Cached everything the build imports."));
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spawn `deno <denoArgs>` — {@link spawnDeno} finds the Deno to run, and puts
|
|
3
|
+
* that Deno first on the child's `PATH` — in a fresh temp directory named
|
|
4
|
+
* with `prefix`, which is removed afterwards. Returns the child's exit code.
|
|
5
|
+
* The directory holds only a memberless workspace-root `deno.json`, so Deno resolves
|
|
6
|
+
* nothing from the directories above it.
|
|
7
|
+
*
|
|
8
|
+
* The child's output is not inherited. It can repeat arguments the user passed
|
|
9
|
+
* (`deno doc` names a `--filter` it could not find), and it can print a
|
|
10
|
+
* third-party package's own text, and neither may reach an Actions runner raw.
|
|
11
|
+
* Its stdin is closed rather than inherited: these subcommands never read the
|
|
12
|
+
* terminal, and the CLI's own stdin is not theirs to consume.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runDenoIsolated(denoArgs: string[], prefix: string): Promise<number>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* Running a one-off Deno subcommand away from the caller's project.
|
|
5
|
+
*
|
|
6
|
+
* `zuke doc` (`deno doc <spec>`) and `zuke upgrade` (`deno install -g …`)
|
|
7
|
+
* both run Deno on the CLI's own behalf rather than the project's, so neither
|
|
8
|
+
* may pick up the surrounding repo's `deno.json`, import map, `node_modules`
|
|
9
|
+
* or `tsconfig`. Both run from a throwaway directory, and both relay what the
|
|
10
|
+
* child printed through the package's sink instead of inheriting its stdio.
|
|
11
|
+
*
|
|
12
|
+
* That directory sits under the shared temp dir, whose ancestors (`/tmp`) any
|
|
13
|
+
* local user can seed with a `deno.json` whose import map Deno would honour.
|
|
14
|
+
* `deno doc` has no `--no-config`, so the directory carries its own workspace
|
|
15
|
+
* root config, which ends Deno's walk up before it reaches them.
|
|
16
|
+
*
|
|
17
|
+
* @module
|
|
18
|
+
*/
|
|
19
|
+
import { FileTasks } from "@zuke/core";
|
|
20
|
+
import { spawnDeno } from "./deno_path.js";
|
|
21
|
+
import { output } from "./output.js";
|
|
22
|
+
/**
|
|
23
|
+
* The config written into the isolated directory: a workspace root with no
|
|
24
|
+
* members, so no ancestor config — not even one listing this directory as a
|
|
25
|
+
* member — is discovered. A plain `{}` is not enough: it would join an
|
|
26
|
+
* ancestor's `workspace`.
|
|
27
|
+
*/
|
|
28
|
+
const ISOLATED_DENO_CONFIG = '{ "workspace": [] }\n';
|
|
29
|
+
/**
|
|
30
|
+
* Spawn `deno <denoArgs>` — {@link spawnDeno} finds the Deno to run, and puts
|
|
31
|
+
* that Deno first on the child's `PATH` — in a fresh temp directory named
|
|
32
|
+
* with `prefix`, which is removed afterwards. Returns the child's exit code.
|
|
33
|
+
* The directory holds only a memberless workspace-root `deno.json`, so Deno resolves
|
|
34
|
+
* nothing from the directories above it.
|
|
35
|
+
*
|
|
36
|
+
* The child's output is not inherited. It can repeat arguments the user passed
|
|
37
|
+
* (`deno doc` names a `--filter` it could not find), and it can print a
|
|
38
|
+
* third-party package's own text, and neither may reach an Actions runner raw.
|
|
39
|
+
* Its stdin is closed rather than inherited: these subcommands never read the
|
|
40
|
+
* terminal, and the CLI's own stdin is not theirs to consume.
|
|
41
|
+
*/
|
|
42
|
+
export async function runDenoIsolated(denoArgs, prefix) {
|
|
43
|
+
const cwd = await FileTasks.makeTempDirectory((s) => s.prefix(prefix));
|
|
44
|
+
try {
|
|
45
|
+
await FileTasks.writeText(`${cwd}/deno.json`, ISOLATED_DENO_CONFIG);
|
|
46
|
+
const child = spawnDeno(denoArgs, {
|
|
47
|
+
cwd,
|
|
48
|
+
stdin: "null",
|
|
49
|
+
stdout: "piped",
|
|
50
|
+
stderr: "piped",
|
|
51
|
+
});
|
|
52
|
+
const [{ code }, stdout, stderr] = await Promise.all([
|
|
53
|
+
child.status,
|
|
54
|
+
new Response(child.stdout).text(),
|
|
55
|
+
new Response(child.stderr).text(),
|
|
56
|
+
]);
|
|
57
|
+
const relay = (text, write) => {
|
|
58
|
+
// The console adds the line's own newline; keep the text otherwise as
|
|
59
|
+
// the child wrote it, blank lines included.
|
|
60
|
+
if (text !== "")
|
|
61
|
+
write(text.endsWith("\n") ? text.slice(0, -1) : text);
|
|
62
|
+
};
|
|
63
|
+
relay(stdout, output.info);
|
|
64
|
+
relay(stderr, output.error);
|
|
65
|
+
return code;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
await FileTasks.remove(cwd, { recursive: true });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finding the Deno that runs a project's build.
|
|
3
|
+
*
|
|
4
|
+
* Every subprocess this package spawns is Deno itself: the forwarded build
|
|
5
|
+
* (`deno run -A zuke.ts …`) and `zuke doc` (`deno doc <spec>`). Under
|
|
6
|
+
* `deno run` the executable running this code **is** Deno, so
|
|
7
|
+
* `Deno.execPath()` names it and nothing has to be looked up — a project with
|
|
8
|
+
* no ambient `deno` on `PATH` still works.
|
|
9
|
+
*
|
|
10
|
+
* Compiled with `deno compile` it is not. There `Deno.execPath()` is the
|
|
11
|
+
* compiled binary, so spawning it re-enters the CLI: `deno doc core` becomes
|
|
12
|
+
* `zuke doc core`, which spawns `zuke doc core` again, and a forwarded
|
|
13
|
+
* `zuke ci` becomes `zuke run -A --frozen zuke.ts ci`, whose first argument is
|
|
14
|
+
* not one of the CLI's own commands and is therefore forwarded too. Neither
|
|
15
|
+
* terminates, and neither reports anything: the failure is unbounded process
|
|
16
|
+
* creation rather than a message. `denoExecutable` in `@zuke/core` is what
|
|
17
|
+
* tells the two cases apart — the same answer the build CLI's `doc` runner and
|
|
18
|
+
* the MCP registry's module launch use — so this package adds only what is its
|
|
19
|
+
* own: where to look when the compiled case has to find a Deno.
|
|
20
|
+
*
|
|
21
|
+
* The order mirrors the launchers, which answer the same question in shell:
|
|
22
|
+
* whatever `PATH` resolves first, then the bootstrap directory they install
|
|
23
|
+
* into (`DENO_INSTALL`, `~/.deno` by default). A candidate is tried by
|
|
24
|
+
* spawning it rather than by walking `PATH` — the same choice
|
|
25
|
+
* `ToolSettings.run` makes in `@zuke/core`, which lets the OS apply `PATHEXT`
|
|
26
|
+
* on Windows instead of re-implementing it here.
|
|
27
|
+
*
|
|
28
|
+
* @module
|
|
29
|
+
*/
|
|
30
|
+
import { type ChildProcess, type ProcessStdio } from "@zuke/core";
|
|
31
|
+
/**
|
|
32
|
+
* The environment questions Deno resolution asks, injectable so the ordering
|
|
33
|
+
* is testable without a second machine.
|
|
34
|
+
*/
|
|
35
|
+
export interface DenoHost {
|
|
36
|
+
/** Whether this process is a `deno compile` binary rather than Deno itself. */
|
|
37
|
+
standalone(): boolean;
|
|
38
|
+
/** An environment variable's value, or `undefined` when it is unset. */
|
|
39
|
+
env(name: string): string | undefined;
|
|
40
|
+
/** Whether this platform is Windows, where the binary is `deno.exe`. */
|
|
41
|
+
windows(): boolean;
|
|
42
|
+
}
|
|
43
|
+
/** The real, `Deno`-backed {@link DenoHost}. */
|
|
44
|
+
export declare const defaultDenoHost: DenoHost;
|
|
45
|
+
/** The first of `names` with a non-empty value, or `undefined` if none has one. */
|
|
46
|
+
export declare function firstSet(host: DenoHost, ...names: string[]): string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* The Deno executables to try, in order. The first is whatever
|
|
49
|
+
* {@link denoExecutable} says Deno is here — the running executable under
|
|
50
|
+
* `deno run`, the bare name for the OS to resolve on `PATH` when compiled —
|
|
51
|
+
* and the rest is this package's own: the launchers' bootstrap directory, for
|
|
52
|
+
* the compiled case where `PATH` may have no Deno at all.
|
|
53
|
+
*/
|
|
54
|
+
export declare function denoCandidates(host?: DenoHost): string[];
|
|
55
|
+
/**
|
|
56
|
+
* The environment overlay for a spawned Deno: its own directory first on
|
|
57
|
+
* `PATH`, so a CLI the build provisions with `deno install` is found by name,
|
|
58
|
+
* which is what the launchers do with the same directory. A bare name carries
|
|
59
|
+
* no directory to prepend, and the `PATH` that resolved it already leads
|
|
60
|
+
* where it should, so it overlays nothing.
|
|
61
|
+
*/
|
|
62
|
+
export declare function pathWithDeno(command: string, host?: DenoHost): Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* What every Deno this package spawns runs with on top of its inherited
|
|
65
|
+
* environment: no update check. Deno's "A new release of Deno is available"
|
|
66
|
+
* notice otherwise lands in the middle of the CLI's own output — between the
|
|
67
|
+
* version lines of `zuke --version`, or above a forwarded build's first line —
|
|
68
|
+
* and it is about Deno, which this command did not ask about.
|
|
69
|
+
*/
|
|
70
|
+
export declare const QUIET_DENO_ENV: Readonly<Record<string, string>>;
|
|
71
|
+
/** Thrown when no Deno could be found to run a build with. */
|
|
72
|
+
export declare class DenoNotFoundError extends Error {
|
|
73
|
+
/** The error's name, as reported by `String(error)` and stack traces. */
|
|
74
|
+
name: string;
|
|
75
|
+
/** The executables that were spawned and not found, in the order tried. */
|
|
76
|
+
readonly tried: readonly string[];
|
|
77
|
+
/**
|
|
78
|
+
* Build the failure from the candidates that were tried, in order.
|
|
79
|
+
*
|
|
80
|
+
* @param tried The executables that were spawned and not found.
|
|
81
|
+
*/
|
|
82
|
+
constructor(tried: readonly string[]);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* What {@link spawnDeno} accepts: where the child runs and how its streams are
|
|
86
|
+
* connected, beside the argv, which is the caller's `args`. An `env` is added
|
|
87
|
+
* to the inherited environment; it can never override {@link QUIET_DENO_ENV}'s
|
|
88
|
+
* update check, nor the resolved Deno's directory on `PATH`, which only this
|
|
89
|
+
* function knows.
|
|
90
|
+
*/
|
|
91
|
+
export interface DenoSpawnOptions {
|
|
92
|
+
/** The working directory. Omitted: this process's own. */
|
|
93
|
+
cwd?: string;
|
|
94
|
+
/** Variables added to the inherited environment. */
|
|
95
|
+
env?: Record<string, string>;
|
|
96
|
+
/** The child's stdin. Omitted: inherited. */
|
|
97
|
+
stdin?: ProcessStdio;
|
|
98
|
+
/** The child's stdout. Omitted: inherited. */
|
|
99
|
+
stdout?: ProcessStdio;
|
|
100
|
+
/** The child's stderr. Omitted: inherited. */
|
|
101
|
+
stderr?: ProcessStdio;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Spawn Deno with `args`, trying each candidate in order and skipping the ones
|
|
105
|
+
* that are not installed.
|
|
106
|
+
*
|
|
107
|
+
* `candidates` is this loop's own seam: the list is the only thing a test has
|
|
108
|
+
* to vary to reach the skip and the not-found paths, which a real machine —
|
|
109
|
+
* where a bare `deno` resolves — cannot produce. The resolution it defaults to
|
|
110
|
+
* is pure and takes a {@link DenoHost} instead, so each layer is injected at
|
|
111
|
+
* the level it decides something.
|
|
112
|
+
*
|
|
113
|
+
* @throws {DenoNotFoundError} when every candidate is missing.
|
|
114
|
+
*/
|
|
115
|
+
export declare function spawnDeno(args: string[], options?: DenoSpawnOptions, candidates?: readonly string[]): ChildProcess;
|
package/src/deno_path.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* Finding the Deno that runs a project's build.
|
|
5
|
+
*
|
|
6
|
+
* Every subprocess this package spawns is Deno itself: the forwarded build
|
|
7
|
+
* (`deno run -A zuke.ts …`) and `zuke doc` (`deno doc <spec>`). Under
|
|
8
|
+
* `deno run` the executable running this code **is** Deno, so
|
|
9
|
+
* `Deno.execPath()` names it and nothing has to be looked up — a project with
|
|
10
|
+
* no ambient `deno` on `PATH` still works.
|
|
11
|
+
*
|
|
12
|
+
* Compiled with `deno compile` it is not. There `Deno.execPath()` is the
|
|
13
|
+
* compiled binary, so spawning it re-enters the CLI: `deno doc core` becomes
|
|
14
|
+
* `zuke doc core`, which spawns `zuke doc core` again, and a forwarded
|
|
15
|
+
* `zuke ci` becomes `zuke run -A --frozen zuke.ts ci`, whose first argument is
|
|
16
|
+
* not one of the CLI's own commands and is therefore forwarded too. Neither
|
|
17
|
+
* terminates, and neither reports anything: the failure is unbounded process
|
|
18
|
+
* creation rather than a message. `denoExecutable` in `@zuke/core` is what
|
|
19
|
+
* tells the two cases apart — the same answer the build CLI's `doc` runner and
|
|
20
|
+
* the MCP registry's module launch use — so this package adds only what is its
|
|
21
|
+
* own: where to look when the compiled case has to find a Deno.
|
|
22
|
+
*
|
|
23
|
+
* The order mirrors the launchers, which answer the same question in shell:
|
|
24
|
+
* whatever `PATH` resolves first, then the bootstrap directory they install
|
|
25
|
+
* into (`DENO_INSTALL`, `~/.deno` by default). A candidate is tried by
|
|
26
|
+
* spawning it rather than by walking `PATH` — the same choice
|
|
27
|
+
* `ToolSettings.run` makes in `@zuke/core`, which lets the OS apply `PATHEXT`
|
|
28
|
+
* on Windows instead of re-implementing it here.
|
|
29
|
+
*
|
|
30
|
+
* @module
|
|
31
|
+
*/
|
|
32
|
+
import { absolutePath, denoExecutable, EnvTasks, FileTasks, ProcessTasks, RuntimeTasks, } from "@zuke/core";
|
|
33
|
+
import { DENO_INSTALL_DOCS } from "./launcher.js";
|
|
34
|
+
/** The real, `Deno`-backed {@link DenoHost}. */
|
|
35
|
+
export const defaultDenoHost = {
|
|
36
|
+
standalone: () => RuntimeTasks.facts().standalone,
|
|
37
|
+
env: (name) => EnvTasks.get(name),
|
|
38
|
+
windows: () => RuntimeTasks.os() === "windows",
|
|
39
|
+
};
|
|
40
|
+
/** The first of `names` with a non-empty value, or `undefined` if none has one. */
|
|
41
|
+
export function firstSet(host, ...names) {
|
|
42
|
+
for (const name of names) {
|
|
43
|
+
const value = host.env(name);
|
|
44
|
+
if (value !== undefined && value !== "")
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The launchers' bootstrap directory: `DENO_INSTALL`, or `~/.deno`. `HOME` is
|
|
51
|
+
* what the bash launcher reads; `USERPROFILE` is its Windows equivalent, where
|
|
52
|
+
* `HOME` is often unset outside PowerShell. `undefined` when the environment
|
|
53
|
+
* names no directory the candidate can be built from — none of the three set,
|
|
54
|
+
* or a value that is not an absolute path — which leaves `PATH` as the only
|
|
55
|
+
* candidate rather than a crash on the way to spawning anything.
|
|
56
|
+
*/
|
|
57
|
+
function installDir(host) {
|
|
58
|
+
const explicit = firstSet(host, "DENO_INSTALL");
|
|
59
|
+
const home = firstSet(host, "HOME", "USERPROFILE");
|
|
60
|
+
try {
|
|
61
|
+
if (explicit !== undefined)
|
|
62
|
+
return absolutePath(explicit);
|
|
63
|
+
if (home !== undefined)
|
|
64
|
+
return absolutePath(home)(".deno");
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// A relative `DENO_INSTALL` or `HOME` resolves against nothing meaningful
|
|
68
|
+
// here, and `absolutePath` refuses it rather than guessing a base.
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The Deno executables to try, in order. The first is whatever
|
|
74
|
+
* {@link denoExecutable} says Deno is here — the running executable under
|
|
75
|
+
* `deno run`, the bare name for the OS to resolve on `PATH` when compiled —
|
|
76
|
+
* and the rest is this package's own: the launchers' bootstrap directory, for
|
|
77
|
+
* the compiled case where `PATH` may have no Deno at all.
|
|
78
|
+
*/
|
|
79
|
+
export function denoCandidates(host = defaultDenoHost) {
|
|
80
|
+
const candidates = [denoExecutable(host.standalone())];
|
|
81
|
+
if (!host.standalone())
|
|
82
|
+
return candidates;
|
|
83
|
+
const install = installDir(host);
|
|
84
|
+
if (install !== undefined) {
|
|
85
|
+
candidates.push(install("bin", host.windows() ? "deno.exe" : "deno").path);
|
|
86
|
+
}
|
|
87
|
+
return candidates;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The environment overlay for a spawned Deno: its own directory first on
|
|
91
|
+
* `PATH`, so a CLI the build provisions with `deno install` is found by name,
|
|
92
|
+
* which is what the launchers do with the same directory. A bare name carries
|
|
93
|
+
* no directory to prepend, and the `PATH` that resolved it already leads
|
|
94
|
+
* where it should, so it overlays nothing.
|
|
95
|
+
*/
|
|
96
|
+
export function pathWithDeno(command, host = defaultDenoHost) {
|
|
97
|
+
if (!command.includes("/") && !command.includes("\\"))
|
|
98
|
+
return {};
|
|
99
|
+
const binDir = absolutePath(command).parent().path;
|
|
100
|
+
// An empty `PATH` is unset, not an entry to append to: a zero-length element
|
|
101
|
+
// is the POSIX spelling of "the current directory", so joining onto one
|
|
102
|
+
// would put the build's own working directory on its children's `PATH` —
|
|
103
|
+
// the same reading of an empty value {@link firstSet} makes above.
|
|
104
|
+
const inherited = firstSet(host, "PATH");
|
|
105
|
+
const separator = host.windows() ? ";" : ":";
|
|
106
|
+
return {
|
|
107
|
+
PATH: inherited === undefined
|
|
108
|
+
? binDir
|
|
109
|
+
: `${binDir}${separator}${inherited}`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* What every Deno this package spawns runs with on top of its inherited
|
|
114
|
+
* environment: no update check. Deno's "A new release of Deno is available"
|
|
115
|
+
* notice otherwise lands in the middle of the CLI's own output — between the
|
|
116
|
+
* version lines of `zuke --version`, or above a forwarded build's first line —
|
|
117
|
+
* and it is about Deno, which this command did not ask about.
|
|
118
|
+
*/
|
|
119
|
+
export const QUIET_DENO_ENV = {
|
|
120
|
+
DENO_NO_UPDATE_CHECK: "1",
|
|
121
|
+
};
|
|
122
|
+
/** Thrown when no Deno could be found to run a build with. */
|
|
123
|
+
export class DenoNotFoundError extends Error {
|
|
124
|
+
/** The error's name, as reported by `String(error)` and stack traces. */
|
|
125
|
+
name = "DenoNotFoundError";
|
|
126
|
+
/** The executables that were spawned and not found, in the order tried. */
|
|
127
|
+
tried;
|
|
128
|
+
/**
|
|
129
|
+
* Build the failure from the candidates that were tried, in order.
|
|
130
|
+
*
|
|
131
|
+
* @param tried The executables that were spawned and not found.
|
|
132
|
+
*/
|
|
133
|
+
constructor(tried) {
|
|
134
|
+
super(`zuke: running a build needs Deno, and none was found — tried ` +
|
|
135
|
+
`${tried.join(", ")}. Install Deno (${DENO_INSTALL_DOCS}), or run the ` +
|
|
136
|
+
`project's own ./zuke launcher, which installs a pinned Deno itself.`);
|
|
137
|
+
this.tried = tried;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Whether `cwd` still names a directory to spawn in — vacuously true when the
|
|
142
|
+
* caller named none and the child inherits this process's own.
|
|
143
|
+
*/
|
|
144
|
+
function cwdUsable(cwd) {
|
|
145
|
+
if (cwd === undefined)
|
|
146
|
+
return true;
|
|
147
|
+
try {
|
|
148
|
+
return FileTasks.statSync(cwd).isDirectory;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Spawn Deno with `args`, trying each candidate in order and skipping the ones
|
|
156
|
+
* that are not installed.
|
|
157
|
+
*
|
|
158
|
+
* `candidates` is this loop's own seam: the list is the only thing a test has
|
|
159
|
+
* to vary to reach the skip and the not-found paths, which a real machine —
|
|
160
|
+
* where a bare `deno` resolves — cannot produce. The resolution it defaults to
|
|
161
|
+
* is pure and takes a {@link DenoHost} instead, so each layer is injected at
|
|
162
|
+
* the level it decides something.
|
|
163
|
+
*
|
|
164
|
+
* @throws {DenoNotFoundError} when every candidate is missing.
|
|
165
|
+
*/
|
|
166
|
+
export function spawnDeno(args, options = {}, candidates = denoCandidates()) {
|
|
167
|
+
const tried = [];
|
|
168
|
+
for (const command of candidates) {
|
|
169
|
+
tried.push(command);
|
|
170
|
+
try {
|
|
171
|
+
return ProcessTasks.spawn(command, (s) => {
|
|
172
|
+
s.args(...args);
|
|
173
|
+
if (options.cwd !== undefined)
|
|
174
|
+
s.cwd(options.cwd);
|
|
175
|
+
if (options.stdin !== undefined)
|
|
176
|
+
s.stdin(options.stdin);
|
|
177
|
+
if (options.stdout !== undefined)
|
|
178
|
+
s.stdout(options.stdout);
|
|
179
|
+
if (options.stderr !== undefined)
|
|
180
|
+
s.stderr(options.stderr);
|
|
181
|
+
const env = {
|
|
182
|
+
...options.env,
|
|
183
|
+
...QUIET_DENO_ENV,
|
|
184
|
+
...pathWithDeno(command),
|
|
185
|
+
};
|
|
186
|
+
for (const [name, value] of Object.entries(env))
|
|
187
|
+
s.env(name, value);
|
|
188
|
+
return s;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
// Not installed here; the next candidate may be. Anything else — a
|
|
193
|
+
// permission denial, a directory where the binary should be — is the
|
|
194
|
+
// caller's to see rather than a reason to keep looking. `spawn` reports
|
|
195
|
+
// a `cwd` that is gone as `NotFound` as well, and no other Deno would
|
|
196
|
+
// fix that: telling the user to install one they already have would send
|
|
197
|
+
// them somewhere the problem is not.
|
|
198
|
+
if (!FileTasks.isNotFound(error))
|
|
199
|
+
throw error;
|
|
200
|
+
if (!cwdUsable(options.cwd))
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
throw new DenoNotFoundError(tried);
|
|
205
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Deno release the bootstrapping launchers install, and the SHA-256 of
|
|
3
|
+
* each platform's release asset they verify it against.
|
|
4
|
+
*
|
|
5
|
+
* This is the one place the pin lives. The repository's own `./zuke` and
|
|
6
|
+
* `zuke.ps1` are generated from the launcher template that reads it (see
|
|
7
|
+
* `build/launchers.ts`), and `zuke setup` stamps the same template into every
|
|
8
|
+
* project that opts into the bootstrap — so bumping Deno is a change here, a
|
|
9
|
+
* `./zuke launcherSync`, and a commit, never a hand edit of a shell file.
|
|
10
|
+
*
|
|
11
|
+
* Bump the version and the checksums *together*: pull the new asset digests
|
|
12
|
+
* from the release page (GitHub reports each asset's `digest`), or from
|
|
13
|
+
* `gh release view <tag> --repo denoland/deno --json assets`, and cross-check
|
|
14
|
+
* by downloading and hashing the artifact.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* A Deno release asset's target triple, as it appears in the asset name
|
|
20
|
+
* (`deno-<target>.zip`).
|
|
21
|
+
*/
|
|
22
|
+
export type DenoTarget = "x86_64-unknown-linux-gnu" | "aarch64-unknown-linux-gnu" | "x86_64-apple-darwin" | "aarch64-apple-darwin" | "x86_64-pc-windows-msvc" | "aarch64-pc-windows-msvc";
|
|
23
|
+
/** The pinned Deno release and the checksum of each platform's asset. */
|
|
24
|
+
export interface DenoPin {
|
|
25
|
+
/** The release version without its `v` prefix, e.g. `"2.8.3"`. */
|
|
26
|
+
readonly version: string;
|
|
27
|
+
/** Lowercase hex SHA-256 of `deno-<target>.zip` for each supported target. */
|
|
28
|
+
readonly checksums: Readonly<Record<DenoTarget, string>>;
|
|
29
|
+
}
|
|
30
|
+
/** The Deno release the launchers bootstrap, with its verified checksums. */
|
|
31
|
+
export declare const DENO_PIN: DenoPin;
|
|
32
|
+
/** The release tag the pin downloads, e.g. `v2.8.3`. */
|
|
33
|
+
export declare function denoReleaseTag(pin: DenoPin): string;
|
|
34
|
+
/** The targets the POSIX launcher can bootstrap (Linux and macOS). */
|
|
35
|
+
export declare const POSIX_TARGETS: readonly DenoTarget[];
|
|
36
|
+
/** The targets the PowerShell launcher can bootstrap (Windows). */
|
|
37
|
+
export declare const WINDOWS_TARGETS: readonly DenoTarget[];
|
package/src/deno_pin.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/* cspell:disable */
|
|
4
|
+
/** The Deno release the launchers bootstrap, with its verified checksums. */
|
|
5
|
+
export const DENO_PIN = {
|
|
6
|
+
version: "2.8.3",
|
|
7
|
+
checksums: {
|
|
8
|
+
"x86_64-unknown-linux-gnu": "30455b845ffa6082209c3590269c910ad3b7efdf28c9879afd4006c47ae54197",
|
|
9
|
+
"aarch64-unknown-linux-gnu": "d4589cc1ffcbf1995c92a0127d932aaf832ac70cfdcc6d5b7bf38043cf303575",
|
|
10
|
+
"x86_64-apple-darwin": "4254ec12123cfcf88b87703d7acf092a1ea024bdf9be8dd3cd9d4474761cb74e",
|
|
11
|
+
"aarch64-apple-darwin": "88b350be928fdba0e5d8142ff7c101a17133426371e3cf5ed0e0f74e62476f6c",
|
|
12
|
+
"x86_64-pc-windows-msvc": "7fdd1f42e6b0855421ecf27bb406e2492ade1087c85e30ebf0deab6280ea743c",
|
|
13
|
+
"aarch64-pc-windows-msvc": "243f478ac577ade1bbd980ecf510607a10ed8cc977b462083ada48e5f6580de1",
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
/* cspell:enable */
|
|
17
|
+
/** The release tag the pin downloads, e.g. `v2.8.3`. */
|
|
18
|
+
export function denoReleaseTag(pin) {
|
|
19
|
+
return `v${pin.version}`;
|
|
20
|
+
}
|
|
21
|
+
/** The targets the POSIX launcher can bootstrap (Linux and macOS). */
|
|
22
|
+
export const POSIX_TARGETS = [
|
|
23
|
+
"x86_64-unknown-linux-gnu",
|
|
24
|
+
"aarch64-unknown-linux-gnu",
|
|
25
|
+
"x86_64-apple-darwin",
|
|
26
|
+
"aarch64-apple-darwin",
|
|
27
|
+
];
|
|
28
|
+
/** The targets the PowerShell launcher can bootstrap (Windows). */
|
|
29
|
+
export const WINDOWS_TARGETS = [
|
|
30
|
+
"x86_64-pc-windows-msvc",
|
|
31
|
+
"aarch64-pc-windows-msvc",
|
|
32
|
+
];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `zuke add` and `zuke remove`: change the project's dependencies with
|
|
3
|
+
* `deno add` and `deno remove`, run in the project root.
|
|
4
|
+
*
|
|
5
|
+
* A bare name is a Zuke package, so `zuke add docker gh` adds
|
|
6
|
+
* `jsr:@zuke/docker` and `jsr:@zuke/gh` to the project's `deno.json` imports
|
|
7
|
+
* — the bare-specifier form a build imports them by. A scoped name (`@x/y`)
|
|
8
|
+
* is a JSR package, and a full specifier (`jsr:…`, `npm:…`) passes through.
|
|
9
|
+
*
|
|
10
|
+
* Neither takes `--min-dep-age`: `deno add` rejects Deno's
|
|
11
|
+
* `--minimum-dependency-age` flag. Both honour the project's own
|
|
12
|
+
* `minimumDependencyAge` in `deno.json`, which Deno reads for them.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
import type { BuildProbe } from "./dispatch.ts";
|
|
17
|
+
import type { CliPaint } from "./paint.ts";
|
|
18
|
+
import { type ProjectHost } from "./project.ts";
|
|
19
|
+
/** What `zuke add` and `zuke remove` do with their packages. */
|
|
20
|
+
export type DependencyCommand = "add" | "remove";
|
|
21
|
+
/**
|
|
22
|
+
* The `deno add` / `deno remove` operand for `name`: a bare name becomes the
|
|
23
|
+
* Zuke package `jsr:@zuke/<name>`, a scoped name `jsr:@scope/name`, and a
|
|
24
|
+
* full `jsr:` or `npm:` specifier passes through.
|
|
25
|
+
*
|
|
26
|
+
* @throws {Error} naming `command` on anything else — an option Deno would
|
|
27
|
+
* read, or a name no registry accepts — rather than handing it to Deno.
|
|
28
|
+
*/
|
|
29
|
+
export declare function dependencySpecifier(command: DependencyCommand, name: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Parse `zuke add`'s or `zuke remove`'s arguments: one or more packages, and
|
|
32
|
+
* `--dry-run`.
|
|
33
|
+
*
|
|
34
|
+
* @throws {Error} naming `command` when no package is given, or on anything
|
|
35
|
+
* {@link dependencySpecifier} refuses.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseDependencyArgs(command: DependencyCommand, args: readonly string[]): {
|
|
38
|
+
specifiers: string[];
|
|
39
|
+
dryRun: boolean;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Run `zuke add <args>` or `zuke remove <args>` from `cwd`, reporting
|
|
43
|
+
* through `log`, and return the exit code.
|
|
44
|
+
*
|
|
45
|
+
* @throws {Error} with a message for the user when the request cannot be
|
|
46
|
+
* carried out. `main` prints the message and exits 1.
|
|
47
|
+
*/
|
|
48
|
+
export declare function runDependencies(command: DependencyCommand, args: string[], log: (line: string) => void, host: ProjectHost, paint: CliPaint, cwd: string, probe: BuildProbe): Promise<number>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { projectLocation } from "./project.js";
|
|
4
|
+
import { projectConfigText } from "./version_report.js";
|
|
5
|
+
/** A bare Zuke package name, as `zuke add docker` takes it. */
|
|
6
|
+
const BARE_NAME = /^[a-z0-9][a-z0-9-]*$/;
|
|
7
|
+
/** A scoped package name, `@scope/name`. */
|
|
8
|
+
const SCOPED_NAME = /^@[a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*$/;
|
|
9
|
+
/** A full specifier with a registry prefix, passed through as written. */
|
|
10
|
+
const FULL_SPECIFIER = /^(jsr|npm):\S+$/;
|
|
11
|
+
/**
|
|
12
|
+
* The `deno add` / `deno remove` operand for `name`: a bare name becomes the
|
|
13
|
+
* Zuke package `jsr:@zuke/<name>`, a scoped name `jsr:@scope/name`, and a
|
|
14
|
+
* full `jsr:` or `npm:` specifier passes through.
|
|
15
|
+
*
|
|
16
|
+
* @throws {Error} naming `command` on anything else — an option Deno would
|
|
17
|
+
* read, or a name no registry accepts — rather than handing it to Deno.
|
|
18
|
+
*/
|
|
19
|
+
export function dependencySpecifier(command, name) {
|
|
20
|
+
if (BARE_NAME.test(name))
|
|
21
|
+
return `jsr:@zuke/${name}`;
|
|
22
|
+
if (SCOPED_NAME.test(name))
|
|
23
|
+
return `jsr:${name}`;
|
|
24
|
+
if (FULL_SPECIFIER.test(name))
|
|
25
|
+
return name;
|
|
26
|
+
throw new Error(`zuke ${command}: "${name}" is not a package. Pass a Zuke package name ` +
|
|
27
|
+
"(docker), a scoped JSR name (@scope/name), or a jsr: or npm: " +
|
|
28
|
+
"specifier.");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse `zuke add`'s or `zuke remove`'s arguments: one or more packages, and
|
|
32
|
+
* `--dry-run`.
|
|
33
|
+
*
|
|
34
|
+
* @throws {Error} naming `command` when no package is given, or on anything
|
|
35
|
+
* {@link dependencySpecifier} refuses.
|
|
36
|
+
*/
|
|
37
|
+
export function parseDependencyArgs(command, args) {
|
|
38
|
+
const dryRun = args.includes("--dry-run");
|
|
39
|
+
const names = args.filter((arg) => arg !== "--dry-run");
|
|
40
|
+
if (names.length === 0) {
|
|
41
|
+
throw new Error(`zuke ${command}: name at least one package, as in ` +
|
|
42
|
+
`zuke ${command} docker.`);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
specifiers: names.map((name) => dependencySpecifier(command, name)),
|
|
46
|
+
dryRun,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Run `zuke add <args>` or `zuke remove <args>` from `cwd`, reporting
|
|
51
|
+
* through `log`, and return the exit code.
|
|
52
|
+
*
|
|
53
|
+
* @throws {Error} with a message for the user when the request cannot be
|
|
54
|
+
* carried out. `main` prints the message and exits 1.
|
|
55
|
+
*/
|
|
56
|
+
export async function runDependencies(command, args, log, host, paint, cwd, probe) {
|
|
57
|
+
const { specifiers, dryRun } = parseDependencyArgs(command, args);
|
|
58
|
+
const { root } = await projectLocation(cwd, probe, command);
|
|
59
|
+
const denoArgs = [command, ...specifiers];
|
|
60
|
+
if (dryRun) {
|
|
61
|
+
log(`Would run in ${root}: deno ${denoArgs.join(" ")}`);
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
const config = () => projectConfigText((path) => host.readText(path), root);
|
|
65
|
+
const before = await config();
|
|
66
|
+
const code = await host.deno(denoArgs, root);
|
|
67
|
+
if (code !== 0) {
|
|
68
|
+
log(paint.fail(`zuke ${command}: deno ${command} exited ${code}.`));
|
|
69
|
+
return code;
|
|
70
|
+
}
|
|
71
|
+
// `deno remove` exits 0 when it finds nothing to remove; an unchanged
|
|
72
|
+
// config is how that shows.
|
|
73
|
+
if (command === "remove" && (await config()) === before) {
|
|
74
|
+
log(paint.fail(`zuke remove: nothing was removed; this project's deno.json has no ` +
|
|
75
|
+
`${specifiers.join(", ")}.`));
|
|
76
|
+
return 1;
|
|
77
|
+
}
|
|
78
|
+
log(paint.ok(`${command === "add" ? "Added" : "Removed"} ${specifiers.join(", ")}.`));
|
|
79
|
+
return 0;
|
|
80
|
+
}
|