remote-components 0.4.6 → 0.4.8
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.
- package/dist/{chunk-IVJ37EUX.cjs → chunk-EW5O3Q24.cjs} +7 -7
- package/dist/{chunk-LRR2OE4G.js → chunk-FF4SXSSG.js} +2 -2
- package/dist/{chunk-AEW3XYKI.cjs → chunk-KAFPXSRI.cjs} +6 -6
- package/dist/{chunk-WCCUTJJR.js → chunk-KCUEMMYL.js} +2 -2
- package/dist/{chunk-U2OFZFJI.cjs → chunk-O4ED3BUP.cjs} +10 -10
- package/dist/{chunk-6GHGHHQ3.js → chunk-STMO56U2.js} +81 -11
- package/dist/chunk-STMO56U2.js.map +1 -0
- package/dist/{chunk-NOHDLKL6.js → chunk-VJO4PTWG.js} +3 -3
- package/dist/{chunk-OP2PTYS6.cjs → chunk-YJJFRORQ.cjs} +107 -37
- package/dist/chunk-YJJFRORQ.cjs.map +1 -0
- package/dist/host/html.cjs +13 -13
- package/dist/host/html.js +5 -5
- package/dist/host/nextjs/app/client-only.cjs +6 -6
- package/dist/host/nextjs/app/client-only.js +4 -4
- package/dist/host/react.cjs +5 -5
- package/dist/host/react.js +4 -4
- package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/module.cjs +71 -8
- package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/module.d.ts +21 -0
- package/dist/internal/runtime/turbopack/module.js +71 -8
- package/dist/internal/runtime/turbopack/module.js.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.cjs +9 -2
- package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.js +10 -3
- package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
- package/dist/{turbopack-7PFUIFBT.cjs → turbopack-RXVSOWF7.cjs} +8 -8
- package/dist/{turbopack-NUCVQCQL.js → turbopack-XDIGB4GI.js} +3 -3
- package/dist/{webpack-34PB2JBT.js → webpack-3QXPAZN4.js} +2 -2
- package/dist/{webpack-DEFHHH6B.cjs → webpack-HKD7RZRE.cjs} +5 -5
- package/package.json +1 -1
- package/dist/chunk-6GHGHHQ3.js.map +0 -1
- package/dist/chunk-OP2PTYS6.cjs.map +0 -1
- /package/dist/{chunk-IVJ37EUX.cjs.map → chunk-EW5O3Q24.cjs.map} +0 -0
- /package/dist/{chunk-LRR2OE4G.js.map → chunk-FF4SXSSG.js.map} +0 -0
- /package/dist/{chunk-AEW3XYKI.cjs.map → chunk-KAFPXSRI.cjs.map} +0 -0
- /package/dist/{chunk-WCCUTJJR.js.map → chunk-KCUEMMYL.js.map} +0 -0
- /package/dist/{chunk-U2OFZFJI.cjs.map → chunk-O4ED3BUP.cjs.map} +0 -0
- /package/dist/{chunk-NOHDLKL6.js.map → chunk-VJO4PTWG.js.map} +0 -0
- /package/dist/{turbopack-7PFUIFBT.cjs.map → turbopack-RXVSOWF7.cjs.map} +0 -0
- /package/dist/{turbopack-NUCVQCQL.js.map → turbopack-XDIGB4GI.js.map} +0 -0
- /package/dist/{webpack-34PB2JBT.js.map → webpack-3QXPAZN4.js.map} +0 -0
- /package/dist/{webpack-DEFHHH6B.cjs.map → webpack-HKD7RZRE.cjs.map} +0 -0
package/dist/host/html.js
CHANGED
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
makeEventEmitter,
|
|
8
8
|
preparePipeline,
|
|
9
9
|
resolveNameFromSrc
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-VJO4PTWG.js";
|
|
11
11
|
import "../chunk-WGSS7TJP.js";
|
|
12
|
-
import "../chunk-
|
|
13
|
-
import "../chunk-
|
|
12
|
+
import "../chunk-FF4SXSSG.js";
|
|
13
|
+
import "../chunk-STMO56U2.js";
|
|
14
14
|
import "../chunk-LEKG4YWI.js";
|
|
15
15
|
import {
|
|
16
16
|
DEFAULT_BUNDLE_NAME,
|
|
@@ -125,10 +125,10 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
if (type === "webpack") {
|
|
128
|
-
const { webpackRuntime } = await import("../webpack-
|
|
128
|
+
const { webpackRuntime } = await import("../webpack-3QXPAZN4.js");
|
|
129
129
|
return webpackRuntime(bundle, shared, remoteShared, resolveClientUrl);
|
|
130
130
|
} else if (type === "turbopack") {
|
|
131
|
-
const { turbopackRuntime } = await import("../turbopack-
|
|
131
|
+
const { turbopackRuntime } = await import("../turbopack-XDIGB4GI.js");
|
|
132
132
|
return turbopackRuntime(
|
|
133
133
|
url,
|
|
134
134
|
bundle,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkO4ED3BUPcjs = require('../../../chunk-O4ED3BUP.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkEW5O3Q24cjs = require('../../../chunk-EW5O3Q24.cjs');
|
|
8
8
|
require('../../../chunk-4MLJE6UP.cjs');
|
|
9
|
-
require('../../../chunk-
|
|
10
|
-
require('../../../chunk-
|
|
9
|
+
require('../../../chunk-KAFPXSRI.cjs');
|
|
10
|
+
require('../../../chunk-YJJFRORQ.cjs');
|
|
11
11
|
require('../../../chunk-3AX5WLZD.cjs');
|
|
12
12
|
require('../../../chunk-N3SQTOSE.cjs');
|
|
13
13
|
|
|
@@ -32,7 +32,7 @@ function resolveForBundle(unbound, bundle) {
|
|
|
32
32
|
if (!unbound)
|
|
33
33
|
return void 0;
|
|
34
34
|
const remoteSrc = _nullishCoalesce(_optionalChain([_chunkI7VKDF3Ecjs.getScope.call(void 0, bundle), 'optionalAccess', _2 => _2.url, 'access', _3 => _3.href]), () => ( ""));
|
|
35
|
-
return
|
|
35
|
+
return _chunkEW5O3Q24cjs.bindResolveClientUrl.call(void 0, unbound, remoteSrc);
|
|
36
36
|
}
|
|
37
37
|
function createImageLoaderSharedEntries({
|
|
38
38
|
bound,
|
|
@@ -191,7 +191,7 @@ function ConsumeRemoteComponent2(props) {
|
|
|
191
191
|
return _nullishCoalesce(props.children, () => ( null));
|
|
192
192
|
}
|
|
193
193
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
194
|
-
|
|
194
|
+
_chunkO4ED3BUPcjs.ConsumeRemoteComponent,
|
|
195
195
|
{
|
|
196
196
|
...props,
|
|
197
197
|
shared: sharedModules(props.shared, props.resolveClientUrl)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
ConsumeRemoteComponent
|
|
4
|
-
} from "../../../chunk-
|
|
4
|
+
} from "../../../chunk-KCUEMMYL.js";
|
|
5
5
|
import {
|
|
6
6
|
bindResolveClientUrl
|
|
7
|
-
} from "../../../chunk-
|
|
7
|
+
} from "../../../chunk-VJO4PTWG.js";
|
|
8
8
|
import "../../../chunk-WGSS7TJP.js";
|
|
9
|
-
import "../../../chunk-
|
|
10
|
-
import "../../../chunk-
|
|
9
|
+
import "../../../chunk-FF4SXSSG.js";
|
|
10
|
+
import "../../../chunk-STMO56U2.js";
|
|
11
11
|
import "../../../chunk-LEKG4YWI.js";
|
|
12
12
|
import "../../../chunk-RHGEBXPL.js";
|
|
13
13
|
import {
|
package/dist/host/react.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../chunk-
|
|
4
|
+
var _chunkO4ED3BUPcjs = require('../chunk-O4ED3BUP.cjs');
|
|
5
|
+
require('../chunk-EW5O3Q24.cjs');
|
|
6
6
|
require('../chunk-4MLJE6UP.cjs');
|
|
7
|
-
require('../chunk-
|
|
8
|
-
require('../chunk-
|
|
7
|
+
require('../chunk-KAFPXSRI.cjs');
|
|
8
|
+
require('../chunk-YJJFRORQ.cjs');
|
|
9
9
|
require('../chunk-3AX5WLZD.cjs');
|
|
10
10
|
require('../chunk-N3SQTOSE.cjs');
|
|
11
11
|
require('../chunk-I7VKDF3E.cjs');
|
|
@@ -18,5 +18,5 @@ require('../chunk-SHFJ5OQA.cjs');
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
exports.ConsumeRemoteComponent =
|
|
21
|
+
exports.ConsumeRemoteComponent = _chunkO4ED3BUPcjs.ConsumeRemoteComponent; exports.useRemoteNavigate = _chunkO4ED3BUPcjs.useRemoteNavigate;
|
|
22
22
|
//# sourceMappingURL=react.cjs.map
|
package/dist/host/react.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ConsumeRemoteComponent,
|
|
3
3
|
useRemoteNavigate
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-KCUEMMYL.js";
|
|
5
|
+
import "../chunk-VJO4PTWG.js";
|
|
6
6
|
import "../chunk-WGSS7TJP.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-FF4SXSSG.js";
|
|
8
|
+
import "../chunk-STMO56U2.js";
|
|
9
9
|
import "../chunk-LEKG4YWI.js";
|
|
10
10
|
import "../chunk-RHGEBXPL.js";
|
|
11
11
|
import "../chunk-JZRA6DPE.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/chunk-loader.ts"],"sourcesContent":["import { RUNTIME_WEBPACK } from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { collapseDoubleSlashes } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport {\n logDebug,\n logWarn,\n warnCrossOriginFetchError,\n} from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\nimport {\n formatRemoteId,\n getScope,\n parseRemoteId,\n type RemoteScope,\n} from './remote-scope';\n\n/**\n * Loads a chunk using a specific scope. All state (base URL, proxy callback,\n * TURBOPACK global key) comes from the scope — no global lookups needed.\n *\n * This is the primary chunk loader called directly from:\n * - setupRemoteScope (initial chunks)\n * - TurbopackContext.l (module-level chunk loading)\n * - handleTurbopackChunk (CHUNK_LIST additional chunks)\n *\n * The global chunk dedup cache is keyed by absolute URL, so different origins\n * naturally get separate cache entries even when sharing a bundle name.\n */\nexport function loadChunkWithScope(\n scope: RemoteScope,\n chunkId: string,\n): Promise<unknown> | undefined {\n logDebug(\n 'ChunkLoader',\n `loadChunkWithScope: \"${chunkId}\" (scope: \"${scope.scopedName}\")`,\n );\n const self = globalThis as GlobalScope;\n const ns = getNamespace();\n\n const { bundle, path, prefix } = parseRemoteId(chunkId);\n\n // Skip webpack runtime chunks\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : scope.runtime;\n if (remoteRuntime === RUNTIME_WEBPACK) {\n return Promise.resolve(undefined);\n }\n\n const rawPath = path ? collapseDoubleSlashes(`${prefix}${path}`) : '/';\n const url = new URL(rawPath, scope.url).href;\n\n if (url.endsWith('.css')) {\n return;\n }\n\n if (ns.chunkCache[url]) {\n logDebug('ChunkLoader', `Cache hit for \"${chunkId}\" (url=\"${url}\")`);\n return ns.chunkCache[url];\n }\n\n const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;\n if (resolvedUrl !== url) {\n logDebug('ChunkLoader', `Proxied chunk URL: \"${url}\" → \"${resolvedUrl}\"`);\n }\n\n ns.chunkCache[url] = new Promise((resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n // Worker chunks reference self.TURBOPACK_NEXT_CHUNK_URLS and must be\n // skipped before Turbopack detection — they are not loadable as scripts.\n // Check this first so the detection below doesn't need to account for it.\n if (/importScripts\\(\\.\\.\\.self\\.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const hasTurbopackLegacyGlobal = TURBOPACK_GLOBAL_RE.test(code);\n // When chunkLoadingGlobal is configured at build time, chunks use the\n // custom scoped name instead of the shared TURBOPACK global, so\n // TURBOPACK_GLOBAL_RE won't match — detect via the custom name instead.\n // The config sets \"TURBOPACK_remote_chunk_loading_global_<name>\" which\n // Next.js leaves unchanged (it only auto-prefixes values that don't\n // already start with \"TURBOPACK_\"). Chunks emit bracket notation:\n // globalThis[\"TURBOPACK_remote_chunk_loading_global_<name>\"].\n const customGlobalProp = `TURBOPACK_remote_chunk_loading_global_${scope.name}`;\n const hasCustomGlobal = code.includes(customGlobalProp);\n const isTurbopackChunk = hasTurbopackLegacyGlobal || hasCustomGlobal;\n if (isTurbopackChunk) {\n logDebug(\n 'ChunkLoader',\n hasCustomGlobal && !hasTurbopackLegacyGlobal\n ? `Chunk \"${url}\" uses build-time chunkLoadingGlobal \"${customGlobalProp}\" — skipping runtime TURBOPACK rename.`\n : `Chunk \"${url}\" uses legacy globalThis.TURBOPACK — applying runtime rename for scope \"${scope.scopedName}\".`,\n );\n return handleTurbopackChunk(\n code,\n scope,\n url,\n hasTurbopackLegacyGlobal,\n );\n }\n // Chunk doesn't contain Turbopack globals — nothing to process\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n });\n\n return ns.chunkCache[url];\n}\n\n/**\n * Creates the global `__webpack_chunk_load__` dispatcher.\n * This is a thin wrapper called only by external code (React's RSC runtime).\n * It parses the chunkId, resolves the correct scope, and delegates to\n * `loadChunkWithScope`.\n */\nexport function createChunkDispatcher(): (\n chunkId: string,\n scriptBundle?: string,\n) => Promise<unknown> | undefined {\n return function __chunk_dispatcher__(chunkId: string, scriptBundle?: string) {\n logDebug('ChunkDispatcher', `Dispatching chunk: \"${chunkId}\"`);\n\n const { bundle } = parseRemoteId(chunkId);\n const bundleName = bundle || scriptBundle || 'default';\n\n // Works with both the scoped name (Next.js hosts with server-side\n // rewriting) and the plain bundle name (static/HTML hosts).\n const scope = getScope(bundleName);\n\n logDebug(\n 'ChunkDispatcher',\n `Scope resolution: bundle=\"${bundleName}\", scope=${scope?.scopedName ?? 'null'}`,\n );\n\n if (!scope) {\n logWarn('ChunkDispatcher', `No scope found for bundle \"${bundleName}\"`);\n return Promise.resolve(undefined);\n }\n\n return loadChunkWithScope(scope, chunkId);\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n * Receives scope directly — no global state lookups needed.\n *\n * `renameTurbopackGlobal` is true when chunks use the shared\n * `globalThis.TURBOPACK` name and must be renamed at runtime. When\n * `chunkLoadingGlobal` is configured at build time, chunks already use a\n * unique scoped name so those renames are skipped — only the remaining\n * hardcoded globals (WORKER_LOCATION, NEXT_CHUNK_URLS, CHUNK_UPDATE_LISTENERS,\n * etc.) still need renaming.\n */\nasync function handleTurbopackChunk(\n code: string,\n scope: RemoteScope,\n url: string,\n renameTurbopackGlobal: boolean,\n): Promise<void> {\n const self = globalThis as GlobalScope;\n const { globalKey, name } = scope;\n\n // When chunkLoadingGlobal is configured at build time, chunks already use a\n // unique name — no runtime rename needed for those four patterns. Otherwise\n // the shared globalThis.TURBOPACK must be renamed here.\n // For new-style chunks the prop matches exactly what config sets:\n // \"TURBOPACK_remote_chunk_loading_global_<name>\".\n const globalProp = renameTurbopackGlobal\n ? `TURBOPACK_${globalKey}`\n : `TURBOPACK_remote_chunk_loading_global_${name}`;\n\n let transformedCode = code;\n if (renameTurbopackGlobal) {\n // Legacy chunks use the shared globalThis.TURBOPACK name. Rename it and\n // the CHUNK_LISTS global (which Turbopack derives as \"{global}_CHUNK_LISTS\")\n // to per-scope names so multiple remotes don't collide.\n transformedCode = transformedCode\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${globalKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${globalKey}`)\n .replace(/TURBOPACK_CHUNK_LISTS/g, `TURBOPACK_${globalKey}_CHUNK_LISTS`);\n }\n // These globals are hardcoded in the Turbopack runtime JS (not derived from\n // chunkLoadingGlobal) so they need renaming for both legacy and new-style chunks.\n transformedCode = transformedCode\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${globalKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${globalKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${globalKey}`,\n )\n .replace(/__next_require__/g, `__${globalKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${new URL('.', new URL(url, scope.url)).href}$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle as a real Array with a push interceptor.\n // Must be a true Array instance so Next.js 15.x turbopack runtimes whose\n // module-system IIFE guards with `Array.isArray(globalThis.TURBOPACK)`\n // don't bail out after we rewrite the global name.\n //\n // The interceptor captures module entries into scope.turbopackModules —\n // a flat array we control. We use Object.defineProperty to intercept\n // when the turbopack runtime replaces the global with a deferred-loading\n // dispatcher (canary builds), wrapping the replacement's push too.\n //\n // The scope is reused across loads of different components from the same\n // remote (see setupRemoteScope), so subsequent loads accumulate into\n // the same turbopackModules array. Chunk cache deduplication means\n // handleTurbopackChunk only runs once per unique chunk URL — all captured\n // modules remain available for any component that needs them.\n if (!self[globalProp]) {\n const wrapPush = <T extends { push?: (...args: unknown[]) => unknown }>(\n target: T,\n ): T => {\n const originalPush = target.push;\n if (typeof originalPush !== 'function') return target;\n target.push = (...items: unknown[]) => {\n for (const item of items) {\n if (Array.isArray(item)) {\n for (const entry of item) {\n scope.turbopackModules.push(entry);\n }\n } else {\n scope.turbopackModules.push(item);\n }\n }\n return originalPush.apply(target, items);\n };\n return target;\n };\n\n let currentValue: unknown = wrapPush([] as unknown[]);\n Object.defineProperty(self, globalProp, {\n get() {\n return currentValue;\n },\n set(newValue: unknown) {\n // When the turbopack runtime replaces the array with a dispatcher,\n // wrap the new object's push so we keep capturing module entries.\n if (newValue && typeof newValue === 'object') {\n wrapPush(newValue as { push?: (...args: unknown[]) => unknown });\n }\n currentValue = newValue;\n },\n configurable: true,\n enumerable: true,\n });\n }\n\n // load the script dynamically using a Blob URL\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n // These CHUNK_LIST chunks load directly via scope — no global dispatch needed.\n // For new-style chunks the list global is \"${globalProp}_CHUNK_LISTS\"; for\n // legacy it was renamed to \"TURBOPACK_${globalKey}_CHUNK_LISTS\" by the\n // transform above. Both cases are covered by reading from \"${globalProp}_CHUNK_LISTS\".\n const chunkLists = self[`${globalProp}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n const loadChunkPromises: (Promise<unknown> | undefined)[] = [];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n for (const id of chunks) {\n const baseUrl = url.slice(0, url.indexOf('/_next'));\n const chunkLoadResult = loadChunkWithScope(\n scope,\n formatRemoteId(scope, `${baseUrl}/_next/${id}`),\n );\n if (chunkLoadResult) {\n loadChunkPromises.push(chunkLoadResult);\n }\n }\n }\n }\n if (loadChunkPromises.length > 0) {\n await Promise.all(loadChunkPromises);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAgC;AAChC,uBAA6B;AAC7B,sBAAsC;AAEtC,mCAA6B;AAC7B,mBAGO;AACP,oBAIO;AACP,IAAAA,mBAAoC;AAC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vD,UAAM,OAAO,IAAI,KAAK,CAAC,eAAe,GAAG;AAAA,MACvC,MAAM;AAAA,IACR,CAAC;AACD,UAAM,YAAY,IAAI,gBAAgB,IAAI;AAC1C,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,aAAa,sBAAsB,GAAG;AAC7C,WAAO,MAAM;AACb,WAAO,QAAQ;AACf,WAAO,SAAS,MAAM;AACpB,UAAI,gBAAgB,SAAS;AAC7B,oBAAc,MAAS;AACvB,aAAO,OAAO;AAAA,IAChB;AACA,WAAO,UAAU,MAAM;AACrB,UAAI,gBAAgB,SAAS;AAC7B;AAAA,QACE,IAAI;AAAA,UACF,+BAA+B,OAAO;AAAA,QACxC;AAAA,MACF;AACA,aAAO,OAAO;AAAA,IAChB;AACA,aAAS,KAAK,YAAY,MAAM;AAAA,EAClC,CAAC;AAOD,QAAM,aAAa,KAAK,GAAG,wBAAwB;AAGnD,QAAM,oBAAsD,CAAC;AAC7D,SAAO,YAAY,QAAQ;AACzB,UAAM,EAAE,OAAO,IAAI,WAAW,MAAM,KAAK,EAAE,QAAQ,CAAC,EAAE;AACtD,QAAI,OAAO,SAAS,GAAG;AACrB,iBAAW,MAAM,QAAQ;AACvB,cAAM,UAAU,IAAI,MAAM,GAAG,IAAI,QAAQ,QAAQ,CAAC;AAClD,cAAM,kBAAkB;AAAA,UACtB;AAAA,cACA,oCAAe,OAAO,GAAG,iBAAiB,IAAI;AAAA,QAChD;AACA,YAAI,iBAAiB;AACnB,4BAAkB,KAAK,eAAe;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,MAAI,kBAAkB,SAAS,GAAG;AAChC,UAAM,QAAQ,IAAI,iBAAiB;AAAA,EACrC;AACF;","names":["import_patterns"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/chunk-loader.ts"],"sourcesContent":["import { RUNTIME_WEBPACK } from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { collapseDoubleSlashes } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport {\n logDebug,\n logWarn,\n warnCrossOriginFetchError,\n} from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\nimport {\n formatRemoteId,\n getScope,\n parseRemoteId,\n type RemoteScope,\n} from './remote-scope';\n\n/**\n * Loads a chunk using a specific scope. All state (base URL, proxy callback,\n * TURBOPACK global key) comes from the scope — no global lookups needed.\n *\n * This is the primary chunk loader called directly from:\n * - setupRemoteScope (initial chunks)\n * - TurbopackContext.l (module-level chunk loading)\n * - handleTurbopackChunk (CHUNK_LIST additional chunks)\n *\n * The global chunk dedup cache is keyed by absolute URL, so different origins\n * naturally get separate cache entries even when sharing a bundle name.\n */\nexport function loadChunkWithScope(\n scope: RemoteScope,\n chunkId: string,\n): Promise<unknown> | undefined {\n logDebug(\n 'ChunkLoader',\n `loadChunkWithScope: \"${chunkId}\" (scope: \"${scope.scopedName}\")`,\n );\n const self = globalThis as GlobalScope;\n const ns = getNamespace();\n\n const { bundle, path, prefix } = parseRemoteId(chunkId);\n\n // Skip webpack runtime chunks\n //\n // TODO(MFES-?): dynamic chunks emitted by the remote's webpack runtime\n // (e.g. via `next/dynamic` -> `__webpack_require__.e` -> `.l`) bypass this\n // function entirely. The remote was compiled with a public path baked\n // into webpack's runtime pointing at the remote's own origin, so on\n // deployment-protected previews those URLs 401 with no path through\n // `scope.resolveClientUrl`. A previous attempt wrapped\n // `__remote_webpack_require__[bundle].l` here on the host side; it\n // produced incorrect proxy URLs (resolved against the remote origin\n // instead of the host) and was reverted. The right fix likely needs to\n // either rewrite the remote's `__webpack_require__.p` at runtime to a\n // host-proxy prefix, or intercept at the JSONP loader with a fully-\n // qualified host URL (not a relative path). Until that lands, the\n // async-loader integration test is skipped for webpack remotes.\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : scope.runtime;\n if (remoteRuntime === RUNTIME_WEBPACK) {\n return Promise.resolve(undefined);\n }\n\n const rawPath = path ? collapseDoubleSlashes(`${prefix}${path}`) : '/';\n const url = new URL(rawPath, scope.url).href;\n\n if (url.endsWith('.css')) {\n return;\n }\n\n if (ns.chunkCache[url]) {\n logDebug('ChunkLoader', `Cache hit for \"${chunkId}\" (url=\"${url}\")`);\n return ns.chunkCache[url];\n }\n\n const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;\n if (resolvedUrl !== url) {\n logDebug('ChunkLoader', `Proxied chunk URL: \"${url}\" → \"${resolvedUrl}\"`);\n }\n\n ns.chunkCache[url] = new Promise((resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n // Worker chunks reference self.TURBOPACK_NEXT_CHUNK_URLS and must be\n // skipped before Turbopack detection — they are not loadable as scripts.\n // Check this first so the detection below doesn't need to account for it.\n if (/importScripts\\(\\.\\.\\.self\\.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const hasTurbopackLegacyGlobal = TURBOPACK_GLOBAL_RE.test(code);\n // When chunkLoadingGlobal is configured at build time, chunks use the\n // custom scoped name instead of the shared TURBOPACK global, so\n // TURBOPACK_GLOBAL_RE won't match — detect via the custom name instead.\n // The config sets \"TURBOPACK_remote_chunk_loading_global_<name>\" which\n // Next.js leaves unchanged (it only auto-prefixes values that don't\n // already start with \"TURBOPACK_\"). Chunks emit bracket notation:\n // globalThis[\"TURBOPACK_remote_chunk_loading_global_<name>\"].\n const customGlobalProp = `TURBOPACK_remote_chunk_loading_global_${scope.name}`;\n const hasCustomGlobal = code.includes(customGlobalProp);\n const isTurbopackChunk = hasTurbopackLegacyGlobal || hasCustomGlobal;\n if (isTurbopackChunk) {\n logDebug(\n 'ChunkLoader',\n hasCustomGlobal && !hasTurbopackLegacyGlobal\n ? `Chunk \"${url}\" uses build-time chunkLoadingGlobal \"${customGlobalProp}\" — skipping runtime TURBOPACK rename.`\n : `Chunk \"${url}\" uses legacy globalThis.TURBOPACK — applying runtime rename for scope \"${scope.scopedName}\".`,\n );\n return handleTurbopackChunk(\n code,\n scope,\n url,\n hasTurbopackLegacyGlobal,\n );\n }\n // Chunk doesn't contain Turbopack globals — nothing to process\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n });\n\n return ns.chunkCache[url];\n}\n\n/**\n * Creates the global `__webpack_chunk_load__` dispatcher.\n * This is a thin wrapper called only by external code (React's RSC runtime).\n * It parses the chunkId, resolves the correct scope, and delegates to\n * `loadChunkWithScope`.\n */\nexport function createChunkDispatcher(): (\n chunkId: string,\n scriptBundle?: string,\n) => Promise<unknown> | undefined {\n return function __chunk_dispatcher__(chunkId: string, scriptBundle?: string) {\n logDebug('ChunkDispatcher', `Dispatching chunk: \"${chunkId}\"`);\n\n const { bundle } = parseRemoteId(chunkId);\n const bundleName = bundle || scriptBundle || 'default';\n\n // Works with both the scoped name (Next.js hosts with server-side\n // rewriting) and the plain bundle name (static/HTML hosts).\n const scope = getScope(bundleName);\n\n logDebug(\n 'ChunkDispatcher',\n `Scope resolution: bundle=\"${bundleName}\", scope=${scope?.scopedName ?? 'null'}`,\n );\n\n if (!scope) {\n logWarn('ChunkDispatcher', `No scope found for bundle \"${bundleName}\"`);\n return Promise.resolve(undefined);\n }\n\n return loadChunkWithScope(scope, chunkId);\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n * Receives scope directly — no global state lookups needed.\n *\n * `renameTurbopackGlobal` is true when chunks use the shared\n * `globalThis.TURBOPACK` name and must be renamed at runtime. When\n * `chunkLoadingGlobal` is configured at build time, chunks already use a\n * unique scoped name so those renames are skipped — only the remaining\n * hardcoded globals (WORKER_LOCATION, NEXT_CHUNK_URLS, CHUNK_UPDATE_LISTENERS,\n * etc.) still need renaming.\n */\nasync function handleTurbopackChunk(\n code: string,\n scope: RemoteScope,\n url: string,\n renameTurbopackGlobal: boolean,\n): Promise<void> {\n const self = globalThis as GlobalScope;\n const { globalKey, name } = scope;\n\n // When chunkLoadingGlobal is configured at build time, chunks already use a\n // unique name — no runtime rename needed for those four patterns. Otherwise\n // the shared globalThis.TURBOPACK must be renamed here.\n // For new-style chunks the prop matches exactly what config sets:\n // \"TURBOPACK_remote_chunk_loading_global_<name>\".\n const globalProp = renameTurbopackGlobal\n ? `TURBOPACK_${globalKey}`\n : `TURBOPACK_remote_chunk_loading_global_${name}`;\n\n let transformedCode = code;\n if (renameTurbopackGlobal) {\n // Legacy chunks use the shared globalThis.TURBOPACK name. Rename it and\n // the CHUNK_LISTS global (which Turbopack derives as \"{global}_CHUNK_LISTS\")\n // to per-scope names so multiple remotes don't collide.\n transformedCode = transformedCode\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${globalKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${globalKey}`)\n .replace(/TURBOPACK_CHUNK_LISTS/g, `TURBOPACK_${globalKey}_CHUNK_LISTS`);\n }\n // These globals are hardcoded in the Turbopack runtime JS (not derived from\n // chunkLoadingGlobal) so they need renaming for both legacy and new-style chunks.\n transformedCode = transformedCode\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${globalKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${globalKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${globalKey}`,\n )\n .replace(/__next_require__/g, `__${globalKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${new URL('.', new URL(url, scope.url)).href}$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle as a real Array with a push interceptor.\n // Must be a true Array instance so Next.js 15.x turbopack runtimes whose\n // module-system IIFE guards with `Array.isArray(globalThis.TURBOPACK)`\n // don't bail out after we rewrite the global name.\n //\n // The interceptor captures module entries into scope.turbopackModules —\n // a flat array we control. We use Object.defineProperty to intercept\n // when the turbopack runtime replaces the global with a deferred-loading\n // dispatcher (canary builds), wrapping the replacement's push too.\n //\n // The scope is reused across loads of different components from the same\n // remote (see setupRemoteScope), so subsequent loads accumulate into\n // the same turbopackModules array. Chunk cache deduplication means\n // handleTurbopackChunk only runs once per unique chunk URL — all captured\n // modules remain available for any component that needs them.\n if (!self[globalProp]) {\n const wrapPush = <T extends { push?: (...args: unknown[]) => unknown }>(\n target: T,\n ): T => {\n const originalPush = target.push;\n if (typeof originalPush !== 'function') return target;\n target.push = (...items: unknown[]) => {\n for (const item of items) {\n if (Array.isArray(item)) {\n for (const entry of item) {\n scope.turbopackModules.push(entry);\n }\n } else {\n scope.turbopackModules.push(item);\n }\n }\n return originalPush.apply(target, items);\n };\n return target;\n };\n\n let currentValue: unknown = wrapPush([] as unknown[]);\n Object.defineProperty(self, globalProp, {\n get() {\n return currentValue;\n },\n set(newValue: unknown) {\n // When the turbopack runtime replaces the array with a dispatcher,\n // wrap the new object's push so we keep capturing module entries.\n if (newValue && typeof newValue === 'object') {\n wrapPush(newValue as { push?: (...args: unknown[]) => unknown });\n }\n currentValue = newValue;\n },\n configurable: true,\n enumerable: true,\n });\n }\n\n // load the script dynamically using a Blob URL\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n // These CHUNK_LIST chunks load directly via scope — no global dispatch needed.\n // For new-style chunks the list global is \"${globalProp}_CHUNK_LISTS\"; for\n // legacy it was renamed to \"TURBOPACK_${globalKey}_CHUNK_LISTS\" by the\n // transform above. Both cases are covered by reading from \"${globalProp}_CHUNK_LISTS\".\n const chunkLists = self[`${globalProp}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n const loadChunkPromises: (Promise<unknown> | undefined)[] = [];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n for (const id of chunks) {\n const baseUrl = url.slice(0, url.indexOf('/_next'));\n const chunkLoadResult = loadChunkWithScope(\n scope,\n formatRemoteId(scope, `${baseUrl}/_next/${id}`),\n );\n if (chunkLoadResult) {\n loadChunkPromises.push(chunkLoadResult);\n }\n }\n }\n }\n if (loadChunkPromises.length > 0) {\n await Promise.all(loadChunkPromises);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAgC;AAChC,uBAA6B;AAC7B,sBAAsC;AAEt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Content":["import { RUNTIME_WEBPACK } from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { collapseDoubleSlashes } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport {\n logDebug,\n logWarn,\n warnCrossOriginFetchError,\n} from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\nimport {\n formatRemoteId,\n getScope,\n parseRemoteId,\n type RemoteScope,\n} from './remote-scope';\n\n/**\n * Loads a chunk using a specific scope. All state (base URL, proxy callback,\n * TURBOPACK global key) comes from the scope — no global lookups needed.\n *\n * This is the primary chunk loader called directly from:\n * - setupRemoteScope (initial chunks)\n * - TurbopackContext.l (module-level chunk loading)\n * - handleTurbopackChunk (CHUNK_LIST additional chunks)\n *\n * The global chunk dedup cache is keyed by absolute URL, so different origins\n * naturally get separate cache entries even when sharing a bundle name.\n */\nexport function loadChunkWithScope(\n scope: RemoteScope,\n chunkId: string,\n): Promise<unknown> | undefined {\n logDebug(\n 'ChunkLoader',\n `loadChunkWithScope: \"${chunkId}\" (scope: \"${scope.scopedName}\")`,\n );\n const self = globalThis as GlobalScope;\n const ns = getNamespace();\n\n const { bundle, path, prefix } = parseRemoteId(chunkId);\n\n // Skip webpack runtime chunks\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : scope.runtime;\n if (remoteRuntime === RUNTIME_WEBPACK) {\n return Promise.resolve(undefined);\n }\n\n const rawPath = path ? collapseDoubleSlashes(`${prefix}${path}`) : '/';\n const url = new URL(rawPath, scope.url).href;\n\n if (url.endsWith('.css')) {\n return;\n }\n\n if (ns.chunkCache[url]) {\n logDebug('ChunkLoader', `Cache hit for \"${chunkId}\" (url=\"${url}\")`);\n return ns.chunkCache[url];\n }\n\n const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;\n if (resolvedUrl !== url) {\n logDebug('ChunkLoader', `Proxied chunk URL: \"${url}\" → \"${resolvedUrl}\"`);\n }\n\n ns.chunkCache[url] = new Promise((resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n // Worker chunks reference self.TURBOPACK_NEXT_CHUNK_URLS and must be\n // skipped before Turbopack detection — they are not loadable as scripts.\n // Check this first so the detection below doesn't need to account for it.\n if (/importScripts\\(\\.\\.\\.self\\.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const hasTurbopackLegacyGlobal = TURBOPACK_GLOBAL_RE.test(code);\n // When chunkLoadingGlobal is configured at build time, chunks use the\n // custom scoped name instead of the shared TURBOPACK global, so\n // TURBOPACK_GLOBAL_RE won't match — detect via the custom name instead.\n // The config sets \"TURBOPACK_remote_chunk_loading_global_<name>\" which\n // Next.js leaves unchanged (it only auto-prefixes values that don't\n // already start with \"TURBOPACK_\"). Chunks emit bracket notation:\n // globalThis[\"TURBOPACK_remote_chunk_loading_global_<name>\"].\n const customGlobalProp = `TURBOPACK_remote_chunk_loading_global_${scope.name}`;\n const hasCustomGlobal = code.includes(customGlobalProp);\n const isTurbopackChunk = hasTurbopackLegacyGlobal || hasCustomGlobal;\n if (isTurbopackChunk) {\n logDebug(\n 'ChunkLoader',\n hasCustomGlobal && !hasTurbopackLegacyGlobal\n ? `Chunk \"${url}\" uses build-time chunkLoadingGlobal \"${customGlobalProp}\" — skipping runtime TURBOPACK rename.`\n : `Chunk \"${url}\" uses legacy globalThis.TURBOPACK — applying runtime rename for scope \"${scope.scopedName}\".`,\n );\n return handleTurbopackChunk(\n code,\n scope,\n url,\n hasTurbopackLegacyGlobal,\n );\n }\n // Chunk doesn't contain Turbopack globals — nothing to process\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n });\n\n return ns.chunkCache[url];\n}\n\n/**\n * Creates the global `__webpack_chunk_load__` dispatcher.\n * This is a thin wrapper called only by external code (React's RSC runtime).\n * It parses the chunkId, resolves the correct scope, and delegates to\n * `loadChunkWithScope`.\n */\nexport function createChunkDispatcher(): (\n chunkId: string,\n scriptBundle?: string,\n) => Promise<unknown> | undefined {\n return function __chunk_dispatcher__(chunkId: string, scriptBundle?: string) {\n logDebug('ChunkDispatcher', `Dispatching chunk: \"${chunkId}\"`);\n\n const { bundle } = parseRemoteId(chunkId);\n const bundleName = bundle || scriptBundle || 'default';\n\n // Works with both the scoped name (Next.js hosts with server-side\n // rewriting) and the plain bundle name (static/HTML hosts).\n const scope = getScope(bundleName);\n\n logDebug(\n 'ChunkDispatcher',\n `Scope resolution: bundle=\"${bundleName}\", scope=${scope?.scopedName ?? 'null'}`,\n );\n\n if (!scope) {\n logWarn('ChunkDispatcher', `No scope found for bundle \"${bundleName}\"`);\n return Promise.resolve(undefined);\n }\n\n return loadChunkWithScope(scope, chunkId);\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n * Receives scope directly — no global state lookups needed.\n *\n * `renameTurbopackGlobal` is true when chunks use the shared\n * `globalThis.TURBOPACK` name and must be renamed at runtime. When\n * `chunkLoadingGlobal` is configured at build time, chunks already use a\n * unique scoped name so those renames are skipped — only the remaining\n * hardcoded globals (WORKER_LOCATION, NEXT_CHUNK_URLS, CHUNK_UPDATE_LISTENERS,\n * etc.) still need renaming.\n */\nasync function handleTurbopackChunk(\n code: string,\n scope: RemoteScope,\n url: string,\n renameTurbopackGlobal: boolean,\n): Promise<void> {\n const self = globalThis as GlobalScope;\n const { globalKey, name } = scope;\n\n // When chunkLoadingGlobal is configured at build time, chunks already use a\n // unique name — no runtime rename needed for those four patterns. Otherwise\n // the shared globalThis.TURBOPACK must be renamed here.\n // For new-style chunks the prop matches exactly what config sets:\n // \"TURBOPACK_remote_chunk_loading_global_<name>\".\n const globalProp = renameTurbopackGlobal\n ? `TURBOPACK_${globalKey}`\n : `TURBOPACK_remote_chunk_loading_global_${name}`;\n\n let transformedCode = code;\n if (renameTurbopackGlobal) {\n // Legacy chunks use the shared globalThis.TURBOPACK name. Rename it and\n // the CHUNK_LISTS global (which Turbopack derives as \"{global}_CHUNK_LISTS\")\n // to per-scope names so multiple remotes don't collide.\n transformedCode = transformedCode\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${globalKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${globalKey}`)\n .replace(/TURBOPACK_CHUNK_LISTS/g, `TURBOPACK_${globalKey}_CHUNK_LISTS`);\n }\n // These globals are hardcoded in the Turbopack runtime JS (not derived from\n // chunkLoadingGlobal) so they need renaming for both legacy and new-style chunks.\n transformedCode = transformedCode\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${globalKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${globalKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${globalKey}`,\n )\n .replace(/__next_require__/g, `__${globalKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${new URL('.', new URL(url, scope.url)).href}$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle as a real Array with a push interceptor.\n // Must be a true Array instance so Next.js 15.x turbopack runtimes whose\n // module-system IIFE guards with `Array.isArray(globalThis.TURBOPACK)`\n // don't bail out after we rewrite the global name.\n //\n // The interceptor captures module entries into scope.turbopackModules —\n // a flat array we control. We use Object.defineProperty to intercept\n // when the turbopack runtime replaces the global with a deferred-loading\n // dispatcher (canary builds), wrapping the replacement's push too.\n //\n // The scope is reused across loads of different components from the same\n // remote (see setupRemoteScope), so subsequent loads accumulate into\n // the same turbopackModules array. Chunk cache deduplication means\n // handleTurbopackChunk only runs once per unique chunk URL — all captured\n // modules remain available for any component that needs them.\n if (!self[globalProp]) {\n const wrapPush = <T extends { push?: (...args: unknown[]) => unknown }>(\n target: T,\n ): T => {\n const originalPush = target.push;\n if (typeof originalPush !== 'function') return target;\n target.push = (...items: unknown[]) => {\n for (const item of items) {\n if (Array.isArray(item)) {\n for (const entry of item) {\n scope.turbopackModules.push(entry);\n }\n } else {\n scope.turbopackModules.push(item);\n }\n }\n return originalPush.apply(target, items);\n };\n return target;\n };\n\n let currentValue: unknown = wrapPush([] as unknown[]);\n Object.defineProperty(self, globalProp, {\n get() {\n return currentValue;\n },\n set(newValue: unknown) {\n // When the turbopack runtime replaces the array with a dispatcher,\n // wrap the new object's push so we keep capturing module entries.\n if (newValue && typeof newValue === 'object') {\n wrapPush(newValue as { push?: (...args: unknown[]) => unknown });\n }\n currentValue = newValue;\n },\n configurable: true,\n enumerable: true,\n });\n }\n\n // load the script dynamically using a Blob URL\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n // These CHUNK_LIST chunks load directly via scope — no global dispatch needed.\n // For new-style chunks the list global is \"${globalProp}_CHUNK_LISTS\"; for\n // legacy it was renamed to \"TURBOPACK_${globalKey}_CHUNK_LISTS\" by the\n // transform above. Both cases are covered by reading from \"${globalProp}_CHUNK_LISTS\".\n const chunkLists = self[`${globalProp}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n const loadChunkPromises: (Promise<unknown> | undefined)[] = [];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n for (const id of chunks) {\n const baseUrl = url.slice(0, url.indexOf('/_next'));\n const chunkLoadResult = loadChunkWithScope(\n scope,\n formatRemoteId(scope, `${baseUrl}/_next/${id}`),\n );\n if (chunkLoadResult) {\n loadChunkPromises.push(chunkLoadResult);\n }\n }\n }\n }\n if (loadChunkPromises.length > 0) {\n await Promise.all(loadChunkPromises);\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAEtC,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAcA,SAAS,mBACd,OACA,SAC8B;AAC9B;AAAA,IACE;AAAA,IACA,wBAAwB,qBAAqB,MAAM;AAAA,EACrD;AACA,QAAM,OAAO;AACb,QAAM,KAAK,aAAa;AAExB,QAAM,EAAE,QAAQ,MAAM,OAAO,IAAI,cAAc,OAAO;AAGtD,QAAM,gBA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f,WAAO,SAAS,MAAM;AACpB,UAAI,gBAAgB,SAAS;AAC7B,oBAAc,MAAS;AACvB,aAAO,OAAO;AAAA,IAChB;AACA,WAAO,UAAU,MAAM;AACrB,UAAI,gBAAgB,SAAS;AAC7B;AAAA,QACE,IAAI;AAAA,UACF,+BAA+B,OAAO;AAAA,QACxC;AAAA,MACF;AACA,aAAO,OAAO;AAAA,IAChB;AACA,aAAS,KAAK,YAAY,MAAM;AAAA,EAClC,CAAC;AAOD,QAAM,aAAa,KAAK,GAAG,wBAAwB;AAGnD,QAAM,oBAAsD,CAAC;AAC7D,SAAO,YAAY,QAAQ;AACzB,UAAM,EAAE,OAAO,IAAI,WAAW,MAAM,KAAK,EAAE,QAAQ,CAAC,EAAE;AACtD,QAAI,OAAO,SAAS,GAAG;AACrB,iBAAW,MAAM,QAAQ;AACvB,cAAM,UAAU,IAAI,MAAM,GAAG,IAAI,QAAQ,QAAQ,CAAC;AAClD,cAAM,kBAAkB;AAAA,UACtB;AAAA,UACA,eAAe,OAAO,GAAG,iBAAiB,IAAI;AAAA,QAChD;AACA,YAAI,iBAAiB;AACnB,4BAAkB,KAAK,eAAe;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,MAAI,kBAAkB,SAAS,GAAG;AAChC,UAAM,QAAQ,IAAI,iBAAiB;AAAA,EACrC;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/chunk-loader.ts"],"sourcesContent":["import { RUNTIME_WEBPACK } from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { collapseDoubleSlashes } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport {\n logDebug,\n logWarn,\n warnCrossOriginFetchError,\n} from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\nimport {\n formatRemoteId,\n getScope,\n parseRemoteId,\n type RemoteScope,\n} from './remote-scope';\n\n/**\n * Loads a chunk using a specific scope. All state (base URL, proxy callback,\n * TURBOPACK global key) comes from the scope — no global lookups needed.\n *\n * This is the primary chunk loader called directly from:\n * - setupRemoteScope (initial chunks)\n * - TurbopackContext.l (module-level chunk loading)\n * - handleTurbopackChunk (CHUNK_LIST additional chunks)\n *\n * The global chunk dedup cache is keyed by absolute URL, so different origins\n * naturally get separate cache entries even when sharing a bundle name.\n */\nexport function loadChunkWithScope(\n scope: RemoteScope,\n chunkId: string,\n): Promise<unknown> | undefined {\n logDebug(\n 'ChunkLoader',\n `loadChunkWithScope: \"${chunkId}\" (scope: \"${scope.scopedName}\")`,\n );\n const self = globalThis as GlobalScope;\n const ns = getNamespace();\n\n const { bundle, path, prefix } = parseRemoteId(chunkId);\n\n // Skip webpack runtime chunks\n //\n // TODO(MFES-?): dynamic chunks emitted by the remote's webpack runtime\n // (e.g. via `next/dynamic` -> `__webpack_require__.e` -> `.l`) bypass this\n // function entirely. The remote was compiled with a public path baked\n // into webpack's runtime pointing at the remote's own origin, so on\n // deployment-protected previews those URLs 401 with no path through\n // `scope.resolveClientUrl`. A previous attempt wrapped\n // `__remote_webpack_require__[bundle].l` here on the host side; it\n // produced incorrect proxy URLs (resolved against the remote origin\n // instead of the host) and was reverted. The right fix likely needs to\n // either rewrite the remote's `__webpack_require__.p` at runtime to a\n // host-proxy prefix, or intercept at the JSONP loader with a fully-\n // qualified host URL (not a relative path). Until that lands, the\n // async-loader integration test is skipped for webpack remotes.\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : scope.runtime;\n if (remoteRuntime === RUNTIME_WEBPACK) {\n return Promise.resolve(undefined);\n }\n\n const rawPath = path ? collapseDoubleSlashes(`${prefix}${path}`) : '/';\n const url = new URL(rawPath, scope.url).href;\n\n if (url.endsWith('.css')) {\n return;\n }\n\n if (ns.chunkCache[url]) {\n logDebug('ChunkLoader', `Cache hit for \"${chunkId}\" (url=\"${url}\")`);\n return ns.chunkCache[url];\n }\n\n const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;\n if (resolvedUrl !== url) {\n logDebug('ChunkLoader', `Proxied chunk URL: \"${url}\" → \"${resolvedUrl}\"`);\n }\n\n ns.chunkCache[url] = new Promise((resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n // Worker chunks reference self.TURBOPACK_NEXT_CHUNK_URLS and must be\n // skipped before Turbopack detection — they are not loadable as scripts.\n // Check this first so the detection below doesn't need to account for it.\n if (/importScripts\\(\\.\\.\\.self\\.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const hasTurbopackLegacyGlobal = TURBOPACK_GLOBAL_RE.test(code);\n // When chunkLoadingGlobal is configured at build time, chunks use the\n // custom scoped name instead of the shared TURBOPACK global, so\n // TURBOPACK_GLOBAL_RE won't match — detect via the custom name instead.\n // The config sets \"TURBOPACK_remote_chunk_loading_global_<name>\" which\n // Next.js leaves unchanged (it only auto-prefixes values that don't\n // already start with \"TURBOPACK_\"). Chunks emit bracket notation:\n // globalThis[\"TURBOPACK_remote_chunk_loading_global_<name>\"].\n const customGlobalProp = `TURBOPACK_remote_chunk_loading_global_${scope.name}`;\n const hasCustomGlobal = code.includes(customGlobalProp);\n const isTurbopackChunk = hasTurbopackLegacyGlobal || hasCustomGlobal;\n if (isTurbopackChunk) {\n logDebug(\n 'ChunkLoader',\n hasCustomGlobal && !hasTurbopackLegacyGlobal\n ? `Chunk \"${url}\" uses build-time chunkLoadingGlobal \"${customGlobalProp}\" — skipping runtime TURBOPACK rename.`\n : `Chunk \"${url}\" uses legacy globalThis.TURBOPACK — applying runtime rename for scope \"${scope.scopedName}\".`,\n );\n return handleTurbopackChunk(\n code,\n scope,\n url,\n hasTurbopackLegacyGlobal,\n );\n }\n // Chunk doesn't contain Turbopack globals — nothing to process\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n });\n\n return ns.chunkCache[url];\n}\n\n/**\n * Creates the global `__webpack_chunk_load__` dispatcher.\n * This is a thin wrapper called only by external code (React's RSC runtime).\n * It parses the chunkId, resolves the correct scope, and delegates to\n * `loadChunkWithScope`.\n */\nexport function createChunkDispatcher(): (\n chunkId: string,\n scriptBundle?: string,\n) => Promise<unknown> | undefined {\n return function __chunk_dispatcher__(chunkId: string, scriptBundle?: string) {\n logDebug('ChunkDispatcher', `Dispatching chunk: \"${chunkId}\"`);\n\n const { bundle } = parseRemoteId(chunkId);\n const bundleName = bundle || scriptBundle || 'default';\n\n // Works with both the scoped name (Next.js hosts with server-side\n // rewriting) and the plain bundle name (static/HTML hosts).\n const scope = getScope(bundleName);\n\n logDebug(\n 'ChunkDispatcher',\n `Scope resolution: bundle=\"${bundleName}\", scope=${scope?.scopedName ?? 'null'}`,\n );\n\n if (!scope) {\n logWarn('ChunkDispatcher', `No scope found for bundle \"${bundleName}\"`);\n return Promise.resolve(undefined);\n }\n\n return loadChunkWithScope(scope, chunkId);\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n * Receives scope directly — no global state lookups needed.\n *\n * `renameTurbopackGlobal` is true when chunks use the shared\n * `globalThis.TURBOPACK` name and must be renamed at runtime. When\n * `chunkLoadingGlobal` is configured at build time, chunks already use a\n * unique scoped name so those renames are skipped — only the remaining\n * hardcoded globals (WORKER_LOCATION, NEXT_CHUNK_URLS, CHUNK_UPDATE_LISTENERS,\n * etc.) still need renaming.\n */\nasync function handleTurbopackChunk(\n code: string,\n scope: RemoteScope,\n url: string,\n renameTurbopackGlobal: boolean,\n): Promise<void> {\n const self = globalThis as GlobalScope;\n const { globalKey, name } = scope;\n\n // When chunkLoadingGlobal is configured at build time, chunks already use a\n // unique name — no runtime rename needed for those four patterns. Otherwise\n // the shared globalThis.TURBOPACK must be renamed here.\n // For new-style chunks the prop matches exactly what config sets:\n // \"TURBOPACK_remote_chunk_loading_global_<name>\".\n const globalProp = renameTurbopackGlobal\n ? `TURBOPACK_${globalKey}`\n : `TURBOPACK_remote_chunk_loading_global_${name}`;\n\n let transformedCode = code;\n if (renameTurbopackGlobal) {\n // Legacy chunks use the shared globalThis.TURBOPACK name. Rename it and\n // the CHUNK_LISTS global (which Turbopack derives as \"{global}_CHUNK_LISTS\")\n // to per-scope names so multiple remotes don't collide.\n transformedCode = transformedCode\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${globalKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${globalKey}`)\n .replace(/TURBOPACK_CHUNK_LISTS/g, `TURBOPACK_${globalKey}_CHUNK_LISTS`);\n }\n // These globals are hardcoded in the Turbopack runtime JS (not derived from\n // chunkLoadingGlobal) so they need renaming for both legacy and new-style chunks.\n transformedCode = transformedCode\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${globalKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${globalKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${globalKey}`,\n )\n .replace(/__next_require__/g, `__${globalKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${new URL('.', new URL(url, scope.url)).href}$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle as a real Array with a push interceptor.\n // Must be a true Array instance so Next.js 15.x turbopack runtimes whose\n // module-system IIFE guards with `Array.isArray(globalThis.TURBOPACK)`\n // don't bail out after we rewrite the global name.\n //\n // The interceptor captures module entries into scope.turbopackModules —\n // a flat array we control. We use Object.defineProperty to intercept\n // when the turbopack runtime replaces the global with a deferred-loading\n // dispatcher (canary builds), wrapping the replacement's push too.\n //\n // The scope is reused across loads of different components from the same\n // remote (see setupRemoteScope), so subsequent loads accumulate into\n // the same turbopackModules array. Chunk cache deduplication means\n // handleTurbopackChunk only runs once per unique chunk URL — all captured\n // modules remain available for any component that needs them.\n if (!self[globalProp]) {\n const wrapPush = <T extends { push?: (...args: unknown[]) => unknown }>(\n target: T,\n ): T => {\n const originalPush = target.push;\n if (typeof originalPush !== 'function') return target;\n target.push = (...items: unknown[]) => {\n for (const item of items) {\n if (Array.isArray(item)) {\n for (const entry of item) {\n scope.turbopackModules.push(entry);\n }\n } else {\n scope.turbopackModules.push(item);\n }\n }\n return originalPush.apply(target, items);\n };\n return target;\n };\n\n let currentValue: unknown = wrapPush([] as unknown[]);\n Object.defineProperty(self, globalProp, {\n get() {\n return currentValue;\n },\n set(newValue: unknown) {\n // When the turbopack runtime replaces the array with a dispatcher,\n // wrap the new object's push so we keep capturing module entries.\n if (newValue && typeof newValue === 'object') {\n wrapPush(newValue as { push?: (...args: unknown[]) => unknown });\n }\n currentValue = newValue;\n },\n configurable: true,\n enumerable: true,\n });\n }\n\n // load the script dynamically using a Blob URL\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n // These CHUNK_LIST chunks load directly via scope — no global dispatch needed.\n // For new-style chunks the list global is \"${globalProp}_CHUNK_LISTS\"; for\n // legacy it was renamed to \"TURBOPACK_${globalKey}_CHUNK_LISTS\" by the\n // transform above. Both cases are covered by reading from \"${globalProp}_CHUNK_LISTS\".\n const chunkLists = self[`${globalProp}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n const loadChunkPromises: (Promise<unknown> | undefined)[] = [];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n for (const id of chunks) {\n const baseUrl = url.slice(0, url.indexOf('/_next'));\n const chunkLoadResult = loadChunkWithScope(\n scope,\n formatRemoteId(scope, `${baseUrl}/_next/${id}`),\n );\n if (chunkLoadResult) {\n loadChunkPromises.push(chunkLoadResult);\n }\n }\n }\n }\n if (loadChunkPromises.length > 0) {\n await Promise.all(loadChunkPromises);\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAEtC,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAcA,SAAS,mBACd,OACA,SAC8B;AAC9B;AAAA,IACE;AAAA,IACA,wBAAwB,qBAAqB,MAAM;AAAA,EACrD;AACA,QAA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UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,aAAa,sBAAsB,GAAG;AAC7C,WAAO,MAAM;AACb,WAAO,QAAQ;AACf,WAAO,SAAS,MAAM;AACpB,UAAI,gBAAgB,SAAS;AAC7B,oBAAc,MAAS;AACvB,aAAO,OAAO;AAAA,IAChB;AACA,WAAO,UAAU,MAAM;AACrB,UAAI,gBAAgB,SAAS;AAC7B;AAAA,QACE,IAAI;AAAA,UACF,+BAA+B,OAAO;AAAA,QACxC;AAAA,MACF;AACA,aAAO,OAAO;AAAA,IAChB;AACA,aAAS,KAAK,YAAY,MAAM;AAAA,EAClC,CAAC;AAOD,QAAM,aAAa,KAAK,GAAG,wBAAwB;AAGnD,QAAM,oBAAsD,CAAC;AAC7D,SAAO,YAAY,QAAQ;AACzB,UAAM,EAAE,OAAO,IAAI,WAAW,MAAM,KAAK,EAAE,QAAQ,CAAC,EAAE;AACtD,QAAI,OAAO,SAAS,GAAG;AACrB,iBAAW,MAAM,QAAQ;AACvB,cAAM,UAAU,IAAI,MAAM,GAAG,IAAI,QAAQ,QAAQ,CAAC;AAClD,cAAM,kBAAkB;AAAA,UACtB;AAAA,UACA,eAAe,OAAO,GAAG,iBAAiB,IAAI;AAAA,QAChD;AACA,YAAI,iBAAiB;AACnB,4BAAkB,KAAK,eAAe;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,MAAI,kBAAkB,SAAS,GAAG;AAChC,UAAM,QAAQ,IAAI,iBAAiB;AAAA,EACrC;AACF;","names":[]}
|
|
@@ -27,6 +27,27 @@ var import_logger = require("#internal/utils/logger");
|
|
|
27
27
|
var import_chunk_loader = require("./chunk-loader");
|
|
28
28
|
var import_remote_scope = require("./remote-scope");
|
|
29
29
|
var import_shared_modules = require("./shared-modules");
|
|
30
|
+
function RelativeURL(inputUrl) {
|
|
31
|
+
const realUrl = new URL(inputUrl, "x:/");
|
|
32
|
+
const values = {};
|
|
33
|
+
for (const key in realUrl) {
|
|
34
|
+
values[key] = realUrl[key];
|
|
35
|
+
}
|
|
36
|
+
values.href = inputUrl;
|
|
37
|
+
values.pathname = inputUrl.replace(/[?#].*/, "");
|
|
38
|
+
values.origin = "";
|
|
39
|
+
values.protocol = "";
|
|
40
|
+
values.toString = () => inputUrl;
|
|
41
|
+
values.toJSON = () => inputUrl;
|
|
42
|
+
for (const key in values) {
|
|
43
|
+
Object.defineProperty(this, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
value: values[key]
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
RelativeURL.prototype = URL.prototype;
|
|
30
51
|
function requireModule(scope, moduleId, fullId) {
|
|
31
52
|
const idStr = String(moduleId);
|
|
32
53
|
const sharedModule = (0, import_shared_modules.getSharedModule)(scope, moduleId);
|
|
@@ -208,13 +229,17 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
|
|
|
208
229
|
r(requireId) {
|
|
209
230
|
return scopedRequire(requireId);
|
|
210
231
|
},
|
|
211
|
-
//
|
|
232
|
+
// exportValue — mirrors upstream Turbopack's `exportValue`, which sets
|
|
233
|
+
// `module.exports = value` regardless of value type. Most importantly,
|
|
234
|
+
// when Turbopack emits an async-loader module the body is
|
|
235
|
+
// ctx.v((parentImport) => Promise.all([...]).then(() => parentImport(id)))
|
|
236
|
+
// The function must be stored as-is so that the consumer's `ctx.A(id)`
|
|
237
|
+
// can invoke it with the real parent-import resolver. Calling it eagerly
|
|
238
|
+
// here (the prior remote-components behavior) ran the loader with the
|
|
239
|
+
// wrong argument and stored a `Promise` as `exports.default`, which then
|
|
240
|
+
// crashed `ctx.A` with `.default is not a function`.
|
|
212
241
|
v(value) {
|
|
213
|
-
|
|
214
|
-
exports.default = value((vid) => scopedRequire(vid));
|
|
215
|
-
} else {
|
|
216
|
-
moduleExports.exports = value;
|
|
217
|
-
}
|
|
242
|
+
moduleExports.exports = value;
|
|
218
243
|
},
|
|
219
244
|
// exportUrl — used by static asset modules (images, fonts, JSON, etc.).
|
|
220
245
|
// Turbopack emits a tiny module whose entire body is ctx.q(url), which
|
|
@@ -227,6 +252,20 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
|
|
|
227
252
|
moduleExports.exports = value;
|
|
228
253
|
}
|
|
229
254
|
},
|
|
255
|
+
// exportNamespace — Turbopack emits `ctx.n(namespace, esmId?)` when a
|
|
256
|
+
// module's exports should be replaced wholesale with a precomputed ESM
|
|
257
|
+
// namespace object (commonly at module evaluation time for re-export
|
|
258
|
+
// patterns and CJS-to-ESM interop wrappers). Mirrors upstream
|
|
259
|
+
// `exportNamespace` which sets both `module.exports` and
|
|
260
|
+
// `module.namespaceObject`; remote-components keeps a single exports
|
|
261
|
+
// record per module, so we assign to `exports` only.
|
|
262
|
+
n(namespace, esmId) {
|
|
263
|
+
if (esmId != null) {
|
|
264
|
+
scope.moduleCache[String(esmId)] = namespace;
|
|
265
|
+
} else {
|
|
266
|
+
moduleExports.exports = namespace;
|
|
267
|
+
}
|
|
268
|
+
},
|
|
230
269
|
// async module initializer
|
|
231
270
|
async a(mod) {
|
|
232
271
|
let result;
|
|
@@ -237,10 +276,24 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
|
|
|
237
276
|
);
|
|
238
277
|
exports.default = result;
|
|
239
278
|
},
|
|
240
|
-
// async module loader — resolves directly via scope
|
|
279
|
+
// async module loader — resolves directly via scope.
|
|
280
|
+
//
|
|
281
|
+
// Upstream Turbopack's `asyncLoader` treats `require(id)` itself as the
|
|
282
|
+
// loader function (see `module.exports = loaderFn` set by the factory).
|
|
283
|
+
// remote-components additionally supports `{ default: loaderFn }`, which
|
|
284
|
+
// is what a factory using `ctx.s([['default', () => fn]], ...)` produces.
|
|
285
|
+
// Both shapes must be accepted: when `ctx.n(loaderFn, esmId)` injects a
|
|
286
|
+
// function directly into the cache, the require result is the function
|
|
287
|
+
// itself and there is no `.default` to dereference.
|
|
241
288
|
async A(Aid) {
|
|
242
289
|
const mod = scopedRequire(Aid);
|
|
243
|
-
|
|
290
|
+
const loader = typeof mod === "function" ? mod : mod?.default;
|
|
291
|
+
if (typeof loader !== "function") {
|
|
292
|
+
throw new Error(
|
|
293
|
+
`Async module loader for "${Aid}" is not a function (got ${typeof loader})`
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
return loader((parentId) => scopedRequire(parentId));
|
|
244
297
|
},
|
|
245
298
|
// dynamic import tracking — no-op for remote components
|
|
246
299
|
j() {
|
|
@@ -264,6 +317,16 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
|
|
|
264
317
|
`Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
|
|
265
318
|
);
|
|
266
319
|
},
|
|
320
|
+
// resolveAbsolutePath — Turbopack uses this to construct file:// URLs
|
|
321
|
+
// for source-map and debug output. Browser context has no real
|
|
322
|
+
// filesystem path; passing the input through unchanged keeps the
|
|
323
|
+
// surface satisfied without inventing values.
|
|
324
|
+
P(path) {
|
|
325
|
+
return path;
|
|
326
|
+
},
|
|
327
|
+
// relativeURL constructor — see RelativeURL function declaration above
|
|
328
|
+
// for the constructor-vs-method-shorthand explanation.
|
|
329
|
+
U: RelativeURL,
|
|
267
330
|
// globalThis substitute shared across all modules in this scope
|
|
268
331
|
g: scope.moduleGlobal,
|
|
269
332
|
m: moduleExports,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/module.ts"],"sourcesContent":["import { logDebug, logError } from '#internal/utils/logger';\nimport { loadChunkWithScope } from './chunk-loader';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\nimport { getSharedModule, getTurbopackModules } from './shared-modules';\n\n/**\n * Function signature for Turbopack module initializers.\n * These functions are generated by Turbopack and initialize module exports.\n */\nexport type TurbopackModuleInit = (\n turbopackContext: TurbopackContext,\n module: TurbopackModule,\n exports: Record<string, unknown>,\n) => void;\n\ninterface TurbopackHotModule {\n active: boolean;\n data: Record<string, unknown>;\n accept(): void;\n dispose(callback?: (data: Record<string, unknown>) => void): void;\n invalidate(): void;\n}\n\ninterface TurbopackModule {\n exports: Record<string, unknown>;\n hot: TurbopackHotModule;\n}\n\n/**\n * The context object passed to Turbopack module initializers.\n * This provides the runtime API that modules use for imports, exports, and HMR.\n */\ninterface TurbopackContext {\n /** HMR (Hot Module Replacement) - not implemented for remote components */\n k: {\n register(): void;\n registerExports(): void;\n signature(): (fn: unknown) => unknown;\n };\n /** ESM exports setup */\n s: (\n bindings:\n | Record<string, () => unknown>\n | [...([string, () => unknown] | [string, number, () => unknown])],\n esmId?: string | number,\n ) => void;\n /** Import module */\n i: (importId: string | number) => Record<string, unknown> | undefined;\n /** Require module */\n r: (requireId: string | number) => unknown;\n /** Value exports */\n v: (value: unknown) => void;\n /**\n * Export URL — used by static asset modules (images, fonts, JSON, etc.).\n * The entire body of a Turbopack asset module is a single `ctx.q(url)` call\n * that sets `module.exports` to the asset URL string.\n */\n q: (value: unknown, esmId?: string | number) => void;\n /** Async module initializer */\n a: (\n mod: (\n handleDeps: unknown,\n setResult: (value: unknown) => void,\n ) => Promise<void>,\n ) => Promise<void>;\n /** Async module loader */\n A: (Aid: string | number) => Promise<unknown>;\n /**\n * Dynamic import tracking. Called in production chunks after ctx.s() to\n * register async/dynamic module relationships. e.g. t.j(importedMod, 58790)\n */\n j: (module: unknown, esmId?: string | number) => void;\n /** Chunk loader */\n l: (url: string) => Promise<unknown> | undefined;\n /** Global object for this bundle */\n g: unknown;\n /** Module object */\n m: TurbopackModule;\n /** Exports object */\n e: Record<string, unknown>;\n}\n\n/**\n * Turbopack pushes chunks as flat arrays in one of two shapes:\n *\n * Module chunk (common case):\n * [scriptElement, id1, factory1, id2, factory2, ...]\n * - index 0: the script Element (document.currentScript) or undefined\n * - alternating pairs: numeric ID (prod) or path string (dev), then factory function\n *\n * Runtime manifest (bootstrapper only, no module factories):\n * [scriptElement, { otherChunks: [...], runtimeModuleIds: [...] }]\n *\n * Newer Next.js canary versions may also store modules as a plain object\n * { [moduleId]: factory } rather than as an array.\n */\ntype BundleModules =\n | (\n | Element\n | string\n | number\n | TurbopackModuleInit\n | Record<string, TurbopackModuleInit>\n | null\n | undefined\n )[]\n | Record<string, TurbopackModuleInit>\n | undefined;\n\n/**\n * Resolves a module within a scope: checks shared modules first, then\n * falls back to Turbopack module resolution. This is the scope-local\n * equivalent of the global __webpack_require__ dispatcher.\n */\nexport function requireModule(\n scope: RemoteScope,\n moduleId: string | number,\n fullId?: string,\n): unknown {\n const idStr = String(moduleId);\n\n // Shared modules are NOT cached in moduleCache because ctx.s() also\n // uses moduleCache for esmId lookups. Caching the host's frozen module\n // object here would cause ctx.s() to attempt Object.defineProperty on\n // it, failing with \"Cannot redefine property\" for non-configurable\n // exports. Keeping shared modules in their own map avoids the collision.\n //\n // Exact shared IDs must win over stale remote moduleCache entries. This is\n // a compatibility guard for the old shared-modules architecture, where a\n // remote chunk can instantiate a shared module before the broker has claimed\n // that ID. Delete this special ordering once all shared modules are resolved\n // through scope adapters before any remote factory can execute.\n const sharedModule = getSharedModule(scope, moduleId);\n if (sharedModule !== null) {\n if (scope.moduleCache[idStr]) {\n logDebug(\n 'TurbopackModule',\n `Shared module \"${idStr}\" resolved from host and overrides a cached remote copy in \"${scope.scopedName}\"`,\n );\n }\n return sharedModule;\n }\n\n // moduleCache is checked first inside handleTurbopackModule too, but\n // checking here keeps non-shared re-entry cheap.\n if (scope.moduleCache[idStr]) return scope.moduleCache[idStr];\n\n return handleTurbopackModule(\n scope,\n idStr,\n fullId ?? formatRemoteId(scope, idStr),\n );\n}\n\n/**\n * Handles Turbopack module resolution and execution.\n * Finds a module in the Turbopack bundle, executes its initializer with a\n * custom runtime context, and returns the module exports.\n */\nexport function handleTurbopackModule(\n scope: RemoteScope,\n moduleId: string,\n id: string,\n): unknown {\n // Cache check must come before module init lookup. Module initializers\n // re-enter handleTurbopackModule for their own imports, so without this\n // guard circular dependencies would infinite-loop.\n if (scope.moduleCache[moduleId]) {\n return scope.moduleCache[moduleId];\n }\n\n const modules = getTurbopackModules(scope) as BundleModules;\n\n // Log only if bundle is completely missing (critical error)\n if (!modules) {\n logError(\n 'TurbopackModule',\n `TURBOPACK_${scope.globalKey} is undefined (scope: \"${scope.scopedName}\")`,\n );\n }\n\n const moduleInit = findModuleInit(modules, moduleId);\n const exports = {} as Record<string, unknown>;\n const moduleExports = {\n exports,\n hot: createNoopHotModule(),\n };\n\n if (typeof moduleInit !== 'function') {\n throw new Error(\n `Module ${id} not found in bundle ${scope.name} with id ${moduleId}`,\n );\n }\n\n // store a reference to the module exports in the cache before execution\n // to handle circular dependencies\n scope.moduleCache[moduleId] = moduleExports.exports;\n\n // execute the module initializer with our custom Turbopack context\n moduleInit(\n createTurbopackContext(\n scope,\n exports,\n moduleExports,\n modules,\n moduleInit,\n id,\n ),\n moduleExports,\n exports,\n );\n\n // update the cache with the final exports (may have changed during execution)\n if (scope.moduleCache[moduleId] !== moduleExports.exports) {\n scope.moduleCache[moduleId] = moduleExports.exports;\n }\n\n return moduleExports.exports;\n}\n\n/**\n * Finds the module initializer function for a given ID in the Turbopack bundle.\n * Handles all bundle shapes: flat array, object map, nested arrays, and\n * embedded object entries within arrays. Performs exact match first, then\n * falls back to startsWith for dev-mode IDs with appended qualifiers.\n */\nexport function findModuleInit(\n modules: BundleModules | unknown[] | undefined,\n moduleId: string,\n): TurbopackModuleInit | undefined {\n if (!modules || typeof modules !== 'object') return;\n\n // Object format: { [id]: factory } (newer Next.js canary builds)\n if (!Array.isArray(modules)) {\n const key =\n moduleId in modules\n ? moduleId\n : Object.keys(modules).find((k) => k.startsWith(moduleId));\n return key !== undefined ? modules[key] : undefined;\n }\n\n const flat = modules.flat();\n\n // Two-pass ID search: exact match first to avoid prefix false positives.\n // The startsWith fallback handles dev-mode IDs with appended qualifiers\n // such as \"[project]/path.tsx [app-client] (ecmascript, async loader)\".\n let idx = flat.findIndex((e) => String(e) === String(moduleId));\n if (idx < 0) {\n idx = flat.findIndex(\n (e) => typeof e === 'string' && e.startsWith(moduleId),\n );\n }\n if (idx >= 0) {\n // Factory is the first function entry that follows the module ID\n return flat\n .slice(idx + 1)\n .find((e): e is TurbopackModuleInit => typeof e === 'function');\n }\n\n // Embedded object map: entries of the form { [moduleId]: factory }\n for (const entry of flat) {\n if (!entry || typeof entry !== 'object') continue;\n const obj = entry as Record<string, TurbopackModuleInit>;\n if (moduleId in obj) return obj[moduleId];\n const prefixKey = Object.keys(obj).find((k) => k.startsWith(moduleId));\n if (prefixKey) return obj[prefixKey];\n }\n return undefined;\n}\n\n/**\n * Creates the Turbopack context object that provides the runtime API for modules.\n * All context methods close over the scope directly — no global dispatch needed\n * for internal module-to-module calls.\n */\nfunction createTurbopackContext(\n scope: RemoteScope,\n exports: Record<string, unknown>,\n moduleExports: TurbopackModule,\n modules: BundleModules,\n moduleInit: TurbopackModuleInit,\n id: string,\n): TurbopackContext {\n /** Scope-local require: shared modules → turbopack module resolution. */\n const scopedRequire = (moduleId: string | number): unknown =>\n requireModule(scope, moduleId, formatRemoteId(scope, String(moduleId)));\n\n return {\n // HMR not implemented for Remote Components\n k: {\n register() {\n // omit\n },\n registerExports() {\n // omit\n },\n signature() {\n return (fn: unknown) => fn;\n },\n },\n\n // ESM exports setup\n s(\n bindings:\n | Record<string, () => unknown>\n | [...([string, () => unknown] | [string, number, () => unknown])],\n esmId?: string | number,\n ) {\n let mod = exports;\n if (typeof esmId === 'string' || typeof esmId === 'number') {\n if (!scope.moduleCache[esmId]) {\n scope.moduleCache[esmId] = {} as Record<string, unknown>;\n }\n mod = scope.moduleCache[esmId] as Record<string, unknown>;\n }\n\n Object.defineProperty(mod, '__esModule', { value: true });\n if (Array.isArray(bindings)) {\n let i = 0;\n while (i < bindings.length) {\n const propName = bindings[i++] as string;\n const tagOrFunc = bindings[i++];\n if (typeof tagOrFunc === 'number') {\n Object.defineProperty(mod, propName, {\n value: bindings[i++],\n enumerable: true,\n writable: false,\n });\n } else {\n const getterFn = tagOrFunc as () => unknown;\n if (typeof bindings[i] === 'function') {\n const setterFn = bindings[i++] as (v: unknown) => unknown;\n Object.defineProperty(mod, propName, {\n get: getterFn,\n set: setterFn,\n enumerable: true,\n });\n } else {\n Object.defineProperty(mod, propName, {\n get: getterFn,\n enumerable: true,\n });\n }\n }\n }\n }\n },\n\n // import — resolves directly via scope, no global dispatch\n i(importId: string | number) {\n let mod: Record<string, unknown> | undefined;\n if (typeof importId === 'string') {\n // parse export syntax if present (e.g., \"module <export foo as bar>\")\n const { exportSource, exportName } =\n /\\s+<export (?<exportSource>.*?) as (?<exportName>.*?)>$/.exec(\n importId,\n )?.groups ?? {};\n const normalizedId = importId.replace(\n /\\s+<export(?<specifier>.*)>$/,\n '',\n );\n mod = scopedRequire(normalizedId) as\n | Record<string, unknown>\n | undefined;\n // map the requested export to the module exports\n if (\n mod &&\n exportSource &&\n exportName &&\n (exportSource === '*' || typeof mod[exportSource] !== 'undefined') &&\n typeof mod[exportName] === 'undefined'\n ) {\n if (exportSource === '*') {\n mod[exportName] = mod;\n } else {\n mod[exportName] = mod[exportSource];\n }\n }\n } else {\n mod = scopedRequire(importId) as Record<string, unknown> | undefined;\n }\n\n if (typeof mod !== 'object' || mod === null) {\n mod = { default: mod };\n } else if (\n !('default' in mod) &&\n // ES module namespace objects have a null prototype, so calling\n // mod.toString() directly throws. Use Object.prototype.toString\n // to safely detect them.\n Object.prototype.toString.call(mod) !== '[object Module]'\n ) {\n try {\n mod.default = mod;\n } catch {\n // ignore if mod is not extensible\n }\n }\n return mod;\n },\n\n // require — resolves directly via scope\n r(requireId: string | number) {\n return scopedRequire(requireId);\n },\n\n // value exports\n v(value: unknown) {\n if (typeof value === 'function') {\n exports.default = value((vid: string | number) => scopedRequire(vid));\n } else {\n moduleExports.exports = value as Record<string, unknown>;\n }\n },\n\n // exportUrl — used by static asset modules (images, fonts, JSON, etc.).\n // Turbopack emits a tiny module whose entire body is ctx.q(url), which\n // sets module.exports to the asset URL string so importers get the URL\n // as the module's default export.\n q(value: unknown, esmId?: string | number) {\n if (esmId != null) {\n scope.moduleCache[String(esmId)] = value as Record<string, unknown>;\n } else {\n moduleExports.exports = value as Record<string, unknown>;\n }\n },\n\n // async module initializer\n async a(\n mod: (\n handleDeps: unknown,\n setResult: (value: unknown) => void,\n ) => Promise<void>,\n ) {\n let result;\n await mod(\n () => {\n // not implemented\n },\n (value) => (result = value),\n );\n exports.default = result;\n },\n\n // async module loader — resolves directly via scope\n async A(Aid: string | number) {\n const mod = scopedRequire(Aid) as {\n default: (\n parentImport: (parentId: string) => unknown,\n ) => Promise<unknown>;\n };\n return mod.default((parentId: string) => scopedRequire(parentId));\n },\n\n // dynamic import tracking — no-op for remote components\n j() {\n // omit\n },\n\n // chunk loader — loads directly via scope, no global dispatch\n l(url: string) {\n // find the script tag that loaded the current module to determine base URL\n const flatModules = Array.isArray(modules) ? modules : [];\n const moduleInitIndex = flatModules.indexOf(moduleInit);\n if (moduleInitIndex !== -1) {\n const scriptIndex = flatModules\n .slice(0, moduleInitIndex)\n .findLastIndex((bundleEntry) => bundleEntry instanceof Element);\n if (scriptIndex !== -1) {\n const script = flatModules[scriptIndex] as HTMLScriptElement;\n const scriptSrc = script.getAttribute('data-turbopack-src') || '';\n const nextIndex = scriptSrc.indexOf('/_next');\n const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : '';\n const chunkUrl = `${baseUrl}/_next/${url}`;\n return loadChunkWithScope(scope, formatRemoteId(scope, chunkUrl));\n }\n }\n throw new Error(\n `Failed to load Turbopack chunk \"${url}\" for module \"${id}\". Check the URL is correct.`,\n );\n },\n\n // globalThis substitute shared across all modules in this scope\n g: scope.moduleGlobal,\n m: moduleExports,\n e: exports,\n };\n}\n\nfunction createNoopHotModule(): TurbopackHotModule {\n // Remote Components does not implement HMR, but Next.js dev page-loader\n // modules still call module.hot.* when Turbopack emits Pages Router code.\n return {\n active: true,\n data: {},\n accept() {},\n dispose() {},\n invalidate() {},\n };\n}\n"],"mappings":";;;;;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K7B,aAAO,IAAI,QAAQ,CAAC,aAAqB,cAAc,QAAQ,CAAC;AAAA,IAClE;AAAA;AAAA,IAGA,IAAI;AAAA,IAEJ;AAAA;AAAA,IAGA,EAAE,KAAa;AAEb,YAAM,cAAc,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC;AACxD,YAAM,kBAAkB,YAAY,QAAQ,UAAU;AACtD,UAAI,oBAAoB,IAAI;AAC1B,cAAM,cAAc,YACjB,MAAM,GAAG,eAAe,EACxB,cAAc,CAAC,gBAAgB,uBAAuB,OAAO;AAChE,YAAI,gBAAgB,IAAI;AACtB,gBAAM,SAAS,YAAY,WAAW;AACtC,gBAAM,YAAY,OAAO,aAAa,oBAAoB,KAAK;AAC/D,gBAAM,YAAY,UAAU,QAAQ,QAAQ;AAC5C,gBAAM,UAAU,cAAc,KAAK,UAAU,MAAM,GAAG,SAAS,IAAI;AACnE,gBAAM,WAAW,GAAG,iBAAiB;AACrC,qBAAO,wCAAmB,WAAO,oCAAe,OAAO,QAAQ,CAAC;AAAA,QAClE;AAAA,MACF;AACA,YAAM,IAAI;AAAA,QACR,mCAAmC,oBAAoB;AAAA,MACzD;AAAA,IACF;AAAA;AAAA,IAGA,GAAG,MAAM;AAAA,IACT,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;AAEA,SAAS,sBAA0C;AAGjD,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,MAAM,CAAC;AAAA,IACP,SAAS;AAAA,IAAC;AAAA,IACV,UAAU;AAAA,IAAC;AAAA,IACX,aAAa;AAAA,IAAC;AAAA,EAChB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/module.ts"],"sourcesContent":["import { logDebug, logError } from '#internal/utils/logger';\nimport { loadChunkWithScope } from './chunk-loader';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\nimport { getSharedModule, getTurbopackModules } from './shared-modules';\n\n/**\n * Function signature for Turbopack module initializers.\n * These functions are generated by Turbopack and initialize module exports.\n */\nexport type TurbopackModuleInit = (\n turbopackContext: TurbopackContext,\n module: TurbopackModule,\n exports: Record<string, unknown>,\n) => void;\n\ninterface TurbopackHotModule {\n active: boolean;\n data: Record<string, unknown>;\n accept(): void;\n dispose(callback?: (data: Record<string, unknown>) => void): void;\n invalidate(): void;\n}\n\ninterface TurbopackModule {\n exports: Record<string, unknown>;\n hot: TurbopackHotModule;\n}\n\n/**\n * The context object passed to Turbopack module initializers.\n * This provides the runtime API that modules use for imports, exports, and HMR.\n */\ninterface TurbopackContext {\n /** HMR (Hot Module Replacement) - not implemented for remote components */\n k: {\n register(): void;\n registerExports(): void;\n signature(): (fn: unknown) => unknown;\n };\n /** ESM exports setup */\n s: (\n bindings:\n | Record<string, () => unknown>\n | [...([string, () => unknown] | [string, number, () => unknown])],\n esmId?: string | number,\n ) => void;\n /** Import module */\n i: (importId: string | number) => Record<string, unknown> | undefined;\n /** Require module */\n r: (requireId: string | number) => unknown;\n /** Value exports */\n v: (value: unknown) => void;\n /**\n * Export URL — used by static asset modules (images, fonts, JSON, etc.).\n * The entire body of a Turbopack asset module is a single `ctx.q(url)` call\n * that sets `module.exports` to the asset URL string.\n */\n q: (value: unknown, esmId?: string | number) => void;\n /**\n * Export namespace — used when Turbopack inlines a precomputed ESM\n * namespace object as the module's exports. Called as `ctx.n(namespace)`\n * for the current module, or `ctx.n(namespace, esmId)` to target another\n * cached module. Mirrors upstream Turbopack's `exportNamespace` helper.\n */\n n: (namespace: unknown, esmId?: string | number) => void;\n /** Async module initializer */\n a: (\n mod: (\n handleDeps: unknown,\n setResult: (value: unknown) => void,\n ) => Promise<void>,\n ) => Promise<void>;\n /** Async module loader */\n A: (Aid: string | number) => Promise<unknown>;\n /**\n * Dynamic import tracking. Called in production chunks after ctx.s() to\n * register async/dynamic module relationships. e.g. t.j(importedMod, 58790)\n */\n j: (module: unknown, esmId?: string | number) => void;\n /** Chunk loader */\n l: (url: string) => Promise<unknown> | undefined;\n /**\n * Resolve absolute path — Turbopack uses this when constructing source-\n * map and debug URLs (e.g. ``${`file://${ctx.P('rel/path')}`}``). Browser\n * context has no real filesystem path, so the polyfill passes the input\n * through unchanged.\n */\n P: (path: string) => string;\n /**\n * Relative URL constructor — invoked as `new ctx.U(input)` by code that\n * Turbopack compiles from `new URL(<rel>, import.meta.url)`. Must be a\n * real constructor (not method shorthand) so `new` works; prototype is\n * `URL.prototype` so `instanceof URL` holds on the result.\n */\n U: new (\n input: string,\n ) => URL;\n /** Global object for this bundle */\n g: unknown;\n /** Module object */\n m: TurbopackModule;\n /** Exports object */\n e: Record<string, unknown>;\n}\n\n/**\n * Relative URL constructor — mirrors Turbopack's `relativeURL` helper for\n * the source pattern `new URL('./asset', import.meta.url)`. Declared as a\n * named function expression (not method shorthand) so that `new ctx.U(...)`\n * works; method shorthand creates non-constructable functions that throw\n * `TypeError: ... is not a constructor` under `new`.\n *\n * The body mirrors upstream Turbopack byte-for-byte: take the input URL\n * relative to a synthetic base, copy URL fields onto `this` as plain\n * values, override `href`/`pathname`/`origin`/`protocol`/`toString`/`toJSON`\n * to preserve the original input as the canonical representation, and\n * inherit `URL.prototype` so `instanceof URL` holds.\n */\nfunction RelativeURL(this: URL, inputUrl: string): void {\n const realUrl = new URL(inputUrl, 'x:/');\n const values: Record<string, unknown> = {};\n for (const key in realUrl) {\n values[key] = (realUrl as unknown as Record<string, unknown>)[key];\n }\n values.href = inputUrl;\n values.pathname = inputUrl.replace(/[?#].*/, '');\n values.origin = '';\n values.protocol = '';\n values.toString = () => inputUrl;\n values.toJSON = () => inputUrl;\n for (const key in values) {\n Object.defineProperty(this, key, {\n enumerable: true,\n configurable: true,\n value: values[key],\n });\n }\n}\nRelativeURL.prototype = URL.prototype;\n\n/**\n * Turbopack pushes chunks as flat arrays in one of two shapes:\n *\n * Module chunk (common case):\n * [scriptElement, id1, factory1, id2, factory2, ...]\n * - index 0: the script Element (document.currentScript) or undefined\n * - alternating pairs: numeric ID (prod) or path string (dev), then factory function\n *\n * Runtime manifest (bootstrapper only, no module factories):\n * [scriptElement, { otherChunks: [...], runtimeModuleIds: [...] }]\n *\n * Newer Next.js canary versions may also store modules as a plain object\n * { [moduleId]: factory } rather than as an array.\n */\ntype BundleModules =\n | (\n | Element\n | string\n | number\n | TurbopackModuleInit\n | Record<string, TurbopackModuleInit>\n | null\n | undefined\n )[]\n | Record<string, TurbopackModuleInit>\n | undefined;\n\n/**\n * Resolves a module within a scope: checks shared modules first, then\n * falls back to Turbopack module resolution. This is the scope-local\n * equivalent of the global __webpack_require__ dispatcher.\n */\nexport function requireModule(\n scope: RemoteScope,\n moduleId: string | number,\n fullId?: string,\n): unknown {\n const idStr = String(moduleId);\n\n // Shared modules are NOT cached in moduleCache because ctx.s() also\n // uses moduleCache for esmId lookups. Caching the host's frozen module\n // object here would cause ctx.s() to attempt Object.defineProperty on\n // it, failing with \"Cannot redefine property\" for non-configurable\n // exports. Keeping shared modules in their own map avoids the collision.\n //\n // Exact shared IDs must win over stale remote moduleCache entries. This is\n // a compatibility guard for the old shared-modules architecture, where a\n // remote chunk can instantiate a shared module before the broker has claimed\n // that ID. Delete this special ordering once all shared modules are resolved\n // through scope adapters before any remote factory can execute.\n const sharedModule = getSharedModule(scope, moduleId);\n if (sharedModule !== null) {\n if (scope.moduleCache[idStr]) {\n logDebug(\n 'TurbopackModule',\n `Shared module \"${idStr}\" resolved from host and overrides a cached remote copy in \"${scope.scopedName}\"`,\n );\n }\n return sharedModule;\n }\n\n // moduleCache is checked first inside handleTurbopackModule too, but\n // checking here keeps non-shared re-entry cheap.\n if (scope.moduleCache[idStr]) return scope.moduleCache[idStr];\n\n return handleTurbopackModule(\n scope,\n idStr,\n fullId ?? formatRemoteId(scope, idStr),\n );\n}\n\n/**\n * Handles Turbopack module resolution and execution.\n * Finds a module in the Turbopack bundle, executes its initializer with a\n * custom runtime context, and returns the module exports.\n */\nexport function handleTurbopackModule(\n scope: RemoteScope,\n moduleId: string,\n id: string,\n): unknown {\n // Cache check must come before module init lookup. Module initializers\n // re-enter handleTurbopackModule for their own imports, so without this\n // guard circular dependencies would infinite-loop.\n if (scope.moduleCache[moduleId]) {\n return scope.moduleCache[moduleId];\n }\n\n const modules = getTurbopackModules(scope) as BundleModules;\n\n // Log only if bundle is completely missing (critical error)\n if (!modules) {\n logError(\n 'TurbopackModule',\n `TURBOPACK_${scope.globalKey} is undefined (scope: \"${scope.scopedName}\")`,\n );\n }\n\n const moduleInit = findModuleInit(modules, moduleId);\n const exports = {} as Record<string, unknown>;\n const moduleExports = {\n exports,\n hot: createNoopHotModule(),\n };\n\n if (typeof moduleInit !== 'function') {\n throw new Error(\n `Module ${id} not found in bundle ${scope.name} with id ${moduleId}`,\n );\n }\n\n // store a reference to the module exports in the cache before execution\n // to handle circular dependencies\n scope.moduleCache[moduleId] = moduleExports.exports;\n\n // execute the module initializer with our custom Turbopack context\n moduleInit(\n createTurbopackContext(\n scope,\n exports,\n moduleExports,\n modules,\n moduleInit,\n id,\n ),\n moduleExports,\n exports,\n );\n\n // update the cache with the final exports (may have changed during execution)\n if (scope.moduleCache[moduleId] !== moduleExports.exports) {\n scope.moduleCache[moduleId] = moduleExports.exports;\n }\n\n return moduleExports.exports;\n}\n\n/**\n * Finds the module initializer function for a given ID in the Turbopack bundle.\n * Handles all bundle shapes: flat array, object map, nested arrays, and\n * embedded object entries within arrays. Performs exact match first, then\n * falls back to startsWith for dev-mode IDs with appended qualifiers.\n */\nexport function findModuleInit(\n modules: BundleModules | unknown[] | undefined,\n moduleId: string,\n): TurbopackModuleInit | undefined {\n if (!modules || typeof modules !== 'object') return;\n\n // Object format: { [id]: factory } (newer Next.js canary builds)\n if (!Array.isArray(modules)) {\n const key =\n moduleId in modules\n ? moduleId\n : Object.keys(modules).find((k) => k.startsWith(moduleId));\n return key !== undefined ? modules[key] : undefined;\n }\n\n const flat = modules.flat();\n\n // Two-pass ID search: exact match first to avoid prefix false positives.\n // The startsWith fallback handles dev-mode IDs with appended qualifiers\n // such as \"[project]/path.tsx [app-client] (ecmascript, async loader)\".\n let idx = flat.findIndex((e) => String(e) === String(moduleId));\n if (idx < 0) {\n idx = flat.findIndex(\n (e) => typeof e === 'string' && e.startsWith(moduleId),\n );\n }\n if (idx >= 0) {\n // Factory is the first function entry that follows the module ID\n return flat\n .slice(idx + 1)\n .find((e): e is TurbopackModuleInit => typeof e === 'function');\n }\n\n // Embedded object map: entries of the form { [moduleId]: factory }\n for (const entry of flat) {\n if (!entry || typeof entry !== 'object') continue;\n const obj = entry as Record<string, TurbopackModuleInit>;\n if (moduleId in obj) return obj[moduleId];\n const prefixKey = Object.keys(obj).find((k) => k.startsWith(moduleId));\n if (prefixKey) return obj[prefixKey];\n }\n return undefined;\n}\n\n/**\n * Creates the Turbopack context object that provides the runtime API for modules.\n * All context methods close over the scope directly — no global dispatch needed\n * for internal module-to-module calls.\n */\nfunction createTurbopackContext(\n scope: RemoteScope,\n exports: Record<string, unknown>,\n moduleExports: TurbopackModule,\n modules: BundleModules,\n moduleInit: TurbopackModuleInit,\n id: string,\n): TurbopackContext {\n /** Scope-local require: shared modules → turbopack module resolution. */\n const scopedRequire = (moduleId: string | number): unknown =>\n requireModule(scope, moduleId, formatRemoteId(scope, String(moduleId)));\n\n return {\n // HMR not implemented for Remote Components\n k: {\n register() {\n // omit\n },\n registerExports() {\n // omit\n },\n signature() {\n return (fn: unknown) => fn;\n },\n },\n\n // ESM exports setup\n s(\n bindings:\n | Record<string, () => unknown>\n | [...([string, () => unknown] | [string, number, () => unknown])],\n esmId?: string | number,\n ) {\n let mod = exports;\n if (typeof esmId === 'string' || typeof esmId === 'number') {\n if (!scope.moduleCache[esmId]) {\n scope.moduleCache[esmId] = {} as Record<string, unknown>;\n }\n mod = scope.moduleCache[esmId] as Record<string, unknown>;\n }\n\n Object.defineProperty(mod, '__esModule', { value: true });\n if (Array.isArray(bindings)) {\n let i = 0;\n while (i < bindings.length) {\n const propName = bindings[i++] as string;\n const tagOrFunc = bindings[i++];\n if (typeof tagOrFunc === 'number') {\n Object.defineProperty(mod, propName, {\n value: bindings[i++],\n enumerable: true,\n writable: false,\n });\n } else {\n const getterFn = tagOrFunc as () => unknown;\n if (typeof bindings[i] === 'function') {\n const setterFn = bindings[i++] as (v: unknown) => unknown;\n Object.defineProperty(mod, propName, {\n get: getterFn,\n set: setterFn,\n enumerable: true,\n });\n } else {\n Object.defineProperty(mod, propName, {\n get: getterFn,\n enumerable: true,\n });\n }\n }\n }\n }\n },\n\n // import — resolves directly via scope, no global dispatch\n i(importId: string | number) {\n let mod: Record<string, unknown> | undefined;\n if (typeof importId === 'string') {\n // parse export syntax if present (e.g., \"module <export foo as bar>\")\n const { exportSource, exportName } =\n /\\s+<export (?<exportSource>.*?) as (?<exportName>.*?)>$/.exec(\n importId,\n )?.groups ?? {};\n const normalizedId = importId.replace(\n /\\s+<export(?<specifier>.*)>$/,\n '',\n );\n mod = scopedRequire(normalizedId) as\n | Record<string, unknown>\n | undefined;\n // map the requested export to the module exports\n if (\n mod &&\n exportSource &&\n exportName &&\n (exportSource === '*' || typeof mod[exportSource] !== 'undefined') &&\n typeof mod[exportName] === 'undefined'\n ) {\n if (exportSource === '*') {\n mod[exportName] = mod;\n } else {\n mod[exportName] = mod[exportSource];\n }\n }\n } else {\n mod = scopedRequire(importId) as Record<string, unknown> | undefined;\n }\n\n if (typeof mod !== 'object' || mod === null) {\n mod = { default: mod };\n } else if (\n !('default' in mod) &&\n // ES module namespace objects have a null prototype, so calling\n // mod.toString() directly throws. Use Object.prototype.toString\n // to safely detect them.\n Object.prototype.toString.call(mod) !== '[object Module]'\n ) {\n try {\n mod.default = mod;\n } catch {\n // ignore if mod is not extensible\n }\n }\n return mod;\n },\n\n // require — resolves directly via scope\n r(requireId: string | number) {\n return scopedRequire(requireId);\n },\n\n // exportValue — mirrors upstream Turbopack's `exportValue`, which sets\n // `module.exports = value` regardless of value type. Most importantly,\n // when Turbopack emits an async-loader module the body is\n // ctx.v((parentImport) => Promise.all([...]).then(() => parentImport(id)))\n // The function must be stored as-is so that the consumer's `ctx.A(id)`\n // can invoke it with the real parent-import resolver. Calling it eagerly\n // here (the prior remote-components behavior) ran the loader with the\n // wrong argument and stored a `Promise` as `exports.default`, which then\n // crashed `ctx.A` with `.default is not a function`.\n v(value: unknown) {\n moduleExports.exports = value as Record<string, unknown>;\n },\n\n // exportUrl — used by static asset modules (images, fonts, JSON, etc.).\n // Turbopack emits a tiny module whose entire body is ctx.q(url), which\n // sets module.exports to the asset URL string so importers get the URL\n // as the module's default export.\n q(value: unknown, esmId?: string | number) {\n if (esmId != null) {\n scope.moduleCache[String(esmId)] = value as Record<string, unknown>;\n } else {\n moduleExports.exports = value as Record<string, unknown>;\n }\n },\n\n // exportNamespace — Turbopack emits `ctx.n(namespace, esmId?)` when a\n // module's exports should be replaced wholesale with a precomputed ESM\n // namespace object (commonly at module evaluation time for re-export\n // patterns and CJS-to-ESM interop wrappers). Mirrors upstream\n // `exportNamespace` which sets both `module.exports` and\n // `module.namespaceObject`; remote-components keeps a single exports\n // record per module, so we assign to `exports` only.\n n(namespace: unknown, esmId?: string | number) {\n if (esmId != null) {\n scope.moduleCache[String(esmId)] = namespace as Record<string, unknown>;\n } else {\n moduleExports.exports = namespace as Record<string, unknown>;\n }\n },\n\n // async module initializer\n async a(\n mod: (\n handleDeps: unknown,\n setResult: (value: unknown) => void,\n ) => Promise<void>,\n ) {\n let result;\n await mod(\n () => {\n // not implemented\n },\n (value) => (result = value),\n );\n exports.default = result;\n },\n\n // async module loader — resolves directly via scope.\n //\n // Upstream Turbopack's `asyncLoader` treats `require(id)` itself as the\n // loader function (see `module.exports = loaderFn` set by the factory).\n // remote-components additionally supports `{ default: loaderFn }`, which\n // is what a factory using `ctx.s([['default', () => fn]], ...)` produces.\n // Both shapes must be accepted: when `ctx.n(loaderFn, esmId)` injects a\n // function directly into the cache, the require result is the function\n // itself and there is no `.default` to dereference.\n async A(Aid: string | number) {\n const mod = scopedRequire(Aid);\n const loader =\n typeof mod === 'function'\n ? (mod as (p: (id: string) => unknown) => Promise<unknown>)\n : ((mod as { default?: unknown } | null | undefined)?.default as\n | ((p: (id: string) => unknown) => Promise<unknown>)\n | undefined);\n if (typeof loader !== 'function') {\n throw new Error(\n `Async module loader for \"${Aid}\" is not a function (got ${typeof loader})`,\n );\n }\n return loader((parentId: string) => scopedRequire(parentId));\n },\n\n // dynamic import tracking — no-op for remote components\n j() {\n // omit\n },\n\n // chunk loader — loads directly via scope, no global dispatch\n l(url: string) {\n // find the script tag that loaded the current module to determine base URL\n const flatModules = Array.isArray(modules) ? modules : [];\n const moduleInitIndex = flatModules.indexOf(moduleInit);\n if (moduleInitIndex !== -1) {\n const scriptIndex = flatModules\n .slice(0, moduleInitIndex)\n .findLastIndex((bundleEntry) => bundleEntry instanceof Element);\n if (scriptIndex !== -1) {\n const script = flatModules[scriptIndex] as HTMLScriptElement;\n const scriptSrc = script.getAttribute('data-turbopack-src') || '';\n const nextIndex = scriptSrc.indexOf('/_next');\n const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : '';\n const chunkUrl = `${baseUrl}/_next/${url}`;\n return loadChunkWithScope(scope, formatRemoteId(scope, chunkUrl));\n }\n }\n throw new Error(\n `Failed to load Turbopack chunk \"${url}\" for module \"${id}\". Check the URL is correct.`,\n );\n },\n\n // resolveAbsolutePath — Turbopack uses this to construct file:// URLs\n // for source-map and debug output. Browser context has no real\n // filesystem path; passing the input through unchanged keeps the\n // surface satisfied without inventing values.\n P(path: string): string {\n return path;\n },\n\n // relativeURL constructor — see RelativeURL function declaration above\n // for the constructor-vs-method-shorthand explanation.\n U: RelativeURL as unknown as new (input: string) => URL,\n\n // globalThis substitute shared across all modules in this scope\n g: scope.moduleGlobal,\n m: moduleExports,\n e: exports,\n };\n}\n\nfunction createNoopHotModule(): TurbopackHotModule {\n // Remote Components does not implement HMR, but Next.js dev page-loader\n // modules still call module.hot.* when Turbopack emits Pages Router code.\n return {\n active: true,\n data: {},\n accept() {},\n dispose() {},\n invalidate() {},\n };\n}\n"],"mapp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,gBAAM,YAAY,OAAO,aAAa,oBAAoB,KAAK;AAC/D,gBAAM,YAAY,UAAU,QAAQ,QAAQ;AAC5C,gBAAM,UAAU,cAAc,KAAK,UAAU,MAAM,GAAG,SAAS,IAAI;AACnE,gBAAM,WAAW,GAAG,iBAAiB;AACrC,qBAAO,wCAAmB,WAAO,oCAAe,OAAO,QAAQ,CAAC;AAAA,QAClE;AAAA,MACF;AACA,YAAM,IAAI;AAAA,QACR,mCAAmC,oBAAoB;AAAA,MACzD;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,EAAE,MAAsB;AACtB,aAAO;AAAA,IACT;AAAA;AAAA;AAAA,IAIA,GAAG;AAAA;AAAA,IAGH,GAAG,MAAM;AAAA,IACT,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;AAEA,SAAS,sBAA0C;AAGjD,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,MAAM,CAAC;AAAA,IACP,SAAS;AAAA,IAAC;AAAA,IACV,UAAU;AAAA,IAAC;AAAA,IACX,aAAa;AAAA,IAAC;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -43,6 +43,13 @@ interface TurbopackContext {
|
|
|
43
43
|
* that sets `module.exports` to the asset URL string.
|
|
44
44
|
*/
|
|
45
45
|
q: (value: unknown, esmId?: string | number) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Export namespace — used when Turbopack inlines a precomputed ESM
|
|
48
|
+
* namespace object as the module's exports. Called as `ctx.n(namespace)`
|
|
49
|
+
* for the current module, or `ctx.n(namespace, esmId)` to target another
|
|
50
|
+
* cached module. Mirrors upstream Turbopack's `exportNamespace` helper.
|
|
51
|
+
*/
|
|
52
|
+
n: (namespace: unknown, esmId?: string | number) => void;
|
|
46
53
|
/** Async module initializer */
|
|
47
54
|
a: (mod: (handleDeps: unknown, setResult: (value: unknown) => void) => Promise<void>) => Promise<void>;
|
|
48
55
|
/** Async module loader */
|
|
@@ -54,6 +61,20 @@ interface TurbopackContext {
|
|
|
54
61
|
j: (module: unknown, esmId?: string | number) => void;
|
|
55
62
|
/** Chunk loader */
|
|
56
63
|
l: (url: string) => Promise<unknown> | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Resolve absolute path — Turbopack uses this when constructing source-
|
|
66
|
+
* map and debug URLs (e.g. ``${`file://${ctx.P('rel/path')}`}``). Browser
|
|
67
|
+
* context has no real filesystem path, so the polyfill passes the input
|
|
68
|
+
* through unchanged.
|
|
69
|
+
*/
|
|
70
|
+
P: (path: string) => string;
|
|
71
|
+
/**
|
|
72
|
+
* Relative URL constructor — invoked as `new ctx.U(input)` by code that
|
|
73
|
+
* Turbopack compiles from `new URL(<rel>, import.meta.url)`. Must be a
|
|
74
|
+
* real constructor (not method shorthand) so `new` works; prototype is
|
|
75
|
+
* `URL.prototype` so `instanceof URL` holds on the result.
|
|
76
|
+
*/
|
|
77
|
+
U: new (input: string) => URL;
|
|
57
78
|
/** Global object for this bundle */
|
|
58
79
|
g: unknown;
|
|
59
80
|
/** Module object */
|