@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
package/src/upgrade.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type BinaryPin } from "./binary_pin.ts";
|
|
2
|
+
import type { CliPaint } from "./paint.ts";
|
|
3
|
+
import { type InstallHost } from "./install_source.ts";
|
|
4
|
+
/** The CLI's JSR package, whose releases are the `zuke` releases. */
|
|
5
|
+
export declare const CLI_PACKAGE = "@zuke/cli";
|
|
6
|
+
/**
|
|
7
|
+
* What `zuke upgrade` reaches outside the process, injectable so the
|
|
8
|
+
* command is testable without the network or a real reinstall.
|
|
9
|
+
*/
|
|
10
|
+
export interface UpgradeHost extends InstallHost {
|
|
11
|
+
/**
|
|
12
|
+
* The directory `deno install -g` installs into (`<root>/bin`):
|
|
13
|
+
* `DENO_INSTALL_ROOT`, else `~/.deno`, as Deno resolves it. `undefined`
|
|
14
|
+
* when the environment names neither as an absolute path.
|
|
15
|
+
*/
|
|
16
|
+
binDir(): string | undefined;
|
|
17
|
+
/** Whether `path` exists. */
|
|
18
|
+
exists(path: string): Promise<boolean>;
|
|
19
|
+
/** Whether this is Windows, where the running shim is a `.cmd` file. */
|
|
20
|
+
windows(): boolean;
|
|
21
|
+
/** Fetch and parse `@zuke/cli`'s JSR `meta.json`. */
|
|
22
|
+
meta(): Promise<unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the pin of `zuke` release `version`, which `zuke setup --sdk`
|
|
25
|
+
* scaffolds a hosted build's launchers with and `zuke upgrade --engine`
|
|
26
|
+
* moves them to: its archives' digests and the engine it carries.
|
|
27
|
+
*/
|
|
28
|
+
binaryPin(version: string): Promise<BinaryPin>;
|
|
29
|
+
/** Run `deno <denoArgs>` to reinstall, returning its exit code. */
|
|
30
|
+
install(denoArgs: string[]): Promise<number>;
|
|
31
|
+
/**
|
|
32
|
+
* The version of the Deno that runs the reinstall: the one running this
|
|
33
|
+
* CLI, since `zuke upgrade` only ever runs from a JSR install under Deno.
|
|
34
|
+
*/
|
|
35
|
+
denoVersion(): string;
|
|
36
|
+
/** Read a text file, rejecting when it cannot be read. */
|
|
37
|
+
readText(path: string): Promise<string>;
|
|
38
|
+
}
|
|
39
|
+
/** The real {@link UpgradeHost}: `Deno.mainModule`, JSR, and `deno install`. */
|
|
40
|
+
export declare const defaultUpgradeHost: UpgradeHost;
|
|
41
|
+
/** Flags accepted by `zuke upgrade`. */
|
|
42
|
+
export interface UpgradeFlags {
|
|
43
|
+
/** The exact release to install. When unset, the registry's latest. */
|
|
44
|
+
version?: string;
|
|
45
|
+
/** Report what would be installed, and install nothing. */
|
|
46
|
+
dryRun: boolean;
|
|
47
|
+
/** Reinstall even when the target is the running version. */
|
|
48
|
+
force: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Parse the argument list following `zuke upgrade`.
|
|
52
|
+
*
|
|
53
|
+
* This is stricter than `setup`'s parser: this command replaces the installed
|
|
54
|
+
* executable, so a typo of `--dry-run` must stop it rather than be ignored on
|
|
55
|
+
* the way to a real reinstall.
|
|
56
|
+
*
|
|
57
|
+
* @throws {Error} on an unknown flag, a second version, or a malformed one.
|
|
58
|
+
*/
|
|
59
|
+
export declare function parseUpgradeFlags(args: string[]): UpgradeFlags;
|
|
60
|
+
/**
|
|
61
|
+
* The release of `pkg` that `version` asks for, or its latest when none is
|
|
62
|
+
* named, checked against the registry's `meta`. Errors open with `command`,
|
|
63
|
+
* the `zuke` command asking.
|
|
64
|
+
*
|
|
65
|
+
* @throws {Error} when the document has no latest, or the requested version
|
|
66
|
+
* is unpublished or yanked.
|
|
67
|
+
*/
|
|
68
|
+
export declare function resolveRelease(meta: unknown, version: string | undefined, pkg: string, command: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* `meta` read through `read`, with a failure to reach the registry reported
|
|
71
|
+
* as the `zuke` `command`'s own error.
|
|
72
|
+
*/
|
|
73
|
+
export declare function registryMeta(read: () => Promise<unknown>, pkg: string, command: string): Promise<unknown>;
|
|
74
|
+
/**
|
|
75
|
+
* Whether the reinstall passes `--minimum-dependency-age=0` on Deno
|
|
76
|
+
* `version`: 2.6.0 and later. The flag arrived during 2.5 (2.5.0 rejects it
|
|
77
|
+
* as an unknown argument, which fails the whole install), and no Deno before
|
|
78
|
+
* 2.9 applies a default age, so gating on a whole minor that has it loses
|
|
79
|
+
* nothing.
|
|
80
|
+
*/
|
|
81
|
+
export declare function acceptsMinimumDependencyAge(version: string): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Whether `deno install -g` on Deno `version` writes the lock beside the shim
|
|
84
|
+
* (`<root>/bin/.zuke/deno.lock`): 2.7.0 and later. An older Deno installs a
|
|
85
|
+
* `--no-config` shim and leaves any lock a newer Deno wrote untouched, so
|
|
86
|
+
* that lock says nothing about what it just installed and is not checked.
|
|
87
|
+
*/
|
|
88
|
+
export declare function writesInstallLock(version: string): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* The `deno install` argv that reinstalls the global command at `target`.
|
|
91
|
+
* When `target` is the latest release, the specifier is unversioned (see the
|
|
92
|
+
* module docs for why the shim must not change).
|
|
93
|
+
*
|
|
94
|
+
* On a Deno that has one, the minimum dependency age is turned off. Deno 2.9
|
|
95
|
+
* applies a cooling-off window to registry resolution, which skips releases
|
|
96
|
+
* from the last few days: an unversioned install then resolves to an older
|
|
97
|
+
* release, and a pinned one fails to resolve at all. Upgrading is an explicit
|
|
98
|
+
* choice of a specific published release, so the window does not apply. The
|
|
99
|
+
* flag only steers resolution and is not written into the shim.
|
|
100
|
+
*
|
|
101
|
+
* `--no-config` keeps any discovered config out of the install, the isolated
|
|
102
|
+
* directory's own included (which would otherwise draw a "discovered config
|
|
103
|
+
* file will be ignored" warning); the install still writes its lock.
|
|
104
|
+
*/
|
|
105
|
+
export declare function installArgs(target: string, latest: boolean, denoVersion: string): string[];
|
|
106
|
+
/**
|
|
107
|
+
* Run `zuke upgrade <args>`, reporting through `log`, and return the exit
|
|
108
|
+
* code.
|
|
109
|
+
*
|
|
110
|
+
* @throws {Error} with a message for the user when the request cannot be
|
|
111
|
+
* carried out. `main` prints the message and exits 1.
|
|
112
|
+
*/
|
|
113
|
+
export declare function runUpgrade(args: string[], log: (line: string) => void, host: UpgradeHost, paint: CliPaint): Promise<number>;
|
package/src/upgrade.js
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* `zuke upgrade`: replace the globally installed CLI with another release
|
|
5
|
+
* from JSR.
|
|
6
|
+
*
|
|
7
|
+
* The CLI cannot drift forward by itself. Since Deno 2, `deno install -g`
|
|
8
|
+
* writes a lockfile beside the shim (`<root>/bin/.zuke/deno.lock`), which pins
|
|
9
|
+
* `jsr:@zuke/cli@*` to the version resolved on install day, so the installed
|
|
10
|
+
* `zuke` stays on that version until someone re-runs the install with
|
|
11
|
+
* `--force`. This command does that re-run.
|
|
12
|
+
*
|
|
13
|
+
* The reinstall keeps the shim byte-for-byte identical whenever it targets
|
|
14
|
+
* the latest release. It passes the same unversioned specifier as the
|
|
15
|
+
* documented install, plus `--reload` so Deno re-reads the registry's
|
|
16
|
+
* metadata, and only the lock moves. That matters on Windows, where the shim
|
|
17
|
+
* is a `.cmd` file and is rewritten *while it is executing*: `cmd.exe`
|
|
18
|
+
* resumes reading the batch file at its old byte offset once `deno` returns,
|
|
19
|
+
* so a longer file would run the tail of its new last line as a command. Only
|
|
20
|
+
* an explicit non-latest version pins a specifier into the shim, which grows
|
|
21
|
+
* the file, so on Windows that one case is refused with the command to run
|
|
22
|
+
* from another shell. Moving back to latest shrinks the file, which is safe.
|
|
23
|
+
*
|
|
24
|
+
* On Deno 2.6 and later the reinstall turns the minimum dependency age off
|
|
25
|
+
* (see {@link installArgs}), and on a Deno that writes the install lock (2.7
|
|
26
|
+
* and later) success is reported only once that lock resolves `@zuke/cli` to
|
|
27
|
+
* the release that was asked for: Deno exiting 0 means it installed *a*
|
|
28
|
+
* version, not necessarily that one.
|
|
29
|
+
*
|
|
30
|
+
* It only ever replaces an install that is there: the shim's own
|
|
31
|
+
* `<root>/bin/.zuke/deno.json` must exist, so a one-off
|
|
32
|
+
* `deno run jsr:@zuke/cli upgrade`, or an install under another `--root`,
|
|
33
|
+
* is told so instead of gaining a second `zuke` in the default root.
|
|
34
|
+
*
|
|
35
|
+
* The command and its flags mirror `deno upgrade` (`[VERSION]`, `--dry-run`,
|
|
36
|
+
* `--force`).
|
|
37
|
+
*
|
|
38
|
+
* @module
|
|
39
|
+
*/
|
|
40
|
+
import { absolutePath, FileTasks, httpJson, lockedJsrSpecifiers, RuntimeTasks, } from "@zuke/core";
|
|
41
|
+
import { resolveBinaryPin } from "./binary_pin.js";
|
|
42
|
+
import { runDenoIsolated } from "./deno_isolated.js";
|
|
43
|
+
import { VERSION_PATTERN } from "./version_report.js";
|
|
44
|
+
import { defaultDenoHost, firstSet } from "./deno_path.js";
|
|
45
|
+
import { VERSION } from "./version.js";
|
|
46
|
+
import { ZUKE_REPO_URL } from "./star.js";
|
|
47
|
+
import { installSource, JSR_PACKAGE as PACKAGE, } from "./install_source.js";
|
|
48
|
+
/** Where the compiled binaries are published. */
|
|
49
|
+
const RELEASES_URL = `${ZUKE_REPO_URL}/releases`;
|
|
50
|
+
/** The registry document listing every published version of `pkg` and the latest. */
|
|
51
|
+
function metaUrl(pkg) {
|
|
52
|
+
return `https://jsr.io/${pkg}/meta.json`;
|
|
53
|
+
}
|
|
54
|
+
/** The CLI's JSR package, whose releases are the `zuke` releases. */
|
|
55
|
+
export const CLI_PACKAGE = "@zuke/cli";
|
|
56
|
+
/** The real {@link UpgradeHost}: `Deno.mainModule`, JSR, and `deno install`. */
|
|
57
|
+
export const defaultUpgradeHost = {
|
|
58
|
+
standalone: () => RuntimeTasks.facts().standalone,
|
|
59
|
+
mainModule: () => RuntimeTasks.mainModule(),
|
|
60
|
+
execPath: () => RuntimeTasks.execPath(),
|
|
61
|
+
realPath: (path) => FileTasks.realPath(path),
|
|
62
|
+
binDir: () => {
|
|
63
|
+
const explicit = firstSet(defaultDenoHost, "DENO_INSTALL_ROOT");
|
|
64
|
+
const home = firstSet(defaultDenoHost, "HOME", "USERPROFILE");
|
|
65
|
+
try {
|
|
66
|
+
if (explicit !== undefined)
|
|
67
|
+
return absolutePath(explicit)("bin").path;
|
|
68
|
+
if (home !== undefined)
|
|
69
|
+
return absolutePath(home)(".deno", "bin").path;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// A relative value names no directory to look in.
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
},
|
|
76
|
+
exists: async (path) => {
|
|
77
|
+
try {
|
|
78
|
+
await FileTasks.stat(path);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
windows: () => defaultDenoHost.windows(),
|
|
86
|
+
meta: () => httpJson(metaUrl(CLI_PACKAGE)),
|
|
87
|
+
binaryPin: (version) => resolveBinaryPin(version, fetch),
|
|
88
|
+
install: (denoArgs) => runDenoIsolated(denoArgs, "zuke-upgrade-"),
|
|
89
|
+
// The cli runs on Deno, so the runtime is the Deno that runs the command.
|
|
90
|
+
denoVersion: () => RuntimeTasks.facts().version,
|
|
91
|
+
readText: (path) => FileTasks.readText(path),
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Parse the argument list following `zuke upgrade`.
|
|
95
|
+
*
|
|
96
|
+
* This is stricter than `setup`'s parser: this command replaces the installed
|
|
97
|
+
* executable, so a typo of `--dry-run` must stop it rather than be ignored on
|
|
98
|
+
* the way to a real reinstall.
|
|
99
|
+
*
|
|
100
|
+
* @throws {Error} on an unknown flag, a second version, or a malformed one.
|
|
101
|
+
*/
|
|
102
|
+
export function parseUpgradeFlags(args) {
|
|
103
|
+
const flags = { dryRun: false, force: false };
|
|
104
|
+
for (const arg of args) {
|
|
105
|
+
if (arg === "--dry-run") {
|
|
106
|
+
flags.dryRun = true;
|
|
107
|
+
}
|
|
108
|
+
else if (arg === "--force" || arg === "-f") {
|
|
109
|
+
flags.force = true;
|
|
110
|
+
}
|
|
111
|
+
else if (arg.startsWith("-")) {
|
|
112
|
+
throw new Error(`zuke upgrade: unknown option ${arg}. Usage: zuke upgrade ` +
|
|
113
|
+
"[<version>] [--dry-run] [--force]");
|
|
114
|
+
}
|
|
115
|
+
else if (flags.version !== undefined) {
|
|
116
|
+
throw new Error(`zuke upgrade: name one version, not ${flags.version} and ${arg}.`);
|
|
117
|
+
}
|
|
118
|
+
else if (!VERSION_PATTERN.test(arg)) {
|
|
119
|
+
throw new Error(`zuke upgrade: "${arg}" is not a version — name a release such as ` +
|
|
120
|
+
"1.8.0.");
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
flags.version = arg;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return flags;
|
|
127
|
+
}
|
|
128
|
+
/** A field of a parsed JSON value, or `undefined` when it is not an object. */
|
|
129
|
+
function field(value, name) {
|
|
130
|
+
return value !== null && typeof value === "object"
|
|
131
|
+
? Reflect.get(value, name)
|
|
132
|
+
: undefined;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The release of `pkg` that `version` asks for, or its latest when none is
|
|
136
|
+
* named, checked against the registry's `meta`. Errors open with `command`,
|
|
137
|
+
* the `zuke` command asking.
|
|
138
|
+
*
|
|
139
|
+
* @throws {Error} when the document has no latest, or the requested version
|
|
140
|
+
* is unpublished or yanked.
|
|
141
|
+
*/
|
|
142
|
+
export function resolveRelease(meta, version, pkg, command) {
|
|
143
|
+
const latest = field(meta, "latest");
|
|
144
|
+
if (typeof latest !== "string") {
|
|
145
|
+
throw new Error(`${command}: JSR's metadata for ${pkg} names no latest version.`);
|
|
146
|
+
}
|
|
147
|
+
if (version === undefined)
|
|
148
|
+
return latest;
|
|
149
|
+
const entry = field(field(meta, "versions"), version);
|
|
150
|
+
if (entry === null || typeof entry !== "object") {
|
|
151
|
+
throw new Error(`${command}: ${pkg} ${version} is not published on JSR ` +
|
|
152
|
+
`(latest is ${latest}).`);
|
|
153
|
+
}
|
|
154
|
+
if (field(entry, "yanked") === true) {
|
|
155
|
+
throw new Error(`${command}: ${pkg} ${version} has been yanked from JSR ` +
|
|
156
|
+
`(latest is ${latest}).`);
|
|
157
|
+
}
|
|
158
|
+
return version;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* `meta` read through `read`, with a failure to reach the registry reported
|
|
162
|
+
* as the `zuke` `command`'s own error.
|
|
163
|
+
*/
|
|
164
|
+
export async function registryMeta(read, pkg, command) {
|
|
165
|
+
try {
|
|
166
|
+
return await read();
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
throw new Error(`${command}: could not read ${pkg}'s versions from JSR: ` +
|
|
170
|
+
(error instanceof Error ? error.message : String(error)));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Whether Deno `version` is 2.`minor` or later. A version this cannot read is
|
|
175
|
+
* treated as older: each caller gates something that misbehaves on a Deno
|
|
176
|
+
* that lacks it.
|
|
177
|
+
*/
|
|
178
|
+
function denoAtLeast(version, minor) {
|
|
179
|
+
const match = /^(\d+)\.(\d+)\./.exec(version);
|
|
180
|
+
if (match === null)
|
|
181
|
+
return false;
|
|
182
|
+
const major = Number(match[1]);
|
|
183
|
+
return major > 2 || (major === 2 && Number(match[2]) >= minor);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Whether the reinstall passes `--minimum-dependency-age=0` on Deno
|
|
187
|
+
* `version`: 2.6.0 and later. The flag arrived during 2.5 (2.5.0 rejects it
|
|
188
|
+
* as an unknown argument, which fails the whole install), and no Deno before
|
|
189
|
+
* 2.9 applies a default age, so gating on a whole minor that has it loses
|
|
190
|
+
* nothing.
|
|
191
|
+
*/
|
|
192
|
+
export function acceptsMinimumDependencyAge(version) {
|
|
193
|
+
return denoAtLeast(version, 6);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Whether `deno install -g` on Deno `version` writes the lock beside the shim
|
|
197
|
+
* (`<root>/bin/.zuke/deno.lock`): 2.7.0 and later. An older Deno installs a
|
|
198
|
+
* `--no-config` shim and leaves any lock a newer Deno wrote untouched, so
|
|
199
|
+
* that lock says nothing about what it just installed and is not checked.
|
|
200
|
+
*/
|
|
201
|
+
export function writesInstallLock(version) {
|
|
202
|
+
return denoAtLeast(version, 7);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The `deno install` argv that reinstalls the global command at `target`.
|
|
206
|
+
* When `target` is the latest release, the specifier is unversioned (see the
|
|
207
|
+
* module docs for why the shim must not change).
|
|
208
|
+
*
|
|
209
|
+
* On a Deno that has one, the minimum dependency age is turned off. Deno 2.9
|
|
210
|
+
* applies a cooling-off window to registry resolution, which skips releases
|
|
211
|
+
* from the last few days: an unversioned install then resolves to an older
|
|
212
|
+
* release, and a pinned one fails to resolve at all. Upgrading is an explicit
|
|
213
|
+
* choice of a specific published release, so the window does not apply. The
|
|
214
|
+
* flag only steers resolution and is not written into the shim.
|
|
215
|
+
*
|
|
216
|
+
* `--no-config` keeps any discovered config out of the install, the isolated
|
|
217
|
+
* directory's own included (which would otherwise draw a "discovered config
|
|
218
|
+
* file will be ignored" warning); the install still writes its lock.
|
|
219
|
+
*/
|
|
220
|
+
export function installArgs(target, latest, denoVersion) {
|
|
221
|
+
const args = ["install", "--global", "--force", "--allow-all", "--no-config"];
|
|
222
|
+
if (acceptsMinimumDependencyAge(denoVersion)) {
|
|
223
|
+
args.push("--minimum-dependency-age=0");
|
|
224
|
+
}
|
|
225
|
+
args.push("--name", "zuke");
|
|
226
|
+
if (latest)
|
|
227
|
+
return [...args, `--reload=${PACKAGE}`, PACKAGE];
|
|
228
|
+
return [...args, `${PACKAGE}@${target}`];
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* The version the install's lock resolves `spec` to (the specifier the
|
|
232
|
+
* install was given), or `undefined` when the lock cannot be read or does not
|
|
233
|
+
* name it: what was actually installed, whatever was asked for. The exact
|
|
234
|
+
* specifier is matched, so another `@zuke/cli` entry in the lock cannot stand
|
|
235
|
+
* in for it.
|
|
236
|
+
*/
|
|
237
|
+
async function installedVersion(host, lockPath, spec) {
|
|
238
|
+
let text;
|
|
239
|
+
try {
|
|
240
|
+
text = await host.readText(lockPath);
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
// Deno records an unversioned specifier as the `*` range.
|
|
246
|
+
const key = spec === PACKAGE ? `${PACKAGE}@*` : spec;
|
|
247
|
+
return lockedJsrSpecifiers(text).find((entry) => entry.specifier === key)
|
|
248
|
+
?.resolved;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Run `zuke upgrade <args>`, reporting through `log`, and return the exit
|
|
252
|
+
* code.
|
|
253
|
+
*
|
|
254
|
+
* @throws {Error} with a message for the user when the request cannot be
|
|
255
|
+
* carried out. `main` prints the message and exits 1.
|
|
256
|
+
*/
|
|
257
|
+
export async function runUpgrade(args, log, host, paint) {
|
|
258
|
+
const flags = parseUpgradeFlags(args);
|
|
259
|
+
// Anything but a JSR install is refused: reinstalling from JSR would put a
|
|
260
|
+
// different executable on PATH and leave this one, the one actually
|
|
261
|
+
// running, exactly as it was. A compiled binary is classified before its
|
|
262
|
+
// main module is read, because one compiled from JSR still reports
|
|
263
|
+
// `jsr:@zuke/cli` and would otherwise upgrade a second, unrelated install.
|
|
264
|
+
const source = await installSource(host);
|
|
265
|
+
if (source.kind === "homebrew") {
|
|
266
|
+
throw new Error(`zuke upgrade: this zuke was installed with Homebrew ` +
|
|
267
|
+
`(${source.location}), so reinstalling from JSR would not update ` +
|
|
268
|
+
"it. Update it with: brew upgrade zuke");
|
|
269
|
+
}
|
|
270
|
+
if (source.kind === "chocolatey") {
|
|
271
|
+
throw new Error(`zuke upgrade: this zuke was installed with Chocolatey ` +
|
|
272
|
+
`(${source.location}), so reinstalling from JSR would not update ` +
|
|
273
|
+
"it. Update it with: choco upgrade zuke");
|
|
274
|
+
}
|
|
275
|
+
if (source.kind === "binary") {
|
|
276
|
+
throw new Error(`zuke upgrade: this zuke is a standalone binary (${source.location}), ` +
|
|
277
|
+
"so reinstalling from JSR would not update it. Replace it with the " +
|
|
278
|
+
`binary from ${RELEASES_URL}, or install with Homebrew (brew install ` +
|
|
279
|
+
"zuke-build/tap/zuke), with Chocolatey (choco install zuke) or from " +
|
|
280
|
+
`JSR (deno install -A -g -n zuke ${PACKAGE}).`);
|
|
281
|
+
}
|
|
282
|
+
if (source.kind === "npm") {
|
|
283
|
+
log("This zuke was installed from npm. Update it with: " +
|
|
284
|
+
"npm install -g @zuke-build/cli@latest");
|
|
285
|
+
return 0;
|
|
286
|
+
}
|
|
287
|
+
if (source.kind === "source") {
|
|
288
|
+
throw new Error(`zuke upgrade: this zuke runs ${source.location}, not ${PACKAGE}, so ` +
|
|
289
|
+
"reinstalling from JSR would not update it. Update it where it came " +
|
|
290
|
+
"from.");
|
|
291
|
+
}
|
|
292
|
+
const binDir = host.binDir();
|
|
293
|
+
const marker = binDir === undefined
|
|
294
|
+
? undefined
|
|
295
|
+
: absolutePath(binDir)(".zuke", "deno.json").path;
|
|
296
|
+
if (marker === undefined || !(await host.exists(marker))) {
|
|
297
|
+
throw new Error("zuke upgrade: found no global install of zuke to replace" +
|
|
298
|
+
(marker === undefined
|
|
299
|
+
? " (neither DENO_INSTALL_ROOT nor a home directory is set)"
|
|
300
|
+
: ` (no ${marker})`) +
|
|
301
|
+
". Install it with: deno install -A -g -n zuke " + PACKAGE);
|
|
302
|
+
}
|
|
303
|
+
const meta = await registryMeta(() => host.meta(), CLI_PACKAGE, "zuke upgrade");
|
|
304
|
+
const target = resolveRelease(meta, flags.version, CLI_PACKAGE, "zuke upgrade");
|
|
305
|
+
if (target === VERSION && !flags.force) {
|
|
306
|
+
log(paint.ok(`zuke ${VERSION} is already ${flags.version === undefined ? "the latest release" : "installed"}. Pass --force to reinstall it.`));
|
|
307
|
+
return 0;
|
|
308
|
+
}
|
|
309
|
+
const latest = target === field(meta, "latest");
|
|
310
|
+
const denoArgs = installArgs(target, latest, host.denoVersion());
|
|
311
|
+
if (!latest && host.windows()) {
|
|
312
|
+
throw new Error(`zuke upgrade: on Windows, installing ${target} would rewrite the ` +
|
|
313
|
+
"zuke.cmd running this command into a longer file, and cmd.exe " +
|
|
314
|
+
"would then run a fragment of it. Run this from another shell " +
|
|
315
|
+
`instead: deno ${denoArgs.join(" ")}`);
|
|
316
|
+
}
|
|
317
|
+
if (flags.dryRun) {
|
|
318
|
+
log(`Would replace zuke ${VERSION} with ${target}: deno ${denoArgs.join(" ")}`);
|
|
319
|
+
return 0;
|
|
320
|
+
}
|
|
321
|
+
log(`Replacing zuke ${VERSION} with ${target}…`);
|
|
322
|
+
const code = await host.install(denoArgs);
|
|
323
|
+
if (code !== 0) {
|
|
324
|
+
// Not "still on the old version": a forced install that failed part-way
|
|
325
|
+
// may have replaced some of it, and Deno's own output above says how far.
|
|
326
|
+
log(paint.fail(`zuke upgrade: deno install exited ${code}; see its output above.`));
|
|
327
|
+
return code;
|
|
328
|
+
}
|
|
329
|
+
// A zero exit says Deno installed *something*. Confirm it is the target
|
|
330
|
+
// before saying so: a resolver that picks another release (Deno 2.9's
|
|
331
|
+
// dependency-age window did) would otherwise be reported as a success.
|
|
332
|
+
const deno = host.denoVersion();
|
|
333
|
+
const installed = writesInstallLock(deno)
|
|
334
|
+
? await installedVersion(host, absolutePath(marker).parent()("deno.lock").path, denoArgs[denoArgs.length - 1])
|
|
335
|
+
: target;
|
|
336
|
+
if (installed !== target) {
|
|
337
|
+
log(paint.fail(`zuke upgrade: deno install finished, but its lock resolves ` +
|
|
338
|
+
`@zuke/cli to ${installed ?? "nothing"}, not ${target}. ` +
|
|
339
|
+
"Check with: zuke --version"));
|
|
340
|
+
return 1;
|
|
341
|
+
}
|
|
342
|
+
log(paint.ok(`Done — zuke ${target} is installed. Check with: zuke --version`));
|
|
343
|
+
return 0;
|
|
344
|
+
}
|
package/src/version.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@zuke/cli` version. Kept in sync with deno.json by release-please.
|
|
3
|
+
*
|
|
4
|
+
* Annotated `string` for the reason `@zuke/core`'s copy is: an inferred
|
|
5
|
+
* literal type is what `deno doc` would record, and a generated doc that
|
|
6
|
+
* pins the version goes stale the moment release-please bumps the marked
|
|
7
|
+
* line. This constant is internal to the package today, so nothing generated
|
|
8
|
+
* reads it — the annotation is what keeps that from mattering if it is ever
|
|
9
|
+
* exported.
|
|
10
|
+
*/
|
|
11
|
+
export declare const VERSION: string;
|
package/src/version.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The `@zuke/cli` version. Kept in sync with deno.json by release-please.
|
|
5
|
+
*
|
|
6
|
+
* Annotated `string` for the reason `@zuke/core`'s copy is: an inferred
|
|
7
|
+
* literal type is what `deno doc` would record, and a generated doc that
|
|
8
|
+
* pins the version goes stale the moment release-please bumps the marked
|
|
9
|
+
* line. This constant is internal to the package today, so nothing generated
|
|
10
|
+
* reads it — the annotation is what keeps that from mattering if it is ever
|
|
11
|
+
* exported.
|
|
12
|
+
*/
|
|
13
|
+
export const VERSION = "2.7.0"; // x-release-please-version
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The text of the first of Deno's config files at `root` that can be read, in
|
|
3
|
+
* the order Deno prefers them (`deno.json`, then `deno.jsonc`), or
|
|
4
|
+
* `undefined` when there is none: the input {@link projectLockPath} takes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function projectConfigText(readText: (path: string) => Promise<string>, root: string): Promise<string | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* The lockfile the project at `root` resolves through, from the text of its
|
|
9
|
+
* config (the first of `DENO_CONFIG_FILES` that exists, or `undefined` when
|
|
10
|
+
* there is none), or `null` when no lock can be read for it.
|
|
11
|
+
*
|
|
12
|
+
* It follows Deno's `lock` setting:
|
|
13
|
+
* - `false` disables the lock, and Deno then ignores any `deno.lock` left
|
|
14
|
+
* behind, so reading that file would report a version the build does not
|
|
15
|
+
* run. That is `null`.
|
|
16
|
+
* - A string, or an object's `path`, names the lockfile, relative to `root`
|
|
17
|
+
* unless it is absolute.
|
|
18
|
+
* - No setting, `true`, or an object without a `path` keeps `deno.lock`.
|
|
19
|
+
*
|
|
20
|
+
* Comments and trailing commas are read as Deno reads them. A config that is
|
|
21
|
+
* still not valid is a setting this cannot read, so it is also `null` rather
|
|
22
|
+
* than a guess; the caller then asks the build, as it does for a project with
|
|
23
|
+
* no lock.
|
|
24
|
+
*/
|
|
25
|
+
export declare function projectLockPath(root: string, configText: string | undefined): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* A release version: a numeric core with an optional prerelease and build.
|
|
28
|
+
* `zuke upgrade` checks the version it is asked for against it, and a lock's
|
|
29
|
+
* resolved core version must match it before it is printed.
|
|
30
|
+
*/
|
|
31
|
+
export declare const VERSION_PATTERN: RegExp;
|
|
32
|
+
/**
|
|
33
|
+
* The `@zuke/core` versions a lock resolves, from its text: one entry per
|
|
34
|
+
* distinct version (a lock normally holds one, but several ranges can each
|
|
35
|
+
* resolve their own), in the order the lock lists them. Empty when the lock
|
|
36
|
+
* names no core, or is not a lock this can read.
|
|
37
|
+
*
|
|
38
|
+
* A resolved value that is not a release version is dropped rather than
|
|
39
|
+
* printed. The lock is the project's own file, and a value carrying a newline
|
|
40
|
+
* or a terminal escape sequence would otherwise reach the terminal as written,
|
|
41
|
+
* from a command that promises only to report a number.
|
|
42
|
+
*/
|
|
43
|
+
export declare function lockedCoreVersions(lockText: string): string[];
|
|
44
|
+
/**
|
|
45
|
+
* `path` with the home directory written `~`, for display: a project path is
|
|
46
|
+
* usually under home, and the prefix is the least informative part of it.
|
|
47
|
+
* Only a whole leading directory is replaced, so `/home/me2` stays as it is
|
|
48
|
+
* under `/home/me`.
|
|
49
|
+
*
|
|
50
|
+
* `path` is an {@link absolutePath} one (forward slashes, also on Windows), so
|
|
51
|
+
* `home` is normalised the same way before comparing, and compared without
|
|
52
|
+
* regard to case on Windows, whose paths are case-insensitive. A `home` that
|
|
53
|
+
* is not absolute names no prefix to strip.
|
|
54
|
+
*/
|
|
55
|
+
export declare function homeRelative(path: string, home: string | undefined, windows: boolean): string;
|