css-typed-vars 0.4.8 → 0.4.9

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.
@@ -3,7 +3,7 @@ import {
3
3
  generateDeclaration,
4
4
  generateJs,
5
5
  scanVarNames
6
- } from "./chunk-MJEASOAN.js";
6
+ } from "./chunk-Y3WJXRDA.js";
7
7
 
8
8
  // src/unplugin.ts
9
9
  import { createUnplugin } from "unplugin";
@@ -1,9 +1,10 @@
1
1
  import {
2
+ findKeyCollisions,
2
3
  generateCode,
3
4
  generateDeclaration,
4
5
  generateJs,
5
6
  scanVarNames
6
- } from "./chunk-MJEASOAN.js";
7
+ } from "./chunk-Y3WJXRDA.js";
7
8
 
8
9
  // src/index.ts
9
10
  import { writeFile, mkdir } from "fs/promises";
@@ -13,6 +14,9 @@ async function generate(options) {
13
14
  if (names.length === 0) {
14
15
  console.warn("css-typed-vars: no CSS custom properties found.");
15
16
  }
17
+ for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
18
+ console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
19
+ }
16
20
  const outPath = resolve(options.output);
17
21
  await mkdir(dirname(outPath), { recursive: true });
18
22
  if (options.output.endsWith(".js")) {
@@ -60,6 +60,19 @@ function formatKey(key, naming = "camelCase") {
60
60
  if (naming === "kebab") return `'${key}'`;
61
61
  return key;
62
62
  }
63
+ function findKeyCollisions(varNames, prefix, naming) {
64
+ const byKey = /* @__PURE__ */ new Map();
65
+ for (const name of varNames) {
66
+ const key = applyPrefix(toKey(name, naming), prefix, naming);
67
+ const existing = byKey.get(key);
68
+ if (existing) existing.push(name);
69
+ else byKey.set(key, [name]);
70
+ }
71
+ for (const [key, names] of byKey) {
72
+ if (names.length < 2) byKey.delete(key);
73
+ }
74
+ return byKey;
75
+ }
63
76
  function generateCode(varNames, prefix, naming) {
64
77
  const entries = varNames.map((name) => {
65
78
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
@@ -106,6 +119,7 @@ export {
106
119
  __dirname,
107
120
  parseVarNames,
108
121
  scanVarNames,
122
+ findKeyCollisions,
109
123
  generateCode,
110
124
  generateJs,
111
125
  generateDeclaration
package/dist/cli.cjs CHANGED
@@ -94,6 +94,19 @@ function formatKey(key, naming = "camelCase") {
94
94
  if (naming === "kebab") return `'${key}'`;
95
95
  return key;
96
96
  }
97
+ function findKeyCollisions(varNames, prefix, naming) {
98
+ const byKey = /* @__PURE__ */ new Map();
99
+ for (const name of varNames) {
100
+ const key = applyPrefix(toKey(name, naming), prefix, naming);
101
+ const existing = byKey.get(key);
102
+ if (existing) existing.push(name);
103
+ else byKey.set(key, [name]);
104
+ }
105
+ for (const [key, names] of byKey) {
106
+ if (names.length < 2) byKey.delete(key);
107
+ }
108
+ return byKey;
109
+ }
97
110
  function generateCode(varNames, prefix, naming) {
98
111
  const entries = varNames.map((name) => {
99
112
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
@@ -142,6 +155,9 @@ async function generate(options) {
142
155
  if (names.length === 0) {
143
156
  console.warn("css-typed-vars: no CSS custom properties found.");
144
157
  }
158
+ for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
159
+ console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
160
+ }
145
161
  const outPath = (0, import_node_path.resolve)(options.output);
146
162
  await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
147
163
  if (options.output.endsWith(".js")) {
@@ -154,7 +170,10 @@ async function generate(options) {
154
170
  }
155
171
 
156
172
  // src/cli.ts
157
- var args = process.argv.slice(2);
173
+ var args = process.argv.slice(2).flatMap((arg) => {
174
+ const match = /^(--[\w-]+)=(.*)$/.exec(arg);
175
+ return match ? [match[1], match[2]] : [arg];
176
+ });
158
177
  var getArg = (flag) => {
159
178
  const i = args.indexOf(flag);
160
179
  return i !== -1 ? args[i + 1] : void 0;
package/dist/cli.js CHANGED
@@ -1,15 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  generate
4
- } from "./chunk-CDJTXVSE.js";
5
- import "./chunk-MJEASOAN.js";
4
+ } from "./chunk-MQAIY4QW.js";
5
+ import "./chunk-Y3WJXRDA.js";
6
6
 
7
7
  // src/cli.ts
8
8
  import { readFile } from "fs/promises";
9
9
  import { resolve } from "path";
10
10
  import { pathToFileURL } from "url";
11
11
  import { watch } from "chokidar";
12
- var args = process.argv.slice(2);
12
+ var args = process.argv.slice(2).flatMap((arg) => {
13
+ const match = /^(--[\w-]+)=(.*)$/.exec(arg);
14
+ return match ? [match[1], match[2]] : [arg];
15
+ });
13
16
  var getArg = (flag) => {
14
17
  const i = args.indexOf(flag);
15
18
  return i !== -1 ? args[i + 1] : void 0;
package/dist/esbuild.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-QJWQDFW4.js";
4
- import "./chunk-MJEASOAN.js";
3
+ } from "./chunk-7QP7R3IQ.js";
4
+ import "./chunk-Y3WJXRDA.js";
5
5
 
6
6
  // src/esbuild.ts
7
7
  var esbuild_default = unplugin_default.esbuild;
package/dist/index.cjs CHANGED
@@ -98,6 +98,19 @@ function formatKey(key, naming = "camelCase") {
98
98
  if (naming === "kebab") return `'${key}'`;
99
99
  return key;
100
100
  }
101
+ function findKeyCollisions(varNames, prefix, naming) {
102
+ const byKey = /* @__PURE__ */ new Map();
103
+ for (const name of varNames) {
104
+ const key = applyPrefix(toKey(name, naming), prefix, naming);
105
+ const existing = byKey.get(key);
106
+ if (existing) existing.push(name);
107
+ else byKey.set(key, [name]);
108
+ }
109
+ for (const [key, names] of byKey) {
110
+ if (names.length < 2) byKey.delete(key);
111
+ }
112
+ return byKey;
113
+ }
101
114
  function generateCode(varNames, prefix, naming) {
102
115
  const entries = varNames.map((name) => {
103
116
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
@@ -146,6 +159,9 @@ async function generate(options) {
146
159
  if (names.length === 0) {
147
160
  console.warn("css-typed-vars: no CSS custom properties found.");
148
161
  }
162
+ for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
163
+ console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
164
+ }
149
165
  const outPath = (0, import_node_path.resolve)(options.output);
150
166
  await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
151
167
  if (options.output.endsWith(".js")) {
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  generate
3
- } from "./chunk-CDJTXVSE.js";
3
+ } from "./chunk-MQAIY4QW.js";
4
4
  import {
5
5
  generateCode,
6
6
  generateDeclaration,
7
7
  generateJs,
8
8
  parseVarNames,
9
9
  scanVarNames
10
- } from "./chunk-MJEASOAN.js";
10
+ } from "./chunk-Y3WJXRDA.js";
11
11
  export {
12
12
  generate,
13
13
  generateCode,
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-QJWQDFW4.js";
4
- import "./chunk-MJEASOAN.js";
3
+ } from "./chunk-7QP7R3IQ.js";
4
+ import "./chunk-Y3WJXRDA.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  var rollup_default = unplugin_default.rollup;
package/dist/unplugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-QJWQDFW4.js";
4
- import "./chunk-MJEASOAN.js";
3
+ } from "./chunk-7QP7R3IQ.js";
4
+ import "./chunk-Y3WJXRDA.js";
5
5
  export {
6
6
  unplugin_default as default
7
7
  };
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-QJWQDFW4.js";
4
- import "./chunk-MJEASOAN.js";
3
+ } from "./chunk-7QP7R3IQ.js";
4
+ import "./chunk-Y3WJXRDA.js";
5
5
 
6
6
  // src/vite.ts
7
7
  var vite_default = unplugin_default.vite;
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-QJWQDFW4.js";
4
- import "./chunk-MJEASOAN.js";
3
+ } from "./chunk-7QP7R3IQ.js";
4
+ import "./chunk-Y3WJXRDA.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.8",
3
+ "version": "0.4.9",
4
4
  "description": "Generate TypeScript typed constants from CSS custom properties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",