@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
@@ -1,14 +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.DXgxFHzO.mjs';
5
- import { i as injectNextRuntimeImports } from './shared/unplugin.CBMJufQ8.mjs';
6
- import { r as resolveTransformCacheDir, n as normalizePathSeparators } from './shared/unplugin.CDqY7kmk.mjs';
3
+ import { i as injectNextRuntimeImports, e as ensureThemeGroupsFile, a as insertAfterUseDirective, t as themeGroupsSpecifier } from './shared/unplugin.BcsvXjIV.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.DjRylBC_.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.DKcwO8O4.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';
10
+ import '@csszyx/types';
11
+ import 'node:os';
12
+ import 'proper-lockfile';
12
13
 
13
14
  function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
14
15
  const options = normalizeOptions(loaderContext, explicitOptions);
@@ -19,7 +20,7 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
19
20
  loaderContext: loaderContext.context,
20
21
  cacheDir: options.cacheDir,
21
22
  safelistOutputFile: options.safelistOutputFile,
22
- config: options.config ?? {},
23
+ config: configWithImportedStaticSz(options.config ?? {}, options.importedStaticSz),
23
24
  env: options.env ?? process.env,
24
25
  envKeys: options.envKeys,
25
26
  nextVersion: options.nextVersion ?? "unknown-next",
@@ -28,34 +29,49 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
28
29
  mode: options.mode ?? normalizeMode(loaderContext.mode)
29
30
  });
30
31
  assertProductionManifestReady(context, options);
32
+ const crossModule = resolveNextCrossModule({
33
+ filename: loaderContext.resourcePath,
34
+ source,
35
+ root: context.root,
36
+ importedStaticSz: options.importedStaticSz
37
+ });
31
38
  const transform = transformNextSource({
32
39
  source,
33
40
  filename: loaderContext.resourcePath,
34
41
  parserMode: options.parserMode ?? "rust",
35
- compilerOptions: options.compilerOptions,
42
+ compilerOptions: withCrossModuleStatics(options.compilerOptions, crossModule.statics),
36
43
  cacheRoot: resolveTransformCacheDir(
37
44
  context.root,
38
45
  path.relative(context.root, context.cacheDir)
39
46
  ),
40
47
  pluginVersion: options.csszyxVersion ?? readPackageVersion("../package.json", import.meta.url),
41
48
  compilerVersion: options.compilerVersion ?? readPackageVersion("../../compiler/package.json", import.meta.url),
42
- astBudget: options.astBudget,
43
- allowBabelFallback: options.allowBabelFallback
49
+ astBudget: options.astBudget
44
50
  });
45
51
  const injected = injectNextRuntimeImports(transform.result.code, transform.result);
52
+ const callsSzcn = transform.result.usesSzcn || /\bszcn\s*\(/.test(source);
53
+ const themeGroups = callsSzcn ? ensureThemeGroupsFile(context.root, path.join(context.root, ".csszyx")) : { file: null, watch: [] };
54
+ for (const stylesheet of themeGroups.watch) loaderContext.addDependency?.(stylesheet);
55
+ for (const provider of normalizeProviderPaths(crossModule.providers)) {
56
+ loaderContext.addDependency?.(provider);
57
+ }
58
+ const code = themeGroups.file === null ? injected.code : insertAfterUseDirective(
59
+ injected.code,
60
+ `import '${themeGroupsSpecifier(loaderContext.resourcePath, themeGroups.file)}';
61
+ `
62
+ );
46
63
  const metadata = collectNextTransformMetadata(
47
64
  transform.result,
48
65
  source,
49
66
  loaderContext.resourcePath
50
67
  );
51
- let shardPath = null;
52
68
  let materialized = false;
53
69
  const shardResult = writeNextSafelistShard(
54
70
  context.safelist.shardsDir,
55
71
  createNextSafelistShardFromMetadata(metadata, createShardCacheKey(context, metadata)),
56
72
  options.writeOptions
57
73
  );
58
- shardPath = shardResult.filePath;
74
+ const shardPath = shardResult.filePath;
59
75
  if (options.materializeSafelist !== false && shardResult.changed) {
60
76
  runNextWatcherCycle(context, {
61
77
  writeOptions: options.writeOptions,
@@ -68,12 +84,12 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
68
84
  materialized = true;
69
85
  }
70
86
  return {
71
- code: injected.code,
87
+ code,
72
88
  context,
73
89
  transform,
74
90
  shardPath,
75
91
  materialized,
76
- dependencies: []
92
+ dependencies: themeGroups.watch
77
93
  };
78
94
  }
79
95
  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';
@@ -1,10 +1,10 @@
1
1
  import { SourceTransformResult } from '@csszyx/compiler';
2
2
 
3
3
  /** Parser implementation that produced a cache entry. */
4
- type TransformCacheProducer = 'babel' | 'babel-fallback' | 'oxc' | 'rust';
4
+ type TransformCacheProducer = 'rust' | 'wasm';
5
5
 
6
6
  /** Parser mode supported by the Next Turbopack source transformer. */
7
- type NextSourceParserMode = 'babel' | 'oxc' | 'rust';
7
+ type NextSourceParserMode = 'rust' | 'wasm';
8
8
  /** Result of one source transform plus cache metadata for loader diagnostics. */
9
9
  interface NextSourceTransformOutput {
10
10
  result: SourceTransformResult;
@@ -1,10 +1,10 @@
1
1
  import { SourceTransformResult } from '@csszyx/compiler';
2
2
 
3
3
  /** Parser implementation that produced a cache entry. */
4
- type TransformCacheProducer = 'babel' | 'babel-fallback' | 'oxc' | 'rust';
4
+ type TransformCacheProducer = 'rust' | 'wasm';
5
5
 
6
6
  /** Parser mode supported by the Next Turbopack source transformer. */
7
- type NextSourceParserMode = 'babel' | 'oxc' | 'rust';
7
+ type NextSourceParserMode = 'rust' | 'wasm';
8
8
  /** Result of one source transform plus cache metadata for loader diagnostics. */
9
9
  interface NextSourceTransformOutput {
10
10
  result: SourceTransformResult;
@@ -1,11 +1,89 @@
1
1
  'use strict';
2
2
 
3
3
  const fs = require('node:fs');
4
+ const path = require('node:path');
4
5
  const compiler = require('@csszyx/compiler');
5
- const transformCache = require('./unplugin.DbZ7tCfN.cjs');
6
+ const types = require('@csszyx/types');
7
+ const transformCache = require('./unplugin.BKGCkMgM.cjs');
6
8
  const node_crypto = require('node:crypto');
7
9
  const htmlEscape = require('./unplugin.BkRah5Ot.cjs');
8
10
 
11
+ function _interopNamespaceCompat(e) {
12
+ if (e && typeof e === 'object' && 'default' in e) return e;
13
+ const n = Object.create(null);
14
+ if (e) {
15
+ for (const k in e) {
16
+ n[k] = e[k];
17
+ }
18
+ }
19
+ n.default = e;
20
+ return n;
21
+ }
22
+
23
+ const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
24
+
25
+ function resolveImportedStaticSz(value) {
26
+ return value ?? types.DEFAULT_IMPORTED_STATIC_SZ;
27
+ }
28
+ const aliasesByRoot = /* @__PURE__ */ new Map();
29
+ function resolveNextCrossModule(input) {
30
+ const empty = { statics: {}, providers: [] };
31
+ if (!input.source.includes("from")) return empty;
32
+ let aliases = aliasesByRoot.get(input.root);
33
+ if (aliases === void 0) {
34
+ aliases = transformCache.collectSpecifierAliases(input.root);
35
+ aliasesByRoot.set(input.root, aliases);
36
+ }
37
+ const directory = path__namespace.dirname(input.filename);
38
+ const statics = {};
39
+ const providers = [];
40
+ const seen = /* @__PURE__ */ new Set();
41
+ for (const specifier of transformCache.importedSpecifiersIn(input.source)) {
42
+ if (seen.has(specifier)) continue;
43
+ seen.add(specifier);
44
+ for (const base of transformCache.specifierBases(specifier, directory, aliases)) {
45
+ const provider = transformCache.resolveProviderPathWith(base, transformCache.isReadableProviderFile);
46
+ if (provider === void 0) continue;
47
+ providers.push(provider);
48
+ recordEntries(statics, specifier, readProviderEntries(provider), input);
49
+ break;
50
+ }
51
+ }
52
+ return { statics, providers };
53
+ }
54
+ function readProviderEntries(provider) {
55
+ try {
56
+ return compiler.extractCrossModuleRegistryEntries(fs.readFileSync(provider, "utf8"), provider);
57
+ } catch {
58
+ return [];
59
+ }
60
+ }
61
+ function recordEntries(statics, specifier, entries, input) {
62
+ for (const entry of entries) {
63
+ if (entry.kind === "sz-object" && !resolveImportedStaticSz(input.importedStaticSz)) {
64
+ continue;
65
+ }
66
+ transformCache.recordResolvedEntry(statics, entry.kind, specifier, entry.exportName, entry.value);
67
+ }
68
+ }
69
+ function withCrossModuleStatics(options, statics) {
70
+ if (statics.szvConfigs === void 0 && statics.szObjects === void 0) return options;
71
+ return {
72
+ ...options,
73
+ ...statics.szvConfigs === void 0 ? {} : { crossModuleStatics: statics.szvConfigs },
74
+ ...statics.szObjects === void 0 ? {} : { crossModuleSzObjects: statics.szObjects }
75
+ };
76
+ }
77
+ function configWithImportedStaticSz(config, importedStaticSz) {
78
+ return {
79
+ ...config,
80
+ importedStaticSz: resolveImportedStaticSz(importedStaticSz)
81
+ };
82
+ }
83
+ function normalizeProviderPaths(providers) {
84
+ return [...new Set(providers.map(transformCache.normalizePathSeparators))];
85
+ }
86
+
9
87
  function readPackageVersion(relativePackageJson, fromUrl) {
10
88
  try {
11
89
  const packageJson = JSON.parse(
@@ -128,34 +206,16 @@ function isRegexLiteralStart(emitted) {
128
206
  }
129
207
  function runNextSourceTransform(input, filename) {
130
208
  const compilerOptions = input.compilerOptions;
131
- if (input.parserMode === "babel") {
132
- return {
133
- result: compiler.transformSourceCode(input.source, filename, compilerOptions),
134
- producer: "babel"
135
- };
136
- }
137
209
  if (input.parserMode === "rust") {
138
210
  return {
139
211
  result: compiler.transformRust(input.source, filename, compilerOptions),
140
212
  producer: "rust"
141
213
  };
142
214
  }
143
- try {
144
- return {
145
- result: compiler.transformOxc(input.source, filename, compilerOptions),
146
- producer: "oxc"
147
- };
148
- } catch (error) {
149
- if (input.allowBabelFallback === false) {
150
- throw error;
151
- }
152
- const result = compiler.transformSourceCode(input.source, filename, compilerOptions);
153
- const reason = transformCache.babelFallbackReason(error);
154
- result.diagnostics.push(
155
- `[csszyx] oxc parser fell back to Babel for ${filename}: ${reason}`
156
- );
157
- return { result, producer: "babel-fallback" };
158
- }
215
+ return {
216
+ result: compiler.transformWasm(input.source, filename, compilerOptions),
217
+ producer: "wasm"
218
+ };
159
219
  }
160
220
  function createNextSourceTransformCacheInput(input, filename, producer) {
161
221
  return {
@@ -169,6 +229,12 @@ function createNextSourceTransformCacheInput(input, filename, producer) {
169
229
  globalVarAliases: normalizeGlobalVarAliasesForCache(
170
230
  input.compilerOptions?.globalVarAliases
171
231
  ),
232
+ // The registry slice this file was compiled against is part of its
233
+ // identity. Without it an edited provider serves its importers the
234
+ // cached output built from the value it used to have — the one failure
235
+ // this lane refused to risk before it resolved anything at all.
236
+ crossModuleStatics: input.compilerOptions?.crossModuleStatics === void 0 ? void 0 : JSON.stringify(input.compilerOptions.crossModuleStatics),
237
+ crossModuleSzObjects: input.compilerOptions?.crossModuleSzObjects === void 0 ? void 0 : JSON.stringify(input.compilerOptions.crossModuleSzObjects),
172
238
  filename,
173
239
  source: input.source
174
240
  };
@@ -278,6 +344,10 @@ function collectTransformClasses(result, discoveredClasses) {
278
344
  }
279
345
 
280
346
  exports.collectNextTransformMetadata = collectNextTransformMetadata;
347
+ exports.configWithImportedStaticSz = configWithImportedStaticSz;
281
348
  exports.createNextSafelistShardFromMetadata = createNextSafelistShardFromMetadata;
349
+ exports.normalizeProviderPaths = normalizeProviderPaths;
282
350
  exports.readPackageVersion = readPackageVersion;
351
+ exports.resolveNextCrossModule = resolveNextCrossModule;
283
352
  exports.transformNextSource = transformNextSource;
353
+ exports.withCrossModuleStatics = withCrossModuleStatics;