@zuke-build/cli 0.0.0-stage → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +343 -2
  3. package/mod.d.ts +99 -0
  4. package/mod.js +893 -0
  5. package/package.json +35 -4
  6. package/src/binary_launcher.d.ts +49 -0
  7. package/src/binary_launcher.js +327 -0
  8. package/src/binary_pin.d.ts +47 -0
  9. package/src/binary_pin.js +117 -0
  10. package/src/build_file.d.ts +25 -0
  11. package/src/build_file.js +65 -0
  12. package/src/cache.d.ts +23 -0
  13. package/src/cache.js +26 -0
  14. package/src/deno_isolated.d.ts +14 -0
  15. package/src/deno_isolated.js +70 -0
  16. package/src/deno_path.d.ts +115 -0
  17. package/src/deno_path.js +205 -0
  18. package/src/deno_pin.d.ts +37 -0
  19. package/src/deno_pin.js +32 -0
  20. package/src/dependencies.d.ts +48 -0
  21. package/src/dependencies.js +80 -0
  22. package/src/dispatch.d.ts +220 -0
  23. package/src/dispatch.js +538 -0
  24. package/src/embedded_engine.d.ts +28 -0
  25. package/src/embedded_engine.js +21 -0
  26. package/src/engine_pin.d.ts +56 -0
  27. package/src/engine_pin.js +196 -0
  28. package/src/fs.d.ts +14 -0
  29. package/src/fs.js +25 -0
  30. package/src/import.d.ts +132 -0
  31. package/src/import.js +289 -0
  32. package/src/install_source.d.ts +79 -0
  33. package/src/install_source.js +104 -0
  34. package/src/launcher.d.ts +37 -0
  35. package/src/launcher.js +464 -0
  36. package/src/mcp_config.d.ts +63 -0
  37. package/src/mcp_config.js +86 -0
  38. package/src/output.d.ts +38 -0
  39. package/src/output.js +43 -0
  40. package/src/paint.d.ts +42 -0
  41. package/src/paint.js +38 -0
  42. package/src/project.d.ts +69 -0
  43. package/src/project.js +132 -0
  44. package/src/pyproject.d.ts +30 -0
  45. package/src/pyproject.js +156 -0
  46. package/src/python_build.d.ts +27 -0
  47. package/src/python_build.js +197 -0
  48. package/src/records.d.ts +9 -0
  49. package/src/records.js +13 -0
  50. package/src/relock.d.ts +11 -0
  51. package/src/relock.js +182 -0
  52. package/src/setup.d.ts +251 -0
  53. package/src/setup.js +601 -0
  54. package/src/star.d.ts +44 -0
  55. package/src/star.js +100 -0
  56. package/src/starter.d.ts +55 -0
  57. package/src/starter.js +126 -0
  58. package/src/toml.d.ts +32 -0
  59. package/src/toml.js +354 -0
  60. package/src/translate.d.ts +69 -0
  61. package/src/translate.js +198 -0
  62. package/src/upgrade.d.ts +113 -0
  63. package/src/upgrade.js +344 -0
  64. package/src/version.d.ts +11 -0
  65. package/src/version.js +13 -0
  66. package/src/version_report.d.ts +55 -0
  67. package/src/version_report.js +187 -0
  68. package/zuke.js +8 -0
@@ -0,0 +1,69 @@
1
+ /** One `&&`-separated segment of a command: argv to run, or text to keep verbatim. */
2
+ export type Segment = {
3
+ readonly argv: readonly string[];
4
+ } | {
5
+ readonly raw: string;
6
+ };
7
+ /**
8
+ * Split a shell command into its `&&`-separated segments, each one argv
9
+ * (never empty: a segment is non-blank and holds no backslash), or the raw
10
+ * text when it is too shell-specific to translate (or its quoting does not
11
+ * balance). Blank segments are dropped.
12
+ */
13
+ export declare function segments(command: string): Segment[];
14
+ /** Split a command on top-level `&&`, ignoring `&&` inside quotes. */
15
+ export declare function splitChain(command: string): string[];
16
+ /**
17
+ * Split a command segment into argv with POSIX quoting rules, or `undefined`
18
+ * when the segment's quoting is unbalanced. An unterminated quote is not
19
+ * translatable, so the caller falls back to preserving the raw text — the
20
+ * scaffold must never silently drop half a command.
21
+ */
22
+ export declare function tokenize(segment: string): string[] | undefined;
23
+ /**
24
+ * A double-quoted string literal for `value`, valid as TypeScript and as
25
+ * Python alike — the one escaper every generated literal goes through.
26
+ *
27
+ * `JSON.stringify` escapes quotes, backslashes, and control characters (as
28
+ * `\n`, `\t`, `\uXXXX`, which both languages read the same way), but leaves
29
+ * U+2028/U+2029 raw — legal inside JSON strings, line terminators to a
30
+ * JavaScript parser — so those are escaped on top, keeping the generated
31
+ * literal on one line whatever the imported command contains.
32
+ */
33
+ export declare function literal(value: string): string;
34
+ /**
35
+ * `text` on one line, fit for a `//` or `#` comment: every run of whitespace
36
+ * or control characters collapses to a space, so an embedded newline cannot
37
+ * break the text out of its comment, and a NUL (which Python refuses in
38
+ * source) never reaches the file.
39
+ */
40
+ export declare function oneLine(text: string): string;
41
+ /** An imported task with a unique identifier and its dependencies remapped to identifiers. */
42
+ export interface Named<T> {
43
+ /** The identifier of the generated target field. */
44
+ readonly id: string;
45
+ /** The task as it was imported. */
46
+ readonly task: T;
47
+ /** The identifiers of the tasks it depends on (unknown names dropped). */
48
+ readonly deps: readonly string[];
49
+ }
50
+ /**
51
+ * Give each task a unique identifier — `toId` of its name, suffixed with `_`
52
+ * until it collides with neither another task's nor a `reserved` one — and
53
+ * remap its dependencies to those identifiers.
54
+ */
55
+ export declare function normalize<T extends {
56
+ name: string;
57
+ deps: readonly string[];
58
+ }>(tasks: readonly T[], toId: (name: string) => string, reserved: ReadonlySet<string>): Named<T>[];
59
+ /**
60
+ * Order tasks so every dependency is declared before its dependents (Zuke
61
+ * forbids forward references), dropping the edges that would close a cycle
62
+ * (a task naming itself included). Returns the order — each task's `deps`
63
+ * without its dropped edges, so every one names a task declared above it —
64
+ * plus, per task id, the dependency ids that were dropped.
65
+ */
66
+ export declare function order<T>(tasks: readonly Named<T>[]): {
67
+ ordered: Named<T>[];
68
+ dropped: Map<string, string[]>;
69
+ };
@@ -0,0 +1,198 @@
1
+ // Copyright (c) 2026 the Zuke contributors
2
+ // SPDX-License-Identifier: MIT
3
+ /**
4
+ * The language-neutral half of `zuke import`: splitting an imported shell
5
+ * command into argv (or flagging it as too shell-specific to translate),
6
+ * quoting a value into a generated source file, and giving imported tasks
7
+ * unique identifiers in a declaration order with no forward reference. The
8
+ * TypeScript (`zuke.ts`) and Python (`build.py`) generators both render from
9
+ * these, so the two can never disagree about what a command means.
10
+ *
11
+ * @module
12
+ */
13
+ import { splitShellArgs } from "@zuke/core/shell";
14
+ /** Shell features a single argv cannot faithfully express. */
15
+ function needsShell(segment) {
16
+ // pipe, redirect, subst, env expand, and a newline (a second command)
17
+ if (/[|<>;`$\n\r]/.test(segment))
18
+ return true;
19
+ if (/(^|\s)&(\s|$)/.test(segment))
20
+ return true; // background job
21
+ if (hasUnquotedBackslash(segment))
22
+ return true; // escape or Windows separator?
23
+ const first = segment.trim().split(/\s+/)[0] ?? "";
24
+ return /^[A-Za-z_][A-Za-z0-9_]*=/.test(first); // leading VAR=value assignment
25
+ }
26
+ /**
27
+ * Whether `segment` contains a backslash outside quotes, which is ambiguous and
28
+ * therefore not translatable: a POSIX shell reads it as an escape (`a\ b` is one
29
+ * argument), while a `package.json` script written on Windows — where npm runs
30
+ * scripts through `cmd.exe` — uses it as a path separator (`node scripts\b.js`).
31
+ * Picking either reading silently changes the command, so the segment is
32
+ * preserved verbatim for a human to resolve. A backslash inside quotes is
33
+ * unambiguous and stays translatable.
34
+ */
35
+ function hasUnquotedBackslash(segment) {
36
+ let quote;
37
+ for (let i = 0; i < segment.length; i++) {
38
+ const ch = segment[i];
39
+ if (quote !== undefined) {
40
+ // Inside double quotes a backslash escapes the next character, so skip it
41
+ // and keep tracking the quote state accurately.
42
+ if (quote === '"' && ch === "\\")
43
+ i++;
44
+ else if (ch === quote)
45
+ quote = undefined;
46
+ continue;
47
+ }
48
+ if (ch === '"' || ch === "'")
49
+ quote = ch;
50
+ else if (ch === "\\")
51
+ return true;
52
+ }
53
+ return false;
54
+ }
55
+ /**
56
+ * Split a shell command into its `&&`-separated segments, each one argv
57
+ * (never empty: a segment is non-blank and holds no backslash), or the raw
58
+ * text when it is too shell-specific to translate (or its quoting does not
59
+ * balance). Blank segments are dropped.
60
+ */
61
+ export function segments(command) {
62
+ const out = [];
63
+ for (const raw of splitChain(command)) {
64
+ const segment = raw.trim();
65
+ if (segment === "")
66
+ continue;
67
+ const argv = needsShell(segment) ? undefined : tokenize(segment);
68
+ out.push(argv === undefined ? { raw: segment } : { argv });
69
+ }
70
+ return out;
71
+ }
72
+ /** Split a command on top-level `&&`, ignoring `&&` inside quotes. */
73
+ export function splitChain(command) {
74
+ const parts = [];
75
+ let current = "";
76
+ let quote;
77
+ for (let i = 0; i < command.length; i++) {
78
+ const ch = command[i];
79
+ if (quote !== undefined) {
80
+ current += ch;
81
+ if (ch === quote)
82
+ quote = undefined;
83
+ continue;
84
+ }
85
+ if (ch === '"' || ch === "'") {
86
+ quote = ch;
87
+ current += ch;
88
+ continue;
89
+ }
90
+ if (ch === "&" && command[i + 1] === "&") {
91
+ parts.push(current);
92
+ current = "";
93
+ i++;
94
+ continue;
95
+ }
96
+ current += ch;
97
+ }
98
+ parts.push(current);
99
+ return parts;
100
+ }
101
+ /**
102
+ * Split a command segment into argv with POSIX quoting rules, or `undefined`
103
+ * when the segment's quoting is unbalanced. An unterminated quote is not
104
+ * translatable, so the caller falls back to preserving the raw text — the
105
+ * scaffold must never silently drop half a command.
106
+ */
107
+ export function tokenize(segment) {
108
+ try {
109
+ return splitShellArgs(segment);
110
+ }
111
+ catch {
112
+ return undefined; // Only ShellArgsError can escape splitShellArgs.
113
+ }
114
+ }
115
+ /**
116
+ * A double-quoted string literal for `value`, valid as TypeScript and as
117
+ * Python alike — the one escaper every generated literal goes through.
118
+ *
119
+ * `JSON.stringify` escapes quotes, backslashes, and control characters (as
120
+ * `\n`, `\t`, `\uXXXX`, which both languages read the same way), but leaves
121
+ * U+2028/U+2029 raw — legal inside JSON strings, line terminators to a
122
+ * JavaScript parser — so those are escaped on top, keeping the generated
123
+ * literal on one line whatever the imported command contains.
124
+ */
125
+ export function literal(value) {
126
+ return JSON.stringify(value)
127
+ .replace(/\u2028/g, "\\u2028")
128
+ .replace(/\u2029/g, "\\u2029");
129
+ }
130
+ /**
131
+ * `text` on one line, fit for a `//` or `#` comment: every run of whitespace
132
+ * or control characters collapses to a space, so an embedded newline cannot
133
+ * break the text out of its comment, and a NUL (which Python refuses in
134
+ * source) never reaches the file.
135
+ */
136
+ export function oneLine(text) {
137
+ // deno-lint-ignore no-control-regex -- matching control characters is the point
138
+ return text.replace(/[\s\x00-\x1f\x7f]+/g, " ").trim();
139
+ }
140
+ /**
141
+ * Give each task a unique identifier — `toId` of its name, suffixed with `_`
142
+ * until it collides with neither another task's nor a `reserved` one — and
143
+ * remap its dependencies to those identifiers.
144
+ */
145
+ export function normalize(tasks, toId, reserved) {
146
+ const idByName = new Map();
147
+ const used = new Set(reserved);
148
+ for (const task of tasks) {
149
+ let id = toId(task.name);
150
+ while (used.has(id))
151
+ id = `${id}_`;
152
+ used.add(id);
153
+ idByName.set(task.name, id);
154
+ }
155
+ return tasks.map((task) => ({
156
+ id: idByName.get(task.name) ?? toId(task.name),
157
+ task,
158
+ deps: task.deps
159
+ .map((d) => idByName.get(d))
160
+ .filter((d) => d !== undefined),
161
+ }));
162
+ }
163
+ /**
164
+ * Order tasks so every dependency is declared before its dependents (Zuke
165
+ * forbids forward references), dropping the edges that would close a cycle
166
+ * (a task naming itself included). Returns the order — each task's `deps`
167
+ * without its dropped edges, so every one names a task declared above it —
168
+ * plus, per task id, the dependency ids that were dropped.
169
+ */
170
+ export function order(tasks) {
171
+ const byId = new Map(tasks.map((t) => [t.id, t]));
172
+ const state = new Map();
173
+ const ordered = [];
174
+ const dropped = new Map();
175
+ const visit = (task) => {
176
+ state.set(task.id, "open");
177
+ for (const dep of task.deps) {
178
+ const target = byId.get(dep);
179
+ if (target === undefined)
180
+ continue;
181
+ const st = state.get(dep);
182
+ if (st === "open") {
183
+ dropped.set(task.id, [...(dropped.get(task.id) ?? []), dep]);
184
+ }
185
+ else if (st === undefined) {
186
+ visit(target);
187
+ }
188
+ }
189
+ state.set(task.id, "done");
190
+ const cut = dropped.get(task.id) ?? [];
191
+ ordered.push({ ...task, deps: task.deps.filter((d) => !cut.includes(d)) });
192
+ };
193
+ for (const task of tasks) {
194
+ if (state.get(task.id) === undefined)
195
+ visit(task);
196
+ }
197
+ return { ordered, dropped };
198
+ }
@@ -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>;