@zuke-build/cli 2.10.0 → 2.12.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 +36 -0
- package/src/uv_pin.js +36 -0
- package/src/version.js +1 -1
package/src/dispatch.d.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Forwarding a build command from the global `zuke` to the project's build.
|
|
3
3
|
*
|
|
4
|
-
* The global command
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* `./zuke`. A root with no executable launcher (and every root on Windows,
|
|
15
|
-
* whose files report no mode) gets the launcher's own invocation instead:
|
|
16
|
-
* `deno run -A zuke.ts`, with `--frozen` once a `deno.lock` exists.
|
|
4
|
+
* The global command owns only `setup`, `import`, `doc` and `upgrade`.
|
|
5
|
+
* Everything else — `zuke ci`, `zuke --list`, `zuke graph`, `zuke mcp` —
|
|
6
|
+
* belongs to the build in the current project, so `main` forwards it: it
|
|
7
|
+
* walks up from the working directory to the nearest `zuke.json` (the
|
|
8
|
+
* repository-root marker `zuke setup` writes), then runs the build file it
|
|
9
|
+
* names from that root, stdio inherited — `node <build>` for a build on Node,
|
|
10
|
+
* `deno run -A <build>` (with `--frozen` once a `deno.lock` exists) for one on
|
|
11
|
+
* Deno. The runtime is found on `PATH`, or where `zuke` installs its pinned
|
|
12
|
+
* release, and installed there when it is missing (`runtime_install.ts`), so
|
|
13
|
+
* `zuke` needs nothing else in the project to run it.
|
|
17
14
|
*
|
|
18
15
|
* Discovery has a trust gate, because it runs code the caller never named:
|
|
19
16
|
* a `zuke.json` planted in a shared parent (`/tmp`, a shared checkout tree)
|
|
@@ -24,17 +21,16 @@
|
|
|
24
21
|
* own — it discovers `deno.json` and `package.json` in the root's ancestors,
|
|
25
22
|
* and an import map planted there rewrites what `zuke.ts` imports — so the
|
|
26
23
|
* gate also refuses any such ancestor config file owned by another user. The
|
|
27
|
-
* error names what was refused and
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* not judged either: running the launcher was the explicit act.
|
|
24
|
+
* error names what was refused and how to go on: fix the ownership. Where the
|
|
25
|
+
* platform has no file ownership to compare (Windows), the gate is inert. A
|
|
26
|
+
* root named in {@link LAUNCHER_ROOT_ENV}, by the script that started this
|
|
27
|
+
* `zuke` from inside it, is not judged: starting it there was the explicit
|
|
28
|
+
* act.
|
|
33
29
|
*
|
|
34
30
|
* A build another SDK hosts (a `zuke.json` and no `zuke.ts`) needs nothing
|
|
35
31
|
* from Deno's stack. The standalone binary runs it on its built-in engine,
|
|
36
|
-
*
|
|
37
|
-
*
|
|
32
|
+
* and refuses a pin that engine cannot serve, saying how to get a `zuke` that
|
|
33
|
+
* serves it; it never falls back to Deno.
|
|
38
34
|
*
|
|
39
35
|
* Locating and planning are pure given a probe, so the routing is
|
|
40
36
|
* unit-testable; the spawn goes through the injectable {@link BuildRunner}.
|
|
@@ -43,6 +39,7 @@
|
|
|
43
39
|
*/
|
|
44
40
|
import { type RuntimeFacts } from "@zuke/core";
|
|
45
41
|
import { type ProjectRuntime } from "./runtime_field.ts";
|
|
42
|
+
import { type RuntimeSetup } from "./runtime_install.ts";
|
|
46
43
|
import { type EmbeddedEngine } from "./embedded_engine.ts";
|
|
47
44
|
/**
|
|
48
45
|
* Deno's own config files, in the order it prefers them: a `deno.json` wins
|
|
@@ -51,17 +48,17 @@ import { type EmbeddedEngine } from "./embedded_engine.ts";
|
|
|
51
48
|
export declare const DENO_CONFIG_FILES: readonly ["deno.json", "deno.jsonc"];
|
|
52
49
|
/** The lockfile whose presence turns on `--frozen`, as in the launchers. */
|
|
53
50
|
export declare const LOCK_FILE = "deno.lock";
|
|
54
|
-
/** The POSIX launcher
|
|
51
|
+
/** The POSIX launcher `zuke setup` writes beside {@link CONFIG_FILE}. */
|
|
55
52
|
export declare const LAUNCHER_FILE = "zuke";
|
|
56
53
|
/**
|
|
57
|
-
* Set to `1`
|
|
58
|
-
*
|
|
54
|
+
* Set to `1` by the launchers `zuke setup` writes, in the environment of what
|
|
55
|
+
* they start; this command does not read it.
|
|
59
56
|
*/
|
|
60
57
|
export declare const FORWARDED_ENV = "ZUKE_FORWARDED";
|
|
61
58
|
/**
|
|
62
|
-
* Set
|
|
63
|
-
*
|
|
64
|
-
*
|
|
59
|
+
* Set to a project root by a script that starts `zuke` from inside it (a
|
|
60
|
+
* hosted build's download launcher does), so this `zuke` does not refuse that
|
|
61
|
+
* root at the trust gate: the caller named the project by running it there.
|
|
65
62
|
*/
|
|
66
63
|
export declare const LAUNCHER_ROOT_ENV = "ZUKE_LAUNCHER_ROOT";
|
|
67
64
|
/** Where a forwarded command runs, and how. */
|
|
@@ -70,12 +67,6 @@ export interface BuildLocation {
|
|
|
70
67
|
root: string;
|
|
71
68
|
/** Whether a `deno.lock` sits at the root, so the run passes `--frozen`. */
|
|
72
69
|
frozen: boolean;
|
|
73
|
-
/**
|
|
74
|
-
* The absolute path of the executable `zuke` launcher at the root, run in
|
|
75
|
-
* place of `deno run` — or `null` when there is none, or the platform
|
|
76
|
-
* reports no file mode to tell (Windows).
|
|
77
|
-
*/
|
|
78
|
-
launcher: string | null;
|
|
79
70
|
/**
|
|
80
71
|
* The build file's name: the one the root's `zuke.json` names in its
|
|
81
72
|
* `build` field, `zuke.ts` when it names none.
|
|
@@ -148,9 +139,9 @@ export declare class UntrustedBuildError extends Error {
|
|
|
148
139
|
/**
|
|
149
140
|
* Walk up from `cwd` to the nearest directory holding {@link CONFIG_FILE},
|
|
150
141
|
* asking `probe`. Returns `null` when no ancestor has one — the caller is not
|
|
151
|
-
* inside a Zuke project. A root equal to `vouched`, the directory
|
|
152
|
-
*
|
|
153
|
-
*
|
|
142
|
+
* inside a Zuke project. A root equal to `vouched`, the directory the script
|
|
143
|
+
* that started this process named ({@link LAUNCHER_ROOT_ENV}), is not held to
|
|
144
|
+
* the trust gate.
|
|
154
145
|
*
|
|
155
146
|
* @throws {UntrustedBuildError} when the root found fails the trust gate (see
|
|
156
147
|
* the module docs).
|
|
@@ -181,36 +172,25 @@ export declare function servingEngine(location: BuildLocation, engine: EmbeddedE
|
|
|
181
172
|
/**
|
|
182
173
|
* Run a forwarded command through `runner`. A hosted build whose pin the
|
|
183
174
|
* binary's own `engine` serves runs on it: the binary again, in engine mode,
|
|
184
|
-
* with `args` as they are
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* one this CLI runs on.
|
|
175
|
+
* with `args` as they are. A build file on Node runs as `node <build>`, and
|
|
176
|
+
* anything else on Deno with {@link buildRunArgs} — except a hosted build in
|
|
177
|
+
* the binary or on Node, which never falls back to Deno: a project another SDK
|
|
178
|
+
* hosts needs nothing from Deno's stack. `runtime` is the one this CLI runs
|
|
179
|
+
* on.
|
|
190
180
|
* @throws {Error} for a hosted build the binary cannot serve, or a CLI on
|
|
191
|
-
* Node cannot run,
|
|
192
|
-
* zuke that does.
|
|
181
|
+
* Node cannot run, naming how to get a zuke that does.
|
|
193
182
|
*/
|
|
194
183
|
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
|
|
184
|
+
/** The program a build file on Node runs with: the `node` on `PATH`, else the pinned one `zuke` installs. */
|
|
196
185
|
export declare const NODE = "node";
|
|
197
|
-
/**
|
|
198
|
-
* The stderr line for a hosted build the binary's own `engine` cannot serve,
|
|
199
|
-
* which then goes to the project's launcher; `undefined` when there is
|
|
200
|
-
* nothing to say: no engine compiled in, a `zuke.ts` build, a pin it serves,
|
|
201
|
-
* or no launcher to go to, which {@link runBuild} refuses instead.
|
|
202
|
-
*/
|
|
203
|
-
export declare function embeddedEngineNotice(location: BuildLocation, engine: EmbeddedEngine | undefined): string | undefined;
|
|
204
186
|
/** The launchers' notice for a build on Deno, verbatim. */
|
|
205
187
|
export declare const DENO_SUPPORT_NOTICE: string;
|
|
206
188
|
/**
|
|
207
189
|
* Whether `zuke` prints {@link DENO_SUPPORT_NOTICE} before running the build
|
|
208
|
-
* at `location`: a build on Deno
|
|
209
|
-
*
|
|
210
|
-
* that does not print it and calls `zuke` itself hears it twice. A build on Node,
|
|
211
|
-
* or one another SDK hosts, is told nothing.
|
|
190
|
+
* at `location`: a build file on Deno. A build on Node, or one another SDK
|
|
191
|
+
* hosts, is told nothing.
|
|
212
192
|
*/
|
|
213
|
-
export declare function owesDenoSupportNotice(location: BuildLocation
|
|
193
|
+
export declare function owesDenoSupportNotice(location: BuildLocation): boolean;
|
|
214
194
|
/** The launchers' notice for a run without a lockfile, verbatim. */
|
|
215
195
|
export declare const NO_LOCK_NOTICE: string;
|
|
216
196
|
/**
|
|
@@ -220,20 +200,23 @@ export declare const NO_LOCK_NOTICE: string;
|
|
|
220
200
|
*/
|
|
221
201
|
export declare function runningNotice(location: BuildLocation, engine?: EmbeddedEngine): string;
|
|
222
202
|
/**
|
|
223
|
-
* Runs `program <args>` from `root` — Deno when `program` is omitted,
|
|
224
|
-
*
|
|
225
|
-
* and resolves to its exit code: the
|
|
203
|
+
* Runs `program <args>` from `root` — Deno when `program` is omitted,
|
|
204
|
+
* {@link NODE} for a build file on Node, else the program at that path (this
|
|
205
|
+
* binary, to run its built-in engine) — and resolves to its exit code: the
|
|
226
206
|
* injectable subprocess seam, so the forwarding is testable without a build.
|
|
227
207
|
* `env` adds variables to the environment the child inherits.
|
|
228
208
|
*/
|
|
229
209
|
export type BuildRunner = (root: string, args: string[], program?: string, env?: Readonly<Record<string, string>>) => Promise<number>;
|
|
230
210
|
/**
|
|
231
|
-
*
|
|
232
|
-
* Deno is
|
|
233
|
-
* first on the child's `PATH
|
|
211
|
+
* A {@link BuildRunner} that installs a missing Node or Deno through `setup`
|
|
212
|
+
* (see `runtime_install.ts`). Deno is found by {@link spawnDeno}, which puts
|
|
213
|
+
* it first on the child's `PATH`; {@link NODE} the same way, on `PATH` and
|
|
214
|
+
* then where `zuke` installs the pinned Node. Stdio is inherited, because
|
|
234
215
|
* `zuke mcp` speaks JSON-RPC over the same stdin/stdout and a build may
|
|
235
216
|
* prompt. For the build's lifetime the parent handles signals as
|
|
236
217
|
* {@link signalPlan} says, so an interrupted build is never orphaned with its
|
|
237
218
|
* exit code lost.
|
|
238
219
|
*/
|
|
220
|
+
export declare function buildRunnerWith(setup: RuntimeSetup): BuildRunner;
|
|
221
|
+
/** The default {@link BuildRunner}: {@link buildRunnerWith} the real terminal and installers. */
|
|
239
222
|
export declare const defaultBuildRunner: BuildRunner;
|
package/src/dispatch.js
CHANGED
|
@@ -3,19 +3,16 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Forwarding a build command from the global `zuke` to the project's build.
|
|
5
5
|
*
|
|
6
|
-
* The global command
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* `./zuke`. A root with no executable launcher (and every root on Windows,
|
|
17
|
-
* whose files report no mode) gets the launcher's own invocation instead:
|
|
18
|
-
* `deno run -A zuke.ts`, with `--frozen` once a `deno.lock` exists.
|
|
6
|
+
* The global command owns only `setup`, `import`, `doc` and `upgrade`.
|
|
7
|
+
* Everything else — `zuke ci`, `zuke --list`, `zuke graph`, `zuke mcp` —
|
|
8
|
+
* belongs to the build in the current project, so `main` forwards it: it
|
|
9
|
+
* walks up from the working directory to the nearest `zuke.json` (the
|
|
10
|
+
* repository-root marker `zuke setup` writes), then runs the build file it
|
|
11
|
+
* names from that root, stdio inherited — `node <build>` for a build on Node,
|
|
12
|
+
* `deno run -A <build>` (with `--frozen` once a `deno.lock` exists) for one on
|
|
13
|
+
* Deno. The runtime is found on `PATH`, or where `zuke` installs its pinned
|
|
14
|
+
* release, and installed there when it is missing (`runtime_install.ts`), so
|
|
15
|
+
* `zuke` needs nothing else in the project to run it.
|
|
19
16
|
*
|
|
20
17
|
* Discovery has a trust gate, because it runs code the caller never named:
|
|
21
18
|
* a `zuke.json` planted in a shared parent (`/tmp`, a shared checkout tree)
|
|
@@ -26,17 +23,16 @@
|
|
|
26
23
|
* own — it discovers `deno.json` and `package.json` in the root's ancestors,
|
|
27
24
|
* and an import map planted there rewrites what `zuke.ts` imports — so the
|
|
28
25
|
* gate also refuses any such ancestor config file owned by another user. The
|
|
29
|
-
* error names what was refused and
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* not judged either: running the launcher was the explicit act.
|
|
26
|
+
* error names what was refused and how to go on: fix the ownership. Where the
|
|
27
|
+
* platform has no file ownership to compare (Windows), the gate is inert. A
|
|
28
|
+
* root named in {@link LAUNCHER_ROOT_ENV}, by the script that started this
|
|
29
|
+
* `zuke` from inside it, is not judged: starting it there was the explicit
|
|
30
|
+
* act.
|
|
35
31
|
*
|
|
36
32
|
* A build another SDK hosts (a `zuke.json` and no `zuke.ts`) needs nothing
|
|
37
33
|
* from Deno's stack. The standalone binary runs it on its built-in engine,
|
|
38
|
-
*
|
|
39
|
-
*
|
|
34
|
+
* and refuses a pin that engine cannot serve, saying how to get a `zuke` that
|
|
35
|
+
* serves it; it never falls back to Deno.
|
|
40
36
|
*
|
|
41
37
|
* Locating and planning are pure given a probe, so the routing is
|
|
42
38
|
* unit-testable; the spawn goes through the injectable {@link BuildRunner}.
|
|
@@ -48,7 +44,9 @@ import { denoSupportNotice, noLockNotice } from "./launcher.js";
|
|
|
48
44
|
import { BINARY_INSTALL_DOCS } from "./binary_pin.js";
|
|
49
45
|
import { BUILD_FILE, buildFileNamed } from "./build_file.js";
|
|
50
46
|
import { runtimeNamed } from "./runtime_field.js";
|
|
51
|
-
import { QUIET_DENO_ENV, spawnDeno } from "./deno_path.js";
|
|
47
|
+
import { denoCandidates, QUIET_DENO_ENV, spawnDeno, spawnFirst, } from "./deno_path.js";
|
|
48
|
+
import { nodeCandidates, NodeNotFoundError } from "./node_path.js";
|
|
49
|
+
import { defaultRuntimeSetup, provisionDeno, provisionNode, } from "./runtime_install.js";
|
|
52
50
|
import { EMBEDDED_ENGINE_ENV } from "./embedded_engine.js";
|
|
53
51
|
/**
|
|
54
52
|
* Deno's own config files, in the order it prefers them: a `deno.json` wins
|
|
@@ -57,17 +55,17 @@ import { EMBEDDED_ENGINE_ENV } from "./embedded_engine.js";
|
|
|
57
55
|
export const DENO_CONFIG_FILES = ["deno.json", "deno.jsonc"];
|
|
58
56
|
/** The lockfile whose presence turns on `--frozen`, as in the launchers. */
|
|
59
57
|
export const LOCK_FILE = "deno.lock";
|
|
60
|
-
/** The POSIX launcher
|
|
58
|
+
/** The POSIX launcher `zuke setup` writes beside {@link CONFIG_FILE}. */
|
|
61
59
|
export const LAUNCHER_FILE = "zuke";
|
|
62
60
|
/**
|
|
63
|
-
* Set to `1`
|
|
64
|
-
*
|
|
61
|
+
* Set to `1` by the launchers `zuke setup` writes, in the environment of what
|
|
62
|
+
* they start; this command does not read it.
|
|
65
63
|
*/
|
|
66
64
|
export const FORWARDED_ENV = "ZUKE_FORWARDED";
|
|
67
65
|
/**
|
|
68
|
-
* Set
|
|
69
|
-
*
|
|
70
|
-
*
|
|
66
|
+
* Set to a project root by a script that starts `zuke` from inside it (a
|
|
67
|
+
* hosted build's download launcher does), so this `zuke` does not refuse that
|
|
68
|
+
* root at the trust gate: the caller named the project by running it there.
|
|
71
69
|
*/
|
|
72
70
|
export const LAUNCHER_ROOT_ENV = "ZUKE_LAUNCHER_ROOT";
|
|
73
71
|
/**
|
|
@@ -125,11 +123,11 @@ export class UntrustedBuildError extends Error {
|
|
|
125
123
|
*/
|
|
126
124
|
constructor(root, reason) {
|
|
127
125
|
// Prose only — never a rendered shell line to paste, since `root` is
|
|
128
|
-
// whatever the filesystem says
|
|
129
|
-
// owns it.
|
|
126
|
+
// whatever the filesystem says.
|
|
130
127
|
super(`zuke: refusing to run the build at ${root}: ${reason}, so the files ` +
|
|
131
|
-
`there could have been planted by someone else. If you trust it,
|
|
132
|
-
`
|
|
128
|
+
`there could have been planted by someone else. If you trust it, ` +
|
|
129
|
+
`make them yours (or stop them being writable by everyone) and run ` +
|
|
130
|
+
`zuke again.`);
|
|
133
131
|
this.root = root;
|
|
134
132
|
this.reason = reason;
|
|
135
133
|
}
|
|
@@ -141,77 +139,19 @@ export class UntrustedBuildError extends Error {
|
|
|
141
139
|
const ANCESTOR_CONFIG_FILES = [...DENO_CONFIG_FILES, "package.json"];
|
|
142
140
|
/**
|
|
143
141
|
* The files in the root itself that decide what runs: the marker, the default
|
|
144
|
-
* build file, the
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* were. The probe follows links, so a symlinked launcher is judged by the
|
|
149
|
-
* file it points at.
|
|
142
|
+
* build file, the lockfile, and the root's own config. A build file the
|
|
143
|
+
* marker names is judged on top of these. Owning the directory is not owning
|
|
144
|
+
* these — a `chown` of the directory alone leaves them as they were. The
|
|
145
|
+
* probe follows links, so a symlinked file is judged by the file it points at.
|
|
150
146
|
*/
|
|
151
147
|
const ROOT_FILES = [
|
|
152
148
|
CONFIG_FILE,
|
|
153
149
|
BUILD_FILE,
|
|
154
|
-
LAUNCHER_FILE,
|
|
155
150
|
LOCK_FILE,
|
|
156
151
|
...ANCESTOR_CONFIG_FILES,
|
|
157
152
|
];
|
|
158
153
|
/** The world-writable permission bit. */
|
|
159
154
|
const WORLD_WRITABLE = 0o002;
|
|
160
|
-
/** The file-type bits of a mode, and the value that marks a regular file. */
|
|
161
|
-
const FILE_TYPE = 0o170000;
|
|
162
|
-
const REGULAR_FILE = 0o100000;
|
|
163
|
-
/** Any of the execute permission bits. */
|
|
164
|
-
const EXECUTABLE = 0o111;
|
|
165
|
-
/**
|
|
166
|
-
* The root's launcher, resolved through any link, when it is an executable
|
|
167
|
-
* regular file, else `null`. Where the gate is inert (no user id: Windows)
|
|
168
|
-
* there is no launcher either, so nothing runs that the gate did not judge.
|
|
169
|
-
* The file itself was judged with the root's files; a link's target
|
|
170
|
-
* directory is judged here, since whoever can write there can swap the file.
|
|
171
|
-
*
|
|
172
|
-
* @throws {UntrustedBuildError} when the target's directory fails the gate.
|
|
173
|
-
*/
|
|
174
|
-
async function launcherAt(root, probe) {
|
|
175
|
-
const uid = probe.uid();
|
|
176
|
-
if (uid === null)
|
|
177
|
-
return null;
|
|
178
|
-
const path = root(LAUNCHER_FILE).path;
|
|
179
|
-
const mode = (await probe.ownership(path))?.mode ?? null;
|
|
180
|
-
if (mode === null)
|
|
181
|
-
return null;
|
|
182
|
-
const runnable = (mode & FILE_TYPE) === REGULAR_FILE &&
|
|
183
|
-
(mode & EXECUTABLE) !== 0;
|
|
184
|
-
if (!runnable)
|
|
185
|
-
return null;
|
|
186
|
-
// Only the target's own directory, not its ancestors — the root's
|
|
187
|
-
// ancestors are not judged as directories either.
|
|
188
|
-
const real = await probe.realPath(path);
|
|
189
|
-
const home = absolutePath(real).parent();
|
|
190
|
-
assertEntry(await probe.ownership(home.path), home.path, uid, root);
|
|
191
|
-
// Run it by its path under the root, not the resolved one. A launcher finds
|
|
192
|
-
// the project it builds from the path it was called by (`dirname "$0"`), so
|
|
193
|
-
// a `zuke` symlinked to a launcher shared across repos, called by its
|
|
194
|
-
// resolved path, would build the shared launcher's own directory instead.
|
|
195
|
-
const link = await probe.readLink(path);
|
|
196
|
-
if (link === null)
|
|
197
|
-
return path;
|
|
198
|
-
// Running the link re-resolves it, so it is only the file that was judged
|
|
199
|
-
// if the link is one hop straight to it: re-pointing that hop needs write
|
|
200
|
-
// access to the root, which the gate refuses to anyone but you. A chain
|
|
201
|
-
// through another directory could be re-pointed by whoever writes there,
|
|
202
|
-
// after the check. Rather than judge every hop, a chain gets the launcher's
|
|
203
|
-
// own `deno run` — the right project, and only files the gate judged.
|
|
204
|
-
//
|
|
205
|
-
// A relative link is read against the root's real path, not the root as
|
|
206
|
-
// written: the root's own ancestors are not judged (macOS's `/var` is a link
|
|
207
|
-
// to `/private/var`, so every temp directory is reached through one), while
|
|
208
|
-
// any link inside the target — the hops that matter — still leaves the
|
|
209
|
-
// lexical path short of the real one, and falls back.
|
|
210
|
-
const target = link.startsWith("/")
|
|
211
|
-
? absolutePath(link)
|
|
212
|
-
: absolutePath(await probe.realPath(root.path))(link);
|
|
213
|
-
return target.path === real ? path : null;
|
|
214
|
-
}
|
|
215
155
|
/**
|
|
216
156
|
* Refuse an entry owned by someone other than `uid`, or writable by everyone;
|
|
217
157
|
* an absent entry, or a property the platform does not report, passes.
|
|
@@ -230,9 +170,9 @@ function assertEntry(own, subject, uid, root) {
|
|
|
230
170
|
/**
|
|
231
171
|
* Walk up from `cwd` to the nearest directory holding {@link CONFIG_FILE},
|
|
232
172
|
* asking `probe`. Returns `null` when no ancestor has one — the caller is not
|
|
233
|
-
* inside a Zuke project. A root equal to `vouched`, the directory
|
|
234
|
-
*
|
|
235
|
-
*
|
|
173
|
+
* inside a Zuke project. A root equal to `vouched`, the directory the script
|
|
174
|
+
* that started this process named ({@link LAUNCHER_ROOT_ENV}), is not held to
|
|
175
|
+
* the trust gate.
|
|
236
176
|
*
|
|
237
177
|
* @throws {UntrustedBuildError} when the root found fails the trust gate (see
|
|
238
178
|
* the module docs).
|
|
@@ -241,8 +181,7 @@ export async function locateBuild(cwd, probe, vouched = EnvTasks.get(LAUNCHER_RO
|
|
|
241
181
|
let dir = absolutePath(cwd);
|
|
242
182
|
while (true) {
|
|
243
183
|
if (await probe.exists(dir(CONFIG_FILE).path)) {
|
|
244
|
-
// The root a
|
|
245
|
-
// that launcher is the one running, so it is neither judged nor rerun.
|
|
184
|
+
// The root a script started this from was named by running it there.
|
|
246
185
|
const named = vouched !== undefined && dir.path === vouched;
|
|
247
186
|
if (!named)
|
|
248
187
|
await assertTrusted(dir, probe);
|
|
@@ -260,7 +199,6 @@ export async function locateBuild(cwd, probe, vouched = EnvTasks.get(LAUNCHER_RO
|
|
|
260
199
|
build,
|
|
261
200
|
runtime,
|
|
262
201
|
frozen: await probe.exists(dir(LOCK_FILE).path),
|
|
263
|
-
launcher: named ? null : await launcherAt(dir, probe),
|
|
264
202
|
engine: await probe.exists(dir(build).path)
|
|
265
203
|
? null
|
|
266
204
|
: await hostedEngine(dir, build, probe),
|
|
@@ -398,22 +336,16 @@ export function servingEngine(location, engine) {
|
|
|
398
336
|
? engine
|
|
399
337
|
: undefined;
|
|
400
338
|
}
|
|
401
|
-
/** Whether a forwarded command goes to the root's launcher rather than running here. */
|
|
402
|
-
function viaLauncher(location) {
|
|
403
|
-
return location.launcher !== null && EnvTasks.get(FORWARDED_ENV) !== "1";
|
|
404
|
-
}
|
|
405
339
|
/**
|
|
406
340
|
* Run a forwarded command through `runner`. A hosted build whose pin the
|
|
407
341
|
* binary's own `engine` serves runs on it: the binary again, in engine mode,
|
|
408
|
-
* with `args` as they are
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
* one this CLI runs on.
|
|
342
|
+
* with `args` as they are. A build file on Node runs as `node <build>`, and
|
|
343
|
+
* anything else on Deno with {@link buildRunArgs} — except a hosted build in
|
|
344
|
+
* the binary or on Node, which never falls back to Deno: a project another SDK
|
|
345
|
+
* hosts needs nothing from Deno's stack. `runtime` is the one this CLI runs
|
|
346
|
+
* on.
|
|
414
347
|
* @throws {Error} for a hosted build the binary cannot serve, or a CLI on
|
|
415
|
-
* Node cannot run,
|
|
416
|
-
* zuke that does.
|
|
348
|
+
* Node cannot run, naming how to get a zuke that does.
|
|
417
349
|
*/
|
|
418
350
|
export function runBuild(runner, location, args, env, engine, runtime = RuntimeTasks.facts().name) {
|
|
419
351
|
const serving = servingEngine(location, engine);
|
|
@@ -423,23 +355,18 @@ export function runBuild(runner, location, args, env, engine, runtime = RuntimeT
|
|
|
423
355
|
[EMBEDDED_ENGINE_ENV]: "1",
|
|
424
356
|
});
|
|
425
357
|
}
|
|
426
|
-
if (location.launcher !== null && viaLauncher(location)) {
|
|
427
|
-
return runner(location.root, args, location.launcher, env);
|
|
428
|
-
}
|
|
429
358
|
if (location.engine !== null && runtime !== "deno") {
|
|
430
359
|
// Installed from npm and run by Node: the Deno route would make a project
|
|
431
360
|
// another SDK hosts need Deno, which it never does.
|
|
432
361
|
throw new Error(`zuke: this zuke runs on Node and has no @zuke/engine to run ` +
|
|
433
|
-
`${CONFIG_FILE}'s ${location.engine}.
|
|
434
|
-
|
|
435
|
-
`release it pins, or install the zuke binary (${BINARY_INSTALL_DOCS}).`);
|
|
362
|
+
`${CONFIG_FILE}'s ${location.engine}. Install the zuke binary ` +
|
|
363
|
+
`(${BINARY_INSTALL_DOCS}).`);
|
|
436
364
|
}
|
|
437
365
|
if (engine !== undefined && location.engine !== null) {
|
|
438
366
|
throw new Error(`zuke: this zuke's built-in @zuke/engine ${engine.version} cannot run ` +
|
|
439
367
|
`${CONFIG_FILE}'s ${location.engine}. Install a zuke release that ` +
|
|
440
|
-
`carries it (${BINARY_INSTALL_DOCS}
|
|
441
|
-
"
|
|
442
|
-
"release it pins, or move the project with `zuke upgrade --engine`.");
|
|
368
|
+
`carries it (${BINARY_INSTALL_DOCS}; brew upgrade zuke for ` +
|
|
369
|
+
"Homebrew), or move the project with `zuke upgrade --engine`.");
|
|
443
370
|
}
|
|
444
371
|
// A build file on Node runs as `node <build>`: Node strips the types of a
|
|
445
372
|
// TypeScript file itself, and resolves its imports from node_modules.
|
|
@@ -448,39 +375,17 @@ export function runBuild(runner, location, args, env, engine, runtime = RuntimeT
|
|
|
448
375
|
}
|
|
449
376
|
return runner(location.root, buildRunArgs(location, args), undefined, env);
|
|
450
377
|
}
|
|
451
|
-
/** The program a build file on Node runs with
|
|
378
|
+
/** The program a build file on Node runs with: the `node` on `PATH`, else the pinned one `zuke` installs. */
|
|
452
379
|
export const NODE = "node";
|
|
453
|
-
/**
|
|
454
|
-
* The stderr line for a hosted build the binary's own `engine` cannot serve,
|
|
455
|
-
* which then goes to the project's launcher; `undefined` when there is
|
|
456
|
-
* nothing to say: no engine compiled in, a `zuke.ts` build, a pin it serves,
|
|
457
|
-
* or no launcher to go to, which {@link runBuild} refuses instead.
|
|
458
|
-
*/
|
|
459
|
-
export function embeddedEngineNotice(location, engine) {
|
|
460
|
-
if (engine === undefined || location.engine === null ||
|
|
461
|
-
servingEngine(location, engine) !== undefined || !viaLauncher(location)) {
|
|
462
|
-
return undefined;
|
|
463
|
-
}
|
|
464
|
-
return `zuke: this zuke's built-in @zuke/engine ${engine.version} cannot ` +
|
|
465
|
-
`run ${CONFIG_FILE}'s ${location.engine}, so the project's launcher ` +
|
|
466
|
-
"runs it";
|
|
467
|
-
}
|
|
468
380
|
/** The launchers' notice for a build on Deno, verbatim. */
|
|
469
381
|
export const DENO_SUPPORT_NOTICE = denoSupportNotice("—");
|
|
470
382
|
/**
|
|
471
383
|
* Whether `zuke` prints {@link DENO_SUPPORT_NOTICE} before running the build
|
|
472
|
-
* at `location`: a build on Deno
|
|
473
|
-
*
|
|
474
|
-
* that does not print it and calls `zuke` itself hears it twice. A build on Node,
|
|
475
|
-
* or one another SDK hosts, is told nothing.
|
|
384
|
+
* at `location`: a build file on Deno. A build on Node, or one another SDK
|
|
385
|
+
* hosts, is told nothing.
|
|
476
386
|
*/
|
|
477
|
-
export
|
|
478
|
-
|
|
479
|
-
return false;
|
|
480
|
-
// runBuild skips the launcher when this is a launcher's own call, or one
|
|
481
|
-
// inherited from a build a launcher started: then nothing else says it.
|
|
482
|
-
return location.launcher === null || !viaLauncher(location) ||
|
|
483
|
-
!(await probe.readText(location.launcher)).includes(DENO_SUPPORT_NOTICE);
|
|
387
|
+
export function owesDenoSupportNotice(location) {
|
|
388
|
+
return location.engine === null && location.runtime === "deno";
|
|
484
389
|
}
|
|
485
390
|
/** The launchers' notice for a run without a lockfile, verbatim. */
|
|
486
391
|
export const NO_LOCK_NOTICE = noLockNotice("—");
|
|
@@ -501,8 +406,7 @@ export function runningNotice(location, engine) {
|
|
|
501
406
|
/**
|
|
502
407
|
* The signals the forwarding parent handles while the build runs, and how.
|
|
503
408
|
*
|
|
504
|
-
*
|
|
505
|
-
* forwarding parent cannot exec, so it must not die first: a Ctrl-C reaches
|
|
409
|
+
* A forwarding parent cannot exec into the build, so it must not die first: a Ctrl-C reaches
|
|
506
410
|
* the whole foreground group, and the build's own handler cancels it
|
|
507
411
|
* gracefully (a second Ctrl-C force-exits), so the parent only **ignores**
|
|
508
412
|
* SIGINT — forwarding it would deliver that second signal — and stays to
|
|
@@ -525,31 +429,43 @@ function signalPlan(child) {
|
|
|
525
429
|
: [["SIGINT", ignore], ["SIGTERM", forward("SIGTERM")]];
|
|
526
430
|
}
|
|
527
431
|
/**
|
|
528
|
-
*
|
|
529
|
-
* Deno is
|
|
530
|
-
* first on the child's `PATH
|
|
432
|
+
* A {@link BuildRunner} that installs a missing Node or Deno through `setup`
|
|
433
|
+
* (see `runtime_install.ts`). Deno is found by {@link spawnDeno}, which puts
|
|
434
|
+
* it first on the child's `PATH`; {@link NODE} the same way, on `PATH` and
|
|
435
|
+
* then where `zuke` installs the pinned Node. Stdio is inherited, because
|
|
531
436
|
* `zuke mcp` speaks JSON-RPC over the same stdin/stdout and a build may
|
|
532
437
|
* prompt. For the build's lifetime the parent handles signals as
|
|
533
438
|
* {@link signalPlan} says, so an interrupted build is never orphaned with its
|
|
534
439
|
* exit code lost.
|
|
535
440
|
*/
|
|
536
|
-
export
|
|
537
|
-
|
|
538
|
-
|
|
441
|
+
export function buildRunnerWith(setup) {
|
|
442
|
+
return async (root, args, program, env) => {
|
|
443
|
+
const options = {
|
|
539
444
|
cwd: root,
|
|
540
445
|
stdin: "inherit",
|
|
541
446
|
stdout: "inherit",
|
|
542
447
|
stderr: "inherit",
|
|
543
|
-
env,
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
448
|
+
env: { ...env },
|
|
449
|
+
};
|
|
450
|
+
const child = program === undefined
|
|
451
|
+
? await spawnDeno(args, options, denoCandidates(), provisionDeno(setup))
|
|
452
|
+
: program === NODE
|
|
453
|
+
? await spawnFirst(args, options, nodeCandidates(), (tried) => new NodeNotFoundError(tried), provisionNode("node", "node.exe", setup))
|
|
454
|
+
: ProcessTasks.spawn(program, (s) => {
|
|
455
|
+
s.args(...args).cwd(root).stdin("inherit").stdout("inherit")
|
|
456
|
+
.stderr("inherit");
|
|
457
|
+
for (const [name, value] of Object.entries({ ...env, ...QUIET_DENO_ENV })) {
|
|
458
|
+
s.env(name, value);
|
|
459
|
+
}
|
|
460
|
+
return s;
|
|
461
|
+
});
|
|
462
|
+
return await awaitBuild(child);
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
/** The default {@link BuildRunner}: {@link buildRunnerWith} the real terminal and installers. */
|
|
466
|
+
export const defaultBuildRunner = buildRunnerWith(defaultRuntimeSetup);
|
|
467
|
+
/** The build's exit code, with {@link signalPlan}'s handlers held while it runs. */
|
|
468
|
+
async function awaitBuild(child) {
|
|
553
469
|
const plan = signalPlan(child);
|
|
554
470
|
for (const [signal, handler] of plan) {
|
|
555
471
|
ProcessTasks.addSignalListener(signal, handler);
|
|
@@ -563,4 +479,4 @@ export const defaultBuildRunner = async (root, args, program, env) => {
|
|
|
563
479
|
ProcessTasks.removeSignalListener(signal, handler);
|
|
564
480
|
}
|
|
565
481
|
}
|
|
566
|
-
}
|
|
482
|
+
}
|