@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
@@ -0,0 +1,187 @@
1
+ // Copyright (c) 2026 the Zuke contributors
2
+ // SPDX-License-Identifier: MIT
3
+ /**
4
+ * What `zuke --version` reports about the project it was run in. The rich
5
+ * panel it prints on a terminal is core's `versionPanel`, so it matches the
6
+ * build's own.
7
+ *
8
+ * The project's Zuke version is read from its `deno.lock` — the version the
9
+ * build actually resolves — rather than by running the build's own
10
+ * `--version`. Asking the build only works on a build whose core answers that
11
+ * flag, which is core 1.60.0 and later; on anything older it printed
12
+ * `Unknown flag "--version"`. The lock answers for every version, without
13
+ * spawning a process. Asking the build is kept only as the fallback for a
14
+ * project with no lock, or a lock that names no core.
15
+ *
16
+ * @module
17
+ */
18
+ import { absolutePath, lockedJsrSpecifiers } from "@zuke/core";
19
+ import { isRecord } from "./records.js";
20
+ import { DENO_CONFIG_FILES, LOCK_FILE } from "./dispatch.js";
21
+ /**
22
+ * `text` with its JSONC comments and trailing commas removed, so `JSON.parse`
23
+ * reads it. Deno reads `deno.json` and `deno.jsonc` alike as JSONC, and a
24
+ * comment is the usual reason for a `deno.jsonc`. Text inside a string is left
25
+ * alone, escapes included; anything this does not make valid stays invalid.
26
+ */
27
+ function stripJsonc(text) {
28
+ let out = "";
29
+ // A comma is held back until the next token shows whether it trails.
30
+ let comma = false;
31
+ let i = 0;
32
+ const emit = (token) => {
33
+ if (comma && token !== "}" && token !== "]")
34
+ out += ",";
35
+ comma = false;
36
+ out += token;
37
+ };
38
+ while (i < text.length) {
39
+ const ch = text[i];
40
+ if (ch === '"') {
41
+ let end = i + 1;
42
+ while (end < text.length && text[end] !== '"') {
43
+ end += text[end] === "\\" ? 2 : 1;
44
+ }
45
+ emit(text.slice(i, end + 1));
46
+ i = end + 1;
47
+ }
48
+ else if (text.startsWith("//", i)) {
49
+ const end = text.indexOf("\n", i);
50
+ i = end === -1 ? text.length : end;
51
+ }
52
+ else if (text.startsWith("/*", i)) {
53
+ const end = text.indexOf("*/", i + 2);
54
+ i = end === -1 ? text.length : end + 2;
55
+ }
56
+ else if (ch === ",") {
57
+ if (comma)
58
+ out += ",";
59
+ comma = true;
60
+ i++;
61
+ }
62
+ else if (/\s/.test(ch)) {
63
+ out += ch;
64
+ i++;
65
+ }
66
+ else {
67
+ emit(ch);
68
+ i++;
69
+ }
70
+ }
71
+ return comma ? `${out},` : out;
72
+ }
73
+ /**
74
+ * The text of the first of Deno's config files at `root` that can be read, in
75
+ * the order Deno prefers them (`deno.json`, then `deno.jsonc`), or
76
+ * `undefined` when there is none: the input {@link projectLockPath} takes.
77
+ */
78
+ export async function projectConfigText(readText, root) {
79
+ for (const name of DENO_CONFIG_FILES) {
80
+ try {
81
+ return await readText(`${root}/${name}`);
82
+ }
83
+ catch {
84
+ // Not there: try the next one Deno would.
85
+ }
86
+ }
87
+ return undefined;
88
+ }
89
+ /**
90
+ * The lockfile the project at `root` resolves through, from the text of its
91
+ * config (the first of `DENO_CONFIG_FILES` that exists, or `undefined` when
92
+ * there is none), or `null` when no lock can be read for it.
93
+ *
94
+ * It follows Deno's `lock` setting:
95
+ * - `false` disables the lock, and Deno then ignores any `deno.lock` left
96
+ * behind, so reading that file would report a version the build does not
97
+ * run. That is `null`.
98
+ * - A string, or an object's `path`, names the lockfile, relative to `root`
99
+ * unless it is absolute.
100
+ * - No setting, `true`, or an object without a `path` keeps `deno.lock`.
101
+ *
102
+ * Comments and trailing commas are read as Deno reads them. A config that is
103
+ * still not valid is a setting this cannot read, so it is also `null` rather
104
+ * than a guess; the caller then asks the build, as it does for a project with
105
+ * no lock.
106
+ */
107
+ export function projectLockPath(root, configText) {
108
+ if (configText === undefined)
109
+ return `${root}/${LOCK_FILE}`;
110
+ let config;
111
+ try {
112
+ config = JSON.parse(stripJsonc(configText));
113
+ }
114
+ catch {
115
+ return null;
116
+ }
117
+ const lock = isRecord(config) ? config.lock : undefined;
118
+ if (lock === false)
119
+ return null;
120
+ const path = typeof lock === "string"
121
+ ? lock
122
+ : isRecord(lock) && typeof lock.path === "string"
123
+ ? lock.path
124
+ : LOCK_FILE;
125
+ try {
126
+ return absolutePath(path).path;
127
+ }
128
+ catch {
129
+ return absolutePath(root, path).path;
130
+ }
131
+ }
132
+ /** The core package whose resolved version a project's lock is read for. */
133
+ const CORE_PACKAGE = "@zuke/core";
134
+ /**
135
+ * A release version: a numeric core with an optional prerelease and build.
136
+ * `zuke upgrade` checks the version it is asked for against it, and a lock's
137
+ * resolved core version must match it before it is printed.
138
+ */
139
+ export const VERSION_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
140
+ /**
141
+ * The `@zuke/core` versions a lock resolves, from its text: one entry per
142
+ * distinct version (a lock normally holds one, but several ranges can each
143
+ * resolve their own), in the order the lock lists them. Empty when the lock
144
+ * names no core, or is not a lock this can read.
145
+ *
146
+ * A resolved value that is not a release version is dropped rather than
147
+ * printed. The lock is the project's own file, and a value carrying a newline
148
+ * or a terminal escape sequence would otherwise reach the terminal as written,
149
+ * from a command that promises only to report a number.
150
+ */
151
+ export function lockedCoreVersions(lockText) {
152
+ const versions = lockedJsrSpecifiers(lockText)
153
+ .filter((entry) => entry.name === CORE_PACKAGE)
154
+ .map((entry) => entry.resolved)
155
+ .filter((version) => VERSION_PATTERN.test(version));
156
+ return [...new Set(versions)];
157
+ }
158
+ /**
159
+ * `path` with the home directory written `~`, for display: a project path is
160
+ * usually under home, and the prefix is the least informative part of it.
161
+ * Only a whole leading directory is replaced, so `/home/me2` stays as it is
162
+ * under `/home/me`.
163
+ *
164
+ * `path` is an {@link absolutePath} one (forward slashes, also on Windows), so
165
+ * `home` is normalised the same way before comparing, and compared without
166
+ * regard to case on Windows, whose paths are case-insensitive. A `home` that
167
+ * is not absolute names no prefix to strip.
168
+ */
169
+ export function homeRelative(path, home, windows) {
170
+ if (home === undefined)
171
+ return path;
172
+ let base;
173
+ try {
174
+ base = absolutePath(home).path;
175
+ }
176
+ catch {
177
+ return path;
178
+ }
179
+ if (base === "/" || /^[A-Za-z]:\/?$/.test(base))
180
+ return path;
181
+ const fold = (text) => windows ? text.toLowerCase() : text;
182
+ if (fold(path) === fold(base))
183
+ return "~";
184
+ return fold(path).startsWith(`${fold(base)}/`)
185
+ ? `~${path.slice(base.length)}`
186
+ : path;
187
+ }
package/zuke.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ // Copyright (c) 2026 the Zuke contributors
3
+ // SPDX-License-Identifier: MIT
4
+
5
+ import { RuntimeTasks } from "@zuke/core";
6
+ import { main } from "./mod.js";
7
+
8
+ RuntimeTasks.exit(await main(RuntimeTasks.args()));