@bamboocss/dev 1.56.7 → 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.
package/dist/cli-main.cjs CHANGED
@@ -1,11 +1,13 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("./chunk-CKQMccvm.cjs");
3
- const require_package = require("./package-bb-vfRkr.cjs");
3
+ const require_package = require("./package-DWYvR3kk.cjs");
4
4
  let _bamboocss_logger = require("@bamboocss/logger");
5
5
  let _bamboocss_node = require("@bamboocss/node");
6
6
  let _bamboocss_shared = require("@bamboocss/shared");
7
7
  let cac = require("cac");
8
- let path = require("path");
8
+ let node_fs = require("node:fs");
9
+ let node_console = require("node:console");
10
+ let node_path = require("node:path");
9
11
  //#region src/cli-main.ts
10
12
  /**
11
13
  * The negative spellings, answered here rather than left to cac, which only recognises
@@ -39,21 +41,65 @@ const normalizeStrictTokens = (value) => {
39
41
  if (named === "true" || named === "yes" || named === "on") return true;
40
42
  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.`);
41
43
  };
44
+ /**
45
+ * Refuse a word one slip from a command, and naming nothing on disk — `bamboo codgen`.
46
+ *
47
+ * The default command reads its arguments as `include` globs, so a mistyped command matched no
48
+ * files, built a stylesheet from nothing over the real one, and exited 0. `generate` refuses any
49
+ * glob matching nothing; this answers the one case it can say more about, the command meant.
50
+ * Watching or not, as the typo is a typo either way. A word near no command — `bamboo deploy` —
51
+ * is left to `generate`, which watching lets wait for the files to appear.
52
+ */
53
+ const assertKnownCommand = (files, cwd, commands) => {
54
+ for (const file of files) {
55
+ if (!/^[a-z][\w-]*$/i.test(file) || (0, node_fs.existsSync)((0, node_path.resolve)(cwd, file))) continue;
56
+ const suggestion = (0, _bamboocss_shared.closestMatch)(file.toLowerCase(), commands);
57
+ if (!suggestion) continue;
58
+ 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." });
59
+ }
60
+ };
61
+ function silenced(config, silent) {
62
+ return silent ? {
63
+ ...config,
64
+ logLevel: "silent"
65
+ } : config;
66
+ }
67
+ /**
68
+ * Keep stdout to a command's output, as `bamboo mcp` keeps it to its protocol: the log, which the
69
+ * logger writes through `console`, goes to stderr, and a reader that has gone — `bamboo analyze
70
+ * --unused | head -1` — ends the command, rather than failing it with `EPIPE`.
71
+ */
72
+ const keepStdoutToOutput = () => {
73
+ const toStderr = new node_console.Console({
74
+ stdout: process.stderr,
75
+ stderr: process.stderr
76
+ });
77
+ for (const method of [
78
+ "log",
79
+ "info",
80
+ "debug",
81
+ "dir"
82
+ ]) console[method] = toStderr[method].bind(toStderr);
83
+ process.stdout.on("error", (error) => {
84
+ if (error.code === "EPIPE" || error.code === "ERR_STREAM_DESTROYED") process.exit(0);
85
+ throw error;
86
+ });
87
+ };
42
88
  async function main() {
43
89
  const cli = (0, cac.cac)("bamboo");
44
90
  const cwd = process.cwd();
45
91
  cli.command("init", "Initialize the bamboo config file").option("-i, --interactive", "Run in interactive mode", { default: false }).option("-f, --force", "Force overwrite existing config file").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--silent", "Suppress all messages except errors").option("--no-gitignore", "Don't update the .gitignore").option("--no-codegen", "Don't run the codegen logic").option("--out-extension <ext>", "The extension of the generated js files (default: 'mjs')").option("--outdir <dir>", "The output directory for the generated files").option("--strict-values [mode]", "Require every style value to be a token, so a raw css value is written `[14px]`").option("--logfile <file>", "Outputs logs to a file").action(async (initFlags = {}) => {
46
92
  let options = {};
47
93
  if (initFlags.interactive) {
48
- const { interactive } = await Promise.resolve().then(() => require("./interactive-DkhMVz6R.cjs"));
49
- options = await interactive({ cwd: (0, path.resolve)(initFlags.cwd ?? "") });
94
+ const { interactive } = await Promise.resolve().then(() => require("./interactive-DQdQtZSY.cjs"));
95
+ options = await interactive({ cwd: (0, node_path.resolve)(initFlags.cwd ?? "") });
50
96
  }
51
97
  const flags = {
52
98
  ...initFlags,
53
99
  ...options
54
100
  };
55
101
  const { force, silent, gitignore, outExtension, strictValues, config: configPath } = flags;
56
- const cwd = (0, path.resolve)(flags.cwd ?? "");
102
+ const cwd = (0, node_path.resolve)(flags.cwd ?? "");
57
103
  if (silent) _bamboocss_logger.logger.level = "silent";
58
104
  const stream = (0, _bamboocss_node.setLogStream)({
59
105
  cwd,
@@ -70,10 +116,10 @@ async function main() {
70
116
  const ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
71
117
  cwd,
72
118
  configPath,
73
- config: (0, _bamboocss_shared.compact)({
119
+ config: silenced((0, _bamboocss_shared.compact)({
74
120
  gitignore,
75
121
  outdir: flags.outdir
76
- })
122
+ }), silent)
77
123
  });
78
124
  if (gitignore) (0, _bamboocss_node.setupGitIgnore)(ctx);
79
125
  if (flags.codegen) {
@@ -85,7 +131,7 @@ async function main() {
85
131
  });
86
132
  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) => {
87
133
  const { silent, clean, config: configPath, watch, poll } = flags;
88
- const cwd = (0, path.resolve)(flags.cwd ?? "");
134
+ const cwd = (0, node_path.resolve)(flags.cwd ?? "");
89
135
  const stream = (0, _bamboocss_node.setLogStream)({
90
136
  cwd,
91
137
  logfile: flags.logfile
@@ -95,7 +141,7 @@ async function main() {
95
141
  if (silent) _bamboocss_logger.logger.level = "silent";
96
142
  let ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
97
143
  cwd,
98
- config: { clean },
144
+ config: silenced((0, _bamboocss_shared.compact)({ clean }), silent),
99
145
  configPath
100
146
  });
101
147
  const { msg } = await (0, _bamboocss_node.codegen)(ctx);
@@ -108,7 +154,7 @@ async function main() {
108
154
  config: ctx.config,
109
155
  changes: affecteds
110
156
  });
111
- await (0, _bamboocss_node.codegen)(ctx, Array.from(affecteds.artifacts));
157
+ await (0, _bamboocss_node.codegen)(ctx, (0, _bamboocss_node.artifactsToRebuild)(affecteds));
112
158
  _bamboocss_logger.logger.info("ctx:updated", "config rebuilt ✅");
113
159
  }, {
114
160
  cwd,
@@ -119,7 +165,7 @@ async function main() {
119
165
  });
120
166
  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 = {}) => {
121
167
  const { silent, config: configPath, outfile, watch, poll, splitting, ...rest } = flags;
122
- const cwd = (0, path.resolve)(flags.cwd ?? "");
168
+ const cwd = (0, node_path.resolve)(flags.cwd ?? "");
123
169
  const stream = (0, _bamboocss_node.setLogStream)({
124
170
  cwd,
125
171
  logfile: flags.logfile
@@ -137,10 +183,10 @@ async function main() {
137
183
  if (silent) _bamboocss_logger.logger.level = "silent";
138
184
  let ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
139
185
  cwd,
140
- config: {
186
+ config: silenced({
141
187
  ...rest,
142
188
  ...glob ? { include: [glob] } : void 0
143
- },
189
+ }, silent),
144
190
  configPath
145
191
  });
146
192
  const options = {
@@ -181,9 +227,10 @@ async function main() {
181
227
  stopProfiling();
182
228
  }
183
229
  });
184
- 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) => {
230
+ 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) => {
185
231
  const { config: configPath, silent, ...rest } = flags;
186
- const cwd = (0, path.resolve)(flags.cwd ?? "");
232
+ const cwd = (0, node_path.resolve)(flags.cwd ?? "");
233
+ assertKnownCommand(files, cwd, cli.commands.map((command) => command.name).filter(Boolean));
187
234
  const stream = (0, _bamboocss_node.setLogStream)({
188
235
  cwd,
189
236
  logfile: flags.logfile
@@ -191,39 +238,67 @@ async function main() {
191
238
  let stopProfiling = () => void 0;
192
239
  if (flags.cpuProf) stopProfiling = await (0, _bamboocss_node.startProfiling)(cwd, "cli", flags.watch);
193
240
  if (silent) _bamboocss_logger.logger.level = "silent";
194
- await (0, _bamboocss_node.generate)((0, _bamboocss_shared.compact)({
195
- include: files,
241
+ await (0, _bamboocss_node.generate)(silenced((0, _bamboocss_shared.compact)({
242
+ include: files.length ? files : void 0,
196
243
  ...rest,
197
244
  cwd
198
- }), configPath);
245
+ }), silent), configPath, { requireFiles: files.length > 0 });
199
246
  stopProfiling();
200
247
  if (!flags.watch) stream.end();
201
248
  });
202
249
  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) => {
203
250
  const { silent, config: configPath, outdir } = flags;
204
- const cwd = (0, path.resolve)(flags.cwd ?? "");
251
+ const cwd = (0, node_path.resolve)(flags.cwd ?? "");
205
252
  if (silent) _bamboocss_logger.logger.level = "silent";
206
253
  await (0, _bamboocss_node.spec)(await (0, _bamboocss_node.loadConfigAndCreateContext)({
207
254
  cwd,
208
255
  configPath,
209
- config: { cwd }
256
+ config: silenced({ cwd }, silent)
210
257
  }), { outdir });
211
258
  });
212
- 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 = {}) => {
213
- const { silent, config: configPath, scope } = flags;
259
+ 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 = {}) => {
260
+ const { silent, config: configPath } = flags;
261
+ const scope = flags.scope?.replace(/s$/, "");
262
+ if (scope != null && ![
263
+ "token",
264
+ "recipe",
265
+ "pattern",
266
+ "keyframe"
267
+ ].includes(scope)) throw new _bamboocss_shared.BambooError("INVALID_FLAG", `--scope is one of token, recipe, pattern or keyframe, not "${flags.scope}".`);
268
+ if (!flags.unused && (scope === "pattern" || scope === "keyframe")) throw new _bamboocss_shared.BambooError("INVALID_FLAG", `--scope ${scope} lists what is unused, with --unused.`);
214
269
  const tokenScope = scope == null || scope === "token";
215
270
  const recipeScope = scope == null || scope === "recipe";
216
- const cwd = (0, path.resolve)(flags.cwd);
271
+ const cwd = (0, node_path.resolve)(flags.cwd);
217
272
  if (silent) _bamboocss_logger.logger.level = "silent";
273
+ const outfile = typeof flags.outfile === "string" ? (0, node_path.resolve)(flags.outfile) : void 0;
274
+ if (flags.unused && !outfile) keepStdoutToOutput();
218
275
  const ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
219
276
  cwd,
220
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
277
+ config: silenced((0, _bamboocss_shared.compact)({ include: maybeGlob ? [maybeGlob] : void 0 }), silent),
221
278
  configPath
222
279
  });
223
280
  const result = await (0, _bamboocss_node.analyze)(ctx);
281
+ if (flags.unused) {
282
+ const keys = {
283
+ token: "tokens",
284
+ recipe: "recipes",
285
+ pattern: "patterns",
286
+ keyframe: "keyframes"
287
+ };
288
+ const scoped = scope ? keys[scope] : void 0;
289
+ const unused = result.getUnused(scoped ? [scoped] : void 0);
290
+ if (outfile) {
291
+ await result.writeUnused(outfile, scoped ? { [scoped]: unused[scoped] } : unused);
292
+ _bamboocss_logger.logger.info("cli", `JSON report saved to ${outfile}`);
293
+ return;
294
+ }
295
+ const lines = Object.entries(keys).flatMap(([kind, key]) => scoped == null ? unused[key].map((name) => `${kind} ${name}`) : key === scoped ? unused[key] : []);
296
+ if (lines.length) process.stdout.write(lines.join("\n") + "\n");
297
+ return;
298
+ }
224
299
  if (flags?.outfile && typeof flags.outfile === "string") {
225
300
  await result.writeReport(flags.outfile);
226
- _bamboocss_logger.logger.info("cli", `JSON report saved to ${(0, path.resolve)(flags.outfile)}`);
301
+ _bamboocss_logger.logger.info("cli", `JSON report saved to ${(0, node_path.resolve)(flags.outfile)}`);
227
302
  return;
228
303
  }
229
304
  if (tokenScope) if (!ctx.tokens.isEmpty) {
@@ -235,9 +310,20 @@ async function main() {
235
310
  _bamboocss_logger.logger.info("analyze:recipes", `Config recipes usage report 🎛️ \n${recipeAnalysis.formatted}`);
236
311
  } else _bamboocss_logger.logger.info("analyze:recipes", "No config recipes found");
237
312
  });
238
- 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 = {}) => {
313
+ 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 = {}) => {
314
+ const cwd = (0, node_path.resolve)(flags.cwd);
315
+ if (flags.json) keepStdoutToOutput();
316
+ const report = await (0, _bamboocss_node.doctor)(await (0, _bamboocss_node.loadConfigAndCreateContext)({
317
+ cwd,
318
+ configPath: flags.config
319
+ }));
320
+ process.stdout.write((flags.json ? JSON.stringify(report, null, 2) : (0, _bamboocss_node.formatDoctorReport)(report)) + "\n");
321
+ if (report.problems.length) process.exitCode = 1;
322
+ });
323
+ 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 = {}) => {
239
324
  const { silent, dry = false, outdir: outdirFlag, config: configPath } = flags ?? {};
240
- const cwd = (0, path.resolve)(flags.cwd);
325
+ if (dry && flags.zip) throw new _bamboocss_shared.BambooError("INVALID_FLAG", "--zip writes an archive, and --dry writes nothing.");
326
+ const cwd = (0, node_path.resolve)(flags.cwd);
241
327
  const stream = (0, _bamboocss_node.setLogStream)({
242
328
  cwd,
243
329
  logfile: flags.logfile
@@ -247,28 +333,31 @@ async function main() {
247
333
  if (silent) _bamboocss_logger.logger.level = "silent";
248
334
  const ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
249
335
  cwd,
250
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
336
+ config: silenced(maybeGlob ? { include: [maybeGlob] } : void 0, silent),
251
337
  configPath
252
338
  });
253
339
  await (0, _bamboocss_node.debug)(ctx, {
254
- outdir: outdirFlag ?? (0, path.join)(...ctx.paths.root, "debug"),
340
+ outdir: typeof outdirFlag === "string" ? outdirFlag : (0, node_path.join)(...ctx.paths.root, "debug"),
255
341
  dry,
256
- onlyConfig: flags.onlyConfig
342
+ onlyConfig: flags.onlyConfig,
343
+ zip: flags.zip
257
344
  });
258
345
  stopProfiling();
259
346
  stream.end();
260
347
  });
261
348
  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 = {}) => {
262
349
  const { silent, outfile: outfileFlag, minify, config: configPath, watch, poll } = flags;
263
- const cwd = (0, path.resolve)(flags.cwd);
350
+ const cwd = (0, node_path.resolve)(flags.cwd);
264
351
  if (silent) _bamboocss_logger.logger.level = "silent";
265
352
  let ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
266
353
  cwd,
267
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
354
+ config: silenced((0, _bamboocss_shared.compact)({
355
+ include: maybeGlob ? [maybeGlob] : void 0,
356
+ minify
357
+ }), silent),
268
358
  configPath
269
359
  });
270
- const outfile = outfileFlag ?? (0, path.join)(...ctx.paths.root, "bamboo.buildinfo.json");
271
- if (minify) ctx.config.minify = true;
360
+ const outfile = outfileFlag ?? (0, node_path.join)(...ctx.paths.root, "bamboo.buildinfo.json");
272
361
  await (0, _bamboocss_node.buildInfo)(ctx, outfile);
273
362
  if (watch) {
274
363
  ctx.watchConfig(async () => {
@@ -300,12 +389,12 @@ async function main() {
300
389
  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) => {
301
390
  const { outdir, silent, base } = flags;
302
391
  if (silent) _bamboocss_logger.logger.level = "silent";
303
- const cwd = (0, path.resolve)(flags.cwd);
392
+ const cwd = (0, node_path.resolve)(flags.cwd);
304
393
  const ctx = await (0, _bamboocss_node.loadConfigAndCreateContext)({
305
394
  cwd,
306
- config: { cwd }
395
+ config: silenced({ cwd }, silent)
307
396
  });
308
- const pkgPath = (0, path.resolve)(cwd, outdir, "package.json");
397
+ const pkgPath = (0, node_path.resolve)(cwd, outdir, "package.json");
309
398
  const exists = ctx.runtime.fs.existsSync(pkgPath);
310
399
  /**
311
400
  * The same map codegen writes into the outdir, re-derived here with the package's
@@ -374,8 +463,8 @@ async function main() {
374
463
  process.exitCode = 1;
375
464
  });
376
465
  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) => {
377
- const { initMcpConfig } = await Promise.resolve().then(() => require("./mcp-init-DzE4FgdX.cjs"));
378
- const resolvedCwd = (0, path.resolve)(mcpInitFlags.cwd ?? cwd);
466
+ const { initMcpConfig } = await Promise.resolve().then(() => require("./mcp-init-C5_g6W-U.cjs"));
467
+ const resolvedCwd = (0, node_path.resolve)(mcpInitFlags.cwd ?? cwd);
379
468
  let clients;
380
469
  if (mcpInitFlags.client) clients = (Array.isArray(mcpInitFlags.client) ? mcpInitFlags.client : [mcpInitFlags.client]).flatMap((c) => c.split(",")).map((c) => c.trim());
381
470
  await initMcpConfig({
package/dist/cli-main.mjs CHANGED
@@ -1,9 +1,11 @@
1
- import { t as version } from "./package-DtugIbci.mjs";
1
+ import { t as version } from "./package-Cqdhaelc.mjs";
2
2
  import { logger } from "@bamboocss/logger";
3
- import { BambooContext, analyze, buildInfo, codegen, cssgen, debug, generate, generatePackageExports, loadConfigAndCreateContext, setLogStream, setupConfig, setupGitIgnore, spec, startProfiling } from "@bamboocss/node";
4
- import { BambooError, compact } from "@bamboocss/shared";
3
+ import { BambooContext, analyze, artifactsToRebuild, buildInfo, codegen, cssgen, debug, doctor, formatDoctorReport, generate, generatePackageExports, loadConfigAndCreateContext, setLogStream, setupConfig, setupGitIgnore, spec, startProfiling } from "@bamboocss/node";
4
+ import { BambooError, closestMatch, compact } from "@bamboocss/shared";
5
5
  import { cac } from "cac";
6
- import { join, resolve } from "path";
6
+ import { existsSync } from "node:fs";
7
+ import { Console } from "node:console";
8
+ import { join, resolve } from "node:path";
7
9
  //#region src/cli-main.ts
8
10
  /**
9
11
  * The negative spellings, answered here rather than left to cac, which only recognises
@@ -37,13 +39,57 @@ const normalizeStrictTokens = (value) => {
37
39
  if (named === "true" || named === "yes" || named === "on") return true;
38
40
  throw new BambooError("CONFIG_ERROR", `\`--strict-values ${named}\` is not a setting. Pass it bare to require every value to be a token.`);
39
41
  };
42
+ /**
43
+ * Refuse a word one slip from a command, and naming nothing on disk — `bamboo codgen`.
44
+ *
45
+ * The default command reads its arguments as `include` globs, so a mistyped command matched no
46
+ * files, built a stylesheet from nothing over the real one, and exited 0. `generate` refuses any
47
+ * glob matching nothing; this answers the one case it can say more about, the command meant.
48
+ * Watching or not, as the typo is a typo either way. A word near no command — `bamboo deploy` —
49
+ * is left to `generate`, which watching lets wait for the files to appear.
50
+ */
51
+ const assertKnownCommand = (files, cwd, commands) => {
52
+ for (const file of files) {
53
+ if (!/^[a-z][\w-]*$/i.test(file) || existsSync(resolve(cwd, file))) continue;
54
+ const suggestion = closestMatch(file.toLowerCase(), commands);
55
+ if (!suggestion) continue;
56
+ 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." });
57
+ }
58
+ };
59
+ function silenced(config, silent) {
60
+ return silent ? {
61
+ ...config,
62
+ logLevel: "silent"
63
+ } : config;
64
+ }
65
+ /**
66
+ * Keep stdout to a command's output, as `bamboo mcp` keeps it to its protocol: the log, which the
67
+ * logger writes through `console`, goes to stderr, and a reader that has gone — `bamboo analyze
68
+ * --unused | head -1` — ends the command, rather than failing it with `EPIPE`.
69
+ */
70
+ const keepStdoutToOutput = () => {
71
+ const toStderr = new Console({
72
+ stdout: process.stderr,
73
+ stderr: process.stderr
74
+ });
75
+ for (const method of [
76
+ "log",
77
+ "info",
78
+ "debug",
79
+ "dir"
80
+ ]) console[method] = toStderr[method].bind(toStderr);
81
+ process.stdout.on("error", (error) => {
82
+ if (error.code === "EPIPE" || error.code === "ERR_STREAM_DESTROYED") process.exit(0);
83
+ throw error;
84
+ });
85
+ };
40
86
  async function main() {
41
87
  const cli = cac("bamboo");
42
88
  const cwd = process.cwd();
43
89
  cli.command("init", "Initialize the bamboo config file").option("-i, --interactive", "Run in interactive mode", { default: false }).option("-f, --force", "Force overwrite existing config file").option("-c, --config <path>", "Path to bamboo config file").option("--cwd <cwd>", "Current working directory", { default: cwd }).option("--silent", "Suppress all messages except errors").option("--no-gitignore", "Don't update the .gitignore").option("--no-codegen", "Don't run the codegen logic").option("--out-extension <ext>", "The extension of the generated js files (default: 'mjs')").option("--outdir <dir>", "The output directory for the generated files").option("--strict-values [mode]", "Require every style value to be a token, so a raw css value is written `[14px]`").option("--logfile <file>", "Outputs logs to a file").action(async (initFlags = {}) => {
44
90
  let options = {};
45
91
  if (initFlags.interactive) {
46
- const { interactive } = await import("./interactive-C2dqO9fu.mjs");
92
+ const { interactive } = await import("./interactive-BsLF_8Nh.mjs");
47
93
  options = await interactive({ cwd: resolve(initFlags.cwd ?? "") });
48
94
  }
49
95
  const flags = {
@@ -68,10 +114,10 @@ async function main() {
68
114
  const ctx = await loadConfigAndCreateContext({
69
115
  cwd,
70
116
  configPath,
71
- config: compact({
117
+ config: silenced(compact({
72
118
  gitignore,
73
119
  outdir: flags.outdir
74
- })
120
+ }), silent)
75
121
  });
76
122
  if (gitignore) setupGitIgnore(ctx);
77
123
  if (flags.codegen) {
@@ -93,7 +139,7 @@ async function main() {
93
139
  if (silent) logger.level = "silent";
94
140
  let ctx = await loadConfigAndCreateContext({
95
141
  cwd,
96
- config: { clean },
142
+ config: silenced(compact({ clean }), silent),
97
143
  configPath
98
144
  });
99
145
  const { msg } = await codegen(ctx);
@@ -106,7 +152,7 @@ async function main() {
106
152
  config: ctx.config,
107
153
  changes: affecteds
108
154
  });
109
- await codegen(ctx, Array.from(affecteds.artifacts));
155
+ await codegen(ctx, artifactsToRebuild(affecteds));
110
156
  logger.info("ctx:updated", "config rebuilt ✅");
111
157
  }, {
112
158
  cwd,
@@ -135,10 +181,10 @@ async function main() {
135
181
  if (silent) logger.level = "silent";
136
182
  let ctx = await loadConfigAndCreateContext({
137
183
  cwd,
138
- config: {
184
+ config: silenced({
139
185
  ...rest,
140
186
  ...glob ? { include: [glob] } : void 0
141
- },
187
+ }, silent),
142
188
  configPath
143
189
  });
144
190
  const options = {
@@ -179,9 +225,10 @@ async function main() {
179
225
  stopProfiling();
180
226
  }
181
227
  });
182
- 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) => {
228
+ 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) => {
183
229
  const { config: configPath, silent, ...rest } = flags;
184
230
  const cwd = resolve(flags.cwd ?? "");
231
+ assertKnownCommand(files, cwd, cli.commands.map((command) => command.name).filter(Boolean));
185
232
  const stream = setLogStream({
186
233
  cwd,
187
234
  logfile: flags.logfile
@@ -189,11 +236,11 @@ async function main() {
189
236
  let stopProfiling = () => void 0;
190
237
  if (flags.cpuProf) stopProfiling = await startProfiling(cwd, "cli", flags.watch);
191
238
  if (silent) logger.level = "silent";
192
- await generate(compact({
193
- include: files,
239
+ await generate(silenced(compact({
240
+ include: files.length ? files : void 0,
194
241
  ...rest,
195
242
  cwd
196
- }), configPath);
243
+ }), silent), configPath, { requireFiles: files.length > 0 });
197
244
  stopProfiling();
198
245
  if (!flags.watch) stream.end();
199
246
  });
@@ -204,21 +251,49 @@ async function main() {
204
251
  await spec(await loadConfigAndCreateContext({
205
252
  cwd,
206
253
  configPath,
207
- config: { cwd }
254
+ config: silenced({ cwd }, silent)
208
255
  }), { outdir });
209
256
  });
210
- 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 = {}) => {
211
- const { silent, config: configPath, scope } = flags;
257
+ 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 = {}) => {
258
+ const { silent, config: configPath } = flags;
259
+ const scope = flags.scope?.replace(/s$/, "");
260
+ if (scope != null && ![
261
+ "token",
262
+ "recipe",
263
+ "pattern",
264
+ "keyframe"
265
+ ].includes(scope)) throw new BambooError("INVALID_FLAG", `--scope is one of token, recipe, pattern or keyframe, not "${flags.scope}".`);
266
+ if (!flags.unused && (scope === "pattern" || scope === "keyframe")) throw new BambooError("INVALID_FLAG", `--scope ${scope} lists what is unused, with --unused.`);
212
267
  const tokenScope = scope == null || scope === "token";
213
268
  const recipeScope = scope == null || scope === "recipe";
214
269
  const cwd = resolve(flags.cwd);
215
270
  if (silent) logger.level = "silent";
271
+ const outfile = typeof flags.outfile === "string" ? resolve(flags.outfile) : void 0;
272
+ if (flags.unused && !outfile) keepStdoutToOutput();
216
273
  const ctx = await loadConfigAndCreateContext({
217
274
  cwd,
218
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
275
+ config: silenced(compact({ include: maybeGlob ? [maybeGlob] : void 0 }), silent),
219
276
  configPath
220
277
  });
221
278
  const result = await analyze(ctx);
279
+ if (flags.unused) {
280
+ const keys = {
281
+ token: "tokens",
282
+ recipe: "recipes",
283
+ pattern: "patterns",
284
+ keyframe: "keyframes"
285
+ };
286
+ const scoped = scope ? keys[scope] : void 0;
287
+ const unused = result.getUnused(scoped ? [scoped] : void 0);
288
+ if (outfile) {
289
+ await result.writeUnused(outfile, scoped ? { [scoped]: unused[scoped] } : unused);
290
+ logger.info("cli", `JSON report saved to ${outfile}`);
291
+ return;
292
+ }
293
+ const lines = Object.entries(keys).flatMap(([kind, key]) => scoped == null ? unused[key].map((name) => `${kind} ${name}`) : key === scoped ? unused[key] : []);
294
+ if (lines.length) process.stdout.write(lines.join("\n") + "\n");
295
+ return;
296
+ }
222
297
  if (flags?.outfile && typeof flags.outfile === "string") {
223
298
  await result.writeReport(flags.outfile);
224
299
  logger.info("cli", `JSON report saved to ${resolve(flags.outfile)}`);
@@ -233,8 +308,19 @@ async function main() {
233
308
  logger.info("analyze:recipes", `Config recipes usage report 🎛️ \n${recipeAnalysis.formatted}`);
234
309
  } else logger.info("analyze:recipes", "No config recipes found");
235
310
  });
236
- 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 = {}) => {
311
+ 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 = {}) => {
312
+ const cwd = resolve(flags.cwd);
313
+ if (flags.json) keepStdoutToOutput();
314
+ const report = await doctor(await loadConfigAndCreateContext({
315
+ cwd,
316
+ configPath: flags.config
317
+ }));
318
+ process.stdout.write((flags.json ? JSON.stringify(report, null, 2) : formatDoctorReport(report)) + "\n");
319
+ if (report.problems.length) process.exitCode = 1;
320
+ });
321
+ 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 = {}) => {
237
322
  const { silent, dry = false, outdir: outdirFlag, config: configPath } = flags ?? {};
323
+ if (dry && flags.zip) throw new BambooError("INVALID_FLAG", "--zip writes an archive, and --dry writes nothing.");
238
324
  const cwd = resolve(flags.cwd);
239
325
  const stream = setLogStream({
240
326
  cwd,
@@ -245,13 +331,14 @@ async function main() {
245
331
  if (silent) logger.level = "silent";
246
332
  const ctx = await loadConfigAndCreateContext({
247
333
  cwd,
248
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
334
+ config: silenced(maybeGlob ? { include: [maybeGlob] } : void 0, silent),
249
335
  configPath
250
336
  });
251
337
  await debug(ctx, {
252
- outdir: outdirFlag ?? join(...ctx.paths.root, "debug"),
338
+ outdir: typeof outdirFlag === "string" ? outdirFlag : join(...ctx.paths.root, "debug"),
253
339
  dry,
254
- onlyConfig: flags.onlyConfig
340
+ onlyConfig: flags.onlyConfig,
341
+ zip: flags.zip
255
342
  });
256
343
  stopProfiling();
257
344
  stream.end();
@@ -262,11 +349,13 @@ async function main() {
262
349
  if (silent) logger.level = "silent";
263
350
  let ctx = await loadConfigAndCreateContext({
264
351
  cwd,
265
- config: maybeGlob ? { include: [maybeGlob] } : void 0,
352
+ config: silenced(compact({
353
+ include: maybeGlob ? [maybeGlob] : void 0,
354
+ minify
355
+ }), silent),
266
356
  configPath
267
357
  });
268
358
  const outfile = outfileFlag ?? join(...ctx.paths.root, "bamboo.buildinfo.json");
269
- if (minify) ctx.config.minify = true;
270
359
  await buildInfo(ctx, outfile);
271
360
  if (watch) {
272
361
  ctx.watchConfig(async () => {
@@ -301,7 +390,7 @@ async function main() {
301
390
  const cwd = resolve(flags.cwd);
302
391
  const ctx = await loadConfigAndCreateContext({
303
392
  cwd,
304
- config: { cwd }
393
+ config: silenced({ cwd }, silent)
305
394
  });
306
395
  const pkgPath = resolve(cwd, outdir, "package.json");
307
396
  const exists = ctx.runtime.fs.existsSync(pkgPath);
@@ -372,7 +461,7 @@ async function main() {
372
461
  process.exitCode = 1;
373
462
  });
374
463
  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) => {
375
- const { initMcpConfig } = await import("./mcp-init-NdVHT1_H.mjs");
464
+ const { initMcpConfig } = await import("./mcp-init-CCfzkOPO.mjs");
376
465
  const resolvedCwd = resolve(mcpInitFlags.cwd ?? cwd);
377
466
  let clients;
378
467
  if (mcpInitFlags.client) clients = (Array.isArray(mcpInitFlags.client) ? mcpInitFlags.client : [mcpInitFlags.client]).flatMap((c) => c.split(",")).map((c) => c.trim());
package/dist/errors.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- let worker_threads = require("worker_threads");
2
+ let node_worker_threads = require("node:worker_threads");
3
3
  let _bamboocss_shared = require("@bamboocss/shared");
4
4
  //#region ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/index.mjs
5
5
  let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY = true;
@@ -111,7 +111,7 @@ function handleError(error) {
111
111
  console.error($.red(message));
112
112
  }
113
113
  process.exitCode = 1;
114
- if (!worker_threads.isMainThread && worker_threads.parentPort) worker_threads.parentPort.postMessage("error");
114
+ if (!node_worker_threads.isMainThread && node_worker_threads.parentPort) node_worker_threads.parentPort.postMessage("error");
115
115
  }
116
116
  function isLocError(error) {
117
117
  return typeof error === "object" && error !== null && "loc" in error && typeof error.loc === "object" && "message" in error;
package/dist/errors.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isMainThread, parentPort } from "worker_threads";
1
+ import { isMainThread, parentPort } from "node:worker_threads";
2
2
  import { BambooError } from "@bamboocss/shared";
3
3
  //#region ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/index.mjs
4
4
  let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY = true;
@@ -1,4 +1,4 @@
1
- import { t as version } from "./package-DtugIbci.mjs";
1
+ import { t as version } from "./package-Cqdhaelc.mjs";
2
2
  import * as p from "@clack/prompts";
3
3
  //#region src/interactive.ts
4
4
  const interactive = async (_options = {}) => {