@csszyx/unplugin 0.9.0 → 0.9.2
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/index.cjs +19 -2
- package/dist/index.d.cts +91 -5
- package/dist/index.d.mts +90 -3
- package/dist/index.mjs +4 -2
- package/dist/next-prebuild.cjs +148 -0
- package/dist/next-prebuild.d.cts +66 -0
- package/dist/next-prebuild.d.mts +66 -0
- package/dist/next-prebuild.mjs +131 -0
- package/dist/next-turbo-loader.cjs +210 -0
- package/dist/next-turbo-loader.d.cts +68 -0
- package/dist/next-turbo-loader.d.mts +66 -0
- package/dist/next-turbo-loader.mjs +190 -0
- package/dist/next-watcher.cjs +237 -0
- package/dist/next-watcher.d.cts +106 -0
- package/dist/next-watcher.d.mts +106 -0
- package/dist/next-watcher.mjs +219 -0
- package/dist/shared/unplugin.8er8o6rn.mjs +276 -0
- package/dist/shared/unplugin.B_U4rZvG.cjs +281 -0
- package/dist/shared/{unplugin.BEOG6ePC.mjs → unplugin.BbtspS8t.mjs} +1436 -324
- package/dist/shared/unplugin.BceVw1eW.mjs +184 -0
- package/dist/shared/unplugin.BtQzlC2C.mjs +567 -0
- package/dist/shared/{unplugin.CL0F6RZa.cjs → unplugin.CFp386gH.cjs} +1456 -327
- package/dist/shared/unplugin.CPEWNSA0.d.cts +77 -0
- package/dist/shared/unplugin.CPEWNSA0.d.mts +77 -0
- package/dist/shared/unplugin.CScQRdTp.d.cts +15 -0
- package/dist/shared/unplugin.CScQRdTp.d.mts +15 -0
- package/dist/shared/unplugin.CdZxp0x-.d.mts +16 -0
- package/dist/shared/unplugin.DLrBgECN.d.cts +282 -0
- package/dist/shared/unplugin.DLrBgECN.d.mts +282 -0
- package/dist/shared/unplugin.DUxdYaSG.cjs +205 -0
- package/dist/shared/unplugin.s62yJbu1.cjs +591 -0
- package/dist/shared/unplugin.xeED_qwh.d.cts +16 -0
- package/dist/vite.cjs +3 -1
- package/dist/vite.d.cts +2 -1
- package/dist/vite.d.mts +2 -1
- package/dist/vite.mjs +3 -1
- package/dist/webpack.cjs +3 -1
- package/dist/webpack.d.cts +2 -1
- package/dist/webpack.d.mts +2 -1
- package/dist/webpack.mjs +3 -1
- package/package.json +41 -8
- package/dist/shared/unplugin.DUbr5w-N.d.cts +0 -49
- package/dist/shared/unplugin.DUbr5w-N.d.mts +0 -49
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { ensureRustTransformAvailable, transformSourceCode, transformRust, transformOxc, transform } from '@csszyx/compiler';
|
|
3
|
+
import { c as createTransformCacheKey, a as readTransformCache, w as writeTransformCache } from './unplugin.BceVw1eW.mjs';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
|
|
6
|
+
function readPackageVersion(relativePackageJson, fromUrl) {
|
|
7
|
+
try {
|
|
8
|
+
const packageJson = JSON.parse(
|
|
9
|
+
readFileSync(new URL(relativePackageJson, fromUrl), "utf8")
|
|
10
|
+
);
|
|
11
|
+
return typeof packageJson.version === "string" ? packageJson.version : "0.0.0";
|
|
12
|
+
} catch {
|
|
13
|
+
return "0.0.0";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function transformNextSource(input) {
|
|
18
|
+
const filename = normalizeSourceFilename(input.filename);
|
|
19
|
+
const producer = input.parserMode;
|
|
20
|
+
const cacheInput = createNextSourceTransformCacheInput(input, filename, producer);
|
|
21
|
+
if (input.parserMode === "rust") {
|
|
22
|
+
ensureRustTransformAvailable();
|
|
23
|
+
}
|
|
24
|
+
const cacheKey = input.cacheRoot ? createTransformCacheKey(cacheInput) : null;
|
|
25
|
+
if (input.cacheRoot && cacheKey) {
|
|
26
|
+
const cached = readTransformCache(input.cacheRoot, cacheInput, cacheKey);
|
|
27
|
+
if (cached) {
|
|
28
|
+
return { result: cached, cacheStatus: "hit", producer };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const result = runNextSourceTransform(input, filename);
|
|
32
|
+
assertNoUnsafePassThrough(input.source, result.result, filename);
|
|
33
|
+
if (input.cacheRoot && cacheKey && result.producer === producer) {
|
|
34
|
+
writeTransformCache(input.cacheRoot, cacheInput, result.result, cacheKey);
|
|
35
|
+
return { ...result, cacheStatus: "write" };
|
|
36
|
+
}
|
|
37
|
+
return { ...result, cacheStatus: input.cacheRoot ? "miss" : "disabled" };
|
|
38
|
+
}
|
|
39
|
+
function assertNoUnsafePassThrough(source, result, filename) {
|
|
40
|
+
if (!hasSzSyntax(source)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!result.transformed && result.code === source) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`[csszyx] Next source transform failed closed for ${filename}: source still contains csszyx sz syntax.`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function hasSzSyntax(source) {
|
|
50
|
+
const cleaned = stripJsCommentsAndStrings(source);
|
|
51
|
+
return /\bsz\s*=/.test(cleaned) || /\bsz\s*:\s*[{"']/.test(cleaned);
|
|
52
|
+
}
|
|
53
|
+
function stripJsCommentsAndStrings(source) {
|
|
54
|
+
let out = "";
|
|
55
|
+
let index = 0;
|
|
56
|
+
const length = source.length;
|
|
57
|
+
while (index < length) {
|
|
58
|
+
const char = source[index];
|
|
59
|
+
const peek = index + 1 < length ? source[index + 1] : "";
|
|
60
|
+
if (char === "/" && peek === "/") {
|
|
61
|
+
index += 2;
|
|
62
|
+
while (index < length && source[index] !== "\n") {
|
|
63
|
+
index++;
|
|
64
|
+
}
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (char === "/" && peek === "*") {
|
|
68
|
+
index += 2;
|
|
69
|
+
while (index + 1 < length && !(source[index] === "*" && source[index + 1] === "/")) {
|
|
70
|
+
index++;
|
|
71
|
+
}
|
|
72
|
+
index = Math.min(length, index + 2);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (char === "/" && isRegexLiteralStart(out)) {
|
|
76
|
+
index++;
|
|
77
|
+
let inCharClass = false;
|
|
78
|
+
while (index < length) {
|
|
79
|
+
const current = source[index];
|
|
80
|
+
if (current === "\\" && index + 1 < length) {
|
|
81
|
+
index += 2;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (current === "[") {
|
|
85
|
+
inCharClass = true;
|
|
86
|
+
index++;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (current === "]") {
|
|
90
|
+
inCharClass = false;
|
|
91
|
+
index++;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (current === "/" && !inCharClass) {
|
|
95
|
+
index++;
|
|
96
|
+
while (/[a-z]/i.test(source[index] ?? "")) {
|
|
97
|
+
index++;
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
index++;
|
|
102
|
+
}
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (char === '"' || char === "'" || char === "`") {
|
|
106
|
+
const quote = char;
|
|
107
|
+
index++;
|
|
108
|
+
while (index < length && source[index] !== quote) {
|
|
109
|
+
if (source[index] === "\\" && index + 1 < length) {
|
|
110
|
+
index += 2;
|
|
111
|
+
} else {
|
|
112
|
+
index++;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
index++;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
out += char;
|
|
119
|
+
index++;
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
function isRegexLiteralStart(emitted) {
|
|
124
|
+
const trimmed = emitted.trimEnd();
|
|
125
|
+
const previous = trimmed.length > 0 ? trimmed.charAt(trimmed.length - 1) : void 0;
|
|
126
|
+
return previous === void 0 || /[({[=:;,!&|?+\-*%^~<>]/.test(previous);
|
|
127
|
+
}
|
|
128
|
+
function runNextSourceTransform(input, filename) {
|
|
129
|
+
const compilerOptions = input.compilerOptions;
|
|
130
|
+
if (input.parserMode === "babel") {
|
|
131
|
+
return {
|
|
132
|
+
result: transformSourceCode(input.source, filename, compilerOptions),
|
|
133
|
+
producer: "babel"
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (input.parserMode === "rust") {
|
|
137
|
+
return {
|
|
138
|
+
result: transformRust(input.source, filename, compilerOptions),
|
|
139
|
+
producer: "rust"
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
return {
|
|
144
|
+
result: transformOxc(input.source, filename, compilerOptions),
|
|
145
|
+
producer: "oxc"
|
|
146
|
+
};
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (input.allowBabelFallback === false) {
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
const result = transformSourceCode(input.source, filename, compilerOptions);
|
|
152
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
153
|
+
result.diagnostics.push(
|
|
154
|
+
`[csszyx] oxc parser fell back to Babel for ${filename}: ${reason}`
|
|
155
|
+
);
|
|
156
|
+
return { result, producer: "babel-fallback" };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function createNextSourceTransformCacheInput(input, filename, producer) {
|
|
160
|
+
return {
|
|
161
|
+
pluginVersion: input.pluginVersion,
|
|
162
|
+
compilerVersion: input.compilerVersion,
|
|
163
|
+
parserMode: input.parserMode,
|
|
164
|
+
producer,
|
|
165
|
+
astBudget: input.astBudget ?? input.compilerOptions?.astBudget,
|
|
166
|
+
mangleVars: input.compilerOptions?.mangleVars,
|
|
167
|
+
mangleVarHoistMaxDepth: input.compilerOptions?.mangleVarHoistMaxDepth,
|
|
168
|
+
globalVarAliases: normalizeGlobalVarAliasesForCache(
|
|
169
|
+
input.compilerOptions?.globalVarAliases
|
|
170
|
+
),
|
|
171
|
+
filename,
|
|
172
|
+
source: input.source
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function normalizeSourceFilename(filename) {
|
|
176
|
+
return filename.replace(/\\/g, "/");
|
|
177
|
+
}
|
|
178
|
+
function normalizeGlobalVarAliasesForCache(aliases) {
|
|
179
|
+
if (!aliases) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
const entries = aliases instanceof Map ? aliases.entries() : Array.isArray(aliases) ? aliases : Object.entries(aliases);
|
|
183
|
+
const normalized = /* @__PURE__ */ new Map();
|
|
184
|
+
for (const [original, alias] of entries) {
|
|
185
|
+
if (original.startsWith("--") && alias.startsWith("--")) {
|
|
186
|
+
normalized.set(original, alias);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return [...normalized].sort(([left], [right]) => left.localeCompare(right));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function collectNextTransformMetadata(result, source, sourcePath) {
|
|
193
|
+
const classes = new Set(result.classes);
|
|
194
|
+
collectRuntimeStaticClasses(result, classes);
|
|
195
|
+
return {
|
|
196
|
+
sourcePath,
|
|
197
|
+
sourceHash: createHash("sha256").update(source).digest("hex"),
|
|
198
|
+
classes: [...classes].sort(),
|
|
199
|
+
rawClassNames: [...result.rawClassNames].sort(),
|
|
200
|
+
recoveryTokenCount: result.recoveryTokens.size,
|
|
201
|
+
cssVariableCount: result.cssVariableMap.size
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function createNextSafelistShardFromMetadata(metadata, cacheKey) {
|
|
205
|
+
return {
|
|
206
|
+
cacheKey,
|
|
207
|
+
sourcePath: metadata.sourcePath,
|
|
208
|
+
sourceHash: metadata.sourceHash,
|
|
209
|
+
classes: metadata.classes
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function collectRuntimeStaticClasses(result, discoveredClasses) {
|
|
213
|
+
if (!result.usesRuntime) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const szCallRe = /_sz\(\s*\{/g;
|
|
217
|
+
for (const szMatch of result.code.matchAll(szCallRe)) {
|
|
218
|
+
let depth = 1;
|
|
219
|
+
let index = (szMatch.index ?? 0) + szMatch[0].length;
|
|
220
|
+
while (index < result.code.length && depth > 0) {
|
|
221
|
+
if (result.code[index] === "{") {
|
|
222
|
+
depth++;
|
|
223
|
+
} else if (result.code[index] === "}") {
|
|
224
|
+
depth--;
|
|
225
|
+
}
|
|
226
|
+
index++;
|
|
227
|
+
}
|
|
228
|
+
const objectSource = result.code.slice((szMatch.index ?? 0) + szMatch[0].length, index - 1);
|
|
229
|
+
collectRuntimeStringClasses(objectSource, discoveredClasses);
|
|
230
|
+
collectRuntimeNumberClasses(objectSource, discoveredClasses);
|
|
231
|
+
collectRuntimeBooleanClasses(objectSource, discoveredClasses);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function collectRuntimeStringClasses(objectSource, discoveredClasses) {
|
|
235
|
+
const stringKeyValue = /(\w+)\s*:\s*(?:"([^"]*)"|'([^']*)')/g;
|
|
236
|
+
for (const match of objectSource.matchAll(stringKeyValue)) {
|
|
237
|
+
try {
|
|
238
|
+
collectTransformClasses(
|
|
239
|
+
transform({ [match[1]]: match[2] ?? match[3] }),
|
|
240
|
+
discoveredClasses
|
|
241
|
+
);
|
|
242
|
+
} catch {
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function collectRuntimeNumberClasses(objectSource, discoveredClasses) {
|
|
247
|
+
const numberKeyValue = /(\w+)\s*:\s*(-?\d+(?:\.\d+)?)\s*(?=[,}\n])/g;
|
|
248
|
+
for (const match of objectSource.matchAll(numberKeyValue)) {
|
|
249
|
+
try {
|
|
250
|
+
collectTransformClasses(
|
|
251
|
+
transform({ [match[1]]: Number.parseFloat(match[2]) }),
|
|
252
|
+
discoveredClasses
|
|
253
|
+
);
|
|
254
|
+
} catch {
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function collectRuntimeBooleanClasses(objectSource, discoveredClasses) {
|
|
259
|
+
const booleanKeyValue = /(\w+)\s*:\s*(true|false)\s*(?=[,}\n])/g;
|
|
260
|
+
for (const match of objectSource.matchAll(booleanKeyValue)) {
|
|
261
|
+
try {
|
|
262
|
+
collectTransformClasses(
|
|
263
|
+
transform({ [match[1]]: match[2] === "true" }),
|
|
264
|
+
discoveredClasses
|
|
265
|
+
);
|
|
266
|
+
} catch {
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function collectTransformClasses(result, discoveredClasses) {
|
|
271
|
+
for (const className of result.className.split(/\s+/).filter(Boolean)) {
|
|
272
|
+
discoveredClasses.add(className);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export { createNextSafelistShardFromMetadata as a, collectNextTransformMetadata as c, readPackageVersion as r, transformNextSource as t };
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const compiler = require('@csszyx/compiler');
|
|
5
|
+
const transformCache = require('./unplugin.DUxdYaSG.cjs');
|
|
6
|
+
const node_crypto = require('node:crypto');
|
|
7
|
+
|
|
8
|
+
function readPackageVersion(relativePackageJson, fromUrl) {
|
|
9
|
+
try {
|
|
10
|
+
const packageJson = JSON.parse(
|
|
11
|
+
fs.readFileSync(new URL(relativePackageJson, fromUrl), "utf8")
|
|
12
|
+
);
|
|
13
|
+
return typeof packageJson.version === "string" ? packageJson.version : "0.0.0";
|
|
14
|
+
} catch {
|
|
15
|
+
return "0.0.0";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function transformNextSource(input) {
|
|
20
|
+
const filename = normalizeSourceFilename(input.filename);
|
|
21
|
+
const producer = input.parserMode;
|
|
22
|
+
const cacheInput = createNextSourceTransformCacheInput(input, filename, producer);
|
|
23
|
+
if (input.parserMode === "rust") {
|
|
24
|
+
compiler.ensureRustTransformAvailable();
|
|
25
|
+
}
|
|
26
|
+
const cacheKey = input.cacheRoot ? transformCache.createTransformCacheKey(cacheInput) : null;
|
|
27
|
+
if (input.cacheRoot && cacheKey) {
|
|
28
|
+
const cached = transformCache.readTransformCache(input.cacheRoot, cacheInput, cacheKey);
|
|
29
|
+
if (cached) {
|
|
30
|
+
return { result: cached, cacheStatus: "hit", producer };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const result = runNextSourceTransform(input, filename);
|
|
34
|
+
assertNoUnsafePassThrough(input.source, result.result, filename);
|
|
35
|
+
if (input.cacheRoot && cacheKey && result.producer === producer) {
|
|
36
|
+
transformCache.writeTransformCache(input.cacheRoot, cacheInput, result.result, cacheKey);
|
|
37
|
+
return { ...result, cacheStatus: "write" };
|
|
38
|
+
}
|
|
39
|
+
return { ...result, cacheStatus: input.cacheRoot ? "miss" : "disabled" };
|
|
40
|
+
}
|
|
41
|
+
function assertNoUnsafePassThrough(source, result, filename) {
|
|
42
|
+
if (!hasSzSyntax(source)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!result.transformed && result.code === source) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`[csszyx] Next source transform failed closed for ${filename}: source still contains csszyx sz syntax.`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function hasSzSyntax(source) {
|
|
52
|
+
const cleaned = stripJsCommentsAndStrings(source);
|
|
53
|
+
return /\bsz\s*=/.test(cleaned) || /\bsz\s*:\s*[{"']/.test(cleaned);
|
|
54
|
+
}
|
|
55
|
+
function stripJsCommentsAndStrings(source) {
|
|
56
|
+
let out = "";
|
|
57
|
+
let index = 0;
|
|
58
|
+
const length = source.length;
|
|
59
|
+
while (index < length) {
|
|
60
|
+
const char = source[index];
|
|
61
|
+
const peek = index + 1 < length ? source[index + 1] : "";
|
|
62
|
+
if (char === "/" && peek === "/") {
|
|
63
|
+
index += 2;
|
|
64
|
+
while (index < length && source[index] !== "\n") {
|
|
65
|
+
index++;
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (char === "/" && peek === "*") {
|
|
70
|
+
index += 2;
|
|
71
|
+
while (index + 1 < length && !(source[index] === "*" && source[index + 1] === "/")) {
|
|
72
|
+
index++;
|
|
73
|
+
}
|
|
74
|
+
index = Math.min(length, index + 2);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (char === "/" && isRegexLiteralStart(out)) {
|
|
78
|
+
index++;
|
|
79
|
+
let inCharClass = false;
|
|
80
|
+
while (index < length) {
|
|
81
|
+
const current = source[index];
|
|
82
|
+
if (current === "\\" && index + 1 < length) {
|
|
83
|
+
index += 2;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (current === "[") {
|
|
87
|
+
inCharClass = true;
|
|
88
|
+
index++;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (current === "]") {
|
|
92
|
+
inCharClass = false;
|
|
93
|
+
index++;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (current === "/" && !inCharClass) {
|
|
97
|
+
index++;
|
|
98
|
+
while (/[a-z]/i.test(source[index] ?? "")) {
|
|
99
|
+
index++;
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
index++;
|
|
104
|
+
}
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (char === '"' || char === "'" || char === "`") {
|
|
108
|
+
const quote = char;
|
|
109
|
+
index++;
|
|
110
|
+
while (index < length && source[index] !== quote) {
|
|
111
|
+
if (source[index] === "\\" && index + 1 < length) {
|
|
112
|
+
index += 2;
|
|
113
|
+
} else {
|
|
114
|
+
index++;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
index++;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
out += char;
|
|
121
|
+
index++;
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
function isRegexLiteralStart(emitted) {
|
|
126
|
+
const trimmed = emitted.trimEnd();
|
|
127
|
+
const previous = trimmed.length > 0 ? trimmed.charAt(trimmed.length - 1) : void 0;
|
|
128
|
+
return previous === void 0 || /[({[=:;,!&|?+\-*%^~<>]/.test(previous);
|
|
129
|
+
}
|
|
130
|
+
function runNextSourceTransform(input, filename) {
|
|
131
|
+
const compilerOptions = input.compilerOptions;
|
|
132
|
+
if (input.parserMode === "babel") {
|
|
133
|
+
return {
|
|
134
|
+
result: compiler.transformSourceCode(input.source, filename, compilerOptions),
|
|
135
|
+
producer: "babel"
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (input.parserMode === "rust") {
|
|
139
|
+
return {
|
|
140
|
+
result: compiler.transformRust(input.source, filename, compilerOptions),
|
|
141
|
+
producer: "rust"
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
return {
|
|
146
|
+
result: compiler.transformOxc(input.source, filename, compilerOptions),
|
|
147
|
+
producer: "oxc"
|
|
148
|
+
};
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (input.allowBabelFallback === false) {
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
const result = compiler.transformSourceCode(input.source, filename, compilerOptions);
|
|
154
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
155
|
+
result.diagnostics.push(
|
|
156
|
+
`[csszyx] oxc parser fell back to Babel for ${filename}: ${reason}`
|
|
157
|
+
);
|
|
158
|
+
return { result, producer: "babel-fallback" };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function createNextSourceTransformCacheInput(input, filename, producer) {
|
|
162
|
+
return {
|
|
163
|
+
pluginVersion: input.pluginVersion,
|
|
164
|
+
compilerVersion: input.compilerVersion,
|
|
165
|
+
parserMode: input.parserMode,
|
|
166
|
+
producer,
|
|
167
|
+
astBudget: input.astBudget ?? input.compilerOptions?.astBudget,
|
|
168
|
+
mangleVars: input.compilerOptions?.mangleVars,
|
|
169
|
+
mangleVarHoistMaxDepth: input.compilerOptions?.mangleVarHoistMaxDepth,
|
|
170
|
+
globalVarAliases: normalizeGlobalVarAliasesForCache(
|
|
171
|
+
input.compilerOptions?.globalVarAliases
|
|
172
|
+
),
|
|
173
|
+
filename,
|
|
174
|
+
source: input.source
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function normalizeSourceFilename(filename) {
|
|
178
|
+
return filename.replace(/\\/g, "/");
|
|
179
|
+
}
|
|
180
|
+
function normalizeGlobalVarAliasesForCache(aliases) {
|
|
181
|
+
if (!aliases) {
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
const entries = aliases instanceof Map ? aliases.entries() : Array.isArray(aliases) ? aliases : Object.entries(aliases);
|
|
185
|
+
const normalized = /* @__PURE__ */ new Map();
|
|
186
|
+
for (const [original, alias] of entries) {
|
|
187
|
+
if (original.startsWith("--") && alias.startsWith("--")) {
|
|
188
|
+
normalized.set(original, alias);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return [...normalized].sort(([left], [right]) => left.localeCompare(right));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function collectNextTransformMetadata(result, source, sourcePath) {
|
|
195
|
+
const classes = new Set(result.classes);
|
|
196
|
+
collectRuntimeStaticClasses(result, classes);
|
|
197
|
+
return {
|
|
198
|
+
sourcePath,
|
|
199
|
+
sourceHash: node_crypto.createHash("sha256").update(source).digest("hex"),
|
|
200
|
+
classes: [...classes].sort(),
|
|
201
|
+
rawClassNames: [...result.rawClassNames].sort(),
|
|
202
|
+
recoveryTokenCount: result.recoveryTokens.size,
|
|
203
|
+
cssVariableCount: result.cssVariableMap.size
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function createNextSafelistShardFromMetadata(metadata, cacheKey) {
|
|
207
|
+
return {
|
|
208
|
+
cacheKey,
|
|
209
|
+
sourcePath: metadata.sourcePath,
|
|
210
|
+
sourceHash: metadata.sourceHash,
|
|
211
|
+
classes: metadata.classes
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function collectRuntimeStaticClasses(result, discoveredClasses) {
|
|
215
|
+
if (!result.usesRuntime) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const szCallRe = /_sz\(\s*\{/g;
|
|
219
|
+
for (const szMatch of result.code.matchAll(szCallRe)) {
|
|
220
|
+
let depth = 1;
|
|
221
|
+
let index = (szMatch.index ?? 0) + szMatch[0].length;
|
|
222
|
+
while (index < result.code.length && depth > 0) {
|
|
223
|
+
if (result.code[index] === "{") {
|
|
224
|
+
depth++;
|
|
225
|
+
} else if (result.code[index] === "}") {
|
|
226
|
+
depth--;
|
|
227
|
+
}
|
|
228
|
+
index++;
|
|
229
|
+
}
|
|
230
|
+
const objectSource = result.code.slice((szMatch.index ?? 0) + szMatch[0].length, index - 1);
|
|
231
|
+
collectRuntimeStringClasses(objectSource, discoveredClasses);
|
|
232
|
+
collectRuntimeNumberClasses(objectSource, discoveredClasses);
|
|
233
|
+
collectRuntimeBooleanClasses(objectSource, discoveredClasses);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function collectRuntimeStringClasses(objectSource, discoveredClasses) {
|
|
237
|
+
const stringKeyValue = /(\w+)\s*:\s*(?:"([^"]*)"|'([^']*)')/g;
|
|
238
|
+
for (const match of objectSource.matchAll(stringKeyValue)) {
|
|
239
|
+
try {
|
|
240
|
+
collectTransformClasses(
|
|
241
|
+
compiler.transform({ [match[1]]: match[2] ?? match[3] }),
|
|
242
|
+
discoveredClasses
|
|
243
|
+
);
|
|
244
|
+
} catch {
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function collectRuntimeNumberClasses(objectSource, discoveredClasses) {
|
|
249
|
+
const numberKeyValue = /(\w+)\s*:\s*(-?\d+(?:\.\d+)?)\s*(?=[,}\n])/g;
|
|
250
|
+
for (const match of objectSource.matchAll(numberKeyValue)) {
|
|
251
|
+
try {
|
|
252
|
+
collectTransformClasses(
|
|
253
|
+
compiler.transform({ [match[1]]: Number.parseFloat(match[2]) }),
|
|
254
|
+
discoveredClasses
|
|
255
|
+
);
|
|
256
|
+
} catch {
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function collectRuntimeBooleanClasses(objectSource, discoveredClasses) {
|
|
261
|
+
const booleanKeyValue = /(\w+)\s*:\s*(true|false)\s*(?=[,}\n])/g;
|
|
262
|
+
for (const match of objectSource.matchAll(booleanKeyValue)) {
|
|
263
|
+
try {
|
|
264
|
+
collectTransformClasses(
|
|
265
|
+
compiler.transform({ [match[1]]: match[2] === "true" }),
|
|
266
|
+
discoveredClasses
|
|
267
|
+
);
|
|
268
|
+
} catch {
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function collectTransformClasses(result, discoveredClasses) {
|
|
273
|
+
for (const className of result.className.split(/\s+/).filter(Boolean)) {
|
|
274
|
+
discoveredClasses.add(className);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
exports.collectNextTransformMetadata = collectNextTransformMetadata;
|
|
279
|
+
exports.createNextSafelistShardFromMetadata = createNextSafelistShardFromMetadata;
|
|
280
|
+
exports.readPackageVersion = readPackageVersion;
|
|
281
|
+
exports.transformNextSource = transformNextSource;
|