@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,62 +1,15 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import * as path from 'node:path';
3
- import { c as createNextStateContext, w as writeNextSafelistShard, r as runNextWatcherCycle, v as validateNextGenerationManifest, a as readNextGenerationManifest } from './shared/unplugin.DMcbmP01.mjs';
4
- import { r as readPackageVersion, t as transformNextSource, c as collectNextTransformMetadata, a as createNextSafelistShardFromMetadata } from './shared/unplugin.-yLpX1Ck.mjs';
5
- import { i as importsRuntimeHelper, a as insertAfterUseDirective } from './shared/unplugin.Lhzkcj-A.mjs';
6
- import { r as resolveTransformCacheDir, n as normalizePathSeparators } from './shared/unplugin.fOnGXWgS.mjs';
3
+ import { i as injectNextRuntimeImports, e as ensureThemeGroupsFile, a as insertAfterUseDirective, t as themeGroupsSpecifier } from './shared/unplugin.5l4RHMQh.mjs';
4
+ import { r as readPackageVersion, c as configWithImportedStaticSz, a as resolveNextCrossModule, t as transformNextSource, w as withCrossModuleStatics, n as normalizeProviderPaths, b as collectNextTransformMetadata, d as createNextSafelistShardFromMetadata } from './shared/unplugin.CogPHmDs.mjs';
5
+ import { c as createNextStateContext, w as writeNextSafelistShard, r as runNextWatcherCycle, v as validateNextGenerationManifest, a as readNextGenerationManifest } from './shared/unplugin.BU0O4IkX.mjs';
6
+ import { r as resolveTransformCacheDir, n as normalizePathSeparators } from './shared/unplugin.BB0iWSds.mjs';
7
7
  import 'node:fs';
8
- import 'node:os';
9
- import 'proper-lockfile';
10
8
  import './shared/unplugin.B3XoSRB8.mjs';
11
9
  import '@csszyx/compiler';
12
-
13
- function injectNextRuntimeImports(code, usage) {
14
- const helpers = runtimeHelpersFromUsage(usage);
15
- if (helpers.length === 0) {
16
- return { code, injected: [] };
17
- }
18
- const hasRuntimeImport = code.includes("@csszyx/runtime");
19
- const missing = hasRuntimeImport ? helpers.filter((helper) => !importsRuntimeHelper(code, helper)) : helpers;
20
- if (missing.length === 0) {
21
- return { code, injected: [] };
22
- }
23
- return {
24
- code: insertRuntimeImport(
25
- code,
26
- `import { ${missing.join(", ")} } from '@csszyx/runtime';
27
- `
28
- ),
29
- injected: missing
30
- };
31
- }
32
- function runtimeHelpersFromUsage(usage) {
33
- const helpers = [];
34
- if (usage.usesRuntime) {
35
- helpers.push("_sz");
36
- }
37
- if (usage.usesMerge) {
38
- helpers.push("_szMerge");
39
- }
40
- if (usage.usesSzcn) {
41
- helpers.push("_szcn");
42
- }
43
- if (usage.usesSzPart) {
44
- helpers.push("_szPart");
45
- }
46
- if (usage.usesColorVar) {
47
- helpers.push("__szColorVar");
48
- }
49
- if (usage.usesSpacingVar) {
50
- helpers.push("__szSpacingVar");
51
- }
52
- if (usage.usesUnitVar) {
53
- helpers.push("__szUnitVar");
54
- }
55
- return helpers;
56
- }
57
- function insertRuntimeImport(code, importStmt) {
58
- return insertAfterUseDirective(code, importStmt);
59
- }
10
+ import '@csszyx/types';
11
+ import 'node:os';
12
+ import 'proper-lockfile';
60
13
 
61
14
  function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
62
15
  const options = normalizeOptions(loaderContext, explicitOptions);
@@ -67,7 +20,7 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
67
20
  loaderContext: loaderContext.context,
68
21
  cacheDir: options.cacheDir,
69
22
  safelistOutputFile: options.safelistOutputFile,
70
- config: options.config ?? {},
23
+ config: configWithImportedStaticSz(options.config ?? {}, options.importedStaticSz),
71
24
  env: options.env ?? process.env,
72
25
  envKeys: options.envKeys,
73
26
  nextVersion: options.nextVersion ?? "unknown-next",
@@ -76,11 +29,17 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
76
29
  mode: options.mode ?? normalizeMode(loaderContext.mode)
77
30
  });
78
31
  assertProductionManifestReady(context, options);
32
+ const crossModule = resolveNextCrossModule({
33
+ filename: loaderContext.resourcePath,
34
+ source,
35
+ root: context.root,
36
+ importedStaticSz: options.importedStaticSz
37
+ });
79
38
  const transform = transformNextSource({
80
39
  source,
81
40
  filename: loaderContext.resourcePath,
82
41
  parserMode: options.parserMode ?? "rust",
83
- compilerOptions: options.compilerOptions,
42
+ compilerOptions: withCrossModuleStatics(options.compilerOptions, crossModule.statics),
84
43
  cacheRoot: resolveTransformCacheDir(
85
44
  context.root,
86
45
  path.relative(context.root, context.cacheDir)
@@ -91,6 +50,17 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
91
50
  allowBabelFallback: options.allowBabelFallback
92
51
  });
93
52
  const injected = injectNextRuntimeImports(transform.result.code, transform.result);
53
+ const callsSzcn = transform.result.usesSzcn || /\bszcn\s*\(/.test(source);
54
+ const themeGroups = callsSzcn ? ensureThemeGroupsFile(context.root, path.join(context.root, ".csszyx")) : { file: null, watch: [] };
55
+ for (const stylesheet of themeGroups.watch) loaderContext.addDependency?.(stylesheet);
56
+ for (const provider of normalizeProviderPaths(crossModule.providers)) {
57
+ loaderContext.addDependency?.(provider);
58
+ }
59
+ const code = themeGroups.file === null ? injected.code : insertAfterUseDirective(
60
+ injected.code,
61
+ `import '${themeGroupsSpecifier(loaderContext.resourcePath, themeGroups.file)}';
62
+ `
63
+ );
94
64
  const metadata = collectNextTransformMetadata(
95
65
  transform.result,
96
66
  source,
@@ -116,12 +86,12 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
116
86
  materialized = true;
117
87
  }
118
88
  return {
119
- code: injected.code,
89
+ code,
120
90
  context,
121
91
  transform,
122
92
  shardPath,
123
93
  materialized,
124
- dependencies: []
94
+ dependencies: themeGroups.watch
125
95
  };
126
96
  }
127
97
  function nextTurboLoader(source) {
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const path = require('node:path');
4
- const nextWatcherCycle = require('./shared/unplugin.DblMogcN.cjs');
4
+ const nextWatcherCycle = require('./shared/unplugin.Cji6O5jv.cjs');
5
5
  require('node:fs');
6
6
  require('node:crypto');
7
7
  require('node:os');
@@ -1,5 +1,5 @@
1
1
  import * as path from 'node:path';
2
- import { r as runNextWatcherCycle } from './shared/unplugin.DMcbmP01.mjs';
2
+ import { r as runNextWatcherCycle } from './shared/unplugin.BU0O4IkX.mjs';
3
3
  import 'node:fs';
4
4
  import 'node:crypto';
5
5
  import 'node:os';
@@ -0,0 +1,529 @@
1
+ 'use strict';
2
+
3
+ const compiler = require('@csszyx/compiler');
4
+ const path = require('node:path');
5
+ const fs = require('node:fs');
6
+ const node_crypto = require('node:crypto');
7
+
8
+ function _interopNamespaceCompat(e) {
9
+ if (e && typeof e === 'object' && 'default' in e) return e;
10
+ const n = Object.create(null);
11
+ if (e) {
12
+ for (const k in e) {
13
+ n[k] = e[k];
14
+ }
15
+ }
16
+ n.default = e;
17
+ return n;
18
+ }
19
+
20
+ const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
21
+ const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
22
+
23
+ const WINDOWS_PATH_SEPARATOR = String.fromCodePoint(92);
24
+ function normalizePathSeparators(value) {
25
+ return value.split(WINDOWS_PATH_SEPARATOR).join("/");
26
+ }
27
+
28
+ function babelFallbackReason(error) {
29
+ if (error instanceof compiler.OxcNotImplementedError) {
30
+ return error.detail;
31
+ }
32
+ return error instanceof Error ? error.message : String(error);
33
+ }
34
+
35
+ const TSCONFIG_CANDIDATES = ["tsconfig.json", "jsconfig.json", "tsconfig.app.json"];
36
+ const MAX_EXTENDS_DEPTH = 8;
37
+ function collectSpecifierAliases(rootDir, resolveAlias) {
38
+ return [...aliasesFromResolveConfig(rootDir, resolveAlias), ...aliasesFromTsconfig(rootDir)];
39
+ }
40
+ function aliasesFromResolveConfig(rootDir, raw) {
41
+ const aliases = [];
42
+ if (Array.isArray(raw)) {
43
+ for (const entry of raw) {
44
+ const find = entry.find;
45
+ const replacement = entry.replacement;
46
+ if (typeof find !== "string" || typeof replacement !== "string") continue;
47
+ aliases.push(makeAlias(rootDir, find, replacement));
48
+ }
49
+ return aliases;
50
+ }
51
+ if (raw === null || typeof raw !== "object") return aliases;
52
+ for (const [find, target] of Object.entries(raw)) {
53
+ for (const value of Array.isArray(target) ? target : [target]) {
54
+ if (typeof value !== "string") continue;
55
+ aliases.push(makeAlias(rootDir, find, value));
56
+ }
57
+ }
58
+ return aliases;
59
+ }
60
+ function makeAlias(rootDir, find, replacement) {
61
+ const exact = find.endsWith("$");
62
+ return {
63
+ find: exact ? find.slice(0, -1) : find,
64
+ replacement: absolute(rootDir, replacement),
65
+ exact
66
+ };
67
+ }
68
+ function aliasesFromTsconfig(rootDir) {
69
+ for (const candidate of TSCONFIG_CANDIDATES) {
70
+ const loaded = loadPathsConfig(path__namespace.join(rootDir, candidate), 0);
71
+ if (loaded === void 0) continue;
72
+ const aliases = pathsToAliases(loaded.base, loaded.paths);
73
+ if (aliases.length > 0) return aliases;
74
+ }
75
+ return [];
76
+ }
77
+ function loadPathsConfig(configPath, depth) {
78
+ if (depth > MAX_EXTENDS_DEPTH) return void 0;
79
+ let parsed;
80
+ try {
81
+ parsed = parseJsonc(fs__namespace.readFileSync(configPath, "utf-8"));
82
+ } catch {
83
+ return void 0;
84
+ }
85
+ const directory = path__namespace.dirname(configPath);
86
+ const compilerOptions = asRecord(parsed.compilerOptions);
87
+ const paths = asRecord(compilerOptions?.paths);
88
+ if (paths !== void 0) {
89
+ const baseUrl = compilerOptions?.baseUrl;
90
+ return {
91
+ base: typeof baseUrl === "string" ? absolute(directory, baseUrl) : absolute(directory, "."),
92
+ paths
93
+ };
94
+ }
95
+ const extended = parsed.extends;
96
+ if (typeof extended !== "string" || !extended.startsWith(".")) return void 0;
97
+ const resolved = path__namespace.resolve(directory, extended);
98
+ return loadPathsConfig(resolved, depth + 1) ?? loadPathsConfig(`${resolved}.json`, depth + 1);
99
+ }
100
+ function pathsToAliases(base, paths) {
101
+ return Object.entries(paths).flatMap(
102
+ ([pattern, targets]) => patternToAliases(base, pattern, targets)
103
+ );
104
+ }
105
+ function patternToAliases(base, pattern, targets) {
106
+ const wildcard = pattern.indexOf("*");
107
+ if (wildcard !== -1 && wildcard !== pattern.length - 1) return [];
108
+ const exact = wildcard === -1;
109
+ const find = exact ? pattern : pattern.slice(0, -1);
110
+ const declared = Array.isArray(targets) ? targets : [targets];
111
+ return declared.filter((target) => typeof target === "string").map((target) => ({
112
+ find,
113
+ replacement: absolute(base, target.endsWith("*") ? target.slice(0, -1) : target),
114
+ exact
115
+ }));
116
+ }
117
+ function aliasedSpecifierBases(specifier, aliases) {
118
+ const bases = [];
119
+ for (const alias of aliases) {
120
+ if (alias.exact) {
121
+ if (specifier === alias.find) bases.push(alias.replacement);
122
+ continue;
123
+ }
124
+ if (!specifier.startsWith(alias.find)) continue;
125
+ bases.push(normalizePathSeparators(alias.replacement + specifier.slice(alias.find.length)));
126
+ }
127
+ return bases;
128
+ }
129
+ function absolute(directory, target) {
130
+ const resolved = normalizePathSeparators(path__namespace.resolve(directory, target));
131
+ const declaredTrailingSlash = target.endsWith("/") || target.endsWith("\\");
132
+ return declaredTrailingSlash && !resolved.endsWith("/") ? `${resolved}/` : resolved;
133
+ }
134
+ function asRecord(value) {
135
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
136
+ }
137
+ function parseJsonc(text) {
138
+ const parsed = JSON.parse(stripComments(text).replace(/,(\s*[}\]])/g, "$1"));
139
+ return asRecord(parsed) ?? {};
140
+ }
141
+ function stripComments(text) {
142
+ const out = [];
143
+ let index = 0;
144
+ while (index < text.length) {
145
+ const run = consumeString(text, index) ?? consumeComment(text, index);
146
+ if (run === void 0) {
147
+ out.push(text[index]);
148
+ index += 1;
149
+ continue;
150
+ }
151
+ out.push(run.keep);
152
+ index = run.next;
153
+ }
154
+ return out.join("");
155
+ }
156
+ function consumeString(text, start) {
157
+ if (text[start] !== '"') return void 0;
158
+ let index = start + 1;
159
+ while (index < text.length) {
160
+ const char = text[index];
161
+ if (char === "\\") {
162
+ index += 2;
163
+ continue;
164
+ }
165
+ index += 1;
166
+ if (char === '"') break;
167
+ }
168
+ return { keep: text.slice(start, index), next: index };
169
+ }
170
+ function consumeComment(text, start) {
171
+ if (text[start] !== "/") return void 0;
172
+ if (text[start + 1] === "/") {
173
+ const end = text.indexOf("\n", start);
174
+ return { keep: "", next: end === -1 ? text.length : end };
175
+ }
176
+ if (text[start + 1] === "*") {
177
+ const end = text.indexOf("*/", start + 2);
178
+ return { keep: "", next: end === -1 ? text.length : end + 2 };
179
+ }
180
+ return void 0;
181
+ }
182
+
183
+ function mayExportSzvFactories(content) {
184
+ return content.includes("szv(") && content.includes("export");
185
+ }
186
+ function recordSzvRegistryFile(registry, filePath, content) {
187
+ const entries = mayExportSzvFactories(content) ? compiler.extractCrossModuleRegistryEntries(content, filePath) : [];
188
+ replaceEntriesOfKind(registry, filePath, "szv-config", entries);
189
+ }
190
+ function recordSzObjectRegistryFile(registry, filePath, content) {
191
+ replaceEntriesOfKind(
192
+ registry,
193
+ filePath,
194
+ "sz-object",
195
+ compiler.extractCrossModuleRegistryEntries(content, filePath)
196
+ );
197
+ }
198
+ function replaceEntriesOfKind(registry, filePath, kind, entries) {
199
+ const key = normalizePathSeparators(filePath);
200
+ const byName = emptyNameIndex();
201
+ for (const [name, recorded] of Object.entries(registry.get(key) ?? {})) {
202
+ if (recorded.kind !== kind) byName[name] = recorded;
203
+ }
204
+ for (const entry of entries) {
205
+ if (entry.kind === kind) byName[entry.exportName] = { kind, value: entry.value };
206
+ }
207
+ if (Object.keys(byName).length === 0) registry.delete(key);
208
+ else registry.set(key, byName);
209
+ }
210
+ function emptyNameIndex() {
211
+ return /* @__PURE__ */ Object.create(null);
212
+ }
213
+ const SPECIFIER_PROBES = ["", ".ts", ".tsx", ".js", ".jsx", "/index.ts", "/index.tsx"];
214
+ const EMITTED_EXTENSION_SOURCES = [
215
+ [".js", [".ts", ".tsx"]],
216
+ [".jsx", [".tsx"]],
217
+ [".mjs", [".mts"]],
218
+ [".cjs", [".cts"]]
219
+ ];
220
+ function resolveCrossModuleStaticsFor(registry, filename, source, aliases = []) {
221
+ if (registry.size === 0 || !source.includes("from")) return {};
222
+ const directory = path__namespace.dirname(filename);
223
+ const resolved = {};
224
+ const seen = /* @__PURE__ */ new Set();
225
+ for (const specifier of importedSpecifiersIn(source)) {
226
+ if (seen.has(specifier)) continue;
227
+ seen.add(specifier);
228
+ const entries = firstRegistryHit(registry, specifier, directory, aliases);
229
+ if (entries !== void 0) fileUnderSpecifier(resolved, specifier, entries);
230
+ }
231
+ return resolved;
232
+ }
233
+ function firstRegistryHit(registry, specifier, directory, aliases) {
234
+ for (const base of specifierBases(specifier, directory, aliases)) {
235
+ const entries = lookupRegistryKey(registry, base);
236
+ if (entries !== void 0) return entries;
237
+ }
238
+ return void 0;
239
+ }
240
+ function recordResolvedEntry(resolved, kind, specifier, name, value) {
241
+ if (specifier === "__proto__" || name === "__proto__") return;
242
+ const channel = kind === "szv-config" ? "szvConfigs" : "szObjects";
243
+ let bySpecifier = resolved[channel];
244
+ if (bySpecifier === void 0) {
245
+ bySpecifier = emptyNameIndex();
246
+ resolved[channel] = bySpecifier;
247
+ }
248
+ let byName = bySpecifier[specifier];
249
+ if (byName === void 0) {
250
+ byName = emptyNameIndex();
251
+ bySpecifier[specifier] = byName;
252
+ }
253
+ byName[name] = value;
254
+ }
255
+ function fileUnderSpecifier(resolved, specifier, entries) {
256
+ for (const [name, recorded] of Object.entries(entries)) {
257
+ recordResolvedEntry(resolved, recorded.kind, specifier, name, recorded.value);
258
+ }
259
+ }
260
+ function importedSpecifiersIn(source) {
261
+ if (!source.includes("from")) return [];
262
+ return [...source.matchAll(/from\s*['"]([^'"]*)['"]/g)].map((match) => match[1]);
263
+ }
264
+ function specifierBases(specifier, directory, aliases) {
265
+ if (specifier.startsWith(".")) {
266
+ return [normalizePathSeparators(path__namespace.resolve(directory, specifier))];
267
+ }
268
+ return aliasedSpecifierBases(specifier, aliases);
269
+ }
270
+ function resolveProviderPath(seenPaths, base) {
271
+ return resolveProviderPathWith(base, (candidate) => seenPaths.has(candidate));
272
+ }
273
+ function resolveProviderPathWith(base, exists) {
274
+ return probeSpecifier(base, (candidate) => exists(candidate) ? candidate : void 0);
275
+ }
276
+ function probeSpecifier(base, lookup) {
277
+ for (const probe of SPECIFIER_PROBES) {
278
+ const found = lookup(`${base}${probe}`);
279
+ if (found !== void 0) return found;
280
+ }
281
+ for (const [emitted, sources] of EMITTED_EXTENSION_SOURCES) {
282
+ if (!base.endsWith(emitted)) continue;
283
+ const stem = base.slice(0, -emitted.length);
284
+ for (const extension of sources) {
285
+ const found = lookup(`${stem}${extension}`);
286
+ if (found !== void 0) return found;
287
+ }
288
+ break;
289
+ }
290
+ return void 0;
291
+ }
292
+ function lookupRegistryKey(registry, base) {
293
+ return probeSpecifier(base, (candidate) => registry.get(candidate));
294
+ }
295
+
296
+ function isReadableProviderFile(candidate) {
297
+ try {
298
+ return fs.existsSync(candidate) && fs.statSync(candidate).isFile();
299
+ } catch {
300
+ return false;
301
+ }
302
+ }
303
+
304
+ const CACHE_SCHEMA_VERSION = 16;
305
+ function resolveTransformCacheDir(rootDir, cacheDir) {
306
+ return path__namespace.resolve(rootDir, cacheDir ?? ".csszyx/cache", "transform");
307
+ }
308
+ function createTransformCacheKey(input) {
309
+ const inputSha256 = node_crypto.createHash("sha256").update(input.source).digest("hex");
310
+ const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
311
+ const keyMaterial = [
312
+ `schema=${CACHE_SCHEMA_VERSION}`,
313
+ `plugin=${input.pluginVersion}`,
314
+ `compiler=${input.compilerVersion}`,
315
+ `native=${input.nativeIdentity ?? "none"}`,
316
+ `parser=${input.parserMode}`,
317
+ `producer=${input.producer}`,
318
+ `astBudget=${input.astBudget ?? "default"}`,
319
+ `mangleVars=${input.mangleVars === true}`,
320
+ `mangleVarHoistMaxDepth=${input.mangleVarHoistMaxDepth ?? "default"}`,
321
+ `globalVarAliases=${JSON.stringify(globalVarAliases)}`,
322
+ `crossModuleStatics=${input.crossModuleStatics ?? "none"}`,
323
+ `crossModuleSzObjects=${input.crossModuleSzObjects ?? "none"}`,
324
+ `filename=${input.filename}`,
325
+ `source=${inputSha256}`
326
+ ].join("\n");
327
+ return {
328
+ key: node_crypto.createHash("sha256").update(keyMaterial).digest("hex").slice(0, 16),
329
+ inputSha256
330
+ };
331
+ }
332
+ function readTransformCache(cacheRoot, input, precomputedKey) {
333
+ const { key, inputSha256 } = precomputedKey ?? createTransformCacheKey(input);
334
+ const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
335
+ const file = cacheEntryPath(cacheRoot, key);
336
+ let entry;
337
+ try {
338
+ entry = JSON.parse(fs__namespace.readFileSync(file, "utf8"));
339
+ } catch {
340
+ return null;
341
+ }
342
+ 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) {
343
+ return null;
344
+ }
345
+ return deserializeResult(entry.result);
346
+ }
347
+ function writeTransformCache(cacheRoot, input, result, precomputedKey) {
348
+ const { key, inputSha256 } = precomputedKey ?? createTransformCacheKey(input);
349
+ const globalVarAliases = normalizeGlobalVarAliasEntries(input.globalVarAliases);
350
+ const file = cacheEntryPath(cacheRoot, key);
351
+ const dir = path__namespace.dirname(file);
352
+ const tmp = path__namespace.join(dir, `.tmp-${process.pid}-${Date.now()}-${node_crypto.randomUUID()}.json`);
353
+ const entry = {
354
+ version: CACHE_SCHEMA_VERSION,
355
+ pluginVersion: input.pluginVersion,
356
+ compilerVersion: input.compilerVersion,
357
+ nativeIdentity: input.nativeIdentity ?? null,
358
+ parserMode: input.parserMode,
359
+ producer: input.producer,
360
+ astBudget: input.astBudget ?? null,
361
+ mangleVars: input.mangleVars === true,
362
+ mangleVarHoistMaxDepth: input.mangleVarHoistMaxDepth ?? null,
363
+ globalVarAliases,
364
+ filename: input.filename,
365
+ inputSha256,
366
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
367
+ result: serializeResult(result)
368
+ };
369
+ try {
370
+ fs__namespace.mkdirSync(dir, { recursive: true });
371
+ fs__namespace.writeFileSync(tmp, JSON.stringify(entry), "utf8");
372
+ fs__namespace.renameSync(tmp, file);
373
+ } catch {
374
+ try {
375
+ fs__namespace.rmSync(tmp, { force: true });
376
+ } catch {
377
+ }
378
+ }
379
+ }
380
+ function evictOldTransformCacheEntries(cacheRoot, options) {
381
+ let deleted = 0;
382
+ const now = options.now ?? Date.now();
383
+ const survivors = [];
384
+ for (const file of listJsonFiles(cacheRoot)) {
385
+ try {
386
+ const entry = JSON.parse(fs__namespace.readFileSync(file, "utf8"));
387
+ const timestamp = typeof entry.timestamp === "string" ? Date.parse(entry.timestamp) : 0;
388
+ if (!Number.isFinite(timestamp) || now - timestamp > options.maxAgeMs) {
389
+ fs__namespace.rmSync(file, { force: true });
390
+ deleted++;
391
+ } else {
392
+ survivors.push({ file, timestamp });
393
+ }
394
+ } catch {
395
+ fs__namespace.rmSync(file, { force: true });
396
+ deleted++;
397
+ }
398
+ }
399
+ const overflow = survivors.length - options.maxEntries ;
400
+ if (overflow > 0) {
401
+ survivors.sort((a, b) => a.timestamp - b.timestamp);
402
+ for (const survivor of survivors.slice(0, overflow)) {
403
+ fs__namespace.rmSync(survivor.file, { force: true });
404
+ deleted++;
405
+ }
406
+ }
407
+ return deleted;
408
+ }
409
+ function cacheEntryPath(cacheRoot, key) {
410
+ return path__namespace.join(cacheRoot, key.slice(0, 2), `${key.slice(2)}.json`);
411
+ }
412
+ function serializeResult(result) {
413
+ return {
414
+ code: result.code,
415
+ transformed: result.transformed,
416
+ usesRuntime: result.usesRuntime,
417
+ usesMerge: result.usesMerge,
418
+ usesSzcn: result.usesSzcn,
419
+ usesSzPart: result.usesSzPart,
420
+ usesSzvPick: result.usesSzvPick,
421
+ usesSzvPick1: result.usesSzvPick1,
422
+ szPartArgsProvable: result.szPartArgsProvable,
423
+ usesColorVar: result.usesColorVar,
424
+ usesSpacingVar: result.usesSpacingVar,
425
+ usesUnitVar: result.usesUnitVar,
426
+ classes: [...result.classes],
427
+ rawClassNames: [...result.rawClassNames],
428
+ diagnostics: [...result.diagnostics],
429
+ recoveryTokens: [...result.recoveryTokens],
430
+ cssVariableMap: [...result.cssVariableMap ?? /* @__PURE__ */ new Map()]
431
+ };
432
+ }
433
+ function deserializeResult(result) {
434
+ return {
435
+ code: result.code,
436
+ transformed: result.transformed,
437
+ usesRuntime: result.usesRuntime,
438
+ usesMerge: result.usesMerge,
439
+ usesSzcn: result.usesSzcn,
440
+ usesSzPart: result.usesSzPart,
441
+ usesSzvPick: result.usesSzvPick,
442
+ usesSzvPick1: result.usesSzvPick1,
443
+ szPartArgsProvable: result.szPartArgsProvable,
444
+ usesColorVar: result.usesColorVar,
445
+ usesSpacingVar: result.usesSpacingVar,
446
+ usesUnitVar: result.usesUnitVar,
447
+ classes: new Set(result.classes),
448
+ rawClassNames: new Set(result.rawClassNames),
449
+ diagnostics: [...result.diagnostics],
450
+ recoveryTokens: new Map(result.recoveryTokens),
451
+ cssVariableMap: new Map(result.cssVariableMap ?? [])
452
+ };
453
+ }
454
+ function normalizeGlobalVarAliasEntries(aliases) {
455
+ if (!aliases || aliases.length === 0) {
456
+ return [];
457
+ }
458
+ const normalized = /* @__PURE__ */ new Map();
459
+ for (const [original, alias] of aliases) {
460
+ if (typeof original === "string" && typeof alias === "string") {
461
+ normalized.set(original, alias);
462
+ }
463
+ }
464
+ return [...normalized].sort(([left], [right]) => left.localeCompare(right));
465
+ }
466
+ function sameGlobalVarAliases(left, right) {
467
+ if (!Array.isArray(left) || left.length !== right.length) {
468
+ return false;
469
+ }
470
+ for (let index = 0; index < left.length; index++) {
471
+ const leftEntry = left[index];
472
+ const rightEntry = right[index];
473
+ if (leftEntry?.[0] !== rightEntry?.[0] || leftEntry?.[1] !== rightEntry?.[1]) {
474
+ return false;
475
+ }
476
+ }
477
+ return true;
478
+ }
479
+ function listJsonFiles(dir) {
480
+ let entries;
481
+ try {
482
+ entries = fs__namespace.readdirSync(dir, { withFileTypes: true });
483
+ } catch {
484
+ return [];
485
+ }
486
+ const files = [];
487
+ for (const entry of entries) {
488
+ const fullPath = path__namespace.join(dir, entry.name);
489
+ if (entry.isDirectory()) {
490
+ files.push(...listJsonFiles(fullPath));
491
+ } else if (entry.isFile() && entry.name.endsWith(".json")) {
492
+ files.push(fullPath);
493
+ }
494
+ }
495
+ return files;
496
+ }
497
+ function evictMemoryCacheToBudget(cache, totalCodeChars, maxEntries, maxCodeChars) {
498
+ let total = totalCodeChars;
499
+ while (cache.size > maxEntries || total > maxCodeChars && cache.size > 1) {
500
+ const oldest = cache.keys().next().value;
501
+ if (oldest === void 0) {
502
+ break;
503
+ }
504
+ const evicted = cache.get(oldest);
505
+ cache.delete(oldest);
506
+ total -= evicted?.code.length ?? 0;
507
+ }
508
+ return total;
509
+ }
510
+
511
+ exports.babelFallbackReason = babelFallbackReason;
512
+ exports.collectSpecifierAliases = collectSpecifierAliases;
513
+ exports.createTransformCacheKey = createTransformCacheKey;
514
+ exports.evictMemoryCacheToBudget = evictMemoryCacheToBudget;
515
+ exports.evictOldTransformCacheEntries = evictOldTransformCacheEntries;
516
+ exports.importedSpecifiersIn = importedSpecifiersIn;
517
+ exports.isReadableProviderFile = isReadableProviderFile;
518
+ exports.mayExportSzvFactories = mayExportSzvFactories;
519
+ exports.normalizePathSeparators = normalizePathSeparators;
520
+ exports.readTransformCache = readTransformCache;
521
+ exports.recordResolvedEntry = recordResolvedEntry;
522
+ exports.recordSzObjectRegistryFile = recordSzObjectRegistryFile;
523
+ exports.recordSzvRegistryFile = recordSzvRegistryFile;
524
+ exports.resolveCrossModuleStaticsFor = resolveCrossModuleStaticsFor;
525
+ exports.resolveProviderPath = resolveProviderPath;
526
+ exports.resolveProviderPathWith = resolveProviderPathWith;
527
+ exports.resolveTransformCacheDir = resolveTransformCacheDir;
528
+ exports.specifierBases = specifierBases;
529
+ exports.writeTransformCache = writeTransformCache;