@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,416 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The `./zuke` (bash) and `zuke.ps1` (PowerShell) launchers of a project whose
|
|
5
|
+
* build runs on Node, so a checkout with no Node installed can run
|
|
6
|
+
* `./zuke <target>`. Each uses, in order: a `node` on `PATH` whose major
|
|
7
|
+
* version is at least the pin's ({@link "./node_pin.ts"}); the copy cached
|
|
8
|
+
* under `ZUKE_NODE_HOME` (default `~/.zuke/node`), one directory per release;
|
|
9
|
+
* or the pinned release downloaded from nodejs.org, verified against its
|
|
10
|
+
* SHA-256 and unpacked there. `NODE_VERSION` overrides the release and must
|
|
11
|
+
* come with `NODE_SHA256`: nothing unverified is ever installed.
|
|
12
|
+
*
|
|
13
|
+
* The chosen node's directory goes first on `PATH`, so the `npm` the build runs
|
|
14
|
+
* is that node's. Dependencies are installed with `--ignore-scripts` before the
|
|
15
|
+
* build starts: `npm ci` when `package-lock.json` is newer than the last
|
|
16
|
+
* successful install (or there is none), `npm install` when there is a
|
|
17
|
+
* `package.json` and no lockfile. The launcher is a Node project's own; it names no other stack.
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import { assertBuildFileName, BUILD_FILE } from "./build_file.js";
|
|
22
|
+
import { bashFetchVerified, LICENSE_HEADER, pwshFetchVerified, } from "./launcher_shared.js";
|
|
23
|
+
import { NODE_DIST_URL, NODE_PIN, NODE_POSIX_PLATFORMS, NODE_WINDOWS_PLATFORMS, } from "./node_pin.js";
|
|
24
|
+
/** The pin's major version: the oldest `node` on `PATH` a launcher accepts. */
|
|
25
|
+
function majorOf(pin) {
|
|
26
|
+
return pin.version.split(".")[0];
|
|
27
|
+
}
|
|
28
|
+
/** The `NODE_VERSION` / `NODE_SHA256` / `ZUKE_NODE_HOME` contract, as the comment block both scripts carry. */
|
|
29
|
+
function envDocs(pin) {
|
|
30
|
+
return `# Honoured environment variables:
|
|
31
|
+
# ZUKE_NODE_HOME where Node is kept (default: ~/.zuke/node), one directory
|
|
32
|
+
# per release
|
|
33
|
+
# NODE_VERSION which Node to download, an exact release (e.g. ${pin.version}).
|
|
34
|
+
# Defaults to the pinned, verified ${pin.version}.
|
|
35
|
+
# NODE_SHA256 required alongside a NODE_VERSION override: the SHA-256 of
|
|
36
|
+
# the release asset for the current platform. This launcher
|
|
37
|
+
# never downloads an unverified binary.`;
|
|
38
|
+
}
|
|
39
|
+
/* cspell:disable */
|
|
40
|
+
/**
|
|
41
|
+
* The bash launcher (`./zuke`) of a Node project.
|
|
42
|
+
*
|
|
43
|
+
* @throws {Error} when the build file name is not a plain file name.
|
|
44
|
+
*/
|
|
45
|
+
export function nodeLauncherBash(options = {}, pin = NODE_PIN) {
|
|
46
|
+
const build = assertBuildFileName(options.buildFile ?? BUILD_FILE);
|
|
47
|
+
const arms = NODE_POSIX_PLATFORMS.map((platform) => ` ${platform})\n echo "${pin.checksums[platform]}" ;;`).join("\n");
|
|
48
|
+
return `#!/usr/bin/env bash
|
|
49
|
+
${LICENSE_HEADER}
|
|
50
|
+
#
|
|
51
|
+
# Zuke launcher for a build that runs on Node.
|
|
52
|
+
#
|
|
53
|
+
# ./zuke # run the default target
|
|
54
|
+
# ./zuke <target> # run one target and its prerequisites
|
|
55
|
+
# ./zuke --list # list every target
|
|
56
|
+
#
|
|
57
|
+
# Uses the node on PATH when it is Node ${majorOf(pin)} or newer, else a pinned,
|
|
58
|
+
# checksum-verified Node it downloads once, then installs the project's
|
|
59
|
+
# dependencies and runs ${build}.
|
|
60
|
+
#
|
|
61
|
+
${envDocs(pin)}
|
|
62
|
+
set -euo pipefail
|
|
63
|
+
|
|
64
|
+
DEFAULT_NODE_VERSION="${pin.version}"
|
|
65
|
+
MIN_NODE_MAJOR=${majorOf(pin)}
|
|
66
|
+
|
|
67
|
+
# SHA-256 of each \`node-v<version>-<platform>.tar.gz\` asset, from
|
|
68
|
+
# ${NODE_DIST_URL}/v${pin.version}/SHASUMS256.txt. Generated from @zuke/cli's
|
|
69
|
+
# node_pin.ts: change the pin there.
|
|
70
|
+
node_checksum_for() {
|
|
71
|
+
case "$1" in
|
|
72
|
+
${arms}
|
|
73
|
+
*)
|
|
74
|
+
return 1 ;;
|
|
75
|
+
esac
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
dir="$(cd "$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
|
|
79
|
+
cd "$dir"
|
|
80
|
+
|
|
81
|
+
node_version="\${NODE_VERSION:-$DEFAULT_NODE_VERSION}"
|
|
82
|
+
node_version="\${node_version#v}"
|
|
83
|
+
node_home="\${ZUKE_NODE_HOME:-$HOME/.zuke/node}/v$node_version"
|
|
84
|
+
|
|
85
|
+
# The major version of the node on PATH, empty when there is none or it cannot
|
|
86
|
+
# say (a version-manager shim with no runtime installed, say).
|
|
87
|
+
path_major=""
|
|
88
|
+
if command -v node >/dev/null 2>&1; then
|
|
89
|
+
path_major="$(node --version 2>/dev/null | sed -n 's/^v\\([0-9][0-9]*\\)\\..*/\\1/p')" || path_major=""
|
|
90
|
+
fi
|
|
91
|
+
|
|
92
|
+
if [ -n "$path_major" ] && [ "$path_major" -ge "$MIN_NODE_MAJOR" ]; then
|
|
93
|
+
node_dir="$(dirname "$(command -v node)")"
|
|
94
|
+
elif [ -x "$node_home/bin/node" ]; then
|
|
95
|
+
node_dir="$node_home/bin"
|
|
96
|
+
else
|
|
97
|
+
echo "zuke: Node $MIN_NODE_MAJOR or newer not found — installing $node_version now..." >&2
|
|
98
|
+
for cmd in curl tar; do
|
|
99
|
+
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
100
|
+
echo "zuke: $cmd is required to download Node; install Node $MIN_NODE_MAJOR or newer instead." >&2
|
|
101
|
+
exit 1
|
|
102
|
+
fi
|
|
103
|
+
done
|
|
104
|
+
|
|
105
|
+
case "$(uname -s)" in
|
|
106
|
+
Linux) os_part="linux" ;;
|
|
107
|
+
Darwin) os_part="darwin" ;;
|
|
108
|
+
*)
|
|
109
|
+
echo "zuke: unsupported OS for the checksum-verified Node download: $(uname -s)." >&2
|
|
110
|
+
exit 1
|
|
111
|
+
;;
|
|
112
|
+
esac
|
|
113
|
+
case "$(uname -m)" in
|
|
114
|
+
x86_64 | amd64) arch_part="x64" ;;
|
|
115
|
+
arm64 | aarch64) arch_part="arm64" ;;
|
|
116
|
+
*)
|
|
117
|
+
echo "zuke: unsupported architecture for the checksum-verified Node download: $(uname -m)." >&2
|
|
118
|
+
exit 1
|
|
119
|
+
;;
|
|
120
|
+
esac
|
|
121
|
+
platform="\${os_part}-\${arch_part}"
|
|
122
|
+
|
|
123
|
+
if [ "$node_version" = "$DEFAULT_NODE_VERSION" ]; then
|
|
124
|
+
expected_sha256="$(node_checksum_for "$platform")" || {
|
|
125
|
+
echo "zuke: no pinned checksum for $platform." >&2
|
|
126
|
+
exit 1
|
|
127
|
+
}
|
|
128
|
+
elif [ -n "\${NODE_SHA256:-}" ]; then
|
|
129
|
+
expected_sha256="$NODE_SHA256"
|
|
130
|
+
else
|
|
131
|
+
echo "zuke: NODE_VERSION=$node_version overrides the pinned $DEFAULT_NODE_VERSION," >&2
|
|
132
|
+
echo " but no checksum is pinned for it. Set NODE_SHA256 to the expected" >&2
|
|
133
|
+
echo " SHA-256 of node-v$node_version-$platform.tar.gz, or unset NODE_VERSION." >&2
|
|
134
|
+
exit 1
|
|
135
|
+
fi
|
|
136
|
+
|
|
137
|
+
asset="node-v\${node_version}-\${platform}.tar.gz"
|
|
138
|
+
download_url="${NODE_DIST_URL}/v\${node_version}/\${asset}"
|
|
139
|
+
${bashFetchVerified("Node")}
|
|
140
|
+
|
|
141
|
+
# Unpack into a sibling of the final directory, on the same filesystem, then
|
|
142
|
+
# rename it into place: the rename is atomic, so an interrupted run never
|
|
143
|
+
# leaves a half-extracted Node that looks installed.
|
|
144
|
+
node_root="$(dirname "$node_home")"
|
|
145
|
+
mkdir -p "$node_root"
|
|
146
|
+
staging="$(mktemp -d "$node_root/.v$node_version.XXXXXX")"
|
|
147
|
+
trap 'rm -rf "$work_dir" "$staging"' EXIT
|
|
148
|
+
tar -xzf "$archive" -C "$staging" --strip-components=1
|
|
149
|
+
# The rename publishes ours. If a concurrent launcher published first, mv
|
|
150
|
+
# either fails (their rename won the race) or nests ours inside theirs; we
|
|
151
|
+
# drop ours and use theirs. Nothing already at $node_home is ever deleted: it
|
|
152
|
+
# may be another run's Node.
|
|
153
|
+
mv "$staging" "$node_home" 2>/dev/null || true
|
|
154
|
+
rm -rf "$node_home/$(basename "$staging")"
|
|
155
|
+
# Here, not only in the trap: the exec below replaces this shell, so the
|
|
156
|
+
# EXIT trap never runs on success.
|
|
157
|
+
rm -rf "$staging" "$work_dir"
|
|
158
|
+
if [ ! -x "$node_home/bin/node" ]; then
|
|
159
|
+
echo "zuke: $node_home exists but holds no bin/node; remove it and run again." >&2
|
|
160
|
+
exit 1
|
|
161
|
+
fi
|
|
162
|
+
node_dir="$node_home/bin"
|
|
163
|
+
fi
|
|
164
|
+
|
|
165
|
+
# This node first on PATH, so the npm and npx the build runs are its own.
|
|
166
|
+
export PATH="$node_dir:$PATH"
|
|
167
|
+
|
|
168
|
+
# Written only after npm succeeds, so a failed install is retried next run.
|
|
169
|
+
installed=node_modules/.zuke-installed
|
|
170
|
+
|
|
171
|
+
# The npm command this checkout needs, or nothing when its install is current.
|
|
172
|
+
install_needed() {
|
|
173
|
+
if [ -f package-lock.json ]; then
|
|
174
|
+
if [ ! -f "$installed" ] || [ package-lock.json -nt "$installed" ]; then
|
|
175
|
+
echo ci
|
|
176
|
+
fi
|
|
177
|
+
elif [ -f package.json ] && [ ! -f "$installed" ]; then
|
|
178
|
+
echo install
|
|
179
|
+
fi
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if [ -n "$(install_needed)" ]; then
|
|
183
|
+
# One install at a time per checkout: a second launcher waits for the lock,
|
|
184
|
+
# then finds the first one's install current. The lock is created with
|
|
185
|
+
# noclobber, which fails when it exists, and holds its owner's process id. A
|
|
186
|
+
# lock whose owner is gone is reported, never removed: deciding that for
|
|
187
|
+
# another run is a guess two waiting runs could both act on.
|
|
188
|
+
lock=.zuke/install.lock
|
|
189
|
+
mkdir -p .zuke
|
|
190
|
+
waited=0
|
|
191
|
+
until (set -C; echo "$$" > "$lock") 2>/dev/null; do
|
|
192
|
+
holder="$(cat "$lock" 2>/dev/null || true)"
|
|
193
|
+
if [ -n "$holder" ] && ! kill -0 "$holder" 2>/dev/null; then
|
|
194
|
+
echo "zuke: $lock was left by an install that did not finish (process $holder); remove it and run again." >&2
|
|
195
|
+
exit 1
|
|
196
|
+
fi
|
|
197
|
+
if [ "$waited" -ge 600 ]; then
|
|
198
|
+
echo "zuke: another launcher has held $lock for 10 minutes; if none is running, remove it and run again." >&2
|
|
199
|
+
exit 1
|
|
200
|
+
fi
|
|
201
|
+
sleep 1
|
|
202
|
+
waited=$((waited + 1))
|
|
203
|
+
done
|
|
204
|
+
trap 'rm -f "$lock"' EXIT
|
|
205
|
+
case "$(install_needed)" in
|
|
206
|
+
ci)
|
|
207
|
+
rm -f "$installed"
|
|
208
|
+
npm ci --ignore-scripts
|
|
209
|
+
mkdir -p node_modules && : > "$installed"
|
|
210
|
+
;;
|
|
211
|
+
install)
|
|
212
|
+
echo "zuke: no package-lock.json here yet — running npm install so one can be written." >&2
|
|
213
|
+
npm install --ignore-scripts
|
|
214
|
+
mkdir -p node_modules && : > "$installed"
|
|
215
|
+
;;
|
|
216
|
+
esac
|
|
217
|
+
# Released here, because the exec below skips the EXIT trap.
|
|
218
|
+
rm -f "$lock"
|
|
219
|
+
trap - EXIT
|
|
220
|
+
fi
|
|
221
|
+
|
|
222
|
+
exec node ${build} "$@"
|
|
223
|
+
`;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* The PowerShell launcher (`.\zuke.ps1`) of a Node project, mirroring
|
|
227
|
+
* {@link nodeLauncherBash}.
|
|
228
|
+
*
|
|
229
|
+
* @throws {Error} when the build file name is not a plain file name.
|
|
230
|
+
*/
|
|
231
|
+
export function nodeLauncherPowerShell(options = {}, pin = NODE_PIN) {
|
|
232
|
+
const build = assertBuildFileName(options.buildFile ?? BUILD_FILE);
|
|
233
|
+
const width = Math.max(...NODE_WINDOWS_PLATFORMS.map((p) => p.length)) + 2;
|
|
234
|
+
const entries = NODE_WINDOWS_PLATFORMS.map((platform) => ` ${`"${platform}"`.padEnd(width)} = "${pin.checksums[platform]}"`).join("\n");
|
|
235
|
+
return `#!/usr/bin/env pwsh
|
|
236
|
+
${LICENSE_HEADER}
|
|
237
|
+
#
|
|
238
|
+
# Zuke launcher (PowerShell) for a build that runs on Node.
|
|
239
|
+
#
|
|
240
|
+
# .\\zuke.ps1 # run the default target
|
|
241
|
+
# .\\zuke.ps1 <target> # run one target and its prerequisites
|
|
242
|
+
# .\\zuke.ps1 --list # list every target
|
|
243
|
+
#
|
|
244
|
+
# Uses the node on PATH when it is Node ${majorOf(pin)} or newer, else a pinned,
|
|
245
|
+
# checksum-verified Node it downloads once, then installs the project's
|
|
246
|
+
# dependencies and runs ${build}.
|
|
247
|
+
#
|
|
248
|
+
${envDocs(pin)}
|
|
249
|
+
|
|
250
|
+
$ErrorActionPreference = "Stop"
|
|
251
|
+
|
|
252
|
+
$DefaultNodeVersion = "${pin.version}"
|
|
253
|
+
$MinNodeMajor = ${majorOf(pin)}
|
|
254
|
+
|
|
255
|
+
# SHA-256 of each \`node-v<version>-<platform>.zip\` asset, from
|
|
256
|
+
# ${NODE_DIST_URL}/v${pin.version}/SHASUMS256.txt. Generated from @zuke/cli's
|
|
257
|
+
# node_pin.ts: change the pin there.
|
|
258
|
+
$NodeChecksums = @{
|
|
259
|
+
${entries}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
$dir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
263
|
+
Set-Location $dir
|
|
264
|
+
|
|
265
|
+
$nodeVersion = if ($env:NODE_VERSION) { $env:NODE_VERSION } else { $DefaultNodeVersion }
|
|
266
|
+
$nodeVersion = $nodeVersion.TrimStart("v")
|
|
267
|
+
$nodeRoot = if ($env:ZUKE_NODE_HOME) { $env:ZUKE_NODE_HOME } else { Join-Path $HOME ".zuke\\node" }
|
|
268
|
+
$nodeHome = Join-Path $nodeRoot "v$nodeVersion"
|
|
269
|
+
|
|
270
|
+
function Resolve-Node {
|
|
271
|
+
$onPath = Get-Command node -CommandType Application -ErrorAction SilentlyContinue
|
|
272
|
+
if ($onPath) {
|
|
273
|
+
# A shim that cannot report a version is treated as no node at all.
|
|
274
|
+
$reported = ""
|
|
275
|
+
try { $reported = & $onPath.Source --version 2>$null } catch { }
|
|
276
|
+
if ($reported -match '^v(\\d+)\\.' -and [int]$Matches[1] -ge $MinNodeMajor) {
|
|
277
|
+
return $onPath.Source
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
$local = Join-Path $nodeHome "node.exe"
|
|
281
|
+
if (Test-Path $local) { return $local }
|
|
282
|
+
return $null
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
$node = Resolve-Node
|
|
286
|
+
if (-not $node) {
|
|
287
|
+
Write-Host "zuke: Node $MinNodeMajor or newer not found - installing $nodeVersion now..."
|
|
288
|
+
|
|
289
|
+
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()
|
|
290
|
+
$platform = switch ($arch) {
|
|
291
|
+
"X64" { "win-x64" }
|
|
292
|
+
"Arm64" { "win-arm64" }
|
|
293
|
+
default {
|
|
294
|
+
throw "zuke: unsupported architecture for the checksum-verified Node download: $arch."
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if ($nodeVersion -eq $DefaultNodeVersion -and $NodeChecksums.ContainsKey($platform)) {
|
|
299
|
+
$expectedSha256 = $NodeChecksums[$platform]
|
|
300
|
+
} elseif ($env:NODE_SHA256) {
|
|
301
|
+
$expectedSha256 = $env:NODE_SHA256
|
|
302
|
+
} else {
|
|
303
|
+
throw "zuke: NODE_VERSION=$nodeVersion overrides the pinned $DefaultNodeVersion, " +
|
|
304
|
+
"but no checksum is pinned for it. Set NODE_SHA256 to the expected SHA-256 " +
|
|
305
|
+
"of node-v$nodeVersion-$platform.zip, or unset NODE_VERSION."
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
$asset = "node-v$nodeVersion-$platform.zip"
|
|
309
|
+
$downloadUrl = "${NODE_DIST_URL}/v$nodeVersion/$asset"
|
|
310
|
+
$workDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid())
|
|
311
|
+
New-Item -ItemType Directory -Path $workDir | Out-Null
|
|
312
|
+
$archive = Join-Path $workDir $asset
|
|
313
|
+
$staging = $null
|
|
314
|
+
try {
|
|
315
|
+
${pwshFetchVerified("Node")}
|
|
316
|
+
|
|
317
|
+
# Unpack into a sibling of the final directory, on the same volume, then
|
|
318
|
+
# move the release folder into place: the move is a rename there, so an
|
|
319
|
+
# interrupted run never leaves a half-extracted Node that looks installed.
|
|
320
|
+
New-Item -ItemType Directory -Force -Path $nodeRoot | Out-Null
|
|
321
|
+
$staging = Join-Path $nodeRoot ".v$nodeVersion.$([System.Guid]::NewGuid())"
|
|
322
|
+
Expand-Archive -Path $archive -DestinationPath $staging -Force
|
|
323
|
+
$release = Get-ChildItem -Path $staging -Directory | Select-Object -First 1
|
|
324
|
+
# A name of its own, so a nested copy below is only ever this run's.
|
|
325
|
+
$release = Rename-Item -Path $release.FullName -NewName ([System.Guid]::NewGuid()) -PassThru
|
|
326
|
+
# The move publishes ours; if a concurrent launcher published first, ours
|
|
327
|
+
# is refused or nested inside theirs, and we drop it and use theirs.
|
|
328
|
+
# Nothing already at $nodeHome is ever deleted: it may be another run's Node.
|
|
329
|
+
try {
|
|
330
|
+
Move-Item -Path $release.FullName -Destination $nodeHome
|
|
331
|
+
} catch {
|
|
332
|
+
if (-not (Test-Path $nodeHome)) { throw }
|
|
333
|
+
}
|
|
334
|
+
$nested = Join-Path $nodeHome $release.Name
|
|
335
|
+
Remove-Item -Recurse -Force $nested -ErrorAction SilentlyContinue
|
|
336
|
+
if (-not (Test-Path (Join-Path $nodeHome "node.exe"))) {
|
|
337
|
+
throw "zuke: $nodeHome exists but holds no node.exe; remove it and run again."
|
|
338
|
+
}
|
|
339
|
+
} finally {
|
|
340
|
+
Remove-Item -Recurse -Force $workDir -ErrorAction SilentlyContinue
|
|
341
|
+
if ($staging) { Remove-Item -Recurse -Force $staging -ErrorAction SilentlyContinue }
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
$node = Join-Path $nodeHome "node.exe"
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
# This node first on PATH, so the npm and npx the build runs are its own.
|
|
348
|
+
$env:PATH = (Split-Path -Parent $node) + [IO.Path]::PathSeparator + $env:PATH
|
|
349
|
+
|
|
350
|
+
# Written only after npm succeeds, so a failed install is retried next run.
|
|
351
|
+
$installed = Join-Path "node_modules" ".zuke-installed"
|
|
352
|
+
|
|
353
|
+
# The npm command this checkout needs, or $null when its install is current.
|
|
354
|
+
function Get-InstallNeeded {
|
|
355
|
+
if (Test-Path "package-lock.json") {
|
|
356
|
+
if (-not (Test-Path $installed) -or
|
|
357
|
+
(Get-Item "package-lock.json").LastWriteTime -gt (Get-Item $installed).LastWriteTime) {
|
|
358
|
+
return "ci"
|
|
359
|
+
}
|
|
360
|
+
} elseif ((Test-Path "package.json") -and -not (Test-Path $installed)) {
|
|
361
|
+
return "install"
|
|
362
|
+
}
|
|
363
|
+
return $null
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (Get-InstallNeeded) {
|
|
367
|
+
# One install at a time per checkout: a second launcher waits for the lock,
|
|
368
|
+
# then finds the first one's install current. The lock is created with
|
|
369
|
+
# CreateNew, which fails when it exists, and holds its owner's process id. A
|
|
370
|
+
# lock whose owner is gone is reported, never removed: deciding that for
|
|
371
|
+
# another run is a guess two waiting runs could both act on.
|
|
372
|
+
New-Item -ItemType Directory -Force -Path (Join-Path $dir ".zuke") | Out-Null
|
|
373
|
+
$lock = Join-Path $dir ".zuke/install.lock"
|
|
374
|
+
$waited = 0
|
|
375
|
+
while ($true) {
|
|
376
|
+
try {
|
|
377
|
+
$stream = [System.IO.File]::Open($lock, [System.IO.FileMode]::CreateNew, [System.IO.FileAccess]::Write)
|
|
378
|
+
$bytes = [System.Text.Encoding]::ASCII.GetBytes("$PID")
|
|
379
|
+
$stream.Write($bytes, 0, $bytes.Length)
|
|
380
|
+
$stream.Close()
|
|
381
|
+
break
|
|
382
|
+
} catch {
|
|
383
|
+
$holder = 0
|
|
384
|
+
$text = Get-Content -Path $lock -Raw -ErrorAction SilentlyContinue
|
|
385
|
+
if ([int]::TryParse("$text".Trim(), [ref]$holder) -and
|
|
386
|
+
-not (Get-Process -Id $holder -ErrorAction SilentlyContinue)) {
|
|
387
|
+
throw "zuke: $lock was left by an install that did not finish (process $holder); remove it and run again."
|
|
388
|
+
}
|
|
389
|
+
if ($waited -ge 600) {
|
|
390
|
+
throw "zuke: another launcher has held $lock for 10 minutes; if none is running, remove it and run again."
|
|
391
|
+
}
|
|
392
|
+
Start-Sleep -Seconds 1
|
|
393
|
+
$waited++
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
try {
|
|
397
|
+
$install = Get-InstallNeeded
|
|
398
|
+
if ($install -eq "install") {
|
|
399
|
+
Write-Warning "zuke: no package-lock.json here yet - running npm install so one can be written."
|
|
400
|
+
}
|
|
401
|
+
if ($install) {
|
|
402
|
+
if (Test-Path $installed) { Remove-Item -Force $installed }
|
|
403
|
+
& npm $install --ignore-scripts
|
|
404
|
+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
|
405
|
+
New-Item -ItemType File -Force -Path $installed | Out-Null
|
|
406
|
+
}
|
|
407
|
+
} finally {
|
|
408
|
+
Remove-Item -Force $lock -ErrorAction SilentlyContinue
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
& $node (Join-Path $dir "${build}") @args
|
|
413
|
+
exit $LASTEXITCODE
|
|
414
|
+
`;
|
|
415
|
+
}
|
|
416
|
+
/* cspell:enable */
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Node.js release the Node launchers bootstrap, and the SHA-256 of each
|
|
3
|
+
* platform's official `nodejs.org` dist asset they verify it against. The one
|
|
4
|
+
* place the pin lives, as {@link "./deno_pin.ts"} is for Deno: bump the version
|
|
5
|
+
* and the checksums together, from `https://nodejs.org/dist/v<version>/SHASUMS256.txt`.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** A Node dist platform, as it appears in the asset name `node-v<version>-<platform>.<ext>`. */
|
|
10
|
+
export type NodePlatform = "darwin-arm64" | "darwin-x64" | "linux-arm64" | "linux-x64" | "win-arm64" | "win-x64";
|
|
11
|
+
/** The pinned Node release and the checksum of each platform's asset. */
|
|
12
|
+
export interface NodePin {
|
|
13
|
+
/** The release version without its `v` prefix, e.g. `"26.13.1"`. */
|
|
14
|
+
readonly version: string;
|
|
15
|
+
/** Lowercase hex SHA-256 of the dist asset for each supported platform. */
|
|
16
|
+
readonly checksums: Readonly<Record<NodePlatform, string>>;
|
|
17
|
+
}
|
|
18
|
+
/** The Node release the launchers bootstrap (Node 26, Active LTS), with its verified checksums. */
|
|
19
|
+
export declare const NODE_PIN: NodePin;
|
|
20
|
+
/** The platforms the POSIX launcher can bootstrap (`.tar.gz` assets). */
|
|
21
|
+
export declare const NODE_POSIX_PLATFORMS: readonly NodePlatform[];
|
|
22
|
+
/** The platforms the PowerShell launcher can bootstrap (`.zip` assets). */
|
|
23
|
+
export declare const NODE_WINDOWS_PLATFORMS: readonly NodePlatform[];
|
|
24
|
+
/** Where the dist assets are downloaded from; the launchers append `v<version>/<asset>`. */
|
|
25
|
+
export declare const NODE_DIST_URL = "https://nodejs.org/dist";
|
package/src/node_pin.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/* cspell:disable */
|
|
4
|
+
/** The Node release the launchers bootstrap (Node 26, Active LTS), with its verified checksums. */
|
|
5
|
+
export const NODE_PIN = {
|
|
6
|
+
version: "26.13.1",
|
|
7
|
+
checksums: {
|
|
8
|
+
"darwin-arm64": "aec2514ea1ceb2ba52455e9ec65986f6749a06dd759e5db2a72e6889668c9735",
|
|
9
|
+
"darwin-x64": "82bb96078a24ca50b9c9a38f2379e6be6d87171fcd400fc14c8934b3bce96e2f",
|
|
10
|
+
"linux-arm64": "80a330b35415382878df18d41afbd106ea89bfb3be0087d6608e289a14c5cc7d",
|
|
11
|
+
"linux-x64": "518674de2b621728a5e4486f5fb3b7d2900bb3cc4aa97969edaa463db99f9778",
|
|
12
|
+
"win-arm64": "181ebe431b90787113a9e4fc80d38ce86d37888a353a0386de44d2872e48cb97",
|
|
13
|
+
"win-x64": "e2edda75bfb089654705cf65a13b58933bfd5f57148e8ebda916f58a2474f1f7",
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
/* cspell:enable */
|
|
17
|
+
/** The platforms the POSIX launcher can bootstrap (`.tar.gz` assets). */
|
|
18
|
+
export const NODE_POSIX_PLATFORMS = [
|
|
19
|
+
"darwin-arm64",
|
|
20
|
+
"darwin-x64",
|
|
21
|
+
"linux-arm64",
|
|
22
|
+
"linux-x64",
|
|
23
|
+
];
|
|
24
|
+
/** The platforms the PowerShell launcher can bootstrap (`.zip` assets). */
|
|
25
|
+
export const NODE_WINDOWS_PLATFORMS = [
|
|
26
|
+
"win-arm64",
|
|
27
|
+
"win-x64",
|
|
28
|
+
];
|
|
29
|
+
/** Where the dist assets are downloaded from; the launchers append `v<version>/<asset>`. */
|
|
30
|
+
export const NODE_DIST_URL = "https://nodejs.org/dist";
|
package/src/output.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place `@zuke/cli` writes to the console.
|
|
3
|
+
*
|
|
4
|
+
* A GitHub Actions runner parses the job's output for workflow commands: a
|
|
5
|
+
* line whose first non-blank characters are `::` is executed (`::error::`
|
|
6
|
+
* forges an annotation, `::stop-commands::` silences every command that
|
|
7
|
+
* follows, including Zuke's own `::add-mask::`), and `##[` anywhere in a line
|
|
8
|
+
* is the legacy form. The CLI echoes text it did not author — an unknown
|
|
9
|
+
* command straight from argv, a `--dir` or `--from` the user typed, a path or
|
|
10
|
+
* an error message from the filesystem or a failed spawn, and what a
|
|
11
|
+
* subprocess it ran said — so every line goes out through here and is
|
|
12
|
+
* neutralised when something is parsing for commands. Off a runner nothing
|
|
13
|
+
* scans the stream and the line goes out byte for byte.
|
|
14
|
+
*
|
|
15
|
+
* The sink is `@zuke/core`'s own `cliReporter`, the one every core command
|
|
16
|
+
* writes through, so the escaping has exactly one implementation. It decides
|
|
17
|
+
* per line, not once at import, so an embedder or a test that sets the
|
|
18
|
+
* environment after loading this module is honoured.
|
|
19
|
+
*
|
|
20
|
+
* `tests/output_test.ts` scans this package's source and fails on any other
|
|
21
|
+
* console write, so the guard cannot quietly come undone by a new
|
|
22
|
+
* `console.log` elsewhere.
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import { type Reporter } from "@zuke/core";
|
|
27
|
+
/**
|
|
28
|
+
* `line` as it may reach an Actions runner: neutralised while one is parsing
|
|
29
|
+
* the output, untouched anywhere else — the same decision the sink makes,
|
|
30
|
+
* for the one write the sink cannot own: the text Deno's `prompt` puts on the
|
|
31
|
+
* terminal, which carries a default the user typed on the command line.
|
|
32
|
+
*/
|
|
33
|
+
export declare function neutralise(line: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* The CLI's console sink: `info` is stdout, `error` is stderr, and each line
|
|
36
|
+
* is neutralised on an Actions runner before it is written.
|
|
37
|
+
*/
|
|
38
|
+
export declare const output: Reporter;
|
package/src/output.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The one place `@zuke/cli` writes to the console.
|
|
5
|
+
*
|
|
6
|
+
* A GitHub Actions runner parses the job's output for workflow commands: a
|
|
7
|
+
* line whose first non-blank characters are `::` is executed (`::error::`
|
|
8
|
+
* forges an annotation, `::stop-commands::` silences every command that
|
|
9
|
+
* follows, including Zuke's own `::add-mask::`), and `##[` anywhere in a line
|
|
10
|
+
* is the legacy form. The CLI echoes text it did not author — an unknown
|
|
11
|
+
* command straight from argv, a `--dir` or `--from` the user typed, a path or
|
|
12
|
+
* an error message from the filesystem or a failed spawn, and what a
|
|
13
|
+
* subprocess it ran said — so every line goes out through here and is
|
|
14
|
+
* neutralised when something is parsing for commands. Off a runner nothing
|
|
15
|
+
* scans the stream and the line goes out byte for byte.
|
|
16
|
+
*
|
|
17
|
+
* The sink is `@zuke/core`'s own `cliReporter`, the one every core command
|
|
18
|
+
* writes through, so the escaping has exactly one implementation. It decides
|
|
19
|
+
* per line, not once at import, so an embedder or a test that sets the
|
|
20
|
+
* environment after loading this module is honoured.
|
|
21
|
+
*
|
|
22
|
+
* `tests/output_test.ts` scans this package's source and fails on any other
|
|
23
|
+
* console write, so the guard cannot quietly come undone by a new
|
|
24
|
+
* `console.log` elsewhere.
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
import { cliReporter, detectCiHost } from "@zuke/core";
|
|
29
|
+
import { escapeLineIf } from "@zuke/core/render";
|
|
30
|
+
/**
|
|
31
|
+
* `line` as it may reach an Actions runner: neutralised while one is parsing
|
|
32
|
+
* the output, untouched anywhere else — the same decision the sink makes,
|
|
33
|
+
* for the one write the sink cannot own: the text Deno's `prompt` puts on the
|
|
34
|
+
* terminal, which carries a default the user typed on the command line.
|
|
35
|
+
*/
|
|
36
|
+
export function neutralise(line) {
|
|
37
|
+
return escapeLineIf(detectCiHost() === "github", line);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The CLI's console sink: `info` is stdout, `error` is stderr, and each line
|
|
41
|
+
* is neutralised on an Actions runner before it is written.
|
|
42
|
+
*/
|
|
43
|
+
export const output = cliReporter;
|
package/src/paint.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the global CLI paints its own output: `--version`, `--help`, and the
|
|
3
|
+
* status lines `setup`, `import` and `upgrade` print.
|
|
4
|
+
*
|
|
5
|
+
* The palette is `@zuke/core`'s — the one the build's own CLI is painted with,
|
|
6
|
+
* exported from `@zuke/core/render` — so the two cannot drift apart. The CLI
|
|
7
|
+
* adds one fact the build's palette has no use for: whether to open with the
|
|
8
|
+
* logo, which `setup`, `import` and `--help` do.
|
|
9
|
+
*
|
|
10
|
+
* Whether to paint is `@zuke/core`'s {@link resolveOutputMode} — the same
|
|
11
|
+
* answer the build's own CLI and the executor get — so `ZUKE_PLAIN`, `--plain`,
|
|
12
|
+
* CI and a pipe mean the same thing here as in the build. Every method is the
|
|
13
|
+
* identity when output is not rich, which is what keeps the plain output
|
|
14
|
+
* exactly what it was before it had a rich form.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import { type OutputMode } from "@zuke/core";
|
|
19
|
+
import { type CliPaint as CorePaint } from "@zuke/core/render";
|
|
20
|
+
/** Core's palette, plus whether this command opens with the logo. */
|
|
21
|
+
export type CliPaint = CorePaint & {
|
|
22
|
+
/**
|
|
23
|
+
* Whether to open with the logo banner: off when plain output was asked for
|
|
24
|
+
* (`ZUKE_PLAIN` / `--plain`), which implies no banner, or when the banner
|
|
25
|
+
* itself was (`ZUKE_NO_BANNER`). A pipe or CI is not rich either, but nobody
|
|
26
|
+
* asked it to drop the banner.
|
|
27
|
+
*/
|
|
28
|
+
banner: boolean;
|
|
29
|
+
};
|
|
30
|
+
/** The identity palette: plain output, and every test's default. */
|
|
31
|
+
export declare const PLAIN_PAINT: CliPaint;
|
|
32
|
+
/**
|
|
33
|
+
* The palette for `mode`: core's, with `mode.banner` beside it. Colour follows
|
|
34
|
+
* `mode.color` on its own, so `NO_COLOR` keeps the glyphs and drops the escape
|
|
35
|
+
* codes.
|
|
36
|
+
*/
|
|
37
|
+
export declare function cliPaint(mode: OutputMode): CliPaint;
|
|
38
|
+
/**
|
|
39
|
+
* The palette for this invocation: an explicit `--plain`, else `ZUKE_PLAIN`,
|
|
40
|
+
* CI and whether stdout is a terminal, as {@link resolveOutputMode} reads them.
|
|
41
|
+
*/
|
|
42
|
+
export declare function invocationPaint(plain: boolean | undefined, isTerminal: (() => boolean) | undefined): CliPaint;
|
package/src/paint.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* How the global CLI paints its own output: `--version`, `--help`, and the
|
|
5
|
+
* status lines `setup`, `import` and `upgrade` print.
|
|
6
|
+
*
|
|
7
|
+
* The palette is `@zuke/core`'s — the one the build's own CLI is painted with,
|
|
8
|
+
* exported from `@zuke/core/render` — so the two cannot drift apart. The CLI
|
|
9
|
+
* adds one fact the build's palette has no use for: whether to open with the
|
|
10
|
+
* logo, which `setup`, `import` and `--help` do.
|
|
11
|
+
*
|
|
12
|
+
* Whether to paint is `@zuke/core`'s {@link resolveOutputMode} — the same
|
|
13
|
+
* answer the build's own CLI and the executor get — so `ZUKE_PLAIN`, `--plain`,
|
|
14
|
+
* CI and a pipe mean the same thing here as in the build. Every method is the
|
|
15
|
+
* identity when output is not rich, which is what keeps the plain output
|
|
16
|
+
* exactly what it was before it had a rich form.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import { resolveOutputMode } from "@zuke/core";
|
|
21
|
+
import { cliPaint as corePaint, PLAIN_PAINT as CORE_PLAIN, } from "@zuke/core/render";
|
|
22
|
+
/** The identity palette: plain output, and every test's default. */
|
|
23
|
+
export const PLAIN_PAINT = { ...CORE_PLAIN, banner: true };
|
|
24
|
+
/**
|
|
25
|
+
* The palette for `mode`: core's, with `mode.banner` beside it. Colour follows
|
|
26
|
+
* `mode.color` on its own, so `NO_COLOR` keeps the glyphs and drops the escape
|
|
27
|
+
* codes.
|
|
28
|
+
*/
|
|
29
|
+
export function cliPaint(mode) {
|
|
30
|
+
return { ...corePaint(mode), banner: mode.banner };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The palette for this invocation: an explicit `--plain`, else `ZUKE_PLAIN`,
|
|
34
|
+
* CI and whether stdout is a terminal, as {@link resolveOutputMode} reads them.
|
|
35
|
+
*/
|
|
36
|
+
export function invocationPaint(plain, isTerminal) {
|
|
37
|
+
return cliPaint(resolveOutputMode({ plain, isTerminal }));
|
|
38
|
+
}
|