@bamboocss/dev 1.56.6 → 1.57.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.
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  require("./chunk-C2EiDwsr.cjs");
4
- let worker_threads = require("worker_threads");
4
+ let node_worker_threads = require("node:worker_threads");
5
5
  let _bamboocss_shared = require("@bamboocss/shared");
6
6
  let _bamboocss_logger = require("@bamboocss/logger");
7
7
  let _bamboocss_node = require("@bamboocss/node");
8
8
  let cac = require("cac");
9
- let path = require("path");
9
+ let node_fs = require("node:fs");
10
+ let node_console = require("node:console");
11
+ let node_path = require("node:path");
10
12
  //#region ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/index.mjs
11
13
  let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY = true;
12
14
  if (typeof process !== "undefined") {
@@ -117,7 +119,7 @@ function handleError(error) {
117
119
  console.error($.red(message));
118
120
  }
119
121
  process.exitCode = 1;
120
- if (!worker_threads.isMainThread && worker_threads.parentPort) worker_threads.parentPort.postMessage("error");
122
+ if (!node_worker_threads.isMainThread && node_worker_threads.parentPort) node_worker_threads.parentPort.postMessage("error");
121
123
  }
122
124
  function isLocError(error) {
123
125
  return typeof error === "object" && error !== null && "loc" in error && typeof error.loc === "object" && "message" in error;
@@ -125,7 +127,7 @@ function isLocError(error) {
125
127
  //#endregion
126
128
  //#region package.json
127
129
  var name = "@bamboocss/dev";
128
- var version = "1.56.6";
130
+ var version = "1.57.0";
129
131
  //#endregion
130
132
  //#region src/cli-main.ts
131
133
  /**
@@ -160,6 +162,50 @@ const normalizeStrictTokens = (value) => {
160
162
  if (named === "true" || named === "yes" || named === "on") return true;
161
163
  throw new _bamboocss_shared.BambooError("CONFIG_ERROR", `\`--strict-values ${named}\` is not a setting. Pass it bare to require every value to be a token.`);
162
164
  };
165
+ /**
166
+ * Refuse a word one slip from a command, and naming nothing on disk — `bamboo codgen`.
167
+ *
168
+ * The default command reads its arguments as `include` globs, so a mistyped command matched no
169
+ * files, built a stylesheet from nothing over the real one, and exited 0. `generate` refuses any
170
+ * glob matching nothing; this answers the one case it can say more about, the command meant.
171
+ * Watching or not, as the typo is a typo either way. A word near no command — `bamboo deploy` —
172
+ * is left to `generate`, which watching lets wait for the files to appear.
173
+ */
174
+ const assertKnownCommand = (files, cwd, commands) => {
175
+ for (const file of files) {
176
+ if (!/^[a-z][\w-]*$/i.test(file) || (0, node_fs.existsSync)((0, node_path.resolve)(cwd, file))) continue;
177
+ const suggestion = (0, _bamboocss_shared.closestMatch)(file.toLowerCase(), commands);
178
+ if (!suggestion) continue;
179
+ throw new _bamboocss_shared.BambooError("UNKNOWN_COMMAND", `\`bamboo ${file}\` is not a command; did you mean \`bamboo ${suggestion}\`?`, { hint: "Run `bamboo --help` for the list of commands." });
180
+ }
181
+ };
182
+ function silenced(config, silent) {
183
+ return silent ? {
184
+ ...config,
185
+ logLevel: "silent"
186
+ } : config;
187
+ }
188
+ /**
189
+ * Keep stdout to a command's output, as `bamboo mcp` keeps it to its protocol: the log, which the
190
+ * logger writes through `console`, goes to stderr, and a reader that has gone — `bamboo analyze
191
+ * --unused | head -1` — ends the command, rather than failing it with `EPIPE`.
192
+ */
193
+ const keepStdoutToOutput = () => {
194
+ const toStderr = new node_console.Console({
195
+ stdout: process.stderr,
196
+ stderr: process.stderr
197
+ });
198
+ for (const method of [
199
+ "log",
200
+ "info",
201
+ "debug",
202
+ "dir"
203
+ ]) console[method] = toStderr[method].bind(toStderr);
204
+ process.stdout.on("error", (error) => {
205
+ if (error.code === "EPIPE" || error.code === "ERR_STREAM_DESTROYED") process.exit(0);
206
+ throw error;
207
+ });
208
+ };
163
209
  async function main() {
164
210
  const cli = (0, cac.cac)("bamboo");
165
211
  const cwd = process.cwd();
@@ -167,14 +213,14 @@ async function main() {
167
213
  let options = {};
168
214
  if (initFlags.interactive) {
169
215
  const { interactive } = await Promise.resolve().then(() => require("./interactive-CR8If8u4.cjs"));
170
- options = await interactive({ cwd: (0, path.resolve)(initFlags.cwd ?? "") });
216
+ options = await interactive({ cwd: (0, node_path.resolve)(initFlags.cwd ?? "") });
171
217
  }
172
218
  const flags = {
173
219
  ...initFlags,
174
220
  ...options
175
221
  };
176
222
  const { force, silent, gitignore, outExtension, strictValues, config: configPath } = flags;
177
- const cwd = (0, path.resolve)(flags.cwd ?? "");
223
+ const cwd = (0, node_path.resolve)(flags.cwd ?? "");
178
224
  if (silent) _bamboocss_logger.logger.level = "silent";
179
225
  const stream = (0, _bamboocss_node.setLogStream)({
180
226
  cwd,
@@ -191,10 +237,10 @@ async function main() {
191
237
  const ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
192
238
  cwd,
193
239
  configPath,
194
- config: (0, _bamboocss_shared.compact)({
240
+ config: silenced((0, _bamboocss_shared.compact)({
195
241
  gitignore,
196
242
  outdir: flags.outdir
197
- })
243
+ }), silent)
198
244
  });
199
245
  if (gitignore) (0, _bamboocss_node.setupGitIgnore)(ctx);
200
246
  if (flags.codegen) {
@@ -206,7 +252,7 @@ async function main() {
206
252
  });
207
253
  cli.command("codegen", "Generate the bamboo system").option("--silent", "Don't print any logs").option("--clean", "Clean the output directory before generating").option("-c, --config <path>", "Path to bamboo config file").option("-w, --watch", "Watch files and rebuild").option("-p, --poll", "Use polling instead of filesystem events when watching").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (flags) => {
208
254
  const { silent, clean, config: configPath, watch, poll } = flags;
209
- const cwd = (0, path.resolve)(flags.cwd ?? "");
255
+ const cwd = (0, node_path.resolve)(flags.cwd ?? "");
210
256
  const stream = (0, _bamboocss_node.setLogStream)({
211
257
  cwd,
212
258
  logfile: flags.logfile
@@ -216,7 +262,7 @@ async function main() {
216
262
  if (silent) _bamboocss_logger.logger.level = "silent";
217
263
  let ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
218
264
  cwd,
219
- config: { clean },
265
+ config: silenced((0, _bamboocss_shared.compact)({ clean }), silent),
220
266
  configPath
221
267
  });
222
268
  const { msg } = await (0, _bamboocss_node.codegen)(ctx);
@@ -229,7 +275,7 @@ async function main() {
229
275
  config: ctx.config,
230
276
  changes: affecteds
231
277
  });
232
- await (0, _bamboocss_node.codegen)(ctx, Array.from(affecteds.artifacts));
278
+ await (0, _bamboocss_node.codegen)(ctx, (0, _bamboocss_node.artifactsToRebuild)(affecteds));
233
279
  _bamboocss_logger.logger.info("ctx:updated", "config rebuilt ✅");
234
280
  }, {
235
281
  cwd,
@@ -240,7 +286,7 @@ async function main() {
240
286
  });
241
287
  cli.command("cssgen [globOrType]", "Generate the css from files, or generate the css from the specified type which can be: preflight, tokens, static, global, keyframes").option("--silent", "Don't print any logs").option("-m, --minify", "Minify generated code").option("--clean", "Clean the output before generating").option("-c, --config <path>", "Path to bamboo config file").option("-w, --watch", "Watch files and rebuild").option("-p, --poll", "Use polling instead of filesystem events when watching").option("-o, --outfile [file]", "Output file for extracted css, default to './styled-system/styles.css'").option("--splitting", "Emit CSS as separate files per layer (reset, global, tokens, utilities)").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (maybeGlob, flags = {}) => {
242
288
  const { silent, config: configPath, outfile, watch, poll, splitting, ...rest } = flags;
243
- const cwd = (0, path.resolve)(flags.cwd ?? "");
289
+ const cwd = (0, node_path.resolve)(flags.cwd ?? "");
244
290
  const stream = (0, _bamboocss_node.setLogStream)({
245
291
  cwd,
246
292
  logfile: flags.logfile
@@ -258,10 +304,10 @@ async function main() {
258
304
  if (silent) _bamboocss_logger.logger.level = "silent";
259
305
  let ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
260
306
  cwd,
261
- config: {
307
+ config: silenced({
262
308
  ...rest,
263
309
  ...glob ? { include: [glob] } : void 0
264
- },
310
+ }, silent),
265
311
  configPath
266
312
  });
267
313
  const options = {
@@ -302,9 +348,10 @@ async function main() {
302
348
  stopProfiling();
303
349
  }
304
350
  });
305
- cli.command("[files]", "Include file glob", { ignoreOptionDefaultValue: true }).option("-o, --outdir <dir>", "Output directory", { default: "styled-system" }).option("-m, --minify", "Minify generated code").option("-w, --watch", "Watch files and rebuild").option("-p, --poll", "Use polling instead of filesystem events when watching").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--preflight", "Enable css reset").option("--silent", "Suppress all messages except errors").option("-e, --exclude <files>", "Exclude files", { default: [] }).option("--clean", "Clean output directory").option("--hash", "Hash the generated classnames to make them shorter").option("--emitTokensOnly", "Whether to only emit the `tokens` directory").option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (files, flags) => {
351
+ cli.command("[...files]", "Include file globs", { ignoreOptionDefaultValue: true }).option("-o, --outdir <dir>", "Output directory", { default: "styled-system" }).option("-m, --minify", "Minify generated code").option("-w, --watch", "Watch files and rebuild").option("-p, --poll", "Use polling instead of filesystem events when watching").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--preflight", "Enable css reset").option("--silent", "Suppress all messages except errors").option("-e, --exclude <files>", "Exclude files", { default: [] }).option("--clean", "Clean output directory").option("--hash", "Hash the generated classnames to make them shorter").option("--emitTokensOnly", "Whether to only emit the `tokens` directory").option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (files, flags) => {
306
352
  const { config: configPath, silent, ...rest } = flags;
307
- const cwd = (0, path.resolve)(flags.cwd ?? "");
353
+ const cwd = (0, node_path.resolve)(flags.cwd ?? "");
354
+ assertKnownCommand(files, cwd, cli.commands.map((command) => command.name).filter(Boolean));
308
355
  const stream = (0, _bamboocss_node.setLogStream)({
309
356
  cwd,
310
357
  logfile: flags.logfile
@@ -312,39 +359,67 @@ async function main() {
312
359
  let stopProfiling = () => void 0;
313
360
  if (flags.cpuProf) stopProfiling = await (0, _bamboocss_node.startProfiling)(cwd, "cli", flags.watch);
314
361
  if (silent) _bamboocss_logger.logger.level = "silent";
315
- await (0, _bamboocss_node.generate)((0, _bamboocss_shared.compact)({
316
- include: files,
362
+ await (0, _bamboocss_node.generate)(silenced((0, _bamboocss_shared.compact)({
363
+ include: files.length ? files : void 0,
317
364
  ...rest,
318
365
  cwd
319
- }), configPath);
366
+ }), silent), configPath, { requireFiles: files.length > 0 });
320
367
  stopProfiling();
321
368
  if (!flags.watch) stream.end();
322
369
  });
323
370
  cli.command("spec", "Generate spec files for your theme (useful for documentation)").option("--silent", "Don't print any logs").option("--outdir <dir>", "Output directory for spec files").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (flags) => {
324
371
  const { silent, config: configPath, outdir } = flags;
325
- const cwd = (0, path.resolve)(flags.cwd ?? "");
372
+ const cwd = (0, node_path.resolve)(flags.cwd ?? "");
326
373
  if (silent) _bamboocss_logger.logger.level = "silent";
327
374
  await (0, _bamboocss_node.spec)(await (0, _bamboocss_node.loadConfigAndCreateContext)({
328
375
  cwd,
329
376
  configPath,
330
- config: { cwd }
377
+ config: silenced({ cwd }, silent)
331
378
  }), { outdir });
332
379
  });
333
- cli.command("analyze [glob]", "Analyze design token usage in glob").option("--outfile [filepath]", "Output analyze report in JSON").option("--silent", "Don't print any logs").option("--scope <type>", "Select analysis scope (token or recipe)").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (maybeGlob, flags = {}) => {
334
- const { silent, config: configPath, scope } = flags;
380
+ cli.command("analyze [glob]", "Analyze design token usage in glob").option("--outfile [filepath]", "Output analyze report in JSON").option("--silent", "Don't print any logs").option("--scope <type>", "Select analysis scope: token or recipe, and with --unused pattern or keyframe").option("--unused", "List only the configured names no source uses, one per line").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (maybeGlob, flags = {}) => {
381
+ const { silent, config: configPath } = flags;
382
+ const scope = flags.scope?.replace(/s$/, "");
383
+ if (scope != null && ![
384
+ "token",
385
+ "recipe",
386
+ "pattern",
387
+ "keyframe"
388
+ ].includes(scope)) throw new _bamboocss_shared.BambooError("INVALID_FLAG", `--scope is one of token, recipe, pattern or keyframe, not "${flags.scope}".`);
389
+ if (!flags.unused && (scope === "pattern" || scope === "keyframe")) throw new _bamboocss_shared.BambooError("INVALID_FLAG", `--scope ${scope} lists what is unused, with --unused.`);
335
390
  const tokenScope = scope == null || scope === "token";
336
391
  const recipeScope = scope == null || scope === "recipe";
337
- const cwd = (0, path.resolve)(flags.cwd);
392
+ const cwd = (0, node_path.resolve)(flags.cwd);
338
393
  if (silent) _bamboocss_logger.logger.level = "silent";
394
+ const outfile = typeof flags.outfile === "string" ? (0, node_path.resolve)(flags.outfile) : void 0;
395
+ if (flags.unused && !outfile) keepStdoutToOutput();
339
396
  const ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
340
397
  cwd,
341
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
398
+ config: silenced((0, _bamboocss_shared.compact)({ include: maybeGlob ? [maybeGlob] : void 0 }), silent),
342
399
  configPath
343
400
  });
344
401
  const result = await (0, _bamboocss_node.analyze)(ctx);
402
+ if (flags.unused) {
403
+ const keys = {
404
+ token: "tokens",
405
+ recipe: "recipes",
406
+ pattern: "patterns",
407
+ keyframe: "keyframes"
408
+ };
409
+ const scoped = scope ? keys[scope] : void 0;
410
+ const unused = result.getUnused(scoped ? [scoped] : void 0);
411
+ if (outfile) {
412
+ await result.writeUnused(outfile, scoped ? { [scoped]: unused[scoped] } : unused);
413
+ _bamboocss_logger.logger.info("cli", `JSON report saved to ${outfile}`);
414
+ return;
415
+ }
416
+ const lines = Object.entries(keys).flatMap(([kind, key]) => scoped == null ? unused[key].map((name) => `${kind} ${name}`) : key === scoped ? unused[key] : []);
417
+ if (lines.length) process.stdout.write(lines.join("\n") + "\n");
418
+ return;
419
+ }
345
420
  if (flags?.outfile && typeof flags.outfile === "string") {
346
421
  await result.writeReport(flags.outfile);
347
- _bamboocss_logger.logger.info("cli", `JSON report saved to ${(0, path.resolve)(flags.outfile)}`);
422
+ _bamboocss_logger.logger.info("cli", `JSON report saved to ${(0, node_path.resolve)(flags.outfile)}`);
348
423
  return;
349
424
  }
350
425
  if (tokenScope) if (!ctx.tokens.isEmpty) {
@@ -356,9 +431,20 @@ async function main() {
356
431
  _bamboocss_logger.logger.info("analyze:recipes", `Config recipes usage report 🎛️ \n${recipeAnalysis.formatted}`);
357
432
  } else _bamboocss_logger.logger.info("analyze:recipes", "No config recipes found");
358
433
  });
359
- cli.command("debug [glob]", "Debug design token extraction & css generated from files in glob").option("--silent", "Don't print any logs").option("--dry", "Output debug files in stdout without writing to disk").option("--outdir [dir]", "Output directory for debug files, default to './styled-system/debug'").option("--only-config", "Should only output the config file, default to 'false'").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (maybeGlob, flags = {}) => {
434
+ cli.command("doctor", "Check the project as the build reads it: its config, sources and generated files").option("--json", "Print the report as JSON").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (flags = {}) => {
435
+ const cwd = (0, node_path.resolve)(flags.cwd);
436
+ if (flags.json) keepStdoutToOutput();
437
+ const report = await (0, _bamboocss_node.doctor)(await (0, _bamboocss_node.loadConfigAndCreateContext)({
438
+ cwd,
439
+ configPath: flags.config
440
+ }));
441
+ process.stdout.write((flags.json ? JSON.stringify(report, null, 2) : (0, _bamboocss_node.formatDoctorReport)(report)) + "\n");
442
+ if (report.problems.length) process.exitCode = 1;
443
+ });
444
+ cli.command("debug [glob]", "Debug design token extraction & css generated from files in glob").option("--silent", "Don't print any logs").option("--dry", "Output debug files in stdout without writing to disk").option("--outdir [dir]", "Output directory for debug files, default to './styled-system/debug'").option("--only-config", "Should only output the config file, default to 'false'").option("--zip", "Write the debug files as one <outdir>.zip, to attach to a bug report").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (maybeGlob, flags = {}) => {
360
445
  const { silent, dry = false, outdir: outdirFlag, config: configPath } = flags ?? {};
361
- const cwd = (0, path.resolve)(flags.cwd);
446
+ if (dry && flags.zip) throw new _bamboocss_shared.BambooError("INVALID_FLAG", "--zip writes an archive, and --dry writes nothing.");
447
+ const cwd = (0, node_path.resolve)(flags.cwd);
362
448
  const stream = (0, _bamboocss_node.setLogStream)({
363
449
  cwd,
364
450
  logfile: flags.logfile
@@ -368,28 +454,31 @@ async function main() {
368
454
  if (silent) _bamboocss_logger.logger.level = "silent";
369
455
  const ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
370
456
  cwd,
371
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
457
+ config: silenced(maybeGlob ? { include: [maybeGlob] } : void 0, silent),
372
458
  configPath
373
459
  });
374
460
  await (0, _bamboocss_node.debug)(ctx, {
375
- outdir: outdirFlag ?? (0, path.join)(...ctx.paths.root, "debug"),
461
+ outdir: typeof outdirFlag === "string" ? outdirFlag : (0, node_path.join)(...ctx.paths.root, "debug"),
376
462
  dry,
377
- onlyConfig: flags.onlyConfig
463
+ onlyConfig: flags.onlyConfig,
464
+ zip: flags.zip
378
465
  });
379
466
  stopProfiling();
380
467
  stream.end();
381
468
  });
382
469
  cli.command("ship [glob]", "Ship extract result from files in glob").option("--silent", "Don't print any logs").option("--o, --outfile [file]", "Output path for the build info file, default to './styled-system/bamboo.buildinfo.json'").option("-m, --minify", "Minify generated JSON file").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("-w, --watch", "Watch files and rebuild").option("-p, --poll", "Use polling instead of filesystem events when watching").action(async (maybeGlob, flags = {}) => {
383
470
  const { silent, outfile: outfileFlag, minify, config: configPath, watch, poll } = flags;
384
- const cwd = (0, path.resolve)(flags.cwd);
471
+ const cwd = (0, node_path.resolve)(flags.cwd);
385
472
  if (silent) _bamboocss_logger.logger.level = "silent";
386
473
  let ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
387
474
  cwd,
388
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
475
+ config: silenced((0, _bamboocss_shared.compact)({
476
+ include: maybeGlob ? [maybeGlob] : void 0,
477
+ minify
478
+ }), silent),
389
479
  configPath
390
480
  });
391
- const outfile = outfileFlag ?? (0, path.join)(...ctx.paths.root, "bamboo.buildinfo.json");
392
- if (minify) ctx.config.minify = true;
481
+ const outfile = outfileFlag ?? (0, node_path.join)(...ctx.paths.root, "bamboo.buildinfo.json");
393
482
  await (0, _bamboocss_node.buildInfo)(ctx, outfile);
394
483
  if (watch) {
395
484
  ctx.watchConfig(async () => {
@@ -421,12 +510,12 @@ async function main() {
421
510
  cli.command("emit-pkg", "Emit package.json with entrypoints").option("--outdir <dir>", "Output directory", { default: "." }).option("--base <source>", "The base directory of the package.json entrypoints").option("--silent", "Don't print any logs").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (flags) => {
422
511
  const { outdir, silent, base } = flags;
423
512
  if (silent) _bamboocss_logger.logger.level = "silent";
424
- const cwd = (0, path.resolve)(flags.cwd);
513
+ const cwd = (0, node_path.resolve)(flags.cwd);
425
514
  const ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
426
515
  cwd,
427
- config: { cwd }
516
+ config: silenced({ cwd }, silent)
428
517
  });
429
- const pkgPath = (0, path.resolve)(cwd, outdir, "package.json");
518
+ const pkgPath = (0, node_path.resolve)(cwd, outdir, "package.json");
430
519
  const exists = ctx.runtime.fs.existsSync(pkgPath);
431
520
  /**
432
521
  * The same map codegen writes into the outdir, re-derived here with the package's
@@ -495,8 +584,8 @@ async function main() {
495
584
  process.exitCode = 1;
496
585
  });
497
586
  cli.command("init-mcp", "Initialize MCP configuration for AI clients").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--client <clients>", "AI clients to configure (claude, cursor, vscode, windsurf, codex)").action(async (mcpInitFlags) => {
498
- const { initMcpConfig } = await Promise.resolve().then(() => require("./mcp-init-DAn6FsEJ.cjs"));
499
- const resolvedCwd = (0, path.resolve)(mcpInitFlags.cwd ?? cwd);
587
+ const { initMcpConfig } = await Promise.resolve().then(() => require("./mcp-init-DPvpdzws.cjs"));
588
+ const resolvedCwd = (0, node_path.resolve)(mcpInitFlags.cwd ?? cwd);
500
589
  let clients;
501
590
  if (mcpInitFlags.client) clients = (Array.isArray(mcpInitFlags.client) ? mcpInitFlags.client : [mcpInitFlags.client]).flatMap((c) => c.split(",")).map((c) => c.trim());
502
591
  await initMcpConfig({
@@ -521,7 +610,7 @@ async function main() {
521
610
  * lands in a log nobody opens. Gating on a TTY and importing dynamically keeps the tree in a
522
611
  * chunk that only an interactive run loads.
523
612
  */
524
- if (process.stdout.isTTY) Promise.resolve().then(() => require("./update-notifier-Bne2G0qU.cjs")).then(({ default: updateNotifier }) => updateNotifier({
613
+ if (process.stdout.isTTY) Promise.resolve().then(() => require("./update-notifier-BiU20Gpu.cjs")).then(({ default: updateNotifier }) => updateNotifier({
525
614
  pkg: {
526
615
  name,
527
616
  version
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { isMainThread, parentPort } from "worker_threads";
3
- import { BambooError, compact } from "@bamboocss/shared";
2
+ import { isMainThread, parentPort } from "node:worker_threads";
3
+ import { BambooError, closestMatch, compact } from "@bamboocss/shared";
4
4
  import { logger } from "@bamboocss/logger";
5
- import { BambooContext, analyze, buildInfo, codegen, cssgen, debug, generate, generatePackageExports, loadConfigAndCreateContext, setLogStream, setupConfig, setupGitIgnore, spec, startProfiling } from "@bamboocss/node";
5
+ import { BambooContext, analyze, artifactsToRebuild, buildInfo, codegen, cssgen, debug, doctor, formatDoctorReport, generate, generatePackageExports, loadConfigAndCreateContext, setLogStream, setupConfig, setupGitIgnore, spec, startProfiling } from "@bamboocss/node";
6
6
  import { cac } from "cac";
7
- import { join, resolve } from "path";
7
+ import { existsSync } from "node:fs";
8
+ import { Console } from "node:console";
9
+ import { join, resolve } from "node:path";
8
10
  //#region ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/index.mjs
9
11
  let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY = true;
10
12
  if (typeof process !== "undefined") {
@@ -123,7 +125,7 @@ function isLocError(error) {
123
125
  //#endregion
124
126
  //#region package.json
125
127
  var name = "@bamboocss/dev";
126
- var version = "1.56.6";
128
+ var version = "1.57.0";
127
129
  //#endregion
128
130
  //#region src/cli-main.ts
129
131
  /**
@@ -158,6 +160,50 @@ const normalizeStrictTokens = (value) => {
158
160
  if (named === "true" || named === "yes" || named === "on") return true;
159
161
  throw new BambooError("CONFIG_ERROR", `\`--strict-values ${named}\` is not a setting. Pass it bare to require every value to be a token.`);
160
162
  };
163
+ /**
164
+ * Refuse a word one slip from a command, and naming nothing on disk — `bamboo codgen`.
165
+ *
166
+ * The default command reads its arguments as `include` globs, so a mistyped command matched no
167
+ * files, built a stylesheet from nothing over the real one, and exited 0. `generate` refuses any
168
+ * glob matching nothing; this answers the one case it can say more about, the command meant.
169
+ * Watching or not, as the typo is a typo either way. A word near no command — `bamboo deploy` —
170
+ * is left to `generate`, which watching lets wait for the files to appear.
171
+ */
172
+ const assertKnownCommand = (files, cwd, commands) => {
173
+ for (const file of files) {
174
+ if (!/^[a-z][\w-]*$/i.test(file) || existsSync(resolve(cwd, file))) continue;
175
+ const suggestion = closestMatch(file.toLowerCase(), commands);
176
+ if (!suggestion) continue;
177
+ throw new BambooError("UNKNOWN_COMMAND", `\`bamboo ${file}\` is not a command; did you mean \`bamboo ${suggestion}\`?`, { hint: "Run `bamboo --help` for the list of commands." });
178
+ }
179
+ };
180
+ function silenced(config, silent) {
181
+ return silent ? {
182
+ ...config,
183
+ logLevel: "silent"
184
+ } : config;
185
+ }
186
+ /**
187
+ * Keep stdout to a command's output, as `bamboo mcp` keeps it to its protocol: the log, which the
188
+ * logger writes through `console`, goes to stderr, and a reader that has gone — `bamboo analyze
189
+ * --unused | head -1` — ends the command, rather than failing it with `EPIPE`.
190
+ */
191
+ const keepStdoutToOutput = () => {
192
+ const toStderr = new Console({
193
+ stdout: process.stderr,
194
+ stderr: process.stderr
195
+ });
196
+ for (const method of [
197
+ "log",
198
+ "info",
199
+ "debug",
200
+ "dir"
201
+ ]) console[method] = toStderr[method].bind(toStderr);
202
+ process.stdout.on("error", (error) => {
203
+ if (error.code === "EPIPE" || error.code === "ERR_STREAM_DESTROYED") process.exit(0);
204
+ throw error;
205
+ });
206
+ };
161
207
  async function main() {
162
208
  const cli = cac("bamboo");
163
209
  const cwd = process.cwd();
@@ -189,10 +235,10 @@ async function main() {
189
235
  const ctx = await loadConfigAndCreateContext({
190
236
  cwd,
191
237
  configPath,
192
- config: compact({
238
+ config: silenced(compact({
193
239
  gitignore,
194
240
  outdir: flags.outdir
195
- })
241
+ }), silent)
196
242
  });
197
243
  if (gitignore) setupGitIgnore(ctx);
198
244
  if (flags.codegen) {
@@ -214,7 +260,7 @@ async function main() {
214
260
  if (silent) logger.level = "silent";
215
261
  let ctx = await loadConfigAndCreateContext({
216
262
  cwd,
217
- config: { clean },
263
+ config: silenced(compact({ clean }), silent),
218
264
  configPath
219
265
  });
220
266
  const { msg } = await codegen(ctx);
@@ -227,7 +273,7 @@ async function main() {
227
273
  config: ctx.config,
228
274
  changes: affecteds
229
275
  });
230
- await codegen(ctx, Array.from(affecteds.artifacts));
276
+ await codegen(ctx, artifactsToRebuild(affecteds));
231
277
  logger.info("ctx:updated", "config rebuilt ✅");
232
278
  }, {
233
279
  cwd,
@@ -256,10 +302,10 @@ async function main() {
256
302
  if (silent) logger.level = "silent";
257
303
  let ctx = await loadConfigAndCreateContext({
258
304
  cwd,
259
- config: {
305
+ config: silenced({
260
306
  ...rest,
261
307
  ...glob ? { include: [glob] } : void 0
262
- },
308
+ }, silent),
263
309
  configPath
264
310
  });
265
311
  const options = {
@@ -300,9 +346,10 @@ async function main() {
300
346
  stopProfiling();
301
347
  }
302
348
  });
303
- cli.command("[files]", "Include file glob", { ignoreOptionDefaultValue: true }).option("-o, --outdir <dir>", "Output directory", { default: "styled-system" }).option("-m, --minify", "Minify generated code").option("-w, --watch", "Watch files and rebuild").option("-p, --poll", "Use polling instead of filesystem events when watching").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--preflight", "Enable css reset").option("--silent", "Suppress all messages except errors").option("-e, --exclude <files>", "Exclude files", { default: [] }).option("--clean", "Clean output directory").option("--hash", "Hash the generated classnames to make them shorter").option("--emitTokensOnly", "Whether to only emit the `tokens` directory").option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (files, flags) => {
349
+ cli.command("[...files]", "Include file globs", { ignoreOptionDefaultValue: true }).option("-o, --outdir <dir>", "Output directory", { default: "styled-system" }).option("-m, --minify", "Minify generated code").option("-w, --watch", "Watch files and rebuild").option("-p, --poll", "Use polling instead of filesystem events when watching").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--preflight", "Enable css reset").option("--silent", "Suppress all messages except errors").option("-e, --exclude <files>", "Exclude files", { default: [] }).option("--clean", "Clean output directory").option("--hash", "Hash the generated classnames to make them shorter").option("--emitTokensOnly", "Whether to only emit the `tokens` directory").option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (files, flags) => {
304
350
  const { config: configPath, silent, ...rest } = flags;
305
351
  const cwd = resolve(flags.cwd ?? "");
352
+ assertKnownCommand(files, cwd, cli.commands.map((command) => command.name).filter(Boolean));
306
353
  const stream = setLogStream({
307
354
  cwd,
308
355
  logfile: flags.logfile
@@ -310,11 +357,11 @@ async function main() {
310
357
  let stopProfiling = () => void 0;
311
358
  if (flags.cpuProf) stopProfiling = await startProfiling(cwd, "cli", flags.watch);
312
359
  if (silent) logger.level = "silent";
313
- await generate(compact({
314
- include: files,
360
+ await generate(silenced(compact({
361
+ include: files.length ? files : void 0,
315
362
  ...rest,
316
363
  cwd
317
- }), configPath);
364
+ }), silent), configPath, { requireFiles: files.length > 0 });
318
365
  stopProfiling();
319
366
  if (!flags.watch) stream.end();
320
367
  });
@@ -325,21 +372,49 @@ async function main() {
325
372
  await spec(await loadConfigAndCreateContext({
326
373
  cwd,
327
374
  configPath,
328
- config: { cwd }
375
+ config: silenced({ cwd }, silent)
329
376
  }), { outdir });
330
377
  });
331
- cli.command("analyze [glob]", "Analyze design token usage in glob").option("--outfile [filepath]", "Output analyze report in JSON").option("--silent", "Don't print any logs").option("--scope <type>", "Select analysis scope (token or recipe)").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (maybeGlob, flags = {}) => {
332
- const { silent, config: configPath, scope } = flags;
378
+ cli.command("analyze [glob]", "Analyze design token usage in glob").option("--outfile [filepath]", "Output analyze report in JSON").option("--silent", "Don't print any logs").option("--scope <type>", "Select analysis scope: token or recipe, and with --unused pattern or keyframe").option("--unused", "List only the configured names no source uses, one per line").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (maybeGlob, flags = {}) => {
379
+ const { silent, config: configPath } = flags;
380
+ const scope = flags.scope?.replace(/s$/, "");
381
+ if (scope != null && ![
382
+ "token",
383
+ "recipe",
384
+ "pattern",
385
+ "keyframe"
386
+ ].includes(scope)) throw new BambooError("INVALID_FLAG", `--scope is one of token, recipe, pattern or keyframe, not "${flags.scope}".`);
387
+ if (!flags.unused && (scope === "pattern" || scope === "keyframe")) throw new BambooError("INVALID_FLAG", `--scope ${scope} lists what is unused, with --unused.`);
333
388
  const tokenScope = scope == null || scope === "token";
334
389
  const recipeScope = scope == null || scope === "recipe";
335
390
  const cwd = resolve(flags.cwd);
336
391
  if (silent) logger.level = "silent";
392
+ const outfile = typeof flags.outfile === "string" ? resolve(flags.outfile) : void 0;
393
+ if (flags.unused && !outfile) keepStdoutToOutput();
337
394
  const ctx = await loadConfigAndCreateContext({
338
395
  cwd,
339
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
396
+ config: silenced(compact({ include: maybeGlob ? [maybeGlob] : void 0 }), silent),
340
397
  configPath
341
398
  });
342
399
  const result = await analyze(ctx);
400
+ if (flags.unused) {
401
+ const keys = {
402
+ token: "tokens",
403
+ recipe: "recipes",
404
+ pattern: "patterns",
405
+ keyframe: "keyframes"
406
+ };
407
+ const scoped = scope ? keys[scope] : void 0;
408
+ const unused = result.getUnused(scoped ? [scoped] : void 0);
409
+ if (outfile) {
410
+ await result.writeUnused(outfile, scoped ? { [scoped]: unused[scoped] } : unused);
411
+ logger.info("cli", `JSON report saved to ${outfile}`);
412
+ return;
413
+ }
414
+ const lines = Object.entries(keys).flatMap(([kind, key]) => scoped == null ? unused[key].map((name) => `${kind} ${name}`) : key === scoped ? unused[key] : []);
415
+ if (lines.length) process.stdout.write(lines.join("\n") + "\n");
416
+ return;
417
+ }
343
418
  if (flags?.outfile && typeof flags.outfile === "string") {
344
419
  await result.writeReport(flags.outfile);
345
420
  logger.info("cli", `JSON report saved to ${resolve(flags.outfile)}`);
@@ -354,8 +429,19 @@ async function main() {
354
429
  logger.info("analyze:recipes", `Config recipes usage report 🎛️ \n${recipeAnalysis.formatted}`);
355
430
  } else logger.info("analyze:recipes", "No config recipes found");
356
431
  });
357
- cli.command("debug [glob]", "Debug design token extraction & css generated from files in glob").option("--silent", "Don't print any logs").option("--dry", "Output debug files in stdout without writing to disk").option("--outdir [dir]", "Output directory for debug files, default to './styled-system/debug'").option("--only-config", "Should only output the config file, default to 'false'").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (maybeGlob, flags = {}) => {
432
+ cli.command("doctor", "Check the project as the build reads it: its config, sources and generated files").option("--json", "Print the report as JSON").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(async (flags = {}) => {
433
+ const cwd = resolve(flags.cwd);
434
+ if (flags.json) keepStdoutToOutput();
435
+ const report = await doctor(await loadConfigAndCreateContext({
436
+ cwd,
437
+ configPath: flags.config
438
+ }));
439
+ process.stdout.write((flags.json ? JSON.stringify(report, null, 2) : formatDoctorReport(report)) + "\n");
440
+ if (report.problems.length) process.exitCode = 1;
441
+ });
442
+ cli.command("debug [glob]", "Debug design token extraction & css generated from files in glob").option("--silent", "Don't print any logs").option("--dry", "Output debug files in stdout without writing to disk").option("--outdir [dir]", "Output directory for debug files, default to './styled-system/debug'").option("--only-config", "Should only output the config file, default to 'false'").option("--zip", "Write the debug files as one <outdir>.zip, to attach to a bug report").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--cpu-prof", "Generates a `.cpuprofile` to help debug performance issues").option("--logfile <file>", "Outputs logs to a file").action(async (maybeGlob, flags = {}) => {
358
443
  const { silent, dry = false, outdir: outdirFlag, config: configPath } = flags ?? {};
444
+ if (dry && flags.zip) throw new BambooError("INVALID_FLAG", "--zip writes an archive, and --dry writes nothing.");
359
445
  const cwd = resolve(flags.cwd);
360
446
  const stream = setLogStream({
361
447
  cwd,
@@ -366,13 +452,14 @@ async function main() {
366
452
  if (silent) logger.level = "silent";
367
453
  const ctx = await loadConfigAndCreateContext({
368
454
  cwd,
369
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
455
+ config: silenced(maybeGlob ? { include: [maybeGlob] } : void 0, silent),
370
456
  configPath
371
457
  });
372
458
  await debug(ctx, {
373
- outdir: outdirFlag ?? join(...ctx.paths.root, "debug"),
459
+ outdir: typeof outdirFlag === "string" ? outdirFlag : join(...ctx.paths.root, "debug"),
374
460
  dry,
375
- onlyConfig: flags.onlyConfig
461
+ onlyConfig: flags.onlyConfig,
462
+ zip: flags.zip
376
463
  });
377
464
  stopProfiling();
378
465
  stream.end();
@@ -383,11 +470,13 @@ async function main() {
383
470
  if (silent) logger.level = "silent";
384
471
  let ctx = await loadConfigAndCreateContext({
385
472
  cwd,
386
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
473
+ config: silenced(compact({
474
+ include: maybeGlob ? [maybeGlob] : void 0,
475
+ minify
476
+ }), silent),
387
477
  configPath
388
478
  });
389
479
  const outfile = outfileFlag ?? join(...ctx.paths.root, "bamboo.buildinfo.json");
390
- if (minify) ctx.config.minify = true;
391
480
  await buildInfo(ctx, outfile);
392
481
  if (watch) {
393
482
  ctx.watchConfig(async () => {
@@ -422,7 +511,7 @@ async function main() {
422
511
  const cwd = resolve(flags.cwd);
423
512
  const ctx = await loadConfigAndCreateContext({
424
513
  cwd,
425
- config: { cwd }
514
+ config: silenced({ cwd }, silent)
426
515
  });
427
516
  const pkgPath = resolve(cwd, outdir, "package.json");
428
517
  const exists = ctx.runtime.fs.existsSync(pkgPath);
@@ -493,7 +582,7 @@ async function main() {
493
582
  process.exitCode = 1;
494
583
  });
495
584
  cli.command("init-mcp", "Initialize MCP configuration for AI clients").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--client <clients>", "AI clients to configure (claude, cursor, vscode, windsurf, codex)").action(async (mcpInitFlags) => {
496
- const { initMcpConfig } = await import("./mcp-init-MPfnXfaE.mjs");
585
+ const { initMcpConfig } = await import("./mcp-init-DbWbUOwg.mjs");
497
586
  const resolvedCwd = resolve(mcpInitFlags.cwd ?? cwd);
498
587
  let clients;
499
588
  if (mcpInitFlags.client) clients = (Array.isArray(mcpInitFlags.client) ? mcpInitFlags.client : [mcpInitFlags.client]).flatMap((c) => c.split(",")).map((c) => c.trim());
@@ -519,7 +608,7 @@ async function main() {
519
608
  * lands in a log nobody opens. Gating on a TTY and importing dynamically keeps the tree in a
520
609
  * chunk that only an interactive run loads.
521
610
  */
522
- if (process.stdout.isTTY) import("./update-notifier-SlOlBi-b.mjs").then(({ default: updateNotifier }) => updateNotifier({
611
+ if (process.stdout.isTTY) import("./update-notifier-Cv5chHXk.mjs").then(({ default: updateNotifier }) => updateNotifier({
523
612
  pkg: {
524
613
  name,
525
614
  version