css-typed-vars 0.4.15 → 0.4.17
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/{chunk-AUFD5VOT.js → chunk-DOOYTSTY.js} +12 -11
- package/dist/{chunk-2QDRH4OL.js → chunk-EHRNYU34.js} +4 -6
- package/dist/{chunk-W4JDUG2N.js → chunk-WYLYZXQJ.js} +41 -16
- package/dist/cli.cjs +41 -18
- package/dist/cli.js +2 -2
- package/dist/esbuild.cjs +49 -23
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +41 -18
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +49 -23
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +49 -23
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +49 -23
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +49 -23
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__dirname,
|
|
3
|
-
findKeyCollisions,
|
|
4
3
|
generateDeclaration,
|
|
5
4
|
generateJs,
|
|
6
|
-
scanVarNames
|
|
7
|
-
|
|
5
|
+
scanVarNames,
|
|
6
|
+
warnOnCollisions
|
|
7
|
+
} from "./chunk-WYLYZXQJ.js";
|
|
8
8
|
|
|
9
9
|
// src/unplugin.ts
|
|
10
10
|
import { createUnplugin } from "unplugin";
|
|
@@ -12,11 +12,6 @@ import { writeFile } from "fs/promises";
|
|
|
12
12
|
import { join, resolve } from "path";
|
|
13
13
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
14
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
|
-
}
|
|
20
15
|
function getDtsPath(options) {
|
|
21
16
|
if (options.dts === false) return null;
|
|
22
17
|
return options.dts ? resolve(process.cwd(), options.dts) : join(__dirname, "generated.d.ts");
|
|
@@ -30,16 +25,22 @@ var unplugin_default = createUnplugin((options) => {
|
|
|
30
25
|
configureServer(server) {
|
|
31
26
|
let generation = 0;
|
|
32
27
|
let debounceTimer = null;
|
|
28
|
+
let writeQueue = Promise.resolve();
|
|
33
29
|
const rescan = async () => {
|
|
34
30
|
const myGeneration = ++generation;
|
|
35
31
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
36
32
|
cachedNames = namesPromise;
|
|
37
33
|
const names = await namesPromise;
|
|
38
34
|
if (myGeneration !== generation) return;
|
|
39
|
-
warnOnCollisions(names, options);
|
|
35
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
40
36
|
const dtsPath = getDtsPath(options);
|
|
41
37
|
if (dtsPath) {
|
|
42
|
-
|
|
38
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
39
|
+
writeQueue = writeQueue.then(async () => {
|
|
40
|
+
if (myGeneration !== generation) return;
|
|
41
|
+
await writeFile(dtsPath, content, "utf8");
|
|
42
|
+
}).catch(console.error);
|
|
43
|
+
await writeQueue;
|
|
43
44
|
}
|
|
44
45
|
if (myGeneration !== generation) return;
|
|
45
46
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -64,7 +65,7 @@ var unplugin_default = createUnplugin((options) => {
|
|
|
64
65
|
async buildStart() {
|
|
65
66
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
66
67
|
const names = await cachedNames;
|
|
67
|
-
warnOnCollisions(names, options);
|
|
68
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
68
69
|
const dtsPath = getDtsPath(options);
|
|
69
70
|
if (!dtsPath) return;
|
|
70
71
|
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
findKeyCollisions,
|
|
3
2
|
generateCode,
|
|
4
3
|
generateDeclaration,
|
|
5
4
|
generateJs,
|
|
6
|
-
scanVarNames
|
|
7
|
-
|
|
5
|
+
scanVarNames,
|
|
6
|
+
warnOnCollisions
|
|
7
|
+
} from "./chunk-WYLYZXQJ.js";
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
10
|
import { writeFile, mkdir } from "fs/promises";
|
|
@@ -14,9 +14,7 @@ async function generate(options) {
|
|
|
14
14
|
if (names.length === 0) {
|
|
15
15
|
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
16
16
|
}
|
|
17
|
-
|
|
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
|
-
}
|
|
17
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
20
18
|
const outPath = resolve(options.output);
|
|
21
19
|
await mkdir(dirname(outPath), { recursive: true });
|
|
22
20
|
const jsExtMatch = /\.(m|c)?js$/i.exec(options.output);
|
|
@@ -6,6 +6,12 @@ var getDirname = () => path.dirname(getFilename());
|
|
|
6
6
|
var __dirname = /* @__PURE__ */ getDirname();
|
|
7
7
|
|
|
8
8
|
// src/parser.ts
|
|
9
|
+
function stepQuote(text, i, quote) {
|
|
10
|
+
const char = text[i];
|
|
11
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
12
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
13
|
+
return { consumed: 1, closed: false };
|
|
14
|
+
}
|
|
9
15
|
function stripComments(text) {
|
|
10
16
|
let result = "";
|
|
11
17
|
let quote = null;
|
|
@@ -13,12 +19,10 @@ function stripComments(text) {
|
|
|
13
19
|
for (let i = 0; i < text.length; i++) {
|
|
14
20
|
const char = text[i];
|
|
15
21
|
if (quote) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
quote = null;
|
|
21
|
-
}
|
|
22
|
+
const step = stepQuote(text, i, quote);
|
|
23
|
+
result += text.slice(i, i + step.consumed);
|
|
24
|
+
if (step.closed) quote = null;
|
|
25
|
+
i += step.consumed - 1;
|
|
22
26
|
continue;
|
|
23
27
|
}
|
|
24
28
|
if (char === '"' || char === "'") {
|
|
@@ -62,8 +66,9 @@ function extractBlock(text, start) {
|
|
|
62
66
|
for (; i < text.length && depth > 0; i++) {
|
|
63
67
|
const char = text[i];
|
|
64
68
|
if (quote) {
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
const step = stepQuote(text, i, quote);
|
|
70
|
+
if (step.closed) quote = null;
|
|
71
|
+
i += step.consumed - 1;
|
|
67
72
|
} else if (char === '"' || char === "'") {
|
|
68
73
|
quote = char;
|
|
69
74
|
} else if (char === "{") {
|
|
@@ -80,15 +85,14 @@ function maskQuotedContent(text) {
|
|
|
80
85
|
for (let i = 0; i < text.length; i++) {
|
|
81
86
|
const char = text[i];
|
|
82
87
|
if (quote) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
i++;
|
|
86
|
-
} else if (char === quote) {
|
|
87
|
-
quote = null;
|
|
88
|
+
const step = stepQuote(text, i, quote);
|
|
89
|
+
if (step.closed) {
|
|
88
90
|
result += char;
|
|
91
|
+
quote = null;
|
|
89
92
|
} else {
|
|
90
|
-
result += " ";
|
|
93
|
+
result += " ".repeat(step.consumed);
|
|
91
94
|
}
|
|
95
|
+
i += step.consumed - 1;
|
|
92
96
|
continue;
|
|
93
97
|
}
|
|
94
98
|
if (char === '"' || char === "'") {
|
|
@@ -158,11 +162,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
158
162
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
159
163
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
160
164
|
}
|
|
165
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
166
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
167
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
168
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
169
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
170
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
171
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
172
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
173
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
174
|
+
function escapeSingleQuoted(value) {
|
|
175
|
+
let result = "";
|
|
176
|
+
for (const char of value) {
|
|
177
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
178
|
+
}
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
161
181
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
162
182
|
if (!prefix) return key;
|
|
163
183
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
164
184
|
if (naming === "kebab") {
|
|
165
|
-
normalizedPrefix = normalizedPrefix
|
|
185
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
166
186
|
return `${normalizedPrefix}-${key}`;
|
|
167
187
|
}
|
|
168
188
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -187,6 +207,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
187
207
|
}
|
|
188
208
|
return byKey;
|
|
189
209
|
}
|
|
210
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
211
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
212
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
190
215
|
function buildEntries(varNames, prefix, naming) {
|
|
191
216
|
const byKey = /* @__PURE__ */ new Map();
|
|
192
217
|
for (const name of varNames) {
|
|
@@ -233,7 +258,7 @@ export {
|
|
|
233
258
|
parseVarNames,
|
|
234
259
|
scanVarNames,
|
|
235
260
|
VALID_NAMINGS,
|
|
236
|
-
|
|
261
|
+
warnOnCollisions,
|
|
237
262
|
generateCode,
|
|
238
263
|
generateJs,
|
|
239
264
|
generateDeclaration
|
package/dist/cli.cjs
CHANGED
|
@@ -42,6 +42,12 @@ var import_promises = require("fs/promises");
|
|
|
42
42
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
43
43
|
|
|
44
44
|
// src/parser.ts
|
|
45
|
+
function stepQuote(text, i, quote) {
|
|
46
|
+
const char = text[i];
|
|
47
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
48
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
49
|
+
return { consumed: 1, closed: false };
|
|
50
|
+
}
|
|
45
51
|
function stripComments(text) {
|
|
46
52
|
let result = "";
|
|
47
53
|
let quote = null;
|
|
@@ -49,12 +55,10 @@ function stripComments(text) {
|
|
|
49
55
|
for (let i = 0; i < text.length; i++) {
|
|
50
56
|
const char = text[i];
|
|
51
57
|
if (quote) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
quote = null;
|
|
57
|
-
}
|
|
58
|
+
const step = stepQuote(text, i, quote);
|
|
59
|
+
result += text.slice(i, i + step.consumed);
|
|
60
|
+
if (step.closed) quote = null;
|
|
61
|
+
i += step.consumed - 1;
|
|
58
62
|
continue;
|
|
59
63
|
}
|
|
60
64
|
if (char === '"' || char === "'") {
|
|
@@ -98,8 +102,9 @@ function extractBlock(text, start) {
|
|
|
98
102
|
for (; i < text.length && depth > 0; i++) {
|
|
99
103
|
const char = text[i];
|
|
100
104
|
if (quote) {
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
const step = stepQuote(text, i, quote);
|
|
106
|
+
if (step.closed) quote = null;
|
|
107
|
+
i += step.consumed - 1;
|
|
103
108
|
} else if (char === '"' || char === "'") {
|
|
104
109
|
quote = char;
|
|
105
110
|
} else if (char === "{") {
|
|
@@ -116,15 +121,14 @@ function maskQuotedContent(text) {
|
|
|
116
121
|
for (let i = 0; i < text.length; i++) {
|
|
117
122
|
const char = text[i];
|
|
118
123
|
if (quote) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
i++;
|
|
122
|
-
} else if (char === quote) {
|
|
123
|
-
quote = null;
|
|
124
|
+
const step = stepQuote(text, i, quote);
|
|
125
|
+
if (step.closed) {
|
|
124
126
|
result += char;
|
|
127
|
+
quote = null;
|
|
125
128
|
} else {
|
|
126
|
-
result += " ";
|
|
129
|
+
result += " ".repeat(step.consumed);
|
|
127
130
|
}
|
|
131
|
+
i += step.consumed - 1;
|
|
128
132
|
continue;
|
|
129
133
|
}
|
|
130
134
|
if (char === '"' || char === "'") {
|
|
@@ -192,11 +196,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
192
196
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
193
197
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
194
198
|
}
|
|
199
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
200
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
201
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
202
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
203
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
208
|
+
function escapeSingleQuoted(value) {
|
|
209
|
+
let result = "";
|
|
210
|
+
for (const char of value) {
|
|
211
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
195
215
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
196
216
|
if (!prefix) return key;
|
|
197
217
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
198
218
|
if (naming === "kebab") {
|
|
199
|
-
normalizedPrefix = normalizedPrefix
|
|
219
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
200
220
|
return `${normalizedPrefix}-${key}`;
|
|
201
221
|
}
|
|
202
222
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -221,6 +241,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
221
241
|
}
|
|
222
242
|
return byKey;
|
|
223
243
|
}
|
|
244
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
245
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
246
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
224
249
|
function buildEntries(varNames, prefix, naming) {
|
|
225
250
|
const byKey = /* @__PURE__ */ new Map();
|
|
226
251
|
for (const name of varNames) {
|
|
@@ -268,9 +293,7 @@ async function generate(options) {
|
|
|
268
293
|
if (names.length === 0) {
|
|
269
294
|
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
270
295
|
}
|
|
271
|
-
|
|
272
|
-
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
273
|
-
}
|
|
296
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
274
297
|
const outPath = (0, import_node_path.resolve)(options.output);
|
|
275
298
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
276
299
|
const jsExtMatch = /\.(m|c)?js$/i.exec(options.output);
|
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
generate
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-EHRNYU34.js";
|
|
5
5
|
import {
|
|
6
6
|
VALID_NAMINGS
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-WYLYZXQJ.js";
|
|
8
8
|
|
|
9
9
|
// src/cli.ts
|
|
10
10
|
import { readFile } from "fs/promises";
|
package/dist/esbuild.cjs
CHANGED
|
@@ -44,6 +44,12 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function stepQuote(text, i, quote) {
|
|
48
|
+
const char = text[i];
|
|
49
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
50
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
51
|
+
return { consumed: 1, closed: false };
|
|
52
|
+
}
|
|
47
53
|
function stripComments(text) {
|
|
48
54
|
let result = "";
|
|
49
55
|
let quote = null;
|
|
@@ -51,12 +57,10 @@ function stripComments(text) {
|
|
|
51
57
|
for (let i = 0; i < text.length; i++) {
|
|
52
58
|
const char = text[i];
|
|
53
59
|
if (quote) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
quote = null;
|
|
59
|
-
}
|
|
60
|
+
const step = stepQuote(text, i, quote);
|
|
61
|
+
result += text.slice(i, i + step.consumed);
|
|
62
|
+
if (step.closed) quote = null;
|
|
63
|
+
i += step.consumed - 1;
|
|
60
64
|
continue;
|
|
61
65
|
}
|
|
62
66
|
if (char === '"' || char === "'") {
|
|
@@ -100,8 +104,9 @@ function extractBlock(text, start) {
|
|
|
100
104
|
for (; i < text.length && depth > 0; i++) {
|
|
101
105
|
const char = text[i];
|
|
102
106
|
if (quote) {
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
const step = stepQuote(text, i, quote);
|
|
108
|
+
if (step.closed) quote = null;
|
|
109
|
+
i += step.consumed - 1;
|
|
105
110
|
} else if (char === '"' || char === "'") {
|
|
106
111
|
quote = char;
|
|
107
112
|
} else if (char === "{") {
|
|
@@ -118,15 +123,14 @@ function maskQuotedContent(text) {
|
|
|
118
123
|
for (let i = 0; i < text.length; i++) {
|
|
119
124
|
const char = text[i];
|
|
120
125
|
if (quote) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
i++;
|
|
124
|
-
} else if (char === quote) {
|
|
125
|
-
quote = null;
|
|
126
|
+
const step = stepQuote(text, i, quote);
|
|
127
|
+
if (step.closed) {
|
|
126
128
|
result += char;
|
|
129
|
+
quote = null;
|
|
127
130
|
} else {
|
|
128
|
-
result += " ";
|
|
131
|
+
result += " ".repeat(step.consumed);
|
|
129
132
|
}
|
|
133
|
+
i += step.consumed - 1;
|
|
130
134
|
continue;
|
|
131
135
|
}
|
|
132
136
|
if (char === '"' || char === "'") {
|
|
@@ -194,11 +198,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
194
198
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
195
199
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
196
200
|
}
|
|
201
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
202
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
203
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
208
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
209
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
210
|
+
function escapeSingleQuoted(value) {
|
|
211
|
+
let result = "";
|
|
212
|
+
for (const char of value) {
|
|
213
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
197
217
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
198
218
|
if (!prefix) return key;
|
|
199
219
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
200
220
|
if (naming === "kebab") {
|
|
201
|
-
normalizedPrefix = normalizedPrefix
|
|
221
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
202
222
|
return `${normalizedPrefix}-${key}`;
|
|
203
223
|
}
|
|
204
224
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -223,6 +243,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
223
243
|
}
|
|
224
244
|
return byKey;
|
|
225
245
|
}
|
|
246
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
247
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
248
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
226
251
|
function buildEntries(varNames, prefix, naming) {
|
|
227
252
|
const byKey = /* @__PURE__ */ new Map();
|
|
228
253
|
for (const name of varNames) {
|
|
@@ -255,11 +280,6 @@ function generateDeclaration(varNames, prefix, naming) {
|
|
|
255
280
|
// src/unplugin.ts
|
|
256
281
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
257
282
|
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
|
-
}
|
|
263
283
|
function getDtsPath(options) {
|
|
264
284
|
if (options.dts === false) return null;
|
|
265
285
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
@@ -273,16 +293,22 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
273
293
|
configureServer(server) {
|
|
274
294
|
let generation = 0;
|
|
275
295
|
let debounceTimer = null;
|
|
296
|
+
let writeQueue = Promise.resolve();
|
|
276
297
|
const rescan = async () => {
|
|
277
298
|
const myGeneration = ++generation;
|
|
278
299
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
279
300
|
cachedNames = namesPromise;
|
|
280
301
|
const names = await namesPromise;
|
|
281
302
|
if (myGeneration !== generation) return;
|
|
282
|
-
warnOnCollisions(names, options);
|
|
303
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
283
304
|
const dtsPath = getDtsPath(options);
|
|
284
305
|
if (dtsPath) {
|
|
285
|
-
|
|
306
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
307
|
+
writeQueue = writeQueue.then(async () => {
|
|
308
|
+
if (myGeneration !== generation) return;
|
|
309
|
+
await (0, import_promises2.writeFile)(dtsPath, content, "utf8");
|
|
310
|
+
}).catch(console.error);
|
|
311
|
+
await writeQueue;
|
|
286
312
|
}
|
|
287
313
|
if (myGeneration !== generation) return;
|
|
288
314
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -307,7 +333,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
307
333
|
async buildStart() {
|
|
308
334
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
309
335
|
const names = await cachedNames;
|
|
310
|
-
warnOnCollisions(names, options);
|
|
336
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
311
337
|
const dtsPath = getDtsPath(options);
|
|
312
338
|
if (!dtsPath) return;
|
|
313
339
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,12 @@ var import_promises = require("fs/promises");
|
|
|
46
46
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
47
47
|
|
|
48
48
|
// src/parser.ts
|
|
49
|
+
function stepQuote(text, i, quote) {
|
|
50
|
+
const char = text[i];
|
|
51
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
52
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
53
|
+
return { consumed: 1, closed: false };
|
|
54
|
+
}
|
|
49
55
|
function stripComments(text) {
|
|
50
56
|
let result = "";
|
|
51
57
|
let quote = null;
|
|
@@ -53,12 +59,10 @@ function stripComments(text) {
|
|
|
53
59
|
for (let i = 0; i < text.length; i++) {
|
|
54
60
|
const char = text[i];
|
|
55
61
|
if (quote) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
quote = null;
|
|
61
|
-
}
|
|
62
|
+
const step = stepQuote(text, i, quote);
|
|
63
|
+
result += text.slice(i, i + step.consumed);
|
|
64
|
+
if (step.closed) quote = null;
|
|
65
|
+
i += step.consumed - 1;
|
|
62
66
|
continue;
|
|
63
67
|
}
|
|
64
68
|
if (char === '"' || char === "'") {
|
|
@@ -102,8 +106,9 @@ function extractBlock(text, start) {
|
|
|
102
106
|
for (; i < text.length && depth > 0; i++) {
|
|
103
107
|
const char = text[i];
|
|
104
108
|
if (quote) {
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
const step = stepQuote(text, i, quote);
|
|
110
|
+
if (step.closed) quote = null;
|
|
111
|
+
i += step.consumed - 1;
|
|
107
112
|
} else if (char === '"' || char === "'") {
|
|
108
113
|
quote = char;
|
|
109
114
|
} else if (char === "{") {
|
|
@@ -120,15 +125,14 @@ function maskQuotedContent(text) {
|
|
|
120
125
|
for (let i = 0; i < text.length; i++) {
|
|
121
126
|
const char = text[i];
|
|
122
127
|
if (quote) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
i++;
|
|
126
|
-
} else if (char === quote) {
|
|
127
|
-
quote = null;
|
|
128
|
+
const step = stepQuote(text, i, quote);
|
|
129
|
+
if (step.closed) {
|
|
128
130
|
result += char;
|
|
131
|
+
quote = null;
|
|
129
132
|
} else {
|
|
130
|
-
result += " ";
|
|
133
|
+
result += " ".repeat(step.consumed);
|
|
131
134
|
}
|
|
135
|
+
i += step.consumed - 1;
|
|
132
136
|
continue;
|
|
133
137
|
}
|
|
134
138
|
if (char === '"' || char === "'") {
|
|
@@ -196,11 +200,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
196
200
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
197
201
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
198
202
|
}
|
|
203
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
204
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
205
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
206
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
208
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
209
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
210
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
211
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
212
|
+
function escapeSingleQuoted(value) {
|
|
213
|
+
let result = "";
|
|
214
|
+
for (const char of value) {
|
|
215
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
199
219
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
200
220
|
if (!prefix) return key;
|
|
201
221
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
202
222
|
if (naming === "kebab") {
|
|
203
|
-
normalizedPrefix = normalizedPrefix
|
|
223
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
204
224
|
return `${normalizedPrefix}-${key}`;
|
|
205
225
|
}
|
|
206
226
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -225,6 +245,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
225
245
|
}
|
|
226
246
|
return byKey;
|
|
227
247
|
}
|
|
248
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
249
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
250
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
228
253
|
function buildEntries(varNames, prefix, naming) {
|
|
229
254
|
const byKey = /* @__PURE__ */ new Map();
|
|
230
255
|
for (const name of varNames) {
|
|
@@ -272,9 +297,7 @@ async function generate(options) {
|
|
|
272
297
|
if (names.length === 0) {
|
|
273
298
|
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
274
299
|
}
|
|
275
|
-
|
|
276
|
-
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
277
|
-
}
|
|
300
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
278
301
|
const outPath = (0, import_node_path.resolve)(options.output);
|
|
279
302
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
280
303
|
const jsExtMatch = /\.(m|c)?js$/i.exec(options.output);
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EHRNYU34.js";
|
|
4
4
|
import {
|
|
5
5
|
generateCode,
|
|
6
6
|
generateDeclaration,
|
|
7
7
|
generateJs,
|
|
8
8
|
parseVarNames,
|
|
9
9
|
scanVarNames
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-WYLYZXQJ.js";
|
|
11
11
|
export {
|
|
12
12
|
generate,
|
|
13
13
|
generateCode,
|
package/dist/rollup.cjs
CHANGED
|
@@ -44,6 +44,12 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function stepQuote(text, i, quote) {
|
|
48
|
+
const char = text[i];
|
|
49
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
50
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
51
|
+
return { consumed: 1, closed: false };
|
|
52
|
+
}
|
|
47
53
|
function stripComments(text) {
|
|
48
54
|
let result = "";
|
|
49
55
|
let quote = null;
|
|
@@ -51,12 +57,10 @@ function stripComments(text) {
|
|
|
51
57
|
for (let i = 0; i < text.length; i++) {
|
|
52
58
|
const char = text[i];
|
|
53
59
|
if (quote) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
quote = null;
|
|
59
|
-
}
|
|
60
|
+
const step = stepQuote(text, i, quote);
|
|
61
|
+
result += text.slice(i, i + step.consumed);
|
|
62
|
+
if (step.closed) quote = null;
|
|
63
|
+
i += step.consumed - 1;
|
|
60
64
|
continue;
|
|
61
65
|
}
|
|
62
66
|
if (char === '"' || char === "'") {
|
|
@@ -100,8 +104,9 @@ function extractBlock(text, start) {
|
|
|
100
104
|
for (; i < text.length && depth > 0; i++) {
|
|
101
105
|
const char = text[i];
|
|
102
106
|
if (quote) {
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
const step = stepQuote(text, i, quote);
|
|
108
|
+
if (step.closed) quote = null;
|
|
109
|
+
i += step.consumed - 1;
|
|
105
110
|
} else if (char === '"' || char === "'") {
|
|
106
111
|
quote = char;
|
|
107
112
|
} else if (char === "{") {
|
|
@@ -118,15 +123,14 @@ function maskQuotedContent(text) {
|
|
|
118
123
|
for (let i = 0; i < text.length; i++) {
|
|
119
124
|
const char = text[i];
|
|
120
125
|
if (quote) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
i++;
|
|
124
|
-
} else if (char === quote) {
|
|
125
|
-
quote = null;
|
|
126
|
+
const step = stepQuote(text, i, quote);
|
|
127
|
+
if (step.closed) {
|
|
126
128
|
result += char;
|
|
129
|
+
quote = null;
|
|
127
130
|
} else {
|
|
128
|
-
result += " ";
|
|
131
|
+
result += " ".repeat(step.consumed);
|
|
129
132
|
}
|
|
133
|
+
i += step.consumed - 1;
|
|
130
134
|
continue;
|
|
131
135
|
}
|
|
132
136
|
if (char === '"' || char === "'") {
|
|
@@ -194,11 +198,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
194
198
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
195
199
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
196
200
|
}
|
|
201
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
202
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
203
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
208
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
209
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
210
|
+
function escapeSingleQuoted(value) {
|
|
211
|
+
let result = "";
|
|
212
|
+
for (const char of value) {
|
|
213
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
197
217
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
198
218
|
if (!prefix) return key;
|
|
199
219
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
200
220
|
if (naming === "kebab") {
|
|
201
|
-
normalizedPrefix = normalizedPrefix
|
|
221
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
202
222
|
return `${normalizedPrefix}-${key}`;
|
|
203
223
|
}
|
|
204
224
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -223,6 +243,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
223
243
|
}
|
|
224
244
|
return byKey;
|
|
225
245
|
}
|
|
246
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
247
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
248
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
226
251
|
function buildEntries(varNames, prefix, naming) {
|
|
227
252
|
const byKey = /* @__PURE__ */ new Map();
|
|
228
253
|
for (const name of varNames) {
|
|
@@ -255,11 +280,6 @@ function generateDeclaration(varNames, prefix, naming) {
|
|
|
255
280
|
// src/unplugin.ts
|
|
256
281
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
257
282
|
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
|
-
}
|
|
263
283
|
function getDtsPath(options) {
|
|
264
284
|
if (options.dts === false) return null;
|
|
265
285
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
@@ -273,16 +293,22 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
273
293
|
configureServer(server) {
|
|
274
294
|
let generation = 0;
|
|
275
295
|
let debounceTimer = null;
|
|
296
|
+
let writeQueue = Promise.resolve();
|
|
276
297
|
const rescan = async () => {
|
|
277
298
|
const myGeneration = ++generation;
|
|
278
299
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
279
300
|
cachedNames = namesPromise;
|
|
280
301
|
const names = await namesPromise;
|
|
281
302
|
if (myGeneration !== generation) return;
|
|
282
|
-
warnOnCollisions(names, options);
|
|
303
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
283
304
|
const dtsPath = getDtsPath(options);
|
|
284
305
|
if (dtsPath) {
|
|
285
|
-
|
|
306
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
307
|
+
writeQueue = writeQueue.then(async () => {
|
|
308
|
+
if (myGeneration !== generation) return;
|
|
309
|
+
await (0, import_promises2.writeFile)(dtsPath, content, "utf8");
|
|
310
|
+
}).catch(console.error);
|
|
311
|
+
await writeQueue;
|
|
286
312
|
}
|
|
287
313
|
if (myGeneration !== generation) return;
|
|
288
314
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -307,7 +333,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
307
333
|
async buildStart() {
|
|
308
334
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
309
335
|
const names = await cachedNames;
|
|
310
|
-
warnOnCollisions(names, options);
|
|
336
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
311
337
|
const dtsPath = getDtsPath(options);
|
|
312
338
|
if (!dtsPath) return;
|
|
313
339
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -42,6 +42,12 @@ var import_promises = require("fs/promises");
|
|
|
42
42
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
43
43
|
|
|
44
44
|
// src/parser.ts
|
|
45
|
+
function stepQuote(text, i, quote) {
|
|
46
|
+
const char = text[i];
|
|
47
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
48
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
49
|
+
return { consumed: 1, closed: false };
|
|
50
|
+
}
|
|
45
51
|
function stripComments(text) {
|
|
46
52
|
let result = "";
|
|
47
53
|
let quote = null;
|
|
@@ -49,12 +55,10 @@ function stripComments(text) {
|
|
|
49
55
|
for (let i = 0; i < text.length; i++) {
|
|
50
56
|
const char = text[i];
|
|
51
57
|
if (quote) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
quote = null;
|
|
57
|
-
}
|
|
58
|
+
const step = stepQuote(text, i, quote);
|
|
59
|
+
result += text.slice(i, i + step.consumed);
|
|
60
|
+
if (step.closed) quote = null;
|
|
61
|
+
i += step.consumed - 1;
|
|
58
62
|
continue;
|
|
59
63
|
}
|
|
60
64
|
if (char === '"' || char === "'") {
|
|
@@ -98,8 +102,9 @@ function extractBlock(text, start) {
|
|
|
98
102
|
for (; i < text.length && depth > 0; i++) {
|
|
99
103
|
const char = text[i];
|
|
100
104
|
if (quote) {
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
const step = stepQuote(text, i, quote);
|
|
106
|
+
if (step.closed) quote = null;
|
|
107
|
+
i += step.consumed - 1;
|
|
103
108
|
} else if (char === '"' || char === "'") {
|
|
104
109
|
quote = char;
|
|
105
110
|
} else if (char === "{") {
|
|
@@ -116,15 +121,14 @@ function maskQuotedContent(text) {
|
|
|
116
121
|
for (let i = 0; i < text.length; i++) {
|
|
117
122
|
const char = text[i];
|
|
118
123
|
if (quote) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
i++;
|
|
122
|
-
} else if (char === quote) {
|
|
123
|
-
quote = null;
|
|
124
|
+
const step = stepQuote(text, i, quote);
|
|
125
|
+
if (step.closed) {
|
|
124
126
|
result += char;
|
|
127
|
+
quote = null;
|
|
125
128
|
} else {
|
|
126
|
-
result += " ";
|
|
129
|
+
result += " ".repeat(step.consumed);
|
|
127
130
|
}
|
|
131
|
+
i += step.consumed - 1;
|
|
128
132
|
continue;
|
|
129
133
|
}
|
|
130
134
|
if (char === '"' || char === "'") {
|
|
@@ -192,11 +196,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
192
196
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
193
197
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
194
198
|
}
|
|
199
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
200
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
201
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
202
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
203
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
208
|
+
function escapeSingleQuoted(value) {
|
|
209
|
+
let result = "";
|
|
210
|
+
for (const char of value) {
|
|
211
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
195
215
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
196
216
|
if (!prefix) return key;
|
|
197
217
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
198
218
|
if (naming === "kebab") {
|
|
199
|
-
normalizedPrefix = normalizedPrefix
|
|
219
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
200
220
|
return `${normalizedPrefix}-${key}`;
|
|
201
221
|
}
|
|
202
222
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -221,6 +241,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
221
241
|
}
|
|
222
242
|
return byKey;
|
|
223
243
|
}
|
|
244
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
245
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
246
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
224
249
|
function buildEntries(varNames, prefix, naming) {
|
|
225
250
|
const byKey = /* @__PURE__ */ new Map();
|
|
226
251
|
for (const name of varNames) {
|
|
@@ -253,11 +278,6 @@ function generateDeclaration(varNames, prefix, naming) {
|
|
|
253
278
|
// src/unplugin.ts
|
|
254
279
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
255
280
|
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
|
-
}
|
|
261
281
|
function getDtsPath(options) {
|
|
262
282
|
if (options.dts === false) return null;
|
|
263
283
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
@@ -271,16 +291,22 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
271
291
|
configureServer(server) {
|
|
272
292
|
let generation = 0;
|
|
273
293
|
let debounceTimer = null;
|
|
294
|
+
let writeQueue = Promise.resolve();
|
|
274
295
|
const rescan = async () => {
|
|
275
296
|
const myGeneration = ++generation;
|
|
276
297
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
277
298
|
cachedNames = namesPromise;
|
|
278
299
|
const names = await namesPromise;
|
|
279
300
|
if (myGeneration !== generation) return;
|
|
280
|
-
warnOnCollisions(names, options);
|
|
301
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
281
302
|
const dtsPath = getDtsPath(options);
|
|
282
303
|
if (dtsPath) {
|
|
283
|
-
|
|
304
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
305
|
+
writeQueue = writeQueue.then(async () => {
|
|
306
|
+
if (myGeneration !== generation) return;
|
|
307
|
+
await (0, import_promises2.writeFile)(dtsPath, content, "utf8");
|
|
308
|
+
}).catch(console.error);
|
|
309
|
+
await writeQueue;
|
|
284
310
|
}
|
|
285
311
|
if (myGeneration !== generation) return;
|
|
286
312
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -305,7 +331,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
305
331
|
async buildStart() {
|
|
306
332
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
307
333
|
const names = await cachedNames;
|
|
308
|
-
warnOnCollisions(names, options);
|
|
334
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
309
335
|
const dtsPath = getDtsPath(options);
|
|
310
336
|
if (!dtsPath) return;
|
|
311
337
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -44,6 +44,12 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function stepQuote(text, i, quote) {
|
|
48
|
+
const char = text[i];
|
|
49
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
50
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
51
|
+
return { consumed: 1, closed: false };
|
|
52
|
+
}
|
|
47
53
|
function stripComments(text) {
|
|
48
54
|
let result = "";
|
|
49
55
|
let quote = null;
|
|
@@ -51,12 +57,10 @@ function stripComments(text) {
|
|
|
51
57
|
for (let i = 0; i < text.length; i++) {
|
|
52
58
|
const char = text[i];
|
|
53
59
|
if (quote) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
quote = null;
|
|
59
|
-
}
|
|
60
|
+
const step = stepQuote(text, i, quote);
|
|
61
|
+
result += text.slice(i, i + step.consumed);
|
|
62
|
+
if (step.closed) quote = null;
|
|
63
|
+
i += step.consumed - 1;
|
|
60
64
|
continue;
|
|
61
65
|
}
|
|
62
66
|
if (char === '"' || char === "'") {
|
|
@@ -100,8 +104,9 @@ function extractBlock(text, start) {
|
|
|
100
104
|
for (; i < text.length && depth > 0; i++) {
|
|
101
105
|
const char = text[i];
|
|
102
106
|
if (quote) {
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
const step = stepQuote(text, i, quote);
|
|
108
|
+
if (step.closed) quote = null;
|
|
109
|
+
i += step.consumed - 1;
|
|
105
110
|
} else if (char === '"' || char === "'") {
|
|
106
111
|
quote = char;
|
|
107
112
|
} else if (char === "{") {
|
|
@@ -118,15 +123,14 @@ function maskQuotedContent(text) {
|
|
|
118
123
|
for (let i = 0; i < text.length; i++) {
|
|
119
124
|
const char = text[i];
|
|
120
125
|
if (quote) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
i++;
|
|
124
|
-
} else if (char === quote) {
|
|
125
|
-
quote = null;
|
|
126
|
+
const step = stepQuote(text, i, quote);
|
|
127
|
+
if (step.closed) {
|
|
126
128
|
result += char;
|
|
129
|
+
quote = null;
|
|
127
130
|
} else {
|
|
128
|
-
result += " ";
|
|
131
|
+
result += " ".repeat(step.consumed);
|
|
129
132
|
}
|
|
133
|
+
i += step.consumed - 1;
|
|
130
134
|
continue;
|
|
131
135
|
}
|
|
132
136
|
if (char === '"' || char === "'") {
|
|
@@ -194,11 +198,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
194
198
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
195
199
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
196
200
|
}
|
|
201
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
202
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
203
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
208
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
209
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
210
|
+
function escapeSingleQuoted(value) {
|
|
211
|
+
let result = "";
|
|
212
|
+
for (const char of value) {
|
|
213
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
197
217
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
198
218
|
if (!prefix) return key;
|
|
199
219
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
200
220
|
if (naming === "kebab") {
|
|
201
|
-
normalizedPrefix = normalizedPrefix
|
|
221
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
202
222
|
return `${normalizedPrefix}-${key}`;
|
|
203
223
|
}
|
|
204
224
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -223,6 +243,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
223
243
|
}
|
|
224
244
|
return byKey;
|
|
225
245
|
}
|
|
246
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
247
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
248
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
226
251
|
function buildEntries(varNames, prefix, naming) {
|
|
227
252
|
const byKey = /* @__PURE__ */ new Map();
|
|
228
253
|
for (const name of varNames) {
|
|
@@ -255,11 +280,6 @@ function generateDeclaration(varNames, prefix, naming) {
|
|
|
255
280
|
// src/unplugin.ts
|
|
256
281
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
257
282
|
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
|
-
}
|
|
263
283
|
function getDtsPath(options) {
|
|
264
284
|
if (options.dts === false) return null;
|
|
265
285
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
@@ -273,16 +293,22 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
273
293
|
configureServer(server) {
|
|
274
294
|
let generation = 0;
|
|
275
295
|
let debounceTimer = null;
|
|
296
|
+
let writeQueue = Promise.resolve();
|
|
276
297
|
const rescan = async () => {
|
|
277
298
|
const myGeneration = ++generation;
|
|
278
299
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
279
300
|
cachedNames = namesPromise;
|
|
280
301
|
const names = await namesPromise;
|
|
281
302
|
if (myGeneration !== generation) return;
|
|
282
|
-
warnOnCollisions(names, options);
|
|
303
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
283
304
|
const dtsPath = getDtsPath(options);
|
|
284
305
|
if (dtsPath) {
|
|
285
|
-
|
|
306
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
307
|
+
writeQueue = writeQueue.then(async () => {
|
|
308
|
+
if (myGeneration !== generation) return;
|
|
309
|
+
await (0, import_promises2.writeFile)(dtsPath, content, "utf8");
|
|
310
|
+
}).catch(console.error);
|
|
311
|
+
await writeQueue;
|
|
286
312
|
}
|
|
287
313
|
if (myGeneration !== generation) return;
|
|
288
314
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -307,7 +333,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
307
333
|
async buildStart() {
|
|
308
334
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
309
335
|
const names = await cachedNames;
|
|
310
|
-
warnOnCollisions(names, options);
|
|
336
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
311
337
|
const dtsPath = getDtsPath(options);
|
|
312
338
|
if (!dtsPath) return;
|
|
313
339
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -44,6 +44,12 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function stepQuote(text, i, quote) {
|
|
48
|
+
const char = text[i];
|
|
49
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
50
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
51
|
+
return { consumed: 1, closed: false };
|
|
52
|
+
}
|
|
47
53
|
function stripComments(text) {
|
|
48
54
|
let result = "";
|
|
49
55
|
let quote = null;
|
|
@@ -51,12 +57,10 @@ function stripComments(text) {
|
|
|
51
57
|
for (let i = 0; i < text.length; i++) {
|
|
52
58
|
const char = text[i];
|
|
53
59
|
if (quote) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
quote = null;
|
|
59
|
-
}
|
|
60
|
+
const step = stepQuote(text, i, quote);
|
|
61
|
+
result += text.slice(i, i + step.consumed);
|
|
62
|
+
if (step.closed) quote = null;
|
|
63
|
+
i += step.consumed - 1;
|
|
60
64
|
continue;
|
|
61
65
|
}
|
|
62
66
|
if (char === '"' || char === "'") {
|
|
@@ -100,8 +104,9 @@ function extractBlock(text, start) {
|
|
|
100
104
|
for (; i < text.length && depth > 0; i++) {
|
|
101
105
|
const char = text[i];
|
|
102
106
|
if (quote) {
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
const step = stepQuote(text, i, quote);
|
|
108
|
+
if (step.closed) quote = null;
|
|
109
|
+
i += step.consumed - 1;
|
|
105
110
|
} else if (char === '"' || char === "'") {
|
|
106
111
|
quote = char;
|
|
107
112
|
} else if (char === "{") {
|
|
@@ -118,15 +123,14 @@ function maskQuotedContent(text) {
|
|
|
118
123
|
for (let i = 0; i < text.length; i++) {
|
|
119
124
|
const char = text[i];
|
|
120
125
|
if (quote) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
i++;
|
|
124
|
-
} else if (char === quote) {
|
|
125
|
-
quote = null;
|
|
126
|
+
const step = stepQuote(text, i, quote);
|
|
127
|
+
if (step.closed) {
|
|
126
128
|
result += char;
|
|
129
|
+
quote = null;
|
|
127
130
|
} else {
|
|
128
|
-
result += " ";
|
|
131
|
+
result += " ".repeat(step.consumed);
|
|
129
132
|
}
|
|
133
|
+
i += step.consumed - 1;
|
|
130
134
|
continue;
|
|
131
135
|
}
|
|
132
136
|
if (char === '"' || char === "'") {
|
|
@@ -194,11 +198,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
194
198
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
195
199
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
196
200
|
}
|
|
201
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
202
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
203
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
208
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
209
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
210
|
+
function escapeSingleQuoted(value) {
|
|
211
|
+
let result = "";
|
|
212
|
+
for (const char of value) {
|
|
213
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
197
217
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
198
218
|
if (!prefix) return key;
|
|
199
219
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
200
220
|
if (naming === "kebab") {
|
|
201
|
-
normalizedPrefix = normalizedPrefix
|
|
221
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
202
222
|
return `${normalizedPrefix}-${key}`;
|
|
203
223
|
}
|
|
204
224
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -223,6 +243,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
223
243
|
}
|
|
224
244
|
return byKey;
|
|
225
245
|
}
|
|
246
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
247
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
248
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
226
251
|
function buildEntries(varNames, prefix, naming) {
|
|
227
252
|
const byKey = /* @__PURE__ */ new Map();
|
|
228
253
|
for (const name of varNames) {
|
|
@@ -255,11 +280,6 @@ function generateDeclaration(varNames, prefix, naming) {
|
|
|
255
280
|
// src/unplugin.ts
|
|
256
281
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
257
282
|
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
|
-
}
|
|
263
283
|
function getDtsPath(options) {
|
|
264
284
|
if (options.dts === false) return null;
|
|
265
285
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
@@ -273,16 +293,22 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
273
293
|
configureServer(server) {
|
|
274
294
|
let generation = 0;
|
|
275
295
|
let debounceTimer = null;
|
|
296
|
+
let writeQueue = Promise.resolve();
|
|
276
297
|
const rescan = async () => {
|
|
277
298
|
const myGeneration = ++generation;
|
|
278
299
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
279
300
|
cachedNames = namesPromise;
|
|
280
301
|
const names = await namesPromise;
|
|
281
302
|
if (myGeneration !== generation) return;
|
|
282
|
-
warnOnCollisions(names, options);
|
|
303
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
283
304
|
const dtsPath = getDtsPath(options);
|
|
284
305
|
if (dtsPath) {
|
|
285
|
-
|
|
306
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
307
|
+
writeQueue = writeQueue.then(async () => {
|
|
308
|
+
if (myGeneration !== generation) return;
|
|
309
|
+
await (0, import_promises2.writeFile)(dtsPath, content, "utf8");
|
|
310
|
+
}).catch(console.error);
|
|
311
|
+
await writeQueue;
|
|
286
312
|
}
|
|
287
313
|
if (myGeneration !== generation) return;
|
|
288
314
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -307,7 +333,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
307
333
|
async buildStart() {
|
|
308
334
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
309
335
|
const names = await cachedNames;
|
|
310
|
-
warnOnCollisions(names, options);
|
|
336
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
311
337
|
const dtsPath = getDtsPath(options);
|
|
312
338
|
if (!dtsPath) return;
|
|
313
339
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
package/dist/webpack.js
CHANGED