css-typed-vars 0.6.0 → 0.8.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 +189 -9
- package/dist/{chunk-TD7SYMDA.js → chunk-32V3V6WT.js} +46 -29
- package/dist/chunk-5HPTHW7S.js +820 -0
- package/dist/{chunk-VZ2BHHXD.js → chunk-YDXCJQPL.js} +42 -29
- package/dist/cli.cjs +542 -151
- package/dist/cli.js +142 -73
- package/dist/esbuild.cjs +358 -87
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.d.ts +1 -1
- package/dist/esbuild.js +2 -2
- package/dist/generator-DJ9uOYBP.d.cts +69 -0
- package/dist/generator-DJ9uOYBP.d.ts +69 -0
- package/dist/index.cjs +423 -77
- package/dist/index.d.cts +29 -6
- package/dist/index.d.ts +29 -6
- package/dist/index.js +14 -2
- package/dist/rollup.cjs +358 -87
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +358 -87
- package/dist/unplugin.d.cts +12 -2
- package/dist/unplugin.d.ts +12 -2
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +358 -87
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +358 -87
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-LH53WYFF.js +0 -487
- package/dist/generator-C2AppeJL.d.cts +0 -15
- package/dist/generator-C2AppeJL.d.ts +0 -15
|
@@ -1,64 +1,76 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
assertPruneCompatible,
|
|
3
|
+
collectVarNames,
|
|
3
4
|
generateCode,
|
|
4
5
|
generateDeclaration,
|
|
5
6
|
generateJs,
|
|
7
|
+
generateTokens,
|
|
8
|
+
partitionUnused,
|
|
6
9
|
scanCss,
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
scanReferences,
|
|
11
|
+
scanUsage,
|
|
9
12
|
warnOnCollisions
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-5HPTHW7S.js";
|
|
11
14
|
|
|
12
15
|
// src/index.ts
|
|
13
16
|
import { writeFile, mkdir, readFile } from "fs/promises";
|
|
14
17
|
import { dirname, resolve } from "path";
|
|
15
|
-
function assertPruneCompatible(options) {
|
|
16
|
-
if (!options.prune) return;
|
|
17
|
-
if (options.group) throw new Error('css-typed-vars: "prune" cannot be combined with "group".');
|
|
18
|
-
if (!options.usage) throw new Error('css-typed-vars: "prune" requires "usage" (glob(s) of source files to scan).');
|
|
19
|
-
}
|
|
20
|
-
function partitionUnused(names, usedKeys, prefix, naming) {
|
|
21
|
-
const used = [];
|
|
22
|
-
const unused = [];
|
|
23
|
-
for (const name of names) {
|
|
24
|
-
(usedKeys.has(computeKey(name, prefix, naming)) ? used : unused).push(name);
|
|
25
|
-
}
|
|
26
|
-
return { used, unused };
|
|
27
|
-
}
|
|
28
18
|
async function findUnusedVars(options) {
|
|
29
19
|
if (!options.usage) throw new Error('css-typed-vars: findUnusedVars requires "usage" (glob(s) of source files to scan).');
|
|
30
|
-
const [
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
const [scanned, usage] = await Promise.all([
|
|
21
|
+
scanCss(options.input, options.exclude, options.selectors, options.themes),
|
|
22
|
+
scanUsage(options.usage, options.usageExclude)
|
|
33
23
|
]);
|
|
34
|
-
const names =
|
|
35
|
-
return partitionUnused(names,
|
|
24
|
+
const names = collectVarNames(scanned);
|
|
25
|
+
return partitionUnused(names, usage, options).unused;
|
|
26
|
+
}
|
|
27
|
+
function matchesIgnore(name, patterns) {
|
|
28
|
+
return patterns.some((pattern) => pattern.endsWith("*") ? name.startsWith(pattern.slice(0, -1)) : name === pattern);
|
|
29
|
+
}
|
|
30
|
+
async function findUndefinedRefs(options) {
|
|
31
|
+
const { references, declared } = await scanReferences(options.input, options.exclude);
|
|
32
|
+
const ignore = options.refsIgnore ?? [];
|
|
33
|
+
return references.filter((ref) => !declared.has(ref.name) && !matchesIgnore(ref.name, ignore));
|
|
36
34
|
}
|
|
37
35
|
async function computeOutputs(options) {
|
|
38
36
|
assertPruneCompatible(options);
|
|
39
|
-
const
|
|
40
|
-
|
|
37
|
+
const scanned = await scanCss(options.input, options.exclude, options.selectors, options.themes);
|
|
38
|
+
const { declarations, properties } = scanned;
|
|
39
|
+
let names = collectVarNames(scanned);
|
|
41
40
|
if (names.length === 0) {
|
|
42
41
|
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
43
42
|
}
|
|
44
43
|
warnOnCollisions(names, options.prefix, options.naming);
|
|
45
44
|
if (options.prune) {
|
|
46
|
-
const
|
|
47
|
-
const { used, unused } = partitionUnused(names,
|
|
45
|
+
const usage = await scanUsage(options.usage, options.usageExclude);
|
|
46
|
+
const { used, unused } = partitionUnused(names, usage, options);
|
|
48
47
|
if (unused.length > 0) {
|
|
49
48
|
console.warn(`css-typed-vars: pruned ${unused.length} unused variable(s): ${unused.join(", ")}`);
|
|
50
49
|
}
|
|
51
50
|
names = used;
|
|
52
51
|
}
|
|
53
52
|
const outPath = resolve(options.output);
|
|
53
|
+
const generatorOptions = {
|
|
54
|
+
prefix: options.prefix,
|
|
55
|
+
naming: options.naming,
|
|
56
|
+
declarations,
|
|
57
|
+
group: options.group,
|
|
58
|
+
properties,
|
|
59
|
+
helpers: options.helpers,
|
|
60
|
+
themes: scanned.themes,
|
|
61
|
+
docs: scanned.docs
|
|
62
|
+
};
|
|
63
|
+
if (/\.json$/i.test(options.output)) {
|
|
64
|
+
return { outPath, content: generateTokens(names, generatorOptions) };
|
|
65
|
+
}
|
|
54
66
|
const jsExtMatch = /\.(m|c)?js$/i.exec(options.output);
|
|
55
67
|
if (jsExtMatch) {
|
|
56
|
-
const content = generateJs(names,
|
|
68
|
+
const content = generateJs(names, generatorOptions);
|
|
57
69
|
const dtsPath = outPath.slice(0, -jsExtMatch[0].length) + ".d.ts";
|
|
58
|
-
const dtsContent = generateDeclaration(names,
|
|
70
|
+
const dtsContent = generateDeclaration(names, generatorOptions);
|
|
59
71
|
return { outPath, content, dtsPath, dtsContent };
|
|
60
72
|
}
|
|
61
|
-
return { outPath, content: generateCode(names,
|
|
73
|
+
return { outPath, content: generateCode(names, generatorOptions) };
|
|
62
74
|
}
|
|
63
75
|
async function generate(options) {
|
|
64
76
|
const { outPath, content, dtsPath, dtsContent } = await computeOutputs(options);
|
|
@@ -81,6 +93,7 @@ async function checkGenerated(options) {
|
|
|
81
93
|
|
|
82
94
|
export {
|
|
83
95
|
findUnusedVars,
|
|
96
|
+
findUndefinedRefs,
|
|
84
97
|
generate,
|
|
85
98
|
checkGenerated
|
|
86
99
|
};
|