@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.
- package/LICENSE +21 -0
- package/README.md +353 -2
- package/mod.d.ts +102 -0
- package/mod.js +931 -0
- package/package.json +35 -4
- package/src/binary_launcher.d.ts +49 -0
- package/src/binary_launcher.js +325 -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 +58 -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 +229 -0
- package/src/dispatch.js +549 -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 +405 -0
- package/src/launcher_shared.d.ts +25 -0
- package/src/launcher_shared.js +91 -0
- package/src/mcp_config.d.ts +71 -0
- package/src/mcp_config.js +96 -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/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 +18 -0
- package/src/records.js +31 -0
- package/src/relock.d.ts +11 -0
- package/src/relock.js +182 -0
- package/src/runtime_field.d.ts +15 -0
- package/src/runtime_field.js +29 -0
- package/src/setup.d.ts +259 -0
- package/src/setup.js +693 -0
- package/src/star.d.ts +44 -0
- package/src/star.js +100 -0
- package/src/starter.d.ts +64 -0
- package/src/starter.js +138 -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,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
|
+
}
|