@csszyx/unplugin 0.11.11 → 0.13.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.
Files changed (44) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs +11 -7
  3. package/dist/index.d.cts +4 -4
  4. package/dist/index.d.mts +4 -4
  5. package/dist/index.mjs +4 -3
  6. package/dist/next-config.cjs +3 -0
  7. package/dist/next-config.d.cts +10 -0
  8. package/dist/next-config.d.mts +10 -0
  9. package/dist/next-config.mjs +3 -0
  10. package/dist/next-prebuild.cjs +12 -5
  11. package/dist/next-prebuild.d.cts +7 -0
  12. package/dist/next-prebuild.d.mts +7 -0
  13. package/dist/next-prebuild.mjs +12 -5
  14. package/dist/next-turbo-loader.cjs +29 -59
  15. package/dist/next-turbo-loader.d.cts +10 -0
  16. package/dist/next-turbo-loader.d.mts +10 -0
  17. package/dist/next-turbo-loader.mjs +28 -58
  18. package/dist/next-watcher.cjs +1 -1
  19. package/dist/next-watcher.mjs +1 -1
  20. package/dist/shared/unplugin.4du3qMst.cjs +529 -0
  21. package/dist/shared/unplugin.5l4RHMQh.mjs +578 -0
  22. package/dist/shared/unplugin.BB0iWSds.mjs +495 -0
  23. package/dist/shared/{unplugin.DMcbmP01.mjs → unplugin.BU0O4IkX.mjs} +4 -1
  24. package/dist/shared/{unplugin.CJcFsJcf.cjs → unplugin.Bf4fNbp7.cjs} +452 -504
  25. package/dist/shared/{unplugin.BZq6FKn2.cjs → unplugin.CUTa6bY9.cjs} +89 -1
  26. package/dist/shared/{unplugin.DblMogcN.cjs → unplugin.Cji6O5jv.cjs} +4 -1
  27. package/dist/shared/{unplugin.-yLpX1Ck.mjs → unplugin.CogPHmDs.mjs} +73 -3
  28. package/dist/shared/{unplugin.BK7BIeBn.d.cts → unplugin.DCT7DDG6.d.cts} +88 -26
  29. package/dist/shared/{unplugin.BK7BIeBn.d.mts → unplugin.DCT7DDG6.d.mts} +88 -26
  30. package/dist/shared/unplugin.X9a9SL_s.cjs +612 -0
  31. package/dist/shared/{unplugin.B2RUVK6Z.mjs → unplugin.ymMe428s.mjs} +426 -477
  32. package/dist/vite.cjs +4 -3
  33. package/dist/vite.d.cts +2 -2
  34. package/dist/vite.d.mts +1 -1
  35. package/dist/vite.mjs +4 -3
  36. package/dist/webpack.cjs +4 -3
  37. package/dist/webpack.d.cts +2 -2
  38. package/dist/webpack.d.mts +1 -1
  39. package/dist/webpack.mjs +4 -3
  40. package/package.json +13 -11
  41. package/dist/shared/unplugin.CKIOVNOg.cjs +0 -241
  42. package/dist/shared/unplugin.Cnxm1DcC.cjs +0 -53
  43. package/dist/shared/unplugin.Lhzkcj-A.mjs +0 -49
  44. package/dist/shared/unplugin.fOnGXWgS.mjs +0 -217
@@ -1,217 +0,0 @@
1
- import { OxcNotImplementedError } from '@csszyx/compiler';
2
- import { createHash, randomUUID } from 'node:crypto';
3
- import * as fs from 'node:fs';
4
- import * as path from 'node:path';
5
-
6
- const WINDOWS_PATH_SEPARATOR = String.fromCodePoint(92);
7
- function normalizePathSeparators(value) {
8
- return value.split(WINDOWS_PATH_SEPARATOR).join("/");
9
- }
10
-
11
- function babelFallbackReason(error) {
12
- if (error instanceof OxcNotImplementedError) {
13
- return error.detail;
14
- }
15
- return error instanceof Error ? error.message : String(error);
16
- }
17
-
18
- const CACHE_SCHEMA_VERSION = 10;
19
- function resolveTransformCacheDir(rootDir, cacheDir) {
20
- return path.resolve(rootDir, cacheDir ?? ".csszyx/cache", "transform");
21
- }
22
- function createTransformCacheKey(input) {
23
- const inputSha256 = createHash("sha256").update(input.source).digest("hex");
24
- const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
25
- const keyMaterial = [
26
- `schema=${CACHE_SCHEMA_VERSION}`,
27
- `plugin=${input.pluginVersion}`,
28
- `compiler=${input.compilerVersion}`,
29
- `native=${input.nativeIdentity ?? "none"}`,
30
- `parser=${input.parserMode}`,
31
- `producer=${input.producer}`,
32
- `astBudget=${input.astBudget ?? "default"}`,
33
- `mangleVars=${input.mangleVars === true}`,
34
- `mangleVarHoistMaxDepth=${input.mangleVarHoistMaxDepth ?? "default"}`,
35
- `globalVarAliases=${JSON.stringify(globalVarAliases)}`,
36
- `filename=${input.filename}`,
37
- `source=${inputSha256}`
38
- ].join("\n");
39
- return {
40
- key: createHash("sha256").update(keyMaterial).digest("hex").slice(0, 16),
41
- inputSha256
42
- };
43
- }
44
- function readTransformCache(cacheRoot, input, precomputedKey) {
45
- const { key, inputSha256 } = precomputedKey ?? createTransformCacheKey(input);
46
- const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
47
- const file = cacheEntryPath(cacheRoot, key);
48
- let entry;
49
- try {
50
- entry = JSON.parse(fs.readFileSync(file, "utf8"));
51
- } catch {
52
- return null;
53
- }
54
- if (entry.version !== CACHE_SCHEMA_VERSION || entry.pluginVersion !== input.pluginVersion || entry.compilerVersion !== input.compilerVersion || entry.nativeIdentity !== (input.nativeIdentity ?? null) || 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) {
55
- return null;
56
- }
57
- return deserializeResult(entry.result);
58
- }
59
- function writeTransformCache(cacheRoot, input, result, precomputedKey) {
60
- const { key, inputSha256 } = precomputedKey ?? createTransformCacheKey(input);
61
- const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
62
- const file = cacheEntryPath(cacheRoot, key);
63
- const dir = path.dirname(file);
64
- const tmp = path.join(dir, `.tmp-${process.pid}-${Date.now()}-${randomUUID()}.json`);
65
- const entry = {
66
- version: CACHE_SCHEMA_VERSION,
67
- pluginVersion: input.pluginVersion,
68
- compilerVersion: input.compilerVersion,
69
- nativeIdentity: input.nativeIdentity ?? null,
70
- parserMode: input.parserMode,
71
- producer: input.producer,
72
- astBudget: input.astBudget ?? null,
73
- mangleVars: input.mangleVars === true,
74
- mangleVarHoistMaxDepth: input.mangleVarHoistMaxDepth ?? null,
75
- globalVarAliases,
76
- filename: input.filename,
77
- inputSha256,
78
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
79
- result: serializeResult(result)
80
- };
81
- try {
82
- fs.mkdirSync(dir, { recursive: true });
83
- fs.writeFileSync(tmp, JSON.stringify(entry), "utf8");
84
- fs.renameSync(tmp, file);
85
- } catch {
86
- try {
87
- fs.rmSync(tmp, { force: true });
88
- } catch {
89
- }
90
- }
91
- }
92
- function evictOldTransformCacheEntries(cacheRoot, options) {
93
- let deleted = 0;
94
- const now = options.now ?? Date.now();
95
- const survivors = [];
96
- for (const file of listJsonFiles(cacheRoot)) {
97
- try {
98
- const entry = JSON.parse(fs.readFileSync(file, "utf8"));
99
- const timestamp = typeof entry.timestamp === "string" ? Date.parse(entry.timestamp) : 0;
100
- if (!Number.isFinite(timestamp) || now - timestamp > options.maxAgeMs) {
101
- fs.rmSync(file, { force: true });
102
- deleted++;
103
- } else {
104
- survivors.push({ file, timestamp });
105
- }
106
- } catch {
107
- fs.rmSync(file, { force: true });
108
- deleted++;
109
- }
110
- }
111
- const overflow = survivors.length - options.maxEntries ;
112
- if (overflow > 0) {
113
- survivors.sort((a, b) => a.timestamp - b.timestamp);
114
- for (const survivor of survivors.slice(0, overflow)) {
115
- fs.rmSync(survivor.file, { force: true });
116
- deleted++;
117
- }
118
- }
119
- return deleted;
120
- }
121
- function cacheEntryPath(cacheRoot, key) {
122
- return path.join(cacheRoot, key.slice(0, 2), `${key.slice(2)}.json`);
123
- }
124
- function serializeResult(result) {
125
- return {
126
- code: result.code,
127
- transformed: result.transformed,
128
- usesRuntime: result.usesRuntime,
129
- usesMerge: result.usesMerge,
130
- usesSzcn: result.usesSzcn,
131
- usesSzPart: result.usesSzPart,
132
- usesColorVar: result.usesColorVar,
133
- usesSpacingVar: result.usesSpacingVar,
134
- usesUnitVar: result.usesUnitVar,
135
- classes: [...result.classes],
136
- rawClassNames: [...result.rawClassNames],
137
- diagnostics: [...result.diagnostics],
138
- recoveryTokens: [...result.recoveryTokens],
139
- cssVariableMap: [...result.cssVariableMap ?? /* @__PURE__ */ new Map()]
140
- };
141
- }
142
- function deserializeResult(result) {
143
- return {
144
- code: result.code,
145
- transformed: result.transformed,
146
- usesRuntime: result.usesRuntime,
147
- usesMerge: result.usesMerge,
148
- usesSzcn: result.usesSzcn,
149
- usesSzPart: result.usesSzPart,
150
- usesColorVar: result.usesColorVar,
151
- usesSpacingVar: result.usesSpacingVar,
152
- usesUnitVar: result.usesUnitVar,
153
- classes: new Set(result.classes),
154
- rawClassNames: new Set(result.rawClassNames),
155
- diagnostics: [...result.diagnostics],
156
- recoveryTokens: new Map(result.recoveryTokens),
157
- cssVariableMap: new Map(result.cssVariableMap ?? [])
158
- };
159
- }
160
- function normalizeGlobalVarAliasEntries(aliases) {
161
- if (!aliases || aliases.length === 0) {
162
- return [];
163
- }
164
- const normalized = /* @__PURE__ */ new Map();
165
- for (const [original, alias] of aliases) {
166
- if (typeof original === "string" && typeof alias === "string") {
167
- normalized.set(original, alias);
168
- }
169
- }
170
- return [...normalized].sort(([left], [right]) => left.localeCompare(right));
171
- }
172
- function sameGlobalVarAliases(left, right) {
173
- if (!Array.isArray(left) || left.length !== right.length) {
174
- return false;
175
- }
176
- for (let index = 0; index < left.length; index++) {
177
- const leftEntry = left[index];
178
- const rightEntry = right[index];
179
- if (leftEntry?.[0] !== rightEntry?.[0] || leftEntry?.[1] !== rightEntry?.[1]) {
180
- return false;
181
- }
182
- }
183
- return true;
184
- }
185
- function listJsonFiles(dir) {
186
- let entries;
187
- try {
188
- entries = fs.readdirSync(dir, { withFileTypes: true });
189
- } catch {
190
- return [];
191
- }
192
- const files = [];
193
- for (const entry of entries) {
194
- const fullPath = path.join(dir, entry.name);
195
- if (entry.isDirectory()) {
196
- files.push(...listJsonFiles(fullPath));
197
- } else if (entry.isFile() && entry.name.endsWith(".json")) {
198
- files.push(fullPath);
199
- }
200
- }
201
- return files;
202
- }
203
- function evictMemoryCacheToBudget(cache, totalCodeChars, maxEntries, maxCodeChars) {
204
- let total = totalCodeChars;
205
- while (cache.size > maxEntries || total > maxCodeChars && cache.size > 1) {
206
- const oldest = cache.keys().next().value;
207
- if (oldest === void 0) {
208
- break;
209
- }
210
- const evicted = cache.get(oldest);
211
- cache.delete(oldest);
212
- total -= evicted?.code.length ?? 0;
213
- }
214
- return total;
215
- }
216
-
217
- export { readTransformCache as a, babelFallbackReason as b, createTransformCacheKey as c, evictMemoryCacheToBudget as d, evictOldTransformCacheEntries as e, normalizePathSeparators as n, resolveTransformCacheDir as r, writeTransformCache as w };