@csszyx/unplugin 0.12.0 → 0.14.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 (46) hide show
  1. package/README.md +8 -10
  2. package/dist/index.cjs +14 -7
  3. package/dist/index.d.cts +4 -4
  4. package/dist/index.d.mts +4 -4
  5. package/dist/index.mjs +3 -3
  6. package/dist/next-config.cjs +3 -0
  7. package/dist/next-config.d.cts +13 -2
  8. package/dist/next-config.d.mts +13 -2
  9. package/dist/next-config.mjs +3 -0
  10. package/dist/next-prebuild.cjs +13 -7
  11. package/dist/next-prebuild.d.cts +8 -2
  12. package/dist/next-prebuild.d.mts +8 -2
  13. package/dist/next-prebuild.mjs +13 -7
  14. package/dist/next-turbo-loader.cjs +31 -15
  15. package/dist/next-turbo-loader.d.cts +11 -2
  16. package/dist/next-turbo-loader.d.mts +11 -2
  17. package/dist/next-turbo-loader.mjs +30 -14
  18. package/dist/next-watcher.cjs +1 -1
  19. package/dist/next-watcher.mjs +1 -1
  20. package/dist/shared/{unplugin.CXV7fOa2.d.cts → unplugin.B32Exn-K.d.cts} +2 -2
  21. package/dist/shared/{unplugin.CXV7fOa2.d.mts → unplugin.B32Exn-K.d.mts} +2 -2
  22. package/dist/shared/{unplugin.Bb5TeU9B.cjs → unplugin.BJiWWF6w.cjs} +93 -23
  23. package/dist/shared/unplugin.BKGCkMgM.cjs +523 -0
  24. package/dist/shared/{unplugin.DMcbmP01.mjs → unplugin.BU0O4IkX.mjs} +4 -1
  25. package/dist/shared/unplugin.BcsvXjIV.mjs +579 -0
  26. package/dist/shared/{unplugin.CtnKJhAi.d.cts → unplugin.BsjD3mtb.d.cts} +165 -33
  27. package/dist/shared/{unplugin.CtnKJhAi.d.mts → unplugin.BsjD3mtb.d.mts} +165 -33
  28. package/dist/shared/{unplugin.DblMogcN.cjs → unplugin.Cji6O5jv.cjs} +4 -1
  29. package/dist/shared/unplugin.CkNQjA4G.cjs +613 -0
  30. package/dist/shared/unplugin.DKcwO8O4.mjs +490 -0
  31. package/dist/shared/{unplugin.DXgxFHzO.mjs → unplugin.DjRylBC_.mjs} +77 -25
  32. package/dist/shared/{unplugin.BK3XVHe8.cjs → unplugin.ZMa9YE1H.cjs} +621 -615
  33. package/dist/shared/{unplugin.B9vpjOhD.mjs → unplugin.gR_h2DVG.mjs} +585 -582
  34. package/dist/vite.cjs +3 -3
  35. package/dist/vite.d.cts +2 -2
  36. package/dist/vite.d.mts +1 -1
  37. package/dist/vite.mjs +3 -3
  38. package/dist/webpack.cjs +3 -3
  39. package/dist/webpack.d.cts +2 -2
  40. package/dist/webpack.d.mts +1 -1
  41. package/dist/webpack.mjs +3 -3
  42. package/package.json +9 -9
  43. package/dist/shared/unplugin.C2lHQFii.cjs +0 -114
  44. package/dist/shared/unplugin.CBMJufQ8.mjs +0 -108
  45. package/dist/shared/unplugin.CDqY7kmk.mjs +0 -224
  46. package/dist/shared/unplugin.DbZ7tCfN.cjs +0 -248
@@ -0,0 +1,490 @@
1
+ import * as path from 'node:path';
2
+ import { extractCrossModuleRegistryEntries } from '@csszyx/compiler';
3
+ import * as fs from 'node:fs';
4
+ import { existsSync, statSync } from 'node:fs';
5
+ import { createHash, randomUUID } from 'node:crypto';
6
+
7
+ const WINDOWS_PATH_SEPARATOR = String.fromCodePoint(92);
8
+ function normalizePathSeparators(value) {
9
+ return value.split(WINDOWS_PATH_SEPARATOR).join("/");
10
+ }
11
+
12
+ const TSCONFIG_CANDIDATES = ["tsconfig.json", "jsconfig.json", "tsconfig.app.json"];
13
+ const MAX_EXTENDS_DEPTH = 8;
14
+ function collectSpecifierAliases(rootDir, resolveAlias) {
15
+ return [...aliasesFromResolveConfig(rootDir, resolveAlias), ...aliasesFromTsconfig(rootDir)];
16
+ }
17
+ function aliasesFromResolveConfig(rootDir, raw) {
18
+ const aliases = [];
19
+ if (Array.isArray(raw)) {
20
+ for (const entry of raw) {
21
+ const find = entry.find;
22
+ const replacement = entry.replacement;
23
+ if (typeof find !== "string" || typeof replacement !== "string") continue;
24
+ aliases.push(makeAlias(rootDir, find, replacement));
25
+ }
26
+ return aliases;
27
+ }
28
+ if (raw === null || typeof raw !== "object") return aliases;
29
+ for (const [find, target] of Object.entries(raw)) {
30
+ for (const value of Array.isArray(target) ? target : [target]) {
31
+ if (typeof value !== "string") continue;
32
+ aliases.push(makeAlias(rootDir, find, value));
33
+ }
34
+ }
35
+ return aliases;
36
+ }
37
+ function makeAlias(rootDir, find, replacement) {
38
+ const exact = find.endsWith("$");
39
+ return {
40
+ find: exact ? find.slice(0, -1) : find,
41
+ replacement: absolute(rootDir, replacement),
42
+ exact
43
+ };
44
+ }
45
+ function aliasesFromTsconfig(rootDir) {
46
+ for (const candidate of TSCONFIG_CANDIDATES) {
47
+ const loaded = loadPathsConfig(path.join(rootDir, candidate), 0);
48
+ if (loaded === void 0) continue;
49
+ const aliases = pathsToAliases(loaded.base, loaded.paths);
50
+ if (aliases.length > 0) return aliases;
51
+ }
52
+ return [];
53
+ }
54
+ function loadPathsConfig(configPath, depth) {
55
+ if (depth > MAX_EXTENDS_DEPTH) return void 0;
56
+ let parsed;
57
+ try {
58
+ parsed = parseJsonc(fs.readFileSync(configPath, "utf-8"));
59
+ } catch {
60
+ return void 0;
61
+ }
62
+ const directory = path.dirname(configPath);
63
+ const compilerOptions = asRecord(parsed.compilerOptions);
64
+ const paths = asRecord(compilerOptions?.paths);
65
+ if (paths !== void 0) {
66
+ const baseUrl = compilerOptions?.baseUrl;
67
+ return {
68
+ base: typeof baseUrl === "string" ? absolute(directory, baseUrl) : absolute(directory, "."),
69
+ paths
70
+ };
71
+ }
72
+ const extended = parsed.extends;
73
+ if (typeof extended !== "string" || !extended.startsWith(".")) return void 0;
74
+ const resolved = path.resolve(directory, extended);
75
+ return loadPathsConfig(resolved, depth + 1) ?? loadPathsConfig(`${resolved}.json`, depth + 1);
76
+ }
77
+ function pathsToAliases(base, paths) {
78
+ return Object.entries(paths).flatMap(
79
+ ([pattern, targets]) => patternToAliases(base, pattern, targets)
80
+ );
81
+ }
82
+ function patternToAliases(base, pattern, targets) {
83
+ const wildcard = pattern.indexOf("*");
84
+ if (wildcard !== -1 && wildcard !== pattern.length - 1) return [];
85
+ const exact = wildcard === -1;
86
+ const find = exact ? pattern : pattern.slice(0, -1);
87
+ const declared = Array.isArray(targets) ? targets : [targets];
88
+ return declared.filter((target) => typeof target === "string").map((target) => ({
89
+ find,
90
+ replacement: absolute(base, target.endsWith("*") ? target.slice(0, -1) : target),
91
+ exact
92
+ }));
93
+ }
94
+ function aliasedSpecifierBases(specifier, aliases) {
95
+ const bases = [];
96
+ for (const alias of aliases) {
97
+ if (alias.exact) {
98
+ if (specifier === alias.find) bases.push(alias.replacement);
99
+ continue;
100
+ }
101
+ if (!specifier.startsWith(alias.find)) continue;
102
+ bases.push(normalizePathSeparators(alias.replacement + specifier.slice(alias.find.length)));
103
+ }
104
+ return bases;
105
+ }
106
+ function absolute(directory, target) {
107
+ const resolved = normalizePathSeparators(path.resolve(directory, target));
108
+ const declaredTrailingSlash = target.endsWith("/") || target.endsWith("\\");
109
+ return declaredTrailingSlash && !resolved.endsWith("/") ? `${resolved}/` : resolved;
110
+ }
111
+ function asRecord(value) {
112
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
113
+ }
114
+ function parseJsonc(text) {
115
+ const parsed = JSON.parse(stripComments(text).replace(/,(\s*[}\]])/g, "$1"));
116
+ return asRecord(parsed) ?? {};
117
+ }
118
+ function stripComments(text) {
119
+ const out = [];
120
+ let index = 0;
121
+ while (index < text.length) {
122
+ const run = consumeString(text, index) ?? consumeComment(text, index);
123
+ if (run === void 0) {
124
+ out.push(text[index]);
125
+ index += 1;
126
+ continue;
127
+ }
128
+ out.push(run.keep);
129
+ index = run.next;
130
+ }
131
+ return out.join("");
132
+ }
133
+ function consumeString(text, start) {
134
+ if (text[start] !== '"') return void 0;
135
+ let index = start + 1;
136
+ while (index < text.length) {
137
+ const char = text[index];
138
+ if (char === "\\") {
139
+ index += 2;
140
+ continue;
141
+ }
142
+ index += 1;
143
+ if (char === '"') break;
144
+ }
145
+ return { keep: text.slice(start, index), next: index };
146
+ }
147
+ function consumeComment(text, start) {
148
+ if (text[start] !== "/") return void 0;
149
+ if (text[start + 1] === "/") {
150
+ const end = text.indexOf("\n", start);
151
+ return { keep: "", next: end === -1 ? text.length : end };
152
+ }
153
+ if (text[start + 1] === "*") {
154
+ const end = text.indexOf("*/", start + 2);
155
+ return { keep: "", next: end === -1 ? text.length : end + 2 };
156
+ }
157
+ return void 0;
158
+ }
159
+
160
+ function mayExportSzvFactories(content) {
161
+ return content.includes("szv(") && content.includes("export");
162
+ }
163
+ function recordSzvRegistryFile(registry, filePath, content) {
164
+ const entries = mayExportSzvFactories(content) ? extractCrossModuleRegistryEntries(content, filePath) : [];
165
+ replaceEntriesOfKind(registry, filePath, "szv-config", entries);
166
+ }
167
+ function recordSzObjectRegistryFile(registry, filePath, content) {
168
+ replaceEntriesOfKind(
169
+ registry,
170
+ filePath,
171
+ "sz-object",
172
+ extractCrossModuleRegistryEntries(content, filePath)
173
+ );
174
+ }
175
+ function replaceEntriesOfKind(registry, filePath, kind, entries) {
176
+ const key = normalizePathSeparators(filePath);
177
+ const byName = emptyNameIndex();
178
+ for (const [name, recorded] of Object.entries(registry.get(key) ?? {})) {
179
+ if (recorded.kind !== kind) byName[name] = recorded;
180
+ }
181
+ for (const entry of entries) {
182
+ if (entry.kind === kind) byName[entry.exportName] = { kind, value: entry.value };
183
+ }
184
+ if (Object.keys(byName).length === 0) registry.delete(key);
185
+ else registry.set(key, byName);
186
+ }
187
+ function emptyNameIndex() {
188
+ return /* @__PURE__ */ Object.create(null);
189
+ }
190
+ const SPECIFIER_PROBES = ["", ".ts", ".tsx", ".js", ".jsx", "/index.ts", "/index.tsx"];
191
+ const EMITTED_EXTENSION_SOURCES = [
192
+ [".js", [".ts", ".tsx"]],
193
+ [".jsx", [".tsx"]],
194
+ [".mjs", [".mts"]],
195
+ [".cjs", [".cts"]]
196
+ ];
197
+ function resolveCrossModuleStaticsFor(registry, filename, source, aliases = []) {
198
+ if (registry.size === 0 || !source.includes("from")) return {};
199
+ const directory = path.dirname(filename);
200
+ const resolved = {};
201
+ const seen = /* @__PURE__ */ new Set();
202
+ for (const specifier of importedSpecifiersIn(source)) {
203
+ if (seen.has(specifier)) continue;
204
+ seen.add(specifier);
205
+ const entries = firstRegistryHit(registry, specifier, directory, aliases);
206
+ if (entries !== void 0) fileUnderSpecifier(resolved, specifier, entries);
207
+ }
208
+ return resolved;
209
+ }
210
+ function firstRegistryHit(registry, specifier, directory, aliases) {
211
+ for (const base of specifierBases(specifier, directory, aliases)) {
212
+ const entries = lookupRegistryKey(registry, base);
213
+ if (entries !== void 0) return entries;
214
+ }
215
+ return void 0;
216
+ }
217
+ function recordResolvedEntry(resolved, kind, specifier, name, value) {
218
+ if (specifier === "__proto__" || name === "__proto__") return;
219
+ const channel = kind === "szv-config" ? "szvConfigs" : "szObjects";
220
+ let bySpecifier = resolved[channel];
221
+ if (bySpecifier === void 0) {
222
+ bySpecifier = emptyNameIndex();
223
+ resolved[channel] = bySpecifier;
224
+ }
225
+ let byName = bySpecifier[specifier];
226
+ if (byName === void 0) {
227
+ byName = emptyNameIndex();
228
+ bySpecifier[specifier] = byName;
229
+ }
230
+ byName[name] = value;
231
+ }
232
+ function fileUnderSpecifier(resolved, specifier, entries) {
233
+ for (const [name, recorded] of Object.entries(entries)) {
234
+ recordResolvedEntry(resolved, recorded.kind, specifier, name, recorded.value);
235
+ }
236
+ }
237
+ function importedSpecifiersIn(source) {
238
+ if (!source.includes("from")) return [];
239
+ return [...source.matchAll(/from\s*['"]([^'"]*)['"]/g)].map((match) => match[1]);
240
+ }
241
+ function specifierBases(specifier, directory, aliases) {
242
+ if (specifier.startsWith(".")) {
243
+ return [normalizePathSeparators(path.resolve(directory, specifier))];
244
+ }
245
+ return aliasedSpecifierBases(specifier, aliases);
246
+ }
247
+ function resolveProviderPath(seenPaths, base) {
248
+ return resolveProviderPathWith(base, (candidate) => seenPaths.has(candidate));
249
+ }
250
+ function resolveProviderPathWith(base, exists) {
251
+ return probeSpecifier(base, (candidate) => exists(candidate) ? candidate : void 0);
252
+ }
253
+ function probeSpecifier(base, lookup) {
254
+ for (const probe of SPECIFIER_PROBES) {
255
+ const found = lookup(`${base}${probe}`);
256
+ if (found !== void 0) return found;
257
+ }
258
+ for (const [emitted, sources] of EMITTED_EXTENSION_SOURCES) {
259
+ if (!base.endsWith(emitted)) continue;
260
+ const stem = base.slice(0, -emitted.length);
261
+ for (const extension of sources) {
262
+ const found = lookup(`${stem}${extension}`);
263
+ if (found !== void 0) return found;
264
+ }
265
+ break;
266
+ }
267
+ return void 0;
268
+ }
269
+ function lookupRegistryKey(registry, base) {
270
+ return probeSpecifier(base, (candidate) => registry.get(candidate));
271
+ }
272
+
273
+ function isReadableProviderFile(candidate) {
274
+ try {
275
+ return existsSync(candidate) && statSync(candidate).isFile();
276
+ } catch {
277
+ return false;
278
+ }
279
+ }
280
+
281
+ const CACHE_SCHEMA_VERSION = 17;
282
+ function resolveTransformCacheDir(rootDir, cacheDir) {
283
+ return path.resolve(rootDir, cacheDir ?? ".csszyx/cache", "transform");
284
+ }
285
+ function createTransformCacheKey(input) {
286
+ const inputSha256 = createHash("sha256").update(input.source).digest("hex");
287
+ const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
288
+ const keyMaterial = [
289
+ `schema=${CACHE_SCHEMA_VERSION}`,
290
+ `plugin=${input.pluginVersion}`,
291
+ `compiler=${input.compilerVersion}`,
292
+ `native=${input.nativeIdentity ?? "none"}`,
293
+ `parser=${input.parserMode}`,
294
+ `producer=${input.producer}`,
295
+ `astBudget=${input.astBudget ?? "default"}`,
296
+ `mangleVars=${input.mangleVars === true}`,
297
+ `mangleVarHoistMaxDepth=${input.mangleVarHoistMaxDepth ?? "default"}`,
298
+ `globalVarAliases=${JSON.stringify(globalVarAliases)}`,
299
+ `crossModuleStatics=${input.crossModuleStatics ?? "none"}`,
300
+ `crossModuleSzObjects=${input.crossModuleSzObjects ?? "none"}`,
301
+ `filename=${input.filename}`,
302
+ `source=${inputSha256}`
303
+ ].join("\n");
304
+ return {
305
+ key: createHash("sha256").update(keyMaterial).digest("hex").slice(0, 16),
306
+ inputSha256
307
+ };
308
+ }
309
+ function readTransformCache(cacheRoot, input, precomputedKey) {
310
+ const { key, inputSha256 } = precomputedKey ?? createTransformCacheKey(input);
311
+ const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
312
+ const file = cacheEntryPath(cacheRoot, key);
313
+ let entry;
314
+ try {
315
+ entry = JSON.parse(fs.readFileSync(file, "utf8"));
316
+ } catch {
317
+ return null;
318
+ }
319
+ 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) {
320
+ return null;
321
+ }
322
+ return deserializeResult(entry.result);
323
+ }
324
+ function writeTransformCache(cacheRoot, input, result, precomputedKey) {
325
+ const { key, inputSha256 } = precomputedKey ?? createTransformCacheKey(input);
326
+ const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
327
+ const file = cacheEntryPath(cacheRoot, key);
328
+ const dir = path.dirname(file);
329
+ const tmp = path.join(dir, `.tmp-${process.pid}-${Date.now()}-${randomUUID()}.json`);
330
+ const entry = {
331
+ version: CACHE_SCHEMA_VERSION,
332
+ pluginVersion: input.pluginVersion,
333
+ compilerVersion: input.compilerVersion,
334
+ nativeIdentity: input.nativeIdentity ?? null,
335
+ parserMode: input.parserMode,
336
+ producer: input.producer,
337
+ astBudget: input.astBudget ?? null,
338
+ mangleVars: input.mangleVars === true,
339
+ mangleVarHoistMaxDepth: input.mangleVarHoistMaxDepth ?? null,
340
+ globalVarAliases,
341
+ filename: input.filename,
342
+ inputSha256,
343
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
344
+ result: serializeResult(result)
345
+ };
346
+ try {
347
+ fs.mkdirSync(dir, { recursive: true });
348
+ fs.writeFileSync(tmp, JSON.stringify(entry), "utf8");
349
+ fs.renameSync(tmp, file);
350
+ } catch {
351
+ try {
352
+ fs.rmSync(tmp, { force: true });
353
+ } catch {
354
+ }
355
+ }
356
+ }
357
+ function evictOldTransformCacheEntries(cacheRoot, options) {
358
+ let deleted = 0;
359
+ const now = options.now ?? Date.now();
360
+ const survivors = [];
361
+ for (const file of listJsonFiles(cacheRoot)) {
362
+ try {
363
+ const entry = JSON.parse(fs.readFileSync(file, "utf8"));
364
+ const timestamp = typeof entry.timestamp === "string" ? Date.parse(entry.timestamp) : 0;
365
+ if (!Number.isFinite(timestamp) || now - timestamp > options.maxAgeMs) {
366
+ fs.rmSync(file, { force: true });
367
+ deleted++;
368
+ } else {
369
+ survivors.push({ file, timestamp });
370
+ }
371
+ } catch {
372
+ fs.rmSync(file, { force: true });
373
+ deleted++;
374
+ }
375
+ }
376
+ const overflow = survivors.length - options.maxEntries ;
377
+ if (overflow > 0) {
378
+ survivors.sort((a, b) => a.timestamp - b.timestamp);
379
+ for (const survivor of survivors.slice(0, overflow)) {
380
+ fs.rmSync(survivor.file, { force: true });
381
+ deleted++;
382
+ }
383
+ }
384
+ return deleted;
385
+ }
386
+ function cacheEntryPath(cacheRoot, key) {
387
+ return path.join(cacheRoot, key.slice(0, 2), `${key.slice(2)}.json`);
388
+ }
389
+ function serializeResult(result) {
390
+ return {
391
+ code: result.code,
392
+ transformed: result.transformed,
393
+ usesRuntime: result.usesRuntime,
394
+ usesMerge: result.usesMerge,
395
+ usesSzcn: result.usesSzcn,
396
+ usesSzPart: result.usesSzPart,
397
+ usesSzvPick: result.usesSzvPick,
398
+ usesSzvPick1: result.usesSzvPick1,
399
+ szPartArgsProvable: result.szPartArgsProvable,
400
+ usesColorVar: result.usesColorVar,
401
+ usesSpacingVar: result.usesSpacingVar,
402
+ usesUnitVar: result.usesUnitVar,
403
+ usesBoolClass: result.usesBoolClass,
404
+ classes: [...result.classes],
405
+ rawClassNames: [...result.rawClassNames],
406
+ diagnostics: [...result.diagnostics],
407
+ recoveryTokens: [...result.recoveryTokens],
408
+ cssVariableMap: [...result.cssVariableMap ?? /* @__PURE__ */ new Map()]
409
+ };
410
+ }
411
+ function deserializeResult(result) {
412
+ return {
413
+ code: result.code,
414
+ transformed: result.transformed,
415
+ usesRuntime: result.usesRuntime,
416
+ usesMerge: result.usesMerge,
417
+ usesSzcn: result.usesSzcn,
418
+ usesSzPart: result.usesSzPart,
419
+ usesSzvPick: result.usesSzvPick,
420
+ usesSzvPick1: result.usesSzvPick1,
421
+ szPartArgsProvable: result.szPartArgsProvable,
422
+ usesColorVar: result.usesColorVar,
423
+ usesSpacingVar: result.usesSpacingVar,
424
+ usesUnitVar: result.usesUnitVar,
425
+ usesBoolClass: result.usesBoolClass,
426
+ classes: new Set(result.classes),
427
+ rawClassNames: new Set(result.rawClassNames),
428
+ diagnostics: [...result.diagnostics],
429
+ recoveryTokens: new Map(result.recoveryTokens),
430
+ cssVariableMap: new Map(result.cssVariableMap ?? [])
431
+ };
432
+ }
433
+ function normalizeGlobalVarAliasEntries(aliases) {
434
+ if (!aliases || aliases.length === 0) {
435
+ return [];
436
+ }
437
+ const normalized = /* @__PURE__ */ new Map();
438
+ for (const [original, alias] of aliases) {
439
+ if (typeof original === "string" && typeof alias === "string") {
440
+ normalized.set(original, alias);
441
+ }
442
+ }
443
+ return [...normalized].sort(([left], [right]) => left.localeCompare(right));
444
+ }
445
+ function sameGlobalVarAliases(left, right) {
446
+ if (!Array.isArray(left) || left.length !== right.length) {
447
+ return false;
448
+ }
449
+ for (let index = 0; index < left.length; index++) {
450
+ const leftEntry = left[index];
451
+ const rightEntry = right[index];
452
+ if (leftEntry?.[0] !== rightEntry?.[0] || leftEntry?.[1] !== rightEntry?.[1]) {
453
+ return false;
454
+ }
455
+ }
456
+ return true;
457
+ }
458
+ function listJsonFiles(dir) {
459
+ let entries;
460
+ try {
461
+ entries = fs.readdirSync(dir, { withFileTypes: true });
462
+ } catch {
463
+ return [];
464
+ }
465
+ const files = [];
466
+ for (const entry of entries) {
467
+ const fullPath = path.join(dir, entry.name);
468
+ if (entry.isDirectory()) {
469
+ files.push(...listJsonFiles(fullPath));
470
+ } else if (entry.isFile() && entry.name.endsWith(".json")) {
471
+ files.push(fullPath);
472
+ }
473
+ }
474
+ return files;
475
+ }
476
+ function evictMemoryCacheToBudget(cache, totalCodeChars, maxEntries, maxCodeChars) {
477
+ let total = totalCodeChars;
478
+ while (cache.size > maxEntries || total > maxCodeChars && cache.size > 1) {
479
+ const oldest = cache.keys().next().value;
480
+ if (oldest === void 0) {
481
+ break;
482
+ }
483
+ const evicted = cache.get(oldest);
484
+ cache.delete(oldest);
485
+ total -= evicted?.code.length ?? 0;
486
+ }
487
+ return total;
488
+ }
489
+
490
+ export { resolveProviderPathWith as a, recordResolvedEntry as b, collectSpecifierAliases as c, isReadableProviderFile as d, createTransformCacheKey as e, readTransformCache as f, recordSzvRegistryFile as g, recordSzObjectRegistryFile as h, importedSpecifiersIn as i, resolveCrossModuleStaticsFor as j, evictOldTransformCacheEntries as k, evictMemoryCacheToBudget as l, mayExportSzvFactories as m, normalizePathSeparators as n, resolveProviderPath as o, resolveTransformCacheDir as r, specifierBases as s, writeTransformCache as w };
@@ -1,9 +1,73 @@
1
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, n as normalizePathSeparators, b as babelFallbackReason } from './unplugin.CDqY7kmk.mjs';
2
+ import * as path from 'node:path';
3
+ import { extractCrossModuleRegistryEntries, ensureRustTransformAvailable, transformRust, transformWasm, transform } from '@csszyx/compiler';
4
+ import { DEFAULT_IMPORTED_STATIC_SZ } from '@csszyx/types';
5
+ import { c as collectSpecifierAliases, i as importedSpecifiersIn, s as specifierBases, a as resolveProviderPathWith, n as normalizePathSeparators, b as recordResolvedEntry, d as isReadableProviderFile, e as createTransformCacheKey, f as readTransformCache, w as writeTransformCache } from './unplugin.DKcwO8O4.mjs';
4
6
  import { createHash } from 'node:crypto';
5
7
  import { s as sortStrings } from './unplugin.B3XoSRB8.mjs';
6
8
 
9
+ function resolveImportedStaticSz(value) {
10
+ return value ?? DEFAULT_IMPORTED_STATIC_SZ;
11
+ }
12
+ const aliasesByRoot = /* @__PURE__ */ new Map();
13
+ function resolveNextCrossModule(input) {
14
+ const empty = { statics: {}, providers: [] };
15
+ if (!input.source.includes("from")) return empty;
16
+ let aliases = aliasesByRoot.get(input.root);
17
+ if (aliases === void 0) {
18
+ aliases = collectSpecifierAliases(input.root);
19
+ aliasesByRoot.set(input.root, aliases);
20
+ }
21
+ const directory = path.dirname(input.filename);
22
+ const statics = {};
23
+ const providers = [];
24
+ const seen = /* @__PURE__ */ new Set();
25
+ for (const specifier of importedSpecifiersIn(input.source)) {
26
+ if (seen.has(specifier)) continue;
27
+ seen.add(specifier);
28
+ for (const base of specifierBases(specifier, directory, aliases)) {
29
+ const provider = resolveProviderPathWith(base, isReadableProviderFile);
30
+ if (provider === void 0) continue;
31
+ providers.push(provider);
32
+ recordEntries(statics, specifier, readProviderEntries(provider), input);
33
+ break;
34
+ }
35
+ }
36
+ return { statics, providers };
37
+ }
38
+ function readProviderEntries(provider) {
39
+ try {
40
+ return extractCrossModuleRegistryEntries(readFileSync(provider, "utf8"), provider);
41
+ } catch {
42
+ return [];
43
+ }
44
+ }
45
+ function recordEntries(statics, specifier, entries, input) {
46
+ for (const entry of entries) {
47
+ if (entry.kind === "sz-object" && !resolveImportedStaticSz(input.importedStaticSz)) {
48
+ continue;
49
+ }
50
+ recordResolvedEntry(statics, entry.kind, specifier, entry.exportName, entry.value);
51
+ }
52
+ }
53
+ function withCrossModuleStatics(options, statics) {
54
+ if (statics.szvConfigs === void 0 && statics.szObjects === void 0) return options;
55
+ return {
56
+ ...options,
57
+ ...statics.szvConfigs === void 0 ? {} : { crossModuleStatics: statics.szvConfigs },
58
+ ...statics.szObjects === void 0 ? {} : { crossModuleSzObjects: statics.szObjects }
59
+ };
60
+ }
61
+ function configWithImportedStaticSz(config, importedStaticSz) {
62
+ return {
63
+ ...config,
64
+ importedStaticSz: resolveImportedStaticSz(importedStaticSz)
65
+ };
66
+ }
67
+ function normalizeProviderPaths(providers) {
68
+ return [...new Set(providers.map(normalizePathSeparators))];
69
+ }
70
+
7
71
  function readPackageVersion(relativePackageJson, fromUrl) {
8
72
  try {
9
73
  const packageJson = JSON.parse(
@@ -126,34 +190,16 @@ function isRegexLiteralStart(emitted) {
126
190
  }
127
191
  function runNextSourceTransform(input, filename) {
128
192
  const compilerOptions = input.compilerOptions;
129
- if (input.parserMode === "babel") {
130
- return {
131
- result: transformSourceCode(input.source, filename, compilerOptions),
132
- producer: "babel"
133
- };
134
- }
135
193
  if (input.parserMode === "rust") {
136
194
  return {
137
195
  result: transformRust(input.source, filename, compilerOptions),
138
196
  producer: "rust"
139
197
  };
140
198
  }
141
- try {
142
- return {
143
- result: transformOxc(input.source, filename, compilerOptions),
144
- producer: "oxc"
145
- };
146
- } catch (error) {
147
- if (input.allowBabelFallback === false) {
148
- throw error;
149
- }
150
- const result = transformSourceCode(input.source, filename, compilerOptions);
151
- const reason = babelFallbackReason(error);
152
- result.diagnostics.push(
153
- `[csszyx] oxc parser fell back to Babel for ${filename}: ${reason}`
154
- );
155
- return { result, producer: "babel-fallback" };
156
- }
199
+ return {
200
+ result: transformWasm(input.source, filename, compilerOptions),
201
+ producer: "wasm"
202
+ };
157
203
  }
158
204
  function createNextSourceTransformCacheInput(input, filename, producer) {
159
205
  return {
@@ -167,6 +213,12 @@ function createNextSourceTransformCacheInput(input, filename, producer) {
167
213
  globalVarAliases: normalizeGlobalVarAliasesForCache(
168
214
  input.compilerOptions?.globalVarAliases
169
215
  ),
216
+ // The registry slice this file was compiled against is part of its
217
+ // identity. Without it an edited provider serves its importers the
218
+ // cached output built from the value it used to have — the one failure
219
+ // this lane refused to risk before it resolved anything at all.
220
+ crossModuleStatics: input.compilerOptions?.crossModuleStatics === void 0 ? void 0 : JSON.stringify(input.compilerOptions.crossModuleStatics),
221
+ crossModuleSzObjects: input.compilerOptions?.crossModuleSzObjects === void 0 ? void 0 : JSON.stringify(input.compilerOptions.crossModuleSzObjects),
170
222
  filename,
171
223
  source: input.source
172
224
  };
@@ -275,4 +327,4 @@ function collectTransformClasses(result, discoveredClasses) {
275
327
  }
276
328
  }
277
329
 
278
- export { createNextSafelistShardFromMetadata as a, collectNextTransformMetadata as c, readPackageVersion as r, transformNextSource as t };
330
+ export { resolveNextCrossModule as a, collectNextTransformMetadata as b, configWithImportedStaticSz as c, createNextSafelistShardFromMetadata as d, normalizeProviderPaths as n, readPackageVersion as r, transformNextSource as t, withCrossModuleStatics as w };