css-typed-vars 0.4.14 → 0.4.15

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.
@@ -4,7 +4,7 @@ import {
4
4
  generateDeclaration,
5
5
  generateJs,
6
6
  scanVarNames
7
- } from "./chunk-3UIYKYIL.js";
7
+ } from "./chunk-W4JDUG2N.js";
8
8
 
9
9
  // src/index.ts
10
10
  import { writeFile, mkdir } from "fs/promises";
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  __dirname,
3
+ findKeyCollisions,
3
4
  generateDeclaration,
4
5
  generateJs,
5
6
  scanVarNames
6
- } from "./chunk-3UIYKYIL.js";
7
+ } from "./chunk-W4JDUG2N.js";
7
8
 
8
9
  // src/unplugin.ts
9
10
  import { createUnplugin } from "unplugin";
@@ -11,6 +12,11 @@ import { writeFile } from "fs/promises";
11
12
  import { join, resolve } from "path";
12
13
  var VIRTUAL_ID = "css-typed-vars/vars";
13
14
  var RESOLVED_ID = "\0css-typed-vars/vars";
15
+ function warnOnCollisions(names, options) {
16
+ for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
17
+ console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
18
+ }
19
+ }
14
20
  function getDtsPath(options) {
15
21
  if (options.dts === false) return null;
16
22
  return options.dts ? resolve(process.cwd(), options.dts) : join(__dirname, "generated.d.ts");
@@ -22,31 +28,45 @@ var unplugin_default = createUnplugin((options) => {
22
28
  vite: {
23
29
  enforce: "pre",
24
30
  configureServer(server) {
25
- const handle = async (file) => {
26
- if (!/\.(css|scss|less)$/i.test(file)) return;
27
- cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
28
- const names = await cachedNames;
31
+ let generation = 0;
32
+ let debounceTimer = null;
33
+ const rescan = async () => {
34
+ const myGeneration = ++generation;
35
+ const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
36
+ cachedNames = namesPromise;
37
+ const names = await namesPromise;
38
+ if (myGeneration !== generation) return;
39
+ warnOnCollisions(names, options);
29
40
  const dtsPath = getDtsPath(options);
30
41
  if (dtsPath) {
31
42
  await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
32
43
  }
44
+ if (myGeneration !== generation) return;
33
45
  const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
34
46
  if (mod) {
35
47
  server.moduleGraph.invalidateModule(mod);
36
48
  server.ws.send({ type: "full-reload" });
37
49
  }
38
50
  };
39
- const safeHandle = (file) => handle(file).catch(console.error);
40
- server.watcher.on("change", safeHandle);
41
- server.watcher.on("add", safeHandle);
42
- server.watcher.on("unlink", safeHandle);
51
+ const handle = (file) => {
52
+ if (!/\.(css|scss|less)$/i.test(file)) return;
53
+ if (debounceTimer) clearTimeout(debounceTimer);
54
+ debounceTimer = setTimeout(() => {
55
+ debounceTimer = null;
56
+ rescan().catch(console.error);
57
+ }, 100);
58
+ };
59
+ server.watcher.on("change", handle);
60
+ server.watcher.on("add", handle);
61
+ server.watcher.on("unlink", handle);
43
62
  }
44
63
  },
45
64
  async buildStart() {
46
65
  cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
66
+ const names = await cachedNames;
67
+ warnOnCollisions(names, options);
47
68
  const dtsPath = getDtsPath(options);
48
69
  if (!dtsPath) return;
49
- const names = await cachedNames;
50
70
  await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
51
71
  },
52
72
  resolveId(id) {
@@ -149,7 +149,7 @@ async function scanVarNames(patterns, exclude, selectors) {
149
149
  var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
150
150
  function convertCase(value, naming) {
151
151
  if (!VALID_NAMINGS.includes(naming)) {
152
- throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
152
+ throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: ${VALID_NAMINGS.join(", ")}`);
153
153
  }
154
154
  if (naming === "kebab") return value;
155
155
  return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
@@ -187,11 +187,16 @@ function findKeyCollisions(varNames, prefix, naming) {
187
187
  }
188
188
  return byKey;
189
189
  }
190
- function generateCode(varNames, prefix, naming) {
191
- const entries = varNames.map((name) => {
190
+ function buildEntries(varNames, prefix, naming) {
191
+ const byKey = /* @__PURE__ */ new Map();
192
+ for (const name of varNames) {
192
193
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
193
- return ` ${key}: 'var(${name})',`;
194
- });
194
+ byKey.set(key, name);
195
+ }
196
+ return [...byKey].map(([key, name]) => ({ key, name }));
197
+ }
198
+ function generateCode(varNames, prefix, naming) {
199
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})',`);
195
200
  return [
196
201
  "// generated \u2014 do not edit",
197
202
  "export const cssVars = {",
@@ -203,10 +208,7 @@ function generateCode(varNames, prefix, naming) {
203
208
  ].join("\n");
204
209
  }
205
210
  function generateJs(varNames, prefix, naming) {
206
- const entries = varNames.map((name) => {
207
- const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
208
- return ` ${key}: 'var(${name})',`;
209
- });
211
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})',`);
210
212
  return [
211
213
  "// generated \u2014 do not edit",
212
214
  "export const cssVars = {",
@@ -216,10 +218,7 @@ function generateJs(varNames, prefix, naming) {
216
218
  ].join("\n");
217
219
  }
218
220
  function generateDeclaration(varNames, prefix, naming) {
219
- const entries = varNames.map((name) => {
220
- const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
221
- return ` ${key}: 'var(${name})';`;
222
- });
221
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})';`);
223
222
  return [
224
223
  "export declare const cssVars: {",
225
224
  ...entries,
@@ -233,6 +232,7 @@ export {
233
232
  __dirname,
234
233
  parseVarNames,
235
234
  scanVarNames,
235
+ VALID_NAMINGS,
236
236
  findKeyCollisions,
237
237
  generateCode,
238
238
  generateJs,
package/dist/cli.cjs CHANGED
@@ -183,7 +183,7 @@ async function scanVarNames(patterns, exclude, selectors) {
183
183
  var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
184
184
  function convertCase(value, naming) {
185
185
  if (!VALID_NAMINGS.includes(naming)) {
186
- throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
186
+ throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: ${VALID_NAMINGS.join(", ")}`);
187
187
  }
188
188
  if (naming === "kebab") return value;
189
189
  return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
@@ -221,11 +221,16 @@ function findKeyCollisions(varNames, prefix, naming) {
221
221
  }
222
222
  return byKey;
223
223
  }
224
- function generateCode(varNames, prefix, naming) {
225
- const entries = varNames.map((name) => {
224
+ function buildEntries(varNames, prefix, naming) {
225
+ const byKey = /* @__PURE__ */ new Map();
226
+ for (const name of varNames) {
226
227
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
227
- return ` ${key}: 'var(${name})',`;
228
- });
228
+ byKey.set(key, name);
229
+ }
230
+ return [...byKey].map(([key, name]) => ({ key, name }));
231
+ }
232
+ function generateCode(varNames, prefix, naming) {
233
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})',`);
229
234
  return [
230
235
  "// generated \u2014 do not edit",
231
236
  "export const cssVars = {",
@@ -237,10 +242,7 @@ function generateCode(varNames, prefix, naming) {
237
242
  ].join("\n");
238
243
  }
239
244
  function generateJs(varNames, prefix, naming) {
240
- const entries = varNames.map((name) => {
241
- const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
242
- return ` ${key}: 'var(${name})',`;
243
- });
245
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})',`);
244
246
  return [
245
247
  "// generated \u2014 do not edit",
246
248
  "export const cssVars = {",
@@ -250,10 +252,7 @@ function generateJs(varNames, prefix, naming) {
250
252
  ].join("\n");
251
253
  }
252
254
  function generateDeclaration(varNames, prefix, naming) {
253
- const entries = varNames.map((name) => {
254
- const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
255
- return ` ${key}: 'var(${name})';`;
256
- });
255
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})';`);
257
256
  return [
258
257
  "export declare const cssVars: {",
259
258
  ...entries,
@@ -343,8 +342,8 @@ async function main() {
343
342
  const exclude = excludeArgs.length > 0 ? excludeArgs : config.exclude;
344
343
  const prefix = getArg("--prefix") ?? config.prefix;
345
344
  const namingRaw = getArg("--naming") ?? config.naming;
346
- if (namingRaw !== void 0 && !["camelCase", "snake", "kebab"].includes(namingRaw)) {
347
- console.error(`css-typed-vars: invalid --naming value "${namingRaw}". Valid values: camelCase, snake, kebab`);
345
+ if (namingRaw !== void 0 && !VALID_NAMINGS.includes(namingRaw)) {
346
+ console.error(`css-typed-vars: invalid --naming value "${namingRaw}". Valid values: ${VALID_NAMINGS.join(", ")}`);
348
347
  process.exit(1);
349
348
  }
350
349
  const naming = namingRaw;
package/dist/cli.js CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  generate
4
- } from "./chunk-2JDQ2DY7.js";
5
- import "./chunk-3UIYKYIL.js";
4
+ } from "./chunk-2QDRH4OL.js";
5
+ import {
6
+ VALID_NAMINGS
7
+ } from "./chunk-W4JDUG2N.js";
6
8
 
7
9
  // src/cli.ts
8
10
  import { readFile } from "fs/promises";
@@ -67,8 +69,8 @@ async function main() {
67
69
  const exclude = excludeArgs.length > 0 ? excludeArgs : config.exclude;
68
70
  const prefix = getArg("--prefix") ?? config.prefix;
69
71
  const namingRaw = getArg("--naming") ?? config.naming;
70
- if (namingRaw !== void 0 && !["camelCase", "snake", "kebab"].includes(namingRaw)) {
71
- console.error(`css-typed-vars: invalid --naming value "${namingRaw}". Valid values: camelCase, snake, kebab`);
72
+ if (namingRaw !== void 0 && !VALID_NAMINGS.includes(namingRaw)) {
73
+ console.error(`css-typed-vars: invalid --naming value "${namingRaw}". Valid values: ${VALID_NAMINGS.join(", ")}`);
72
74
  process.exit(1);
73
75
  }
74
76
  const naming = namingRaw;
package/dist/esbuild.cjs CHANGED
@@ -185,7 +185,7 @@ async function scanVarNames(patterns, exclude, selectors) {
185
185
  var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
186
186
  function convertCase(value, naming) {
187
187
  if (!VALID_NAMINGS.includes(naming)) {
188
- throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
188
+ throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: ${VALID_NAMINGS.join(", ")}`);
189
189
  }
190
190
  if (naming === "kebab") return value;
191
191
  return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
@@ -210,11 +210,29 @@ function formatKey(key, naming = "camelCase") {
210
210
  if (naming === "kebab") return `'${key}'`;
211
211
  return key;
212
212
  }
213
- function generateJs(varNames, prefix, naming) {
214
- const entries = varNames.map((name) => {
213
+ function findKeyCollisions(varNames, prefix, naming) {
214
+ const byKey = /* @__PURE__ */ new Map();
215
+ for (const name of varNames) {
216
+ const key = applyPrefix(toKey(name, naming), prefix, naming);
217
+ const existing = byKey.get(key);
218
+ if (existing) existing.push(name);
219
+ else byKey.set(key, [name]);
220
+ }
221
+ for (const [key, names] of byKey) {
222
+ if (names.length < 2) byKey.delete(key);
223
+ }
224
+ return byKey;
225
+ }
226
+ function buildEntries(varNames, prefix, naming) {
227
+ const byKey = /* @__PURE__ */ new Map();
228
+ for (const name of varNames) {
215
229
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
216
- return ` ${key}: 'var(${name})',`;
217
- });
230
+ byKey.set(key, name);
231
+ }
232
+ return [...byKey].map(([key, name]) => ({ key, name }));
233
+ }
234
+ function generateJs(varNames, prefix, naming) {
235
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})',`);
218
236
  return [
219
237
  "// generated \u2014 do not edit",
220
238
  "export const cssVars = {",
@@ -224,10 +242,7 @@ function generateJs(varNames, prefix, naming) {
224
242
  ].join("\n");
225
243
  }
226
244
  function generateDeclaration(varNames, prefix, naming) {
227
- const entries = varNames.map((name) => {
228
- const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
229
- return ` ${key}: 'var(${name})';`;
230
- });
245
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})';`);
231
246
  return [
232
247
  "export declare const cssVars: {",
233
248
  ...entries,
@@ -240,6 +255,11 @@ function generateDeclaration(varNames, prefix, naming) {
240
255
  // src/unplugin.ts
241
256
  var VIRTUAL_ID = "css-typed-vars/vars";
242
257
  var RESOLVED_ID = "\0css-typed-vars/vars";
258
+ function warnOnCollisions(names, options) {
259
+ for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
260
+ console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
261
+ }
262
+ }
243
263
  function getDtsPath(options) {
244
264
  if (options.dts === false) return null;
245
265
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
@@ -251,31 +271,45 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
251
271
  vite: {
252
272
  enforce: "pre",
253
273
  configureServer(server) {
254
- const handle = async (file) => {
255
- if (!/\.(css|scss|less)$/i.test(file)) return;
256
- cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
257
- const names = await cachedNames;
274
+ let generation = 0;
275
+ let debounceTimer = null;
276
+ const rescan = async () => {
277
+ const myGeneration = ++generation;
278
+ const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
279
+ cachedNames = namesPromise;
280
+ const names = await namesPromise;
281
+ if (myGeneration !== generation) return;
282
+ warnOnCollisions(names, options);
258
283
  const dtsPath = getDtsPath(options);
259
284
  if (dtsPath) {
260
285
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
261
286
  }
287
+ if (myGeneration !== generation) return;
262
288
  const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
263
289
  if (mod) {
264
290
  server.moduleGraph.invalidateModule(mod);
265
291
  server.ws.send({ type: "full-reload" });
266
292
  }
267
293
  };
268
- const safeHandle = (file) => handle(file).catch(console.error);
269
- server.watcher.on("change", safeHandle);
270
- server.watcher.on("add", safeHandle);
271
- server.watcher.on("unlink", safeHandle);
294
+ const handle = (file) => {
295
+ if (!/\.(css|scss|less)$/i.test(file)) return;
296
+ if (debounceTimer) clearTimeout(debounceTimer);
297
+ debounceTimer = setTimeout(() => {
298
+ debounceTimer = null;
299
+ rescan().catch(console.error);
300
+ }, 100);
301
+ };
302
+ server.watcher.on("change", handle);
303
+ server.watcher.on("add", handle);
304
+ server.watcher.on("unlink", handle);
272
305
  }
273
306
  },
274
307
  async buildStart() {
275
308
  cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
309
+ const names = await cachedNames;
310
+ warnOnCollisions(names, options);
276
311
  const dtsPath = getDtsPath(options);
277
312
  if (!dtsPath) return;
278
- const names = await cachedNames;
279
313
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
280
314
  },
281
315
  resolveId(id) {
package/dist/esbuild.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-HS4B2QT2.js";
4
- import "./chunk-3UIYKYIL.js";
3
+ } from "./chunk-AUFD5VOT.js";
4
+ import "./chunk-W4JDUG2N.js";
5
5
 
6
6
  // src/esbuild.ts
7
7
  var esbuild_default = unplugin_default.esbuild;
package/dist/index.cjs CHANGED
@@ -187,7 +187,7 @@ async function scanVarNames(patterns, exclude, selectors) {
187
187
  var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
188
188
  function convertCase(value, naming) {
189
189
  if (!VALID_NAMINGS.includes(naming)) {
190
- throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
190
+ throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: ${VALID_NAMINGS.join(", ")}`);
191
191
  }
192
192
  if (naming === "kebab") return value;
193
193
  return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
@@ -225,11 +225,16 @@ function findKeyCollisions(varNames, prefix, naming) {
225
225
  }
226
226
  return byKey;
227
227
  }
228
- function generateCode(varNames, prefix, naming) {
229
- const entries = varNames.map((name) => {
228
+ function buildEntries(varNames, prefix, naming) {
229
+ const byKey = /* @__PURE__ */ new Map();
230
+ for (const name of varNames) {
230
231
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
231
- return ` ${key}: 'var(${name})',`;
232
- });
232
+ byKey.set(key, name);
233
+ }
234
+ return [...byKey].map(([key, name]) => ({ key, name }));
235
+ }
236
+ function generateCode(varNames, prefix, naming) {
237
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})',`);
233
238
  return [
234
239
  "// generated \u2014 do not edit",
235
240
  "export const cssVars = {",
@@ -241,10 +246,7 @@ function generateCode(varNames, prefix, naming) {
241
246
  ].join("\n");
242
247
  }
243
248
  function generateJs(varNames, prefix, naming) {
244
- const entries = varNames.map((name) => {
245
- const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
246
- return ` ${key}: 'var(${name})',`;
247
- });
249
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})',`);
248
250
  return [
249
251
  "// generated \u2014 do not edit",
250
252
  "export const cssVars = {",
@@ -254,10 +256,7 @@ function generateJs(varNames, prefix, naming) {
254
256
  ].join("\n");
255
257
  }
256
258
  function generateDeclaration(varNames, prefix, naming) {
257
- const entries = varNames.map((name) => {
258
- const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
259
- return ` ${key}: 'var(${name})';`;
260
- });
259
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})';`);
261
260
  return [
262
261
  "export declare const cssVars: {",
263
262
  ...entries,
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  generate
3
- } from "./chunk-2JDQ2DY7.js";
3
+ } from "./chunk-2QDRH4OL.js";
4
4
  import {
5
5
  generateCode,
6
6
  generateDeclaration,
7
7
  generateJs,
8
8
  parseVarNames,
9
9
  scanVarNames
10
- } from "./chunk-3UIYKYIL.js";
10
+ } from "./chunk-W4JDUG2N.js";
11
11
  export {
12
12
  generate,
13
13
  generateCode,
package/dist/rollup.cjs CHANGED
@@ -185,7 +185,7 @@ async function scanVarNames(patterns, exclude, selectors) {
185
185
  var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
186
186
  function convertCase(value, naming) {
187
187
  if (!VALID_NAMINGS.includes(naming)) {
188
- throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
188
+ throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: ${VALID_NAMINGS.join(", ")}`);
189
189
  }
190
190
  if (naming === "kebab") return value;
191
191
  return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
@@ -210,11 +210,29 @@ function formatKey(key, naming = "camelCase") {
210
210
  if (naming === "kebab") return `'${key}'`;
211
211
  return key;
212
212
  }
213
- function generateJs(varNames, prefix, naming) {
214
- const entries = varNames.map((name) => {
213
+ function findKeyCollisions(varNames, prefix, naming) {
214
+ const byKey = /* @__PURE__ */ new Map();
215
+ for (const name of varNames) {
216
+ const key = applyPrefix(toKey(name, naming), prefix, naming);
217
+ const existing = byKey.get(key);
218
+ if (existing) existing.push(name);
219
+ else byKey.set(key, [name]);
220
+ }
221
+ for (const [key, names] of byKey) {
222
+ if (names.length < 2) byKey.delete(key);
223
+ }
224
+ return byKey;
225
+ }
226
+ function buildEntries(varNames, prefix, naming) {
227
+ const byKey = /* @__PURE__ */ new Map();
228
+ for (const name of varNames) {
215
229
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
216
- return ` ${key}: 'var(${name})',`;
217
- });
230
+ byKey.set(key, name);
231
+ }
232
+ return [...byKey].map(([key, name]) => ({ key, name }));
233
+ }
234
+ function generateJs(varNames, prefix, naming) {
235
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})',`);
218
236
  return [
219
237
  "// generated \u2014 do not edit",
220
238
  "export const cssVars = {",
@@ -224,10 +242,7 @@ function generateJs(varNames, prefix, naming) {
224
242
  ].join("\n");
225
243
  }
226
244
  function generateDeclaration(varNames, prefix, naming) {
227
- const entries = varNames.map((name) => {
228
- const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
229
- return ` ${key}: 'var(${name})';`;
230
- });
245
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})';`);
231
246
  return [
232
247
  "export declare const cssVars: {",
233
248
  ...entries,
@@ -240,6 +255,11 @@ function generateDeclaration(varNames, prefix, naming) {
240
255
  // src/unplugin.ts
241
256
  var VIRTUAL_ID = "css-typed-vars/vars";
242
257
  var RESOLVED_ID = "\0css-typed-vars/vars";
258
+ function warnOnCollisions(names, options) {
259
+ for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
260
+ console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
261
+ }
262
+ }
243
263
  function getDtsPath(options) {
244
264
  if (options.dts === false) return null;
245
265
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
@@ -251,31 +271,45 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
251
271
  vite: {
252
272
  enforce: "pre",
253
273
  configureServer(server) {
254
- const handle = async (file) => {
255
- if (!/\.(css|scss|less)$/i.test(file)) return;
256
- cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
257
- const names = await cachedNames;
274
+ let generation = 0;
275
+ let debounceTimer = null;
276
+ const rescan = async () => {
277
+ const myGeneration = ++generation;
278
+ const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
279
+ cachedNames = namesPromise;
280
+ const names = await namesPromise;
281
+ if (myGeneration !== generation) return;
282
+ warnOnCollisions(names, options);
258
283
  const dtsPath = getDtsPath(options);
259
284
  if (dtsPath) {
260
285
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
261
286
  }
287
+ if (myGeneration !== generation) return;
262
288
  const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
263
289
  if (mod) {
264
290
  server.moduleGraph.invalidateModule(mod);
265
291
  server.ws.send({ type: "full-reload" });
266
292
  }
267
293
  };
268
- const safeHandle = (file) => handle(file).catch(console.error);
269
- server.watcher.on("change", safeHandle);
270
- server.watcher.on("add", safeHandle);
271
- server.watcher.on("unlink", safeHandle);
294
+ const handle = (file) => {
295
+ if (!/\.(css|scss|less)$/i.test(file)) return;
296
+ if (debounceTimer) clearTimeout(debounceTimer);
297
+ debounceTimer = setTimeout(() => {
298
+ debounceTimer = null;
299
+ rescan().catch(console.error);
300
+ }, 100);
301
+ };
302
+ server.watcher.on("change", handle);
303
+ server.watcher.on("add", handle);
304
+ server.watcher.on("unlink", handle);
272
305
  }
273
306
  },
274
307
  async buildStart() {
275
308
  cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
309
+ const names = await cachedNames;
310
+ warnOnCollisions(names, options);
276
311
  const dtsPath = getDtsPath(options);
277
312
  if (!dtsPath) return;
278
- const names = await cachedNames;
279
313
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
280
314
  },
281
315
  resolveId(id) {
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-HS4B2QT2.js";
4
- import "./chunk-3UIYKYIL.js";
3
+ } from "./chunk-AUFD5VOT.js";
4
+ import "./chunk-W4JDUG2N.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  var rollup_default = unplugin_default.rollup;
package/dist/unplugin.cjs CHANGED
@@ -183,7 +183,7 @@ async function scanVarNames(patterns, exclude, selectors) {
183
183
  var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
184
184
  function convertCase(value, naming) {
185
185
  if (!VALID_NAMINGS.includes(naming)) {
186
- throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
186
+ throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: ${VALID_NAMINGS.join(", ")}`);
187
187
  }
188
188
  if (naming === "kebab") return value;
189
189
  return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
@@ -208,11 +208,29 @@ function formatKey(key, naming = "camelCase") {
208
208
  if (naming === "kebab") return `'${key}'`;
209
209
  return key;
210
210
  }
211
- function generateJs(varNames, prefix, naming) {
212
- const entries = varNames.map((name) => {
211
+ function findKeyCollisions(varNames, prefix, naming) {
212
+ const byKey = /* @__PURE__ */ new Map();
213
+ for (const name of varNames) {
214
+ const key = applyPrefix(toKey(name, naming), prefix, naming);
215
+ const existing = byKey.get(key);
216
+ if (existing) existing.push(name);
217
+ else byKey.set(key, [name]);
218
+ }
219
+ for (const [key, names] of byKey) {
220
+ if (names.length < 2) byKey.delete(key);
221
+ }
222
+ return byKey;
223
+ }
224
+ function buildEntries(varNames, prefix, naming) {
225
+ const byKey = /* @__PURE__ */ new Map();
226
+ for (const name of varNames) {
213
227
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
214
- return ` ${key}: 'var(${name})',`;
215
- });
228
+ byKey.set(key, name);
229
+ }
230
+ return [...byKey].map(([key, name]) => ({ key, name }));
231
+ }
232
+ function generateJs(varNames, prefix, naming) {
233
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})',`);
216
234
  return [
217
235
  "// generated \u2014 do not edit",
218
236
  "export const cssVars = {",
@@ -222,10 +240,7 @@ function generateJs(varNames, prefix, naming) {
222
240
  ].join("\n");
223
241
  }
224
242
  function generateDeclaration(varNames, prefix, naming) {
225
- const entries = varNames.map((name) => {
226
- const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
227
- return ` ${key}: 'var(${name})';`;
228
- });
243
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})';`);
229
244
  return [
230
245
  "export declare const cssVars: {",
231
246
  ...entries,
@@ -238,6 +253,11 @@ function generateDeclaration(varNames, prefix, naming) {
238
253
  // src/unplugin.ts
239
254
  var VIRTUAL_ID = "css-typed-vars/vars";
240
255
  var RESOLVED_ID = "\0css-typed-vars/vars";
256
+ function warnOnCollisions(names, options) {
257
+ for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
258
+ console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
259
+ }
260
+ }
241
261
  function getDtsPath(options) {
242
262
  if (options.dts === false) return null;
243
263
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
@@ -249,31 +269,45 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
249
269
  vite: {
250
270
  enforce: "pre",
251
271
  configureServer(server) {
252
- const handle = async (file) => {
253
- if (!/\.(css|scss|less)$/i.test(file)) return;
254
- cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
255
- const names = await cachedNames;
272
+ let generation = 0;
273
+ let debounceTimer = null;
274
+ const rescan = async () => {
275
+ const myGeneration = ++generation;
276
+ const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
277
+ cachedNames = namesPromise;
278
+ const names = await namesPromise;
279
+ if (myGeneration !== generation) return;
280
+ warnOnCollisions(names, options);
256
281
  const dtsPath = getDtsPath(options);
257
282
  if (dtsPath) {
258
283
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
259
284
  }
285
+ if (myGeneration !== generation) return;
260
286
  const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
261
287
  if (mod) {
262
288
  server.moduleGraph.invalidateModule(mod);
263
289
  server.ws.send({ type: "full-reload" });
264
290
  }
265
291
  };
266
- const safeHandle = (file) => handle(file).catch(console.error);
267
- server.watcher.on("change", safeHandle);
268
- server.watcher.on("add", safeHandle);
269
- server.watcher.on("unlink", safeHandle);
292
+ const handle = (file) => {
293
+ if (!/\.(css|scss|less)$/i.test(file)) return;
294
+ if (debounceTimer) clearTimeout(debounceTimer);
295
+ debounceTimer = setTimeout(() => {
296
+ debounceTimer = null;
297
+ rescan().catch(console.error);
298
+ }, 100);
299
+ };
300
+ server.watcher.on("change", handle);
301
+ server.watcher.on("add", handle);
302
+ server.watcher.on("unlink", handle);
270
303
  }
271
304
  },
272
305
  async buildStart() {
273
306
  cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
307
+ const names = await cachedNames;
308
+ warnOnCollisions(names, options);
274
309
  const dtsPath = getDtsPath(options);
275
310
  if (!dtsPath) return;
276
- const names = await cachedNames;
277
311
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
278
312
  },
279
313
  resolveId(id) {
package/dist/unplugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-HS4B2QT2.js";
4
- import "./chunk-3UIYKYIL.js";
3
+ } from "./chunk-AUFD5VOT.js";
4
+ import "./chunk-W4JDUG2N.js";
5
5
  export {
6
6
  unplugin_default as default
7
7
  };
package/dist/vite.cjs CHANGED
@@ -185,7 +185,7 @@ async function scanVarNames(patterns, exclude, selectors) {
185
185
  var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
186
186
  function convertCase(value, naming) {
187
187
  if (!VALID_NAMINGS.includes(naming)) {
188
- throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
188
+ throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: ${VALID_NAMINGS.join(", ")}`);
189
189
  }
190
190
  if (naming === "kebab") return value;
191
191
  return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
@@ -210,11 +210,29 @@ function formatKey(key, naming = "camelCase") {
210
210
  if (naming === "kebab") return `'${key}'`;
211
211
  return key;
212
212
  }
213
- function generateJs(varNames, prefix, naming) {
214
- const entries = varNames.map((name) => {
213
+ function findKeyCollisions(varNames, prefix, naming) {
214
+ const byKey = /* @__PURE__ */ new Map();
215
+ for (const name of varNames) {
216
+ const key = applyPrefix(toKey(name, naming), prefix, naming);
217
+ const existing = byKey.get(key);
218
+ if (existing) existing.push(name);
219
+ else byKey.set(key, [name]);
220
+ }
221
+ for (const [key, names] of byKey) {
222
+ if (names.length < 2) byKey.delete(key);
223
+ }
224
+ return byKey;
225
+ }
226
+ function buildEntries(varNames, prefix, naming) {
227
+ const byKey = /* @__PURE__ */ new Map();
228
+ for (const name of varNames) {
215
229
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
216
- return ` ${key}: 'var(${name})',`;
217
- });
230
+ byKey.set(key, name);
231
+ }
232
+ return [...byKey].map(([key, name]) => ({ key, name }));
233
+ }
234
+ function generateJs(varNames, prefix, naming) {
235
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})',`);
218
236
  return [
219
237
  "// generated \u2014 do not edit",
220
238
  "export const cssVars = {",
@@ -224,10 +242,7 @@ function generateJs(varNames, prefix, naming) {
224
242
  ].join("\n");
225
243
  }
226
244
  function generateDeclaration(varNames, prefix, naming) {
227
- const entries = varNames.map((name) => {
228
- const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
229
- return ` ${key}: 'var(${name})';`;
230
- });
245
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})';`);
231
246
  return [
232
247
  "export declare const cssVars: {",
233
248
  ...entries,
@@ -240,6 +255,11 @@ function generateDeclaration(varNames, prefix, naming) {
240
255
  // src/unplugin.ts
241
256
  var VIRTUAL_ID = "css-typed-vars/vars";
242
257
  var RESOLVED_ID = "\0css-typed-vars/vars";
258
+ function warnOnCollisions(names, options) {
259
+ for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
260
+ console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
261
+ }
262
+ }
243
263
  function getDtsPath(options) {
244
264
  if (options.dts === false) return null;
245
265
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
@@ -251,31 +271,45 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
251
271
  vite: {
252
272
  enforce: "pre",
253
273
  configureServer(server) {
254
- const handle = async (file) => {
255
- if (!/\.(css|scss|less)$/i.test(file)) return;
256
- cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
257
- const names = await cachedNames;
274
+ let generation = 0;
275
+ let debounceTimer = null;
276
+ const rescan = async () => {
277
+ const myGeneration = ++generation;
278
+ const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
279
+ cachedNames = namesPromise;
280
+ const names = await namesPromise;
281
+ if (myGeneration !== generation) return;
282
+ warnOnCollisions(names, options);
258
283
  const dtsPath = getDtsPath(options);
259
284
  if (dtsPath) {
260
285
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
261
286
  }
287
+ if (myGeneration !== generation) return;
262
288
  const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
263
289
  if (mod) {
264
290
  server.moduleGraph.invalidateModule(mod);
265
291
  server.ws.send({ type: "full-reload" });
266
292
  }
267
293
  };
268
- const safeHandle = (file) => handle(file).catch(console.error);
269
- server.watcher.on("change", safeHandle);
270
- server.watcher.on("add", safeHandle);
271
- server.watcher.on("unlink", safeHandle);
294
+ const handle = (file) => {
295
+ if (!/\.(css|scss|less)$/i.test(file)) return;
296
+ if (debounceTimer) clearTimeout(debounceTimer);
297
+ debounceTimer = setTimeout(() => {
298
+ debounceTimer = null;
299
+ rescan().catch(console.error);
300
+ }, 100);
301
+ };
302
+ server.watcher.on("change", handle);
303
+ server.watcher.on("add", handle);
304
+ server.watcher.on("unlink", handle);
272
305
  }
273
306
  },
274
307
  async buildStart() {
275
308
  cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
309
+ const names = await cachedNames;
310
+ warnOnCollisions(names, options);
276
311
  const dtsPath = getDtsPath(options);
277
312
  if (!dtsPath) return;
278
- const names = await cachedNames;
279
313
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
280
314
  },
281
315
  resolveId(id) {
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-HS4B2QT2.js";
4
- import "./chunk-3UIYKYIL.js";
3
+ } from "./chunk-AUFD5VOT.js";
4
+ import "./chunk-W4JDUG2N.js";
5
5
 
6
6
  // src/vite.ts
7
7
  var vite_default = unplugin_default.vite;
package/dist/webpack.cjs CHANGED
@@ -185,7 +185,7 @@ async function scanVarNames(patterns, exclude, selectors) {
185
185
  var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
186
186
  function convertCase(value, naming) {
187
187
  if (!VALID_NAMINGS.includes(naming)) {
188
- throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
188
+ throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: ${VALID_NAMINGS.join(", ")}`);
189
189
  }
190
190
  if (naming === "kebab") return value;
191
191
  return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
@@ -210,11 +210,29 @@ function formatKey(key, naming = "camelCase") {
210
210
  if (naming === "kebab") return `'${key}'`;
211
211
  return key;
212
212
  }
213
- function generateJs(varNames, prefix, naming) {
214
- const entries = varNames.map((name) => {
213
+ function findKeyCollisions(varNames, prefix, naming) {
214
+ const byKey = /* @__PURE__ */ new Map();
215
+ for (const name of varNames) {
216
+ const key = applyPrefix(toKey(name, naming), prefix, naming);
217
+ const existing = byKey.get(key);
218
+ if (existing) existing.push(name);
219
+ else byKey.set(key, [name]);
220
+ }
221
+ for (const [key, names] of byKey) {
222
+ if (names.length < 2) byKey.delete(key);
223
+ }
224
+ return byKey;
225
+ }
226
+ function buildEntries(varNames, prefix, naming) {
227
+ const byKey = /* @__PURE__ */ new Map();
228
+ for (const name of varNames) {
215
229
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
216
- return ` ${key}: 'var(${name})',`;
217
- });
230
+ byKey.set(key, name);
231
+ }
232
+ return [...byKey].map(([key, name]) => ({ key, name }));
233
+ }
234
+ function generateJs(varNames, prefix, naming) {
235
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})',`);
218
236
  return [
219
237
  "// generated \u2014 do not edit",
220
238
  "export const cssVars = {",
@@ -224,10 +242,7 @@ function generateJs(varNames, prefix, naming) {
224
242
  ].join("\n");
225
243
  }
226
244
  function generateDeclaration(varNames, prefix, naming) {
227
- const entries = varNames.map((name) => {
228
- const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
229
- return ` ${key}: 'var(${name})';`;
230
- });
245
+ const entries = buildEntries(varNames, prefix, naming).map(({ key, name }) => ` ${key}: 'var(${name})';`);
231
246
  return [
232
247
  "export declare const cssVars: {",
233
248
  ...entries,
@@ -240,6 +255,11 @@ function generateDeclaration(varNames, prefix, naming) {
240
255
  // src/unplugin.ts
241
256
  var VIRTUAL_ID = "css-typed-vars/vars";
242
257
  var RESOLVED_ID = "\0css-typed-vars/vars";
258
+ function warnOnCollisions(names, options) {
259
+ for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
260
+ console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
261
+ }
262
+ }
243
263
  function getDtsPath(options) {
244
264
  if (options.dts === false) return null;
245
265
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
@@ -251,31 +271,45 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
251
271
  vite: {
252
272
  enforce: "pre",
253
273
  configureServer(server) {
254
- const handle = async (file) => {
255
- if (!/\.(css|scss|less)$/i.test(file)) return;
256
- cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
257
- const names = await cachedNames;
274
+ let generation = 0;
275
+ let debounceTimer = null;
276
+ const rescan = async () => {
277
+ const myGeneration = ++generation;
278
+ const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
279
+ cachedNames = namesPromise;
280
+ const names = await namesPromise;
281
+ if (myGeneration !== generation) return;
282
+ warnOnCollisions(names, options);
258
283
  const dtsPath = getDtsPath(options);
259
284
  if (dtsPath) {
260
285
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
261
286
  }
287
+ if (myGeneration !== generation) return;
262
288
  const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
263
289
  if (mod) {
264
290
  server.moduleGraph.invalidateModule(mod);
265
291
  server.ws.send({ type: "full-reload" });
266
292
  }
267
293
  };
268
- const safeHandle = (file) => handle(file).catch(console.error);
269
- server.watcher.on("change", safeHandle);
270
- server.watcher.on("add", safeHandle);
271
- server.watcher.on("unlink", safeHandle);
294
+ const handle = (file) => {
295
+ if (!/\.(css|scss|less)$/i.test(file)) return;
296
+ if (debounceTimer) clearTimeout(debounceTimer);
297
+ debounceTimer = setTimeout(() => {
298
+ debounceTimer = null;
299
+ rescan().catch(console.error);
300
+ }, 100);
301
+ };
302
+ server.watcher.on("change", handle);
303
+ server.watcher.on("add", handle);
304
+ server.watcher.on("unlink", handle);
272
305
  }
273
306
  },
274
307
  async buildStart() {
275
308
  cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
309
+ const names = await cachedNames;
310
+ warnOnCollisions(names, options);
276
311
  const dtsPath = getDtsPath(options);
277
312
  if (!dtsPath) return;
278
- const names = await cachedNames;
279
313
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
280
314
  },
281
315
  resolveId(id) {
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-HS4B2QT2.js";
4
- import "./chunk-3UIYKYIL.js";
3
+ } from "./chunk-AUFD5VOT.js";
4
+ import "./chunk-W4JDUG2N.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.4.14",
3
+ "version": "0.4.15",
4
4
  "description": "Generate TypeScript typed constants from CSS custom properties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",