next 16.1.1-canary.31 → 16.1.1-canary.32

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 (58) hide show
  1. package/dist/.build-commit +1 -1
  2. package/dist/bin/next +2 -2
  3. package/dist/build/index.js +3 -3
  4. package/dist/build/swc/index.js +1 -1
  5. package/dist/build/webpack-config.js +3 -3
  6. package/dist/bundle-analyzer/404.html +2 -2
  7. package/dist/bundle-analyzer/__next.__PAGE__.txt +1 -1
  8. package/dist/bundle-analyzer/__next._full.txt +1 -1
  9. package/dist/bundle-analyzer/__next._head.txt +1 -1
  10. package/dist/bundle-analyzer/__next._index.txt +1 -1
  11. package/dist/bundle-analyzer/__next._tree.txt +1 -1
  12. package/dist/bundle-analyzer/_not-found/__next._full.txt +1 -1
  13. package/dist/bundle-analyzer/_not-found/__next._head.txt +1 -1
  14. package/dist/bundle-analyzer/_not-found/__next._index.txt +1 -1
  15. package/dist/bundle-analyzer/_not-found/__next._not-found.__PAGE__.txt +1 -1
  16. package/dist/bundle-analyzer/_not-found/__next._not-found.txt +1 -1
  17. package/dist/bundle-analyzer/_not-found/__next._tree.txt +1 -1
  18. package/dist/bundle-analyzer/_not-found.html +2 -2
  19. package/dist/bundle-analyzer/_not-found.txt +1 -1
  20. package/dist/bundle-analyzer/index.html +2 -2
  21. package/dist/bundle-analyzer/index.txt +1 -1
  22. package/dist/client/app-bootstrap.js +1 -1
  23. package/dist/client/index.js +1 -1
  24. package/dist/compiled/next-server/pages-api-turbo.runtime.prod.js +1 -1
  25. package/dist/compiled/next-server/pages-api-turbo.runtime.prod.js.map +1 -1
  26. package/dist/compiled/next-server/pages-turbo.runtime.prod.js +1 -1
  27. package/dist/compiled/next-server/pages-turbo.runtime.prod.js.map +1 -1
  28. package/dist/compiled/next-server/server.runtime.prod.js +1 -1
  29. package/dist/esm/build/index.js +3 -3
  30. package/dist/esm/build/swc/index.js +1 -1
  31. package/dist/esm/build/webpack-config.js +3 -3
  32. package/dist/esm/client/app-bootstrap.js +1 -1
  33. package/dist/esm/client/index.js +1 -1
  34. package/dist/esm/lib/resolve-build-paths.js +7 -19
  35. package/dist/esm/lib/resolve-build-paths.js.map +1 -1
  36. package/dist/esm/server/dev/hot-reloader-turbopack.js +1 -1
  37. package/dist/esm/server/dev/hot-reloader-webpack.js +1 -1
  38. package/dist/esm/server/lib/app-info-log.js +1 -1
  39. package/dist/esm/server/lib/start-server.js +1 -1
  40. package/dist/esm/server/node-environment-extensions/fast-set-immediate.external.js +2 -2
  41. package/dist/esm/server/node-environment-extensions/fast-set-immediate.external.js.map +1 -1
  42. package/dist/esm/shared/lib/errors/canary-only-config-error.js +1 -1
  43. package/dist/lib/resolve-build-paths.js +7 -19
  44. package/dist/lib/resolve-build-paths.js.map +1 -1
  45. package/dist/server/dev/hot-reloader-turbopack.js +1 -1
  46. package/dist/server/dev/hot-reloader-webpack.js +1 -1
  47. package/dist/server/lib/app-info-log.js +1 -1
  48. package/dist/server/lib/start-server.js +1 -1
  49. package/dist/server/node-environment-extensions/fast-set-immediate.external.js +2 -2
  50. package/dist/server/node-environment-extensions/fast-set-immediate.external.js.map +1 -1
  51. package/dist/shared/lib/errors/canary-only-config-error.js +1 -1
  52. package/dist/telemetry/anonymous-meta.js +1 -1
  53. package/dist/telemetry/events/session-stopped.js +2 -2
  54. package/dist/telemetry/events/version.js +2 -2
  55. package/package.json +15 -15
  56. /package/dist/bundle-analyzer/_next/static/{Nj0DMjMmkmFqbF6pIiv9O → ch2xoP64DtWbb5dkwAboX}/_buildManifest.js +0 -0
  57. /package/dist/bundle-analyzer/_next/static/{Nj0DMjMmkmFqbF6pIiv9O → ch2xoP64DtWbb5dkwAboX}/_clientMiddlewareManifest.json +0 -0
  58. /package/dist/bundle-analyzer/_next/static/{Nj0DMjMmkmFqbF6pIiv9O → ch2xoP64DtWbb5dkwAboX}/_ssgManifest.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/server/node-environment-extensions/fast-set-immediate.external.ts"],"sourcesContent":["import { promisify } from 'node:util'\nimport { InvariantError } from '../../shared/lib/invariant-error'\nimport { bindSnapshot } from '../app-render/async-local-storage'\n\ntype Execution = {\n state: ExecutionState\n queuedImmediates: QueueItem[]\n}\n\nenum ExecutionState {\n Waiting = 1,\n Working = 2,\n Finished = 3,\n Abandoned = 4,\n}\n\nlet wasEnabledAtLeastOnce = false\n\nlet pendingNextTicks = 0\nlet currentExecution: Execution | null = null\n\nconst originalSetImmediate = globalThis.setImmediate\nconst originalClearImmediate = globalThis.clearImmediate\nconst originalNextTick = process.nextTick\nconst originalSetImmediatePromisify: (typeof setImmediate)['__promisify__'] =\n // @ts-expect-error: the types for `promisify.custom` are strange\n originalSetImmediate[promisify.custom]\n\nexport { originalSetImmediate as unpatchedSetImmediate }\n\nfunction install() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n // Nothing to patch. The exported functions all error if used in the edge runtime,\n // so we're not going to violate any assumptions by not patching.\n return\n } else {\n debug?.('installing fast setImmediate patch')\n\n const nodeTimers = require('node:timers') as typeof import('node:timers')\n globalThis.setImmediate = nodeTimers.setImmediate =\n // Workaround for missing __promisify__ which is not a real property\n patchedSetImmediate as unknown as typeof setImmediate\n globalThis.clearImmediate = nodeTimers.clearImmediate =\n patchedClearImmediate\n\n const nodeTimersPromises =\n require('node:timers/promises') as typeof import('node:timers/promises')\n nodeTimersPromises.setImmediate =\n patchedSetImmediatePromise as typeof import('node:timers/promises').setImmediate\n\n process.nextTick = patchedNextTick\n }\n}\n\n/**\n * **WARNING: This function changes the usual behavior of the event loop!**\n * **Be VERY careful about where you call it.**\n *\n * Starts capturing calls to `setImmediate` to run them as \"fast immediates\".\n * All calls captured in this way will be executed after the current task\n * (after callbacks from `process.nextTick()`, microtasks, and nextTicks scheduled from microtasks).\n * This function needs to be called again in each task that needs the\n * \"fast immediates\" behavior.\n *\n * ### Motivation\n *\n * We don't want `setImmediate` to be considered IO in Cache Components.\n * To achieve this in a staged (pre)render, we want to allow immediates scheduled\n * in stage N to run before stage N+1.\n * Since we schedule stages using sequential `setTimeout`, this isn't possible without\n * intercepting `setImmediate` and doing the scheduling on our own.\n * We refer to this as a \"fast immediate\".\n *\n * Notably, this affects React's `scheduleWork` in render, which uses `setImmediate`.\n * This is desirable -- if async work was scheduled during a stage, then it should\n * get to run before we finish that stage.\n *\n * ### Example\n *\n * ```ts\n * setTimeout(() => {\n * runPendingImmediatesAfterCurrentTask()\n * console.log(\"timeout 1\")\n * setImmediate(() => {\n * console.log(\"immediate!!!\")\n * })\n * })\n * setTimeout(() => {\n * console.log(\"timeout 2\")\n * })\n * ```\n * will print\n *\n * ```\n * timeout 1\n * immediate!!!\n * timeout 2\n * ```\n *\n * instead of the usual order\n * ```\n * timeout 1\n * timeout 2\n * immediate!!!\n * ```\n * > **NOTE**\n * > The above is *most common* order, but it's not guaranteed.\n * > Under some circumstances (e.g. when the event loop is blocked on CPU work),\n * > Node will reorder things and run the immediate before timeout 2.\n * > So, in a sense, we're just making this reordering happen consistently.\n *\n * Recursive `setImmediate` calls will also be executed as \"fast immediates\".\n * If multiple immediates were scheduled, `process.nextTick()` (and associated microtasks)\n * will be allowed to execute between them.\n * See the unit tests for more examples.\n * */\nexport function DANGEROUSLY_runPendingImmediatesAfterCurrentTask() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'DANGEROUSLY_runPendingImmediatesAfterCurrentTask cannot be called in the edge runtime'\n )\n } else {\n const execution = startCapturingImmediates()\n\n try {\n scheduleWorkAfterNextTicksAndMicrotasks(execution)\n } catch (err) {\n // If this error comes from a bail() call, rethrow it.\n if (execution.state === ExecutionState.Abandoned) {\n throw err\n }\n // Otherwise, bail out here.\n bail(\n execution,\n new InvariantError(\n 'An unexpected error occurred while starting to capture immediates',\n {\n cause: err,\n }\n )\n )\n }\n }\n}\n\n/**\n * This should always be called a task after `DANGEROUSLY_runPendingImmediatesAfterCurrentTask`\n * to make sure that everything executed as expected and we're not left in an inconsistent state.\n * Ideally, this wouldn't be necessary, but we're not in control of the event loop\n * and need to guard against unexpected behaviors not forseen in this implementation,\n * so we have to be defensive.\n */\nexport function expectNoPendingImmediates() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'expectNoPendingImmediates cannot be called in the edge runtime'\n )\n } else {\n if (currentExecution !== null) {\n bail(\n currentExecution,\n new InvariantError(\n `Expected all captured immediates to have been executed (state: ${ExecutionState[currentExecution.state]})`\n )\n )\n }\n }\n}\n\n/**\n * Wait until all nextTicks and microtasks spawned from the current task are done,\n * then execute any immediates that they queued.\n * */\nfunction scheduleWorkAfterNextTicksAndMicrotasks(execution: Execution) {\n if (execution.state !== ExecutionState.Waiting) {\n throw new InvariantError(\n `scheduleWorkAfterTicksAndMicrotasks can only be called while waiting (state: ${ExecutionState[execution.state]})`\n )\n }\n\n // We want to execute \"fast immediates\" after all the nextTicks and microtasks\n // spawned from the current task are done.\n // The ordering here is:\n //\n // 1. sync code\n // 2. process.nextTick (scheduled from sync code, or from one of these nextTicks)\n // 3. microtasks\n // 4. process.nextTick (scheduled from microtasks, e.g. `queueMicrotask(() => process.nextTick(callback))`)\n //\n // We want to run to run in step 4, because that's the latest point before the next tick.\n // However, there might also be other callbacks scheduled to run in that step.\n // But importantly, they had to be scheduled using a `process.nextTick`,\n // so we can detect them by checking if `pendingNextTicks > 0`.\n // In that case, we'll just reschedule ourselves in the same way again to let them run first.\n // (this process can theoretically repeat multiple times, hence the recursion).\n\n queueMicrotask(() => {\n // (note that this call won't increment `pendingNextTicks`,\n // only the patched `process.nextTick` does that, so this won't loop infinitely)\n originalNextTick(() => {\n // We're now in a nextTick, which means that we're executing inside `processTicksAndRejections`:\n // https://github.com/nodejs/node/blob/d546e7fd0bc3cbb4bcc2baae6f3aa44d2e81a413/lib/internal/process/task_queues.js#L84\n // All the work scheduled here will happen within that `processTicksAndRejections` loop.\n // Reading the source of `processTicksAndRejections` can help understand the timing here --\n // All we're really doing is strategically pushing callbacks into the two queues\n // (nextTicks and microtasks) that that function is currently looping over.\n\n try {\n if (\n execution.state === ExecutionState.Abandoned ||\n currentExecution !== execution\n ) {\n debug?.(`scheduler :: the execution was abandoned`)\n return\n }\n if (pendingNextTicks > 0) {\n // Other nextTicks have been scheduled. Let those run first, then try again --\n // we're simulating a event loop task, so all nextTicks should be exhausted before we execute.\n debug?.(`scheduler :: yielding to ${pendingNextTicks} nextTicks`)\n return scheduleWorkAfterNextTicksAndMicrotasks(execution)\n }\n\n // There's no other nextTicks, we're the last one, so we're about to move on to the next task (likely a timer).\n // Now, we can try and execute any queued immediates.\n return performWork(execution)\n } catch (err) {\n // If this error comes from a bail() call, rethrow it.\n\n // typescript can't tell that the state might've been mutated\n // and the narrowing from above is no longer valid\n const executionAfterWork = execution as Execution\n if (executionAfterWork.state === ExecutionState.Abandoned) {\n throw err\n }\n\n // Otherwise, bail out here (which will trigger an uncaught exception)\n // Note that we're using the same microtask trick as `safelyRunNextTickCallback`.\n queueMicrotask(() => {\n bail(\n execution,\n new InvariantError(\n 'An unexpected error occurred while executing immediates',\n { cause: err }\n )\n )\n })\n }\n })\n })\n}\n\n/** Execute one immediate, and schedule a check for more (in case there's others in the queue) */\nfunction performWork(execution: Execution) {\n if (execution.state === ExecutionState.Abandoned) {\n return\n }\n\n debug?.(`scheduler :: performing work`)\n\n if (execution.state !== ExecutionState.Waiting) {\n throw new InvariantError(\n `performWork can only be called while waiting (state: ${ExecutionState[execution.state]})`\n )\n }\n execution.state = ExecutionState.Working\n\n const queueItem = takeNextActiveQueueItem(execution)\n\n if (queueItem === null) {\n debug?.(`scheduler :: no immediates queued, exiting`)\n stopCapturingImmediates(execution)\n return\n }\n\n debug?.(`scheduler :: executing queued immediate`)\n\n const { immediateObject, callback, args } = queueItem\n\n immediateObject[INTERNALS].queueItem = null\n clearQueueItem(queueItem)\n\n // Execute the immediate.\n\n // If a sync error was thrown in the immediate, we want to trigger a `uncaughtException`.\n // However, we're executing in a nextTick, and if a nextTick callback errors,\n // It'll break out of `processTicksAndRejections` (note the lack of a `catch` block):\n // https://github.com/nodejs/node/blob/d546e7fd0bc3cbb4bcc2baae6f3aa44d2e81a413/lib/internal/process/task_queues.js#L81-L97\n // Meaning that the event loop will stop executing nextTicks and move on to the next timer\n // (or other phase of the event loop, but we expect to be running in a sequence of timers here).\n // Then, the remaining ticks will run after that timer, since they're still in the queue.\n //\n // This would completely break the timing we're trying to achieve here --\n // The point of this patch is to execute immediates before the next timer!\n // So, we need to work around this behavior. (both here and in our `process.nextTick` patch).\n //\n // We can sidestep this by catching the synchronous error and rethrowing it in a microtask.\n // (NOTE: if we use `queueMicrotask`, it'll trigger `uncaughtException`, not `unhandledRejection`,\n // because there's no promise being rejected.)\n //\n // This will make `uncaughtException` happen:\n // - Before the next fast immediate (`scheduleWorkAfterNextTicksAndMicrotasks` also uses `queueMicrotask`).\n // This is good, and matches usual observable behavior of immediates.\n // - AFTER nextTicks scheduled from the immediate itself.\n // This deviates from native setImmediate, which would call `uncaughtException` first,\n // and skip ahead to the next task as explained above.\n //\n // This is technically an observable difference in behavior, but it seems niche enough that\n // it shouldn't cause problems -- we don't expect user code to use `uncaughtException` for control flow,\n // only error reporting, so subtly changing the timing shouldn't matter.\n\n let didThrow = false\n let thrownValue: unknown = undefined\n queueMicrotask(() => {\n if (didThrow) {\n debug?.('scheduler :: rethrowing sync error from immediate in microtask')\n throw thrownValue\n }\n })\n\n try {\n if (args !== null) {\n callback.apply(null, args)\n } else {\n callback()\n }\n } catch (err) {\n // We'll rethrow the error in the microtask above.\n didThrow = true\n thrownValue = err\n }\n\n // Schedule the loop again in case there's more immediates after this one.\n // Note that we can't just check if the queue is empty now, because new immediates\n // might still be scheduled asynchronously, from an upcoming nextTick or microtask.\n execution.state = ExecutionState.Waiting\n scheduleWorkAfterNextTicksAndMicrotasks(execution)\n}\n\nfunction takeNextActiveQueueItem(execution: Execution): ActiveQueueItem | null {\n // Find the first (if any) queued immediate that wasn't cleared.\n // We don't remove immediates from the array when they're cleared,\n // so this requires some legwork to exclude (and possibly drop) cleared items.\n const { queuedImmediates } = execution\n\n let firstActiveItem: ActiveQueueItem | null = null\n let firstActiveItemIndex = -1\n for (let i = 0; i < queuedImmediates.length; i++) {\n const item = queuedImmediates[i]\n if (!item.isCleared) {\n firstActiveItem = item\n firstActiveItemIndex = i\n break\n }\n }\n\n if (firstActiveItem === null) {\n // We didn't find an active item.\n\n // If the queue isn't empty, then it must only contain cleared items. Empty it.\n if (queuedImmediates.length > 0) {\n queuedImmediates.length = 0\n }\n\n return null\n }\n\n // Remove all items up to and including `nextActiveItemIndex` from the queue.\n // (if it's not the first item, then it must be preceded by cleared items, which we want to drop anyway)\n if (firstActiveItemIndex === 0) {\n // Fast path - drop the first item\n // (`splice` creates a result array for the removed items, so this is more efficient)\n queuedImmediates.shift()\n } else {\n queuedImmediates.splice(0, firstActiveItemIndex + 1)\n }\n\n return firstActiveItem\n}\n\nfunction startCapturingImmediates(): Execution {\n if (currentExecution !== null) {\n bail(\n currentExecution,\n new InvariantError(\n `Cannot start capturing immediates again without finishing the previous task (state: ${ExecutionState[currentExecution.state]})`\n )\n )\n }\n wasEnabledAtLeastOnce = true\n\n const execution: Execution = {\n state: ExecutionState.Waiting,\n queuedImmediates: [],\n }\n currentExecution = execution\n\n return execution\n}\n\nfunction stopCapturingImmediates(execution: Execution) {\n if (execution.state === ExecutionState.Abandoned) {\n return\n }\n\n // This check enforces that we run performWork at least once before stopping\n // to make sure that we've waited for all the nextTicks and microtasks\n // that might've scheduled some immediates after sync code.\n if (execution.state !== ExecutionState.Working) {\n throw new InvariantError(\n `Cannot stop capturing immediates before execution is finished (state: ${ExecutionState[execution.state]})`\n )\n }\n\n execution.state = ExecutionState.Finished\n\n if (currentExecution === execution) {\n currentExecution = null\n }\n}\n\nfunction bail(execution: Execution, error: Error): never {\n // Reset the state as best we can to prevent further crashes.\n // Otherwise, any subsequent call to `DANGEROUSLY_runPendingImmediatesAfterCurrentTask`\n // would error, requiring a server restart to fix.\n\n if (currentExecution === execution) {\n currentExecution = null\n }\n\n execution.state = ExecutionState.Abandoned\n\n // If we have any queued immediates, schedule them with native `setImmediate` and clear the queue.\n // We don't want to skip running them altogether, because that could lead to\n // e.g. hanging promises (for `new Promise((resolve) => setImmediate(resolve))`),\n // but we're in an inconsistent state and can't run them as fast immediates,\n // so this is the next best thing.\n for (const queueItem of execution.queuedImmediates) {\n if (queueItem.isCleared) {\n continue\n }\n scheduleQueuedImmediateAsNativeImmediate(queueItem)\n }\n execution.queuedImmediates.length = 0\n\n // Don't reset `pendingNextTicks` -- it will reset to 0 on its own as the nextTicks execute.\n // If we set it to 0 here while we still have pending ticks, they'd decrement it below 0.\n\n throw error\n}\n\nfunction scheduleQueuedImmediateAsNativeImmediate(queueItem: ActiveQueueItem) {\n const { callback, args, immediateObject } = queueItem\n const hasRef = immediateObject[INTERNALS].hasRef\n\n clearQueueItem(queueItem)\n\n const nativeImmediate =\n args !== null\n ? originalSetImmediate(callback, ...args)\n : originalSetImmediate(callback)\n\n if (!hasRef) {\n nativeImmediate.unref()\n }\n\n // Make our fake immediate object proxy all relevant operations\n // (clearing, ref(), unref(), hasRef()) to the actual native immediate.\n proxyQueuedImmediateToNativeImmediate(immediateObject, nativeImmediate)\n}\n\ntype QueueItem = ActiveQueueItem | ClearedQueueItem\ntype ActiveQueueItem = {\n isCleared: false\n callback: (...args: any[]) => any\n args: any[] | null\n immediateObject: NextImmediate\n}\ntype ClearedQueueItem = {\n isCleared: true\n callback: null\n args: null\n immediateObject: null\n}\n\nfunction clearQueueItem(originalQueueItem: QueueItem) {\n const queueItem = originalQueueItem as ClearedQueueItem\n queueItem.isCleared = true\n queueItem.callback = null\n queueItem.args = null\n queueItem.immediateObject = null\n}\n\n//========================================================\n\nfunction patchedNextTick<TArgs extends any[]>(\n callback: (...args: TArgs) => void,\n ...args: TArgs\n): void\nfunction patchedNextTick() {\n if (currentExecution === null) {\n return originalNextTick.apply(\n null,\n // @ts-expect-error: this is valid, but typescript doesn't get it\n arguments\n )\n }\n\n if (arguments.length === 0 || typeof arguments[0] !== 'function') {\n // Let the original nextTick error for invalid arguments\n // so that we don't have to mirror the error message.\n originalNextTick.apply(\n null,\n // @ts-expect-error: explicitly passing arguments that we know are invalid\n arguments\n )\n\n // We expect the above call to throw. If it didn't, something's broken.\n bail(\n currentExecution,\n new InvariantError(\n 'Expected process.nextTick to reject invalid arguments'\n )\n )\n }\n\n debug?.(\n `scheduler :: process.nextTick called (previous pending: ${pendingNextTicks})`\n )\n\n const callback: (...args: any[]) => any = arguments[0]\n const args: any[] | null =\n arguments.length > 1 ? Array.prototype.slice.call(arguments, 1) : null\n\n pendingNextTicks += 1\n return originalNextTick(safelyRunNextTickCallback, callback, args)\n}\n\nfunction safelyRunNextTickCallback(\n callback: (...args: any[]) => any,\n args: any[] | null\n) {\n pendingNextTicks -= 1\n debug?.(\n `scheduler :: process.nextTick executing (still pending: ${pendingNextTicks})`\n )\n\n // Synchronous errors in nextTick break out of `processTicksAndRejections` and cause us\n // to move on to the next timer without having executed the whole nextTick queue,\n // which breaks our entire scheduling mechanism. See `performWork` for more details.\n try {\n if (args !== null) {\n callback.apply(null, args)\n } else {\n callback()\n }\n } catch (err) {\n // We want to make sure `nextTick` is cheap, so unlike `performWork`,\n // we only queue the microtask if an error actually occurs.\n // This (observably) changes the timing of `uncaughtException` even more,\n // because it'll run after microtasks queued from the nextTick,\n // but hopefully this is niche enough to not affect any real world code.\n queueMicrotask(() => {\n debug?.(`scheduler :: rethrowing sync error from nextTick in a microtask`)\n throw err\n })\n }\n}\n\nfunction patchedSetImmediate<TArgs extends any[]>(\n callback: (...args: TArgs) => void,\n ...args: TArgs\n): NodeJS.Immediate\nfunction patchedSetImmediate(callback: (args: void) => void): NodeJS.Immediate\nfunction patchedSetImmediate(): NodeJS.Immediate {\n if (currentExecution === null) {\n return originalSetImmediate.apply(\n null,\n // @ts-expect-error: this is valid, but typescript doesn't get it\n arguments\n )\n }\n\n if (arguments.length === 0 || typeof arguments[0] !== 'function') {\n // Let the original setImmediate error for invalid arguments\n // so that we don't have to mirror the error message.\n originalSetImmediate.apply(\n null,\n // @ts-expect-error: explicitly passing arguments that we know are invalid\n arguments\n )\n\n // We expect the above call to throw. If it didn't, something's broken.\n bail(\n currentExecution,\n new InvariantError('Expected setImmediate to reject invalid arguments')\n )\n }\n\n const callback: (...args: any[]) => any = arguments[0]\n const args: any[] | null =\n arguments.length > 1 ? Array.prototype.slice.call(arguments, 1) : null\n\n // Normally, Node would capture and propagate the async context to the immediate.\n // We'll be running it on our own queue, so we need to propagate it ourselves.\n const callbackWithAsyncContext = bindSnapshot(callback)\n\n const immediateObject = new NextImmediate()\n\n const queueItem: ActiveQueueItem = {\n isCleared: false,\n callback: callbackWithAsyncContext,\n args,\n immediateObject,\n }\n currentExecution.queuedImmediates.push(queueItem)\n\n immediateObject[INTERNALS].queueItem = queueItem\n\n return immediateObject\n}\n\nfunction patchedSetImmediatePromise<T = void>(\n value: T,\n options?: import('node:timers').TimerOptions\n): Promise<T> {\n if (currentExecution === null) {\n return originalSetImmediatePromisify(value, options)\n }\n\n return new Promise<T>((resolve, reject) => {\n // The abort signal makes the promise reject.\n // If it is already aborted, we reject immediately.\n const signal = options?.signal\n if (signal && signal.aborted) {\n return reject(signal.reason)\n }\n\n const immediate = patchedSetImmediate(resolve, value)\n\n // Unref-ing only really has an observable effect if we bail out to a native immediate,\n // but we do it for completeness\n if (options?.ref === false) {\n immediate.unref()\n }\n\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n patchedClearImmediate(immediate)\n reject(signal.reason)\n },\n { once: true }\n )\n }\n })\n}\n\npatchedSetImmediate[promisify.custom] = patchedSetImmediatePromise\n\nconst patchedClearImmediate = (\n immediateObject: NodeJS.Immediate | undefined\n) => {\n // NOTE: we defensively check for patched immediates even if we're not\n // currently capturing immediates, because the objects returned from\n // the patched setImmediate can be kept around for arbitrarily long.\n // As an optimization, we only do this if the patch was enabled at least once --\n // otherwise, no patched objects could've been created.\n if (\n wasEnabledAtLeastOnce &&\n immediateObject &&\n typeof immediateObject === 'object' &&\n INTERNALS in immediateObject\n ) {\n ;(immediateObject as NextImmediate)[Symbol.dispose]()\n } else {\n originalClearImmediate(immediateObject)\n }\n}\n\n//========================================================\n\nconst INTERNALS: unique symbol = Symbol.for('next.Immediate.internals')\n\ntype NextImmediateInternals =\n | {\n /** Stored to reflect `ref()`/`unref()` calls, but has no effect otherwise */\n hasRef: boolean\n queueItem: ActiveQueueItem | null\n nativeImmediate: null\n }\n | {\n hasRef: null\n queueItem: null\n nativeImmediate: NodeJS.Immediate\n }\n\nfunction proxyQueuedImmediateToNativeImmediate(\n immediateObject: NextImmediate,\n nativeImmediate: NodeJS.Immediate\n) {\n immediateObject[INTERNALS].hasRef = null\n immediateObject[INTERNALS].queueItem = null\n immediateObject[INTERNALS].nativeImmediate = nativeImmediate\n}\n\n/** Makes sure that we're implementing all the public `Immediate` methods */\ninterface NativeImmediate extends NodeJS.Immediate {}\n\n/** Implements a shim for the native `Immediate` class returned by `setImmediate` */\nclass NextImmediate implements NativeImmediate {\n [INTERNALS]: NextImmediateInternals = {\n queueItem: null,\n hasRef: true,\n nativeImmediate: null,\n }\n hasRef() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n return internals.hasRef\n } else if (internals.nativeImmediate) {\n return internals.nativeImmediate.hasRef()\n } else {\n // if we're no longer queued (cleared or executed), hasRef is always false\n return false\n }\n }\n ref() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n internals.hasRef = true\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate.ref()\n }\n return this\n }\n unref() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n internals.hasRef = false\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate.unref()\n }\n return this\n }\n\n /**\n * Node invokes `_onImmediate` when an immediate is executed:\n * https://github.com/nodejs/node/blob/42d363205715ffa5a4a6d90f4be1311487053d65/lib/internal/timers.js#L504\n * It's visible on the public types, so we want to have it here for parity, but it's a noop.\n * */\n _onImmediate() {}\n\n [Symbol.dispose]() {\n // This is equivalent to `clearImmediate`.\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n // this is still queued. drop it.\n const queueItem = internals.queueItem\n internals.queueItem = null\n clearQueueItem(queueItem)\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate[Symbol.dispose]()\n }\n }\n}\n\n// ==========================================\n\nconst debug =\n process.env.NEXT_DEBUG_IMMEDIATES !== '1'\n ? undefined\n : (...args: any[]) => {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'Fast setImmediate is not available in the edge runtime.'\n )\n } else {\n const { inspect } = require('node:util') as typeof import('node:util')\n const { writeFileSync } =\n require('node:fs') as typeof import('node:fs')\n\n let logLine =\n args\n .map((arg) =>\n typeof arg === 'string' ? arg : inspect(arg, { colors: true })\n )\n .join(' ') + '\\n'\n\n logLine = '\\x1B[2m' + logLine + '\\x1B[22m' // styleText('dim', logLine)\n writeFileSync(process.stdout.fd, logLine)\n }\n }\n\n// ==========================================\n\ninstall()\n"],"names":["promisify","InvariantError","bindSnapshot","ExecutionState","wasEnabledAtLeastOnce","pendingNextTicks","currentExecution","originalSetImmediate","globalThis","setImmediate","originalClearImmediate","clearImmediate","originalNextTick","process","nextTick","originalSetImmediatePromisify","custom","unpatchedSetImmediate","install","env","NEXT_RUNTIME","debug","nodeTimers","require","patchedSetImmediate","patchedClearImmediate","nodeTimersPromises","patchedSetImmediatePromise","patchedNextTick","DANGEROUSLY_runPendingImmediatesAfterCurrentTask","execution","startCapturingImmediates","scheduleWorkAfterNextTicksAndMicrotasks","err","state","bail","cause","expectNoPendingImmediates","queueMicrotask","performWork","executionAfterWork","queueItem","takeNextActiveQueueItem","stopCapturingImmediates","immediateObject","callback","args","INTERNALS","clearQueueItem","didThrow","thrownValue","undefined","apply","queuedImmediates","firstActiveItem","firstActiveItemIndex","i","length","item","isCleared","shift","splice","error","scheduleQueuedImmediateAsNativeImmediate","hasRef","nativeImmediate","unref","proxyQueuedImmediateToNativeImmediate","originalQueueItem","arguments","Array","prototype","slice","call","safelyRunNextTickCallback","callbackWithAsyncContext","NextImmediate","push","value","options","Promise","resolve","reject","signal","aborted","reason","immediate","ref","addEventListener","once","Symbol","dispose","for","internals","_onImmediate","NEXT_DEBUG_IMMEDIATES","inspect","writeFileSync","logLine","map","arg","colors","join","stdout","fd"],"mappings":"AAAA,SAASA,SAAS,QAAQ,YAAW;AACrC,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,YAAY,QAAQ,oCAAmC;AAOhE,IAAA,AAAKC,wCAAAA;;;;;WAAAA;EAAAA;AAOL,IAAIC,wBAAwB;AAE5B,IAAIC,mBAAmB;AACvB,IAAIC,mBAAqC;AAEzC,MAAMC,uBAAuBC,WAAWC,YAAY;AACpD,MAAMC,yBAAyBF,WAAWG,cAAc;AACxD,MAAMC,mBAAmBC,QAAQC,QAAQ;AACzC,MAAMC,gCACJ,iEAAiE;AACjER,oBAAoB,CAACP,UAAUgB,MAAM,CAAC;AAExC,SAAST,wBAAwBU,qBAAqB,GAAE;AAExD,SAASC;IACP,IAAIL,QAAQM,GAAG,CAACC,YAAY,KAAK,QAAQ;QACvC,kFAAkF;QAClF,iEAAiE;QACjE;IACF,OAAO;QACLC,yBAAAA,MAAQ;QAER,MAAMC,aAAaC,QAAQ;QAC3Bf,WAAWC,YAAY,GAAGa,WAAWb,YAAY,GAC/C,oEAAoE;QACpEe;QACFhB,WAAWG,cAAc,GAAGW,WAAWX,cAAc,GACnDc;QAEF,MAAMC,qBACJH,QAAQ;QACVG,mBAAmBjB,YAAY,GAC7BkB;QAEFd,QAAQC,QAAQ,GAAGc;IACrB;AACF;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG,GACH,OAAO,SAASC;IACd,IAAIhB,QAAQM,GAAG,CAACC,YAAY,KAAK,QAAQ;QACvC,MAAM,qBAEL,CAFK,IAAInB,eAC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AS,GAAG;YACtBO,eAAeP;QACjB,OAAO,IAAIoD,UAAU5B,eAAe,EAAE;YACpC4B,UAAU5B,eAAe,CAACyB,OAAOC,OAAO,CAAC;QAC3C;IACF;;YArDA,CAAC5C,UAAU,GAA2B;YACpCN,WAAW;YACXuB,QAAQ;YACRC,iBAAiB;QACnB;;AAkDF;AAEA,6CAA6C;AAE7C,MAAM5C,QACJR,QAAQM,GAAG,CAAC4E,qBAAqB,KAAK,MAClC5C,YACA,CAAC,GAAGL;IACF,IAAIjC,QAAQM,GAAG,CAACC,YAAY,KAAK,QAAQ;QACvC,MAAM,qBAEL,CAFK,IAAInB,eACR,4DADI,qBAAA;mBAAA;wBAAA;0BAAA;QAEN;IACF,OAAO;QACL,MAAM,EAAE+F,OAAO,EAAE,GAAGzE,QAAQ;QAC5B,MAAM,EAAE0E,aAAa,EAAE,GACrB1E,QAAQ;QAEV,IAAI2E,UACFpD,KACGqD,GAAG,CAAC,CAACC,MACJ,OAAOA,QAAQ,WAAWA,MAAMJ,QAAQI,KAAK;gBAAEC,QAAQ;YAAK,IAE7DC,IAAI,CAAC,OAAO;QAEjBJ,UAAU,YAAYA,UAAU,WAAW,4BAA4B;;QACvED,cAAcpF,QAAQ0F,MAAM,CAACC,EAAE,EAAEN;IACnC;AACF;AAEN,6CAA6C;AAE7ChF","ignoreList":[0]}
1
+ {"version":3,"sources":["../../../../src/server/node-environment-extensions/fast-set-immediate.external.ts"],"sourcesContent":["import { promisify } from 'node:util'\nimport { InvariantError } from '../../shared/lib/invariant-error'\nimport { bindSnapshot } from '../app-render/async-local-storage'\n\ntype Execution = {\n state: ExecutionState\n queuedImmediates: QueueItem[]\n}\n\nenum ExecutionState {\n Waiting = 1,\n Working = 2,\n Finished = 3,\n Abandoned = 4,\n}\n\nlet wasEnabledAtLeastOnce = false\n\nlet pendingNextTicks = 0\nlet currentExecution: Execution | null = null\n\nconst originalSetImmediate = globalThis.setImmediate\nconst originalClearImmediate = globalThis.clearImmediate\nconst originalNextTick = process.nextTick\nconst originalSetImmediatePromisify: (typeof setImmediate)['__promisify__'] =\n typeof originalSetImmediate === 'function'\n ? // @ts-expect-error: the types for `promisify.custom` are strange\n originalSetImmediate[promisify.custom]\n : // if setImmediate is not defined, we must be in the edge runtime,\n // and won't ever enable the patch, so this can be a dummy value\n undefined!\n\nexport { originalSetImmediate as unpatchedSetImmediate }\n\nfunction install() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n // Nothing to patch. The exported functions all error if used in the edge runtime,\n // so we're not going to violate any assumptions by not patching.\n return\n } else {\n debug?.('installing fast setImmediate patch')\n\n const nodeTimers = require('node:timers') as typeof import('node:timers')\n globalThis.setImmediate = nodeTimers.setImmediate =\n // Workaround for missing __promisify__ which is not a real property\n patchedSetImmediate as unknown as typeof setImmediate\n globalThis.clearImmediate = nodeTimers.clearImmediate =\n patchedClearImmediate\n\n const nodeTimersPromises =\n require('node:timers/promises') as typeof import('node:timers/promises')\n nodeTimersPromises.setImmediate =\n patchedSetImmediatePromise as typeof import('node:timers/promises').setImmediate\n\n process.nextTick = patchedNextTick\n }\n}\n\n/**\n * **WARNING: This function changes the usual behavior of the event loop!**\n * **Be VERY careful about where you call it.**\n *\n * Starts capturing calls to `setImmediate` to run them as \"fast immediates\".\n * All calls captured in this way will be executed after the current task\n * (after callbacks from `process.nextTick()`, microtasks, and nextTicks scheduled from microtasks).\n * This function needs to be called again in each task that needs the\n * \"fast immediates\" behavior.\n *\n * ### Motivation\n *\n * We don't want `setImmediate` to be considered IO in Cache Components.\n * To achieve this in a staged (pre)render, we want to allow immediates scheduled\n * in stage N to run before stage N+1.\n * Since we schedule stages using sequential `setTimeout`, this isn't possible without\n * intercepting `setImmediate` and doing the scheduling on our own.\n * We refer to this as a \"fast immediate\".\n *\n * Notably, this affects React's `scheduleWork` in render, which uses `setImmediate`.\n * This is desirable -- if async work was scheduled during a stage, then it should\n * get to run before we finish that stage.\n *\n * ### Example\n *\n * ```ts\n * setTimeout(() => {\n * runPendingImmediatesAfterCurrentTask()\n * console.log(\"timeout 1\")\n * setImmediate(() => {\n * console.log(\"immediate!!!\")\n * })\n * })\n * setTimeout(() => {\n * console.log(\"timeout 2\")\n * })\n * ```\n * will print\n *\n * ```\n * timeout 1\n * immediate!!!\n * timeout 2\n * ```\n *\n * instead of the usual order\n * ```\n * timeout 1\n * timeout 2\n * immediate!!!\n * ```\n * > **NOTE**\n * > The above is *most common* order, but it's not guaranteed.\n * > Under some circumstances (e.g. when the event loop is blocked on CPU work),\n * > Node will reorder things and run the immediate before timeout 2.\n * > So, in a sense, we're just making this reordering happen consistently.\n *\n * Recursive `setImmediate` calls will also be executed as \"fast immediates\".\n * If multiple immediates were scheduled, `process.nextTick()` (and associated microtasks)\n * will be allowed to execute between them.\n * See the unit tests for more examples.\n * */\nexport function DANGEROUSLY_runPendingImmediatesAfterCurrentTask() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'DANGEROUSLY_runPendingImmediatesAfterCurrentTask cannot be called in the edge runtime'\n )\n } else {\n const execution = startCapturingImmediates()\n\n try {\n scheduleWorkAfterNextTicksAndMicrotasks(execution)\n } catch (err) {\n // If this error comes from a bail() call, rethrow it.\n if (execution.state === ExecutionState.Abandoned) {\n throw err\n }\n // Otherwise, bail out here.\n bail(\n execution,\n new InvariantError(\n 'An unexpected error occurred while starting to capture immediates',\n {\n cause: err,\n }\n )\n )\n }\n }\n}\n\n/**\n * This should always be called a task after `DANGEROUSLY_runPendingImmediatesAfterCurrentTask`\n * to make sure that everything executed as expected and we're not left in an inconsistent state.\n * Ideally, this wouldn't be necessary, but we're not in control of the event loop\n * and need to guard against unexpected behaviors not forseen in this implementation,\n * so we have to be defensive.\n */\nexport function expectNoPendingImmediates() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'expectNoPendingImmediates cannot be called in the edge runtime'\n )\n } else {\n if (currentExecution !== null) {\n bail(\n currentExecution,\n new InvariantError(\n `Expected all captured immediates to have been executed (state: ${ExecutionState[currentExecution.state]})`\n )\n )\n }\n }\n}\n\n/**\n * Wait until all nextTicks and microtasks spawned from the current task are done,\n * then execute any immediates that they queued.\n * */\nfunction scheduleWorkAfterNextTicksAndMicrotasks(execution: Execution) {\n if (execution.state !== ExecutionState.Waiting) {\n throw new InvariantError(\n `scheduleWorkAfterTicksAndMicrotasks can only be called while waiting (state: ${ExecutionState[execution.state]})`\n )\n }\n\n // We want to execute \"fast immediates\" after all the nextTicks and microtasks\n // spawned from the current task are done.\n // The ordering here is:\n //\n // 1. sync code\n // 2. process.nextTick (scheduled from sync code, or from one of these nextTicks)\n // 3. microtasks\n // 4. process.nextTick (scheduled from microtasks, e.g. `queueMicrotask(() => process.nextTick(callback))`)\n //\n // We want to run to run in step 4, because that's the latest point before the next tick.\n // However, there might also be other callbacks scheduled to run in that step.\n // But importantly, they had to be scheduled using a `process.nextTick`,\n // so we can detect them by checking if `pendingNextTicks > 0`.\n // In that case, we'll just reschedule ourselves in the same way again to let them run first.\n // (this process can theoretically repeat multiple times, hence the recursion).\n\n queueMicrotask(() => {\n // (note that this call won't increment `pendingNextTicks`,\n // only the patched `process.nextTick` does that, so this won't loop infinitely)\n originalNextTick(() => {\n // We're now in a nextTick, which means that we're executing inside `processTicksAndRejections`:\n // https://github.com/nodejs/node/blob/d546e7fd0bc3cbb4bcc2baae6f3aa44d2e81a413/lib/internal/process/task_queues.js#L84\n // All the work scheduled here will happen within that `processTicksAndRejections` loop.\n // Reading the source of `processTicksAndRejections` can help understand the timing here --\n // All we're really doing is strategically pushing callbacks into the two queues\n // (nextTicks and microtasks) that that function is currently looping over.\n\n try {\n if (\n execution.state === ExecutionState.Abandoned ||\n currentExecution !== execution\n ) {\n debug?.(`scheduler :: the execution was abandoned`)\n return\n }\n if (pendingNextTicks > 0) {\n // Other nextTicks have been scheduled. Let those run first, then try again --\n // we're simulating a event loop task, so all nextTicks should be exhausted before we execute.\n debug?.(`scheduler :: yielding to ${pendingNextTicks} nextTicks`)\n return scheduleWorkAfterNextTicksAndMicrotasks(execution)\n }\n\n // There's no other nextTicks, we're the last one, so we're about to move on to the next task (likely a timer).\n // Now, we can try and execute any queued immediates.\n return performWork(execution)\n } catch (err) {\n // If this error comes from a bail() call, rethrow it.\n\n // typescript can't tell that the state might've been mutated\n // and the narrowing from above is no longer valid\n const executionAfterWork = execution as Execution\n if (executionAfterWork.state === ExecutionState.Abandoned) {\n throw err\n }\n\n // Otherwise, bail out here (which will trigger an uncaught exception)\n // Note that we're using the same microtask trick as `safelyRunNextTickCallback`.\n queueMicrotask(() => {\n bail(\n execution,\n new InvariantError(\n 'An unexpected error occurred while executing immediates',\n { cause: err }\n )\n )\n })\n }\n })\n })\n}\n\n/** Execute one immediate, and schedule a check for more (in case there's others in the queue) */\nfunction performWork(execution: Execution) {\n if (execution.state === ExecutionState.Abandoned) {\n return\n }\n\n debug?.(`scheduler :: performing work`)\n\n if (execution.state !== ExecutionState.Waiting) {\n throw new InvariantError(\n `performWork can only be called while waiting (state: ${ExecutionState[execution.state]})`\n )\n }\n execution.state = ExecutionState.Working\n\n const queueItem = takeNextActiveQueueItem(execution)\n\n if (queueItem === null) {\n debug?.(`scheduler :: no immediates queued, exiting`)\n stopCapturingImmediates(execution)\n return\n }\n\n debug?.(`scheduler :: executing queued immediate`)\n\n const { immediateObject, callback, args } = queueItem\n\n immediateObject[INTERNALS].queueItem = null\n clearQueueItem(queueItem)\n\n // Execute the immediate.\n\n // If a sync error was thrown in the immediate, we want to trigger a `uncaughtException`.\n // However, we're executing in a nextTick, and if a nextTick callback errors,\n // It'll break out of `processTicksAndRejections` (note the lack of a `catch` block):\n // https://github.com/nodejs/node/blob/d546e7fd0bc3cbb4bcc2baae6f3aa44d2e81a413/lib/internal/process/task_queues.js#L81-L97\n // Meaning that the event loop will stop executing nextTicks and move on to the next timer\n // (or other phase of the event loop, but we expect to be running in a sequence of timers here).\n // Then, the remaining ticks will run after that timer, since they're still in the queue.\n //\n // This would completely break the timing we're trying to achieve here --\n // The point of this patch is to execute immediates before the next timer!\n // So, we need to work around this behavior. (both here and in our `process.nextTick` patch).\n //\n // We can sidestep this by catching the synchronous error and rethrowing it in a microtask.\n // (NOTE: if we use `queueMicrotask`, it'll trigger `uncaughtException`, not `unhandledRejection`,\n // because there's no promise being rejected.)\n //\n // This will make `uncaughtException` happen:\n // - Before the next fast immediate (`scheduleWorkAfterNextTicksAndMicrotasks` also uses `queueMicrotask`).\n // This is good, and matches usual observable behavior of immediates.\n // - AFTER nextTicks scheduled from the immediate itself.\n // This deviates from native setImmediate, which would call `uncaughtException` first,\n // and skip ahead to the next task as explained above.\n //\n // This is technically an observable difference in behavior, but it seems niche enough that\n // it shouldn't cause problems -- we don't expect user code to use `uncaughtException` for control flow,\n // only error reporting, so subtly changing the timing shouldn't matter.\n\n let didThrow = false\n let thrownValue: unknown = undefined\n queueMicrotask(() => {\n if (didThrow) {\n debug?.('scheduler :: rethrowing sync error from immediate in microtask')\n throw thrownValue\n }\n })\n\n try {\n if (args !== null) {\n callback.apply(null, args)\n } else {\n callback()\n }\n } catch (err) {\n // We'll rethrow the error in the microtask above.\n didThrow = true\n thrownValue = err\n }\n\n // Schedule the loop again in case there's more immediates after this one.\n // Note that we can't just check if the queue is empty now, because new immediates\n // might still be scheduled asynchronously, from an upcoming nextTick or microtask.\n execution.state = ExecutionState.Waiting\n scheduleWorkAfterNextTicksAndMicrotasks(execution)\n}\n\nfunction takeNextActiveQueueItem(execution: Execution): ActiveQueueItem | null {\n // Find the first (if any) queued immediate that wasn't cleared.\n // We don't remove immediates from the array when they're cleared,\n // so this requires some legwork to exclude (and possibly drop) cleared items.\n const { queuedImmediates } = execution\n\n let firstActiveItem: ActiveQueueItem | null = null\n let firstActiveItemIndex = -1\n for (let i = 0; i < queuedImmediates.length; i++) {\n const item = queuedImmediates[i]\n if (!item.isCleared) {\n firstActiveItem = item\n firstActiveItemIndex = i\n break\n }\n }\n\n if (firstActiveItem === null) {\n // We didn't find an active item.\n\n // If the queue isn't empty, then it must only contain cleared items. Empty it.\n if (queuedImmediates.length > 0) {\n queuedImmediates.length = 0\n }\n\n return null\n }\n\n // Remove all items up to and including `nextActiveItemIndex` from the queue.\n // (if it's not the first item, then it must be preceded by cleared items, which we want to drop anyway)\n if (firstActiveItemIndex === 0) {\n // Fast path - drop the first item\n // (`splice` creates a result array for the removed items, so this is more efficient)\n queuedImmediates.shift()\n } else {\n queuedImmediates.splice(0, firstActiveItemIndex + 1)\n }\n\n return firstActiveItem\n}\n\nfunction startCapturingImmediates(): Execution {\n if (currentExecution !== null) {\n bail(\n currentExecution,\n new InvariantError(\n `Cannot start capturing immediates again without finishing the previous task (state: ${ExecutionState[currentExecution.state]})`\n )\n )\n }\n wasEnabledAtLeastOnce = true\n\n const execution: Execution = {\n state: ExecutionState.Waiting,\n queuedImmediates: [],\n }\n currentExecution = execution\n\n return execution\n}\n\nfunction stopCapturingImmediates(execution: Execution) {\n if (execution.state === ExecutionState.Abandoned) {\n return\n }\n\n // This check enforces that we run performWork at least once before stopping\n // to make sure that we've waited for all the nextTicks and microtasks\n // that might've scheduled some immediates after sync code.\n if (execution.state !== ExecutionState.Working) {\n throw new InvariantError(\n `Cannot stop capturing immediates before execution is finished (state: ${ExecutionState[execution.state]})`\n )\n }\n\n execution.state = ExecutionState.Finished\n\n if (currentExecution === execution) {\n currentExecution = null\n }\n}\n\nfunction bail(execution: Execution, error: Error): never {\n // Reset the state as best we can to prevent further crashes.\n // Otherwise, any subsequent call to `DANGEROUSLY_runPendingImmediatesAfterCurrentTask`\n // would error, requiring a server restart to fix.\n\n if (currentExecution === execution) {\n currentExecution = null\n }\n\n execution.state = ExecutionState.Abandoned\n\n // If we have any queued immediates, schedule them with native `setImmediate` and clear the queue.\n // We don't want to skip running them altogether, because that could lead to\n // e.g. hanging promises (for `new Promise((resolve) => setImmediate(resolve))`),\n // but we're in an inconsistent state and can't run them as fast immediates,\n // so this is the next best thing.\n for (const queueItem of execution.queuedImmediates) {\n if (queueItem.isCleared) {\n continue\n }\n scheduleQueuedImmediateAsNativeImmediate(queueItem)\n }\n execution.queuedImmediates.length = 0\n\n // Don't reset `pendingNextTicks` -- it will reset to 0 on its own as the nextTicks execute.\n // If we set it to 0 here while we still have pending ticks, they'd decrement it below 0.\n\n throw error\n}\n\nfunction scheduleQueuedImmediateAsNativeImmediate(queueItem: ActiveQueueItem) {\n const { callback, args, immediateObject } = queueItem\n const hasRef = immediateObject[INTERNALS].hasRef\n\n clearQueueItem(queueItem)\n\n const nativeImmediate =\n args !== null\n ? originalSetImmediate(callback, ...args)\n : originalSetImmediate(callback)\n\n if (!hasRef) {\n nativeImmediate.unref()\n }\n\n // Make our fake immediate object proxy all relevant operations\n // (clearing, ref(), unref(), hasRef()) to the actual native immediate.\n proxyQueuedImmediateToNativeImmediate(immediateObject, nativeImmediate)\n}\n\ntype QueueItem = ActiveQueueItem | ClearedQueueItem\ntype ActiveQueueItem = {\n isCleared: false\n callback: (...args: any[]) => any\n args: any[] | null\n immediateObject: NextImmediate\n}\ntype ClearedQueueItem = {\n isCleared: true\n callback: null\n args: null\n immediateObject: null\n}\n\nfunction clearQueueItem(originalQueueItem: QueueItem) {\n const queueItem = originalQueueItem as ClearedQueueItem\n queueItem.isCleared = true\n queueItem.callback = null\n queueItem.args = null\n queueItem.immediateObject = null\n}\n\n//========================================================\n\nfunction patchedNextTick<TArgs extends any[]>(\n callback: (...args: TArgs) => void,\n ...args: TArgs\n): void\nfunction patchedNextTick() {\n if (currentExecution === null) {\n return originalNextTick.apply(\n null,\n // @ts-expect-error: this is valid, but typescript doesn't get it\n arguments\n )\n }\n\n if (arguments.length === 0 || typeof arguments[0] !== 'function') {\n // Let the original nextTick error for invalid arguments\n // so that we don't have to mirror the error message.\n originalNextTick.apply(\n null,\n // @ts-expect-error: explicitly passing arguments that we know are invalid\n arguments\n )\n\n // We expect the above call to throw. If it didn't, something's broken.\n bail(\n currentExecution,\n new InvariantError(\n 'Expected process.nextTick to reject invalid arguments'\n )\n )\n }\n\n debug?.(\n `scheduler :: process.nextTick called (previous pending: ${pendingNextTicks})`\n )\n\n const callback: (...args: any[]) => any = arguments[0]\n const args: any[] | null =\n arguments.length > 1 ? Array.prototype.slice.call(arguments, 1) : null\n\n pendingNextTicks += 1\n return originalNextTick(safelyRunNextTickCallback, callback, args)\n}\n\nfunction safelyRunNextTickCallback(\n callback: (...args: any[]) => any,\n args: any[] | null\n) {\n pendingNextTicks -= 1\n debug?.(\n `scheduler :: process.nextTick executing (still pending: ${pendingNextTicks})`\n )\n\n // Synchronous errors in nextTick break out of `processTicksAndRejections` and cause us\n // to move on to the next timer without having executed the whole nextTick queue,\n // which breaks our entire scheduling mechanism. See `performWork` for more details.\n try {\n if (args !== null) {\n callback.apply(null, args)\n } else {\n callback()\n }\n } catch (err) {\n // We want to make sure `nextTick` is cheap, so unlike `performWork`,\n // we only queue the microtask if an error actually occurs.\n // This (observably) changes the timing of `uncaughtException` even more,\n // because it'll run after microtasks queued from the nextTick,\n // but hopefully this is niche enough to not affect any real world code.\n queueMicrotask(() => {\n debug?.(`scheduler :: rethrowing sync error from nextTick in a microtask`)\n throw err\n })\n }\n}\n\nfunction patchedSetImmediate<TArgs extends any[]>(\n callback: (...args: TArgs) => void,\n ...args: TArgs\n): NodeJS.Immediate\nfunction patchedSetImmediate(callback: (args: void) => void): NodeJS.Immediate\nfunction patchedSetImmediate(): NodeJS.Immediate {\n if (currentExecution === null) {\n return originalSetImmediate.apply(\n null,\n // @ts-expect-error: this is valid, but typescript doesn't get it\n arguments\n )\n }\n\n if (arguments.length === 0 || typeof arguments[0] !== 'function') {\n // Let the original setImmediate error for invalid arguments\n // so that we don't have to mirror the error message.\n originalSetImmediate.apply(\n null,\n // @ts-expect-error: explicitly passing arguments that we know are invalid\n arguments\n )\n\n // We expect the above call to throw. If it didn't, something's broken.\n bail(\n currentExecution,\n new InvariantError('Expected setImmediate to reject invalid arguments')\n )\n }\n\n const callback: (...args: any[]) => any = arguments[0]\n const args: any[] | null =\n arguments.length > 1 ? Array.prototype.slice.call(arguments, 1) : null\n\n // Normally, Node would capture and propagate the async context to the immediate.\n // We'll be running it on our own queue, so we need to propagate it ourselves.\n const callbackWithAsyncContext = bindSnapshot(callback)\n\n const immediateObject = new NextImmediate()\n\n const queueItem: ActiveQueueItem = {\n isCleared: false,\n callback: callbackWithAsyncContext,\n args,\n immediateObject,\n }\n currentExecution.queuedImmediates.push(queueItem)\n\n immediateObject[INTERNALS].queueItem = queueItem\n\n return immediateObject\n}\n\nfunction patchedSetImmediatePromise<T = void>(\n value: T,\n options?: import('node:timers').TimerOptions\n): Promise<T> {\n if (currentExecution === null) {\n return originalSetImmediatePromisify(value, options)\n }\n\n return new Promise<T>((resolve, reject) => {\n // The abort signal makes the promise reject.\n // If it is already aborted, we reject immediately.\n const signal = options?.signal\n if (signal && signal.aborted) {\n return reject(signal.reason)\n }\n\n const immediate = patchedSetImmediate(resolve, value)\n\n // Unref-ing only really has an observable effect if we bail out to a native immediate,\n // but we do it for completeness\n if (options?.ref === false) {\n immediate.unref()\n }\n\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n patchedClearImmediate(immediate)\n reject(signal.reason)\n },\n { once: true }\n )\n }\n })\n}\n\npatchedSetImmediate[promisify.custom] = patchedSetImmediatePromise\n\nconst patchedClearImmediate = (\n immediateObject: NodeJS.Immediate | undefined\n) => {\n // NOTE: we defensively check for patched immediates even if we're not\n // currently capturing immediates, because the objects returned from\n // the patched setImmediate can be kept around for arbitrarily long.\n // As an optimization, we only do this if the patch was enabled at least once --\n // otherwise, no patched objects could've been created.\n if (\n wasEnabledAtLeastOnce &&\n immediateObject &&\n typeof immediateObject === 'object' &&\n INTERNALS in immediateObject\n ) {\n ;(immediateObject as NextImmediate)[Symbol.dispose]()\n } else {\n originalClearImmediate(immediateObject)\n }\n}\n\n//========================================================\n\nconst INTERNALS: unique symbol = Symbol.for('next.Immediate.internals')\n\ntype NextImmediateInternals =\n | {\n /** Stored to reflect `ref()`/`unref()` calls, but has no effect otherwise */\n hasRef: boolean\n queueItem: ActiveQueueItem | null\n nativeImmediate: null\n }\n | {\n hasRef: null\n queueItem: null\n nativeImmediate: NodeJS.Immediate\n }\n\nfunction proxyQueuedImmediateToNativeImmediate(\n immediateObject: NextImmediate,\n nativeImmediate: NodeJS.Immediate\n) {\n immediateObject[INTERNALS].hasRef = null\n immediateObject[INTERNALS].queueItem = null\n immediateObject[INTERNALS].nativeImmediate = nativeImmediate\n}\n\n/** Makes sure that we're implementing all the public `Immediate` methods */\ninterface NativeImmediate extends NodeJS.Immediate {}\n\n/** Implements a shim for the native `Immediate` class returned by `setImmediate` */\nclass NextImmediate implements NativeImmediate {\n [INTERNALS]: NextImmediateInternals = {\n queueItem: null,\n hasRef: true,\n nativeImmediate: null,\n }\n hasRef() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n return internals.hasRef\n } else if (internals.nativeImmediate) {\n return internals.nativeImmediate.hasRef()\n } else {\n // if we're no longer queued (cleared or executed), hasRef is always false\n return false\n }\n }\n ref() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n internals.hasRef = true\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate.ref()\n }\n return this\n }\n unref() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n internals.hasRef = false\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate.unref()\n }\n return this\n }\n\n /**\n * Node invokes `_onImmediate` when an immediate is executed:\n * https://github.com/nodejs/node/blob/42d363205715ffa5a4a6d90f4be1311487053d65/lib/internal/timers.js#L504\n * It's visible on the public types, so we want to have it here for parity, but it's a noop.\n * */\n _onImmediate() {}\n\n [Symbol.dispose]() {\n // This is equivalent to `clearImmediate`.\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n // this is still queued. drop it.\n const queueItem = internals.queueItem\n internals.queueItem = null\n clearQueueItem(queueItem)\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate[Symbol.dispose]()\n }\n }\n}\n\n// ==========================================\n\nconst debug =\n process.env.NEXT_DEBUG_IMMEDIATES !== '1'\n ? undefined\n : (...args: any[]) => {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'Fast setImmediate is not available in the edge runtime.'\n )\n } else {\n const { inspect } = require('node:util') as typeof import('node:util')\n const { writeFileSync } =\n require('node:fs') as typeof import('node:fs')\n\n let logLine =\n args\n .map((arg) =>\n typeof arg === 'string' ? arg : inspect(arg, { colors: true })\n )\n .join(' ') + '\\n'\n\n logLine = '\\x1B[2m' + logLine + '\\x1B[22m' // styleText('dim', logLine)\n writeFileSync(process.stdout.fd, logLine)\n }\n }\n\n// ==========================================\n\ninstall()\n"],"names":["promisify","InvariantError","bindSnapshot","ExecutionState","wasEnabledAtLeastOnce","pendingNextTicks","currentExecution","originalSetImmediate","globalThis","setImmediate","originalClearImmediate","clearImmediate","originalNextTick","process","nextTick","originalSetImmediatePromisify","custom","undefined","unpatchedSetImmediate","install","env","NEXT_RUNTIME","debug","nodeTimers","require","patchedSetImmediate","patchedClearImmediate","nodeTimersPromises","patchedSetImmediatePromise","patchedNextTick","DANGEROUSLY_runPendingImmediatesAfterCurrentTask","execution","startCapturingImmediates","scheduleWorkAfterNextTicksAndMicrotasks","err","state","bail","cause","expectNoPendingImmediates","queueMicrotask","performWork","executionAfterWork","queueItem","takeNextActiveQueueItem","stopCapturingImmediates","immediateObject","callback","args","INTERNALS","clearQueueItem","didThrow","thrownValue","apply","queuedImmediates","firstActiveItem","firstActiveItemIndex","i","length","item","isCleared","shift","splice","error","scheduleQueuedImmediateAsNativeImmediate","hasRef","nativeImmediate","unref","proxyQueuedImmediateToNativeImmediate","originalQueueItem","arguments","Array","prototype","slice","call","safelyRunNextTickCallback","callbackWithAsyncContext","NextImmediate","push","value","options","Promise","resolve","reject","signal","aborted","reason","immediate","ref","addEventListener","once","Symbol","dispose","for","internals","_onImmediate","NEXT_DEBUG_IMMEDIATES","inspect","writeFileSync","logLine","map","arg","colors","join","stdout","fd"],"mappings":"AAAA,SAASA,SAAS,QAAQ,YAAW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QACJT,QAAQO,GAAG,CAAC2E,qBAAqB,KAAK,MAClC9E,YACA,CAAC,GAAG8B;IACF,IAAIlC,QAAQO,GAAG,CAACC,YAAY,KAAK,QAAQ;QACvC,MAAM,qBAEL,CAFK,IAAIpB,eACR,4DADI,qBAAA;mBAAA;wBAAA;0BAAA;QAEN;IACF,OAAO;QACL,MAAM,EAAE+F,OAAO,EAAE,GAAGxE,QAAQ;QAC5B,MAAM,EAAEyE,aAAa,EAAE,GACrBzE,QAAQ;QAEV,IAAI0E,UACFnD,KACGoD,GAAG,CAAC,CAACC,MACJ,OAAOA,QAAQ,WAAWA,MAAMJ,QAAQI,KAAK;gBAAEC,QAAQ;YAAK,IAE7DC,IAAI,CAAC,OAAO;QAEjBJ,UAAU,YAAYA,UAAU,WAAW,4BAA4B;;QACvED,cAAcpF,QAAQ0F,MAAM,CAACC,EAAE,EAAEN;IACnC;AACF;AAEN,6CAA6C;AAE7C/E","ignoreList":[0]}
@@ -1,5 +1,5 @@
1
1
  export function isStableBuild() {
2
- return !"16.1.1-canary.31"?.includes('canary') && !process.env.__NEXT_TEST_MODE && !process.env.NEXT_PRIVATE_LOCAL_DEV;
2
+ return !"16.1.1-canary.32"?.includes('canary') && !process.env.__NEXT_TEST_MODE && !process.env.NEXT_PRIVATE_LOCAL_DEV;
3
3
  }
4
4
  export class CanaryOnlyConfigError extends Error {
5
5
  constructor(arg){
@@ -74,25 +74,13 @@ function _interop_require_wildcard(obj, nodeInterop) {
74
74
  }
75
75
  const glob = (0, _util.promisify)(_glob.default);
76
76
  /**
77
- * Escapes bracket expressions that correspond to existing directories.
78
- * This allows Next.js dynamic routes like [slug] to work with glob patterns.
77
+ * Escapes Next.js dynamic route bracket expressions so glob treats them as
78
+ * literal directory names rather than character classes.
79
79
  *
80
80
  * e.g., "app/blog/[slug]/** /page.tsx" → "app/blog/\[slug\]/** /page.tsx"
81
- * (if app/blog/[slug] directory exists)
82
- */ function escapeExistingBrackets(pattern, projectDir) {
83
- // Match bracket expressions: [name], [...name], [[...name]]
84
- const bracketRegex = /\[\[?\.\.\.[^\]]+\]?\]|\[[^\]]+\]/g;
85
- let lastIndex = 0;
86
- let result = '';
87
- let match;
88
- while((match = bracketRegex.exec(pattern)) !== null){
89
- const pathPrefix = pattern.slice(0, match.index + match[0].length);
90
- const exists = _fs.default.existsSync(_path.default.join(projectDir, pathPrefix));
91
- result += pattern.slice(lastIndex, match.index);
92
- result += exists ? match[0].replace(/\[/g, '\\[').replace(/\]/g, '\\]') : match[0];
93
- lastIndex = match.index + match[0].length;
94
- }
95
- return result + pattern.slice(lastIndex);
81
+ */ function escapeBrackets(pattern) {
82
+ // Match Next.js dynamic route patterns: [name], [...name], [[...name]]
83
+ return pattern.replace(/\[\[?\.\.\.[^\]]+\]?\]|\[[^\]]+\]/g, (match)=>match.replace(/\[/g, '\\[').replace(/\]/g, '\\]'));
96
84
  }
97
85
  async function resolveBuildPaths(patterns, projectDir) {
98
86
  const appPaths = new Set();
@@ -101,8 +89,8 @@ async function resolveBuildPaths(patterns, projectDir) {
101
89
  const trimmed = pattern.trim();
102
90
  if (!trimmed) continue;
103
91
  try {
104
- // Escape brackets that correspond to existing Next.js dynamic route directories
105
- const escapedPattern = escapeExistingBrackets(trimmed, projectDir);
92
+ // Escape brackets for Next.js dynamic route directories
93
+ const escapedPattern = escapeBrackets(trimmed);
106
94
  const matches = await glob(escapedPattern, {
107
95
  cwd: projectDir
108
96
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/resolve-build-paths.ts"],"sourcesContent":["import { promisify } from 'util'\nimport globOriginal from 'next/dist/compiled/glob'\nimport * as Log from '../build/output/log'\nimport path from 'path'\nimport fs from 'fs'\nimport isError from './is-error'\n\nconst glob = promisify(globOriginal)\n\ninterface ResolvedBuildPaths {\n appPaths: string[]\n pagePaths: string[]\n}\n\n/**\n * Escapes bracket expressions that correspond to existing directories.\n * This allows Next.js dynamic routes like [slug] to work with glob patterns.\n *\n * e.g., \"app/blog/[slug]/** /page.tsx\" → \"app/blog/\\[slug\\]/** /page.tsx\"\n * (if app/blog/[slug] directory exists)\n */\nfunction escapeExistingBrackets(pattern: string, projectDir: string): string {\n // Match bracket expressions: [name], [...name], [[...name]]\n const bracketRegex = /\\[\\[?\\.\\.\\.[^\\]]+\\]?\\]|\\[[^\\]]+\\]/g\n let lastIndex = 0\n let result = ''\n let match: RegExpExecArray | null\n\n while ((match = bracketRegex.exec(pattern)) !== null) {\n const pathPrefix = pattern.slice(0, match.index + match[0].length)\n const exists = fs.existsSync(path.join(projectDir, pathPrefix))\n\n result += pattern.slice(lastIndex, match.index)\n result += exists\n ? match[0].replace(/\\[/g, '\\\\[').replace(/\\]/g, '\\\\]')\n : match[0]\n lastIndex = match.index + match[0].length\n }\n\n return result + pattern.slice(lastIndex)\n}\n\n/**\n * Resolves glob patterns and explicit paths to actual file paths.\n * Categorizes them into App Router and Pages Router paths.\n */\nexport async function resolveBuildPaths(\n patterns: string[],\n projectDir: string\n): Promise<ResolvedBuildPaths> {\n const appPaths: Set<string> = new Set()\n const pagePaths: Set<string> = new Set()\n\n for (const pattern of patterns) {\n const trimmed = pattern.trim()\n if (!trimmed) continue\n\n try {\n // Escape brackets that correspond to existing Next.js dynamic route directories\n const escapedPattern = escapeExistingBrackets(trimmed, projectDir)\n const matches = (await glob(escapedPattern, {\n cwd: projectDir,\n })) as string[]\n\n if (matches.length === 0) {\n Log.warn(`Pattern \"${trimmed}\" did not match any files`)\n }\n\n for (const file of matches) {\n if (!fs.statSync(path.join(projectDir, file)).isDirectory()) {\n categorizeAndAddPath(file, appPaths, pagePaths)\n }\n }\n } catch (error) {\n throw new Error(\n `Failed to resolve pattern \"${trimmed}\": ${\n isError(error) ? error.message : String(error)\n }`\n )\n }\n }\n\n return {\n appPaths: Array.from(appPaths).sort(),\n pagePaths: Array.from(pagePaths).sort(),\n }\n}\n\n/**\n * Categorizes a file path to either app or pages router based on its prefix.\n *\n * Examples:\n * - \"app/page.tsx\" → appPaths.add(\"/page.tsx\")\n * - \"pages/index.tsx\" → pagePaths.add(\"/index.tsx\")\n */\nfunction categorizeAndAddPath(\n filePath: string,\n appPaths: Set<string>,\n pagePaths: Set<string>\n): void {\n const normalized = filePath.replace(/\\\\/g, '/')\n\n if (normalized.startsWith('app/')) {\n appPaths.add('/' + normalized.slice(4))\n } else if (normalized.startsWith('pages/')) {\n pagePaths.add('/' + normalized.slice(6))\n }\n}\n\n/**\n * Parse build paths from comma-separated format\n * Supports:\n * - Comma-separated values: \"app/page.tsx,app/about/page.tsx\"\n *\n * @param input - String input to parse\n * @returns Array of path patterns\n */\nexport function parseBuildPathsInput(input: string): string[] {\n // Comma-separated values\n return input\n .split(',')\n .map((p) => p.trim())\n .filter((p) => p.length > 0)\n}\n"],"names":["parseBuildPathsInput","resolveBuildPaths","glob","promisify","globOriginal","escapeExistingBrackets","pattern","projectDir","bracketRegex","lastIndex","result","match","exec","pathPrefix","slice","index","length","exists","fs","existsSync","path","join","replace","patterns","appPaths","Set","pagePaths","trimmed","trim","escapedPattern","matches","cwd","Log","warn","file","statSync","isDirectory","categorizeAndAddPath","error","Error","isError","message","String","Array","from","sort","filePath","normalized","startsWith","add","input","split","map","p","filter"],"mappings":";;;;;;;;;;;;;;;IAqHgBA,oBAAoB;eAApBA;;IAvEMC,iBAAiB;eAAjBA;;;sBA9CI;6DACD;6DACJ;6DACJ;2DACF;gEACK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEpB,MAAMC,OAAOC,IAAAA,eAAS,EAACC,aAAY;AAOnC;;;;;;CAMC,GACD,SAASC,uBAAuBC,OAAe,EAAEC,UAAkB;IACjE,4DAA4D;IAC5D,MAAMC,eAAe;IACrB,IAAIC,YAAY;IAChB,IAAIC,SAAS;IACb,IAAIC;IAEJ,MAAO,AAACA,CAAAA,QAAQH,aAAaI,IAAI,CAACN,QAAO,MAAO,KAAM;QACpD,MAAMO,aAAaP,QAAQQ,KAAK,CAAC,GAAGH,MAAMI,KA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AAA;YAIN;QACF;IACF;IAEA,OAAO;QACLd,UAAUmB,MAAMC,IAAI,CAACpB,UAAUqB,IAAI;QACnCnB,WAAWiB,MAAMC,IAAI,CAAClB,WAAWmB,IAAI;IACvC;AACF;AAEA;;;;;;CAMC,GACD,SAASR,qBACPS,QAAgB,EAChBtB,QAAqB,EACrBE,SAAsB;IAEtB,MAAMqB,aAAaD,SAASxB,OAAO,CAAC,OAAO;IAE3C,IAAIyB,WAAWC,UAAU,CAAC,SAAS;QACjCxB,SAASyB,GAAG,CAAC,MAAMF,WAAWjC,KAAK,CAAC;IACtC,OAAO,IAAIiC,WAAWC,UAAU,CAAC,WAAW;QAC1CtB,UAAUuB,GAAG,CAAC,MAAMF,WAAWjC,KAAK,CAAC;IACvC;AACF;AAUO,SAASd,qBAAqBkD,KAAa;IAChD,yBAAyB;IACzB,OAAOA,MACJC,KAAK,CAAC,KACNC,GAAG,CAAC,CAACC,IAAMA,EAAEzB,IAAI,IACjB0B,MAAM,CAAC,CAACD,IAAMA,EAAErC,MAAM,GAAG;AAC9B","ignoreList":[0]}
1
+ {"version":3,"sources":["../../src/lib/resolve-build-paths.ts"],"sourcesContent":["import { promisify } from 'util'\nimport globOriginal from 'next/dist/compiled/glob'\nimport * as Log from '../build/output/log'\nimport path from 'path'\nimport fs from 'fs'\nimport isError from './is-error'\n\nconst glob = promisify(globOriginal)\n\ninterface ResolvedBuildPaths {\n appPaths: string[]\n pagePaths: string[]\n}\n\n/**\n * Escapes Next.js dynamic route bracket expressions so glob treats them as\n * literal directory names rather than character classes.\n *\n * e.g., \"app/blog/[slug]/** /page.tsx\" → \"app/blog/\\[slug\\]/** /page.tsx\"\n */\nfunction escapeBrackets(pattern: string): string {\n // Match Next.js dynamic route patterns: [name], [...name], [[...name]]\n return pattern.replace(/\\[\\[?\\.\\.\\.[^\\]]+\\]?\\]|\\[[^\\]]+\\]/g, (match) =>\n match.replace(/\\[/g, '\\\\[').replace(/\\]/g, '\\\\]')\n )\n}\n\n/**\n * Resolves glob patterns and explicit paths to actual file paths.\n * Categorizes them into App Router and Pages Router paths.\n */\nexport async function resolveBuildPaths(\n patterns: string[],\n projectDir: string\n): Promise<ResolvedBuildPaths> {\n const appPaths: Set<string> = new Set()\n const pagePaths: Set<string> = new Set()\n\n for (const pattern of patterns) {\n const trimmed = pattern.trim()\n if (!trimmed) continue\n\n try {\n // Escape brackets for Next.js dynamic route directories\n const escapedPattern = escapeBrackets(trimmed)\n const matches = (await glob(escapedPattern, {\n cwd: projectDir,\n })) as string[]\n\n if (matches.length === 0) {\n Log.warn(`Pattern \"${trimmed}\" did not match any files`)\n }\n\n for (const file of matches) {\n if (!fs.statSync(path.join(projectDir, file)).isDirectory()) {\n categorizeAndAddPath(file, appPaths, pagePaths)\n }\n }\n } catch (error) {\n throw new Error(\n `Failed to resolve pattern \"${trimmed}\": ${\n isError(error) ? error.message : String(error)\n }`\n )\n }\n }\n\n return {\n appPaths: Array.from(appPaths).sort(),\n pagePaths: Array.from(pagePaths).sort(),\n }\n}\n\n/**\n * Categorizes a file path to either app or pages router based on its prefix.\n *\n * Examples:\n * - \"app/page.tsx\" → appPaths.add(\"/page.tsx\")\n * - \"pages/index.tsx\" → pagePaths.add(\"/index.tsx\")\n */\nfunction categorizeAndAddPath(\n filePath: string,\n appPaths: Set<string>,\n pagePaths: Set<string>\n): void {\n const normalized = filePath.replace(/\\\\/g, '/')\n\n if (normalized.startsWith('app/')) {\n appPaths.add('/' + normalized.slice(4))\n } else if (normalized.startsWith('pages/')) {\n pagePaths.add('/' + normalized.slice(6))\n }\n}\n\n/**\n * Parse build paths from comma-separated format\n * Supports:\n * - Comma-separated values: \"app/page.tsx,app/about/page.tsx\"\n *\n * @param input - String input to parse\n * @returns Array of path patterns\n */\nexport function parseBuildPathsInput(input: string): string[] {\n // Comma-separated values\n return input\n .split(',')\n .map((p) => p.trim())\n .filter((p) => p.length > 0)\n}\n"],"names":["parseBuildPathsInput","resolveBuildPaths","glob","promisify","globOriginal","escapeBrackets","pattern","replace","match","patterns","projectDir","appPaths","Set","pagePaths","trimmed","trim","escapedPattern","matches","cwd","length","Log","warn","file","fs","statSync","path","join","isDirectory","categorizeAndAddPath","error","Error","isError","message","String","Array","from","sort","filePath","normalized","startsWith","add","slice","input","split","map","p","filter"],"mappings":";;;;;;;;;;;;;;;IAsGgBA,oBAAoB;eAApBA;;IAvEMC,iBAAiB;eAAjBA;;;sBA/BI;6DACD;6DACJ;6DACJ;2DACF;gEACK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEpB,MAAMC,OAAOC,IAAAA,eAAS,EAACC,aAAY;AAOnC;;;;;CAKC,GACD,SAASC,eAAeC,OAAe;IACrC,uEAAuE;IACvE,OAAOA,QAAQC,OAAO,CAAC,sCAAsC,CAACC,QAC5DA,MAAMD,OAAO,CAAC,OAAO,OAAOA,OAAO,CAAC,OAAO;AAE/C;AAMO,eAAeN,kBACpBQ,QAAkB,EAClBC,UAAkB;IAElB,MAAMC,WAAwB,IAAIC;IAClC,MAAMC,YAAyB,IAAID;IAEnC,KAAK,MAAMN,WAAWG,SAAU;QAC9B,MAAMK,UAAUR,QAAQS,IAAI;QAC5B,IAAI,CAACD,SAAS;QAEd,IAAI;YACF,wDAAwD;YACxD,MAAME,iBAAiBX,eAAeS;YACtC,MAAMG,UAAW,MAAMf,KAAKc,gBAAgB;gBAC1CE,KAAKR;YACP;YAEA,IAAIO,QAAQE,MAAM,KAAK,GAAG;gBACxBC,KAAIC,IAAI,CAAC,CAAC,SAAS,EAAEP,QAAQ,yBAAyB,CAAC;YACzD;YAEA,KAAK,MAAMQ,QAAQL,QAAS;gBAC1B,IAAI,CAACM,WAAE,CAACC,QAAQ,CAACC,aAAI,CAACC,IAAI,CAAChB,YAAYY,OAAOK,WAAW,IAAI;oBAC3DC,qBAAqBN,MAAMX,UAAUE;gBACvC;YACF;QACF,EAAE,OAAOgB,OAAO;YACd,MAAM,qBAIL,CAJK,IAAIC,MACR,CAAC,2BAA2B,EAAEhB,QAAQ,GAAG,EACvCiB,IAAAA,gBAAO,EAACF,SAASA,MAAMG,OAAO,GAAGC,OAAOJ,QACxC,GAHE,qBAAA;uBAAA;4BAAA;8BAAA;YAIN;QACF;IACF;IAEA,OAAO;QACLlB,UAAUuB,MAAMC,IAAI,CAACxB,UAAUyB,IAAI;QACnCvB,WAAWqB,MAAMC,IAAI,CAACtB,WAAWuB,IAAI;IACvC;AACF;AAEA;;;;;;CAMC,GACD,SAASR,qBACPS,QAAgB,EAChB1B,QAAqB,EACrBE,SAAsB;IAEtB,MAAMyB,aAAaD,SAAS9B,OAAO,CAAC,OAAO;IAE3C,IAAI+B,WAAWC,UAAU,CAAC,SAAS;QACjC5B,SAAS6B,GAAG,CAAC,MAAMF,WAAWG,KAAK,CAAC;IACtC,OAAO,IAAIH,WAAWC,UAAU,CAAC,WAAW;QAC1C1B,UAAU2B,GAAG,CAAC,MAAMF,WAAWG,KAAK,CAAC;IACvC;AACF;AAUO,SAASzC,qBAAqB0C,KAAa;IAChD,yBAAyB;IACzB,OAAOA,MACJC,KAAK,CAAC,KACNC,GAAG,CAAC,CAACC,IAAMA,EAAE9B,IAAI,IACjB+B,MAAM,CAAC,CAACD,IAAMA,EAAE1B,MAAM,GAAG;AAC9B","ignoreList":[0]}
@@ -153,7 +153,7 @@ async function createHotReloaderTurbopack(opts, serverFields, distDir, resetFetc
153
153
  }
154
154
  const hasRewrites = opts.fsChecker.rewrites.afterFiles.length > 0 || opts.fsChecker.rewrites.beforeFiles.length > 0 || opts.fsChecker.rewrites.fallback.length > 0;
155
155
  const hotReloaderSpan = (0, _trace.trace)('hot-reloader', undefined, {
156
- version: "16.1.1-canary.31"
156
+ version: "16.1.1-canary.32"
157
157
  });
158
158
  // Ensure the hotReloaderSpan is flushed immediately as it's the parentSpan for all processing
159
159
  // of the current `next dev` invocation.
@@ -233,7 +233,7 @@ class HotReloaderWebpack {
233
233
  this.previewProps = previewProps;
234
234
  this.rewrites = rewrites;
235
235
  this.hotReloaderSpan = (0, _trace.trace)('hot-reloader', undefined, {
236
- version: "16.1.1-canary.31"
236
+ version: "16.1.1-canary.32"
237
237
  });
238
238
  // Ensure the hotReloaderSpan is flushed immediately as it's the parentSpan for all processing
239
239
  // of the current `next dev` invocation.
@@ -85,7 +85,7 @@ function logStartInfo({ networkUrl, appUrl, envInfo, logBundler }) {
85
85
  if (parts.length > 0) {
86
86
  versionSuffix = ` (${parts.join(', ')})`;
87
87
  }
88
- _log.bootstrap(`${(0, _picocolors.bold)((0, _picocolors.purple)(`${_log.prefixes.ready} Next.js ${"16.1.1-canary.31"}`))}${versionSuffix}`);
88
+ _log.bootstrap(`${(0, _picocolors.bold)((0, _picocolors.purple)(`${_log.prefixes.ready} Next.js ${"16.1.1-canary.32"}`))}${versionSuffix}`);
89
89
  if (appUrl) {
90
90
  _log.bootstrap(`- Local: ${appUrl}`);
91
91
  }
@@ -177,7 +177,7 @@ async function getRequestHandlers({ dir, port, isDev, onDevServerCleanup, server
177
177
  async function startServer(serverOptions) {
178
178
  const { dir, isDev, hostname, minimalMode, allowRetry, keepAliveTimeout, selfSignedCertificate } = serverOptions;
179
179
  let { port } = serverOptions;
180
- process.title = `next-server (v${"16.1.1-canary.31"})`;
180
+ process.title = `next-server (v${"16.1.1-canary.32"})`;
181
181
  let handlersReady = ()=>{};
182
182
  let handlersError = ()=>{};
183
183
  let handlersPromise = new Promise((resolve, reject)=>{
@@ -40,8 +40,8 @@ let currentExecution = null;
40
40
  const originalSetImmediate = globalThis.setImmediate;
41
41
  const originalClearImmediate = globalThis.clearImmediate;
42
42
  const originalNextTick = process.nextTick;
43
- const originalSetImmediatePromisify = // @ts-expect-error: the types for `promisify.custom` are strange
44
- originalSetImmediate[_nodeutil.promisify.custom];
43
+ const originalSetImmediatePromisify = typeof originalSetImmediate === 'function' ? originalSetImmediate[_nodeutil.promisify.custom] : // and won't ever enable the patch, so this can be a dummy value
44
+ undefined;
45
45
  function install() {
46
46
  if (process.env.NEXT_RUNTIME === 'edge') {
47
47
  // Nothing to patch. The exported functions all error if used in the edge runtime,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/node-environment-extensions/fast-set-immediate.external.ts"],"sourcesContent":["import { promisify } from 'node:util'\nimport { InvariantError } from '../../shared/lib/invariant-error'\nimport { bindSnapshot } from '../app-render/async-local-storage'\n\ntype Execution = {\n state: ExecutionState\n queuedImmediates: QueueItem[]\n}\n\nenum ExecutionState {\n Waiting = 1,\n Working = 2,\n Finished = 3,\n Abandoned = 4,\n}\n\nlet wasEnabledAtLeastOnce = false\n\nlet pendingNextTicks = 0\nlet currentExecution: Execution | null = null\n\nconst originalSetImmediate = globalThis.setImmediate\nconst originalClearImmediate = globalThis.clearImmediate\nconst originalNextTick = process.nextTick\nconst originalSetImmediatePromisify: (typeof setImmediate)['__promisify__'] =\n // @ts-expect-error: the types for `promisify.custom` are strange\n originalSetImmediate[promisify.custom]\n\nexport { originalSetImmediate as unpatchedSetImmediate }\n\nfunction install() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n // Nothing to patch. The exported functions all error if used in the edge runtime,\n // so we're not going to violate any assumptions by not patching.\n return\n } else {\n debug?.('installing fast setImmediate patch')\n\n const nodeTimers = require('node:timers') as typeof import('node:timers')\n globalThis.setImmediate = nodeTimers.setImmediate =\n // Workaround for missing __promisify__ which is not a real property\n patchedSetImmediate as unknown as typeof setImmediate\n globalThis.clearImmediate = nodeTimers.clearImmediate =\n patchedClearImmediate\n\n const nodeTimersPromises =\n require('node:timers/promises') as typeof import('node:timers/promises')\n nodeTimersPromises.setImmediate =\n patchedSetImmediatePromise as typeof import('node:timers/promises').setImmediate\n\n process.nextTick = patchedNextTick\n }\n}\n\n/**\n * **WARNING: This function changes the usual behavior of the event loop!**\n * **Be VERY careful about where you call it.**\n *\n * Starts capturing calls to `setImmediate` to run them as \"fast immediates\".\n * All calls captured in this way will be executed after the current task\n * (after callbacks from `process.nextTick()`, microtasks, and nextTicks scheduled from microtasks).\n * This function needs to be called again in each task that needs the\n * \"fast immediates\" behavior.\n *\n * ### Motivation\n *\n * We don't want `setImmediate` to be considered IO in Cache Components.\n * To achieve this in a staged (pre)render, we want to allow immediates scheduled\n * in stage N to run before stage N+1.\n * Since we schedule stages using sequential `setTimeout`, this isn't possible without\n * intercepting `setImmediate` and doing the scheduling on our own.\n * We refer to this as a \"fast immediate\".\n *\n * Notably, this affects React's `scheduleWork` in render, which uses `setImmediate`.\n * This is desirable -- if async work was scheduled during a stage, then it should\n * get to run before we finish that stage.\n *\n * ### Example\n *\n * ```ts\n * setTimeout(() => {\n * runPendingImmediatesAfterCurrentTask()\n * console.log(\"timeout 1\")\n * setImmediate(() => {\n * console.log(\"immediate!!!\")\n * })\n * })\n * setTimeout(() => {\n * console.log(\"timeout 2\")\n * })\n * ```\n * will print\n *\n * ```\n * timeout 1\n * immediate!!!\n * timeout 2\n * ```\n *\n * instead of the usual order\n * ```\n * timeout 1\n * timeout 2\n * immediate!!!\n * ```\n * > **NOTE**\n * > The above is *most common* order, but it's not guaranteed.\n * > Under some circumstances (e.g. when the event loop is blocked on CPU work),\n * > Node will reorder things and run the immediate before timeout 2.\n * > So, in a sense, we're just making this reordering happen consistently.\n *\n * Recursive `setImmediate` calls will also be executed as \"fast immediates\".\n * If multiple immediates were scheduled, `process.nextTick()` (and associated microtasks)\n * will be allowed to execute between them.\n * See the unit tests for more examples.\n * */\nexport function DANGEROUSLY_runPendingImmediatesAfterCurrentTask() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'DANGEROUSLY_runPendingImmediatesAfterCurrentTask cannot be called in the edge runtime'\n )\n } else {\n const execution = startCapturingImmediates()\n\n try {\n scheduleWorkAfterNextTicksAndMicrotasks(execution)\n } catch (err) {\n // If this error comes from a bail() call, rethrow it.\n if (execution.state === ExecutionState.Abandoned) {\n throw err\n }\n // Otherwise, bail out here.\n bail(\n execution,\n new InvariantError(\n 'An unexpected error occurred while starting to capture immediates',\n {\n cause: err,\n }\n )\n )\n }\n }\n}\n\n/**\n * This should always be called a task after `DANGEROUSLY_runPendingImmediatesAfterCurrentTask`\n * to make sure that everything executed as expected and we're not left in an inconsistent state.\n * Ideally, this wouldn't be necessary, but we're not in control of the event loop\n * and need to guard against unexpected behaviors not forseen in this implementation,\n * so we have to be defensive.\n */\nexport function expectNoPendingImmediates() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'expectNoPendingImmediates cannot be called in the edge runtime'\n )\n } else {\n if (currentExecution !== null) {\n bail(\n currentExecution,\n new InvariantError(\n `Expected all captured immediates to have been executed (state: ${ExecutionState[currentExecution.state]})`\n )\n )\n }\n }\n}\n\n/**\n * Wait until all nextTicks and microtasks spawned from the current task are done,\n * then execute any immediates that they queued.\n * */\nfunction scheduleWorkAfterNextTicksAndMicrotasks(execution: Execution) {\n if (execution.state !== ExecutionState.Waiting) {\n throw new InvariantError(\n `scheduleWorkAfterTicksAndMicrotasks can only be called while waiting (state: ${ExecutionState[execution.state]})`\n )\n }\n\n // We want to execute \"fast immediates\" after all the nextTicks and microtasks\n // spawned from the current task are done.\n // The ordering here is:\n //\n // 1. sync code\n // 2. process.nextTick (scheduled from sync code, or from one of these nextTicks)\n // 3. microtasks\n // 4. process.nextTick (scheduled from microtasks, e.g. `queueMicrotask(() => process.nextTick(callback))`)\n //\n // We want to run to run in step 4, because that's the latest point before the next tick.\n // However, there might also be other callbacks scheduled to run in that step.\n // But importantly, they had to be scheduled using a `process.nextTick`,\n // so we can detect them by checking if `pendingNextTicks > 0`.\n // In that case, we'll just reschedule ourselves in the same way again to let them run first.\n // (this process can theoretically repeat multiple times, hence the recursion).\n\n queueMicrotask(() => {\n // (note that this call won't increment `pendingNextTicks`,\n // only the patched `process.nextTick` does that, so this won't loop infinitely)\n originalNextTick(() => {\n // We're now in a nextTick, which means that we're executing inside `processTicksAndRejections`:\n // https://github.com/nodejs/node/blob/d546e7fd0bc3cbb4bcc2baae6f3aa44d2e81a413/lib/internal/process/task_queues.js#L84\n // All the work scheduled here will happen within that `processTicksAndRejections` loop.\n // Reading the source of `processTicksAndRejections` can help understand the timing here --\n // All we're really doing is strategically pushing callbacks into the two queues\n // (nextTicks and microtasks) that that function is currently looping over.\n\n try {\n if (\n execution.state === ExecutionState.Abandoned ||\n currentExecution !== execution\n ) {\n debug?.(`scheduler :: the execution was abandoned`)\n return\n }\n if (pendingNextTicks > 0) {\n // Other nextTicks have been scheduled. Let those run first, then try again --\n // we're simulating a event loop task, so all nextTicks should be exhausted before we execute.\n debug?.(`scheduler :: yielding to ${pendingNextTicks} nextTicks`)\n return scheduleWorkAfterNextTicksAndMicrotasks(execution)\n }\n\n // There's no other nextTicks, we're the last one, so we're about to move on to the next task (likely a timer).\n // Now, we can try and execute any queued immediates.\n return performWork(execution)\n } catch (err) {\n // If this error comes from a bail() call, rethrow it.\n\n // typescript can't tell that the state might've been mutated\n // and the narrowing from above is no longer valid\n const executionAfterWork = execution as Execution\n if (executionAfterWork.state === ExecutionState.Abandoned) {\n throw err\n }\n\n // Otherwise, bail out here (which will trigger an uncaught exception)\n // Note that we're using the same microtask trick as `safelyRunNextTickCallback`.\n queueMicrotask(() => {\n bail(\n execution,\n new InvariantError(\n 'An unexpected error occurred while executing immediates',\n { cause: err }\n )\n )\n })\n }\n })\n })\n}\n\n/** Execute one immediate, and schedule a check for more (in case there's others in the queue) */\nfunction performWork(execution: Execution) {\n if (execution.state === ExecutionState.Abandoned) {\n return\n }\n\n debug?.(`scheduler :: performing work`)\n\n if (execution.state !== ExecutionState.Waiting) {\n throw new InvariantError(\n `performWork can only be called while waiting (state: ${ExecutionState[execution.state]})`\n )\n }\n execution.state = ExecutionState.Working\n\n const queueItem = takeNextActiveQueueItem(execution)\n\n if (queueItem === null) {\n debug?.(`scheduler :: no immediates queued, exiting`)\n stopCapturingImmediates(execution)\n return\n }\n\n debug?.(`scheduler :: executing queued immediate`)\n\n const { immediateObject, callback, args } = queueItem\n\n immediateObject[INTERNALS].queueItem = null\n clearQueueItem(queueItem)\n\n // Execute the immediate.\n\n // If a sync error was thrown in the immediate, we want to trigger a `uncaughtException`.\n // However, we're executing in a nextTick, and if a nextTick callback errors,\n // It'll break out of `processTicksAndRejections` (note the lack of a `catch` block):\n // https://github.com/nodejs/node/blob/d546e7fd0bc3cbb4bcc2baae6f3aa44d2e81a413/lib/internal/process/task_queues.js#L81-L97\n // Meaning that the event loop will stop executing nextTicks and move on to the next timer\n // (or other phase of the event loop, but we expect to be running in a sequence of timers here).\n // Then, the remaining ticks will run after that timer, since they're still in the queue.\n //\n // This would completely break the timing we're trying to achieve here --\n // The point of this patch is to execute immediates before the next timer!\n // So, we need to work around this behavior. (both here and in our `process.nextTick` patch).\n //\n // We can sidestep this by catching the synchronous error and rethrowing it in a microtask.\n // (NOTE: if we use `queueMicrotask`, it'll trigger `uncaughtException`, not `unhandledRejection`,\n // because there's no promise being rejected.)\n //\n // This will make `uncaughtException` happen:\n // - Before the next fast immediate (`scheduleWorkAfterNextTicksAndMicrotasks` also uses `queueMicrotask`).\n // This is good, and matches usual observable behavior of immediates.\n // - AFTER nextTicks scheduled from the immediate itself.\n // This deviates from native setImmediate, which would call `uncaughtException` first,\n // and skip ahead to the next task as explained above.\n //\n // This is technically an observable difference in behavior, but it seems niche enough that\n // it shouldn't cause problems -- we don't expect user code to use `uncaughtException` for control flow,\n // only error reporting, so subtly changing the timing shouldn't matter.\n\n let didThrow = false\n let thrownValue: unknown = undefined\n queueMicrotask(() => {\n if (didThrow) {\n debug?.('scheduler :: rethrowing sync error from immediate in microtask')\n throw thrownValue\n }\n })\n\n try {\n if (args !== null) {\n callback.apply(null, args)\n } else {\n callback()\n }\n } catch (err) {\n // We'll rethrow the error in the microtask above.\n didThrow = true\n thrownValue = err\n }\n\n // Schedule the loop again in case there's more immediates after this one.\n // Note that we can't just check if the queue is empty now, because new immediates\n // might still be scheduled asynchronously, from an upcoming nextTick or microtask.\n execution.state = ExecutionState.Waiting\n scheduleWorkAfterNextTicksAndMicrotasks(execution)\n}\n\nfunction takeNextActiveQueueItem(execution: Execution): ActiveQueueItem | null {\n // Find the first (if any) queued immediate that wasn't cleared.\n // We don't remove immediates from the array when they're cleared,\n // so this requires some legwork to exclude (and possibly drop) cleared items.\n const { queuedImmediates } = execution\n\n let firstActiveItem: ActiveQueueItem | null = null\n let firstActiveItemIndex = -1\n for (let i = 0; i < queuedImmediates.length; i++) {\n const item = queuedImmediates[i]\n if (!item.isCleared) {\n firstActiveItem = item\n firstActiveItemIndex = i\n break\n }\n }\n\n if (firstActiveItem === null) {\n // We didn't find an active item.\n\n // If the queue isn't empty, then it must only contain cleared items. Empty it.\n if (queuedImmediates.length > 0) {\n queuedImmediates.length = 0\n }\n\n return null\n }\n\n // Remove all items up to and including `nextActiveItemIndex` from the queue.\n // (if it's not the first item, then it must be preceded by cleared items, which we want to drop anyway)\n if (firstActiveItemIndex === 0) {\n // Fast path - drop the first item\n // (`splice` creates a result array for the removed items, so this is more efficient)\n queuedImmediates.shift()\n } else {\n queuedImmediates.splice(0, firstActiveItemIndex + 1)\n }\n\n return firstActiveItem\n}\n\nfunction startCapturingImmediates(): Execution {\n if (currentExecution !== null) {\n bail(\n currentExecution,\n new InvariantError(\n `Cannot start capturing immediates again without finishing the previous task (state: ${ExecutionState[currentExecution.state]})`\n )\n )\n }\n wasEnabledAtLeastOnce = true\n\n const execution: Execution = {\n state: ExecutionState.Waiting,\n queuedImmediates: [],\n }\n currentExecution = execution\n\n return execution\n}\n\nfunction stopCapturingImmediates(execution: Execution) {\n if (execution.state === ExecutionState.Abandoned) {\n return\n }\n\n // This check enforces that we run performWork at least once before stopping\n // to make sure that we've waited for all the nextTicks and microtasks\n // that might've scheduled some immediates after sync code.\n if (execution.state !== ExecutionState.Working) {\n throw new InvariantError(\n `Cannot stop capturing immediates before execution is finished (state: ${ExecutionState[execution.state]})`\n )\n }\n\n execution.state = ExecutionState.Finished\n\n if (currentExecution === execution) {\n currentExecution = null\n }\n}\n\nfunction bail(execution: Execution, error: Error): never {\n // Reset the state as best we can to prevent further crashes.\n // Otherwise, any subsequent call to `DANGEROUSLY_runPendingImmediatesAfterCurrentTask`\n // would error, requiring a server restart to fix.\n\n if (currentExecution === execution) {\n currentExecution = null\n }\n\n execution.state = ExecutionState.Abandoned\n\n // If we have any queued immediates, schedule them with native `setImmediate` and clear the queue.\n // We don't want to skip running them altogether, because that could lead to\n // e.g. hanging promises (for `new Promise((resolve) => setImmediate(resolve))`),\n // but we're in an inconsistent state and can't run them as fast immediates,\n // so this is the next best thing.\n for (const queueItem of execution.queuedImmediates) {\n if (queueItem.isCleared) {\n continue\n }\n scheduleQueuedImmediateAsNativeImmediate(queueItem)\n }\n execution.queuedImmediates.length = 0\n\n // Don't reset `pendingNextTicks` -- it will reset to 0 on its own as the nextTicks execute.\n // If we set it to 0 here while we still have pending ticks, they'd decrement it below 0.\n\n throw error\n}\n\nfunction scheduleQueuedImmediateAsNativeImmediate(queueItem: ActiveQueueItem) {\n const { callback, args, immediateObject } = queueItem\n const hasRef = immediateObject[INTERNALS].hasRef\n\n clearQueueItem(queueItem)\n\n const nativeImmediate =\n args !== null\n ? originalSetImmediate(callback, ...args)\n : originalSetImmediate(callback)\n\n if (!hasRef) {\n nativeImmediate.unref()\n }\n\n // Make our fake immediate object proxy all relevant operations\n // (clearing, ref(), unref(), hasRef()) to the actual native immediate.\n proxyQueuedImmediateToNativeImmediate(immediateObject, nativeImmediate)\n}\n\ntype QueueItem = ActiveQueueItem | ClearedQueueItem\ntype ActiveQueueItem = {\n isCleared: false\n callback: (...args: any[]) => any\n args: any[] | null\n immediateObject: NextImmediate\n}\ntype ClearedQueueItem = {\n isCleared: true\n callback: null\n args: null\n immediateObject: null\n}\n\nfunction clearQueueItem(originalQueueItem: QueueItem) {\n const queueItem = originalQueueItem as ClearedQueueItem\n queueItem.isCleared = true\n queueItem.callback = null\n queueItem.args = null\n queueItem.immediateObject = null\n}\n\n//========================================================\n\nfunction patchedNextTick<TArgs extends any[]>(\n callback: (...args: TArgs) => void,\n ...args: TArgs\n): void\nfunction patchedNextTick() {\n if (currentExecution === null) {\n return originalNextTick.apply(\n null,\n // @ts-expect-error: this is valid, but typescript doesn't get it\n arguments\n )\n }\n\n if (arguments.length === 0 || typeof arguments[0] !== 'function') {\n // Let the original nextTick error for invalid arguments\n // so that we don't have to mirror the error message.\n originalNextTick.apply(\n null,\n // @ts-expect-error: explicitly passing arguments that we know are invalid\n arguments\n )\n\n // We expect the above call to throw. If it didn't, something's broken.\n bail(\n currentExecution,\n new InvariantError(\n 'Expected process.nextTick to reject invalid arguments'\n )\n )\n }\n\n debug?.(\n `scheduler :: process.nextTick called (previous pending: ${pendingNextTicks})`\n )\n\n const callback: (...args: any[]) => any = arguments[0]\n const args: any[] | null =\n arguments.length > 1 ? Array.prototype.slice.call(arguments, 1) : null\n\n pendingNextTicks += 1\n return originalNextTick(safelyRunNextTickCallback, callback, args)\n}\n\nfunction safelyRunNextTickCallback(\n callback: (...args: any[]) => any,\n args: any[] | null\n) {\n pendingNextTicks -= 1\n debug?.(\n `scheduler :: process.nextTick executing (still pending: ${pendingNextTicks})`\n )\n\n // Synchronous errors in nextTick break out of `processTicksAndRejections` and cause us\n // to move on to the next timer without having executed the whole nextTick queue,\n // which breaks our entire scheduling mechanism. See `performWork` for more details.\n try {\n if (args !== null) {\n callback.apply(null, args)\n } else {\n callback()\n }\n } catch (err) {\n // We want to make sure `nextTick` is cheap, so unlike `performWork`,\n // we only queue the microtask if an error actually occurs.\n // This (observably) changes the timing of `uncaughtException` even more,\n // because it'll run after microtasks queued from the nextTick,\n // but hopefully this is niche enough to not affect any real world code.\n queueMicrotask(() => {\n debug?.(`scheduler :: rethrowing sync error from nextTick in a microtask`)\n throw err\n })\n }\n}\n\nfunction patchedSetImmediate<TArgs extends any[]>(\n callback: (...args: TArgs) => void,\n ...args: TArgs\n): NodeJS.Immediate\nfunction patchedSetImmediate(callback: (args: void) => void): NodeJS.Immediate\nfunction patchedSetImmediate(): NodeJS.Immediate {\n if (currentExecution === null) {\n return originalSetImmediate.apply(\n null,\n // @ts-expect-error: this is valid, but typescript doesn't get it\n arguments\n )\n }\n\n if (arguments.length === 0 || typeof arguments[0] !== 'function') {\n // Let the original setImmediate error for invalid arguments\n // so that we don't have to mirror the error message.\n originalSetImmediate.apply(\n null,\n // @ts-expect-error: explicitly passing arguments that we know are invalid\n arguments\n )\n\n // We expect the above call to throw. If it didn't, something's broken.\n bail(\n currentExecution,\n new InvariantError('Expected setImmediate to reject invalid arguments')\n )\n }\n\n const callback: (...args: any[]) => any = arguments[0]\n const args: any[] | null =\n arguments.length > 1 ? Array.prototype.slice.call(arguments, 1) : null\n\n // Normally, Node would capture and propagate the async context to the immediate.\n // We'll be running it on our own queue, so we need to propagate it ourselves.\n const callbackWithAsyncContext = bindSnapshot(callback)\n\n const immediateObject = new NextImmediate()\n\n const queueItem: ActiveQueueItem = {\n isCleared: false,\n callback: callbackWithAsyncContext,\n args,\n immediateObject,\n }\n currentExecution.queuedImmediates.push(queueItem)\n\n immediateObject[INTERNALS].queueItem = queueItem\n\n return immediateObject\n}\n\nfunction patchedSetImmediatePromise<T = void>(\n value: T,\n options?: import('node:timers').TimerOptions\n): Promise<T> {\n if (currentExecution === null) {\n return originalSetImmediatePromisify(value, options)\n }\n\n return new Promise<T>((resolve, reject) => {\n // The abort signal makes the promise reject.\n // If it is already aborted, we reject immediately.\n const signal = options?.signal\n if (signal && signal.aborted) {\n return reject(signal.reason)\n }\n\n const immediate = patchedSetImmediate(resolve, value)\n\n // Unref-ing only really has an observable effect if we bail out to a native immediate,\n // but we do it for completeness\n if (options?.ref === false) {\n immediate.unref()\n }\n\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n patchedClearImmediate(immediate)\n reject(signal.reason)\n },\n { once: true }\n )\n }\n })\n}\n\npatchedSetImmediate[promisify.custom] = patchedSetImmediatePromise\n\nconst patchedClearImmediate = (\n immediateObject: NodeJS.Immediate | undefined\n) => {\n // NOTE: we defensively check for patched immediates even if we're not\n // currently capturing immediates, because the objects returned from\n // the patched setImmediate can be kept around for arbitrarily long.\n // As an optimization, we only do this if the patch was enabled at least once --\n // otherwise, no patched objects could've been created.\n if (\n wasEnabledAtLeastOnce &&\n immediateObject &&\n typeof immediateObject === 'object' &&\n INTERNALS in immediateObject\n ) {\n ;(immediateObject as NextImmediate)[Symbol.dispose]()\n } else {\n originalClearImmediate(immediateObject)\n }\n}\n\n//========================================================\n\nconst INTERNALS: unique symbol = Symbol.for('next.Immediate.internals')\n\ntype NextImmediateInternals =\n | {\n /** Stored to reflect `ref()`/`unref()` calls, but has no effect otherwise */\n hasRef: boolean\n queueItem: ActiveQueueItem | null\n nativeImmediate: null\n }\n | {\n hasRef: null\n queueItem: null\n nativeImmediate: NodeJS.Immediate\n }\n\nfunction proxyQueuedImmediateToNativeImmediate(\n immediateObject: NextImmediate,\n nativeImmediate: NodeJS.Immediate\n) {\n immediateObject[INTERNALS].hasRef = null\n immediateObject[INTERNALS].queueItem = null\n immediateObject[INTERNALS].nativeImmediate = nativeImmediate\n}\n\n/** Makes sure that we're implementing all the public `Immediate` methods */\ninterface NativeImmediate extends NodeJS.Immediate {}\n\n/** Implements a shim for the native `Immediate` class returned by `setImmediate` */\nclass NextImmediate implements NativeImmediate {\n [INTERNALS]: NextImmediateInternals = {\n queueItem: null,\n hasRef: true,\n nativeImmediate: null,\n }\n hasRef() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n return internals.hasRef\n } else if (internals.nativeImmediate) {\n return internals.nativeImmediate.hasRef()\n } else {\n // if we're no longer queued (cleared or executed), hasRef is always false\n return false\n }\n }\n ref() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n internals.hasRef = true\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate.ref()\n }\n return this\n }\n unref() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n internals.hasRef = false\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate.unref()\n }\n return this\n }\n\n /**\n * Node invokes `_onImmediate` when an immediate is executed:\n * https://github.com/nodejs/node/blob/42d363205715ffa5a4a6d90f4be1311487053d65/lib/internal/timers.js#L504\n * It's visible on the public types, so we want to have it here for parity, but it's a noop.\n * */\n _onImmediate() {}\n\n [Symbol.dispose]() {\n // This is equivalent to `clearImmediate`.\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n // this is still queued. drop it.\n const queueItem = internals.queueItem\n internals.queueItem = null\n clearQueueItem(queueItem)\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate[Symbol.dispose]()\n }\n }\n}\n\n// ==========================================\n\nconst debug =\n process.env.NEXT_DEBUG_IMMEDIATES !== '1'\n ? undefined\n : (...args: any[]) => {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'Fast setImmediate is not available in the edge runtime.'\n )\n } else {\n const { inspect } = require('node:util') as typeof import('node:util')\n const { writeFileSync } =\n require('node:fs') as typeof import('node:fs')\n\n let logLine =\n args\n .map((arg) =>\n typeof arg === 'string' ? arg : inspect(arg, { colors: true })\n )\n .join(' ') + '\\n'\n\n logLine = '\\x1B[2m' + logLine + '\\x1B[22m' // styleText('dim', logLine)\n writeFileSync(process.stdout.fd, logLine)\n }\n }\n\n// ==========================================\n\ninstall()\n"],"names":["DANGEROUSLY_runPendingImmediatesAfterCurrentTask","expectNoPendingImmediates","unpatchedSetImmediate","originalSetImmediate","ExecutionState","wasEnabledAtLeastOnce","pendingNextTicks","currentExecution","globalThis","setImmediate","originalClearImmediate","clearImmediate","originalNextTick","process","nextTick","originalSetImmediatePromisify","promisify","custom","install","env","NEXT_RUNTIME","debug","nodeTimers","require","patchedSetImmediate","patchedClearImmediate","nodeTimersPromises","patchedSetImmediatePromise","patchedNextTick","InvariantError","execution","startCapturingImmediates","scheduleWorkAfterNextTicksAndMicrotasks","err","state","bail","cause","queueMicrotask","performWork","executionAfterWork","queueItem","takeNextActiveQueueItem","stopCapturingImmediates","immediateObject","callback","args","INTERNALS","clearQueueItem","didThrow","thrownValue","undefined","apply","queuedImmediates","firstActiveItem","firstActiveItemIndex","i","length","item","isCleared","shift","splice","error","scheduleQueuedImmediateAsNativeImmediate","hasRef","nativeImmediate","unref","proxyQueuedImmediateToNativeImmediate","originalQueueItem","arguments","Array","prototype","slice","call","safelyRunNextTickCallback","callbackWithAsyncContext","bindSnapshot","NextImmediate","push","value","options","Promise","resolve","reject","signal","aborted","reason","immediate","ref","addEventListener","once","Symbol","dispose","for","internals","_onImmediate","NEXT_DEBUG_IMMEDIATES","inspect","writeFileSync","logLine","map","arg","colors","join","stdout","fd"],"mappings":";;;;;;;;;;;;;;;;IAoHgBA,gDAAgD;eAAhDA;;IAoCAC,yBAAyB;eAAzBA;;IA5HiBC,qBAAqB;eAA7CC;;;0BA5BiB;gCACK;mCACF;AAO7B,IAAA,AAAKC,wCAAAA;;;;;WAAAA;EAAAA;AAOL,IAAIC,wBAAwB;AAE5B,IAAIC,mBAAmB;AACvB,IAAIC,mBAAqC;AAEzC,MAAMJ,uBAAuBK,WAAWC,YAAY;AACpD,MAAMC,yBAAyBF,WAAWG,cAAc;AACxD,MAAMC,mBAAmBC,QAAQC,QAAQ;AACzC,MAAMC,gCACJ,iEAAiE;AACjEZ,oBAAoB,CAACa,mBAAS,CAACC,MAAM,CAAC;AAIxC,SAASC;IACP,IAAIL,QAAQM,GAAG,CAACC,YAAY,KAAK,QAAQ;QACvC,kFAAkF;QAClF,iEAAiE;QACjE;IACF,OAAO;QACLC,yBAAAA,MAAQ;QAER,MAAMC,aAAaC,QAAQ;QAC3Bf,WAAWC,YAAY,GAAGa,WAAWb,YAAY,GAC/C,oEAAoE;QACpEe;QACFhB,WAAWG,cAAc,GAAGW,WAAWX,cAAc,GACnDc;QAEF,MAAMC,qBACJH,QAAQ;QACVG,mBAAmBjB,YAAY,GAC7BkB;QAEFd,QAAQC,QAAQ,GAAGc;IACrB;AACF;AAgEO,SAAS5B;IACd,IAAIa,QAAQM,GAAG,CAACC,YAAY,KAAK,QAAQ;QACvC,MAAM,qBAEL,CAFK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D,SAAS,EAAE;YACvB,iCAAiC;YACjC,MAAMA,YAAYqD,UAAUrD,SAAS;YACrCqD,UAAUrD,SAAS,GAAG;YACtBO,eAAeP;QACjB,OAAO,IAAIqD,UAAU7B,eAAe,EAAE;YACpC6B,UAAU7B,eAAe,CAAC0B,OAAOC,OAAO,CAAC;QAC3C;IACF;;YArDA,CAAC7C,UAAU,GAA2B;YACpCN,WAAW;YACXuB,QAAQ;YACRC,iBAAiB;QACnB;;AAkDF;AAEA,6CAA6C;AAE7C,MAAM3C,QACJR,QAAQM,GAAG,CAAC4E,qBAAqB,KAAK,MAClC7C,YACA,CAAC,GAAGL;IACF,IAAIhC,QAAQM,GAAG,CAACC,YAAY,KAAK,QAAQ;QACvC,MAAM,qBAEL,CAFK,IAAIS,8BAAc,CACtB,4DADI,qBAAA;mBAAA;wBAAA;0BAAA;QAEN;IACF,OAAO;QACL,MAAM,EAAEmE,OAAO,EAAE,GAAGzE,QAAQ;QAC5B,MAAM,EAAE0E,aAAa,EAAE,GACrB1E,QAAQ;QAEV,IAAI2E,UACFrD,KACGsD,GAAG,CAAC,CAACC,MACJ,OAAOA,QAAQ,WAAWA,MAAMJ,QAAQI,KAAK;gBAAEC,QAAQ;YAAK,IAE7DC,IAAI,CAAC,OAAO;QAEjBJ,UAAU,YAAYA,UAAU,WAAW,4BAA4B;;QACvED,cAAcpF,QAAQ0F,MAAM,CAACC,EAAE,EAAEN;IACnC;AACF;AAEN,6CAA6C;AAE7ChF","ignoreList":[0]}
1
+ {"version":3,"sources":["../../../src/server/node-environment-extensions/fast-set-immediate.external.ts"],"sourcesContent":["import { promisify } from 'node:util'\nimport { InvariantError } from '../../shared/lib/invariant-error'\nimport { bindSnapshot } from '../app-render/async-local-storage'\n\ntype Execution = {\n state: ExecutionState\n queuedImmediates: QueueItem[]\n}\n\nenum ExecutionState {\n Waiting = 1,\n Working = 2,\n Finished = 3,\n Abandoned = 4,\n}\n\nlet wasEnabledAtLeastOnce = false\n\nlet pendingNextTicks = 0\nlet currentExecution: Execution | null = null\n\nconst originalSetImmediate = globalThis.setImmediate\nconst originalClearImmediate = globalThis.clearImmediate\nconst originalNextTick = process.nextTick\nconst originalSetImmediatePromisify: (typeof setImmediate)['__promisify__'] =\n typeof originalSetImmediate === 'function'\n ? // @ts-expect-error: the types for `promisify.custom` are strange\n originalSetImmediate[promisify.custom]\n : // if setImmediate is not defined, we must be in the edge runtime,\n // and won't ever enable the patch, so this can be a dummy value\n undefined!\n\nexport { originalSetImmediate as unpatchedSetImmediate }\n\nfunction install() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n // Nothing to patch. The exported functions all error if used in the edge runtime,\n // so we're not going to violate any assumptions by not patching.\n return\n } else {\n debug?.('installing fast setImmediate patch')\n\n const nodeTimers = require('node:timers') as typeof import('node:timers')\n globalThis.setImmediate = nodeTimers.setImmediate =\n // Workaround for missing __promisify__ which is not a real property\n patchedSetImmediate as unknown as typeof setImmediate\n globalThis.clearImmediate = nodeTimers.clearImmediate =\n patchedClearImmediate\n\n const nodeTimersPromises =\n require('node:timers/promises') as typeof import('node:timers/promises')\n nodeTimersPromises.setImmediate =\n patchedSetImmediatePromise as typeof import('node:timers/promises').setImmediate\n\n process.nextTick = patchedNextTick\n }\n}\n\n/**\n * **WARNING: This function changes the usual behavior of the event loop!**\n * **Be VERY careful about where you call it.**\n *\n * Starts capturing calls to `setImmediate` to run them as \"fast immediates\".\n * All calls captured in this way will be executed after the current task\n * (after callbacks from `process.nextTick()`, microtasks, and nextTicks scheduled from microtasks).\n * This function needs to be called again in each task that needs the\n * \"fast immediates\" behavior.\n *\n * ### Motivation\n *\n * We don't want `setImmediate` to be considered IO in Cache Components.\n * To achieve this in a staged (pre)render, we want to allow immediates scheduled\n * in stage N to run before stage N+1.\n * Since we schedule stages using sequential `setTimeout`, this isn't possible without\n * intercepting `setImmediate` and doing the scheduling on our own.\n * We refer to this as a \"fast immediate\".\n *\n * Notably, this affects React's `scheduleWork` in render, which uses `setImmediate`.\n * This is desirable -- if async work was scheduled during a stage, then it should\n * get to run before we finish that stage.\n *\n * ### Example\n *\n * ```ts\n * setTimeout(() => {\n * runPendingImmediatesAfterCurrentTask()\n * console.log(\"timeout 1\")\n * setImmediate(() => {\n * console.log(\"immediate!!!\")\n * })\n * })\n * setTimeout(() => {\n * console.log(\"timeout 2\")\n * })\n * ```\n * will print\n *\n * ```\n * timeout 1\n * immediate!!!\n * timeout 2\n * ```\n *\n * instead of the usual order\n * ```\n * timeout 1\n * timeout 2\n * immediate!!!\n * ```\n * > **NOTE**\n * > The above is *most common* order, but it's not guaranteed.\n * > Under some circumstances (e.g. when the event loop is blocked on CPU work),\n * > Node will reorder things and run the immediate before timeout 2.\n * > So, in a sense, we're just making this reordering happen consistently.\n *\n * Recursive `setImmediate` calls will also be executed as \"fast immediates\".\n * If multiple immediates were scheduled, `process.nextTick()` (and associated microtasks)\n * will be allowed to execute between them.\n * See the unit tests for more examples.\n * */\nexport function DANGEROUSLY_runPendingImmediatesAfterCurrentTask() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'DANGEROUSLY_runPendingImmediatesAfterCurrentTask cannot be called in the edge runtime'\n )\n } else {\n const execution = startCapturingImmediates()\n\n try {\n scheduleWorkAfterNextTicksAndMicrotasks(execution)\n } catch (err) {\n // If this error comes from a bail() call, rethrow it.\n if (execution.state === ExecutionState.Abandoned) {\n throw err\n }\n // Otherwise, bail out here.\n bail(\n execution,\n new InvariantError(\n 'An unexpected error occurred while starting to capture immediates',\n {\n cause: err,\n }\n )\n )\n }\n }\n}\n\n/**\n * This should always be called a task after `DANGEROUSLY_runPendingImmediatesAfterCurrentTask`\n * to make sure that everything executed as expected and we're not left in an inconsistent state.\n * Ideally, this wouldn't be necessary, but we're not in control of the event loop\n * and need to guard against unexpected behaviors not forseen in this implementation,\n * so we have to be defensive.\n */\nexport function expectNoPendingImmediates() {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'expectNoPendingImmediates cannot be called in the edge runtime'\n )\n } else {\n if (currentExecution !== null) {\n bail(\n currentExecution,\n new InvariantError(\n `Expected all captured immediates to have been executed (state: ${ExecutionState[currentExecution.state]})`\n )\n )\n }\n }\n}\n\n/**\n * Wait until all nextTicks and microtasks spawned from the current task are done,\n * then execute any immediates that they queued.\n * */\nfunction scheduleWorkAfterNextTicksAndMicrotasks(execution: Execution) {\n if (execution.state !== ExecutionState.Waiting) {\n throw new InvariantError(\n `scheduleWorkAfterTicksAndMicrotasks can only be called while waiting (state: ${ExecutionState[execution.state]})`\n )\n }\n\n // We want to execute \"fast immediates\" after all the nextTicks and microtasks\n // spawned from the current task are done.\n // The ordering here is:\n //\n // 1. sync code\n // 2. process.nextTick (scheduled from sync code, or from one of these nextTicks)\n // 3. microtasks\n // 4. process.nextTick (scheduled from microtasks, e.g. `queueMicrotask(() => process.nextTick(callback))`)\n //\n // We want to run to run in step 4, because that's the latest point before the next tick.\n // However, there might also be other callbacks scheduled to run in that step.\n // But importantly, they had to be scheduled using a `process.nextTick`,\n // so we can detect them by checking if `pendingNextTicks > 0`.\n // In that case, we'll just reschedule ourselves in the same way again to let them run first.\n // (this process can theoretically repeat multiple times, hence the recursion).\n\n queueMicrotask(() => {\n // (note that this call won't increment `pendingNextTicks`,\n // only the patched `process.nextTick` does that, so this won't loop infinitely)\n originalNextTick(() => {\n // We're now in a nextTick, which means that we're executing inside `processTicksAndRejections`:\n // https://github.com/nodejs/node/blob/d546e7fd0bc3cbb4bcc2baae6f3aa44d2e81a413/lib/internal/process/task_queues.js#L84\n // All the work scheduled here will happen within that `processTicksAndRejections` loop.\n // Reading the source of `processTicksAndRejections` can help understand the timing here --\n // All we're really doing is strategically pushing callbacks into the two queues\n // (nextTicks and microtasks) that that function is currently looping over.\n\n try {\n if (\n execution.state === ExecutionState.Abandoned ||\n currentExecution !== execution\n ) {\n debug?.(`scheduler :: the execution was abandoned`)\n return\n }\n if (pendingNextTicks > 0) {\n // Other nextTicks have been scheduled. Let those run first, then try again --\n // we're simulating a event loop task, so all nextTicks should be exhausted before we execute.\n debug?.(`scheduler :: yielding to ${pendingNextTicks} nextTicks`)\n return scheduleWorkAfterNextTicksAndMicrotasks(execution)\n }\n\n // There's no other nextTicks, we're the last one, so we're about to move on to the next task (likely a timer).\n // Now, we can try and execute any queued immediates.\n return performWork(execution)\n } catch (err) {\n // If this error comes from a bail() call, rethrow it.\n\n // typescript can't tell that the state might've been mutated\n // and the narrowing from above is no longer valid\n const executionAfterWork = execution as Execution\n if (executionAfterWork.state === ExecutionState.Abandoned) {\n throw err\n }\n\n // Otherwise, bail out here (which will trigger an uncaught exception)\n // Note that we're using the same microtask trick as `safelyRunNextTickCallback`.\n queueMicrotask(() => {\n bail(\n execution,\n new InvariantError(\n 'An unexpected error occurred while executing immediates',\n { cause: err }\n )\n )\n })\n }\n })\n })\n}\n\n/** Execute one immediate, and schedule a check for more (in case there's others in the queue) */\nfunction performWork(execution: Execution) {\n if (execution.state === ExecutionState.Abandoned) {\n return\n }\n\n debug?.(`scheduler :: performing work`)\n\n if (execution.state !== ExecutionState.Waiting) {\n throw new InvariantError(\n `performWork can only be called while waiting (state: ${ExecutionState[execution.state]})`\n )\n }\n execution.state = ExecutionState.Working\n\n const queueItem = takeNextActiveQueueItem(execution)\n\n if (queueItem === null) {\n debug?.(`scheduler :: no immediates queued, exiting`)\n stopCapturingImmediates(execution)\n return\n }\n\n debug?.(`scheduler :: executing queued immediate`)\n\n const { immediateObject, callback, args } = queueItem\n\n immediateObject[INTERNALS].queueItem = null\n clearQueueItem(queueItem)\n\n // Execute the immediate.\n\n // If a sync error was thrown in the immediate, we want to trigger a `uncaughtException`.\n // However, we're executing in a nextTick, and if a nextTick callback errors,\n // It'll break out of `processTicksAndRejections` (note the lack of a `catch` block):\n // https://github.com/nodejs/node/blob/d546e7fd0bc3cbb4bcc2baae6f3aa44d2e81a413/lib/internal/process/task_queues.js#L81-L97\n // Meaning that the event loop will stop executing nextTicks and move on to the next timer\n // (or other phase of the event loop, but we expect to be running in a sequence of timers here).\n // Then, the remaining ticks will run after that timer, since they're still in the queue.\n //\n // This would completely break the timing we're trying to achieve here --\n // The point of this patch is to execute immediates before the next timer!\n // So, we need to work around this behavior. (both here and in our `process.nextTick` patch).\n //\n // We can sidestep this by catching the synchronous error and rethrowing it in a microtask.\n // (NOTE: if we use `queueMicrotask`, it'll trigger `uncaughtException`, not `unhandledRejection`,\n // because there's no promise being rejected.)\n //\n // This will make `uncaughtException` happen:\n // - Before the next fast immediate (`scheduleWorkAfterNextTicksAndMicrotasks` also uses `queueMicrotask`).\n // This is good, and matches usual observable behavior of immediates.\n // - AFTER nextTicks scheduled from the immediate itself.\n // This deviates from native setImmediate, which would call `uncaughtException` first,\n // and skip ahead to the next task as explained above.\n //\n // This is technically an observable difference in behavior, but it seems niche enough that\n // it shouldn't cause problems -- we don't expect user code to use `uncaughtException` for control flow,\n // only error reporting, so subtly changing the timing shouldn't matter.\n\n let didThrow = false\n let thrownValue: unknown = undefined\n queueMicrotask(() => {\n if (didThrow) {\n debug?.('scheduler :: rethrowing sync error from immediate in microtask')\n throw thrownValue\n }\n })\n\n try {\n if (args !== null) {\n callback.apply(null, args)\n } else {\n callback()\n }\n } catch (err) {\n // We'll rethrow the error in the microtask above.\n didThrow = true\n thrownValue = err\n }\n\n // Schedule the loop again in case there's more immediates after this one.\n // Note that we can't just check if the queue is empty now, because new immediates\n // might still be scheduled asynchronously, from an upcoming nextTick or microtask.\n execution.state = ExecutionState.Waiting\n scheduleWorkAfterNextTicksAndMicrotasks(execution)\n}\n\nfunction takeNextActiveQueueItem(execution: Execution): ActiveQueueItem | null {\n // Find the first (if any) queued immediate that wasn't cleared.\n // We don't remove immediates from the array when they're cleared,\n // so this requires some legwork to exclude (and possibly drop) cleared items.\n const { queuedImmediates } = execution\n\n let firstActiveItem: ActiveQueueItem | null = null\n let firstActiveItemIndex = -1\n for (let i = 0; i < queuedImmediates.length; i++) {\n const item = queuedImmediates[i]\n if (!item.isCleared) {\n firstActiveItem = item\n firstActiveItemIndex = i\n break\n }\n }\n\n if (firstActiveItem === null) {\n // We didn't find an active item.\n\n // If the queue isn't empty, then it must only contain cleared items. Empty it.\n if (queuedImmediates.length > 0) {\n queuedImmediates.length = 0\n }\n\n return null\n }\n\n // Remove all items up to and including `nextActiveItemIndex` from the queue.\n // (if it's not the first item, then it must be preceded by cleared items, which we want to drop anyway)\n if (firstActiveItemIndex === 0) {\n // Fast path - drop the first item\n // (`splice` creates a result array for the removed items, so this is more efficient)\n queuedImmediates.shift()\n } else {\n queuedImmediates.splice(0, firstActiveItemIndex + 1)\n }\n\n return firstActiveItem\n}\n\nfunction startCapturingImmediates(): Execution {\n if (currentExecution !== null) {\n bail(\n currentExecution,\n new InvariantError(\n `Cannot start capturing immediates again without finishing the previous task (state: ${ExecutionState[currentExecution.state]})`\n )\n )\n }\n wasEnabledAtLeastOnce = true\n\n const execution: Execution = {\n state: ExecutionState.Waiting,\n queuedImmediates: [],\n }\n currentExecution = execution\n\n return execution\n}\n\nfunction stopCapturingImmediates(execution: Execution) {\n if (execution.state === ExecutionState.Abandoned) {\n return\n }\n\n // This check enforces that we run performWork at least once before stopping\n // to make sure that we've waited for all the nextTicks and microtasks\n // that might've scheduled some immediates after sync code.\n if (execution.state !== ExecutionState.Working) {\n throw new InvariantError(\n `Cannot stop capturing immediates before execution is finished (state: ${ExecutionState[execution.state]})`\n )\n }\n\n execution.state = ExecutionState.Finished\n\n if (currentExecution === execution) {\n currentExecution = null\n }\n}\n\nfunction bail(execution: Execution, error: Error): never {\n // Reset the state as best we can to prevent further crashes.\n // Otherwise, any subsequent call to `DANGEROUSLY_runPendingImmediatesAfterCurrentTask`\n // would error, requiring a server restart to fix.\n\n if (currentExecution === execution) {\n currentExecution = null\n }\n\n execution.state = ExecutionState.Abandoned\n\n // If we have any queued immediates, schedule them with native `setImmediate` and clear the queue.\n // We don't want to skip running them altogether, because that could lead to\n // e.g. hanging promises (for `new Promise((resolve) => setImmediate(resolve))`),\n // but we're in an inconsistent state and can't run them as fast immediates,\n // so this is the next best thing.\n for (const queueItem of execution.queuedImmediates) {\n if (queueItem.isCleared) {\n continue\n }\n scheduleQueuedImmediateAsNativeImmediate(queueItem)\n }\n execution.queuedImmediates.length = 0\n\n // Don't reset `pendingNextTicks` -- it will reset to 0 on its own as the nextTicks execute.\n // If we set it to 0 here while we still have pending ticks, they'd decrement it below 0.\n\n throw error\n}\n\nfunction scheduleQueuedImmediateAsNativeImmediate(queueItem: ActiveQueueItem) {\n const { callback, args, immediateObject } = queueItem\n const hasRef = immediateObject[INTERNALS].hasRef\n\n clearQueueItem(queueItem)\n\n const nativeImmediate =\n args !== null\n ? originalSetImmediate(callback, ...args)\n : originalSetImmediate(callback)\n\n if (!hasRef) {\n nativeImmediate.unref()\n }\n\n // Make our fake immediate object proxy all relevant operations\n // (clearing, ref(), unref(), hasRef()) to the actual native immediate.\n proxyQueuedImmediateToNativeImmediate(immediateObject, nativeImmediate)\n}\n\ntype QueueItem = ActiveQueueItem | ClearedQueueItem\ntype ActiveQueueItem = {\n isCleared: false\n callback: (...args: any[]) => any\n args: any[] | null\n immediateObject: NextImmediate\n}\ntype ClearedQueueItem = {\n isCleared: true\n callback: null\n args: null\n immediateObject: null\n}\n\nfunction clearQueueItem(originalQueueItem: QueueItem) {\n const queueItem = originalQueueItem as ClearedQueueItem\n queueItem.isCleared = true\n queueItem.callback = null\n queueItem.args = null\n queueItem.immediateObject = null\n}\n\n//========================================================\n\nfunction patchedNextTick<TArgs extends any[]>(\n callback: (...args: TArgs) => void,\n ...args: TArgs\n): void\nfunction patchedNextTick() {\n if (currentExecution === null) {\n return originalNextTick.apply(\n null,\n // @ts-expect-error: this is valid, but typescript doesn't get it\n arguments\n )\n }\n\n if (arguments.length === 0 || typeof arguments[0] !== 'function') {\n // Let the original nextTick error for invalid arguments\n // so that we don't have to mirror the error message.\n originalNextTick.apply(\n null,\n // @ts-expect-error: explicitly passing arguments that we know are invalid\n arguments\n )\n\n // We expect the above call to throw. If it didn't, something's broken.\n bail(\n currentExecution,\n new InvariantError(\n 'Expected process.nextTick to reject invalid arguments'\n )\n )\n }\n\n debug?.(\n `scheduler :: process.nextTick called (previous pending: ${pendingNextTicks})`\n )\n\n const callback: (...args: any[]) => any = arguments[0]\n const args: any[] | null =\n arguments.length > 1 ? Array.prototype.slice.call(arguments, 1) : null\n\n pendingNextTicks += 1\n return originalNextTick(safelyRunNextTickCallback, callback, args)\n}\n\nfunction safelyRunNextTickCallback(\n callback: (...args: any[]) => any,\n args: any[] | null\n) {\n pendingNextTicks -= 1\n debug?.(\n `scheduler :: process.nextTick executing (still pending: ${pendingNextTicks})`\n )\n\n // Synchronous errors in nextTick break out of `processTicksAndRejections` and cause us\n // to move on to the next timer without having executed the whole nextTick queue,\n // which breaks our entire scheduling mechanism. See `performWork` for more details.\n try {\n if (args !== null) {\n callback.apply(null, args)\n } else {\n callback()\n }\n } catch (err) {\n // We want to make sure `nextTick` is cheap, so unlike `performWork`,\n // we only queue the microtask if an error actually occurs.\n // This (observably) changes the timing of `uncaughtException` even more,\n // because it'll run after microtasks queued from the nextTick,\n // but hopefully this is niche enough to not affect any real world code.\n queueMicrotask(() => {\n debug?.(`scheduler :: rethrowing sync error from nextTick in a microtask`)\n throw err\n })\n }\n}\n\nfunction patchedSetImmediate<TArgs extends any[]>(\n callback: (...args: TArgs) => void,\n ...args: TArgs\n): NodeJS.Immediate\nfunction patchedSetImmediate(callback: (args: void) => void): NodeJS.Immediate\nfunction patchedSetImmediate(): NodeJS.Immediate {\n if (currentExecution === null) {\n return originalSetImmediate.apply(\n null,\n // @ts-expect-error: this is valid, but typescript doesn't get it\n arguments\n )\n }\n\n if (arguments.length === 0 || typeof arguments[0] !== 'function') {\n // Let the original setImmediate error for invalid arguments\n // so that we don't have to mirror the error message.\n originalSetImmediate.apply(\n null,\n // @ts-expect-error: explicitly passing arguments that we know are invalid\n arguments\n )\n\n // We expect the above call to throw. If it didn't, something's broken.\n bail(\n currentExecution,\n new InvariantError('Expected setImmediate to reject invalid arguments')\n )\n }\n\n const callback: (...args: any[]) => any = arguments[0]\n const args: any[] | null =\n arguments.length > 1 ? Array.prototype.slice.call(arguments, 1) : null\n\n // Normally, Node would capture and propagate the async context to the immediate.\n // We'll be running it on our own queue, so we need to propagate it ourselves.\n const callbackWithAsyncContext = bindSnapshot(callback)\n\n const immediateObject = new NextImmediate()\n\n const queueItem: ActiveQueueItem = {\n isCleared: false,\n callback: callbackWithAsyncContext,\n args,\n immediateObject,\n }\n currentExecution.queuedImmediates.push(queueItem)\n\n immediateObject[INTERNALS].queueItem = queueItem\n\n return immediateObject\n}\n\nfunction patchedSetImmediatePromise<T = void>(\n value: T,\n options?: import('node:timers').TimerOptions\n): Promise<T> {\n if (currentExecution === null) {\n return originalSetImmediatePromisify(value, options)\n }\n\n return new Promise<T>((resolve, reject) => {\n // The abort signal makes the promise reject.\n // If it is already aborted, we reject immediately.\n const signal = options?.signal\n if (signal && signal.aborted) {\n return reject(signal.reason)\n }\n\n const immediate = patchedSetImmediate(resolve, value)\n\n // Unref-ing only really has an observable effect if we bail out to a native immediate,\n // but we do it for completeness\n if (options?.ref === false) {\n immediate.unref()\n }\n\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n patchedClearImmediate(immediate)\n reject(signal.reason)\n },\n { once: true }\n )\n }\n })\n}\n\npatchedSetImmediate[promisify.custom] = patchedSetImmediatePromise\n\nconst patchedClearImmediate = (\n immediateObject: NodeJS.Immediate | undefined\n) => {\n // NOTE: we defensively check for patched immediates even if we're not\n // currently capturing immediates, because the objects returned from\n // the patched setImmediate can be kept around for arbitrarily long.\n // As an optimization, we only do this if the patch was enabled at least once --\n // otherwise, no patched objects could've been created.\n if (\n wasEnabledAtLeastOnce &&\n immediateObject &&\n typeof immediateObject === 'object' &&\n INTERNALS in immediateObject\n ) {\n ;(immediateObject as NextImmediate)[Symbol.dispose]()\n } else {\n originalClearImmediate(immediateObject)\n }\n}\n\n//========================================================\n\nconst INTERNALS: unique symbol = Symbol.for('next.Immediate.internals')\n\ntype NextImmediateInternals =\n | {\n /** Stored to reflect `ref()`/`unref()` calls, but has no effect otherwise */\n hasRef: boolean\n queueItem: ActiveQueueItem | null\n nativeImmediate: null\n }\n | {\n hasRef: null\n queueItem: null\n nativeImmediate: NodeJS.Immediate\n }\n\nfunction proxyQueuedImmediateToNativeImmediate(\n immediateObject: NextImmediate,\n nativeImmediate: NodeJS.Immediate\n) {\n immediateObject[INTERNALS].hasRef = null\n immediateObject[INTERNALS].queueItem = null\n immediateObject[INTERNALS].nativeImmediate = nativeImmediate\n}\n\n/** Makes sure that we're implementing all the public `Immediate` methods */\ninterface NativeImmediate extends NodeJS.Immediate {}\n\n/** Implements a shim for the native `Immediate` class returned by `setImmediate` */\nclass NextImmediate implements NativeImmediate {\n [INTERNALS]: NextImmediateInternals = {\n queueItem: null,\n hasRef: true,\n nativeImmediate: null,\n }\n hasRef() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n return internals.hasRef\n } else if (internals.nativeImmediate) {\n return internals.nativeImmediate.hasRef()\n } else {\n // if we're no longer queued (cleared or executed), hasRef is always false\n return false\n }\n }\n ref() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n internals.hasRef = true\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate.ref()\n }\n return this\n }\n unref() {\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n internals.hasRef = false\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate.unref()\n }\n return this\n }\n\n /**\n * Node invokes `_onImmediate` when an immediate is executed:\n * https://github.com/nodejs/node/blob/42d363205715ffa5a4a6d90f4be1311487053d65/lib/internal/timers.js#L504\n * It's visible on the public types, so we want to have it here for parity, but it's a noop.\n * */\n _onImmediate() {}\n\n [Symbol.dispose]() {\n // This is equivalent to `clearImmediate`.\n const internals = this[INTERNALS]\n if (internals.queueItem) {\n // this is still queued. drop it.\n const queueItem = internals.queueItem\n internals.queueItem = null\n clearQueueItem(queueItem)\n } else if (internals.nativeImmediate) {\n internals.nativeImmediate[Symbol.dispose]()\n }\n }\n}\n\n// ==========================================\n\nconst debug =\n process.env.NEXT_DEBUG_IMMEDIATES !== '1'\n ? undefined\n : (...args: any[]) => {\n if (process.env.NEXT_RUNTIME === 'edge') {\n throw new InvariantError(\n 'Fast setImmediate is not available in the edge runtime.'\n )\n } else {\n const { inspect } = require('node:util') as typeof import('node:util')\n const { writeFileSync } =\n require('node:fs') as typeof import('node:fs')\n\n let logLine =\n args\n .map((arg) =>\n typeof arg === 'string' ? arg : inspect(arg, { colors: true })\n )\n .join(' ') + '\\n'\n\n logLine = '\\x1B[2m' + logLine + '\\x1B[22m' // styleText('dim', logLine)\n writeFileSync(process.stdout.fd, logLine)\n }\n }\n\n// ==========================================\n\ninstall()\n"],"names":["DANGEROUSLY_runPendingImmediatesAfterCurrentTask","expectNoPendingImmediates","unpatchedSetImmediate","originalSetImmediate","ExecutionState","wasEnabledAtLeastOnce","pendingNextTicks","currentExecution","globalThis","setImmediate","originalClearImmediate","clearImmediate","originalNextTick","process","nextTick","originalSetImmediatePromisify","promisify","custom","undefined","install","env","NEXT_RUNTIME","debug","nodeTimers","require","patchedSetImmediate","patchedClearImmediate","nodeTimersPromises","patchedSetImmediatePromise","patchedNextTick","InvariantError","execution","startCapturingImmediates","scheduleWorkAfterNextTicksAndMicrotasks","err","state","bail","cause","queueMicrotask","performWork","executionAfterWork","queueItem","takeNextActiveQueueItem","stopCapturingImmediates","immediateObject","callback","args","INTERNALS","clearQueueItem","didThrow","thrownValue","apply","queuedImmediates","firstActiveItem","firstActiveItemIndex","i","length","item","isCleared","shift","splice","error","scheduleQueuedImmediateAsNativeImmediate","hasRef","nativeImmediate","unref","proxyQueuedImmediateToNativeImmediate","originalQueueItem","arguments","Array","prototype","slice","call","safelyRunNextTickCallback","callbackWithAsyncContext","bindSnapshot","NextImmediate","push","value","options","Promise","resolve","reject","signal","aborted","reason","immediate","ref","addEventListener","once","Symbol","dispose","for","internals","_onImmediate","NEXT_DE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CN,WAAW;YACXsB,QAAQ;YACRC,iBAAiB;QACnB;;AAkDF;AAEA,6CAA6C;AAE7C,MAAM1C,QACJT,QAAQO,GAAG,CAAC2E,qBAAqB,KAAK,MAClC7E,YACA,CAAC,GAAG4B;IACF,IAAIjC,QAAQO,GAAG,CAACC,YAAY,KAAK,QAAQ;QACvC,MAAM,qBAEL,CAFK,IAAIS,8BAAc,CACtB,4DADI,qBAAA;mBAAA;wBAAA;0BAAA;QAEN;IACF,OAAO;QACL,MAAM,EAAEkE,OAAO,EAAE,GAAGxE,QAAQ;QAC5B,MAAM,EAAEyE,aAAa,EAAE,GACrBzE,QAAQ;QAEV,IAAI0E,UACFpD,KACGqD,GAAG,CAAC,CAACC,MACJ,OAAOA,QAAQ,WAAWA,MAAMJ,QAAQI,KAAK;gBAAEC,QAAQ;YAAK,IAE7DC,IAAI,CAAC,OAAO;QAEjBJ,UAAU,YAAYA,UAAU,WAAW,4BAA4B;;QACvED,cAAcpF,QAAQ0F,MAAM,CAACC,EAAE,EAAEN;IACnC;AACF;AAEN,6CAA6C;AAE7C/E","ignoreList":[0]}
@@ -21,7 +21,7 @@ _export(exports, {
21
21
  }
22
22
  });
23
23
  function isStableBuild() {
24
- return !"16.1.1-canary.31"?.includes('canary') && !process.env.__NEXT_TEST_MODE && !process.env.NEXT_PRIVATE_LOCAL_DEV;
24
+ return !"16.1.1-canary.32"?.includes('canary') && !process.env.__NEXT_TEST_MODE && !process.env.NEXT_PRIVATE_LOCAL_DEV;
25
25
  }
26
26
  class CanaryOnlyConfigError extends Error {
27
27
  constructor(arg){
@@ -81,7 +81,7 @@ function getAnonymousMeta() {
81
81
  isWsl: _iswsl.default,
82
82
  isCI: _ciinfo.isCI,
83
83
  ciName: _ciinfo.isCI && _ciinfo.name || null,
84
- nextVersion: "16.1.1-canary.31"
84
+ nextVersion: "16.1.1-canary.32"
85
85
  };
86
86
  return traits;
87
87
  }
@@ -11,11 +11,11 @@ Object.defineProperty(exports, "eventCliSessionStopped", {
11
11
  const EVENT_VERSION = 'NEXT_CLI_SESSION_STOPPED';
12
12
  function eventCliSessionStopped(event) {
13
13
  // This should be an invariant, if it fails our build tooling is broken.
14
- if (typeof "16.1.1-canary.31" !== 'string') {
14
+ if (typeof "16.1.1-canary.32" !== 'string') {
15
15
  return [];
16
16
  }
17
17
  const payload = {
18
- nextVersion: "16.1.1-canary.31",
18
+ nextVersion: "16.1.1-canary.32",
19
19
  nodeVersion: process.version,
20
20
  cliCommand: event.cliCommand,
21
21
  durationMilliseconds: event.durationMilliseconds,