@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
package/README.md
CHANGED
|
@@ -39,7 +39,8 @@ scaffold Zuke into any project with `zuke setup`, then run its build from
|
|
|
39
39
|
anywhere inside the project with `zuke <target>`: every command that is not
|
|
40
40
|
the CLI's own (`setup`, `import`, `doc`, `upgrade`, and the project
|
|
41
41
|
commands `add`, `remove`, `cache` and `relock`) is forwarded to the
|
|
42
|
-
nearest `zuke.ts`,
|
|
42
|
+
nearest `zuke.ts`, which it runs on Node or Deno, installing either when
|
|
43
|
+
the machine has none. Update the
|
|
43
44
|
installed CLI itself with `zuke upgrade`, and manage a project's
|
|
44
45
|
dependencies and lock with `zuke add`, `remove`, `cache` and `relock`.
|
|
45
46
|
@module
|
|
@@ -67,12 +68,29 @@ const EMBEDDED_ENGINE_ENV: "ZUKE_EMBEDDED_ENGINE"
|
|
|
67
68
|
and removes it, so nothing the build starts inherits it.
|
|
68
69
|
|
|
69
70
|
const FORWARDED_ENV: "ZUKE_FORWARDED"
|
|
70
|
-
Set to `1`
|
|
71
|
-
|
|
71
|
+
Set to `1` by the launchers `zuke setup` writes, in the environment of what
|
|
72
|
+
they start; this command does not read it.
|
|
73
|
+
|
|
74
|
+
const WorkerTasks: WorkerTasksApi
|
|
75
|
+
What starts a hosted build's worker: finding (or installing) its program.
|
|
72
76
|
|
|
73
77
|
const defaultPrompter: Prompter
|
|
74
78
|
The real {@link Prompter}, backed by Deno's `prompt`/`confirm`.
|
|
75
79
|
|
|
80
|
+
class UvNotFoundError extends Error
|
|
81
|
+
Thrown when a build's worker runs uv and none was found or installed.
|
|
82
|
+
|
|
83
|
+
constructor(tried: readonly string[])
|
|
84
|
+
Build the failure from the candidates that were tried, in order.
|
|
85
|
+
|
|
86
|
+
@param tried
|
|
87
|
+
The executables that were looked for and not found.
|
|
88
|
+
|
|
89
|
+
override name: string
|
|
90
|
+
The error's name, as reported by `String(error)` and stack traces.
|
|
91
|
+
readonly tried: readonly string[]
|
|
92
|
+
The executables that were looked for and not found, in the order tried.
|
|
93
|
+
|
|
76
94
|
interface BinaryPin
|
|
77
95
|
The pinned `zuke` release, the engine inside it, and each archive's digest.
|
|
78
96
|
|
|
@@ -90,10 +108,6 @@ interface BuildLocation
|
|
|
90
108
|
The absolute repository root: the directory holding `zuke.json`.
|
|
91
109
|
frozen: boolean
|
|
92
110
|
Whether a `deno.lock` sits at the root, so the run passes `--frozen`.
|
|
93
|
-
launcher: string | null
|
|
94
|
-
The absolute path of the executable `zuke` launcher at the root, run in
|
|
95
|
-
place of `deno run` — or `null` when there is none, or the platform
|
|
96
|
-
reports no file mode to tell (Windows).
|
|
97
111
|
build: string
|
|
98
112
|
The build file's name: the one the root's `zuke.json` names in its
|
|
99
113
|
`build` field, `zuke.ts` when it names none.
|
|
@@ -332,13 +346,30 @@ interface UpgradeHost extends InstallHost
|
|
|
332
346
|
readText(path: string): Promise<string>
|
|
333
347
|
Read a text file, rejecting when it cannot be read.
|
|
334
348
|
|
|
349
|
+
interface WorkerTasksApi
|
|
350
|
+
The shape of {@link WorkerTasks}.
|
|
351
|
+
|
|
352
|
+
resolveProgram(program: string): Promise<string>
|
|
353
|
+
The executable to start a worker whose `sdk.command` begins with
|
|
354
|
+
`program`: for `uv`, the one on `PATH`, else the pinned uv `zuke`
|
|
355
|
+
installed, else that uv installed now (see `runtime_install.ts` for when
|
|
356
|
+
it asks first); any
|
|
357
|
+
other program unchanged. The `zuke` binary hands this to the engine as its
|
|
358
|
+
`resolveProgram`.
|
|
359
|
+
|
|
360
|
+
@param program
|
|
361
|
+
The first word of the build's `sdk.command`.
|
|
362
|
+
|
|
363
|
+
@throws {UvNotFoundError}
|
|
364
|
+
when there is no uv and none may be installed.
|
|
365
|
+
|
|
335
366
|
type BinaryTarget = "aarch64-apple-darwin" | "x86_64-apple-darwin" | "aarch64-unknown-linux-gnu" | "x86_64-unknown-linux-gnu" | "x86_64-pc-windows-msvc"
|
|
336
367
|
A platform a `zuke` release ships a binary for, as its archive names it.
|
|
337
368
|
|
|
338
369
|
type BuildRunner = (root: string, args: string[], program?: string, env?: Readonly<Record<string, string>>) => Promise<number>
|
|
339
|
-
Runs `program <args>` from `root` — Deno when `program` is omitted,
|
|
340
|
-
|
|
341
|
-
and resolves to its exit code: the
|
|
370
|
+
Runs `program <args>` from `root` — Deno when `program` is omitted,
|
|
371
|
+
{@link NODE} for a build file on Node, else the program at that path (this
|
|
372
|
+
binary, to run its built-in engine) — and resolves to its exit code: the
|
|
342
373
|
injectable subprocess seam, so the forwarding is testable without a build.
|
|
343
374
|
`env` adds variables to the environment the child inherits.
|
|
344
375
|
|
package/mod.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type { ProjectHost } from "./src/project.ts";
|
|
|
18
18
|
export type { ProjectRuntime } from "./src/runtime_field.ts";
|
|
19
19
|
export type { BuildLocation, BuildProbe, BuildRunner, Ownership, } from "./src/dispatch.ts";
|
|
20
20
|
export { FORWARDED_ENV } from "./src/dispatch.ts";
|
|
21
|
+
export { UvNotFoundError, WorkerTasks, type WorkerTasksApi, } from "./src/uv_path.ts";
|
|
21
22
|
/**
|
|
22
23
|
* The interactive surface, injectable so the wizard is testable without a TTY.
|
|
23
24
|
*/
|
package/mod.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* anywhere inside the project with `zuke <target>`: every command that is not
|
|
12
12
|
* the CLI's own (`setup`, `import`, `doc`, `upgrade`, and the project
|
|
13
13
|
* commands `add`, `remove`, `cache` and `relock`) is forwarded to the
|
|
14
|
-
* nearest `zuke.ts`,
|
|
14
|
+
* nearest `zuke.ts`, which it runs on Node or Deno, installing either when
|
|
15
|
+
* the machine has none. Update the
|
|
15
16
|
* installed CLI itself with `zuke upgrade`, and manage a project's
|
|
16
17
|
* dependencies and lock with `zuke add`, `remove`, `cache` and `relock`.
|
|
17
18
|
*
|
|
@@ -25,7 +26,7 @@ import { defaultStarActions, promptStar, } from "./src/star.js";
|
|
|
25
26
|
import { VERSION } from "./src/version.js";
|
|
26
27
|
import { installLabel, installSource, } from "./src/install_source.js";
|
|
27
28
|
import { DENO_PIN } from "./src/deno_pin.js";
|
|
28
|
-
import { buildLabel, defaultBuildProbe, defaultBuildRunner, DENO_SUPPORT_NOTICE,
|
|
29
|
+
import { buildLabel, defaultBuildProbe, defaultBuildRunner, DENO_SUPPORT_NOTICE, locateBuild, NO_LOCK_NOTICE, owesDenoSupportNotice, runBuild, runningNotice, servingEngine, } from "./src/dispatch.js";
|
|
29
30
|
import { absolutePath, logoLines, resolveDocSpec, RuntimeTasks, } from "@zuke/core";
|
|
30
31
|
import { runDenoIsolated } from "./src/deno_isolated.js";
|
|
31
32
|
import { defaultDenoHost, firstSet } from "./src/deno_path.js";
|
|
@@ -41,6 +42,7 @@ import { versionPanel } from "@zuke/core/render";
|
|
|
41
42
|
import { homeRelative, lockedCoreVersions, projectConfigText, projectLockPath, VERSION_PATTERN, } from "./src/version_report.js";
|
|
42
43
|
export { EMBEDDED_ENGINE_ENV, } from "./src/embedded_engine.js";
|
|
43
44
|
export { FORWARDED_ENV } from "./src/dispatch.js";
|
|
45
|
+
export { UvNotFoundError, WorkerTasks, } from "./src/uv_path.js";
|
|
44
46
|
/** The real {@link Prompter}, backed by Deno's `prompt`/`confirm`. */
|
|
45
47
|
export const defaultPrompter = {
|
|
46
48
|
interactive() {
|
|
@@ -386,7 +388,7 @@ function helpText(paint) {
|
|
|
386
388
|
*/
|
|
387
389
|
function buildHelpHeading(location, paint, engine) {
|
|
388
390
|
const title = `This project's build (${buildLabel(location, engine)}) — ` +
|
|
389
|
-
`run as \`zuke <target
|
|
391
|
+
`run as \`zuke <target>\`:`;
|
|
390
392
|
return `\n${paint.muted("─".repeat(72))}\n${paint.heading(title)}\n`;
|
|
391
393
|
}
|
|
392
394
|
/**
|
|
@@ -631,7 +633,7 @@ async function commandDoc(args, host, runner) {
|
|
|
631
633
|
*/
|
|
632
634
|
async function forwardToBuild(args, probe, runner, engine) {
|
|
633
635
|
// The CLI's own stderr sink, not `ConsoleTasks`: `ZUKE_LOG_LEVEL` is a knob
|
|
634
|
-
// for the build's output, and neither a security refusal nor the
|
|
636
|
+
// for the build's output, and neither a security refusal nor the
|
|
635
637
|
// unverified-lockfile notice may be silenced by it. The sink neutralises the
|
|
636
638
|
// line on an Actions runner — the root and the error message below carry
|
|
637
639
|
// text from the filesystem and from a failed spawn, not from Zuke.
|
|
@@ -641,23 +643,17 @@ async function forwardToBuild(args, probe, runner, engine) {
|
|
|
641
643
|
if (location === null)
|
|
642
644
|
return null;
|
|
643
645
|
// Discovery ran something the caller never named: say which, unless it
|
|
644
|
-
// is the build right here,
|
|
646
|
+
// is the build right here, which the caller did name by standing in it.
|
|
645
647
|
if (location.root !== absolutePath(cwd).path) {
|
|
646
648
|
output.error(runningNotice(location, engine));
|
|
647
649
|
}
|
|
648
|
-
|
|
649
|
-
if (fallback !== undefined)
|
|
650
|
-
output.error(fallback);
|
|
651
|
-
// A launcher prints its own notices; the CLI says where a Deno build
|
|
652
|
-
// stands only when the launcher it goes through does not.
|
|
653
|
-
if (await owesDenoSupportNotice(location, probe)) {
|
|
650
|
+
if (owesDenoSupportNotice(location)) {
|
|
654
651
|
output.error(DENO_SUPPORT_NOTICE);
|
|
655
652
|
}
|
|
656
|
-
// Only the bare `deno run` a launcher stands in for is this notice's.
|
|
657
653
|
// A hosted build has no Deno config for Deno to write a lock into, and a
|
|
658
654
|
// Node build never writes a deno.lock, so neither is told.
|
|
659
|
-
if (location.
|
|
660
|
-
location.
|
|
655
|
+
if (!location.frozen && location.engine === null &&
|
|
656
|
+
location.runtime === "deno") {
|
|
661
657
|
output.error(NO_LOCK_NOTICE);
|
|
662
658
|
}
|
|
663
659
|
return await runBuild(runner, location, args, undefined, engine);
|
package/package.json
CHANGED
package/src/binary_launcher.d.ts
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* - **plain** — require `zuke` on `PATH`, and when it is missing print where
|
|
16
16
|
* to get it and exit 1, for a project that must not download its tools.
|
|
17
17
|
*
|
|
18
|
-
* Both set `ZUKE_FORWARDED`,
|
|
19
|
-
*
|
|
18
|
+
* Both set `ZUKE_FORWARDED`, which an older `zuke` read so as not to run this
|
|
19
|
+
* launcher again (today's never runs a launcher), and `ZUKE_LAUNCHER_ROOT` to the
|
|
20
20
|
* launcher's directory: running a launcher is an explicit act on the
|
|
21
21
|
* project it sits in, so the discovery trust gate does not judge that root.
|
|
22
22
|
*
|
package/src/binary_launcher.js
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
* - **plain** — require `zuke` on `PATH`, and when it is missing print where
|
|
18
18
|
* to get it and exit 1, for a project that must not download its tools.
|
|
19
19
|
*
|
|
20
|
-
* Both set `ZUKE_FORWARDED`,
|
|
21
|
-
*
|
|
20
|
+
* Both set `ZUKE_FORWARDED`, which an older `zuke` read so as not to run this
|
|
21
|
+
* launcher again (today's never runs a launcher), and `ZUKE_LAUNCHER_ROOT` to the
|
|
22
22
|
* launcher's directory: running a launcher is an explicit act on the
|
|
23
23
|
* project it sits in, so the discovery trust gate does not judge that root.
|
|
24
24
|
*
|
package/src/deno_isolated.js
CHANGED
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
* @module
|
|
18
18
|
*/
|
|
19
19
|
import { FileTasks } from "@zuke/core";
|
|
20
|
-
import { spawnDeno } from "./deno_path.js";
|
|
20
|
+
import { denoCandidates, spawnDeno } from "./deno_path.js";
|
|
21
|
+
import { provisionDeno } from "./runtime_install.js";
|
|
21
22
|
import { output } from "./output.js";
|
|
22
23
|
/**
|
|
23
24
|
* The config written into the isolated directory: a workspace root with no
|
|
@@ -48,7 +49,7 @@ export async function runDenoIsolated(denoArgs, prefix) {
|
|
|
48
49
|
stdin: "null",
|
|
49
50
|
stdout: "piped",
|
|
50
51
|
stderr: "piped",
|
|
51
|
-
});
|
|
52
|
+
}, denoCandidates(), provisionDeno());
|
|
52
53
|
const [{ code }, stdout, stderr] = await Promise.all([
|
|
53
54
|
child.status,
|
|
54
55
|
new Response(child.stdout).text(),
|
package/src/deno_path.d.ts
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
*
|
|
28
28
|
* @module
|
|
29
29
|
*/
|
|
30
|
-
import { type ChildProcess, type ProcessStdio } from "@zuke/core";
|
|
30
|
+
import { type AbsolutePath, type ChildProcess, type ProcessStdio } from "@zuke/core";
|
|
31
31
|
/**
|
|
32
32
|
* The environment questions Deno resolution asks, injectable so the ordering
|
|
33
33
|
* is testable without a second machine.
|
|
@@ -44,12 +44,29 @@ export interface DenoHost {
|
|
|
44
44
|
export declare const defaultDenoHost: DenoHost;
|
|
45
45
|
/** The first of `names` with a non-empty value, or `undefined` if none has one. */
|
|
46
46
|
export declare function firstSet(host: DenoHost, ...names: string[]): string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Deno's install directory: `DENO_INSTALL`, or `~/.deno`, where Deno's own
|
|
49
|
+
* installer puts it and where `zuke` installs the pinned Deno (in `bin`).
|
|
50
|
+
* `USERPROFILE` stands in for `HOME` on Windows, where `HOME` is often unset
|
|
51
|
+
* outside PowerShell. `undefined` when the environment
|
|
52
|
+
* names no directory the candidate can be built from — none of the three set,
|
|
53
|
+
* or a value that is not an absolute path — which leaves `PATH` as the only
|
|
54
|
+
* candidate rather than a crash on the way to spawning anything.
|
|
55
|
+
*/
|
|
56
|
+
export declare function denoInstallDir(host: DenoHost): AbsolutePath | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* The directory `variable` names, else `home` under the user's home
|
|
59
|
+
* (`HOME`, or `USERPROFILE` on Windows). `undefined` when neither is set, or
|
|
60
|
+
* the value is not an absolute path.
|
|
61
|
+
*/
|
|
62
|
+
export declare function installDirFrom(host: DenoHost, variable: string, ...home: string[]): AbsolutePath | undefined;
|
|
47
63
|
/**
|
|
48
64
|
* The Deno executables to try, in order. The first is whatever
|
|
49
65
|
* {@link denoExecutable} says Deno is here — the running executable under
|
|
50
66
|
* `deno run`, the bare name for the OS to resolve on `PATH` when compiled —
|
|
51
|
-
* and the rest is this package's own:
|
|
52
|
-
*
|
|
67
|
+
* and the rest is this package's own: Deno's install directory, for a `zuke`
|
|
68
|
+
* that is not Deno itself (compiled, or on Node), where `PATH` may have no
|
|
69
|
+
* Deno at all.
|
|
53
70
|
*/
|
|
54
71
|
export declare function denoCandidates(host?: DenoHost): string[];
|
|
55
72
|
/**
|
|
@@ -72,12 +89,12 @@ export declare const QUIET_DENO_ENV: Readonly<Record<string, string>>;
|
|
|
72
89
|
export declare class DenoNotFoundError extends Error {
|
|
73
90
|
/** The error's name, as reported by `String(error)` and stack traces. */
|
|
74
91
|
name: string;
|
|
75
|
-
/** The executables that were
|
|
92
|
+
/** The executables that were looked for and not found, in the order tried. */
|
|
76
93
|
readonly tried: readonly string[];
|
|
77
94
|
/**
|
|
78
95
|
* Build the failure from the candidates that were tried, in order.
|
|
79
96
|
*
|
|
80
|
-
* @param tried The executables that were
|
|
97
|
+
* @param tried The executables that were looked for and not found.
|
|
81
98
|
*/
|
|
82
99
|
constructor(tried: readonly string[]);
|
|
83
100
|
}
|
|
@@ -110,6 +127,31 @@ export interface DenoSpawnOptions {
|
|
|
110
127
|
* is pure and takes a {@link DenoHost} instead, so each layer is injected at
|
|
111
128
|
* the level it decides something.
|
|
112
129
|
*
|
|
113
|
-
*
|
|
130
|
+
* With `provision`, a Deno that none of the candidates is gets installed (see
|
|
131
|
+
* `runtime_install.ts`) and run.
|
|
132
|
+
*
|
|
133
|
+
* @throws {DenoNotFoundError} when every candidate is missing and none was
|
|
134
|
+
* installed.
|
|
135
|
+
*/
|
|
136
|
+
export declare function spawnDeno(args: string[], options?: DenoSpawnOptions, candidates?: readonly string[], provision?: Provision): Promise<ChildProcess>;
|
|
137
|
+
/**
|
|
138
|
+
* Install the runtime none of the candidates was and return its executable,
|
|
139
|
+
* or throw `notFound` — the error the caller would otherwise see — when it
|
|
140
|
+
* may not be installed.
|
|
141
|
+
*/
|
|
142
|
+
export type Provision = (notFound: Error) => Promise<string>;
|
|
143
|
+
/**
|
|
144
|
+
* Spawn the first of `candidates` that is installed with `args`, each with
|
|
145
|
+
* {@link QUIET_DENO_ENV} and its own directory first on `PATH`; the loop
|
|
146
|
+
* behind {@link spawnDeno}, shared with the Node a build file runs on. Each
|
|
147
|
+
* candidate is a bare name for the OS to find on `PATH` or an absolute path,
|
|
148
|
+
* as every candidate list here builds them: {@link pathWithDeno} refuses a
|
|
149
|
+
* relative one.
|
|
150
|
+
*
|
|
151
|
+
* When none is installed, `provision` (if given) installs one, which is then
|
|
152
|
+
* spawned.
|
|
153
|
+
*
|
|
154
|
+
* @throws the error `notFound` builds from every candidate tried, when none
|
|
155
|
+
* is installed and none was provisioned.
|
|
114
156
|
*/
|
|
115
|
-
export declare function
|
|
157
|
+
export declare function spawnFirst(args: string[], options: DenoSpawnOptions, candidates: readonly string[], notFound: (tried: readonly string[]) => Error, provision?: Provision): Promise<ChildProcess>;
|
package/src/deno_path.js
CHANGED
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
*/
|
|
32
32
|
import { absolutePath, denoExecutable, EnvTasks, FileTasks, ProcessTasks, RuntimeTasks, } from "@zuke/core";
|
|
33
33
|
import { DENO_INSTALL_DOCS } from "./launcher.js";
|
|
34
|
+
import { DENO_PIN } from "./deno_pin.js";
|
|
34
35
|
/** The real, `Deno`-backed {@link DenoHost}. */
|
|
35
36
|
export const defaultDenoHost = {
|
|
36
37
|
standalone: () => RuntimeTasks.facts().standalone,
|
|
@@ -47,25 +48,34 @@ export function firstSet(host, ...names) {
|
|
|
47
48
|
return undefined;
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* `
|
|
51
|
+
* Deno's install directory: `DENO_INSTALL`, or `~/.deno`, where Deno's own
|
|
52
|
+
* installer puts it and where `zuke` installs the pinned Deno (in `bin`).
|
|
53
|
+
* `USERPROFILE` stands in for `HOME` on Windows, where `HOME` is often unset
|
|
54
|
+
* outside PowerShell. `undefined` when the environment
|
|
53
55
|
* names no directory the candidate can be built from — none of the three set,
|
|
54
56
|
* or a value that is not an absolute path — which leaves `PATH` as the only
|
|
55
57
|
* candidate rather than a crash on the way to spawning anything.
|
|
56
58
|
*/
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
export function denoInstallDir(host) {
|
|
60
|
+
return installDirFrom(host, "DENO_INSTALL", ".deno");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The directory `variable` names, else `home` under the user's home
|
|
64
|
+
* (`HOME`, or `USERPROFILE` on Windows). `undefined` when neither is set, or
|
|
65
|
+
* the value is not an absolute path.
|
|
66
|
+
*/
|
|
67
|
+
export function installDirFrom(host, variable, ...home) {
|
|
68
|
+
const explicit = firstSet(host, variable);
|
|
69
|
+
const user = firstSet(host, "HOME", "USERPROFILE");
|
|
60
70
|
try {
|
|
61
71
|
if (explicit !== undefined)
|
|
62
72
|
return absolutePath(explicit);
|
|
63
|
-
if (
|
|
64
|
-
return absolutePath(
|
|
73
|
+
if (user !== undefined)
|
|
74
|
+
return absolutePath(user)(...home);
|
|
65
75
|
}
|
|
66
76
|
catch {
|
|
67
|
-
// A relative
|
|
68
|
-
//
|
|
77
|
+
// A relative value resolves against nothing meaningful here, and
|
|
78
|
+
// `absolutePath` refuses it rather than guessing a base.
|
|
69
79
|
}
|
|
70
80
|
return undefined;
|
|
71
81
|
}
|
|
@@ -73,14 +83,16 @@ function installDir(host) {
|
|
|
73
83
|
* The Deno executables to try, in order. The first is whatever
|
|
74
84
|
* {@link denoExecutable} says Deno is here — the running executable under
|
|
75
85
|
* `deno run`, the bare name for the OS to resolve on `PATH` when compiled —
|
|
76
|
-
* and the rest is this package's own:
|
|
77
|
-
*
|
|
86
|
+
* and the rest is this package's own: Deno's install directory, for a `zuke`
|
|
87
|
+
* that is not Deno itself (compiled, or on Node), where `PATH` may have no
|
|
88
|
+
* Deno at all.
|
|
78
89
|
*/
|
|
79
90
|
export function denoCandidates(host = defaultDenoHost) {
|
|
80
91
|
const candidates = [denoExecutable(host.standalone())];
|
|
81
|
-
|
|
92
|
+
// Under `deno run` the first candidate is the running Deno itself.
|
|
93
|
+
if (candidates[0] !== "deno")
|
|
82
94
|
return candidates;
|
|
83
|
-
const install =
|
|
95
|
+
const install = denoInstallDir(host);
|
|
84
96
|
if (install !== undefined) {
|
|
85
97
|
candidates.push(install("bin", host.windows() ? "deno.exe" : "deno").path);
|
|
86
98
|
}
|
|
@@ -123,17 +135,17 @@ export const QUIET_DENO_ENV = {
|
|
|
123
135
|
export class DenoNotFoundError extends Error {
|
|
124
136
|
/** The error's name, as reported by `String(error)` and stack traces. */
|
|
125
137
|
name = "DenoNotFoundError";
|
|
126
|
-
/** The executables that were
|
|
138
|
+
/** The executables that were looked for and not found, in the order tried. */
|
|
127
139
|
tried;
|
|
128
140
|
/**
|
|
129
141
|
* Build the failure from the candidates that were tried, in order.
|
|
130
142
|
*
|
|
131
|
-
* @param tried The executables that were
|
|
143
|
+
* @param tried The executables that were looked for and not found.
|
|
132
144
|
*/
|
|
133
145
|
constructor(tried) {
|
|
134
146
|
super(`zuke: this needs Deno, and none was found — tried ` +
|
|
135
|
-
`${tried.join(", ")}. Install Deno (${DENO_INSTALL_DOCS})
|
|
136
|
-
`
|
|
147
|
+
`${tried.join(", ")}. Install Deno (${DENO_INSTALL_DOCS}) and put it on PATH, or run ` +
|
|
148
|
+
`zuke again and let it install Deno ${DENO_PIN.version}.`);
|
|
137
149
|
this.tried = tried;
|
|
138
150
|
}
|
|
139
151
|
}
|
|
@@ -161,12 +173,38 @@ function cwdUsable(cwd) {
|
|
|
161
173
|
* is pure and takes a {@link DenoHost} instead, so each layer is injected at
|
|
162
174
|
* the level it decides something.
|
|
163
175
|
*
|
|
164
|
-
*
|
|
176
|
+
* With `provision`, a Deno that none of the candidates is gets installed (see
|
|
177
|
+
* `runtime_install.ts`) and run.
|
|
178
|
+
*
|
|
179
|
+
* @throws {DenoNotFoundError} when every candidate is missing and none was
|
|
180
|
+
* installed.
|
|
181
|
+
*/
|
|
182
|
+
export function spawnDeno(args, options = {}, candidates = denoCandidates(), provision) {
|
|
183
|
+
return spawnFirst(args, options, candidates, (tried) => new DenoNotFoundError(tried), provision);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Spawn the first of `candidates` that is installed with `args`, each with
|
|
187
|
+
* {@link QUIET_DENO_ENV} and its own directory first on `PATH`; the loop
|
|
188
|
+
* behind {@link spawnDeno}, shared with the Node a build file runs on. Each
|
|
189
|
+
* candidate is a bare name for the OS to find on `PATH` or an absolute path,
|
|
190
|
+
* as every candidate list here builds them: {@link pathWithDeno} refuses a
|
|
191
|
+
* relative one.
|
|
192
|
+
*
|
|
193
|
+
* When none is installed, `provision` (if given) installs one, which is then
|
|
194
|
+
* spawned.
|
|
195
|
+
*
|
|
196
|
+
* @throws the error `notFound` builds from every candidate tried, when none
|
|
197
|
+
* is installed and none was provisioned.
|
|
165
198
|
*/
|
|
166
|
-
export async function
|
|
199
|
+
export async function spawnFirst(args, options, candidates, notFound, provision) {
|
|
167
200
|
const tried = [];
|
|
168
201
|
for (const command of candidates) {
|
|
169
202
|
tried.push(command);
|
|
203
|
+
// A path that is not there is skipped before spawning: Windows reports
|
|
204
|
+
// spawning one as an error that is not a plain "not found".
|
|
205
|
+
const isPath = command.includes("/") || command.includes("\\");
|
|
206
|
+
if (isPath && !(await FileTasks.exists(command)))
|
|
207
|
+
continue;
|
|
170
208
|
try {
|
|
171
209
|
const child = ProcessTasks.spawn(command, (s) => {
|
|
172
210
|
s.args(...args);
|
|
@@ -197,14 +235,17 @@ export async function spawnDeno(args, options = {}, candidates = denoCandidates(
|
|
|
197
235
|
// Not installed here; the next candidate may be. Anything else — a
|
|
198
236
|
// permission denial, a directory where the binary should be — is the
|
|
199
237
|
// caller's to see rather than a reason to keep looking. `spawn` reports
|
|
200
|
-
// a `cwd` that is gone as `NotFound` as well, and no other
|
|
201
|
-
// fix that: telling the user to install one they already have would
|
|
202
|
-
// them somewhere the problem is not.
|
|
238
|
+
// a `cwd` that is gone as `NotFound` as well, and no other runtime would
|
|
239
|
+
// fix that: telling the user to install one they already have would
|
|
240
|
+
// send them somewhere the problem is not.
|
|
203
241
|
if (!FileTasks.isNotFound(error))
|
|
204
242
|
throw error;
|
|
205
243
|
if (!cwdUsable(options.cwd))
|
|
206
244
|
throw error;
|
|
207
245
|
}
|
|
208
246
|
}
|
|
209
|
-
|
|
247
|
+
const missing = notFound(tried);
|
|
248
|
+
if (provision === undefined)
|
|
249
|
+
throw missing;
|
|
250
|
+
return spawnFirst(args, options, [await provision(missing)], notFound);
|
|
210
251
|
}
|