@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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -2
  3. package/mod.d.ts +102 -0
  4. package/mod.js +931 -0
  5. package/package.json +35 -4
  6. package/src/binary_launcher.d.ts +49 -0
  7. package/src/binary_launcher.js +325 -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 +58 -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 +229 -0
  23. package/src/dispatch.js +549 -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 +405 -0
  36. package/src/launcher_shared.d.ts +25 -0
  37. package/src/launcher_shared.js +91 -0
  38. package/src/mcp_config.d.ts +71 -0
  39. package/src/mcp_config.js +96 -0
  40. package/src/node_launcher.d.ts +19 -0
  41. package/src/node_launcher.js +416 -0
  42. package/src/node_pin.d.ts +25 -0
  43. package/src/node_pin.js +30 -0
  44. package/src/output.d.ts +38 -0
  45. package/src/output.js +43 -0
  46. package/src/paint.d.ts +42 -0
  47. package/src/paint.js +38 -0
  48. package/src/project.d.ts +69 -0
  49. package/src/project.js +132 -0
  50. package/src/pyproject.d.ts +30 -0
  51. package/src/pyproject.js +156 -0
  52. package/src/python_build.d.ts +27 -0
  53. package/src/python_build.js +197 -0
  54. package/src/records.d.ts +18 -0
  55. package/src/records.js +31 -0
  56. package/src/relock.d.ts +11 -0
  57. package/src/relock.js +182 -0
  58. package/src/runtime_field.d.ts +15 -0
  59. package/src/runtime_field.js +29 -0
  60. package/src/setup.d.ts +259 -0
  61. package/src/setup.js +693 -0
  62. package/src/star.d.ts +44 -0
  63. package/src/star.js +100 -0
  64. package/src/starter.d.ts +64 -0
  65. package/src/starter.js +138 -0
  66. package/src/toml.d.ts +32 -0
  67. package/src/toml.js +354 -0
  68. package/src/translate.d.ts +69 -0
  69. package/src/translate.js +198 -0
  70. package/src/upgrade.d.ts +113 -0
  71. package/src/upgrade.js +344 -0
  72. package/src/version.d.ts +11 -0
  73. package/src/version.js +13 -0
  74. package/src/version_report.d.ts +55 -0
  75. package/src/version_report.js +187 -0
  76. package/zuke.js +8 -0
package/src/star.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The end-of-`setup` "star the repo" prompt: ask once, then help with the
3
+ * answer — star directly through an authenticated `gh`, fall back to opening
4
+ * the repository page in the browser, and fall back again to printing the URL.
5
+ * Every side effect sits behind {@link StarActions} so the flow is testable
6
+ * without a network, a `gh` install, or a browser.
7
+ *
8
+ * @module
9
+ */
10
+ import { BrowserTasks } from "@zuke/core";
11
+ import { GhTasks } from "@zuke/gh";
12
+ import type { SetupHost } from "./setup.ts";
13
+ import type { Prompter } from "../mod.ts";
14
+ /** The Zuke repository's home page. */
15
+ export declare const ZUKE_REPO_URL = "https://github.com/zuke-build/zuke";
16
+ /**
17
+ * The side effects behind {@link promptStar}, injectable so tests never spawn
18
+ * `gh` or a browser.
19
+ */
20
+ export interface StarActions {
21
+ /** Whether the `gh` CLI is installed and holds a login. */
22
+ ghAuthenticated(): Promise<boolean>;
23
+ /** Star the Zuke repository through `gh api`. */
24
+ starWithGh(): Promise<void>;
25
+ /** Open `url` in the default browser; `false` when it could not launch. */
26
+ openBrowser(url: string): Promise<boolean>;
27
+ }
28
+ /**
29
+ * Build the real {@link StarActions} over the given task functions. The
30
+ * parameters exist as seams — production uses the defaults ({@link GhTasks}
31
+ * and {@link BrowserTasks}); tests substitute fakes so no process is spawned.
32
+ */
33
+ export declare function realStarActions(runGh?: typeof GhTasks.run, apiGh?: typeof GhTasks.api, openUrl?: typeof BrowserTasks.open): StarActions;
34
+ /** The real {@link StarActions}, backed by `GhTasks` and `BrowserTasks`. */
35
+ export declare const defaultStarActions: StarActions;
36
+ /**
37
+ * Ask the user to star the Zuke repository and help with a yes. The `gh` login
38
+ * is probed *before* asking, so the question says what a yes will do: with an
39
+ * authenticated `gh`, that the star is placed on their behalf through it;
40
+ * without one, that the repository page opens in the browser (falling back to
41
+ * printing its URL). A "no" is respected silently, and no failure here ever
42
+ * fails the setup that just succeeded.
43
+ */
44
+ export declare function promptStar(host: SetupHost, prompter: Prompter, actions: StarActions): Promise<void>;
package/src/star.js ADDED
@@ -0,0 +1,100 @@
1
+ // Copyright (c) 2026 the Zuke contributors
2
+ // SPDX-License-Identifier: MIT
3
+ /**
4
+ * The end-of-`setup` "star the repo" prompt: ask once, then help with the
5
+ * answer — star directly through an authenticated `gh`, fall back to opening
6
+ * the repository page in the browser, and fall back again to printing the URL.
7
+ * Every side effect sits behind {@link StarActions} so the flow is testable
8
+ * without a network, a `gh` install, or a browser.
9
+ *
10
+ * @module
11
+ */
12
+ import { BrowserTasks } from "@zuke/core";
13
+ import { GhTasks } from "@zuke/gh";
14
+ /** The Zuke repository's home page. */
15
+ export const ZUKE_REPO_URL = "https://github.com/zuke-build/zuke";
16
+ /** The `gh api` endpoint that stars the Zuke repository for the caller. */
17
+ const STAR_ENDPOINT = "user/starred/zuke-build/zuke";
18
+ /**
19
+ * Build the real {@link StarActions} over the given task functions. The
20
+ * parameters exist as seams — production uses the defaults ({@link GhTasks}
21
+ * and {@link BrowserTasks}); tests substitute fakes so no process is spawned.
22
+ */
23
+ export function realStarActions(runGh = GhTasks.run, apiGh = GhTasks.api, openUrl = BrowserTasks.open) {
24
+ return {
25
+ async ghAuthenticated() {
26
+ try {
27
+ const output = await runGh((s) => s.command("auth", "status").quiet().noThrow());
28
+ return output.code === 0;
29
+ }
30
+ catch {
31
+ return false; // gh not installed (ToolNotFoundError) — use the browser.
32
+ }
33
+ },
34
+ async starWithGh() {
35
+ await apiGh(STAR_ENDPOINT, (s) => s.method("PUT").silent().quiet());
36
+ },
37
+ async openBrowser(url) {
38
+ try {
39
+ const output = await openUrl(url, (s) => s.quiet().noThrow());
40
+ return output.code === 0;
41
+ }
42
+ catch {
43
+ return false; // no opener on this system — fall back to the URL.
44
+ }
45
+ },
46
+ };
47
+ }
48
+ /** The real {@link StarActions}, backed by `GhTasks` and `BrowserTasks`. */
49
+ export const defaultStarActions = realStarActions();
50
+ /** Star through `gh`, reporting success; `false` sends the caller onward. */
51
+ async function starViaGh(host, actions) {
52
+ try {
53
+ await actions.starWithGh();
54
+ }
55
+ catch {
56
+ return false; // gh was there but the call failed (network, scope).
57
+ }
58
+ host.log("★ Starred zuke-build/zuke — thank you!");
59
+ return true;
60
+ }
61
+ /** Open the repo page, reporting success; `false` sends the caller onward. */
62
+ async function openRepoPage(host, actions) {
63
+ try {
64
+ if (!(await actions.openBrowser(ZUKE_REPO_URL)))
65
+ return false;
66
+ }
67
+ catch {
68
+ return false; // no opener on this system — fall back to the URL.
69
+ }
70
+ host.log(`Opened ${ZUKE_REPO_URL} — click “☆ Star”. Thank you!`);
71
+ return true;
72
+ }
73
+ /**
74
+ * Ask the user to star the Zuke repository and help with a yes. The `gh` login
75
+ * is probed *before* asking, so the question says what a yes will do: with an
76
+ * authenticated `gh`, that the star is placed on their behalf through it;
77
+ * without one, that the repository page opens in the browser (falling back to
78
+ * printing its URL). A "no" is respected silently, and no failure here ever
79
+ * fails the setup that just succeeded.
80
+ */
81
+ export async function promptStar(host, prompter, actions) {
82
+ let authed = false;
83
+ try {
84
+ authed = await actions.ghAuthenticated();
85
+ }
86
+ catch {
87
+ // A probe failure only means the browser path — never a failed setup.
88
+ }
89
+ const how = authed
90
+ ? "uses your gh login to star on your behalf"
91
+ : "opens the repo page in your browser";
92
+ if (!prompter.confirm(`Enjoying Zuke? Star zuke-build/zuke on GitHub? (${how})`)) {
93
+ return;
94
+ }
95
+ if (authed && (await starViaGh(host, actions)))
96
+ return;
97
+ if (await openRepoPage(host, actions))
98
+ return;
99
+ host.log(`Star Zuke at ${ZUKE_REPO_URL} — thank you!`);
100
+ }
@@ -0,0 +1,64 @@
1
+ import { type ProjectRuntime } from "./runtime_field.ts";
2
+ /**
3
+ * The `jsr:` dependency a scaffolded `deno.json` maps `@zuke/<name>` to.
4
+ *
5
+ * The caret major is what gets pinned: every Zuke package is 1.x on full
6
+ * semver, so `@^1` takes minors and patches and stops a future major from
7
+ * landing in a scaffolded build unannounced. One definition, so the starter
8
+ * build and `zuke import`'s generated one cannot drift apart on it.
9
+ */
10
+ export declare function zukeDependency(name: string): string;
11
+ /**
12
+ * The `package.json` dependency a Node project maps `@zuke/<name>` to: the npm
13
+ * package every Zuke package is also published as, behind an alias so the build
14
+ * imports the same bare specifier. The caret major is the one
15
+ * {@link zukeDependency} pins.
16
+ */
17
+ export declare function zukeNpmDependency(name: string): string;
18
+ /**
19
+ * The `deno.json` import map entries the starter build resolves through.
20
+ *
21
+ * The build imports `@zuke/core` by its **bare** specifier rather than writing
22
+ * `jsr:@zuke/core@^1` inline, because Deno's default lint set (the one that
23
+ * applies to a `deno.json` that does not configure `lint.rules`, which is
24
+ * exactly what `setup` writes) rejects an inline `jsr:` specifier under
25
+ * `no-import-prefix` — so a scaffold that inlined it failed `deno lint` on its
26
+ * own first file. The pin moves to the map instead; it is not lost.
27
+ */
28
+ export declare const STARTER_IMPORTS: Readonly<Record<string, string>>;
29
+ /** The starter `zuke.ts`, with the build class named `name`. */
30
+ export declare function starterBuild(name: string): string;
31
+ /**
32
+ * The starter `zuke.json` config. Its presence at the repository root is what
33
+ * `@zuke/core`'s `repoRoot()` walks up to find; the recorded `name` is the
34
+ * build class for reference, and `build` names the build file when it is not
35
+ * the default `zuke.ts`. A `runtime` other than Deno is recorded as the
36
+ * `runtime` field.
37
+ */
38
+ export declare function starterConfig(name: string, buildFile: string, runtime?: ProjectRuntime): string;
39
+ /** The build file `zuke setup --sdk python` writes, which `sdk.command` runs. */
40
+ export declare const PYTHON_BUILD_FILE = "build.py";
41
+ /**
42
+ * The `sdk.command` a Python scaffold's `zuke.json` names: `uv run` reads the
43
+ * inline script metadata atop {@link starterPythonBuild} and provides the
44
+ * `zuke` package, so the build runs with no project file of its own.
45
+ */
46
+ export declare const PYTHON_SDK_COMMAND: readonly string[];
47
+ /**
48
+ * The inline script metadata (PEP 723) every scaffolded `build.py` opens with,
49
+ * which makes `uv run build.py` install the `zuke` SDK by itself. Shared by
50
+ * {@link starterPythonBuild} and `zuke import`'s generated build.
51
+ */
52
+ export declare const PYTHON_SCRIPT_METADATA = "# /// script\n# requires-python = \">=3.12\"\n# dependencies = [\"zuke\"]\n# ///\n";
53
+ /**
54
+ * The starter `build.py`, the Python SDK's shape of {@link starterBuild}: the
55
+ * build class named `name`, a sample target and a `default`. The script
56
+ * metadata block makes `uv run build.py` install the SDK by itself.
57
+ */
58
+ export declare function starterPythonBuild(name: string): string;
59
+ /**
60
+ * The `zuke.json` of a build another SDK hosts: {@link starterConfig}'s
61
+ * `name`, the `sdk.command` that starts the worker, and the exact
62
+ * `@zuke/engine` release the launchers and the `zuke` command run it on.
63
+ */
64
+ export declare function starterSdkConfig(name: string, engine: string): string;
package/src/starter.js ADDED
@@ -0,0 +1,138 @@
1
+ // Copyright (c) 2026 the Zuke contributors
2
+ // SPDX-License-Identifier: MIT
3
+ /**
4
+ * The files `zuke setup` scaffolds from a template: the starter build and the
5
+ * repository-root marker. Kept apart from the scaffolder because the build
6
+ * template is source code for the user's project — its `console.log` runs in
7
+ * their build, not in this process — and the suite's check that nothing in
8
+ * this package writes to the console except its sink names this module as the
9
+ * one file that may look as if it does.
10
+ *
11
+ * @module
12
+ */
13
+ import { BUILD_FIELD, BUILD_FILE } from "./build_file.js";
14
+ import { RUNTIME_FIELD } from "./runtime_field.js";
15
+ /**
16
+ * The `jsr:` dependency a scaffolded `deno.json` maps `@zuke/<name>` to.
17
+ *
18
+ * The caret major is what gets pinned: every Zuke package is 1.x on full
19
+ * semver, so `@^1` takes minors and patches and stops a future major from
20
+ * landing in a scaffolded build unannounced. One definition, so the starter
21
+ * build and `zuke import`'s generated one cannot drift apart on it.
22
+ */
23
+ export function zukeDependency(name) {
24
+ return `jsr:@zuke/${name}@^1`;
25
+ }
26
+ /**
27
+ * The `package.json` dependency a Node project maps `@zuke/<name>` to: the npm
28
+ * package every Zuke package is also published as, behind an alias so the build
29
+ * imports the same bare specifier. The caret major is the one
30
+ * {@link zukeDependency} pins.
31
+ */
32
+ export function zukeNpmDependency(name) {
33
+ return `npm:@zuke-build/${name}@^1`;
34
+ }
35
+ /**
36
+ * The `deno.json` import map entries the starter build resolves through.
37
+ *
38
+ * The build imports `@zuke/core` by its **bare** specifier rather than writing
39
+ * `jsr:@zuke/core@^1` inline, because Deno's default lint set (the one that
40
+ * applies to a `deno.json` that does not configure `lint.rules`, which is
41
+ * exactly what `setup` writes) rejects an inline `jsr:` specifier under
42
+ * `no-import-prefix` — so a scaffold that inlined it failed `deno lint` on its
43
+ * own first file. The pin moves to the map instead; it is not lost.
44
+ */
45
+ export const STARTER_IMPORTS = {
46
+ "@zuke/core": zukeDependency("core"),
47
+ };
48
+ /** The starter `zuke.ts`, with the build class named `name`. */
49
+ export function starterBuild(name) {
50
+ return `import { Build, run, target } from "@zuke/core";
51
+
52
+ /** Your project's build. Run a target with \`./zuke <target>\`. */
53
+ class ${name} extends Build {
54
+ hello = target()
55
+ .description("A sample target — replace me with real work")
56
+ .executes(() => {
57
+ console.log("Hello from Zuke!");
58
+ });
59
+
60
+ // Convention: \`default\` runs when no target is named.
61
+ default = target()
62
+ .description("Default target")
63
+ .dependsOn(this.hello)
64
+ .executes(() => {});
65
+ }
66
+
67
+ await run(${name});
68
+ `;
69
+ }
70
+ /**
71
+ * The starter `zuke.json` config. Its presence at the repository root is what
72
+ * `@zuke/core`'s `repoRoot()` walks up to find; the recorded `name` is the
73
+ * build class for reference, and `build` names the build file when it is not
74
+ * the default `zuke.ts`. A `runtime` other than Deno is recorded as the
75
+ * `runtime` field.
76
+ */
77
+ export function starterConfig(name, buildFile, runtime = "deno") {
78
+ const build = buildFile === BUILD_FILE ? {} : { [BUILD_FIELD]: buildFile };
79
+ const on = runtime === "deno" ? {} : { [RUNTIME_FIELD]: runtime };
80
+ return `${JSON.stringify({ name, ...build, ...on }, null, 2)}\n`;
81
+ }
82
+ /** The build file `zuke setup --sdk python` writes, which `sdk.command` runs. */
83
+ export const PYTHON_BUILD_FILE = "build.py";
84
+ /**
85
+ * The `sdk.command` a Python scaffold's `zuke.json` names: `uv run` reads the
86
+ * inline script metadata atop {@link starterPythonBuild} and provides the
87
+ * `zuke` package, so the build runs with no project file of its own.
88
+ */
89
+ export const PYTHON_SDK_COMMAND = [
90
+ "uv",
91
+ "run",
92
+ PYTHON_BUILD_FILE,
93
+ ];
94
+ /**
95
+ * The inline script metadata (PEP 723) every scaffolded `build.py` opens with,
96
+ * which makes `uv run build.py` install the `zuke` SDK by itself. Shared by
97
+ * {@link starterPythonBuild} and `zuke import`'s generated build.
98
+ */
99
+ export const PYTHON_SCRIPT_METADATA = `# /// script
100
+ # requires-python = ">=3.12"
101
+ # dependencies = ["zuke"]
102
+ # ///
103
+ `;
104
+ /**
105
+ * The starter `build.py`, the Python SDK's shape of {@link starterBuild}: the
106
+ * build class named `name`, a sample target and a `default`. The script
107
+ * metadata block makes `uv run build.py` install the SDK by itself.
108
+ */
109
+ export function starterPythonBuild(name) {
110
+ return `${PYTHON_SCRIPT_METADATA}"""Your project's build. Run a target with ./zuke <target>."""
111
+
112
+ from zuke import Build, run, target
113
+
114
+
115
+ class ${name}(Build):
116
+ """The targets of this project."""
117
+
118
+ hello = (
119
+ target()
120
+ .description("A sample target, replace me with real work")
121
+ .executes(lambda ctx: ctx.log("Hello from Zuke!"))
122
+ )
123
+
124
+ # Convention: default runs when no target is named.
125
+ default = target().description("Default target").depends_on(hello)
126
+
127
+
128
+ run(${name})
129
+ `;
130
+ }
131
+ /**
132
+ * The `zuke.json` of a build another SDK hosts: {@link starterConfig}'s
133
+ * `name`, the `sdk.command` that starts the worker, and the exact
134
+ * `@zuke/engine` release the launchers and the `zuke` command run it on.
135
+ */
136
+ export function starterSdkConfig(name, engine) {
137
+ return `${JSON.stringify({ name, sdk: { command: PYTHON_SDK_COMMAND }, engine }, null, 2)}\n`;
138
+ }
package/src/toml.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * A strict reader for the subset of TOML that `zuke import` needs from a
3
+ * `pyproject.toml`, so the package stays dependency-free.
4
+ *
5
+ * Read: comments; `[table]` headers with bare, quoted and dotted keys
6
+ * (`[tool.hatch.envs."default".scripts]`); key/value pairs with bare, quoted
7
+ * and dotted keys; basic and literal strings, single- and multi-line
8
+ * (`"""`/`'''`, with the basic form's escapes and line-ending backslash);
9
+ * decimal integers and floats; booleans; arrays (multi-line, comments inside,
10
+ * trailing comma); and inline tables (newlines and a trailing comma tolerated,
11
+ * as TOML 1.1 allows).
12
+ *
13
+ * `[[array.of.tables]]` headers are parsed and their contents validated, but
14
+ * discarded: no task table is an array of tables, and skipping them keeps
15
+ * every `pyproject.toml` that carries a `[[tool.mypy.overrides]]` readable.
16
+ *
17
+ * Rejected, naming the line: dates and times, hexadecimal/octal/binary
18
+ * integers, `inf`/`nan`, a duplicate key, a table defined twice, a control
19
+ * character in a string, and anything else malformed.
20
+ *
21
+ * @module
22
+ */
23
+ /** A parsed TOML table: plain data, to be narrowed by the caller. */
24
+ type Table = Record<string, unknown>;
25
+ /**
26
+ * Parse `text` as TOML into plain data: tables are objects, arrays are arrays,
27
+ * strings, numbers and booleans are themselves.
28
+ *
29
+ * @throws {SyntaxError} naming the line of the first construct it cannot read.
30
+ */
31
+ export declare function parseToml(text: string): Table;
32
+ export {};