@maltty/cli 1.0.0-rc.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 (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -0
  3. package/bin/maltty.js +3 -0
  4. package/dist/_format-CeQhQTl5.js +23 -0
  5. package/dist/_format-CeQhQTl5.js.map +1 -0
  6. package/dist/attemptAsync-BdXzRSIT.js +42 -0
  7. package/dist/attemptAsync-BdXzRSIT.js.map +1 -0
  8. package/dist/chunk-DsIazq42.js +26 -0
  9. package/dist/commands/add/command.d.ts +7 -0
  10. package/dist/commands/add/command.d.ts.map +1 -0
  11. package/dist/commands/add/command.js +123 -0
  12. package/dist/commands/add/command.js.map +1 -0
  13. package/dist/commands/add/config.d.ts +7 -0
  14. package/dist/commands/add/config.d.ts.map +1 -0
  15. package/dist/commands/add/config.js +57 -0
  16. package/dist/commands/add/config.js.map +1 -0
  17. package/dist/commands/add/index.d.ts +7 -0
  18. package/dist/commands/add/index.d.ts.map +1 -0
  19. package/dist/commands/add/index.js +7 -0
  20. package/dist/commands/add/index.js.map +1 -0
  21. package/dist/commands/add/middleware.d.ts +7 -0
  22. package/dist/commands/add/middleware.d.ts.map +1 -0
  23. package/dist/commands/add/middleware.js +88 -0
  24. package/dist/commands/add/middleware.js.map +1 -0
  25. package/dist/commands/build.d.ts +15 -0
  26. package/dist/commands/build.d.ts.map +1 -0
  27. package/dist/commands/build.js +246 -0
  28. package/dist/commands/build.js.map +1 -0
  29. package/dist/commands/commands.d.ts +14 -0
  30. package/dist/commands/commands.d.ts.map +1 -0
  31. package/dist/commands/commands.js +189 -0
  32. package/dist/commands/commands.js.map +1 -0
  33. package/dist/commands/dev.d.ts +13 -0
  34. package/dist/commands/dev.d.ts.map +1 -0
  35. package/dist/commands/dev.js +58 -0
  36. package/dist/commands/dev.js.map +1 -0
  37. package/dist/commands/doctor.d.ts +13 -0
  38. package/dist/commands/doctor.d.ts.map +1 -0
  39. package/dist/commands/doctor.js +658 -0
  40. package/dist/commands/doctor.js.map +1 -0
  41. package/dist/commands/init.d.ts +7 -0
  42. package/dist/commands/init.d.ts.map +1 -0
  43. package/dist/commands/init.js +305 -0
  44. package/dist/commands/init.js.map +1 -0
  45. package/dist/commands/run.d.ts +19 -0
  46. package/dist/commands/run.d.ts.map +1 -0
  47. package/dist/commands/run.js +478 -0
  48. package/dist/commands/run.js.map +1 -0
  49. package/dist/commands/stories.d.ts +11 -0
  50. package/dist/commands/stories.d.ts.map +1 -0
  51. package/dist/commands/stories.js +22 -0
  52. package/dist/commands/stories.js.map +1 -0
  53. package/dist/config-helpers-pv_2Spux.js +15 -0
  54. package/dist/config-helpers-pv_2Spux.js.map +1 -0
  55. package/dist/defu-BBwssjW3.js +192 -0
  56. package/dist/defu-BBwssjW3.js.map +1 -0
  57. package/dist/detect-AOq1ehTE.js +61 -0
  58. package/dist/detect-AOq1ehTE.js.map +1 -0
  59. package/dist/dist-DW_gRP7_.js +1119 -0
  60. package/dist/dist-DW_gRP7_.js.map +1 -0
  61. package/dist/dist-Xa07jNxS.js +15617 -0
  62. package/dist/dist-Xa07jNxS.js.map +1 -0
  63. package/dist/index.d.ts +1 -0
  64. package/dist/index.js +46 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/jiti-CxWlVmZ_.js +5458 -0
  67. package/dist/jiti-CxWlVmZ_.js.map +1 -0
  68. package/dist/json-D7WbuVK1.js +43 -0
  69. package/dist/json-D7WbuVK1.js.map +1 -0
  70. package/dist/json5-z-PGDMyy.js +777 -0
  71. package/dist/json5-z-PGDMyy.js.map +1 -0
  72. package/dist/jsonc-DqZkfC3S.js +401 -0
  73. package/dist/jsonc-DqZkfC3S.js.map +1 -0
  74. package/dist/jsonc-KADMdSjU.js +2 -0
  75. package/dist/lib/templates/command/command.ts.liquid +12 -0
  76. package/dist/lib/templates/config/config.ts.liquid +16 -0
  77. package/dist/lib/templates/middleware/middleware.ts.liquid +9 -0
  78. package/dist/lib/templates/project/gitignore.liquid +3 -0
  79. package/dist/lib/templates/project/maltty.config.ts.liquid +6 -0
  80. package/dist/lib/templates/project/package.json.liquid +30 -0
  81. package/dist/lib/templates/project/src/commands/hello.ts.liquid +12 -0
  82. package/dist/lib/templates/project/src/config.ts.liquid +16 -0
  83. package/dist/lib/templates/project/src/index.ts.liquid +13 -0
  84. package/dist/lib/templates/project/tsconfig.json.liquid +19 -0
  85. package/dist/lib/templates/project/vitest.config.ts.liquid +8 -0
  86. package/dist/main-C_8x2aB3.js +274 -0
  87. package/dist/main-C_8x2aB3.js.map +1 -0
  88. package/dist/manifest-BIKVDJML.js +112 -0
  89. package/dist/manifest-BIKVDJML.js.map +1 -0
  90. package/dist/multipart-parser-MNkxNO83.js +174 -0
  91. package/dist/multipart-parser-MNkxNO83.js.map +1 -0
  92. package/dist/node-C91xGGqn.js +644 -0
  93. package/dist/node-C91xGGqn.js.map +1 -0
  94. package/dist/node-Drmc03fL.js +3973 -0
  95. package/dist/node-Drmc03fL.js.map +1 -0
  96. package/dist/ohash-BPoV4zBH.js +185 -0
  97. package/dist/ohash-BPoV4zBH.js.map +1 -0
  98. package/dist/pnpm-workspace.yaml +26 -0
  99. package/dist/toml-LuHsHQtV.js +646 -0
  100. package/dist/toml-LuHsHQtV.js.map +1 -0
  101. package/dist/utils-DlIJNGLQ.js +1905 -0
  102. package/dist/utils-DlIJNGLQ.js.map +1 -0
  103. package/dist/validate-C_SXBoLq.js +18 -0
  104. package/dist/validate-C_SXBoLq.js.map +1 -0
  105. package/dist/write-CSwG4Stj.js +152 -0
  106. package/dist/write-CSwG4Stj.js.map +1 -0
  107. package/dist/yaml-BS9RDuUr.js +1067 -0
  108. package/dist/yaml-BS9RDuUr.js.map +1 -0
  109. package/package.json +65 -0
@@ -0,0 +1,478 @@
1
+ import { i as M, n as process_exports } from "../node-C91xGGqn.js";
2
+ import { i as normalizeCompileOptions, r as createBundler } from "../dist-DW_gRP7_.js";
3
+ import { n as loadConfig, t as compileTargets } from "../utils-DlIJNGLQ.js";
4
+ import { t as extractConfig } from "../config-helpers-pv_2Spux.js";
5
+ import { command } from "maltty";
6
+ import { resolve } from "node:path";
7
+ import { z } from "zod";
8
+ //#region src/commands/run.ts
9
+ const EngineSchema = z.enum([
10
+ "node",
11
+ "tsx",
12
+ "binary"
13
+ ]);
14
+ const compileTargetValues = compileTargets.map((entry) => entry.target);
15
+ const TargetSchema = z.enum(compileTargetValues);
16
+ /**
17
+ * Run the current maltty CLI project.
18
+ *
19
+ * Supports three engines:
20
+ * - `node` (default) — builds first, then runs `node dist/index.js`
21
+ * - `tsx` — runs the source entry file directly via `tsx`
22
+ * - `binary` — builds and compiles, then executes the compiled binary
23
+ *
24
+ * All unknown flags are forwarded to the executed CLI. Supports
25
+ * `--inspect`, `--inspect-brk`, `--inspect-wait`, and `--inspect-port`
26
+ * for attaching a debugger (node and tsx engines only).
27
+ */
28
+ const runCommand = command({
29
+ options: z.object({
30
+ engine: EngineSchema.default("node").describe("Runtime engine: node (built), tsx (source), or binary (compiled)"),
31
+ inspect: z.boolean().optional().describe("Enable the Node.js inspector (--inspect)"),
32
+ "inspect-brk": z.boolean().optional().describe("Enable the Node.js inspector and break before user code starts (--inspect-brk)"),
33
+ "inspect-port": z.number().optional().describe("Set the inspector port"),
34
+ "inspect-wait": z.boolean().optional().describe("Enable the Node.js inspector and wait for debugger to attach (--inspect-wait)"),
35
+ target: z.string().optional().describe("Compile target for binary engine (e.g. darwin-arm64)")
36
+ }),
37
+ strict: false,
38
+ description: "Run the current maltty CLI project",
39
+ handler: async (ctx) => {
40
+ const cwd = process.cwd();
41
+ const [configError, configResult] = await loadConfig({ cwd });
42
+ if (configError) return ctx.fail(configError.message);
43
+ const config = extractConfig(configResult);
44
+ if (ctx.args.engine === "binary" && hasInspectFlag(ctx.args)) return ctx.fail("Inspector flags are not supported with the binary engine. Use --engine=node or --engine=tsx instead.");
45
+ const passthroughArgs = extractPassthroughArgs();
46
+ const exitCode = await M(ctx.args.engine).with("node", () => runWithNode({
47
+ args: ctx.args,
48
+ config,
49
+ cwd,
50
+ passthroughArgs,
51
+ ctx
52
+ })).with("tsx", () => runWithTsx({
53
+ args: ctx.args,
54
+ config,
55
+ cwd,
56
+ passthroughArgs,
57
+ ctx
58
+ })).with("binary", () => runWithBinary({
59
+ args: ctx.args,
60
+ config,
61
+ cwd,
62
+ passthroughArgs,
63
+ ctx
64
+ })).exhaustive();
65
+ if (exitCode !== 0) return ctx.fail(`Process exited with code ${exitCode}`);
66
+ }
67
+ });
68
+ /**
69
+ * Build the project and run the bundled entry file with `node`.
70
+ *
71
+ * @private
72
+ * @param params - Engine execution parameters.
73
+ * @returns The exit code of the spawned process.
74
+ */
75
+ async function runWithNode(params) {
76
+ const buildOutput = await buildProject({
77
+ bundler: await createBundler({
78
+ config: params.config,
79
+ cwd: params.cwd
80
+ }),
81
+ ctx: params.ctx
82
+ });
83
+ return spawnProcess({
84
+ args: [
85
+ ...buildInspectFlags(params.args),
86
+ buildOutput.entryFile,
87
+ ...params.passthroughArgs
88
+ ],
89
+ cmd: "node",
90
+ cwd: params.cwd
91
+ });
92
+ }
93
+ /**
94
+ * Run the source entry file directly with `tsx`.
95
+ *
96
+ * @private
97
+ * @param params - Engine execution parameters.
98
+ * @returns The exit code of the spawned process.
99
+ */
100
+ async function runWithTsx(params) {
101
+ const entryFile = resolve(params.cwd, params.config.entry ?? "./src/index.ts");
102
+ return spawnProcess({
103
+ args: [
104
+ ...buildInspectFlags(params.args),
105
+ entryFile,
106
+ ...params.passthroughArgs
107
+ ],
108
+ cmd: "tsx",
109
+ cwd: params.cwd
110
+ });
111
+ }
112
+ /**
113
+ * Build and compile the project, then execute the compiled binary.
114
+ *
115
+ * Requires compile targets to be configured in `maltty.config.ts` or
116
+ * provided via `--target`. Resolves the current platform's binary
117
+ * from the compile output.
118
+ *
119
+ * @private
120
+ * @param params - Engine execution parameters.
121
+ * @returns The exit code of the spawned process.
122
+ */
123
+ async function runWithBinary(params) {
124
+ const validatedTarget = validateTarget({
125
+ ctx: params.ctx,
126
+ target: params.args.target
127
+ });
128
+ const configWithTarget = applyTargetOverride({
129
+ config: params.config,
130
+ target: validatedTarget
131
+ });
132
+ if (!hasCompileTargets(configWithTarget)) return params.ctx.fail("No compile targets configured. Set targets in maltty.config.ts or use --target.");
133
+ const bundler = await createBundler({
134
+ config: configWithTarget,
135
+ cwd: params.cwd
136
+ });
137
+ await buildProject({
138
+ bundler,
139
+ ctx: params.ctx
140
+ });
141
+ params.ctx.status.spinner.message("Compiling binary...");
142
+ const binary = resolveBinary({
143
+ compileOutput: await compileProject({
144
+ bundler,
145
+ ctx: params.ctx
146
+ }),
147
+ ctx: params.ctx,
148
+ target: params.args.target
149
+ });
150
+ params.ctx.status.spinner.stop("Build complete");
151
+ return spawnProcess({
152
+ args: params.passthroughArgs,
153
+ cmd: binary.path,
154
+ cwd: params.cwd
155
+ });
156
+ }
157
+ /**
158
+ * Build the project using the bundler and return the build output.
159
+ *
160
+ * Starts a spinner, invokes the build, and fails the command on error.
161
+ *
162
+ * @private
163
+ * @param params - The bundler instance and command context.
164
+ * @returns The successful build output.
165
+ */
166
+ async function buildProject(params) {
167
+ params.ctx.status.spinner.start("Building...");
168
+ const [buildError, buildOutput] = await params.bundler.build();
169
+ if (buildError) {
170
+ params.ctx.status.spinner.stop("Build failed");
171
+ return params.ctx.fail(buildError.message);
172
+ }
173
+ params.ctx.status.spinner.stop("Built");
174
+ return buildOutput;
175
+ }
176
+ /**
177
+ * Compile the project into standalone binaries.
178
+ *
179
+ * @private
180
+ * @param params - The bundler instance and command context.
181
+ * @returns The successful compile output.
182
+ */
183
+ async function compileProject(params) {
184
+ const [compileError, compileOutput] = await params.bundler.compile();
185
+ if (compileError) {
186
+ params.ctx.status.spinner.stop("Compile failed");
187
+ return params.ctx.fail(compileError.message);
188
+ }
189
+ return compileOutput;
190
+ }
191
+ /**
192
+ * Resolve the binary to execute from compile output.
193
+ *
194
+ * When `--target` is provided, finds the matching binary. Otherwise
195
+ * detects the host platform and architecture to find the correct binary.
196
+ *
197
+ * @private
198
+ * @param params - The compile output, optional target, and command context.
199
+ * @returns The resolved compiled binary.
200
+ */
201
+ function resolveBinary(params) {
202
+ if (params.target) {
203
+ const binary = params.compileOutput.binaries.find((b) => b.target === params.target);
204
+ if (!binary) return params.ctx.fail(`No binary found for target "${params.target}"`);
205
+ return binary;
206
+ }
207
+ const hostTarget = resolveHostTarget();
208
+ const candidates = resolveHostTargetCandidates(hostTarget);
209
+ const binary = findFirstMatchingBinary(params.compileOutput.binaries, candidates);
210
+ if (!binary) return params.ctx.fail(`No binary found for target "${hostTarget}"`);
211
+ return binary;
212
+ }
213
+ /**
214
+ * Build an ordered list of candidate targets for the current host.
215
+ *
216
+ * On Linux x64, includes both the musl variant (`linux-x64-musl`) and the
217
+ * glibc variant (`linux-x64`) so the correct binary is found on Alpine-like
218
+ * hosts. The musl variant is preferred when available.
219
+ *
220
+ * @private
221
+ * @param hostTarget - The base host target string (e.g. `linux-x64`).
222
+ * @returns An ordered list of candidate target strings to try.
223
+ */
224
+ function resolveHostTargetCandidates(hostTarget) {
225
+ if (hostTarget === "linux-x64") return [`${hostTarget}-musl`, hostTarget];
226
+ return [hostTarget];
227
+ }
228
+ /**
229
+ * Find the first binary matching any of the candidate targets.
230
+ *
231
+ * @private
232
+ * @param binaries - The compiled binaries to search.
233
+ * @param candidates - Ordered candidate target strings.
234
+ * @returns The first matching binary, or `undefined`.
235
+ */
236
+ function findFirstMatchingBinary(binaries, candidates) {
237
+ return candidates.reduce((found, candidate) => found ?? binaries.find((b) => b.target === candidate), void 0);
238
+ }
239
+ /**
240
+ * Map from Node.js `process.platform` to compile target OS prefix.
241
+ *
242
+ * @private
243
+ */
244
+ const PLATFORM_MAP = {
245
+ darwin: "darwin",
246
+ linux: "linux",
247
+ win32: "windows"
248
+ };
249
+ /**
250
+ * Map from Node.js `process.arch` to compile target architecture suffix.
251
+ *
252
+ * @private
253
+ */
254
+ const ARCH_MAP = {
255
+ arm64: "arm64",
256
+ x64: "x64"
257
+ };
258
+ /**
259
+ * Detect the host platform and architecture, returning a compile target string.
260
+ *
261
+ * Combines `process.platform` and `process.arch` into a target like `darwin-arm64`.
262
+ *
263
+ * @private
264
+ * @returns The compile target string for the current host.
265
+ */
266
+ function resolveHostTarget() {
267
+ return `${PLATFORM_MAP[process.platform] ?? process.platform}-${ARCH_MAP[process.arch] ?? process.arch}`;
268
+ }
269
+ /**
270
+ * Check whether a config has compilation enabled.
271
+ *
272
+ * Returns `true` for `compile: true` (boolean shorthand), for object configs
273
+ * that omit `targets` (the bundler fills in defaults), and for object configs
274
+ * with a non-empty `targets` array. Only returns `false` when compile is
275
+ * `false`, `undefined`, or an object with an explicitly empty `targets` array.
276
+ *
277
+ * @private
278
+ * @param config - The maltty config to check.
279
+ * @returns `true` when compilation is enabled.
280
+ */
281
+ function hasCompileTargets(config) {
282
+ if (config.compile === true) return true;
283
+ if (typeof config.compile !== "object") return false;
284
+ if (config.compile.targets === void 0) return true;
285
+ return config.compile.targets.length > 0;
286
+ }
287
+ /**
288
+ * Validate a `--target` string against known compile targets.
289
+ *
290
+ * Returns the validated target when provided, or `undefined` when no target
291
+ * was specified. Fails the command with a descriptive error for invalid values.
292
+ *
293
+ * @private
294
+ * @param params - The target string and command context.
295
+ * @returns The validated compile target, or `undefined`.
296
+ */
297
+ function validateTarget(params) {
298
+ if (!params.target) return;
299
+ const parsed = TargetSchema.safeParse(params.target);
300
+ if (!parsed.success) {
301
+ const validTargets = TargetSchema.options.join(", ");
302
+ return params.ctx.fail(`Invalid compile target "${params.target}". Must be one of: ${validTargets}`);
303
+ }
304
+ return parsed.data;
305
+ }
306
+ /**
307
+ * Apply a `--target` CLI override to the config's compile targets.
308
+ *
309
+ * @private
310
+ * @param params - The config and optional validated target override.
311
+ * @returns A config with the target override applied.
312
+ */
313
+ function applyTargetOverride(params) {
314
+ if (!params.target) return params.config;
315
+ const existingCompile = normalizeCompileOptions(params.config.compile);
316
+ return {
317
+ ...params.config,
318
+ compile: {
319
+ ...existingCompile,
320
+ targets: [params.target]
321
+ }
322
+ };
323
+ }
324
+ /**
325
+ * Extract passthrough arguments by sequentially walking argv tokens
326
+ * and skipping known `maltty run` flags and their values.
327
+ *
328
+ * Uses positional parsing: when a known flag that takes a value is
329
+ * encountered (e.g. `--engine`), the next token is also skipped.
330
+ * This avoids the fragile value-based matching that could accidentally
331
+ * consume user CLI arguments that happen to match a known flag's value.
332
+ *
333
+ * @private
334
+ * @returns An array of arguments to forward to the user's CLI.
335
+ */
336
+ function extractPassthroughArgs() {
337
+ const argv = process.argv.slice(2);
338
+ const runIndex = argv.indexOf("run");
339
+ if (runIndex === -1) return [];
340
+ return collectPassthroughTokens(argv.slice(runIndex + 1));
341
+ }
342
+ /**
343
+ * Known boolean flags for the `maltty run` command (no value follows).
344
+ *
345
+ * @private
346
+ */
347
+ const KNOWN_BOOLEAN_FLAGS = new Set([
348
+ "--inspect",
349
+ "--inspect-brk",
350
+ "--inspect-wait"
351
+ ]);
352
+ /**
353
+ * Known value flags for the `maltty run` command (next token is consumed as value).
354
+ *
355
+ * @private
356
+ */
357
+ const KNOWN_VALUE_FLAGS = new Set([
358
+ "--engine",
359
+ "--inspect-port",
360
+ "--target"
361
+ ]);
362
+ /**
363
+ * Walk an array of CLI tokens sequentially and collect only passthrough args.
364
+ *
365
+ * Skips known boolean flags, known value flags (and their following value token),
366
+ * and `--flag=value` forms. All other tokens are collected as passthrough.
367
+ *
368
+ * @private
369
+ * @param tokens - The CLI tokens after the `run` subcommand.
370
+ * @returns The filtered passthrough arguments.
371
+ */
372
+ function collectPassthroughTokens(tokens) {
373
+ return tokens.reduce((acc, token) => {
374
+ if (acc.skip) return {
375
+ result: acc.result,
376
+ skip: false
377
+ };
378
+ if (KNOWN_BOOLEAN_FLAGS.has(token)) return {
379
+ result: acc.result,
380
+ skip: false
381
+ };
382
+ if (KNOWN_VALUE_FLAGS.has(token)) return {
383
+ result: acc.result,
384
+ skip: true
385
+ };
386
+ if (isKnownEqualsSyntax(token)) return {
387
+ result: acc.result,
388
+ skip: false
389
+ };
390
+ return {
391
+ result: [...acc.result, token],
392
+ skip: false
393
+ };
394
+ }, {
395
+ result: [],
396
+ skip: false
397
+ }).result;
398
+ }
399
+ /**
400
+ * Check whether a token uses `--flag=value` syntax for a known flag.
401
+ *
402
+ * @private
403
+ * @param token - The CLI token to check.
404
+ * @returns `true` when the token is a known flag in `--flag=value` form.
405
+ */
406
+ function isKnownEqualsSyntax(token) {
407
+ const eqIndex = token.indexOf("=");
408
+ if (eqIndex <= 0) return false;
409
+ const flagPart = token.slice(0, eqIndex);
410
+ return KNOWN_BOOLEAN_FLAGS.has(flagPart) || KNOWN_VALUE_FLAGS.has(flagPart);
411
+ }
412
+ /**
413
+ * Check whether any inspector flag is set, including `--inspect-port`.
414
+ *
415
+ * @private
416
+ * @param args - The parsed CLI args.
417
+ * @returns `true` when any inspector flag is enabled.
418
+ */
419
+ function hasInspectFlag(args) {
420
+ return args.inspect === true || args["inspect-brk"] === true || args["inspect-wait"] === true || args["inspect-port"] !== void 0;
421
+ }
422
+ /**
423
+ * Build inspector-related Node.js flags from parsed CLI args.
424
+ *
425
+ * Only one inspector mode is active at a time, with `inspect-brk` taking
426
+ * precedence over `inspect-wait`, which takes precedence over `inspect`.
427
+ *
428
+ * @private
429
+ * @param args - The parsed CLI args.
430
+ * @returns An array of inspector flags.
431
+ */
432
+ function buildInspectFlags(args) {
433
+ const flag = resolveInspectMode(args);
434
+ if (!flag) return [];
435
+ return [formatInspectFlag(flag, args["inspect-port"])];
436
+ }
437
+ /**
438
+ * Determine which inspector mode to use based on parsed CLI args.
439
+ *
440
+ * When only `--inspect-port` is provided without an explicit mode,
441
+ * defaults to `'inspect'` so the port is not silently ignored.
442
+ *
443
+ * @private
444
+ * @param args - The parsed CLI args.
445
+ * @returns The inspector flag name, or `undefined` if none is active.
446
+ */
447
+ function resolveInspectMode(args) {
448
+ if (args["inspect-brk"]) return "inspect-brk";
449
+ if (args["inspect-wait"]) return "inspect-wait";
450
+ if (args.inspect) return "inspect";
451
+ if (args["inspect-port"] !== void 0) return "inspect";
452
+ }
453
+ /**
454
+ * Format an inspector flag with an optional port.
455
+ *
456
+ * @private
457
+ * @param flag - The inspector flag name (e.g. 'inspect', 'inspect-brk').
458
+ * @param port - Optional port number.
459
+ * @returns The formatted flag string.
460
+ */
461
+ function formatInspectFlag(flag, port) {
462
+ if (port !== void 0) return `--${flag}=${port}`;
463
+ return `--${flag}`;
464
+ }
465
+ /**
466
+ * Spawn a process with the given command and arguments, inheriting stdio.
467
+ *
468
+ * @private
469
+ * @param params - The command, arguments, and working directory.
470
+ * @returns The exit code of the spawned process.
471
+ */
472
+ function spawnProcess(params) {
473
+ return process_exports.spawn(params);
474
+ }
475
+ //#endregion
476
+ export { runCommand as default };
477
+
478
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","names":["match","proc"],"sources":["../../src/commands/run.ts"],"sourcesContent":["import { resolve } from 'node:path'\n\nimport { createBundler, DEFAULT_ENTRY, normalizeCompileOptions } from '@maltty/bundler'\nimport type { BuildOutput, Bundler, CompileOutput, CompiledBinary } from '@maltty/bundler'\nimport type { CompileTarget, MalttyConfig } from '@maltty/config'\nimport { compileTargets, loadConfig } from '@maltty/config/utils'\nimport { process as proc } from '@maltty/utils/node'\nimport { command } from 'maltty'\nimport type { Command, CommandContext } from 'maltty'\nimport { match } from 'ts-pattern'\nimport { z } from 'zod'\n\nimport { extractConfig } from '../lib/config-helpers.js'\n\nconst EngineSchema = z.enum(['node', 'tsx', 'binary'])\n\nconst compileTargetValues = compileTargets.map((entry) => entry.target) as [\n CompileTarget,\n ...CompileTarget[],\n]\nconst TargetSchema = z.enum(compileTargetValues)\n\nconst options = z.object({\n engine: EngineSchema.default('node').describe(\n 'Runtime engine: node (built), tsx (source), or binary (compiled)'\n ),\n inspect: z.boolean().optional().describe('Enable the Node.js inspector (--inspect)'),\n 'inspect-brk': z\n .boolean()\n .optional()\n .describe('Enable the Node.js inspector and break before user code starts (--inspect-brk)'),\n 'inspect-port': z.number().optional().describe('Set the inspector port'),\n 'inspect-wait': z\n .boolean()\n .optional()\n .describe('Enable the Node.js inspector and wait for debugger to attach (--inspect-wait)'),\n target: z.string().optional().describe('Compile target for binary engine (e.g. darwin-arm64)'),\n})\n\ntype RunArgs = z.infer<typeof options>\n\n/**\n * Run the current maltty CLI project.\n *\n * Supports three engines:\n * - `node` (default) — builds first, then runs `node dist/index.js`\n * - `tsx` — runs the source entry file directly via `tsx`\n * - `binary` — builds and compiles, then executes the compiled binary\n *\n * All unknown flags are forwarded to the executed CLI. Supports\n * `--inspect`, `--inspect-brk`, `--inspect-wait`, and `--inspect-port`\n * for attaching a debugger (node and tsx engines only).\n */\nconst runCommand: Command = command({\n options,\n strict: false,\n description: 'Run the current maltty CLI project',\n handler: async (ctx: CommandContext<RunArgs>) => {\n const cwd = process.cwd()\n\n const [configError, configResult] = await loadConfig({ cwd })\n\n if (configError) {\n return ctx.fail(configError.message)\n }\n\n const config = extractConfig(configResult)\n\n if (ctx.args.engine === 'binary' && hasInspectFlag(ctx.args)) {\n return ctx.fail(\n 'Inspector flags are not supported with the binary engine. Use --engine=node or --engine=tsx instead.'\n )\n }\n\n const passthroughArgs = extractPassthroughArgs()\n\n const exitCode = await match(ctx.args.engine)\n .with('node', () => runWithNode({ args: ctx.args, config, cwd, passthroughArgs, ctx }))\n .with('tsx', () => runWithTsx({ args: ctx.args, config, cwd, passthroughArgs, ctx }))\n .with('binary', () => runWithBinary({ args: ctx.args, config, cwd, passthroughArgs, ctx }))\n .exhaustive()\n\n if (exitCode !== 0) {\n return ctx.fail(`Process exited with code ${exitCode}`)\n }\n },\n})\n\nexport default runCommand\n\n// ---------------------------------------------------------------------------\n\n/**\n * Build the project and run the bundled entry file with `node`.\n *\n * @private\n * @param params - Engine execution parameters.\n * @returns The exit code of the spawned process.\n */\nasync function runWithNode(params: EngineParams): Promise<number> {\n const bundler = await createBundler({ config: params.config, cwd: params.cwd })\n const buildOutput = await buildProject({ bundler, ctx: params.ctx })\n const inspectFlags = buildInspectFlags(params.args)\n\n return spawnProcess({\n args: [...inspectFlags, buildOutput.entryFile, ...params.passthroughArgs],\n cmd: 'node',\n cwd: params.cwd,\n })\n}\n\n/**\n * Run the source entry file directly with `tsx`.\n *\n * @private\n * @param params - Engine execution parameters.\n * @returns The exit code of the spawned process.\n */\nasync function runWithTsx(params: EngineParams): Promise<number> {\n const entryFile = resolve(params.cwd, params.config.entry ?? DEFAULT_ENTRY)\n const inspectFlags = buildInspectFlags(params.args)\n\n return spawnProcess({\n args: [...inspectFlags, entryFile, ...params.passthroughArgs],\n cmd: 'tsx',\n cwd: params.cwd,\n })\n}\n\n/**\n * Build and compile the project, then execute the compiled binary.\n *\n * Requires compile targets to be configured in `maltty.config.ts` or\n * provided via `--target`. Resolves the current platform's binary\n * from the compile output.\n *\n * @private\n * @param params - Engine execution parameters.\n * @returns The exit code of the spawned process.\n */\nasync function runWithBinary(params: EngineParams): Promise<number> {\n const validatedTarget = validateTarget({ ctx: params.ctx, target: params.args.target })\n\n const configWithTarget = applyTargetOverride({\n config: params.config,\n target: validatedTarget,\n })\n\n if (!hasCompileTargets(configWithTarget)) {\n return params.ctx.fail(\n 'No compile targets configured. Set targets in maltty.config.ts or use --target.'\n )\n }\n\n const bundler = await createBundler({ config: configWithTarget, cwd: params.cwd })\n\n await buildProject({ bundler, ctx: params.ctx })\n\n params.ctx.status.spinner.message('Compiling binary...')\n\n const compileOutput = await compileProject({ bundler, ctx: params.ctx })\n\n const binary = resolveBinary({\n compileOutput,\n ctx: params.ctx,\n target: params.args.target,\n })\n\n params.ctx.status.spinner.stop('Build complete')\n\n return spawnProcess({\n args: params.passthroughArgs,\n cmd: binary.path,\n cwd: params.cwd,\n })\n}\n\n/**\n * Parameters shared across all engine execution functions.\n *\n * @private\n */\ninterface EngineParams {\n readonly args: RunArgs\n readonly config: MalttyConfig\n readonly ctx: CommandContext<RunArgs>\n readonly cwd: string\n readonly passthroughArgs: readonly string[]\n}\n\n/**\n * Build the project using the bundler and return the build output.\n *\n * Starts a spinner, invokes the build, and fails the command on error.\n *\n * @private\n * @param params - The bundler instance and command context.\n * @returns The successful build output.\n */\nasync function buildProject(params: {\n readonly bundler: Bundler\n readonly ctx: CommandContext<RunArgs>\n}): Promise<BuildOutput> {\n params.ctx.status.spinner.start('Building...')\n\n const [buildError, buildOutput] = await params.bundler.build()\n\n if (buildError) {\n params.ctx.status.spinner.stop('Build failed')\n return params.ctx.fail(buildError.message)\n }\n\n params.ctx.status.spinner.stop('Built')\n\n return buildOutput\n}\n\n/**\n * Compile the project into standalone binaries.\n *\n * @private\n * @param params - The bundler instance and command context.\n * @returns The successful compile output.\n */\nasync function compileProject(params: {\n readonly bundler: Bundler\n readonly ctx: CommandContext<RunArgs>\n}): Promise<CompileOutput> {\n const [compileError, compileOutput] = await params.bundler.compile()\n\n if (compileError) {\n params.ctx.status.spinner.stop('Compile failed')\n return params.ctx.fail(compileError.message)\n }\n\n return compileOutput\n}\n\n/**\n * Resolve the binary to execute from compile output.\n *\n * When `--target` is provided, finds the matching binary. Otherwise\n * detects the host platform and architecture to find the correct binary.\n *\n * @private\n * @param params - The compile output, optional target, and command context.\n * @returns The resolved compiled binary.\n */\nfunction resolveBinary(params: {\n readonly compileOutput: CompileOutput\n readonly ctx: CommandContext<RunArgs>\n readonly target: string | undefined\n}): CompiledBinary {\n if (params.target) {\n const binary = params.compileOutput.binaries.find((b) => b.target === params.target)\n\n if (!binary) {\n return params.ctx.fail(`No binary found for target \"${params.target}\"`)\n }\n\n return binary\n }\n\n const hostTarget = resolveHostTarget()\n const candidates = resolveHostTargetCandidates(hostTarget)\n const binary = findFirstMatchingBinary(params.compileOutput.binaries, candidates)\n\n if (!binary) {\n return params.ctx.fail(`No binary found for target \"${hostTarget}\"`)\n }\n\n return binary\n}\n\n/**\n * Build an ordered list of candidate targets for the current host.\n *\n * On Linux x64, includes both the musl variant (`linux-x64-musl`) and the\n * glibc variant (`linux-x64`) so the correct binary is found on Alpine-like\n * hosts. The musl variant is preferred when available.\n *\n * @private\n * @param hostTarget - The base host target string (e.g. `linux-x64`).\n * @returns An ordered list of candidate target strings to try.\n */\nfunction resolveHostTargetCandidates(hostTarget: string): readonly string[] {\n if (hostTarget === 'linux-x64') {\n return [`${hostTarget}-musl`, hostTarget]\n }\n\n return [hostTarget]\n}\n\n/**\n * Find the first binary matching any of the candidate targets.\n *\n * @private\n * @param binaries - The compiled binaries to search.\n * @param candidates - Ordered candidate target strings.\n * @returns The first matching binary, or `undefined`.\n */\nfunction findFirstMatchingBinary(\n binaries: readonly CompiledBinary[],\n candidates: readonly string[]\n): CompiledBinary | undefined {\n return candidates.reduce<CompiledBinary | undefined>(\n (found, candidate) => found ?? binaries.find((b) => b.target === candidate),\n undefined\n )\n}\n\n/**\n * Map from Node.js `process.platform` to compile target OS prefix.\n *\n * @private\n */\nconst PLATFORM_MAP: Readonly<Record<string, string>> = {\n darwin: 'darwin',\n linux: 'linux',\n win32: 'windows',\n}\n\n/**\n * Map from Node.js `process.arch` to compile target architecture suffix.\n *\n * @private\n */\nconst ARCH_MAP: Readonly<Record<string, string>> = {\n arm64: 'arm64',\n x64: 'x64',\n}\n\n/**\n * Detect the host platform and architecture, returning a compile target string.\n *\n * Combines `process.platform` and `process.arch` into a target like `darwin-arm64`.\n *\n * @private\n * @returns The compile target string for the current host.\n */\nfunction resolveHostTarget(): string {\n const os = PLATFORM_MAP[process.platform] ?? process.platform\n const arch = ARCH_MAP[process.arch] ?? process.arch\n return `${os}-${arch}`\n}\n\n/**\n * Check whether a config has compilation enabled.\n *\n * Returns `true` for `compile: true` (boolean shorthand), for object configs\n * that omit `targets` (the bundler fills in defaults), and for object configs\n * with a non-empty `targets` array. Only returns `false` when compile is\n * `false`, `undefined`, or an object with an explicitly empty `targets` array.\n *\n * @private\n * @param config - The maltty config to check.\n * @returns `true` when compilation is enabled.\n */\nfunction hasCompileTargets(config: MalttyConfig): boolean {\n if (config.compile === true) {\n return true\n }\n\n if (typeof config.compile !== 'object') {\n return false\n }\n\n if (config.compile.targets === undefined) {\n return true\n }\n\n return config.compile.targets.length > 0\n}\n\n/**\n * Validate a `--target` string against known compile targets.\n *\n * Returns the validated target when provided, or `undefined` when no target\n * was specified. Fails the command with a descriptive error for invalid values.\n *\n * @private\n * @param params - The target string and command context.\n * @returns The validated compile target, or `undefined`.\n */\nfunction validateTarget(params: {\n readonly ctx: CommandContext<RunArgs>\n readonly target: string | undefined\n}): CompileTarget | undefined {\n if (!params.target) {\n return undefined\n }\n\n const parsed = TargetSchema.safeParse(params.target)\n\n if (!parsed.success) {\n const validTargets = TargetSchema.options.join(', ')\n return params.ctx.fail(\n `Invalid compile target \"${params.target}\". Must be one of: ${validTargets}`\n )\n }\n\n return parsed.data\n}\n\n/**\n * Apply a `--target` CLI override to the config's compile targets.\n *\n * @private\n * @param params - The config and optional validated target override.\n * @returns A config with the target override applied.\n */\nfunction applyTargetOverride(params: {\n readonly config: MalttyConfig\n readonly target: CompileTarget | undefined\n}): MalttyConfig {\n if (!params.target) {\n return params.config\n }\n\n const existingCompile = normalizeCompileOptions(params.config.compile)\n\n return {\n ...params.config,\n compile: {\n ...existingCompile,\n targets: [params.target],\n },\n }\n}\n\n/**\n * Extract passthrough arguments by sequentially walking argv tokens\n * and skipping known `maltty run` flags and their values.\n *\n * Uses positional parsing: when a known flag that takes a value is\n * encountered (e.g. `--engine`), the next token is also skipped.\n * This avoids the fragile value-based matching that could accidentally\n * consume user CLI arguments that happen to match a known flag's value.\n *\n * @private\n * @returns An array of arguments to forward to the user's CLI.\n */\nfunction extractPassthroughArgs(): readonly string[] {\n const argv = process.argv.slice(2)\n const runIndex = argv.indexOf('run')\n\n if (runIndex === -1) {\n return []\n }\n\n const afterRun = argv.slice(runIndex + 1)\n\n return collectPassthroughTokens(afterRun)\n}\n\n/**\n * Known boolean flags for the `maltty run` command (no value follows).\n *\n * @private\n */\nconst KNOWN_BOOLEAN_FLAGS: ReadonlySet<string> = new Set([\n '--inspect',\n '--inspect-brk',\n '--inspect-wait',\n])\n\n/**\n * Known value flags for the `maltty run` command (next token is consumed as value).\n *\n * @private\n */\nconst KNOWN_VALUE_FLAGS: ReadonlySet<string> = new Set(['--engine', '--inspect-port', '--target'])\n\n/**\n * Walk an array of CLI tokens sequentially and collect only passthrough args.\n *\n * Skips known boolean flags, known value flags (and their following value token),\n * and `--flag=value` forms. All other tokens are collected as passthrough.\n *\n * @private\n * @param tokens - The CLI tokens after the `run` subcommand.\n * @returns The filtered passthrough arguments.\n */\nfunction collectPassthroughTokens(tokens: readonly string[]): readonly string[] {\n return tokens.reduce<{ readonly result: readonly string[]; readonly skip: boolean }>(\n (acc, token) => {\n if (acc.skip) {\n return { result: acc.result, skip: false }\n }\n\n if (KNOWN_BOOLEAN_FLAGS.has(token)) {\n return { result: acc.result, skip: false }\n }\n\n if (KNOWN_VALUE_FLAGS.has(token)) {\n return { result: acc.result, skip: true }\n }\n\n if (isKnownEqualsSyntax(token)) {\n return { result: acc.result, skip: false }\n }\n\n return { result: [...acc.result, token], skip: false }\n },\n { result: [], skip: false }\n ).result\n}\n\n/**\n * Check whether a token uses `--flag=value` syntax for a known flag.\n *\n * @private\n * @param token - The CLI token to check.\n * @returns `true` when the token is a known flag in `--flag=value` form.\n */\nfunction isKnownEqualsSyntax(token: string): boolean {\n const eqIndex = token.indexOf('=')\n if (eqIndex <= 0) {\n return false\n }\n\n const flagPart = token.slice(0, eqIndex)\n return KNOWN_BOOLEAN_FLAGS.has(flagPart) || KNOWN_VALUE_FLAGS.has(flagPart)\n}\n\n/**\n * Check whether any inspector flag is set, including `--inspect-port`.\n *\n * @private\n * @param args - The parsed CLI args.\n * @returns `true` when any inspector flag is enabled.\n */\nfunction hasInspectFlag(args: RunArgs): boolean {\n return (\n args.inspect === true ||\n args['inspect-brk'] === true ||\n args['inspect-wait'] === true ||\n args['inspect-port'] !== undefined\n )\n}\n\n/**\n * Build inspector-related Node.js flags from parsed CLI args.\n *\n * Only one inspector mode is active at a time, with `inspect-brk` taking\n * precedence over `inspect-wait`, which takes precedence over `inspect`.\n *\n * @private\n * @param args - The parsed CLI args.\n * @returns An array of inspector flags.\n */\nfunction buildInspectFlags(args: RunArgs): readonly string[] {\n const flag = resolveInspectMode(args)\n\n if (!flag) {\n return []\n }\n\n return [formatInspectFlag(flag, args['inspect-port'])]\n}\n\n/**\n * Determine which inspector mode to use based on parsed CLI args.\n *\n * When only `--inspect-port` is provided without an explicit mode,\n * defaults to `'inspect'` so the port is not silently ignored.\n *\n * @private\n * @param args - The parsed CLI args.\n * @returns The inspector flag name, or `undefined` if none is active.\n */\nfunction resolveInspectMode(args: RunArgs): string | undefined {\n if (args['inspect-brk']) {\n return 'inspect-brk'\n }\n\n if (args['inspect-wait']) {\n return 'inspect-wait'\n }\n\n if (args.inspect) {\n return 'inspect'\n }\n\n if (args['inspect-port'] !== undefined) {\n return 'inspect'\n }\n\n return undefined\n}\n\n/**\n * Format an inspector flag with an optional port.\n *\n * @private\n * @param flag - The inspector flag name (e.g. 'inspect', 'inspect-brk').\n * @param port - Optional port number.\n * @returns The formatted flag string.\n */\nfunction formatInspectFlag(flag: string, port: number | undefined): string {\n if (port !== undefined) {\n return `--${flag}=${port}`\n }\n\n return `--${flag}`\n}\n\n/**\n * Spawn a process with the given command and arguments, inheriting stdio.\n *\n * @private\n * @param params - The command, arguments, and working directory.\n * @returns The exit code of the spawned process.\n */\nfunction spawnProcess(params: {\n readonly cmd: string\n readonly args: readonly string[]\n readonly cwd: string\n}): Promise<number> {\n return proc.spawn(params)\n}\n"],"mappings":";;;;;;;;AAcA,MAAM,eAAe,EAAE,KAAK;CAAC;CAAQ;CAAO;CAAS,CAAC;AAEtD,MAAM,sBAAsB,eAAe,KAAK,UAAU,MAAM,OAAO;AAIvE,MAAM,eAAe,EAAE,KAAK,oBAAoB;;;;;;;;;;;;;AAiChD,MAAM,aAAsB,QAAQ;CAClC,SAhCc,EAAE,OAA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;;;AAUd,SAAS,aAAa,QAIF;AAClB,QAAOC,gBAAK,MAAM,OAAO"}
@@ -0,0 +1,11 @@
1
+ import { Command } from "maltty";
2
+
3
+ //#region src/commands/stories.d.ts
4
+ /**
5
+ * Launch the stories viewer TUI for browsing and editing
6
+ * component stories in the terminal.
7
+ */
8
+ declare const storiesCommand: Command;
9
+ //#endregion
10
+ export { storiesCommand as default };
11
+ //# sourceMappingURL=stories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stories.d.ts","names":[],"sources":["../../src/commands/stories.ts"],"mappings":";;;;;AAA6B;;cAkBvB,cAAA,EAAgB,OAAA"}
@@ -0,0 +1,22 @@
1
+ import { z } from "zod";
2
+ import { StoriesScreen } from "maltty/stories";
3
+ import { screen } from "maltty/ui";
4
+ //#region src/commands/stories.ts
5
+ /**
6
+ * Launch the stories viewer TUI for browsing and editing
7
+ * component stories in the terminal.
8
+ */
9
+ const storiesCommand = screen({
10
+ description: "Browse and preview component stories in the terminal",
11
+ options: z.object({
12
+ include: z.string().describe("Glob pattern for story files").optional(),
13
+ out: z.string().describe("Render story to stdout (pass story name, or omit for all)").optional(),
14
+ check: z.boolean().describe("Validate stories for common issues").default(false)
15
+ }),
16
+ exit: "manual",
17
+ render: StoriesScreen
18
+ });
19
+ //#endregion
20
+ export { storiesCommand as default };
21
+
22
+ //# sourceMappingURL=stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stories.js","names":[],"sources":["../../src/commands/stories.ts"],"sourcesContent":["import type { Command } from 'maltty'\nimport { StoriesScreen } from 'maltty/stories'\nimport { screen } from 'maltty/ui'\nimport { z } from 'zod'\n\n/**\n * Options schema for the `maltty stories` command.\n */\nconst options = z.object({\n include: z.string().describe('Glob pattern for story files').optional(),\n out: z.string().describe('Render story to stdout (pass story name, or omit for all)').optional(),\n check: z.boolean().describe('Validate stories for common issues').default(false),\n})\n\n/**\n * Launch the stories viewer TUI for browsing and editing\n * component stories in the terminal.\n */\nconst storiesCommand: Command = screen({\n description: 'Browse and preview component stories in the terminal',\n options,\n exit: 'manual',\n render: StoriesScreen,\n})\n\nexport default storiesCommand\n"],"mappings":";;;;;;;;AAkBA,MAAM,iBAA0B,OAAO;CACrC,aAAa;CACb,SAZc,EAAE,OAAO;EACvB,SAAS,EAAE,QAAQ,CAAC,SAAS,+BAA+B,CAAC,UAAU;EACvE,KAAK,EAAE,QAAQ,CAAC,SAAS,4DAA4D,CAAC,UAAU;EAChG,OAAO,EAAE,SAAS,CAAC,SAAS,qCAAqC,CAAC,QAAQ,MAAM;EACjF,CAAC;CASA,MAAM;CACN,QAAQ;CACT,CAAC"}
@@ -0,0 +1,15 @@
1
+ //#region src/lib/config-helpers.ts
2
+ /**
3
+ * Extract a MalttyConfig from a load result, falling back to empty defaults.
4
+ *
5
+ * @param result - The result from loadConfig, or null when loading failed.
6
+ * @returns The loaded config or an empty object (all MalttyConfig fields are optional).
7
+ */
8
+ function extractConfig(result) {
9
+ if (result) return result.config;
10
+ return {};
11
+ }
12
+ //#endregion
13
+ export { extractConfig as t };
14
+
15
+ //# sourceMappingURL=config-helpers-pv_2Spux.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-helpers-pv_2Spux.js","names":[],"sources":["../src/lib/config-helpers.ts"],"sourcesContent":["import type { MalttyConfig } from '@maltty/config'\nimport type { LoadConfigResult } from '@maltty/config/utils'\n\n/**\n * Extract a MalttyConfig from a load result, falling back to empty defaults.\n *\n * @param result - The result from loadConfig, or null when loading failed.\n * @returns The loaded config or an empty object (all MalttyConfig fields are optional).\n */\nexport function extractConfig(result: LoadConfigResult | null): MalttyConfig {\n if (result) {\n return result.config\n }\n\n return {}\n}\n"],"mappings":";;;;;;;AASA,SAAgB,cAAc,QAA+C;AAC3E,KAAI,OACF,QAAO,OAAO;AAGhB,QAAO,EAAE"}