@csszyx/unplugin 0.16.0 → 0.17.1

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 (54) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs +15 -4
  3. package/dist/index.d.cts +2 -2
  4. package/dist/index.d.mts +2 -2
  5. package/dist/index.mjs +14 -4
  6. package/dist/jest-transform.cjs +186 -0
  7. package/dist/jest-transform.d.cts +112 -0
  8. package/dist/jest-transform.d.mts +110 -0
  9. package/dist/jest-transform.mjs +175 -0
  10. package/dist/next-prebuild.cjs +7 -6
  11. package/dist/next-prebuild.d.cts +12 -2
  12. package/dist/next-prebuild.d.mts +12 -2
  13. package/dist/next-prebuild.mjs +6 -5
  14. package/dist/next-turbo-loader.cjs +11 -9
  15. package/dist/next-turbo-loader.d.cts +1 -1
  16. package/dist/next-turbo-loader.d.mts +1 -1
  17. package/dist/next-turbo-loader.mjs +8 -6
  18. package/dist/next-watcher.cjs +124 -15
  19. package/dist/next-watcher.d.cts +16 -3
  20. package/dist/next-watcher.d.mts +16 -3
  21. package/dist/next-watcher.mjs +124 -15
  22. package/dist/shared/{unplugin.C-oQU1jl.mjs → unplugin.2uf-U76p.mjs} +1 -1
  23. package/dist/shared/{unplugin.BWnmKv07.cjs → unplugin.BKID6KXV.cjs} +5 -1
  24. package/dist/shared/{unplugin.PKo7wFzu.d.cts → unplugin.BO2_hyS3.d.cts} +38 -5
  25. package/dist/shared/{unplugin.DH_ij6cf.mjs → unplugin.Ba3O1r8M.mjs} +2 -6
  26. package/dist/shared/unplugin.BqKLlo1h.cjs +8 -0
  27. package/dist/shared/{unplugin.Vn9x8SBP.mjs → unplugin.C3bgc29e.mjs} +3 -2
  28. package/dist/shared/{unplugin.Ceq-N4jI.mjs → unplugin.CK-DfKTP.mjs} +21 -111
  29. package/dist/shared/{unplugin.COlI0dJs.d.mts → unplugin.C_2R8vIk.d.cts} +1 -1
  30. package/dist/shared/unplugin.CcSfaIVx.mjs +13547 -0
  31. package/dist/shared/{unplugin.rWOMecQs.d.cts → unplugin.CfXjAV63.d.mts} +1 -1
  32. package/dist/shared/{unplugin.J6ue_lRJ.cjs → unplugin.D0tMgokL.cjs} +24 -115
  33. package/dist/shared/{unplugin.DDSWQJYX.cjs → unplugin.DS6CFjim.cjs} +3 -8
  34. package/dist/shared/{unplugin.gksolKh2.cjs → unplugin.DXzIP7lP.cjs} +5 -4
  35. package/dist/shared/unplugin.DZdsqdQa.cjs +13635 -0
  36. package/dist/shared/unplugin.DcXM9sq5.mjs +109 -0
  37. package/dist/shared/unplugin.Defu9wGh.cjs +115 -0
  38. package/dist/shared/{unplugin.Bu2rzRtv.d.mts → unplugin.DptK3pl4.d.mts} +38 -5
  39. package/dist/shared/{unplugin.BGog1Bib.d.cts → unplugin.XdPo6azz.d.cts} +3 -0
  40. package/dist/shared/{unplugin.BGog1Bib.d.mts → unplugin.XdPo6azz.d.mts} +3 -0
  41. package/dist/shared/{unplugin.BzF0V2kw.cjs → unplugin.YcnV3Izb.cjs} +6 -6
  42. package/dist/shared/{unplugin.BLptVbUe.mjs → unplugin.eCo7_znv.mjs} +4 -2
  43. package/dist/shared/unplugin.wMeicb6E.mjs +6 -0
  44. package/dist/vite.cjs +14 -4
  45. package/dist/vite.d.cts +2 -2
  46. package/dist/vite.d.mts +1 -1
  47. package/dist/vite.mjs +14 -4
  48. package/dist/webpack.cjs +14 -4
  49. package/dist/webpack.d.cts +1 -2
  50. package/dist/webpack.d.mts +1 -1
  51. package/dist/webpack.mjs +14 -4
  52. package/package.json +22 -11
  53. package/dist/shared/unplugin.D3yBoTHP.cjs +0 -5462
  54. package/dist/shared/unplugin.Dx0ngYWw.mjs +0 -5381
@@ -0,0 +1,175 @@
1
+ import { createHash } from 'node:crypto';
2
+ import fs__default from 'node:fs';
3
+ import path__default from 'node:path';
4
+ import { VERSION, transformSource, szFallbackConsequenceOf } from '@csszyx/compiler';
5
+ import { i as injectNextRuntimeImports } from './shared/unplugin.DcXM9sq5.mjs';
6
+ import { n as normalizePathSeparators } from './shared/unplugin.wMeicb6E.mjs';
7
+
8
+ const SETTLE_MS = 2e3;
9
+ function mtimeOf(dir) {
10
+ try {
11
+ return fs__default.statSync(dir).mtimeMs;
12
+ } catch {
13
+ return -1;
14
+ }
15
+ }
16
+ function settled(mtime) {
17
+ return Date.now() - mtime < SETTLE_MS ? -1 : mtime;
18
+ }
19
+ function writtenAt(entry) {
20
+ return typeof entry.timestamp === "string" ? entry.timestamp : "";
21
+ }
22
+ class TransformCacheIndex {
23
+ /** Directories seen, with the modification time they were last read at. */
24
+ dirs = /* @__PURE__ */ new Map();
25
+ seen = /* @__PURE__ */ new Set();
26
+ byFilename = /* @__PURE__ */ new Map();
27
+ /**
28
+ * @param root - The transform cache directory.
29
+ */
30
+ constructor(root) {
31
+ this.dirs.set(root, -1);
32
+ }
33
+ /**
34
+ * Read every entry file written since the last refresh.
35
+ */
36
+ refresh() {
37
+ const moved = [];
38
+ for (const [dir, readAt] of this.dirs) {
39
+ const mtime = mtimeOf(dir);
40
+ if (mtime !== readAt) moved.push(dir);
41
+ }
42
+ for (const dir of moved) {
43
+ this.dirs.set(dir, settled(mtimeOf(dir)));
44
+ this.readDir(dir);
45
+ }
46
+ }
47
+ /**
48
+ * Parse the entry files in one directory the index has not read yet.
49
+ *
50
+ * @param dir - The directory.
51
+ */
52
+ readDir(dir) {
53
+ let names;
54
+ try {
55
+ names = fs__default.readdirSync(dir, { withFileTypes: true });
56
+ } catch {
57
+ return;
58
+ }
59
+ for (const entry of names) {
60
+ const full = path__default.join(dir, entry.name);
61
+ if (entry.isDirectory()) {
62
+ if (!this.dirs.has(full)) {
63
+ this.dirs.set(full, settled(mtimeOf(full)));
64
+ this.readDir(full);
65
+ }
66
+ continue;
67
+ }
68
+ if (!entry.name.endsWith(".json") || this.seen.has(full)) continue;
69
+ this.seen.add(full);
70
+ this.add(full);
71
+ }
72
+ }
73
+ /**
74
+ * Parse one entry file into the index.
75
+ *
76
+ * @param file - The entry file.
77
+ */
78
+ add(file) {
79
+ let entry;
80
+ try {
81
+ entry = JSON.parse(fs__default.readFileSync(file, "utf8"));
82
+ } catch {
83
+ return;
84
+ }
85
+ if (typeof entry.filename !== "string") return;
86
+ const list = this.byFilename.get(entry.filename) ?? [];
87
+ list.push(entry);
88
+ this.byFilename.set(entry.filename, list);
89
+ }
90
+ /**
91
+ * The build output for one file, when the build saw exactly these contents.
92
+ *
93
+ * @param filename - Path of the file under test, as the plugin records it.
94
+ * @param source - Its current contents.
95
+ * @returns The matching entry's result, or null.
96
+ */
97
+ find(filename, source) {
98
+ const wanted = createHash("sha256").update(source).digest("hex");
99
+ const hit = this.pick(filename, wanted);
100
+ if (hit !== null) return hit;
101
+ this.refresh();
102
+ return this.pick(filename, wanted);
103
+ }
104
+ /**
105
+ * The best entry among those recorded for one file and hash.
106
+ *
107
+ * The plugin keys its cache on more than the source — the compiler that
108
+ * wrote the entry, whether variables were mangled, the cross-module
109
+ * registry — so one file and hash can have several entries. A test wants
110
+ * the output this compiler produces with readable variable names, and of
111
+ * those the newest.
112
+ *
113
+ * @param filename - Path as the plugin records it.
114
+ * @param sha256 - Hash of the current contents.
115
+ * @returns The chosen entry's result, or null when none qualifies.
116
+ */
117
+ pick(filename, sha256) {
118
+ let best = null;
119
+ for (const entry of this.byFilename.get(filename) ?? []) {
120
+ if (entry.inputSha256 !== sha256) continue;
121
+ if (entry.compilerVersion !== VERSION || entry.mangleVars === true) continue;
122
+ if (typeof entry.result?.code !== "string") continue;
123
+ if (best === null || writtenAt(entry) > writtenAt(best)) {
124
+ best = entry;
125
+ }
126
+ }
127
+ return best?.result ?? null;
128
+ }
129
+ }
130
+ function findCachedTransform(cacheRoot, filename, source) {
131
+ const index = new TransformCacheIndex(cacheRoot);
132
+ index.refresh();
133
+ const code = index.find(normalizePathSeparators(filename), source)?.code;
134
+ return typeof code === "string" ? code : null;
135
+ }
136
+ const DEFAULT_EXTENSIONS = [".tsx", ".jsx", ".ts", ".js", ".mts", ".mjs"];
137
+ function reportDeadClasses(sourcePath, diagnostics) {
138
+ if (!Array.isArray(diagnostics)) return;
139
+ for (const message of diagnostics) {
140
+ if (typeof message !== "string" || szFallbackConsequenceOf(message) === "nudge") continue;
141
+ console.warn(`[csszyx] ${sourcePath}
142
+ ${message}`);
143
+ }
144
+ }
145
+ function finish(code, usage) {
146
+ return injectNextRuntimeImports(code, usage).code;
147
+ }
148
+ function createTransformer(options = {}) {
149
+ const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
150
+ const cacheRoot = options.cacheRoot ?? path__default.resolve(process.cwd(), ".csszyx/cache", "transform");
151
+ const index = new TransformCacheIndex(cacheRoot);
152
+ index.refresh();
153
+ const compiles = (sourcePath) => extensions.some((extension) => sourcePath.endsWith(extension));
154
+ const cached = (sourceText, sourcePath) => index.find(normalizePathSeparators(sourcePath), sourceText);
155
+ return {
156
+ process(sourceText, sourcePath) {
157
+ if (!compiles(sourcePath)) return { code: sourceText };
158
+ const built = cached(sourceText, sourcePath);
159
+ if (built !== null && typeof built.code === "string") {
160
+ reportDeadClasses(sourcePath, built.diagnostics);
161
+ return { code: finish(built.code, built) };
162
+ }
163
+ const result = transformSource(sourceText, sourcePath);
164
+ reportDeadClasses(sourcePath, result.diagnostics);
165
+ return { code: result.transformed ? finish(result.code, result) : sourceText };
166
+ },
167
+ getCacheKey(sourceText, sourcePath, cacheKeyOptions) {
168
+ const built = compiles(sourcePath) ? cached(sourceText, sourcePath) : null;
169
+ return createHash("sha256").update(sourceText).update("\0").update(sourcePath).update("\0").update(typeof built?.code === "string" ? built.code : "").update("\0").update(cacheKeyOptions?.configString ?? "").update("\0").update(VERSION).digest("hex");
170
+ }
171
+ };
172
+ }
173
+ const transformerModule = { createTransformer };
174
+
175
+ export { createTransformer, transformerModule as default, findCachedTransform };
@@ -3,10 +3,11 @@
3
3
  const node_crypto = require('node:crypto');
4
4
  const fs = require('node:fs');
5
5
  const path = require('node:path');
6
- const nextTransformMetadata = require('./shared/unplugin.gksolKh2.cjs');
7
- const nextWatcherCycle = require('./shared/unplugin.BWnmKv07.cjs');
8
- const safelistSource = require('./shared/unplugin.DDSWQJYX.cjs');
9
- const transformCache = require('./shared/unplugin.BzF0V2kw.cjs');
6
+ const nextTransformMetadata = require('./shared/unplugin.DXzIP7lP.cjs');
7
+ const nextWatcherCycle = require('./shared/unplugin.BKID6KXV.cjs');
8
+ const pathNormalization = require('./shared/unplugin.BqKLlo1h.cjs');
9
+ const safelistSource = require('./shared/unplugin.DS6CFjim.cjs');
10
+ const transformCache = require('./shared/unplugin.YcnV3Izb.cjs');
10
11
  require('@csszyx/compiler');
11
12
  require('@csszyx/types');
12
13
  require('node:os');
@@ -103,7 +104,7 @@ function runNextPrebuild(options) {
103
104
  lockOptions: {
104
105
  root: context.root,
105
106
  mode: context.manifestExpectation.mode,
106
- command: "csszyx next prebuild"
107
+ command: options.lockCommand ?? nextWatcherCycle.NEXT_PREBUILD_LOCK_COMMAND
107
108
  },
108
109
  createdAt: options.createdAt
109
110
  });
@@ -153,7 +154,7 @@ function uniqueFiles(files) {
153
154
  return result;
154
155
  }
155
156
  function createShardCacheKey(context, metadata) {
156
- return node_crypto.createHash("sha256").update(context.identity.generation).update("\0").update(safelistSource.normalizePathSeparators(path__namespace.relative(context.root, metadata.sourcePath))).digest("hex");
157
+ return node_crypto.createHash("sha256").update(context.identity.generation).update("\0").update(pathNormalization.normalizePathSeparators(path__namespace.relative(context.root, metadata.sourcePath))).digest("hex");
157
158
  }
158
159
 
159
160
  exports.runNextPrebuild = runNextPrebuild;
@@ -1,7 +1,7 @@
1
1
  import { TransformSourceCodeOptions } from '@csszyx/compiler';
2
- import { J as JsonLike, A as AtomicWriteOptions, N as NextStateContext } from './shared/unplugin.BGog1Bib.cjs';
2
+ import { J as JsonLike, A as AtomicWriteOptions, N as NextStateContext } from './shared/unplugin.XdPo6azz.cjs';
3
3
  import { N as NextSourceTransformOutput, a as NextSourceParserMode } from './shared/unplugin.B32Exn-K.cjs';
4
- import { N as NextWatcherCycleResult } from './shared/unplugin.rWOMecQs.cjs';
4
+ import { N as NextWatcherCycleResult } from './shared/unplugin.C_2R8vIk.cjs';
5
5
 
6
6
  /** Serializable options accepted by the Next Turbopack csszyx prebuild core. */
7
7
  interface NextPrebuildOptions {
@@ -35,6 +35,16 @@ interface NextPrebuildOptions {
35
35
  allowProductionMangling?: boolean;
36
36
  writeOptions?: AtomicWriteOptions;
37
37
  createdAt?: string;
38
+ /**
39
+ * What this pass records on the state lock; `csszyx next prebuild` by
40
+ * default.
41
+ *
42
+ * The Turbopack loader steps aside only for a watcher's command. `next
43
+ * watch` passes that command here because its initial cycle follows this
44
+ * pass and reads every shard the loader wrote meanwhile. A standalone
45
+ * prebuild keeps the default: nothing after it would pick those shards up.
46
+ */
47
+ lockCommand?: string;
38
48
  }
39
49
  /** Per-file result captured by one prebuild pass. */
40
50
  interface NextPrebuildFileResult {
@@ -1,7 +1,7 @@
1
1
  import { TransformSourceCodeOptions } from '@csszyx/compiler';
2
- import { J as JsonLike, A as AtomicWriteOptions, N as NextStateContext } from './shared/unplugin.BGog1Bib.mjs';
2
+ import { J as JsonLike, A as AtomicWriteOptions, N as NextStateContext } from './shared/unplugin.XdPo6azz.mjs';
3
3
  import { N as NextSourceTransformOutput, a as NextSourceParserMode } from './shared/unplugin.B32Exn-K.mjs';
4
- import { N as NextWatcherCycleResult } from './shared/unplugin.COlI0dJs.mjs';
4
+ import { N as NextWatcherCycleResult } from './shared/unplugin.CfXjAV63.mjs';
5
5
 
6
6
  /** Serializable options accepted by the Next Turbopack csszyx prebuild core. */
7
7
  interface NextPrebuildOptions {
@@ -35,6 +35,16 @@ interface NextPrebuildOptions {
35
35
  allowProductionMangling?: boolean;
36
36
  writeOptions?: AtomicWriteOptions;
37
37
  createdAt?: string;
38
+ /**
39
+ * What this pass records on the state lock; `csszyx next prebuild` by
40
+ * default.
41
+ *
42
+ * The Turbopack loader steps aside only for a watcher's command. `next
43
+ * watch` passes that command here because its initial cycle follows this
44
+ * pass and reads every shard the loader wrote meanwhile. A standalone
45
+ * prebuild keeps the default: nothing after it would pick those shards up.
46
+ */
47
+ lockCommand?: string;
38
48
  }
39
49
  /** Per-file result captured by one prebuild pass. */
40
50
  interface NextPrebuildFileResult {
@@ -1,10 +1,11 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import * as path from 'node:path';
4
- import { r as readPackageVersion, c as configWithImportedStaticSz, a as resolveNextCrossModule, t as transformNextSource, w as withCrossModuleStatics, b as collectNextTransformMetadata, d as createNextSafelistShardFromMetadata } from './shared/unplugin.Vn9x8SBP.mjs';
5
- import { c as createNextStateContext, w as writeNextSafelistShard, r as runNextWatcherCycle } from './shared/unplugin.BLptVbUe.mjs';
6
- import { f as findPostcssConfigWithoutCsszyx, m as missingPostcssPluginMessage, n as normalizePathSeparators } from './shared/unplugin.DH_ij6cf.mjs';
7
- import { r as resolveTransformCacheDir } from './shared/unplugin.C-oQU1jl.mjs';
4
+ import { r as readPackageVersion, c as configWithImportedStaticSz, a as resolveNextCrossModule, t as transformNextSource, w as withCrossModuleStatics, b as collectNextTransformMetadata, d as createNextSafelistShardFromMetadata } from './shared/unplugin.C3bgc29e.mjs';
5
+ import { c as createNextStateContext, w as writeNextSafelistShard, r as runNextWatcherCycle, N as NEXT_PREBUILD_LOCK_COMMAND } from './shared/unplugin.eCo7_znv.mjs';
6
+ import { n as normalizePathSeparators } from './shared/unplugin.wMeicb6E.mjs';
7
+ import { f as findPostcssConfigWithoutCsszyx, m as missingPostcssPluginMessage } from './shared/unplugin.Ba3O1r8M.mjs';
8
+ import { r as resolveTransformCacheDir } from './shared/unplugin.2uf-U76p.mjs';
8
9
  import '@csszyx/compiler';
9
10
  import '@csszyx/types';
10
11
  import 'node:os';
@@ -86,7 +87,7 @@ function runNextPrebuild(options) {
86
87
  lockOptions: {
87
88
  root: context.root,
88
89
  mode: context.manifestExpectation.mode,
89
- command: "csszyx next prebuild"
90
+ command: options.lockCommand ?? NEXT_PREBUILD_LOCK_COMMAND
90
91
  },
91
92
  createdAt: options.createdAt
92
93
  });
@@ -4,14 +4,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const node_crypto = require('node:crypto');
6
6
  const path = require('node:path');
7
- const themeGroupsFile = require('./shared/unplugin.J6ue_lRJ.cjs');
8
- const nextTransformMetadata = require('./shared/unplugin.gksolKh2.cjs');
9
- const nextWatcherCycle = require('./shared/unplugin.BWnmKv07.cjs');
10
- const safelistSource = require('./shared/unplugin.DDSWQJYX.cjs');
11
- const transformCache = require('./shared/unplugin.BzF0V2kw.cjs');
7
+ const nextRuntimeInjection = require('./shared/unplugin.Defu9wGh.cjs');
8
+ const nextTransformMetadata = require('./shared/unplugin.DXzIP7lP.cjs');
9
+ const nextWatcherCycle = require('./shared/unplugin.BKID6KXV.cjs');
10
+ const pathNormalization = require('./shared/unplugin.BqKLlo1h.cjs');
11
+ const themeGroupsFile = require('./shared/unplugin.D0tMgokL.cjs');
12
+ const transformCache = require('./shared/unplugin.YcnV3Izb.cjs');
12
13
  require('node:fs');
13
14
  require('@csszyx/compiler');
14
15
  require('@csszyx/types');
16
+ require('./shared/unplugin.DS6CFjim.cjs');
15
17
  require('node:os');
16
18
  require('proper-lockfile');
17
19
 
@@ -67,14 +69,14 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
67
69
  compilerVersion: options.compilerVersion ?? nextTransformMetadata.readPackageVersion("../../compiler/package.json", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('next-turbo-loader.cjs', document.baseURI).href))),
68
70
  astBudget: options.astBudget
69
71
  });
70
- const injected = themeGroupsFile.injectNextRuntimeImports(transform.result.code, transform.result);
72
+ const injected = nextRuntimeInjection.injectNextRuntimeImports(transform.result.code, transform.result);
71
73
  const callsSzcn = transform.result.usesSzcn || /\bszcn\s*\(/.test(source);
72
74
  const themeGroups = callsSzcn ? themeGroupsFile.ensureThemeGroupsFile(context.root, path__namespace.join(context.root, ".csszyx")) : { file: null, watch: [] };
73
75
  for (const stylesheet of themeGroups.watch) loaderContext.addDependency?.(stylesheet);
74
76
  for (const provider of nextTransformMetadata.normalizeProviderPaths(crossModule.providers)) {
75
77
  loaderContext.addDependency?.(provider);
76
78
  }
77
- const code = themeGroups.file === null ? injected.code : themeGroupsFile.insertAfterUseDirective(
79
+ const code = themeGroups.file === null ? injected.code : nextRuntimeInjection.insertAfterUseDirective(
78
80
  injected.code,
79
81
  `import '${themeGroupsFile.themeGroupsSpecifier(loaderContext.resourcePath, themeGroups.file)}';
80
82
  `
@@ -98,7 +100,7 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
98
100
  lockOptions: {
99
101
  root: context.root,
100
102
  mode: context.manifestExpectation.mode,
101
- command: "csszyx next turbo-loader"
103
+ command: nextWatcherCycle.NEXT_TURBO_LOADER_LOCK_COMMAND
102
104
  }
103
105
  });
104
106
  materialized = true;
@@ -192,7 +194,7 @@ function hasEnabledMangleVars(config) {
192
194
  return config.mangleVars === true;
193
195
  }
194
196
  function createShardCacheKey(context, metadata) {
195
- return node_crypto.createHash("sha256").update(context.identity.generation).update("\0").update(safelistSource.normalizePathSeparators(path__namespace.relative(context.root, metadata.sourcePath))).digest("hex");
197
+ return node_crypto.createHash("sha256").update(context.identity.generation).update("\0").update(pathNormalization.normalizePathSeparators(path__namespace.relative(context.root, metadata.sourcePath))).digest("hex");
196
198
  }
197
199
 
198
200
  exports.default = nextTurboLoader;
@@ -1,5 +1,5 @@
1
1
  import { TransformSourceCodeOptions } from '@csszyx/compiler';
2
- import { J as JsonLike, A as AtomicWriteOptions, N as NextStateContext } from './shared/unplugin.BGog1Bib.cjs';
2
+ import { J as JsonLike, A as AtomicWriteOptions, N as NextStateContext } from './shared/unplugin.XdPo6azz.cjs';
3
3
  import { a as NextSourceParserMode, N as NextSourceTransformOutput } from './shared/unplugin.B32Exn-K.cjs';
4
4
 
5
5
  /** Serializable options accepted by the Next Turbopack csszyx loader. */
@@ -1,5 +1,5 @@
1
1
  import { TransformSourceCodeOptions } from '@csszyx/compiler';
2
- import { J as JsonLike, A as AtomicWriteOptions, N as NextStateContext } from './shared/unplugin.BGog1Bib.mjs';
2
+ import { J as JsonLike, A as AtomicWriteOptions, N as NextStateContext } from './shared/unplugin.XdPo6azz.mjs';
3
3
  import { a as NextSourceParserMode, N as NextSourceTransformOutput } from './shared/unplugin.B32Exn-K.mjs';
4
4
 
5
5
  /** Serializable options accepted by the Next Turbopack csszyx loader. */
@@ -1,13 +1,15 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import * as path from 'node:path';
3
- import { i as injectNextRuntimeImports, e as ensureThemeGroupsFile, b as insertAfterUseDirective, t as themeGroupsSpecifier } from './shared/unplugin.Ceq-N4jI.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.Vn9x8SBP.mjs';
5
- import { c as createNextStateContext, w as writeNextSafelistShard, r as runNextWatcherCycle, N as NextSafelistStateLockedError, a as NEXT_WATCH_LOCK_COMMAND, v as validateNextGenerationManifest, b as readNextGenerationManifest } from './shared/unplugin.BLptVbUe.mjs';
6
- import { n as normalizePathSeparators } from './shared/unplugin.DH_ij6cf.mjs';
7
- import { r as resolveTransformCacheDir } from './shared/unplugin.C-oQU1jl.mjs';
3
+ import { i as injectNextRuntimeImports, a as insertAfterUseDirective } from './shared/unplugin.DcXM9sq5.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.C3bgc29e.mjs';
5
+ import { c as createNextStateContext, w as writeNextSafelistShard, r as runNextWatcherCycle, a as NEXT_TURBO_LOADER_LOCK_COMMAND, b as NextSafelistStateLockedError, d as NEXT_WATCH_LOCK_COMMAND, v as validateNextGenerationManifest, e as readNextGenerationManifest } from './shared/unplugin.eCo7_znv.mjs';
6
+ import { n as normalizePathSeparators } from './shared/unplugin.wMeicb6E.mjs';
7
+ import { e as ensureThemeGroupsFile, t as themeGroupsSpecifier } from './shared/unplugin.CK-DfKTP.mjs';
8
+ import { r as resolveTransformCacheDir } from './shared/unplugin.2uf-U76p.mjs';
8
9
  import 'node:fs';
9
10
  import '@csszyx/compiler';
10
11
  import '@csszyx/types';
12
+ import './shared/unplugin.Ba3O1r8M.mjs';
11
13
  import 'node:os';
12
14
  import 'proper-lockfile';
13
15
 
@@ -79,7 +81,7 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
79
81
  lockOptions: {
80
82
  root: context.root,
81
83
  mode: context.manifestExpectation.mode,
82
- command: "csszyx next turbo-loader"
84
+ command: NEXT_TURBO_LOADER_LOCK_COMMAND
83
85
  }
84
86
  });
85
87
  materialized = true;
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  const path = require('node:path');
4
- const nextWatcherCycle = require('./shared/unplugin.BWnmKv07.cjs');
4
+ const nextWatcherCycle = require('./shared/unplugin.BKID6KXV.cjs');
5
5
  require('node:fs');
6
- require('./shared/unplugin.DDSWQJYX.cjs');
6
+ require('./shared/unplugin.DS6CFjim.cjs');
7
7
  require('node:crypto');
8
+ require('./shared/unplugin.BqKLlo1h.cjs');
8
9
  require('node:os');
9
10
  require('proper-lockfile');
10
11
 
@@ -22,6 +23,12 @@ function _interopNamespaceCompat(e) {
22
23
 
23
24
  const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
24
25
 
26
+ const LOADER_LOCK_RETRY_MIN_MS = 50;
27
+ const LOADER_LOCK_WARN_AFTER_MS = 1e3;
28
+ const LOADER_LOCK_GIVE_UP_AFTER_MS = 6e4;
29
+ function isHeldByTurbopackLoader(error) {
30
+ return error instanceof nextWatcherCycle.NextSafelistStateLockedError && error.holder.command === nextWatcherCycle.NEXT_TURBO_LOADER_LOCK_COMMAND;
31
+ }
25
32
  class NextWatcherLoop {
26
33
  context;
27
34
  cycleOptions;
@@ -29,10 +36,15 @@ class NextWatcherLoop {
29
36
  runCycle;
30
37
  setTimeoutFn;
31
38
  clearTimeoutFn;
39
+ nowFn;
32
40
  onError;
41
+ onWarn;
33
42
  timer;
34
43
  disposed = false;
35
44
  pendingReasons = /* @__PURE__ */ new Set();
45
+ /** When the current wait on the loader's lock began; unset while not waiting. */
46
+ loaderWaitStartedAt;
47
+ loaderWaitWarned = false;
36
48
  lastResult;
37
49
  lastError;
38
50
  /**
@@ -46,7 +58,9 @@ class NextWatcherLoop {
46
58
  this.runCycle = options.runCycle ?? nextWatcherCycle.runNextWatcherCycle;
47
59
  this.setTimeoutFn = options.setTimeout ?? setTimeout;
48
60
  this.clearTimeoutFn = options.clearTimeout ?? clearTimeout;
61
+ this.nowFn = options.now ?? Date.now;
49
62
  this.onError = options.onError;
63
+ this.onWarn = options.onWarn;
50
64
  }
51
65
  /**
52
66
  *
@@ -69,17 +83,7 @@ class NextWatcherLoop {
69
83
  return;
70
84
  }
71
85
  this.pendingReasons.add(reason);
72
- if (this.timer !== void 0) {
73
- return;
74
- }
75
- this.timer = this.setTimeoutFn(() => {
76
- try {
77
- this.runPendingCycle();
78
- } catch (error) {
79
- this.lastError = error;
80
- this.onError?.(error);
81
- }
82
- }, this.debounceMs);
86
+ this.schedule(this.debounceMs);
83
87
  }
84
88
  /**
85
89
  *
@@ -90,6 +94,32 @@ class NextWatcherLoop {
90
94
  }
91
95
  return this.runPendingCycle();
92
96
  }
97
+ /**
98
+ * Run the pending cycle now, or queue it when the Turbopack loader holds the
99
+ * lock.
100
+ *
101
+ * `flush` throws on every failure, which is what closing needs. Starting
102
+ * needs this instead: `next watch` and `next dev` start together, so the
103
+ * loader's first compile can hold the lock exactly when the initial cycle
104
+ * runs, and that overlap is not a failure.
105
+ *
106
+ * @returns The cycle result, or `undefined` when nothing was pending or the
107
+ * cycle is queued behind the loader.
108
+ */
109
+ flushOrQueue() {
110
+ if (this.disposed || this.timer === void 0) {
111
+ return void 0;
112
+ }
113
+ const reasons = [...this.pendingReasons];
114
+ try {
115
+ return this.runPendingCycle();
116
+ } catch (error) {
117
+ if (this.waitForLoader(error, reasons)) {
118
+ return void 0;
119
+ }
120
+ throw error;
121
+ }
122
+ }
93
123
  /**
94
124
  *
95
125
  */
@@ -101,6 +131,75 @@ class NextWatcherLoop {
101
131
  this.pendingReasons.clear();
102
132
  this.disposed = true;
103
133
  }
134
+ /**
135
+ * Run the pending cycle after `delayMs`, unless a run is already scheduled.
136
+ *
137
+ * @param delayMs - How long to wait before running it.
138
+ */
139
+ schedule(delayMs) {
140
+ if (this.timer !== void 0) {
141
+ return;
142
+ }
143
+ this.timer = this.setTimeoutFn(() => {
144
+ const reasons = [...this.pendingReasons];
145
+ try {
146
+ this.runPendingCycle();
147
+ } catch (error) {
148
+ if (this.waitForLoader(error, reasons)) {
149
+ return;
150
+ }
151
+ this.lastError = error;
152
+ this.onError?.(error);
153
+ }
154
+ }, delayMs);
155
+ }
156
+ /**
157
+ * Queue a cycle again when it failed only because the Turbopack loader holds
158
+ * the lock.
159
+ *
160
+ * Retried, not dropped: the loader's pass read the shards as they stood when
161
+ * it began, and the event that woke this cycle may be newer. The wait is
162
+ * timed from the first refusal, says so once when it runs long, and ends in
163
+ * a reported failure when it runs longer than any live loader could explain.
164
+ *
165
+ * @param error - What the cycle threw.
166
+ * @param reasons - The reasons the failed cycle carried, queued again with it.
167
+ * @returns True when nothing should be reported: the cycle is queued, or the
168
+ * loop was disposed meanwhile.
169
+ */
170
+ waitForLoader(error, reasons) {
171
+ if (!isHeldByTurbopackLoader(error)) {
172
+ return false;
173
+ }
174
+ const now = this.nowFn();
175
+ this.loaderWaitStartedAt ??= now;
176
+ const waited = now - this.loaderWaitStartedAt;
177
+ if (waited > LOADER_LOCK_GIVE_UP_AFTER_MS) {
178
+ this.endLoaderWait();
179
+ return false;
180
+ }
181
+ if (waited >= LOADER_LOCK_WARN_AFTER_MS && !this.loaderWaitWarned) {
182
+ this.loaderWaitWarned = true;
183
+ const warn = this.onWarn ?? (() => {
184
+ });
185
+ warn(
186
+ `[csszyx] next watch is waiting for the safelist lock held by the Turbopack loader (process ${error.holder.pid}). Classes added meanwhile get no CSS until it is released; a lock left by a loader that exited is recovered within 30 s.`
187
+ );
188
+ }
189
+ if (this.disposed) {
190
+ return true;
191
+ }
192
+ for (const reason of reasons) {
193
+ this.pendingReasons.add(reason);
194
+ }
195
+ this.schedule(Math.max(this.debounceMs, LOADER_LOCK_RETRY_MIN_MS));
196
+ return true;
197
+ }
198
+ /** Forget the current wait on the loader, once a cycle gets through or gives up. */
199
+ endLoaderWait() {
200
+ this.loaderWaitStartedAt = void 0;
201
+ this.loaderWaitWarned = false;
202
+ }
104
203
  /**
105
204
  *
106
205
  */
@@ -115,6 +214,7 @@ class NextWatcherLoop {
115
214
  const result = this.runCycle(this.context, this.cycleOptions, reasons);
116
215
  this.lastResult = result;
117
216
  this.lastError = void 0;
217
+ this.endLoaderWait();
118
218
  return result;
119
219
  }
120
220
  }
@@ -168,6 +268,14 @@ class NextSafelistWatcher {
168
268
  }
169
269
  /**
170
270
  * Materialize existing shards before accepting live filesystem events.
271
+ *
272
+ * `next watch` and `next dev` start together in the documented setup, so
273
+ * the Turbopack loader's first compile can hold the state lock at this
274
+ * exact moment. The initial cycle is then queued behind it instead of
275
+ * throwing, the same way a scheduled cycle waits.
276
+ *
277
+ * @returns The initial cycle's result, or `undefined` while it is queued
278
+ * behind the Turbopack loader.
171
279
  */
172
280
  start() {
173
281
  if (this.closed) {
@@ -178,8 +286,8 @@ class NextSafelistWatcher {
178
286
  }
179
287
  this.started = true;
180
288
  this.loop.notify("initial");
181
- const result = this.loop.flush();
182
- if (!result) {
289
+ const result = this.loop.flushOrQueue();
290
+ if (!result && !this.loop.pending) {
183
291
  throw new Error("[csszyx] Next safelist watcher failed to run its initial cycle.");
184
292
  }
185
293
  return result;
@@ -233,6 +341,7 @@ class NextSafelistWatcher {
233
341
  }
234
342
  }
235
343
 
344
+ exports.NEXT_WATCH_LOCK_COMMAND = nextWatcherCycle.NEXT_WATCH_LOCK_COMMAND;
236
345
  exports.NextSafelistWatcher = NextSafelistWatcher;
237
346
  exports.isNextAppSourcePath = isNextAppSourcePath;
238
347
  exports.isNextSafelistShardPath = isNextSafelistShardPath;
@@ -1,5 +1,6 @@
1
- import { N as NextStateContext } from './shared/unplugin.BGog1Bib.cjs';
2
- import { a as NextWatcherCycleOptions, N as NextWatcherCycleResult } from './shared/unplugin.rWOMecQs.cjs';
1
+ import { N as NextStateContext } from './shared/unplugin.XdPo6azz.cjs';
2
+ export { c as NEXT_WATCH_LOCK_COMMAND } from './shared/unplugin.XdPo6azz.cjs';
3
+ import { a as NextWatcherCycleOptions, N as NextWatcherCycleResult } from './shared/unplugin.C_2R8vIk.cjs';
3
4
 
4
5
  /**
5
6
  *
@@ -11,6 +12,8 @@ type NextWatcherLoopCycleRunner = (context: NextStateContext, options: NextWatch
11
12
  interface NextWatcherLoopTimerHooks {
12
13
  setTimeout?: (callback: () => void, delayMs: number) => WatcherTimer;
13
14
  clearTimeout?: (timer: WatcherTimer) => void;
15
+ /** Clock that times a wait on the loader's lock; `Date.now` by default. */
16
+ now?: () => number;
14
17
  }
15
18
 
16
19
  /** Filesystem events that can change the materialized safelist. */
@@ -22,6 +25,8 @@ interface NextSafelistWatcherOptions extends NextWatcherLoopTimerHooks {
22
25
  debounceMs?: number;
23
26
  runCycle?: NextWatcherLoopCycleRunner;
24
27
  onError?: (error: unknown) => void;
28
+ /** Receives a notice the watcher keeps running through; dropped by default. */
29
+ onWarn?: (message: string) => void;
25
30
  }
26
31
  /**
27
32
  * Validate one watcher event path against the flat safelist shard directory.
@@ -75,8 +80,16 @@ declare class NextSafelistWatcher {
75
80
  get lastError(): unknown;
76
81
  /**
77
82
  * Materialize existing shards before accepting live filesystem events.
83
+ *
84
+ * `next watch` and `next dev` start together in the documented setup, so
85
+ * the Turbopack loader's first compile can hold the state lock at this
86
+ * exact moment. The initial cycle is then queued behind it instead of
87
+ * throwing, the same way a scheduled cycle waits.
88
+ *
89
+ * @returns The initial cycle's result, or `undefined` while it is queued
90
+ * behind the Turbopack loader.
78
91
  */
79
- start(): NextWatcherCycleResult;
92
+ start(): NextWatcherCycleResult | undefined;
80
93
  /**
81
94
  * Queue a materialization cycle for one relevant shard filesystem event.
82
95
  *