remote-components 0.3.0 → 0.3.2
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/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js.map +1 -1
- package/dist/host/html.cjs +467 -395
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +467 -395
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +507 -447
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +515 -455
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/nextjs/app.cjs +5 -6
- package/dist/host/nextjs/app.cjs.map +1 -1
- package/dist/host/nextjs/app.js +5 -6
- package/dist/host/nextjs/app.js.map +1 -1
- package/dist/host/nextjs/pages.cjs +6 -11
- package/dist/host/nextjs/pages.cjs.map +1 -1
- package/dist/host/nextjs/pages.js +9 -11
- package/dist/host/nextjs/pages.js.map +1 -1
- package/dist/host/react.cjs +435 -374
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +435 -374
- package/dist/host/react.js.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.cjs +16 -7
- package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.d.ts +2 -2
- package/dist/internal/host/nextjs/dom-flight.js +16 -7
- package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
- package/dist/internal/host/nextjs/image-shared.cjs +2 -2
- package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-shared.js +2 -2
- package/dist/internal/host/nextjs/image-shared.js.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.cjs +183 -149
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +185 -149
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/shared/remote-image-loader.cjs +2 -5
- package/dist/internal/host/shared/remote-image-loader.cjs.map +1 -1
- package/dist/internal/host/shared/remote-image-loader.js +2 -5
- package/dist/internal/host/shared/remote-image-loader.js.map +1 -1
- package/dist/internal/runtime/constants.cjs +6 -6
- package/dist/internal/runtime/constants.cjs.map +1 -1
- package/dist/internal/runtime/constants.d.ts +3 -3
- package/dist/internal/runtime/constants.js +4 -4
- package/dist/internal/runtime/constants.js.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.cjs +11 -15
- package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.d.ts +2 -12
- package/dist/internal/runtime/html/parse-remote-html.js +17 -15
- package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.cjs +2 -2
- package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.js +1 -1
- package/dist/internal/runtime/loaders/script-loader.js.map +1 -1
- package/dist/internal/runtime/metadata.cjs +42 -0
- package/dist/internal/runtime/metadata.cjs.map +1 -1
- package/dist/internal/runtime/metadata.d.ts +21 -1
- package/dist/internal/runtime/metadata.js +38 -0
- package/dist/internal/runtime/metadata.js.map +1 -1
- package/dist/internal/runtime/patterns.cjs +38 -0
- package/dist/internal/runtime/patterns.cjs.map +1 -0
- package/dist/internal/runtime/patterns.d.ts +5 -0
- package/dist/internal/runtime/patterns.js +12 -0
- package/dist/internal/runtime/patterns.js.map +1 -0
- package/dist/internal/runtime/turbopack/chunk-loader.cjs +79 -128
- package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.d.ts +22 -7
- package/dist/internal/runtime/turbopack/chunk-loader.js +85 -131
- package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/module.cjs +56 -57
- package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/module.d.ts +14 -11
- package/dist/internal/runtime/turbopack/module.js +54 -56
- package/dist/internal/runtime/turbopack/module.js.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.cjs +101 -0
- package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -0
- package/dist/internal/runtime/turbopack/remote-scope.d.ts +55 -0
- package/dist/internal/runtime/turbopack/remote-scope.js +73 -0
- package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -0
- package/dist/internal/runtime/turbopack/shared-modules.cjs +62 -56
- package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.d.ts +7 -3
- package/dist/internal/runtime/turbopack/shared-modules.js +63 -57
- package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs +50 -31
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +5 -2
- package/dist/internal/runtime/turbopack/webpack-runtime.js +52 -34
- package/dist/internal/runtime/turbopack/webpack-runtime.js.map +1 -1
- package/dist/internal/runtime/types.cjs.map +1 -1
- package/dist/internal/runtime/types.d.ts +4 -3
- package/dist/internal/utils/logger.cjs.map +1 -1
- package/dist/internal/utils/logger.d.ts +1 -1
- package/dist/internal/utils/logger.js.map +1 -1
- package/dist/internal/utils.cjs +5 -0
- package/dist/internal/utils.cjs.map +1 -1
- package/dist/internal/utils.d.ts +15 -1
- package/dist/internal/utils.js +4 -0
- package/dist/internal/utils.js.map +1 -1
- package/dist/remote/html.cjs.map +1 -1
- package/dist/remote/html.js.map +1 -1
- package/dist/remote/nextjs/app.cjs +2 -1
- package/dist/remote/nextjs/app.cjs.map +1 -1
- package/dist/remote/nextjs/app.js +2 -1
- package/dist/remote/nextjs/app.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/module.ts"],"sourcesContent":["import { getBundleKey } from '#internal/runtime/constants';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { logError } from '#internal/utils/logger';\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: { exports: Record<string, unknown> },\n exports: Record<string, unknown>,\n) => void;\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) => unknown;\n /** Value exports */\n v: (value: unknown) => 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) => 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: { exports: Record<string, unknown> };\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 * Handles Turbopack module resolution and execution.\n * This function finds a module in the Turbopack bundle, executes its initializer,\n * and returns the module exports.\n *\n * The Turbopack bundle stores modules as arrays where each entry is either:\n * - A module ID (string or number)\n * - A module initializer function\n *\n * This function provides a custom runtime context that implements the Turbopack\n * module system API, enabling remote modules to resolve their dependencies.\n */\nexport function handleTurbopackModule(\n bundle: string,\n moduleId: string,\n id: string,\n): unknown {\n const self = globalThis as GlobalScope;\n const bundleKey = getBundleKey(bundle);\n const raw = self[`TURBOPACK_${bundleKey}`];\n\n // Normalize the bundle global to a flat entry list. The chunk-loader push\n // interceptor stores modules as { __chunks__: [[Element, id, fn, ...], ...] }.\n let modules: BundleModules;\n if (raw && typeof raw === 'object' && '__chunks__' in raw) {\n modules = (\n raw as { __chunks__: unknown[][] }\n ).__chunks__.flat() as unknown as BundleModules;\n } else if (Array.isArray(raw)) {\n modules = (raw as unknown[]).flat() as unknown as BundleModules;\n } else {\n modules = raw as BundleModules;\n }\n\n // prepare module cache to handle circular dependencies\n if (!self.__remote_components_turbopack_modules__) {\n self.__remote_components_turbopack_modules__ = {};\n }\n if (!self.__remote_components_turbopack_modules__[bundle]) {\n self.__remote_components_turbopack_modules__[bundle] = {};\n }\n // return cached module if already loaded (CRITICAL: check this FIRST)\n if (self.__remote_components_turbopack_modules__[bundle][moduleId]) {\n return self.__remote_components_turbopack_modules__[bundle][moduleId];\n }\n\n // Log only if bundle is completely missing (critical error)\n if (!modules) {\n logError('TurbopackModule', `TURBOPACK_${bundleKey} is undefined`);\n }\n\n const moduleInit = findModuleInit(modules, moduleId);\n const exports = {} as Record<string, unknown>;\n const moduleExports = { exports };\n\n if (typeof moduleInit !== 'function') {\n throw new Error(\n `Module ${id} not found in bundle ${bundle} 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 self.__remote_components_turbopack_modules__[bundle][moduleId] =\n moduleExports.exports;\n\n // prepare global object for the bundle\n if (!self.__remote_components_turbopack_global__) {\n self.__remote_components_turbopack_global__ = {};\n }\n if (!self.__remote_components_turbopack_global__[bundle]) {\n self.__remote_components_turbopack_global__[bundle] = {};\n }\n\n // execute the module initializer with our custom Turbopack context\n moduleInit(\n createTurbopackContext(\n bundle,\n exports,\n moduleExports,\n modules,\n moduleInit,\n id,\n self,\n ),\n moduleExports,\n exports,\n );\n\n // update the cache with the final exports (may have changed during execution)\n if (\n self.__remote_components_turbopack_modules__[bundle][moduleId] !==\n moduleExports.exports\n ) {\n self.__remote_components_turbopack_modules__[bundle][moduleId] =\n moduleExports.exports;\n }\n\n return moduleExports.exports;\n}\n\n/**\n * Finds the module initializer function in the Turbopack bundle.\n */\nfunction findModuleInit(\n modules: BundleModules,\n\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 return flat.find((e): e is Record<string, TurbopackModuleInit> =>\n Boolean(e && typeof e === 'object' && moduleId in (e as object)),\n )?.[moduleId];\n}\n\n/**\n * Creates the Turbopack context object that provides the runtime API for modules.\n */\nfunction createTurbopackContext(\n bundle: string,\n exports: Record<string, unknown>,\n moduleExports: { exports: Record<string, unknown> },\n modules: BundleModules,\n moduleInit: TurbopackModuleInit,\n id: string,\n self: GlobalScope,\n): TurbopackContext {\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 (!self.__remote_components_turbopack_modules__) {\n self.__remote_components_turbopack_modules__ = {};\n }\n if (!self.__remote_components_turbopack_modules__[bundle]) {\n self.__remote_components_turbopack_modules__[bundle] = {};\n }\n if (!self.__remote_components_turbopack_modules__[bundle][esmId]) {\n self.__remote_components_turbopack_modules__[bundle][esmId] =\n {} as Record<string, unknown>;\n }\n mod = self.__remote_components_turbopack_modules__[bundle][\n esmId\n ] 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\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 = self.__webpack_require__?.(`[${bundle}] ${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 = self.__webpack_require__?.(`[${bundle}] ${importId}`) as\n | Record<string, unknown>\n | undefined;\n }\n\n if (typeof mod !== 'object' || mod === null) {\n mod = { default: mod };\n } else if (!('default' in mod) && mod.toString() !== '[object Module]') {\n try {\n mod.default = mod;\n } catch {\n // ignore if mod is not extensible\n }\n }\n return mod;\n },\n\n // require\n r(requireId: string) {\n return self.__webpack_require__?.(`[${bundle}] ${requireId}`);\n },\n\n // value exports\n v(value: unknown) {\n if (typeof value === 'function') {\n exports.default = value((vid: string | number) => {\n return self.__webpack_require__?.(`[${bundle}] ${vid}`);\n });\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\n async A(Aid: string) {\n const mod = self.__webpack_require__?.(`[${bundle}] ${Aid}`) as {\n default: (\n parentImport: (parentId: string) => unknown,\n ) => Promise<unknown>;\n };\n return mod.default((parentId: string) =>\n self.__webpack_require__?.(`[${bundle}] ${parentId}`),\n );\n },\n\n // dynamic import tracking — no-op for remote components\n j() {\n // omit\n },\n\n // chunk loader\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 bundleUrl = `[${bundle}] ${baseUrl}/_next/${url}`;\n return self.__webpack_chunk_load__?.(bundleUrl, bundle);\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 // global object for this bundle\n g: self.__remote_components_turbopack_global__?.[bundle],\n m: moduleExports,\n e: exports,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA6B;AAE7B,oBAAyB;AAmGlB,SAAS,sBACd,QACA,UACA,IACS;AACT,QAAM,OAAO;AACb,QAAM,gBAAY,+BAAa,MAAM;AACrC,QAAM,MAAM,KAAK,aAAa,WAAW;AAIzC,MAAI;AACJ,MAAI,OAAO,OAAO,QAAQ,YAAY,gBAAgB,KAAK;AACzD,cACE,IACA,WAAW,KAAK;AAAA,EACpB,WAAW,MAAM,QAAQ,GAAG,GAAG;AAC7B,cAAW,IAAkB,KAAK;AAAA,EACpC,OAAO;AACL,cAAU;AAAA,EACZ;AAGA,MAAI,CAAC,KAAK,yCAAyC;AACjD,SAAK,0CAA0C,CAAC;AAAA,EAClD;AACA,MAAI,CAAC,KAAK,wCAAwC,MAAM,GAAG;AACzD,SAAK,wCAAwC,MAAM,IAAI,CAAC;AAAA,EAC1D;AAEA,MAAI,KAAK,wCAAwC,MAAM,EAAE,QAAQ,GAAG;AAClE,WAAO,KAAK,wCAAwC,MAAM,EAAE,QAAQ;AAAA,EACtE;AAGA,MAAI,CAAC,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M,IAAI;AAAA,QACR,mCAAmC,oBAAoB;AAAA,MACzD;AAAA,IACF;AAAA;AAAA,IAGA,GAAG,KAAK,yCAAyC,MAAM;AAAA,IACvD,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/module.ts"],"sourcesContent":["import type { GlobalScope } from '#internal/runtime/types';\nimport { logError } from '#internal/utils/logger';\nimport { loadChunkWithScope } from './chunk-loader';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\nimport { getSharedModule } 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: { exports: Record<string, unknown> },\n exports: Record<string, unknown>,\n) => void;\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) => unknown;\n /** Value exports */\n v: (value: unknown) => 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) => 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: { exports: Record<string, unknown> };\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 // moduleCache is checked first inside handleTurbopackModule too, but\n // checking here avoids the shared-module lookup on every re-entry.\n if (scope.moduleCache[idStr]) return scope.moduleCache[idStr];\n\n const sharedModule = getSharedModule(scope, moduleId);\n if (sharedModule) {\n // Cache the shared module so subsequent lookups for the same id\n // resolve from moduleCache without re-scanning sharedModules.\n scope.moduleCache[idStr] = sharedModule;\n return sharedModule;\n }\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 const self = globalThis as GlobalScope;\n\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 raw = self[`TURBOPACK_${scope.globalKey}`];\n\n // Normalize the bundle global to a flat entry list. The chunk-loader push\n // interceptor stores modules as { __chunks__: [[Element, id, fn, ...], ...] }.\n let modules: BundleModules;\n if (raw && typeof raw === 'object' && '__chunks__' in raw) {\n modules = (\n raw as { __chunks__: unknown[][] }\n ).__chunks__.flat() as unknown as BundleModules;\n } else if (Array.isArray(raw)) {\n modules = (raw as unknown[]).flat() as unknown as BundleModules;\n } else {\n modules = raw as BundleModules;\n }\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 = { exports };\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 in the Turbopack bundle.\n */\nfunction findModuleInit(\n modules: BundleModules,\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 return flat.find((e): e is Record<string, TurbopackModuleInit> =>\n Boolean(e && typeof e === 'object' && moduleId in (e as object)),\n )?.[moduleId];\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: { exports: Record<string, unknown> },\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 (!('default' in mod) && mod.toString() !== '[object Module]') {\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) {\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 // 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) {\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"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAyB;AACzB,0BAAmC;AACnC,0BAAiD;AACjD,4BAAgC;AA4FzB,SAAS,cACd,OACA,UACA,QACS;AACT,QAAM,QAAQ,OAAO,QAAQ;AAI7B,MAAI,MAAM,YAAY,KAAK;AAAG,WAAO,MAAM,YAAY,KAAK;AAE5D,QAAM,mBAAe,uCAAgB,OAAO,QAAQ;AACpD,MAAI,cAAc;AAGhB,UAAM,YAAY,KAAK,IAAI;AAC3B,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,cAAU,oCAAe,OAAO,KAAK;AAAA,EACvC;AACF;AAOO,SAAS,sBACd,OACA,UACA,IACS;AACT,QAAM,OAAO;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,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;","names":[]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { RemoteScope } from './remote-scope.js';
|
|
2
|
+
import '../url/resolve-client-url.js';
|
|
3
|
+
import '../constants.js';
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Function signature for Turbopack module initializers.
|
|
3
7
|
* These functions are generated by Turbopack and initialize module exports.
|
|
@@ -44,18 +48,17 @@ interface TurbopackContext {
|
|
|
44
48
|
/** Exports object */
|
|
45
49
|
e: Record<string, unknown>;
|
|
46
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolves a module within a scope: checks shared modules first, then
|
|
53
|
+
* falls back to Turbopack module resolution. This is the scope-local
|
|
54
|
+
* equivalent of the global __webpack_require__ dispatcher.
|
|
55
|
+
*/
|
|
56
|
+
declare function requireModule(scope: RemoteScope, moduleId: string | number, fullId?: string): unknown;
|
|
47
57
|
/**
|
|
48
58
|
* Handles Turbopack module resolution and execution.
|
|
49
|
-
*
|
|
50
|
-
* and returns the module exports.
|
|
51
|
-
*
|
|
52
|
-
* The Turbopack bundle stores modules as arrays where each entry is either:
|
|
53
|
-
* - A module ID (string or number)
|
|
54
|
-
* - A module initializer function
|
|
55
|
-
*
|
|
56
|
-
* This function provides a custom runtime context that implements the Turbopack
|
|
57
|
-
* module system API, enabling remote modules to resolve their dependencies.
|
|
59
|
+
* Finds a module in the Turbopack bundle, executes its initializer with a
|
|
60
|
+
* custom runtime context, and returns the module exports.
|
|
58
61
|
*/
|
|
59
|
-
declare function handleTurbopackModule(
|
|
62
|
+
declare function handleTurbopackModule(scope: RemoteScope, moduleId: string, id: string): unknown;
|
|
60
63
|
|
|
61
|
-
export { TurbopackModuleInit, handleTurbopackModule };
|
|
64
|
+
export { TurbopackModuleInit, handleTurbopackModule, requireModule };
|
|
@@ -1,9 +1,28 @@
|
|
|
1
|
-
import { getBundleKey } from "#internal/runtime/constants";
|
|
2
1
|
import { logError } from "#internal/utils/logger";
|
|
3
|
-
|
|
2
|
+
import { loadChunkWithScope } from "./chunk-loader";
|
|
3
|
+
import { formatRemoteId } from "./remote-scope";
|
|
4
|
+
import { getSharedModule } from "./shared-modules";
|
|
5
|
+
function requireModule(scope, moduleId, fullId) {
|
|
6
|
+
const idStr = String(moduleId);
|
|
7
|
+
if (scope.moduleCache[idStr])
|
|
8
|
+
return scope.moduleCache[idStr];
|
|
9
|
+
const sharedModule = getSharedModule(scope, moduleId);
|
|
10
|
+
if (sharedModule) {
|
|
11
|
+
scope.moduleCache[idStr] = sharedModule;
|
|
12
|
+
return sharedModule;
|
|
13
|
+
}
|
|
14
|
+
return handleTurbopackModule(
|
|
15
|
+
scope,
|
|
16
|
+
idStr,
|
|
17
|
+
fullId ?? formatRemoteId(scope, idStr)
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
function handleTurbopackModule(scope, moduleId, id) {
|
|
4
21
|
const self = globalThis;
|
|
5
|
-
|
|
6
|
-
|
|
22
|
+
if (scope.moduleCache[moduleId]) {
|
|
23
|
+
return scope.moduleCache[moduleId];
|
|
24
|
+
}
|
|
25
|
+
const raw = self[`TURBOPACK_${scope.globalKey}`];
|
|
7
26
|
let modules;
|
|
8
27
|
if (raw && typeof raw === "object" && "__chunks__" in raw) {
|
|
9
28
|
modules = raw.__chunks__.flat();
|
|
@@ -12,48 +31,35 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
12
31
|
} else {
|
|
13
32
|
modules = raw;
|
|
14
33
|
}
|
|
15
|
-
if (!self.__remote_components_turbopack_modules__) {
|
|
16
|
-
self.__remote_components_turbopack_modules__ = {};
|
|
17
|
-
}
|
|
18
|
-
if (!self.__remote_components_turbopack_modules__[bundle]) {
|
|
19
|
-
self.__remote_components_turbopack_modules__[bundle] = {};
|
|
20
|
-
}
|
|
21
|
-
if (self.__remote_components_turbopack_modules__[bundle][moduleId]) {
|
|
22
|
-
return self.__remote_components_turbopack_modules__[bundle][moduleId];
|
|
23
|
-
}
|
|
24
34
|
if (!modules) {
|
|
25
|
-
logError(
|
|
35
|
+
logError(
|
|
36
|
+
"TurbopackModule",
|
|
37
|
+
`TURBOPACK_${scope.globalKey} is undefined (scope: "${scope.scopedName}")`
|
|
38
|
+
);
|
|
26
39
|
}
|
|
27
40
|
const moduleInit = findModuleInit(modules, moduleId);
|
|
28
41
|
const exports = {};
|
|
29
42
|
const moduleExports = { exports };
|
|
30
43
|
if (typeof moduleInit !== "function") {
|
|
31
44
|
throw new Error(
|
|
32
|
-
`Module ${id} not found in bundle ${
|
|
45
|
+
`Module ${id} not found in bundle ${scope.name} with id ${moduleId}`
|
|
33
46
|
);
|
|
34
47
|
}
|
|
35
|
-
|
|
36
|
-
if (!self.__remote_components_turbopack_global__) {
|
|
37
|
-
self.__remote_components_turbopack_global__ = {};
|
|
38
|
-
}
|
|
39
|
-
if (!self.__remote_components_turbopack_global__[bundle]) {
|
|
40
|
-
self.__remote_components_turbopack_global__[bundle] = {};
|
|
41
|
-
}
|
|
48
|
+
scope.moduleCache[moduleId] = moduleExports.exports;
|
|
42
49
|
moduleInit(
|
|
43
50
|
createTurbopackContext(
|
|
44
|
-
|
|
51
|
+
scope,
|
|
45
52
|
exports,
|
|
46
53
|
moduleExports,
|
|
47
54
|
modules,
|
|
48
55
|
moduleInit,
|
|
49
|
-
id
|
|
50
|
-
self
|
|
56
|
+
id
|
|
51
57
|
),
|
|
52
58
|
moduleExports,
|
|
53
59
|
exports
|
|
54
60
|
);
|
|
55
|
-
if (
|
|
56
|
-
|
|
61
|
+
if (scope.moduleCache[moduleId] !== moduleExports.exports) {
|
|
62
|
+
scope.moduleCache[moduleId] = moduleExports.exports;
|
|
57
63
|
}
|
|
58
64
|
return moduleExports.exports;
|
|
59
65
|
}
|
|
@@ -78,7 +84,8 @@ function findModuleInit(modules, moduleId) {
|
|
|
78
84
|
(e) => Boolean(e && typeof e === "object" && moduleId in e)
|
|
79
85
|
)?.[moduleId];
|
|
80
86
|
}
|
|
81
|
-
function createTurbopackContext(
|
|
87
|
+
function createTurbopackContext(scope, exports, moduleExports, modules, moduleInit, id) {
|
|
88
|
+
const scopedRequire = (moduleId) => requireModule(scope, moduleId, formatRemoteId(scope, String(moduleId)));
|
|
82
89
|
return {
|
|
83
90
|
// HMR not implemented for Remote Components
|
|
84
91
|
k: {
|
|
@@ -94,16 +101,10 @@ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleI
|
|
|
94
101
|
s(bindings, esmId) {
|
|
95
102
|
let mod = exports;
|
|
96
103
|
if (typeof esmId === "string" || typeof esmId === "number") {
|
|
97
|
-
if (!
|
|
98
|
-
|
|
104
|
+
if (!scope.moduleCache[esmId]) {
|
|
105
|
+
scope.moduleCache[esmId] = {};
|
|
99
106
|
}
|
|
100
|
-
|
|
101
|
-
self.__remote_components_turbopack_modules__[bundle] = {};
|
|
102
|
-
}
|
|
103
|
-
if (!self.__remote_components_turbopack_modules__[bundle][esmId]) {
|
|
104
|
-
self.__remote_components_turbopack_modules__[bundle][esmId] = {};
|
|
105
|
-
}
|
|
106
|
-
mod = self.__remote_components_turbopack_modules__[bundle][esmId];
|
|
107
|
+
mod = scope.moduleCache[esmId];
|
|
107
108
|
}
|
|
108
109
|
Object.defineProperty(mod, "__esModule", { value: true });
|
|
109
110
|
if (Array.isArray(bindings)) {
|
|
@@ -136,7 +137,7 @@ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleI
|
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
},
|
|
139
|
-
// import
|
|
140
|
+
// import — resolves directly via scope, no global dispatch
|
|
140
141
|
i(importId) {
|
|
141
142
|
let mod;
|
|
142
143
|
if (typeof importId === "string") {
|
|
@@ -147,7 +148,7 @@ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleI
|
|
|
147
148
|
/\s+<export(?<specifier>.*)>$/,
|
|
148
149
|
""
|
|
149
150
|
);
|
|
150
|
-
mod =
|
|
151
|
+
mod = scopedRequire(normalizedId);
|
|
151
152
|
if (mod && exportSource && exportName && (exportSource === "*" || typeof mod[exportSource] !== "undefined") && typeof mod[exportName] === "undefined") {
|
|
152
153
|
if (exportSource === "*") {
|
|
153
154
|
mod[exportName] = mod;
|
|
@@ -156,7 +157,7 @@ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleI
|
|
|
156
157
|
}
|
|
157
158
|
}
|
|
158
159
|
} else {
|
|
159
|
-
mod =
|
|
160
|
+
mod = scopedRequire(importId);
|
|
160
161
|
}
|
|
161
162
|
if (typeof mod !== "object" || mod === null) {
|
|
162
163
|
mod = { default: mod };
|
|
@@ -168,16 +169,14 @@ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleI
|
|
|
168
169
|
}
|
|
169
170
|
return mod;
|
|
170
171
|
},
|
|
171
|
-
// require
|
|
172
|
+
// require — resolves directly via scope
|
|
172
173
|
r(requireId) {
|
|
173
|
-
return
|
|
174
|
+
return scopedRequire(requireId);
|
|
174
175
|
},
|
|
175
176
|
// value exports
|
|
176
177
|
v(value) {
|
|
177
178
|
if (typeof value === "function") {
|
|
178
|
-
exports.default = value((vid) =>
|
|
179
|
-
return self.__webpack_require__?.(`[${bundle}] ${vid}`);
|
|
180
|
-
});
|
|
179
|
+
exports.default = value((vid) => scopedRequire(vid));
|
|
181
180
|
} else {
|
|
182
181
|
moduleExports.exports = value;
|
|
183
182
|
}
|
|
@@ -192,17 +191,15 @@ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleI
|
|
|
192
191
|
);
|
|
193
192
|
exports.default = result;
|
|
194
193
|
},
|
|
195
|
-
// async module loader
|
|
194
|
+
// async module loader — resolves directly via scope
|
|
196
195
|
async A(Aid) {
|
|
197
|
-
const mod =
|
|
198
|
-
return mod.default(
|
|
199
|
-
(parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
|
|
200
|
-
);
|
|
196
|
+
const mod = scopedRequire(Aid);
|
|
197
|
+
return mod.default((parentId) => scopedRequire(parentId));
|
|
201
198
|
},
|
|
202
199
|
// dynamic import tracking — no-op for remote components
|
|
203
200
|
j() {
|
|
204
201
|
},
|
|
205
|
-
// chunk loader
|
|
202
|
+
// chunk loader — loads directly via scope, no global dispatch
|
|
206
203
|
l(url) {
|
|
207
204
|
const flatModules = Array.isArray(modules) ? modules : [];
|
|
208
205
|
const moduleInitIndex = flatModules.indexOf(moduleInit);
|
|
@@ -213,21 +210,22 @@ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleI
|
|
|
213
210
|
const scriptSrc = script.getAttribute("data-turbopack-src") || "";
|
|
214
211
|
const nextIndex = scriptSrc.indexOf("/_next");
|
|
215
212
|
const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
|
|
216
|
-
const
|
|
217
|
-
return
|
|
213
|
+
const chunkUrl = `${baseUrl}/_next/${url}`;
|
|
214
|
+
return loadChunkWithScope(scope, formatRemoteId(scope, chunkUrl));
|
|
218
215
|
}
|
|
219
216
|
}
|
|
220
217
|
throw new Error(
|
|
221
218
|
`Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
|
|
222
219
|
);
|
|
223
220
|
},
|
|
224
|
-
//
|
|
225
|
-
g:
|
|
221
|
+
// globalThis substitute shared across all modules in this scope
|
|
222
|
+
g: scope.moduleGlobal,
|
|
226
223
|
m: moduleExports,
|
|
227
224
|
e: exports
|
|
228
225
|
};
|
|
229
226
|
}
|
|
230
227
|
export {
|
|
231
|
-
handleTurbopackModule
|
|
228
|
+
handleTurbopackModule,
|
|
229
|
+
requireModule
|
|
232
230
|
};
|
|
233
231
|
//# sourceMappingURL=module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/module.ts"],"sourcesContent":["import { getBundleKey } from '#internal/runtime/constants';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { logError } from '#internal/utils/logger';\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: { exports: Record<string, unknown> },\n exports: Record<string, unknown>,\n) => void;\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) => unknown;\n /** Value exports */\n v: (value: unknown) => 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) => 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: { exports: Record<string, unknown> };\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 * Handles Turbopack module resolution and execution.\n * This function finds a module in the Turbopack bundle, executes its initializer,\n * and returns the module exports.\n *\n * The Turbopack bundle stores modules as arrays where each entry is either:\n * - A module ID (string or number)\n * - A module initializer function\n *\n * This function provides a custom runtime context that implements the Turbopack\n * module system API, enabling remote modules to resolve their dependencies.\n */\nexport function handleTurbopackModule(\n bundle: string,\n moduleId: string,\n id: string,\n): unknown {\n const self = globalThis as GlobalScope;\n const bundleKey = getBundleKey(bundle);\n const raw = self[`TURBOPACK_${bundleKey}`];\n\n // Normalize the bundle global to a flat entry list. The chunk-loader push\n // interceptor stores modules as { __chunks__: [[Element, id, fn, ...], ...] }.\n let modules: BundleModules;\n if (raw && typeof raw === 'object' && '__chunks__' in raw) {\n modules = (\n raw as { __chunks__: unknown[][] }\n ).__chunks__.flat() as unknown as BundleModules;\n } else if (Array.isArray(raw)) {\n modules = (raw as unknown[]).flat() as unknown as BundleModules;\n } else {\n modules = raw as BundleModules;\n }\n\n // prepare module cache to handle circular dependencies\n if (!self.__remote_components_turbopack_modules__) {\n self.__remote_components_turbopack_modules__ = {};\n }\n if (!self.__remote_components_turbopack_modules__[bundle]) {\n self.__remote_components_turbopack_modules__[bundle] = {};\n }\n // return cached module if already loaded (CRITICAL: check this FIRST)\n if (self.__remote_components_turbopack_modules__[bundle][moduleId]) {\n return self.__remote_components_turbopack_modules__[bundle][moduleId];\n }\n\n // Log only if bundle is completely missing (critical error)\n if (!modules) {\n logError('TurbopackModule', `TURBOPACK_${bundleKey} is undefined`);\n }\n\n const moduleInit = findModuleInit(modules, moduleId);\n const exports = {} as Record<string, unknown>;\n const moduleExports = { exports };\n\n if (typeof moduleInit !== 'function') {\n throw new Error(\n `Module ${id} not found in bundle ${bundle} 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 self.__remote_components_turbopack_modules__[bundle][moduleId] =\n moduleExports.exports;\n\n // prepare global object for the bundle\n if (!self.__remote_components_turbopack_global__) {\n self.__remote_components_turbopack_global__ = {};\n }\n if (!self.__remote_components_turbopack_global__[bundle]) {\n self.__remote_components_turbopack_global__[bundle] = {};\n }\n\n // execute the module initializer with our custom Turbopack context\n moduleInit(\n createTurbopackContext(\n bundle,\n exports,\n moduleExports,\n modules,\n moduleInit,\n id,\n self,\n ),\n moduleExports,\n exports,\n );\n\n // update the cache with the final exports (may have changed during execution)\n if (\n self.__remote_components_turbopack_modules__[bundle][moduleId] !==\n moduleExports.exports\n ) {\n self.__remote_components_turbopack_modules__[bundle][moduleId] =\n moduleExports.exports;\n }\n\n return moduleExports.exports;\n}\n\n/**\n * Finds the module initializer function in the Turbopack bundle.\n */\nfunction findModuleInit(\n modules: BundleModules,\n\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 return flat.find((e): e is Record<string, TurbopackModuleInit> =>\n Boolean(e && typeof e === 'object' && moduleId in (e as object)),\n )?.[moduleId];\n}\n\n/**\n * Creates the Turbopack context object that provides the runtime API for modules.\n */\nfunction createTurbopackContext(\n bundle: string,\n exports: Record<string, unknown>,\n moduleExports: { exports: Record<string, unknown> },\n modules: BundleModules,\n moduleInit: TurbopackModuleInit,\n id: string,\n self: GlobalScope,\n): TurbopackContext {\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 (!self.__remote_components_turbopack_modules__) {\n self.__remote_components_turbopack_modules__ = {};\n }\n if (!self.__remote_components_turbopack_modules__[bundle]) {\n self.__remote_components_turbopack_modules__[bundle] = {};\n }\n if (!self.__remote_components_turbopack_modules__[bundle][esmId]) {\n self.__remote_components_turbopack_modules__[bundle][esmId] =\n {} as Record<string, unknown>;\n }\n mod = self.__remote_components_turbopack_modules__[bundle][\n esmId\n ] 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\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 = self.__webpack_require__?.(`[${bundle}] ${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 = self.__webpack_require__?.(`[${bundle}] ${importId}`) as\n | Record<string, unknown>\n | undefined;\n }\n\n if (typeof mod !== 'object' || mod === null) {\n mod = { default: mod };\n } else if (!('default' in mod) && mod.toString() !== '[object Module]') {\n try {\n mod.default = mod;\n } catch {\n // ignore if mod is not extensible\n }\n }\n return mod;\n },\n\n // require\n r(requireId: string) {\n return self.__webpack_require__?.(`[${bundle}] ${requireId}`);\n },\n\n // value exports\n v(value: unknown) {\n if (typeof value === 'function') {\n exports.default = value((vid: string | number) => {\n return self.__webpack_require__?.(`[${bundle}] ${vid}`);\n });\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\n async A(Aid: string) {\n const mod = self.__webpack_require__?.(`[${bundle}] ${Aid}`) as {\n default: (\n parentImport: (parentId: string) => unknown,\n ) => Promise<unknown>;\n };\n return mod.default((parentId: string) =>\n self.__webpack_require__?.(`[${bundle}] ${parentId}`),\n );\n },\n\n // dynamic import tracking — no-op for remote components\n j() {\n // omit\n },\n\n // chunk loader\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 bundleUrl = `[${bundle}] ${baseUrl}/_next/${url}`;\n return self.__webpack_chunk_load__?.(bundleUrl, bundle);\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 // global object for this bundle\n g: self.__remote_components_turbopack_global__?.[bundle],\n m: moduleExports,\n e: exports,\n };\n}\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB;AAmGlB,SAAS,sBACd,QACA,UACA,IACS;AACT,QAAM,OAAO;AACb,QAAM,YAAY,aAAa,MAAM;AACrC,QAAM,MAAM,KAAK,aAAa,WAAW;AAIzC,MAAI;AACJ,MAAI,OAAO,OAAO,QAAQ,YAAY,gBAAgB,KAAK;AACzD,cACE,IACA,WAAW,KAAK;AAAA,EACpB,WAAW,MAAM,QAAQ,GAAG,GAAG;AAC7B,cAAW,IAAkB,KAAK;AAAA,EACpC,OAAO;AACL,cAAU;AAAA,EACZ;AAGA,MAAI,CAAC,KAAK,yCAAyC;AACjD,SAAK,0CAA0C,CAAC;AAAA,EAClD;AACA,MAAI,CAAC,KAAK,wCAAwC,MAAM,GAAG;AACzD,SAAK,wCAAwC,MAAM,IAAI,CAAC;AAAA,EAC1D;AAEA,MAAI,KAAK,wCAAwC,MAAM,EAAE,QAAQ,GAAG;AAClE,WAAO,KAAK,wCAAwC,MAAM,EAAE,QAAQ;AAAA,EACtE;AAGA,MAAI,CAAC,SAAS;AACZ,aAAS,mBAAmB,aAAa,wBAAwB;AAAA,EACnE;AAEA,QAAM,aAAa,eAAe,SAAS,QAAQ;AACnD,QAAM,UAAU,CAAC;AACjB,QAAM,gBAAgB,EAAE,QAAQ;AAEhC,MAAI,OAAO,eAAe,YAAY;AACpC,UAAM,IAAI;AAAA,MACR,UAAU,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ourcesContent":["import type { GlobalScope } from '#internal/runtime/types';\nimport { logError } from '#internal/utils/logger';\nimport { loadChunkWithScope } from './chunk-loader';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\nimport { getSharedModule } 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: { exports: Record<string, unknown> },\n exports: Record<string, unknown>,\n) => void;\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) => unknown;\n /** Value exports */\n v: (value: unknown) => 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) => 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: { exports: Record<string, unknown> };\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 // moduleCache is checked first inside handleTurbopackModule too, but\n // checking here avoids the shared-module lookup on every re-entry.\n if (scope.moduleCache[idStr]) return scope.moduleCache[idStr];\n\n const sharedModule = getSharedModule(scope, moduleId);\n if (sharedModule) {\n // Cache the shared module so subsequent lookups for the same id\n // resolve from moduleCache without re-scanning sharedModules.\n scope.moduleCache[idStr] = sharedModule;\n return sharedModule;\n }\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 const self = globalThis as GlobalScope;\n\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 raw = self[`TURBOPACK_${scope.globalKey}`];\n\n // Normalize the bundle global to a flat entry list. The chunk-loader push\n // interceptor stores modules as { __chunks__: [[Element, id, fn, ...], ...] }.\n let modules: BundleModules;\n if (raw && typeof raw === 'object' && '__chunks__' in raw) {\n modules = (\n raw as { __chunks__: unknown[][] }\n ).__chunks__.flat() as unknown as BundleModules;\n } else if (Array.isArray(raw)) {\n modules = (raw as unknown[]).flat() as unknown as BundleModules;\n } else {\n modules = raw as BundleModules;\n }\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 = { exports };\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 in the Turbopack bundle.\n */\nfunction findModuleInit(\n modules: BundleModules,\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 return flat.find((e): e is Record<string, TurbopackModuleInit> =>\n Boolean(e && typeof e === 'object' && moduleId in (e as object)),\n )?.[moduleId];\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: { exports: Record<string, unknown> },\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 (!('default' in mod) && mod.toString() !== '[object Module]') {\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) {\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 // 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) {\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"],"mappings":"AACA,SAAS,gBAAgB;AACzB,SAAS,0BAA0B;AACnC,SAAS,sBAAwC;AACjD,SAAS,uBAAuB;AA4FzB,SAAS,cACd,OACA,UACA,QACS;AACT,QAAM,QAAQ,OAAO,QAAQ;AAI7B,MAAI,MAAM,YAAY,KAAK;AAAG,WAAO,MAAM,YAAY,KAAK;AAE5D,QAAM,eAAe,gBAAgB,OAAO,QAAQ;AACpD,MAAI,cAAc;AAGhB,UAAM,YAAY,KAAK,IAAI;AAC3B,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,UAAU,eAAe,OAAO,KAAK;AAAA,EACvC;AACF;AAOO,SAAS,sBACd,OACA,UACA,IACS;AACT,QAAM,OAAO;AAKb,MAAI,MAAM,YAAY,QAAQ,GAAG;AAC/B,WAAO,MAAM,YAAY,QAAQ;AAAA,EACnC;AAEA,QAAM,MAAM,KAAK,aAAa,MAAM,WAAW;AAI/C,MAAI;AACJ,MAAI,OAAO,OAAO,QAAQ,YAAY,gBAAgB,KAAK;AACzD,cACE,IACA,WAAW,KAAK;AAAA,EACpB,WAAW,MAAM,QAAQ,GA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GA,MAAM,EACJ,KAIA;AACA,UAAI;AACJ,YAAM;AAAA,QACJ,MAAM;AAAA,QAEN;AAAA,QACA,CAAC,UAAW,SAAS;AAAA,MACvB;AACA,cAAQ,UAAU;AAAA,IACpB;AAAA;AAAA,IAGA,MAAM,EAAE,KAAa;AACnB,YAAM,MAAM,cAAc,GAAG;AAK7B,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,iBAAO,mBAAmB,OAAO,eAAe,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;","names":[]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var remote_scope_exports = {};
|
|
20
|
+
__export(remote_scope_exports, {
|
|
21
|
+
createScope: () => createScope,
|
|
22
|
+
formatRemoteId: () => formatRemoteId,
|
|
23
|
+
getScope: () => getScope,
|
|
24
|
+
parseRemoteId: () => parseRemoteId,
|
|
25
|
+
registerScope: () => registerScope
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(remote_scope_exports);
|
|
28
|
+
var import_constants = require("#internal/runtime/constants");
|
|
29
|
+
var import_patterns = require("#internal/runtime/patterns");
|
|
30
|
+
var import_utils = require("#internal/utils");
|
|
31
|
+
var import_logger = require("#internal/utils/logger");
|
|
32
|
+
function getRegistry() {
|
|
33
|
+
const self = globalThis;
|
|
34
|
+
if (!self.__remote_component_scopes__) {
|
|
35
|
+
self.__remote_component_scopes__ = /* @__PURE__ */ new Map();
|
|
36
|
+
}
|
|
37
|
+
return self.__remote_component_scopes__;
|
|
38
|
+
}
|
|
39
|
+
function createScope(name, url, runtime, resolveClientUrl) {
|
|
40
|
+
const isCrossOrigin = url.origin !== location.origin;
|
|
41
|
+
const scopedName = (0, import_utils.computeScopedName)(name, {
|
|
42
|
+
remoteHost: url.host,
|
|
43
|
+
isCrossOrigin
|
|
44
|
+
});
|
|
45
|
+
const globalKey = (0, import_constants.getBundleKey)(scopedName);
|
|
46
|
+
return {
|
|
47
|
+
name,
|
|
48
|
+
scopedName,
|
|
49
|
+
globalKey,
|
|
50
|
+
url,
|
|
51
|
+
runtime,
|
|
52
|
+
resolveClientUrl,
|
|
53
|
+
moduleCache: {},
|
|
54
|
+
sharedModules: {},
|
|
55
|
+
moduleGlobal: {}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function registerScope(scope) {
|
|
59
|
+
const registry = getRegistry();
|
|
60
|
+
registry.set(scope.scopedName, scope);
|
|
61
|
+
if (scope.scopedName !== scope.name) {
|
|
62
|
+
const existing = registry.get(scope.name);
|
|
63
|
+
if (existing && existing.scopedName !== scope.scopedName) {
|
|
64
|
+
(0, import_logger.logWarn)(
|
|
65
|
+
"RemoteScope",
|
|
66
|
+
`Plain name "${scope.name}" already registered by scope "${existing.scopedName}" \u2014 overwriting with "${scope.scopedName}". Static hosts will only resolve the latest one.`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
registry.set(scope.name, scope);
|
|
70
|
+
}
|
|
71
|
+
(0, import_logger.logDebug)(
|
|
72
|
+
"RemoteScope",
|
|
73
|
+
`Registered scope "${scope.scopedName}" (${registry.size} total)`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
function getScope(name) {
|
|
77
|
+
return getRegistry().get(name);
|
|
78
|
+
}
|
|
79
|
+
function formatRemoteId(scope, path) {
|
|
80
|
+
return `[${scope.scopedName}] ${path}`;
|
|
81
|
+
}
|
|
82
|
+
function parseRemoteId(id) {
|
|
83
|
+
const groups = import_patterns.REMOTE_COMPONENT_REGEX.exec(id)?.groups;
|
|
84
|
+
if (groups?.bundle && groups.id) {
|
|
85
|
+
return {
|
|
86
|
+
bundle: groups.bundle,
|
|
87
|
+
path: groups.id,
|
|
88
|
+
prefix: groups.prefix ?? ""
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return { bundle: "default", path: id, prefix: "" };
|
|
92
|
+
}
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
createScope,
|
|
96
|
+
formatRemoteId,
|
|
97
|
+
getScope,
|
|
98
|
+
parseRemoteId,
|
|
99
|
+
registerScope
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=remote-scope.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/remote-scope.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { getBundleKey, type Runtime } from '#internal/runtime/constants';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { computeScopedName } from '#internal/utils';\nimport { logDebug, logWarn } from '#internal/utils/logger';\n\n/**\n * Encapsulates all per-remote state so that two remotes sharing the same\n * bundle name but served from different origins never collide.\n *\n * A scope is created once per `setupWebpackRuntime` call and threaded\n * directly through internal code paths (chunk loading, module resolution,\n * shared modules). Global dispatchers (`__webpack_require__`,\n * `__webpack_chunk_load__`) only exist for external callers (RSC runtime)\n * and resolve the correct scope via the registry.\n */\nexport interface RemoteScope {\n /** Plain bundle name (e.g. \"remote-component-registry\") */\n name: string;\n /** Origin-qualified key — unique even when two remotes share a name */\n scopedName: string;\n /** Escaped key used as suffix for TURBOPACK_ globals */\n globalKey: string;\n /** Base URL for resolving relative chunk paths */\n url: URL;\n /** Bundler runtime type */\n runtime: Runtime;\n /** Proxy callback for routing chunks through the host */\n resolveClientUrl?: InternalResolveClientUrl;\n /** Per-scope cache of executed Turbopack module exports */\n moduleCache: Record<string, unknown>;\n /** Per-scope shared modules provided by the host (React, etc.) */\n sharedModules: Record<string, unknown>;\n /** Per-scope globalThis substitute passed to module initializers as `g` */\n moduleGlobal: Record<string, unknown>;\n}\n\nfunction getRegistry(): Map<string, RemoteScope> {\n const self = globalThis as GlobalScope;\n if (!self.__remote_component_scopes__) {\n self.__remote_component_scopes__ = new Map<string, unknown>();\n }\n return self.__remote_component_scopes__ as unknown as Map<\n string,\n RemoteScope\n >;\n}\n\nexport function createScope(\n name: string,\n url: URL,\n runtime: Runtime,\n resolveClientUrl?: InternalResolveClientUrl,\n): RemoteScope {\n const isCrossOrigin = url.origin !== location.origin;\n const scopedName = computeScopedName(name, {\n remoteHost: url.host,\n isCrossOrigin,\n });\n const globalKey = getBundleKey(scopedName);\n return {\n name,\n scopedName,\n globalKey,\n url,\n runtime,\n resolveClientUrl,\n moduleCache: {},\n sharedModules: {},\n moduleGlobal: {},\n };\n}\n\nexport function registerScope(scope: RemoteScope): void {\n const registry = getRegistry();\n registry.set(scope.scopedName, scope);\n\n // Also register under the plain name so hosts without server-side RSC\n // rewriting (static/HTML hosts) can look up cross-origin scopes by\n // the bundle name that appears in unrewritten chunk/module IDs.\n if (scope.scopedName !== scope.name) {\n const existing = registry.get(scope.name);\n if (existing && existing.scopedName !== scope.scopedName) {\n logWarn(\n 'RemoteScope',\n `Plain name \"${scope.name}\" already registered by scope \"${existing.scopedName}\" — ` +\n `overwriting with \"${scope.scopedName}\". Static hosts will only resolve the latest one.`,\n );\n }\n registry.set(scope.name, scope);\n }\n\n logDebug(\n 'RemoteScope',\n `Registered scope \"${scope.scopedName}\" (${registry.size} total)`,\n );\n}\n\n/**\n * Resolves a scope by name. Accepts either the scoped name (used by Next.js\n * hosts that rewrite RSC data server-side) or the plain bundle name (used by\n * static/HTML hosts where chunks arrive unrewritten).\n */\nexport function getScope(name: string): RemoteScope | undefined {\n return getRegistry().get(name);\n}\n\n/** Formats a `[scopedName] path` string for use in chunk/module IDs. */\nexport function formatRemoteId(scope: RemoteScope, path: string): string {\n return `[${scope.scopedName}] ${path}`;\n}\n\n/**\n * Parses the `[bundle] path` format used in chunk/module IDs.\n * Uses REMOTE_COMPONENT_REGEX (the same pattern used by the module dispatcher\n * and script loader) so the two parsing paths can never diverge.\n */\nexport function parseRemoteId(id: string): {\n bundle: string;\n path: string;\n prefix: string;\n} {\n const groups = REMOTE_COMPONENT_REGEX.exec(id)?.groups;\n if (groups?.bundle && groups.id) {\n return {\n bundle: groups.bundle,\n path: groups.id,\n prefix: groups.prefix ?? '',\n };\n }\n return { bundle: 'default', path: id, prefix: '' };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA2C;AAC3C,sBAAuC;AAEvC,mBAAkC;AAClC,oBAAkC;AAiClC,SAAS,cAAwC;AAC/C,QAAM,OAAO;AACb,MAAI,CAAC,KAAK,6BAA6B;AACrC,SAAK,8BAA8B,oBAAI,IAAqB;AAAA,EAC9D;AACA,SAAO,KAAK;AAId;AAEO,SAAS,YACd,MACA,KACA,SACA,kBACa;AACb,QAAM,gBAAgB,IAAI,WAAW,SAAS;AAC9C,QAAM,iBAAa,gCAAkB,MAAM;AAAA,IACzC,YAAY,IAAI;AAAA,IAChB;AAAA,EACF,CAAC;AACD,QAAM,gBAAY,+BAAa,UAAU;AACzC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa,CAAC;AAAA,IACd,eAAe,CAAC;AAAA,IAChB,cAAc,CAAC;AAAA,EACjB;AACF;AAEO,SAAS,cAAc,OAA0B;AACtD,QAAM,WAAW,YAAY;AAC7B,WAAS,IAAI,MAAM,YAAY,KAAK;AAKpC,MAAI,MAAM,eAAe,MAAM,MAAM;AACnC,UAAM,WAAW,SAAS,IAAI,MAAM,IAAI;AACxC,QAAI,YAAY,SAAS,eAAe,MAAM,YAAY;AACxD;AAAA,QACE;AAAA,QACA,eAAe,MAAM,sCAAsC,SAAS,wCAC7C,MAAM;AAAA,MAC/B;AAAA,IACF;AACA,aAAS,IAAI,MAAM,MAAM,KAAK;AAAA,EAChC;AAEA;AAAA,IACE;AAAA,IACA,qBAAqB,MAAM,gBAAgB,SAAS;AAAA,EACtD;AACF;AAOO,SAAS,SAAS,MAAuC;AAC9D,SAAO,YAAY,EAAE,IAAI,IAAI;AAC/B;AAGO,SAAS,eAAe,OAAoB,MAAsB;AACvE,SAAO,IAAI,MAAM,eAAe;AAClC;AAOO,SAAS,cAAc,IAI5B;AACA,QAAM,SAAS,uCAAuB,KAAK,EAAE,GAAG;AAChD,MAAI,QAAQ,UAAU,OAAO,IAAI;AAC/B,WAAO;AAAA,MACL,QAAQ,OAAO;AAAA,MACf,MAAM,OAAO;AAAA,MACb,QAAQ,OAAO,UAAU;AAAA,IAC3B;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,WAAW,MAAM,IAAI,QAAQ,GAAG;AACnD;","names":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { InternalResolveClientUrl } from '../url/resolve-client-url.js';
|
|
2
|
+
import { Runtime } from '../constants.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Encapsulates all per-remote state so that two remotes sharing the same
|
|
6
|
+
* bundle name but served from different origins never collide.
|
|
7
|
+
*
|
|
8
|
+
* A scope is created once per `setupWebpackRuntime` call and threaded
|
|
9
|
+
* directly through internal code paths (chunk loading, module resolution,
|
|
10
|
+
* shared modules). Global dispatchers (`__webpack_require__`,
|
|
11
|
+
* `__webpack_chunk_load__`) only exist for external callers (RSC runtime)
|
|
12
|
+
* and resolve the correct scope via the registry.
|
|
13
|
+
*/
|
|
14
|
+
interface RemoteScope {
|
|
15
|
+
/** Plain bundle name (e.g. "remote-component-registry") */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Origin-qualified key — unique even when two remotes share a name */
|
|
18
|
+
scopedName: string;
|
|
19
|
+
/** Escaped key used as suffix for TURBOPACK_ globals */
|
|
20
|
+
globalKey: string;
|
|
21
|
+
/** Base URL for resolving relative chunk paths */
|
|
22
|
+
url: URL;
|
|
23
|
+
/** Bundler runtime type */
|
|
24
|
+
runtime: Runtime;
|
|
25
|
+
/** Proxy callback for routing chunks through the host */
|
|
26
|
+
resolveClientUrl?: InternalResolveClientUrl;
|
|
27
|
+
/** Per-scope cache of executed Turbopack module exports */
|
|
28
|
+
moduleCache: Record<string, unknown>;
|
|
29
|
+
/** Per-scope shared modules provided by the host (React, etc.) */
|
|
30
|
+
sharedModules: Record<string, unknown>;
|
|
31
|
+
/** Per-scope globalThis substitute passed to module initializers as `g` */
|
|
32
|
+
moduleGlobal: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
declare function createScope(name: string, url: URL, runtime: Runtime, resolveClientUrl?: InternalResolveClientUrl): RemoteScope;
|
|
35
|
+
declare function registerScope(scope: RemoteScope): void;
|
|
36
|
+
/**
|
|
37
|
+
* Resolves a scope by name. Accepts either the scoped name (used by Next.js
|
|
38
|
+
* hosts that rewrite RSC data server-side) or the plain bundle name (used by
|
|
39
|
+
* static/HTML hosts where chunks arrive unrewritten).
|
|
40
|
+
*/
|
|
41
|
+
declare function getScope(name: string): RemoteScope | undefined;
|
|
42
|
+
/** Formats a `[scopedName] path` string for use in chunk/module IDs. */
|
|
43
|
+
declare function formatRemoteId(scope: RemoteScope, path: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Parses the `[bundle] path` format used in chunk/module IDs.
|
|
46
|
+
* Uses REMOTE_COMPONENT_REGEX (the same pattern used by the module dispatcher
|
|
47
|
+
* and script loader) so the two parsing paths can never diverge.
|
|
48
|
+
*/
|
|
49
|
+
declare function parseRemoteId(id: string): {
|
|
50
|
+
bundle: string;
|
|
51
|
+
path: string;
|
|
52
|
+
prefix: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { RemoteScope, createScope, formatRemoteId, getScope, parseRemoteId, registerScope };
|