css-typed-vars 0.11.0 → 0.12.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/README.md CHANGED
@@ -144,6 +144,7 @@ npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prune-check
144
144
  | `--prune-check` | Like `--prune`, but only reports unused vars without writing; exits 1 if any are found. Doesn't need `--output`. Useful in CI. |
145
145
  | `--lint-refs` | Report `var(--name)` references to variables not declared anywhere in the input; exits 1 if any (without a fallback) are found — see [Linting var() references](#linting-var-references) |
146
146
  | `--refs-ignore` | Name or `--prefix-*` pattern for `--lint-refs` to skip (repeatable) |
147
+ | `--refs-source` | Source files whose `var()` references `--lint-refs` checks too (repeatable) — see [below](#in-source-files) |
147
148
  | `--usage` | Glob of source files to scan for `cssVars` usage, for `--prune`/`--prune-check` (repeatable) |
148
149
  | `--usage-exclude` | Glob of source files to exclude from the usage scan (repeatable) |
149
150
  | `--watch` | Watch the `input` files (and, with `--prune`, the `--usage` files) and regenerate on change |
@@ -183,6 +184,24 @@ css-typed-vars: 2 reference(s) to undeclared variables:
183
184
  - References inside comments and strings are ignored; positions point to the original file.
184
185
  - Variables set from JavaScript or defined by another stylesheet you don't scan can be skipped with `--refs-ignore` (repeatable, a trailing `*` matches a prefix): `--refs-ignore "--tw-*" --refs-ignore --app-height`, or `refsIgnore` in the config file.
185
186
 
187
+ #### In source files
188
+
189
+ `var(--name)` strings in components are just as easy to get wrong. Add `--refs-source` (repeatable, or `refsSource` in the config file) to check them against the same declarations:
190
+
191
+ ```sh
192
+ npx css-typed-vars --input "src/**/*.css" --lint-refs --refs-source "src/**/*.{ts,tsx,vue,html}"
193
+ ```
194
+
195
+ ```
196
+ css-typed-vars: 1 reference(s) to undeclared variables:
197
+ src/Card.tsx:14:22 var(--colr-primary)
198
+ ```
199
+
200
+ - Finds `var(--name)` anywhere in the file — in strings, template literals, Tailwind classes like `bg-[var(--brand)]` — and Tailwind v4's `bg-(--brand)` shorthand.
201
+ - Variables a source file sets itself count as declared: an object key (`{ '--gap': '4px' }`), a `style` attribute (`style="--gap: 4px"`), `setProperty('--gap', ...)` or a Tailwind arbitrary property (`[--gap:4px]`). This applies to the CSS references too.
202
+ - Like the `--prune` usage scan, this is textual: a reference inside a comment counts too.
203
+ - The target's own output file is skipped even if the glob matches it — `--check` is what tells whether it's stale.
204
+
186
205
  ### Config file
187
206
 
188
207
  The CLI looks for a config file in the current working directory (in order):
@@ -212,6 +231,7 @@ export default defineConfig({
212
231
  group: false,
213
232
  helpers: false,
214
233
  refsIgnore: ['--tw-*'],
234
+ refsSource: 'src/**/*.{ts,tsx}',
215
235
  prune: false,
216
236
  usage: 'src/**/*.{ts,tsx}',
217
237
  });
@@ -439,7 +459,7 @@ await generate({
439
459
 
440
460
  `checkGenerated(options)` takes the same options and returns `Promise<boolean>` — `true` if the existing output already matches what would be generated, without writing anything. Same thing `--check` does on the CLI.
441
461
 
442
- `findUndefinedRefs({ input, exclude?, refsIgnore? })` returns `Promise<FileReference[]>` — each undeclared `var()` reference with its `file`, `line`, `column` and `hasFallback`. Same thing `--lint-refs` does on the CLI.
462
+ `findUndefinedRefs({ input, exclude?, refsIgnore?, refsSource? })` returns `Promise<FileReference[]>` — each undeclared `var()` reference with its `file`, `line`, `column` and `hasFallback`. Same thing `--lint-refs` does on the CLI.
443
463
 
444
464
  `findUnusedVars(options)` takes `input`/`exclude`/`selectors`/`prefix`/`naming`/`group`/`usage`/`usageExclude` and returns `Promise<string[]>` — the CSS variable names with no detected `cssVars.<key>` usage, without writing or pruning anything. Same thing `--prune-check` does on the CLI.
445
465
 
@@ -461,6 +481,8 @@ By default, variables are scanned from `:root {}` blocks (including attribute se
461
481
 
462
482
  ## Theme values
463
483
 
484
+ When a variable is declared in several files, the last file read wins. Files are read in `input` order (a file matched by several globs counts at the last one), and within a glob a directory's files come before its subdirectories', alphabetically — so `styles/themes/dark.css` overrides `styles/tokens.css`.
485
+
464
486
  By default, a variable redeclared in another block (`:root[data-theme="dark"]`, or a `selectors` entry) simply overwrites its `@default` value — last one wins. The `themes` option names those blocks instead, so each theme's value is kept separately:
465
487
 
466
488
  ```js
@@ -315,6 +315,29 @@ function parseVarReferences(css) {
315
315
  }
316
316
  return refs;
317
317
  }
318
+ var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(,)?|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
319
+ function parseSourceVarReferences(text) {
320
+ const lineStarts = [0];
321
+ for (let i = 0; i < text.length; i++) if (text[i] === "\n") lineStarts.push(i + 1);
322
+ const refs = [];
323
+ for (const match of text.matchAll(SOURCE_REF_RE)) {
324
+ let line = lineStarts.length - 1;
325
+ while (lineStarts[line] > match.index) line--;
326
+ refs.push({
327
+ name: match[1] ?? match[3],
328
+ hasFallback: match[2] === ",",
329
+ line: line + 1,
330
+ column: match.index - lineStarts[line] + 1
331
+ });
332
+ }
333
+ return refs;
334
+ }
335
+ function parseSourceDeclaredNames(text) {
336
+ const names = /* @__PURE__ */ new Set();
337
+ for (const match of text.matchAll(/(?<![\w-])(--[\w-]+)['"`]?\s*:/g)) names.add(match[1]);
338
+ for (const match of text.matchAll(/\bsetProperty\(\s*['"`](--[\w-]+)['"`]/g)) names.add(match[1]);
339
+ return names;
340
+ }
318
341
  function parseDeclaredNames(css) {
319
342
  const masked = maskQuotedContent(stripComments(css));
320
343
  const names = /* @__PURE__ */ new Set();
@@ -325,12 +348,45 @@ function parseDeclaredNames(css) {
325
348
 
326
349
  // src/scanner.ts
327
350
  import { readFile as readFile2 } from "fs/promises";
328
- import { dirname as dirname2, relative, resolve } from "path";
329
- import fg from "fast-glob";
351
+ import { dirname as dirname2, posix, relative, resolve } from "path";
330
352
  import picomatch from "picomatch";
353
+ import { glob } from "tinyglobby";
331
354
  function normalizePatterns(patterns) {
332
355
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
333
356
  }
357
+ function comparePaths(a, b) {
358
+ const as = a.split("/");
359
+ const bs = b.split("/");
360
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
361
+ if (as[i] === bs[i]) continue;
362
+ const aIsFile = i === as.length - 1;
363
+ const bIsFile = i === bs.length - 1;
364
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
365
+ return as[i] < bs[i] ? -1 : 1;
366
+ }
367
+ return as.length - bs.length;
368
+ }
369
+ async function globFiles(pattern, ignore) {
370
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
371
+ return glob(pattern, { absolute: true, ignore, expandDirectories: false });
372
+ }
373
+ const { base, glob: rest, isGlob } = picomatch.scan(pattern);
374
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [posix.dirname(pattern), posix.basename(pattern)];
375
+ const matches = await glob(relativeGlob, { cwd, absolute: true, expandDirectories: false });
376
+ if (ignore.length === 0) return matches;
377
+ const isIgnored = picomatch(ignore, { dot: true });
378
+ return matches.filter((file) => !isIgnored(file));
379
+ }
380
+ async function findFiles(patterns, exclude) {
381
+ const normalized = normalizePatterns(patterns);
382
+ const ignore = [
383
+ ...exclude ? normalizePatterns(exclude) : [],
384
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
385
+ ];
386
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
387
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
388
+ return [...new Set(files.reverse())].reverse();
389
+ }
334
390
  function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
335
391
  const compile = (globs) => picomatch(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
336
392
  const include = compile(patterns);
@@ -345,9 +401,9 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
345
401
  function globWatchRoots(patterns, cwd = process.cwd()) {
346
402
  const roots = /* @__PURE__ */ new Map();
347
403
  for (const pattern of normalizePatterns(patterns)) {
348
- const { base, glob, isGlob } = picomatch.scan(pattern);
404
+ const { base, glob: glob2, isGlob } = picomatch.scan(pattern);
349
405
  const dir = resolve(cwd, isGlob ? base || "." : dirname2(pattern));
350
- const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob) ? void 0 : glob.split("/").length - 1;
406
+ const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
351
407
  const previous = roots.get(dir);
352
408
  const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
353
409
  roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
@@ -365,9 +421,7 @@ function collectVarNames(scanned) {
365
421
  return [...names].sort();
366
422
  }
367
423
  async function scanCss(patterns, exclude, selectors, themes = {}) {
368
- const normalized = normalizePatterns(patterns);
369
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
370
- const files = await fg(normalized, { absolute: true, ignore: normalizedExclude });
424
+ const files = await findFiles(patterns, exclude);
371
425
  const perFile = await Promise.all(
372
426
  files.map(async (file) => {
373
427
  let css;
@@ -431,9 +485,7 @@ function extractUsage(text, into) {
431
485
  }
432
486
  }
433
487
  async function scanUsage(patterns, exclude) {
434
- const normalized = normalizePatterns(patterns);
435
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
436
- const files = await fg(normalized, { absolute: true, ignore: normalizedExclude });
488
+ const files = await findFiles(patterns, exclude);
437
489
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
438
490
  const texts = await Promise.all(
439
491
  files.map(async (file) => {
@@ -448,10 +500,10 @@ async function scanUsage(patterns, exclude) {
448
500
  for (const text of texts) extractUsage(text, usage);
449
501
  return usage;
450
502
  }
451
- async function scanReferences(patterns, exclude) {
452
- const normalized = normalizePatterns(patterns);
453
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
454
- const files = (await fg(normalized, { absolute: true, ignore: normalizedExclude })).sort();
503
+ async function scanReferences(patterns, exclude, source = false) {
504
+ const parseReferences = source ? parseSourceVarReferences : parseVarReferences;
505
+ const parseDeclared = source ? parseSourceDeclaredNames : parseDeclaredNames;
506
+ const files = (await findFiles(patterns, exclude)).sort();
455
507
  const perFile = await Promise.all(
456
508
  files.map(async (file) => {
457
509
  try {
@@ -466,8 +518,8 @@ async function scanReferences(patterns, exclude) {
466
518
  const declared = /* @__PURE__ */ new Set();
467
519
  for (const result of perFile) {
468
520
  if (!result) continue;
469
- for (const ref of parseVarReferences(result.css)) references.push({ ...ref, file: result.file });
470
- for (const name of parseDeclaredNames(result.css)) declared.add(name);
521
+ for (const ref of parseReferences(result.css)) references.push({ ...ref, file: result.file });
522
+ for (const name of parseDeclared(result.css)) declared.add(name);
471
523
  }
472
524
  return { references, declared };
473
525
  }
@@ -11,7 +11,7 @@ import {
11
11
  scanUsage,
12
12
  warnOnCollisions,
13
13
  writeOutput
14
- } from "./chunk-TR53YUPE.js";
14
+ } from "./chunk-RZLASYCF.js";
15
15
 
16
16
  // src/index.ts
17
17
  import { readFile } from "fs/promises";
@@ -32,9 +32,13 @@ function matchesIgnore(name, patterns) {
32
32
  return patterns.some((pattern) => pattern.endsWith("*") ? name.startsWith(pattern.slice(0, -1)) : name === pattern);
33
33
  }
34
34
  async function findUndefinedRefs(options) {
35
- const { references, declared } = await scanReferences(options.input, options.exclude);
35
+ const [css, source] = await Promise.all([
36
+ scanReferences(options.input, options.exclude),
37
+ options.refsSource ? scanReferences(options.refsSource, void 0, true) : null
38
+ ]);
39
+ const declared = /* @__PURE__ */ new Set([...css.declared, ...source?.declared ?? []]);
36
40
  const ignore = options.refsIgnore ?? [];
37
- return references.filter((ref) => !declared.has(ref.name) && !matchesIgnore(ref.name, ignore));
41
+ return [...css.references, ...source?.references ?? []].filter((ref) => !declared.has(ref.name) && !matchesIgnore(ref.name, ignore));
38
42
  }
39
43
  async function computeOutputs(options) {
40
44
  assertPruneCompatible(options);
@@ -12,7 +12,7 @@ import {
12
12
  scanUsage,
13
13
  warnOnCollisions,
14
14
  writeOutput
15
- } from "./chunk-TR53YUPE.js";
15
+ } from "./chunk-RZLASYCF.js";
16
16
 
17
17
  // src/unplugin.ts
18
18
  import { createUnplugin } from "unplugin";
package/dist/cli.cjs CHANGED
@@ -36,8 +36,8 @@ var import_chokidar = require("chokidar");
36
36
  // src/scanner.ts
37
37
  var import_promises = require("fs/promises");
38
38
  var import_node_path = require("path");
39
- var import_fast_glob = __toESM(require("fast-glob"), 1);
40
39
  var import_picomatch = __toESM(require("picomatch"), 1);
40
+ var import_tinyglobby = require("tinyglobby");
41
41
 
42
42
  // src/parser.ts
43
43
  function stepQuote(text, i, quote) {
@@ -328,6 +328,29 @@ function parseVarReferences(css) {
328
328
  }
329
329
  return refs;
330
330
  }
331
+ var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(,)?|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
332
+ function parseSourceVarReferences(text) {
333
+ const lineStarts = [0];
334
+ for (let i = 0; i < text.length; i++) if (text[i] === "\n") lineStarts.push(i + 1);
335
+ const refs = [];
336
+ for (const match of text.matchAll(SOURCE_REF_RE)) {
337
+ let line = lineStarts.length - 1;
338
+ while (lineStarts[line] > match.index) line--;
339
+ refs.push({
340
+ name: match[1] ?? match[3],
341
+ hasFallback: match[2] === ",",
342
+ line: line + 1,
343
+ column: match.index - lineStarts[line] + 1
344
+ });
345
+ }
346
+ return refs;
347
+ }
348
+ function parseSourceDeclaredNames(text) {
349
+ const names = /* @__PURE__ */ new Set();
350
+ for (const match of text.matchAll(/(?<![\w-])(--[\w-]+)['"`]?\s*:/g)) names.add(match[1]);
351
+ for (const match of text.matchAll(/\bsetProperty\(\s*['"`](--[\w-]+)['"`]/g)) names.add(match[1]);
352
+ return names;
353
+ }
331
354
  function parseDeclaredNames(css) {
332
355
  const masked = maskQuotedContent(stripComments(css));
333
356
  const names = /* @__PURE__ */ new Set();
@@ -340,6 +363,39 @@ function parseDeclaredNames(css) {
340
363
  function normalizePatterns(patterns) {
341
364
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
342
365
  }
366
+ function comparePaths(a, b) {
367
+ const as = a.split("/");
368
+ const bs = b.split("/");
369
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
370
+ if (as[i] === bs[i]) continue;
371
+ const aIsFile = i === as.length - 1;
372
+ const bIsFile = i === bs.length - 1;
373
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
374
+ return as[i] < bs[i] ? -1 : 1;
375
+ }
376
+ return as.length - bs.length;
377
+ }
378
+ async function globFiles(pattern, ignore) {
379
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
380
+ return (0, import_tinyglobby.glob)(pattern, { absolute: true, ignore, expandDirectories: false });
381
+ }
382
+ const { base, glob: rest, isGlob } = import_picomatch.default.scan(pattern);
383
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [import_node_path.posix.dirname(pattern), import_node_path.posix.basename(pattern)];
384
+ const matches = await (0, import_tinyglobby.glob)(relativeGlob, { cwd, absolute: true, expandDirectories: false });
385
+ if (ignore.length === 0) return matches;
386
+ const isIgnored = (0, import_picomatch.default)(ignore, { dot: true });
387
+ return matches.filter((file) => !isIgnored(file));
388
+ }
389
+ async function findFiles(patterns, exclude) {
390
+ const normalized = normalizePatterns(patterns);
391
+ const ignore = [
392
+ ...exclude ? normalizePatterns(exclude) : [],
393
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
394
+ ];
395
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
396
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
397
+ return [...new Set(files.reverse())].reverse();
398
+ }
343
399
  function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
344
400
  const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
345
401
  const include = compile(patterns);
@@ -354,9 +410,9 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
354
410
  function globWatchRoots(patterns, cwd = process.cwd()) {
355
411
  const roots = /* @__PURE__ */ new Map();
356
412
  for (const pattern of normalizePatterns(patterns)) {
357
- const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
413
+ const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
358
414
  const dir = (0, import_node_path.resolve)(cwd, isGlob ? base || "." : (0, import_node_path.dirname)(pattern));
359
- const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob) ? void 0 : glob.split("/").length - 1;
415
+ const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
360
416
  const previous = roots.get(dir);
361
417
  const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
362
418
  roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
@@ -371,9 +427,7 @@ function collectVarNames(scanned) {
371
427
  return [...names].sort();
372
428
  }
373
429
  async function scanCss(patterns, exclude, selectors, themes = {}) {
374
- const normalized = normalizePatterns(patterns);
375
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
376
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
430
+ const files = await findFiles(patterns, exclude);
377
431
  const perFile = await Promise.all(
378
432
  files.map(async (file) => {
379
433
  let css;
@@ -430,9 +484,7 @@ function extractUsage(text, into) {
430
484
  }
431
485
  }
432
486
  async function scanUsage(patterns, exclude) {
433
- const normalized = normalizePatterns(patterns);
434
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
435
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
487
+ const files = await findFiles(patterns, exclude);
436
488
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
437
489
  const texts = await Promise.all(
438
490
  files.map(async (file) => {
@@ -447,10 +499,10 @@ async function scanUsage(patterns, exclude) {
447
499
  for (const text of texts) extractUsage(text, usage);
448
500
  return usage;
449
501
  }
450
- async function scanReferences(patterns, exclude) {
451
- const normalized = normalizePatterns(patterns);
452
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
453
- const files = (await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude })).sort();
502
+ async function scanReferences(patterns, exclude, source = false) {
503
+ const parseReferences = source ? parseSourceVarReferences : parseVarReferences;
504
+ const parseDeclared = source ? parseSourceDeclaredNames : parseDeclaredNames;
505
+ const files = (await findFiles(patterns, exclude)).sort();
454
506
  const perFile = await Promise.all(
455
507
  files.map(async (file) => {
456
508
  try {
@@ -465,8 +517,8 @@ async function scanReferences(patterns, exclude) {
465
517
  const declared = /* @__PURE__ */ new Set();
466
518
  for (const result of perFile) {
467
519
  if (!result) continue;
468
- for (const ref of parseVarReferences(result.css)) references.push({ ...ref, file: result.file });
469
- for (const name of parseDeclaredNames(result.css)) declared.add(name);
520
+ for (const ref of parseReferences(result.css)) references.push({ ...ref, file: result.file });
521
+ for (const name of parseDeclared(result.css)) declared.add(name);
470
522
  }
471
523
  return { references, declared };
472
524
  }
@@ -869,9 +921,13 @@ function matchesIgnore(name, patterns) {
869
921
  return patterns.some((pattern) => pattern.endsWith("*") ? name.startsWith(pattern.slice(0, -1)) : name === pattern);
870
922
  }
871
923
  async function findUndefinedRefs(options) {
872
- const { references, declared } = await scanReferences(options.input, options.exclude);
924
+ const [css, source] = await Promise.all([
925
+ scanReferences(options.input, options.exclude),
926
+ options.refsSource ? scanReferences(options.refsSource, void 0, true) : null
927
+ ]);
928
+ const declared = /* @__PURE__ */ new Set([...css.declared, ...source?.declared ?? []]);
873
929
  const ignore = options.refsIgnore ?? [];
874
- return references.filter((ref) => !declared.has(ref.name) && !matchesIgnore(ref.name, ignore));
930
+ return [...css.references, ...source?.references ?? []].filter((ref) => !declared.has(ref.name) && !matchesIgnore(ref.name, ignore));
875
931
  }
876
932
  async function computeOutputs(options) {
877
933
  assertPruneCompatible(options);
@@ -946,7 +1002,8 @@ var CONFIG_KEYS = [
946
1002
  "usage",
947
1003
  "usageExclude",
948
1004
  "helpers",
949
- "refsIgnore"
1005
+ "refsIgnore",
1006
+ "refsSource"
950
1007
  ];
951
1008
 
952
1009
  // src/cli.ts
@@ -982,7 +1039,8 @@ var OPTION_FLAGS = [
982
1039
  "--usage",
983
1040
  "--usage-exclude",
984
1041
  "--helpers",
985
- "--refs-ignore"
1042
+ "--refs-ignore",
1043
+ "--refs-source"
986
1044
  ];
987
1045
  var USAGE = "Usage: css-typed-vars --input <glob> --output <file> [options]";
988
1046
  var VALUE_FLAGS = [
@@ -996,6 +1054,7 @@ var VALUE_FLAGS = [
996
1054
  "--usage",
997
1055
  "--usage-exclude",
998
1056
  "--refs-ignore",
1057
+ "--refs-source",
999
1058
  "--config"
1000
1059
  ];
1001
1060
  var BOOLEAN_FLAGS = [
@@ -1037,6 +1096,7 @@ Modes:
1037
1096
  --prune-check Exit 1 if any var has no cssVars.<key> usage (needs --usage)
1038
1097
  --lint-refs Exit 1 on var() references to undeclared variables
1039
1098
  --refs-ignore <name> Name or --prefix-* pattern for --lint-refs to skip (repeatable)
1099
+ --refs-source <glob> Source files whose var() references --lint-refs checks too (repeatable)
1040
1100
  --version, -v Print the version
1041
1101
  --help, -h Print this help
1042
1102
 
@@ -1130,6 +1190,7 @@ function applyFlags(config) {
1130
1190
  const usageArgs = getArgs("--usage");
1131
1191
  const usageExcludeArgs = getArgs("--usage-exclude");
1132
1192
  const refsIgnoreArgs = getArgs("--refs-ignore");
1193
+ const refsSourceArgs = getArgs("--refs-source");
1133
1194
  return {
1134
1195
  ...config,
1135
1196
  input: inputArgs.length > 0 ? inputArgs : config.input,
@@ -1144,7 +1205,8 @@ function applyFlags(config) {
1144
1205
  usage: usageArgs.length > 0 ? usageArgs : config.usage,
1145
1206
  usageExclude: usageExcludeArgs.length > 0 ? usageExcludeArgs : config.usageExclude,
1146
1207
  helpers: args.includes("--helpers") || config.helpers,
1147
- refsIgnore: refsIgnoreArgs.length > 0 ? refsIgnoreArgs : config.refsIgnore
1208
+ refsIgnore: refsIgnoreArgs.length > 0 ? refsIgnoreArgs : config.refsIgnore,
1209
+ refsSource: refsSourceArgs.length > 0 ? refsSourceArgs : config.refsSource
1148
1210
  };
1149
1211
  }
1150
1212
  function loadTargets(config) {
@@ -1191,8 +1253,15 @@ Or add a css-typed-vars.config.js file with input and output fields. Run with --
1191
1253
  throw new CliError(`${tag}: --prune/--prune-check requires --usage <glob> (source files to scan for cssVars usage).`);
1192
1254
  }
1193
1255
  }
1256
+ function outputPaths(output) {
1257
+ if (!output) return /* @__PURE__ */ new Set();
1258
+ const jsExt = /\.(m|c)?js$/i.exec(output);
1259
+ return new Set([output, ...jsExt ? [output.slice(0, -jsExt[0].length) + ".d.ts"] : []].map((path) => (0, import_node_path4.resolve)(path)));
1260
+ }
1194
1261
  async function lintRefs({ options, tag }) {
1195
- const refs = await findUndefinedRefs({ input: options.input, exclude: options.exclude, refsIgnore: options.refsIgnore });
1262
+ const { input, exclude, refsIgnore, refsSource } = options;
1263
+ const outputs = outputPaths(options.output);
1264
+ const refs = (await findUndefinedRefs({ input, exclude, refsIgnore, refsSource })).filter((ref) => !outputs.has((0, import_node_path4.resolve)(ref.file)));
1196
1265
  const format = (ref) => ` ${(0, import_node_path4.relative)(process.cwd(), ref.file).replace(/\\/g, "/")}:${ref.line}:${ref.column} var(${ref.name}${ref.hasFallback ? ", \u2026" : ""})`;
1197
1266
  const errors = refs.filter((ref) => !ref.hasFallback);
1198
1267
  const warnings = refs.filter((ref) => ref.hasFallback);
@@ -1232,8 +1301,7 @@ async function run({ options }) {
1232
1301
  var toArray = (value) => value === void 0 ? [] : Array.isArray(value) ? value : [value];
1233
1302
  function watchTarget(target) {
1234
1303
  const { input, exclude, output, prune, usage, usageExclude } = target.options;
1235
- const jsExt = /\.(m|c)?js$/i.exec(output);
1236
- const outputs = new Set([output, ...jsExt ? [output.slice(0, -jsExt[0].length) + ".d.ts"] : []].map((path) => (0, import_node_path4.resolve)(path)));
1304
+ const outputs = outputPaths(output);
1237
1305
  let timer = null;
1238
1306
  let running = false;
1239
1307
  let pending = false;
package/dist/cli.js CHANGED
@@ -4,12 +4,12 @@ import {
4
4
  findUndefinedRefs,
5
5
  findUnusedVars,
6
6
  generate
7
- } from "./chunk-P3HJQZ6Y.js";
7
+ } from "./chunk-ULIGESN5.js";
8
8
  import {
9
9
  VALID_NAMINGS,
10
10
  createFileMatcher,
11
11
  globWatchRoots
12
- } from "./chunk-TR53YUPE.js";
12
+ } from "./chunk-RZLASYCF.js";
13
13
 
14
14
  // src/cli.ts
15
15
  import { access, readFile } from "fs/promises";
@@ -31,7 +31,8 @@ var CONFIG_KEYS = [
31
31
  "usage",
32
32
  "usageExclude",
33
33
  "helpers",
34
- "refsIgnore"
34
+ "refsIgnore",
35
+ "refsSource"
35
36
  ];
36
37
 
37
38
  // src/cli.ts
@@ -67,7 +68,8 @@ var OPTION_FLAGS = [
67
68
  "--usage",
68
69
  "--usage-exclude",
69
70
  "--helpers",
70
- "--refs-ignore"
71
+ "--refs-ignore",
72
+ "--refs-source"
71
73
  ];
72
74
  var USAGE = "Usage: css-typed-vars --input <glob> --output <file> [options]";
73
75
  var VALUE_FLAGS = [
@@ -81,6 +83,7 @@ var VALUE_FLAGS = [
81
83
  "--usage",
82
84
  "--usage-exclude",
83
85
  "--refs-ignore",
86
+ "--refs-source",
84
87
  "--config"
85
88
  ];
86
89
  var BOOLEAN_FLAGS = [
@@ -122,6 +125,7 @@ Modes:
122
125
  --prune-check Exit 1 if any var has no cssVars.<key> usage (needs --usage)
123
126
  --lint-refs Exit 1 on var() references to undeclared variables
124
127
  --refs-ignore <name> Name or --prefix-* pattern for --lint-refs to skip (repeatable)
128
+ --refs-source <glob> Source files whose var() references --lint-refs checks too (repeatable)
125
129
  --version, -v Print the version
126
130
  --help, -h Print this help
127
131
 
@@ -215,6 +219,7 @@ function applyFlags(config) {
215
219
  const usageArgs = getArgs("--usage");
216
220
  const usageExcludeArgs = getArgs("--usage-exclude");
217
221
  const refsIgnoreArgs = getArgs("--refs-ignore");
222
+ const refsSourceArgs = getArgs("--refs-source");
218
223
  return {
219
224
  ...config,
220
225
  input: inputArgs.length > 0 ? inputArgs : config.input,
@@ -229,7 +234,8 @@ function applyFlags(config) {
229
234
  usage: usageArgs.length > 0 ? usageArgs : config.usage,
230
235
  usageExclude: usageExcludeArgs.length > 0 ? usageExcludeArgs : config.usageExclude,
231
236
  helpers: args.includes("--helpers") || config.helpers,
232
- refsIgnore: refsIgnoreArgs.length > 0 ? refsIgnoreArgs : config.refsIgnore
237
+ refsIgnore: refsIgnoreArgs.length > 0 ? refsIgnoreArgs : config.refsIgnore,
238
+ refsSource: refsSourceArgs.length > 0 ? refsSourceArgs : config.refsSource
233
239
  };
234
240
  }
235
241
  function loadTargets(config) {
@@ -276,8 +282,15 @@ Or add a css-typed-vars.config.js file with input and output fields. Run with --
276
282
  throw new CliError(`${tag}: --prune/--prune-check requires --usage <glob> (source files to scan for cssVars usage).`);
277
283
  }
278
284
  }
285
+ function outputPaths(output) {
286
+ if (!output) return /* @__PURE__ */ new Set();
287
+ const jsExt = /\.(m|c)?js$/i.exec(output);
288
+ return new Set([output, ...jsExt ? [output.slice(0, -jsExt[0].length) + ".d.ts"] : []].map((path) => resolve(path)));
289
+ }
279
290
  async function lintRefs({ options, tag }) {
280
- const refs = await findUndefinedRefs({ input: options.input, exclude: options.exclude, refsIgnore: options.refsIgnore });
291
+ const { input, exclude, refsIgnore, refsSource } = options;
292
+ const outputs = outputPaths(options.output);
293
+ const refs = (await findUndefinedRefs({ input, exclude, refsIgnore, refsSource })).filter((ref) => !outputs.has(resolve(ref.file)));
281
294
  const format = (ref) => ` ${relative(process.cwd(), ref.file).replace(/\\/g, "/")}:${ref.line}:${ref.column} var(${ref.name}${ref.hasFallback ? ", \u2026" : ""})`;
282
295
  const errors = refs.filter((ref) => !ref.hasFallback);
283
296
  const warnings = refs.filter((ref) => ref.hasFallback);
@@ -317,8 +330,7 @@ async function run({ options }) {
317
330
  var toArray = (value) => value === void 0 ? [] : Array.isArray(value) ? value : [value];
318
331
  function watchTarget(target) {
319
332
  const { input, exclude, output, prune, usage, usageExclude } = target.options;
320
- const jsExt = /\.(m|c)?js$/i.exec(output);
321
- const outputs = new Set([output, ...jsExt ? [output.slice(0, -jsExt[0].length) + ".d.ts"] : []].map((path) => resolve(path)));
333
+ const outputs = outputPaths(output);
322
334
  let timer = null;
323
335
  let running = false;
324
336
  let pending = false;
package/dist/esbuild.cjs CHANGED
@@ -54,8 +54,8 @@ var import_node_path3 = require("path");
54
54
  // src/scanner.ts
55
55
  var import_promises2 = require("fs/promises");
56
56
  var import_node_path2 = require("path");
57
- var import_fast_glob = __toESM(require("fast-glob"), 1);
58
57
  var import_picomatch = __toESM(require("picomatch"), 1);
58
+ var import_tinyglobby = require("tinyglobby");
59
59
 
60
60
  // src/parser.ts
61
61
  function stepQuote(text, i, quote) {
@@ -337,6 +337,39 @@ function toRawPosition(stripped, strippedPos) {
337
337
  function normalizePatterns(patterns) {
338
338
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
339
339
  }
340
+ function comparePaths(a, b) {
341
+ const as = a.split("/");
342
+ const bs = b.split("/");
343
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
344
+ if (as[i] === bs[i]) continue;
345
+ const aIsFile = i === as.length - 1;
346
+ const bIsFile = i === bs.length - 1;
347
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
348
+ return as[i] < bs[i] ? -1 : 1;
349
+ }
350
+ return as.length - bs.length;
351
+ }
352
+ async function globFiles(pattern, ignore) {
353
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
354
+ return (0, import_tinyglobby.glob)(pattern, { absolute: true, ignore, expandDirectories: false });
355
+ }
356
+ const { base, glob: rest, isGlob } = import_picomatch.default.scan(pattern);
357
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [import_node_path2.posix.dirname(pattern), import_node_path2.posix.basename(pattern)];
358
+ const matches = await (0, import_tinyglobby.glob)(relativeGlob, { cwd, absolute: true, expandDirectories: false });
359
+ if (ignore.length === 0) return matches;
360
+ const isIgnored = (0, import_picomatch.default)(ignore, { dot: true });
361
+ return matches.filter((file) => !isIgnored(file));
362
+ }
363
+ async function findFiles(patterns, exclude) {
364
+ const normalized = normalizePatterns(patterns);
365
+ const ignore = [
366
+ ...exclude ? normalizePatterns(exclude) : [],
367
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
368
+ ];
369
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
370
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
371
+ return [...new Set(files.reverse())].reverse();
372
+ }
340
373
  function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
341
374
  const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
342
375
  const include = compile(patterns);
@@ -351,9 +384,9 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
351
384
  function globWatchRoots(patterns, cwd = process.cwd()) {
352
385
  const roots = /* @__PURE__ */ new Map();
353
386
  for (const pattern of normalizePatterns(patterns)) {
354
- const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
387
+ const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
355
388
  const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
356
- const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob) ? void 0 : glob.split("/").length - 1;
389
+ const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
357
390
  const previous = roots.get(dir);
358
391
  const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
359
392
  roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
@@ -371,9 +404,7 @@ function collectVarNames(scanned) {
371
404
  return [...names].sort();
372
405
  }
373
406
  async function scanCss(patterns, exclude, selectors, themes = {}) {
374
- const normalized = normalizePatterns(patterns);
375
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
376
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
407
+ const files = await findFiles(patterns, exclude);
377
408
  const perFile = await Promise.all(
378
409
  files.map(async (file) => {
379
410
  let css;
@@ -430,9 +461,7 @@ function extractUsage(text, into) {
430
461
  }
431
462
  }
432
463
  async function scanUsage(patterns, exclude) {
433
- const normalized = normalizePatterns(patterns);
434
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
435
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
464
+ const files = await findFiles(patterns, exclude);
436
465
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
437
466
  const texts = await Promise.all(
438
467
  files.map(async (file) => {
package/dist/esbuild.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-CBN3J54B.js";
4
- import "./chunk-TR53YUPE.js";
3
+ } from "./chunk-XWMRTHOE.js";
4
+ import "./chunk-RZLASYCF.js";
5
5
 
6
6
  // src/esbuild.ts
7
7
  var esbuild_default = unplugin_default.esbuild;
package/dist/index.cjs CHANGED
@@ -69,8 +69,8 @@ async function writeOutput(path, content) {
69
69
  // src/scanner.ts
70
70
  var import_promises2 = require("fs/promises");
71
71
  var import_node_path2 = require("path");
72
- var import_fast_glob = __toESM(require("fast-glob"), 1);
73
72
  var import_picomatch = __toESM(require("picomatch"), 1);
73
+ var import_tinyglobby = require("tinyglobby");
74
74
 
75
75
  // src/parser.ts
76
76
  function stepQuote(text, i, quote) {
@@ -371,6 +371,29 @@ function parseVarReferences(css) {
371
371
  }
372
372
  return refs;
373
373
  }
374
+ var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(,)?|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
375
+ function parseSourceVarReferences(text) {
376
+ const lineStarts = [0];
377
+ for (let i = 0; i < text.length; i++) if (text[i] === "\n") lineStarts.push(i + 1);
378
+ const refs = [];
379
+ for (const match of text.matchAll(SOURCE_REF_RE)) {
380
+ let line = lineStarts.length - 1;
381
+ while (lineStarts[line] > match.index) line--;
382
+ refs.push({
383
+ name: match[1] ?? match[3],
384
+ hasFallback: match[2] === ",",
385
+ line: line + 1,
386
+ column: match.index - lineStarts[line] + 1
387
+ });
388
+ }
389
+ return refs;
390
+ }
391
+ function parseSourceDeclaredNames(text) {
392
+ const names = /* @__PURE__ */ new Set();
393
+ for (const match of text.matchAll(/(?<![\w-])(--[\w-]+)['"`]?\s*:/g)) names.add(match[1]);
394
+ for (const match of text.matchAll(/\bsetProperty\(\s*['"`](--[\w-]+)['"`]/g)) names.add(match[1]);
395
+ return names;
396
+ }
374
397
  function parseDeclaredNames(css) {
375
398
  const masked = maskQuotedContent(stripComments(css));
376
399
  const names = /* @__PURE__ */ new Set();
@@ -383,6 +406,39 @@ function parseDeclaredNames(css) {
383
406
  function normalizePatterns(patterns) {
384
407
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
385
408
  }
409
+ function comparePaths(a, b) {
410
+ const as = a.split("/");
411
+ const bs = b.split("/");
412
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
413
+ if (as[i] === bs[i]) continue;
414
+ const aIsFile = i === as.length - 1;
415
+ const bIsFile = i === bs.length - 1;
416
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
417
+ return as[i] < bs[i] ? -1 : 1;
418
+ }
419
+ return as.length - bs.length;
420
+ }
421
+ async function globFiles(pattern, ignore) {
422
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
423
+ return (0, import_tinyglobby.glob)(pattern, { absolute: true, ignore, expandDirectories: false });
424
+ }
425
+ const { base, glob: rest, isGlob } = import_picomatch.default.scan(pattern);
426
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [import_node_path2.posix.dirname(pattern), import_node_path2.posix.basename(pattern)];
427
+ const matches = await (0, import_tinyglobby.glob)(relativeGlob, { cwd, absolute: true, expandDirectories: false });
428
+ if (ignore.length === 0) return matches;
429
+ const isIgnored = (0, import_picomatch.default)(ignore, { dot: true });
430
+ return matches.filter((file) => !isIgnored(file));
431
+ }
432
+ async function findFiles(patterns, exclude) {
433
+ const normalized = normalizePatterns(patterns);
434
+ const ignore = [
435
+ ...exclude ? normalizePatterns(exclude) : [],
436
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
437
+ ];
438
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
439
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
440
+ return [...new Set(files.reverse())].reverse();
441
+ }
386
442
  function collectVarNames(scanned) {
387
443
  const names = new Set(scanned.declarations.keys());
388
444
  for (const values of scanned.themes.values()) {
@@ -391,9 +447,7 @@ function collectVarNames(scanned) {
391
447
  return [...names].sort();
392
448
  }
393
449
  async function scanCss(patterns, exclude, selectors, themes = {}) {
394
- const normalized = normalizePatterns(patterns);
395
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
396
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
450
+ const files = await findFiles(patterns, exclude);
397
451
  const perFile = await Promise.all(
398
452
  files.map(async (file) => {
399
453
  let css;
@@ -457,9 +511,7 @@ function extractUsage(text, into) {
457
511
  }
458
512
  }
459
513
  async function scanUsage(patterns, exclude) {
460
- const normalized = normalizePatterns(patterns);
461
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
462
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
514
+ const files = await findFiles(patterns, exclude);
463
515
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
464
516
  const texts = await Promise.all(
465
517
  files.map(async (file) => {
@@ -474,10 +526,10 @@ async function scanUsage(patterns, exclude) {
474
526
  for (const text of texts) extractUsage(text, usage);
475
527
  return usage;
476
528
  }
477
- async function scanReferences(patterns, exclude) {
478
- const normalized = normalizePatterns(patterns);
479
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
480
- const files = (await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude })).sort();
529
+ async function scanReferences(patterns, exclude, source = false) {
530
+ const parseReferences = source ? parseSourceVarReferences : parseVarReferences;
531
+ const parseDeclared = source ? parseSourceDeclaredNames : parseDeclaredNames;
532
+ const files = (await findFiles(patterns, exclude)).sort();
481
533
  const perFile = await Promise.all(
482
534
  files.map(async (file) => {
483
535
  try {
@@ -492,8 +544,8 @@ async function scanReferences(patterns, exclude) {
492
544
  const declared = /* @__PURE__ */ new Set();
493
545
  for (const result of perFile) {
494
546
  if (!result) continue;
495
- for (const ref of parseVarReferences(result.css)) references.push({ ...ref, file: result.file });
496
- for (const name of parseDeclaredNames(result.css)) declared.add(name);
547
+ for (const ref of parseReferences(result.css)) references.push({ ...ref, file: result.file });
548
+ for (const name of parseDeclared(result.css)) declared.add(name);
497
549
  }
498
550
  return { references, declared };
499
551
  }
@@ -887,9 +939,13 @@ function matchesIgnore(name, patterns) {
887
939
  return patterns.some((pattern) => pattern.endsWith("*") ? name.startsWith(pattern.slice(0, -1)) : name === pattern);
888
940
  }
889
941
  async function findUndefinedRefs(options) {
890
- const { references, declared } = await scanReferences(options.input, options.exclude);
942
+ const [css, source] = await Promise.all([
943
+ scanReferences(options.input, options.exclude),
944
+ options.refsSource ? scanReferences(options.refsSource, void 0, true) : null
945
+ ]);
946
+ const declared = /* @__PURE__ */ new Set([...css.declared, ...source?.declared ?? []]);
891
947
  const ignore = options.refsIgnore ?? [];
892
- return references.filter((ref) => !declared.has(ref.name) && !matchesIgnore(ref.name, ignore));
948
+ return [...css.references, ...source?.references ?? []].filter((ref) => !declared.has(ref.name) && !matchesIgnore(ref.name, ignore));
893
949
  }
894
950
  async function computeOutputs(options) {
895
951
  assertPruneCompatible(options);
package/dist/index.d.cts CHANGED
@@ -17,7 +17,7 @@ declare function scanVarNames(patterns: string | string[], exclude?: string | st
17
17
  interface FileReference extends VarReference {
18
18
  file: string;
19
19
  }
20
- declare function scanReferences(patterns: string | string[], exclude?: string | string[]): Promise<{
20
+ declare function scanReferences(patterns: string | string[], exclude?: string | string[], source?: boolean): Promise<{
21
21
  references: FileReference[];
22
22
  declared: Set<string>;
23
23
  }>;
@@ -47,6 +47,11 @@ interface GenerateOptions {
47
47
  helpers?: boolean;
48
48
  /** Names (or `--prefix-*` patterns) that `findUndefinedRefs` shouldn't report, e.g. vars set from JS. */
49
49
  refsIgnore?: string[];
50
+ /**
51
+ * Glob(s) of source files (TS/JSX, Vue, HTML, ...) whose `var(--name)` references
52
+ * (and Tailwind `bg-(--name)` shorthands) `findUndefinedRefs` also checks.
53
+ */
54
+ refsSource?: string | string[];
50
55
  }
51
56
  /** A CLI config file's options — like `GenerateOptions`, but anything may come from CLI flags instead. */
52
57
  type Config = Partial<GenerateOptions>;
@@ -57,7 +62,7 @@ type Config = Partial<GenerateOptions>;
57
62
  declare function defineConfig(config: Config): Config;
58
63
  declare function defineConfig(config: Config[]): Config[];
59
64
  declare function findUnusedVars(options: Pick<GenerateOptions, 'input' | 'exclude' | 'selectors' | 'themes' | 'prefix' | 'naming' | 'group' | 'usage' | 'usageExclude'>): Promise<string[]>;
60
- declare function findUndefinedRefs(options: Pick<GenerateOptions, 'input' | 'exclude' | 'refsIgnore'>): Promise<FileReference[]>;
65
+ declare function findUndefinedRefs(options: Pick<GenerateOptions, 'input' | 'exclude' | 'refsIgnore' | 'refsSource'>): Promise<FileReference[]>;
61
66
  declare function generate(options: GenerateOptions): Promise<boolean>;
62
67
  declare function checkGenerated(options: GenerateOptions): Promise<boolean>;
63
68
 
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ declare function scanVarNames(patterns: string | string[], exclude?: string | st
17
17
  interface FileReference extends VarReference {
18
18
  file: string;
19
19
  }
20
- declare function scanReferences(patterns: string | string[], exclude?: string | string[]): Promise<{
20
+ declare function scanReferences(patterns: string | string[], exclude?: string | string[], source?: boolean): Promise<{
21
21
  references: FileReference[];
22
22
  declared: Set<string>;
23
23
  }>;
@@ -47,6 +47,11 @@ interface GenerateOptions {
47
47
  helpers?: boolean;
48
48
  /** Names (or `--prefix-*` patterns) that `findUndefinedRefs` shouldn't report, e.g. vars set from JS. */
49
49
  refsIgnore?: string[];
50
+ /**
51
+ * Glob(s) of source files (TS/JSX, Vue, HTML, ...) whose `var(--name)` references
52
+ * (and Tailwind `bg-(--name)` shorthands) `findUndefinedRefs` also checks.
53
+ */
54
+ refsSource?: string | string[];
50
55
  }
51
56
  /** A CLI config file's options — like `GenerateOptions`, but anything may come from CLI flags instead. */
52
57
  type Config = Partial<GenerateOptions>;
@@ -57,7 +62,7 @@ type Config = Partial<GenerateOptions>;
57
62
  declare function defineConfig(config: Config): Config;
58
63
  declare function defineConfig(config: Config[]): Config[];
59
64
  declare function findUnusedVars(options: Pick<GenerateOptions, 'input' | 'exclude' | 'selectors' | 'themes' | 'prefix' | 'naming' | 'group' | 'usage' | 'usageExclude'>): Promise<string[]>;
60
- declare function findUndefinedRefs(options: Pick<GenerateOptions, 'input' | 'exclude' | 'refsIgnore'>): Promise<FileReference[]>;
65
+ declare function findUndefinedRefs(options: Pick<GenerateOptions, 'input' | 'exclude' | 'refsIgnore' | 'refsSource'>): Promise<FileReference[]>;
61
66
  declare function generate(options: GenerateOptions): Promise<boolean>;
62
67
  declare function checkGenerated(options: GenerateOptions): Promise<boolean>;
63
68
 
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  findUndefinedRefs,
5
5
  findUnusedVars,
6
6
  generate
7
- } from "./chunk-P3HJQZ6Y.js";
7
+ } from "./chunk-ULIGESN5.js";
8
8
  import {
9
9
  generateCode,
10
10
  generateDeclaration,
@@ -21,7 +21,7 @@ import {
21
21
  scanUsedKeys,
22
22
  scanVarDeclarations,
23
23
  scanVarNames
24
- } from "./chunk-TR53YUPE.js";
24
+ } from "./chunk-RZLASYCF.js";
25
25
  export {
26
26
  checkGenerated,
27
27
  defineConfig,
package/dist/rollup.cjs CHANGED
@@ -54,8 +54,8 @@ var import_node_path3 = require("path");
54
54
  // src/scanner.ts
55
55
  var import_promises2 = require("fs/promises");
56
56
  var import_node_path2 = require("path");
57
- var import_fast_glob = __toESM(require("fast-glob"), 1);
58
57
  var import_picomatch = __toESM(require("picomatch"), 1);
58
+ var import_tinyglobby = require("tinyglobby");
59
59
 
60
60
  // src/parser.ts
61
61
  function stepQuote(text, i, quote) {
@@ -337,6 +337,39 @@ function toRawPosition(stripped, strippedPos) {
337
337
  function normalizePatterns(patterns) {
338
338
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
339
339
  }
340
+ function comparePaths(a, b) {
341
+ const as = a.split("/");
342
+ const bs = b.split("/");
343
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
344
+ if (as[i] === bs[i]) continue;
345
+ const aIsFile = i === as.length - 1;
346
+ const bIsFile = i === bs.length - 1;
347
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
348
+ return as[i] < bs[i] ? -1 : 1;
349
+ }
350
+ return as.length - bs.length;
351
+ }
352
+ async function globFiles(pattern, ignore) {
353
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
354
+ return (0, import_tinyglobby.glob)(pattern, { absolute: true, ignore, expandDirectories: false });
355
+ }
356
+ const { base, glob: rest, isGlob } = import_picomatch.default.scan(pattern);
357
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [import_node_path2.posix.dirname(pattern), import_node_path2.posix.basename(pattern)];
358
+ const matches = await (0, import_tinyglobby.glob)(relativeGlob, { cwd, absolute: true, expandDirectories: false });
359
+ if (ignore.length === 0) return matches;
360
+ const isIgnored = (0, import_picomatch.default)(ignore, { dot: true });
361
+ return matches.filter((file) => !isIgnored(file));
362
+ }
363
+ async function findFiles(patterns, exclude) {
364
+ const normalized = normalizePatterns(patterns);
365
+ const ignore = [
366
+ ...exclude ? normalizePatterns(exclude) : [],
367
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
368
+ ];
369
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
370
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
371
+ return [...new Set(files.reverse())].reverse();
372
+ }
340
373
  function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
341
374
  const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
342
375
  const include = compile(patterns);
@@ -351,9 +384,9 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
351
384
  function globWatchRoots(patterns, cwd = process.cwd()) {
352
385
  const roots = /* @__PURE__ */ new Map();
353
386
  for (const pattern of normalizePatterns(patterns)) {
354
- const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
387
+ const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
355
388
  const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
356
- const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob) ? void 0 : glob.split("/").length - 1;
389
+ const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
357
390
  const previous = roots.get(dir);
358
391
  const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
359
392
  roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
@@ -371,9 +404,7 @@ function collectVarNames(scanned) {
371
404
  return [...names].sort();
372
405
  }
373
406
  async function scanCss(patterns, exclude, selectors, themes = {}) {
374
- const normalized = normalizePatterns(patterns);
375
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
376
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
407
+ const files = await findFiles(patterns, exclude);
377
408
  const perFile = await Promise.all(
378
409
  files.map(async (file) => {
379
410
  let css;
@@ -430,9 +461,7 @@ function extractUsage(text, into) {
430
461
  }
431
462
  }
432
463
  async function scanUsage(patterns, exclude) {
433
- const normalized = normalizePatterns(patterns);
434
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
435
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
464
+ const files = await findFiles(patterns, exclude);
436
465
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
437
466
  const texts = await Promise.all(
438
467
  files.map(async (file) => {
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-CBN3J54B.js";
4
- import "./chunk-TR53YUPE.js";
3
+ } from "./chunk-XWMRTHOE.js";
4
+ import "./chunk-RZLASYCF.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  var rollup_default = unplugin_default.rollup;
package/dist/unplugin.cjs CHANGED
@@ -52,8 +52,8 @@ var import_node_path3 = require("path");
52
52
  // src/scanner.ts
53
53
  var import_promises2 = require("fs/promises");
54
54
  var import_node_path2 = require("path");
55
- var import_fast_glob = __toESM(require("fast-glob"), 1);
56
55
  var import_picomatch = __toESM(require("picomatch"), 1);
56
+ var import_tinyglobby = require("tinyglobby");
57
57
 
58
58
  // src/parser.ts
59
59
  function stepQuote(text, i, quote) {
@@ -335,6 +335,39 @@ function toRawPosition(stripped, strippedPos) {
335
335
  function normalizePatterns(patterns) {
336
336
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
337
337
  }
338
+ function comparePaths(a, b) {
339
+ const as = a.split("/");
340
+ const bs = b.split("/");
341
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
342
+ if (as[i] === bs[i]) continue;
343
+ const aIsFile = i === as.length - 1;
344
+ const bIsFile = i === bs.length - 1;
345
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
346
+ return as[i] < bs[i] ? -1 : 1;
347
+ }
348
+ return as.length - bs.length;
349
+ }
350
+ async function globFiles(pattern, ignore) {
351
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
352
+ return (0, import_tinyglobby.glob)(pattern, { absolute: true, ignore, expandDirectories: false });
353
+ }
354
+ const { base, glob: rest, isGlob } = import_picomatch.default.scan(pattern);
355
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [import_node_path2.posix.dirname(pattern), import_node_path2.posix.basename(pattern)];
356
+ const matches = await (0, import_tinyglobby.glob)(relativeGlob, { cwd, absolute: true, expandDirectories: false });
357
+ if (ignore.length === 0) return matches;
358
+ const isIgnored = (0, import_picomatch.default)(ignore, { dot: true });
359
+ return matches.filter((file) => !isIgnored(file));
360
+ }
361
+ async function findFiles(patterns, exclude) {
362
+ const normalized = normalizePatterns(patterns);
363
+ const ignore = [
364
+ ...exclude ? normalizePatterns(exclude) : [],
365
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
366
+ ];
367
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
368
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
369
+ return [...new Set(files.reverse())].reverse();
370
+ }
338
371
  function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
339
372
  const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
340
373
  const include = compile(patterns);
@@ -349,9 +382,9 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
349
382
  function globWatchRoots(patterns, cwd = process.cwd()) {
350
383
  const roots = /* @__PURE__ */ new Map();
351
384
  for (const pattern of normalizePatterns(patterns)) {
352
- const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
385
+ const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
353
386
  const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
354
- const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob) ? void 0 : glob.split("/").length - 1;
387
+ const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
355
388
  const previous = roots.get(dir);
356
389
  const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
357
390
  roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
@@ -369,9 +402,7 @@ function collectVarNames(scanned) {
369
402
  return [...names].sort();
370
403
  }
371
404
  async function scanCss(patterns, exclude, selectors, themes = {}) {
372
- const normalized = normalizePatterns(patterns);
373
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
374
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
405
+ const files = await findFiles(patterns, exclude);
375
406
  const perFile = await Promise.all(
376
407
  files.map(async (file) => {
377
408
  let css;
@@ -428,9 +459,7 @@ function extractUsage(text, into) {
428
459
  }
429
460
  }
430
461
  async function scanUsage(patterns, exclude) {
431
- const normalized = normalizePatterns(patterns);
432
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
433
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
462
+ const files = await findFiles(patterns, exclude);
434
463
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
435
464
  const texts = await Promise.all(
436
465
  files.map(async (file) => {
package/dist/unplugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-CBN3J54B.js";
4
- import "./chunk-TR53YUPE.js";
3
+ } from "./chunk-XWMRTHOE.js";
4
+ import "./chunk-RZLASYCF.js";
5
5
  export {
6
6
  unplugin_default as default
7
7
  };
package/dist/vite.cjs CHANGED
@@ -54,8 +54,8 @@ var import_node_path3 = require("path");
54
54
  // src/scanner.ts
55
55
  var import_promises2 = require("fs/promises");
56
56
  var import_node_path2 = require("path");
57
- var import_fast_glob = __toESM(require("fast-glob"), 1);
58
57
  var import_picomatch = __toESM(require("picomatch"), 1);
58
+ var import_tinyglobby = require("tinyglobby");
59
59
 
60
60
  // src/parser.ts
61
61
  function stepQuote(text, i, quote) {
@@ -337,6 +337,39 @@ function toRawPosition(stripped, strippedPos) {
337
337
  function normalizePatterns(patterns) {
338
338
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
339
339
  }
340
+ function comparePaths(a, b) {
341
+ const as = a.split("/");
342
+ const bs = b.split("/");
343
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
344
+ if (as[i] === bs[i]) continue;
345
+ const aIsFile = i === as.length - 1;
346
+ const bIsFile = i === bs.length - 1;
347
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
348
+ return as[i] < bs[i] ? -1 : 1;
349
+ }
350
+ return as.length - bs.length;
351
+ }
352
+ async function globFiles(pattern, ignore) {
353
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
354
+ return (0, import_tinyglobby.glob)(pattern, { absolute: true, ignore, expandDirectories: false });
355
+ }
356
+ const { base, glob: rest, isGlob } = import_picomatch.default.scan(pattern);
357
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [import_node_path2.posix.dirname(pattern), import_node_path2.posix.basename(pattern)];
358
+ const matches = await (0, import_tinyglobby.glob)(relativeGlob, { cwd, absolute: true, expandDirectories: false });
359
+ if (ignore.length === 0) return matches;
360
+ const isIgnored = (0, import_picomatch.default)(ignore, { dot: true });
361
+ return matches.filter((file) => !isIgnored(file));
362
+ }
363
+ async function findFiles(patterns, exclude) {
364
+ const normalized = normalizePatterns(patterns);
365
+ const ignore = [
366
+ ...exclude ? normalizePatterns(exclude) : [],
367
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
368
+ ];
369
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
370
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
371
+ return [...new Set(files.reverse())].reverse();
372
+ }
340
373
  function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
341
374
  const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
342
375
  const include = compile(patterns);
@@ -351,9 +384,9 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
351
384
  function globWatchRoots(patterns, cwd = process.cwd()) {
352
385
  const roots = /* @__PURE__ */ new Map();
353
386
  for (const pattern of normalizePatterns(patterns)) {
354
- const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
387
+ const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
355
388
  const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
356
- const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob) ? void 0 : glob.split("/").length - 1;
389
+ const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
357
390
  const previous = roots.get(dir);
358
391
  const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
359
392
  roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
@@ -371,9 +404,7 @@ function collectVarNames(scanned) {
371
404
  return [...names].sort();
372
405
  }
373
406
  async function scanCss(patterns, exclude, selectors, themes = {}) {
374
- const normalized = normalizePatterns(patterns);
375
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
376
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
407
+ const files = await findFiles(patterns, exclude);
377
408
  const perFile = await Promise.all(
378
409
  files.map(async (file) => {
379
410
  let css;
@@ -430,9 +461,7 @@ function extractUsage(text, into) {
430
461
  }
431
462
  }
432
463
  async function scanUsage(patterns, exclude) {
433
- const normalized = normalizePatterns(patterns);
434
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
435
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
464
+ const files = await findFiles(patterns, exclude);
436
465
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
437
466
  const texts = await Promise.all(
438
467
  files.map(async (file) => {
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-CBN3J54B.js";
4
- import "./chunk-TR53YUPE.js";
3
+ } from "./chunk-XWMRTHOE.js";
4
+ import "./chunk-RZLASYCF.js";
5
5
 
6
6
  // src/vite.ts
7
7
  var vite_default = unplugin_default.vite;
package/dist/webpack.cjs CHANGED
@@ -54,8 +54,8 @@ var import_node_path3 = require("path");
54
54
  // src/scanner.ts
55
55
  var import_promises2 = require("fs/promises");
56
56
  var import_node_path2 = require("path");
57
- var import_fast_glob = __toESM(require("fast-glob"), 1);
58
57
  var import_picomatch = __toESM(require("picomatch"), 1);
58
+ var import_tinyglobby = require("tinyglobby");
59
59
 
60
60
  // src/parser.ts
61
61
  function stepQuote(text, i, quote) {
@@ -337,6 +337,39 @@ function toRawPosition(stripped, strippedPos) {
337
337
  function normalizePatterns(patterns) {
338
338
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
339
339
  }
340
+ function comparePaths(a, b) {
341
+ const as = a.split("/");
342
+ const bs = b.split("/");
343
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
344
+ if (as[i] === bs[i]) continue;
345
+ const aIsFile = i === as.length - 1;
346
+ const bIsFile = i === bs.length - 1;
347
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
348
+ return as[i] < bs[i] ? -1 : 1;
349
+ }
350
+ return as.length - bs.length;
351
+ }
352
+ async function globFiles(pattern, ignore) {
353
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
354
+ return (0, import_tinyglobby.glob)(pattern, { absolute: true, ignore, expandDirectories: false });
355
+ }
356
+ const { base, glob: rest, isGlob } = import_picomatch.default.scan(pattern);
357
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [import_node_path2.posix.dirname(pattern), import_node_path2.posix.basename(pattern)];
358
+ const matches = await (0, import_tinyglobby.glob)(relativeGlob, { cwd, absolute: true, expandDirectories: false });
359
+ if (ignore.length === 0) return matches;
360
+ const isIgnored = (0, import_picomatch.default)(ignore, { dot: true });
361
+ return matches.filter((file) => !isIgnored(file));
362
+ }
363
+ async function findFiles(patterns, exclude) {
364
+ const normalized = normalizePatterns(patterns);
365
+ const ignore = [
366
+ ...exclude ? normalizePatterns(exclude) : [],
367
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
368
+ ];
369
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
370
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
371
+ return [...new Set(files.reverse())].reverse();
372
+ }
340
373
  function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
341
374
  const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
342
375
  const include = compile(patterns);
@@ -351,9 +384,9 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
351
384
  function globWatchRoots(patterns, cwd = process.cwd()) {
352
385
  const roots = /* @__PURE__ */ new Map();
353
386
  for (const pattern of normalizePatterns(patterns)) {
354
- const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
387
+ const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
355
388
  const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
356
- const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob) ? void 0 : glob.split("/").length - 1;
389
+ const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
357
390
  const previous = roots.get(dir);
358
391
  const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
359
392
  roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
@@ -371,9 +404,7 @@ function collectVarNames(scanned) {
371
404
  return [...names].sort();
372
405
  }
373
406
  async function scanCss(patterns, exclude, selectors, themes = {}) {
374
- const normalized = normalizePatterns(patterns);
375
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
376
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
407
+ const files = await findFiles(patterns, exclude);
377
408
  const perFile = await Promise.all(
378
409
  files.map(async (file) => {
379
410
  let css;
@@ -430,9 +461,7 @@ function extractUsage(text, into) {
430
461
  }
431
462
  }
432
463
  async function scanUsage(patterns, exclude) {
433
- const normalized = normalizePatterns(patterns);
434
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
435
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
464
+ const files = await findFiles(patterns, exclude);
436
465
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
437
466
  const texts = await Promise.all(
438
467
  files.map(async (file) => {
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-CBN3J54B.js";
4
- import "./chunk-TR53YUPE.js";
3
+ } from "./chunk-XWMRTHOE.js";
4
+ import "./chunk-RZLASYCF.js";
5
5
 
6
6
  // src/webpack.ts
7
7
  var webpack_default = unplugin_default.webpack;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-typed-vars",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Generate TypeScript typed constants from CSS custom properties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -83,13 +83,13 @@
83
83
  },
84
84
  "dependencies": {
85
85
  "chokidar": "^5.0.0",
86
- "fast-glob": "^3.3.2",
87
- "picomatch": "^2.3.2",
86
+ "picomatch": "^4.0.7",
87
+ "tinyglobby": "^0.2.17",
88
88
  "unplugin": "^3.0.0"
89
89
  },
90
90
  "devDependencies": {
91
91
  "@types/node": "^25.5.2",
92
- "@types/picomatch": "^2.3.4",
92
+ "@types/picomatch": "^4.0.3",
93
93
  "tsup": "^8.0.0",
94
94
  "typescript": "^5.4.0",
95
95
  "vitepress": "^1.6.4",
package/schema.json CHANGED
@@ -77,6 +77,10 @@
77
77
  "type": "array",
78
78
  "items": { "type": "string" },
79
79
  "description": "Names (or --prefix-* patterns) that --lint-refs shouldn't report, e.g. vars set from JS."
80
+ },
81
+ "refsSource": {
82
+ "$ref": "#/definitions/globs",
83
+ "description": "Glob(s) of source files (TS/JSX, Vue, HTML, ...) whose var(--name) references --lint-refs checks too."
80
84
  }
81
85
  }
82
86
  }