@zuke-build/cli 0.0.0-stage → 2.6.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.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +343 -2
  3. package/mod.d.ts +99 -0
  4. package/mod.js +893 -0
  5. package/package.json +35 -4
  6. package/src/binary_launcher.d.ts +49 -0
  7. package/src/binary_launcher.js +327 -0
  8. package/src/binary_pin.d.ts +47 -0
  9. package/src/binary_pin.js +117 -0
  10. package/src/build_file.d.ts +25 -0
  11. package/src/build_file.js +65 -0
  12. package/src/cache.d.ts +23 -0
  13. package/src/cache.js +26 -0
  14. package/src/deno_isolated.d.ts +14 -0
  15. package/src/deno_isolated.js +70 -0
  16. package/src/deno_path.d.ts +115 -0
  17. package/src/deno_path.js +205 -0
  18. package/src/deno_pin.d.ts +37 -0
  19. package/src/deno_pin.js +32 -0
  20. package/src/dependencies.d.ts +48 -0
  21. package/src/dependencies.js +80 -0
  22. package/src/dispatch.d.ts +220 -0
  23. package/src/dispatch.js +538 -0
  24. package/src/embedded_engine.d.ts +28 -0
  25. package/src/embedded_engine.js +21 -0
  26. package/src/engine_pin.d.ts +56 -0
  27. package/src/engine_pin.js +196 -0
  28. package/src/fs.d.ts +14 -0
  29. package/src/fs.js +25 -0
  30. package/src/import.d.ts +132 -0
  31. package/src/import.js +289 -0
  32. package/src/install_source.d.ts +79 -0
  33. package/src/install_source.js +104 -0
  34. package/src/launcher.d.ts +37 -0
  35. package/src/launcher.js +464 -0
  36. package/src/mcp_config.d.ts +63 -0
  37. package/src/mcp_config.js +86 -0
  38. package/src/output.d.ts +38 -0
  39. package/src/output.js +43 -0
  40. package/src/paint.d.ts +42 -0
  41. package/src/paint.js +38 -0
  42. package/src/project.d.ts +69 -0
  43. package/src/project.js +132 -0
  44. package/src/pyproject.d.ts +30 -0
  45. package/src/pyproject.js +156 -0
  46. package/src/python_build.d.ts +27 -0
  47. package/src/python_build.js +197 -0
  48. package/src/records.d.ts +9 -0
  49. package/src/records.js +13 -0
  50. package/src/relock.d.ts +11 -0
  51. package/src/relock.js +182 -0
  52. package/src/setup.d.ts +251 -0
  53. package/src/setup.js +601 -0
  54. package/src/star.d.ts +44 -0
  55. package/src/star.js +100 -0
  56. package/src/starter.d.ts +55 -0
  57. package/src/starter.js +126 -0
  58. package/src/toml.d.ts +32 -0
  59. package/src/toml.js +354 -0
  60. package/src/translate.d.ts +69 -0
  61. package/src/translate.js +198 -0
  62. package/src/upgrade.d.ts +113 -0
  63. package/src/upgrade.js +344 -0
  64. package/src/version.d.ts +11 -0
  65. package/src/version.js +13 -0
  66. package/src/version_report.d.ts +55 -0
  67. package/src/version_report.js +187 -0
  68. 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;
@@ -0,0 +1,464 @@
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 { DENO_PIN, denoReleaseTag, POSIX_TARGETS, WINDOWS_TARGETS, } from "./deno_pin.js";
37
+ /** Which launcher variant to render. */
38
+ /**
39
+ * The notice a run without a lockfile prints — a fresh scaffold has none, so
40
+ * the first run must be allowed to write one, and saying so keeps a deleted
41
+ * lockfile from downgrading verification silently. Shared by both launcher
42
+ * templates and the global CLI's forwarding, so the three cannot drift.
43
+ * `dash` is the hyphen the caller's encoding is comfortable with (PowerShell
44
+ * sources are kept ASCII).
45
+ */
46
+ export function noLockNotice(dash) {
47
+ return `zuke: no deno.lock here yet ${dash} running without lockfile ` +
48
+ "verification so Deno can write one.";
49
+ }
50
+ /** The build file a launcher with `options` runs, checked before it is written into a script. */
51
+ function buildFileOf(options) {
52
+ return assertBuildFileName(options.buildFile ?? BUILD_FILE);
53
+ }
54
+ /** The line a plain Deno launcher carries, which `zuke upgrade --engine` keeps a launcher plain by. */
55
+ export const PLAIN_DENO_LAUNCHER = "# Requires Deno:";
56
+ /** The URL the plain launchers point at when Deno is missing. */
57
+ export const DENO_INSTALL_DOCS = "https://docs.deno.com/runtime/getting_started/installation/";
58
+ /** The MIT notice every generated launcher opens with (after its shebang). */
59
+ const LICENSE_HEADER = `# Copyright (c) 2026 the Zuke contributors
60
+ # SPDX-License-Identifier: MIT`;
61
+ /* cspell:disable */
62
+ /**
63
+ * The `DENO_VERSION` / `DENO_SHA256` / `DENO_INSTALL` contract, as the comment
64
+ * block both bootstrap launchers carry. `dash` is the hyphen the script's
65
+ * encoding is comfortable with (PowerShell sources are kept ASCII).
66
+ */
67
+ function bootstrapEnvDocs(pin, dash) {
68
+ return `# Honoured environment variables:
69
+ # DENO_INSTALL where Deno is installed/looked for (default: ~/.deno)
70
+ # DENO_VERSION which Deno to install on bootstrap. Defaults to a pinned,
71
+ # known-good version (see below) for reproducible and more
72
+ # predictable installs. An override must name an exact release
73
+ # tag (e.g. ${denoReleaseTag(pin)}) ${dash} "latest" is rejected, because a moving
74
+ # target has no checksum to pin ${dash} and is only installed if
75
+ # DENO_SHA256 also supplies the matching per-platform checksum
76
+ # (see below); this launcher never downloads an unverified
77
+ # binary.
78
+ # DENO_SHA256 required alongside a DENO_VERSION override: the expected
79
+ # SHA-256 of the release zip for the *current* platform (see
80
+ # the asset name printed on a checksum mismatch).`;
81
+ }
82
+ /** The provenance comment above the pinned checksums. */
83
+ function checksumProvenance(pin, versionVar) {
84
+ return `# SHA-256 of each \`deno-<target>.zip\` release asset, from
85
+ # https://github.com/denoland/deno/releases/tag/${denoReleaseTag(pin)} (GitHub's own reported
86
+ # asset \`digest\`, cross-checked by downloading and hashing the artifact).
87
+ # Bump *together* with ${versionVar}: this file is generated from
88
+ # @zuke/cli's deno_pin.ts, so change the pin there and regenerate.`;
89
+ }
90
+ /** The bash launcher's Deno resolution: the bootstrap, or the fail-closed check. */
91
+ function bashResolveDeno(options, pin) {
92
+ if (!options.bootstrapDeno) {
93
+ return `if ! command -v deno >/dev/null 2>&1; then
94
+ echo "zuke: Deno not found on PATH. Install it, then re-run this launcher:" >&2
95
+ echo " ${DENO_INSTALL_DOCS}" >&2
96
+ exit 1
97
+ fi
98
+ deno_bin="$(command -v deno)"`;
99
+ }
100
+ return `deno_install="\${DENO_INSTALL:-$HOME/.deno}"
101
+
102
+ if command -v deno >/dev/null 2>&1; then
103
+ deno_bin="$(command -v deno)"
104
+ elif [ -x "$deno_install/bin/deno" ]; then
105
+ deno_bin="$deno_install/bin/deno"
106
+ else
107
+ echo "zuke: Deno not found — installing it now..." >&2
108
+ for cmd in curl unzip; do
109
+ if ! command -v "$cmd" >/dev/null 2>&1; then
110
+ echo "zuke: $cmd is required to bootstrap Deno; install Deno manually:" >&2
111
+ echo " ${DENO_INSTALL_DOCS}" >&2
112
+ exit 1
113
+ fi
114
+ done
115
+
116
+ deno_version="\${DENO_VERSION:-$DEFAULT_DENO_VERSION}"
117
+ case "$deno_version" in
118
+ latest)
119
+ # There is no \`latest\` release tag to download, and a moving target has no
120
+ # checksum to pin — so name the release you want instead.
121
+ echo "zuke: DENO_VERSION=latest is not supported: this launcher verifies the" >&2
122
+ echo " download against a pinned SHA-256, and \\"latest\\" has no fixed hash." >&2
123
+ echo " Set DENO_VERSION to an exact release tag (e.g. ${denoReleaseTag(pin)}) plus DENO_SHA256" >&2
124
+ echo " with that release's deno-<target>.zip hash, or unset DENO_VERSION to" >&2
125
+ echo " install the verified default $DEFAULT_DENO_VERSION." >&2
126
+ exit 1
127
+ ;;
128
+ v*) ;;
129
+ *) deno_version="v$deno_version" ;;
130
+ esac
131
+
132
+ # Map uname's OS/arch spelling to Deno's release asset target triple.
133
+ case "$(uname -s)" in
134
+ Linux) os_part="unknown-linux-gnu" ;;
135
+ Darwin) os_part="apple-darwin" ;;
136
+ *)
137
+ echo "zuke: unsupported OS for the checksum-verified bootstrap: $(uname -s)." >&2
138
+ echo " Install Deno manually: ${DENO_INSTALL_DOCS}" >&2
139
+ exit 1
140
+ ;;
141
+ esac
142
+ case "$(uname -m)" in
143
+ x86_64 | amd64) arch_part="x86_64" ;;
144
+ arm64 | aarch64) arch_part="aarch64" ;;
145
+ *)
146
+ echo "zuke: unsupported architecture for the checksum-verified bootstrap: $(uname -m)." >&2
147
+ echo " Install Deno manually: ${DENO_INSTALL_DOCS}" >&2
148
+ exit 1
149
+ ;;
150
+ esac
151
+ target="\${arch_part}-\${os_part}"
152
+
153
+ if [ "$deno_version" = "$DEFAULT_DENO_VERSION" ]; then
154
+ expected_sha256="$(deno_checksum_for "$target")" || {
155
+ echo "zuke: no pinned checksum for $target — this platform isn't covered yet." >&2
156
+ exit 1
157
+ }
158
+ elif [ -n "\${DENO_SHA256:-}" ]; then
159
+ # An explicit override: the caller vouches for this version/platform pair
160
+ # by supplying its own checksum, so the download is still verified.
161
+ expected_sha256="$DENO_SHA256"
162
+ else
163
+ echo "zuke: DENO_VERSION=$deno_version overrides the pinned $DEFAULT_DENO_VERSION," >&2
164
+ echo " but no checksum is pinned for it. Set DENO_SHA256 to the expected" >&2
165
+ echo " SHA-256 of deno-$target.zip for that release, or unset DENO_VERSION" >&2
166
+ echo " to use the verified default." >&2
167
+ exit 1
168
+ fi
169
+
170
+ asset="deno-\${target}.zip"
171
+ download_url="https://github.com/denoland/deno/releases/download/\${deno_version}/\${asset}"
172
+ work_dir="$(mktemp -d)"
173
+ trap 'rm -rf "$work_dir"' EXIT
174
+ archive="$work_dir/$asset"
175
+
176
+ # The download fetches over the network, which is occasionally flaky (e.g. a
177
+ # transient 5xx from the CDN). Retry a few times with backoff so a blip
178
+ # doesn't fail the whole run.
179
+ download_deno() {
180
+ curl -fsSL -o "$archive" "$download_url"
181
+ }
182
+ attempt=1
183
+ max_attempts=4
184
+ until download_deno; do
185
+ if [ "$attempt" -ge "$max_attempts" ]; then
186
+ echo "zuke: failed to download Deno after $max_attempts attempts." >&2
187
+ exit 1
188
+ fi
189
+ delay=$((attempt * 3))
190
+ echo "zuke: Deno download failed (attempt $attempt/$max_attempts); retrying in \${delay}s..." >&2
191
+ sleep "$delay"
192
+ attempt=$((attempt + 1))
193
+ done
194
+
195
+ if command -v sha256sum >/dev/null 2>&1; then
196
+ actual_sha256="$(sha256sum "$archive" | awk '{print $1}')"
197
+ elif command -v shasum >/dev/null 2>&1; then
198
+ actual_sha256="$(shasum -a 256 "$archive" | awk '{print $1}')"
199
+ else
200
+ echo "zuke: neither sha256sum nor shasum is available to verify the download." >&2
201
+ exit 1
202
+ fi
203
+ if [ "$actual_sha256" != "$expected_sha256" ]; then
204
+ echo "zuke: checksum mismatch for $asset:" >&2
205
+ echo " expected $expected_sha256" >&2
206
+ echo " got $actual_sha256" >&2
207
+ exit 1
208
+ fi
209
+
210
+ mkdir -p "$deno_install/bin"
211
+ unzip -oq "$archive" -d "$deno_install/bin"
212
+ chmod +x "$deno_install/bin/deno"
213
+ deno_bin="$deno_install/bin/deno"
214
+ fi
215
+
216
+ # Put this Deno on PATH so CLIs the build provisions with \`deno install\` — whose
217
+ # generated launchers invoke \`deno\` by name — can find it even when Deno was
218
+ # bootstrapped to a non-PATH location (e.g. ~/.deno/bin).
219
+ export PATH="$(dirname "$deno_bin"):$PATH"`;
220
+ }
221
+ /** The bash launcher's pin block: the version and the per-platform checksums. */
222
+ function bashPin(pin) {
223
+ const arms = POSIX_TARGETS.map((target) => ` ${target})\n echo "${pin.checksums[target]}" ;;`).join("\n");
224
+ return `# Pinned default so the bootstrap installs a known version rather than whatever
225
+ # "latest" happens to be.
226
+ DEFAULT_DENO_VERSION="${denoReleaseTag(pin)}"
227
+
228
+ # --- Pinned per-platform checksums for DEFAULT_DENO_VERSION -----------------
229
+ ${checksumProvenance(pin, "DEFAULT_DENO_VERSION")}
230
+ deno_checksum_for() {
231
+ case "$1" in
232
+ ${arms}
233
+ *)
234
+ return 1 ;;
235
+ esac
236
+ }
237
+ # -----------------------------------------------------------------------------
238
+ `;
239
+ }
240
+ /**
241
+ * The bash launcher (`./zuke`). Runs the build file with the Deno on `PATH`, or
242
+ * with the one it bootstraps first (see the module docs for the variants).
243
+ */
244
+ export function launcherBash(options, pin = DENO_PIN) {
245
+ const build = buildFileOf(options);
246
+ const purpose = options.bootstrapDeno
247
+ ? `# Zuke bootstrap launcher — a \`./build.sh\`-style entry point for Deno.
248
+ #
249
+ # ./zuke # run the default target
250
+ # ./zuke <target> # run one target and its prerequisites
251
+ # ./zuke --list # list every target
252
+ #
253
+ # Ensures Deno is available (installing it on first use if missing), then runs
254
+ # the project's build file (${build}). No global install required.
255
+ #
256
+ ${bootstrapEnvDocs(pin, "—")}`
257
+ : `# Zuke launcher — runs the project's build file (${build}) with the Deno on PATH.
258
+ #
259
+ # ./zuke # run the default target
260
+ # ./zuke <target> # run one target and its prerequisites
261
+ # ./zuke --list # list every target
262
+ #
263
+ ${PLAIN_DENO_LAUNCHER} ${DENO_INSTALL_DOCS}`;
264
+ const pinBlock = options.bootstrapDeno ? `\n${bashPin(pin)}` : "";
265
+ return `#!/usr/bin/env bash
266
+ ${LICENSE_HEADER}
267
+ #
268
+ ${purpose}
269
+ set -euo pipefail
270
+ ${pinBlock}
271
+ dir="$(cd "$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
272
+ cd "$dir"
273
+
274
+ ${bashResolveDeno(options, pin)}
275
+
276
+ # The first run has no lockfile to verify against, so let Deno write one; from
277
+ # then on --frozen fails the build if the module graph changed. Say so when
278
+ # skipping, so a deleted lockfile downgrades verification visibly instead of
279
+ # silently.
280
+ if [ -f deno.lock ]; then
281
+ exec "$deno_bin" run -A --frozen ${build} "$@"
282
+ else
283
+ echo "${noLockNotice("—")}" >&2
284
+ exec "$deno_bin" run -A ${build} "$@"
285
+ fi
286
+ `;
287
+ }
288
+ /** The PowerShell launcher's Deno resolution: the bootstrap, or the fail-closed check. */
289
+ function pwshResolveDeno(options, pin) {
290
+ if (!options.bootstrapDeno) {
291
+ return `$found = Get-Command deno -CommandType Application -ErrorAction SilentlyContinue
292
+ if (-not $found) {
293
+ Write-Error "zuke: Deno not found on PATH. Install it, then re-run this launcher: ${DENO_INSTALL_DOCS}"
294
+ exit 1
295
+ }
296
+ $deno = $found.Source`;
297
+ }
298
+ return `if (-not $env:DENO_INSTALL) {
299
+ $env:DENO_INSTALL = Join-Path $HOME ".deno"
300
+ }
301
+
302
+ function Resolve-Deno {
303
+ $onPath = Get-Command deno -CommandType Application -ErrorAction SilentlyContinue
304
+ if ($onPath) { return $onPath.Source }
305
+ $local = Join-Path $env:DENO_INSTALL "bin\\deno.exe"
306
+ if (Test-Path $local) { return $local }
307
+ return $null
308
+ }
309
+
310
+ $deno = Resolve-Deno
311
+ if (-not $deno) {
312
+ Write-Host "zuke: Deno not found - installing it now..."
313
+
314
+ $denoVersion = if ($env:DENO_VERSION) { $env:DENO_VERSION } else { $DefaultDenoVersion }
315
+ if ($denoVersion -eq "latest") {
316
+ # There is no \`latest\` release tag to download, and a moving target has no
317
+ # checksum to pin - so name the release you want instead.
318
+ throw "zuke: DENO_VERSION=latest is not supported: this launcher verifies the " +
319
+ "download against a pinned SHA-256, and ""latest"" has no fixed hash. Set " +
320
+ "DENO_VERSION to an exact release tag (e.g. ${denoReleaseTag(pin)}) plus DENO_SHA256 with that " +
321
+ "release's deno-<target>.zip hash, or unset DENO_VERSION to install the " +
322
+ "verified default $DefaultDenoVersion."
323
+ }
324
+ $vTag = if ($denoVersion.StartsWith("v")) { $denoVersion } else { "v$denoVersion" }
325
+ $bareVersion = $vTag.Substring(1)
326
+
327
+ # .ToString() forces a plain string comparison in the switch below,
328
+ # independent of how PowerShell would otherwise coerce the enum/string types.
329
+ $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()
330
+ $target = switch ($arch) {
331
+ "X64" { "x86_64-pc-windows-msvc" }
332
+ "Arm64" { "aarch64-pc-windows-msvc" }
333
+ default {
334
+ throw "zuke: unsupported architecture for the checksum-verified bootstrap: $arch. " +
335
+ "Install Deno manually: ${DENO_INSTALL_DOCS}"
336
+ }
337
+ }
338
+
339
+ if ($bareVersion -eq $DefaultDenoVersion -and $DenoChecksums.ContainsKey($target)) {
340
+ $expectedSha256 = $DenoChecksums[$target]
341
+ } elseif ($env:DENO_SHA256) {
342
+ # An explicit override: the caller vouches for this version/platform pair
343
+ # by supplying its own checksum, so the download is still verified.
344
+ $expectedSha256 = $env:DENO_SHA256
345
+ } else {
346
+ throw "zuke: DENO_VERSION=$denoVersion overrides the pinned $DefaultDenoVersion, " +
347
+ "but no checksum is pinned for it. Set DENO_SHA256 to the expected SHA-256 " +
348
+ "of deno-$target.zip for that release, or unset DENO_VERSION to use the " +
349
+ "verified default."
350
+ }
351
+
352
+ $asset = "deno-$target.zip"
353
+ $downloadUrl = "https://github.com/denoland/deno/releases/download/$vTag/$asset"
354
+ $workDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid())
355
+ New-Item -ItemType Directory -Path $workDir | Out-Null
356
+ $archive = Join-Path $workDir $asset
357
+ try {
358
+ # The download fetches over the network, which is occasionally flaky (e.g.
359
+ # a transient 5xx from the CDN). Retry a few times with backoff so a blip
360
+ # doesn't fail the whole run.
361
+ $maxAttempts = 4
362
+ for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) {
363
+ try {
364
+ Invoke-WebRequest -Uri $downloadUrl -OutFile $archive
365
+ break
366
+ } catch {
367
+ if ($attempt -ge $maxAttempts) {
368
+ throw "zuke: failed to download Deno after $maxAttempts attempts: $_"
369
+ }
370
+ $delay = $attempt * 3
371
+ Write-Host "zuke: Deno download failed (attempt $attempt/$maxAttempts); retrying in \${delay}s..."
372
+ Start-Sleep -Seconds $delay
373
+ }
374
+ }
375
+
376
+ $actualSha256 = (Get-FileHash -Path $archive -Algorithm SHA256).Hash.ToLowerInvariant()
377
+ if ($actualSha256 -ne $expectedSha256.ToLowerInvariant()) {
378
+ throw "zuke: checksum mismatch for \${asset}: expected $expectedSha256, got $actualSha256"
379
+ }
380
+
381
+ $binDir = Join-Path $env:DENO_INSTALL "bin"
382
+ New-Item -ItemType Directory -Force -Path $binDir | Out-Null
383
+ Expand-Archive -Path $archive -DestinationPath $binDir -Force
384
+ } finally {
385
+ Remove-Item -Recurse -Force $workDir -ErrorAction SilentlyContinue
386
+ }
387
+
388
+ $deno = Join-Path $env:DENO_INSTALL "bin\\deno.exe"
389
+ }
390
+
391
+ # Put this Deno on PATH so CLIs the build provisions with \`deno install\` - whose
392
+ # generated launchers invoke \`deno\` by name - can find it even when Deno was
393
+ # bootstrapped to a non-PATH location.
394
+ $env:PATH = (Split-Path -Parent $deno) + [IO.Path]::PathSeparator + $env:PATH`;
395
+ }
396
+ /** The PowerShell launcher's pin block: the version and the per-platform checksums. */
397
+ function pwshPin(pin) {
398
+ const width = Math.max(...WINDOWS_TARGETS.map((t) => t.length)) + 2;
399
+ const entries = WINDOWS_TARGETS.map((target) => ` ${`"${target}"`.padEnd(width)} = "${pin.checksums[target]}"`).join("\n");
400
+ return `# Pinned default so the bootstrap installs a known version rather than whatever
401
+ # "latest" happens to be.
402
+ $DefaultDenoVersion = "${pin.version}"
403
+
404
+ # --- Pinned per-platform checksums for $DefaultDenoVersion ------------------
405
+ ${checksumProvenance(pin, "$DefaultDenoVersion")}
406
+ $DenoChecksums = @{
407
+ ${entries}
408
+ }
409
+ # -----------------------------------------------------------------------------
410
+ `;
411
+ }
412
+ /**
413
+ * The PowerShell launcher (`.\zuke.ps1`). Mirrors {@link launcherBash},
414
+ * variant for variant, including the conditional `--frozen`.
415
+ */
416
+ export function launcherPwsh(options, pin = DENO_PIN) {
417
+ const build = buildFileOf(options);
418
+ const purpose = options.bootstrapDeno
419
+ ? `# Zuke bootstrap launcher (PowerShell) - a \`.\\build.ps1\`-style entry point.
420
+ #
421
+ # .\\zuke.ps1 # run the default target
422
+ # .\\zuke.ps1 <target> # run one target and its prerequisites
423
+ # .\\zuke.ps1 --list # list every target
424
+ #
425
+ # Ensures Deno is available (installing it on first use if missing), then runs
426
+ # the project's build file (${build}). No global install required.
427
+ #
428
+ ${bootstrapEnvDocs(pin, "-")}`
429
+ : `# Zuke launcher (PowerShell) - runs the project's build file (${build}) with the Deno on PATH.
430
+ #
431
+ # .\\zuke.ps1 # run the default target
432
+ # .\\zuke.ps1 <target> # run one target and its prerequisites
433
+ # .\\zuke.ps1 --list # list every target
434
+ #
435
+ ${PLAIN_DENO_LAUNCHER} ${DENO_INSTALL_DOCS}`;
436
+ const pinBlock = options.bootstrapDeno ? `\n${pwshPin(pin)}` : "";
437
+ return `#!/usr/bin/env pwsh
438
+ ${LICENSE_HEADER}
439
+ #
440
+ ${purpose}
441
+
442
+ $ErrorActionPreference = "Stop"
443
+ ${pinBlock}
444
+ $dir = Split-Path -Parent $MyInvocation.MyCommand.Path
445
+ Set-Location $dir
446
+
447
+ ${pwshResolveDeno(options, pin)}
448
+
449
+ # The first run has no lockfile to verify against, so let Deno write one; from
450
+ # then on --frozen fails the build if the module graph changed. Say so when
451
+ # skipping, so a deleted lockfile downgrades verification visibly instead of
452
+ # silently.
453
+ $denoArgs = @("run", "-A")
454
+ if (Test-Path (Join-Path $dir "deno.lock")) {
455
+ $denoArgs += "--frozen"
456
+ } else {
457
+ Write-Warning "${noLockNotice("-")}"
458
+ }
459
+ $denoArgs += (Join-Path $dir "${build}")
460
+ & $deno @denoArgs @args
461
+ exit $LASTEXITCODE
462
+ `;
463
+ }
464
+ /* cspell:enable */