@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
package/dist/index.cjs CHANGED
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const cssMangler = require('./css-mangler.cjs');
6
- const unplugin = require('./shared/unplugin.9zs6T4Gf.cjs');
7
- const themeGroupsFile = require('./shared/unplugin.2qOISpzl.cjs');
6
+ const unplugin = require('./shared/unplugin.DZdsqdQa.cjs');
7
+ const themeGroupsFile = require('./shared/unplugin.D0tMgokL.cjs');
8
8
  const types = require('@csszyx/types');
9
9
  const safelistSource = require('./shared/unplugin.DS6CFjim.cjs');
10
10
  require('postcss');
@@ -25,6 +25,14 @@ require('./shared/unplugin.YcnV3Izb.cjs');
25
25
  require('./shared/unplugin.BqKLlo1h.cjs');
26
26
  require('./shared/unplugin.Defu9wGh.cjs');
27
27
  require('node:zlib');
28
+ require('node:fs/promises');
29
+ require('os');
30
+ require('path');
31
+ require('util');
32
+ require('stream');
33
+ require('events');
34
+ require('fs');
35
+ require('@csszyx/runtime/split');
28
36
  require('postcss-value-parser');
29
37
 
30
38
 
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  export { classAttributeSelectorKey, createPostCSSPlugin, escapeCSSClassName, mangleCSS, mangleCSSSync, unescapeTailwindClass } from './css-mangler.mjs';
2
- export { a as allocateMangleTokens, b as assertNoRSCBoundaryViolation, c as assertNoRSCGraphViolation, d as collectMangleHybridHazards, e as createGlobalVarAliasValidationOptions, f as createGlobalVarMapAssetSource, g as createGlobalVarScanCacheKey, h as createRSCModuleRecord, i as cssHasContentScope, u as default, j as deleteRSCModuleRecord, k as emitKeyValueDiagnostic, l as emitMissingCssFallback, m as esbuildPlugin, n as extractGlobalVarAliasesForManifest, o as fileMayContainSafelistableSz, p as findLocalImportSources, q as findRSCBoundaryViolation, r as findRSCGraphViolation, s as hasInjectableTailwindCandidate, t as hasUseClientDirective, v as hasUseServerDirective, w as isAdvisoryDiagnostic, x as isCompileSourceOptedIn, y as isHardIgnoredPath, z as isMangleableCssId, A as isMonorepoPackage, B as isPackagesSkippedSource, C as isRSCServerModule, D as isTailwindReservedGlobalVar, E as lateMangleCensusMessage, F as mangleCodeClassesSync, G as mangleEligibleClasses, H as mangleHybridHazardMessage, I as missingTailwindEntryMessage, J as normalizeGlobalVarAliasesForCache, K as planGlobalVarAliases, L as readGlobalVarScanCache, M as realContentHashDisabledMessage, N as recordGlobalVarSourceFile, O as resolveCompileSourceDirs, P as resolveGlobalVarScanCacheDir, Q as resolveNativeCacheIdentity, R as resolveQuietMode, S as rewriteGlobalVarCssAliases, T as rollupPlugin, U as scanGlobalVarCss, V as shouldEmitMissingCssFallback, W as shouldEmitWarning, X as shouldHoldAdvisories, Y as shouldTrackGlobalVarSources, Z as shouldWarnMissingTailwindEntry, _ as shouldWarnUnscopedMonorepo, $ as skippedSzFilesMessage, a0 as suppressedAdvisoryMessage, u as unplugin, a1 as unscopedMonorepoMessage, a2 as validateGlobalVarAliasInputs, a3 as vitePlugin, a4 as watchModeMangleMessage, a5 as webpackPlugin, a6 as writeGlobalVarScanCache } from './shared/unplugin.Cs4H9z9v.mjs';
3
- export { h as hasTokens, m as mergeThemes, p as parseThemeBlocks, a as parseUtilityBlocks, s as scanCustomPropertyNames } from './shared/unplugin.995yC_cN.mjs';
2
+ export { a as allocateMangleTokens, b as assertNoRSCBoundaryViolation, c as assertNoRSCGraphViolation, d as collectMangleHybridHazards, e as createGlobalVarAliasValidationOptions, f as createGlobalVarMapAssetSource, g as createGlobalVarScanCacheKey, h as createRSCModuleRecord, i as cssHasContentScope, u as default, j as deleteRSCModuleRecord, k as emitKeyValueDiagnostic, l as emitMissingCssFallback, m as esbuildPlugin, n as extractGlobalVarAliasesForManifest, o as fileMayContainSafelistableSz, p as findLocalImportSources, q as findRSCBoundaryViolation, r as findRSCGraphViolation, s as hasInjectableTailwindCandidate, t as hasUseClientDirective, v as hasUseServerDirective, w as isAdvisoryDiagnostic, x as isCompileSourceOptedIn, y as isHardIgnoredPath, z as isMangleableCssId, A as isMonorepoPackage, B as isPackagesSkippedSource, C as isRSCServerModule, D as isTailwindReservedGlobalVar, E as lateMangleCensusMessage, F as mangleCodeClassesSync, G as mangleEligibleClasses, H as mangleHybridHazardMessage, I as missingTailwindEntryMessage, J as normalizeGlobalVarAliasesForCache, K as planGlobalVarAliases, L as readGlobalVarScanCache, M as realContentHashDisabledMessage, N as recordGlobalVarSourceFile, O as resolveCompileSourceDirs, P as resolveGlobalVarScanCacheDir, Q as resolveNativeCacheIdentity, R as resolveQuietMode, S as rewriteGlobalVarCssAliases, T as rollupPlugin, U as scanGlobalVarCss, V as shouldEmitMissingCssFallback, W as shouldEmitWarning, X as shouldHoldAdvisories, Y as shouldTrackGlobalVarSources, Z as shouldWarnMissingTailwindEntry, _ as shouldWarnUnscopedMonorepo, $ as skippedSzFilesMessage, a0 as suppressedAdvisoryMessage, u as unplugin, a1 as unscopedMonorepoMessage, a2 as validateGlobalVarAliasInputs, a3 as vitePlugin, a4 as watchModeMangleMessage, a5 as webpackPlugin, a6 as writeGlobalVarScanCache } from './shared/unplugin.CcSfaIVx.mjs';
3
+ export { h as hasTokens, m as mergeThemes, p as parseThemeBlocks, a as parseUtilityBlocks, s as scanCustomPropertyNames } from './shared/unplugin.CK-DfKTP.mjs';
4
4
  export { CSSZYX_GLOBAL_ALIAS_PREFIX, TAILWIND_RESERVED_PREFIXES } from '@csszyx/types';
5
5
  export { S as SAFELIST_FILE, a as appendTailwindSourceDirective, c as computeSafelistRelPath, b as cssImportsTailwind } from './shared/unplugin.Ba3O1r8M.mjs';
6
6
  import 'postcss';
@@ -21,4 +21,12 @@ import './shared/unplugin.2uf-U76p.mjs';
21
21
  import './shared/unplugin.wMeicb6E.mjs';
22
22
  import './shared/unplugin.DcXM9sq5.mjs';
23
23
  import 'node:zlib';
24
+ import 'node:fs/promises';
25
+ import 'os';
26
+ import 'path';
27
+ import 'util';
28
+ import 'stream';
29
+ import 'events';
30
+ import 'fs';
31
+ import '@csszyx/runtime/split';
24
32
  import 'postcss-value-parser';
@@ -4,7 +4,7 @@ const node_crypto = require('node:crypto');
4
4
  const fs = require('node:fs');
5
5
  const path = require('node:path');
6
6
  const nextTransformMetadata = require('./shared/unplugin.DXzIP7lP.cjs');
7
- const nextWatcherCycle = require('./shared/unplugin.alhYXymJ.cjs');
7
+ const nextWatcherCycle = require('./shared/unplugin.BKID6KXV.cjs');
8
8
  const pathNormalization = require('./shared/unplugin.BqKLlo1h.cjs');
9
9
  const safelistSource = require('./shared/unplugin.DS6CFjim.cjs');
10
10
  const transformCache = require('./shared/unplugin.YcnV3Izb.cjs');
@@ -104,7 +104,7 @@ function runNextPrebuild(options) {
104
104
  lockOptions: {
105
105
  root: context.root,
106
106
  mode: context.manifestExpectation.mode,
107
- command: "csszyx next prebuild"
107
+ command: options.lockCommand ?? nextWatcherCycle.NEXT_PREBUILD_LOCK_COMMAND
108
108
  },
109
109
  createdAt: options.createdAt
110
110
  });
@@ -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 {
@@ -2,7 +2,7 @@ import { createHash } from 'node:crypto';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import * as path from 'node:path';
4
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 } from './shared/unplugin.DPSQP5XG.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
6
  import { n as normalizePathSeparators } from './shared/unplugin.wMeicb6E.mjs';
7
7
  import { f as findPostcssConfigWithoutCsszyx, m as missingPostcssPluginMessage } from './shared/unplugin.Ba3O1r8M.mjs';
8
8
  import { r as resolveTransformCacheDir } from './shared/unplugin.2uf-U76p.mjs';
@@ -87,7 +87,7 @@ function runNextPrebuild(options) {
87
87
  lockOptions: {
88
88
  root: context.root,
89
89
  mode: context.manifestExpectation.mode,
90
- command: "csszyx next prebuild"
90
+ command: options.lockCommand ?? NEXT_PREBUILD_LOCK_COMMAND
91
91
  },
92
92
  createdAt: options.createdAt
93
93
  });
@@ -6,9 +6,9 @@ const node_crypto = require('node:crypto');
6
6
  const path = require('node:path');
7
7
  const nextRuntimeInjection = require('./shared/unplugin.Defu9wGh.cjs');
8
8
  const nextTransformMetadata = require('./shared/unplugin.DXzIP7lP.cjs');
9
- const nextWatcherCycle = require('./shared/unplugin.alhYXymJ.cjs');
9
+ const nextWatcherCycle = require('./shared/unplugin.BKID6KXV.cjs');
10
10
  const pathNormalization = require('./shared/unplugin.BqKLlo1h.cjs');
11
- const themeGroupsFile = require('./shared/unplugin.2qOISpzl.cjs');
11
+ const themeGroupsFile = require('./shared/unplugin.D0tMgokL.cjs');
12
12
  const transformCache = require('./shared/unplugin.YcnV3Izb.cjs');
13
13
  require('node:fs');
14
14
  require('@csszyx/compiler');
@@ -100,7 +100,7 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
100
100
  lockOptions: {
101
101
  root: context.root,
102
102
  mode: context.manifestExpectation.mode,
103
- command: "csszyx next turbo-loader"
103
+ command: nextWatcherCycle.NEXT_TURBO_LOADER_LOCK_COMMAND
104
104
  }
105
105
  });
106
106
  materialized = true;
@@ -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. */
@@ -2,9 +2,9 @@ import { createHash } from 'node:crypto';
2
2
  import * as path from 'node:path';
3
3
  import { i as injectNextRuntimeImports, a as insertAfterUseDirective } from './shared/unplugin.DcXM9sq5.mjs';
4
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, N as NextSafelistStateLockedError, a as NEXT_WATCH_LOCK_COMMAND, v as validateNextGenerationManifest, b as readNextGenerationManifest } from './shared/unplugin.DPSQP5XG.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
6
  import { n as normalizePathSeparators } from './shared/unplugin.wMeicb6E.mjs';
7
- import { e as ensureThemeGroupsFile, t as themeGroupsSpecifier } from './shared/unplugin.995yC_cN.mjs';
7
+ import { e as ensureThemeGroupsFile, t as themeGroupsSpecifier } from './shared/unplugin.CK-DfKTP.mjs';
8
8
  import { r as resolveTransformCacheDir } from './shared/unplugin.2uf-U76p.mjs';
9
9
  import 'node:fs';
10
10
  import '@csszyx/compiler';
@@ -81,7 +81,7 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
81
81
  lockOptions: {
82
82
  root: context.root,
83
83
  mode: context.manifestExpectation.mode,
84
- command: "csszyx next turbo-loader"
84
+ command: NEXT_TURBO_LOADER_LOCK_COMMAND
85
85
  }
86
86
  });
87
87
  materialized = true;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const path = require('node:path');
4
- const nextWatcherCycle = require('./shared/unplugin.alhYXymJ.cjs');
4
+ const nextWatcherCycle = require('./shared/unplugin.BKID6KXV.cjs');
5
5
  require('node:fs');
6
6
  require('./shared/unplugin.DS6CFjim.cjs');
7
7
  require('node:crypto');
@@ -23,6 +23,12 @@ function _interopNamespaceCompat(e) {
23
23
 
24
24
  const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
25
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
+ }
26
32
  class NextWatcherLoop {
27
33
  context;
28
34
  cycleOptions;
@@ -30,10 +36,15 @@ class NextWatcherLoop {
30
36
  runCycle;
31
37
  setTimeoutFn;
32
38
  clearTimeoutFn;
39
+ nowFn;
33
40
  onError;
41
+ onWarn;
34
42
  timer;
35
43
  disposed = false;
36
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;
37
48
  lastResult;
38
49
  lastError;
39
50
  /**
@@ -47,7 +58,9 @@ class NextWatcherLoop {
47
58
  this.runCycle = options.runCycle ?? nextWatcherCycle.runNextWatcherCycle;
48
59
  this.setTimeoutFn = options.setTimeout ?? setTimeout;
49
60
  this.clearTimeoutFn = options.clearTimeout ?? clearTimeout;
61
+ this.nowFn = options.now ?? Date.now;
50
62
  this.onError = options.onError;
63
+ this.onWarn = options.onWarn;
51
64
  }
52
65
  /**
53
66
  *
@@ -70,17 +83,7 @@ class NextWatcherLoop {
70
83
  return;
71
84
  }
72
85
  this.pendingReasons.add(reason);
73
- if (this.timer !== void 0) {
74
- return;
75
- }
76
- this.timer = this.setTimeoutFn(() => {
77
- try {
78
- this.runPendingCycle();
79
- } catch (error) {
80
- this.lastError = error;
81
- this.onError?.(error);
82
- }
83
- }, this.debounceMs);
86
+ this.schedule(this.debounceMs);
84
87
  }
85
88
  /**
86
89
  *
@@ -91,6 +94,32 @@ class NextWatcherLoop {
91
94
  }
92
95
  return this.runPendingCycle();
93
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
+ }
94
123
  /**
95
124
  *
96
125
  */
@@ -102,6 +131,75 @@ class NextWatcherLoop {
102
131
  this.pendingReasons.clear();
103
132
  this.disposed = true;
104
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
+ }
105
203
  /**
106
204
  *
107
205
  */
@@ -116,6 +214,7 @@ class NextWatcherLoop {
116
214
  const result = this.runCycle(this.context, this.cycleOptions, reasons);
117
215
  this.lastResult = result;
118
216
  this.lastError = void 0;
217
+ this.endLoaderWait();
119
218
  return result;
120
219
  }
121
220
  }
@@ -169,6 +268,14 @@ class NextSafelistWatcher {
169
268
  }
170
269
  /**
171
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.
172
279
  */
173
280
  start() {
174
281
  if (this.closed) {
@@ -179,8 +286,8 @@ class NextSafelistWatcher {
179
286
  }
180
287
  this.started = true;
181
288
  this.loop.notify("initial");
182
- const result = this.loop.flush();
183
- if (!result) {
289
+ const result = this.loop.flushOrQueue();
290
+ if (!result && !this.loop.pending) {
184
291
  throw new Error("[csszyx] Next safelist watcher failed to run its initial cycle.");
185
292
  }
186
293
  return result;
@@ -234,6 +341,7 @@ class NextSafelistWatcher {
234
341
  }
235
342
  }
236
343
 
344
+ exports.NEXT_WATCH_LOCK_COMMAND = nextWatcherCycle.NEXT_WATCH_LOCK_COMMAND;
237
345
  exports.NextSafelistWatcher = NextSafelistWatcher;
238
346
  exports.isNextAppSourcePath = isNextAppSourcePath;
239
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
  *
@@ -1,5 +1,6 @@
1
- import { N as NextStateContext } from './shared/unplugin.BGog1Bib.mjs';
2
- import { a as NextWatcherCycleOptions, N as NextWatcherCycleResult } from './shared/unplugin.COlI0dJs.mjs';
1
+ import { N as NextStateContext } from './shared/unplugin.XdPo6azz.mjs';
2
+ export { c as NEXT_WATCH_LOCK_COMMAND } from './shared/unplugin.XdPo6azz.mjs';
3
+ import { a as NextWatcherCycleOptions, N as NextWatcherCycleResult } from './shared/unplugin.CfXjAV63.mjs';
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
  *