@csszyx/unplugin 0.17.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 (31) hide show
  1. package/dist/index.cjs +10 -2
  2. package/dist/index.mjs +10 -2
  3. package/dist/next-prebuild.cjs +2 -2
  4. package/dist/next-prebuild.d.cts +12 -2
  5. package/dist/next-prebuild.d.mts +12 -2
  6. package/dist/next-prebuild.mjs +2 -2
  7. package/dist/next-turbo-loader.cjs +3 -3
  8. package/dist/next-turbo-loader.d.cts +1 -1
  9. package/dist/next-turbo-loader.d.mts +1 -1
  10. package/dist/next-turbo-loader.mjs +3 -3
  11. package/dist/next-watcher.cjs +122 -14
  12. package/dist/next-watcher.d.cts +16 -3
  13. package/dist/next-watcher.d.mts +16 -3
  14. package/dist/next-watcher.mjs +122 -14
  15. package/dist/shared/{unplugin.alhYXymJ.cjs → unplugin.BKID6KXV.cjs} +4 -0
  16. package/dist/shared/{unplugin.995yC_cN.mjs → unplugin.CK-DfKTP.mjs} +20 -2
  17. package/dist/shared/{unplugin.COlI0dJs.d.mts → unplugin.C_2R8vIk.d.cts} +1 -1
  18. package/dist/shared/unplugin.CcSfaIVx.mjs +13547 -0
  19. package/dist/shared/{unplugin.rWOMecQs.d.cts → unplugin.CfXjAV63.d.mts} +1 -1
  20. package/dist/shared/{unplugin.2qOISpzl.cjs → unplugin.D0tMgokL.cjs} +23 -1
  21. package/dist/shared/unplugin.DZdsqdQa.cjs +13635 -0
  22. package/dist/shared/{unplugin.BGog1Bib.d.mts → unplugin.XdPo6azz.d.cts} +3 -0
  23. package/dist/shared/{unplugin.BGog1Bib.d.cts → unplugin.XdPo6azz.d.mts} +3 -0
  24. package/dist/shared/{unplugin.DPSQP5XG.mjs → unplugin.eCo7_znv.mjs} +3 -1
  25. package/dist/vite.cjs +10 -2
  26. package/dist/vite.mjs +10 -2
  27. package/dist/webpack.cjs +10 -2
  28. package/dist/webpack.mjs +10 -2
  29. package/package.json +12 -11
  30. package/dist/shared/unplugin.9zs6T4Gf.cjs +0 -5471
  31. package/dist/shared/unplugin.Cs4H9z9v.mjs +0 -5389
@@ -1,5 +1,6 @@
1
1
  import * as path from 'node:path';
2
- import { r as runNextWatcherCycle } from './shared/unplugin.DPSQP5XG.mjs';
2
+ import { r as runNextWatcherCycle, b as NextSafelistStateLockedError, a as NEXT_TURBO_LOADER_LOCK_COMMAND } from './shared/unplugin.eCo7_znv.mjs';
3
+ export { d as NEXT_WATCH_LOCK_COMMAND } from './shared/unplugin.eCo7_znv.mjs';
3
4
  import 'node:fs';
4
5
  import './shared/unplugin.Ba3O1r8M.mjs';
5
6
  import 'node:crypto';
@@ -7,6 +8,12 @@ import './shared/unplugin.wMeicb6E.mjs';
7
8
  import 'node:os';
8
9
  import 'proper-lockfile';
9
10
 
11
+ const LOADER_LOCK_RETRY_MIN_MS = 50;
12
+ const LOADER_LOCK_WARN_AFTER_MS = 1e3;
13
+ const LOADER_LOCK_GIVE_UP_AFTER_MS = 6e4;
14
+ function isHeldByTurbopackLoader(error) {
15
+ return error instanceof NextSafelistStateLockedError && error.holder.command === NEXT_TURBO_LOADER_LOCK_COMMAND;
16
+ }
10
17
  class NextWatcherLoop {
11
18
  context;
12
19
  cycleOptions;
@@ -14,10 +21,15 @@ class NextWatcherLoop {
14
21
  runCycle;
15
22
  setTimeoutFn;
16
23
  clearTimeoutFn;
24
+ nowFn;
17
25
  onError;
26
+ onWarn;
18
27
  timer;
19
28
  disposed = false;
20
29
  pendingReasons = /* @__PURE__ */ new Set();
30
+ /** When the current wait on the loader's lock began; unset while not waiting. */
31
+ loaderWaitStartedAt;
32
+ loaderWaitWarned = false;
21
33
  lastResult;
22
34
  lastError;
23
35
  /**
@@ -31,7 +43,9 @@ class NextWatcherLoop {
31
43
  this.runCycle = options.runCycle ?? runNextWatcherCycle;
32
44
  this.setTimeoutFn = options.setTimeout ?? setTimeout;
33
45
  this.clearTimeoutFn = options.clearTimeout ?? clearTimeout;
46
+ this.nowFn = options.now ?? Date.now;
34
47
  this.onError = options.onError;
48
+ this.onWarn = options.onWarn;
35
49
  }
36
50
  /**
37
51
  *
@@ -54,17 +68,7 @@ class NextWatcherLoop {
54
68
  return;
55
69
  }
56
70
  this.pendingReasons.add(reason);
57
- if (this.timer !== void 0) {
58
- return;
59
- }
60
- this.timer = this.setTimeoutFn(() => {
61
- try {
62
- this.runPendingCycle();
63
- } catch (error) {
64
- this.lastError = error;
65
- this.onError?.(error);
66
- }
67
- }, this.debounceMs);
71
+ this.schedule(this.debounceMs);
68
72
  }
69
73
  /**
70
74
  *
@@ -75,6 +79,32 @@ class NextWatcherLoop {
75
79
  }
76
80
  return this.runPendingCycle();
77
81
  }
82
+ /**
83
+ * Run the pending cycle now, or queue it when the Turbopack loader holds the
84
+ * lock.
85
+ *
86
+ * `flush` throws on every failure, which is what closing needs. Starting
87
+ * needs this instead: `next watch` and `next dev` start together, so the
88
+ * loader's first compile can hold the lock exactly when the initial cycle
89
+ * runs, and that overlap is not a failure.
90
+ *
91
+ * @returns The cycle result, or `undefined` when nothing was pending or the
92
+ * cycle is queued behind the loader.
93
+ */
94
+ flushOrQueue() {
95
+ if (this.disposed || this.timer === void 0) {
96
+ return void 0;
97
+ }
98
+ const reasons = [...this.pendingReasons];
99
+ try {
100
+ return this.runPendingCycle();
101
+ } catch (error) {
102
+ if (this.waitForLoader(error, reasons)) {
103
+ return void 0;
104
+ }
105
+ throw error;
106
+ }
107
+ }
78
108
  /**
79
109
  *
80
110
  */
@@ -86,6 +116,75 @@ class NextWatcherLoop {
86
116
  this.pendingReasons.clear();
87
117
  this.disposed = true;
88
118
  }
119
+ /**
120
+ * Run the pending cycle after `delayMs`, unless a run is already scheduled.
121
+ *
122
+ * @param delayMs - How long to wait before running it.
123
+ */
124
+ schedule(delayMs) {
125
+ if (this.timer !== void 0) {
126
+ return;
127
+ }
128
+ this.timer = this.setTimeoutFn(() => {
129
+ const reasons = [...this.pendingReasons];
130
+ try {
131
+ this.runPendingCycle();
132
+ } catch (error) {
133
+ if (this.waitForLoader(error, reasons)) {
134
+ return;
135
+ }
136
+ this.lastError = error;
137
+ this.onError?.(error);
138
+ }
139
+ }, delayMs);
140
+ }
141
+ /**
142
+ * Queue a cycle again when it failed only because the Turbopack loader holds
143
+ * the lock.
144
+ *
145
+ * Retried, not dropped: the loader's pass read the shards as they stood when
146
+ * it began, and the event that woke this cycle may be newer. The wait is
147
+ * timed from the first refusal, says so once when it runs long, and ends in
148
+ * a reported failure when it runs longer than any live loader could explain.
149
+ *
150
+ * @param error - What the cycle threw.
151
+ * @param reasons - The reasons the failed cycle carried, queued again with it.
152
+ * @returns True when nothing should be reported: the cycle is queued, or the
153
+ * loop was disposed meanwhile.
154
+ */
155
+ waitForLoader(error, reasons) {
156
+ if (!isHeldByTurbopackLoader(error)) {
157
+ return false;
158
+ }
159
+ const now = this.nowFn();
160
+ this.loaderWaitStartedAt ??= now;
161
+ const waited = now - this.loaderWaitStartedAt;
162
+ if (waited > LOADER_LOCK_GIVE_UP_AFTER_MS) {
163
+ this.endLoaderWait();
164
+ return false;
165
+ }
166
+ if (waited >= LOADER_LOCK_WARN_AFTER_MS && !this.loaderWaitWarned) {
167
+ this.loaderWaitWarned = true;
168
+ const warn = this.onWarn ?? (() => {
169
+ });
170
+ warn(
171
+ `[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.`
172
+ );
173
+ }
174
+ if (this.disposed) {
175
+ return true;
176
+ }
177
+ for (const reason of reasons) {
178
+ this.pendingReasons.add(reason);
179
+ }
180
+ this.schedule(Math.max(this.debounceMs, LOADER_LOCK_RETRY_MIN_MS));
181
+ return true;
182
+ }
183
+ /** Forget the current wait on the loader, once a cycle gets through or gives up. */
184
+ endLoaderWait() {
185
+ this.loaderWaitStartedAt = void 0;
186
+ this.loaderWaitWarned = false;
187
+ }
89
188
  /**
90
189
  *
91
190
  */
@@ -100,6 +199,7 @@ class NextWatcherLoop {
100
199
  const result = this.runCycle(this.context, this.cycleOptions, reasons);
101
200
  this.lastResult = result;
102
201
  this.lastError = void 0;
202
+ this.endLoaderWait();
103
203
  return result;
104
204
  }
105
205
  }
@@ -153,6 +253,14 @@ class NextSafelistWatcher {
153
253
  }
154
254
  /**
155
255
  * Materialize existing shards before accepting live filesystem events.
256
+ *
257
+ * `next watch` and `next dev` start together in the documented setup, so
258
+ * the Turbopack loader's first compile can hold the state lock at this
259
+ * exact moment. The initial cycle is then queued behind it instead of
260
+ * throwing, the same way a scheduled cycle waits.
261
+ *
262
+ * @returns The initial cycle's result, or `undefined` while it is queued
263
+ * behind the Turbopack loader.
156
264
  */
157
265
  start() {
158
266
  if (this.closed) {
@@ -163,8 +271,8 @@ class NextSafelistWatcher {
163
271
  }
164
272
  this.started = true;
165
273
  this.loop.notify("initial");
166
- const result = this.loop.flush();
167
- if (!result) {
274
+ const result = this.loop.flushOrQueue();
275
+ if (!result && !this.loop.pending) {
168
276
  throw new Error("[csszyx] Next safelist watcher failed to run its initial cycle.");
169
277
  }
170
278
  return result;
@@ -326,6 +326,8 @@ class NextSafelistStateLockedError extends Error {
326
326
  }
327
327
  }
328
328
  const NEXT_WATCH_LOCK_COMMAND = "csszyx next watch";
329
+ const NEXT_TURBO_LOADER_LOCK_COMMAND = "csszyx next turbo-loader";
330
+ const NEXT_PREBUILD_LOCK_COMMAND = "csszyx next prebuild";
329
331
  function formatLiveLockError(metadata) {
330
332
  return [
331
333
  `csszyx Next safelist state is already locked by process ${metadata.pid}.`,
@@ -593,6 +595,8 @@ function runNextWatcherCycle(context, options = {}) {
593
595
  }
594
596
  }
595
597
 
598
+ exports.NEXT_PREBUILD_LOCK_COMMAND = NEXT_PREBUILD_LOCK_COMMAND;
599
+ exports.NEXT_TURBO_LOADER_LOCK_COMMAND = NEXT_TURBO_LOADER_LOCK_COMMAND;
596
600
  exports.NEXT_WATCH_LOCK_COMMAND = NEXT_WATCH_LOCK_COMMAND;
597
601
  exports.NextSafelistStateLockedError = NextSafelistStateLockedError;
598
602
  exports.createNextStateContext = createNextStateContext;
@@ -310,7 +310,7 @@ export default checksum;
310
310
  `;
311
311
  }
312
312
  function isVirtualModule(id) {
313
- return id === VIRTUAL_MODULE_ID || id === VIRTUAL_CHECKSUM_ID || id === THEME_GROUPS_VIRTUAL_ID || id === MANGLE_RUNTIME_VIRTUAL_ID;
313
+ return id === VIRTUAL_MODULE_ID || id === VIRTUAL_CHECKSUM_ID || id === THEME_GROUPS_VIRTUAL_ID || id === MANGLE_RUNTIME_VIRTUAL_ID || id === UNSERVED_VIRTUAL_ID;
314
314
  }
315
315
  function resolveVirtualModule(id) {
316
316
  if (id === VIRTUAL_MODULE_ID) {
@@ -325,14 +325,32 @@ function resolveVirtualModule(id) {
325
325
  if (id === MANGLE_RUNTIME_VIRTUAL_ID) {
326
326
  return RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID;
327
327
  }
328
+ if (id === UNSERVED_VIRTUAL_ID) {
329
+ return RESOLVED_UNSERVED_VIRTUAL_ID;
330
+ }
328
331
  return void 0;
329
332
  }
330
333
  const MANGLE_RUNTIME_VIRTUAL_ID = "virtual:csszyx/mangle-runtime";
331
334
  const RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID = `\0${MANGLE_RUNTIME_VIRTUAL_ID}`;
335
+ const UNSERVED_VIRTUAL_ID = "virtual:csszyx/unserved";
336
+ const RESOLVED_UNSERVED_VIRTUAL_ID = `\0${UNSERVED_VIRTUAL_ID}`;
332
337
  const MANGLE_MAP_PLACEHOLDER = "___CSSZYX_MANGLE_MAP___";
333
338
  const CENSUS_PLACEHOLDER = "___CSSZYX_CENSUS___";
334
339
  const VAR_MANGLE_MAP_PLACEHOLDER = "___CSSZYX_VAR_MANGLE_MAP___";
335
340
  const CHECKSUM_PLACEHOLDER = "___CSSZYX_CHECKSUM___";
341
+ const UNSERVED_PLACEHOLDER = "___CSSZYX_UNSERVED___";
342
+ function createUnservedRuntimeModule(classes) {
343
+ return `/**
344
+ * Auto-generated by csszyx: registers the class names this project's Tailwind
345
+ * produces no CSS for.
346
+ *
347
+ * @generated
348
+ */
349
+ import { registerUnservedClasses } from '@csszyx/runtime';
350
+
351
+ registerUnservedClasses(${classes === void 0 ? UNSERVED_PLACEHOLDER : JSON.stringify(classes)});
352
+ `;
353
+ }
336
354
  function createMangleRuntimeModule(globalVarAliasPrefix, exposeDebugGlobal = false) {
337
355
  return `/**
338
356
  * Auto-generated by csszyx: registers the runtime mangle map from the bundle.
@@ -479,4 +497,4 @@ function themeGroupsSpecifier(fromFile, themeGroupsFile) {
479
497
  return relative.startsWith("./") || relative.startsWith("../") ? relative : `./${relative}`;
480
498
  }
481
499
 
482
- export { CHECKSUM_PLACEHOLDER as C, MANGLE_RUNTIME_VIRTUAL_ID as M, RESOLVED_VIRTUAL_MODULE_ID as R, THEME_GROUPS_VIRTUAL_ID as T, VAR_MANGLE_MAP_PLACEHOLDER as V, parseUtilityBlocks as a, createMangleMapModule as b, createMangleRuntimeModule as c, RESOLVED_VIRTUAL_CHECKSUM_ID as d, ensureThemeGroupsFile as e, createChecksumModule as f, RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID as g, hasTokens as h, RESOLVED_THEME_GROUPS_VIRTUAL_ID as i, createThemeGroupsModule as j, isVirtualModule as k, discoverProjectTheme as l, mergeThemes as m, CENSUS_PLACEHOLDER as n, THEME_GROUPS_FILE_MARKER as o, parseThemeBlocks as p, MANGLE_MAP_PLACEHOLDER as q, resolveVirtualModule as r, scanCustomPropertyNames as s, themeGroupsSpecifier as t };
500
+ export { CHECKSUM_PLACEHOLDER as C, MANGLE_RUNTIME_VIRTUAL_ID as M, RESOLVED_VIRTUAL_MODULE_ID as R, THEME_GROUPS_VIRTUAL_ID as T, UNSERVED_VIRTUAL_ID as U, VAR_MANGLE_MAP_PLACEHOLDER as V, parseUtilityBlocks as a, createUnservedRuntimeModule as b, createMangleRuntimeModule as c, createMangleMapModule as d, ensureThemeGroupsFile as e, RESOLVED_VIRTUAL_CHECKSUM_ID as f, createChecksumModule as g, hasTokens as h, RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID as i, RESOLVED_UNSERVED_VIRTUAL_ID as j, RESOLVED_THEME_GROUPS_VIRTUAL_ID as k, createThemeGroupsModule as l, mergeThemes as m, isVirtualModule as n, discoverProjectTheme as o, parseThemeBlocks as p, CENSUS_PLACEHOLDER as q, resolveVirtualModule as r, scanCustomPropertyNames as s, themeGroupsSpecifier as t, THEME_GROUPS_FILE_MARKER as u, UNSERVED_PLACEHOLDER as v, MANGLE_MAP_PLACEHOLDER as w };
@@ -1,4 +1,4 @@
1
- import { a as NextSafelistMaterializeResult, b as NextSafelistStateLockOptions, A as AtomicWriteOptions } from './unplugin.BGog1Bib.mjs';
1
+ import { a as NextSafelistMaterializeResult, b as NextSafelistStateLockOptions, A as AtomicWriteOptions } from './unplugin.XdPo6azz.cjs';
2
2
 
3
3
  /** Options for one synchronous watcher materialization cycle. */
4
4
  interface NextWatcherCycleOptions {