@bamboocss/node 1.43.0 → 1.44.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 +168 -19
- package/dist/index.mjs +168 -19
- package/package.json +12 -12
package/dist/index.cjs
CHANGED
|
@@ -1862,7 +1862,7 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
1862
1862
|
file,
|
|
1863
1863
|
call
|
|
1864
1864
|
})));
|
|
1865
|
-
const detail = (0, _bamboocss_shared.truncateList)(Array.from((0, _bamboocss_shared.groupBy)(occurrences, ({ call }) => `${call.entrypoint}
|
|
1865
|
+
const detail = (0, _bamboocss_shared.truncateList)(Array.from((0, _bamboocss_shared.groupBy)(occurrences, ({ call }) => `${call.entrypoint}\0${call.mod}\0${call.name}\0${call.alias}`), ([, group]) => {
|
|
1866
1866
|
const { call } = group[0];
|
|
1867
1867
|
const named = call.alias === call.name ? `\`${call.name}\`` : `\`${call.name}\` (called as \`${call.alias}\`)`;
|
|
1868
1868
|
const files = (0, _bamboocss_shared.uniq)(group.map(({ file }) => this.relative(file)));
|
|
@@ -2409,9 +2409,9 @@ function* snapshotTexts(snapshot) {
|
|
|
2409
2409
|
//#endregion
|
|
2410
2410
|
//#region src/token-accounting.ts
|
|
2411
2411
|
/**
|
|
2412
|
-
* The one decline `prune.
|
|
2412
|
+
* The one decline `prune.unresolvedPath: 'error'` fails the build on.
|
|
2413
2413
|
*
|
|
2414
|
-
*
|
|
2414
|
+
* That setting asserts that every token path resolves, and this is the reason that says otherwise:
|
|
2415
2415
|
* a token binding used in a way the build cannot follow — a path built at runtime, a binding
|
|
2416
2416
|
* assigned away, a namespace enumerated. It is about the author's *token usage*, and it has a
|
|
2417
2417
|
* fix at the call site.
|
|
@@ -2436,7 +2436,7 @@ function accountSnapshot(ctx, snapshot, accounting) {
|
|
|
2436
2436
|
const { filePath, onDisk, parsed, sourceFile } = snapshot;
|
|
2437
2437
|
const { paths, prefixes, declined } = accounting;
|
|
2438
2438
|
if (onDisk == null || parsed == null || parsed !== onDisk) {
|
|
2439
|
-
if (!((onDisk
|
|
2439
|
+
if (!(mentionsToken(ctx, onDisk) || mentionsToken(ctx, parsed))) return;
|
|
2440
2440
|
declined.push({
|
|
2441
2441
|
filePath,
|
|
2442
2442
|
line: 1,
|
|
@@ -2445,7 +2445,7 @@ function accountSnapshot(ctx, snapshot, accounting) {
|
|
|
2445
2445
|
return;
|
|
2446
2446
|
}
|
|
2447
2447
|
if (parseErrorCount(sourceFile)) {
|
|
2448
|
-
if (!parsed
|
|
2448
|
+
if (!mentionsToken(ctx, parsed)) return;
|
|
2449
2449
|
declined.push({
|
|
2450
2450
|
filePath,
|
|
2451
2451
|
line: 1,
|
|
@@ -2453,9 +2453,40 @@ function accountSnapshot(ctx, snapshot, accounting) {
|
|
|
2453
2453
|
});
|
|
2454
2454
|
return;
|
|
2455
2455
|
}
|
|
2456
|
+
if (!mentionsToken(ctx, parsed)) return;
|
|
2456
2457
|
accountFile(ctx, sourceFile, filePath, paths, prefixes, declined);
|
|
2457
2458
|
}
|
|
2458
2459
|
/**
|
|
2460
|
+
* Whether a file is worth walking — because it can name the artifact, or because a shape in it
|
|
2461
|
+
* declines without naming one.
|
|
2462
|
+
*
|
|
2463
|
+
* The obvious half is the substring `token`, which an import of the default entrypoint, a call,
|
|
2464
|
+
* a member read and a `require` of it all put in the source. Three things defeat it, and each one
|
|
2465
|
+
* is a silent under-keep rather than a slow build, so the test errs wide:
|
|
2466
|
+
*
|
|
2467
|
+
* - **A configured entrypoint need not spell it.** `importMap: { tokens: '@acme/design' }` and a
|
|
2468
|
+
* tsconfig path mapping both make `isTokensEntrypoint` true for a specifier with no `token` in
|
|
2469
|
+
* it, so the configured modules are tested for as well.
|
|
2470
|
+
* - **An identifier may be written with unicode escapes.** An import specifier can spell the `t`
|
|
2471
|
+
* of `token` as a backslash-u escape and still bind the export, which `nameOf` resolves and
|
|
2472
|
+
* there is a test on. Both escape forms — the four-digit one and the braced one — begin with a
|
|
2473
|
+
* backslash followed by `u`, so testing for that pair catches every spelling.
|
|
2474
|
+
* - **`require()` and `import()` decline on a specifier this cannot read**, which is a statement
|
|
2475
|
+
* about the specifier rather than about tokens: `import(`./pages/${name}`)` names nothing and
|
|
2476
|
+
* declines all the same, because it *could* be the artifact. Skipping the file would drop that
|
|
2477
|
+
* decline and with it the keep it was standing in for.
|
|
2478
|
+
*
|
|
2479
|
+
* A false positive costs one identifier walk. A false negative deletes a declaration something
|
|
2480
|
+
* still asks for, so anything uncertain belongs on the walking side.
|
|
2481
|
+
*/
|
|
2482
|
+
const IMPORTING_CALL = /\b(?:require|import)\s*\(/;
|
|
2483
|
+
const mentionsToken = (ctx, text) => {
|
|
2484
|
+
if (text == null) return false;
|
|
2485
|
+
if (text.includes("token") || text.includes("\\u")) return true;
|
|
2486
|
+
if (ctx.imports.value.tokens.some((mod) => text.includes(mod))) return true;
|
|
2487
|
+
return IMPORTING_CALL.test(text);
|
|
2488
|
+
};
|
|
2489
|
+
/**
|
|
2459
2490
|
* How many syntax errors the parse produced.
|
|
2460
2491
|
*
|
|
2461
2492
|
* `parseDiagnostics` is TypeScript-internal and absent from the public `SourceFile` type, so
|
|
@@ -2525,10 +2556,16 @@ function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
|
|
|
2525
2556
|
if (!argument) continue;
|
|
2526
2557
|
if (ts_morph.Node.isStringLiteral(argument) ? isTokensEntrypoint(ctx, argument.getLiteralValue()) : true) decline(call, isRequire ? "require" : "dynamic-import");
|
|
2527
2558
|
}
|
|
2559
|
+
const shadows = shadowedScopes(sourceFile);
|
|
2528
2560
|
for (const identifier of sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.Identifier)) {
|
|
2529
2561
|
const text = nameOf(identifier);
|
|
2530
2562
|
if (!bindings.has(text) && text !== "token") continue;
|
|
2531
2563
|
const parent = identifier.getParent();
|
|
2564
|
+
if (ts_morph.Node.isExportSpecifier(parent)) {
|
|
2565
|
+
const declaration = parent.getFirstAncestorByKind(ts_morph.SyntaxKind.ExportDeclaration);
|
|
2566
|
+
if (declaration && !declaration.getModuleSpecifier()) decline(identifier, "re-exported");
|
|
2567
|
+
continue;
|
|
2568
|
+
}
|
|
2532
2569
|
if (ts_morph.Node.isPropertyAccessExpression(parent) && parent.getNameNode() === identifier) {
|
|
2533
2570
|
const object = parent.getExpression();
|
|
2534
2571
|
const objectName = ts_morph.Node.isIdentifier(object) ? object.getText() : void 0;
|
|
@@ -2536,7 +2573,8 @@ function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
|
|
|
2536
2573
|
decline(identifier, "unresolved-reference");
|
|
2537
2574
|
continue;
|
|
2538
2575
|
}
|
|
2539
|
-
if (
|
|
2576
|
+
if (isDeclarationName(identifier, parent)) continue;
|
|
2577
|
+
if (isShadowed(identifier, shadows.get(text))) continue;
|
|
2540
2578
|
const resolved = accountedPath(identifier);
|
|
2541
2579
|
if (resolved === void 0) {
|
|
2542
2580
|
decline(identifier, "unresolved-reference");
|
|
@@ -2571,6 +2609,119 @@ function usesTokenMember(sourceFile, namespace) {
|
|
|
2571
2609
|
* unequal, which let an import of the artifact's export past the checks that key on the name.
|
|
2572
2610
|
*/
|
|
2573
2611
|
const nameOf = (node) => ts_morph.Node.isIdentifier(node) ? String(node.compilerNode.escapedText) : node.getText();
|
|
2612
|
+
/** Every name a binding name binds, following object and array destructuring. */
|
|
2613
|
+
function boundNames(name, bound) {
|
|
2614
|
+
if (!name) return;
|
|
2615
|
+
if (ts_morph.Node.isIdentifier(name)) {
|
|
2616
|
+
bound(nameOf(name));
|
|
2617
|
+
return;
|
|
2618
|
+
}
|
|
2619
|
+
if (!ts_morph.Node.isObjectBindingPattern(name) && !ts_morph.Node.isArrayBindingPattern(name)) return;
|
|
2620
|
+
for (const element of name.getElements()) if (ts_morph.Node.isBindingElement(element)) boundNames(element.getNameNode(), bound);
|
|
2621
|
+
}
|
|
2622
|
+
/**
|
|
2623
|
+
* Scopes that bind a name to something which cannot be the artifact, keyed by that name.
|
|
2624
|
+
*
|
|
2625
|
+
* A parameter named `token` is not the `token` export. `items.map((token) => token.value)`
|
|
2626
|
+
* iterates token *objects* — from `@bamboocss/token-dictionary`, or from any list — and `token`
|
|
2627
|
+
* is the obvious name to reach for. The identifier walk keyed on the spelling alone, so every
|
|
2628
|
+
* read off such a parameter declined as an `unresolved-reference`, and one decline anywhere
|
|
2629
|
+
* keeps every declaration in the project.
|
|
2630
|
+
*
|
|
2631
|
+
* That is not hypothetical: on this repository's own documentation site it was 40 declines
|
|
2632
|
+
* across seven components, none of them a token call, holding a token layer of 500 declarations
|
|
2633
|
+
* where 146 are referenced. Token accounting there emitted a byte-identical
|
|
2634
|
+
* stylesheet and a wall of warnings — the feature reporting loudly that it had done nothing.
|
|
2635
|
+
*
|
|
2636
|
+
* Only the forms that *cannot* hold the artifact are collected. A parameter, a catch variable,
|
|
2637
|
+
* and a function or class declaration each bind something this file defines. A `const token = …`
|
|
2638
|
+
* in general does not — its initializer can be anything, including the artifact reached through a
|
|
2639
|
+
* barrel — so it goes on declining. Declining is free; accepting a reference whose path is never
|
|
2640
|
+
* recorded is the failure this module exists to prevent.
|
|
2641
|
+
*
|
|
2642
|
+
* The one variable form that is collected is a read off a binding already known to be local:
|
|
2643
|
+
* `const { token } = props` is whatever `props` holds, and `props` is a parameter. Rooting the
|
|
2644
|
+
* test at a local binding is what keeps `const { token } = ui` — a namespace import, which a
|
|
2645
|
+
* barrel could make the artifact — declining as before.
|
|
2646
|
+
*/
|
|
2647
|
+
function shadowedScopes(sourceFile) {
|
|
2648
|
+
const scopes = /* @__PURE__ */ new Map();
|
|
2649
|
+
const add = (name, scope) => {
|
|
2650
|
+
if (!scope) return;
|
|
2651
|
+
const existing = scopes.get(name);
|
|
2652
|
+
if (existing) existing.push(scope);
|
|
2653
|
+
else scopes.set(name, [scope]);
|
|
2654
|
+
};
|
|
2655
|
+
const variables = [];
|
|
2656
|
+
sourceFile.forEachDescendant((node) => {
|
|
2657
|
+
if (ts_morph.Node.isParameterDeclaration(node)) {
|
|
2658
|
+
const scope = node.getParent();
|
|
2659
|
+
boundNames(node.getNameNode(), (name) => add(name, scope));
|
|
2660
|
+
return;
|
|
2661
|
+
}
|
|
2662
|
+
if (ts_morph.Node.isCatchClause(node)) {
|
|
2663
|
+
boundNames(node.getVariableDeclaration()?.getNameNode(), (name) => add(name, node));
|
|
2664
|
+
return;
|
|
2665
|
+
}
|
|
2666
|
+
if (ts_morph.Node.isFunctionDeclaration(node) || ts_morph.Node.isClassDeclaration(node)) {
|
|
2667
|
+
const name = node.getNameNode();
|
|
2668
|
+
if (name) add(nameOf(name), node.getParent());
|
|
2669
|
+
return;
|
|
2670
|
+
}
|
|
2671
|
+
if (ts_morph.Node.isFunctionExpression(node) || ts_morph.Node.isClassExpression(node)) {
|
|
2672
|
+
const name = node.getNameNode();
|
|
2673
|
+
if (name) add(nameOf(name), node);
|
|
2674
|
+
return;
|
|
2675
|
+
}
|
|
2676
|
+
if (ts_morph.Node.isVariableDeclaration(node)) variables.push(node);
|
|
2677
|
+
});
|
|
2678
|
+
for (const declaration of variables) {
|
|
2679
|
+
if (!ts_morph.Node.isVariableDeclaration(declaration)) continue;
|
|
2680
|
+
const root = rootIdentifier(declaration.getInitializer());
|
|
2681
|
+
if (!root || !isShadowed(root, scopes.get(nameOf(root)))) continue;
|
|
2682
|
+
const scope = declaration.getFirstAncestor((ancestor) => ts_morph.Node.isBlock(ancestor) || ts_morph.Node.isSourceFile(ancestor) || ts_morph.Node.isModuleBlock(ancestor) || ts_morph.Node.isCaseClause(ancestor) || ts_morph.Node.isDefaultClause(ancestor) || ts_morph.Node.isForStatement(ancestor) || ts_morph.Node.isForOfStatement(ancestor) || ts_morph.Node.isForInStatement(ancestor));
|
|
2683
|
+
boundNames(declaration.getNameNode(), (name) => add(name, scope));
|
|
2684
|
+
}
|
|
2685
|
+
return scopes;
|
|
2686
|
+
}
|
|
2687
|
+
/**
|
|
2688
|
+
* The identifier an expression is rooted at, for the member reads that keep it local.
|
|
2689
|
+
*
|
|
2690
|
+
* `props`, `props.theme` and `props['theme']` all root at `props`. Anything else — a call, an
|
|
2691
|
+
* `await`, a literal — returns nothing, so the variable it initializes is not treated as local.
|
|
2692
|
+
*/
|
|
2693
|
+
function rootIdentifier(expression) {
|
|
2694
|
+
let current = expression;
|
|
2695
|
+
while (current && (ts_morph.Node.isPropertyAccessExpression(current) || ts_morph.Node.isElementAccessExpression(current))) current = current.getExpression();
|
|
2696
|
+
return current && ts_morph.Node.isIdentifier(current) ? current : void 0;
|
|
2697
|
+
}
|
|
2698
|
+
/**
|
|
2699
|
+
* Whether an identifier is the *name* of a declaration rather than a read of one.
|
|
2700
|
+
*
|
|
2701
|
+
* `interface Props { token: Token }` names a member and reads nothing, but reached
|
|
2702
|
+
* `accountedPath`, which cannot read it and so declined — and an `unresolved-reference` is the
|
|
2703
|
+
* one decline that fails a strict build. `PropertyAssignment` was already excluded for this
|
|
2704
|
+
* reason; the type and class members are the same statement about a different node.
|
|
2705
|
+
*
|
|
2706
|
+
* `ShorthandPropertyAssignment` is deliberately absent: `{ token }` names a property *and* reads
|
|
2707
|
+
* the binding, so it is a reference like any other.
|
|
2708
|
+
*/
|
|
2709
|
+
function isDeclarationName(identifier, parent) {
|
|
2710
|
+
if (ts_morph.Node.isPropertyAssignment(parent) || ts_morph.Node.isPropertySignature(parent) || ts_morph.Node.isMethodSignature(parent) || ts_morph.Node.isPropertyDeclaration(parent) || ts_morph.Node.isMethodDeclaration(parent) || ts_morph.Node.isEnumMember(parent)) return parent.getNameNode() === identifier;
|
|
2711
|
+
return false;
|
|
2712
|
+
}
|
|
2713
|
+
/**
|
|
2714
|
+
* Whether an occurrence falls inside one of the scopes that shadow its name.
|
|
2715
|
+
*
|
|
2716
|
+
* Both nodes come from the same file, so containment in the tree is containment in the source
|
|
2717
|
+
* range — which answers it without walking ancestors once per candidate scope.
|
|
2718
|
+
*/
|
|
2719
|
+
function isShadowed(identifier, scopes) {
|
|
2720
|
+
if (!scopes) return false;
|
|
2721
|
+
const start = identifier.getStart();
|
|
2722
|
+
const end = identifier.getEnd();
|
|
2723
|
+
return scopes.some((scope) => scope.getStart() <= start && end <= scope.getEnd());
|
|
2724
|
+
}
|
|
2574
2725
|
/**
|
|
2575
2726
|
* What one occurrence asks for, or `undefined` if it is not a call this can read.
|
|
2576
2727
|
*
|
|
@@ -2682,8 +2833,9 @@ const TOKEN_CALL_LITERAL = /\btoken(?:\s*\.\s*value)?\s*\(\s*['"`]/;
|
|
|
2682
2833
|
const STRING_LITERAL = /'(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|`(?:[^`\\]|\\.)*`/g;
|
|
2683
2834
|
/**
|
|
2684
2835
|
* Whether a token is reached from javascript at all — a call of any shape, or an import of the
|
|
2685
|
-
* artifact.
|
|
2686
|
-
*
|
|
2836
|
+
* artifact. It no longer decides pruning on its own: the accounting does that, and this is the
|
|
2837
|
+
* gate the *fallback* defers to when the accounting declines. A project reaching for no token at
|
|
2838
|
+
* all is one a decline cannot endanger, so it keeps nothing extra.
|
|
2687
2839
|
*
|
|
2688
2840
|
* The awkward part is that a token reference inside a css value is now spelled `token(…)` too,
|
|
2689
2841
|
* and it must *not* count: `css({ border: '1px solid token(colors.red.300)' })` reaches a token
|
|
@@ -2747,10 +2899,8 @@ function* sourceTexts(ctx) {
|
|
|
2747
2899
|
* nothing was removed from still declares everything it declared.
|
|
2748
2900
|
*/
|
|
2749
2901
|
function pruneTokensForBuild(ctx, sheet, results) {
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
const accounts = strategy === "accounted";
|
|
2753
|
-
const unresolved = accounts ? ctx.config.prune?.unresolvedPath ?? "warn" : "off";
|
|
2902
|
+
if (ctx.config.prune?.tokens === false) return ctx.pruneTokens(sheet)?.reachable ?? "all";
|
|
2903
|
+
const unresolved = ctx.config.prune?.unresolvedPath ?? "off";
|
|
2754
2904
|
const paths = /* @__PURE__ */ new Set();
|
|
2755
2905
|
const vars = /* @__PURE__ */ new Set();
|
|
2756
2906
|
const accounting = {
|
|
@@ -2766,15 +2916,14 @@ function pruneTokensForBuild(ctx, sheet, results) {
|
|
|
2766
2916
|
for (const name of (0, _bamboocss_shared.cssVarRefs)(text)) vars.add(name);
|
|
2767
2917
|
if (!reachable && reachableFromJs(text)) reachable = true;
|
|
2768
2918
|
}
|
|
2769
|
-
|
|
2919
|
+
accountSnapshot(ctx, snapshot, accounting);
|
|
2770
2920
|
}
|
|
2771
2921
|
for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
|
|
2772
2922
|
const declared = declaredKeeps(ctx);
|
|
2773
2923
|
for (const name of tokenVarsFor(ctx, declared)) vars.add(name);
|
|
2774
|
-
if (!accounts) return ctx.pruneTokens(sheet, vars, reachable)?.reachable ?? "all";
|
|
2775
2924
|
for (const name of tokenVarsFor(ctx, accounting.paths)) vars.add(name);
|
|
2776
2925
|
const bounded = (ctx.config.prune?.keepTokens?.length ?? 0) > 0;
|
|
2777
|
-
if (accounting.prefixes.size && (bounded || !accounting.declined.length)) {
|
|
2926
|
+
if (accounting.prefixes.size && (bounded || !accounting.declined.length || !reachable)) {
|
|
2778
2927
|
const prefixes = Array.from(accounting.prefixes);
|
|
2779
2928
|
const matched = [];
|
|
2780
2929
|
for (const token of ctx.tokens.allTokens) if (prefixes.some((prefix) => token.name.startsWith(prefix))) matched.push(token.name);
|
|
@@ -2785,8 +2934,8 @@ function pruneTokensForBuild(ctx, sheet, results) {
|
|
|
2785
2934
|
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.`);
|
|
2786
2935
|
if (failing.length && unresolved !== "off") {
|
|
2787
2936
|
const where = `${failing.length} token reference(s) could not be resolved.\n\n${formatDeclined(ctx, failing)}\n\n`;
|
|
2788
|
-
if (unresolved === "error") throw new _bamboocss_shared.BambooError("TOKEN_REFERENCE_UNRESOLVED", where + "`prune.
|
|
2789
|
-
_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 + "
|
|
2937
|
+
if (unresolved === "error") throw new _bamboocss_shared.BambooError("TOKEN_REFERENCE_UNRESOLVED", where + "`prune.unresolvedPath: 'error'` 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: { unresolvedPath: 'off' }` to stop asserting.");
|
|
2938
|
+
_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 + "An unfollowable path keeps every token declaration. 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: { unresolvedPath: 'off' }` to stop reporting it.");
|
|
2790
2939
|
}
|
|
2791
2940
|
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."));
|
|
2792
2941
|
return ctx.pruneTokens(sheet, vars, !bounded && accounting.declined.length > 0 && reachable)?.reachable ?? "all";
|
|
@@ -2816,7 +2965,7 @@ function declaredKeeps(ctx) {
|
|
|
2816
2965
|
const patterns = ctx.config.prune?.keepTokens;
|
|
2817
2966
|
if (!patterns?.length) return [];
|
|
2818
2967
|
const includes = patterns.filter((pattern) => !pattern.startsWith("!"));
|
|
2819
|
-
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:
|
|
2968
|
+
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: false }\` if keeping everything is the intent.`);
|
|
2820
2969
|
const matched = [];
|
|
2821
2970
|
const used = /* @__PURE__ */ new Set();
|
|
2822
2971
|
for (const token of ctx.tokens.allTokens) {
|
|
@@ -3554,7 +3703,7 @@ strictValues: ${JSON.stringify(strictValues)},\n` : ""}
|
|
|
3554
3703
|
// by default — worth 36-78% of a new project's stylesheet. If you read tokens from
|
|
3555
3704
|
// somewhere the build cannot see them — \`token()\` with a computed path, or a
|
|
3556
3705
|
// hand-written stylesheet outside \`include\` — name the categories they land in with
|
|
3557
|
-
// \`prune: { keepTokens: ['colors.*'] }\`, or set \`prune: { tokens:
|
|
3706
|
+
// \`prune: { keepTokens: ['colors.*'] }\`, or set \`prune: { tokens: false }\`.
|
|
3558
3707
|
|
|
3559
3708
|
// Useful for theme customization
|
|
3560
3709
|
theme: {
|
package/dist/index.mjs
CHANGED
|
@@ -1848,7 +1848,7 @@ var BambooContext = class extends Generator {
|
|
|
1848
1848
|
file,
|
|
1849
1849
|
call
|
|
1850
1850
|
})));
|
|
1851
|
-
const detail = truncateList(Array.from(groupBy(occurrences, ({ call }) => `${call.entrypoint}
|
|
1851
|
+
const detail = truncateList(Array.from(groupBy(occurrences, ({ call }) => `${call.entrypoint}\0${call.mod}\0${call.name}\0${call.alias}`), ([, group]) => {
|
|
1852
1852
|
const { call } = group[0];
|
|
1853
1853
|
const named = call.alias === call.name ? `\`${call.name}\`` : `\`${call.name}\` (called as \`${call.alias}\`)`;
|
|
1854
1854
|
const files = uniq(group.map(({ file }) => this.relative(file)));
|
|
@@ -2395,9 +2395,9 @@ function* snapshotTexts(snapshot) {
|
|
|
2395
2395
|
//#endregion
|
|
2396
2396
|
//#region src/token-accounting.ts
|
|
2397
2397
|
/**
|
|
2398
|
-
* The one decline `prune.
|
|
2398
|
+
* The one decline `prune.unresolvedPath: 'error'` fails the build on.
|
|
2399
2399
|
*
|
|
2400
|
-
*
|
|
2400
|
+
* That setting asserts that every token path resolves, and this is the reason that says otherwise:
|
|
2401
2401
|
* a token binding used in a way the build cannot follow — a path built at runtime, a binding
|
|
2402
2402
|
* assigned away, a namespace enumerated. It is about the author's *token usage*, and it has a
|
|
2403
2403
|
* fix at the call site.
|
|
@@ -2422,7 +2422,7 @@ function accountSnapshot(ctx, snapshot, accounting) {
|
|
|
2422
2422
|
const { filePath, onDisk, parsed, sourceFile } = snapshot;
|
|
2423
2423
|
const { paths, prefixes, declined } = accounting;
|
|
2424
2424
|
if (onDisk == null || parsed == null || parsed !== onDisk) {
|
|
2425
|
-
if (!((onDisk
|
|
2425
|
+
if (!(mentionsToken(ctx, onDisk) || mentionsToken(ctx, parsed))) return;
|
|
2426
2426
|
declined.push({
|
|
2427
2427
|
filePath,
|
|
2428
2428
|
line: 1,
|
|
@@ -2431,7 +2431,7 @@ function accountSnapshot(ctx, snapshot, accounting) {
|
|
|
2431
2431
|
return;
|
|
2432
2432
|
}
|
|
2433
2433
|
if (parseErrorCount(sourceFile)) {
|
|
2434
|
-
if (!parsed
|
|
2434
|
+
if (!mentionsToken(ctx, parsed)) return;
|
|
2435
2435
|
declined.push({
|
|
2436
2436
|
filePath,
|
|
2437
2437
|
line: 1,
|
|
@@ -2439,9 +2439,40 @@ function accountSnapshot(ctx, snapshot, accounting) {
|
|
|
2439
2439
|
});
|
|
2440
2440
|
return;
|
|
2441
2441
|
}
|
|
2442
|
+
if (!mentionsToken(ctx, parsed)) return;
|
|
2442
2443
|
accountFile(ctx, sourceFile, filePath, paths, prefixes, declined);
|
|
2443
2444
|
}
|
|
2444
2445
|
/**
|
|
2446
|
+
* Whether a file is worth walking — because it can name the artifact, or because a shape in it
|
|
2447
|
+
* declines without naming one.
|
|
2448
|
+
*
|
|
2449
|
+
* The obvious half is the substring `token`, which an import of the default entrypoint, a call,
|
|
2450
|
+
* a member read and a `require` of it all put in the source. Three things defeat it, and each one
|
|
2451
|
+
* is a silent under-keep rather than a slow build, so the test errs wide:
|
|
2452
|
+
*
|
|
2453
|
+
* - **A configured entrypoint need not spell it.** `importMap: { tokens: '@acme/design' }` and a
|
|
2454
|
+
* tsconfig path mapping both make `isTokensEntrypoint` true for a specifier with no `token` in
|
|
2455
|
+
* it, so the configured modules are tested for as well.
|
|
2456
|
+
* - **An identifier may be written with unicode escapes.** An import specifier can spell the `t`
|
|
2457
|
+
* of `token` as a backslash-u escape and still bind the export, which `nameOf` resolves and
|
|
2458
|
+
* there is a test on. Both escape forms — the four-digit one and the braced one — begin with a
|
|
2459
|
+
* backslash followed by `u`, so testing for that pair catches every spelling.
|
|
2460
|
+
* - **`require()` and `import()` decline on a specifier this cannot read**, which is a statement
|
|
2461
|
+
* about the specifier rather than about tokens: `import(`./pages/${name}`)` names nothing and
|
|
2462
|
+
* declines all the same, because it *could* be the artifact. Skipping the file would drop that
|
|
2463
|
+
* decline and with it the keep it was standing in for.
|
|
2464
|
+
*
|
|
2465
|
+
* A false positive costs one identifier walk. A false negative deletes a declaration something
|
|
2466
|
+
* still asks for, so anything uncertain belongs on the walking side.
|
|
2467
|
+
*/
|
|
2468
|
+
const IMPORTING_CALL = /\b(?:require|import)\s*\(/;
|
|
2469
|
+
const mentionsToken = (ctx, text) => {
|
|
2470
|
+
if (text == null) return false;
|
|
2471
|
+
if (text.includes("token") || text.includes("\\u")) return true;
|
|
2472
|
+
if (ctx.imports.value.tokens.some((mod) => text.includes(mod))) return true;
|
|
2473
|
+
return IMPORTING_CALL.test(text);
|
|
2474
|
+
};
|
|
2475
|
+
/**
|
|
2445
2476
|
* How many syntax errors the parse produced.
|
|
2446
2477
|
*
|
|
2447
2478
|
* `parseDiagnostics` is TypeScript-internal and absent from the public `SourceFile` type, so
|
|
@@ -2511,10 +2542,16 @@ function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
|
|
|
2511
2542
|
if (!argument) continue;
|
|
2512
2543
|
if (Node.isStringLiteral(argument) ? isTokensEntrypoint(ctx, argument.getLiteralValue()) : true) decline(call, isRequire ? "require" : "dynamic-import");
|
|
2513
2544
|
}
|
|
2545
|
+
const shadows = shadowedScopes(sourceFile);
|
|
2514
2546
|
for (const identifier of sourceFile.getDescendantsOfKind(SyntaxKind.Identifier)) {
|
|
2515
2547
|
const text = nameOf(identifier);
|
|
2516
2548
|
if (!bindings.has(text) && text !== "token") continue;
|
|
2517
2549
|
const parent = identifier.getParent();
|
|
2550
|
+
if (Node.isExportSpecifier(parent)) {
|
|
2551
|
+
const declaration = parent.getFirstAncestorByKind(SyntaxKind.ExportDeclaration);
|
|
2552
|
+
if (declaration && !declaration.getModuleSpecifier()) decline(identifier, "re-exported");
|
|
2553
|
+
continue;
|
|
2554
|
+
}
|
|
2518
2555
|
if (Node.isPropertyAccessExpression(parent) && parent.getNameNode() === identifier) {
|
|
2519
2556
|
const object = parent.getExpression();
|
|
2520
2557
|
const objectName = Node.isIdentifier(object) ? object.getText() : void 0;
|
|
@@ -2522,7 +2559,8 @@ function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
|
|
|
2522
2559
|
decline(identifier, "unresolved-reference");
|
|
2523
2560
|
continue;
|
|
2524
2561
|
}
|
|
2525
|
-
if (
|
|
2562
|
+
if (isDeclarationName(identifier, parent)) continue;
|
|
2563
|
+
if (isShadowed(identifier, shadows.get(text))) continue;
|
|
2526
2564
|
const resolved = accountedPath(identifier);
|
|
2527
2565
|
if (resolved === void 0) {
|
|
2528
2566
|
decline(identifier, "unresolved-reference");
|
|
@@ -2557,6 +2595,119 @@ function usesTokenMember(sourceFile, namespace) {
|
|
|
2557
2595
|
* unequal, which let an import of the artifact's export past the checks that key on the name.
|
|
2558
2596
|
*/
|
|
2559
2597
|
const nameOf = (node) => Node.isIdentifier(node) ? String(node.compilerNode.escapedText) : node.getText();
|
|
2598
|
+
/** Every name a binding name binds, following object and array destructuring. */
|
|
2599
|
+
function boundNames(name, bound) {
|
|
2600
|
+
if (!name) return;
|
|
2601
|
+
if (Node.isIdentifier(name)) {
|
|
2602
|
+
bound(nameOf(name));
|
|
2603
|
+
return;
|
|
2604
|
+
}
|
|
2605
|
+
if (!Node.isObjectBindingPattern(name) && !Node.isArrayBindingPattern(name)) return;
|
|
2606
|
+
for (const element of name.getElements()) if (Node.isBindingElement(element)) boundNames(element.getNameNode(), bound);
|
|
2607
|
+
}
|
|
2608
|
+
/**
|
|
2609
|
+
* Scopes that bind a name to something which cannot be the artifact, keyed by that name.
|
|
2610
|
+
*
|
|
2611
|
+
* A parameter named `token` is not the `token` export. `items.map((token) => token.value)`
|
|
2612
|
+
* iterates token *objects* — from `@bamboocss/token-dictionary`, or from any list — and `token`
|
|
2613
|
+
* is the obvious name to reach for. The identifier walk keyed on the spelling alone, so every
|
|
2614
|
+
* read off such a parameter declined as an `unresolved-reference`, and one decline anywhere
|
|
2615
|
+
* keeps every declaration in the project.
|
|
2616
|
+
*
|
|
2617
|
+
* That is not hypothetical: on this repository's own documentation site it was 40 declines
|
|
2618
|
+
* across seven components, none of them a token call, holding a token layer of 500 declarations
|
|
2619
|
+
* where 146 are referenced. Token accounting there emitted a byte-identical
|
|
2620
|
+
* stylesheet and a wall of warnings — the feature reporting loudly that it had done nothing.
|
|
2621
|
+
*
|
|
2622
|
+
* Only the forms that *cannot* hold the artifact are collected. A parameter, a catch variable,
|
|
2623
|
+
* and a function or class declaration each bind something this file defines. A `const token = …`
|
|
2624
|
+
* in general does not — its initializer can be anything, including the artifact reached through a
|
|
2625
|
+
* barrel — so it goes on declining. Declining is free; accepting a reference whose path is never
|
|
2626
|
+
* recorded is the failure this module exists to prevent.
|
|
2627
|
+
*
|
|
2628
|
+
* The one variable form that is collected is a read off a binding already known to be local:
|
|
2629
|
+
* `const { token } = props` is whatever `props` holds, and `props` is a parameter. Rooting the
|
|
2630
|
+
* test at a local binding is what keeps `const { token } = ui` — a namespace import, which a
|
|
2631
|
+
* barrel could make the artifact — declining as before.
|
|
2632
|
+
*/
|
|
2633
|
+
function shadowedScopes(sourceFile) {
|
|
2634
|
+
const scopes = /* @__PURE__ */ new Map();
|
|
2635
|
+
const add = (name, scope) => {
|
|
2636
|
+
if (!scope) return;
|
|
2637
|
+
const existing = scopes.get(name);
|
|
2638
|
+
if (existing) existing.push(scope);
|
|
2639
|
+
else scopes.set(name, [scope]);
|
|
2640
|
+
};
|
|
2641
|
+
const variables = [];
|
|
2642
|
+
sourceFile.forEachDescendant((node) => {
|
|
2643
|
+
if (Node.isParameterDeclaration(node)) {
|
|
2644
|
+
const scope = node.getParent();
|
|
2645
|
+
boundNames(node.getNameNode(), (name) => add(name, scope));
|
|
2646
|
+
return;
|
|
2647
|
+
}
|
|
2648
|
+
if (Node.isCatchClause(node)) {
|
|
2649
|
+
boundNames(node.getVariableDeclaration()?.getNameNode(), (name) => add(name, node));
|
|
2650
|
+
return;
|
|
2651
|
+
}
|
|
2652
|
+
if (Node.isFunctionDeclaration(node) || Node.isClassDeclaration(node)) {
|
|
2653
|
+
const name = node.getNameNode();
|
|
2654
|
+
if (name) add(nameOf(name), node.getParent());
|
|
2655
|
+
return;
|
|
2656
|
+
}
|
|
2657
|
+
if (Node.isFunctionExpression(node) || Node.isClassExpression(node)) {
|
|
2658
|
+
const name = node.getNameNode();
|
|
2659
|
+
if (name) add(nameOf(name), node);
|
|
2660
|
+
return;
|
|
2661
|
+
}
|
|
2662
|
+
if (Node.isVariableDeclaration(node)) variables.push(node);
|
|
2663
|
+
});
|
|
2664
|
+
for (const declaration of variables) {
|
|
2665
|
+
if (!Node.isVariableDeclaration(declaration)) continue;
|
|
2666
|
+
const root = rootIdentifier(declaration.getInitializer());
|
|
2667
|
+
if (!root || !isShadowed(root, scopes.get(nameOf(root)))) continue;
|
|
2668
|
+
const scope = declaration.getFirstAncestor((ancestor) => Node.isBlock(ancestor) || Node.isSourceFile(ancestor) || Node.isModuleBlock(ancestor) || Node.isCaseClause(ancestor) || Node.isDefaultClause(ancestor) || Node.isForStatement(ancestor) || Node.isForOfStatement(ancestor) || Node.isForInStatement(ancestor));
|
|
2669
|
+
boundNames(declaration.getNameNode(), (name) => add(name, scope));
|
|
2670
|
+
}
|
|
2671
|
+
return scopes;
|
|
2672
|
+
}
|
|
2673
|
+
/**
|
|
2674
|
+
* The identifier an expression is rooted at, for the member reads that keep it local.
|
|
2675
|
+
*
|
|
2676
|
+
* `props`, `props.theme` and `props['theme']` all root at `props`. Anything else — a call, an
|
|
2677
|
+
* `await`, a literal — returns nothing, so the variable it initializes is not treated as local.
|
|
2678
|
+
*/
|
|
2679
|
+
function rootIdentifier(expression) {
|
|
2680
|
+
let current = expression;
|
|
2681
|
+
while (current && (Node.isPropertyAccessExpression(current) || Node.isElementAccessExpression(current))) current = current.getExpression();
|
|
2682
|
+
return current && Node.isIdentifier(current) ? current : void 0;
|
|
2683
|
+
}
|
|
2684
|
+
/**
|
|
2685
|
+
* Whether an identifier is the *name* of a declaration rather than a read of one.
|
|
2686
|
+
*
|
|
2687
|
+
* `interface Props { token: Token }` names a member and reads nothing, but reached
|
|
2688
|
+
* `accountedPath`, which cannot read it and so declined — and an `unresolved-reference` is the
|
|
2689
|
+
* one decline that fails a strict build. `PropertyAssignment` was already excluded for this
|
|
2690
|
+
* reason; the type and class members are the same statement about a different node.
|
|
2691
|
+
*
|
|
2692
|
+
* `ShorthandPropertyAssignment` is deliberately absent: `{ token }` names a property *and* reads
|
|
2693
|
+
* the binding, so it is a reference like any other.
|
|
2694
|
+
*/
|
|
2695
|
+
function isDeclarationName(identifier, parent) {
|
|
2696
|
+
if (Node.isPropertyAssignment(parent) || Node.isPropertySignature(parent) || Node.isMethodSignature(parent) || Node.isPropertyDeclaration(parent) || Node.isMethodDeclaration(parent) || Node.isEnumMember(parent)) return parent.getNameNode() === identifier;
|
|
2697
|
+
return false;
|
|
2698
|
+
}
|
|
2699
|
+
/**
|
|
2700
|
+
* Whether an occurrence falls inside one of the scopes that shadow its name.
|
|
2701
|
+
*
|
|
2702
|
+
* Both nodes come from the same file, so containment in the tree is containment in the source
|
|
2703
|
+
* range — which answers it without walking ancestors once per candidate scope.
|
|
2704
|
+
*/
|
|
2705
|
+
function isShadowed(identifier, scopes) {
|
|
2706
|
+
if (!scopes) return false;
|
|
2707
|
+
const start = identifier.getStart();
|
|
2708
|
+
const end = identifier.getEnd();
|
|
2709
|
+
return scopes.some((scope) => scope.getStart() <= start && end <= scope.getEnd());
|
|
2710
|
+
}
|
|
2560
2711
|
/**
|
|
2561
2712
|
* What one occurrence asks for, or `undefined` if it is not a call this can read.
|
|
2562
2713
|
*
|
|
@@ -2668,8 +2819,9 @@ const TOKEN_CALL_LITERAL = /\btoken(?:\s*\.\s*value)?\s*\(\s*['"`]/;
|
|
|
2668
2819
|
const STRING_LITERAL = /'(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|`(?:[^`\\]|\\.)*`/g;
|
|
2669
2820
|
/**
|
|
2670
2821
|
* Whether a token is reached from javascript at all — a call of any shape, or an import of the
|
|
2671
|
-
* artifact.
|
|
2672
|
-
*
|
|
2822
|
+
* artifact. It no longer decides pruning on its own: the accounting does that, and this is the
|
|
2823
|
+
* gate the *fallback* defers to when the accounting declines. A project reaching for no token at
|
|
2824
|
+
* all is one a decline cannot endanger, so it keeps nothing extra.
|
|
2673
2825
|
*
|
|
2674
2826
|
* The awkward part is that a token reference inside a css value is now spelled `token(…)` too,
|
|
2675
2827
|
* and it must *not* count: `css({ border: '1px solid token(colors.red.300)' })` reaches a token
|
|
@@ -2733,10 +2885,8 @@ function* sourceTexts(ctx) {
|
|
|
2733
2885
|
* nothing was removed from still declares everything it declared.
|
|
2734
2886
|
*/
|
|
2735
2887
|
function pruneTokensForBuild(ctx, sheet, results) {
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
const accounts = strategy === "accounted";
|
|
2739
|
-
const unresolved = accounts ? ctx.config.prune?.unresolvedPath ?? "warn" : "off";
|
|
2888
|
+
if (ctx.config.prune?.tokens === false) return ctx.pruneTokens(sheet)?.reachable ?? "all";
|
|
2889
|
+
const unresolved = ctx.config.prune?.unresolvedPath ?? "off";
|
|
2740
2890
|
const paths = /* @__PURE__ */ new Set();
|
|
2741
2891
|
const vars = /* @__PURE__ */ new Set();
|
|
2742
2892
|
const accounting = {
|
|
@@ -2752,15 +2902,14 @@ function pruneTokensForBuild(ctx, sheet, results) {
|
|
|
2752
2902
|
for (const name of cssVarRefs(text)) vars.add(name);
|
|
2753
2903
|
if (!reachable && reachableFromJs(text)) reachable = true;
|
|
2754
2904
|
}
|
|
2755
|
-
|
|
2905
|
+
accountSnapshot(ctx, snapshot, accounting);
|
|
2756
2906
|
}
|
|
2757
2907
|
for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
|
|
2758
2908
|
const declared = declaredKeeps(ctx);
|
|
2759
2909
|
for (const name of tokenVarsFor(ctx, declared)) vars.add(name);
|
|
2760
|
-
if (!accounts) return ctx.pruneTokens(sheet, vars, reachable)?.reachable ?? "all";
|
|
2761
2910
|
for (const name of tokenVarsFor(ctx, accounting.paths)) vars.add(name);
|
|
2762
2911
|
const bounded = (ctx.config.prune?.keepTokens?.length ?? 0) > 0;
|
|
2763
|
-
if (accounting.prefixes.size && (bounded || !accounting.declined.length)) {
|
|
2912
|
+
if (accounting.prefixes.size && (bounded || !accounting.declined.length || !reachable)) {
|
|
2764
2913
|
const prefixes = Array.from(accounting.prefixes);
|
|
2765
2914
|
const matched = [];
|
|
2766
2915
|
for (const token of ctx.tokens.allTokens) if (prefixes.some((prefix) => token.name.startsWith(prefix))) matched.push(token.name);
|
|
@@ -2771,8 +2920,8 @@ function pruneTokensForBuild(ctx, sheet, results) {
|
|
|
2771
2920
|
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.`);
|
|
2772
2921
|
if (failing.length && unresolved !== "off") {
|
|
2773
2922
|
const where = `${failing.length} token reference(s) could not be resolved.\n\n${formatDeclined(ctx, failing)}\n\n`;
|
|
2774
|
-
if (unresolved === "error") throw new BambooError("TOKEN_REFERENCE_UNRESOLVED", where + "`prune.
|
|
2775
|
-
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 + "
|
|
2923
|
+
if (unresolved === "error") throw new BambooError("TOKEN_REFERENCE_UNRESOLVED", where + "`prune.unresolvedPath: 'error'` 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: { unresolvedPath: 'off' }` to stop asserting.");
|
|
2924
|
+
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 + "An unfollowable path keeps every token declaration. 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: { unresolvedPath: 'off' }` to stop reporting it.");
|
|
2776
2925
|
}
|
|
2777
2926
|
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."));
|
|
2778
2927
|
return ctx.pruneTokens(sheet, vars, !bounded && accounting.declined.length > 0 && reachable)?.reachable ?? "all";
|
|
@@ -2802,7 +2951,7 @@ function declaredKeeps(ctx) {
|
|
|
2802
2951
|
const patterns = ctx.config.prune?.keepTokens;
|
|
2803
2952
|
if (!patterns?.length) return [];
|
|
2804
2953
|
const includes = patterns.filter((pattern) => !pattern.startsWith("!"));
|
|
2805
|
-
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:
|
|
2954
|
+
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: false }\` if keeping everything is the intent.`);
|
|
2806
2955
|
const matched = [];
|
|
2807
2956
|
const used = /* @__PURE__ */ new Set();
|
|
2808
2957
|
for (const token of ctx.tokens.allTokens) {
|
|
@@ -3540,7 +3689,7 @@ strictValues: ${JSON.stringify(strictValues)},\n` : ""}
|
|
|
3540
3689
|
// by default — worth 36-78% of a new project's stylesheet. If you read tokens from
|
|
3541
3690
|
// somewhere the build cannot see them — \`token()\` with a computed path, or a
|
|
3542
3691
|
// hand-written stylesheet outside \`include\` — name the categories they land in with
|
|
3543
|
-
// \`prune: { keepTokens: ['colors.*'] }\`, or set \`prune: { tokens:
|
|
3692
|
+
// \`prune: { keepTokens: ['colors.*'] }\`, or set \`prune: { tokens: false }\`.
|
|
3544
3693
|
|
|
3545
3694
|
// Useful for theme customization
|
|
3546
3695
|
theme: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.44.0",
|
|
4
4
|
"description": "The core css bamboo library",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,17 +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.
|
|
56
|
-
"@bamboocss/core": "1.
|
|
57
|
-
"@bamboocss/generator": "1.
|
|
58
|
-
"@bamboocss/logger": "1.
|
|
59
|
-
"@bamboocss/parser": "1.
|
|
60
|
-
"@bamboocss/plugin-svelte": "1.
|
|
61
|
-
"@bamboocss/plugin-vue": "1.
|
|
62
|
-
"@bamboocss/reporter": "1.
|
|
63
|
-
"@bamboocss/shared": "1.
|
|
64
|
-
"@bamboocss/token-dictionary": "1.
|
|
65
|
-
"@bamboocss/types": "1.
|
|
55
|
+
"@bamboocss/config": "1.44.0",
|
|
56
|
+
"@bamboocss/core": "1.44.0",
|
|
57
|
+
"@bamboocss/generator": "1.44.0",
|
|
58
|
+
"@bamboocss/logger": "1.44.0",
|
|
59
|
+
"@bamboocss/parser": "1.44.0",
|
|
60
|
+
"@bamboocss/plugin-svelte": "1.44.0",
|
|
61
|
+
"@bamboocss/plugin-vue": "1.44.0",
|
|
62
|
+
"@bamboocss/reporter": "1.44.0",
|
|
63
|
+
"@bamboocss/shared": "1.44.0",
|
|
64
|
+
"@bamboocss/token-dictionary": "1.44.0",
|
|
65
|
+
"@bamboocss/types": "1.44.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/fs-extra": "11.0.4",
|