@zuke-build/cli 2.6.0 → 2.8.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/README.md +14 -1
- package/mod.d.ts +3 -0
- package/mod.js +39 -1
- package/package.json +1 -1
- package/src/binary_launcher.js +1 -3
- package/src/build_file.js +3 -10
- package/src/cache.d.ts +4 -0
- package/src/cache.js +18 -2
- package/src/deno_isolated.js +1 -1
- package/src/deno_path.d.ts +1 -1
- package/src/deno_path.js +7 -2
- package/src/dependencies.d.ts +17 -0
- package/src/dependencies.js +60 -11
- package/src/dispatch.d.ts +10 -1
- package/src/dispatch.js +13 -2
- package/src/launcher.js +3 -62
- package/src/launcher_shared.d.ts +25 -0
- package/src/launcher_shared.js +91 -0
- package/src/mcp_config.d.ts +8 -0
- package/src/mcp_config.js +10 -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/npm_path.d.ts +16 -0
- package/src/npm_path.js +78 -0
- package/src/project.d.ts +14 -1
- package/src/project.js +21 -4
- package/src/records.d.ts +12 -3
- package/src/records.js +21 -3
- package/src/relock.js +116 -59
- package/src/runtime_field.d.ts +15 -0
- package/src/runtime_field.js +29 -0
- package/src/setup.d.ts +8 -0
- package/src/setup.js +126 -29
- package/src/starter.d.ts +11 -2
- package/src/starter.js +15 -3
- package/src/version.js +1 -1
package/src/setup.js
CHANGED
|
@@ -9,15 +9,16 @@
|
|
|
9
9
|
* so the logic stays pure and unit-testable; {@link defaultHost} is the real
|
|
10
10
|
* `Deno`-backed implementation used in production.
|
|
11
11
|
*/
|
|
12
|
-
import { binaryMcpEntry, MCP_CONFIG_FILE, mcpServerEntry, mergeMcpConfig, parseMcpConfig, } from "./mcp_config.js";
|
|
13
|
-
import { FileTasks } from "@zuke/core";
|
|
12
|
+
import { binaryMcpEntry, MCP_CONFIG_FILE, mcpServerEntry, mergeMcpConfig, nodeMcpEntry, parseMcpConfig, } from "./mcp_config.js";
|
|
13
|
+
import { FileTasks, RuntimeTasks } from "@zuke/core";
|
|
14
14
|
import { isRecord } from "./records.js";
|
|
15
15
|
import { assertBuildFileName, BUILD_FILE, buildFileNamed, NEW_BUILD_FILE, } from "./build_file.js";
|
|
16
16
|
import { launcherBash, launcherPwsh } from "./launcher.js";
|
|
17
|
+
import { nodeLauncherBash, nodeLauncherPowerShell } from "./node_launcher.js";
|
|
17
18
|
import { binaryLauncherBash, binaryLauncherPwsh } from "./binary_launcher.js";
|
|
18
19
|
import { lstatOrNull } from "./fs.js";
|
|
19
20
|
import { output } from "./output.js";
|
|
20
|
-
import { PYTHON_BUILD_FILE, STARTER_IMPORTS, starterBuild, starterConfig, starterPythonBuild, starterSdkConfig, } from "./starter.js";
|
|
21
|
+
import { PYTHON_BUILD_FILE, STARTER_IMPORTS, starterBuild, starterConfig, starterPythonBuild, starterSdkConfig, zukeNpmDependency, } from "./starter.js";
|
|
21
22
|
// Re-exported so the merge guard keeps its historical home for importers.
|
|
22
23
|
export { isRecord };
|
|
23
24
|
/**
|
|
@@ -190,6 +191,11 @@ export const defaultHost = {
|
|
|
190
191
|
// pre-write check. The temporary name is created exclusively, so it cannot
|
|
191
192
|
// itself be a link someone left waiting.
|
|
192
193
|
const temp = `${path}.zuke-${crypto.randomUUID().slice(0, 8)}.tmp`;
|
|
194
|
+
// `--dir` may name a directory that is not there yet; every path written
|
|
195
|
+
// is that directory joined with a file name.
|
|
196
|
+
const parent = path.lastIndexOf("/");
|
|
197
|
+
if (parent > 0)
|
|
198
|
+
await FileTasks.createDirectory(path.slice(0, parent));
|
|
193
199
|
try {
|
|
194
200
|
await FileTasks.writeText(temp, content, (s) => s.createNew());
|
|
195
201
|
await FileTasks.move(temp, path);
|
|
@@ -221,6 +227,7 @@ const RESERVED_NON_LAUNCHER = new Set([
|
|
|
221
227
|
PYTHON_BUILD_FILE,
|
|
222
228
|
"zuke.json",
|
|
223
229
|
"deno.json",
|
|
230
|
+
"package.json",
|
|
224
231
|
".gitignore",
|
|
225
232
|
MCP_CONFIG_FILE,
|
|
226
233
|
]);
|
|
@@ -319,6 +326,11 @@ export async function runSetup(options, host = defaultHost) {
|
|
|
319
326
|
const notes = [];
|
|
320
327
|
const launcher = options.launcherName ?? DEFAULT_LAUNCHER;
|
|
321
328
|
const sdk = options.sdk;
|
|
329
|
+
const node = options.runtime === "node";
|
|
330
|
+
if (sdk !== undefined && node) {
|
|
331
|
+
throw new Error("zuke setup: --runtime picks the runtime of a TypeScript build; " +
|
|
332
|
+
"--sdk python builds run on the zuke binary.");
|
|
333
|
+
}
|
|
322
334
|
if (sdk !== undefined && options.buildFile !== undefined) {
|
|
323
335
|
throw new Error("zuke setup: --build-file names a TypeScript build file; a Python " +
|
|
324
336
|
`build is always ${PYTHON_BUILD_FILE}.`);
|
|
@@ -342,23 +354,27 @@ export async function runSetup(options, host = defaultHost) {
|
|
|
342
354
|
},
|
|
343
355
|
{
|
|
344
356
|
name: launcher,
|
|
345
|
-
content:
|
|
346
|
-
?
|
|
347
|
-
:
|
|
357
|
+
content: node
|
|
358
|
+
? nodeLauncherBash({ buildFile })
|
|
359
|
+
: sdk === undefined
|
|
360
|
+
? launcherBash(variant)
|
|
361
|
+
: binaryLauncherBash({ download: variant.bootstrapDeno }, sdk.pin),
|
|
348
362
|
mode: 0o755,
|
|
349
363
|
launcher: true,
|
|
350
364
|
},
|
|
351
365
|
{
|
|
352
366
|
name: `${launcher}.ps1`,
|
|
353
|
-
content:
|
|
354
|
-
?
|
|
355
|
-
:
|
|
367
|
+
content: node
|
|
368
|
+
? nodeLauncherPowerShell({ buildFile })
|
|
369
|
+
: sdk === undefined
|
|
370
|
+
? launcherPwsh(variant)
|
|
371
|
+
: binaryLauncherPwsh({ download: variant.bootstrapDeno }, sdk.pin),
|
|
356
372
|
launcher: true,
|
|
357
373
|
},
|
|
358
374
|
{
|
|
359
375
|
name: "zuke.json",
|
|
360
376
|
content: sdk === undefined
|
|
361
|
-
? starterConfig(options.name, buildFile)
|
|
377
|
+
? starterConfig(options.name, buildFile, options.runtime)
|
|
362
378
|
: starterSdkConfig(options.name, sdk.pin.engine),
|
|
363
379
|
},
|
|
364
380
|
];
|
|
@@ -368,7 +384,9 @@ export async function runSetup(options, host = defaultHost) {
|
|
|
368
384
|
// setup writes, including the separately-written deno.json and .gitignore.
|
|
369
385
|
const collisionTargets = [
|
|
370
386
|
...scaffold.map((s) => ({ name: s.name, launcher: s.launcher === true })),
|
|
371
|
-
...(sdk === undefined
|
|
387
|
+
...(sdk === undefined
|
|
388
|
+
? [{ name: node ? "package.json" : "deno.json", launcher: false }]
|
|
389
|
+
: []),
|
|
372
390
|
{ name: ".gitignore", launcher: false },
|
|
373
391
|
...(options.mcp ? [{ name: MCP_CONFIG_FILE, launcher: false }] : []),
|
|
374
392
|
];
|
|
@@ -418,18 +436,23 @@ export async function runSetup(options, host = defaultHost) {
|
|
|
418
436
|
host.log(` ${existed ? "update" : "create"} ${item.name}`);
|
|
419
437
|
files.push({ path: item.name, status });
|
|
420
438
|
}
|
|
421
|
-
if (
|
|
439
|
+
if (node) {
|
|
440
|
+
files.push(await setupPackageJson(options.dir, host, manualSteps, notes));
|
|
441
|
+
}
|
|
442
|
+
else if (sdk === undefined) {
|
|
422
443
|
files.push(await setupDenoJson(options.dir, options.imports ?? STARTER_IMPORTS, buildFile, host, manualSteps, notes));
|
|
423
444
|
}
|
|
424
|
-
files.push(await setupGitignore(options.dir, host));
|
|
445
|
+
files.push(await setupGitignore(options.dir, host, node ? [GITIGNORE_ENTRY, "node_modules/"] : [GITIGNORE_ENTRY]));
|
|
425
446
|
if (options.mcp) {
|
|
426
447
|
files.push(await setupMcpConfig(options.dir, options.force, host, notes,
|
|
427
448
|
// A hosted build is served by the zuke binary, whichever CLI
|
|
428
449
|
// registered it: its project needs nothing from Deno's stack. A
|
|
429
450
|
// TypeScript build stays on Deno.
|
|
430
|
-
|
|
431
|
-
?
|
|
432
|
-
:
|
|
451
|
+
node
|
|
452
|
+
? nodeMcpEntry(options.mcp.allowRun, buildFile)
|
|
453
|
+
: sdk === undefined
|
|
454
|
+
? mcpServerEntry(options.mcp.allowRun, buildFile)
|
|
455
|
+
: binaryMcpEntry(options.mcp.allowRun)));
|
|
433
456
|
}
|
|
434
457
|
return { files, manualSteps, notes };
|
|
435
458
|
}
|
|
@@ -470,24 +493,98 @@ async function setupMcpConfig(dir, force, host, notes, entry) {
|
|
|
470
493
|
}
|
|
471
494
|
/** The line `setup` ensures is present in `.gitignore` for generated output. */
|
|
472
495
|
const GITIGNORE_ENTRY = ".zuke/";
|
|
473
|
-
/**
|
|
474
|
-
|
|
496
|
+
/**
|
|
497
|
+
* Create or update `.gitignore` so every one of `entries` is ignored, adding
|
|
498
|
+
* only the lines it does not already have.
|
|
499
|
+
*/
|
|
500
|
+
async function setupGitignore(dir, host, entries) {
|
|
475
501
|
const name = ".gitignore";
|
|
476
502
|
const path = joinPath(dir, name);
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
if (before.split(/\r?\n/).some((line) => line.trim() === GITIGNORE_ENTRY)) {
|
|
484
|
-
host.log(` skip ${name} (${GITIGNORE_ENTRY} already ignored)`);
|
|
503
|
+
const exists = await host.exists(path);
|
|
504
|
+
const before = exists ? await host.readText(path) : "";
|
|
505
|
+
const lines = before.split(/\r?\n/).map((line) => line.trim());
|
|
506
|
+
const missing = entries.filter((entry) => !lines.includes(entry));
|
|
507
|
+
if (missing.length === 0) {
|
|
508
|
+
host.log(` skip ${name} (${entries.join(", ")} already ignored)`);
|
|
485
509
|
return { path: name, status: "skipped" };
|
|
486
510
|
}
|
|
487
511
|
const separator = before === "" || before.endsWith("\n") ? "" : "\n";
|
|
488
|
-
await host.writeText(path, `${before}${separator}${
|
|
489
|
-
host.log(` update ${name}`);
|
|
490
|
-
return { path: name, status: "overwritten" };
|
|
512
|
+
await host.writeText(path, `${before}${separator}${missing.join("\n")}\n`);
|
|
513
|
+
host.log(` ${exists ? "update" : "create"} ${name}`);
|
|
514
|
+
return { path: name, status: exists ? "overwritten" : "created" };
|
|
515
|
+
}
|
|
516
|
+
/** The name a new `package.json` takes: the project directory's, as npm spells one. */
|
|
517
|
+
function packageNameFor(dir) {
|
|
518
|
+
const last = (dir === "." ? RuntimeTasks.cwd() : dir).split(/[\\/]/).filter(Boolean)
|
|
519
|
+
.at(-1) ?? "";
|
|
520
|
+
const name = last.toLowerCase().replace(/[^a-z0-9._-]+/g, "-")
|
|
521
|
+
.replace(/^[._-]+/, "");
|
|
522
|
+
return name === "" ? "zuke-build" : name;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Create or merge `package.json` for a Node project: `type: module` and the
|
|
526
|
+
* `@zuke/core` dependency, each only when absent. A different `type` is kept
|
|
527
|
+
* and noted, since a CommonJS package cannot load the starter build; a file
|
|
528
|
+
* that is not JSON is left alone and reported as a manual step.
|
|
529
|
+
*/
|
|
530
|
+
async function setupPackageJson(dir, host, steps, notes) {
|
|
531
|
+
const name = "package.json";
|
|
532
|
+
const path = joinPath(dir, name);
|
|
533
|
+
const dependency = [
|
|
534
|
+
["@zuke/core", zukeNpmDependency("core")],
|
|
535
|
+
];
|
|
536
|
+
const exists = await host.exists(path);
|
|
537
|
+
const root = {};
|
|
538
|
+
let original = "";
|
|
539
|
+
if (exists) {
|
|
540
|
+
let parsed;
|
|
541
|
+
try {
|
|
542
|
+
parsed = JSON.parse(await host.readText(path));
|
|
543
|
+
}
|
|
544
|
+
catch {
|
|
545
|
+
parsed = undefined;
|
|
546
|
+
}
|
|
547
|
+
// Not JSON, or JSON that is not an object: either way not a manifest setup
|
|
548
|
+
// can merge into, so it is left exactly as it is.
|
|
549
|
+
if (!isRecord(parsed)) {
|
|
550
|
+
host.log(` skip ${name} (not a JSON object, edit by hand)`);
|
|
551
|
+
steps.push(`${path} is not a JSON object. Add "type": "module" and a dependency ` +
|
|
552
|
+
`"@zuke/core": "${dependency[0][1]}" — the scaffolded build will ` +
|
|
553
|
+
"not run until you do.");
|
|
554
|
+
return { path: name, status: "skipped" };
|
|
555
|
+
}
|
|
556
|
+
Object.assign(root, parsed);
|
|
557
|
+
original = JSON.stringify(root);
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
root.name = packageNameFor(dir);
|
|
561
|
+
root.private = true;
|
|
562
|
+
}
|
|
563
|
+
if (root.type === undefined)
|
|
564
|
+
root.type = "module";
|
|
565
|
+
else if (root.type !== "module") {
|
|
566
|
+
notes.push(`${path} has "type": ${JSON.stringify(root.type)}; setup kept it, but ` +
|
|
567
|
+
'the scaffolded build uses import syntax and needs "type": "module".');
|
|
568
|
+
}
|
|
569
|
+
const declared = root.dependencies;
|
|
570
|
+
const added = !(isRecord(declared) && dependency[0][0] in declared);
|
|
571
|
+
mergeMissing(root, "dependencies", dependency);
|
|
572
|
+
// The launcher runs npm ci, which refuses a lockfile that no longer matches
|
|
573
|
+
// package.json, so a dependency added beside an existing lock needs one
|
|
574
|
+
// npm install to record it.
|
|
575
|
+
const lock = joinPath(dir, "package-lock.json");
|
|
576
|
+
if (added && await host.exists(lock)) {
|
|
577
|
+
steps.push(`Run \`npm install --ignore-scripts\` in ${dir} once to add ` +
|
|
578
|
+
`${dependency[0][0]} to package-lock.json: ./zuke installs with ` +
|
|
579
|
+
"npm ci, which refuses a lockfile that does not match package.json.");
|
|
580
|
+
}
|
|
581
|
+
if (exists && JSON.stringify(root) === original) {
|
|
582
|
+
host.log(` skip ${name} (type and @zuke/core already declared)`);
|
|
583
|
+
return { path: name, status: "skipped" };
|
|
584
|
+
}
|
|
585
|
+
await host.writeText(path, `${JSON.stringify(root, null, 2)}\n`);
|
|
586
|
+
host.log(` ${exists ? "update" : "create"} ${name}`);
|
|
587
|
+
return { path: name, status: exists ? "overwritten" : "created" };
|
|
491
588
|
}
|
|
492
589
|
/** The `imports` entries `steps` tells the reader to add, as JSON lines. */
|
|
493
590
|
function importLines(imports) {
|
package/src/starter.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ProjectRuntime } from "./runtime_field.ts";
|
|
1
2
|
/**
|
|
2
3
|
* The `jsr:` dependency a scaffolded `deno.json` maps `@zuke/<name>` to.
|
|
3
4
|
*
|
|
@@ -7,6 +8,13 @@
|
|
|
7
8
|
* build and `zuke import`'s generated one cannot drift apart on it.
|
|
8
9
|
*/
|
|
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;
|
|
10
18
|
/**
|
|
11
19
|
* The `deno.json` import map entries the starter build resolves through.
|
|
12
20
|
*
|
|
@@ -24,9 +32,10 @@ export declare function starterBuild(name: string): string;
|
|
|
24
32
|
* The starter `zuke.json` config. Its presence at the repository root is what
|
|
25
33
|
* `@zuke/core`'s `repoRoot()` walks up to find; the recorded `name` is the
|
|
26
34
|
* build class for reference, and `build` names the build file when it is not
|
|
27
|
-
* the default `zuke.ts`.
|
|
35
|
+
* the default `zuke.ts`. A `runtime` other than Deno is recorded as the
|
|
36
|
+
* `runtime` field.
|
|
28
37
|
*/
|
|
29
|
-
export declare function starterConfig(name: string, buildFile: string): string;
|
|
38
|
+
export declare function starterConfig(name: string, buildFile: string, runtime?: ProjectRuntime): string;
|
|
30
39
|
/** The build file `zuke setup --sdk python` writes, which `sdk.command` runs. */
|
|
31
40
|
export declare const PYTHON_BUILD_FILE = "build.py";
|
|
32
41
|
/**
|
package/src/starter.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* @module
|
|
12
12
|
*/
|
|
13
13
|
import { BUILD_FIELD, BUILD_FILE } from "./build_file.js";
|
|
14
|
+
import { RUNTIME_FIELD } from "./runtime_field.js";
|
|
14
15
|
/**
|
|
15
16
|
* The `jsr:` dependency a scaffolded `deno.json` maps `@zuke/<name>` to.
|
|
16
17
|
*
|
|
@@ -22,6 +23,15 @@ import { BUILD_FIELD, BUILD_FILE } from "./build_file.js";
|
|
|
22
23
|
export function zukeDependency(name) {
|
|
23
24
|
return `jsr:@zuke/${name}@^1`;
|
|
24
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
|
+
}
|
|
25
35
|
/**
|
|
26
36
|
* The `deno.json` import map entries the starter build resolves through.
|
|
27
37
|
*
|
|
@@ -61,11 +71,13 @@ await run(${name});
|
|
|
61
71
|
* The starter `zuke.json` config. Its presence at the repository root is what
|
|
62
72
|
* `@zuke/core`'s `repoRoot()` walks up to find; the recorded `name` is the
|
|
63
73
|
* build class for reference, and `build` names the build file when it is not
|
|
64
|
-
* the default `zuke.ts`.
|
|
74
|
+
* the default `zuke.ts`. A `runtime` other than Deno is recorded as the
|
|
75
|
+
* `runtime` field.
|
|
65
76
|
*/
|
|
66
|
-
export function starterConfig(name, buildFile) {
|
|
77
|
+
export function starterConfig(name, buildFile, runtime = "deno") {
|
|
67
78
|
const build = buildFile === BUILD_FILE ? {} : { [BUILD_FIELD]: buildFile };
|
|
68
|
-
|
|
79
|
+
const on = runtime === "deno" ? {} : { [RUNTIME_FIELD]: runtime };
|
|
80
|
+
return `${JSON.stringify({ name, ...build, ...on }, null, 2)}\n`;
|
|
69
81
|
}
|
|
70
82
|
/** The build file `zuke setup --sdk python` writes, which `sdk.command` runs. */
|
|
71
83
|
export const PYTHON_BUILD_FILE = "build.py";
|
package/src/version.js
CHANGED