css-typed-vars 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -8,6 +8,8 @@ interface ScannedCss {
8
8
  themes: Map<string, Map<string, string>>;
9
9
  /** `/** ... *\/` doc comments placed directly before a declaration. */
10
10
  docs: Map<string, VarDoc>;
11
+ /** Every file the globs matched, absolute — what the scan's result depends on. */
12
+ files: string[];
11
13
  }
12
14
  declare function scanCss(patterns: string | string[], exclude?: string | string[], selectors?: string[], themes?: Record<string, string>): Promise<ScannedCss>;
13
15
  declare function scanVarDeclarations(patterns: string | string[], exclude?: string | string[], selectors?: string[]): Promise<Map<string, string>>;
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ interface ScannedCss {
8
8
  themes: Map<string, Map<string, string>>;
9
9
  /** `/** ... *\/` doc comments placed directly before a declaration. */
10
10
  docs: Map<string, VarDoc>;
11
+ /** Every file the globs matched, absolute — what the scan's result depends on. */
12
+ files: string[];
11
13
  }
12
14
  declare function scanCss(patterns: string | string[], exclude?: string | string[], selectors?: string[], themes?: Record<string, string>): Promise<ScannedCss>;
13
15
  declare function scanVarDeclarations(patterns: string | string[], exclude?: string | string[], selectors?: string[]): Promise<Map<string, string>>;
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  findUndefinedRefs,
5
5
  findUnusedVars,
6
6
  generate
7
- } from "./chunk-O7MEOCHS.js";
7
+ } from "./chunk-P3HJQZ6Y.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-XCAFJREQ.js";
24
+ } from "./chunk-TR53YUPE.js";
25
25
  export {
26
26
  checkGenerated,
27
27
  defineConfig,
package/dist/rollup.cjs CHANGED
@@ -348,12 +348,20 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
348
348
  return matches(include) && !matches(ignore);
349
349
  };
350
350
  }
351
+ function globWatchRoots(patterns, cwd = process.cwd()) {
352
+ const roots = /* @__PURE__ */ new Map();
353
+ for (const pattern of normalizePatterns(patterns)) {
354
+ const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
355
+ 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;
357
+ const previous = roots.get(dir);
358
+ const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
359
+ roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
360
+ }
361
+ return [...roots].map(([dir, depth]) => depth === void 0 ? { dir } : { dir, depth });
362
+ }
351
363
  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)];
364
+ return globWatchRoots(patterns, cwd).map((root) => root.dir);
357
365
  }
358
366
  function collectVarNames(scanned) {
359
367
  const names = new Set(scanned.declarations.keys());
@@ -391,7 +399,7 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
391
399
  for (const [name, value] of values) themeValues.get(theme).set(name, value);
392
400
  }
393
401
  }
394
- return { declarations, properties, themes: themeValues, docs };
402
+ return { declarations, properties, themes: themeValues, docs, files };
395
403
  }
396
404
  var ROOT_RE = /\bcssVars\b/g;
397
405
  var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
@@ -425,7 +433,7 @@ async function scanUsage(patterns, exclude) {
425
433
  const normalized = normalizePatterns(patterns);
426
434
  const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
427
435
  const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
428
- const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set() };
436
+ const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
429
437
  const texts = await Promise.all(
430
438
  files.map(async (file) => {
431
439
  try {
@@ -794,18 +802,23 @@ function outputFiles(options, names, generatorOptions) {
794
802
  if (options.tokens) files.push([(0, import_node_path3.resolve)(process.cwd(), options.tokens), generateTokens(names, generatorOptions)]);
795
803
  return files;
796
804
  }
797
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
805
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options, meta) => {
798
806
  assertPruneCompatible(options);
799
807
  let cachedScan = null;
808
+ let devServer = false;
800
809
  const scan = () => scanCss(options.input, options.exclude, options.selectors, options.themes);
801
810
  const applyPrune = async (names) => {
802
- if (!options.prune) return names;
811
+ if (!options.prune) return { names, usageFiles: [] };
803
812
  const usage = await scanUsage(options.usage, options.usageExclude);
804
813
  const { used, unused } = partitionUnused(names, usage, options);
805
814
  if (unused.length > 0) {
806
815
  console.warn(`css-typed-vars: pruned ${unused.length} unused variable(s): ${unused.join(", ")}`);
807
816
  }
808
- return used;
817
+ return { names: used, usageFiles: usage.files };
818
+ };
819
+ const watchFiles = (context, scanned, usageFiles) => {
820
+ if (devServer) return;
821
+ for (const file of [...scanned.files, ...usageFiles]) context.addWatchFile((0, import_node_path3.resolve)(file));
809
822
  };
810
823
  const generatorOptions = ({ declarations, properties, themes, docs }) => ({
811
824
  prefix: options.prefix,
@@ -826,6 +839,9 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
826
839
  name: "css-typed-vars",
827
840
  vite: {
828
841
  enforce: "pre",
842
+ configResolved(config) {
843
+ devServer = config.command === "serve";
844
+ },
829
845
  configureServer(server) {
830
846
  let generation = 0;
831
847
  let debounceTimer = null;
@@ -836,7 +852,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
836
852
  cachedScan = scanPromise;
837
853
  const scanned = await scanPromise;
838
854
  if (myGeneration !== generation) return;
839
- const names = await resolveNames(scanned);
855
+ const { names } = await resolveNames(scanned);
840
856
  if (myGeneration !== generation) return;
841
857
  const files = outputFiles(options, names, generatorOptions(scanned));
842
858
  if (files.length > 0) {
@@ -876,7 +892,8 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
876
892
  async buildStart() {
877
893
  cachedScan = scan();
878
894
  const scanned = await cachedScan;
879
- const names = await resolveNames(scanned);
895
+ const { names, usageFiles } = await resolveNames(scanned);
896
+ if (meta.framework !== "esbuild") watchFiles(this, scanned, usageFiles);
880
897
  for (const [path, content] of outputFiles(options, names, generatorOptions(scanned))) {
881
898
  await writeOutput(path, content);
882
899
  }
@@ -887,7 +904,8 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
887
904
  async load(id) {
888
905
  if (id === RESOLVED_ID) {
889
906
  const scanned = await (cachedScan ?? scan());
890
- const names = await applyPrune(collectVarNames(scanned));
907
+ const { names, usageFiles } = await applyPrune(collectVarNames(scanned));
908
+ watchFiles(this, scanned, usageFiles);
891
909
  return generateJs(names, generatorOptions(scanned));
892
910
  }
893
911
  }
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-NZUQZYNM.js";
4
- import "./chunk-XCAFJREQ.js";
3
+ } from "./chunk-CBN3J54B.js";
4
+ import "./chunk-TR53YUPE.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  var rollup_default = unplugin_default.rollup;
package/dist/unplugin.cjs CHANGED
@@ -346,12 +346,20 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
346
346
  return matches(include) && !matches(ignore);
347
347
  };
348
348
  }
349
+ function globWatchRoots(patterns, cwd = process.cwd()) {
350
+ const roots = /* @__PURE__ */ new Map();
351
+ for (const pattern of normalizePatterns(patterns)) {
352
+ const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
353
+ 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;
355
+ const previous = roots.get(dir);
356
+ const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
357
+ roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
358
+ }
359
+ return [...roots].map(([dir, depth]) => depth === void 0 ? { dir } : { dir, depth });
360
+ }
349
361
  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)];
362
+ return globWatchRoots(patterns, cwd).map((root) => root.dir);
355
363
  }
356
364
  function collectVarNames(scanned) {
357
365
  const names = new Set(scanned.declarations.keys());
@@ -389,7 +397,7 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
389
397
  for (const [name, value] of values) themeValues.get(theme).set(name, value);
390
398
  }
391
399
  }
392
- return { declarations, properties, themes: themeValues, docs };
400
+ return { declarations, properties, themes: themeValues, docs, files };
393
401
  }
394
402
  var ROOT_RE = /\bcssVars\b/g;
395
403
  var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
@@ -423,7 +431,7 @@ async function scanUsage(patterns, exclude) {
423
431
  const normalized = normalizePatterns(patterns);
424
432
  const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
425
433
  const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
426
- const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set() };
434
+ const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
427
435
  const texts = await Promise.all(
428
436
  files.map(async (file) => {
429
437
  try {
@@ -792,18 +800,23 @@ function outputFiles(options, names, generatorOptions) {
792
800
  if (options.tokens) files.push([(0, import_node_path3.resolve)(process.cwd(), options.tokens), generateTokens(names, generatorOptions)]);
793
801
  return files;
794
802
  }
795
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
803
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options, meta) => {
796
804
  assertPruneCompatible(options);
797
805
  let cachedScan = null;
806
+ let devServer = false;
798
807
  const scan = () => scanCss(options.input, options.exclude, options.selectors, options.themes);
799
808
  const applyPrune = async (names) => {
800
- if (!options.prune) return names;
809
+ if (!options.prune) return { names, usageFiles: [] };
801
810
  const usage = await scanUsage(options.usage, options.usageExclude);
802
811
  const { used, unused } = partitionUnused(names, usage, options);
803
812
  if (unused.length > 0) {
804
813
  console.warn(`css-typed-vars: pruned ${unused.length} unused variable(s): ${unused.join(", ")}`);
805
814
  }
806
- return used;
815
+ return { names: used, usageFiles: usage.files };
816
+ };
817
+ const watchFiles = (context, scanned, usageFiles) => {
818
+ if (devServer) return;
819
+ for (const file of [...scanned.files, ...usageFiles]) context.addWatchFile((0, import_node_path3.resolve)(file));
807
820
  };
808
821
  const generatorOptions = ({ declarations, properties, themes, docs }) => ({
809
822
  prefix: options.prefix,
@@ -824,6 +837,9 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
824
837
  name: "css-typed-vars",
825
838
  vite: {
826
839
  enforce: "pre",
840
+ configResolved(config) {
841
+ devServer = config.command === "serve";
842
+ },
827
843
  configureServer(server) {
828
844
  let generation = 0;
829
845
  let debounceTimer = null;
@@ -834,7 +850,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
834
850
  cachedScan = scanPromise;
835
851
  const scanned = await scanPromise;
836
852
  if (myGeneration !== generation) return;
837
- const names = await resolveNames(scanned);
853
+ const { names } = await resolveNames(scanned);
838
854
  if (myGeneration !== generation) return;
839
855
  const files = outputFiles(options, names, generatorOptions(scanned));
840
856
  if (files.length > 0) {
@@ -874,7 +890,8 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
874
890
  async buildStart() {
875
891
  cachedScan = scan();
876
892
  const scanned = await cachedScan;
877
- const names = await resolveNames(scanned);
893
+ const { names, usageFiles } = await resolveNames(scanned);
894
+ if (meta.framework !== "esbuild") watchFiles(this, scanned, usageFiles);
878
895
  for (const [path, content] of outputFiles(options, names, generatorOptions(scanned))) {
879
896
  await writeOutput(path, content);
880
897
  }
@@ -885,7 +902,8 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
885
902
  async load(id) {
886
903
  if (id === RESOLVED_ID) {
887
904
  const scanned = await (cachedScan ?? scan());
888
- const names = await applyPrune(collectVarNames(scanned));
905
+ const { names, usageFiles } = await applyPrune(collectVarNames(scanned));
906
+ watchFiles(this, scanned, usageFiles);
889
907
  return generateJs(names, generatorOptions(scanned));
890
908
  }
891
909
  }
package/dist/unplugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-NZUQZYNM.js";
4
- import "./chunk-XCAFJREQ.js";
3
+ } from "./chunk-CBN3J54B.js";
4
+ import "./chunk-TR53YUPE.js";
5
5
  export {
6
6
  unplugin_default as default
7
7
  };
package/dist/vite.cjs CHANGED
@@ -348,12 +348,20 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
348
348
  return matches(include) && !matches(ignore);
349
349
  };
350
350
  }
351
+ function globWatchRoots(patterns, cwd = process.cwd()) {
352
+ const roots = /* @__PURE__ */ new Map();
353
+ for (const pattern of normalizePatterns(patterns)) {
354
+ const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
355
+ 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;
357
+ const previous = roots.get(dir);
358
+ const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
359
+ roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
360
+ }
361
+ return [...roots].map(([dir, depth]) => depth === void 0 ? { dir } : { dir, depth });
362
+ }
351
363
  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)];
364
+ return globWatchRoots(patterns, cwd).map((root) => root.dir);
357
365
  }
358
366
  function collectVarNames(scanned) {
359
367
  const names = new Set(scanned.declarations.keys());
@@ -391,7 +399,7 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
391
399
  for (const [name, value] of values) themeValues.get(theme).set(name, value);
392
400
  }
393
401
  }
394
- return { declarations, properties, themes: themeValues, docs };
402
+ return { declarations, properties, themes: themeValues, docs, files };
395
403
  }
396
404
  var ROOT_RE = /\bcssVars\b/g;
397
405
  var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
@@ -425,7 +433,7 @@ async function scanUsage(patterns, exclude) {
425
433
  const normalized = normalizePatterns(patterns);
426
434
  const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
427
435
  const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
428
- const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set() };
436
+ const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
429
437
  const texts = await Promise.all(
430
438
  files.map(async (file) => {
431
439
  try {
@@ -794,18 +802,23 @@ function outputFiles(options, names, generatorOptions) {
794
802
  if (options.tokens) files.push([(0, import_node_path3.resolve)(process.cwd(), options.tokens), generateTokens(names, generatorOptions)]);
795
803
  return files;
796
804
  }
797
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
805
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options, meta) => {
798
806
  assertPruneCompatible(options);
799
807
  let cachedScan = null;
808
+ let devServer = false;
800
809
  const scan = () => scanCss(options.input, options.exclude, options.selectors, options.themes);
801
810
  const applyPrune = async (names) => {
802
- if (!options.prune) return names;
811
+ if (!options.prune) return { names, usageFiles: [] };
803
812
  const usage = await scanUsage(options.usage, options.usageExclude);
804
813
  const { used, unused } = partitionUnused(names, usage, options);
805
814
  if (unused.length > 0) {
806
815
  console.warn(`css-typed-vars: pruned ${unused.length} unused variable(s): ${unused.join(", ")}`);
807
816
  }
808
- return used;
817
+ return { names: used, usageFiles: usage.files };
818
+ };
819
+ const watchFiles = (context, scanned, usageFiles) => {
820
+ if (devServer) return;
821
+ for (const file of [...scanned.files, ...usageFiles]) context.addWatchFile((0, import_node_path3.resolve)(file));
809
822
  };
810
823
  const generatorOptions = ({ declarations, properties, themes, docs }) => ({
811
824
  prefix: options.prefix,
@@ -826,6 +839,9 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
826
839
  name: "css-typed-vars",
827
840
  vite: {
828
841
  enforce: "pre",
842
+ configResolved(config) {
843
+ devServer = config.command === "serve";
844
+ },
829
845
  configureServer(server) {
830
846
  let generation = 0;
831
847
  let debounceTimer = null;
@@ -836,7 +852,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
836
852
  cachedScan = scanPromise;
837
853
  const scanned = await scanPromise;
838
854
  if (myGeneration !== generation) return;
839
- const names = await resolveNames(scanned);
855
+ const { names } = await resolveNames(scanned);
840
856
  if (myGeneration !== generation) return;
841
857
  const files = outputFiles(options, names, generatorOptions(scanned));
842
858
  if (files.length > 0) {
@@ -876,7 +892,8 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
876
892
  async buildStart() {
877
893
  cachedScan = scan();
878
894
  const scanned = await cachedScan;
879
- const names = await resolveNames(scanned);
895
+ const { names, usageFiles } = await resolveNames(scanned);
896
+ if (meta.framework !== "esbuild") watchFiles(this, scanned, usageFiles);
880
897
  for (const [path, content] of outputFiles(options, names, generatorOptions(scanned))) {
881
898
  await writeOutput(path, content);
882
899
  }
@@ -887,7 +904,8 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
887
904
  async load(id) {
888
905
  if (id === RESOLVED_ID) {
889
906
  const scanned = await (cachedScan ?? scan());
890
- const names = await applyPrune(collectVarNames(scanned));
907
+ const { names, usageFiles } = await applyPrune(collectVarNames(scanned));
908
+ watchFiles(this, scanned, usageFiles);
891
909
  return generateJs(names, generatorOptions(scanned));
892
910
  }
893
911
  }
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-NZUQZYNM.js";
4
- import "./chunk-XCAFJREQ.js";
3
+ } from "./chunk-CBN3J54B.js";
4
+ import "./chunk-TR53YUPE.js";
5
5
 
6
6
  // src/vite.ts
7
7
  var vite_default = unplugin_default.vite;
package/dist/webpack.cjs CHANGED
@@ -348,12 +348,20 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
348
348
  return matches(include) && !matches(ignore);
349
349
  };
350
350
  }
351
+ function globWatchRoots(patterns, cwd = process.cwd()) {
352
+ const roots = /* @__PURE__ */ new Map();
353
+ for (const pattern of normalizePatterns(patterns)) {
354
+ const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
355
+ 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;
357
+ const previous = roots.get(dir);
358
+ const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
359
+ roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
360
+ }
361
+ return [...roots].map(([dir, depth]) => depth === void 0 ? { dir } : { dir, depth });
362
+ }
351
363
  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)];
364
+ return globWatchRoots(patterns, cwd).map((root) => root.dir);
357
365
  }
358
366
  function collectVarNames(scanned) {
359
367
  const names = new Set(scanned.declarations.keys());
@@ -391,7 +399,7 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
391
399
  for (const [name, value] of values) themeValues.get(theme).set(name, value);
392
400
  }
393
401
  }
394
- return { declarations, properties, themes: themeValues, docs };
402
+ return { declarations, properties, themes: themeValues, docs, files };
395
403
  }
396
404
  var ROOT_RE = /\bcssVars\b/g;
397
405
  var IMPORT_RE = /\bimport\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\b/g;
@@ -425,7 +433,7 @@ async function scanUsage(patterns, exclude) {
425
433
  const normalized = normalizePatterns(patterns);
426
434
  const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
427
435
  const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
428
- const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set() };
436
+ const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
429
437
  const texts = await Promise.all(
430
438
  files.map(async (file) => {
431
439
  try {
@@ -794,18 +802,23 @@ function outputFiles(options, names, generatorOptions) {
794
802
  if (options.tokens) files.push([(0, import_node_path3.resolve)(process.cwd(), options.tokens), generateTokens(names, generatorOptions)]);
795
803
  return files;
796
804
  }
797
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
805
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options, meta) => {
798
806
  assertPruneCompatible(options);
799
807
  let cachedScan = null;
808
+ let devServer = false;
800
809
  const scan = () => scanCss(options.input, options.exclude, options.selectors, options.themes);
801
810
  const applyPrune = async (names) => {
802
- if (!options.prune) return names;
811
+ if (!options.prune) return { names, usageFiles: [] };
803
812
  const usage = await scanUsage(options.usage, options.usageExclude);
804
813
  const { used, unused } = partitionUnused(names, usage, options);
805
814
  if (unused.length > 0) {
806
815
  console.warn(`css-typed-vars: pruned ${unused.length} unused variable(s): ${unused.join(", ")}`);
807
816
  }
808
- return used;
817
+ return { names: used, usageFiles: usage.files };
818
+ };
819
+ const watchFiles = (context, scanned, usageFiles) => {
820
+ if (devServer) return;
821
+ for (const file of [...scanned.files, ...usageFiles]) context.addWatchFile((0, import_node_path3.resolve)(file));
809
822
  };
810
823
  const generatorOptions = ({ declarations, properties, themes, docs }) => ({
811
824
  prefix: options.prefix,
@@ -826,6 +839,9 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
826
839
  name: "css-typed-vars",
827
840
  vite: {
828
841
  enforce: "pre",
842
+ configResolved(config) {
843
+ devServer = config.command === "serve";
844
+ },
829
845
  configureServer(server) {
830
846
  let generation = 0;
831
847
  let debounceTimer = null;
@@ -836,7 +852,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
836
852
  cachedScan = scanPromise;
837
853
  const scanned = await scanPromise;
838
854
  if (myGeneration !== generation) return;
839
- const names = await resolveNames(scanned);
855
+ const { names } = await resolveNames(scanned);
840
856
  if (myGeneration !== generation) return;
841
857
  const files = outputFiles(options, names, generatorOptions(scanned));
842
858
  if (files.length > 0) {
@@ -876,7 +892,8 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
876
892
  async buildStart() {
877
893
  cachedScan = scan();
878
894
  const scanned = await cachedScan;
879
- const names = await resolveNames(scanned);
895
+ const { names, usageFiles } = await resolveNames(scanned);
896
+ if (meta.framework !== "esbuild") watchFiles(this, scanned, usageFiles);
880
897
  for (const [path, content] of outputFiles(options, names, generatorOptions(scanned))) {
881
898
  await writeOutput(path, content);
882
899
  }
@@ -887,7 +904,8 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
887
904
  async load(id) {
888
905
  if (id === RESOLVED_ID) {
889
906
  const scanned = await (cachedScan ?? scan());
890
- const names = await applyPrune(collectVarNames(scanned));
907
+ const { names, usageFiles } = await applyPrune(collectVarNames(scanned));
908
+ watchFiles(this, scanned, usageFiles);
891
909
  return generateJs(names, generatorOptions(scanned));
892
910
  }
893
911
  }
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-NZUQZYNM.js";
4
- import "./chunk-XCAFJREQ.js";
3
+ } from "./chunk-CBN3J54B.js";
4
+ import "./chunk-TR53YUPE.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.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Generate TypeScript typed constants from CSS custom properties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -36,7 +36,8 @@
36
36
  "types": "./dist/generated.d.ts",
37
37
  "import": "./dist/vars.js",
38
38
  "require": "./dist/vars.cjs"
39
- }
39
+ },
40
+ "./schema.json": "./schema.json"
40
41
  },
41
42
  "bin": {
42
43
  "css-typed-vars": "./dist/cli.js"
@@ -69,7 +70,8 @@
69
70
  "tailwindcss"
70
71
  ],
71
72
  "files": [
72
- "dist"
73
+ "dist",
74
+ "schema.json"
73
75
  ],
74
76
  "scripts": {
75
77
  "build": "tsup && node scripts/postbuild.mjs",
@@ -80,7 +82,7 @@
80
82
  "docs:preview": "vitepress preview docs"
81
83
  },
82
84
  "dependencies": {
83
- "chokidar": "^3.6.0",
85
+ "chokidar": "^5.0.0",
84
86
  "fast-glob": "^3.3.2",
85
87
  "picomatch": "^2.3.2",
86
88
  "unplugin": "^3.0.0"
package/schema.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://unpkg.com/css-typed-vars/schema.json",
4
+ "title": "css-typed-vars config",
5
+ "description": "Options for the css-typed-vars CLI: one target, or an array of targets.",
6
+ "oneOf": [
7
+ { "$ref": "#/definitions/config" },
8
+ {
9
+ "type": "array",
10
+ "minItems": 1,
11
+ "items": { "$ref": "#/definitions/config" }
12
+ }
13
+ ],
14
+ "definitions": {
15
+ "globs": {
16
+ "oneOf": [
17
+ { "type": "string" },
18
+ { "type": "array", "items": { "type": "string" } }
19
+ ]
20
+ },
21
+ "config": {
22
+ "type": "object",
23
+ "additionalProperties": false,
24
+ "properties": {
25
+ "$schema": { "type": "string" },
26
+ "input": {
27
+ "$ref": "#/definitions/globs",
28
+ "description": "Glob(s) of the CSS files to scan."
29
+ },
30
+ "output": {
31
+ "type": "string",
32
+ "description": "Output file: .ts, .js/.mjs/.cjs (plus a .d.ts), or .json for W3C design tokens (DTCG)."
33
+ },
34
+ "exclude": {
35
+ "$ref": "#/definitions/globs",
36
+ "description": "Glob(s) of files to skip."
37
+ },
38
+ "prefix": {
39
+ "type": "string",
40
+ "description": "Prefix every generated key. Can't be combined with group."
41
+ },
42
+ "naming": {
43
+ "enum": ["camelCase", "snake", "kebab", "constant", "pascal"],
44
+ "description": "Naming convention of the generated keys. Defaults to camelCase."
45
+ },
46
+ "selectors": {
47
+ "type": "array",
48
+ "items": { "type": "string" },
49
+ "description": "Also scan these selectors' blocks, not just :root and @theme."
50
+ },
51
+ "themes": {
52
+ "type": "object",
53
+ "additionalProperties": { "type": "string" },
54
+ "description": "Theme name -> selector ('[data-theme=\"dark\"]') or @media prelude ('@media (prefers-color-scheme: dark)'). Values are emitted as @theme JSDoc tags."
55
+ },
56
+ "group": {
57
+ "type": "boolean",
58
+ "description": "Nest keys by the first hyphen segment of the name (cssVars.color.primary)."
59
+ },
60
+ "helpers": {
61
+ "type": "boolean",
62
+ "description": "Also emit the CssVarRef type and the getCssVar/setCssVar/withFallback helpers."
63
+ },
64
+ "prune": {
65
+ "type": "boolean",
66
+ "description": "Drop vars with no detected cssVars.<key> usage. Requires usage."
67
+ },
68
+ "usage": {
69
+ "$ref": "#/definitions/globs",
70
+ "description": "Glob(s) of the source files to scan for cssVars usage (prune, --prune-check)."
71
+ },
72
+ "usageExclude": {
73
+ "$ref": "#/definitions/globs",
74
+ "description": "Glob(s) of source files to skip in the usage scan."
75
+ },
76
+ "refsIgnore": {
77
+ "type": "array",
78
+ "items": { "type": "string" },
79
+ "description": "Names (or --prefix-* patterns) that --lint-refs shouldn't report, e.g. vars set from JS."
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }