@csszyx/unplugin 0.9.0 → 0.9.1

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.
Files changed (43) hide show
  1. package/dist/index.cjs +19 -2
  2. package/dist/index.d.cts +91 -5
  3. package/dist/index.d.mts +90 -3
  4. package/dist/index.mjs +4 -2
  5. package/dist/next-prebuild.cjs +148 -0
  6. package/dist/next-prebuild.d.cts +66 -0
  7. package/dist/next-prebuild.d.mts +66 -0
  8. package/dist/next-prebuild.mjs +131 -0
  9. package/dist/next-turbo-loader.cjs +210 -0
  10. package/dist/next-turbo-loader.d.cts +68 -0
  11. package/dist/next-turbo-loader.d.mts +66 -0
  12. package/dist/next-turbo-loader.mjs +190 -0
  13. package/dist/next-watcher.cjs +237 -0
  14. package/dist/next-watcher.d.cts +106 -0
  15. package/dist/next-watcher.d.mts +106 -0
  16. package/dist/next-watcher.mjs +219 -0
  17. package/dist/shared/unplugin.8er8o6rn.mjs +276 -0
  18. package/dist/shared/unplugin.B_U4rZvG.cjs +281 -0
  19. package/dist/shared/{unplugin.BEOG6ePC.mjs → unplugin.BbtspS8t.mjs} +1436 -324
  20. package/dist/shared/unplugin.BceVw1eW.mjs +184 -0
  21. package/dist/shared/unplugin.BtQzlC2C.mjs +567 -0
  22. package/dist/shared/{unplugin.CL0F6RZa.cjs → unplugin.CFp386gH.cjs} +1456 -327
  23. package/dist/shared/unplugin.CPEWNSA0.d.cts +77 -0
  24. package/dist/shared/unplugin.CPEWNSA0.d.mts +77 -0
  25. package/dist/shared/unplugin.CScQRdTp.d.cts +15 -0
  26. package/dist/shared/unplugin.CScQRdTp.d.mts +15 -0
  27. package/dist/shared/unplugin.CdZxp0x-.d.mts +16 -0
  28. package/dist/shared/unplugin.DLrBgECN.d.cts +282 -0
  29. package/dist/shared/unplugin.DLrBgECN.d.mts +282 -0
  30. package/dist/shared/unplugin.DUxdYaSG.cjs +205 -0
  31. package/dist/shared/unplugin.s62yJbu1.cjs +591 -0
  32. package/dist/shared/unplugin.xeED_qwh.d.cts +16 -0
  33. package/dist/vite.cjs +3 -1
  34. package/dist/vite.d.cts +2 -1
  35. package/dist/vite.d.mts +2 -1
  36. package/dist/vite.mjs +3 -1
  37. package/dist/webpack.cjs +3 -1
  38. package/dist/webpack.d.cts +2 -1
  39. package/dist/webpack.d.mts +2 -1
  40. package/dist/webpack.mjs +3 -1
  41. package/package.json +41 -8
  42. package/dist/shared/unplugin.DUbr5w-N.d.cts +0 -49
  43. package/dist/shared/unplugin.DUbr5w-N.d.mts +0 -49
@@ -0,0 +1,184 @@
1
+ import { createHash } from 'node:crypto';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
+
5
+ const CACHE_SCHEMA_VERSION = 6;
6
+ function resolveTransformCacheDir(rootDir, cacheDir) {
7
+ return path.resolve(rootDir, cacheDir ?? ".csszyx/cache", "transform");
8
+ }
9
+ function createTransformCacheKey(input) {
10
+ const inputSha256 = createHash("sha256").update(input.source).digest("hex");
11
+ const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
12
+ const keyMaterial = [
13
+ `schema=${CACHE_SCHEMA_VERSION}`,
14
+ `plugin=${input.pluginVersion}`,
15
+ `compiler=${input.compilerVersion}`,
16
+ `parser=${input.parserMode}`,
17
+ `producer=${input.producer}`,
18
+ `astBudget=${input.astBudget ?? "default"}`,
19
+ `mangleVars=${input.mangleVars === true}`,
20
+ `mangleVarHoistMaxDepth=${input.mangleVarHoistMaxDepth ?? "default"}`,
21
+ `globalVarAliases=${JSON.stringify(globalVarAliases)}`,
22
+ `filename=${input.filename}`,
23
+ `source=${inputSha256}`
24
+ ].join("\n");
25
+ return {
26
+ key: createHash("sha256").update(keyMaterial).digest("hex").slice(0, 16),
27
+ inputSha256
28
+ };
29
+ }
30
+ function readTransformCache(cacheRoot, input, precomputedKey) {
31
+ const { key, inputSha256 } = precomputedKey ?? createTransformCacheKey(input);
32
+ const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
33
+ const file = cacheEntryPath(cacheRoot, key);
34
+ let entry;
35
+ try {
36
+ entry = JSON.parse(fs.readFileSync(file, "utf8"));
37
+ } catch {
38
+ return null;
39
+ }
40
+ if (entry.version !== CACHE_SCHEMA_VERSION || entry.pluginVersion !== input.pluginVersion || entry.compilerVersion !== input.compilerVersion || entry.parserMode !== input.parserMode || entry.producer !== input.producer || entry.astBudget !== (input.astBudget ?? null) || entry.mangleVars !== (input.mangleVars === true) || entry.mangleVarHoistMaxDepth !== (input.mangleVarHoistMaxDepth ?? null) || !sameGlobalVarAliases(entry.globalVarAliases, globalVarAliases) || entry.filename !== input.filename || entry.inputSha256 !== inputSha256) {
41
+ return null;
42
+ }
43
+ return deserializeResult(entry.result);
44
+ }
45
+ function writeTransformCache(cacheRoot, input, result, precomputedKey) {
46
+ const { key, inputSha256 } = precomputedKey ?? createTransformCacheKey(input);
47
+ const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
48
+ const file = cacheEntryPath(cacheRoot, key);
49
+ const dir = path.dirname(file);
50
+ const tmp = path.join(
51
+ dir,
52
+ `.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.json`
53
+ );
54
+ const entry = {
55
+ version: CACHE_SCHEMA_VERSION,
56
+ pluginVersion: input.pluginVersion,
57
+ compilerVersion: input.compilerVersion,
58
+ parserMode: input.parserMode,
59
+ producer: input.producer,
60
+ astBudget: input.astBudget ?? null,
61
+ mangleVars: input.mangleVars === true,
62
+ mangleVarHoistMaxDepth: input.mangleVarHoistMaxDepth ?? null,
63
+ globalVarAliases,
64
+ filename: input.filename,
65
+ inputSha256,
66
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
67
+ result: serializeResult(result)
68
+ };
69
+ try {
70
+ fs.mkdirSync(dir, { recursive: true });
71
+ fs.writeFileSync(tmp, JSON.stringify(entry), "utf8");
72
+ fs.renameSync(tmp, file);
73
+ } catch {
74
+ try {
75
+ fs.rmSync(tmp, { force: true });
76
+ } catch {
77
+ }
78
+ }
79
+ }
80
+ function evictOldTransformCacheEntries(cacheRoot, options) {
81
+ let deleted = 0;
82
+ const now = options.now ?? Date.now();
83
+ const survivors = [];
84
+ for (const file of listJsonFiles(cacheRoot)) {
85
+ try {
86
+ const entry = JSON.parse(fs.readFileSync(file, "utf8"));
87
+ const timestamp = typeof entry.timestamp === "string" ? Date.parse(entry.timestamp) : 0;
88
+ if (!Number.isFinite(timestamp) || now - timestamp > options.maxAgeMs) {
89
+ fs.rmSync(file, { force: true });
90
+ deleted++;
91
+ } else {
92
+ survivors.push({ file, timestamp });
93
+ }
94
+ } catch {
95
+ fs.rmSync(file, { force: true });
96
+ deleted++;
97
+ }
98
+ }
99
+ const overflow = survivors.length - options.maxEntries ;
100
+ if (overflow > 0) {
101
+ survivors.sort((a, b) => a.timestamp - b.timestamp);
102
+ for (const survivor of survivors.slice(0, overflow)) {
103
+ fs.rmSync(survivor.file, { force: true });
104
+ deleted++;
105
+ }
106
+ }
107
+ return deleted;
108
+ }
109
+ function cacheEntryPath(cacheRoot, key) {
110
+ return path.join(cacheRoot, key.slice(0, 2), `${key.slice(2)}.json`);
111
+ }
112
+ function serializeResult(result) {
113
+ return {
114
+ code: result.code,
115
+ transformed: result.transformed,
116
+ usesRuntime: result.usesRuntime,
117
+ usesMerge: result.usesMerge,
118
+ usesColorVar: result.usesColorVar,
119
+ classes: [...result.classes],
120
+ rawClassNames: [...result.rawClassNames],
121
+ diagnostics: [...result.diagnostics],
122
+ recoveryTokens: [...result.recoveryTokens],
123
+ cssVariableMap: [...result.cssVariableMap ?? /* @__PURE__ */ new Map()]
124
+ };
125
+ }
126
+ function deserializeResult(result) {
127
+ return {
128
+ code: result.code,
129
+ transformed: result.transformed,
130
+ usesRuntime: result.usesRuntime,
131
+ usesMerge: result.usesMerge,
132
+ usesColorVar: result.usesColorVar,
133
+ classes: new Set(result.classes),
134
+ rawClassNames: new Set(result.rawClassNames),
135
+ diagnostics: [...result.diagnostics],
136
+ recoveryTokens: new Map(result.recoveryTokens),
137
+ cssVariableMap: new Map(result.cssVariableMap ?? [])
138
+ };
139
+ }
140
+ function normalizeGlobalVarAliasEntries(aliases) {
141
+ if (!aliases || aliases.length === 0) {
142
+ return [];
143
+ }
144
+ const normalized = /* @__PURE__ */ new Map();
145
+ for (const [original, alias] of aliases) {
146
+ if (typeof original === "string" && typeof alias === "string") {
147
+ normalized.set(original, alias);
148
+ }
149
+ }
150
+ return [...normalized].sort(([left], [right]) => left.localeCompare(right));
151
+ }
152
+ function sameGlobalVarAliases(left, right) {
153
+ if (!Array.isArray(left) || left.length !== right.length) {
154
+ return false;
155
+ }
156
+ for (let index = 0; index < left.length; index++) {
157
+ const leftEntry = left[index];
158
+ const rightEntry = right[index];
159
+ if (leftEntry?.[0] !== rightEntry?.[0] || leftEntry?.[1] !== rightEntry?.[1]) {
160
+ return false;
161
+ }
162
+ }
163
+ return true;
164
+ }
165
+ function listJsonFiles(dir) {
166
+ let entries;
167
+ try {
168
+ entries = fs.readdirSync(dir, { withFileTypes: true });
169
+ } catch {
170
+ return [];
171
+ }
172
+ const files = [];
173
+ for (const entry of entries) {
174
+ const fullPath = path.join(dir, entry.name);
175
+ if (entry.isDirectory()) {
176
+ files.push(...listJsonFiles(fullPath));
177
+ } else if (entry.isFile() && entry.name.endsWith(".json")) {
178
+ files.push(fullPath);
179
+ }
180
+ }
181
+ return files;
182
+ }
183
+
184
+ export { readTransformCache as a, createTransformCacheKey as c, evictOldTransformCacheEntries as e, resolveTransformCacheDir as r, writeTransformCache as w };