@zuke-build/cli 2.10.0 → 2.11.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 +41 -10
- package/mod.d.ts +1 -0
- package/mod.js +10 -14
- package/package.json +1 -1
- package/src/binary_launcher.d.ts +2 -2
- package/src/binary_launcher.js +2 -2
- package/src/deno_isolated.js +3 -2
- package/src/deno_path.d.ts +49 -7
- package/src/deno_path.js +65 -24
- package/src/dispatch.d.ts +46 -63
- package/src/dispatch.js +83 -167
- package/src/node_path.d.ts +43 -0
- package/src/node_path.js +53 -0
- package/src/npm_path.d.ts +17 -4
- package/src/npm_path.js +14 -52
- package/src/project.js +5 -4
- package/src/runtime_install.d.ts +101 -0
- package/src/runtime_install.js +218 -0
- package/src/uv_path.d.ts +49 -0
- package/src/uv_path.js +83 -0
- package/src/uv_pin.d.ts +30 -0
- package/src/uv_pin.js +36 -0
- package/src/version.js +1 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finding the Node a build file on Node runs with.
|
|
3
|
+
*
|
|
4
|
+
* A project whose `zuke.json` says `"runtime": "node"` runs as
|
|
5
|
+
* `node <build>`. The `node` is whatever `PATH` resolves first, then the
|
|
6
|
+
* pinned Node `zuke` installs into `ZUKE_NODE_HOME` (`~/.zuke/node` by
|
|
7
|
+
* default; see `runtime_install.ts`), so a machine whose only Node is the one
|
|
8
|
+
* `zuke` fetched still runs the build.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import type { AbsolutePath } from "@zuke/core";
|
|
13
|
+
import { type DenoHost } from "./deno_path.ts";
|
|
14
|
+
/** Where to download Node from, named when none is found. */
|
|
15
|
+
export declare const NODE_INSTALL_DOCS = "https://nodejs.org/en/download";
|
|
16
|
+
/**
|
|
17
|
+
* The directory pinned Node releases live in, one `v<version>` directory
|
|
18
|
+
* each: `ZUKE_NODE_HOME`, or `~/.zuke/node`. `undefined` when the environment
|
|
19
|
+
* names no absolute directory for it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function nodeHomeRoot(host: DenoHost): AbsolutePath | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The executables to try for `name`, in order: the bare name for `PATH`, then
|
|
24
|
+
* the one in the pinned Node `zuke` installs (`bin/<name>`, or
|
|
25
|
+
* `windowsFile` at the release's root on Windows), where the environment
|
|
26
|
+
* names a place for it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function cachedNodeCandidates(name: string, windowsFile: string, host: DenoHost): string[];
|
|
29
|
+
/** The Node executables to try: `node` on `PATH`, then the pinned one `zuke` installs. */
|
|
30
|
+
export declare function nodeCandidates(host?: DenoHost): string[];
|
|
31
|
+
/** Thrown when no Node could be found to run a build file on Node with. */
|
|
32
|
+
export declare class NodeNotFoundError extends Error {
|
|
33
|
+
/** The error's name, as reported by `String(error)` and stack traces. */
|
|
34
|
+
name: string;
|
|
35
|
+
/** The executables that were looked for and not found, in the order tried. */
|
|
36
|
+
readonly tried: readonly string[];
|
|
37
|
+
/**
|
|
38
|
+
* Build the failure from the candidates that were tried, in order.
|
|
39
|
+
*
|
|
40
|
+
* @param tried The executables that were looked for and not found.
|
|
41
|
+
*/
|
|
42
|
+
constructor(tried: readonly string[]);
|
|
43
|
+
}
|
package/src/node_path.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { defaultDenoHost, installDirFrom } from "./deno_path.js";
|
|
4
|
+
import { NODE_PIN } from "./node_pin.js";
|
|
5
|
+
/** Where to download Node from, named when none is found. */
|
|
6
|
+
export const NODE_INSTALL_DOCS = "https://nodejs.org/en/download";
|
|
7
|
+
/**
|
|
8
|
+
* The directory pinned Node releases live in, one `v<version>` directory
|
|
9
|
+
* each: `ZUKE_NODE_HOME`, or `~/.zuke/node`. `undefined` when the environment
|
|
10
|
+
* names no absolute directory for it.
|
|
11
|
+
*/
|
|
12
|
+
export function nodeHomeRoot(host) {
|
|
13
|
+
return installDirFrom(host, "ZUKE_NODE_HOME", ".zuke", "node");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The executables to try for `name`, in order: the bare name for `PATH`, then
|
|
17
|
+
* the one in the pinned Node `zuke` installs (`bin/<name>`, or
|
|
18
|
+
* `windowsFile` at the release's root on Windows), where the environment
|
|
19
|
+
* names a place for it.
|
|
20
|
+
*/
|
|
21
|
+
export function cachedNodeCandidates(name, windowsFile, host) {
|
|
22
|
+
const release = nodeHomeRoot(host)?.(`v${NODE_PIN.version}`);
|
|
23
|
+
if (release === undefined)
|
|
24
|
+
return [name];
|
|
25
|
+
return [
|
|
26
|
+
name,
|
|
27
|
+
host.windows() ? release(windowsFile).path : release("bin", name).path,
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
/** The Node executables to try: `node` on `PATH`, then the pinned one `zuke` installs. */
|
|
31
|
+
export function nodeCandidates(host = defaultDenoHost) {
|
|
32
|
+
return cachedNodeCandidates("node", "node.exe", host);
|
|
33
|
+
}
|
|
34
|
+
/** Thrown when no Node could be found to run a build file on Node with. */
|
|
35
|
+
export class NodeNotFoundError extends Error {
|
|
36
|
+
/** The error's name, as reported by `String(error)` and stack traces. */
|
|
37
|
+
name = "NodeNotFoundError";
|
|
38
|
+
/** The executables that were looked for and not found, in the order tried. */
|
|
39
|
+
tried;
|
|
40
|
+
/**
|
|
41
|
+
* Build the failure from the candidates that were tried, in order.
|
|
42
|
+
*
|
|
43
|
+
* @param tried The executables that were looked for and not found.
|
|
44
|
+
*/
|
|
45
|
+
constructor(tried) {
|
|
46
|
+
const major = NODE_PIN.version.split(".")[0];
|
|
47
|
+
super(`zuke: this build runs on Node (zuke.json's "runtime"), and none was ` +
|
|
48
|
+
`found — tried ${tried.join(", ")}. Install Node ${major} or newer ` +
|
|
49
|
+
`and put it on PATH (${NODE_INSTALL_DOCS}), or run zuke again and let ` +
|
|
50
|
+
`it install Node ${NODE_PIN.version}.`);
|
|
51
|
+
this.tried = tried;
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/npm_path.d.ts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Finding the npm that changes a Node project's dependencies.
|
|
3
|
+
*
|
|
4
|
+
* `zuke add`, `remove`, `cache` and `relock` run npm in a project whose
|
|
5
|
+
* `zuke.json` says `"runtime": "node"`. The order is the one of the build's
|
|
6
|
+
* Node runner: whatever `PATH` resolves first, then the pinned Node `zuke`
|
|
7
|
+
* installs into `ZUKE_NODE_HOME` (`~/.zuke/node` by default), which it can
|
|
8
|
+
* also install on the spot (`runtime_install.ts`). As in
|
|
9
|
+
* `deno_path.ts`, a candidate is tried by spawning it, which leaves `PATHEXT`
|
|
10
|
+
* (`npm.cmd` on Windows) to the OS.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { type DenoHost, type Provision } from "./deno_path.ts";
|
|
2
15
|
/**
|
|
3
16
|
* The npm executables to try, in order: the bare name for `PATH`, then the
|
|
4
|
-
* one beside the pinned Node
|
|
17
|
+
* one beside the pinned Node `zuke` installs. That one is left out when
|
|
5
18
|
* the environment names no absolute directory to find it in.
|
|
6
19
|
*/
|
|
7
20
|
export declare function npmCandidates(host?: DenoHost): string[];
|
|
@@ -9,8 +22,8 @@ export declare function npmCandidates(host?: DenoHost): string[];
|
|
|
9
22
|
* Run `npm <args>` in `cwd` with the terminal's output, trying each candidate
|
|
10
23
|
* in order and skipping the ones that are not installed, and return its exit
|
|
11
24
|
* code. The cached npm runs with its Node first on `PATH`, which its script
|
|
12
|
-
* needs to start.
|
|
25
|
+
* needs to start ({@link spawnFirst} does both).
|
|
13
26
|
*
|
|
14
27
|
* @throws {Error} naming every candidate tried when none is installed.
|
|
15
28
|
*/
|
|
16
|
-
export declare function runNpm(args: string[], cwd: string, candidates?: readonly string[]): Promise<number>;
|
|
29
|
+
export declare function runNpm(args: string[], cwd: string, candidates?: readonly string[], provision?: Provision): Promise<number>;
|
package/src/npm_path.js
CHANGED
|
@@ -4,75 +4,37 @@
|
|
|
4
4
|
* Finding the npm that changes a Node project's dependencies.
|
|
5
5
|
*
|
|
6
6
|
* `zuke add`, `remove`, `cache` and `relock` run npm in a project whose
|
|
7
|
-
* `zuke.json` says `"runtime": "node"`. The order
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* `zuke.json` says `"runtime": "node"`. The order is the one of the build's
|
|
8
|
+
* Node runner: whatever `PATH` resolves first, then the pinned Node `zuke`
|
|
9
|
+
* installs into `ZUKE_NODE_HOME` (`~/.zuke/node` by default), which it can
|
|
10
|
+
* also install on the spot (`runtime_install.ts`). As in
|
|
11
11
|
* `deno_path.ts`, a candidate is tried by spawning it, which leaves `PATHEXT`
|
|
12
12
|
* (`npm.cmd` on Windows) to the OS.
|
|
13
13
|
*
|
|
14
14
|
* @module
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import { defaultDenoHost, firstSet, pathWithDeno, } from "./deno_path.js";
|
|
16
|
+
import { defaultDenoHost, spawnFirst, } from "./deno_path.js";
|
|
18
17
|
import { NODE_PIN } from "./node_pin.js";
|
|
18
|
+
import { cachedNodeCandidates } from "./node_path.js";
|
|
19
19
|
/**
|
|
20
20
|
* The npm executables to try, in order: the bare name for `PATH`, then the
|
|
21
|
-
* one beside the pinned Node
|
|
21
|
+
* one beside the pinned Node `zuke` installs. That one is left out when
|
|
22
22
|
* the environment names no absolute directory to find it in.
|
|
23
23
|
*/
|
|
24
24
|
export function npmCandidates(host = defaultDenoHost) {
|
|
25
|
-
|
|
26
|
-
const explicit = firstSet(host, "ZUKE_NODE_HOME");
|
|
27
|
-
const home = firstSet(host, "HOME", "USERPROFILE");
|
|
28
|
-
try {
|
|
29
|
-
const root = explicit !== undefined
|
|
30
|
-
? absolutePath(explicit)
|
|
31
|
-
: home !== undefined
|
|
32
|
-
? absolutePath(home)(".zuke", "node")
|
|
33
|
-
: undefined;
|
|
34
|
-
if (root !== undefined) {
|
|
35
|
-
const release = root(`v${NODE_PIN.version}`);
|
|
36
|
-
candidates.push(host.windows() ? release("npm.cmd").path : release("bin", "npm").path);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
// A relative ZUKE_NODE_HOME or HOME names no place to look.
|
|
41
|
-
}
|
|
42
|
-
return candidates;
|
|
25
|
+
return cachedNodeCandidates("npm", "npm.cmd", host);
|
|
43
26
|
}
|
|
44
27
|
/**
|
|
45
28
|
* Run `npm <args>` in `cwd` with the terminal's output, trying each candidate
|
|
46
29
|
* in order and skipping the ones that are not installed, and return its exit
|
|
47
30
|
* code. The cached npm runs with its Node first on `PATH`, which its script
|
|
48
|
-
* needs to start.
|
|
31
|
+
* needs to start ({@link spawnFirst} does both).
|
|
49
32
|
*
|
|
50
33
|
* @throws {Error} naming every candidate tried when none is installed.
|
|
51
34
|
*/
|
|
52
|
-
export async function runNpm(args, cwd, candidates = npmCandidates()) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (isPath && !(await FileTasks.exists(command)))
|
|
58
|
-
continue;
|
|
59
|
-
try {
|
|
60
|
-
const out = await ProcessTasks.run(command, (s) => {
|
|
61
|
-
s.args(...args).cwd(cwd).stdin("null").stdout("inherit")
|
|
62
|
-
.stderr("inherit");
|
|
63
|
-
for (const [name, value] of Object.entries(pathWithDeno(command))) {
|
|
64
|
-
s.env(name, value);
|
|
65
|
-
}
|
|
66
|
-
return s;
|
|
67
|
-
});
|
|
68
|
-
return out.code;
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
if (!FileTasks.isNotFound(error))
|
|
72
|
-
throw error;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
throw new Error(`zuke: this is a Node project, and no npm was found — tried ` +
|
|
76
|
-
`${candidates.join(", ")}. Run the project's ./zuke once, which ` +
|
|
77
|
-
`installs a pinned Node, or put Node ${NODE_PIN.version.split(".")[0]} or newer on PATH.`);
|
|
35
|
+
export async function runNpm(args, cwd, candidates = npmCandidates(), provision) {
|
|
36
|
+
const child = await spawnFirst(args, { cwd, stdin: "null", stdout: "inherit", stderr: "inherit" }, candidates, (tried) => new Error(`zuke: this is a Node project, and no npm was found — tried ` +
|
|
37
|
+
`${tried.join(", ")}. Put Node ${NODE_PIN.version.split(".")[0]} or newer on PATH, or run zuke again and let it install Node ` +
|
|
38
|
+
`${NODE_PIN.version}.`), provision);
|
|
39
|
+
return (await child.status).code;
|
|
78
40
|
}
|
package/src/project.js
CHANGED
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
* @module
|
|
15
15
|
*/
|
|
16
16
|
import { FileTasks, RuntimeTasks } from "@zuke/core";
|
|
17
|
-
import { spawnDeno } from "./deno_path.js";
|
|
18
|
-
import { runNpm } from "./npm_path.js";
|
|
17
|
+
import { denoCandidates, spawnDeno } from "./deno_path.js";
|
|
18
|
+
import { npmCandidates, runNpm } from "./npm_path.js";
|
|
19
|
+
import { provisionDeno, provisionNode } from "./runtime_install.js";
|
|
19
20
|
import { locateBuild, } from "./dispatch.js";
|
|
20
21
|
import { acceptsMinimumDependencyAge } from "./upgrade.js";
|
|
21
22
|
/** The real {@link ProjectHost}: the file system, and `deno` or `npm` in the root. */
|
|
@@ -41,10 +42,10 @@ export const defaultProjectHost = {
|
|
|
41
42
|
stdin: "null",
|
|
42
43
|
stdout: "inherit",
|
|
43
44
|
stderr: "inherit",
|
|
44
|
-
});
|
|
45
|
+
}, denoCandidates(), provisionDeno());
|
|
45
46
|
return (await child.status).code;
|
|
46
47
|
},
|
|
47
|
-
npm: (npmArgs, cwd) => runNpm(npmArgs, cwd),
|
|
48
|
+
npm: (npmArgs, cwd) => runNpm(npmArgs, cwd, npmCandidates(), provisionNode("npm", "npm.cmd")),
|
|
48
49
|
// The cli runs on Deno, so the runtime is the Deno that runs the command.
|
|
49
50
|
denoVersion: () => RuntimeTasks.facts().version,
|
|
50
51
|
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installing the runtime a build needs when the machine has none.
|
|
3
|
+
*
|
|
4
|
+
* A build file runs on Node or on Deno. When `zuke` finds neither the one on
|
|
5
|
+
* `PATH` nor the pinned release it installed before, it offers to install the
|
|
6
|
+
* pinned release itself. A `zuke` on Deno asks first on a terminal; one on
|
|
7
|
+
* Node (the standalone binary, the npm package) has no `confirm` to ask with
|
|
8
|
+
* yet, so it installs and says so on stderr, as every `zuke` does with no
|
|
9
|
+
* terminal to ask on (CI, a pipe, an MCP client). The
|
|
10
|
+
* download is verified against the SHA-256 pinned in `node_pin.ts` or
|
|
11
|
+
* `deno_pin.ts` before anything is unpacked, by core's `installTree` and
|
|
12
|
+
* `installRelease`.
|
|
13
|
+
*
|
|
14
|
+
* Node goes to `ZUKE_NODE_HOME/v<pin>` (`~/.zuke/node` by default), Deno to
|
|
15
|
+
* `DENO_INSTALL/bin` (`~/.deno/bin`), which is where `nodeCandidates` and
|
|
16
|
+
* `denoCandidates` look on the next run. uv, for a Python build whose
|
|
17
|
+
* `sdk.command` runs it, goes to `ZUKE_UV_HOME/v<pin>` (`~/.zuke/uv`), from
|
|
18
|
+
* the PyPI wheel `uv_pin.ts` pins (see `uv_path.ts`).
|
|
19
|
+
*
|
|
20
|
+
* The option builders are pure, so what is downloaded from where and checked
|
|
21
|
+
* against what is unit-tested; the prompt and the download sit behind
|
|
22
|
+
* {@link RuntimeSetup}, so no test reaches the network.
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import { type AbsolutePath, type InstallReleaseOptions, type InstallTreeOptions, type Platform } from "@zuke/core";
|
|
27
|
+
import { type DenoHost } from "./deno_path.ts";
|
|
28
|
+
/**
|
|
29
|
+
* What installs the pinned Node into `root/v<pin>`: the official
|
|
30
|
+
* `nodejs.org` archive for the platform (`.zip` on Windows, `.tar.gz`
|
|
31
|
+
* elsewhere), its top directory stripped, checked against {@link NODE_PIN}.
|
|
32
|
+
*/
|
|
33
|
+
export declare function nodeTreeOptions(root: AbsolutePath, platform: Platform): InstallTreeOptions;
|
|
34
|
+
/**
|
|
35
|
+
* What installs the pinned Deno into `binDir`: the release's
|
|
36
|
+
* `deno-<target>.zip` from GitHub, checked against {@link DENO_PIN}.
|
|
37
|
+
*/
|
|
38
|
+
export declare function denoReleaseOptions(binDir: AbsolutePath, platform: Platform): InstallReleaseOptions;
|
|
39
|
+
/**
|
|
40
|
+
* What installs the pinned uv into `binDir`: the platform's wheel from PyPI,
|
|
41
|
+
* checked against {@link UV_PIN}, with the `uv` binary taken from the wheel's
|
|
42
|
+
* `scripts` directory.
|
|
43
|
+
*/
|
|
44
|
+
export declare function uvReleaseOptions(binDir: AbsolutePath, platform: Platform): InstallReleaseOptions;
|
|
45
|
+
/**
|
|
46
|
+
* The questions and side effects of installing a runtime, injectable so the
|
|
47
|
+
* consent flow is testable without a terminal or a download.
|
|
48
|
+
*/
|
|
49
|
+
export interface RuntimeSetup {
|
|
50
|
+
/** Whether there is a terminal to ask on (stdin is one). */
|
|
51
|
+
interactive(): boolean;
|
|
52
|
+
/** Ask a yes/no question on the terminal. */
|
|
53
|
+
confirm(question: string): boolean;
|
|
54
|
+
/** Say something on stderr. */
|
|
55
|
+
notice(line: string): void;
|
|
56
|
+
/** Install the pinned Node into `root/v<pin>`. */
|
|
57
|
+
installNode(root: AbsolutePath): Promise<void>;
|
|
58
|
+
/** Install the pinned Deno into `binDir`. */
|
|
59
|
+
installDeno(binDir: AbsolutePath): Promise<void>;
|
|
60
|
+
/** Install the pinned uv into `binDir`. */
|
|
61
|
+
installUv(binDir: AbsolutePath): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
/** What a prompt needs of a {@link RuntimeSetup}: the terminal and stderr. */
|
|
64
|
+
export type ConsentSetup = Pick<RuntimeSetup, "interactive" | "confirm" | "notice">;
|
|
65
|
+
/** What {@link provisionUv} needs: the prompt, and the uv installer. */
|
|
66
|
+
export type UvSetup = ConsentSetup & Pick<RuntimeSetup, "installUv">;
|
|
67
|
+
/** The real {@link RuntimeSetup}: the terminal, stderr and core's installers. */
|
|
68
|
+
export declare const defaultRuntimeSetup: RuntimeSetup;
|
|
69
|
+
/**
|
|
70
|
+
* A provision step for {@link "./deno_path.ts".spawnFirst}: install the pinned
|
|
71
|
+
* Node, then return the path of `name` in it (`node`, or `npm`, whose
|
|
72
|
+
* `windowsFile` is `npm.cmd`).
|
|
73
|
+
*
|
|
74
|
+
* @throws the not-found error it is given, when the person declines or the
|
|
75
|
+
* environment names no home to install into.
|
|
76
|
+
*/
|
|
77
|
+
export declare function provisionNode(name: string, windowsFile: string, setup?: RuntimeSetup, host?: DenoHost): (notFound: Error) => Promise<string>;
|
|
78
|
+
/**
|
|
79
|
+
* A provision step for {@link "./deno_path.ts".spawnFirst}: install the pinned
|
|
80
|
+
* Deno into the bootstrap directory and return its path.
|
|
81
|
+
*
|
|
82
|
+
* @throws the not-found error it is given, when the person declines or the
|
|
83
|
+
* environment names no directory to install into.
|
|
84
|
+
*/
|
|
85
|
+
export declare function provisionDeno(setup?: RuntimeSetup, host?: DenoHost): (notFound: Error) => Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* The directory the pinned uv is installed in: `ZUKE_UV_HOME/v<pin>`, or
|
|
88
|
+
* `~/.zuke/uv/v<pin>`. `undefined` when the environment names no absolute
|
|
89
|
+
* directory for it.
|
|
90
|
+
*/
|
|
91
|
+
export declare function uvHome(host: DenoHost): AbsolutePath | undefined;
|
|
92
|
+
/** The path of the pinned uv's binary in `home`. */
|
|
93
|
+
export declare function uvBinary(home: AbsolutePath, host: DenoHost): string;
|
|
94
|
+
/**
|
|
95
|
+
* A provision step for a worker that runs `uv`: install the pinned uv into
|
|
96
|
+
* {@link uvHome} and return its path.
|
|
97
|
+
*
|
|
98
|
+
* @throws the not-found error it is given, when the person declines or the
|
|
99
|
+
* environment names no directory to install into.
|
|
100
|
+
*/
|
|
101
|
+
export declare function provisionUv(setup?: UvSetup, host?: DenoHost): (notFound: Error) => Promise<string>;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* Installing the runtime a build needs when the machine has none.
|
|
5
|
+
*
|
|
6
|
+
* A build file runs on Node or on Deno. When `zuke` finds neither the one on
|
|
7
|
+
* `PATH` nor the pinned release it installed before, it offers to install the
|
|
8
|
+
* pinned release itself. A `zuke` on Deno asks first on a terminal; one on
|
|
9
|
+
* Node (the standalone binary, the npm package) has no `confirm` to ask with
|
|
10
|
+
* yet, so it installs and says so on stderr, as every `zuke` does with no
|
|
11
|
+
* terminal to ask on (CI, a pipe, an MCP client). The
|
|
12
|
+
* download is verified against the SHA-256 pinned in `node_pin.ts` or
|
|
13
|
+
* `deno_pin.ts` before anything is unpacked, by core's `installTree` and
|
|
14
|
+
* `installRelease`.
|
|
15
|
+
*
|
|
16
|
+
* Node goes to `ZUKE_NODE_HOME/v<pin>` (`~/.zuke/node` by default), Deno to
|
|
17
|
+
* `DENO_INSTALL/bin` (`~/.deno/bin`), which is where `nodeCandidates` and
|
|
18
|
+
* `denoCandidates` look on the next run. uv, for a Python build whose
|
|
19
|
+
* `sdk.command` runs it, goes to `ZUKE_UV_HOME/v<pin>` (`~/.zuke/uv`), from
|
|
20
|
+
* the PyPI wheel `uv_pin.ts` pins (see `uv_path.ts`).
|
|
21
|
+
*
|
|
22
|
+
* The option builders are pure, so what is downloaded from where and checked
|
|
23
|
+
* against what is unit-tested; the prompt and the download sit behind
|
|
24
|
+
* {@link RuntimeSetup}, so no test reaches the network.
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
import { hostPlatform, installRelease, installTree, RuntimeTasks, } from "@zuke/core";
|
|
29
|
+
import { defaultDenoHost, denoInstallDir, installDirFrom, } from "./deno_path.js";
|
|
30
|
+
import { DENO_PIN, denoReleaseTag } from "./deno_pin.js";
|
|
31
|
+
import { NODE_DIST_URL, NODE_PIN } from "./node_pin.js";
|
|
32
|
+
import { nodeHomeRoot } from "./node_path.js";
|
|
33
|
+
import { UV_PIN } from "./uv_pin.js";
|
|
34
|
+
import { output } from "./output.js";
|
|
35
|
+
/** The `os-arch` of a {@link Platform}, as the tables below key it. */
|
|
36
|
+
function slug(platform) {
|
|
37
|
+
return `${platform.os}-${platform.arch}`;
|
|
38
|
+
}
|
|
39
|
+
/** Node's dist platform for each host this CLI runs on. */
|
|
40
|
+
const NODE_PLATFORMS = {
|
|
41
|
+
"linux-x86_64": "linux-x64",
|
|
42
|
+
"linux-aarch64": "linux-arm64",
|
|
43
|
+
"macos-x86_64": "darwin-x64",
|
|
44
|
+
"macos-aarch64": "darwin-arm64",
|
|
45
|
+
"windows-x86_64": "win-x64",
|
|
46
|
+
"windows-aarch64": "win-arm64",
|
|
47
|
+
};
|
|
48
|
+
/** Deno's release target for each host this CLI runs on. */
|
|
49
|
+
const DENO_TARGETS = {
|
|
50
|
+
"linux-x86_64": "x86_64-unknown-linux-gnu",
|
|
51
|
+
"linux-aarch64": "aarch64-unknown-linux-gnu",
|
|
52
|
+
"macos-x86_64": "x86_64-apple-darwin",
|
|
53
|
+
"macos-aarch64": "aarch64-apple-darwin",
|
|
54
|
+
"windows-x86_64": "x86_64-pc-windows-msvc",
|
|
55
|
+
"windows-aarch64": "aarch64-pc-windows-msvc",
|
|
56
|
+
};
|
|
57
|
+
/** The entry of `table` for `platform`, or a refusal naming the platform. */
|
|
58
|
+
function pinnedFor(table, platform, runtime) {
|
|
59
|
+
const value = table[slug(platform)];
|
|
60
|
+
if (value === undefined) {
|
|
61
|
+
throw new Error(`zuke: there is no pinned ${runtime} release for ${slug(platform)}; ` +
|
|
62
|
+
`install ${runtime} yourself and put it on PATH.`);
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* What installs the pinned Node into `root/v<pin>`: the official
|
|
68
|
+
* `nodejs.org` archive for the platform (`.zip` on Windows, `.tar.gz`
|
|
69
|
+
* elsewhere), its top directory stripped, checked against {@link NODE_PIN}.
|
|
70
|
+
*/
|
|
71
|
+
export function nodeTreeOptions(root, platform) {
|
|
72
|
+
const dist = pinnedFor(NODE_PLATFORMS, platform, "Node");
|
|
73
|
+
const archive = platform.os === "windows" ? "zip" : "tar.gz";
|
|
74
|
+
const version = NODE_PIN.version;
|
|
75
|
+
return {
|
|
76
|
+
name: `v${version}`,
|
|
77
|
+
destDir: root.path,
|
|
78
|
+
archive,
|
|
79
|
+
strip: 1,
|
|
80
|
+
bins: [platform.os === "windows" ? "node.exe" : "bin/node"],
|
|
81
|
+
checksum: NODE_PIN.checksums[dist],
|
|
82
|
+
url: () => `${NODE_DIST_URL}/v${version}/node-v${version}-${dist}.${archive}`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* What installs the pinned Deno into `binDir`: the release's
|
|
87
|
+
* `deno-<target>.zip` from GitHub, checked against {@link DENO_PIN}.
|
|
88
|
+
*/
|
|
89
|
+
export function denoReleaseOptions(binDir, platform) {
|
|
90
|
+
const target = pinnedFor(DENO_TARGETS, platform, "Deno");
|
|
91
|
+
return {
|
|
92
|
+
name: "deno",
|
|
93
|
+
destDir: binDir.path,
|
|
94
|
+
archive: "zip",
|
|
95
|
+
binaryPath: platform.os === "windows" ? "deno.exe" : "deno",
|
|
96
|
+
checksum: DENO_PIN.checksums[target],
|
|
97
|
+
url: () => `https://github.com/denoland/deno/releases/download/${denoReleaseTag(DENO_PIN)}/deno-${target}.zip`,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* What installs the pinned uv into `binDir`: the platform's wheel from PyPI,
|
|
102
|
+
* checked against {@link UV_PIN}, with the `uv` binary taken from the wheel's
|
|
103
|
+
* `scripts` directory.
|
|
104
|
+
*/
|
|
105
|
+
export function uvReleaseOptions(binDir, platform) {
|
|
106
|
+
const wheel = pinnedFor(UV_PIN.wheels, platform, "uv");
|
|
107
|
+
const binary = platform.os === "windows" ? "uv.exe" : "uv";
|
|
108
|
+
return {
|
|
109
|
+
name: "uv",
|
|
110
|
+
destDir: binDir.path,
|
|
111
|
+
archive: "zip",
|
|
112
|
+
binaryPath: `uv-${UV_PIN.version}.data/scripts/${binary}`,
|
|
113
|
+
checksum: wheel.sha256,
|
|
114
|
+
url: () => wheel.url,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** The real {@link RuntimeSetup}: the terminal, stderr and core's installers. */
|
|
118
|
+
export const defaultRuntimeSetup = {
|
|
119
|
+
// shortcut: Node has no global confirm, so a CLI on Node installs with a
|
|
120
|
+
// notice instead of asking; ask there once core exports its line reader.
|
|
121
|
+
interactive: () => RuntimeTasks.isTerminal("stdin") &&
|
|
122
|
+
typeof globalThis.confirm === "function",
|
|
123
|
+
confirm: (question) => confirm(question),
|
|
124
|
+
notice: (line) => output.error(line),
|
|
125
|
+
installNode: async (root) => {
|
|
126
|
+
await installTree(nodeTreeOptions(root, hostPlatform()));
|
|
127
|
+
},
|
|
128
|
+
installDeno: async (binDir) => {
|
|
129
|
+
await installRelease(denoReleaseOptions(binDir, hostPlatform()));
|
|
130
|
+
},
|
|
131
|
+
installUv: async (binDir) => {
|
|
132
|
+
await installRelease(uvReleaseOptions(binDir, hostPlatform()));
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Ask before installing `what` into `where` on a terminal, or announce it
|
|
137
|
+
* without one.
|
|
138
|
+
*
|
|
139
|
+
* @throws `declined` when the person says no.
|
|
140
|
+
*/
|
|
141
|
+
function agree(setup, what, where, declined) {
|
|
142
|
+
if (!setup.interactive()) {
|
|
143
|
+
setup.notice(`zuke: ${what} was not found — installing it into ${where}.`);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const question = `zuke: this build needs ${what}, which was not found. ` +
|
|
147
|
+
`Install it into ${where} now (downloaded, checksum-verified)?`;
|
|
148
|
+
if (!setup.confirm(question))
|
|
149
|
+
throw declined;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A provision step for {@link "./deno_path.ts".spawnFirst}: install the pinned
|
|
153
|
+
* Node, then return the path of `name` in it (`node`, or `npm`, whose
|
|
154
|
+
* `windowsFile` is `npm.cmd`).
|
|
155
|
+
*
|
|
156
|
+
* @throws the not-found error it is given, when the person declines or the
|
|
157
|
+
* environment names no home to install into.
|
|
158
|
+
*/
|
|
159
|
+
export function provisionNode(name, windowsFile, setup = defaultRuntimeSetup, host = defaultDenoHost) {
|
|
160
|
+
return async (notFound) => {
|
|
161
|
+
const root = nodeHomeRoot(host);
|
|
162
|
+
if (root === undefined)
|
|
163
|
+
throw notFound;
|
|
164
|
+
const release = root(`v${NODE_PIN.version}`);
|
|
165
|
+
agree(setup, `Node ${NODE_PIN.version}`, release.path, notFound);
|
|
166
|
+
await setup.installNode(root);
|
|
167
|
+
return host.windows()
|
|
168
|
+
? release(windowsFile).path
|
|
169
|
+
: release("bin", name).path;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* A provision step for {@link "./deno_path.ts".spawnFirst}: install the pinned
|
|
174
|
+
* Deno into the bootstrap directory and return its path.
|
|
175
|
+
*
|
|
176
|
+
* @throws the not-found error it is given, when the person declines or the
|
|
177
|
+
* environment names no directory to install into.
|
|
178
|
+
*/
|
|
179
|
+
export function provisionDeno(setup = defaultRuntimeSetup, host = defaultDenoHost) {
|
|
180
|
+
return async (notFound) => {
|
|
181
|
+
const install = denoInstallDir(host);
|
|
182
|
+
if (install === undefined)
|
|
183
|
+
throw notFound;
|
|
184
|
+
const bin = install("bin");
|
|
185
|
+
agree(setup, `Deno ${DENO_PIN.version}`, bin.path, notFound);
|
|
186
|
+
await setup.installDeno(bin);
|
|
187
|
+
return bin(host.windows() ? "deno.exe" : "deno").path;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The directory the pinned uv is installed in: `ZUKE_UV_HOME/v<pin>`, or
|
|
192
|
+
* `~/.zuke/uv/v<pin>`. `undefined` when the environment names no absolute
|
|
193
|
+
* directory for it.
|
|
194
|
+
*/
|
|
195
|
+
export function uvHome(host) {
|
|
196
|
+
return installDirFrom(host, "ZUKE_UV_HOME", ".zuke", "uv")?.(`v${UV_PIN.version}`);
|
|
197
|
+
}
|
|
198
|
+
/** The path of the pinned uv's binary in `home`. */
|
|
199
|
+
export function uvBinary(home, host) {
|
|
200
|
+
return home(host.windows() ? "uv.exe" : "uv").path;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* A provision step for a worker that runs `uv`: install the pinned uv into
|
|
204
|
+
* {@link uvHome} and return its path.
|
|
205
|
+
*
|
|
206
|
+
* @throws the not-found error it is given, when the person declines or the
|
|
207
|
+
* environment names no directory to install into.
|
|
208
|
+
*/
|
|
209
|
+
export function provisionUv(setup = defaultRuntimeSetup, host = defaultDenoHost) {
|
|
210
|
+
return async (notFound) => {
|
|
211
|
+
const home = uvHome(host);
|
|
212
|
+
if (home === undefined)
|
|
213
|
+
throw notFound;
|
|
214
|
+
agree(setup, `uv ${UV_PIN.version}`, home.path, notFound);
|
|
215
|
+
await setup.installUv(home);
|
|
216
|
+
return uvBinary(home, host);
|
|
217
|
+
};
|
|
218
|
+
}
|
package/src/uv_path.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type DenoHost } from "./deno_path.ts";
|
|
2
|
+
import { type UvSetup } from "./runtime_install.ts";
|
|
3
|
+
/** Where to read about installing uv, named when none is found. */
|
|
4
|
+
export declare const UV_INSTALL_DOCS = "https://docs.astral.sh/uv/getting-started/installation/";
|
|
5
|
+
/** Thrown when a build's worker runs uv and none was found or installed. */
|
|
6
|
+
export declare class UvNotFoundError extends Error {
|
|
7
|
+
/** The error's name, as reported by `String(error)` and stack traces. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** The executables that were looked for and not found, in the order tried. */
|
|
10
|
+
readonly tried: readonly string[];
|
|
11
|
+
/**
|
|
12
|
+
* Build the failure from the candidates that were tried, in order.
|
|
13
|
+
*
|
|
14
|
+
* @param tried The executables that were looked for and not found.
|
|
15
|
+
*/
|
|
16
|
+
constructor(tried: readonly string[]);
|
|
17
|
+
}
|
|
18
|
+
/** What {@link WorkerTasks.resolveProgram} asks of the machine, injectable for tests. */
|
|
19
|
+
export interface WorkerProgramHost {
|
|
20
|
+
/** The environment questions: home directories, Windows. */
|
|
21
|
+
readonly host: DenoHost;
|
|
22
|
+
/** Whether a bare program name starts from `PATH`. */
|
|
23
|
+
onPath(program: string): Promise<boolean>;
|
|
24
|
+
/** Whether a file exists. */
|
|
25
|
+
exists(path: string): Promise<boolean>;
|
|
26
|
+
/** How a missing uv is installed. */
|
|
27
|
+
readonly setup: UvSetup;
|
|
28
|
+
}
|
|
29
|
+
/** The real {@link WorkerProgramHost}. */
|
|
30
|
+
export declare const defaultWorkerProgramHost: WorkerProgramHost;
|
|
31
|
+
/** The shape of {@link WorkerTasks}. */
|
|
32
|
+
export interface WorkerTasksApi {
|
|
33
|
+
/**
|
|
34
|
+
* The executable to start a worker whose `sdk.command` begins with
|
|
35
|
+
* `program`: for `uv`, the one on `PATH`, else the pinned uv `zuke`
|
|
36
|
+
* installed, else that uv installed now (see `runtime_install.ts` for when
|
|
37
|
+
* it asks first); any
|
|
38
|
+
* other program unchanged. The `zuke` binary hands this to the engine as its
|
|
39
|
+
* `resolveProgram`.
|
|
40
|
+
*
|
|
41
|
+
* @param program The first word of the build's `sdk.command`.
|
|
42
|
+
* @throws {UvNotFoundError} when there is no uv and none may be installed.
|
|
43
|
+
*/
|
|
44
|
+
resolveProgram(program: string): Promise<string>;
|
|
45
|
+
}
|
|
46
|
+
/** What starts a hosted build's worker: finding (or installing) its program. */
|
|
47
|
+
export declare const WorkerTasks: WorkerTasksApi;
|
|
48
|
+
/** {@link WorkerTasks.resolveProgram} against `machine`, the seam tests drive. */
|
|
49
|
+
export declare function resolveWorkerProgram(program: string, machine: WorkerProgramHost): Promise<string>;
|