@bamboocss/node 1.28.0 → 1.29.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.
Files changed (4) hide show
  1. package/README.md +33 -197
  2. package/dist/index.cjs +336 -95
  3. package/dist/index.mjs +336 -95
  4. package/package.json +13 -13
package/README.md CHANGED
@@ -1,208 +1,44 @@
1
- ## Folder structure
1
+ # @bamboocss/node
2
2
 
3
- - `.bamboo`
4
- - `tokens` (index.js, index.d.ts, index.css)
5
- - `styled-system` (index.js, index.d.ts)
6
- - `package.json`
3
+ The Node runtime behind Bamboo CSS: config loading, context creation, extraction and the write side of codegen and
4
+ `styles.css`.
7
5
 
8
- ```js
9
- const tokens = {
10
- 'colors.red.400': { value: '...', variable: '...' },
11
- }
6
+ This is an internal package. It is what `@bamboocss/dev` (the CLI), `@bamboocss/postcss` and `@bamboocss/vite` are built
7
+ on, and it is versioned with them — most projects should install one of those instead. User-facing documentation lives
8
+ at [bamboocss.com/docs](https://bamboocss.com/docs).
12
9
 
13
- const tokenMap = {
14
- colors: [{ group: 'red', key: 'red.400', value: '...' }],
15
- fonts: [],
16
- }
10
+ ## Exports
17
11
 
18
- function getToken(path) {
19
- const { value } = tokens[path] || {}
20
- return value
21
- }
12
+ Everything below is exported from `@bamboocss/node`.
22
13
 
23
- function getTokenVar(path) {
24
- const { variable } = tokens[path] || {}
25
- return variable
26
- }
27
- ```
14
+ ### Context
28
15
 
29
- ```js
30
- import { generateCssVar, generateDts, generateJs } from '@bamboocss/generator'
31
- import { createTokenMap } from '@bamboocss/token-dictionary'
16
+ - `loadConfigAndCreateContext({ cwd?, config?, configPath? })` – resolve the config file, merge presets and inline
17
+ overrides, auto-inject the built-in plugins (`vue`, `svelte`, `lightningcss`), and return a `BambooContext`.
18
+ - `BambooContext` – the resolved config plus everything derived from it: tokens, utilities, conditions, recipes,
19
+ patterns, the `ts-morph` project, the output engine and the diff engine.
20
+ - `Builder` – the incremental driver the bundler plugins use. It owns context setup, tracks which files and config
21
+ dependencies changed, re-extracts only those, and hands back the stylesheet (`toCss`) or writes it into a PostCSS root
22
+ (`write`).
32
23
 
33
- const conf = new Conf()
24
+ ### Commands
34
25
 
35
- const dict = createTokenMap(config)
26
+ Each takes a `BambooContext`, and each backs the CLI command of the same name.
36
27
 
37
- const cssVars = generateCssVar(dict, { root: ':root' })
38
- const dts = generateDts(dict)
39
- const files = generateJs(dict, { formats: ['esm', 'cjs'] })
40
- ```
28
+ - `generate(config, configPath?)` – the full build, including `--watch`. Unlike the rest, it creates its own context.
29
+ - `codegen(ctx, ids?)` – write the generated `styled-system` artifacts.
30
+ - `cssgen(ctx, options)` – write the stylesheet.
31
+ - `analyze(ctx, options?)` – report token and recipe usage.
32
+ - `debug(ctx, options)` – write the resolved config, per-file AST and per-file CSS.
33
+ - `buildInfo(ctx, outfile)` – write the static extraction result as JSON, for consumers that ship it instead of source.
34
+ - `spec(ctx, options)` – write the spec files.
41
35
 
42
- ```json
43
- {
44
- "name": "dot-bamboo",
45
- "description": "...",
46
- "exports": {
47
- "./tokens": {
48
- "import": "./generated/tokens/index.mjs"
49
- },
50
- "./css": {
51
- "import": "./generated/css/index.mjs"
52
- }
53
- },
54
- "typeVersions": {
55
- "*": {
56
- "tokens": ["./generated/tokens"],
57
- "css": ["./generated/css"]
58
- }
59
- }
60
- }
61
- ```
36
+ ### Setup and utilities
62
37
 
63
- ```js
64
- import { definePackage, writePackage } from '@bamboocss/generators'
65
-
66
- const pkg = setupPackage({
67
- name: 'dot-bamboo',
68
- description: '...',
69
- dir: 'generated',
70
- exports: ['tokens', 'css'],
71
- })
72
-
73
- writePackage(pkg)
74
-
75
- updateTsConfig({
76
- compilerOptions: {
77
- paths: {
78
- 'design-system': ['./.bamboo'],
79
- },
80
- },
81
- })
82
-
83
- updateGitIgnore({ comment: '# Bamboo', path: '.@bamboocss/dev' })
84
- ```
85
-
86
- ```ts
87
- type ConditionType =
88
- | 'color-scheme'
89
- | 'resolution'
90
- | 'writing-mode'
91
- | 'pseudo'
92
- | 'selector'
93
- | 'viewport'
94
- | 'interaction-media'
95
- | 'reduced-motion'
96
- | 'reduced-data'
97
- | 'reduced-transparent'
98
- | 'contrast'
99
-
100
- const conditions = {
101
- dark: {
102
- type: 'color-scheme',
103
- value: '[data-theme=dark]',
104
- colorScheme: 'dark',
105
- },
106
- darkDimmed: {
107
- type: 'color-scheme',
108
- value: '[data-theme=dark_dimmed]',
109
- colorScheme: 'dark',
110
- },
111
- ltr: {
112
- type: 'dir',
113
- value: '[dir=rtl]',
114
- },
115
- rtl: {
116
- type: 'dir',
117
- value: '[dir=rtl]',
118
- },
119
- hover: {
120
- type: 'pseudo',
121
- value: '&:hover',
122
- },
123
- focus: {
124
- type: 'pseudo',
125
- value: '&:focus',
126
- },
127
- sm: {
128
- type: 'viewport',
129
- value: '@media (min-width: 480px)',
130
- },
131
- }
132
- ```
133
-
134
- ```ts
135
- const defaults = {
136
- className: ({ prop, value }) => `${prop}-${esc(value)}`,
137
- }
138
-
139
- const tt = defineConfig({
140
- utilities: [
141
- {
142
- properties: {
143
- display: {
144
- className: ({ value }) => `d-${value}`,
145
- transform(value) {
146
- return { display: value }
147
- },
148
- values: {
149
- fl: 'flex',
150
- ib: 'inline-block',
151
- },
152
- },
153
- background: {
154
- className: ({ prop, value }) => `bg-${value}`,
155
- values: ({ tokens }) => ({
156
- ...tokens.colors,
157
- inherit: 'inherit',
158
- }),
159
- },
160
- color: {
161
- className: ({ prop, value }) => `text-${value}`,
162
- values: (tokens) => ({ ...tokens.colors }),
163
- },
164
- fill: { values: 'colors' },
165
- lineClamp: {
166
- className: ({ prop, value }) => `clamp-${value}`,
167
- values: {
168
- '1': {
169
- '--line-clamp': '1',
170
- },
171
- },
172
- },
173
- },
174
- shorthands: {
175
- bg: 'background',
176
- },
177
- },
178
-
179
- {
180
- properties: {
181
- strokeWidth: {
182
- values: { '1': '1px', 2: '2px' },
183
- },
184
- },
185
- },
186
-
187
- {
188
- properties: {
189
- paddingLeft: { values: 'space', className: 'pl' },
190
- paddingRight: { values: 'space', className: 'pr' },
191
- paddingX: {
192
- className: 'px',
193
- values({ theme, map }) {
194
- return map(theme.space, (value) => ({
195
- paddingLeft: value,
196
- paddingRight: value,
197
- }))
198
- },
199
- },
200
- },
201
- shorthands: {
202
- pl: 'paddingLeft',
203
- px: 'paddingX',
204
- },
205
- },
206
- ],
207
- })
208
- ```
38
+ - `setupConfig(cwd, options?)` / `setupPostcss(cwd)` – scaffold `bamboo.config.ts` and the PostCSS config.
39
+ - `setupGitIgnore(ctx)` – add the outdir to `.gitignore`, unless `config.gitignore` is off.
40
+ - `parseDependency(fileOrGlob)` – turn a `config.dependencies` entry into a PostCSS `dependency` or `dir-dependency`
41
+ message.
42
+ - `setLogStream({ cwd, logfile })` – tee logs to a file.
43
+ - `startProfiling(cwd, prefix, isWatching?)` – start a V8 CPU profile; the returned function stops it and writes
44
+ `bamboo-{prefix}-{timestamp}.cpuprofile` into `cwd`.
package/dist/index.cjs CHANGED
@@ -59,6 +59,8 @@ let is_glob = require("is-glob");
59
59
  is_glob = __toESM(is_glob);
60
60
  let glob_parent = require("glob-parent");
61
61
  glob_parent = __toESM(glob_parent);
62
+ let _bamboocss_config_ts_path = require("@bamboocss/config/ts-path");
63
+ let ts_morph = require("ts-morph");
62
64
  let node_readline = require("node:readline");
63
65
  node_readline = __toESM(node_readline);
64
66
  let look_it_up = require("look-it-up");
@@ -1455,6 +1457,25 @@ function globDirname(globs) {
1455
1457
  }
1456
1458
  //#endregion
1457
1459
  //#region src/node-runtime.ts
1460
+ /**
1461
+ * What the source glob ignores.
1462
+ *
1463
+ * `**\/*.d.ts` is unconditional. It used to be a *default* that a user's own `exclude`
1464
+ * replaced, so declaration files were scanned by whether the project happened to set that
1465
+ * option at all — excluded for `exclude: []`, included for `exclude: ['**\/*.stories.tsx']`.
1466
+ * Nothing chose that; the default was simply appended when nothing else was there.
1467
+ *
1468
+ * A declaration file carries no runtime code and can emit no styles. It is still read by the
1469
+ * reference scans, which are deliberately over-inclusive, so scanning one could keep a token
1470
+ * named in a doc comment or a reset rule for an element named in a JSDoc example. Those are
1471
+ * spurious keeps rather than a guarantee anyone relied on — and they were never available to
1472
+ * the projects on the other side of the same condition.
1473
+ *
1474
+ * Copied rather than appended to. `opts.exclude` is `ctx.config.exclude` itself, so pushing
1475
+ * onto it edited the user's resolved config in place, and the next call then saw a list it had
1476
+ * mutated.
1477
+ */
1478
+ const globIgnore = (exclude) => ["**/*.d.ts", ...exclude ?? []];
1458
1479
  const nodeRuntime = {
1459
1480
  cwd() {
1460
1481
  return process.cwd();
@@ -1481,11 +1502,9 @@ const nodeRuntime = {
1481
1502
  },
1482
1503
  glob(opts) {
1483
1504
  if (!opts.include) return [];
1484
- const ignore = opts.exclude ?? [];
1485
- if (!ignore.length) ignore.push("**/*.d.ts");
1486
1505
  return fast_glob.default.sync(opts.include, {
1487
1506
  cwd: opts.cwd,
1488
- ignore,
1507
+ ignore: globIgnore(opts.exclude),
1489
1508
  absolute: true
1490
1509
  });
1491
1510
  },
@@ -2114,15 +2133,258 @@ function parseDependency(fileOrGlob) {
2114
2133
  return message;
2115
2134
  }
2116
2135
  //#endregion
2136
+ //#region src/source-snapshots.ts
2137
+ /**
2138
+ * Every file `include` covers, read once.
2139
+ *
2140
+ * The scans that decide what survives pruning — the token reference set, the reachability
2141
+ * gate, the strict accounting — all want the same two copies of the same files, and each used
2142
+ * to fetch them itself. A strict build therefore read every file three times over: once to
2143
+ * collect references, once to account, and once more for the gate whenever the accounting
2144
+ * declined. Yielding a snapshot lets one walk feed all of them.
2145
+ *
2146
+ * Both copies, because neither alone is complete and the text scans are safe when over-fed. A
2147
+ * file the parser transformed is stored rewritten (`parseSourceFile` calls `replaceWithText`),
2148
+ * and those transforms lose things the scans want: `svelteToTsx` and `vueToTsx` each swallow a
2149
+ * throw and return an empty string, and a Vue SFC with a render function and no `<template>`
2150
+ * becomes the literal `<template>undefined</template>`. Read only the parsed copy and a file
2151
+ * like that reports no tokens and no elements at all.
2152
+ *
2153
+ * The parsed copy still has to be read as well, because `parser:before` is the documented way
2154
+ * to teach bamboo a format it does not know. A template compiled to jsx by such a hook holds
2155
+ * nothing a scan of the raw file would recognise, and that is the hook working as intended.
2156
+ */
2157
+ function* sourceSnapshots(ctx) {
2158
+ for (const file of ctx.getFiles()) {
2159
+ const filePath = ctx.runtime.path.abs(ctx.config.cwd, file);
2160
+ let onDisk;
2161
+ try {
2162
+ onDisk = ctx.runtime.fs.readFileSync(filePath);
2163
+ } catch {
2164
+ onDisk = void 0;
2165
+ }
2166
+ const sourceFile = ctx.project.getSourceFile(filePath);
2167
+ yield {
2168
+ filePath,
2169
+ onDisk,
2170
+ parsed: sourceFile?.getFullText(),
2171
+ sourceFile
2172
+ };
2173
+ }
2174
+ }
2175
+ /**
2176
+ * The distinct texts a snapshot carries.
2177
+ *
2178
+ * One when the parser holds the file as written, two when a transform rewrote it. Every
2179
+ * textual scan wants both, and wants neither twice.
2180
+ */
2181
+ function* snapshotTexts(snapshot) {
2182
+ const { onDisk, parsed } = snapshot;
2183
+ if (onDisk != null) yield onDisk;
2184
+ if (parsed != null && parsed !== onDisk) yield parsed;
2185
+ }
2186
+ //#endregion
2187
+ //#region src/token-accounting.ts
2188
+ /**
2189
+ * One file's contribution, split out so the build can account and scan in a single walk.
2190
+ *
2191
+ * `pruneTokensForBuild` needs the keep set, the reachability answer and this accounting from
2192
+ * the same files; three separate passes read every file three times.
2193
+ */
2194
+ function accountSnapshot(ctx, snapshot, accounting) {
2195
+ const { filePath, onDisk, parsed, sourceFile } = snapshot;
2196
+ const { paths, declined } = accounting;
2197
+ if (onDisk == null || parsed == null || parsed !== onDisk) {
2198
+ if (!((onDisk?.includes("token") ?? false) || (parsed?.includes("token") ?? false))) return;
2199
+ declined.push({
2200
+ filePath,
2201
+ line: 1,
2202
+ reason: onDisk == null || parsed == null ? "unreadable" : "transformed"
2203
+ });
2204
+ return;
2205
+ }
2206
+ if (parseErrorCount(sourceFile)) {
2207
+ if (!parsed.includes("token")) return;
2208
+ declined.push({
2209
+ filePath,
2210
+ line: 1,
2211
+ reason: "unparsed"
2212
+ });
2213
+ return;
2214
+ }
2215
+ accountFile(ctx, sourceFile, filePath, paths, declined);
2216
+ }
2217
+ /**
2218
+ * How many syntax errors the parse produced.
2219
+ *
2220
+ * `parseDiagnostics` is TypeScript-internal and absent from the public `SourceFile` type, so
2221
+ * it is reached through a cast. The alternative, `getPreEmitDiagnostics`, runs the type checker
2222
+ * over the whole program — orders of magnitude more work for a question about syntax, and it
2223
+ * would report type errors this pass has no business declining over.
2224
+ */
2225
+ const parseErrorCount = (sourceFile) => sourceFile.compilerNode.parseDiagnostics?.length ?? 0;
2226
+ /** Whether a module specifier resolves to the generated tokens artifact. */
2227
+ const isTokensEntrypoint = (ctx, specifier) => {
2228
+ const mods = ctx.imports.value.tokens;
2229
+ if (mods.some((mod) => specifier.includes(mod))) return true;
2230
+ const pathMappings = ctx.conf.tsOptions?.pathMappings;
2231
+ if (!pathMappings) return false;
2232
+ const resolved = (0, _bamboocss_config_ts_path.resolveTsPathPattern)(pathMappings, specifier);
2233
+ if (!resolved) return false;
2234
+ return mods.some((mod) => resolved.includes(mod) || resolved === mod);
2235
+ };
2236
+ const lineOf = (node) => node.getSourceFile().getLineAndColumnAtPos(node.getStart()).line;
2237
+ function accountFile(ctx, sourceFile, filePath, paths, declined) {
2238
+ const decline = (node, reason) => declined.push({
2239
+ filePath,
2240
+ line: lineOf(node),
2241
+ reason
2242
+ });
2243
+ /** Local names bound to the artifact: the `token` export, and any namespace of it. */
2244
+ const bindings = /* @__PURE__ */ new Set();
2245
+ for (const statement of sourceFile.getStatements()) {
2246
+ if (ts_morph.Node.isExportDeclaration(statement)) {
2247
+ const specifier = statement.getModuleSpecifierValue();
2248
+ if (specifier && isTokensEntrypoint(ctx, specifier)) decline(statement, "re-exported");
2249
+ continue;
2250
+ }
2251
+ if (!ts_morph.Node.isImportDeclaration(statement)) continue;
2252
+ const specifier = statement.getModuleSpecifierValue();
2253
+ if (!specifier) continue;
2254
+ const clause = statement.getImportClause();
2255
+ if (!clause || statement.isTypeOnly()) continue;
2256
+ if (!isTokensEntrypoint(ctx, specifier)) {
2257
+ for (const named of clause.getNamedImports()) if (!named.isTypeOnly() && nameOf(named.getNameNode()) === "token") decline(named, "unclassified-import");
2258
+ const foreignDefault = clause.getDefaultImport();
2259
+ if (foreignDefault && nameOf(foreignDefault) === "token") decline(foreignDefault, "unclassified-import");
2260
+ const foreignNamespace = clause.getNamespaceImport();
2261
+ if (foreignNamespace && usesTokenMember(sourceFile, foreignNamespace.getText())) decline(foreignNamespace, "unclassified-import");
2262
+ continue;
2263
+ }
2264
+ const defaultImport = clause.getDefaultImport();
2265
+ if (defaultImport) decline(defaultImport, "unsupported-import");
2266
+ const namespace = clause.getNamespaceImport();
2267
+ if (namespace) bindings.add(namespace.getText());
2268
+ for (const named of clause.getNamedImports()) {
2269
+ if (named.isTypeOnly()) continue;
2270
+ if (nameOf(named.getNameNode()) !== "token") {
2271
+ decline(named, "unsupported-import");
2272
+ continue;
2273
+ }
2274
+ bindings.add((named.getAliasNode() ?? named.getNameNode()).getText());
2275
+ }
2276
+ }
2277
+ for (const importEquals of sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.ImportEqualsDeclaration)) if (importEquals.getText().includes("token")) decline(importEquals, "import-equals");
2278
+ for (const call of sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.CallExpression)) {
2279
+ const callee = call.getExpression();
2280
+ const isRequire = ts_morph.Node.isIdentifier(callee) && callee.getText() === "require";
2281
+ const isDynamicImport = callee.getKind() === ts_morph.SyntaxKind.ImportKeyword;
2282
+ if (!isRequire && !isDynamicImport) continue;
2283
+ const argument = call.getArguments()[0];
2284
+ if (!argument) continue;
2285
+ if (ts_morph.Node.isStringLiteral(argument) ? isTokensEntrypoint(ctx, argument.getLiteralValue()) : true) decline(call, isRequire ? "require" : "dynamic-import");
2286
+ }
2287
+ for (const identifier of sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.Identifier)) {
2288
+ const text = nameOf(identifier);
2289
+ if (!bindings.has(text) && text !== "token") continue;
2290
+ const parent = identifier.getParent();
2291
+ if (ts_morph.Node.isPropertyAccessExpression(parent) && parent.getNameNode() === identifier) {
2292
+ const object = parent.getExpression();
2293
+ const objectName = ts_morph.Node.isIdentifier(object) ? object.getText() : void 0;
2294
+ if (objectName && bindings.has(objectName)) continue;
2295
+ decline(identifier, "unresolved-reference");
2296
+ continue;
2297
+ }
2298
+ if (ts_morph.Node.isPropertyAssignment(parent) && parent.getNameNode() === identifier) continue;
2299
+ const path = accountedPath(identifier);
2300
+ if (path === void 0) {
2301
+ decline(identifier, "unresolved-reference");
2302
+ continue;
2303
+ }
2304
+ paths.add(path);
2305
+ }
2306
+ }
2307
+ /**
2308
+ * Whether any `<namespace>.token` member access appears, for an unclassified namespace.
2309
+ *
2310
+ * Element access counts too: `ui['token'](k)` reaches the same export and is invisible to a
2311
+ * property-access-only scan.
2312
+ */
2313
+ function usesTokenMember(sourceFile, namespace) {
2314
+ if (sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.PropertyAccessExpression).some((access) => access.getExpression().getText() === namespace && nameOf(access.getNameNode()) === "token")) return true;
2315
+ return sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.ElementAccessExpression).some((access) => {
2316
+ if (access.getExpression().getText() !== namespace) return false;
2317
+ const argument = access.getArgumentExpression();
2318
+ return argument != null && (!ts_morph.Node.isStringLiteral(argument) || argument.getLiteralValue() === "token");
2319
+ });
2320
+ }
2321
+ /**
2322
+ * An identifier's name as the compiler resolves it, not as it is spelled.
2323
+ *
2324
+ * `token` is the identifier `token`; reading `getText()` returns the escape and compares
2325
+ * unequal, which let an import of the artifact's export past the checks that key on the name.
2326
+ */
2327
+ const nameOf = (node) => ts_morph.Node.isIdentifier(node) ? String(node.compilerNode.escapedText) : node.getText();
2328
+ /**
2329
+ * The token path one occurrence asks for, or `undefined` if it is not a call this can read.
2330
+ *
2331
+ * Accepts the callee position and nothing else — `token('x')`, `token.var('x')`,
2332
+ * `token.value('x')`, and the namespaced spellings. An identifier anywhere else is a value
2333
+ * escaping somewhere this pass cannot follow: assigned (`const t = token`), passed
2334
+ * (`useMemo(() => token)`), spread, or enumerated.
2335
+ */
2336
+ function accountedPath(identifier) {
2337
+ const parent = identifier.getParent();
2338
+ if (!parent) return void 0;
2339
+ if (ts_morph.Node.isImportSpecifier(parent) || ts_morph.Node.isNamespaceImport(parent) || ts_morph.Node.isImportClause(parent)) return "";
2340
+ if (ts_morph.Node.isCallExpression(parent) && parent.getExpression() === identifier) return literalPath(parent);
2341
+ if (!ts_morph.Node.isPropertyAccessExpression(parent) || parent.getExpression() !== identifier) return void 0;
2342
+ const property = parent.getNameNode().getText();
2343
+ const grandParent = parent.getParent();
2344
+ if (property === "var" || property === "value") return ts_morph.Node.isCallExpression(grandParent) && grandParent.getExpression() === parent ? literalPath(grandParent) : void 0;
2345
+ if (property !== "token") return void 0;
2346
+ if (ts_morph.Node.isCallExpression(grandParent) && grandParent.getExpression() === parent) return literalPath(grandParent);
2347
+ if (ts_morph.Node.isPropertyAccessExpression(grandParent) && grandParent.getExpression() === parent) {
2348
+ const method = grandParent.getNameNode().getText();
2349
+ if (method !== "var" && method !== "value") return void 0;
2350
+ const call = grandParent.getParent();
2351
+ return ts_morph.Node.isCallExpression(call) && call.getExpression() === grandParent ? literalPath(call) : void 0;
2352
+ }
2353
+ }
2354
+ /**
2355
+ * The path a call asks for, when the first argument is a literal.
2356
+ *
2357
+ * Read through `getLiteralValue()`, never off the source text. The text carries escapes —
2358
+ * `token('colors.red.300')` — and a path recorded raw looks up nothing, which
2359
+ * would accept a reference and keep no declaration for it. That is the exact failure this
2360
+ * module exists to make unrepresentable.
2361
+ */
2362
+ function literalPath(call) {
2363
+ if (!ts_morph.Node.isCallExpression(call)) return void 0;
2364
+ const argument = call.getArguments()[0];
2365
+ if (!argument) return void 0;
2366
+ if (ts_morph.Node.isStringLiteral(argument)) return argument.getLiteralValue();
2367
+ if (ts_morph.Node.isNoSubstitutionTemplateLiteral(argument)) return argument.getLiteralValue();
2368
+ }
2369
+ //#endregion
2117
2370
  //#region src/token-references.ts
2118
2371
  /**
2119
2372
  * `token.var('colors.red.300')` and `token('spacing.4')`, including the whitespace a
2120
- * formatter may leave behind. The parser already reports `token()` calls and resolves
2121
- * constants and template literals through them, but it does not match `token.var()`,
2122
- * whose callee is a property access. Scanning the text covers that, and covers a path
2123
- * built somewhere the extractor cannot follow.
2373
+ * formatter may leave behind. The parser reports both, resolving constants and template
2374
+ * literals through them — `token.var()` included, since it is recorded as its own kind
2375
+ * rather than dropped for having a property access as its callee. Scanning the text still
2376
+ * earns its place twice over: it covers a path built somewhere the extractor cannot
2377
+ * follow, and it covers the callers below that supply no `results` at all.
2378
+ */
2379
+ const TOKEN_CALL = /\btoken(?:\s*\.\s*(?:var|value))?\s*\(\s*['"`]([^'"`]+)['"`]/g;
2380
+ /**
2381
+ * A token reached from javascript at all — a call of any shape, or an import of the artifact.
2382
+ *
2383
+ * Has to stay a strict superset of `TOKEN_CALL`: it must match wherever that one matches, and
2384
+ * also wherever that one gives up. See `collectTokenReferences` for why the redundancy holds.
2385
+ * No `g` flag, so `test` carries no state between files.
2124
2386
  */
2125
- const TOKEN_CALL = /\btoken(?:\s*\.\s*var)?\s*\(\s*['"`]([^'"`]+)['"`]/g;
2387
+ const REACHABLE_FROM_JS = /\btoken(\s*\.\s*(?:var|value))?\s*\(|\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2126
2388
  /**
2127
2389
  * The text of every file `include` covers — as written on disk, and, when they differ, as the
2128
2390
  * parser understands it.
@@ -2143,60 +2405,58 @@ const TOKEN_CALL = /\btoken(?:\s*\.\s*var)?\s*\(\s*['"`]([^'"`]+)['"`]/g;
2143
2405
  * is an order of magnitude more.
2144
2406
  */
2145
2407
  function* sourceTexts(ctx) {
2146
- for (const file of ctx.getFiles()) {
2147
- const filePath = ctx.runtime.path.abs(ctx.config.cwd, file);
2148
- let onDisk;
2149
- try {
2150
- onDisk = ctx.runtime.fs.readFileSync(filePath);
2151
- } catch {
2152
- onDisk = void 0;
2153
- }
2154
- const parsed = ctx.project.getSourceFile(filePath)?.getFullText();
2155
- if (onDisk != null) yield onDisk;
2156
- if (parsed != null && parsed !== onDisk) yield parsed;
2157
- }
2408
+ for (const snapshot of sourceSnapshots(ctx)) yield* snapshotTexts(snapshot);
2158
2409
  }
2159
2410
  /**
2160
- * Collect token references that reading the generated css cannot reveal.
2411
+ * The token prune, as all three build paths need to run it.
2161
2412
  *
2162
- * This is deliberately textual and therefore over-inclusive: a match inside a comment or
2163
- * a string that is never evaluated keeps a token alive. Keeping a token that is not used
2164
- * costs bytes; dropping one that is breaks the page, so the bias belongs on this side.
2413
+ * One function because it was three copies of one conditional, and the `false` branch went
2414
+ * missing from a copy: a watch rebuild with `pruneUnusedTokens: false` skipped `pruneTokens`
2415
+ * altogether, so it kept `@property` registrations that a full build of the same source
2416
+ * strips. The other two copies carried a comment pointing at that file for the reasoning,
2417
+ * which is how a missing branch reads as intentional.
2165
2418
  *
2166
- * `results` is a second, redundant source for the same paths: the extractor resolves one
2167
- * built from a constant, which the text scan reads literally and fails to look up. Callers
2168
- * that cannot supply it — the watch rebuild and the PostCSS plugin, where re-parsing would
2169
- * encode every style a second time — pass none, and stay correct only because a path the
2170
- * scan misses can lose nothing: `token()` hands javascript a literal for exactly the
2171
- * tokens this cannot see, and hands it a `var()` only for virtual, conditional and
2172
- * negative tokens, which `getAlwaysKeptTokenVars` keeps.
2173
- *
2174
- * Those blanket keeps are no longer unconditional — `tokensReachableFromJs` gates them — and
2175
- * this comment used to warn that narrowing them would break the argument above. It does not,
2176
- * for a reason worth stating rather than rediscovering: the gate matches `token(` regardless
2177
- * of what follows, where `TOKEN_CALL` below needs a string literal. So the one shape this
2178
- * scan cannot resolve, a path built from a constant, is exactly the shape that turns the
2179
- * gate on and restores every blanket keep. The two failures line up, which is what makes the
2180
- * redundancy hold.
2181
- *
2182
- * That alignment is a real coupling, not an observation: the gate's call pattern has to stay
2183
- * a superset of this one, matching wherever `TOKEN_CALL` matches and also wherever it gives
2184
- * up. It briefly was not — this allowed whitespace around the `.` of `token.var` and the gate
2185
- * did not, so a formatter wrapping `token\n .var(SOME_CONST)` slipped past both. Change one
2186
- * of the two and change the other; `token-references.test.ts` pins the property directly.
2187
- *
2188
- * Where it stops holding is a binding renamed away from `token` — `const t = token`, then
2189
- * `t('spacing.4')` — which matches neither. `token-references.test.ts` pins both halves.
2419
+ * Opting out still drops the registrations. Those are not tokens — nothing hands one to
2420
+ * javascript, and none appear in the `token()` surface — so the reachability problem the flag
2421
+ * exists for does not apply to them, and opting out of token pruning should not mean shipping
2422
+ * a preset's whole filter and gradient set for nothing.
2190
2423
  */
2191
- function collectTokenReferences(ctx, results) {
2424
+ function pruneTokensForBuild(ctx, sheet, results) {
2425
+ if (!ctx.config.pruneUnusedTokens) {
2426
+ ctx.pruneTokens(sheet);
2427
+ return;
2428
+ }
2429
+ const strict = ctx.config.pruneUnusedTokens === "strict";
2192
2430
  const paths = /* @__PURE__ */ new Set();
2193
2431
  const vars = /* @__PURE__ */ new Set();
2432
+ const accounting = {
2433
+ paths: /* @__PURE__ */ new Set(),
2434
+ declined: []
2435
+ };
2436
+ let reachable = false;
2194
2437
  for (const result of results) for (const item of result.token) for (const value of item.data ?? []) if (typeof value === "string") paths.add(value);
2195
- for (const content of sourceTexts(ctx)) {
2196
- for (const match of content.matchAll(TOKEN_CALL)) paths.add(match[1]);
2197
- for (const name of (0, _bamboocss_shared.cssVarRefs)(content)) vars.add(name);
2438
+ for (const snapshot of sourceSnapshots(ctx)) {
2439
+ for (const text of snapshotTexts(snapshot)) {
2440
+ for (const match of text.matchAll(TOKEN_CALL)) paths.add(match[1]);
2441
+ for (const name of (0, _bamboocss_shared.cssVarRefs)(text)) vars.add(name);
2442
+ if (!reachable && REACHABLE_FROM_JS.test(text)) reachable = true;
2443
+ }
2444
+ if (strict) accountSnapshot(ctx, snapshot, accounting);
2198
2445
  }
2446
+ for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
2447
+ if (!strict) {
2448
+ ctx.pruneTokens(sheet, vars, reachable);
2449
+ return;
2450
+ }
2451
+ for (const name of tokenVarsFor(ctx, accounting.paths)) vars.add(name);
2452
+ if (accounting.declined.length) _bamboocss_logger.logger.warn("tokens:strict", formatDeclined(ctx, accounting.declined));
2453
+ ctx.pruneTokens(sheet, vars, accounting.declined.length > 0 && reachable);
2454
+ }
2455
+ /** The custom properties a set of token paths resolves to. */
2456
+ function tokenVarsFor(ctx, paths) {
2457
+ const vars = /* @__PURE__ */ new Set();
2199
2458
  for (const path of paths) {
2459
+ if (!path) continue;
2200
2460
  const ref = ctx.tokens.view.getVar(path);
2201
2461
  if (!ref) continue;
2202
2462
  for (const name of (0, _bamboocss_shared.cssVarRefs)(ref)) vars.add(name);
@@ -2204,6 +2464,25 @@ function collectTokenReferences(ctx, results) {
2204
2464
  return vars;
2205
2465
  }
2206
2466
  /**
2467
+ * Why `strict` could not prune, grouped by file.
2468
+ *
2469
+ * Printed rather than thrown. A decline is not an error — the build falls back to keeping
2470
+ * every declaration, which is what would have happened anyway — it is the answer to "why is my
2471
+ * token layer still this size", which otherwise has no answer at all.
2472
+ */
2473
+ function formatDeclined(ctx, declined) {
2474
+ const byFile = /* @__PURE__ */ new Map();
2475
+ for (const entry of declined) {
2476
+ const list = byFile.get(entry.filePath) ?? [];
2477
+ list.push(entry);
2478
+ byFile.set(entry.filePath, list);
2479
+ }
2480
+ const detail = Array.from(byFile.entries()).map(([filePath, entries]) => {
2481
+ return [` ${filePath.startsWith(ctx.config.cwd) ? filePath.slice(ctx.config.cwd.length + 1) : filePath}`, ...entries.map((entry) => ` ${entry.line}: ${entry.reason}`)].join("\n");
2482
+ }).join("\n");
2483
+ return `${declined.length} token reference(s) could not be resolved, so every token declaration is kept.\n\n${detail}\n\nSpell the path as a string literal at the call, move it into \`staticCss\`, or set \`pruneUnusedTokens: true\` to stop asking.`;
2484
+ }
2485
+ /**
2207
2486
  * Collect keyframe names that reading the generated css cannot reveal.
2208
2487
  *
2209
2488
  * A keyframe reached through `css({ animation: 'fade-in 1s' })` lands in the stylesheet
@@ -2261,41 +2540,6 @@ function collectRenderedElements(ctx) {
2261
2540
  for (const content of sourceTexts(ctx)) for (const match of content.matchAll(/<\s*([a-z][\w-]*)(?=[\s/>]|$)/g)) found.add(match[1].toLowerCase());
2262
2541
  return found;
2263
2542
  }
2264
- /**
2265
- * Whether any source file reaches for a token from javascript.
2266
- *
2267
- * The tokens artifact is generated into the project rather than installed, so the import is
2268
- * written in the project's own source and a scan of `include` sees it. When this comes back
2269
- * false, the declarations kept purely so `token()` can answer have no caller to answer.
2270
- *
2271
- * Deliberately loose, and loose in a specific direction: a false positive keeps a declaration
2272
- * nothing reads, a false negative returns a `var()` nothing declares.
2273
- *
2274
- * So the import test is any module specifier with a `/tokens` path segment, rather than the
2275
- * literal `styled-system/tokens` it used to be. `outdir` is configurable, so the artifact is
2276
- * only at `styled-system/` by default, and the literal missed `outdir: 'design-system'`, a
2277
- * tsconfig path alias, and `styled-system/tokens/index.mjs` -- which is the only spelling
2278
- * NodeNext accepts, the artifact being a directory. It is still anchored to `from`, `import`
2279
- * or `require`, because without that anchor a route or a url (`fetch('/api/tokens')`) reads
2280
- * as an import and quietly switches the whole optimisation off.
2281
- *
2282
- * The call test allows whitespace around the dot for the same reason `TOKEN_CALL` does. It
2283
- * did not, which broke the alignment the note on `collectTokenReferences` rests on: a
2284
- * formatter wrapping `token\n .var(SOME_CONST)` was invisible to that scan *and* to this
2285
- * gate *and* to the parser, whose callee is a property access. A comment in the same position
2286
- * -- `token/*x*\/.var(` -- is still invisible to all three.
2287
- *
2288
- * One shape it still does not see, pinned in `token-references.test.ts`: a binding renamed
2289
- * away from `token`, as in `const t = token`. Also unseen is a caller outside `include`,
2290
- * which scopes style extraction rather than everything that may import — a script, a config,
2291
- * or a sibling workspace package. Both prune declarations the running app then asks for, and
2292
- * neither reports itself; `pruneUnusedTokens: false` is the way out.
2293
- */
2294
- function tokensReachableFromJs(ctx) {
2295
- const pattern = /\btoken(\s*\.\s*var)?\s*\(|\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2296
- for (const content of sourceTexts(ctx)) if (pattern.test(content)) return true;
2297
- return false;
2298
- }
2299
2543
  //#endregion
2300
2544
  //#region src/builder.ts
2301
2545
  const fileModifiedMap = /* @__PURE__ */ new Map();
@@ -2478,8 +2722,7 @@ var Builder = class {
2478
2722
  const sheet = ctx.createSheet();
2479
2723
  if (layerParams) ctx.appendLayerParams(sheet);
2480
2724
  ctx.appendBaselineCss(sheet);
2481
- if (ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, []), tokensReachableFromJs(ctx));
2482
- else ctx.pruneTokens(sheet);
2725
+ pruneTokensForBuild(ctx, sheet, []);
2483
2726
  if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2484
2727
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2485
2728
  return ctx.getCss(sheet);
@@ -2584,8 +2827,7 @@ const cssgen = async (ctx, options) => {
2584
2827
  ctx.appendBaselineCss(sheet);
2585
2828
  }
2586
2829
  ctx.appendParserCss(sheet);
2587
- if (!minimal && ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, results), tokensReachableFromJs(ctx));
2588
- else if (!minimal) ctx.pruneTokens(sheet);
2830
+ if (!minimal) pruneTokensForBuild(ctx, sheet, results);
2589
2831
  if (!minimal && ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2590
2832
  if (!minimal && ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2591
2833
  if (splitting) await ctx.writeSplitCss(sheet);
@@ -2657,8 +2899,7 @@ async function build(ctx, artifactIds) {
2657
2899
  ctx.appendBaselineCss(sheet);
2658
2900
  const parsed = ctx.parseFiles();
2659
2901
  ctx.appendParserCss(sheet);
2660
- if (ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, parsed.results), tokensReachableFromJs(ctx));
2661
- else ctx.pruneTokens(sheet);
2902
+ pruneTokensForBuild(ctx, sheet, parsed.results);
2662
2903
  if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2663
2904
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2664
2905
  await ctx.writeCss(sheet);
@@ -2704,7 +2945,7 @@ async function generate(config, configPath) {
2704
2945
  ctx.appendLayerParams(sheet);
2705
2946
  ctx.appendBaselineCss(sheet);
2706
2947
  ctx.appendParserCss(sheet);
2707
- if (ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, []), tokensReachableFromJs(ctx));
2948
+ pruneTokensForBuild(ctx, sheet, []);
2708
2949
  if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2709
2950
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2710
2951
  const css = ctx.getCss(sheet);
@@ -2808,7 +3049,7 @@ export default defineConfig({
2808
3049
 
2809
3050
  // Tokens, keyframes and @property rules nothing in the emitted css reaches are dropped
2810
3051
  // by default — worth 36-78% of a new project's stylesheet. Set \`pruneUnusedTokens: false\`
2811
- // if you read tokens from somewhere the build cannot see them — \`token.var()\` with a
3052
+ // if you read tokens from somewhere the build cannot see them — \`token()\` with a
2812
3053
  // computed path, or a hand-written stylesheet outside \`include\` — or list those under
2813
3054
  // \`staticCss\` to keep them.
2814
3055
 
package/dist/index.mjs CHANGED
@@ -23,6 +23,8 @@ import path from "node:path";
23
23
  import fs, { promises } from "node:fs";
24
24
  import isGlob from "is-glob";
25
25
  import globParent from "glob-parent";
26
+ import { resolveTsPathPattern } from "@bamboocss/config/ts-path";
27
+ import { Node, SyntaxKind } from "ts-morph";
26
28
  import readline from "node:readline";
27
29
  import { lookItUpSync } from "look-it-up";
28
30
  import outdent$1, { outdent } from "outdent";
@@ -1440,6 +1442,25 @@ function globDirname(globs) {
1440
1442
  }
1441
1443
  //#endregion
1442
1444
  //#region src/node-runtime.ts
1445
+ /**
1446
+ * What the source glob ignores.
1447
+ *
1448
+ * `**\/*.d.ts` is unconditional. It used to be a *default* that a user's own `exclude`
1449
+ * replaced, so declaration files were scanned by whether the project happened to set that
1450
+ * option at all — excluded for `exclude: []`, included for `exclude: ['**\/*.stories.tsx']`.
1451
+ * Nothing chose that; the default was simply appended when nothing else was there.
1452
+ *
1453
+ * A declaration file carries no runtime code and can emit no styles. It is still read by the
1454
+ * reference scans, which are deliberately over-inclusive, so scanning one could keep a token
1455
+ * named in a doc comment or a reset rule for an element named in a JSDoc example. Those are
1456
+ * spurious keeps rather than a guarantee anyone relied on — and they were never available to
1457
+ * the projects on the other side of the same condition.
1458
+ *
1459
+ * Copied rather than appended to. `opts.exclude` is `ctx.config.exclude` itself, so pushing
1460
+ * onto it edited the user's resolved config in place, and the next call then saw a list it had
1461
+ * mutated.
1462
+ */
1463
+ const globIgnore = (exclude) => ["**/*.d.ts", ...exclude ?? []];
1443
1464
  const nodeRuntime = {
1444
1465
  cwd() {
1445
1466
  return process.cwd();
@@ -1466,11 +1487,9 @@ const nodeRuntime = {
1466
1487
  },
1467
1488
  glob(opts) {
1468
1489
  if (!opts.include) return [];
1469
- const ignore = opts.exclude ?? [];
1470
- if (!ignore.length) ignore.push("**/*.d.ts");
1471
1490
  return glob.sync(opts.include, {
1472
1491
  cwd: opts.cwd,
1473
- ignore,
1492
+ ignore: globIgnore(opts.exclude),
1474
1493
  absolute: true
1475
1494
  });
1476
1495
  },
@@ -2099,15 +2118,258 @@ function parseDependency(fileOrGlob) {
2099
2118
  return message;
2100
2119
  }
2101
2120
  //#endregion
2121
+ //#region src/source-snapshots.ts
2122
+ /**
2123
+ * Every file `include` covers, read once.
2124
+ *
2125
+ * The scans that decide what survives pruning — the token reference set, the reachability
2126
+ * gate, the strict accounting — all want the same two copies of the same files, and each used
2127
+ * to fetch them itself. A strict build therefore read every file three times over: once to
2128
+ * collect references, once to account, and once more for the gate whenever the accounting
2129
+ * declined. Yielding a snapshot lets one walk feed all of them.
2130
+ *
2131
+ * Both copies, because neither alone is complete and the text scans are safe when over-fed. A
2132
+ * file the parser transformed is stored rewritten (`parseSourceFile` calls `replaceWithText`),
2133
+ * and those transforms lose things the scans want: `svelteToTsx` and `vueToTsx` each swallow a
2134
+ * throw and return an empty string, and a Vue SFC with a render function and no `<template>`
2135
+ * becomes the literal `<template>undefined</template>`. Read only the parsed copy and a file
2136
+ * like that reports no tokens and no elements at all.
2137
+ *
2138
+ * The parsed copy still has to be read as well, because `parser:before` is the documented way
2139
+ * to teach bamboo a format it does not know. A template compiled to jsx by such a hook holds
2140
+ * nothing a scan of the raw file would recognise, and that is the hook working as intended.
2141
+ */
2142
+ function* sourceSnapshots(ctx) {
2143
+ for (const file of ctx.getFiles()) {
2144
+ const filePath = ctx.runtime.path.abs(ctx.config.cwd, file);
2145
+ let onDisk;
2146
+ try {
2147
+ onDisk = ctx.runtime.fs.readFileSync(filePath);
2148
+ } catch {
2149
+ onDisk = void 0;
2150
+ }
2151
+ const sourceFile = ctx.project.getSourceFile(filePath);
2152
+ yield {
2153
+ filePath,
2154
+ onDisk,
2155
+ parsed: sourceFile?.getFullText(),
2156
+ sourceFile
2157
+ };
2158
+ }
2159
+ }
2160
+ /**
2161
+ * The distinct texts a snapshot carries.
2162
+ *
2163
+ * One when the parser holds the file as written, two when a transform rewrote it. Every
2164
+ * textual scan wants both, and wants neither twice.
2165
+ */
2166
+ function* snapshotTexts(snapshot) {
2167
+ const { onDisk, parsed } = snapshot;
2168
+ if (onDisk != null) yield onDisk;
2169
+ if (parsed != null && parsed !== onDisk) yield parsed;
2170
+ }
2171
+ //#endregion
2172
+ //#region src/token-accounting.ts
2173
+ /**
2174
+ * One file's contribution, split out so the build can account and scan in a single walk.
2175
+ *
2176
+ * `pruneTokensForBuild` needs the keep set, the reachability answer and this accounting from
2177
+ * the same files; three separate passes read every file three times.
2178
+ */
2179
+ function accountSnapshot(ctx, snapshot, accounting) {
2180
+ const { filePath, onDisk, parsed, sourceFile } = snapshot;
2181
+ const { paths, declined } = accounting;
2182
+ if (onDisk == null || parsed == null || parsed !== onDisk) {
2183
+ if (!((onDisk?.includes("token") ?? false) || (parsed?.includes("token") ?? false))) return;
2184
+ declined.push({
2185
+ filePath,
2186
+ line: 1,
2187
+ reason: onDisk == null || parsed == null ? "unreadable" : "transformed"
2188
+ });
2189
+ return;
2190
+ }
2191
+ if (parseErrorCount(sourceFile)) {
2192
+ if (!parsed.includes("token")) return;
2193
+ declined.push({
2194
+ filePath,
2195
+ line: 1,
2196
+ reason: "unparsed"
2197
+ });
2198
+ return;
2199
+ }
2200
+ accountFile(ctx, sourceFile, filePath, paths, declined);
2201
+ }
2202
+ /**
2203
+ * How many syntax errors the parse produced.
2204
+ *
2205
+ * `parseDiagnostics` is TypeScript-internal and absent from the public `SourceFile` type, so
2206
+ * it is reached through a cast. The alternative, `getPreEmitDiagnostics`, runs the type checker
2207
+ * over the whole program — orders of magnitude more work for a question about syntax, and it
2208
+ * would report type errors this pass has no business declining over.
2209
+ */
2210
+ const parseErrorCount = (sourceFile) => sourceFile.compilerNode.parseDiagnostics?.length ?? 0;
2211
+ /** Whether a module specifier resolves to the generated tokens artifact. */
2212
+ const isTokensEntrypoint = (ctx, specifier) => {
2213
+ const mods = ctx.imports.value.tokens;
2214
+ if (mods.some((mod) => specifier.includes(mod))) return true;
2215
+ const pathMappings = ctx.conf.tsOptions?.pathMappings;
2216
+ if (!pathMappings) return false;
2217
+ const resolved = resolveTsPathPattern(pathMappings, specifier);
2218
+ if (!resolved) return false;
2219
+ return mods.some((mod) => resolved.includes(mod) || resolved === mod);
2220
+ };
2221
+ const lineOf = (node) => node.getSourceFile().getLineAndColumnAtPos(node.getStart()).line;
2222
+ function accountFile(ctx, sourceFile, filePath, paths, declined) {
2223
+ const decline = (node, reason) => declined.push({
2224
+ filePath,
2225
+ line: lineOf(node),
2226
+ reason
2227
+ });
2228
+ /** Local names bound to the artifact: the `token` export, and any namespace of it. */
2229
+ const bindings = /* @__PURE__ */ new Set();
2230
+ for (const statement of sourceFile.getStatements()) {
2231
+ if (Node.isExportDeclaration(statement)) {
2232
+ const specifier = statement.getModuleSpecifierValue();
2233
+ if (specifier && isTokensEntrypoint(ctx, specifier)) decline(statement, "re-exported");
2234
+ continue;
2235
+ }
2236
+ if (!Node.isImportDeclaration(statement)) continue;
2237
+ const specifier = statement.getModuleSpecifierValue();
2238
+ if (!specifier) continue;
2239
+ const clause = statement.getImportClause();
2240
+ if (!clause || statement.isTypeOnly()) continue;
2241
+ if (!isTokensEntrypoint(ctx, specifier)) {
2242
+ for (const named of clause.getNamedImports()) if (!named.isTypeOnly() && nameOf(named.getNameNode()) === "token") decline(named, "unclassified-import");
2243
+ const foreignDefault = clause.getDefaultImport();
2244
+ if (foreignDefault && nameOf(foreignDefault) === "token") decline(foreignDefault, "unclassified-import");
2245
+ const foreignNamespace = clause.getNamespaceImport();
2246
+ if (foreignNamespace && usesTokenMember(sourceFile, foreignNamespace.getText())) decline(foreignNamespace, "unclassified-import");
2247
+ continue;
2248
+ }
2249
+ const defaultImport = clause.getDefaultImport();
2250
+ if (defaultImport) decline(defaultImport, "unsupported-import");
2251
+ const namespace = clause.getNamespaceImport();
2252
+ if (namespace) bindings.add(namespace.getText());
2253
+ for (const named of clause.getNamedImports()) {
2254
+ if (named.isTypeOnly()) continue;
2255
+ if (nameOf(named.getNameNode()) !== "token") {
2256
+ decline(named, "unsupported-import");
2257
+ continue;
2258
+ }
2259
+ bindings.add((named.getAliasNode() ?? named.getNameNode()).getText());
2260
+ }
2261
+ }
2262
+ for (const importEquals of sourceFile.getDescendantsOfKind(SyntaxKind.ImportEqualsDeclaration)) if (importEquals.getText().includes("token")) decline(importEquals, "import-equals");
2263
+ for (const call of sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)) {
2264
+ const callee = call.getExpression();
2265
+ const isRequire = Node.isIdentifier(callee) && callee.getText() === "require";
2266
+ const isDynamicImport = callee.getKind() === SyntaxKind.ImportKeyword;
2267
+ if (!isRequire && !isDynamicImport) continue;
2268
+ const argument = call.getArguments()[0];
2269
+ if (!argument) continue;
2270
+ if (Node.isStringLiteral(argument) ? isTokensEntrypoint(ctx, argument.getLiteralValue()) : true) decline(call, isRequire ? "require" : "dynamic-import");
2271
+ }
2272
+ for (const identifier of sourceFile.getDescendantsOfKind(SyntaxKind.Identifier)) {
2273
+ const text = nameOf(identifier);
2274
+ if (!bindings.has(text) && text !== "token") continue;
2275
+ const parent = identifier.getParent();
2276
+ if (Node.isPropertyAccessExpression(parent) && parent.getNameNode() === identifier) {
2277
+ const object = parent.getExpression();
2278
+ const objectName = Node.isIdentifier(object) ? object.getText() : void 0;
2279
+ if (objectName && bindings.has(objectName)) continue;
2280
+ decline(identifier, "unresolved-reference");
2281
+ continue;
2282
+ }
2283
+ if (Node.isPropertyAssignment(parent) && parent.getNameNode() === identifier) continue;
2284
+ const path = accountedPath(identifier);
2285
+ if (path === void 0) {
2286
+ decline(identifier, "unresolved-reference");
2287
+ continue;
2288
+ }
2289
+ paths.add(path);
2290
+ }
2291
+ }
2292
+ /**
2293
+ * Whether any `<namespace>.token` member access appears, for an unclassified namespace.
2294
+ *
2295
+ * Element access counts too: `ui['token'](k)` reaches the same export and is invisible to a
2296
+ * property-access-only scan.
2297
+ */
2298
+ function usesTokenMember(sourceFile, namespace) {
2299
+ if (sourceFile.getDescendantsOfKind(SyntaxKind.PropertyAccessExpression).some((access) => access.getExpression().getText() === namespace && nameOf(access.getNameNode()) === "token")) return true;
2300
+ return sourceFile.getDescendantsOfKind(SyntaxKind.ElementAccessExpression).some((access) => {
2301
+ if (access.getExpression().getText() !== namespace) return false;
2302
+ const argument = access.getArgumentExpression();
2303
+ return argument != null && (!Node.isStringLiteral(argument) || argument.getLiteralValue() === "token");
2304
+ });
2305
+ }
2306
+ /**
2307
+ * An identifier's name as the compiler resolves it, not as it is spelled.
2308
+ *
2309
+ * `token` is the identifier `token`; reading `getText()` returns the escape and compares
2310
+ * unequal, which let an import of the artifact's export past the checks that key on the name.
2311
+ */
2312
+ const nameOf = (node) => Node.isIdentifier(node) ? String(node.compilerNode.escapedText) : node.getText();
2313
+ /**
2314
+ * The token path one occurrence asks for, or `undefined` if it is not a call this can read.
2315
+ *
2316
+ * Accepts the callee position and nothing else — `token('x')`, `token.var('x')`,
2317
+ * `token.value('x')`, and the namespaced spellings. An identifier anywhere else is a value
2318
+ * escaping somewhere this pass cannot follow: assigned (`const t = token`), passed
2319
+ * (`useMemo(() => token)`), spread, or enumerated.
2320
+ */
2321
+ function accountedPath(identifier) {
2322
+ const parent = identifier.getParent();
2323
+ if (!parent) return void 0;
2324
+ if (Node.isImportSpecifier(parent) || Node.isNamespaceImport(parent) || Node.isImportClause(parent)) return "";
2325
+ if (Node.isCallExpression(parent) && parent.getExpression() === identifier) return literalPath(parent);
2326
+ if (!Node.isPropertyAccessExpression(parent) || parent.getExpression() !== identifier) return void 0;
2327
+ const property = parent.getNameNode().getText();
2328
+ const grandParent = parent.getParent();
2329
+ if (property === "var" || property === "value") return Node.isCallExpression(grandParent) && grandParent.getExpression() === parent ? literalPath(grandParent) : void 0;
2330
+ if (property !== "token") return void 0;
2331
+ if (Node.isCallExpression(grandParent) && grandParent.getExpression() === parent) return literalPath(grandParent);
2332
+ if (Node.isPropertyAccessExpression(grandParent) && grandParent.getExpression() === parent) {
2333
+ const method = grandParent.getNameNode().getText();
2334
+ if (method !== "var" && method !== "value") return void 0;
2335
+ const call = grandParent.getParent();
2336
+ return Node.isCallExpression(call) && call.getExpression() === grandParent ? literalPath(call) : void 0;
2337
+ }
2338
+ }
2339
+ /**
2340
+ * The path a call asks for, when the first argument is a literal.
2341
+ *
2342
+ * Read through `getLiteralValue()`, never off the source text. The text carries escapes —
2343
+ * `token('colors.red.300')` — and a path recorded raw looks up nothing, which
2344
+ * would accept a reference and keep no declaration for it. That is the exact failure this
2345
+ * module exists to make unrepresentable.
2346
+ */
2347
+ function literalPath(call) {
2348
+ if (!Node.isCallExpression(call)) return void 0;
2349
+ const argument = call.getArguments()[0];
2350
+ if (!argument) return void 0;
2351
+ if (Node.isStringLiteral(argument)) return argument.getLiteralValue();
2352
+ if (Node.isNoSubstitutionTemplateLiteral(argument)) return argument.getLiteralValue();
2353
+ }
2354
+ //#endregion
2102
2355
  //#region src/token-references.ts
2103
2356
  /**
2104
2357
  * `token.var('colors.red.300')` and `token('spacing.4')`, including the whitespace a
2105
- * formatter may leave behind. The parser already reports `token()` calls and resolves
2106
- * constants and template literals through them, but it does not match `token.var()`,
2107
- * whose callee is a property access. Scanning the text covers that, and covers a path
2108
- * built somewhere the extractor cannot follow.
2358
+ * formatter may leave behind. The parser reports both, resolving constants and template
2359
+ * literals through them — `token.var()` included, since it is recorded as its own kind
2360
+ * rather than dropped for having a property access as its callee. Scanning the text still
2361
+ * earns its place twice over: it covers a path built somewhere the extractor cannot
2362
+ * follow, and it covers the callers below that supply no `results` at all.
2363
+ */
2364
+ const TOKEN_CALL = /\btoken(?:\s*\.\s*(?:var|value))?\s*\(\s*['"`]([^'"`]+)['"`]/g;
2365
+ /**
2366
+ * A token reached from javascript at all — a call of any shape, or an import of the artifact.
2367
+ *
2368
+ * Has to stay a strict superset of `TOKEN_CALL`: it must match wherever that one matches, and
2369
+ * also wherever that one gives up. See `collectTokenReferences` for why the redundancy holds.
2370
+ * No `g` flag, so `test` carries no state between files.
2109
2371
  */
2110
- const TOKEN_CALL = /\btoken(?:\s*\.\s*var)?\s*\(\s*['"`]([^'"`]+)['"`]/g;
2372
+ const REACHABLE_FROM_JS = /\btoken(\s*\.\s*(?:var|value))?\s*\(|\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2111
2373
  /**
2112
2374
  * The text of every file `include` covers — as written on disk, and, when they differ, as the
2113
2375
  * parser understands it.
@@ -2128,60 +2390,58 @@ const TOKEN_CALL = /\btoken(?:\s*\.\s*var)?\s*\(\s*['"`]([^'"`]+)['"`]/g;
2128
2390
  * is an order of magnitude more.
2129
2391
  */
2130
2392
  function* sourceTexts(ctx) {
2131
- for (const file of ctx.getFiles()) {
2132
- const filePath = ctx.runtime.path.abs(ctx.config.cwd, file);
2133
- let onDisk;
2134
- try {
2135
- onDisk = ctx.runtime.fs.readFileSync(filePath);
2136
- } catch {
2137
- onDisk = void 0;
2138
- }
2139
- const parsed = ctx.project.getSourceFile(filePath)?.getFullText();
2140
- if (onDisk != null) yield onDisk;
2141
- if (parsed != null && parsed !== onDisk) yield parsed;
2142
- }
2393
+ for (const snapshot of sourceSnapshots(ctx)) yield* snapshotTexts(snapshot);
2143
2394
  }
2144
2395
  /**
2145
- * Collect token references that reading the generated css cannot reveal.
2396
+ * The token prune, as all three build paths need to run it.
2146
2397
  *
2147
- * This is deliberately textual and therefore over-inclusive: a match inside a comment or
2148
- * a string that is never evaluated keeps a token alive. Keeping a token that is not used
2149
- * costs bytes; dropping one that is breaks the page, so the bias belongs on this side.
2398
+ * One function because it was three copies of one conditional, and the `false` branch went
2399
+ * missing from a copy: a watch rebuild with `pruneUnusedTokens: false` skipped `pruneTokens`
2400
+ * altogether, so it kept `@property` registrations that a full build of the same source
2401
+ * strips. The other two copies carried a comment pointing at that file for the reasoning,
2402
+ * which is how a missing branch reads as intentional.
2150
2403
  *
2151
- * `results` is a second, redundant source for the same paths: the extractor resolves one
2152
- * built from a constant, which the text scan reads literally and fails to look up. Callers
2153
- * that cannot supply it — the watch rebuild and the PostCSS plugin, where re-parsing would
2154
- * encode every style a second time — pass none, and stay correct only because a path the
2155
- * scan misses can lose nothing: `token()` hands javascript a literal for exactly the
2156
- * tokens this cannot see, and hands it a `var()` only for virtual, conditional and
2157
- * negative tokens, which `getAlwaysKeptTokenVars` keeps.
2158
- *
2159
- * Those blanket keeps are no longer unconditional — `tokensReachableFromJs` gates them — and
2160
- * this comment used to warn that narrowing them would break the argument above. It does not,
2161
- * for a reason worth stating rather than rediscovering: the gate matches `token(` regardless
2162
- * of what follows, where `TOKEN_CALL` below needs a string literal. So the one shape this
2163
- * scan cannot resolve, a path built from a constant, is exactly the shape that turns the
2164
- * gate on and restores every blanket keep. The two failures line up, which is what makes the
2165
- * redundancy hold.
2166
- *
2167
- * That alignment is a real coupling, not an observation: the gate's call pattern has to stay
2168
- * a superset of this one, matching wherever `TOKEN_CALL` matches and also wherever it gives
2169
- * up. It briefly was not — this allowed whitespace around the `.` of `token.var` and the gate
2170
- * did not, so a formatter wrapping `token\n .var(SOME_CONST)` slipped past both. Change one
2171
- * of the two and change the other; `token-references.test.ts` pins the property directly.
2172
- *
2173
- * Where it stops holding is a binding renamed away from `token` — `const t = token`, then
2174
- * `t('spacing.4')` — which matches neither. `token-references.test.ts` pins both halves.
2404
+ * Opting out still drops the registrations. Those are not tokens — nothing hands one to
2405
+ * javascript, and none appear in the `token()` surface — so the reachability problem the flag
2406
+ * exists for does not apply to them, and opting out of token pruning should not mean shipping
2407
+ * a preset's whole filter and gradient set for nothing.
2175
2408
  */
2176
- function collectTokenReferences(ctx, results) {
2409
+ function pruneTokensForBuild(ctx, sheet, results) {
2410
+ if (!ctx.config.pruneUnusedTokens) {
2411
+ ctx.pruneTokens(sheet);
2412
+ return;
2413
+ }
2414
+ const strict = ctx.config.pruneUnusedTokens === "strict";
2177
2415
  const paths = /* @__PURE__ */ new Set();
2178
2416
  const vars = /* @__PURE__ */ new Set();
2417
+ const accounting = {
2418
+ paths: /* @__PURE__ */ new Set(),
2419
+ declined: []
2420
+ };
2421
+ let reachable = false;
2179
2422
  for (const result of results) for (const item of result.token) for (const value of item.data ?? []) if (typeof value === "string") paths.add(value);
2180
- for (const content of sourceTexts(ctx)) {
2181
- for (const match of content.matchAll(TOKEN_CALL)) paths.add(match[1]);
2182
- for (const name of cssVarRefs(content)) vars.add(name);
2423
+ for (const snapshot of sourceSnapshots(ctx)) {
2424
+ for (const text of snapshotTexts(snapshot)) {
2425
+ for (const match of text.matchAll(TOKEN_CALL)) paths.add(match[1]);
2426
+ for (const name of cssVarRefs(text)) vars.add(name);
2427
+ if (!reachable && REACHABLE_FROM_JS.test(text)) reachable = true;
2428
+ }
2429
+ if (strict) accountSnapshot(ctx, snapshot, accounting);
2183
2430
  }
2431
+ for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
2432
+ if (!strict) {
2433
+ ctx.pruneTokens(sheet, vars, reachable);
2434
+ return;
2435
+ }
2436
+ for (const name of tokenVarsFor(ctx, accounting.paths)) vars.add(name);
2437
+ if (accounting.declined.length) logger.warn("tokens:strict", formatDeclined(ctx, accounting.declined));
2438
+ ctx.pruneTokens(sheet, vars, accounting.declined.length > 0 && reachable);
2439
+ }
2440
+ /** The custom properties a set of token paths resolves to. */
2441
+ function tokenVarsFor(ctx, paths) {
2442
+ const vars = /* @__PURE__ */ new Set();
2184
2443
  for (const path of paths) {
2444
+ if (!path) continue;
2185
2445
  const ref = ctx.tokens.view.getVar(path);
2186
2446
  if (!ref) continue;
2187
2447
  for (const name of cssVarRefs(ref)) vars.add(name);
@@ -2189,6 +2449,25 @@ function collectTokenReferences(ctx, results) {
2189
2449
  return vars;
2190
2450
  }
2191
2451
  /**
2452
+ * Why `strict` could not prune, grouped by file.
2453
+ *
2454
+ * Printed rather than thrown. A decline is not an error — the build falls back to keeping
2455
+ * every declaration, which is what would have happened anyway — it is the answer to "why is my
2456
+ * token layer still this size", which otherwise has no answer at all.
2457
+ */
2458
+ function formatDeclined(ctx, declined) {
2459
+ const byFile = /* @__PURE__ */ new Map();
2460
+ for (const entry of declined) {
2461
+ const list = byFile.get(entry.filePath) ?? [];
2462
+ list.push(entry);
2463
+ byFile.set(entry.filePath, list);
2464
+ }
2465
+ const detail = Array.from(byFile.entries()).map(([filePath, entries]) => {
2466
+ return [` ${filePath.startsWith(ctx.config.cwd) ? filePath.slice(ctx.config.cwd.length + 1) : filePath}`, ...entries.map((entry) => ` ${entry.line}: ${entry.reason}`)].join("\n");
2467
+ }).join("\n");
2468
+ return `${declined.length} token reference(s) could not be resolved, so every token declaration is kept.\n\n${detail}\n\nSpell the path as a string literal at the call, move it into \`staticCss\`, or set \`pruneUnusedTokens: true\` to stop asking.`;
2469
+ }
2470
+ /**
2192
2471
  * Collect keyframe names that reading the generated css cannot reveal.
2193
2472
  *
2194
2473
  * A keyframe reached through `css({ animation: 'fade-in 1s' })` lands in the stylesheet
@@ -2246,41 +2525,6 @@ function collectRenderedElements(ctx) {
2246
2525
  for (const content of sourceTexts(ctx)) for (const match of content.matchAll(/<\s*([a-z][\w-]*)(?=[\s/>]|$)/g)) found.add(match[1].toLowerCase());
2247
2526
  return found;
2248
2527
  }
2249
- /**
2250
- * Whether any source file reaches for a token from javascript.
2251
- *
2252
- * The tokens artifact is generated into the project rather than installed, so the import is
2253
- * written in the project's own source and a scan of `include` sees it. When this comes back
2254
- * false, the declarations kept purely so `token()` can answer have no caller to answer.
2255
- *
2256
- * Deliberately loose, and loose in a specific direction: a false positive keeps a declaration
2257
- * nothing reads, a false negative returns a `var()` nothing declares.
2258
- *
2259
- * So the import test is any module specifier with a `/tokens` path segment, rather than the
2260
- * literal `styled-system/tokens` it used to be. `outdir` is configurable, so the artifact is
2261
- * only at `styled-system/` by default, and the literal missed `outdir: 'design-system'`, a
2262
- * tsconfig path alias, and `styled-system/tokens/index.mjs` -- which is the only spelling
2263
- * NodeNext accepts, the artifact being a directory. It is still anchored to `from`, `import`
2264
- * or `require`, because without that anchor a route or a url (`fetch('/api/tokens')`) reads
2265
- * as an import and quietly switches the whole optimisation off.
2266
- *
2267
- * The call test allows whitespace around the dot for the same reason `TOKEN_CALL` does. It
2268
- * did not, which broke the alignment the note on `collectTokenReferences` rests on: a
2269
- * formatter wrapping `token\n .var(SOME_CONST)` was invisible to that scan *and* to this
2270
- * gate *and* to the parser, whose callee is a property access. A comment in the same position
2271
- * -- `token/*x*\/.var(` -- is still invisible to all three.
2272
- *
2273
- * One shape it still does not see, pinned in `token-references.test.ts`: a binding renamed
2274
- * away from `token`, as in `const t = token`. Also unseen is a caller outside `include`,
2275
- * which scopes style extraction rather than everything that may import — a script, a config,
2276
- * or a sibling workspace package. Both prune declarations the running app then asks for, and
2277
- * neither reports itself; `pruneUnusedTokens: false` is the way out.
2278
- */
2279
- function tokensReachableFromJs(ctx) {
2280
- const pattern = /\btoken(\s*\.\s*var)?\s*\(|\b(?:from|import|require)\s*\(?\s*['"][^'"]*\/tokens(\/[^'"]*|\.[cm]?[jt]sx?)?['"]/;
2281
- for (const content of sourceTexts(ctx)) if (pattern.test(content)) return true;
2282
- return false;
2283
- }
2284
2528
  //#endregion
2285
2529
  //#region src/builder.ts
2286
2530
  const fileModifiedMap = /* @__PURE__ */ new Map();
@@ -2463,8 +2707,7 @@ var Builder = class {
2463
2707
  const sheet = ctx.createSheet();
2464
2708
  if (layerParams) ctx.appendLayerParams(sheet);
2465
2709
  ctx.appendBaselineCss(sheet);
2466
- if (ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, []), tokensReachableFromJs(ctx));
2467
- else ctx.pruneTokens(sheet);
2710
+ pruneTokensForBuild(ctx, sheet, []);
2468
2711
  if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2469
2712
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2470
2713
  return ctx.getCss(sheet);
@@ -2569,8 +2812,7 @@ const cssgen = async (ctx, options) => {
2569
2812
  ctx.appendBaselineCss(sheet);
2570
2813
  }
2571
2814
  ctx.appendParserCss(sheet);
2572
- if (!minimal && ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, results), tokensReachableFromJs(ctx));
2573
- else if (!minimal) ctx.pruneTokens(sheet);
2815
+ if (!minimal) pruneTokensForBuild(ctx, sheet, results);
2574
2816
  if (!minimal && ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2575
2817
  if (!minimal && ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2576
2818
  if (splitting) await ctx.writeSplitCss(sheet);
@@ -2642,8 +2884,7 @@ async function build(ctx, artifactIds) {
2642
2884
  ctx.appendBaselineCss(sheet);
2643
2885
  const parsed = ctx.parseFiles();
2644
2886
  ctx.appendParserCss(sheet);
2645
- if (ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, parsed.results), tokensReachableFromJs(ctx));
2646
- else ctx.pruneTokens(sheet);
2887
+ pruneTokensForBuild(ctx, sheet, parsed.results);
2647
2888
  if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2648
2889
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2649
2890
  await ctx.writeCss(sheet);
@@ -2689,7 +2930,7 @@ async function generate(config, configPath) {
2689
2930
  ctx.appendLayerParams(sheet);
2690
2931
  ctx.appendBaselineCss(sheet);
2691
2932
  ctx.appendParserCss(sheet);
2692
- if (ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, []), tokensReachableFromJs(ctx));
2933
+ pruneTokensForBuild(ctx, sheet, []);
2693
2934
  if (ctx.config.prunePreflight) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
2694
2935
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2695
2936
  const css = ctx.getCss(sheet);
@@ -2793,7 +3034,7 @@ export default defineConfig({
2793
3034
 
2794
3035
  // Tokens, keyframes and @property rules nothing in the emitted css reaches are dropped
2795
3036
  // by default — worth 36-78% of a new project's stylesheet. Set \`pruneUnusedTokens: false\`
2796
- // if you read tokens from somewhere the build cannot see them — \`token.var()\` with a
3037
+ // if you read tokens from somewhere the build cannot see them — \`token()\` with a
2797
3038
  // computed path, or a hand-written stylesheet outside \`include\` — or list those under
2798
3039
  // \`staticCss\` to keep them.
2799
3040
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/node",
3
- "version": "1.28.0",
3
+ "version": "1.29.0",
4
4
  "description": "The core css bamboo library",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
@@ -52,18 +52,18 @@
52
52
  "postcss": "8.5.26",
53
53
  "ts-morph": "28.0.0",
54
54
  "ts-pattern": "5.9.0",
55
- "@bamboocss/config": "1.28.0",
56
- "@bamboocss/core": "1.28.0",
57
- "@bamboocss/generator": "1.28.0",
58
- "@bamboocss/logger": "1.28.0",
59
- "@bamboocss/parser": "1.28.0",
60
- "@bamboocss/plugin-lightningcss": "1.28.0",
61
- "@bamboocss/plugin-svelte": "1.28.0",
62
- "@bamboocss/plugin-vue": "1.28.0",
63
- "@bamboocss/reporter": "1.28.0",
64
- "@bamboocss/shared": "1.28.0",
65
- "@bamboocss/token-dictionary": "1.28.0",
66
- "@bamboocss/types": "1.28.0"
55
+ "@bamboocss/config": "1.29.0",
56
+ "@bamboocss/core": "1.29.0",
57
+ "@bamboocss/generator": "1.29.0",
58
+ "@bamboocss/logger": "1.29.0",
59
+ "@bamboocss/parser": "1.29.0",
60
+ "@bamboocss/plugin-lightningcss": "1.29.0",
61
+ "@bamboocss/plugin-svelte": "1.29.0",
62
+ "@bamboocss/plugin-vue": "1.29.0",
63
+ "@bamboocss/reporter": "1.29.0",
64
+ "@bamboocss/shared": "1.29.0",
65
+ "@bamboocss/token-dictionary": "1.29.0",
66
+ "@bamboocss/types": "1.29.0"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/fs-extra": "11.0.4",