@zuke-build/cli 2.6.0 → 2.8.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 +14 -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/cache.d.ts +4 -0
- package/src/cache.js +18 -2
- package/src/deno_isolated.js +1 -1
- package/src/deno_path.d.ts +1 -1
- package/src/deno_path.js +7 -2
- package/src/dependencies.d.ts +17 -0
- package/src/dependencies.js +60 -11
- package/src/dispatch.d.ts +10 -1
- package/src/dispatch.js +13 -2
- 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/npm_path.d.ts +16 -0
- package/src/npm_path.js +78 -0
- package/src/project.d.ts +14 -1
- package/src/project.js +21 -4
- package/src/records.d.ts +12 -3
- package/src/records.js +21 -3
- package/src/relock.js +116 -59
- 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 +126 -29
- package/src/starter.d.ts +11 -2
- package/src/starter.js +15 -3
- package/src/version.js +1 -1
package/src/npm_path.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* Finding the npm that changes a Node project's dependencies.
|
|
5
|
+
*
|
|
6
|
+
* `zuke add`, `remove`, `cache` and `relock` run npm in a project whose
|
|
7
|
+
* `zuke.json` says `"runtime": "node"`. The order mirrors the project's own
|
|
8
|
+
* launchers: whatever `PATH` resolves first, then the pinned Node they
|
|
9
|
+
* download into `ZUKE_NODE_HOME` (`~/.zuke/node` by default), so a project
|
|
10
|
+
* whose only Node is the one `./zuke` fetched still works. As in
|
|
11
|
+
* `deno_path.ts`, a candidate is tried by spawning it, which leaves `PATHEXT`
|
|
12
|
+
* (`npm.cmd` on Windows) to the OS.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
import { absolutePath, FileTasks, ProcessTasks } from "@zuke/core";
|
|
17
|
+
import { defaultDenoHost, firstSet, pathWithDeno, } from "./deno_path.js";
|
|
18
|
+
import { NODE_PIN } from "./node_pin.js";
|
|
19
|
+
/**
|
|
20
|
+
* The npm executables to try, in order: the bare name for `PATH`, then the
|
|
21
|
+
* one beside the pinned Node the launchers cache. That one is left out when
|
|
22
|
+
* the environment names no absolute directory to find it in.
|
|
23
|
+
*/
|
|
24
|
+
export function npmCandidates(host = defaultDenoHost) {
|
|
25
|
+
const candidates = ["npm"];
|
|
26
|
+
const explicit = firstSet(host, "ZUKE_NODE_HOME");
|
|
27
|
+
const home = firstSet(host, "HOME", "USERPROFILE");
|
|
28
|
+
try {
|
|
29
|
+
const root = explicit !== undefined
|
|
30
|
+
? absolutePath(explicit)
|
|
31
|
+
: home !== undefined
|
|
32
|
+
? absolutePath(home)(".zuke", "node")
|
|
33
|
+
: undefined;
|
|
34
|
+
if (root !== undefined) {
|
|
35
|
+
const release = root(`v${NODE_PIN.version}`);
|
|
36
|
+
candidates.push(host.windows() ? release("npm.cmd").path : release("bin", "npm").path);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// A relative ZUKE_NODE_HOME or HOME names no place to look.
|
|
41
|
+
}
|
|
42
|
+
return candidates;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Run `npm <args>` in `cwd` with the terminal's output, trying each candidate
|
|
46
|
+
* in order and skipping the ones that are not installed, and return its exit
|
|
47
|
+
* code. The cached npm runs with its Node first on `PATH`, which its script
|
|
48
|
+
* needs to start.
|
|
49
|
+
*
|
|
50
|
+
* @throws {Error} naming every candidate tried when none is installed.
|
|
51
|
+
*/
|
|
52
|
+
export async function runNpm(args, cwd, candidates = npmCandidates()) {
|
|
53
|
+
for (const command of candidates) {
|
|
54
|
+
// A path that is not there is skipped before spawning: Windows reports
|
|
55
|
+
// spawning one as an error that is not a plain "not found".
|
|
56
|
+
const isPath = command.includes("/") || command.includes("\\");
|
|
57
|
+
if (isPath && !(await FileTasks.exists(command)))
|
|
58
|
+
continue;
|
|
59
|
+
try {
|
|
60
|
+
const out = await ProcessTasks.run(command, (s) => {
|
|
61
|
+
s.args(...args).cwd(cwd).stdin("null").stdout("inherit")
|
|
62
|
+
.stderr("inherit");
|
|
63
|
+
for (const [name, value] of Object.entries(pathWithDeno(command))) {
|
|
64
|
+
s.env(name, value);
|
|
65
|
+
}
|
|
66
|
+
return s;
|
|
67
|
+
});
|
|
68
|
+
return out.code;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (!FileTasks.isNotFound(error))
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`zuke: this is a Node project, and no npm was found — tried ` +
|
|
76
|
+
`${candidates.join(", ")}. Run the project's ./zuke once, which ` +
|
|
77
|
+
`installs a pinned Node, or put Node ${NODE_PIN.version.split(".")[0]} or newer on PATH.`);
|
|
78
|
+
}
|
package/src/project.d.ts
CHANGED
|
@@ -18,10 +18,15 @@ export interface ProjectHost {
|
|
|
18
18
|
remove(path: string): Promise<void>;
|
|
19
19
|
/** Run `deno <denoArgs>` in `cwd`, returning its exit code. */
|
|
20
20
|
deno(denoArgs: string[], cwd: string): Promise<number>;
|
|
21
|
+
/**
|
|
22
|
+
* Run `npm <npmArgs>` in `cwd`, a Node project's root, returning its exit
|
|
23
|
+
* code.
|
|
24
|
+
*/
|
|
25
|
+
npm(npmArgs: string[], cwd: string): Promise<number>;
|
|
21
26
|
/** The version of the Deno that runs the command. */
|
|
22
27
|
denoVersion(): string;
|
|
23
28
|
}
|
|
24
|
-
/** The real {@link ProjectHost}: the file system, and `deno` in the root. */
|
|
29
|
+
/** The real {@link ProjectHost}: the file system, and `deno` or `npm` in the root. */
|
|
25
30
|
export declare const defaultProjectHost: ProjectHost;
|
|
26
31
|
/**
|
|
27
32
|
* The project at or above `cwd`, through the trust gate: its root, and the
|
|
@@ -67,3 +72,11 @@ export declare function parseInstallFlags(command: string, args: readonly string
|
|
|
67
72
|
* `denoVersion` does not accept the flag.
|
|
68
73
|
*/
|
|
69
74
|
export declare function installArgs(command: string, flags: InstallFlags, denoVersion: string, build: string): string[];
|
|
75
|
+
/**
|
|
76
|
+
* Refuse what `flags` asks of npm that it cannot do: a Node project's
|
|
77
|
+
* dependencies are its `package.json`'s, so there are no further entrypoints
|
|
78
|
+
* to resolve, and `--min-dep-age` is Deno's.
|
|
79
|
+
*
|
|
80
|
+
* @throws {Error} naming `command` when either was given.
|
|
81
|
+
*/
|
|
82
|
+
export declare function nodeInstallFlags(command: string, flags: InstallFlags): void;
|
package/src/project.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
/**
|
|
4
4
|
* What the global CLI's project commands share: `relock`, `cache`, `add` and
|
|
5
|
-
* `remove` each run a `deno` command in the project root
|
|
6
|
-
* a
|
|
5
|
+
* `remove` each run a `deno` command in the project root — or an `npm` one,
|
|
6
|
+
* in a project whose build runs on Node — so that working on a Zuke project
|
|
7
|
+
* needs only `zuke`.
|
|
7
8
|
*
|
|
8
9
|
* They are the CLI's own rather than the build's because they must work
|
|
9
10
|
* whatever core the project is on — including one too old, or too broken, to
|
|
@@ -14,9 +15,10 @@
|
|
|
14
15
|
*/
|
|
15
16
|
import { FileTasks, RuntimeTasks } from "@zuke/core";
|
|
16
17
|
import { spawnDeno } from "./deno_path.js";
|
|
18
|
+
import { runNpm } from "./npm_path.js";
|
|
17
19
|
import { locateBuild, } from "./dispatch.js";
|
|
18
20
|
import { acceptsMinimumDependencyAge } from "./upgrade.js";
|
|
19
|
-
/** The real {@link ProjectHost}: the file system, and `deno` in the root. */
|
|
21
|
+
/** The real {@link ProjectHost}: the file system, and `deno` or `npm` in the root. */
|
|
20
22
|
export const defaultProjectHost = {
|
|
21
23
|
entry: async (path) => {
|
|
22
24
|
try {
|
|
@@ -34,7 +36,7 @@ export const defaultProjectHost = {
|
|
|
34
36
|
await FileTasks.remove(path);
|
|
35
37
|
},
|
|
36
38
|
deno: async (denoArgs, cwd) => {
|
|
37
|
-
const child = spawnDeno(denoArgs, {
|
|
39
|
+
const child = await spawnDeno(denoArgs, {
|
|
38
40
|
cwd,
|
|
39
41
|
stdin: "null",
|
|
40
42
|
stdout: "inherit",
|
|
@@ -42,6 +44,7 @@ export const defaultProjectHost = {
|
|
|
42
44
|
});
|
|
43
45
|
return (await child.status).code;
|
|
44
46
|
},
|
|
47
|
+
npm: (npmArgs, cwd) => runNpm(npmArgs, cwd),
|
|
45
48
|
// The cli runs on Deno, so the runtime is the Deno that runs the command.
|
|
46
49
|
denoVersion: () => RuntimeTasks.facts().version,
|
|
47
50
|
};
|
|
@@ -130,3 +133,17 @@ export function installArgs(command, flags, denoVersion, build) {
|
|
|
130
133
|
}
|
|
131
134
|
return [...args, `--minimum-dependency-age=${flags.minDepAge}`];
|
|
132
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Refuse what `flags` asks of npm that it cannot do: a Node project's
|
|
138
|
+
* dependencies are its `package.json`'s, so there are no further entrypoints
|
|
139
|
+
* to resolve, and `--min-dep-age` is Deno's.
|
|
140
|
+
*
|
|
141
|
+
* @throws {Error} naming `command` when either was given.
|
|
142
|
+
*/
|
|
143
|
+
export function nodeInstallFlags(command, flags) {
|
|
144
|
+
if (flags.entrypoints.length > 0 || flags.minDepAge !== undefined) {
|
|
145
|
+
throw new Error(`zuke ${command}: this project's build runs on Node, whose ` +
|
|
146
|
+
"dependencies are package.json's: it takes only --dry-run, not " +
|
|
147
|
+
"entrypoints or --min-dep-age.");
|
|
148
|
+
}
|
|
149
|
+
}
|
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
|
+
}
|
package/src/relock.js
CHANGED
|
@@ -27,10 +27,15 @@
|
|
|
27
27
|
* matters on Deno 2.9, which by default skips releases from the last day or
|
|
28
28
|
* so: `--min-dep-age 0` resolves the newest published versions.
|
|
29
29
|
*
|
|
30
|
+
* In a project whose build runs on Node it regenerates `package-lock.json`
|
|
31
|
+
* instead, behind the same backup and emptied in place the same way, and
|
|
32
|
+
* `npm install --package-lock-only --ignore-scripts` resolves `package.json`
|
|
33
|
+
* afresh into it, installing nothing.
|
|
34
|
+
*
|
|
30
35
|
* @module
|
|
31
36
|
*/
|
|
32
37
|
import { lockedJsrSpecifiers } from "@zuke/core";
|
|
33
|
-
import { installArgs, parseInstallFlags, projectLocation, } from "./project.js";
|
|
38
|
+
import { installArgs, nodeInstallFlags, parseInstallFlags, projectLocation, } from "./project.js";
|
|
34
39
|
import { lockedCoreVersions, projectConfigText, projectLockPath, } from "./version_report.js";
|
|
35
40
|
/** The suffix of the backup a run keeps while the lock is being rewritten. */
|
|
36
41
|
const BACKUP_SUFFIX = ".relock-backup";
|
|
@@ -54,66 +59,59 @@ function olderThan(a, b) {
|
|
|
54
59
|
}
|
|
55
60
|
return false;
|
|
56
61
|
}
|
|
57
|
-
/** The
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
/** The lock formats `relock` empties: Deno's `deno.lock`, npm's `package-lock.json`. */
|
|
63
|
+
const LOCK_FORMATS = {
|
|
64
|
+
deno: { key: "version", fallback: "5", entries: {} },
|
|
65
|
+
npm: { key: "lockfileVersion", fallback: 3, entries: { packages: {} } },
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The emptied lock a run resolves into: `before`'s format version, no
|
|
69
|
+
* entries. It is written over the lock in place rather than the lock being
|
|
70
|
+
* removed, so a lock that is a symlink to a shared file stays one.
|
|
71
|
+
*/
|
|
72
|
+
function emptied(before, kind) {
|
|
73
|
+
const format = LOCK_FORMATS[kind];
|
|
74
|
+
let version = format.fallback;
|
|
60
75
|
try {
|
|
61
76
|
const parsed = JSON.parse(before);
|
|
62
77
|
if (parsed !== null && typeof parsed === "object") {
|
|
63
|
-
version = Reflect.get(parsed,
|
|
78
|
+
version = Reflect.get(parsed, format.key) ?? version;
|
|
64
79
|
}
|
|
65
80
|
}
|
|
66
81
|
catch {
|
|
67
|
-
// An unreadable lock is still replaced
|
|
82
|
+
// An unreadable lock is still replaced, in the current default format.
|
|
68
83
|
}
|
|
69
|
-
return `${JSON.stringify({ version }, null, 2)}\n`;
|
|
70
|
-
}
|
|
71
|
-
/** The JSR package names `lock` resolves. */
|
|
72
|
-
function jsrPackages(lock) {
|
|
73
|
-
return new Set(lockedJsrSpecifiers(lock).map((entry) => entry.name));
|
|
84
|
+
return `${JSON.stringify({ [format.key]: version, ...format.entries }, null, 2)}\n`;
|
|
74
85
|
}
|
|
75
86
|
/**
|
|
76
|
-
*
|
|
77
|
-
* the
|
|
87
|
+
* Refuse to start while `backup`, a lock an earlier run set aside, is still
|
|
88
|
+
* there: it is the only copy of the lock as it was.
|
|
78
89
|
*
|
|
79
|
-
* @throws {Error}
|
|
80
|
-
* carried out. `main` prints the message and exits 1.
|
|
90
|
+
* @throws {Error} saying how to restore or drop it.
|
|
81
91
|
*/
|
|
82
|
-
|
|
83
|
-
const flags = parseInstallFlags("relock", args);
|
|
84
|
-
const { root, build } = await projectLocation(cwd, probe, "relock");
|
|
85
|
-
const lockPath = projectLockPath(root, await projectConfigText((path) => host.readText(path), root));
|
|
86
|
-
if (lockPath === null) {
|
|
87
|
-
throw new Error("zuke relock: this project's deno.json disables its lock, or could " +
|
|
88
|
-
"not be read as JSON, so there is no lock to regenerate.");
|
|
89
|
-
}
|
|
90
|
-
// Regenerating is the point, so a lock the config freezes is not a reason
|
|
91
|
-
// to refuse the write.
|
|
92
|
-
const denoArgs = [
|
|
93
|
-
...installArgs("relock", flags, host.denoVersion(), build),
|
|
94
|
-
"--frozen=false",
|
|
95
|
-
];
|
|
96
|
-
const name = lockPath.startsWith(`${root}/`)
|
|
97
|
-
? lockPath.slice(root.length + 1)
|
|
98
|
-
: lockPath;
|
|
99
|
-
if (flags.dryRun) {
|
|
100
|
-
log(`Would regenerate ${name}: deno ${denoArgs.join(" ")}`);
|
|
101
|
-
return 0;
|
|
102
|
-
}
|
|
103
|
-
const backup = `${lockPath}${BACKUP_SUFFIX}`;
|
|
104
|
-
let leftover = true;
|
|
92
|
+
async function refuseLeftover(host, backup, name) {
|
|
105
93
|
try {
|
|
106
94
|
await host.readText(backup);
|
|
107
95
|
}
|
|
108
96
|
catch {
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
if (leftover) {
|
|
112
|
-
throw new Error(`zuke relock: ${backup} is left from a relock that did not finish. ` +
|
|
113
|
-
`It is the lock as it was before that run: move it back over ${name} ` +
|
|
114
|
-
"to restore it, or delete it to keep the lock as it is, then run " +
|
|
115
|
-
"zuke relock again.");
|
|
97
|
+
return;
|
|
116
98
|
}
|
|
99
|
+
throw new Error(`zuke relock: ${backup} is left from a relock that did not finish. ` +
|
|
100
|
+
`It is the lock as it was before that run: move it back over ${name} ` +
|
|
101
|
+
"to restore it, or delete it to keep the lock as it is, then run " +
|
|
102
|
+
"zuke relock again.");
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Regenerate the lock at `lockPath` behind a backup, the one sequence both
|
|
106
|
+
* runtimes share: refuse to start over a backup an earlier run left, set the
|
|
107
|
+
* lock aside, empty it in place in format `kind` (written through, so a link
|
|
108
|
+
* stays one), and run `regenerate`. Its result is kept only when it exits 0
|
|
109
|
+
* and writes a lock that is not still the emptied one; otherwise the old text
|
|
110
|
+
* goes back the same way. The backup is removed either way, and on a throw.
|
|
111
|
+
*/
|
|
112
|
+
async function regenerateLock(host, lockPath, name, kind, log, regenerate) {
|
|
113
|
+
const backup = `${lockPath}${BACKUP_SUFFIX}`;
|
|
114
|
+
await refuseLeftover(host, backup, name);
|
|
117
115
|
let before;
|
|
118
116
|
try {
|
|
119
117
|
before = await host.readText(lockPath);
|
|
@@ -123,21 +121,22 @@ export async function runRelock(args, log, host, paint, cwd, probe) {
|
|
|
123
121
|
}
|
|
124
122
|
if (before !== undefined) {
|
|
125
123
|
await host.writeText(backup, before);
|
|
126
|
-
await host.writeText(lockPath, emptied(before));
|
|
124
|
+
await host.writeText(lockPath, emptied(before, kind));
|
|
127
125
|
}
|
|
128
|
-
const
|
|
129
|
-
if (before
|
|
126
|
+
const settle = async (keep) => {
|
|
127
|
+
if (before === undefined)
|
|
128
|
+
return;
|
|
129
|
+
if (!keep)
|
|
130
130
|
await host.writeText(lockPath, before);
|
|
131
|
+
await host.remove(backup);
|
|
131
132
|
};
|
|
132
133
|
log(`Regenerating ${name}…`);
|
|
133
134
|
let code;
|
|
134
135
|
try {
|
|
135
|
-
code = await
|
|
136
|
+
code = await regenerate();
|
|
136
137
|
}
|
|
137
138
|
catch (error) {
|
|
138
|
-
await
|
|
139
|
-
if (before !== undefined)
|
|
140
|
-
await host.remove(backup);
|
|
139
|
+
await settle(false);
|
|
141
140
|
throw error;
|
|
142
141
|
}
|
|
143
142
|
let after;
|
|
@@ -146,21 +145,79 @@ export async function runRelock(args, log, host, paint, cwd, probe) {
|
|
|
146
145
|
after = await host.readText(lockPath);
|
|
147
146
|
}
|
|
148
147
|
catch {
|
|
149
|
-
// Reported
|
|
148
|
+
// Reported by the caller, as no lock written.
|
|
150
149
|
}
|
|
151
150
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
const fresh = code === 0 && after !== undefined &&
|
|
152
|
+
after !== emptied(before ?? "", kind);
|
|
153
|
+
await settle(fresh);
|
|
154
|
+
return { code, before, after: fresh ? after : undefined };
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Regenerate a Node project's `package-lock.json` in `root`, resolving
|
|
158
|
+
* `package.json` afresh with npm behind {@link regenerateLock}'s backup.
|
|
159
|
+
*/
|
|
160
|
+
async function relockNode(flags, root, log, host, paint) {
|
|
161
|
+
nodeInstallFlags("relock", flags);
|
|
162
|
+
const name = "package-lock.json";
|
|
163
|
+
const npmArgs = ["install", "--package-lock-only", "--ignore-scripts"];
|
|
164
|
+
if (flags.dryRun) {
|
|
165
|
+
log(`Would regenerate ${name}: npm ${npmArgs.join(" ")}`);
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
const { code, before, after } = await regenerateLock(host, `${root}/${name}`, name, "npm", log, () => host.npm(npmArgs, root));
|
|
169
|
+
if (after === undefined) {
|
|
170
|
+
log(paint.fail(code !== 0
|
|
171
|
+
? `zuke relock: npm install exited ${code}; ${name} is unchanged.`
|
|
172
|
+
: `zuke relock: npm install wrote no ${name}${before === undefined ? "" : "; the old one is restored"}.`));
|
|
173
|
+
return code !== 0 ? code : 1;
|
|
174
|
+
}
|
|
175
|
+
log(paint.ok(`Regenerated ${name}.`));
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
/** The JSR package names `lock` resolves. */
|
|
179
|
+
function jsrPackages(lock) {
|
|
180
|
+
return new Set(lockedJsrSpecifiers(lock).map((entry) => entry.name));
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Run `zuke relock <args>` from `cwd`, reporting through `log`, and return
|
|
184
|
+
* the exit code.
|
|
185
|
+
*
|
|
186
|
+
* @throws {Error} with a message for the user when the request cannot be
|
|
187
|
+
* carried out. `main` prints the message and exits 1.
|
|
188
|
+
*/
|
|
189
|
+
export async function runRelock(args, log, host, paint, cwd, probe) {
|
|
190
|
+
const flags = parseInstallFlags("relock", args);
|
|
191
|
+
const { root, build, runtime } = await projectLocation(cwd, probe, "relock");
|
|
192
|
+
if (runtime === "node") {
|
|
193
|
+
return await relockNode(flags, root, log, host, paint);
|
|
194
|
+
}
|
|
195
|
+
const lockPath = projectLockPath(root, await projectConfigText((path) => host.readText(path), root));
|
|
196
|
+
if (lockPath === null) {
|
|
197
|
+
throw new Error("zuke relock: this project's deno.json disables its lock, or could " +
|
|
198
|
+
"not be read as JSON, so there is no lock to regenerate.");
|
|
199
|
+
}
|
|
200
|
+
// Regenerating is the point, so a lock the config freezes is not a reason
|
|
201
|
+
// to refuse the write.
|
|
202
|
+
const denoArgs = [
|
|
203
|
+
...installArgs("relock", flags, host.denoVersion(), build),
|
|
204
|
+
"--frozen=false",
|
|
205
|
+
];
|
|
206
|
+
const name = lockPath.startsWith(`${root}/`)
|
|
207
|
+
? lockPath.slice(root.length + 1)
|
|
208
|
+
: lockPath;
|
|
209
|
+
if (flags.dryRun) {
|
|
210
|
+
log(`Would regenerate ${name}: deno ${denoArgs.join(" ")}`);
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
const { code, before, after } = await regenerateLock(host, lockPath, name, "deno", log, () => host.deno(denoArgs, root));
|
|
214
|
+
if (after === undefined) {
|
|
156
215
|
log(paint.fail(code !== 0
|
|
157
216
|
? `zuke relock: deno install exited ${code}; ${name} is unchanged.`
|
|
158
217
|
: `zuke relock: deno install wrote no ${name}${before === undefined ? "" : "; the old one is restored"}. In a workspace member, Deno keeps the lock at the workspace ` +
|
|
159
218
|
"root: run zuke relock there."));
|
|
160
219
|
return code !== 0 ? code : 1;
|
|
161
220
|
}
|
|
162
|
-
if (before !== undefined)
|
|
163
|
-
await host.remove(backup);
|
|
164
221
|
const was = lockedCoreVersions(before ?? "");
|
|
165
222
|
const now = lockedCoreVersions(after);
|
|
166
223
|
log(paint.ok(`Regenerated ${name}: @zuke/core ${shown(was) === shown(now) ? shown(now) : `${shown(was)} → ${shown(now)}`}`));
|
|
@@ -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 {
|