@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.
- package/LICENSE +21 -0
- package/README.md +343 -2
- package/mod.d.ts +99 -0
- package/mod.js +893 -0
- package/package.json +35 -4
- package/src/binary_launcher.d.ts +49 -0
- package/src/binary_launcher.js +327 -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 +65 -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 +220 -0
- package/src/dispatch.js +538 -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 +464 -0
- package/src/mcp_config.d.ts +63 -0
- package/src/mcp_config.js +86 -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 +9 -0
- package/src/records.js +13 -0
- package/src/relock.d.ts +11 -0
- package/src/relock.js +182 -0
- package/src/setup.d.ts +251 -0
- package/src/setup.js +601 -0
- package/src/star.d.ts +44 -0
- package/src/star.js +100 -0
- package/src/starter.d.ts +55 -0
- package/src/starter.js +126 -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
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuke-build/cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.6.0",
|
|
4
|
+
"description": "The zuke command-line tool — scaffold a Zuke project with `zuke setup`, including a starter build, launchers, and tasks.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./mod.d.ts",
|
|
10
|
+
"default": "./mod.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"**/*.js",
|
|
15
|
+
"**/*.d.ts"
|
|
16
|
+
],
|
|
17
|
+
"bin": {
|
|
18
|
+
"zuke": "zuke.js"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=24.12"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/zuke-build/zuke.git",
|
|
26
|
+
"directory": "packages/cli"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://zuke.build",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/zuke-build/zuke/issues"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@zuke/console": "npm:@zuke-build/console@^1.1.0",
|
|
34
|
+
"@zuke/core": "npm:@zuke-build/core@^1.83.0",
|
|
35
|
+
"@zuke/gh": "npm:@zuke-build/gh@^1.6.0"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `./zuke` and `zuke.ps1` launchers of a project another SDK hosts: a
|
|
3
|
+
* Python build, say, with a `zuke.json` and no `zuke.ts`. They run the
|
|
4
|
+
* standalone `zuke` binary, which carries the engine and every tool wrapper,
|
|
5
|
+
* so the project needs nothing from a stack it does not use — no Deno, no
|
|
6
|
+
* Node — on a laptop or a CI runner. Two variants, as for the Deno launchers
|
|
7
|
+
* in {@link "./launcher.ts"}:
|
|
8
|
+
*
|
|
9
|
+
* - **download** — run the `zuke` release the launcher pins
|
|
10
|
+
* ({@link "./binary_pin.ts"}). On first use, download its archive from the
|
|
11
|
+
* release, verify it against the pinned SHA-256, and keep the binary in
|
|
12
|
+
* `ZUKE_INSTALL` (default `~/.zuke`), one directory per release. Nothing is
|
|
13
|
+
* installed that the pin did not vouch for; `ZUKE_RELEASES_URL` names a
|
|
14
|
+
* mirror, whose download is verified the same way.
|
|
15
|
+
* - **plain** — require `zuke` on `PATH`, and when it is missing print where
|
|
16
|
+
* to get it and exit 1, for a project that must not download its tools.
|
|
17
|
+
*
|
|
18
|
+
* Both set `ZUKE_FORWARDED`, so the `zuke` they start runs the build itself
|
|
19
|
+
* rather than this launcher again, and `ZUKE_LAUNCHER_ROOT` to the
|
|
20
|
+
* launcher's directory: running a launcher is an explicit act on the
|
|
21
|
+
* project it sits in, so the discovery trust gate does not judge that root.
|
|
22
|
+
*
|
|
23
|
+
* @module
|
|
24
|
+
*/
|
|
25
|
+
import { type BinaryPin } from "./binary_pin.ts";
|
|
26
|
+
/** Which binary launcher variant to render. */
|
|
27
|
+
export interface BinaryLauncherOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Download the pinned, checksum-verified `zuke` release when it is not
|
|
30
|
+
* already kept (`true`), or require `zuke` on `PATH` and fail closed
|
|
31
|
+
* without it (`false`).
|
|
32
|
+
*/
|
|
33
|
+
download: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** The line every binary launcher opens its description with. */
|
|
36
|
+
export declare const BINARY_LAUNCHER_MARKER = "# Zuke launcher for a build another SDK hosts";
|
|
37
|
+
/** The line a plain binary launcher carries, which `zuke upgrade --engine` keeps it plain by. */
|
|
38
|
+
export declare const PLAIN_BINARY_LAUNCHER = "# Runs the zuke on PATH:";
|
|
39
|
+
/**
|
|
40
|
+
* The bash launcher (`./zuke`) of a hosted build: runs the pinned `zuke`
|
|
41
|
+
* release, downloading it first, or the `zuke` on `PATH` (see the module
|
|
42
|
+
* docs for the variants).
|
|
43
|
+
*/
|
|
44
|
+
export declare function binaryLauncherBash(options: BinaryLauncherOptions, pin: BinaryPin): string;
|
|
45
|
+
/**
|
|
46
|
+
* The PowerShell launcher (`.\zuke.ps1`) of a hosted build. Mirrors
|
|
47
|
+
* {@link binaryLauncherBash}, variant for variant.
|
|
48
|
+
*/
|
|
49
|
+
export declare function binaryLauncherPwsh(options: BinaryLauncherOptions, pin: BinaryPin): string;
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The `./zuke` and `zuke.ps1` launchers of a project another SDK hosts: a
|
|
5
|
+
* Python build, say, with a `zuke.json` and no `zuke.ts`. They run the
|
|
6
|
+
* standalone `zuke` binary, which carries the engine and every tool wrapper,
|
|
7
|
+
* so the project needs nothing from a stack it does not use — no Deno, no
|
|
8
|
+
* Node — on a laptop or a CI runner. Two variants, as for the Deno launchers
|
|
9
|
+
* in {@link "./launcher.ts"}:
|
|
10
|
+
*
|
|
11
|
+
* - **download** — run the `zuke` release the launcher pins
|
|
12
|
+
* ({@link "./binary_pin.ts"}). On first use, download its archive from the
|
|
13
|
+
* release, verify it against the pinned SHA-256, and keep the binary in
|
|
14
|
+
* `ZUKE_INSTALL` (default `~/.zuke`), one directory per release. Nothing is
|
|
15
|
+
* installed that the pin did not vouch for; `ZUKE_RELEASES_URL` names a
|
|
16
|
+
* mirror, whose download is verified the same way.
|
|
17
|
+
* - **plain** — require `zuke` on `PATH`, and when it is missing print where
|
|
18
|
+
* to get it and exit 1, for a project that must not download its tools.
|
|
19
|
+
*
|
|
20
|
+
* Both set `ZUKE_FORWARDED`, so the `zuke` they start runs the build itself
|
|
21
|
+
* rather than this launcher again, and `ZUKE_LAUNCHER_ROOT` to the
|
|
22
|
+
* launcher's directory: running a launcher is an explicit act on the
|
|
23
|
+
* project it sits in, so the discovery trust gate does not judge that root.
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
import { BINARY_INSTALL_DOCS, BINARY_POSIX_TARGETS, BINARY_RELEASES_URL, BINARY_WINDOWS_TARGET, binaryReleaseTag, } from "./binary_pin.js";
|
|
28
|
+
import { FORWARDED_ENV, LAUNCHER_ROOT_ENV } from "./dispatch.js";
|
|
29
|
+
/** The line every binary launcher opens its description with. */
|
|
30
|
+
export const BINARY_LAUNCHER_MARKER = "# Zuke launcher for a build another SDK hosts";
|
|
31
|
+
/** The line a plain binary launcher carries, which `zuke upgrade --engine` keeps it plain by. */
|
|
32
|
+
export const PLAIN_BINARY_LAUNCHER = "# Runs the zuke on PATH:";
|
|
33
|
+
/** The MIT notice every generated launcher opens with (after its shebang). */
|
|
34
|
+
const LICENSE_HEADER = `# Copyright (c) 2026 the Zuke contributors
|
|
35
|
+
# SPDX-License-Identifier: MIT`;
|
|
36
|
+
/* cspell:disable */
|
|
37
|
+
/** The usage lines both scripts open with, for `./zuke` or `.\zuke.ps1`. */
|
|
38
|
+
function usage(command) {
|
|
39
|
+
return `# ${command} # run the default target
|
|
40
|
+
# ${command} <target> # run one target and its prerequisites
|
|
41
|
+
# ${command} --list # list every target`;
|
|
42
|
+
}
|
|
43
|
+
/** The bash launcher's download of the pinned release into `$zuke_bin`. */
|
|
44
|
+
function bashDownload(pin) {
|
|
45
|
+
const arms = BINARY_POSIX_TARGETS.map((target) => ` ${target})\n echo "${pin.checksums[target]}" ;;`).join("\n");
|
|
46
|
+
return `# The pinned release, and the SHA-256 of each platform's archive, from the
|
|
47
|
+
# SHA256SUMS of ${BINARY_RELEASES_URL}/${binaryReleaseTag(pin.version)}.
|
|
48
|
+
# Moved by \`zuke upgrade --engine\`, which rewrites this file; never hand-edit.
|
|
49
|
+
ZUKE_VERSION="${pin.version}"
|
|
50
|
+
zuke_checksum_for() {
|
|
51
|
+
case "$1" in
|
|
52
|
+
${arms}
|
|
53
|
+
*)
|
|
54
|
+
return 1 ;;
|
|
55
|
+
esac
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
zuke_install="\${ZUKE_INSTALL:-$HOME/.zuke}"
|
|
59
|
+
zuke_bin="$zuke_install/releases/$ZUKE_VERSION/zuke"
|
|
60
|
+
|
|
61
|
+
if [ ! -x "$zuke_bin" ]; then
|
|
62
|
+
echo "zuke: zuke $ZUKE_VERSION is not here yet — downloading it..." >&2
|
|
63
|
+
for cmd in curl tar; do
|
|
64
|
+
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
65
|
+
echo "zuke: $cmd is required to download zuke; install zuke instead:" >&2
|
|
66
|
+
echo " ${BINARY_INSTALL_DOCS}" >&2
|
|
67
|
+
exit 1
|
|
68
|
+
fi
|
|
69
|
+
done
|
|
70
|
+
|
|
71
|
+
# Map uname's OS/arch spelling to the release's target triple.
|
|
72
|
+
case "$(uname -s)" in
|
|
73
|
+
Linux) os_part="unknown-linux-gnu" ;;
|
|
74
|
+
Darwin) os_part="apple-darwin" ;;
|
|
75
|
+
*)
|
|
76
|
+
echo "zuke: no zuke release is built for $(uname -s); use zuke.ps1 on Windows." >&2
|
|
77
|
+
exit 1
|
|
78
|
+
;;
|
|
79
|
+
esac
|
|
80
|
+
case "$(uname -m)" in
|
|
81
|
+
x86_64 | amd64) arch_part="x86_64" ;;
|
|
82
|
+
arm64 | aarch64) arch_part="aarch64" ;;
|
|
83
|
+
*)
|
|
84
|
+
echo "zuke: no zuke release is built for the $(uname -m) architecture." >&2
|
|
85
|
+
exit 1
|
|
86
|
+
;;
|
|
87
|
+
esac
|
|
88
|
+
target="\${arch_part}-\${os_part}"
|
|
89
|
+
expected_sha256="$(zuke_checksum_for "$target")" || {
|
|
90
|
+
echo "zuke: no pinned checksum for $target." >&2
|
|
91
|
+
exit 1
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
asset="zuke-\${ZUKE_VERSION}-\${target}.tar.gz"
|
|
95
|
+
download_url="\${ZUKE_RELEASES_URL:-${BINARY_RELEASES_URL}}/cli-v\${ZUKE_VERSION}/\${asset}"
|
|
96
|
+
work_dir="$(mktemp -d)"
|
|
97
|
+
trap 'rm -rf "$work_dir"' EXIT
|
|
98
|
+
archive="$work_dir/$asset"
|
|
99
|
+
|
|
100
|
+
# The network is occasionally flaky (a transient 5xx from the CDN), so a blip
|
|
101
|
+
# is retried with backoff rather than failing the run.
|
|
102
|
+
attempt=1
|
|
103
|
+
max_attempts=4
|
|
104
|
+
until curl -fsSL -o "$archive" "$download_url"; do
|
|
105
|
+
if [ "$attempt" -ge "$max_attempts" ]; then
|
|
106
|
+
echo "zuke: failed to download $download_url after $max_attempts attempts." >&2
|
|
107
|
+
exit 1
|
|
108
|
+
fi
|
|
109
|
+
delay=$((attempt * 3))
|
|
110
|
+
echo "zuke: download failed (attempt $attempt/$max_attempts); retrying in \${delay}s..." >&2
|
|
111
|
+
sleep "$delay"
|
|
112
|
+
attempt=$((attempt + 1))
|
|
113
|
+
done
|
|
114
|
+
|
|
115
|
+
if command -v sha256sum >/dev/null 2>&1; then
|
|
116
|
+
actual_sha256="$(sha256sum "$archive" | awk '{print $1}')"
|
|
117
|
+
elif command -v shasum >/dev/null 2>&1; then
|
|
118
|
+
actual_sha256="$(shasum -a 256 "$archive" | awk '{print $1}')"
|
|
119
|
+
else
|
|
120
|
+
echo "zuke: neither sha256sum nor shasum is available to verify the download." >&2
|
|
121
|
+
exit 1
|
|
122
|
+
fi
|
|
123
|
+
if [ "$actual_sha256" != "$expected_sha256" ]; then
|
|
124
|
+
echo "zuke: checksum mismatch for $asset:" >&2
|
|
125
|
+
echo " expected $expected_sha256" >&2
|
|
126
|
+
echo " got $actual_sha256" >&2
|
|
127
|
+
exit 1
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
tar -xzf "$archive" -C "$work_dir" zuke
|
|
131
|
+
mkdir -p "$(dirname "$zuke_bin")"
|
|
132
|
+
# Moved into place in one step, so a run interrupted mid-copy never leaves a
|
|
133
|
+
# binary behind that later runs would trust without verifying.
|
|
134
|
+
mv -f "$work_dir/zuke" "$zuke_bin.$$"
|
|
135
|
+
chmod +x "$zuke_bin.$$"
|
|
136
|
+
mv -f "$zuke_bin.$$" "$zuke_bin"
|
|
137
|
+
# Removed now: the exec below replaces this shell, so the trap never fires.
|
|
138
|
+
rm -rf "$work_dir"
|
|
139
|
+
trap - EXIT
|
|
140
|
+
fi`;
|
|
141
|
+
}
|
|
142
|
+
/** The bash launcher's plain resolution: the `zuke` on `PATH`, or exit 1. */
|
|
143
|
+
function bashPlain() {
|
|
144
|
+
return `if ! command -v zuke >/dev/null 2>&1; then
|
|
145
|
+
echo "zuke: the zuke command is not on PATH. Install it, then re-run this launcher:" >&2
|
|
146
|
+
echo " ${BINARY_INSTALL_DOCS}" >&2
|
|
147
|
+
exit 1
|
|
148
|
+
fi
|
|
149
|
+
zuke_bin="$(command -v zuke)"
|
|
150
|
+
# An empty or "." entry in PATH finds this very script (it ran \`cd\` into its
|
|
151
|
+
# own directory), and so would a zuke linked to it: running that would loop.
|
|
152
|
+
if [ "$zuke_bin" -ef "\${BASH_SOURCE[0]}" ]; then
|
|
153
|
+
echo "zuke: the zuke on PATH is this launcher ($zuke_bin), not the zuke command." >&2
|
|
154
|
+
echo " Install zuke, or drop the empty or . entry from PATH: ${BINARY_INSTALL_DOCS}" >&2
|
|
155
|
+
exit 1
|
|
156
|
+
fi`;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The bash launcher (`./zuke`) of a hosted build: runs the pinned `zuke`
|
|
160
|
+
* release, downloading it first, or the `zuke` on `PATH` (see the module
|
|
161
|
+
* docs for the variants).
|
|
162
|
+
*/
|
|
163
|
+
export function binaryLauncherBash(options, pin) {
|
|
164
|
+
const purpose = options.download
|
|
165
|
+
? `# Runs zuke ${pin.version}, which carries the engine and every tool wrapper, so
|
|
166
|
+
# this project needs nothing installed but its own SDK's tools. On first use
|
|
167
|
+
# it downloads that release, checksum-verified, into ZUKE_INSTALL.
|
|
168
|
+
#
|
|
169
|
+
# Honoured environment variables:
|
|
170
|
+
# ZUKE_INSTALL where zuke releases are kept (default: ~/.zuke)
|
|
171
|
+
# ZUKE_RELEASES_URL a mirror of ${BINARY_RELEASES_URL};
|
|
172
|
+
# what it serves is verified against the pins below`
|
|
173
|
+
: `${PLAIN_BINARY_LAUNCHER} ${BINARY_INSTALL_DOCS}`;
|
|
174
|
+
const resolve = options.download ? bashDownload(pin) : bashPlain();
|
|
175
|
+
return `#!/usr/bin/env bash
|
|
176
|
+
${LICENSE_HEADER}
|
|
177
|
+
#
|
|
178
|
+
${BINARY_LAUNCHER_MARKER}.
|
|
179
|
+
#
|
|
180
|
+
${usage("./zuke")}
|
|
181
|
+
#
|
|
182
|
+
${purpose}
|
|
183
|
+
set -euo pipefail
|
|
184
|
+
|
|
185
|
+
dir="$(cd "$(dirname "\${BASH_SOURCE[0]}")" && pwd -P)"
|
|
186
|
+
cd "$dir"
|
|
187
|
+
|
|
188
|
+
${resolve}
|
|
189
|
+
|
|
190
|
+
# zuke runs the build here itself rather than this launcher again, and does not
|
|
191
|
+
# hold this directory to the trust gate: running the launcher named it.
|
|
192
|
+
export ${FORWARDED_ENV}=1
|
|
193
|
+
export ${LAUNCHER_ROOT_ENV}="$dir"
|
|
194
|
+
exec "$zuke_bin" "$@"
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
197
|
+
/** The PowerShell launcher's download of the pinned release into `$zuke`. */
|
|
198
|
+
function pwshDownload(pin) {
|
|
199
|
+
return `# The pinned release, and the SHA-256 of its Windows archive, from the
|
|
200
|
+
# SHA256SUMS of ${BINARY_RELEASES_URL}/${binaryReleaseTag(pin.version)}.
|
|
201
|
+
# Moved by \`zuke upgrade --engine\`, which rewrites this file; never hand-edit.
|
|
202
|
+
$ZukeVersion = "${pin.version}"
|
|
203
|
+
$ZukeSha256 = "${pin.checksums[BINARY_WINDOWS_TARGET]}"
|
|
204
|
+
|
|
205
|
+
if ($PSVersionTable.PSEdition -eq "Core" -and -not $IsWindows) {
|
|
206
|
+
throw "zuke: zuke.ps1 runs the Windows release; on this OS run ./zuke instead."
|
|
207
|
+
}
|
|
208
|
+
$install = if ($env:ZUKE_INSTALL) { $env:ZUKE_INSTALL } else { Join-Path $HOME ".zuke" }
|
|
209
|
+
$zuke = Join-Path $install "releases\\$ZukeVersion\\zuke.exe"
|
|
210
|
+
|
|
211
|
+
if (-not (Test-Path $zuke)) {
|
|
212
|
+
Write-Host "zuke: zuke $ZukeVersion is not here yet - downloading it..."
|
|
213
|
+
# Arm64 Windows runs the x64 release under emulation; nothing else is built.
|
|
214
|
+
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()
|
|
215
|
+
if ($arch -ne "X64" -and $arch -ne "Arm64") {
|
|
216
|
+
throw "zuke: no zuke release is built for the $arch architecture."
|
|
217
|
+
}
|
|
218
|
+
$asset = "zuke-$ZukeVersion-${BINARY_WINDOWS_TARGET}.zip"
|
|
219
|
+
$base = if ($env:ZUKE_RELEASES_URL) { $env:ZUKE_RELEASES_URL } else { "${BINARY_RELEASES_URL}" }
|
|
220
|
+
$downloadUrl = "$base/cli-v$ZukeVersion/$asset"
|
|
221
|
+
$workDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid())
|
|
222
|
+
New-Item -ItemType Directory -Path $workDir | Out-Null
|
|
223
|
+
$archive = Join-Path $workDir $asset
|
|
224
|
+
try {
|
|
225
|
+
# The progress bar slows a large download severalfold in Windows PowerShell.
|
|
226
|
+
$ProgressPreference = "SilentlyContinue"
|
|
227
|
+
# The network is occasionally flaky (a transient 5xx from the CDN), so a
|
|
228
|
+
# blip is retried with backoff rather than failing the run.
|
|
229
|
+
$maxAttempts = 4
|
|
230
|
+
for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) {
|
|
231
|
+
try {
|
|
232
|
+
Invoke-WebRequest -Uri $downloadUrl -OutFile $archive -UseBasicParsing
|
|
233
|
+
break
|
|
234
|
+
} catch {
|
|
235
|
+
if ($attempt -ge $maxAttempts) {
|
|
236
|
+
throw "zuke: failed to download $downloadUrl after $maxAttempts attempts: $_"
|
|
237
|
+
}
|
|
238
|
+
$delay = $attempt * 3
|
|
239
|
+
Write-Host "zuke: download failed (attempt $attempt/$maxAttempts); retrying in \${delay}s..."
|
|
240
|
+
Start-Sleep -Seconds $delay
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
# .NET directly, not the hashing and archive cmdlets: those come from
|
|
245
|
+
# script modules, which Windows PowerShell started from a PowerShell 7
|
|
246
|
+
# session (whose module path it inherits) cannot load.
|
|
247
|
+
$stream = [System.IO.File]::OpenRead($archive)
|
|
248
|
+
try {
|
|
249
|
+
$digest = [System.Security.Cryptography.SHA256]::Create().ComputeHash($stream)
|
|
250
|
+
} finally {
|
|
251
|
+
$stream.Dispose()
|
|
252
|
+
}
|
|
253
|
+
$actualSha256 = -join ($digest | ForEach-Object { $_.ToString("x2") })
|
|
254
|
+
if ($actualSha256 -ne $ZukeSha256) {
|
|
255
|
+
throw "zuke: checksum mismatch for \${asset}: expected $ZukeSha256, got $actualSha256"
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
259
|
+
[System.IO.Compression.ZipFile]::ExtractToDirectory($archive, (Join-Path $workDir "unpacked"))
|
|
260
|
+
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $zuke) | Out-Null
|
|
261
|
+
# Copied beside the target first, which may cross volumes, then renamed in
|
|
262
|
+
# one step, so a run interrupted mid-copy never leaves a binary behind
|
|
263
|
+
# that later runs would trust without verifying.
|
|
264
|
+
$staged = "$zuke.$PID"
|
|
265
|
+
Move-Item -Force -Path (Join-Path $workDir "unpacked\\zuke.exe") -Destination $staged
|
|
266
|
+
try {
|
|
267
|
+
Move-Item -Force -Path $staged -Destination $zuke
|
|
268
|
+
} catch {
|
|
269
|
+
# A run started alongside this one put it there first, and may be
|
|
270
|
+
# running it, which Windows will not let this replace.
|
|
271
|
+
Remove-Item -Force $staged -ErrorAction SilentlyContinue
|
|
272
|
+
if (-not (Test-Path $zuke)) { throw }
|
|
273
|
+
}
|
|
274
|
+
} finally {
|
|
275
|
+
Remove-Item -Recurse -Force $workDir -ErrorAction SilentlyContinue
|
|
276
|
+
}
|
|
277
|
+
}`;
|
|
278
|
+
}
|
|
279
|
+
/** The PowerShell launcher's plain resolution: the `zuke` on `PATH`, or fail. */
|
|
280
|
+
function pwshPlain() {
|
|
281
|
+
return `$found = Get-Command zuke -CommandType Application -ErrorAction SilentlyContinue
|
|
282
|
+
if (-not $found) {
|
|
283
|
+
throw "zuke: the zuke command is not on PATH. Install it, then re-run this launcher: ${BINARY_INSTALL_DOCS}"
|
|
284
|
+
}
|
|
285
|
+
$zuke = $found.Source`;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* The PowerShell launcher (`.\zuke.ps1`) of a hosted build. Mirrors
|
|
289
|
+
* {@link binaryLauncherBash}, variant for variant.
|
|
290
|
+
*/
|
|
291
|
+
export function binaryLauncherPwsh(options, pin) {
|
|
292
|
+
const purpose = options.download
|
|
293
|
+
? `# Runs zuke ${pin.version}, which carries the engine and every tool wrapper, so
|
|
294
|
+
# this project needs nothing installed but its own SDK's tools. On first use
|
|
295
|
+
# it downloads that release, checksum-verified, into ZUKE_INSTALL.
|
|
296
|
+
#
|
|
297
|
+
# Honoured environment variables:
|
|
298
|
+
# ZUKE_INSTALL where zuke releases are kept (default: ~/.zuke)
|
|
299
|
+
# ZUKE_RELEASES_URL a mirror of ${BINARY_RELEASES_URL};
|
|
300
|
+
# what it serves is verified against the pin below`
|
|
301
|
+
: `${PLAIN_BINARY_LAUNCHER} ${BINARY_INSTALL_DOCS}`;
|
|
302
|
+
const resolve = options.download ? pwshDownload(pin) : pwshPlain();
|
|
303
|
+
return `#!/usr/bin/env pwsh
|
|
304
|
+
${LICENSE_HEADER}
|
|
305
|
+
#
|
|
306
|
+
${BINARY_LAUNCHER_MARKER} (PowerShell).
|
|
307
|
+
#
|
|
308
|
+
${usage(".\\zuke.ps1")}
|
|
309
|
+
#
|
|
310
|
+
${purpose}
|
|
311
|
+
|
|
312
|
+
$ErrorActionPreference = "Stop"
|
|
313
|
+
|
|
314
|
+
$dir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
315
|
+
Set-Location $dir
|
|
316
|
+
|
|
317
|
+
${resolve}
|
|
318
|
+
|
|
319
|
+
# zuke runs the build here itself rather than this launcher again, and does not
|
|
320
|
+
# hold this directory to the trust gate: running the launcher named it.
|
|
321
|
+
$env:${FORWARDED_ENV} = "1"
|
|
322
|
+
$env:${LAUNCHER_ROOT_ENV} = $dir
|
|
323
|
+
& $zuke @args
|
|
324
|
+
exit $LASTEXITCODE
|
|
325
|
+
`;
|
|
326
|
+
}
|
|
327
|
+
/* cspell:enable */
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** The repository the `zuke` releases are published from. */
|
|
2
|
+
export declare const BINARY_REPO = "zuke-build/zuke";
|
|
3
|
+
/** Where the launchers download a release's archives from, before the tag. */
|
|
4
|
+
export declare const BINARY_RELEASES_URL = "https://github.com/zuke-build/zuke/releases/download";
|
|
5
|
+
/** Where to get `zuke`, as the launchers and refusals name it. */
|
|
6
|
+
export declare const BINARY_INSTALL_DOCS = "https://github.com/zuke-build/zuke/blob/master/docs/install.md";
|
|
7
|
+
/** The checksum manifest each release publishes beside its archives. */
|
|
8
|
+
export declare const BINARY_CHECKSUMS = "SHA256SUMS";
|
|
9
|
+
/** A platform a `zuke` release ships a binary for, as its archive names it. */
|
|
10
|
+
export type BinaryTarget = "aarch64-apple-darwin" | "x86_64-apple-darwin" | "aarch64-unknown-linux-gnu" | "x86_64-unknown-linux-gnu" | "x86_64-pc-windows-msvc";
|
|
11
|
+
/** The targets the bash launcher can download (Linux and macOS), each a `.tar.gz`. */
|
|
12
|
+
export declare const BINARY_POSIX_TARGETS: readonly BinaryTarget[];
|
|
13
|
+
/** The target the PowerShell launcher downloads, a `.zip` holding `zuke.exe`. */
|
|
14
|
+
export declare const BINARY_WINDOWS_TARGET: BinaryTarget;
|
|
15
|
+
/** The pinned `zuke` release, the engine inside it, and each archive's digest. */
|
|
16
|
+
export interface BinaryPin {
|
|
17
|
+
/** The release, without the tag's `cli-v` prefix, e.g. `"2.4.0"`. */
|
|
18
|
+
readonly version: string;
|
|
19
|
+
/** The `@zuke/engine` release compiled into it. */
|
|
20
|
+
readonly engine: string;
|
|
21
|
+
/** Lowercase hex SHA-256 of each target's archive. */
|
|
22
|
+
readonly checksums: Readonly<Record<BinaryTarget, string>>;
|
|
23
|
+
}
|
|
24
|
+
/** The release tag of a `zuke` version: `cli-v2.4.0`. */
|
|
25
|
+
export declare function binaryReleaseTag(version: string): string;
|
|
26
|
+
/** The archive a target's binary ships in: `zuke-2.4.0-x86_64-unknown-linux-gnu.tar.gz`. */
|
|
27
|
+
export declare function binaryArchiveName(version: string, target: BinaryTarget): string;
|
|
28
|
+
/** What resolving a pin reaches over the network, injectable for tests. */
|
|
29
|
+
export type PinFetch = (url: string) => Promise<Response>;
|
|
30
|
+
/**
|
|
31
|
+
* The digests a `SHA256SUMS` manifest lists, by file name.
|
|
32
|
+
*
|
|
33
|
+
* Strict, since what it reads is pinned into launchers and formulas: a line
|
|
34
|
+
* that is not a digest and a name, or a name listed twice, is refused rather
|
|
35
|
+
* than skipped or overwritten.
|
|
36
|
+
*
|
|
37
|
+
* @throws {Error} naming the first line that is not one, or a repeated name.
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseChecksums(text: string): Map<string, string>;
|
|
40
|
+
/**
|
|
41
|
+
* Resolve the pin of `zuke` `version`: every target's archive digest from
|
|
42
|
+
* the release's `SHA256SUMS`, and its engine from the tag's
|
|
43
|
+
* `packages/engine/deno.json`.
|
|
44
|
+
* @throws {Error} when the release has no published binaries, lists no digest
|
|
45
|
+
* for a target, or its engine version cannot be read.
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveBinaryPin(version: string, fetch: PinFetch): Promise<BinaryPin>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The standalone `zuke` release a project another SDK hosts runs on, and the
|
|
5
|
+
* SHA-256 of each platform's archive its launchers verify the download
|
|
6
|
+
* against.
|
|
7
|
+
*
|
|
8
|
+
* Such a project has no Deno code, so its launchers bootstrap no Deno: they
|
|
9
|
+
* download the pinned `zuke` binary from its GitHub release, which carries
|
|
10
|
+
* the engine and every tool wrapper. The pin is read once, when `zuke setup`
|
|
11
|
+
* scaffolds the launchers or `zuke upgrade --engine` moves them: the
|
|
12
|
+
* archives' digests from the release's own `SHA256SUMS`, and the engine the
|
|
13
|
+
* release carries from `packages/engine/deno.json` at its tag. A published
|
|
14
|
+
* release is immutable, so the digests the launchers hold stay the release's.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import { isRecord } from "./records.js";
|
|
19
|
+
import { VERSION_PATTERN } from "./version_report.js";
|
|
20
|
+
/** The repository the `zuke` releases are published from. */
|
|
21
|
+
export const BINARY_REPO = "zuke-build/zuke";
|
|
22
|
+
/** Where the launchers download a release's archives from, before the tag. */
|
|
23
|
+
export const BINARY_RELEASES_URL = `https://github.com/${BINARY_REPO}/releases/download`;
|
|
24
|
+
/** Where to get `zuke`, as the launchers and refusals name it. */
|
|
25
|
+
export const BINARY_INSTALL_DOCS = "https://github.com/zuke-build/zuke/blob/master/docs/install.md";
|
|
26
|
+
/** The checksum manifest each release publishes beside its archives. */
|
|
27
|
+
export const BINARY_CHECKSUMS = "SHA256SUMS";
|
|
28
|
+
/** The targets the bash launcher can download (Linux and macOS), each a `.tar.gz`. */
|
|
29
|
+
export const BINARY_POSIX_TARGETS = [
|
|
30
|
+
"aarch64-apple-darwin",
|
|
31
|
+
"x86_64-apple-darwin",
|
|
32
|
+
"aarch64-unknown-linux-gnu",
|
|
33
|
+
"x86_64-unknown-linux-gnu",
|
|
34
|
+
];
|
|
35
|
+
/** The target the PowerShell launcher downloads, a `.zip` holding `zuke.exe`. */
|
|
36
|
+
export const BINARY_WINDOWS_TARGET = "x86_64-pc-windows-msvc";
|
|
37
|
+
/** The release tag of a `zuke` version: `cli-v2.4.0`. */
|
|
38
|
+
export function binaryReleaseTag(version) {
|
|
39
|
+
return `cli-v${version}`;
|
|
40
|
+
}
|
|
41
|
+
/** The archive a target's binary ships in: `zuke-2.4.0-x86_64-unknown-linux-gnu.tar.gz`. */
|
|
42
|
+
export function binaryArchiveName(version, target) {
|
|
43
|
+
const extension = target === BINARY_WINDOWS_TARGET ? "zip" : "tar.gz";
|
|
44
|
+
return `zuke-${version}-${target}.${extension}`;
|
|
45
|
+
}
|
|
46
|
+
/** A line of a manifest: a digest, two spaces (or a space and `*`), a name. */
|
|
47
|
+
const CHECKSUM_LINE = /^([0-9a-f]{64}) [ *]([^\s/\\]+)$/;
|
|
48
|
+
/**
|
|
49
|
+
* The digests a `SHA256SUMS` manifest lists, by file name.
|
|
50
|
+
*
|
|
51
|
+
* Strict, since what it reads is pinned into launchers and formulas: a line
|
|
52
|
+
* that is not a digest and a name, or a name listed twice, is refused rather
|
|
53
|
+
* than skipped or overwritten.
|
|
54
|
+
*
|
|
55
|
+
* @throws {Error} naming the first line that is not one, or a repeated name.
|
|
56
|
+
*/
|
|
57
|
+
export function parseChecksums(text) {
|
|
58
|
+
const sums = new Map();
|
|
59
|
+
for (const line of text.split("\n")) {
|
|
60
|
+
if (line === "")
|
|
61
|
+
continue;
|
|
62
|
+
const match = CHECKSUM_LINE.exec(line);
|
|
63
|
+
if (match === null) {
|
|
64
|
+
throw new Error(`${BINARY_CHECKSUMS}: not a checksum line: ${JSON.stringify(line)}`);
|
|
65
|
+
}
|
|
66
|
+
const [, sha256, name] = match;
|
|
67
|
+
if (sums.has(name)) {
|
|
68
|
+
throw new Error(`${BINARY_CHECKSUMS}: ${name} is listed twice`);
|
|
69
|
+
}
|
|
70
|
+
sums.set(name, sha256);
|
|
71
|
+
}
|
|
72
|
+
return sums;
|
|
73
|
+
}
|
|
74
|
+
/** The text at `url`, or a message naming what was missing. */
|
|
75
|
+
async function fetchText(fetch, url, what) {
|
|
76
|
+
const response = await fetch(url);
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
await response.body?.cancel();
|
|
79
|
+
throw new Error(`${what} could not be read from ${url} (HTTP ${response.status})`);
|
|
80
|
+
}
|
|
81
|
+
return await response.text();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Resolve the pin of `zuke` `version`: every target's archive digest from
|
|
85
|
+
* the release's `SHA256SUMS`, and its engine from the tag's
|
|
86
|
+
* `packages/engine/deno.json`.
|
|
87
|
+
* @throws {Error} when the release has no published binaries, lists no digest
|
|
88
|
+
* for a target, or its engine version cannot be read.
|
|
89
|
+
*/
|
|
90
|
+
export async function resolveBinaryPin(version, fetch) {
|
|
91
|
+
if (!VERSION_PATTERN.test(version)) {
|
|
92
|
+
throw new Error(`"${version}" is not a zuke release such as 2.4.0`);
|
|
93
|
+
}
|
|
94
|
+
const tag = binaryReleaseTag(version);
|
|
95
|
+
const sums = parseChecksums(await fetchText(fetch, `${BINARY_RELEASES_URL}/${tag}/${BINARY_CHECKSUMS}`, `zuke ${version}'s published binaries`));
|
|
96
|
+
const digest = (target) => {
|
|
97
|
+
const name = binaryArchiveName(version, target);
|
|
98
|
+
const sha256 = sums.get(name);
|
|
99
|
+
if (sha256 === undefined) {
|
|
100
|
+
throw new Error(`zuke ${version}'s ${BINARY_CHECKSUMS} lists no digest for ${name}`);
|
|
101
|
+
}
|
|
102
|
+
return sha256;
|
|
103
|
+
};
|
|
104
|
+
const checksums = {
|
|
105
|
+
"aarch64-apple-darwin": digest("aarch64-apple-darwin"),
|
|
106
|
+
"x86_64-apple-darwin": digest("x86_64-apple-darwin"),
|
|
107
|
+
"aarch64-unknown-linux-gnu": digest("aarch64-unknown-linux-gnu"),
|
|
108
|
+
"x86_64-unknown-linux-gnu": digest("x86_64-unknown-linux-gnu"),
|
|
109
|
+
"x86_64-pc-windows-msvc": digest("x86_64-pc-windows-msvc"),
|
|
110
|
+
};
|
|
111
|
+
const config = JSON.parse(await fetchText(fetch, `https://raw.githubusercontent.com/${BINARY_REPO}/${tag}/packages/engine/deno.json`, `the @zuke/engine release inside zuke ${version}`));
|
|
112
|
+
const engine = isRecord(config) ? config.version : undefined;
|
|
113
|
+
if (typeof engine !== "string" || !VERSION_PATTERN.test(engine)) {
|
|
114
|
+
throw new Error(`zuke ${version}'s packages/engine/deno.json names no engine version`);
|
|
115
|
+
}
|
|
116
|
+
return { version, engine, checksums };
|
|
117
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The build file of a project whose `zuke.json` names none. */
|
|
2
|
+
export declare const BUILD_FILE = "zuke.ts";
|
|
3
|
+
/** The build file `zuke setup` gives a new project, recorded in its `zuke.json`. */
|
|
4
|
+
export declare const NEW_BUILD_FILE = "build.ts";
|
|
5
|
+
/** The field of `zuke.json` naming the build file. */
|
|
6
|
+
export declare const BUILD_FIELD = "build";
|
|
7
|
+
/**
|
|
8
|
+
* `name`, when it is a build file name that is safe to write into a launcher
|
|
9
|
+
* and pass to `deno run`.
|
|
10
|
+
*
|
|
11
|
+
* @throws {Error} naming the two places a name comes from, and the rule,
|
|
12
|
+
* otherwise.
|
|
13
|
+
*/
|
|
14
|
+
export declare function assertBuildFileName(name: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* The build file a `zuke.json` with the contents `text` names.
|
|
17
|
+
*
|
|
18
|
+
* {@link BUILD_FILE} when the file has no `build` field, and also when it is
|
|
19
|
+
* not a JSON object: the file's presence alone marked a project before the
|
|
20
|
+
* field existed, so an empty or malformed one still means `zuke.ts`.
|
|
21
|
+
*
|
|
22
|
+
* @throws {Error} when the field is there and is not a valid name, see
|
|
23
|
+
* {@link assertBuildFileName}.
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildFileNamed(text: string): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The name of a project's build file: `zuke.ts` unless the `build` field of
|
|
5
|
+
* its `zuke.json` names another.
|
|
6
|
+
*
|
|
7
|
+
* The name is written into a shell script, a PowerShell script and JSON, and
|
|
8
|
+
* handed to `deno run`, so one check decides what a name may be and every
|
|
9
|
+
* place that reads or writes it goes through it.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { isRecord } from "./records.js";
|
|
14
|
+
/** The build file of a project whose `zuke.json` names none. */
|
|
15
|
+
export const BUILD_FILE = "zuke.ts";
|
|
16
|
+
/** The build file `zuke setup` gives a new project, recorded in its `zuke.json`. */
|
|
17
|
+
export const NEW_BUILD_FILE = "build.ts";
|
|
18
|
+
/** The field of `zuke.json` naming the build file. */
|
|
19
|
+
export const BUILD_FIELD = "build";
|
|
20
|
+
/**
|
|
21
|
+
* A plain file name: letters, digits, dots, dashes and underscores, no
|
|
22
|
+
* leading dash (it would read as an option), ending in `.ts`.
|
|
23
|
+
*/
|
|
24
|
+
const BUILD_FILE_NAME = /^[A-Za-z0-9_.][A-Za-z0-9_.-]*\.ts$/;
|
|
25
|
+
/**
|
|
26
|
+
* `name`, when it is a build file name that is safe to write into a launcher
|
|
27
|
+
* and pass to `deno run`.
|
|
28
|
+
*
|
|
29
|
+
* @throws {Error} naming the two places a name comes from, and the rule,
|
|
30
|
+
* otherwise.
|
|
31
|
+
*/
|
|
32
|
+
export function assertBuildFileName(name) {
|
|
33
|
+
if (!BUILD_FILE_NAME.test(name)) {
|
|
34
|
+
throw new Error(`zuke: the build file name '${name}' (zuke.json's '${BUILD_FIELD}', ` +
|
|
35
|
+
"or --build-file) is not a plain TypeScript file name: letters, " +
|
|
36
|
+
"digits, dots, dashes and underscores only, not starting with a " +
|
|
37
|
+
"dash, ending in .ts");
|
|
38
|
+
}
|
|
39
|
+
return name;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The build file a `zuke.json` with the contents `text` names.
|
|
43
|
+
*
|
|
44
|
+
* {@link BUILD_FILE} when the file has no `build` field, and also when it is
|
|
45
|
+
* not a JSON object: the file's presence alone marked a project before the
|
|
46
|
+
* field existed, so an empty or malformed one still means `zuke.ts`.
|
|
47
|
+
*
|
|
48
|
+
* @throws {Error} when the field is there and is not a valid name, see
|
|
49
|
+
* {@link assertBuildFileName}.
|
|
50
|
+
*/
|
|
51
|
+
export function buildFileNamed(text) {
|
|
52
|
+
let config;
|
|
53
|
+
try {
|
|
54
|
+
config = JSON.parse(text);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return BUILD_FILE;
|
|
58
|
+
}
|
|
59
|
+
if (!isRecord(config) || !(BUILD_FIELD in config))
|
|
60
|
+
return BUILD_FILE;
|
|
61
|
+
const name = config[BUILD_FIELD];
|
|
62
|
+
// Anything but a string is refused as written: String() would turn the
|
|
63
|
+
// array ["build.ts"] into a name that passes.
|
|
64
|
+
return assertBuildFileName(typeof name === "string" ? name : JSON.stringify(name));
|
|
65
|
+
}
|