@bamboocss/node 1.30.1 → 1.32.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/index.cjs CHANGED
@@ -28,11 +28,8 @@ let _bamboocss_config = require("@bamboocss/config");
28
28
  let _bamboocss_shared = require("@bamboocss/shared");
29
29
  let fs = require("fs");
30
30
  let path = require("path");
31
- let _bamboocss_plugin_lightningcss = require("@bamboocss/plugin-lightningcss");
32
31
  let _bamboocss_plugin_svelte = require("@bamboocss/plugin-svelte");
33
32
  let _bamboocss_plugin_vue = require("@bamboocss/plugin-vue");
34
- let browserslist = require("browserslist");
35
- browserslist = __toESM(browserslist);
36
33
  let _bamboocss_core = require("@bamboocss/core");
37
34
  let _bamboocss_generator = require("@bamboocss/generator");
38
35
  let _bamboocss_parser = require("@bamboocss/parser");
@@ -59,6 +56,7 @@ let is_glob = require("is-glob");
59
56
  is_glob = __toESM(is_glob);
60
57
  let glob_parent = require("glob-parent");
61
58
  glob_parent = __toESM(glob_parent);
59
+ let matcher = require("matcher");
62
60
  let _bamboocss_config_ts_path = require("@bamboocss/config/ts-path");
63
61
  let ts_morph = require("ts-morph");
64
62
  let node_readline = require("node:readline");
@@ -1613,6 +1611,8 @@ var OutputEngine = class {
1613
1611
  };
1614
1612
  //#endregion
1615
1613
  //#region src/create-context.ts
1614
+ /** A thrown value's message, for a `catch` binding that is typed `unknown`. */
1615
+ const messageOf = (error) => error instanceof Error ? error.message : String(error);
1616
1616
  /**
1617
1617
  * What each loss is, and what the author can do about it.
1618
1618
  *
@@ -1633,6 +1633,26 @@ var BambooContext = class extends _bamboocss_generator.Generator {
1633
1633
  output;
1634
1634
  diff;
1635
1635
  explicitDeps = [];
1636
+ /**
1637
+ * Files whose extraction threw, keyed by path, holding what it threw.
1638
+ *
1639
+ * A parse failure is not an opinion about a build that still works. The file's styles never
1640
+ * reach the encoder, so every rule it would have contributed is absent from the stylesheet
1641
+ * and the classes its components ask for have nothing behind them — the same shape as a
1642
+ * naming disagreement, and the reverse of `reportUnresolvedStyles`, where what the build
1643
+ * *did* see still applies. Logging it and carrying on is how a build printed error-level
1644
+ * lines, dropped rules, and exited 0.
1645
+ *
1646
+ * Retained rather than rethrown from the `catch`, so one pass names every broken file
1647
+ * instead of the first. Keyed by file, so a failure survives the incremental passes that
1648
+ * skip an unchanged file: nothing re-parses it, and its styles stay missing until it does.
1649
+ *
1650
+ * The error rather than its message, so `assertExtracted` can hand the originals on as a
1651
+ * `cause`. The aggregate carries a code of its own — `ERR_BAMBOO_EXTRACT_FAILED` — and the
1652
+ * codes underneath it are what a caller has to read to tell a retired token spelling from a
1653
+ * syntax error.
1654
+ */
1655
+ parseFailures = /* @__PURE__ */ new Map();
1636
1656
  constructor(conf) {
1637
1657
  super(conf);
1638
1658
  const config = conf.config;
@@ -1702,6 +1722,35 @@ var BambooContext = class extends _bamboocss_generator.Generator {
1702
1722
  cwd
1703
1723
  });
1704
1724
  };
1725
+ /**
1726
+ * Fail the build if any file's extraction threw.
1727
+ *
1728
+ * Called at the end of an extraction pass rather than from the `catch`, so the message names
1729
+ * every broken file at once — a config with one retired token spelling in six components is
1730
+ * fixed once, not six builds in a row.
1731
+ *
1732
+ * This is what makes the integrations agree. `cssgen` already exited non-zero on a file it
1733
+ * could not extract, by letting the throw through; every bundler goes through `parseFile`,
1734
+ * which caught it. CI running a build passed what CI running `cssgen` rejected, over the same
1735
+ * source.
1736
+ *
1737
+ * `files` is the set still in scope, which the caller has usually just globbed. Deleting the
1738
+ * offending file, or taking it out of `include`, is a *fix* — and nothing re-parses a file
1739
+ * that is gone, so the entry that outlived it would fail every later build, naming a path
1740
+ * that no longer exists. A context outlives rebuilds (it is replaced only when the config
1741
+ * changes) and both long-lived integrations hold one, so that wedged a dev server until the
1742
+ * process was restarted.
1743
+ */
1744
+ assertExtracted = (files) => {
1745
+ if (!this.parseFailures.size) return;
1746
+ const inScope = new Set(Array.from(files ?? this.getFiles(), (file) => this.runtime.path.abs(this.config.cwd, file)));
1747
+ for (const file of this.parseFailures.keys()) if (!inScope.has(file)) this.parseFailures.delete(file);
1748
+ if (!this.parseFailures.size) return;
1749
+ const detail = Array.from(this.parseFailures.entries()).map(([file, error]) => `${this.relative(file)}\n${messageOf(error).replace(/^(?=.)/gm, " ")}`).join("\n\n");
1750
+ throw new _bamboocss_shared.BambooError("EXTRACT_FAILED", `${this.parseFailures.size} file(s) could not be extracted:\n\n${detail}\n\nNothing emits a rule for a file the build could not read, so every style in these is absent from the stylesheet and the classes their components ask for have nothing behind them.`, { cause: new AggregateError(Array.from(this.parseFailures.values()), `${this.parseFailures.size} file(s) could not be extracted`) });
1751
+ };
1752
+ /** A path as the user typed it, when it is under `cwd`. */
1753
+ relative = (file) => file.startsWith(this.config.cwd) ? file.slice(this.config.cwd.length + 1) : file;
1705
1754
  parseFile = (filePath, styleEncoder) => {
1706
1755
  const file = this.runtime.path.abs(this.config.cwd, filePath);
1707
1756
  _bamboocss_logger.logger.debug("file:extract", file);
@@ -1710,27 +1759,34 @@ var BambooContext = class extends _bamboocss_generator.Generator {
1710
1759
  try {
1711
1760
  const encoder = styleEncoder || this.parserOptions.encoder;
1712
1761
  result = this.project.parseSourceFile(file, encoder);
1762
+ this.parseFailures.delete(file);
1713
1763
  } catch (error) {
1714
1764
  _bamboocss_logger.logger.caughtError("file:extract", `Failed to parse ${file}`, error);
1765
+ this.parseFailures.set(file, error);
1715
1766
  }
1716
1767
  if (result) this.reportUnresolvedStyles(result);
1717
1768
  measure();
1718
1769
  return result;
1719
1770
  };
1771
+ /**
1772
+ * Extract every file in one pass, and fail on the ones that could not be read.
1773
+ *
1774
+ * Routed through `parseFile` rather than parsing directly, so the two entry points cannot
1775
+ * disagree about what a failure means. This one used to let the first throw out, which is
1776
+ * why `cssgen` and a bundler build reported different things about the same source.
1777
+ */
1720
1778
  parseFiles = (styleEncoder) => {
1721
1779
  const encoder = styleEncoder || this.parserOptions.encoder;
1722
1780
  const files = this.getFiles();
1723
1781
  const filesWithCss = [];
1724
1782
  const results = [];
1725
1783
  files.forEach((file) => {
1726
- const measure = _bamboocss_logger.logger.time.debug(`Parsed ${file}`);
1727
- const result = this.project.parseSourceFile(file, encoder);
1728
- measure();
1729
- if (result) this.reportUnresolvedStyles(result);
1784
+ const result = this.parseFile(file, encoder);
1730
1785
  if (!result || result.isEmpty() || encoder.isEmpty()) return;
1731
1786
  filesWithCss.push(file);
1732
1787
  results.push(result);
1733
1788
  });
1789
+ this.assertExtracted(files);
1734
1790
  return {
1735
1791
  filesWithCss,
1736
1792
  files,
@@ -2083,12 +2139,17 @@ async function loadTsConfig(conf, cwd) {
2083
2139
  const RESOLVED_HOOKS_NAME = "__resolved__";
2084
2140
  /**
2085
2141
  * Built-in plugins that are auto-injected when using the CLI or PostCSS plugin.
2086
- * These provide Vue/Svelte file support and LightningCSS optimization.
2142
+ * These provide Vue/Svelte single-file-component support.
2143
+ *
2144
+ * LightningCSS is not among them any more. It was reached through a `lightningcss: true`
2145
+ * config flag whose only job was to push `pluginLightningcss()` into this list — a second
2146
+ * way to say something `plugins` already said, and the expensive one: naming the plugin
2147
+ * here meant a static import, which made `@bamboocss/plugin-lightningcss` a hard dependency
2148
+ * of this package, which put a native binary in every install whether or not the flag was
2149
+ * ever set. List the plugin yourself to use it.
2087
2150
  */
2088
- function getAutoPlugins(config) {
2089
- const plugins = [(0, _bamboocss_plugin_vue.pluginVue)(), (0, _bamboocss_plugin_svelte.pluginSvelte)()];
2090
- if (config.lightningcss) plugins.push((0, _bamboocss_plugin_lightningcss.pluginLightningcss)());
2091
- return plugins;
2151
+ function getAutoPlugins() {
2152
+ return [(0, _bamboocss_plugin_vue.pluginVue)(), (0, _bamboocss_plugin_svelte.pluginSvelte)()];
2092
2153
  }
2093
2154
  /**
2094
2155
  * Load config and create context with auto-injected plugins.
@@ -2103,8 +2164,7 @@ async function loadConfigAndCreateContext(options = {}) {
2103
2164
  });
2104
2165
  if (config) Object.assign(conf.config, config);
2105
2166
  if (options.cwd) conf.config.cwd = options.cwd;
2106
- if (conf.config.lightningcss && !conf.config.browserslist) conf.config.browserslist ||= browserslist.default.findConfig(cwd)?.defaults;
2107
- const autoPlugins = getAutoPlugins(conf.config);
2167
+ const autoPlugins = getAutoPlugins();
2108
2168
  conf.hooks = (0, _bamboocss_config.mergeHooks)([...autoPlugins, {
2109
2169
  name: RESOLVED_HOOKS_NAME,
2110
2170
  hooks: conf.hooks
@@ -2206,9 +2266,9 @@ function* snapshotTexts(snapshot) {
2206
2266
  //#endregion
2207
2267
  //#region src/token-accounting.ts
2208
2268
  /**
2209
- * The one decline `strict` fails the build on.
2269
+ * The one decline `prune.tokens: 'accounted'` fails the build on.
2210
2270
  *
2211
- * `strict` asserts that every token path resolves, and this is the reason that says otherwise:
2271
+ * `prune.tokens: 'accounted'` asserts that every token path resolves, and this is the reason that says otherwise:
2212
2272
  * a token binding used in a way the build cannot follow — a path built at runtime, a binding
2213
2273
  * assigned away, a namespace enumerated. It is about the author's *token usage*, and it has a
2214
2274
  * fix at the call site.
@@ -2469,14 +2529,38 @@ function unwrapAssertions(node) {
2469
2529
  * follow, and it covers the callers below that supply no `results` at all.
2470
2530
  */
2471
2531
  const TOKEN_CALL = /\btoken(?:\s*\.\s*value)?\s*\(\s*['"`]([^'"`]+)['"`]/g;
2532
+ /** An import of the generated tokens artifact, under any of the spellings that reach it. */
2533
+ const TOKEN_IMPORT = /\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2534
+ /** A call to `token()` or `token.value()`, whatever the argument is — or is not. */
2535
+ const TOKEN_CALLEE = /\btoken(\s*\.\s*value)?\s*\(/;
2536
+ /** The same, but only where the argument is a string literal — the shape `TOKEN_CALL` resolves. */
2537
+ const TOKEN_CALL_LITERAL = /\btoken(?:\s*\.\s*value)?\s*\(\s*['"`]/;
2538
+ /** String literals, contents and all. */
2539
+ const STRING_LITERAL = /'(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|`(?:[^`\\]|\\.)*`/g;
2472
2540
  /**
2473
- * A token reached from javascript at all — a call of any shape, or an import of the artifact.
2541
+ * Whether a token is reached from javascript at all — a call of any shape, or an import of the
2542
+ * artifact. Being true keeps every token declaration, so the whole of `prune.tokens` rests
2543
+ * on it.
2544
+ *
2545
+ * The awkward part is that a token reference inside a css value is now spelled `token(…)` too,
2546
+ * and it must *not* count: `css({ border: '1px solid token(colors.red.300)' })` reaches a token
2547
+ * from a stylesheet, where the css scan already accounts for it, not from javascript. Reading it
2548
+ * as a call turned pruning off wholesale — measured at 3.2x the stylesheet on a sandbox, since
2549
+ * "keep everything" is what the gate means. It was only ever latent before, because `{…}` was
2550
+ * the spelling the docs used and it looked nothing like a call.
2474
2551
  *
2475
- * Has to stay a strict superset of `TOKEN_CALL`: it must match wherever that one matches, and
2476
- * also wherever that one gives up. See `collectTokenReferences` for why the redundancy holds.
2477
- * No `g` flag, so `test` carries no state between files.
2552
+ * So a `token(` that survives blanking every string literal is a real call, and one that does
2553
+ * not was written inside a string. The literal-argument test comes first and on the raw text,
2554
+ * which is what keeps this a superset of `TOKEN_CALL` as the coupling in `collectTokenReferences`
2555
+ * requires: a resolvable call embedded in a template literal — a fixture holding source code —
2556
+ * still counts, even though blanking would hide it.
2557
+ *
2558
+ * No `g` flag on the tests, so `test` carries no state between files.
2478
2559
  */
2479
- const REACHABLE_FROM_JS = /\btoken(\s*\.\s*value)?\s*\(|\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2560
+ const reachableFromJs = (text) => {
2561
+ if (TOKEN_IMPORT.test(text) || TOKEN_CALL_LITERAL.test(text)) return true;
2562
+ return TOKEN_CALLEE.test(text) && TOKEN_CALLEE.test(text.replace(STRING_LITERAL, "''"));
2563
+ };
2480
2564
  /**
2481
2565
  * The text of every file `include` covers — as written on disk, and, when they differ, as the
2482
2566
  * parser understands it.
@@ -2503,7 +2587,7 @@ function* sourceTexts(ctx) {
2503
2587
  * The token prune, as all three build paths need to run it.
2504
2588
  *
2505
2589
  * One function because it was three copies of one conditional, and the `false` branch went
2506
- * missing from a copy: a watch rebuild with `pruneUnusedTokens: false` skipped `pruneTokens`
2590
+ * missing from a copy: a watch rebuild with `prune: { tokens: 'off' }` skipped `pruneTokens`
2507
2591
  * altogether, so it kept `@property` registrations that a full build of the same source
2508
2592
  * strips. The other two copies carried a comment pointing at that file for the reasoning,
2509
2593
  * which is how a missing branch reads as intentional.
@@ -2514,11 +2598,13 @@ function* sourceTexts(ctx) {
2514
2598
  * a preset's whole filter and gradient set for nothing.
2515
2599
  */
2516
2600
  function pruneTokensForBuild(ctx, sheet, results) {
2517
- if (!ctx.config.pruneUnusedTokens) {
2601
+ const strategy = ctx.config.prune?.tokens ?? "reachable";
2602
+ if (strategy === "off") {
2518
2603
  ctx.pruneTokens(sheet);
2519
2604
  return;
2520
2605
  }
2521
- const strict = ctx.config.pruneUnusedTokens === "strict";
2606
+ const accounts = strategy === "accounted";
2607
+ const unresolved = accounts ? ctx.config.prune?.unresolvedPath ?? "warn" : "off";
2522
2608
  const paths = /* @__PURE__ */ new Set();
2523
2609
  const vars = /* @__PURE__ */ new Set();
2524
2610
  const accounting = {
@@ -2532,17 +2618,20 @@ function pruneTokensForBuild(ctx, sheet, results) {
2532
2618
  for (const text of snapshotTexts(snapshot)) {
2533
2619
  for (const match of text.matchAll(TOKEN_CALL)) paths.add(match[1]);
2534
2620
  for (const name of (0, _bamboocss_shared.cssVarRefs)(text)) vars.add(name);
2535
- if (!reachable && REACHABLE_FROM_JS.test(text)) reachable = true;
2621
+ if (!reachable && reachableFromJs(text)) reachable = true;
2536
2622
  }
2537
- if (strict) accountSnapshot(ctx, snapshot, accounting);
2623
+ if (accounts) accountSnapshot(ctx, snapshot, accounting);
2538
2624
  }
2539
2625
  for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
2540
- if (!strict) {
2626
+ const declared = declaredKeeps(ctx);
2627
+ for (const name of tokenVarsFor(ctx, declared)) vars.add(name);
2628
+ if (!accounts) {
2541
2629
  ctx.pruneTokens(sheet, vars, reachable);
2542
2630
  return;
2543
2631
  }
2544
2632
  for (const name of tokenVarsFor(ctx, accounting.paths)) vars.add(name);
2545
- if (accounting.prefixes.size && !accounting.declined.length) {
2633
+ const bounded = (ctx.config.prune?.keepTokens?.length ?? 0) > 0;
2634
+ if (accounting.prefixes.size && (bounded || !accounting.declined.length)) {
2546
2635
  const prefixes = Array.from(accounting.prefixes);
2547
2636
  const matched = [];
2548
2637
  for (const token of ctx.tokens.allTokens) if (prefixes.some((prefix) => token.name.startsWith(prefix))) matched.push(token.name);
@@ -2550,9 +2639,59 @@ function pruneTokensForBuild(ctx, sheet, results) {
2550
2639
  }
2551
2640
  const failing = accounting.declined.filter(failsStrict);
2552
2641
  const reported = accounting.declined.filter((entry) => !failsStrict(entry));
2553
- if (failing.length) throw new _bamboocss_shared.BambooError("TOKEN_REFERENCE_UNRESOLVED", `${failing.length} token reference(s) could not be resolved.\n\n${formatDeclined(ctx, failing)}\n\n\`pruneUnusedTokens: 'strict'\` asserts that every token path resolves at build time, so this is an error rather than a silent fallback. Spell the path as a string literal at the call, give a template a static prefix so it can be bounded, move the token into \`staticCss\`, or set \`pruneUnusedTokens: true\` to stop asserting.`);
2554
- if (reported.length) _bamboocss_logger.logger.warn("tokens:strict", `${reported.length} reference(s) could not be accounted for, so every token declaration is kept.\n\n${formatDeclined(ctx, reported)}\n\nThese are shapes the build cannot follow rather than paths you can respell — a component stored post-transform, a file it could not parse, a barrel it cannot classify, a dynamic \`import()\`. Narrow \`include\`, or accept the keeps.`);
2555
- ctx.pruneTokens(sheet, vars, accounting.declined.length > 0 && reachable);
2642
+ if (bounded && unresolved === "error" && accounting.declined.length) throw new _bamboocss_shared.BambooError("TOKEN_REFERENCE_UNRESOLVED", `${accounting.declined.length} token reference(s) could not be accounted for.\n\n${formatDeclined(ctx, accounting.declined)}\n\n\`prune.unresolvedPath: 'error'\` asserts that every token path resolves at build time, and \`prune.keepTokens\` declares where the ones that do not will land. Those are contradictory, so one has to go: drop \`keepTokens\` and respell the paths, or set \`prune: { unresolvedPath: 'warn' }\` and let the keeps cover them.`);
2643
+ if (failing.length && unresolved !== "off") {
2644
+ const where = `${failing.length} token reference(s) could not be resolved.\n\n${formatDeclined(ctx, failing)}\n\n`;
2645
+ if (unresolved === "error") throw new _bamboocss_shared.BambooError("TOKEN_REFERENCE_UNRESOLVED", where + "`prune.tokens: 'accounted'` asserts that every token path resolves at build time. Spell the path as a string literal at the call, give a template a static prefix so it can be bounded, name the category they land in with `prune: { keepTokens: ['colors.*'] }` and drop to `prune: { unresolvedPath: 'warn' }`, or set `prune: { tokens: 'reachable' }` to stop asserting.");
2646
+ _bamboocss_logger.logger.warn("tokens:unresolved", bounded ? where + "`prune.keepTokens` covers them: they keep what it names rather than every declaration in the theme. Nothing checks that they stay inside it, which is why it is yours to declare — a read landing outside the patterns loses its declaration and resolves to a `var()` with nothing behind it. Respell what you can, and widen the patterns for what you cannot." : where + "`prune.tokens: 'accounted'` asserts that every token path resolves at build time. Spell the path as a string literal at the call, give a template a static prefix so it can be bounded, name the category they land in with `prune: { keepTokens: ['colors.*'] }`, or set `prune: { tokens: 'reachable' }` to stop asserting.");
2647
+ }
2648
+ if (reported.length && unresolved !== "off") _bamboocss_logger.logger.warn("tokens:unresolved", `${reported.length} reference(s) could not be accounted for, so ` + (bounded ? `\`prune.keepTokens\` decides what they keep` : `every token declaration is kept`) + `.\n\n${formatDeclined(ctx, reported)}\n\nThese are shapes the build cannot follow rather than paths you can respell — a component stored post-transform, a file it could not parse, a barrel it cannot classify, a dynamic \`import()\`. ` + (bounded ? "Nothing checks that they stay inside `keepTokens`, which is why it is yours to declare: a read landing outside it loses its declaration. Narrow `include`, or widen the patterns." : "Narrow `include`, name the categories they reach with `prune: { keepTokens: [...] }`, or accept the keeps."));
2649
+ ctx.pruneTokens(sheet, vars, !bounded && accounting.declined.length > 0 && reachable);
2650
+ }
2651
+ /**
2652
+ * The dash-cased spelling of a token path, as it appears in the emitted css variable.
2653
+ *
2654
+ * Not a transform this applies — only one it recognises, to tell a user their pattern is
2655
+ * written against the wrong side of the system. The paths are camelCase (`fontSizes.3xl`) and
2656
+ * the variables are dash-cased (`--font-sizes-3xl`), so `font-sizes.*` is the natural thing to
2657
+ * write after reading `styles.css` and it matches nothing at all.
2658
+ */
2659
+ const dashed = (path) => path.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
2660
+ /**
2661
+ * The token names `prune.keepTokens` names, matched against the whole theme.
2662
+ *
2663
+ * Patterns are anchored globs over the dotted token *path* — `colors.*`, `colors.brand.*`,
2664
+ * `!colors.legacy.*`, or a bare path for one token. Matched case-sensitively, because a path is
2665
+ * a key in the config rather than free text.
2666
+ *
2667
+ * A pattern that matches nothing is reported rather than ignored. It is nearly always a typo
2668
+ * for one that would have matched, and the failure it causes is the one this whole module is
2669
+ * careful about everywhere else: a declaration dropped while something still asks for it, with
2670
+ * no error and no warning, resolving to a `var()` that inherits instead of falling back.
2671
+ */
2672
+ function declaredKeeps(ctx) {
2673
+ const patterns = ctx.config.prune?.keepTokens;
2674
+ if (!patterns?.length) return [];
2675
+ const includes = patterns.filter((pattern) => !pattern.startsWith("!"));
2676
+ if (!includes.length) _bamboocss_logger.logger.warn("prune:tokens", `\`prune.keepTokens\` holds only exclusions, so it keeps every token they do not name:\n\n${patterns.map((pattern) => ` ${pattern}`).join("\n")}\n\nA leading \`!\` subtracts from a selection and there is none here. Add the categories to keep — \`['colors.*', '!colors.legacy.*']\` — or use \`prune: { tokens: 'off' }\` if keeping everything is the intent.`);
2677
+ const matched = [];
2678
+ const used = /* @__PURE__ */ new Set();
2679
+ for (const token of ctx.tokens.allTokens) {
2680
+ if ((0, matcher.isMatch)(token.name, patterns, { caseSensitive: true })) matched.push(token.name);
2681
+ if (used.size === includes.length) continue;
2682
+ for (const pattern of includes) if ((0, matcher.isMatch)(token.name, pattern, { caseSensitive: true })) used.add(pattern);
2683
+ }
2684
+ const unused = includes.filter((pattern) => !used.has(pattern));
2685
+ if (unused.length) {
2686
+ const paths = ctx.tokens.allTokens.map((token) => token.name);
2687
+ const respell = unused.map((pattern) => {
2688
+ const hit = paths.find((path) => (0, matcher.isMatch)(dashed(path), pattern, { caseSensitive: true }));
2689
+ if (!hit) return ` ${pattern}`;
2690
+ return ` ${pattern} — matches \`${dashed(hit)}\`, which is the css variable's spelling. Write the token path: \`${hit.split(".")[0]}.*\``;
2691
+ }).join("\n");
2692
+ _bamboocss_logger.logger.warn("prune:tokens", `${unused.length} \`prune.keepTokens\` pattern(s) match no token in this theme:\n\n${respell}\n\nA pattern is an anchored glob over the dotted token *path* — \`colors.*\`, not \`colors\`, and \`fontSizes.*\` rather than the \`--font-sizes-\` spelling the css variable uses. One that matches nothing keeps nothing, which is silent everywhere except here.`);
2693
+ }
2694
+ return matched;
2556
2695
  }
2557
2696
  /** The custom properties a set of token paths resolves to. */
2558
2697
  function tokenVarsFor(ctx, paths) {
@@ -2615,7 +2754,7 @@ const keyframeNames = (ctx) => Object.keys(ctx.config.theme?.keyframes ?? {});
2615
2754
  *
2616
2755
  * Lowercase-initial only, so a JSX component (`<Button />`) is not mistaken for an element.
2617
2756
  * That cuts the other way too — a component rendering `<button>` inside a dependency is
2618
- * invisible here, which is why `prunePreflight` is opt-in.
2757
+ * invisible here, which is why `prune.preflight` is opt-in.
2619
2758
  *
2620
2759
  * The commoner blind spot is nearer than a dependency: this reads `include`, and `include`
2621
2760
  * conventionally covers components rather than markup. An entry template — `index.html`,
@@ -2771,16 +2910,17 @@ var Builder = class {
2771
2910
  return parserResult;
2772
2911
  };
2773
2912
  extract = () => {
2913
+ const ctx = this.getContextOrThrow();
2774
2914
  const hasConfigChanged = this.affecteds ? this.affecteds.hasConfigChanged : true;
2775
2915
  if (!this.filesMeta && !hasConfigChanged) {
2776
2916
  _bamboocss_logger.logger.debug("builder", "No files or config changed, skipping extract");
2777
- return;
2917
+ return ctx.assertExtracted();
2778
2918
  }
2779
- const ctx = this.getContextOrThrow();
2780
2919
  const files = ctx.getFiles();
2781
2920
  const done = _bamboocss_logger.logger.time.info("Extracted in");
2782
2921
  files.map((file) => this.extractFile(ctx, file));
2783
2922
  done();
2923
+ ctx.assertExtracted(files);
2784
2924
  };
2785
2925
  isValidRoot = (root) => {
2786
2926
  const ctx = this.getContextOrThrow();
@@ -2818,8 +2958,8 @@ var Builder = class {
2818
2958
  if (layerParams) ctx.appendLayerParams(sheet);
2819
2959
  ctx.appendBaselineCss(sheet);
2820
2960
  pruneTokensForBuild(ctx, sheet, []);
2821
- if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2822
- if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2961
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2962
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2823
2963
  return ctx.getCss(sheet);
2824
2964
  };
2825
2965
  registerDependency = (fn) => {
@@ -2902,12 +3042,12 @@ const startProfiling = async (cwd, prefix, isWatching) => {
2902
3042
  //#endregion
2903
3043
  //#region src/cssgen.ts
2904
3044
  const cssgen = async (ctx, options) => {
2905
- const { outfile, type, minimal, splitting } = options;
3045
+ const { outfile, type, splitting } = options;
2906
3046
  const sheet = ctx.createSheet();
2907
3047
  if (type) {
2908
3048
  const done = _bamboocss_logger.logger.time.info(ctx.messages.cssArtifactComplete(type));
2909
3049
  ctx.appendCssOfType(type, sheet);
2910
- if (type === "preflight" && ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3050
+ if (type === "preflight" && ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2911
3051
  if (outfile) {
2912
3052
  const css = ctx.getCss(sheet);
2913
3053
  _bamboocss_logger.logger.info("css", ctx.runtime.path.resolve(outfile));
@@ -2917,14 +3057,12 @@ const cssgen = async (ctx, options) => {
2917
3057
  } else {
2918
3058
  const { files, results } = ctx.parseFiles();
2919
3059
  const done = _bamboocss_logger.logger.time.info(ctx.messages.buildComplete(files.length));
2920
- if (!minimal) {
2921
- ctx.appendLayerParams(sheet);
2922
- ctx.appendBaselineCss(sheet);
2923
- }
3060
+ ctx.appendLayerParams(sheet);
3061
+ ctx.appendBaselineCss(sheet);
2924
3062
  ctx.appendParserCss(sheet);
2925
- if (!minimal) pruneTokensForBuild(ctx, sheet, results);
2926
- if (!minimal && ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2927
- if (!minimal && ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3063
+ pruneTokensForBuild(ctx, sheet, results);
3064
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3065
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2928
3066
  if (splitting) await ctx.writeSplitCss(sheet);
2929
3067
  else if (outfile) {
2930
3068
  const css = ctx.getCss(sheet);
@@ -2995,8 +3133,8 @@ async function build(ctx, artifactIds) {
2995
3133
  const parsed = ctx.parseFiles();
2996
3134
  ctx.appendParserCss(sheet);
2997
3135
  pruneTokensForBuild(ctx, sheet, parsed.results);
2998
- if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2999
- if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3136
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3137
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3000
3138
  await ctx.writeCss(sheet);
3001
3139
  done(ctx.messages.buildComplete(parsed.files.length));
3002
3140
  }
@@ -3041,8 +3179,8 @@ async function generate(config, configPath) {
3041
3179
  ctx.appendBaselineCss(sheet);
3042
3180
  ctx.appendParserCss(sheet);
3043
3181
  pruneTokensForBuild(ctx, sheet, []);
3044
- if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3045
- if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3182
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3183
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3046
3184
  const css = ctx.getCss(sheet);
3047
3185
  await ctx.runtime.fs.writeFile(outfile, css);
3048
3186
  done();
@@ -3143,10 +3281,10 @@ export default defineConfig({
3143
3281
  exclude: [],
3144
3282
 
3145
3283
  // Tokens, keyframes and @property rules nothing in the emitted css reaches are dropped
3146
- // by default — worth 36-78% of a new project's stylesheet. Set \`pruneUnusedTokens: false\`
3147
- // if you read tokens from somewhere the build cannot see them — \`token()\` with a
3148
- // computed path, or a hand-written stylesheet outside \`include\` — or list those under
3149
- // \`staticCss\` to keep them.
3284
+ // by default — worth 36-78% of a new project's stylesheet. If you read tokens from
3285
+ // somewhere the build cannot see them — \`token()\` with a computed path, or a
3286
+ // hand-written stylesheet outside \`include\` — name the categories they land in with
3287
+ // \`prune: { keepTokens: ['colors.*'] }\`, or set \`prune: { tokens: 'off' }\`.
3150
3288
 
3151
3289
  // Useful for theme customization
3152
3290
  theme: {
@@ -3207,6 +3345,12 @@ exports.codegen = codegen;
3207
3345
  exports.cssgen = cssgen;
3208
3346
  exports.debug = debug;
3209
3347
  exports.generate = generate;
3348
+ Object.defineProperty(exports, "generatePackageExports", {
3349
+ enumerable: true,
3350
+ get: function() {
3351
+ return _bamboocss_generator.generatePackageExports;
3352
+ }
3353
+ });
3210
3354
  exports.loadConfigAndCreateContext = loadConfigAndCreateContext;
3211
3355
  exports.parseDependency = parseDependency;
3212
3356
  exports.setLogStream = setLogStream;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ReportFormat } from "@bamboocss/reporter";
2
2
  import { AnalysisOptions, Artifact, ArtifactId, BambooHooks, Config, CssArtifactType, LoadConfigResult, Runtime, SpecFile, WatchOptions, WatcherEventType } from "@bamboocss/types";
3
3
  import { StyleEncoder, Stylesheet } from "@bamboocss/core";
4
- import { Generator } from "@bamboocss/generator";
4
+ import { Generator, generatePackageExports } from "@bamboocss/generator";
5
5
  import { ParserResult, Project } from "@bamboocss/parser";
6
6
  import { Message, Root } from "postcss";
7
7
 
@@ -51,6 +51,26 @@ declare class BambooContext extends Generator {
51
51
  output: OutputEngine;
52
52
  diff: DiffEngine;
53
53
  explicitDeps: string[];
54
+ /**
55
+ * Files whose extraction threw, keyed by path, holding what it threw.
56
+ *
57
+ * A parse failure is not an opinion about a build that still works. The file's styles never
58
+ * reach the encoder, so every rule it would have contributed is absent from the stylesheet
59
+ * and the classes its components ask for have nothing behind them — the same shape as a
60
+ * naming disagreement, and the reverse of `reportUnresolvedStyles`, where what the build
61
+ * *did* see still applies. Logging it and carrying on is how a build printed error-level
62
+ * lines, dropped rules, and exited 0.
63
+ *
64
+ * Retained rather than rethrown from the `catch`, so one pass names every broken file
65
+ * instead of the first. Keyed by file, so a failure survives the incremental passes that
66
+ * skip an unchanged file: nothing re-parses it, and its styles stay missing until it does.
67
+ *
68
+ * The error rather than its message, so `assertExtracted` can hand the originals on as a
69
+ * `cause`. The aggregate carries a code of its own — `ERR_BAMBOO_EXTRACT_FAILED` — and the
70
+ * codes underneath it are what a caller has to read to tell a retired token spelling from a
71
+ * syntax error.
72
+ */
73
+ parseFailures: Map<string, unknown>;
54
74
  constructor(conf: LoadConfigResult);
55
75
  /**
56
76
  * Report `css()` calls whose styles the build could not fully see.
@@ -65,7 +85,36 @@ declare class BambooContext extends Generator {
65
85
  private getExplicitDependencies;
66
86
  initMessage: () => string;
67
87
  getFiles: () => string[];
88
+ /**
89
+ * Fail the build if any file's extraction threw.
90
+ *
91
+ * Called at the end of an extraction pass rather than from the `catch`, so the message names
92
+ * every broken file at once — a config with one retired token spelling in six components is
93
+ * fixed once, not six builds in a row.
94
+ *
95
+ * This is what makes the integrations agree. `cssgen` already exited non-zero on a file it
96
+ * could not extract, by letting the throw through; every bundler goes through `parseFile`,
97
+ * which caught it. CI running a build passed what CI running `cssgen` rejected, over the same
98
+ * source.
99
+ *
100
+ * `files` is the set still in scope, which the caller has usually just globbed. Deleting the
101
+ * offending file, or taking it out of `include`, is a *fix* — and nothing re-parses a file
102
+ * that is gone, so the entry that outlived it would fail every later build, naming a path
103
+ * that no longer exists. A context outlives rebuilds (it is replaced only when the config
104
+ * changes) and both long-lived integrations hold one, so that wedged a dev server until the
105
+ * process was restarted.
106
+ */
107
+ assertExtracted: (files?: Iterable<string>) => void;
108
+ /** A path as the user typed it, when it is under `cwd`. */
109
+ private relative;
68
110
  parseFile: (filePath: string, styleEncoder?: StyleEncoder) => ParserResult | undefined;
111
+ /**
112
+ * Extract every file in one pass, and fail on the ones that could not be read.
113
+ *
114
+ * Routed through `parseFile` rather than parsing directly, so the two entry points cannot
115
+ * disagree about what a failure means. This one used to let the first throw out, which is
116
+ * why `cssgen` and a bundler build reported different things about the same source.
117
+ */
69
118
  parseFiles: (styleEncoder?: StyleEncoder) => {
70
119
  filesWithCss: string[];
71
120
  files: string[];
@@ -180,7 +229,6 @@ interface CssGenOptions {
180
229
  cwd: string;
181
230
  outfile?: string;
182
231
  type?: CssArtifactType;
183
- minimal?: boolean;
184
232
  splitting?: boolean;
185
233
  }
186
234
  declare const cssgen: (ctx: BambooContext, options: CssGenOptions) => Promise<void>;
@@ -225,4 +273,4 @@ interface SpecOptions {
225
273
  }
226
274
  declare function spec(ctx: BambooContext, options: SpecOptions): Promise<SpecFile[]>;
227
275
  //#endregion
228
- export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
276
+ export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, generate, generatePackageExports, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ReportFormat } from "@bamboocss/reporter";
2
2
  import { StyleEncoder, Stylesheet } from "@bamboocss/core";
3
- import { Generator } from "@bamboocss/generator";
3
+ import { Generator, generatePackageExports } from "@bamboocss/generator";
4
4
  import { ParserResult, Project } from "@bamboocss/parser";
5
5
  import { AnalysisOptions, Artifact, ArtifactId, BambooHooks, Config, CssArtifactType, LoadConfigResult, Runtime, SpecFile, WatchOptions, WatcherEventType } from "@bamboocss/types";
6
6
  import { Message, Root } from "postcss";
@@ -51,6 +51,26 @@ declare class BambooContext extends Generator {
51
51
  output: OutputEngine;
52
52
  diff: DiffEngine;
53
53
  explicitDeps: string[];
54
+ /**
55
+ * Files whose extraction threw, keyed by path, holding what it threw.
56
+ *
57
+ * A parse failure is not an opinion about a build that still works. The file's styles never
58
+ * reach the encoder, so every rule it would have contributed is absent from the stylesheet
59
+ * and the classes its components ask for have nothing behind them — the same shape as a
60
+ * naming disagreement, and the reverse of `reportUnresolvedStyles`, where what the build
61
+ * *did* see still applies. Logging it and carrying on is how a build printed error-level
62
+ * lines, dropped rules, and exited 0.
63
+ *
64
+ * Retained rather than rethrown from the `catch`, so one pass names every broken file
65
+ * instead of the first. Keyed by file, so a failure survives the incremental passes that
66
+ * skip an unchanged file: nothing re-parses it, and its styles stay missing until it does.
67
+ *
68
+ * The error rather than its message, so `assertExtracted` can hand the originals on as a
69
+ * `cause`. The aggregate carries a code of its own — `ERR_BAMBOO_EXTRACT_FAILED` — and the
70
+ * codes underneath it are what a caller has to read to tell a retired token spelling from a
71
+ * syntax error.
72
+ */
73
+ parseFailures: Map<string, unknown>;
54
74
  constructor(conf: LoadConfigResult);
55
75
  /**
56
76
  * Report `css()` calls whose styles the build could not fully see.
@@ -65,7 +85,36 @@ declare class BambooContext extends Generator {
65
85
  private getExplicitDependencies;
66
86
  initMessage: () => string;
67
87
  getFiles: () => string[];
88
+ /**
89
+ * Fail the build if any file's extraction threw.
90
+ *
91
+ * Called at the end of an extraction pass rather than from the `catch`, so the message names
92
+ * every broken file at once — a config with one retired token spelling in six components is
93
+ * fixed once, not six builds in a row.
94
+ *
95
+ * This is what makes the integrations agree. `cssgen` already exited non-zero on a file it
96
+ * could not extract, by letting the throw through; every bundler goes through `parseFile`,
97
+ * which caught it. CI running a build passed what CI running `cssgen` rejected, over the same
98
+ * source.
99
+ *
100
+ * `files` is the set still in scope, which the caller has usually just globbed. Deleting the
101
+ * offending file, or taking it out of `include`, is a *fix* — and nothing re-parses a file
102
+ * that is gone, so the entry that outlived it would fail every later build, naming a path
103
+ * that no longer exists. A context outlives rebuilds (it is replaced only when the config
104
+ * changes) and both long-lived integrations hold one, so that wedged a dev server until the
105
+ * process was restarted.
106
+ */
107
+ assertExtracted: (files?: Iterable<string>) => void;
108
+ /** A path as the user typed it, when it is under `cwd`. */
109
+ private relative;
68
110
  parseFile: (filePath: string, styleEncoder?: StyleEncoder) => ParserResult | undefined;
111
+ /**
112
+ * Extract every file in one pass, and fail on the ones that could not be read.
113
+ *
114
+ * Routed through `parseFile` rather than parsing directly, so the two entry points cannot
115
+ * disagree about what a failure means. This one used to let the first throw out, which is
116
+ * why `cssgen` and a bundler build reported different things about the same source.
117
+ */
69
118
  parseFiles: (styleEncoder?: StyleEncoder) => {
70
119
  filesWithCss: string[];
71
120
  files: string[];
@@ -180,7 +229,6 @@ interface CssGenOptions {
180
229
  cwd: string;
181
230
  outfile?: string;
182
231
  type?: CssArtifactType;
183
- minimal?: boolean;
184
232
  splitting?: boolean;
185
233
  }
186
234
  declare const cssgen: (ctx: BambooContext, options: CssGenOptions) => Promise<void>;
@@ -225,4 +273,4 @@ interface SpecOptions {
225
273
  }
226
274
  declare function spec(ctx: BambooContext, options: SpecOptions): Promise<SpecFile[]>;
227
275
  //#endregion
228
- export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
276
+ export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, generate, generatePackageExports, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
package/dist/index.mjs CHANGED
@@ -4,12 +4,10 @@ import { convertTsPathsToRegexes, diffConfigs, findConfig, getConfigDependencies
4
4
  import { BambooError, cssVarRefs, uniq } from "@bamboocss/shared";
5
5
  import { appendFileSync, existsSync, readFileSync, statSync, writeFileSync } from "fs";
6
6
  import { dirname, extname, isAbsolute, join, normalize, parse, relative, resolve, sep } from "path";
7
- import { pluginLightningcss } from "@bamboocss/plugin-lightningcss";
8
7
  import { pluginSvelte } from "@bamboocss/plugin-svelte";
9
8
  import { pluginVue } from "@bamboocss/plugin-vue";
10
- import browserslist from "browserslist";
11
9
  import { checkNamingAgreement, formatNamingDisagreement, messages } from "@bamboocss/core";
12
- import { Generator } from "@bamboocss/generator";
10
+ import { Generator, generatePackageExports } from "@bamboocss/generator";
13
11
  import { Project } from "@bamboocss/parser";
14
12
  import { debounce } from "perfect-debounce";
15
13
  import process$1 from "node:process";
@@ -23,6 +21,7 @@ import path from "node:path";
23
21
  import fs, { promises } from "node:fs";
24
22
  import isGlob from "is-glob";
25
23
  import globParent from "glob-parent";
24
+ import { isMatch } from "matcher";
26
25
  import { resolveTsPathPattern } from "@bamboocss/config/ts-path";
27
26
  import { Node, SyntaxKind } from "ts-morph";
28
27
  import readline from "node:readline";
@@ -1598,6 +1597,8 @@ var OutputEngine = class {
1598
1597
  };
1599
1598
  //#endregion
1600
1599
  //#region src/create-context.ts
1600
+ /** A thrown value's message, for a `catch` binding that is typed `unknown`. */
1601
+ const messageOf = (error) => error instanceof Error ? error.message : String(error);
1601
1602
  /**
1602
1603
  * What each loss is, and what the author can do about it.
1603
1604
  *
@@ -1618,6 +1619,26 @@ var BambooContext = class extends Generator {
1618
1619
  output;
1619
1620
  diff;
1620
1621
  explicitDeps = [];
1622
+ /**
1623
+ * Files whose extraction threw, keyed by path, holding what it threw.
1624
+ *
1625
+ * A parse failure is not an opinion about a build that still works. The file's styles never
1626
+ * reach the encoder, so every rule it would have contributed is absent from the stylesheet
1627
+ * and the classes its components ask for have nothing behind them — the same shape as a
1628
+ * naming disagreement, and the reverse of `reportUnresolvedStyles`, where what the build
1629
+ * *did* see still applies. Logging it and carrying on is how a build printed error-level
1630
+ * lines, dropped rules, and exited 0.
1631
+ *
1632
+ * Retained rather than rethrown from the `catch`, so one pass names every broken file
1633
+ * instead of the first. Keyed by file, so a failure survives the incremental passes that
1634
+ * skip an unchanged file: nothing re-parses it, and its styles stay missing until it does.
1635
+ *
1636
+ * The error rather than its message, so `assertExtracted` can hand the originals on as a
1637
+ * `cause`. The aggregate carries a code of its own — `ERR_BAMBOO_EXTRACT_FAILED` — and the
1638
+ * codes underneath it are what a caller has to read to tell a retired token spelling from a
1639
+ * syntax error.
1640
+ */
1641
+ parseFailures = /* @__PURE__ */ new Map();
1621
1642
  constructor(conf) {
1622
1643
  super(conf);
1623
1644
  const config = conf.config;
@@ -1687,6 +1708,35 @@ var BambooContext = class extends Generator {
1687
1708
  cwd
1688
1709
  });
1689
1710
  };
1711
+ /**
1712
+ * Fail the build if any file's extraction threw.
1713
+ *
1714
+ * Called at the end of an extraction pass rather than from the `catch`, so the message names
1715
+ * every broken file at once — a config with one retired token spelling in six components is
1716
+ * fixed once, not six builds in a row.
1717
+ *
1718
+ * This is what makes the integrations agree. `cssgen` already exited non-zero on a file it
1719
+ * could not extract, by letting the throw through; every bundler goes through `parseFile`,
1720
+ * which caught it. CI running a build passed what CI running `cssgen` rejected, over the same
1721
+ * source.
1722
+ *
1723
+ * `files` is the set still in scope, which the caller has usually just globbed. Deleting the
1724
+ * offending file, or taking it out of `include`, is a *fix* — and nothing re-parses a file
1725
+ * that is gone, so the entry that outlived it would fail every later build, naming a path
1726
+ * that no longer exists. A context outlives rebuilds (it is replaced only when the config
1727
+ * changes) and both long-lived integrations hold one, so that wedged a dev server until the
1728
+ * process was restarted.
1729
+ */
1730
+ assertExtracted = (files) => {
1731
+ if (!this.parseFailures.size) return;
1732
+ const inScope = new Set(Array.from(files ?? this.getFiles(), (file) => this.runtime.path.abs(this.config.cwd, file)));
1733
+ for (const file of this.parseFailures.keys()) if (!inScope.has(file)) this.parseFailures.delete(file);
1734
+ if (!this.parseFailures.size) return;
1735
+ const detail = Array.from(this.parseFailures.entries()).map(([file, error]) => `${this.relative(file)}\n${messageOf(error).replace(/^(?=.)/gm, " ")}`).join("\n\n");
1736
+ throw new BambooError("EXTRACT_FAILED", `${this.parseFailures.size} file(s) could not be extracted:\n\n${detail}\n\nNothing emits a rule for a file the build could not read, so every style in these is absent from the stylesheet and the classes their components ask for have nothing behind them.`, { cause: new AggregateError(Array.from(this.parseFailures.values()), `${this.parseFailures.size} file(s) could not be extracted`) });
1737
+ };
1738
+ /** A path as the user typed it, when it is under `cwd`. */
1739
+ relative = (file) => file.startsWith(this.config.cwd) ? file.slice(this.config.cwd.length + 1) : file;
1690
1740
  parseFile = (filePath, styleEncoder) => {
1691
1741
  const file = this.runtime.path.abs(this.config.cwd, filePath);
1692
1742
  logger.debug("file:extract", file);
@@ -1695,27 +1745,34 @@ var BambooContext = class extends Generator {
1695
1745
  try {
1696
1746
  const encoder = styleEncoder || this.parserOptions.encoder;
1697
1747
  result = this.project.parseSourceFile(file, encoder);
1748
+ this.parseFailures.delete(file);
1698
1749
  } catch (error) {
1699
1750
  logger.caughtError("file:extract", `Failed to parse ${file}`, error);
1751
+ this.parseFailures.set(file, error);
1700
1752
  }
1701
1753
  if (result) this.reportUnresolvedStyles(result);
1702
1754
  measure();
1703
1755
  return result;
1704
1756
  };
1757
+ /**
1758
+ * Extract every file in one pass, and fail on the ones that could not be read.
1759
+ *
1760
+ * Routed through `parseFile` rather than parsing directly, so the two entry points cannot
1761
+ * disagree about what a failure means. This one used to let the first throw out, which is
1762
+ * why `cssgen` and a bundler build reported different things about the same source.
1763
+ */
1705
1764
  parseFiles = (styleEncoder) => {
1706
1765
  const encoder = styleEncoder || this.parserOptions.encoder;
1707
1766
  const files = this.getFiles();
1708
1767
  const filesWithCss = [];
1709
1768
  const results = [];
1710
1769
  files.forEach((file) => {
1711
- const measure = logger.time.debug(`Parsed ${file}`);
1712
- const result = this.project.parseSourceFile(file, encoder);
1713
- measure();
1714
- if (result) this.reportUnresolvedStyles(result);
1770
+ const result = this.parseFile(file, encoder);
1715
1771
  if (!result || result.isEmpty() || encoder.isEmpty()) return;
1716
1772
  filesWithCss.push(file);
1717
1773
  results.push(result);
1718
1774
  });
1775
+ this.assertExtracted(files);
1719
1776
  return {
1720
1777
  filesWithCss,
1721
1778
  files,
@@ -2068,12 +2125,17 @@ async function loadTsConfig(conf, cwd) {
2068
2125
  const RESOLVED_HOOKS_NAME = "__resolved__";
2069
2126
  /**
2070
2127
  * Built-in plugins that are auto-injected when using the CLI or PostCSS plugin.
2071
- * These provide Vue/Svelte file support and LightningCSS optimization.
2128
+ * These provide Vue/Svelte single-file-component support.
2129
+ *
2130
+ * LightningCSS is not among them any more. It was reached through a `lightningcss: true`
2131
+ * config flag whose only job was to push `pluginLightningcss()` into this list — a second
2132
+ * way to say something `plugins` already said, and the expensive one: naming the plugin
2133
+ * here meant a static import, which made `@bamboocss/plugin-lightningcss` a hard dependency
2134
+ * of this package, which put a native binary in every install whether or not the flag was
2135
+ * ever set. List the plugin yourself to use it.
2072
2136
  */
2073
- function getAutoPlugins(config) {
2074
- const plugins = [pluginVue(), pluginSvelte()];
2075
- if (config.lightningcss) plugins.push(pluginLightningcss());
2076
- return plugins;
2137
+ function getAutoPlugins() {
2138
+ return [pluginVue(), pluginSvelte()];
2077
2139
  }
2078
2140
  /**
2079
2141
  * Load config and create context with auto-injected plugins.
@@ -2088,8 +2150,7 @@ async function loadConfigAndCreateContext(options = {}) {
2088
2150
  });
2089
2151
  if (config) Object.assign(conf.config, config);
2090
2152
  if (options.cwd) conf.config.cwd = options.cwd;
2091
- if (conf.config.lightningcss && !conf.config.browserslist) conf.config.browserslist ||= browserslist.findConfig(cwd)?.defaults;
2092
- const autoPlugins = getAutoPlugins(conf.config);
2153
+ const autoPlugins = getAutoPlugins();
2093
2154
  conf.hooks = mergeHooks([...autoPlugins, {
2094
2155
  name: RESOLVED_HOOKS_NAME,
2095
2156
  hooks: conf.hooks
@@ -2191,9 +2252,9 @@ function* snapshotTexts(snapshot) {
2191
2252
  //#endregion
2192
2253
  //#region src/token-accounting.ts
2193
2254
  /**
2194
- * The one decline `strict` fails the build on.
2255
+ * The one decline `prune.tokens: 'accounted'` fails the build on.
2195
2256
  *
2196
- * `strict` asserts that every token path resolves, and this is the reason that says otherwise:
2257
+ * `prune.tokens: 'accounted'` asserts that every token path resolves, and this is the reason that says otherwise:
2197
2258
  * a token binding used in a way the build cannot follow — a path built at runtime, a binding
2198
2259
  * assigned away, a namespace enumerated. It is about the author's *token usage*, and it has a
2199
2260
  * fix at the call site.
@@ -2454,14 +2515,38 @@ function unwrapAssertions(node) {
2454
2515
  * follow, and it covers the callers below that supply no `results` at all.
2455
2516
  */
2456
2517
  const TOKEN_CALL = /\btoken(?:\s*\.\s*value)?\s*\(\s*['"`]([^'"`]+)['"`]/g;
2518
+ /** An import of the generated tokens artifact, under any of the spellings that reach it. */
2519
+ const TOKEN_IMPORT = /\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2520
+ /** A call to `token()` or `token.value()`, whatever the argument is — or is not. */
2521
+ const TOKEN_CALLEE = /\btoken(\s*\.\s*value)?\s*\(/;
2522
+ /** The same, but only where the argument is a string literal — the shape `TOKEN_CALL` resolves. */
2523
+ const TOKEN_CALL_LITERAL = /\btoken(?:\s*\.\s*value)?\s*\(\s*['"`]/;
2524
+ /** String literals, contents and all. */
2525
+ const STRING_LITERAL = /'(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|`(?:[^`\\]|\\.)*`/g;
2457
2526
  /**
2458
- * A token reached from javascript at all — a call of any shape, or an import of the artifact.
2527
+ * Whether a token is reached from javascript at all — a call of any shape, or an import of the
2528
+ * artifact. Being true keeps every token declaration, so the whole of `prune.tokens` rests
2529
+ * on it.
2530
+ *
2531
+ * The awkward part is that a token reference inside a css value is now spelled `token(…)` too,
2532
+ * and it must *not* count: `css({ border: '1px solid token(colors.red.300)' })` reaches a token
2533
+ * from a stylesheet, where the css scan already accounts for it, not from javascript. Reading it
2534
+ * as a call turned pruning off wholesale — measured at 3.2x the stylesheet on a sandbox, since
2535
+ * "keep everything" is what the gate means. It was only ever latent before, because `{…}` was
2536
+ * the spelling the docs used and it looked nothing like a call.
2537
+ *
2538
+ * So a `token(` that survives blanking every string literal is a real call, and one that does
2539
+ * not was written inside a string. The literal-argument test comes first and on the raw text,
2540
+ * which is what keeps this a superset of `TOKEN_CALL` as the coupling in `collectTokenReferences`
2541
+ * requires: a resolvable call embedded in a template literal — a fixture holding source code —
2542
+ * still counts, even though blanking would hide it.
2459
2543
  *
2460
- * Has to stay a strict superset of `TOKEN_CALL`: it must match wherever that one matches, and
2461
- * also wherever that one gives up. See `collectTokenReferences` for why the redundancy holds.
2462
- * No `g` flag, so `test` carries no state between files.
2544
+ * No `g` flag on the tests, so `test` carries no state between files.
2463
2545
  */
2464
- const REACHABLE_FROM_JS = /\btoken(\s*\.\s*value)?\s*\(|\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2546
+ const reachableFromJs = (text) => {
2547
+ if (TOKEN_IMPORT.test(text) || TOKEN_CALL_LITERAL.test(text)) return true;
2548
+ return TOKEN_CALLEE.test(text) && TOKEN_CALLEE.test(text.replace(STRING_LITERAL, "''"));
2549
+ };
2465
2550
  /**
2466
2551
  * The text of every file `include` covers — as written on disk, and, when they differ, as the
2467
2552
  * parser understands it.
@@ -2488,7 +2573,7 @@ function* sourceTexts(ctx) {
2488
2573
  * The token prune, as all three build paths need to run it.
2489
2574
  *
2490
2575
  * One function because it was three copies of one conditional, and the `false` branch went
2491
- * missing from a copy: a watch rebuild with `pruneUnusedTokens: false` skipped `pruneTokens`
2576
+ * missing from a copy: a watch rebuild with `prune: { tokens: 'off' }` skipped `pruneTokens`
2492
2577
  * altogether, so it kept `@property` registrations that a full build of the same source
2493
2578
  * strips. The other two copies carried a comment pointing at that file for the reasoning,
2494
2579
  * which is how a missing branch reads as intentional.
@@ -2499,11 +2584,13 @@ function* sourceTexts(ctx) {
2499
2584
  * a preset's whole filter and gradient set for nothing.
2500
2585
  */
2501
2586
  function pruneTokensForBuild(ctx, sheet, results) {
2502
- if (!ctx.config.pruneUnusedTokens) {
2587
+ const strategy = ctx.config.prune?.tokens ?? "reachable";
2588
+ if (strategy === "off") {
2503
2589
  ctx.pruneTokens(sheet);
2504
2590
  return;
2505
2591
  }
2506
- const strict = ctx.config.pruneUnusedTokens === "strict";
2592
+ const accounts = strategy === "accounted";
2593
+ const unresolved = accounts ? ctx.config.prune?.unresolvedPath ?? "warn" : "off";
2507
2594
  const paths = /* @__PURE__ */ new Set();
2508
2595
  const vars = /* @__PURE__ */ new Set();
2509
2596
  const accounting = {
@@ -2517,17 +2604,20 @@ function pruneTokensForBuild(ctx, sheet, results) {
2517
2604
  for (const text of snapshotTexts(snapshot)) {
2518
2605
  for (const match of text.matchAll(TOKEN_CALL)) paths.add(match[1]);
2519
2606
  for (const name of cssVarRefs(text)) vars.add(name);
2520
- if (!reachable && REACHABLE_FROM_JS.test(text)) reachable = true;
2607
+ if (!reachable && reachableFromJs(text)) reachable = true;
2521
2608
  }
2522
- if (strict) accountSnapshot(ctx, snapshot, accounting);
2609
+ if (accounts) accountSnapshot(ctx, snapshot, accounting);
2523
2610
  }
2524
2611
  for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
2525
- if (!strict) {
2612
+ const declared = declaredKeeps(ctx);
2613
+ for (const name of tokenVarsFor(ctx, declared)) vars.add(name);
2614
+ if (!accounts) {
2526
2615
  ctx.pruneTokens(sheet, vars, reachable);
2527
2616
  return;
2528
2617
  }
2529
2618
  for (const name of tokenVarsFor(ctx, accounting.paths)) vars.add(name);
2530
- if (accounting.prefixes.size && !accounting.declined.length) {
2619
+ const bounded = (ctx.config.prune?.keepTokens?.length ?? 0) > 0;
2620
+ if (accounting.prefixes.size && (bounded || !accounting.declined.length)) {
2531
2621
  const prefixes = Array.from(accounting.prefixes);
2532
2622
  const matched = [];
2533
2623
  for (const token of ctx.tokens.allTokens) if (prefixes.some((prefix) => token.name.startsWith(prefix))) matched.push(token.name);
@@ -2535,9 +2625,59 @@ function pruneTokensForBuild(ctx, sheet, results) {
2535
2625
  }
2536
2626
  const failing = accounting.declined.filter(failsStrict);
2537
2627
  const reported = accounting.declined.filter((entry) => !failsStrict(entry));
2538
- if (failing.length) throw new BambooError("TOKEN_REFERENCE_UNRESOLVED", `${failing.length} token reference(s) could not be resolved.\n\n${formatDeclined(ctx, failing)}\n\n\`pruneUnusedTokens: 'strict'\` asserts that every token path resolves at build time, so this is an error rather than a silent fallback. Spell the path as a string literal at the call, give a template a static prefix so it can be bounded, move the token into \`staticCss\`, or set \`pruneUnusedTokens: true\` to stop asserting.`);
2539
- if (reported.length) logger.warn("tokens:strict", `${reported.length} reference(s) could not be accounted for, so every token declaration is kept.\n\n${formatDeclined(ctx, reported)}\n\nThese are shapes the build cannot follow rather than paths you can respell — a component stored post-transform, a file it could not parse, a barrel it cannot classify, a dynamic \`import()\`. Narrow \`include\`, or accept the keeps.`);
2540
- ctx.pruneTokens(sheet, vars, accounting.declined.length > 0 && reachable);
2628
+ if (bounded && unresolved === "error" && accounting.declined.length) throw new BambooError("TOKEN_REFERENCE_UNRESOLVED", `${accounting.declined.length} token reference(s) could not be accounted for.\n\n${formatDeclined(ctx, accounting.declined)}\n\n\`prune.unresolvedPath: 'error'\` asserts that every token path resolves at build time, and \`prune.keepTokens\` declares where the ones that do not will land. Those are contradictory, so one has to go: drop \`keepTokens\` and respell the paths, or set \`prune: { unresolvedPath: 'warn' }\` and let the keeps cover them.`);
2629
+ if (failing.length && unresolved !== "off") {
2630
+ const where = `${failing.length} token reference(s) could not be resolved.\n\n${formatDeclined(ctx, failing)}\n\n`;
2631
+ if (unresolved === "error") throw new BambooError("TOKEN_REFERENCE_UNRESOLVED", where + "`prune.tokens: 'accounted'` asserts that every token path resolves at build time. Spell the path as a string literal at the call, give a template a static prefix so it can be bounded, name the category they land in with `prune: { keepTokens: ['colors.*'] }` and drop to `prune: { unresolvedPath: 'warn' }`, or set `prune: { tokens: 'reachable' }` to stop asserting.");
2632
+ logger.warn("tokens:unresolved", bounded ? where + "`prune.keepTokens` covers them: they keep what it names rather than every declaration in the theme. Nothing checks that they stay inside it, which is why it is yours to declare — a read landing outside the patterns loses its declaration and resolves to a `var()` with nothing behind it. Respell what you can, and widen the patterns for what you cannot." : where + "`prune.tokens: 'accounted'` asserts that every token path resolves at build time. Spell the path as a string literal at the call, give a template a static prefix so it can be bounded, name the category they land in with `prune: { keepTokens: ['colors.*'] }`, or set `prune: { tokens: 'reachable' }` to stop asserting.");
2633
+ }
2634
+ if (reported.length && unresolved !== "off") logger.warn("tokens:unresolved", `${reported.length} reference(s) could not be accounted for, so ` + (bounded ? `\`prune.keepTokens\` decides what they keep` : `every token declaration is kept`) + `.\n\n${formatDeclined(ctx, reported)}\n\nThese are shapes the build cannot follow rather than paths you can respell — a component stored post-transform, a file it could not parse, a barrel it cannot classify, a dynamic \`import()\`. ` + (bounded ? "Nothing checks that they stay inside `keepTokens`, which is why it is yours to declare: a read landing outside it loses its declaration. Narrow `include`, or widen the patterns." : "Narrow `include`, name the categories they reach with `prune: { keepTokens: [...] }`, or accept the keeps."));
2635
+ ctx.pruneTokens(sheet, vars, !bounded && accounting.declined.length > 0 && reachable);
2636
+ }
2637
+ /**
2638
+ * The dash-cased spelling of a token path, as it appears in the emitted css variable.
2639
+ *
2640
+ * Not a transform this applies — only one it recognises, to tell a user their pattern is
2641
+ * written against the wrong side of the system. The paths are camelCase (`fontSizes.3xl`) and
2642
+ * the variables are dash-cased (`--font-sizes-3xl`), so `font-sizes.*` is the natural thing to
2643
+ * write after reading `styles.css` and it matches nothing at all.
2644
+ */
2645
+ const dashed = (path) => path.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
2646
+ /**
2647
+ * The token names `prune.keepTokens` names, matched against the whole theme.
2648
+ *
2649
+ * Patterns are anchored globs over the dotted token *path* — `colors.*`, `colors.brand.*`,
2650
+ * `!colors.legacy.*`, or a bare path for one token. Matched case-sensitively, because a path is
2651
+ * a key in the config rather than free text.
2652
+ *
2653
+ * A pattern that matches nothing is reported rather than ignored. It is nearly always a typo
2654
+ * for one that would have matched, and the failure it causes is the one this whole module is
2655
+ * careful about everywhere else: a declaration dropped while something still asks for it, with
2656
+ * no error and no warning, resolving to a `var()` that inherits instead of falling back.
2657
+ */
2658
+ function declaredKeeps(ctx) {
2659
+ const patterns = ctx.config.prune?.keepTokens;
2660
+ if (!patterns?.length) return [];
2661
+ const includes = patterns.filter((pattern) => !pattern.startsWith("!"));
2662
+ if (!includes.length) logger.warn("prune:tokens", `\`prune.keepTokens\` holds only exclusions, so it keeps every token they do not name:\n\n${patterns.map((pattern) => ` ${pattern}`).join("\n")}\n\nA leading \`!\` subtracts from a selection and there is none here. Add the categories to keep — \`['colors.*', '!colors.legacy.*']\` — or use \`prune: { tokens: 'off' }\` if keeping everything is the intent.`);
2663
+ const matched = [];
2664
+ const used = /* @__PURE__ */ new Set();
2665
+ for (const token of ctx.tokens.allTokens) {
2666
+ if (isMatch(token.name, patterns, { caseSensitive: true })) matched.push(token.name);
2667
+ if (used.size === includes.length) continue;
2668
+ for (const pattern of includes) if (isMatch(token.name, pattern, { caseSensitive: true })) used.add(pattern);
2669
+ }
2670
+ const unused = includes.filter((pattern) => !used.has(pattern));
2671
+ if (unused.length) {
2672
+ const paths = ctx.tokens.allTokens.map((token) => token.name);
2673
+ const respell = unused.map((pattern) => {
2674
+ const hit = paths.find((path) => isMatch(dashed(path), pattern, { caseSensitive: true }));
2675
+ if (!hit) return ` ${pattern}`;
2676
+ return ` ${pattern} — matches \`${dashed(hit)}\`, which is the css variable's spelling. Write the token path: \`${hit.split(".")[0]}.*\``;
2677
+ }).join("\n");
2678
+ logger.warn("prune:tokens", `${unused.length} \`prune.keepTokens\` pattern(s) match no token in this theme:\n\n${respell}\n\nA pattern is an anchored glob over the dotted token *path* — \`colors.*\`, not \`colors\`, and \`fontSizes.*\` rather than the \`--font-sizes-\` spelling the css variable uses. One that matches nothing keeps nothing, which is silent everywhere except here.`);
2679
+ }
2680
+ return matched;
2541
2681
  }
2542
2682
  /** The custom properties a set of token paths resolves to. */
2543
2683
  function tokenVarsFor(ctx, paths) {
@@ -2600,7 +2740,7 @@ const keyframeNames = (ctx) => Object.keys(ctx.config.theme?.keyframes ?? {});
2600
2740
  *
2601
2741
  * Lowercase-initial only, so a JSX component (`<Button />`) is not mistaken for an element.
2602
2742
  * That cuts the other way too — a component rendering `<button>` inside a dependency is
2603
- * invisible here, which is why `prunePreflight` is opt-in.
2743
+ * invisible here, which is why `prune.preflight` is opt-in.
2604
2744
  *
2605
2745
  * The commoner blind spot is nearer than a dependency: this reads `include`, and `include`
2606
2746
  * conventionally covers components rather than markup. An entry template — `index.html`,
@@ -2756,16 +2896,17 @@ var Builder = class {
2756
2896
  return parserResult;
2757
2897
  };
2758
2898
  extract = () => {
2899
+ const ctx = this.getContextOrThrow();
2759
2900
  const hasConfigChanged = this.affecteds ? this.affecteds.hasConfigChanged : true;
2760
2901
  if (!this.filesMeta && !hasConfigChanged) {
2761
2902
  logger.debug("builder", "No files or config changed, skipping extract");
2762
- return;
2903
+ return ctx.assertExtracted();
2763
2904
  }
2764
- const ctx = this.getContextOrThrow();
2765
2905
  const files = ctx.getFiles();
2766
2906
  const done = logger.time.info("Extracted in");
2767
2907
  files.map((file) => this.extractFile(ctx, file));
2768
2908
  done();
2909
+ ctx.assertExtracted(files);
2769
2910
  };
2770
2911
  isValidRoot = (root) => {
2771
2912
  const ctx = this.getContextOrThrow();
@@ -2803,8 +2944,8 @@ var Builder = class {
2803
2944
  if (layerParams) ctx.appendLayerParams(sheet);
2804
2945
  ctx.appendBaselineCss(sheet);
2805
2946
  pruneTokensForBuild(ctx, sheet, []);
2806
- if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2807
- if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2947
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2948
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2808
2949
  return ctx.getCss(sheet);
2809
2950
  };
2810
2951
  registerDependency = (fn) => {
@@ -2887,12 +3028,12 @@ const startProfiling = async (cwd, prefix, isWatching) => {
2887
3028
  //#endregion
2888
3029
  //#region src/cssgen.ts
2889
3030
  const cssgen = async (ctx, options) => {
2890
- const { outfile, type, minimal, splitting } = options;
3031
+ const { outfile, type, splitting } = options;
2891
3032
  const sheet = ctx.createSheet();
2892
3033
  if (type) {
2893
3034
  const done = logger.time.info(ctx.messages.cssArtifactComplete(type));
2894
3035
  ctx.appendCssOfType(type, sheet);
2895
- if (type === "preflight" && ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3036
+ if (type === "preflight" && ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2896
3037
  if (outfile) {
2897
3038
  const css = ctx.getCss(sheet);
2898
3039
  logger.info("css", ctx.runtime.path.resolve(outfile));
@@ -2902,14 +3043,12 @@ const cssgen = async (ctx, options) => {
2902
3043
  } else {
2903
3044
  const { files, results } = ctx.parseFiles();
2904
3045
  const done = logger.time.info(ctx.messages.buildComplete(files.length));
2905
- if (!minimal) {
2906
- ctx.appendLayerParams(sheet);
2907
- ctx.appendBaselineCss(sheet);
2908
- }
3046
+ ctx.appendLayerParams(sheet);
3047
+ ctx.appendBaselineCss(sheet);
2909
3048
  ctx.appendParserCss(sheet);
2910
- if (!minimal) pruneTokensForBuild(ctx, sheet, results);
2911
- if (!minimal && ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2912
- if (!minimal && ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3049
+ pruneTokensForBuild(ctx, sheet, results);
3050
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3051
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2913
3052
  if (splitting) await ctx.writeSplitCss(sheet);
2914
3053
  else if (outfile) {
2915
3054
  const css = ctx.getCss(sheet);
@@ -2980,8 +3119,8 @@ async function build(ctx, artifactIds) {
2980
3119
  const parsed = ctx.parseFiles();
2981
3120
  ctx.appendParserCss(sheet);
2982
3121
  pruneTokensForBuild(ctx, sheet, parsed.results);
2983
- if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2984
- if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3122
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3123
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2985
3124
  await ctx.writeCss(sheet);
2986
3125
  done(ctx.messages.buildComplete(parsed.files.length));
2987
3126
  }
@@ -3026,8 +3165,8 @@ async function generate(config, configPath) {
3026
3165
  ctx.appendBaselineCss(sheet);
3027
3166
  ctx.appendParserCss(sheet);
3028
3167
  pruneTokensForBuild(ctx, sheet, []);
3029
- if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3030
- if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3168
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3169
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3031
3170
  const css = ctx.getCss(sheet);
3032
3171
  await ctx.runtime.fs.writeFile(outfile, css);
3033
3172
  done();
@@ -3128,10 +3267,10 @@ export default defineConfig({
3128
3267
  exclude: [],
3129
3268
 
3130
3269
  // Tokens, keyframes and @property rules nothing in the emitted css reaches are dropped
3131
- // by default — worth 36-78% of a new project's stylesheet. Set \`pruneUnusedTokens: false\`
3132
- // if you read tokens from somewhere the build cannot see them — \`token()\` with a
3133
- // computed path, or a hand-written stylesheet outside \`include\` — or list those under
3134
- // \`staticCss\` to keep them.
3270
+ // by default — worth 36-78% of a new project's stylesheet. If you read tokens from
3271
+ // somewhere the build cannot see them — \`token()\` with a computed path, or a
3272
+ // hand-written stylesheet outside \`include\` — name the categories they land in with
3273
+ // \`prune: { keepTokens: ['colors.*'] }\`, or set \`prune: { tokens: 'off' }\`.
3135
3274
 
3136
3275
  // Useful for theme customization
3137
3276
  theme: {
@@ -3184,4 +3323,4 @@ async function spec(ctx, options) {
3184
3323
  return specs;
3185
3324
  }
3186
3325
  //#endregion
3187
- export { BambooContext, Builder, analyze, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
3326
+ export { BambooContext, Builder, analyze, buildInfo, codegen, cssgen, debug, generate, generatePackageExports, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/node",
3
- "version": "1.30.1",
3
+ "version": "1.32.0",
4
4
  "description": "The core css bamboo library",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
@@ -33,7 +33,6 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "browserslist": "4.28.7",
37
36
  "chokidar": "5.0.0",
38
37
  "fast-glob": "3.3.3",
39
38
  "fs-extra": "11.3.2",
@@ -42,6 +41,7 @@
42
41
  "is-glob": "4.0.3",
43
42
  "lodash.merge": "4.6.2",
44
43
  "look-it-up": "2.1.0",
44
+ "matcher": "6.0.0",
45
45
  "outdent": " ^0.8.0",
46
46
  "p-limit": "5.0.0",
47
47
  "package-manager-detector": "1.6.0",
@@ -52,18 +52,17 @@
52
52
  "postcss": "8.5.26",
53
53
  "ts-morph": "28.0.0",
54
54
  "ts-pattern": "5.9.0",
55
- "@bamboocss/config": "1.30.1",
56
- "@bamboocss/core": "1.30.1",
57
- "@bamboocss/generator": "1.30.1",
58
- "@bamboocss/logger": "1.30.1",
59
- "@bamboocss/parser": "1.30.1",
60
- "@bamboocss/plugin-lightningcss": "1.30.1",
61
- "@bamboocss/plugin-svelte": "1.30.1",
62
- "@bamboocss/plugin-vue": "1.30.1",
63
- "@bamboocss/reporter": "1.30.1",
64
- "@bamboocss/shared": "1.30.1",
65
- "@bamboocss/token-dictionary": "1.30.1",
66
- "@bamboocss/types": "1.30.1"
55
+ "@bamboocss/config": "1.32.0",
56
+ "@bamboocss/core": "1.32.0",
57
+ "@bamboocss/generator": "1.32.0",
58
+ "@bamboocss/logger": "1.32.0",
59
+ "@bamboocss/parser": "1.32.0",
60
+ "@bamboocss/plugin-svelte": "1.32.0",
61
+ "@bamboocss/plugin-vue": "1.32.0",
62
+ "@bamboocss/reporter": "1.32.0",
63
+ "@bamboocss/shared": "1.32.0",
64
+ "@bamboocss/token-dictionary": "1.32.0",
65
+ "@bamboocss/types": "1.32.0"
67
66
  },
68
67
  "devDependencies": {
69
68
  "@types/fs-extra": "11.0.4",