@bamboocss/node 1.30.0 → 1.31.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");
@@ -2083,12 +2080,17 @@ async function loadTsConfig(conf, cwd) {
2083
2080
  const RESOLVED_HOOKS_NAME = "__resolved__";
2084
2081
  /**
2085
2082
  * Built-in plugins that are auto-injected when using the CLI or PostCSS plugin.
2086
- * These provide Vue/Svelte file support and LightningCSS optimization.
2083
+ * These provide Vue/Svelte single-file-component support.
2084
+ *
2085
+ * LightningCSS is not among them any more. It was reached through a `lightningcss: true`
2086
+ * config flag whose only job was to push `pluginLightningcss()` into this list — a second
2087
+ * way to say something `plugins` already said, and the expensive one: naming the plugin
2088
+ * here meant a static import, which made `@bamboocss/plugin-lightningcss` a hard dependency
2089
+ * of this package, which put a native binary in every install whether or not the flag was
2090
+ * ever set. List the plugin yourself to use it.
2087
2091
  */
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;
2092
+ function getAutoPlugins() {
2093
+ return [(0, _bamboocss_plugin_vue.pluginVue)(), (0, _bamboocss_plugin_svelte.pluginSvelte)()];
2092
2094
  }
2093
2095
  /**
2094
2096
  * Load config and create context with auto-injected plugins.
@@ -2103,8 +2105,7 @@ async function loadConfigAndCreateContext(options = {}) {
2103
2105
  });
2104
2106
  if (config) Object.assign(conf.config, config);
2105
2107
  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);
2108
+ const autoPlugins = getAutoPlugins();
2108
2109
  conf.hooks = (0, _bamboocss_config.mergeHooks)([...autoPlugins, {
2109
2110
  name: RESOLVED_HOOKS_NAME,
2110
2111
  hooks: conf.hooks
@@ -2206,9 +2207,9 @@ function* snapshotTexts(snapshot) {
2206
2207
  //#endregion
2207
2208
  //#region src/token-accounting.ts
2208
2209
  /**
2209
- * The one decline `strict` fails the build on.
2210
+ * The one decline `prune.tokens: 'accounted'` fails the build on.
2210
2211
  *
2211
- * `strict` asserts that every token path resolves, and this is the reason that says otherwise:
2212
+ * `prune.tokens: 'accounted'` asserts that every token path resolves, and this is the reason that says otherwise:
2212
2213
  * a token binding used in a way the build cannot follow — a path built at runtime, a binding
2213
2214
  * assigned away, a namespace enumerated. It is about the author's *token usage*, and it has a
2214
2215
  * fix at the call site.
@@ -2469,14 +2470,38 @@ function unwrapAssertions(node) {
2469
2470
  * follow, and it covers the callers below that supply no `results` at all.
2470
2471
  */
2471
2472
  const TOKEN_CALL = /\btoken(?:\s*\.\s*value)?\s*\(\s*['"`]([^'"`]+)['"`]/g;
2473
+ /** An import of the generated tokens artifact, under any of the spellings that reach it. */
2474
+ const TOKEN_IMPORT = /\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2475
+ /** A call to `token()` or `token.value()`, whatever the argument is — or is not. */
2476
+ const TOKEN_CALLEE = /\btoken(\s*\.\s*value)?\s*\(/;
2477
+ /** The same, but only where the argument is a string literal — the shape `TOKEN_CALL` resolves. */
2478
+ const TOKEN_CALL_LITERAL = /\btoken(?:\s*\.\s*value)?\s*\(\s*['"`]/;
2479
+ /** String literals, contents and all. */
2480
+ const STRING_LITERAL = /'(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|`(?:[^`\\]|\\.)*`/g;
2472
2481
  /**
2473
- * A token reached from javascript at all — a call of any shape, or an import of the artifact.
2482
+ * Whether a token is reached from javascript at all — a call of any shape, or an import of the
2483
+ * artifact. Being true keeps every token declaration, so the whole of `prune.tokens` rests
2484
+ * on it.
2485
+ *
2486
+ * The awkward part is that a token reference inside a css value is now spelled `token(…)` too,
2487
+ * and it must *not* count: `css({ border: '1px solid token(colors.red.300)' })` reaches a token
2488
+ * from a stylesheet, where the css scan already accounts for it, not from javascript. Reading it
2489
+ * as a call turned pruning off wholesale — measured at 3.2x the stylesheet on a sandbox, since
2490
+ * "keep everything" is what the gate means. It was only ever latent before, because `{…}` was
2491
+ * the spelling the docs used and it looked nothing like a call.
2474
2492
  *
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.
2493
+ * So a `token(` that survives blanking every string literal is a real call, and one that does
2494
+ * not was written inside a string. The literal-argument test comes first and on the raw text,
2495
+ * which is what keeps this a superset of `TOKEN_CALL` as the coupling in `collectTokenReferences`
2496
+ * requires: a resolvable call embedded in a template literal — a fixture holding source code —
2497
+ * still counts, even though blanking would hide it.
2498
+ *
2499
+ * No `g` flag on the tests, so `test` carries no state between files.
2478
2500
  */
2479
- const REACHABLE_FROM_JS = /\btoken(\s*\.\s*value)?\s*\(|\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2501
+ const reachableFromJs = (text) => {
2502
+ if (TOKEN_IMPORT.test(text) || TOKEN_CALL_LITERAL.test(text)) return true;
2503
+ return TOKEN_CALLEE.test(text) && TOKEN_CALLEE.test(text.replace(STRING_LITERAL, "''"));
2504
+ };
2480
2505
  /**
2481
2506
  * The text of every file `include` covers — as written on disk, and, when they differ, as the
2482
2507
  * parser understands it.
@@ -2503,7 +2528,7 @@ function* sourceTexts(ctx) {
2503
2528
  * The token prune, as all three build paths need to run it.
2504
2529
  *
2505
2530
  * 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`
2531
+ * missing from a copy: a watch rebuild with `prune: { tokens: false }` skipped `pruneTokens`
2507
2532
  * altogether, so it kept `@property` registrations that a full build of the same source
2508
2533
  * strips. The other two copies carried a comment pointing at that file for the reasoning,
2509
2534
  * which is how a missing branch reads as intentional.
@@ -2514,11 +2539,13 @@ function* sourceTexts(ctx) {
2514
2539
  * a preset's whole filter and gradient set for nothing.
2515
2540
  */
2516
2541
  function pruneTokensForBuild(ctx, sheet, results) {
2517
- if (!ctx.config.pruneUnusedTokens) {
2542
+ const strategy = ctx.config.prune?.tokens ?? "reachable";
2543
+ if (strategy === "off") {
2518
2544
  ctx.pruneTokens(sheet);
2519
2545
  return;
2520
2546
  }
2521
- const strict = ctx.config.pruneUnusedTokens === "strict";
2547
+ const accounts = strategy === "accounted";
2548
+ const unresolved = accounts ? ctx.config.prune?.unresolvedPath ?? "warn" : "off";
2522
2549
  const paths = /* @__PURE__ */ new Set();
2523
2550
  const vars = /* @__PURE__ */ new Set();
2524
2551
  const accounting = {
@@ -2532,12 +2559,12 @@ function pruneTokensForBuild(ctx, sheet, results) {
2532
2559
  for (const text of snapshotTexts(snapshot)) {
2533
2560
  for (const match of text.matchAll(TOKEN_CALL)) paths.add(match[1]);
2534
2561
  for (const name of (0, _bamboocss_shared.cssVarRefs)(text)) vars.add(name);
2535
- if (!reachable && REACHABLE_FROM_JS.test(text)) reachable = true;
2562
+ if (!reachable && reachableFromJs(text)) reachable = true;
2536
2563
  }
2537
- if (strict) accountSnapshot(ctx, snapshot, accounting);
2564
+ if (accounts) accountSnapshot(ctx, snapshot, accounting);
2538
2565
  }
2539
2566
  for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
2540
- if (!strict) {
2567
+ if (!accounts) {
2541
2568
  ctx.pruneTokens(sheet, vars, reachable);
2542
2569
  return;
2543
2570
  }
@@ -2550,8 +2577,12 @@ function pruneTokensForBuild(ctx, sheet, results) {
2550
2577
  }
2551
2578
  const failing = accounting.declined.filter(failsStrict);
2552
2579
  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.`);
2580
+ if (failing.length) {
2581
+ const message = `${failing.length} token reference(s) could not be resolved.\n\n${formatDeclined(ctx, failing)}\n\n\`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, move the token into \`staticCss\`, set \`prune: { unresolvedPath: 'warn' }\` to keep the assertion without failing, or \`prune: { tokens: 'reachable' }\` to stop asserting.`;
2582
+ if (unresolved === "error") throw new _bamboocss_shared.BambooError("TOKEN_REFERENCE_UNRESOLVED", message);
2583
+ _bamboocss_logger.logger.warn("tokens:unresolved", message);
2584
+ }
2585
+ if (reported.length && unresolved !== "off") _bamboocss_logger.logger.warn("tokens:unresolved", `${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
2586
  ctx.pruneTokens(sheet, vars, accounting.declined.length > 0 && reachable);
2556
2587
  }
2557
2588
  /** The custom properties a set of token paths resolves to. */
@@ -2615,7 +2646,7 @@ const keyframeNames = (ctx) => Object.keys(ctx.config.theme?.keyframes ?? {});
2615
2646
  *
2616
2647
  * Lowercase-initial only, so a JSX component (`<Button />`) is not mistaken for an element.
2617
2648
  * That cuts the other way too — a component rendering `<button>` inside a dependency is
2618
- * invisible here, which is why `prunePreflight` is opt-in.
2649
+ * invisible here, which is why `prune.preflight` is opt-in.
2619
2650
  *
2620
2651
  * The commoner blind spot is nearer than a dependency: this reads `include`, and `include`
2621
2652
  * conventionally covers components rather than markup. An entry template — `index.html`,
@@ -2818,8 +2849,8 @@ var Builder = class {
2818
2849
  if (layerParams) ctx.appendLayerParams(sheet);
2819
2850
  ctx.appendBaselineCss(sheet);
2820
2851
  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)));
2852
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2853
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2823
2854
  return ctx.getCss(sheet);
2824
2855
  };
2825
2856
  registerDependency = (fn) => {
@@ -2907,7 +2938,7 @@ const cssgen = async (ctx, options) => {
2907
2938
  if (type) {
2908
2939
  const done = _bamboocss_logger.logger.time.info(ctx.messages.cssArtifactComplete(type));
2909
2940
  ctx.appendCssOfType(type, sheet);
2910
- if (type === "preflight" && ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2941
+ if (type === "preflight" && ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2911
2942
  if (outfile) {
2912
2943
  const css = ctx.getCss(sheet);
2913
2944
  _bamboocss_logger.logger.info("css", ctx.runtime.path.resolve(outfile));
@@ -2923,8 +2954,8 @@ const cssgen = async (ctx, options) => {
2923
2954
  }
2924
2955
  ctx.appendParserCss(sheet);
2925
2956
  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)));
2957
+ if (!minimal && ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2958
+ if (!minimal && ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2928
2959
  if (splitting) await ctx.writeSplitCss(sheet);
2929
2960
  else if (outfile) {
2930
2961
  const css = ctx.getCss(sheet);
@@ -2995,8 +3026,8 @@ async function build(ctx, artifactIds) {
2995
3026
  const parsed = ctx.parseFiles();
2996
3027
  ctx.appendParserCss(sheet);
2997
3028
  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)));
3029
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3030
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3000
3031
  await ctx.writeCss(sheet);
3001
3032
  done(ctx.messages.buildComplete(parsed.files.length));
3002
3033
  }
@@ -3041,8 +3072,8 @@ async function generate(config, configPath) {
3041
3072
  ctx.appendBaselineCss(sheet);
3042
3073
  ctx.appendParserCss(sheet);
3043
3074
  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)));
3075
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3076
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3046
3077
  const css = ctx.getCss(sheet);
3047
3078
  await ctx.runtime.fs.writeFile(outfile, css);
3048
3079
  done();
@@ -3143,7 +3174,7 @@ export default defineConfig({
3143
3174
  exclude: [],
3144
3175
 
3145
3176
  // 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\`
3177
+ // by default — worth 36-78% of a new project's stylesheet. Set \`prune: { tokens: false }\`
3147
3178
  // if you read tokens from somewhere the build cannot see them — \`token()\` with a
3148
3179
  // computed path, or a hand-written stylesheet outside \`include\` — or list those under
3149
3180
  // \`staticCss\` to keep them.
@@ -3207,6 +3238,12 @@ exports.codegen = codegen;
3207
3238
  exports.cssgen = cssgen;
3208
3239
  exports.debug = debug;
3209
3240
  exports.generate = generate;
3241
+ Object.defineProperty(exports, "generatePackageExports", {
3242
+ enumerable: true,
3243
+ get: function() {
3244
+ return _bamboocss_generator.generatePackageExports;
3245
+ }
3246
+ });
3210
3247
  exports.loadConfigAndCreateContext = loadConfigAndCreateContext;
3211
3248
  exports.parseDependency = parseDependency;
3212
3249
  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
 
@@ -225,4 +225,4 @@ interface SpecOptions {
225
225
  }
226
226
  declare function spec(ctx: BambooContext, options: SpecOptions): Promise<SpecFile[]>;
227
227
  //#endregion
228
- export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
228
+ 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";
@@ -225,4 +225,4 @@ interface SpecOptions {
225
225
  }
226
226
  declare function spec(ctx: BambooContext, options: SpecOptions): Promise<SpecFile[]>;
227
227
  //#endregion
228
- export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
228
+ 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";
@@ -2068,12 +2066,17 @@ async function loadTsConfig(conf, cwd) {
2068
2066
  const RESOLVED_HOOKS_NAME = "__resolved__";
2069
2067
  /**
2070
2068
  * Built-in plugins that are auto-injected when using the CLI or PostCSS plugin.
2071
- * These provide Vue/Svelte file support and LightningCSS optimization.
2069
+ * These provide Vue/Svelte single-file-component support.
2070
+ *
2071
+ * LightningCSS is not among them any more. It was reached through a `lightningcss: true`
2072
+ * config flag whose only job was to push `pluginLightningcss()` into this list — a second
2073
+ * way to say something `plugins` already said, and the expensive one: naming the plugin
2074
+ * here meant a static import, which made `@bamboocss/plugin-lightningcss` a hard dependency
2075
+ * of this package, which put a native binary in every install whether or not the flag was
2076
+ * ever set. List the plugin yourself to use it.
2072
2077
  */
2073
- function getAutoPlugins(config) {
2074
- const plugins = [pluginVue(), pluginSvelte()];
2075
- if (config.lightningcss) plugins.push(pluginLightningcss());
2076
- return plugins;
2078
+ function getAutoPlugins() {
2079
+ return [pluginVue(), pluginSvelte()];
2077
2080
  }
2078
2081
  /**
2079
2082
  * Load config and create context with auto-injected plugins.
@@ -2088,8 +2091,7 @@ async function loadConfigAndCreateContext(options = {}) {
2088
2091
  });
2089
2092
  if (config) Object.assign(conf.config, config);
2090
2093
  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);
2094
+ const autoPlugins = getAutoPlugins();
2093
2095
  conf.hooks = mergeHooks([...autoPlugins, {
2094
2096
  name: RESOLVED_HOOKS_NAME,
2095
2097
  hooks: conf.hooks
@@ -2191,9 +2193,9 @@ function* snapshotTexts(snapshot) {
2191
2193
  //#endregion
2192
2194
  //#region src/token-accounting.ts
2193
2195
  /**
2194
- * The one decline `strict` fails the build on.
2196
+ * The one decline `prune.tokens: 'accounted'` fails the build on.
2195
2197
  *
2196
- * `strict` asserts that every token path resolves, and this is the reason that says otherwise:
2198
+ * `prune.tokens: 'accounted'` asserts that every token path resolves, and this is the reason that says otherwise:
2197
2199
  * a token binding used in a way the build cannot follow — a path built at runtime, a binding
2198
2200
  * assigned away, a namespace enumerated. It is about the author's *token usage*, and it has a
2199
2201
  * fix at the call site.
@@ -2454,14 +2456,38 @@ function unwrapAssertions(node) {
2454
2456
  * follow, and it covers the callers below that supply no `results` at all.
2455
2457
  */
2456
2458
  const TOKEN_CALL = /\btoken(?:\s*\.\s*value)?\s*\(\s*['"`]([^'"`]+)['"`]/g;
2459
+ /** An import of the generated tokens artifact, under any of the spellings that reach it. */
2460
+ const TOKEN_IMPORT = /\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2461
+ /** A call to `token()` or `token.value()`, whatever the argument is — or is not. */
2462
+ const TOKEN_CALLEE = /\btoken(\s*\.\s*value)?\s*\(/;
2463
+ /** The same, but only where the argument is a string literal — the shape `TOKEN_CALL` resolves. */
2464
+ const TOKEN_CALL_LITERAL = /\btoken(?:\s*\.\s*value)?\s*\(\s*['"`]/;
2465
+ /** String literals, contents and all. */
2466
+ const STRING_LITERAL = /'(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|`(?:[^`\\]|\\.)*`/g;
2457
2467
  /**
2458
- * A token reached from javascript at all — a call of any shape, or an import of the artifact.
2468
+ * Whether a token is reached from javascript at all — a call of any shape, or an import of the
2469
+ * artifact. Being true keeps every token declaration, so the whole of `prune.tokens` rests
2470
+ * on it.
2471
+ *
2472
+ * The awkward part is that a token reference inside a css value is now spelled `token(…)` too,
2473
+ * and it must *not* count: `css({ border: '1px solid token(colors.red.300)' })` reaches a token
2474
+ * from a stylesheet, where the css scan already accounts for it, not from javascript. Reading it
2475
+ * as a call turned pruning off wholesale — measured at 3.2x the stylesheet on a sandbox, since
2476
+ * "keep everything" is what the gate means. It was only ever latent before, because `{…}` was
2477
+ * the spelling the docs used and it looked nothing like a call.
2478
+ *
2479
+ * So a `token(` that survives blanking every string literal is a real call, and one that does
2480
+ * not was written inside a string. The literal-argument test comes first and on the raw text,
2481
+ * which is what keeps this a superset of `TOKEN_CALL` as the coupling in `collectTokenReferences`
2482
+ * requires: a resolvable call embedded in a template literal — a fixture holding source code —
2483
+ * still counts, even though blanking would hide it.
2459
2484
  *
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.
2485
+ * No `g` flag on the tests, so `test` carries no state between files.
2463
2486
  */
2464
- const REACHABLE_FROM_JS = /\btoken(\s*\.\s*value)?\s*\(|\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2487
+ const reachableFromJs = (text) => {
2488
+ if (TOKEN_IMPORT.test(text) || TOKEN_CALL_LITERAL.test(text)) return true;
2489
+ return TOKEN_CALLEE.test(text) && TOKEN_CALLEE.test(text.replace(STRING_LITERAL, "''"));
2490
+ };
2465
2491
  /**
2466
2492
  * The text of every file `include` covers — as written on disk, and, when they differ, as the
2467
2493
  * parser understands it.
@@ -2488,7 +2514,7 @@ function* sourceTexts(ctx) {
2488
2514
  * The token prune, as all three build paths need to run it.
2489
2515
  *
2490
2516
  * 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`
2517
+ * missing from a copy: a watch rebuild with `prune: { tokens: false }` skipped `pruneTokens`
2492
2518
  * altogether, so it kept `@property` registrations that a full build of the same source
2493
2519
  * strips. The other two copies carried a comment pointing at that file for the reasoning,
2494
2520
  * which is how a missing branch reads as intentional.
@@ -2499,11 +2525,13 @@ function* sourceTexts(ctx) {
2499
2525
  * a preset's whole filter and gradient set for nothing.
2500
2526
  */
2501
2527
  function pruneTokensForBuild(ctx, sheet, results) {
2502
- if (!ctx.config.pruneUnusedTokens) {
2528
+ const strategy = ctx.config.prune?.tokens ?? "reachable";
2529
+ if (strategy === "off") {
2503
2530
  ctx.pruneTokens(sheet);
2504
2531
  return;
2505
2532
  }
2506
- const strict = ctx.config.pruneUnusedTokens === "strict";
2533
+ const accounts = strategy === "accounted";
2534
+ const unresolved = accounts ? ctx.config.prune?.unresolvedPath ?? "warn" : "off";
2507
2535
  const paths = /* @__PURE__ */ new Set();
2508
2536
  const vars = /* @__PURE__ */ new Set();
2509
2537
  const accounting = {
@@ -2517,12 +2545,12 @@ function pruneTokensForBuild(ctx, sheet, results) {
2517
2545
  for (const text of snapshotTexts(snapshot)) {
2518
2546
  for (const match of text.matchAll(TOKEN_CALL)) paths.add(match[1]);
2519
2547
  for (const name of cssVarRefs(text)) vars.add(name);
2520
- if (!reachable && REACHABLE_FROM_JS.test(text)) reachable = true;
2548
+ if (!reachable && reachableFromJs(text)) reachable = true;
2521
2549
  }
2522
- if (strict) accountSnapshot(ctx, snapshot, accounting);
2550
+ if (accounts) accountSnapshot(ctx, snapshot, accounting);
2523
2551
  }
2524
2552
  for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
2525
- if (!strict) {
2553
+ if (!accounts) {
2526
2554
  ctx.pruneTokens(sheet, vars, reachable);
2527
2555
  return;
2528
2556
  }
@@ -2535,8 +2563,12 @@ function pruneTokensForBuild(ctx, sheet, results) {
2535
2563
  }
2536
2564
  const failing = accounting.declined.filter(failsStrict);
2537
2565
  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.`);
2566
+ if (failing.length) {
2567
+ const message = `${failing.length} token reference(s) could not be resolved.\n\n${formatDeclined(ctx, failing)}\n\n\`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, move the token into \`staticCss\`, set \`prune: { unresolvedPath: 'warn' }\` to keep the assertion without failing, or \`prune: { tokens: 'reachable' }\` to stop asserting.`;
2568
+ if (unresolved === "error") throw new BambooError("TOKEN_REFERENCE_UNRESOLVED", message);
2569
+ logger.warn("tokens:unresolved", message);
2570
+ }
2571
+ if (reported.length && unresolved !== "off") logger.warn("tokens:unresolved", `${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
2572
  ctx.pruneTokens(sheet, vars, accounting.declined.length > 0 && reachable);
2541
2573
  }
2542
2574
  /** The custom properties a set of token paths resolves to. */
@@ -2600,7 +2632,7 @@ const keyframeNames = (ctx) => Object.keys(ctx.config.theme?.keyframes ?? {});
2600
2632
  *
2601
2633
  * Lowercase-initial only, so a JSX component (`<Button />`) is not mistaken for an element.
2602
2634
  * That cuts the other way too — a component rendering `<button>` inside a dependency is
2603
- * invisible here, which is why `prunePreflight` is opt-in.
2635
+ * invisible here, which is why `prune.preflight` is opt-in.
2604
2636
  *
2605
2637
  * The commoner blind spot is nearer than a dependency: this reads `include`, and `include`
2606
2638
  * conventionally covers components rather than markup. An entry template — `index.html`,
@@ -2803,8 +2835,8 @@ var Builder = class {
2803
2835
  if (layerParams) ctx.appendLayerParams(sheet);
2804
2836
  ctx.appendBaselineCss(sheet);
2805
2837
  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)));
2838
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2839
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2808
2840
  return ctx.getCss(sheet);
2809
2841
  };
2810
2842
  registerDependency = (fn) => {
@@ -2892,7 +2924,7 @@ const cssgen = async (ctx, options) => {
2892
2924
  if (type) {
2893
2925
  const done = logger.time.info(ctx.messages.cssArtifactComplete(type));
2894
2926
  ctx.appendCssOfType(type, sheet);
2895
- if (type === "preflight" && ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2927
+ if (type === "preflight" && ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2896
2928
  if (outfile) {
2897
2929
  const css = ctx.getCss(sheet);
2898
2930
  logger.info("css", ctx.runtime.path.resolve(outfile));
@@ -2908,8 +2940,8 @@ const cssgen = async (ctx, options) => {
2908
2940
  }
2909
2941
  ctx.appendParserCss(sheet);
2910
2942
  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)));
2943
+ if (!minimal && ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2944
+ if (!minimal && ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2913
2945
  if (splitting) await ctx.writeSplitCss(sheet);
2914
2946
  else if (outfile) {
2915
2947
  const css = ctx.getCss(sheet);
@@ -2980,8 +3012,8 @@ async function build(ctx, artifactIds) {
2980
3012
  const parsed = ctx.parseFiles();
2981
3013
  ctx.appendParserCss(sheet);
2982
3014
  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)));
3015
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3016
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2985
3017
  await ctx.writeCss(sheet);
2986
3018
  done(ctx.messages.buildComplete(parsed.files.length));
2987
3019
  }
@@ -3026,8 +3058,8 @@ async function generate(config, configPath) {
3026
3058
  ctx.appendBaselineCss(sheet);
3027
3059
  ctx.appendParserCss(sheet);
3028
3060
  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)));
3061
+ if (ctx.config.prune?.preflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
3062
+ if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
3031
3063
  const css = ctx.getCss(sheet);
3032
3064
  await ctx.runtime.fs.writeFile(outfile, css);
3033
3065
  done();
@@ -3128,7 +3160,7 @@ export default defineConfig({
3128
3160
  exclude: [],
3129
3161
 
3130
3162
  // 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\`
3163
+ // by default — worth 36-78% of a new project's stylesheet. Set \`prune: { tokens: false }\`
3132
3164
  // if you read tokens from somewhere the build cannot see them — \`token()\` with a
3133
3165
  // computed path, or a hand-written stylesheet outside \`include\` — or list those under
3134
3166
  // \`staticCss\` to keep them.
@@ -3184,4 +3216,4 @@ async function spec(ctx, options) {
3184
3216
  return specs;
3185
3217
  }
3186
3218
  //#endregion
3187
- export { BambooContext, Builder, analyze, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
3219
+ export { BambooContext, Builder, analyze, buildInfo, codegen, cssgen, debug, generate, generatePackageExports, loadConfigAndCreateContext, parseDependency, setLogStream, setupConfig, setupGitIgnore, setupPostcss, spec, startProfiling };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@bamboocss/node",
3
- "version": "1.30.0",
3
+ "version": "1.31.0",
4
4
  "description": "The core css bamboo library",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
7
7
  "author": "Gajus Kuizinas <gajus@gajus.com>",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/bamboocss/bamboo.git",
10
+ "url": "git+https://github.com/gajus/bamboocss.git",
11
11
  "directory": "packages/node"
12
12
  },
13
13
  "files": [
@@ -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",
@@ -52,18 +51,17 @@
52
51
  "postcss": "8.5.26",
53
52
  "ts-morph": "28.0.0",
54
53
  "ts-pattern": "5.9.0",
55
- "@bamboocss/config": "1.30.0",
56
- "@bamboocss/core": "1.30.0",
57
- "@bamboocss/generator": "1.30.0",
58
- "@bamboocss/logger": "1.30.0",
59
- "@bamboocss/parser": "1.30.0",
60
- "@bamboocss/plugin-lightningcss": "1.30.0",
61
- "@bamboocss/plugin-svelte": "1.30.0",
62
- "@bamboocss/plugin-vue": "1.30.0",
63
- "@bamboocss/reporter": "1.30.0",
64
- "@bamboocss/shared": "1.30.0",
65
- "@bamboocss/token-dictionary": "1.30.0",
66
- "@bamboocss/types": "1.30.0"
54
+ "@bamboocss/config": "1.31.0",
55
+ "@bamboocss/core": "1.31.0",
56
+ "@bamboocss/generator": "1.31.0",
57
+ "@bamboocss/logger": "1.31.0",
58
+ "@bamboocss/parser": "1.31.0",
59
+ "@bamboocss/plugin-svelte": "1.31.0",
60
+ "@bamboocss/plugin-vue": "1.31.0",
61
+ "@bamboocss/reporter": "1.31.0",
62
+ "@bamboocss/shared": "1.31.0",
63
+ "@bamboocss/token-dictionary": "1.31.0",
64
+ "@bamboocss/types": "1.31.0"
67
65
  },
68
66
  "devDependencies": {
69
67
  "@types/fs-extra": "11.0.4",