@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.
- package/LICENSE +21 -0
- package/README.md +343 -2
- package/mod.d.ts +99 -0
- package/mod.js +893 -0
- package/package.json +35 -4
- package/src/binary_launcher.d.ts +49 -0
- package/src/binary_launcher.js +327 -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 +65 -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 +220 -0
- package/src/dispatch.js +538 -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 +464 -0
- package/src/mcp_config.d.ts +63 -0
- package/src/mcp_config.js +86 -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 +9 -0
- package/src/records.js +13 -0
- package/src/relock.d.ts +11 -0
- package/src/relock.js +182 -0
- package/src/setup.d.ts +251 -0
- package/src/setup.js +601 -0
- package/src/star.d.ts +44 -0
- package/src/star.js +100 -0
- package/src/starter.d.ts +55 -0
- package/src/starter.js +126 -0
- package/src/toml.d.ts +32 -0
- package/src/toml.js +354 -0
- package/src/translate.d.ts +69 -0
- package/src/translate.js +198 -0
- package/src/upgrade.d.ts +113 -0
- package/src/upgrade.js +344 -0
- package/src/version.d.ts +11 -0
- package/src/version.js +13 -0
- package/src/version_report.d.ts +55 -0
- package/src/version_report.js +187 -0
- package/zuke.js +8 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** The MCP client configuration file `--mcp` writes, next to `zuke.ts`. */
|
|
2
|
+
export declare const MCP_CONFIG_FILE = ".mcp.json";
|
|
3
|
+
/** The server name registered in the file. */
|
|
4
|
+
export declare const MCP_SERVER_NAME = "zuke";
|
|
5
|
+
/** One server entry in `mcpServers`: the command and its arguments. */
|
|
6
|
+
export interface McpServerEntry {
|
|
7
|
+
/**
|
|
8
|
+
* The executable: `deno`, which is the same on every platform, or the
|
|
9
|
+
* compiled `zuke` for a hosted build it registered.
|
|
10
|
+
*/
|
|
11
|
+
command: string;
|
|
12
|
+
/**
|
|
13
|
+
* The arguments: `run -A zuke.ts mcp`, with the engine release in place of
|
|
14
|
+
* `zuke.ts` for a hosted build, or just `mcp` for the compiled `zuke`; plus
|
|
15
|
+
* `--allow-run` when asked for.
|
|
16
|
+
*/
|
|
17
|
+
args: string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The entry that launches the MCP server of a TypeScript build whose file is
|
|
21
|
+
* `buildFile`: `deno run -A zuke.ts mcp`.
|
|
22
|
+
* Read-only by default: the agent can inspect the build but not execute
|
|
23
|
+
* targets until `allowRun` opts in, mirroring `zuke mcp --allow-run`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function mcpServerEntry(allowRun: boolean, buildFile: string): McpServerEntry;
|
|
26
|
+
/**
|
|
27
|
+
* The entry a hosted build is registered with: `zuke mcp`, which the
|
|
28
|
+
* standalone binary runs on the engine it carries, with no Deno.
|
|
29
|
+
*/
|
|
30
|
+
export declare function binaryMcpEntry(allowRun: boolean): McpServerEntry;
|
|
31
|
+
/**
|
|
32
|
+
* A parsed `.mcp.json`, ready to merge. `present` means a well-formed
|
|
33
|
+
* {@link McpServerEntry} is registered as `zuke` (whatever its arguments — a
|
|
34
|
+
* deliberate `--allow-run` or transport choice survives a re-run without
|
|
35
|
+
* `--force`); `absent` covers a missing key and a malformed one alike, so a
|
|
36
|
+
* broken registration is repaired rather than kept. `document` is the file's
|
|
37
|
+
* top-level object — empty when the text was not one — for the merge to
|
|
38
|
+
* extend. An `unparseable` text carries no document: it is never rewritten,
|
|
39
|
+
* because there is no telling what it held.
|
|
40
|
+
*/
|
|
41
|
+
export type McpConfig = {
|
|
42
|
+
/** The `zuke` entry is registered, or not. */
|
|
43
|
+
state: "present" | "absent";
|
|
44
|
+
/** The top-level object every other key and server is preserved from. */
|
|
45
|
+
document: Record<string, unknown>;
|
|
46
|
+
} | {
|
|
47
|
+
/** The text is not JSON. */
|
|
48
|
+
state: "unparseable";
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Parse an `.mcp.json` text and classify its `zuke` entry. This is the only
|
|
52
|
+
* place the text is parsed: {@link mergeMcpConfig} takes the document it
|
|
53
|
+
* yields, so an unparseable file is rejected here, once, and can never reach
|
|
54
|
+
* the merge.
|
|
55
|
+
*/
|
|
56
|
+
export declare function parseMcpConfig(text: string): McpConfig;
|
|
57
|
+
/**
|
|
58
|
+
* Merge `entry` as the `zuke` server into a parsed `.mcp.json` document,
|
|
59
|
+
* preserving every other server and top-level key. `document` is the object
|
|
60
|
+
* {@link parseMcpConfig} yielded, or `{}` to start fresh; an existing `zuke`
|
|
61
|
+
* entry is replaced. Pure: it parses nothing and cannot throw.
|
|
62
|
+
*/
|
|
63
|
+
export declare function mergeMcpConfig(document: Record<string, unknown>, entry: McpServerEntry): string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The MCP client configuration `zuke setup --mcp` writes: a project-scoped
|
|
5
|
+
* `.mcp.json` registering the build's own MCP server, so an agent can list
|
|
6
|
+
* the targets, read the graph and run one through typed calls from the first
|
|
7
|
+
* commit — instead of someone hand-writing the registration later.
|
|
8
|
+
*
|
|
9
|
+
* The file is Claude Code's project format (`mcpServers.<name>`), which Codex
|
|
10
|
+
* and most stdio MCP clients read too. The command is `deno run -A zuke.ts
|
|
11
|
+
* mcp` rather than the launcher because it is the same on every platform. A
|
|
12
|
+
* build another SDK hosts runs `jsr:@zuke/engine@<version>` in its place, or,
|
|
13
|
+
* when the compiled `zuke` binary is the one registering it, `zuke mcp`: the
|
|
14
|
+
* binary carries the engine, so that needs no Deno and cannot drift from the
|
|
15
|
+
* pin, and it is a real executable an MCP client can start without a shell.
|
|
16
|
+
*
|
|
17
|
+
* @module
|
|
18
|
+
*/
|
|
19
|
+
import { isRecord } from "./records.js";
|
|
20
|
+
/** The MCP client configuration file `--mcp` writes, next to `zuke.ts`. */
|
|
21
|
+
export const MCP_CONFIG_FILE = ".mcp.json";
|
|
22
|
+
/** The server name registered in the file. */
|
|
23
|
+
export const MCP_SERVER_NAME = "zuke";
|
|
24
|
+
/** The `mcp` command's arguments: read-only unless `allowRun` opts in. */
|
|
25
|
+
function mcpArgs(allowRun) {
|
|
26
|
+
return ["mcp", ...(allowRun ? ["--allow-run"] : [])];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The entry that launches the MCP server of a TypeScript build whose file is
|
|
30
|
+
* `buildFile`: `deno run -A zuke.ts mcp`.
|
|
31
|
+
* Read-only by default: the agent can inspect the build but not execute
|
|
32
|
+
* targets until `allowRun` opts in, mirroring `zuke mcp --allow-run`.
|
|
33
|
+
*/
|
|
34
|
+
export function mcpServerEntry(allowRun, buildFile) {
|
|
35
|
+
return {
|
|
36
|
+
command: "deno",
|
|
37
|
+
args: ["run", "-A", buildFile, ...mcpArgs(allowRun)],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The entry a hosted build is registered with: `zuke mcp`, which the
|
|
42
|
+
* standalone binary runs on the engine it carries, with no Deno.
|
|
43
|
+
*/
|
|
44
|
+
export function binaryMcpEntry(allowRun) {
|
|
45
|
+
return { command: "zuke", args: mcpArgs(allowRun) };
|
|
46
|
+
}
|
|
47
|
+
/** Whether `value` is a well-formed server entry: a command and its arguments. */
|
|
48
|
+
function isServerEntry(value) {
|
|
49
|
+
return isRecord(value) && typeof value.command === "string" &&
|
|
50
|
+
Array.isArray(value.args) &&
|
|
51
|
+
value.args.every((arg) => typeof arg === "string");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parse an `.mcp.json` text and classify its `zuke` entry. This is the only
|
|
55
|
+
* place the text is parsed: {@link mergeMcpConfig} takes the document it
|
|
56
|
+
* yields, so an unparseable file is rejected here, once, and can never reach
|
|
57
|
+
* the merge.
|
|
58
|
+
*/
|
|
59
|
+
export function parseMcpConfig(text) {
|
|
60
|
+
let parsed;
|
|
61
|
+
try {
|
|
62
|
+
parsed = JSON.parse(text);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return { state: "unparseable" };
|
|
66
|
+
}
|
|
67
|
+
const document = isRecord(parsed) ? parsed : {};
|
|
68
|
+
const state = isRecord(document.mcpServers) &&
|
|
69
|
+
isServerEntry(document.mcpServers[MCP_SERVER_NAME])
|
|
70
|
+
? "present"
|
|
71
|
+
: "absent";
|
|
72
|
+
return { state, document };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Merge `entry` as the `zuke` server into a parsed `.mcp.json` document,
|
|
76
|
+
* preserving every other server and top-level key. `document` is the object
|
|
77
|
+
* {@link parseMcpConfig} yielded, or `{}` to start fresh; an existing `zuke`
|
|
78
|
+
* entry is replaced. Pure: it parses nothing and cannot throw.
|
|
79
|
+
*/
|
|
80
|
+
export function mergeMcpConfig(document, entry) {
|
|
81
|
+
const servers = isRecord(document.mcpServers)
|
|
82
|
+
? { ...document.mcpServers }
|
|
83
|
+
: {};
|
|
84
|
+
servers[MCP_SERVER_NAME] = entry;
|
|
85
|
+
return `${JSON.stringify({ ...document, mcpServers: servers }, null, 2)}\n`;
|
|
86
|
+
}
|
package/src/output.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place `@zuke/cli` writes to the console.
|
|
3
|
+
*
|
|
4
|
+
* A GitHub Actions runner parses the job's output for workflow commands: a
|
|
5
|
+
* line whose first non-blank characters are `::` is executed (`::error::`
|
|
6
|
+
* forges an annotation, `::stop-commands::` silences every command that
|
|
7
|
+
* follows, including Zuke's own `::add-mask::`), and `##[` anywhere in a line
|
|
8
|
+
* is the legacy form. The CLI echoes text it did not author — an unknown
|
|
9
|
+
* command straight from argv, a `--dir` or `--from` the user typed, a path or
|
|
10
|
+
* an error message from the filesystem or a failed spawn, and what a
|
|
11
|
+
* subprocess it ran said — so every line goes out through here and is
|
|
12
|
+
* neutralised when something is parsing for commands. Off a runner nothing
|
|
13
|
+
* scans the stream and the line goes out byte for byte.
|
|
14
|
+
*
|
|
15
|
+
* The sink is `@zuke/core`'s own `cliReporter`, the one every core command
|
|
16
|
+
* writes through, so the escaping has exactly one implementation. It decides
|
|
17
|
+
* per line, not once at import, so an embedder or a test that sets the
|
|
18
|
+
* environment after loading this module is honoured.
|
|
19
|
+
*
|
|
20
|
+
* `tests/output_test.ts` scans this package's source and fails on any other
|
|
21
|
+
* console write, so the guard cannot quietly come undone by a new
|
|
22
|
+
* `console.log` elsewhere.
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import { type Reporter } from "@zuke/core";
|
|
27
|
+
/**
|
|
28
|
+
* `line` as it may reach an Actions runner: neutralised while one is parsing
|
|
29
|
+
* the output, untouched anywhere else — the same decision the sink makes,
|
|
30
|
+
* for the one write the sink cannot own: the text Deno's `prompt` puts on the
|
|
31
|
+
* terminal, which carries a default the user typed on the command line.
|
|
32
|
+
*/
|
|
33
|
+
export declare function neutralise(line: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* The CLI's console sink: `info` is stdout, `error` is stderr, and each line
|
|
36
|
+
* is neutralised on an Actions runner before it is written.
|
|
37
|
+
*/
|
|
38
|
+
export declare const output: Reporter;
|
package/src/output.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The one place `@zuke/cli` writes to the console.
|
|
5
|
+
*
|
|
6
|
+
* A GitHub Actions runner parses the job's output for workflow commands: a
|
|
7
|
+
* line whose first non-blank characters are `::` is executed (`::error::`
|
|
8
|
+
* forges an annotation, `::stop-commands::` silences every command that
|
|
9
|
+
* follows, including Zuke's own `::add-mask::`), and `##[` anywhere in a line
|
|
10
|
+
* is the legacy form. The CLI echoes text it did not author — an unknown
|
|
11
|
+
* command straight from argv, a `--dir` or `--from` the user typed, a path or
|
|
12
|
+
* an error message from the filesystem or a failed spawn, and what a
|
|
13
|
+
* subprocess it ran said — so every line goes out through here and is
|
|
14
|
+
* neutralised when something is parsing for commands. Off a runner nothing
|
|
15
|
+
* scans the stream and the line goes out byte for byte.
|
|
16
|
+
*
|
|
17
|
+
* The sink is `@zuke/core`'s own `cliReporter`, the one every core command
|
|
18
|
+
* writes through, so the escaping has exactly one implementation. It decides
|
|
19
|
+
* per line, not once at import, so an embedder or a test that sets the
|
|
20
|
+
* environment after loading this module is honoured.
|
|
21
|
+
*
|
|
22
|
+
* `tests/output_test.ts` scans this package's source and fails on any other
|
|
23
|
+
* console write, so the guard cannot quietly come undone by a new
|
|
24
|
+
* `console.log` elsewhere.
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
import { cliReporter, detectCiHost } from "@zuke/core";
|
|
29
|
+
import { escapeLineIf } from "@zuke/core/render";
|
|
30
|
+
/**
|
|
31
|
+
* `line` as it may reach an Actions runner: neutralised while one is parsing
|
|
32
|
+
* the output, untouched anywhere else — the same decision the sink makes,
|
|
33
|
+
* for the one write the sink cannot own: the text Deno's `prompt` puts on the
|
|
34
|
+
* terminal, which carries a default the user typed on the command line.
|
|
35
|
+
*/
|
|
36
|
+
export function neutralise(line) {
|
|
37
|
+
return escapeLineIf(detectCiHost() === "github", line);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The CLI's console sink: `info` is stdout, `error` is stderr, and each line
|
|
41
|
+
* is neutralised on an Actions runner before it is written.
|
|
42
|
+
*/
|
|
43
|
+
export const output = cliReporter;
|
package/src/paint.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the global CLI paints its own output: `--version`, `--help`, and the
|
|
3
|
+
* status lines `setup`, `import` and `upgrade` print.
|
|
4
|
+
*
|
|
5
|
+
* The palette is `@zuke/core`'s — the one the build's own CLI is painted with,
|
|
6
|
+
* exported from `@zuke/core/render` — so the two cannot drift apart. The CLI
|
|
7
|
+
* adds one fact the build's palette has no use for: whether to open with the
|
|
8
|
+
* logo, which `setup`, `import` and `--help` do.
|
|
9
|
+
*
|
|
10
|
+
* Whether to paint is `@zuke/core`'s {@link resolveOutputMode} — the same
|
|
11
|
+
* answer the build's own CLI and the executor get — so `ZUKE_PLAIN`, `--plain`,
|
|
12
|
+
* CI and a pipe mean the same thing here as in the build. Every method is the
|
|
13
|
+
* identity when output is not rich, which is what keeps the plain output
|
|
14
|
+
* exactly what it was before it had a rich form.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import { type OutputMode } from "@zuke/core";
|
|
19
|
+
import { type CliPaint as CorePaint } from "@zuke/core/render";
|
|
20
|
+
/** Core's palette, plus whether this command opens with the logo. */
|
|
21
|
+
export type CliPaint = CorePaint & {
|
|
22
|
+
/**
|
|
23
|
+
* Whether to open with the logo banner: off when plain output was asked for
|
|
24
|
+
* (`ZUKE_PLAIN` / `--plain`), which implies no banner, or when the banner
|
|
25
|
+
* itself was (`ZUKE_NO_BANNER`). A pipe or CI is not rich either, but nobody
|
|
26
|
+
* asked it to drop the banner.
|
|
27
|
+
*/
|
|
28
|
+
banner: boolean;
|
|
29
|
+
};
|
|
30
|
+
/** The identity palette: plain output, and every test's default. */
|
|
31
|
+
export declare const PLAIN_PAINT: CliPaint;
|
|
32
|
+
/**
|
|
33
|
+
* The palette for `mode`: core's, with `mode.banner` beside it. Colour follows
|
|
34
|
+
* `mode.color` on its own, so `NO_COLOR` keeps the glyphs and drops the escape
|
|
35
|
+
* codes.
|
|
36
|
+
*/
|
|
37
|
+
export declare function cliPaint(mode: OutputMode): CliPaint;
|
|
38
|
+
/**
|
|
39
|
+
* The palette for this invocation: an explicit `--plain`, else `ZUKE_PLAIN`,
|
|
40
|
+
* CI and whether stdout is a terminal, as {@link resolveOutputMode} reads them.
|
|
41
|
+
*/
|
|
42
|
+
export declare function invocationPaint(plain: boolean | undefined, isTerminal: (() => boolean) | undefined): CliPaint;
|
package/src/paint.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* How the global CLI paints its own output: `--version`, `--help`, and the
|
|
5
|
+
* status lines `setup`, `import` and `upgrade` print.
|
|
6
|
+
*
|
|
7
|
+
* The palette is `@zuke/core`'s — the one the build's own CLI is painted with,
|
|
8
|
+
* exported from `@zuke/core/render` — so the two cannot drift apart. The CLI
|
|
9
|
+
* adds one fact the build's palette has no use for: whether to open with the
|
|
10
|
+
* logo, which `setup`, `import` and `--help` do.
|
|
11
|
+
*
|
|
12
|
+
* Whether to paint is `@zuke/core`'s {@link resolveOutputMode} — the same
|
|
13
|
+
* answer the build's own CLI and the executor get — so `ZUKE_PLAIN`, `--plain`,
|
|
14
|
+
* CI and a pipe mean the same thing here as in the build. Every method is the
|
|
15
|
+
* identity when output is not rich, which is what keeps the plain output
|
|
16
|
+
* exactly what it was before it had a rich form.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import { resolveOutputMode } from "@zuke/core";
|
|
21
|
+
import { cliPaint as corePaint, PLAIN_PAINT as CORE_PLAIN, } from "@zuke/core/render";
|
|
22
|
+
/** The identity palette: plain output, and every test's default. */
|
|
23
|
+
export const PLAIN_PAINT = { ...CORE_PLAIN, banner: true };
|
|
24
|
+
/**
|
|
25
|
+
* The palette for `mode`: core's, with `mode.banner` beside it. Colour follows
|
|
26
|
+
* `mode.color` on its own, so `NO_COLOR` keeps the glyphs and drops the escape
|
|
27
|
+
* codes.
|
|
28
|
+
*/
|
|
29
|
+
export function cliPaint(mode) {
|
|
30
|
+
return { ...corePaint(mode), banner: mode.banner };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The palette for this invocation: an explicit `--plain`, else `ZUKE_PLAIN`,
|
|
34
|
+
* CI and whether stdout is a terminal, as {@link resolveOutputMode} reads them.
|
|
35
|
+
*/
|
|
36
|
+
export function invocationPaint(plain, isTerminal) {
|
|
37
|
+
return cliPaint(resolveOutputMode({ plain, isTerminal }));
|
|
38
|
+
}
|
package/src/project.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type BuildLocation, type BuildProbe } from "./dispatch.ts";
|
|
2
|
+
/**
|
|
3
|
+
* What the project commands reach outside the process, injectable so they
|
|
4
|
+
* are testable without a real `deno`.
|
|
5
|
+
*/
|
|
6
|
+
export interface ProjectHost {
|
|
7
|
+
/**
|
|
8
|
+
* What is at `path`, not following a link: a regular `file`, nothing
|
|
9
|
+
* (`missing`), or `other` — a directory, or a link, which a write would
|
|
10
|
+
* follow out of the project.
|
|
11
|
+
*/
|
|
12
|
+
entry(path: string): Promise<"file" | "missing" | "other">;
|
|
13
|
+
/** Read a text file, rejecting when it cannot be read. */
|
|
14
|
+
readText(path: string): Promise<string>;
|
|
15
|
+
/** Write a text file, replacing what is there. */
|
|
16
|
+
writeText(path: string, text: string): Promise<void>;
|
|
17
|
+
/** Remove a file. */
|
|
18
|
+
remove(path: string): Promise<void>;
|
|
19
|
+
/** Run `deno <denoArgs>` in `cwd`, returning its exit code. */
|
|
20
|
+
deno(denoArgs: string[], cwd: string): Promise<number>;
|
|
21
|
+
/** The version of the Deno that runs the command. */
|
|
22
|
+
denoVersion(): string;
|
|
23
|
+
}
|
|
24
|
+
/** The real {@link ProjectHost}: the file system, and `deno` in the root. */
|
|
25
|
+
export declare const defaultProjectHost: ProjectHost;
|
|
26
|
+
/**
|
|
27
|
+
* The project at or above `cwd`, through the trust gate: its root, and the
|
|
28
|
+
* build file its `zuke.json` names.
|
|
29
|
+
*
|
|
30
|
+
* Every caller works on the project's own Deno code — its build file, its
|
|
31
|
+
* `deno.json` and the lock beside them — so a build another SDK hosts, which
|
|
32
|
+
* has neither, is refused by name rather than handed to a `deno` command
|
|
33
|
+
* that fails on a missing build file or writes a `deno.json` nothing reads.
|
|
34
|
+
*
|
|
35
|
+
* @throws {Error} naming `command` when there is no project, when the trust
|
|
36
|
+
* gate refuses the one there is, or when it is a build another SDK hosts.
|
|
37
|
+
*/
|
|
38
|
+
export declare function projectLocation(cwd: string, probe: BuildProbe, command: string): Promise<BuildLocation>;
|
|
39
|
+
/** Flags accepted by the commands that resolve the build's module graph. */
|
|
40
|
+
export interface InstallFlags {
|
|
41
|
+
/**
|
|
42
|
+
* Entrypoints to resolve beside the build file — the other programs that share
|
|
43
|
+
* the lock, such as an app's own `main.ts`.
|
|
44
|
+
*/
|
|
45
|
+
entrypoints: string[];
|
|
46
|
+
/** Deno's `--minimum-dependency-age` value, when one was given. */
|
|
47
|
+
minDepAge?: string;
|
|
48
|
+
/** Report what would run, and change nothing. */
|
|
49
|
+
dryRun: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parse `relock`'s or `cache`'s arguments: further entrypoints, then
|
|
53
|
+
* `--min-dep-age <value>` (or `=<value>`) and `--dry-run`. Strict, so a
|
|
54
|
+
* mistyped option is refused rather than ignored by a command that rewrites
|
|
55
|
+
* the lock.
|
|
56
|
+
*
|
|
57
|
+
* @throws {Error} naming `command` on an unknown option or a missing value.
|
|
58
|
+
*/
|
|
59
|
+
export declare function parseInstallFlags(command: string, args: readonly string[]): InstallFlags;
|
|
60
|
+
/**
|
|
61
|
+
* The `deno install` argv that resolves the module graph of `build`, the
|
|
62
|
+
* project's build file — and any
|
|
63
|
+
* further entrypoints — into the lock, honouring `--min-dep-age` when one was
|
|
64
|
+
* given.
|
|
65
|
+
*
|
|
66
|
+
* @throws {Error} naming `command` when a `--min-dep-age` was given and Deno
|
|
67
|
+
* `denoVersion` does not accept the flag.
|
|
68
|
+
*/
|
|
69
|
+
export declare function installArgs(command: string, flags: InstallFlags, denoVersion: string, build: string): string[];
|
package/src/project.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Copyright (c) 2026 the Zuke contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* What the global CLI's project commands share: `relock`, `cache`, `add` and
|
|
5
|
+
* `remove` each run a `deno` command in the project root, so that working on
|
|
6
|
+
* a Zuke project needs only `zuke`.
|
|
7
|
+
*
|
|
8
|
+
* They are the CLI's own rather than the build's because they must work
|
|
9
|
+
* whatever core the project is on — including one too old, or too broken, to
|
|
10
|
+
* update itself. The project is found the way forwarding finds it, through
|
|
11
|
+
* the same trust gate.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
import { FileTasks, RuntimeTasks } from "@zuke/core";
|
|
16
|
+
import { spawnDeno } from "./deno_path.js";
|
|
17
|
+
import { locateBuild, } from "./dispatch.js";
|
|
18
|
+
import { acceptsMinimumDependencyAge } from "./upgrade.js";
|
|
19
|
+
/** The real {@link ProjectHost}: the file system, and `deno` in the root. */
|
|
20
|
+
export const defaultProjectHost = {
|
|
21
|
+
entry: async (path) => {
|
|
22
|
+
try {
|
|
23
|
+
return (await FileTasks.lstat(path)).isFile ? "file" : "other";
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (FileTasks.isNotFound(error))
|
|
27
|
+
return "missing";
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
readText: (path) => FileTasks.readText(path),
|
|
32
|
+
writeText: (path, text) => FileTasks.writeText(path, text),
|
|
33
|
+
remove: async (path) => {
|
|
34
|
+
await FileTasks.remove(path);
|
|
35
|
+
},
|
|
36
|
+
deno: async (denoArgs, cwd) => {
|
|
37
|
+
const child = spawnDeno(denoArgs, {
|
|
38
|
+
cwd,
|
|
39
|
+
stdin: "null",
|
|
40
|
+
stdout: "inherit",
|
|
41
|
+
stderr: "inherit",
|
|
42
|
+
});
|
|
43
|
+
return (await child.status).code;
|
|
44
|
+
},
|
|
45
|
+
// The cli runs on Deno, so the runtime is the Deno that runs the command.
|
|
46
|
+
denoVersion: () => RuntimeTasks.facts().version,
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The project at or above `cwd`, through the trust gate: its root, and the
|
|
50
|
+
* build file its `zuke.json` names.
|
|
51
|
+
*
|
|
52
|
+
* Every caller works on the project's own Deno code — its build file, its
|
|
53
|
+
* `deno.json` and the lock beside them — so a build another SDK hosts, which
|
|
54
|
+
* has neither, is refused by name rather than handed to a `deno` command
|
|
55
|
+
* that fails on a missing build file or writes a `deno.json` nothing reads.
|
|
56
|
+
*
|
|
57
|
+
* @throws {Error} naming `command` when there is no project, when the trust
|
|
58
|
+
* gate refuses the one there is, or when it is a build another SDK hosts.
|
|
59
|
+
*/
|
|
60
|
+
export async function projectLocation(cwd, probe, command) {
|
|
61
|
+
const location = await locateBuild(cwd, probe);
|
|
62
|
+
if (location === null) {
|
|
63
|
+
throw new Error(`zuke ${command}: no zuke.json in this directory or any parent, so ` +
|
|
64
|
+
"there is no project to work on.");
|
|
65
|
+
}
|
|
66
|
+
if (location.engine !== null) {
|
|
67
|
+
throw new Error(`zuke ${command}: the project at ${location.root} is a build another ` +
|
|
68
|
+
`SDK hosts, run on @zuke/engine ${location.engine}, with no ` +
|
|
69
|
+
`${location.build} or deno.json of its own to work on. Its tool ` +
|
|
70
|
+
"wrappers come with the SDK (zuke.tools in Python), and " +
|
|
71
|
+
"zuke upgrade --engine moves the engine it runs on.");
|
|
72
|
+
}
|
|
73
|
+
return location;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Parse `relock`'s or `cache`'s arguments: further entrypoints, then
|
|
77
|
+
* `--min-dep-age <value>` (or `=<value>`) and `--dry-run`. Strict, so a
|
|
78
|
+
* mistyped option is refused rather than ignored by a command that rewrites
|
|
79
|
+
* the lock.
|
|
80
|
+
*
|
|
81
|
+
* @throws {Error} naming `command` on an unknown option or a missing value.
|
|
82
|
+
*/
|
|
83
|
+
export function parseInstallFlags(command, args) {
|
|
84
|
+
const flags = { entrypoints: [], dryRun: false };
|
|
85
|
+
const missing = () => new Error(`zuke ${command}: --min-dep-age needs a value, such as 0 or P2D.`);
|
|
86
|
+
for (let i = 0; i < args.length; i++) {
|
|
87
|
+
const arg = args[i];
|
|
88
|
+
if (arg === "--dry-run") {
|
|
89
|
+
flags.dryRun = true;
|
|
90
|
+
}
|
|
91
|
+
else if (arg.startsWith("--min-dep-age=")) {
|
|
92
|
+
flags.minDepAge = arg.slice("--min-dep-age=".length);
|
|
93
|
+
if (flags.minDepAge === "")
|
|
94
|
+
throw missing();
|
|
95
|
+
}
|
|
96
|
+
else if (arg === "--min-dep-age") {
|
|
97
|
+
const value = args[i + 1];
|
|
98
|
+
if (value === undefined || value === "" || value.startsWith("-")) {
|
|
99
|
+
throw missing();
|
|
100
|
+
}
|
|
101
|
+
flags.minDepAge = value;
|
|
102
|
+
i++;
|
|
103
|
+
}
|
|
104
|
+
else if (!arg.startsWith("-")) {
|
|
105
|
+
flags.entrypoints.push(arg);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw new Error(`zuke ${command}: unknown option ${arg}. It takes further ` +
|
|
109
|
+
"entrypoints, --min-dep-age <value> and --dry-run.");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return flags;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The `deno install` argv that resolves the module graph of `build`, the
|
|
116
|
+
* project's build file — and any
|
|
117
|
+
* further entrypoints — into the lock, honouring `--min-dep-age` when one was
|
|
118
|
+
* given.
|
|
119
|
+
*
|
|
120
|
+
* @throws {Error} naming `command` when a `--min-dep-age` was given and Deno
|
|
121
|
+
* `denoVersion` does not accept the flag.
|
|
122
|
+
*/
|
|
123
|
+
export function installArgs(command, flags, denoVersion, build) {
|
|
124
|
+
const args = ["install", "--entrypoint", build, ...flags.entrypoints];
|
|
125
|
+
if (flags.minDepAge === undefined)
|
|
126
|
+
return args;
|
|
127
|
+
if (!acceptsMinimumDependencyAge(denoVersion)) {
|
|
128
|
+
throw new Error(`zuke ${command}: Deno ${denoVersion} does not accept ` +
|
|
129
|
+
"--minimum-dependency-age; upgrade Deno, or run without --min-dep-age.");
|
|
130
|
+
}
|
|
131
|
+
return [...args, `--minimum-dependency-age=${flags.minDepAge}`];
|
|
132
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** One step of an imported Python task, in the order it runs. */
|
|
2
|
+
export type PyStep =
|
|
3
|
+
/** A shell command line, translated by `segments`. */
|
|
4
|
+
{
|
|
5
|
+
readonly command: string;
|
|
6
|
+
}
|
|
7
|
+
/** An argv the task file already split (pdm's and rye's `cmd = [...]`). */
|
|
8
|
+
| {
|
|
9
|
+
readonly argv: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
/** What no command expresses, kept verbatim for a `TODO` comment. */
|
|
12
|
+
| {
|
|
13
|
+
readonly todo: string;
|
|
14
|
+
};
|
|
15
|
+
/** A task read from a `pyproject.toml`, before identifier normalisation. */
|
|
16
|
+
export interface PyTask {
|
|
17
|
+
/** The task's name, its key in the task table. */
|
|
18
|
+
readonly name: string;
|
|
19
|
+
/** Its commands, in order. */
|
|
20
|
+
readonly steps: readonly PyStep[];
|
|
21
|
+
/** Names of the other tasks it runs first, without repeats. */
|
|
22
|
+
readonly deps: readonly string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parse a `pyproject.toml` document into tasks, in declaration order, from
|
|
26
|
+
* the first task table it carries. No task table: no tasks.
|
|
27
|
+
*
|
|
28
|
+
* @throws {Error} naming the line, when the document is not TOML this reads.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parsePyproject(text: string): PyTask[];
|