css-typed-vars 0.9.0 → 0.10.1

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
@@ -45,6 +45,8 @@ Each generated key also carries a `/** @default ... */` comment with the propert
45
45
  npm install -D css-typed-vars
46
46
  ```
47
47
 
48
+ Requires Node.js 20.19+ or 22.12+.
49
+
48
50
  ## Two approaches
49
51
 
50
52
  | | CLI | Plugin |
@@ -139,7 +141,7 @@ npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prune-check
139
141
  | `--group` | Nest keys under an object named after each variable's first hyphen segment: `--color-primary`/`--color-secondary` → `cssVars.color.primary`/`cssVars.color.secondary`. A variable with no hyphen stays top-level. Can't be combined with `--prefix`. |
140
142
  | `--helpers` | Also emit the `CssVarRef` type and typed `getCssVar(ref, el?)`/`setCssVar(ref, value, el?)`/`withFallback(ref, fallback)` helpers — see [Usage](#usage). |
141
143
  | `--prune` | Drop generated vars with no detected `cssVars.<key>` usage. Requires `--usage <glob>` (repeatable). With `--group`, matches `cssVars.<group>.<key>` and keeps a whole group referenced as `cssVars.<group>`. |
142
- | `--prune-check` | Like `--prune`, but only reports unused vars without writing; exits 1 if any are found. Useful in CI. |
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. |
143
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) |
144
146
  | `--refs-ignore` | Name or `--prefix-*` pattern for `--lint-refs` to skip (repeatable) |
145
147
  | `--usage` | Glob of source files to scan for `cssVars` usage, for `--prune`/`--prune-check` (repeatable) |
@@ -151,9 +153,9 @@ npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prune-check
151
153
 
152
154
  ### Pruning unused variables
153
155
 
154
- `--prune`/`--prune-check` scan your source files for `cssVars.<key>` (dot access) or `cssVars['<key>']`/`cssVars["<key>"]` (bracket access) usage and compare that against the generated keys. This is a textual scan, not a full parser, so it has two limitations worth knowing:
156
+ `--prune`/`--prune-check` scan your source files for `cssVars.<key>` (dot access) or `cssVars['<key>']`/`cssVars["<key>"]` (bracket access) usage and compare that against the generated keys. This is a textual scan, not a full parser, so it has limitations worth knowing:
155
157
 
156
- - It won't see through a renamed import (`import { cssVars as vars } from './cssVars'` — usages via `vars.foo` aren't detected).
158
+ - A renamed import (`import { cssVars as vars } from './cssVars'`) is followed within the file that declares it, but not a re-export under another name or an assignment (`const v = cssVars`).
157
159
  - A match inside a comment or string still counts as "used".
158
160
 
159
161
  When in doubt, use `--prune-check` in CI to review what it would remove before turning on `--prune` for real.
@@ -6,16 +6,18 @@ import {
6
6
  generateDeclaration,
7
7
  generateJs,
8
8
  generateTokens,
9
+ globBaseDirs,
9
10
  partitionUnused,
10
11
  scanCss,
11
12
  scanUsage,
12
13
  warnOnCollisions,
13
14
  writeOutput
14
- } from "./chunk-DHBPPGOE.js";
15
+ } from "./chunk-XCAFJREQ.js";
15
16
 
16
17
  // src/unplugin.ts
17
18
  import { createUnplugin } from "unplugin";
18
19
  import { join, resolve } from "path";
20
+ var toArray = (value) => value === void 0 ? [] : Array.isArray(value) ? value : [value];
19
21
  var VIRTUAL_ID = "css-typed-vars/vars";
20
22
  var RESOLVED_ID = "\0css-typed-vars/vars";
21
23
  function getDtsPath(options) {
@@ -105,6 +107,7 @@ var unplugin_default = createUnplugin((options) => {
105
107
  server.watcher.on("change", handle);
106
108
  server.watcher.on("add", handle);
107
109
  server.watcher.on("unlink", handle);
110
+ server.watcher.add(globBaseDirs([...toArray(options.input), ...options.prune ? toArray(options.usage) : []]));
108
111
  }
109
112
  },
110
113
  async buildStart() {
@@ -11,7 +11,7 @@ import {
11
11
  scanUsage,
12
12
  warnOnCollisions,
13
13
  writeOutput
14
- } from "./chunk-DHBPPGOE.js";
14
+ } from "./chunk-XCAFJREQ.js";
15
15
 
16
16
  // src/index.ts
17
17
  import { readFile } from "fs/promises";
@@ -325,7 +325,7 @@ function parseDeclaredNames(css) {
325
325
 
326
326
  // src/scanner.ts
327
327
  import { readFile as readFile2 } from "fs/promises";
328
- import { relative, resolve } from "path";
328
+ import { dirname as dirname2, relative, resolve } from "path";
329
329
  import fg from "fast-glob";
330
330
  import picomatch from "picomatch";
331
331
  function normalizePatterns(patterns) {
@@ -342,6 +342,13 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
342
342
  return matches(include) && !matches(ignore);
343
343
  };
344
344
  }
345
+ function globBaseDirs(patterns, cwd = process.cwd()) {
346
+ const dirs = normalizePatterns(patterns).map((pattern) => {
347
+ const { base, isGlob } = picomatch.scan(pattern);
348
+ return resolve(cwd, isGlob ? base || "." : dirname2(pattern));
349
+ });
350
+ return [...new Set(dirs)];
351
+ }
345
352
  function collectVarNames(scanned) {
346
353
  const names = new Set(scanned.declarations.keys());
347
354
  for (const values of scanned.themes.values()) {
@@ -388,6 +395,17 @@ async function scanVarNames(patterns, exclude, selectors) {
388
395
  return [...declarations.keys()].sort();
389
396
  }
390
397
  var ROOT_RE = /\bcssVars\b/g;
398
+ var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
399
+ var ALIAS_RE = /(?:^|,)\s*(?:type\s+)?cssVars\s+as\s+([A-Za-z_$][\w$]*)\s*(?=,|$)/g;
400
+ function rootPattern(text) {
401
+ const aliases = /* @__PURE__ */ new Set();
402
+ for (const [, specifiers] of text.matchAll(IMPORT_RE)) {
403
+ for (const [, alias] of specifiers.matchAll(ALIAS_RE)) aliases.add(alias);
404
+ }
405
+ if (aliases.size === 0) return ROOT_RE;
406
+ const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
407
+ return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
408
+ }
391
409
  var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
392
410
  function readAccess(text, from) {
393
411
  ACCESS_RE.lastIndex = from;
@@ -395,7 +413,7 @@ function readAccess(text, from) {
395
413
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
396
414
  }
397
415
  function extractUsage(text, into) {
398
- for (const root of text.matchAll(ROOT_RE)) {
416
+ for (const root of text.matchAll(rootPattern(text))) {
399
417
  const first = readAccess(text, root.index + root[0].length);
400
418
  if (!first) continue;
401
419
  into.keys.add(first.key);
@@ -828,6 +846,7 @@ export {
828
846
  parseVarReferences,
829
847
  parseDeclaredNames,
830
848
  createFileMatcher,
849
+ globBaseDirs,
831
850
  collectVarNames,
832
851
  scanCss,
833
852
  scanVarDeclarations,
package/dist/cli.cjs CHANGED
@@ -394,6 +394,17 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
394
394
  return { declarations, properties, themes: themeValues, docs };
395
395
  }
396
396
  var ROOT_RE = /\bcssVars\b/g;
397
+ var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
398
+ var ALIAS_RE = /(?:^|,)\s*(?:type\s+)?cssVars\s+as\s+([A-Za-z_$][\w$]*)\s*(?=,|$)/g;
399
+ function rootPattern(text) {
400
+ const aliases = /* @__PURE__ */ new Set();
401
+ for (const [, specifiers] of text.matchAll(IMPORT_RE)) {
402
+ for (const [, alias] of specifiers.matchAll(ALIAS_RE)) aliases.add(alias);
403
+ }
404
+ if (aliases.size === 0) return ROOT_RE;
405
+ const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
406
+ return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
407
+ }
397
408
  var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
398
409
  function readAccess(text, from) {
399
410
  ACCESS_RE.lastIndex = from;
@@ -401,7 +412,7 @@ function readAccess(text, from) {
401
412
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
402
413
  }
403
414
  function extractUsage(text, into) {
404
- for (const root of text.matchAll(ROOT_RE)) {
415
+ for (const root of text.matchAll(rootPattern(text))) {
405
416
  const first = readAccess(text, root.index + root[0].length);
406
417
  if (!first) continue;
407
418
  into.keys.add(first.key);
@@ -1114,7 +1125,10 @@ function validateTarget({ options, tag }, single) {
1114
1125
  if (!input) throw new CliError(`${tag}: --lint-refs requires --input <glob> (or "input" in the config file).`);
1115
1126
  return;
1116
1127
  }
1117
- if (!input || !output) {
1128
+ if (pruneCheckMode && !input) {
1129
+ throw new CliError(`${tag}: --prune-check requires --input <glob> (or "input" in the config file).`);
1130
+ }
1131
+ if (!input || !output && !pruneCheckMode) {
1118
1132
  throw new CliError(single ? `${USAGE}
1119
1133
  Or add a css-typed-vars.config.js file with input and output fields. Run with --help to see all options.` : `${tag}: every target needs "input" and "output".`);
1120
1134
  }
package/dist/cli.js CHANGED
@@ -4,10 +4,10 @@ import {
4
4
  findUndefinedRefs,
5
5
  findUnusedVars,
6
6
  generate
7
- } from "./chunk-TB5PSGEF.js";
7
+ } from "./chunk-O7MEOCHS.js";
8
8
  import {
9
9
  VALID_NAMINGS
10
- } from "./chunk-DHBPPGOE.js";
10
+ } from "./chunk-XCAFJREQ.js";
11
11
 
12
12
  // src/cli.ts
13
13
  import { access, readFile } from "fs/promises";
@@ -229,7 +229,10 @@ function validateTarget({ options, tag }, single) {
229
229
  if (!input) throw new CliError(`${tag}: --lint-refs requires --input <glob> (or "input" in the config file).`);
230
230
  return;
231
231
  }
232
- if (!input || !output) {
232
+ if (pruneCheckMode && !input) {
233
+ throw new CliError(`${tag}: --prune-check requires --input <glob> (or "input" in the config file).`);
234
+ }
235
+ if (!input || !output && !pruneCheckMode) {
233
236
  throw new CliError(single ? `${USAGE}
234
237
  Or add a css-typed-vars.config.js file with input and output fields. Run with --help to see all options.` : `${tag}: every target needs "input" and "output".`);
235
238
  }
package/dist/esbuild.cjs CHANGED
@@ -348,6 +348,13 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
348
348
  return matches(include) && !matches(ignore);
349
349
  };
350
350
  }
351
+ function globBaseDirs(patterns, cwd = process.cwd()) {
352
+ const dirs = normalizePatterns(patterns).map((pattern) => {
353
+ const { base, isGlob } = import_picomatch.default.scan(pattern);
354
+ return (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
355
+ });
356
+ return [...new Set(dirs)];
357
+ }
351
358
  function collectVarNames(scanned) {
352
359
  const names = new Set(scanned.declarations.keys());
353
360
  for (const values of scanned.themes.values()) {
@@ -387,6 +394,17 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
387
394
  return { declarations, properties, themes: themeValues, docs };
388
395
  }
389
396
  var ROOT_RE = /\bcssVars\b/g;
397
+ var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
398
+ var ALIAS_RE = /(?:^|,)\s*(?:type\s+)?cssVars\s+as\s+([A-Za-z_$][\w$]*)\s*(?=,|$)/g;
399
+ function rootPattern(text) {
400
+ const aliases = /* @__PURE__ */ new Set();
401
+ for (const [, specifiers] of text.matchAll(IMPORT_RE)) {
402
+ for (const [, alias] of specifiers.matchAll(ALIAS_RE)) aliases.add(alias);
403
+ }
404
+ if (aliases.size === 0) return ROOT_RE;
405
+ const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
406
+ return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
407
+ }
390
408
  var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
391
409
  function readAccess(text, from) {
392
410
  ACCESS_RE.lastIndex = from;
@@ -394,7 +412,7 @@ function readAccess(text, from) {
394
412
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
395
413
  }
396
414
  function extractUsage(text, into) {
397
- for (const root of text.matchAll(ROOT_RE)) {
415
+ for (const root of text.matchAll(rootPattern(text))) {
398
416
  const first = readAccess(text, root.index + root[0].length);
399
417
  if (!first) continue;
400
418
  into.keys.add(first.key);
@@ -762,6 +780,7 @@ function partitionUnused(names, usage, options) {
762
780
  }
763
781
 
764
782
  // src/unplugin.ts
783
+ var toArray = (value) => value === void 0 ? [] : Array.isArray(value) ? value : [value];
765
784
  var VIRTUAL_ID = "css-typed-vars/vars";
766
785
  var RESOLVED_ID = "\0css-typed-vars/vars";
767
786
  function getDtsPath(options) {
@@ -851,6 +870,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
851
870
  server.watcher.on("change", handle);
852
871
  server.watcher.on("add", handle);
853
872
  server.watcher.on("unlink", handle);
873
+ server.watcher.add(globBaseDirs([...toArray(options.input), ...options.prune ? toArray(options.usage) : []]));
854
874
  }
855
875
  },
856
876
  async buildStart() {
package/dist/esbuild.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-66NEMXYL.js";
4
- import "./chunk-DHBPPGOE.js";
3
+ } from "./chunk-NZUQZYNM.js";
4
+ import "./chunk-XCAFJREQ.js";
5
5
 
6
6
  // src/esbuild.ts
7
7
  var esbuild_default = unplugin_default.esbuild;
package/dist/index.cjs CHANGED
@@ -429,6 +429,17 @@ async function scanVarNames(patterns, exclude, selectors) {
429
429
  return [...declarations.keys()].sort();
430
430
  }
431
431
  var ROOT_RE = /\bcssVars\b/g;
432
+ var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
433
+ var ALIAS_RE = /(?:^|,)\s*(?:type\s+)?cssVars\s+as\s+([A-Za-z_$][\w$]*)\s*(?=,|$)/g;
434
+ function rootPattern(text) {
435
+ const aliases = /* @__PURE__ */ new Set();
436
+ for (const [, specifiers] of text.matchAll(IMPORT_RE)) {
437
+ for (const [, alias] of specifiers.matchAll(ALIAS_RE)) aliases.add(alias);
438
+ }
439
+ if (aliases.size === 0) return ROOT_RE;
440
+ const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
441
+ return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
442
+ }
432
443
  var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
433
444
  function readAccess(text, from) {
434
445
  ACCESS_RE.lastIndex = from;
@@ -436,7 +447,7 @@ function readAccess(text, from) {
436
447
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
437
448
  }
438
449
  function extractUsage(text, into) {
439
- for (const root of text.matchAll(ROOT_RE)) {
450
+ for (const root of text.matchAll(rootPattern(text))) {
440
451
  const first = readAccess(text, root.index + root[0].length);
441
452
  if (!first) continue;
442
453
  into.keys.add(first.key);
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  findUndefinedRefs,
5
5
  findUnusedVars,
6
6
  generate
7
- } from "./chunk-TB5PSGEF.js";
7
+ } from "./chunk-O7MEOCHS.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-DHBPPGOE.js";
24
+ } from "./chunk-XCAFJREQ.js";
25
25
  export {
26
26
  checkGenerated,
27
27
  defineConfig,
package/dist/rollup.cjs CHANGED
@@ -348,6 +348,13 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
348
348
  return matches(include) && !matches(ignore);
349
349
  };
350
350
  }
351
+ function globBaseDirs(patterns, cwd = process.cwd()) {
352
+ const dirs = normalizePatterns(patterns).map((pattern) => {
353
+ const { base, isGlob } = import_picomatch.default.scan(pattern);
354
+ return (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
355
+ });
356
+ return [...new Set(dirs)];
357
+ }
351
358
  function collectVarNames(scanned) {
352
359
  const names = new Set(scanned.declarations.keys());
353
360
  for (const values of scanned.themes.values()) {
@@ -387,6 +394,17 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
387
394
  return { declarations, properties, themes: themeValues, docs };
388
395
  }
389
396
  var ROOT_RE = /\bcssVars\b/g;
397
+ var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
398
+ var ALIAS_RE = /(?:^|,)\s*(?:type\s+)?cssVars\s+as\s+([A-Za-z_$][\w$]*)\s*(?=,|$)/g;
399
+ function rootPattern(text) {
400
+ const aliases = /* @__PURE__ */ new Set();
401
+ for (const [, specifiers] of text.matchAll(IMPORT_RE)) {
402
+ for (const [, alias] of specifiers.matchAll(ALIAS_RE)) aliases.add(alias);
403
+ }
404
+ if (aliases.size === 0) return ROOT_RE;
405
+ const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
406
+ return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
407
+ }
390
408
  var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
391
409
  function readAccess(text, from) {
392
410
  ACCESS_RE.lastIndex = from;
@@ -394,7 +412,7 @@ function readAccess(text, from) {
394
412
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
395
413
  }
396
414
  function extractUsage(text, into) {
397
- for (const root of text.matchAll(ROOT_RE)) {
415
+ for (const root of text.matchAll(rootPattern(text))) {
398
416
  const first = readAccess(text, root.index + root[0].length);
399
417
  if (!first) continue;
400
418
  into.keys.add(first.key);
@@ -762,6 +780,7 @@ function partitionUnused(names, usage, options) {
762
780
  }
763
781
 
764
782
  // src/unplugin.ts
783
+ var toArray = (value) => value === void 0 ? [] : Array.isArray(value) ? value : [value];
765
784
  var VIRTUAL_ID = "css-typed-vars/vars";
766
785
  var RESOLVED_ID = "\0css-typed-vars/vars";
767
786
  function getDtsPath(options) {
@@ -851,6 +870,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
851
870
  server.watcher.on("change", handle);
852
871
  server.watcher.on("add", handle);
853
872
  server.watcher.on("unlink", handle);
873
+ server.watcher.add(globBaseDirs([...toArray(options.input), ...options.prune ? toArray(options.usage) : []]));
854
874
  }
855
875
  },
856
876
  async buildStart() {
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-66NEMXYL.js";
4
- import "./chunk-DHBPPGOE.js";
3
+ } from "./chunk-NZUQZYNM.js";
4
+ import "./chunk-XCAFJREQ.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  var rollup_default = unplugin_default.rollup;
package/dist/unplugin.cjs CHANGED
@@ -346,6 +346,13 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
346
346
  return matches(include) && !matches(ignore);
347
347
  };
348
348
  }
349
+ function globBaseDirs(patterns, cwd = process.cwd()) {
350
+ const dirs = normalizePatterns(patterns).map((pattern) => {
351
+ const { base, isGlob } = import_picomatch.default.scan(pattern);
352
+ return (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
353
+ });
354
+ return [...new Set(dirs)];
355
+ }
349
356
  function collectVarNames(scanned) {
350
357
  const names = new Set(scanned.declarations.keys());
351
358
  for (const values of scanned.themes.values()) {
@@ -385,6 +392,17 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
385
392
  return { declarations, properties, themes: themeValues, docs };
386
393
  }
387
394
  var ROOT_RE = /\bcssVars\b/g;
395
+ var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
396
+ var ALIAS_RE = /(?:^|,)\s*(?:type\s+)?cssVars\s+as\s+([A-Za-z_$][\w$]*)\s*(?=,|$)/g;
397
+ function rootPattern(text) {
398
+ const aliases = /* @__PURE__ */ new Set();
399
+ for (const [, specifiers] of text.matchAll(IMPORT_RE)) {
400
+ for (const [, alias] of specifiers.matchAll(ALIAS_RE)) aliases.add(alias);
401
+ }
402
+ if (aliases.size === 0) return ROOT_RE;
403
+ const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
404
+ return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
405
+ }
388
406
  var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
389
407
  function readAccess(text, from) {
390
408
  ACCESS_RE.lastIndex = from;
@@ -392,7 +410,7 @@ function readAccess(text, from) {
392
410
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
393
411
  }
394
412
  function extractUsage(text, into) {
395
- for (const root of text.matchAll(ROOT_RE)) {
413
+ for (const root of text.matchAll(rootPattern(text))) {
396
414
  const first = readAccess(text, root.index + root[0].length);
397
415
  if (!first) continue;
398
416
  into.keys.add(first.key);
@@ -760,6 +778,7 @@ function partitionUnused(names, usage, options) {
760
778
  }
761
779
 
762
780
  // src/unplugin.ts
781
+ var toArray = (value) => value === void 0 ? [] : Array.isArray(value) ? value : [value];
763
782
  var VIRTUAL_ID = "css-typed-vars/vars";
764
783
  var RESOLVED_ID = "\0css-typed-vars/vars";
765
784
  function getDtsPath(options) {
@@ -849,6 +868,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
849
868
  server.watcher.on("change", handle);
850
869
  server.watcher.on("add", handle);
851
870
  server.watcher.on("unlink", handle);
871
+ server.watcher.add(globBaseDirs([...toArray(options.input), ...options.prune ? toArray(options.usage) : []]));
852
872
  }
853
873
  },
854
874
  async buildStart() {
package/dist/unplugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-66NEMXYL.js";
4
- import "./chunk-DHBPPGOE.js";
3
+ } from "./chunk-NZUQZYNM.js";
4
+ import "./chunk-XCAFJREQ.js";
5
5
  export {
6
6
  unplugin_default as default
7
7
  };
package/dist/vite.cjs CHANGED
@@ -348,6 +348,13 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
348
348
  return matches(include) && !matches(ignore);
349
349
  };
350
350
  }
351
+ function globBaseDirs(patterns, cwd = process.cwd()) {
352
+ const dirs = normalizePatterns(patterns).map((pattern) => {
353
+ const { base, isGlob } = import_picomatch.default.scan(pattern);
354
+ return (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
355
+ });
356
+ return [...new Set(dirs)];
357
+ }
351
358
  function collectVarNames(scanned) {
352
359
  const names = new Set(scanned.declarations.keys());
353
360
  for (const values of scanned.themes.values()) {
@@ -387,6 +394,17 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
387
394
  return { declarations, properties, themes: themeValues, docs };
388
395
  }
389
396
  var ROOT_RE = /\bcssVars\b/g;
397
+ var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
398
+ var ALIAS_RE = /(?:^|,)\s*(?:type\s+)?cssVars\s+as\s+([A-Za-z_$][\w$]*)\s*(?=,|$)/g;
399
+ function rootPattern(text) {
400
+ const aliases = /* @__PURE__ */ new Set();
401
+ for (const [, specifiers] of text.matchAll(IMPORT_RE)) {
402
+ for (const [, alias] of specifiers.matchAll(ALIAS_RE)) aliases.add(alias);
403
+ }
404
+ if (aliases.size === 0) return ROOT_RE;
405
+ const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
406
+ return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
407
+ }
390
408
  var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
391
409
  function readAccess(text, from) {
392
410
  ACCESS_RE.lastIndex = from;
@@ -394,7 +412,7 @@ function readAccess(text, from) {
394
412
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
395
413
  }
396
414
  function extractUsage(text, into) {
397
- for (const root of text.matchAll(ROOT_RE)) {
415
+ for (const root of text.matchAll(rootPattern(text))) {
398
416
  const first = readAccess(text, root.index + root[0].length);
399
417
  if (!first) continue;
400
418
  into.keys.add(first.key);
@@ -762,6 +780,7 @@ function partitionUnused(names, usage, options) {
762
780
  }
763
781
 
764
782
  // src/unplugin.ts
783
+ var toArray = (value) => value === void 0 ? [] : Array.isArray(value) ? value : [value];
765
784
  var VIRTUAL_ID = "css-typed-vars/vars";
766
785
  var RESOLVED_ID = "\0css-typed-vars/vars";
767
786
  function getDtsPath(options) {
@@ -851,6 +870,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
851
870
  server.watcher.on("change", handle);
852
871
  server.watcher.on("add", handle);
853
872
  server.watcher.on("unlink", handle);
873
+ server.watcher.add(globBaseDirs([...toArray(options.input), ...options.prune ? toArray(options.usage) : []]));
854
874
  }
855
875
  },
856
876
  async buildStart() {
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-66NEMXYL.js";
4
- import "./chunk-DHBPPGOE.js";
3
+ } from "./chunk-NZUQZYNM.js";
4
+ import "./chunk-XCAFJREQ.js";
5
5
 
6
6
  // src/vite.ts
7
7
  var vite_default = unplugin_default.vite;
package/dist/webpack.cjs CHANGED
@@ -348,6 +348,13 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
348
348
  return matches(include) && !matches(ignore);
349
349
  };
350
350
  }
351
+ function globBaseDirs(patterns, cwd = process.cwd()) {
352
+ const dirs = normalizePatterns(patterns).map((pattern) => {
353
+ const { base, isGlob } = import_picomatch.default.scan(pattern);
354
+ return (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
355
+ });
356
+ return [...new Set(dirs)];
357
+ }
351
358
  function collectVarNames(scanned) {
352
359
  const names = new Set(scanned.declarations.keys());
353
360
  for (const values of scanned.themes.values()) {
@@ -387,6 +394,17 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
387
394
  return { declarations, properties, themes: themeValues, docs };
388
395
  }
389
396
  var ROOT_RE = /\bcssVars\b/g;
397
+ var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
398
+ var ALIAS_RE = /(?:^|,)\s*(?:type\s+)?cssVars\s+as\s+([A-Za-z_$][\w$]*)\s*(?=,|$)/g;
399
+ function rootPattern(text) {
400
+ const aliases = /* @__PURE__ */ new Set();
401
+ for (const [, specifiers] of text.matchAll(IMPORT_RE)) {
402
+ for (const [, alias] of specifiers.matchAll(ALIAS_RE)) aliases.add(alias);
403
+ }
404
+ if (aliases.size === 0) return ROOT_RE;
405
+ const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
406
+ return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
407
+ }
390
408
  var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
391
409
  function readAccess(text, from) {
392
410
  ACCESS_RE.lastIndex = from;
@@ -394,7 +412,7 @@ function readAccess(text, from) {
394
412
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
395
413
  }
396
414
  function extractUsage(text, into) {
397
- for (const root of text.matchAll(ROOT_RE)) {
415
+ for (const root of text.matchAll(rootPattern(text))) {
398
416
  const first = readAccess(text, root.index + root[0].length);
399
417
  if (!first) continue;
400
418
  into.keys.add(first.key);
@@ -762,6 +780,7 @@ function partitionUnused(names, usage, options) {
762
780
  }
763
781
 
764
782
  // src/unplugin.ts
783
+ var toArray = (value) => value === void 0 ? [] : Array.isArray(value) ? value : [value];
765
784
  var VIRTUAL_ID = "css-typed-vars/vars";
766
785
  var RESOLVED_ID = "\0css-typed-vars/vars";
767
786
  function getDtsPath(options) {
@@ -851,6 +870,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
851
870
  server.watcher.on("change", handle);
852
871
  server.watcher.on("add", handle);
853
872
  server.watcher.on("unlink", handle);
873
+ server.watcher.add(globBaseDirs([...toArray(options.input), ...options.prune ? toArray(options.usage) : []]));
854
874
  }
855
875
  },
856
876
  async buildStart() {
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-66NEMXYL.js";
4
- import "./chunk-DHBPPGOE.js";
3
+ } from "./chunk-NZUQZYNM.js";
4
+ import "./chunk-XCAFJREQ.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.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "Generate TypeScript typed constants from CSS custom properties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -42,6 +42,9 @@
42
42
  "css-typed-vars": "./dist/cli.js"
43
43
  },
44
44
  "license": "MIT",
45
+ "engines": {
46
+ "node": "^20.19.0 || >=22.12.0"
47
+ },
45
48
  "homepage": "https://github.com/StanislavKozachenko/css-typed-vars#readme",
46
49
  "repository": {
47
50
  "type": "git",
@@ -50,11 +53,20 @@
50
53
  "keywords": [
51
54
  "css",
52
55
  "scss",
56
+ "less",
53
57
  "css-variables",
54
58
  "custom-properties",
55
59
  "typescript",
56
60
  "codegen",
57
- "typed"
61
+ "typed",
62
+ "vite-plugin",
63
+ "unplugin",
64
+ "webpack-plugin",
65
+ "rollup-plugin",
66
+ "esbuild-plugin",
67
+ "design-tokens",
68
+ "dtcg",
69
+ "tailwindcss"
58
70
  ],
59
71
  "files": [
60
72
  "dist"