css-typed-vars 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -5
- package/dist/{chunk-32V3V6WT.js → chunk-66NEMXYL.js} +11 -6
- package/dist/{chunk-5HPTHW7S.js → chunk-DHBPPGOE.js} +33 -7
- package/dist/{chunk-YDXCJQPL.js → chunk-TB5PSGEF.js} +12 -7
- package/dist/cli.cjs +184 -43
- package/dist/cli.js +155 -27
- package/dist/esbuild.cjs +41 -12
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +32 -14
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +4 -2
- package/dist/rollup.cjs +41 -12
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +41 -12
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +41 -12
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +41 -12
- package/dist/webpack.js +2 -2
- package/package.json +3 -1
package/dist/rollup.cjs
CHANGED
|
@@ -36,12 +36,26 @@ module.exports = __toCommonJS(rollup_exports);
|
|
|
36
36
|
|
|
37
37
|
// src/unplugin.ts
|
|
38
38
|
var import_unplugin = require("unplugin");
|
|
39
|
-
|
|
39
|
+
|
|
40
|
+
// src/write.ts
|
|
41
|
+
var import_promises = require("fs/promises");
|
|
40
42
|
var import_node_path = require("path");
|
|
43
|
+
async function writeOutput(path, content) {
|
|
44
|
+
const current = await (0, import_promises.readFile)(path, "utf8").catch(() => null);
|
|
45
|
+
if (current === content) return false;
|
|
46
|
+
await (0, import_promises.mkdir)((0, import_node_path.dirname)(path), { recursive: true });
|
|
47
|
+
await (0, import_promises.writeFile)(path, content, "utf8");
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/unplugin.ts
|
|
52
|
+
var import_node_path3 = require("path");
|
|
41
53
|
|
|
42
54
|
// src/scanner.ts
|
|
43
|
-
var
|
|
55
|
+
var import_promises2 = require("fs/promises");
|
|
56
|
+
var import_node_path2 = require("path");
|
|
44
57
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
58
|
+
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
45
59
|
|
|
46
60
|
// src/parser.ts
|
|
47
61
|
function stepQuote(text, i, quote) {
|
|
@@ -323,6 +337,17 @@ function toRawPosition(stripped, strippedPos) {
|
|
|
323
337
|
function normalizePatterns(patterns) {
|
|
324
338
|
return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
|
|
325
339
|
}
|
|
340
|
+
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
341
|
+
const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
|
|
342
|
+
const include = compile(patterns);
|
|
343
|
+
const ignore = exclude ? compile(exclude) : () => false;
|
|
344
|
+
return (file) => {
|
|
345
|
+
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
346
|
+
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
347
|
+
const matches = (test) => test(fromCwd) || test(absolute);
|
|
348
|
+
return matches(include) && !matches(ignore);
|
|
349
|
+
};
|
|
350
|
+
}
|
|
326
351
|
function collectVarNames(scanned) {
|
|
327
352
|
const names = new Set(scanned.declarations.keys());
|
|
328
353
|
for (const values of scanned.themes.values()) {
|
|
@@ -338,7 +363,7 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
338
363
|
files.map(async (file) => {
|
|
339
364
|
let css;
|
|
340
365
|
try {
|
|
341
|
-
css = await (0,
|
|
366
|
+
css = await (0, import_promises2.readFile)(file, "utf8");
|
|
342
367
|
} catch (err) {
|
|
343
368
|
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
344
369
|
return null;
|
|
@@ -386,7 +411,7 @@ async function scanUsage(patterns, exclude) {
|
|
|
386
411
|
const texts = await Promise.all(
|
|
387
412
|
files.map(async (file) => {
|
|
388
413
|
try {
|
|
389
|
-
return await (0,
|
|
414
|
+
return await (0, import_promises2.readFile)(file, "utf8");
|
|
390
415
|
} catch (err) {
|
|
391
416
|
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
392
417
|
return "";
|
|
@@ -690,19 +715,19 @@ function generateTokens(varNames, options = {}) {
|
|
|
690
715
|
return value === void 0 ? [] : [{ meta, value, path: computeKeyPath(name, options.prefix, options.naming, options.group) }];
|
|
691
716
|
});
|
|
692
717
|
const paths = new Map(tokens.map(({ meta, path }) => [meta.name, path]));
|
|
693
|
-
const
|
|
718
|
+
const resolve3 = (value) => {
|
|
694
719
|
const target = paths.get(VAR_REF_RE.exec(value.trim())?.[1] ?? "");
|
|
695
720
|
return target ? `{${target.join(".")}}` : value;
|
|
696
721
|
};
|
|
697
722
|
const root = {};
|
|
698
723
|
for (const { meta, value, path } of tokens) {
|
|
699
|
-
const token = { $value:
|
|
724
|
+
const token = { $value: resolve3(value) };
|
|
700
725
|
const type = meta.syntax && TOKEN_TYPES[unquoteCssString(meta.syntax).trim()];
|
|
701
726
|
if (type) token.$type = type;
|
|
702
727
|
if (meta.doc?.description) token.$description = meta.doc.description;
|
|
703
728
|
if (meta.doc?.deprecated) token.$deprecated = meta.doc.deprecated;
|
|
704
729
|
if (meta.themes) {
|
|
705
|
-
const themes = Object.fromEntries(meta.themes.map(([theme, themeValue]) => [theme,
|
|
730
|
+
const themes = Object.fromEntries(meta.themes.map(([theme, themeValue]) => [theme, resolve3(themeValue)]));
|
|
706
731
|
token.$extensions = { "css-typed-vars": { themes } };
|
|
707
732
|
}
|
|
708
733
|
const [key, leaf] = path;
|
|
@@ -741,13 +766,13 @@ var VIRTUAL_ID = "css-typed-vars/vars";
|
|
|
741
766
|
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
742
767
|
function getDtsPath(options) {
|
|
743
768
|
if (options.dts === false) return null;
|
|
744
|
-
return options.dts ? (0,
|
|
769
|
+
return options.dts ? (0, import_node_path3.resolve)(process.cwd(), options.dts) : (0, import_node_path3.join)(__dirname, "generated.d.ts");
|
|
745
770
|
}
|
|
746
771
|
function outputFiles(options, names, generatorOptions) {
|
|
747
772
|
const files = [];
|
|
748
773
|
const dtsPath = getDtsPath(options);
|
|
749
774
|
if (dtsPath) files.push([dtsPath, generateDeclaration(names, generatorOptions)]);
|
|
750
|
-
if (options.tokens) files.push([(0,
|
|
775
|
+
if (options.tokens) files.push([(0, import_node_path3.resolve)(process.cwd(), options.tokens), generateTokens(names, generatorOptions)]);
|
|
751
776
|
return files;
|
|
752
777
|
}
|
|
753
778
|
var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
@@ -799,7 +824,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
799
824
|
writeQueue = writeQueue.then(async () => {
|
|
800
825
|
for (const [path, content] of files) {
|
|
801
826
|
if (myGeneration !== generation) return;
|
|
802
|
-
await (
|
|
827
|
+
await writeOutput(path, content);
|
|
803
828
|
}
|
|
804
829
|
}).catch(console.error);
|
|
805
830
|
await writeQueue;
|
|
@@ -811,8 +836,12 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
811
836
|
server.ws.send({ type: "full-reload" });
|
|
812
837
|
}
|
|
813
838
|
};
|
|
839
|
+
const isInput = createFileMatcher(options.input, options.exclude);
|
|
840
|
+
const isUsage = options.prune ? createFileMatcher(options.usage, options.usageExclude) : () => false;
|
|
841
|
+
const outputs = new Set([getDtsPath(options), options.tokens && (0, import_node_path3.resolve)(process.cwd(), options.tokens)].filter((path) => !!path).map((path) => (0, import_node_path3.resolve)(path)));
|
|
814
842
|
const handle = (file) => {
|
|
815
|
-
if (
|
|
843
|
+
if (outputs.has((0, import_node_path3.resolve)(file))) return;
|
|
844
|
+
if (!isInput(file) && !isUsage(file)) return;
|
|
816
845
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
817
846
|
debounceTimer = setTimeout(() => {
|
|
818
847
|
debounceTimer = null;
|
|
@@ -829,7 +858,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
829
858
|
const scanned = await cachedScan;
|
|
830
859
|
const names = await resolveNames(scanned);
|
|
831
860
|
for (const [path, content] of outputFiles(options, names, generatorOptions(scanned))) {
|
|
832
|
-
await (
|
|
861
|
+
await writeOutput(path, content);
|
|
833
862
|
}
|
|
834
863
|
},
|
|
835
864
|
resolveId(id) {
|
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -34,12 +34,26 @@ __export(unplugin_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(unplugin_exports);
|
|
36
36
|
var import_unplugin = require("unplugin");
|
|
37
|
-
|
|
37
|
+
|
|
38
|
+
// src/write.ts
|
|
39
|
+
var import_promises = require("fs/promises");
|
|
38
40
|
var import_node_path = require("path");
|
|
41
|
+
async function writeOutput(path, content) {
|
|
42
|
+
const current = await (0, import_promises.readFile)(path, "utf8").catch(() => null);
|
|
43
|
+
if (current === content) return false;
|
|
44
|
+
await (0, import_promises.mkdir)((0, import_node_path.dirname)(path), { recursive: true });
|
|
45
|
+
await (0, import_promises.writeFile)(path, content, "utf8");
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/unplugin.ts
|
|
50
|
+
var import_node_path3 = require("path");
|
|
39
51
|
|
|
40
52
|
// src/scanner.ts
|
|
41
|
-
var
|
|
53
|
+
var import_promises2 = require("fs/promises");
|
|
54
|
+
var import_node_path2 = require("path");
|
|
42
55
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
56
|
+
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
43
57
|
|
|
44
58
|
// src/parser.ts
|
|
45
59
|
function stepQuote(text, i, quote) {
|
|
@@ -321,6 +335,17 @@ function toRawPosition(stripped, strippedPos) {
|
|
|
321
335
|
function normalizePatterns(patterns) {
|
|
322
336
|
return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
|
|
323
337
|
}
|
|
338
|
+
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
339
|
+
const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
|
|
340
|
+
const include = compile(patterns);
|
|
341
|
+
const ignore = exclude ? compile(exclude) : () => false;
|
|
342
|
+
return (file) => {
|
|
343
|
+
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
344
|
+
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
345
|
+
const matches = (test) => test(fromCwd) || test(absolute);
|
|
346
|
+
return matches(include) && !matches(ignore);
|
|
347
|
+
};
|
|
348
|
+
}
|
|
324
349
|
function collectVarNames(scanned) {
|
|
325
350
|
const names = new Set(scanned.declarations.keys());
|
|
326
351
|
for (const values of scanned.themes.values()) {
|
|
@@ -336,7 +361,7 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
336
361
|
files.map(async (file) => {
|
|
337
362
|
let css;
|
|
338
363
|
try {
|
|
339
|
-
css = await (0,
|
|
364
|
+
css = await (0, import_promises2.readFile)(file, "utf8");
|
|
340
365
|
} catch (err) {
|
|
341
366
|
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
342
367
|
return null;
|
|
@@ -384,7 +409,7 @@ async function scanUsage(patterns, exclude) {
|
|
|
384
409
|
const texts = await Promise.all(
|
|
385
410
|
files.map(async (file) => {
|
|
386
411
|
try {
|
|
387
|
-
return await (0,
|
|
412
|
+
return await (0, import_promises2.readFile)(file, "utf8");
|
|
388
413
|
} catch (err) {
|
|
389
414
|
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
390
415
|
return "";
|
|
@@ -688,19 +713,19 @@ function generateTokens(varNames, options = {}) {
|
|
|
688
713
|
return value === void 0 ? [] : [{ meta, value, path: computeKeyPath(name, options.prefix, options.naming, options.group) }];
|
|
689
714
|
});
|
|
690
715
|
const paths = new Map(tokens.map(({ meta, path }) => [meta.name, path]));
|
|
691
|
-
const
|
|
716
|
+
const resolve3 = (value) => {
|
|
692
717
|
const target = paths.get(VAR_REF_RE.exec(value.trim())?.[1] ?? "");
|
|
693
718
|
return target ? `{${target.join(".")}}` : value;
|
|
694
719
|
};
|
|
695
720
|
const root = {};
|
|
696
721
|
for (const { meta, value, path } of tokens) {
|
|
697
|
-
const token = { $value:
|
|
722
|
+
const token = { $value: resolve3(value) };
|
|
698
723
|
const type = meta.syntax && TOKEN_TYPES[unquoteCssString(meta.syntax).trim()];
|
|
699
724
|
if (type) token.$type = type;
|
|
700
725
|
if (meta.doc?.description) token.$description = meta.doc.description;
|
|
701
726
|
if (meta.doc?.deprecated) token.$deprecated = meta.doc.deprecated;
|
|
702
727
|
if (meta.themes) {
|
|
703
|
-
const themes = Object.fromEntries(meta.themes.map(([theme, themeValue]) => [theme,
|
|
728
|
+
const themes = Object.fromEntries(meta.themes.map(([theme, themeValue]) => [theme, resolve3(themeValue)]));
|
|
704
729
|
token.$extensions = { "css-typed-vars": { themes } };
|
|
705
730
|
}
|
|
706
731
|
const [key, leaf] = path;
|
|
@@ -739,13 +764,13 @@ var VIRTUAL_ID = "css-typed-vars/vars";
|
|
|
739
764
|
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
740
765
|
function getDtsPath(options) {
|
|
741
766
|
if (options.dts === false) return null;
|
|
742
|
-
return options.dts ? (0,
|
|
767
|
+
return options.dts ? (0, import_node_path3.resolve)(process.cwd(), options.dts) : (0, import_node_path3.join)(__dirname, "generated.d.ts");
|
|
743
768
|
}
|
|
744
769
|
function outputFiles(options, names, generatorOptions) {
|
|
745
770
|
const files = [];
|
|
746
771
|
const dtsPath = getDtsPath(options);
|
|
747
772
|
if (dtsPath) files.push([dtsPath, generateDeclaration(names, generatorOptions)]);
|
|
748
|
-
if (options.tokens) files.push([(0,
|
|
773
|
+
if (options.tokens) files.push([(0, import_node_path3.resolve)(process.cwd(), options.tokens), generateTokens(names, generatorOptions)]);
|
|
749
774
|
return files;
|
|
750
775
|
}
|
|
751
776
|
var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
@@ -797,7 +822,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
797
822
|
writeQueue = writeQueue.then(async () => {
|
|
798
823
|
for (const [path, content] of files) {
|
|
799
824
|
if (myGeneration !== generation) return;
|
|
800
|
-
await (
|
|
825
|
+
await writeOutput(path, content);
|
|
801
826
|
}
|
|
802
827
|
}).catch(console.error);
|
|
803
828
|
await writeQueue;
|
|
@@ -809,8 +834,12 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
809
834
|
server.ws.send({ type: "full-reload" });
|
|
810
835
|
}
|
|
811
836
|
};
|
|
837
|
+
const isInput = createFileMatcher(options.input, options.exclude);
|
|
838
|
+
const isUsage = options.prune ? createFileMatcher(options.usage, options.usageExclude) : () => false;
|
|
839
|
+
const outputs = new Set([getDtsPath(options), options.tokens && (0, import_node_path3.resolve)(process.cwd(), options.tokens)].filter((path) => !!path).map((path) => (0, import_node_path3.resolve)(path)));
|
|
812
840
|
const handle = (file) => {
|
|
813
|
-
if (
|
|
841
|
+
if (outputs.has((0, import_node_path3.resolve)(file))) return;
|
|
842
|
+
if (!isInput(file) && !isUsage(file)) return;
|
|
814
843
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
815
844
|
debounceTimer = setTimeout(() => {
|
|
816
845
|
debounceTimer = null;
|
|
@@ -827,7 +856,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
827
856
|
const scanned = await cachedScan;
|
|
828
857
|
const names = await resolveNames(scanned);
|
|
829
858
|
for (const [path, content] of outputFiles(options, names, generatorOptions(scanned))) {
|
|
830
|
-
await (
|
|
859
|
+
await writeOutput(path, content);
|
|
831
860
|
}
|
|
832
861
|
},
|
|
833
862
|
resolveId(id) {
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -36,12 +36,26 @@ module.exports = __toCommonJS(vite_exports);
|
|
|
36
36
|
|
|
37
37
|
// src/unplugin.ts
|
|
38
38
|
var import_unplugin = require("unplugin");
|
|
39
|
-
|
|
39
|
+
|
|
40
|
+
// src/write.ts
|
|
41
|
+
var import_promises = require("fs/promises");
|
|
40
42
|
var import_node_path = require("path");
|
|
43
|
+
async function writeOutput(path, content) {
|
|
44
|
+
const current = await (0, import_promises.readFile)(path, "utf8").catch(() => null);
|
|
45
|
+
if (current === content) return false;
|
|
46
|
+
await (0, import_promises.mkdir)((0, import_node_path.dirname)(path), { recursive: true });
|
|
47
|
+
await (0, import_promises.writeFile)(path, content, "utf8");
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/unplugin.ts
|
|
52
|
+
var import_node_path3 = require("path");
|
|
41
53
|
|
|
42
54
|
// src/scanner.ts
|
|
43
|
-
var
|
|
55
|
+
var import_promises2 = require("fs/promises");
|
|
56
|
+
var import_node_path2 = require("path");
|
|
44
57
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
58
|
+
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
45
59
|
|
|
46
60
|
// src/parser.ts
|
|
47
61
|
function stepQuote(text, i, quote) {
|
|
@@ -323,6 +337,17 @@ function toRawPosition(stripped, strippedPos) {
|
|
|
323
337
|
function normalizePatterns(patterns) {
|
|
324
338
|
return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
|
|
325
339
|
}
|
|
340
|
+
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
341
|
+
const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
|
|
342
|
+
const include = compile(patterns);
|
|
343
|
+
const ignore = exclude ? compile(exclude) : () => false;
|
|
344
|
+
return (file) => {
|
|
345
|
+
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
346
|
+
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
347
|
+
const matches = (test) => test(fromCwd) || test(absolute);
|
|
348
|
+
return matches(include) && !matches(ignore);
|
|
349
|
+
};
|
|
350
|
+
}
|
|
326
351
|
function collectVarNames(scanned) {
|
|
327
352
|
const names = new Set(scanned.declarations.keys());
|
|
328
353
|
for (const values of scanned.themes.values()) {
|
|
@@ -338,7 +363,7 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
338
363
|
files.map(async (file) => {
|
|
339
364
|
let css;
|
|
340
365
|
try {
|
|
341
|
-
css = await (0,
|
|
366
|
+
css = await (0, import_promises2.readFile)(file, "utf8");
|
|
342
367
|
} catch (err) {
|
|
343
368
|
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
344
369
|
return null;
|
|
@@ -386,7 +411,7 @@ async function scanUsage(patterns, exclude) {
|
|
|
386
411
|
const texts = await Promise.all(
|
|
387
412
|
files.map(async (file) => {
|
|
388
413
|
try {
|
|
389
|
-
return await (0,
|
|
414
|
+
return await (0, import_promises2.readFile)(file, "utf8");
|
|
390
415
|
} catch (err) {
|
|
391
416
|
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
392
417
|
return "";
|
|
@@ -690,19 +715,19 @@ function generateTokens(varNames, options = {}) {
|
|
|
690
715
|
return value === void 0 ? [] : [{ meta, value, path: computeKeyPath(name, options.prefix, options.naming, options.group) }];
|
|
691
716
|
});
|
|
692
717
|
const paths = new Map(tokens.map(({ meta, path }) => [meta.name, path]));
|
|
693
|
-
const
|
|
718
|
+
const resolve3 = (value) => {
|
|
694
719
|
const target = paths.get(VAR_REF_RE.exec(value.trim())?.[1] ?? "");
|
|
695
720
|
return target ? `{${target.join(".")}}` : value;
|
|
696
721
|
};
|
|
697
722
|
const root = {};
|
|
698
723
|
for (const { meta, value, path } of tokens) {
|
|
699
|
-
const token = { $value:
|
|
724
|
+
const token = { $value: resolve3(value) };
|
|
700
725
|
const type = meta.syntax && TOKEN_TYPES[unquoteCssString(meta.syntax).trim()];
|
|
701
726
|
if (type) token.$type = type;
|
|
702
727
|
if (meta.doc?.description) token.$description = meta.doc.description;
|
|
703
728
|
if (meta.doc?.deprecated) token.$deprecated = meta.doc.deprecated;
|
|
704
729
|
if (meta.themes) {
|
|
705
|
-
const themes = Object.fromEntries(meta.themes.map(([theme, themeValue]) => [theme,
|
|
730
|
+
const themes = Object.fromEntries(meta.themes.map(([theme, themeValue]) => [theme, resolve3(themeValue)]));
|
|
706
731
|
token.$extensions = { "css-typed-vars": { themes } };
|
|
707
732
|
}
|
|
708
733
|
const [key, leaf] = path;
|
|
@@ -741,13 +766,13 @@ var VIRTUAL_ID = "css-typed-vars/vars";
|
|
|
741
766
|
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
742
767
|
function getDtsPath(options) {
|
|
743
768
|
if (options.dts === false) return null;
|
|
744
|
-
return options.dts ? (0,
|
|
769
|
+
return options.dts ? (0, import_node_path3.resolve)(process.cwd(), options.dts) : (0, import_node_path3.join)(__dirname, "generated.d.ts");
|
|
745
770
|
}
|
|
746
771
|
function outputFiles(options, names, generatorOptions) {
|
|
747
772
|
const files = [];
|
|
748
773
|
const dtsPath = getDtsPath(options);
|
|
749
774
|
if (dtsPath) files.push([dtsPath, generateDeclaration(names, generatorOptions)]);
|
|
750
|
-
if (options.tokens) files.push([(0,
|
|
775
|
+
if (options.tokens) files.push([(0, import_node_path3.resolve)(process.cwd(), options.tokens), generateTokens(names, generatorOptions)]);
|
|
751
776
|
return files;
|
|
752
777
|
}
|
|
753
778
|
var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
@@ -799,7 +824,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
799
824
|
writeQueue = writeQueue.then(async () => {
|
|
800
825
|
for (const [path, content] of files) {
|
|
801
826
|
if (myGeneration !== generation) return;
|
|
802
|
-
await (
|
|
827
|
+
await writeOutput(path, content);
|
|
803
828
|
}
|
|
804
829
|
}).catch(console.error);
|
|
805
830
|
await writeQueue;
|
|
@@ -811,8 +836,12 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
811
836
|
server.ws.send({ type: "full-reload" });
|
|
812
837
|
}
|
|
813
838
|
};
|
|
839
|
+
const isInput = createFileMatcher(options.input, options.exclude);
|
|
840
|
+
const isUsage = options.prune ? createFileMatcher(options.usage, options.usageExclude) : () => false;
|
|
841
|
+
const outputs = new Set([getDtsPath(options), options.tokens && (0, import_node_path3.resolve)(process.cwd(), options.tokens)].filter((path) => !!path).map((path) => (0, import_node_path3.resolve)(path)));
|
|
814
842
|
const handle = (file) => {
|
|
815
|
-
if (
|
|
843
|
+
if (outputs.has((0, import_node_path3.resolve)(file))) return;
|
|
844
|
+
if (!isInput(file) && !isUsage(file)) return;
|
|
816
845
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
817
846
|
debounceTimer = setTimeout(() => {
|
|
818
847
|
debounceTimer = null;
|
|
@@ -829,7 +858,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
829
858
|
const scanned = await cachedScan;
|
|
830
859
|
const names = await resolveNames(scanned);
|
|
831
860
|
for (const [path, content] of outputFiles(options, names, generatorOptions(scanned))) {
|
|
832
|
-
await (
|
|
861
|
+
await writeOutput(path, content);
|
|
833
862
|
}
|
|
834
863
|
},
|
|
835
864
|
resolveId(id) {
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -36,12 +36,26 @@ module.exports = __toCommonJS(webpack_exports);
|
|
|
36
36
|
|
|
37
37
|
// src/unplugin.ts
|
|
38
38
|
var import_unplugin = require("unplugin");
|
|
39
|
-
|
|
39
|
+
|
|
40
|
+
// src/write.ts
|
|
41
|
+
var import_promises = require("fs/promises");
|
|
40
42
|
var import_node_path = require("path");
|
|
43
|
+
async function writeOutput(path, content) {
|
|
44
|
+
const current = await (0, import_promises.readFile)(path, "utf8").catch(() => null);
|
|
45
|
+
if (current === content) return false;
|
|
46
|
+
await (0, import_promises.mkdir)((0, import_node_path.dirname)(path), { recursive: true });
|
|
47
|
+
await (0, import_promises.writeFile)(path, content, "utf8");
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/unplugin.ts
|
|
52
|
+
var import_node_path3 = require("path");
|
|
41
53
|
|
|
42
54
|
// src/scanner.ts
|
|
43
|
-
var
|
|
55
|
+
var import_promises2 = require("fs/promises");
|
|
56
|
+
var import_node_path2 = require("path");
|
|
44
57
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
58
|
+
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
45
59
|
|
|
46
60
|
// src/parser.ts
|
|
47
61
|
function stepQuote(text, i, quote) {
|
|
@@ -323,6 +337,17 @@ function toRawPosition(stripped, strippedPos) {
|
|
|
323
337
|
function normalizePatterns(patterns) {
|
|
324
338
|
return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
|
|
325
339
|
}
|
|
340
|
+
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
341
|
+
const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
|
|
342
|
+
const include = compile(patterns);
|
|
343
|
+
const ignore = exclude ? compile(exclude) : () => false;
|
|
344
|
+
return (file) => {
|
|
345
|
+
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
346
|
+
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
347
|
+
const matches = (test) => test(fromCwd) || test(absolute);
|
|
348
|
+
return matches(include) && !matches(ignore);
|
|
349
|
+
};
|
|
350
|
+
}
|
|
326
351
|
function collectVarNames(scanned) {
|
|
327
352
|
const names = new Set(scanned.declarations.keys());
|
|
328
353
|
for (const values of scanned.themes.values()) {
|
|
@@ -338,7 +363,7 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
338
363
|
files.map(async (file) => {
|
|
339
364
|
let css;
|
|
340
365
|
try {
|
|
341
|
-
css = await (0,
|
|
366
|
+
css = await (0, import_promises2.readFile)(file, "utf8");
|
|
342
367
|
} catch (err) {
|
|
343
368
|
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
344
369
|
return null;
|
|
@@ -386,7 +411,7 @@ async function scanUsage(patterns, exclude) {
|
|
|
386
411
|
const texts = await Promise.all(
|
|
387
412
|
files.map(async (file) => {
|
|
388
413
|
try {
|
|
389
|
-
return await (0,
|
|
414
|
+
return await (0, import_promises2.readFile)(file, "utf8");
|
|
390
415
|
} catch (err) {
|
|
391
416
|
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
392
417
|
return "";
|
|
@@ -690,19 +715,19 @@ function generateTokens(varNames, options = {}) {
|
|
|
690
715
|
return value === void 0 ? [] : [{ meta, value, path: computeKeyPath(name, options.prefix, options.naming, options.group) }];
|
|
691
716
|
});
|
|
692
717
|
const paths = new Map(tokens.map(({ meta, path }) => [meta.name, path]));
|
|
693
|
-
const
|
|
718
|
+
const resolve3 = (value) => {
|
|
694
719
|
const target = paths.get(VAR_REF_RE.exec(value.trim())?.[1] ?? "");
|
|
695
720
|
return target ? `{${target.join(".")}}` : value;
|
|
696
721
|
};
|
|
697
722
|
const root = {};
|
|
698
723
|
for (const { meta, value, path } of tokens) {
|
|
699
|
-
const token = { $value:
|
|
724
|
+
const token = { $value: resolve3(value) };
|
|
700
725
|
const type = meta.syntax && TOKEN_TYPES[unquoteCssString(meta.syntax).trim()];
|
|
701
726
|
if (type) token.$type = type;
|
|
702
727
|
if (meta.doc?.description) token.$description = meta.doc.description;
|
|
703
728
|
if (meta.doc?.deprecated) token.$deprecated = meta.doc.deprecated;
|
|
704
729
|
if (meta.themes) {
|
|
705
|
-
const themes = Object.fromEntries(meta.themes.map(([theme, themeValue]) => [theme,
|
|
730
|
+
const themes = Object.fromEntries(meta.themes.map(([theme, themeValue]) => [theme, resolve3(themeValue)]));
|
|
706
731
|
token.$extensions = { "css-typed-vars": { themes } };
|
|
707
732
|
}
|
|
708
733
|
const [key, leaf] = path;
|
|
@@ -741,13 +766,13 @@ var VIRTUAL_ID = "css-typed-vars/vars";
|
|
|
741
766
|
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
742
767
|
function getDtsPath(options) {
|
|
743
768
|
if (options.dts === false) return null;
|
|
744
|
-
return options.dts ? (0,
|
|
769
|
+
return options.dts ? (0, import_node_path3.resolve)(process.cwd(), options.dts) : (0, import_node_path3.join)(__dirname, "generated.d.ts");
|
|
745
770
|
}
|
|
746
771
|
function outputFiles(options, names, generatorOptions) {
|
|
747
772
|
const files = [];
|
|
748
773
|
const dtsPath = getDtsPath(options);
|
|
749
774
|
if (dtsPath) files.push([dtsPath, generateDeclaration(names, generatorOptions)]);
|
|
750
|
-
if (options.tokens) files.push([(0,
|
|
775
|
+
if (options.tokens) files.push([(0, import_node_path3.resolve)(process.cwd(), options.tokens), generateTokens(names, generatorOptions)]);
|
|
751
776
|
return files;
|
|
752
777
|
}
|
|
753
778
|
var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
@@ -799,7 +824,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
799
824
|
writeQueue = writeQueue.then(async () => {
|
|
800
825
|
for (const [path, content] of files) {
|
|
801
826
|
if (myGeneration !== generation) return;
|
|
802
|
-
await (
|
|
827
|
+
await writeOutput(path, content);
|
|
803
828
|
}
|
|
804
829
|
}).catch(console.error);
|
|
805
830
|
await writeQueue;
|
|
@@ -811,8 +836,12 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
811
836
|
server.ws.send({ type: "full-reload" });
|
|
812
837
|
}
|
|
813
838
|
};
|
|
839
|
+
const isInput = createFileMatcher(options.input, options.exclude);
|
|
840
|
+
const isUsage = options.prune ? createFileMatcher(options.usage, options.usageExclude) : () => false;
|
|
841
|
+
const outputs = new Set([getDtsPath(options), options.tokens && (0, import_node_path3.resolve)(process.cwd(), options.tokens)].filter((path) => !!path).map((path) => (0, import_node_path3.resolve)(path)));
|
|
814
842
|
const handle = (file) => {
|
|
815
|
-
if (
|
|
843
|
+
if (outputs.has((0, import_node_path3.resolve)(file))) return;
|
|
844
|
+
if (!isInput(file) && !isUsage(file)) return;
|
|
816
845
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
817
846
|
debounceTimer = setTimeout(() => {
|
|
818
847
|
debounceTimer = null;
|
|
@@ -829,7 +858,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
829
858
|
const scanned = await cachedScan;
|
|
830
859
|
const names = await resolveNames(scanned);
|
|
831
860
|
for (const [path, content] of outputFiles(options, names, generatorOptions(scanned))) {
|
|
832
|
-
await (
|
|
861
|
+
await writeOutput(path, content);
|
|
833
862
|
}
|
|
834
863
|
},
|
|
835
864
|
resolveId(id) {
|
package/dist/webpack.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-typed-vars",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Generate TypeScript typed constants from CSS custom properties",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -70,10 +70,12 @@
|
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"chokidar": "^3.6.0",
|
|
72
72
|
"fast-glob": "^3.3.2",
|
|
73
|
+
"picomatch": "^2.3.2",
|
|
73
74
|
"unplugin": "^3.0.0"
|
|
74
75
|
},
|
|
75
76
|
"devDependencies": {
|
|
76
77
|
"@types/node": "^25.5.2",
|
|
78
|
+
"@types/picomatch": "^2.3.4",
|
|
77
79
|
"tsup": "^8.0.0",
|
|
78
80
|
"typescript": "^5.4.0",
|
|
79
81
|
"vitepress": "^1.6.4",
|