@zuke-build/cli 0.0.0-stage → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +353 -2
- package/mod.d.ts +102 -0
- package/mod.js +931 -0
- package/package.json +35 -4
- package/src/binary_launcher.d.ts +49 -0
- package/src/binary_launcher.js +325 -0
- package/src/binary_pin.d.ts +47 -0
- package/src/binary_pin.js +117 -0
- package/src/build_file.d.ts +25 -0
- package/src/build_file.js +58 -0
- package/src/cache.d.ts +23 -0
- package/src/cache.js +26 -0
- package/src/deno_isolated.d.ts +14 -0
- package/src/deno_isolated.js +70 -0
- package/src/deno_path.d.ts +115 -0
- package/src/deno_path.js +205 -0
- package/src/deno_pin.d.ts +37 -0
- package/src/deno_pin.js +32 -0
- package/src/dependencies.d.ts +48 -0
- package/src/dependencies.js +80 -0
- package/src/dispatch.d.ts +229 -0
- package/src/dispatch.js +549 -0
- package/src/embedded_engine.d.ts +28 -0
- package/src/embedded_engine.js +21 -0
- package/src/engine_pin.d.ts +56 -0
- package/src/engine_pin.js +196 -0
- package/src/fs.d.ts +14 -0
- package/src/fs.js +25 -0
- package/src/import.d.ts +132 -0
- package/src/import.js +289 -0
- package/src/install_source.d.ts +79 -0
- package/src/install_source.js +104 -0
- package/src/launcher.d.ts +37 -0
- package/src/launcher.js +405 -0
- package/src/launcher_shared.d.ts +25 -0
- package/src/launcher_shared.js +91 -0
- package/src/mcp_config.d.ts +71 -0
- package/src/mcp_config.js +96 -0
- package/src/node_launcher.d.ts +19 -0
- package/src/node_launcher.js +416 -0
- package/src/node_pin.d.ts +25 -0
- package/src/node_pin.js +30 -0
- package/src/output.d.ts +38 -0
- package/src/output.js +43 -0
- package/src/paint.d.ts +42 -0
- package/src/paint.js +38 -0
- package/src/project.d.ts +69 -0
- package/src/project.js +132 -0
- package/src/pyproject.d.ts +30 -0
- package/src/pyproject.js +156 -0
- package/src/python_build.d.ts +27 -0
- package/src/python_build.js +197 -0
- package/src/records.d.ts +18 -0
- package/src/records.js +31 -0
- package/src/relock.d.ts +11 -0
- package/src/relock.js +182 -0
- package/src/runtime_field.d.ts +15 -0
- package/src/runtime_field.js +29 -0
- package/src/setup.d.ts +259 -0
- package/src/setup.js +693 -0
- package/src/star.d.ts +44 -0
- package/src/star.js +100 -0
- package/src/starter.d.ts +64 -0
- package/src/starter.js +138 -0
- package/src/toml.d.ts +32 -0
- package/src/toml.js +354 -0
- package/src/translate.d.ts +69 -0
- package/src/translate.js +198 -0
- package/src/upgrade.d.ts +113 -0
- package/src/upgrade.js +344 -0
- package/src/version.d.ts +11 -0
- package/src/version.js +13 -0
- package/src/version_report.d.ts +55 -0
- package/src/version_report.js +187 -0
- package/zuke.js +8 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the running `zuke` was installed.
|
|
3
|
+
*
|
|
4
|
+
* The CLI ships two ways: from JSR with `deno install -g`, and as a
|
|
5
|
+
* `deno compile` binary, which Homebrew and Chocolatey install from the
|
|
6
|
+
* release archives.
|
|
7
|
+
* One machine can hold both, so `zuke --version` says which one answered and
|
|
8
|
+
* `zuke upgrade` refuses to reinstall from JSR when that is not where the
|
|
9
|
+
* running executable came from.
|
|
10
|
+
*
|
|
11
|
+
* The main module cannot tell the two apart. A binary compiled from
|
|
12
|
+
* `jsr:@zuke/cli` keeps reporting that specifier as `Deno.mainModule`, so a
|
|
13
|
+
* check on the specifier alone mistakes the Homebrew binary for the JSR
|
|
14
|
+
* install. Whether this process is a compiled binary is asked first, and only
|
|
15
|
+
* a process running under Deno itself is classified by its main module.
|
|
16
|
+
*
|
|
17
|
+
* A Homebrew binary and one downloaded from the release page are the same
|
|
18
|
+
* bytes, so only where the executable lives separates them: Homebrew keeps
|
|
19
|
+
* every formula under `<prefix>/Cellar/<formula>/<version>/`, and links it
|
|
20
|
+
* onto `PATH` from there. Chocolatey unpacks the package into
|
|
21
|
+
* `<ChocolateyInstall>\lib\<id>\tools\`, and its shim on `PATH` runs the
|
|
22
|
+
* executable from there, so that is the path the binary reports. The link is resolved before the path is read, which
|
|
23
|
+
* in a compiled binary needs read permission: the release binaries are
|
|
24
|
+
* compiled with `-A`, as the JSR install runs with it. Without it the path is
|
|
25
|
+
* the one the OS reported — already resolved on Linux, possibly the link on
|
|
26
|
+
* macOS, where a Homebrew install would then read as a plain binary.
|
|
27
|
+
*
|
|
28
|
+
* @module
|
|
29
|
+
*/
|
|
30
|
+
/** The JSR package the global command is installed from. */
|
|
31
|
+
export declare const JSR_PACKAGE = "jsr:@zuke/cli";
|
|
32
|
+
/**
|
|
33
|
+
* Where the running CLI came from:
|
|
34
|
+
* - `jsr`: `deno install -g` of {@link JSR_PACKAGE};
|
|
35
|
+
* - `homebrew`: the compiled binary, installed by Homebrew;
|
|
36
|
+
* - `chocolatey`: the compiled binary, installed by Chocolatey;
|
|
37
|
+
* - `binary`: the compiled binary, installed any other way;
|
|
38
|
+
* - `npm`: installed from npm as `@zuke-build/cli` and run by Node;
|
|
39
|
+
* - `source`: run under Deno from anything but JSR, e.g. a checkout.
|
|
40
|
+
*/
|
|
41
|
+
export type InstallKind = "jsr" | "homebrew" | "chocolatey" | "binary" | "npm" | "source";
|
|
42
|
+
/** The install the running CLI came from, and where it lives. */
|
|
43
|
+
export interface InstallSource {
|
|
44
|
+
/** How it was installed. */
|
|
45
|
+
readonly kind: InstallKind;
|
|
46
|
+
/**
|
|
47
|
+
* The module specifier for `jsr` and `source`, the resolved executable
|
|
48
|
+
* path for the compiled binary's kinds.
|
|
49
|
+
*/
|
|
50
|
+
readonly location: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The process facts {@link installSource} reads, injectable so each install
|
|
54
|
+
* kind is testable from a single process.
|
|
55
|
+
*/
|
|
56
|
+
export interface InstallHost {
|
|
57
|
+
/** Whether this process is a `deno compile` binary (`Deno.build.standalone`). */
|
|
58
|
+
standalone(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The running CLI's main module (`Deno.mainModule`). Deno reports a JSR
|
|
61
|
+
* program by its specifier, `jsr:@zuke/cli` or `jsr:@zuke/cli@<version>`.
|
|
62
|
+
*/
|
|
63
|
+
mainModule(): string;
|
|
64
|
+
/** The running executable's path (`Deno.execPath()`). */
|
|
65
|
+
execPath(): string;
|
|
66
|
+
/** `path` with every symbolic link resolved (`Deno.realPath`). */
|
|
67
|
+
realPath(path: string): Promise<string>;
|
|
68
|
+
}
|
|
69
|
+
/** Whether `main` is the JSR package, with or without a version. */
|
|
70
|
+
export declare function isJsrModule(main: string): boolean;
|
|
71
|
+
/** Classify the running CLI's install. */
|
|
72
|
+
export declare function installSource(host: InstallHost): Promise<InstallSource>;
|
|
73
|
+
/**
|
|
74
|
+
* One line naming the install, for `zuke --version`:
|
|
75
|
+
* `Homebrew (/opt/homebrew/Cellar/zuke/1.14.0/bin/zuke)`. `display` shortens
|
|
76
|
+
* a path for display (the home directory as `~`); a module specifier is shown
|
|
77
|
+
* as it is.
|
|
78
|
+
*/
|
|
79
|
+
export declare function installLabel(source: InstallSource, display: (path: string) => string): string;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* How the running `zuke` was installed.
|
|
5
|
+
*
|
|
6
|
+
* The CLI ships two ways: from JSR with `deno install -g`, and as a
|
|
7
|
+
* `deno compile` binary, which Homebrew and Chocolatey install from the
|
|
8
|
+
* release archives.
|
|
9
|
+
* One machine can hold both, so `zuke --version` says which one answered and
|
|
10
|
+
* `zuke upgrade` refuses to reinstall from JSR when that is not where the
|
|
11
|
+
* running executable came from.
|
|
12
|
+
*
|
|
13
|
+
* The main module cannot tell the two apart. A binary compiled from
|
|
14
|
+
* `jsr:@zuke/cli` keeps reporting that specifier as `Deno.mainModule`, so a
|
|
15
|
+
* check on the specifier alone mistakes the Homebrew binary for the JSR
|
|
16
|
+
* install. Whether this process is a compiled binary is asked first, and only
|
|
17
|
+
* a process running under Deno itself is classified by its main module.
|
|
18
|
+
*
|
|
19
|
+
* A Homebrew binary and one downloaded from the release page are the same
|
|
20
|
+
* bytes, so only where the executable lives separates them: Homebrew keeps
|
|
21
|
+
* every formula under `<prefix>/Cellar/<formula>/<version>/`, and links it
|
|
22
|
+
* onto `PATH` from there. Chocolatey unpacks the package into
|
|
23
|
+
* `<ChocolateyInstall>\lib\<id>\tools\`, and its shim on `PATH` runs the
|
|
24
|
+
* executable from there, so that is the path the binary reports. The link is resolved before the path is read, which
|
|
25
|
+
* in a compiled binary needs read permission: the release binaries are
|
|
26
|
+
* compiled with `-A`, as the JSR install runs with it. Without it the path is
|
|
27
|
+
* the one the OS reported — already resolved on Linux, possibly the link on
|
|
28
|
+
* macOS, where a Homebrew install would then read as a plain binary.
|
|
29
|
+
*
|
|
30
|
+
* @module
|
|
31
|
+
*/
|
|
32
|
+
// cspell:ignore linuxbrew
|
|
33
|
+
/** The JSR package the global command is installed from. */
|
|
34
|
+
export const JSR_PACKAGE = "jsr:@zuke/cli";
|
|
35
|
+
/** The formula name the tap installs the binary under. */
|
|
36
|
+
const FORMULA = "zuke";
|
|
37
|
+
/**
|
|
38
|
+
* A Homebrew-installed executable: `<prefix>/Cellar/zuke/<version>/bin/zuke`.
|
|
39
|
+
* Only the tail is matched, since the prefix differs by platform
|
|
40
|
+
* (`/opt/homebrew`, `/usr/local`, `/home/linuxbrew/.linuxbrew`).
|
|
41
|
+
*/
|
|
42
|
+
const CELLAR_BINARY = new RegExp(`/Cellar/${FORMULA}/[^/]+/bin/${FORMULA}$`);
|
|
43
|
+
/**
|
|
44
|
+
* A Chocolatey-installed executable: `<ChocolateyInstall>\lib\zuke\tools\zuke.exe`.
|
|
45
|
+
* Only the tail is matched, since `ChocolateyInstall` can be moved, and
|
|
46
|
+
* without regard to case, since Windows paths have none.
|
|
47
|
+
*/
|
|
48
|
+
const CHOCOLATEY_BINARY = new RegExp(`[\\\\/]lib[\\\\/]${FORMULA}[\\\\/]tools[\\\\/]${FORMULA}\\.exe$`, "i");
|
|
49
|
+
/**
|
|
50
|
+
* An npm-installed CLI's main module, a file URL or path with either
|
|
51
|
+
* separator: `.../node_modules/@zuke-build/cli/zuke.js`.
|
|
52
|
+
*/
|
|
53
|
+
const NPM_MODULE = /node_modules[\\/]@zuke-build[\\/]cli[\\/]/;
|
|
54
|
+
/** Whether `main` is the JSR package, with or without a version. */
|
|
55
|
+
export function isJsrModule(main) {
|
|
56
|
+
return main === JSR_PACKAGE || main.startsWith(`${JSR_PACKAGE}@`);
|
|
57
|
+
}
|
|
58
|
+
/** Classify the running CLI's install. */
|
|
59
|
+
export async function installSource(host) {
|
|
60
|
+
if (host.standalone()) {
|
|
61
|
+
let path = host.execPath();
|
|
62
|
+
try {
|
|
63
|
+
path = await host.realPath(path);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Unresolvable: the path as the OS reported it is still the best answer.
|
|
67
|
+
}
|
|
68
|
+
const kind = CELLAR_BINARY.test(path)
|
|
69
|
+
? "homebrew"
|
|
70
|
+
: CHOCOLATEY_BINARY.test(path)
|
|
71
|
+
? "chocolatey"
|
|
72
|
+
: "binary";
|
|
73
|
+
return { kind, location: path };
|
|
74
|
+
}
|
|
75
|
+
const main = host.mainModule();
|
|
76
|
+
const kind = isJsrModule(main)
|
|
77
|
+
? "jsr"
|
|
78
|
+
: NPM_MODULE.test(main)
|
|
79
|
+
? "npm"
|
|
80
|
+
: "source";
|
|
81
|
+
return { kind, location: main };
|
|
82
|
+
}
|
|
83
|
+
/** The name each install kind is shown under. */
|
|
84
|
+
const KIND_LABELS = {
|
|
85
|
+
jsr: "JSR",
|
|
86
|
+
homebrew: "Homebrew",
|
|
87
|
+
chocolatey: "Chocolatey",
|
|
88
|
+
binary: "standalone binary",
|
|
89
|
+
npm: "npm",
|
|
90
|
+
source: "source",
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* One line naming the install, for `zuke --version`:
|
|
94
|
+
* `Homebrew (/opt/homebrew/Cellar/zuke/1.14.0/bin/zuke)`. `display` shortens
|
|
95
|
+
* a path for display (the home directory as `~`); a module specifier is shown
|
|
96
|
+
* as it is.
|
|
97
|
+
*/
|
|
98
|
+
export function installLabel(source, display) {
|
|
99
|
+
const where = source.kind === "jsr" || source.kind === "source" ||
|
|
100
|
+
source.kind === "npm"
|
|
101
|
+
? source.location
|
|
102
|
+
: display(source.location);
|
|
103
|
+
return `${KIND_LABELS[source.kind]} (${where})`;
|
|
104
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type DenoPin } from "./deno_pin.ts";
|
|
2
|
+
/** Which launcher variant to render. */
|
|
3
|
+
/**
|
|
4
|
+
* The notice a run without a lockfile prints — a fresh scaffold has none, so
|
|
5
|
+
* the first run must be allowed to write one, and saying so keeps a deleted
|
|
6
|
+
* lockfile from downgrading verification silently. Shared by both launcher
|
|
7
|
+
* templates and the global CLI's forwarding, so the three cannot drift.
|
|
8
|
+
* `dash` is the hyphen the caller's encoding is comfortable with (PowerShell
|
|
9
|
+
* sources are kept ASCII).
|
|
10
|
+
*/
|
|
11
|
+
export declare function noLockNotice(dash: string): string;
|
|
12
|
+
export interface LauncherOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Bootstrap a pinned, checksum-verified Deno when none is on `PATH`
|
|
15
|
+
* (`true`), or require one and fail closed when it is missing (`false`).
|
|
16
|
+
*/
|
|
17
|
+
bootstrapDeno: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The build file the launcher runs, when the project's `zuke.json` names
|
|
20
|
+
* one. Omitted: `zuke.ts`.
|
|
21
|
+
*/
|
|
22
|
+
buildFile?: string;
|
|
23
|
+
}
|
|
24
|
+
/** The line a plain Deno launcher carries, which `zuke upgrade --engine` keeps a launcher plain by. */
|
|
25
|
+
export declare const PLAIN_DENO_LAUNCHER = "# Requires Deno:";
|
|
26
|
+
/** The URL the plain launchers point at when Deno is missing. */
|
|
27
|
+
export declare const DENO_INSTALL_DOCS = "https://docs.deno.com/runtime/getting_started/installation/";
|
|
28
|
+
/**
|
|
29
|
+
* The bash launcher (`./zuke`). Runs the build file with the Deno on `PATH`, or
|
|
30
|
+
* with the one it bootstraps first (see the module docs for the variants).
|
|
31
|
+
*/
|
|
32
|
+
export declare function launcherBash(options: LauncherOptions, pin?: DenoPin): string;
|
|
33
|
+
/**
|
|
34
|
+
* The PowerShell launcher (`.\zuke.ps1`). Mirrors {@link launcherBash},
|
|
35
|
+
* variant for variant, including the conditional `--frozen`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function launcherPwsh(options: LauncherOptions, pin?: DenoPin): string;
|
package/src/launcher.js
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The `./zuke` (bash) and `zuke.ps1` (PowerShell) launcher scripts, rendered
|
|
5
|
+
* from one template in two variants:
|
|
6
|
+
*
|
|
7
|
+
* - **bootstrap** — when no Deno is on `PATH`, download the pinned release
|
|
8
|
+
* from {@link "./deno_pin.ts"}, verify it against the per-platform SHA-256,
|
|
9
|
+
* unpack it into `DENO_INSTALL` (default `~/.deno`), and run the build with
|
|
10
|
+
* it. A checkout needs nothing installed up front. The launcher never runs
|
|
11
|
+
* an install script and never installs an unverified binary: an overriding
|
|
12
|
+
* `DENO_VERSION` must be an exact release tag and must come with the matching
|
|
13
|
+
* `DENO_SHA256`, and `latest` is rejected because a moving target has no
|
|
14
|
+
* hash to pin.
|
|
15
|
+
* - **plain** — require Deno on `PATH`, and when it is missing print the one
|
|
16
|
+
* command to run and exit 1. For a project that must never download a
|
|
17
|
+
* tool from its build entry point (a locked-down CI image, a policy against
|
|
18
|
+
* downloads), so it fails closed instead.
|
|
19
|
+
*
|
|
20
|
+
* Both variants pass `--frozen` only once a `deno.lock` exists: a freshly
|
|
21
|
+
* scaffolded project has none, and `deno run --frozen` against a missing
|
|
22
|
+
* lockfile fails outright ("The lockfile is out of date") instead of writing
|
|
23
|
+
* one. So the first run resolves and records the graph, and every run after
|
|
24
|
+
* that verifies it and fails loudly if it changed. The unfrozen branch says so
|
|
25
|
+
* on stderr — the same branch is taken if a `deno.lock` is later removed, which
|
|
26
|
+
* drops integrity verification, so it must not run unverified in silence.
|
|
27
|
+
*
|
|
28
|
+
* Zuke's own `./zuke` and `zuke.ps1` are the bootstrap variant, generated
|
|
29
|
+
* from here by `./zuke launcherSync` and verified by `launcherSyncCheck`, so
|
|
30
|
+
* the scripts `zuke setup` stamps into a project are the ones this repository
|
|
31
|
+
* runs on every CI job.
|
|
32
|
+
*
|
|
33
|
+
* @module
|
|
34
|
+
*/
|
|
35
|
+
import { assertBuildFileName, BUILD_FILE } from "./build_file.js";
|
|
36
|
+
import { bashFetchVerified, LICENSE_HEADER, pwshFetchVerified, } from "./launcher_shared.js";
|
|
37
|
+
import { DENO_PIN, denoReleaseTag, POSIX_TARGETS, WINDOWS_TARGETS, } from "./deno_pin.js";
|
|
38
|
+
/** Which launcher variant to render. */
|
|
39
|
+
/**
|
|
40
|
+
* The notice a run without a lockfile prints — a fresh scaffold has none, so
|
|
41
|
+
* the first run must be allowed to write one, and saying so keeps a deleted
|
|
42
|
+
* lockfile from downgrading verification silently. Shared by both launcher
|
|
43
|
+
* templates and the global CLI's forwarding, so the three cannot drift.
|
|
44
|
+
* `dash` is the hyphen the caller's encoding is comfortable with (PowerShell
|
|
45
|
+
* sources are kept ASCII).
|
|
46
|
+
*/
|
|
47
|
+
export function noLockNotice(dash) {
|
|
48
|
+
return `zuke: no deno.lock here yet ${dash} running without lockfile ` +
|
|
49
|
+
"verification so Deno can write one.";
|
|
50
|
+
}
|
|
51
|
+
/** The build file a launcher with `options` runs, checked before it is written into a script. */
|
|
52
|
+
function buildFileOf(options) {
|
|
53
|
+
return assertBuildFileName(options.buildFile ?? BUILD_FILE);
|
|
54
|
+
}
|
|
55
|
+
/** The line a plain Deno launcher carries, which `zuke upgrade --engine` keeps a launcher plain by. */
|
|
56
|
+
export const PLAIN_DENO_LAUNCHER = "# Requires Deno:";
|
|
57
|
+
/** The URL the plain launchers point at when Deno is missing. */
|
|
58
|
+
export const DENO_INSTALL_DOCS = "https://docs.deno.com/runtime/getting_started/installation/";
|
|
59
|
+
/* cspell:disable */
|
|
60
|
+
/**
|
|
61
|
+
* The `DENO_VERSION` / `DENO_SHA256` / `DENO_INSTALL` contract, as the comment
|
|
62
|
+
* block both bootstrap launchers carry. `dash` is the hyphen the script's
|
|
63
|
+
* encoding is comfortable with (PowerShell sources are kept ASCII).
|
|
64
|
+
*/
|
|
65
|
+
function bootstrapEnvDocs(pin, dash) {
|
|
66
|
+
return `# Honoured environment variables:
|
|
67
|
+
# DENO_INSTALL where Deno is installed/looked for (default: ~/.deno)
|
|
68
|
+
# DENO_VERSION which Deno to install on bootstrap. Defaults to a pinned,
|
|
69
|
+
# known-good version (see below) for reproducible and more
|
|
70
|
+
# predictable installs. An override must name an exact release
|
|
71
|
+
# tag (e.g. ${denoReleaseTag(pin)}) ${dash} "latest" is rejected, because a moving
|
|
72
|
+
# target has no checksum to pin ${dash} and is only installed if
|
|
73
|
+
# DENO_SHA256 also supplies the matching per-platform checksum
|
|
74
|
+
# (see below); this launcher never downloads an unverified
|
|
75
|
+
# binary.
|
|
76
|
+
# DENO_SHA256 required alongside a DENO_VERSION override: the expected
|
|
77
|
+
# SHA-256 of the release zip for the *current* platform (see
|
|
78
|
+
# the asset name printed on a checksum mismatch).`;
|
|
79
|
+
}
|
|
80
|
+
/** The provenance comment above the pinned checksums. */
|
|
81
|
+
function checksumProvenance(pin, versionVar) {
|
|
82
|
+
return `# SHA-256 of each \`deno-<target>.zip\` release asset, from
|
|
83
|
+
# https://github.com/denoland/deno/releases/tag/${denoReleaseTag(pin)} (GitHub's own reported
|
|
84
|
+
# asset \`digest\`, cross-checked by downloading and hashing the artifact).
|
|
85
|
+
# Bump *together* with ${versionVar}: this file is generated from
|
|
86
|
+
# @zuke/cli's deno_pin.ts, so change the pin there and regenerate.`;
|
|
87
|
+
}
|
|
88
|
+
/** The bash launcher's Deno resolution: the bootstrap, or the fail-closed check. */
|
|
89
|
+
function bashResolveDeno(options, pin) {
|
|
90
|
+
if (!options.bootstrapDeno) {
|
|
91
|
+
return `if ! command -v deno >/dev/null 2>&1; then
|
|
92
|
+
echo "zuke: Deno not found on PATH. Install it, then re-run this launcher:" >&2
|
|
93
|
+
echo " ${DENO_INSTALL_DOCS}" >&2
|
|
94
|
+
exit 1
|
|
95
|
+
fi
|
|
96
|
+
deno_bin="$(command -v deno)"`;
|
|
97
|
+
}
|
|
98
|
+
return `deno_install="\${DENO_INSTALL:-$HOME/.deno}"
|
|
99
|
+
|
|
100
|
+
if command -v deno >/dev/null 2>&1; then
|
|
101
|
+
deno_bin="$(command -v deno)"
|
|
102
|
+
elif [ -x "$deno_install/bin/deno" ]; then
|
|
103
|
+
deno_bin="$deno_install/bin/deno"
|
|
104
|
+
else
|
|
105
|
+
echo "zuke: Deno not found — installing it now..." >&2
|
|
106
|
+
for cmd in curl unzip; do
|
|
107
|
+
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
108
|
+
echo "zuke: $cmd is required to bootstrap Deno; install Deno manually:" >&2
|
|
109
|
+
echo " ${DENO_INSTALL_DOCS}" >&2
|
|
110
|
+
exit 1
|
|
111
|
+
fi
|
|
112
|
+
done
|
|
113
|
+
|
|
114
|
+
deno_version="\${DENO_VERSION:-$DEFAULT_DENO_VERSION}"
|
|
115
|
+
case "$deno_version" in
|
|
116
|
+
latest)
|
|
117
|
+
# There is no \`latest\` release tag to download, and a moving target has no
|
|
118
|
+
# checksum to pin — so name the release you want instead.
|
|
119
|
+
echo "zuke: DENO_VERSION=latest is not supported: this launcher verifies the" >&2
|
|
120
|
+
echo " download against a pinned SHA-256, and \\"latest\\" has no fixed hash." >&2
|
|
121
|
+
echo " Set DENO_VERSION to an exact release tag (e.g. ${denoReleaseTag(pin)}) plus DENO_SHA256" >&2
|
|
122
|
+
echo " with that release's deno-<target>.zip hash, or unset DENO_VERSION to" >&2
|
|
123
|
+
echo " install the verified default $DEFAULT_DENO_VERSION." >&2
|
|
124
|
+
exit 1
|
|
125
|
+
;;
|
|
126
|
+
v*) ;;
|
|
127
|
+
*) deno_version="v$deno_version" ;;
|
|
128
|
+
esac
|
|
129
|
+
|
|
130
|
+
# Map uname's OS/arch spelling to Deno's release asset target triple.
|
|
131
|
+
case "$(uname -s)" in
|
|
132
|
+
Linux) os_part="unknown-linux-gnu" ;;
|
|
133
|
+
Darwin) os_part="apple-darwin" ;;
|
|
134
|
+
*)
|
|
135
|
+
echo "zuke: unsupported OS for the checksum-verified bootstrap: $(uname -s)." >&2
|
|
136
|
+
echo " Install Deno manually: ${DENO_INSTALL_DOCS}" >&2
|
|
137
|
+
exit 1
|
|
138
|
+
;;
|
|
139
|
+
esac
|
|
140
|
+
case "$(uname -m)" in
|
|
141
|
+
x86_64 | amd64) arch_part="x86_64" ;;
|
|
142
|
+
arm64 | aarch64) arch_part="aarch64" ;;
|
|
143
|
+
*)
|
|
144
|
+
echo "zuke: unsupported architecture for the checksum-verified bootstrap: $(uname -m)." >&2
|
|
145
|
+
echo " Install Deno manually: ${DENO_INSTALL_DOCS}" >&2
|
|
146
|
+
exit 1
|
|
147
|
+
;;
|
|
148
|
+
esac
|
|
149
|
+
target="\${arch_part}-\${os_part}"
|
|
150
|
+
|
|
151
|
+
if [ "$deno_version" = "$DEFAULT_DENO_VERSION" ]; then
|
|
152
|
+
expected_sha256="$(deno_checksum_for "$target")" || {
|
|
153
|
+
echo "zuke: no pinned checksum for $target — this platform isn't covered yet." >&2
|
|
154
|
+
exit 1
|
|
155
|
+
}
|
|
156
|
+
elif [ -n "\${DENO_SHA256:-}" ]; then
|
|
157
|
+
# An explicit override: the caller vouches for this version/platform pair
|
|
158
|
+
# by supplying its own checksum, so the download is still verified.
|
|
159
|
+
expected_sha256="$DENO_SHA256"
|
|
160
|
+
else
|
|
161
|
+
echo "zuke: DENO_VERSION=$deno_version overrides the pinned $DEFAULT_DENO_VERSION," >&2
|
|
162
|
+
echo " but no checksum is pinned for it. Set DENO_SHA256 to the expected" >&2
|
|
163
|
+
echo " SHA-256 of deno-$target.zip for that release, or unset DENO_VERSION" >&2
|
|
164
|
+
echo " to use the verified default." >&2
|
|
165
|
+
exit 1
|
|
166
|
+
fi
|
|
167
|
+
|
|
168
|
+
asset="deno-\${target}.zip"
|
|
169
|
+
download_url="https://github.com/denoland/deno/releases/download/\${deno_version}/\${asset}"
|
|
170
|
+
${bashFetchVerified("Deno")}
|
|
171
|
+
|
|
172
|
+
mkdir -p "$deno_install/bin"
|
|
173
|
+
unzip -oq "$archive" -d "$deno_install/bin"
|
|
174
|
+
chmod +x "$deno_install/bin/deno"
|
|
175
|
+
deno_bin="$deno_install/bin/deno"
|
|
176
|
+
fi
|
|
177
|
+
|
|
178
|
+
# Put this Deno on PATH so CLIs the build provisions with \`deno install\` — whose
|
|
179
|
+
# generated launchers invoke \`deno\` by name — can find it even when Deno was
|
|
180
|
+
# bootstrapped to a non-PATH location (e.g. ~/.deno/bin).
|
|
181
|
+
export PATH="$(dirname "$deno_bin"):$PATH"`;
|
|
182
|
+
}
|
|
183
|
+
/** The bash launcher's pin block: the version and the per-platform checksums. */
|
|
184
|
+
function bashPin(pin) {
|
|
185
|
+
const arms = POSIX_TARGETS.map((target) => ` ${target})\n echo "${pin.checksums[target]}" ;;`).join("\n");
|
|
186
|
+
return `# Pinned default so the bootstrap installs a known version rather than whatever
|
|
187
|
+
# "latest" happens to be.
|
|
188
|
+
DEFAULT_DENO_VERSION="${denoReleaseTag(pin)}"
|
|
189
|
+
|
|
190
|
+
# --- Pinned per-platform checksums for DEFAULT_DENO_VERSION -----------------
|
|
191
|
+
${checksumProvenance(pin, "DEFAULT_DENO_VERSION")}
|
|
192
|
+
deno_checksum_for() {
|
|
193
|
+
case "$1" in
|
|
194
|
+
${arms}
|
|
195
|
+
*)
|
|
196
|
+
return 1 ;;
|
|
197
|
+
esac
|
|
198
|
+
}
|
|
199
|
+
# -----------------------------------------------------------------------------
|
|
200
|
+
`;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The bash launcher (`./zuke`). Runs the build file with the Deno on `PATH`, or
|
|
204
|
+
* with the one it bootstraps first (see the module docs for the variants).
|
|
205
|
+
*/
|
|
206
|
+
export function launcherBash(options, pin = DENO_PIN) {
|
|
207
|
+
const build = buildFileOf(options);
|
|
208
|
+
const purpose = options.bootstrapDeno
|
|
209
|
+
? `# Zuke bootstrap launcher — a \`./build.sh\`-style entry point for Deno.
|
|
210
|
+
#
|
|
211
|
+
# ./zuke # run the default target
|
|
212
|
+
# ./zuke <target> # run one target and its prerequisites
|
|
213
|
+
# ./zuke --list # list every target
|
|
214
|
+
#
|
|
215
|
+
# Ensures Deno is available (installing it on first use if missing), then runs
|
|
216
|
+
# the project's build file (${build}). No global install required.
|
|
217
|
+
#
|
|
218
|
+
${bootstrapEnvDocs(pin, "—")}`
|
|
219
|
+
: `# Zuke launcher — runs the project's build file (${build}) with the Deno on PATH.
|
|
220
|
+
#
|
|
221
|
+
# ./zuke # run the default target
|
|
222
|
+
# ./zuke <target> # run one target and its prerequisites
|
|
223
|
+
# ./zuke --list # list every target
|
|
224
|
+
#
|
|
225
|
+
${PLAIN_DENO_LAUNCHER} ${DENO_INSTALL_DOCS}`;
|
|
226
|
+
const pinBlock = options.bootstrapDeno ? `\n${bashPin(pin)}` : "";
|
|
227
|
+
return `#!/usr/bin/env bash
|
|
228
|
+
${LICENSE_HEADER}
|
|
229
|
+
#
|
|
230
|
+
${purpose}
|
|
231
|
+
set -euo pipefail
|
|
232
|
+
${pinBlock}
|
|
233
|
+
dir="$(cd "$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
|
|
234
|
+
cd "$dir"
|
|
235
|
+
|
|
236
|
+
${bashResolveDeno(options, pin)}
|
|
237
|
+
|
|
238
|
+
# The first run has no lockfile to verify against, so let Deno write one; from
|
|
239
|
+
# then on --frozen fails the build if the module graph changed. Say so when
|
|
240
|
+
# skipping, so a deleted lockfile downgrades verification visibly instead of
|
|
241
|
+
# silently.
|
|
242
|
+
if [ -f deno.lock ]; then
|
|
243
|
+
exec "$deno_bin" run -A --frozen ${build} "$@"
|
|
244
|
+
else
|
|
245
|
+
echo "${noLockNotice("—")}" >&2
|
|
246
|
+
exec "$deno_bin" run -A ${build} "$@"
|
|
247
|
+
fi
|
|
248
|
+
`;
|
|
249
|
+
}
|
|
250
|
+
/** The PowerShell launcher's Deno resolution: the bootstrap, or the fail-closed check. */
|
|
251
|
+
function pwshResolveDeno(options, pin) {
|
|
252
|
+
if (!options.bootstrapDeno) {
|
|
253
|
+
return `$found = Get-Command deno -CommandType Application -ErrorAction SilentlyContinue
|
|
254
|
+
if (-not $found) {
|
|
255
|
+
Write-Error "zuke: Deno not found on PATH. Install it, then re-run this launcher: ${DENO_INSTALL_DOCS}"
|
|
256
|
+
exit 1
|
|
257
|
+
}
|
|
258
|
+
$deno = $found.Source`;
|
|
259
|
+
}
|
|
260
|
+
return `if (-not $env:DENO_INSTALL) {
|
|
261
|
+
$env:DENO_INSTALL = Join-Path $HOME ".deno"
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function Resolve-Deno {
|
|
265
|
+
$onPath = Get-Command deno -CommandType Application -ErrorAction SilentlyContinue
|
|
266
|
+
if ($onPath) { return $onPath.Source }
|
|
267
|
+
$local = Join-Path $env:DENO_INSTALL "bin\\deno.exe"
|
|
268
|
+
if (Test-Path $local) { return $local }
|
|
269
|
+
return $null
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
$deno = Resolve-Deno
|
|
273
|
+
if (-not $deno) {
|
|
274
|
+
Write-Host "zuke: Deno not found - installing it now..."
|
|
275
|
+
|
|
276
|
+
$denoVersion = if ($env:DENO_VERSION) { $env:DENO_VERSION } else { $DefaultDenoVersion }
|
|
277
|
+
if ($denoVersion -eq "latest") {
|
|
278
|
+
# There is no \`latest\` release tag to download, and a moving target has no
|
|
279
|
+
# checksum to pin - so name the release you want instead.
|
|
280
|
+
throw "zuke: DENO_VERSION=latest is not supported: this launcher verifies the " +
|
|
281
|
+
"download against a pinned SHA-256, and ""latest"" has no fixed hash. Set " +
|
|
282
|
+
"DENO_VERSION to an exact release tag (e.g. ${denoReleaseTag(pin)}) plus DENO_SHA256 with that " +
|
|
283
|
+
"release's deno-<target>.zip hash, or unset DENO_VERSION to install the " +
|
|
284
|
+
"verified default $DefaultDenoVersion."
|
|
285
|
+
}
|
|
286
|
+
$vTag = if ($denoVersion.StartsWith("v")) { $denoVersion } else { "v$denoVersion" }
|
|
287
|
+
$bareVersion = $vTag.Substring(1)
|
|
288
|
+
|
|
289
|
+
# .ToString() forces a plain string comparison in the switch below,
|
|
290
|
+
# independent of how PowerShell would otherwise coerce the enum/string types.
|
|
291
|
+
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()
|
|
292
|
+
$target = switch ($arch) {
|
|
293
|
+
"X64" { "x86_64-pc-windows-msvc" }
|
|
294
|
+
"Arm64" { "aarch64-pc-windows-msvc" }
|
|
295
|
+
default {
|
|
296
|
+
throw "zuke: unsupported architecture for the checksum-verified bootstrap: $arch. " +
|
|
297
|
+
"Install Deno manually: ${DENO_INSTALL_DOCS}"
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if ($bareVersion -eq $DefaultDenoVersion -and $DenoChecksums.ContainsKey($target)) {
|
|
302
|
+
$expectedSha256 = $DenoChecksums[$target]
|
|
303
|
+
} elseif ($env:DENO_SHA256) {
|
|
304
|
+
# An explicit override: the caller vouches for this version/platform pair
|
|
305
|
+
# by supplying its own checksum, so the download is still verified.
|
|
306
|
+
$expectedSha256 = $env:DENO_SHA256
|
|
307
|
+
} else {
|
|
308
|
+
throw "zuke: DENO_VERSION=$denoVersion overrides the pinned $DefaultDenoVersion, " +
|
|
309
|
+
"but no checksum is pinned for it. Set DENO_SHA256 to the expected SHA-256 " +
|
|
310
|
+
"of deno-$target.zip for that release, or unset DENO_VERSION to use the " +
|
|
311
|
+
"verified default."
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
$asset = "deno-$target.zip"
|
|
315
|
+
$downloadUrl = "https://github.com/denoland/deno/releases/download/$vTag/$asset"
|
|
316
|
+
$workDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid())
|
|
317
|
+
New-Item -ItemType Directory -Path $workDir | Out-Null
|
|
318
|
+
$archive = Join-Path $workDir $asset
|
|
319
|
+
try {
|
|
320
|
+
${pwshFetchVerified("Deno")}
|
|
321
|
+
|
|
322
|
+
$binDir = Join-Path $env:DENO_INSTALL "bin"
|
|
323
|
+
New-Item -ItemType Directory -Force -Path $binDir | Out-Null
|
|
324
|
+
Expand-Archive -Path $archive -DestinationPath $binDir -Force
|
|
325
|
+
} finally {
|
|
326
|
+
Remove-Item -Recurse -Force $workDir -ErrorAction SilentlyContinue
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
$deno = Join-Path $env:DENO_INSTALL "bin\\deno.exe"
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
# Put this Deno on PATH so CLIs the build provisions with \`deno install\` - whose
|
|
333
|
+
# generated launchers invoke \`deno\` by name - can find it even when Deno was
|
|
334
|
+
# bootstrapped to a non-PATH location.
|
|
335
|
+
$env:PATH = (Split-Path -Parent $deno) + [IO.Path]::PathSeparator + $env:PATH`;
|
|
336
|
+
}
|
|
337
|
+
/** The PowerShell launcher's pin block: the version and the per-platform checksums. */
|
|
338
|
+
function pwshPin(pin) {
|
|
339
|
+
const width = Math.max(...WINDOWS_TARGETS.map((t) => t.length)) + 2;
|
|
340
|
+
const entries = WINDOWS_TARGETS.map((target) => ` ${`"${target}"`.padEnd(width)} = "${pin.checksums[target]}"`).join("\n");
|
|
341
|
+
return `# Pinned default so the bootstrap installs a known version rather than whatever
|
|
342
|
+
# "latest" happens to be.
|
|
343
|
+
$DefaultDenoVersion = "${pin.version}"
|
|
344
|
+
|
|
345
|
+
# --- Pinned per-platform checksums for $DefaultDenoVersion ------------------
|
|
346
|
+
${checksumProvenance(pin, "$DefaultDenoVersion")}
|
|
347
|
+
$DenoChecksums = @{
|
|
348
|
+
${entries}
|
|
349
|
+
}
|
|
350
|
+
# -----------------------------------------------------------------------------
|
|
351
|
+
`;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* The PowerShell launcher (`.\zuke.ps1`). Mirrors {@link launcherBash},
|
|
355
|
+
* variant for variant, including the conditional `--frozen`.
|
|
356
|
+
*/
|
|
357
|
+
export function launcherPwsh(options, pin = DENO_PIN) {
|
|
358
|
+
const build = buildFileOf(options);
|
|
359
|
+
const purpose = options.bootstrapDeno
|
|
360
|
+
? `# Zuke bootstrap launcher (PowerShell) - a \`.\\build.ps1\`-style entry point.
|
|
361
|
+
#
|
|
362
|
+
# .\\zuke.ps1 # run the default target
|
|
363
|
+
# .\\zuke.ps1 <target> # run one target and its prerequisites
|
|
364
|
+
# .\\zuke.ps1 --list # list every target
|
|
365
|
+
#
|
|
366
|
+
# Ensures Deno is available (installing it on first use if missing), then runs
|
|
367
|
+
# the project's build file (${build}). No global install required.
|
|
368
|
+
#
|
|
369
|
+
${bootstrapEnvDocs(pin, "-")}`
|
|
370
|
+
: `# Zuke launcher (PowerShell) - runs the project's build file (${build}) with the Deno on PATH.
|
|
371
|
+
#
|
|
372
|
+
# .\\zuke.ps1 # run the default target
|
|
373
|
+
# .\\zuke.ps1 <target> # run one target and its prerequisites
|
|
374
|
+
# .\\zuke.ps1 --list # list every target
|
|
375
|
+
#
|
|
376
|
+
${PLAIN_DENO_LAUNCHER} ${DENO_INSTALL_DOCS}`;
|
|
377
|
+
const pinBlock = options.bootstrapDeno ? `\n${pwshPin(pin)}` : "";
|
|
378
|
+
return `#!/usr/bin/env pwsh
|
|
379
|
+
${LICENSE_HEADER}
|
|
380
|
+
#
|
|
381
|
+
${purpose}
|
|
382
|
+
|
|
383
|
+
$ErrorActionPreference = "Stop"
|
|
384
|
+
${pinBlock}
|
|
385
|
+
$dir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
386
|
+
Set-Location $dir
|
|
387
|
+
|
|
388
|
+
${pwshResolveDeno(options, pin)}
|
|
389
|
+
|
|
390
|
+
# The first run has no lockfile to verify against, so let Deno write one; from
|
|
391
|
+
# then on --frozen fails the build if the module graph changed. Say so when
|
|
392
|
+
# skipping, so a deleted lockfile downgrades verification visibly instead of
|
|
393
|
+
# silently.
|
|
394
|
+
$denoArgs = @("run", "-A")
|
|
395
|
+
if (Test-Path (Join-Path $dir "deno.lock")) {
|
|
396
|
+
$denoArgs += "--frozen"
|
|
397
|
+
} else {
|
|
398
|
+
Write-Warning "${noLockNotice("-")}"
|
|
399
|
+
}
|
|
400
|
+
$denoArgs += (Join-Path $dir "${build}")
|
|
401
|
+
& $deno @denoArgs @args
|
|
402
|
+
exit $LASTEXITCODE
|
|
403
|
+
`;
|
|
404
|
+
}
|
|
405
|
+
/* cspell:enable */
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pieces the bootstrapping launchers share: the license header, and the
|
|
3
|
+
* download-with-retry and SHA-256 verification of a pinned archive. One
|
|
4
|
+
* implementation, so the Deno and Node launchers cannot drift on how a
|
|
5
|
+
* download is retried or verified.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** The MIT notice every generated launcher opens with (after its shebang). */
|
|
10
|
+
export declare const LICENSE_HEADER = "# Copyright (c) 2026 the Zuke contributors\n# SPDX-License-Identifier: MIT";
|
|
11
|
+
/**
|
|
12
|
+
* The bash steps that fetch `$download_url` into `$archive` (inside a fresh
|
|
13
|
+
* `$work_dir`, removed on exit) with retries, then check its SHA-256 against
|
|
14
|
+
* `$expected_sha256`, exiting 1 on a mismatch. Expects `asset`,
|
|
15
|
+
* `download_url` and `expected_sha256` to be set, and is indented for use
|
|
16
|
+
* inside an `if` block. `name` is the tool, for messages.
|
|
17
|
+
*/
|
|
18
|
+
export declare function bashFetchVerified(name: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* The PowerShell steps that fetch `$downloadUrl` into `$archive` with
|
|
21
|
+
* retries, then check its SHA-256 against `$expectedSha256`, throwing on a
|
|
22
|
+
* mismatch. Indented for use inside a `try` block; `name` is the tool, for
|
|
23
|
+
* messages.
|
|
24
|
+
*/
|
|
25
|
+
export declare function pwshFetchVerified(name: string): string;
|