@zuke-build/cli 2.8.0 → 2.9.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 CHANGED
@@ -246,7 +246,7 @@ interface SetupFlags
246
246
  The SDK whose build to scaffold (`--sdk python`): a `build.py` the engine
247
247
  runs, in place of a `zuke.ts`. Unset: a TypeScript build.
248
248
  runtime?: string
249
- The runtime of a TypeScript build (`--runtime deno|node`). Unset: Deno, asked when interactive.
249
+ The runtime of a TypeScript build (`--runtime deno|node`). Unset: the project's own, else Node; asked when interactive.
250
250
  zuke?: string
251
251
  The `zuke` release an SDK build's launchers run (`--zuke`), whose engine
252
252
  `zuke.json` pins. Unset: this zuke's own release.
package/mod.d.ts CHANGED
@@ -62,7 +62,7 @@ export interface SetupFlags {
62
62
  * runs, in place of a `zuke.ts`. Unset: a TypeScript build.
63
63
  */
64
64
  sdk?: string;
65
- /** The runtime of a TypeScript build (`--runtime deno|node`). Unset: Deno, asked when interactive. */
65
+ /** The runtime of a TypeScript build (`--runtime deno|node`). Unset: the project's own, else Node; asked when interactive. */
66
66
  runtime?: string;
67
67
  /**
68
68
  * The `zuke` release an SDK build's launchers run (`--zuke`), whose engine
package/mod.js CHANGED
@@ -19,13 +19,13 @@
19
19
  */
20
20
  import { ConsoleTasks } from "@zuke/console";
21
21
  import { assertBuildFileName, NEW_BUILD_FILE } from "./src/build_file.js";
22
- import { defaultHost, existingBuildFile, runSetup, unrelatedBuildFile, } from "./src/setup.js";
22
+ import { defaultHost, existingBuildFile, existingRuntime, runSetup, unrelatedBuildFile, } from "./src/setup.js";
23
23
  import { runImport } from "./src/import.js";
24
24
  import { defaultStarActions, promptStar, } from "./src/star.js";
25
25
  import { VERSION } from "./src/version.js";
26
26
  import { installLabel, installSource, } from "./src/install_source.js";
27
27
  import { DENO_PIN } from "./src/deno_pin.js";
28
- import { buildLabel, defaultBuildProbe, defaultBuildRunner, embeddedEngineNotice, locateBuild, NO_LOCK_NOTICE, runBuild, runningNotice, servingEngine, } from "./src/dispatch.js";
28
+ import { buildLabel, defaultBuildProbe, defaultBuildRunner, DENO_SUPPORT_NOTICE, embeddedEngineNotice, locateBuild, NO_LOCK_NOTICE, owesDenoSupportNotice, runBuild, runningNotice, servingEngine, } from "./src/dispatch.js";
29
29
  import { absolutePath, logoLines, resolveDocSpec, RuntimeTasks, } from "@zuke/core";
30
30
  import { runDenoIsolated } from "./src/deno_isolated.js";
31
31
  import { defaultDenoHost, firstSet } from "./src/deno_path.js";
@@ -228,7 +228,8 @@ const SDK_BOOTSTRAP_QUESTION = "Launchers: download the pinned, checksum-verifie
228
228
  "use, rather than require zuke on PATH? [y/n]";
229
229
  /** The launcher question when the build's kind is not known yet (`import`). */
230
230
  const ANY_BOOTSTRAP_QUESTION = "Launchers: download their pinned, checksum-verified runtime (Deno for a " +
231
- "TypeScript build, zuke for a Python one) when it is missing? [y/n]";
231
+ "TypeScript build on Deno, zuke for a Python one; a Node build's always " +
232
+ "do) when it is missing? [y/n]";
232
233
  /**
233
234
  * Which launchers to scaffold. A flag decides outright; otherwise the wizard
234
235
  * asks `question` when it is interactive, and the default — bootstrap —
@@ -320,7 +321,8 @@ Setup options:
320
321
  --name <Class> Build class name (default: MyBuild)
321
322
  --build-file <name> TypeScript build file name (default: build.ts, or the project's own)
322
323
  --launcher-name <name> Launcher base name when a zuke/ directory is in the way
323
- --runtime deno|node Runtime of a TypeScript build (default: deno); node scaffolds a package.json and Node launchers
324
+ --runtime deno|node Runtime of a TypeScript build (default: node, or the project's own); node scaffolds a
325
+ package.json and Node launchers, and converts a Deno project in place
324
326
  --sdk python Scaffold a build.py and launchers that run the zuke binary (no Deno)
325
327
  --zuke <version> The zuke release those launchers run (default: this one)
326
328
  --mcp Also write .mcp.json registering the build's MCP server
@@ -336,6 +338,7 @@ Import options:
336
338
  --name <Class> Build class name (default: MyBuild)
337
339
  --from <source> Force a source: package.json, makefile or pyproject (default: auto-detect)
338
340
  --zuke <version> The zuke release a pyproject.toml import's launchers run (default: this one)
341
+ --runtime deno|node Runtime of a generated zuke.ts (default: node, or the project's own)
339
342
  --mcp Also write .mcp.json registering the build's MCP server
340
343
  --allow-run …with --allow-run, so an agent may execute targets (implies --mcp)
341
344
  --bootstrap Launchers download their pinned, checksum-verified runtime when missing (default):
@@ -433,6 +436,13 @@ async function askBuildFile(dir, suggested, host, prompter) {
433
436
  }
434
437
  throw new Error(refusal);
435
438
  }
439
+ /**
440
+ * The runtime `zuke setup` picks when `--runtime` does not: the project's
441
+ * own, so a re-run never converts it, and Node for a new project.
442
+ */
443
+ async function defaultRuntime(dir, host) {
444
+ return await existingRuntime(dir, host) ?? "node";
445
+ }
436
446
  /** Run the `setup` subcommand. */
437
447
  async function commandSetup(args, host, prompter, starActions, paint, upgradeHost) {
438
448
  const flags = parseSetupFlags(args);
@@ -458,13 +468,15 @@ async function commandSetup(args, host, prompter, starActions, paint, upgradeHos
458
468
  force = prompter.confirm("Overwrite existing files if present?");
459
469
  }
460
470
  if (sdk === undefined && runtime === undefined) {
461
- const answer = prompter.ask("Runtime (deno or node)", "deno").trim();
471
+ const answer = prompter.ask("Runtime (deno or node)", await defaultRuntime(dir, host)).trim();
462
472
  if (!isRuntime(answer)) {
463
473
  throw new Error(`zuke setup: unknown runtime "${answer}" — answer deno or node.`);
464
474
  }
465
475
  runtime = answer;
466
476
  }
467
477
  }
478
+ if (sdk === undefined)
479
+ runtime ??= await defaultRuntime(dir, host);
468
480
  // A Node launcher always bootstraps and names no Deno, so it is not asked.
469
481
  const bootstrapDeno = runtime === "node" ? undefined : resolveBootstrapDeno(flags, prompter, interactive, sdk === undefined ? BOOTSTRAP_QUESTION : SDK_BOOTSTRAP_QUESTION);
470
482
  const where = dir === "." ? "the current directory" : dir;
@@ -553,6 +565,9 @@ async function commandImport(args, host, prompter, paint, upgradeHost) {
553
565
  force = prompter.confirm("Overwrite existing files if present?");
554
566
  }
555
567
  }
568
+ // Like setup: the project's own runtime, else Node. A build.py ignores it.
569
+ const runtime = runtimeOption(flags.runtime) ??
570
+ await defaultRuntime(dir, host);
556
571
  const bootstrapDeno = resolveBootstrapDeno(flags, prompter, interactive, ANY_BOOTSTRAP_QUESTION);
557
572
  const result = await runImport({
558
573
  dir,
@@ -562,6 +577,7 @@ async function commandImport(args, host, prompter, paint, upgradeHost) {
562
577
  from: flags.from,
563
578
  mcp: mcpOption(flags),
564
579
  bootstrapDeno,
580
+ runtime,
565
581
  pin: () => binaryPin(flags, upgradeHost, "zuke import"),
566
582
  }, host);
567
583
  if (result.source === null) {
@@ -631,8 +647,12 @@ async function forwardToBuild(args, probe, runner, engine) {
631
647
  const fallback = embeddedEngineNotice(location, engine);
632
648
  if (fallback !== undefined)
633
649
  output.error(fallback);
634
- // A launcher has its own lockfile story to tell; only the bare `deno run`
635
- // it stands in for is this notice's to report.
650
+ // A launcher prints its own notices; the CLI says where a Deno build
651
+ // stands only when the launcher it goes through does not.
652
+ if (await owesDenoSupportNotice(location, probe)) {
653
+ output.error(DENO_SUPPORT_NOTICE);
654
+ }
655
+ // Only the bare `deno run` a launcher stands in for is this notice's.
636
656
  // A hosted build has no Deno config for Deno to write a lock into, so
637
657
  // the launchers say nothing there, and neither does this.
638
658
  if (location.launcher === null && !location.frozen &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuke-build/cli",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "description": "The zuke command-line tool — scaffold a Zuke project with `zuke setup`, including a starter build, launchers, and tasks.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/dispatch.d.ts CHANGED
@@ -201,6 +201,16 @@ export declare const NODE = "node";
201
201
  * or no launcher to go to, which {@link runBuild} refuses instead.
202
202
  */
203
203
  export declare function embeddedEngineNotice(location: BuildLocation, engine: EmbeddedEngine | undefined): string | undefined;
204
+ /** The launchers' notice for a build on Deno, verbatim. */
205
+ export declare const DENO_SUPPORT_NOTICE: string;
206
+ /**
207
+ * Whether `zuke` prints {@link DENO_SUPPORT_NOTICE} before running the build
208
+ * at `location`: a build on Deno that no launcher runs, or whose launcher
209
+ * was written before the launchers printed it themselves. A custom launcher
210
+ * that does not print it and calls `zuke` itself hears it twice. A build on Node,
211
+ * or one another SDK hosts, is told nothing.
212
+ */
213
+ export declare function owesDenoSupportNotice(location: BuildLocation, probe: BuildProbe): Promise<boolean>;
204
214
  /** The launchers' notice for a run without a lockfile, verbatim. */
205
215
  export declare const NO_LOCK_NOTICE: string;
206
216
  /**
package/src/dispatch.js CHANGED
@@ -44,7 +44,7 @@
44
44
  * @module
45
45
  */
46
46
  import { absolutePath, CONFIG_FILE, EnvTasks, FileTasks, ProcessTasks, RuntimeTasks, } from "@zuke/core";
47
- import { noLockNotice } from "./launcher.js";
47
+ import { denoSupportNotice, noLockNotice } from "./launcher.js";
48
48
  import { BINARY_INSTALL_DOCS } from "./binary_pin.js";
49
49
  import { BUILD_FILE, buildFileNamed } from "./build_file.js";
50
50
  import { runtimeNamed } from "./runtime_field.js";
@@ -465,6 +465,23 @@ export function embeddedEngineNotice(location, engine) {
465
465
  `run ${CONFIG_FILE}'s ${location.engine}, so the project's launcher ` +
466
466
  "runs it";
467
467
  }
468
+ /** The launchers' notice for a build on Deno, verbatim. */
469
+ export const DENO_SUPPORT_NOTICE = denoSupportNotice("—");
470
+ /**
471
+ * Whether `zuke` prints {@link DENO_SUPPORT_NOTICE} before running the build
472
+ * at `location`: a build on Deno that no launcher runs, or whose launcher
473
+ * was written before the launchers printed it themselves. A custom launcher
474
+ * that does not print it and calls `zuke` itself hears it twice. A build on Node,
475
+ * or one another SDK hosts, is told nothing.
476
+ */
477
+ export async function owesDenoSupportNotice(location, probe) {
478
+ if (location.engine !== null || location.runtime !== "deno")
479
+ return false;
480
+ // runBuild skips the launcher when this is a launcher's own call, or one
481
+ // inherited from a build a launcher started: then nothing else says it.
482
+ return location.launcher === null || !viaLauncher(location) ||
483
+ !(await probe.readText(location.launcher)).includes(DENO_SUPPORT_NOTICE);
484
+ }
468
485
  /** The launchers' notice for a run without a lockfile, verbatim. */
469
486
  export const NO_LOCK_NOTICE = noLockNotice("—");
470
487
  /**
package/src/import.d.ts CHANGED
@@ -22,6 +22,7 @@
22
22
  *
23
23
  * @module
24
24
  */
25
+ import type { ProjectRuntime } from "./runtime_field.ts";
25
26
  import type { BinaryPin } from "./binary_pin.ts";
26
27
  import { type McpSetupOptions, type ScaffoldImports, type SetupHost, type SetupResult } from "./setup.ts";
27
28
  /** A task discovered in an existing project, before identifier normalisation. */
@@ -104,6 +105,11 @@ export interface ImportOptions {
104
105
  mcp?: McpSetupOptions;
105
106
  /** Which launchers to scaffold (see {@link "./setup.ts".SetupOptions.bootstrapDeno}). */
106
107
  bootstrapDeno?: boolean;
108
+ /**
109
+ * The runtime a generated `zuke.ts` runs on (see
110
+ * {@link "./setup.ts".SetupOptions.runtime}); a `build.py` ignores it.
111
+ */
112
+ runtime?: ProjectRuntime;
107
113
  /**
108
114
  * Resolve the pin of the `zuke` release a Python build's launchers run,
109
115
  * whose engine its `zuke.json` pins. Called only when a `pyproject.toml` is
package/src/import.js CHANGED
@@ -271,6 +271,7 @@ export async function runImport(options, host) {
271
271
  imports: translation.imports,
272
272
  mcp: options.mcp,
273
273
  bootstrapDeno: options.bootstrapDeno,
274
+ runtime: translation.python ? undefined : options.runtime,
274
275
  sdk: translation.python ? { pin: await options.pin() } : undefined,
275
276
  }, host);
276
277
  return {
package/src/launcher.d.ts CHANGED
@@ -9,6 +9,12 @@ import { type DenoPin } from "./deno_pin.ts";
9
9
  * sources are kept ASCII).
10
10
  */
11
11
  export declare function noLockNotice(dash: string): string;
12
+ /**
13
+ * The line a build on Deno prints from its launcher, or from the CLI when it
14
+ * runs the build itself: how long Deno support is confirmed, and the command
15
+ * that moves the project to Node. `dash` as for {@link noLockNotice}.
16
+ */
17
+ export declare function denoSupportNotice(dash: string): string;
12
18
  export interface LauncherOptions {
13
19
  /**
14
20
  * Bootstrap a pinned, checksum-verified Deno when none is on `PATH`
package/src/launcher.js CHANGED
@@ -48,6 +48,15 @@ export function noLockNotice(dash) {
48
48
  return `zuke: no deno.lock here yet ${dash} running without lockfile ` +
49
49
  "verification so Deno can write one.";
50
50
  }
51
+ /**
52
+ * The line a build on Deno prints from its launcher, or from the CLI when it
53
+ * runs the build itself: how long Deno support is confirmed, and the command
54
+ * that moves the project to Node. `dash` as for {@link noLockNotice}.
55
+ */
56
+ export function denoSupportNotice(dash) {
57
+ return `zuke: builds on Deno are supported until October 2027 ${dash} run ` +
58
+ "zuke setup --runtime node to move this project to Node.";
59
+ }
51
60
  /** The build file a launcher with `options` runs, checked before it is written into a script. */
52
61
  function buildFileOf(options) {
53
62
  return assertBuildFileName(options.buildFile ?? BUILD_FILE);
@@ -239,6 +248,7 @@ ${bashResolveDeno(options, pin)}
239
248
  # then on --frozen fails the build if the module graph changed. Say so when
240
249
  # skipping, so a deleted lockfile downgrades verification visibly instead of
241
250
  # silently.
251
+ echo "${denoSupportNotice("—")}" >&2
242
252
  if [ -f deno.lock ]; then
243
253
  exec "$deno_bin" run -A --frozen ${build} "$@"
244
254
  else
@@ -392,10 +402,13 @@ ${pwshResolveDeno(options, pin)}
392
402
  # skipping, so a deleted lockfile downgrades verification visibly instead of
393
403
  # silently.
394
404
  $denoArgs = @("run", "-A")
405
+ # Both notices go to stderr: Write-Warning lands on stdout for a caller that
406
+ # ran this with -File, and stdout is the build's (--list --json, mcp).
407
+ [Console]::Error.WriteLine("${denoSupportNotice("-")}")
395
408
  if (Test-Path (Join-Path $dir "deno.lock")) {
396
409
  $denoArgs += "--frozen"
397
410
  } else {
398
- Write-Warning "${noLockNotice("-")}"
411
+ [Console]::Error.WriteLine("${noLockNotice("-")}")
399
412
  }
400
413
  $denoArgs += (Join-Path $dir "${build}")
401
414
  & $deno @denoArgs @args
@@ -55,6 +55,8 @@ export type McpConfig = {
55
55
  /** The text is not JSON. */
56
56
  state: "unparseable";
57
57
  };
58
+ /** Whether `value` is a well-formed server entry: a command and its arguments. */
59
+ export declare function isServerEntry(value: unknown): value is McpServerEntry;
58
60
  /**
59
61
  * Parse an `.mcp.json` text and classify its `zuke` entry. This is the only
60
62
  * place the text is parsed: {@link mergeMcpConfig} takes the document it
package/src/mcp_config.js CHANGED
@@ -55,7 +55,7 @@ export function nodeMcpEntry(allowRun, buildFile) {
55
55
  return { command: "node", args: [buildFile, ...mcpArgs(allowRun)] };
56
56
  }
57
57
  /** Whether `value` is a well-formed server entry: a command and its arguments. */
58
- function isServerEntry(value) {
58
+ export function isServerEntry(value) {
59
59
  return isRecord(value) && typeof value.command === "string" &&
60
60
  Array.isArray(value.args) &&
61
61
  value.args.every((arg) => typeof arg === "string");
package/src/records.d.ts CHANGED
@@ -16,3 +16,5 @@ export declare function isRecord(value: unknown): value is Record<string, unknow
16
16
  * whether the value it gets is valid.
17
17
  */
18
18
  export declare function forgivingField(text: string, field: string): unknown;
19
+ /** `text` parsed, when it is a JSON object; `undefined` otherwise. */
20
+ export declare function parsedRecord(text: string): Record<string, unknown> | undefined;
package/src/records.js CHANGED
@@ -20,12 +20,16 @@ export function isRecord(value) {
20
20
  * whether the value it gets is valid.
21
21
  */
22
22
  export function forgivingField(text, field) {
23
- let config;
23
+ return parsedRecord(text)?.[field];
24
+ }
25
+ /** `text` parsed, when it is a JSON object; `undefined` otherwise. */
26
+ export function parsedRecord(text) {
27
+ let parsed;
24
28
  try {
25
- config = JSON.parse(text);
29
+ parsed = JSON.parse(text);
26
30
  }
27
31
  catch {
28
32
  return undefined;
29
33
  }
30
- return isRecord(config) ? config[field] : undefined;
34
+ return isRecord(parsed) ? parsed : undefined;
31
35
  }
package/src/setup.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isRecord } from "./records.ts";
2
- import type { ProjectRuntime } from "./runtime_field.ts";
2
+ import { type ProjectRuntime } from "./runtime_field.ts";
3
3
  import type { BinaryPin } from "./binary_pin.ts";
4
4
  export { isRecord };
5
5
  /**
@@ -242,6 +242,14 @@ export declare const DEFAULT_LAUNCHER = "zuke";
242
242
  * @throws {Error} when `zuke.json` names a build file that is not a valid name.
243
243
  */
244
244
  export declare function existingBuildFile(dir: string, host: SetupHost): Promise<string | undefined>;
245
+ /**
246
+ * The runtime the TypeScript project in `dir` already runs on: the one its
247
+ * `zuke.json` names, Deno for one that names none or has a build file and no
248
+ * `zuke.json` yet. `undefined` for a new project.
249
+ *
250
+ * @throws {Error} when `zuke.json` names a runtime Zuke does not run on.
251
+ */
252
+ export declare function existingRuntime(dir: string, host: SetupHost): Promise<ProjectRuntime | undefined>;
245
253
  /**
246
254
  * Whether `name` in `dir` is a file of the project's own that is not a Zuke
247
255
  * build: it exists and does not import `@zuke/core`. A new project must not
package/src/setup.js CHANGED
@@ -9,12 +9,13 @@
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, nodeMcpEntry, parseMcpConfig, } from "./mcp_config.js";
12
+ import { binaryMcpEntry, isServerEntry, MCP_CONFIG_FILE, MCP_SERVER_NAME, mcpServerEntry, mergeMcpConfig, nodeMcpEntry, parseMcpConfig, } from "./mcp_config.js";
13
13
  import { FileTasks, RuntimeTasks } from "@zuke/core";
14
- import { isRecord } from "./records.js";
14
+ import { forgivingField, isRecord, parsedRecord } 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
17
  import { nodeLauncherBash, nodeLauncherPowerShell } from "./node_launcher.js";
18
+ import { runtimeNamed } from "./runtime_field.js";
18
19
  import { binaryLauncherBash, binaryLauncherPwsh } from "./binary_launcher.js";
19
20
  import { lstatOrNull } from "./fs.js";
20
21
  import { output } from "./output.js";
@@ -217,6 +218,8 @@ export const defaultHost = {
217
218
  export function joinPath(dir, name) {
218
219
  return dir === "." ? name : `${dir}/${name}`;
219
220
  }
221
+ /** The line every launcher setup writes opens its description with. */
222
+ const ZUKE_LAUNCHER = /^# Zuke (?:bootstrap )?launcher\b/m;
220
223
  /** The default launcher base name. */
221
224
  export const DEFAULT_LAUNCHER = "zuke";
222
225
  /**
@@ -267,6 +270,30 @@ export async function existingBuildFile(dir, host) {
267
270
  }
268
271
  return await host.exists(joinPath(dir, BUILD_FILE)) ? BUILD_FILE : undefined;
269
272
  }
273
+ /**
274
+ * Whether the project in `dir` is one another SDK hosts: its `zuke.json`
275
+ * names an `sdk`. A `zuke.json` that is a link is not read.
276
+ */
277
+ async function hostedBySdk(dir, host) {
278
+ const config = joinPath(dir, "zuke.json");
279
+ return await host.exists(config) && !(await host.isSymlink(config)) &&
280
+ forgivingField(await host.readText(config), "sdk") !== undefined;
281
+ }
282
+ /**
283
+ * The runtime the TypeScript project in `dir` already runs on: the one its
284
+ * `zuke.json` names, Deno for one that names none or has a build file and no
285
+ * `zuke.json` yet. `undefined` for a new project.
286
+ *
287
+ * @throws {Error} when `zuke.json` names a runtime Zuke does not run on.
288
+ */
289
+ export async function existingRuntime(dir, host) {
290
+ if (await existingBuildFile(dir, host) === undefined)
291
+ return undefined;
292
+ const config = joinPath(dir, "zuke.json");
293
+ return await host.exists(config) && !(await host.isSymlink(config))
294
+ ? runtimeNamed(await host.readText(config))
295
+ : "deno";
296
+ }
270
297
  /**
271
298
  * Whether `name` in `dir` is a file of the project's own that is not a Zuke
272
299
  * build: it exists and does not import `@zuke/core`. A new project must not
@@ -331,6 +358,22 @@ export async function runSetup(options, host = defaultHost) {
331
358
  throw new Error("zuke setup: --runtime picks the runtime of a TypeScript build; " +
332
359
  "--sdk python builds run on the zuke binary.");
333
360
  }
361
+ if (sdk === undefined && await hostedBySdk(options.dir, host)) {
362
+ throw new Error("zuke setup: this project's build is hosted by another SDK (zuke.json " +
363
+ 'names an "sdk"), so it has no TypeScript build to scaffold. Re-run ' +
364
+ "with --sdk python.");
365
+ }
366
+ const was = sdk === undefined
367
+ ? await existingRuntime(options.dir, host)
368
+ : undefined;
369
+ if (was === "node" && !node) {
370
+ throw new Error("zuke setup: this project's build runs on Node (zuke.json's " +
371
+ '"runtime": "node"); setup does not move it back to Deno.');
372
+ }
373
+ // A Deno project asked for Node is converted in place: its launchers and
374
+ // zuke.json are rewritten whether or not --force is given, since that is
375
+ // what the conversion is, and its build file and deno.json are kept.
376
+ const converting = node && was === "deno";
334
377
  if (sdk !== undefined && options.buildFile !== undefined) {
335
378
  throw new Error("zuke setup: --build-file names a TypeScript build file; a Python " +
336
379
  `build is always ${PYTHON_BUILD_FILE}.`);
@@ -361,6 +404,7 @@ export async function runSetup(options, host = defaultHost) {
361
404
  : binaryLauncherBash({ download: variant.bootstrapDeno }, sdk.pin),
362
405
  mode: 0o755,
363
406
  launcher: true,
407
+ converted: converting,
364
408
  },
365
409
  {
366
410
  name: `${launcher}.ps1`,
@@ -370,12 +414,16 @@ export async function runSetup(options, host = defaultHost) {
370
414
  ? launcherPwsh(variant)
371
415
  : binaryLauncherPwsh({ download: variant.bootstrapDeno }, sdk.pin),
372
416
  launcher: true,
417
+ converted: converting,
373
418
  },
374
419
  {
375
420
  name: "zuke.json",
376
- content: sdk === undefined
377
- ? starterConfig(options.name, buildFile, options.runtime)
378
- : starterSdkConfig(options.name, sdk.pin.engine),
421
+ content: converting
422
+ ? await convertedConfig(options.dir, options.name, buildFile, host)
423
+ : sdk === undefined
424
+ ? starterConfig(options.name, buildFile, options.runtime)
425
+ : starterSdkConfig(options.name, sdk.pin.engine),
426
+ converted: converting,
379
427
  },
380
428
  ];
381
429
  // Fail before writing anything if a target name is occupied by a directory —
@@ -387,8 +435,12 @@ export async function runSetup(options, host = defaultHost) {
387
435
  ...(sdk === undefined
388
436
  ? [{ name: node ? "package.json" : "deno.json", launcher: false }]
389
437
  : []),
438
+ // A conversion reads deno.json's imports, so it is held to the same rule.
439
+ ...(converting ? [{ name: "deno.json", launcher: false }] : []),
390
440
  { name: ".gitignore", launcher: false },
391
- ...(options.mcp ? [{ name: MCP_CONFIG_FILE, launcher: false }] : []),
441
+ ...(options.mcp || converting
442
+ ? [{ name: MCP_CONFIG_FILE, launcher: false }]
443
+ : []),
392
444
  ];
393
445
  for (const item of collisionTargets) {
394
446
  const path = joinPath(options.dir, item.name);
@@ -418,7 +470,11 @@ export async function runSetup(options, host = defaultHost) {
418
470
  for (const item of scaffold) {
419
471
  const path = joinPath(options.dir, item.name);
420
472
  const existed = await host.exists(path);
421
- if (existed && !options.force) {
473
+ // A conversion rewrites zuke.json, and a launcher only when what is there
474
+ // is one of Zuke's: a file of the project's own at that name is kept.
475
+ const rewrite = existed && item.converted === true &&
476
+ (item.launcher !== true || ZUKE_LAUNCHER.test(await host.readText(path)));
477
+ if (existed && !options.force && !rewrite) {
422
478
  host.log(` skip ${item.name} (already exists)`);
423
479
  files.push({ path: item.name, status: "skipped" });
424
480
  continue;
@@ -437,11 +493,27 @@ export async function runSetup(options, host = defaultHost) {
437
493
  files.push({ path: item.name, status });
438
494
  }
439
495
  if (node) {
440
- files.push(await setupPackageJson(options.dir, host, manualSteps, notes));
496
+ // What the build file imports, plus, when converting, what the Deno
497
+ // project already declared: an imported build brings its own imports.
498
+ const declared = npmDependencies(Object.keys(options.imports ?? STARTER_IMPORTS));
499
+ const dependencies = converting
500
+ ? [
501
+ ...new Map([
502
+ ...declared,
503
+ ...await convertedDependencies(options.dir, buildFile, host, manualSteps, notes),
504
+ ]),
505
+ ]
506
+ : declared;
507
+ files.push(await setupPackageJson(options.dir, dependencies, host, manualSteps, notes));
441
508
  }
442
509
  else if (sdk === undefined) {
443
510
  files.push(await setupDenoJson(options.dir, options.imports ?? STARTER_IMPORTS, buildFile, host, manualSteps, notes));
444
511
  }
512
+ if (converting) {
513
+ const mcp = await convertMcpConfig(options.dir, buildFile, host, notes);
514
+ if (mcp !== undefined)
515
+ files.push(mcp);
516
+ }
445
517
  files.push(await setupGitignore(options.dir, host, node ? [GITIGNORE_ENTRY, "node_modules/"] : [GITIGNORE_ENTRY]));
446
518
  if (options.mcp) {
447
519
  files.push(await setupMcpConfig(options.dir, options.force, host, notes,
@@ -491,6 +563,48 @@ async function setupMcpConfig(dir, force, host, notes, entry) {
491
563
  host.log(` update ${name}`);
492
564
  return { path: name, status: "overwritten" };
493
565
  }
566
+ /**
567
+ * Point the `zuke` server of a converted project's `.mcp.json` at Node: an
568
+ * entry that runs the build file with `deno run` becomes `node`, keeping the
569
+ * arguments after the build file. Any other entry is the project's own and is
570
+ * left alone with a note; a project with no `.mcp.json`, or no `zuke` server
571
+ * in it, has nothing to convert.
572
+ */
573
+ async function convertMcpConfig(dir, buildFile, host, notes) {
574
+ const name = MCP_CONFIG_FILE;
575
+ const path = joinPath(dir, name);
576
+ if (!(await host.exists(path)))
577
+ return undefined;
578
+ const config = parseMcpConfig(await host.readText(path));
579
+ if (config.state === "unparseable") {
580
+ notes.push(`${path} could not be parsed, so its zuke server was not moved to ` +
581
+ `Node. Point it at node ${buildFile} mcp by hand.`);
582
+ return undefined;
583
+ }
584
+ const servers = config.document.mcpServers;
585
+ const entry = isRecord(servers) ? servers[MCP_SERVER_NAME] : undefined;
586
+ // A bare deno, a path to one, or deno.exe.
587
+ if (!isServerEntry(entry) || !/(?:^|[\\/])deno(?:\.exe)?$/i.test(entry.command)) {
588
+ return undefined;
589
+ }
590
+ // Only the form setup writes: any other Deno option, such as --env-file,
591
+ // has meaning Node would lose, so that entry is the user's to move.
592
+ const [run, all, file, ...rest] = entry.args;
593
+ if (run !== "run" || !["-A", "--allow-all"].includes(all) || file !== buildFile) {
594
+ notes.push(`${path}'s zuke server runs deno in a way setup does not recognise, ` +
595
+ `so it was kept. Point it at node ${buildFile} mcp by hand.`);
596
+ return undefined;
597
+ }
598
+ await host.writeText(path,
599
+ // The entry's own keys (env, cwd, type) are the user's, and kept.
600
+ mergeMcpConfig(config.document, {
601
+ ...entry,
602
+ command: "node",
603
+ args: [buildFile, ...rest],
604
+ }));
605
+ host.log(` update ${name}`);
606
+ return { path: name, status: "overwritten" };
607
+ }
494
608
  /** The line `setup` ensures is present in `.gitignore` for generated output. */
495
609
  const GITIGNORE_ENTRY = ".zuke/";
496
610
  /**
@@ -521,35 +635,105 @@ function packageNameFor(dir) {
521
635
  .replace(/^[._-]+/, "");
522
636
  return name === "" ? "zuke-build" : name;
523
637
  }
638
+ /** The dependency every Node build has: `@zuke/core`, through its npm alias. */
639
+ const STARTER_NPM_DEPENDENCY = [
640
+ "@zuke/core",
641
+ zukeNpmDependency("core"),
642
+ ];
643
+ /** A Zuke package's bare specifier, `@zuke/<name>`, without a subpath. */
644
+ const ZUKE_PACKAGE = /^@zuke\/([a-z0-9][a-z0-9-]*)$/;
645
+ /** An inline `jsr:@zuke/<name>` specifier, with or without a version and subpath. */
646
+ const INLINE_ZUKE_JSR = /["']jsr:@zuke\/([a-z0-9][a-z0-9-]*)(?:@[^"'/]*)?(?:\/[^"']*)?["']/g;
647
+ /** The npm alias of each `@zuke/<name>` among `specifiers`; others are dropped. */
648
+ function npmDependencies(specifiers) {
649
+ return specifiers.flatMap((specifier) => {
650
+ const zuke = ZUKE_PACKAGE.exec(specifier);
651
+ return zuke === null ? [] : [[specifier, zukeNpmDependency(zuke[1])]];
652
+ });
653
+ }
654
+ /**
655
+ * The `zuke.json` of the Deno project in `dir`, converted to Node: its own
656
+ * fields, with `"runtime": "node"`. A project with no `zuke.json` yet gets
657
+ * none of its own, so it gets the starter one.
658
+ *
659
+ * @throws {Error} when `zuke.json` is a link, which setup never reads or
660
+ * writes through, or not a JSON object, which nothing can merge into without
661
+ * losing it.
662
+ */
663
+ async function convertedConfig(dir, name, buildFile, host) {
664
+ const path = joinPath(dir, "zuke.json");
665
+ if (!(await host.exists(path)))
666
+ return starterConfig(name, buildFile, "node");
667
+ if (await host.isSymlink(path)) {
668
+ throw new Error(`zuke setup: refusing to convert ${path} — it is a symbolic link. ` +
669
+ "Replace it with a regular file, then re-run setup.");
670
+ }
671
+ const parsed = parsedRecord(await host.readText(path));
672
+ if (parsed === undefined) {
673
+ throw new Error(`zuke setup: ${path} is not a JSON object, so it cannot be converted ` +
674
+ 'to Node. Fix it, or add "runtime": "node" to it by hand.');
675
+ }
676
+ return `${JSON.stringify({ ...parsed, runtime: "node" }, null, 2)}\n`;
677
+ }
524
678
  /**
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.
679
+ * The dependencies a Deno project converted to Node declares in
680
+ * `package.json`: `@zuke/core`, and the npm alias of every other `@zuke/*`
681
+ * package its `deno.json` imports. What else `deno.json` imports is named in
682
+ * a note, since npm cannot install it under that name; a build file that
683
+ * still imports a `jsr:` specifier is a manual step, since Node cannot load
684
+ * one.
529
685
  */
530
- async function setupPackageJson(dir, host, steps, notes) {
686
+ async function convertedDependencies(dir, buildFile, host, steps, notes) {
687
+ const build = joinPath(dir, buildFile);
688
+ const source = await host.readText(build);
689
+ // A build that inlines its jsr: specifiers declares them nowhere else.
690
+ const inlined = [...source.matchAll(INLINE_ZUKE_JSR)].map((m) => `@zuke/${m[1]}`);
691
+ const dependencies = new Map([
692
+ STARTER_NPM_DEPENDENCY,
693
+ ...npmDependencies(inlined),
694
+ ]);
695
+ const denoJson = joinPath(dir, "deno.json");
696
+ if (await host.exists(denoJson)) {
697
+ const imports = parsedRecord(await host.readText(denoJson))?.imports;
698
+ const others = [];
699
+ for (const specifier of isRecord(imports) ? Object.keys(imports) : []) {
700
+ const [dependency] = npmDependencies([specifier]);
701
+ if (dependency === undefined)
702
+ others.push(specifier);
703
+ else
704
+ dependencies.set(...dependency);
705
+ }
706
+ notes.push(`${denoJson} is kept, but the build no longer reads it on Node. ` +
707
+ (others.length === 0
708
+ ? "Remove it once nothing else uses it."
709
+ : `If ${buildFile} imports ${others.join(", ")}, add an npm equivalent to package.json.`));
710
+ }
711
+ if (/["']jsr:/.test(source)) {
712
+ steps.push(`${build} imports a jsr: specifier, which Node cannot load. Import ` +
713
+ "@zuke/* by bare specifier instead, as package.json declares it.");
714
+ }
715
+ return [...dependencies];
716
+ }
717
+ /**
718
+ * Create or merge `package.json` for a Node project: `type: module` and
719
+ * `dependencies`, each only when absent. A different `type` is kept and
720
+ * noted, since a CommonJS package cannot load the starter build; a file that
721
+ * is not JSON is left alone and reported as a manual step.
722
+ */
723
+ async function setupPackageJson(dir, dependency, host, steps, notes) {
531
724
  const name = "package.json";
532
725
  const path = joinPath(dir, name);
533
- const dependency = [
534
- ["@zuke/core", zukeNpmDependency("core")],
535
- ];
536
726
  const exists = await host.exists(path);
537
727
  const root = {};
538
728
  let original = "";
539
729
  if (exists) {
540
- let parsed;
541
- try {
542
- parsed = JSON.parse(await host.readText(path));
543
- }
544
- catch {
545
- parsed = undefined;
546
- }
730
+ const parsed = parsedRecord(await host.readText(path));
547
731
  // Not JSON, or JSON that is not an object: either way not a manifest setup
548
732
  // can merge into, so it is left exactly as it is.
549
- if (!isRecord(parsed)) {
733
+ if (parsed === undefined) {
550
734
  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 ` +
735
+ steps.push(`${path} is not a JSON object. Add "type": "module" and the ` +
736
+ `dependencies ${npmDependencyLines(dependency)} — the build will ` +
553
737
  "not run until you do.");
554
738
  return { path: name, status: "skipped" };
555
739
  }
@@ -567,25 +751,30 @@ async function setupPackageJson(dir, host, steps, notes) {
567
751
  'the scaffolded build uses import syntax and needs "type": "module".');
568
752
  }
569
753
  const declared = root.dependencies;
570
- const added = !(isRecord(declared) && dependency[0][0] in declared);
754
+ const added = dependency.filter(([dep]) => !(isRecord(declared) && dep in declared));
571
755
  mergeMissing(root, "dependencies", dependency);
572
756
  // The launcher runs npm ci, which refuses a lockfile that no longer matches
573
757
  // package.json, so a dependency added beside an existing lock needs one
574
758
  // npm install to record it.
575
759
  const lock = joinPath(dir, "package-lock.json");
576
- if (added && await host.exists(lock)) {
760
+ if (added.length > 0 && await host.exists(lock)) {
577
761
  steps.push(`Run \`npm install --ignore-scripts\` in ${dir} once to add ` +
578
- `${dependency[0][0]} to package-lock.json: ./zuke installs with ` +
762
+ `${added.map(([dep]) => dep).join(", ")} to package-lock.json: ` +
763
+ "./zuke installs with " +
579
764
  "npm ci, which refuses a lockfile that does not match package.json.");
580
765
  }
581
766
  if (exists && JSON.stringify(root) === original) {
582
- host.log(` skip ${name} (type and @zuke/core already declared)`);
767
+ host.log(` skip ${name} (type and dependencies already declared)`);
583
768
  return { path: name, status: "skipped" };
584
769
  }
585
770
  await host.writeText(path, `${JSON.stringify(root, null, 2)}\n`);
586
771
  host.log(` ${exists ? "update" : "create"} ${name}`);
587
772
  return { path: name, status: exists ? "overwritten" : "created" };
588
773
  }
774
+ /** The `dependencies` entries `steps` tells the reader to add, as JSON. */
775
+ function npmDependencyLines(dependencies) {
776
+ return dependencies.map(([dep, spec]) => `"${dep}": "${spec}"`).join(", ");
777
+ }
589
778
  /** The `imports` entries `steps` tells the reader to add, as JSON lines. */
590
779
  function importLines(imports) {
591
780
  return Object.entries(imports)
package/src/toml.js CHANGED
@@ -250,7 +250,7 @@ class Reader {
250
250
  /** `ch` unchanged, unless it is a control character TOML forbids in a string. */
251
251
  plain(ch) {
252
252
  // deno-lint-ignore no-control-regex -- matching control characters is the point
253
- if (/[\x00-\x08\x0a-\x1f\x7f]/.test(ch)) {
253
+ if (/[\x00-\x08\x0a-\x1f\x7f]/.test(ch)) { // oxlint-disable-line no-control-regex
254
254
  this.fail("control character in string");
255
255
  }
256
256
  return ch;
package/src/translate.js CHANGED
@@ -135,7 +135,7 @@ export function literal(value) {
135
135
  */
136
136
  export function oneLine(text) {
137
137
  // deno-lint-ignore no-control-regex -- matching control characters is the point
138
- return text.replace(/[\s\x00-\x1f\x7f]+/g, " ").trim();
138
+ return text.replace(/[\s\x00-\x1f\x7f]+/g, " ").trim(); // oxlint-disable-line no-control-regex
139
139
  }
140
140
  /**
141
141
  * Give each task a unique identifier — `toId` of its name, suffixed with `_`
package/src/version.js CHANGED
@@ -10,4 +10,4 @@
10
10
  * reads it — the annotation is what keeps that from mattering if it is ever
11
11
  * exported.
12
12
  */
13
- export const VERSION = "2.8.0"; // x-release-please-version
13
+ export const VERSION = "2.9.0"; // x-release-please-version