@zuke-build/cli 2.6.0 → 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/README.md +11 -1
- package/mod.d.ts +3 -0
- package/mod.js +39 -1
- package/package.json +1 -1
- package/src/binary_launcher.js +1 -3
- package/src/build_file.js +3 -10
- package/src/dispatch.d.ts +10 -1
- package/src/dispatch.js +12 -1
- package/src/launcher.js +3 -62
- package/src/launcher_shared.d.ts +25 -0
- package/src/launcher_shared.js +91 -0
- package/src/mcp_config.d.ts +8 -0
- package/src/mcp_config.js +10 -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/records.d.ts +12 -3
- package/src/records.js +21 -3
- package/src/runtime_field.d.ts +15 -0
- package/src/runtime_field.js +29 -0
- package/src/setup.d.ts +8 -0
- package/src/setup.js +121 -29
- package/src/starter.d.ts +11 -2
- package/src/starter.js +15 -3
- package/src/version.js +1 -1
|
@@ -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/records.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
* `.mcp.json`)
|
|
4
|
-
*
|
|
2
|
+
* The JSON-shape guards the scaffolder's file merges share (`deno.json`,
|
|
3
|
+
* `.mcp.json`), and the one forgiving read of a `zuke.json` field that the
|
|
4
|
+
* readers of its `build` and `runtime` fields share. Kept apart from all of
|
|
5
|
+
* them so none has to import another for it.
|
|
5
6
|
*
|
|
6
7
|
* @module
|
|
7
8
|
*/
|
|
8
9
|
/** Whether `value` is a plain object (a JSON object, not an array or null). */
|
|
9
10
|
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* Field `field` of the JSON object `text`, or `undefined` when there is no such
|
|
13
|
+
* field, and also when `text` is not JSON or not an object: a `zuke.json`'s
|
|
14
|
+
* presence alone marked a project before its fields existed, so an empty or
|
|
15
|
+
* malformed one means every field's default. Each field's reader decides
|
|
16
|
+
* whether the value it gets is valid.
|
|
17
|
+
*/
|
|
18
|
+
export declare function forgivingField(text: string, field: string): unknown;
|
package/src/records.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Copyright (c) 2026 the Zuke contributors
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
/**
|
|
4
|
-
* The
|
|
5
|
-
* `.mcp.json`)
|
|
6
|
-
*
|
|
4
|
+
* The JSON-shape guards the scaffolder's file merges share (`deno.json`,
|
|
5
|
+
* `.mcp.json`), and the one forgiving read of a `zuke.json` field that the
|
|
6
|
+
* readers of its `build` and `runtime` fields share. Kept apart from all of
|
|
7
|
+
* them so none has to import another for it.
|
|
7
8
|
*
|
|
8
9
|
* @module
|
|
9
10
|
*/
|
|
@@ -11,3 +12,20 @@
|
|
|
11
12
|
export function isRecord(value) {
|
|
12
13
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Field `field` of the JSON object `text`, or `undefined` when there is no such
|
|
17
|
+
* field, and also when `text` is not JSON or not an object: a `zuke.json`'s
|
|
18
|
+
* presence alone marked a project before its fields existed, so an empty or
|
|
19
|
+
* malformed one means every field's default. Each field's reader decides
|
|
20
|
+
* whether the value it gets is valid.
|
|
21
|
+
*/
|
|
22
|
+
export function forgivingField(text, field) {
|
|
23
|
+
let config;
|
|
24
|
+
try {
|
|
25
|
+
config = JSON.parse(text);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return isRecord(config) ? config[field] : undefined;
|
|
31
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The field of `zuke.json` naming the runtime the build file runs on. */
|
|
2
|
+
export declare const RUNTIME_FIELD = "runtime";
|
|
3
|
+
/** A runtime a project's build file can run on. */
|
|
4
|
+
export type ProjectRuntime = "deno" | "node";
|
|
5
|
+
/** The runtime of a project whose `zuke.json` names none. */
|
|
6
|
+
export declare const DEFAULT_RUNTIME: ProjectRuntime;
|
|
7
|
+
/**
|
|
8
|
+
* The runtime a `zuke.json` with the contents `text` names: its `runtime`
|
|
9
|
+
* field, {@link DEFAULT_RUNTIME} when there is none or the file is not a JSON
|
|
10
|
+
* object (as for the build file's name, the file's presence alone marked a
|
|
11
|
+
* project before the field existed).
|
|
12
|
+
*
|
|
13
|
+
* @throws {Error} when the field is there and names no runtime Zuke runs on.
|
|
14
|
+
*/
|
|
15
|
+
export declare function runtimeNamed(text: string): ProjectRuntime;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The runtime a project's build file runs on: Deno unless the `runtime`
|
|
5
|
+
* field of its `zuke.json` names Node.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { forgivingField } from "./records.js";
|
|
10
|
+
/** The field of `zuke.json` naming the runtime the build file runs on. */
|
|
11
|
+
export const RUNTIME_FIELD = "runtime";
|
|
12
|
+
/** The runtime of a project whose `zuke.json` names none. */
|
|
13
|
+
export const DEFAULT_RUNTIME = "deno";
|
|
14
|
+
/**
|
|
15
|
+
* The runtime a `zuke.json` with the contents `text` names: its `runtime`
|
|
16
|
+
* field, {@link DEFAULT_RUNTIME} when there is none or the file is not a JSON
|
|
17
|
+
* object (as for the build file's name, the file's presence alone marked a
|
|
18
|
+
* project before the field existed).
|
|
19
|
+
*
|
|
20
|
+
* @throws {Error} when the field is there and names no runtime Zuke runs on.
|
|
21
|
+
*/
|
|
22
|
+
export function runtimeNamed(text) {
|
|
23
|
+
const runtime = forgivingField(text, RUNTIME_FIELD);
|
|
24
|
+
if (runtime === undefined)
|
|
25
|
+
return DEFAULT_RUNTIME;
|
|
26
|
+
if (runtime === "deno" || runtime === "node")
|
|
27
|
+
return runtime;
|
|
28
|
+
throw new Error(`zuke: zuke.json's '${RUNTIME_FIELD}' is ${JSON.stringify(runtime)}; it names the runtime the build file runs on, "deno" or "node".`);
|
|
29
|
+
}
|
package/src/setup.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isRecord } from "./records.ts";
|
|
2
|
+
import type { ProjectRuntime } from "./runtime_field.ts";
|
|
2
3
|
import type { BinaryPin } from "./binary_pin.ts";
|
|
3
4
|
export { isRecord };
|
|
4
5
|
/**
|
|
@@ -177,6 +178,13 @@ export interface SetupOptions {
|
|
|
177
178
|
* nothing in the project needs Deno. Omitted: a TypeScript build.
|
|
178
179
|
*/
|
|
179
180
|
sdk?: SdkSetupOptions;
|
|
181
|
+
/**
|
|
182
|
+
* The runtime the build file runs on (`--runtime`): `"node"` scaffolds a
|
|
183
|
+
* `package.json` in place of `deno.json`, a `zuke.json` with
|
|
184
|
+
* `"runtime": "node"` and launchers that bootstrap Node. Omitted or
|
|
185
|
+
* `"deno"`: today's Deno project. Not with {@link SetupOptions.sdk}.
|
|
186
|
+
*/
|
|
187
|
+
runtime?: ProjectRuntime;
|
|
180
188
|
}
|
|
181
189
|
/** What `--sdk python` scaffolds against. */
|
|
182
190
|
export interface SdkSetupOptions {
|