remote-components 0.4.8 → 0.4.10
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-JZRA6DPE.js → chunk-3PR3SWYZ.js} +7 -54
- package/dist/chunk-3PR3SWYZ.js.map +1 -0
- package/dist/{chunk-I7VKDF3E.cjs → chunk-6PZEDIAK.cjs} +5 -52
- package/dist/chunk-6PZEDIAK.cjs.map +1 -0
- package/dist/{chunk-FF4SXSSG.js → chunk-GR5FN73U.js} +3 -3
- package/dist/{chunk-EW5O3Q24.cjs → chunk-HZP4FWPG.cjs} +23 -23
- package/dist/{chunk-EW5O3Q24.cjs.map → chunk-HZP4FWPG.cjs.map} +1 -1
- package/dist/{chunk-WGSS7TJP.js → chunk-M6ACTSVB.js} +2 -2
- package/dist/{chunk-VJO4PTWG.js → chunk-N6AJM72A.js} +6 -6
- package/dist/chunk-N6AJM72A.js.map +1 -0
- package/dist/{chunk-O4ED3BUP.cjs → chunk-OSSMJQFE.cjs} +19 -19
- package/dist/{chunk-YJJFRORQ.cjs → chunk-PCHSF5LH.cjs} +315 -74
- package/dist/chunk-PCHSF5LH.cjs.map +1 -0
- package/dist/{chunk-KCUEMMYL.js → chunk-RHRDUJ3K.js} +3 -3
- package/dist/{chunk-KAFPXSRI.cjs → chunk-RZ224NSH.cjs} +18 -18
- package/dist/{chunk-STMO56U2.js → chunk-VFK4HGZT.js} +264 -23
- package/dist/chunk-VFK4HGZT.js.map +1 -0
- package/dist/{chunk-4MLJE6UP.cjs → chunk-XWRB6CEA.cjs} +3 -3
- package/dist/config/nextjs.cjs +5 -5
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js +1 -1
- package/dist/config/nextjs.js.map +1 -1
- package/dist/host/html.cjs +19 -19
- package/dist/host/html.js +7 -7
- package/dist/host/nextjs/app/client-only.cjs +11 -11
- package/dist/host/nextjs/app/client-only.js +6 -6
- package/dist/host/nextjs/pages/client-only.cjs +42 -24
- package/dist/host/nextjs/pages/client-only.cjs.map +1 -1
- package/dist/host/nextjs/pages/client-only.d.ts +1 -1
- package/dist/host/nextjs/pages/client-only.js +42 -24
- package/dist/host/nextjs/pages/client-only.js.map +1 -1
- package/dist/host/react.cjs +7 -7
- package/dist/host/react.js +6 -6
- package/dist/internal/config/webpack/apply-shared-modules.cjs +8 -0
- package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -1
- package/dist/internal/config/webpack/apply-shared-modules.d.ts +6 -1
- package/dist/internal/config/webpack/apply-shared-modules.js +10 -0
- package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -1
- package/dist/internal/config/webpack/provider-adapter.cjs +85 -0
- package/dist/internal/config/webpack/provider-adapter.cjs.map +1 -0
- package/dist/internal/config/webpack/provider-adapter.d.ts +7 -0
- package/dist/internal/config/webpack/provider-adapter.js +64 -0
- package/dist/internal/config/webpack/provider-adapter.js.map +1 -0
- package/dist/internal/config/webpack/shared-module-resolver.cjs +73 -0
- package/dist/internal/config/webpack/shared-module-resolver.cjs.map +1 -0
- package/dist/internal/config/webpack/shared-module-resolver.d.ts +35 -0
- package/dist/internal/config/webpack/shared-module-resolver.js +50 -0
- package/dist/internal/config/webpack/shared-module-resolver.js.map +1 -0
- package/dist/internal/host/shared/provider.cjs +188 -0
- package/dist/internal/host/shared/provider.cjs.map +1 -0
- package/dist/internal/host/shared/provider.d.ts +71 -0
- package/dist/internal/host/shared/provider.js +161 -0
- package/dist/internal/host/shared/provider.js.map +1 -0
- package/dist/internal/host/shared/shared-broker.cjs +0 -30
- package/dist/internal/host/shared/shared-broker.cjs.map +1 -1
- package/dist/internal/host/shared/shared-broker.d.ts +1 -7
- package/dist/internal/host/shared/shared-broker.js +0 -29
- package/dist/internal/host/shared/shared-broker.js.map +1 -1
- package/dist/internal/host/shared/shared-module-resolver.cjs +7 -29
- package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -1
- package/dist/internal/host/shared/shared-module-resolver.d.ts +13 -34
- package/dist/internal/host/shared/shared-module-resolver.js +5 -29
- package/dist/internal/host/shared/shared-module-resolver.js.map +1 -1
- package/dist/internal/runtime/loaders/component-loader.cjs +3 -2
- package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/component-loader.js +2 -4
- package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.cjs +13 -19
- package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.js +17 -21
- package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
- package/dist/{turbopack-XDIGB4GI.js → turbopack-6BSS3SYN.js} +5 -5
- package/dist/turbopack-6BSS3SYN.js.map +1 -0
- package/dist/{turbopack-RXVSOWF7.cjs → turbopack-UMJ7SLJL.cjs} +12 -12
- package/dist/{turbopack-RXVSOWF7.cjs.map → turbopack-UMJ7SLJL.cjs.map} +1 -1
- package/dist/{webpack-3QXPAZN4.js → webpack-4QYGIVE6.js} +9 -7
- package/dist/webpack-4QYGIVE6.js.map +1 -0
- package/dist/{webpack-HKD7RZRE.cjs → webpack-65BVWX2U.cjs} +13 -11
- package/dist/webpack-65BVWX2U.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-I7VKDF3E.cjs.map +0 -1
- package/dist/chunk-JZRA6DPE.js.map +0 -1
- package/dist/chunk-STMO56U2.js.map +0 -1
- package/dist/chunk-VJO4PTWG.js.map +0 -1
- package/dist/chunk-YJJFRORQ.cjs.map +0 -1
- package/dist/turbopack-XDIGB4GI.js.map +0 -1
- package/dist/webpack-3QXPAZN4.js.map +0 -1
- package/dist/webpack-HKD7RZRE.cjs.map +0 -1
- /package/dist/{chunk-FF4SXSSG.js.map → chunk-GR5FN73U.js.map} +0 -0
- /package/dist/{chunk-WGSS7TJP.js.map → chunk-M6ACTSVB.js.map} +0 -0
- /package/dist/{chunk-O4ED3BUP.cjs.map → chunk-OSSMJQFE.cjs.map} +0 -0
- /package/dist/{chunk-KCUEMMYL.js.map → chunk-RHRDUJ3K.js.map} +0 -0
- /package/dist/{chunk-KAFPXSRI.cjs.map → chunk-RZ224NSH.cjs.map} +0 -0
- /package/dist/{chunk-4MLJE6UP.cjs.map → chunk-XWRB6CEA.cjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/shared-modules.ts"],"sourcesContent":["import {\n createSharedModulePlan,\n installSharedModulePlan,\n isSharedModuleManifest,\n type RemoteSharedModules,\n SHARED_MODULE_MANIFEST_PROTOCOL,\n type SharedModuleFactory,\n type SharedModuleManifest,\n} from '#internal/host/shared/shared-broker';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { findModuleInit, handleTurbopackModule, requireModule } from './module';\nimport {\n ASYNC_MODULE_CALLBACK_RE,\n ASYNC_MODULE_LOADER_RE,\n extractGroup,\n normalizeModuleId,\n REMOTE_SHARED_ASSIGNMENT_RE,\n REMOTE_SHARED_MARKER_RE,\n} from './patterns';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\n\nconst DEDUPLICATION_WARNING =\n 'This module will not be deduplicated — the remote may load its own copy, ' +\n 'which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).';\n// `asyncSharedModuleId` accepts: quoted string, integer, or integer in\n// scientific notation (e.g. `35e3`). Production minifiers occasionally\n// emit the scientific form; see normalizeModuleId() / MODULE_ID_PATTERN\n// in ./patterns.ts for the matching marker-extraction path.\nconst INLINE_REMOTE_SHARED_RE =\n /[\"']?__remote_shared_module_(?<specifier>[^\"':]+)[\"']?\\s*:\\s*\\(\\)\\s*=>\\s*(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>\"[^\"]+\"|[0-9]+e[0-9]+|[0-9]+)\\)/g;\n\n/**\n * Returns the flat module list for a scope.\n *\n * The primary source is `scope.turbopackModules` — a flat array populated by\n * the push interceptor in handleTurbopackChunk. This is immune to the\n * turbopack runtime replacing the TURBOPACK global (canary builds swap the\n * array for a deferred-loading dispatcher object).\n *\n * Falls back to reading the global for pre-populated bundles where the push\n * interceptor was never installed.\n */\nexport function getTurbopackModules(scope: RemoteScope): unknown[] | undefined {\n if (scope.turbopackModules.length > 0) {\n return scope.turbopackModules;\n }\n\n // Fallback: read the global for pre-populated bundles or legacy setups.\n const self = globalThis as GlobalScope;\n const raw = self[`TURBOPACK_${scope.globalKey}`];\n if (!raw) return undefined;\n\n if (Array.isArray(raw)) {\n return (raw as unknown[]).flat();\n }\n return Object.entries(raw as Record<string, unknown>).flat();\n}\n\n/**\n * Initializes shared modules between the host application and remote components.\n * This enables sharing of common dependencies like React to avoid duplicate instances.\n *\n * The function works by:\n * 1. Looking for a shared module initializer in the Turbopack bundle\n * 2. Extracting module IDs from the initializer\n * 3. Loading the corresponding host modules and mapping them to the remote's expected IDs\n */\nexport async function initializeSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory> = {},\n remoteShared: RemoteSharedModules = {},\n // biome-ignore lint/suspicious/noConfusingVoidType: Runtime is undefined but in TS land service it is void\n): Promise<void[]> {\n const allModules = getTurbopackModules(scope);\n\n logDebug(\n 'SharedModules',\n `initializeSharedModules: scope=\"${scope.scopedName}\", ` +\n `allModules=${allModules ? allModules.length : 'null'}, ` +\n `hostShared=[${Object.keys(hostShared).join(', ')}], ` +\n `remoteShared=${JSON.stringify(remoteShared)}`,\n );\n\n let sharedModuleInitializer: Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }> | null = null;\n\n // find the shared module initializer in the Turbopack bundle\n if (allModules) {\n // find the shared module initializer module id by looking for\n // a function that contains the TURBOPACK_REMOTE_SHARED pattern\n const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {\n if (typeof idOrFunc !== 'function') {\n return false;\n }\n const funcCode = idOrFunc.toString();\n return REMOTE_SHARED_MARKER_RE.test(funcCode);\n });\n\n // if found, extract the shared module initializer\n // first element in the array is always the source script element\n if (sharedModuleInitializerIndex > 0) {\n const sharedModuleInitializerCode = (\n allModules[sharedModuleInitializerIndex] as () => unknown\n ).toString();\n const sharedModuleInitializerId = allModules[\n sharedModuleInitializerIndex - 1\n ] as string | number;\n // extract the shared module id from the function code\n const sharedModuleId = extractGroup(\n REMOTE_SHARED_ASSIGNMENT_RE,\n sharedModuleInitializerCode,\n 'sharedModuleId',\n );\n // Load the shared-module-initializer module. Turbopack emits its\n // factory body as\n // ctx.v((parentImport) => Promise.all([...]).then(() => parentImport(id)))\n // so `module.exports` IS the loader function (upstream `exportValue`\n // semantics). Earlier versions of remote-components' `ctx.v` eagerly\n // invoked the function and stored the resulting Promise on\n // `exports.default` — that shape is preserved here as a fallback for\n // bundles built against the old runtime, but the primary path now\n // invokes the loader explicitly with `requireModule` as the parent\n // import (the actual scope-bound require).\n if (sharedModuleId) {\n const moduleExports = handleTurbopackModule(\n scope,\n sharedModuleId,\n formatRemoteId(scope, String(sharedModuleInitializerId)),\n );\n type Loader = (\n parentImport: (id: string | number) => unknown,\n ) => Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n const loaderCandidate =\n typeof moduleExports === 'function'\n ? moduleExports\n : (moduleExports as { default?: unknown })?.default;\n if (typeof loaderCandidate === 'function') {\n sharedModuleInitializer = (loaderCandidate as Loader)((parentId) =>\n requireModule(scope, parentId),\n );\n } else if (\n loaderCandidate &&\n typeof (loaderCandidate as { then?: unknown }).then === 'function'\n ) {\n sharedModuleInitializer = loaderCandidate as Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n }\n }\n }\n\n // if we have a shared module initializer, load the shared modules from the host application\n if (sharedModuleInitializer) {\n const { shared } = await sharedModuleInitializer;\n // map shared module ids to their initializer functions\n const sharedModuleIds = extractSharedModuleIds(shared, scope);\n logDebug(\n 'SharedModules',\n `Resolved shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(sharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(sharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n const inlineSharedModuleIds = extractInlineSharedModuleIds(\n allModules,\n scope,\n );\n if (Object.keys(inlineSharedModuleIds).length > 0) {\n logDebug(\n 'SharedModules',\n `Resolved inline shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(inlineSharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(inlineSharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for inline ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n logWarn(\n 'SharedModules',\n `No shared module initializer found in bundle for scope=\"${scope.scopedName}\" — falling back to remoteShared mapping`,\n );\n } else {\n logWarn(\n 'SharedModules',\n `No TURBOPACK modules found for scope=\"${scope.scopedName}\" (TURBOPACK_${scope.globalKey} is empty)`,\n );\n }\n\n const normalizedRemoteShared =\n normalizeRemoteSharedForTurbopackFallback(remoteShared);\n return installSharedModules(\n scope,\n hostShared,\n normalizedRemoteShared,\n (_id, module) =>\n `Shared module \"${module}\" not found for \"${scope.name}\". ${DEDUPLICATION_WARNING}`,\n );\n}\n\n/**\n * Extracts shared module IDs from the shared module initializer functions.\n * This parses the minified Turbopack code to find the module ID mappings.\n */\nfunction extractSharedModuleIds(\n shared: Record<string, string | (() => Promise<unknown>)>,\n scope: RemoteScope,\n): Record<string, string> {\n return Object.entries(shared)\n .filter(([, value]) => typeof value === 'function')\n .reduce<Record<string, string>>((acc, [key, value]) => {\n const asyncSharedModuleId = extractGroup(\n ASYNC_MODULE_LOADER_RE,\n value.toString(),\n 'asyncSharedModuleId',\n );\n\n if (asyncSharedModuleId) {\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (asyncSharedModule) {\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n // map the shared module id to the actual module name\n acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(\n '__remote_shared_module_',\n '',\n );\n }\n }\n return acc;\n }, {});\n}\n\nfunction extractInlineSharedModuleIds(\n allModules: unknown[],\n scope: RemoteScope,\n): Record<string, string> {\n const sharedModuleIds: Record<string, string> = {};\n\n for (const idOrFunc of allModules) {\n if (typeof idOrFunc !== 'function') continue;\n\n const funcCode = idOrFunc.toString();\n if (!funcCode.includes('__remote_shared_module_')) continue;\n\n INLINE_REMOTE_SHARED_RE.lastIndex = 0;\n for (const match of funcCode.matchAll(INLINE_REMOTE_SHARED_RE)) {\n const specifier = match.groups?.specifier;\n const rawAsyncSharedModuleId = stripQuotes(\n match.groups?.asyncSharedModuleId,\n );\n const asyncSharedModuleId = rawAsyncSharedModuleId\n ? normalizeModuleId(rawAsyncSharedModuleId)\n : undefined;\n if (!specifier || !asyncSharedModuleId) continue;\n\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (!asyncSharedModule) continue;\n\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n sharedModuleIds[sharedModuleId ?? asyncSharedModuleId] = specifier;\n }\n }\n\n return sharedModuleIds;\n}\n\nfunction stripQuotes(value: string | undefined): string | undefined {\n if (value?.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\nfunction installSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory>,\n sharedModuleIds: RemoteSharedModules,\n missingMessage: (id: string, module: string) => string,\n): Promise<undefined[]> {\n const plan = createSharedModulePlan({\n bundle: scope.name,\n hostShared,\n remoteShared: sharedModuleIds,\n scope: `remote:${scope.scopedName}`,\n callerTag: 'SharedModules',\n });\n\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n // Compatibility with the old shared-modules architecture: a remote\n // factory may have already cached its own implementation for this ID.\n // The broker-owned scope.sharedModules entry must replace it. Remove\n // this cache cleanup once Turbopack remotes cannot execute shared\n // factories before the scoped share plan is installed.\n delete scope.moduleCache[entry.id];\n }\n }\n\n return installSharedModulePlan({\n plan,\n target: scope.sharedModules,\n callerTag: 'SharedModules',\n onMissing: (entry) => {\n logError('SharedModules', missingMessage(entry.id, entry.specifier));\n },\n }).then((results) => {\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n delete scope.moduleCache[entry.id];\n }\n }\n return results;\n });\n}\n\nfunction preferSharedManifest(\n sharedModuleIds: Record<string, string>,\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (!isSharedModuleManifest(remoteShared)) return sharedModuleIds;\n\n const extractedIdBySpecifier = new Map(\n Object.entries(sharedModuleIds).map(([id, specifier]) => [specifier, id]),\n );\n\n return {\n protocol: SHARED_MODULE_MANIFEST_PROTOCOL,\n requirements: remoteShared.requirements.map((requirement) => {\n return {\n ...requirement,\n id: extractedIdBySpecifier.get(requirement.specifier) ?? requirement.id,\n };\n }),\n };\n}\n\nfunction normalizeRemoteSharedForTurbopackFallback(\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (isSharedModuleManifest(remoteShared)) {\n return {\n ...remoteShared,\n requirements: remoteShared.requirements.map((requirement) => ({\n ...requirement,\n id:\n typeof requirement.id === 'string'\n ? requirement.id.replace('[app-ssr]', '[app-client]')\n : requirement.id,\n })),\n } satisfies SharedModuleManifest;\n }\n\n // @legacy(remote-components<=0.4.x): normalize server-side generated\n // Turbopack IDs from the historical shared map until 0.4.x remotes are\n // outside the compatibility window.\n return Object.fromEntries(\n Object.entries(remoteShared).map(([id, module]) => [\n id.replace('[app-ssr]', '[app-client]'),\n module,\n ]),\n );\n}\n\n/**\n * Returns a shared module for the given scope and module ID.\n * Shared modules are common dependencies like React that are provided by the host.\n */\nexport function getSharedModule(\n scope: RemoteScope,\n id: string | number,\n): unknown {\n const idStr = String(id);\n\n // Exact match first (covers both string and numeric IDs)\n if (scope.sharedModules[idStr] !== undefined) {\n return scope.sharedModules[idStr];\n }\n\n // Fallback: the id may be a bundle-prefixed string like \"[bundle] /react/index.js\"\n // or a Turbopack dev id like \"[project]/node_modules/react/index.js [client]\".\n // Only path-like keys use the dev-id qualifier match to avoid \"react\"\n // matching \"react-dom\".\n for (const [key, value] of Object.entries(scope.sharedModules)) {\n if (\n typeof value !== 'undefined' &&\n idStr !== key &&\n matchesSharedModuleKey(idStr, key)\n ) {\n return value;\n }\n }\n\n return null;\n}\n\nfunction matchesSharedModuleKey(id: string, key: string): boolean {\n if (id.endsWith(key)) return true;\n if (!key.includes('/') && !key.endsWith('.js')) return false;\n\n const index = id.lastIndexOf(key);\n if (index < 0) return false;\n\n const afterKey = id.slice(index + key.length);\n return /^\\s+(?:\\[[^\\]]+\\]\\s*)?(?:\\([^)]*\\))?$/.test(afterKey);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAQO;AAEP,oBAA4C;AAC5C,oBAAqE;AACrE,sBAOO;AACP,0BAAiD;AAEjD,MAAM,wBACJ;AAMF,MAAM,0BACJ;AAaK,SAAS,oBAAoB,OAA2C;AAC7E,MAAI,MAAM,iBAAiB,SAAS,GAAG;AACrC,WAAO,MAAM;AAAA,EACf;AAGA,QAAM,OAAO;AACb,QAAM,MAAM,KAAK,aAAa,MAAM,WAAW;AAC/C,MAAI,CAAC;AAAK,WAAO;AAEjB,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAQ,IAAkB,KAAK;AAAA,EACjC;AACA,SAAO,OAAO,QAAQ,GAA8B,EAAE,KAAK;AAC7D;AAWA,eAAsB,wBACpB,OACA,aAAkD,CAAC,GACnD,eAAoC,CAAC,GAEpB;AACjB,QAAM,aAAa,oBAAoB,KAAK;AAE5C;AAAA,IACE;AAAA,IACA,mCAAmC,MAAM,2BACzB,aAAa,WAAW,SAAS,u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aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,aAAa,GAAG;AAC9D,QACE,OAAO,UAAU,eACjB,UAAU,OACV,uBAAuB,OAAO,GAAG,GACjC;AACA,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,uBAAuB,IAAY,KAAsB;AAChE,MAAI,GAAG,SAAS,GAAG;AAAG,WAAO;AAC7B,MAAI,CAAC,IAAI,SAAS,GAAG,KAAK,CAAC,IAAI,SAAS,KAAK;AAAG,WAAO;AAEvD,QAAM,QAAQ,GAAG,YAAY,GAAG;AAChC,MAAI,QAAQ;AAAG,WAAO;AAEtB,QAAM,WAAW,GAAG,MAAM,QAAQ,IAAI,MAAM;AAC5C,SAAO,wCAAwC,KAAK,QAAQ;AAC9D;","names":["module"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/shared-modules.ts"],"sourcesContent":["import {\n buildSharedProviderPlan,\n getSharedProviderModule,\n installSharedProviderEntry,\n} from '#internal/host/shared/provider';\nimport {\n isSharedModuleManifest,\n type RemoteSharedModules,\n SHARED_MODULE_MANIFEST_PROTOCOL,\n type SharedModuleFactory,\n type SharedModuleManifest,\n} from '#internal/host/shared/shared-broker';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { findModuleInit, handleTurbopackModule, requireModule } from './module';\nimport {\n ASYNC_MODULE_CALLBACK_RE,\n ASYNC_MODULE_LOADER_RE,\n extractGroup,\n normalizeModuleId,\n REMOTE_SHARED_ASSIGNMENT_RE,\n REMOTE_SHARED_MARKER_RE,\n} from './patterns';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\n\nconst DEDUPLICATION_WARNING =\n 'This module will not be deduplicated — the remote may load its own copy, ' +\n 'which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).';\n// `asyncSharedModuleId` accepts: quoted string, integer, or integer in\n// scientific notation (e.g. `35e3`). Production minifiers occasionally\n// emit the scientific form; see normalizeModuleId() / MODULE_ID_PATTERN\n// in ./patterns.ts for the matching marker-extraction path.\nconst INLINE_REMOTE_SHARED_RE =\n /[\"']?__remote_shared_module_(?<specifier>[^\"':]+)[\"']?\\s*:\\s*\\(\\)\\s*=>\\s*(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>\"[^\"]+\"|[0-9]+e[0-9]+|[0-9]+)\\)/g;\n\n/**\n * Returns the flat module list for a scope.\n *\n * The primary source is `scope.turbopackModules` — a flat array populated by\n * the push interceptor in handleTurbopackChunk. This is immune to the\n * turbopack runtime replacing the TURBOPACK global (canary builds swap the\n * array for a deferred-loading dispatcher object).\n *\n * Falls back to reading the global for pre-populated bundles where the push\n * interceptor was never installed.\n */\nexport function getTurbopackModules(scope: RemoteScope): unknown[] | undefined {\n if (scope.turbopackModules.length > 0) {\n return scope.turbopackModules;\n }\n\n // Fallback: read the global for pre-populated bundles or legacy setups.\n const self = globalThis as GlobalScope;\n const raw = self[`TURBOPACK_${scope.globalKey}`];\n if (!raw) return undefined;\n\n if (Array.isArray(raw)) {\n return (raw as unknown[]).flat();\n }\n return Object.entries(raw as Record<string, unknown>).flat();\n}\n\n/**\n * Initializes shared modules between the host application and remote components.\n * This enables sharing of common dependencies like React to avoid duplicate instances.\n *\n * The function works by:\n * 1. Looking for a shared module initializer in the Turbopack bundle\n * 2. Extracting module IDs from the initializer\n * 3. Loading the corresponding host modules and mapping them to the remote's expected IDs\n */\nexport async function initializeSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory> = {},\n remoteShared: RemoteSharedModules = {},\n // biome-ignore lint/suspicious/noConfusingVoidType: Runtime is undefined but in TS land service it is void\n): Promise<void[]> {\n const allModules = getTurbopackModules(scope);\n\n logDebug(\n 'SharedModules',\n `initializeSharedModules: scope=\"${scope.scopedName}\", ` +\n `allModules=${allModules ? allModules.length : 'null'}, ` +\n `hostShared=[${Object.keys(hostShared).join(', ')}], ` +\n `remoteShared=${JSON.stringify(remoteShared)}`,\n );\n\n let sharedModuleInitializer: Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }> | null = null;\n\n // find the shared module initializer in the Turbopack bundle\n if (allModules) {\n // find the shared module initializer module id by looking for\n // a function that contains the TURBOPACK_REMOTE_SHARED pattern\n const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {\n if (typeof idOrFunc !== 'function') {\n return false;\n }\n const funcCode = idOrFunc.toString();\n return REMOTE_SHARED_MARKER_RE.test(funcCode);\n });\n\n // if found, extract the shared module initializer\n // first element in the array is always the source script element\n if (sharedModuleInitializerIndex > 0) {\n const sharedModuleInitializerCode = (\n allModules[sharedModuleInitializerIndex] as () => unknown\n ).toString();\n const sharedModuleInitializerId = allModules[\n sharedModuleInitializerIndex - 1\n ] as string | number;\n // extract the shared module id from the function code\n const sharedModuleId = extractGroup(\n REMOTE_SHARED_ASSIGNMENT_RE,\n sharedModuleInitializerCode,\n 'sharedModuleId',\n );\n // Load the shared-module-initializer module. Turbopack emits its\n // factory body as\n // ctx.v((parentImport) => Promise.all([...]).then(() => parentImport(id)))\n // so `module.exports` IS the loader function (upstream `exportValue`\n // semantics). Earlier versions of remote-components' `ctx.v` eagerly\n // invoked the function and stored the resulting Promise on\n // `exports.default` — that shape is preserved here as a fallback for\n // bundles built against the old runtime, but the primary path now\n // invokes the loader explicitly with `requireModule` as the parent\n // import (the actual scope-bound require).\n if (sharedModuleId) {\n const moduleExports = handleTurbopackModule(\n scope,\n sharedModuleId,\n formatRemoteId(scope, String(sharedModuleInitializerId)),\n );\n type Loader = (\n parentImport: (id: string | number) => unknown,\n ) => Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n const loaderCandidate =\n typeof moduleExports === 'function'\n ? moduleExports\n : (moduleExports as { default?: unknown })?.default;\n if (typeof loaderCandidate === 'function') {\n sharedModuleInitializer = (loaderCandidate as Loader)((parentId) =>\n requireModule(scope, parentId),\n );\n } else if (\n loaderCandidate &&\n typeof (loaderCandidate as { then?: unknown }).then === 'function'\n ) {\n sharedModuleInitializer = loaderCandidate as Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n }\n }\n }\n\n // if we have a shared module initializer, load the shared modules from the host application\n if (sharedModuleInitializer) {\n const { shared } = await sharedModuleInitializer;\n // map shared module ids to their initializer functions\n const sharedModuleIds = extractSharedModuleIds(shared, scope);\n logDebug(\n 'SharedModules',\n `Resolved shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(sharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(sharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n const inlineSharedModuleIds = extractInlineSharedModuleIds(\n allModules,\n scope,\n );\n if (Object.keys(inlineSharedModuleIds).length > 0) {\n logDebug(\n 'SharedModules',\n `Resolved inline shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(inlineSharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(inlineSharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for inline ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n logWarn(\n 'SharedModules',\n `No shared module initializer found in bundle for scope=\"${scope.scopedName}\" — falling back to remoteShared mapping`,\n );\n } else {\n logWarn(\n 'SharedModules',\n `No TURBOPACK modules found for scope=\"${scope.scopedName}\" (TURBOPACK_${scope.globalKey} is empty)`,\n );\n }\n\n const normalizedRemoteShared =\n normalizeRemoteSharedForTurbopackFallback(remoteShared);\n return installSharedModules(\n scope,\n hostShared,\n normalizedRemoteShared,\n (_id, module) =>\n `Shared module \"${module}\" not found for \"${scope.name}\". ${DEDUPLICATION_WARNING}`,\n );\n}\n\n/**\n * Extracts shared module IDs from the shared module initializer functions.\n * This parses the minified Turbopack code to find the module ID mappings.\n */\nfunction extractSharedModuleIds(\n shared: Record<string, string | (() => Promise<unknown>)>,\n scope: RemoteScope,\n): Record<string, string> {\n return Object.entries(shared)\n .filter(([, value]) => typeof value === 'function')\n .reduce<Record<string, string>>((acc, [key, value]) => {\n const asyncSharedModuleId = extractGroup(\n ASYNC_MODULE_LOADER_RE,\n value.toString(),\n 'asyncSharedModuleId',\n );\n\n if (asyncSharedModuleId) {\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (asyncSharedModule) {\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n // map the shared module id to the actual module name\n acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(\n '__remote_shared_module_',\n '',\n );\n }\n }\n return acc;\n }, {});\n}\n\nfunction extractInlineSharedModuleIds(\n allModules: unknown[],\n scope: RemoteScope,\n): Record<string, string> {\n const sharedModuleIds: Record<string, string> = {};\n\n for (const idOrFunc of allModules) {\n if (typeof idOrFunc !== 'function') continue;\n\n const funcCode = idOrFunc.toString();\n if (!funcCode.includes('__remote_shared_module_')) continue;\n\n INLINE_REMOTE_SHARED_RE.lastIndex = 0;\n for (const match of funcCode.matchAll(INLINE_REMOTE_SHARED_RE)) {\n const specifier = match.groups?.specifier;\n const rawAsyncSharedModuleId = stripQuotes(\n match.groups?.asyncSharedModuleId,\n );\n const asyncSharedModuleId = rawAsyncSharedModuleId\n ? normalizeModuleId(rawAsyncSharedModuleId)\n : undefined;\n if (!specifier || !asyncSharedModuleId) continue;\n\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (!asyncSharedModule) continue;\n\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n sharedModuleIds[sharedModuleId ?? asyncSharedModuleId] = specifier;\n }\n }\n\n return sharedModuleIds;\n}\n\nfunction stripQuotes(value: string | undefined): string | undefined {\n if (value?.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\nfunction installSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory>,\n sharedModuleIds: RemoteSharedModules,\n missingMessage: (id: string, module: string) => string,\n): Promise<undefined[]> {\n return buildSharedProviderPlan({\n bundle: scope.name,\n hostShared,\n remoteShared: sharedModuleIds,\n scope: `remote:${scope.scopedName}`,\n callerTag: 'SharedModules',\n onMissing: (entry) => {\n logError('SharedModules', missingMessage(entry.id, entry.specifier));\n },\n }).then((results) =>\n results.entries.map((entry) => {\n installSharedProviderEntry(entry);\n scope.sharedModules[entry.id] = getSharedProviderModule({\n scope: entry.scope,\n specifier: entry.specifier,\n });\n // Compatibility with the old shared-modules architecture: a remote\n // factory may have already cached its own implementation for this ID.\n // The provider-owned scope.sharedModules entry must replace it. Remove\n // this cache cleanup once Turbopack remotes cannot execute shared\n // factories before the scoped provider plan is installed.\n delete scope.moduleCache[entry.id];\n return undefined;\n }),\n );\n}\n\nfunction preferSharedManifest(\n sharedModuleIds: Record<string, string>,\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (!isSharedModuleManifest(remoteShared)) return sharedModuleIds;\n\n const extractedIdBySpecifier = new Map(\n Object.entries(sharedModuleIds).map(([id, specifier]) => [specifier, id]),\n );\n\n return {\n protocol: SHARED_MODULE_MANIFEST_PROTOCOL,\n requirements: remoteShared.requirements.map((requirement) => {\n return {\n ...requirement,\n id: extractedIdBySpecifier.get(requirement.specifier) ?? requirement.id,\n };\n }),\n };\n}\n\nfunction normalizeRemoteSharedForTurbopackFallback(\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (isSharedModuleManifest(remoteShared)) {\n return {\n ...remoteShared,\n requirements: remoteShared.requirements.map((requirement) => ({\n ...requirement,\n id:\n typeof requirement.id === 'string'\n ? requirement.id.replace('[app-ssr]', '[app-client]')\n : requirement.id,\n })),\n } satisfies SharedModuleManifest;\n }\n\n // @legacy(remote-components<=0.4.x): normalize server-side generated\n // Turbopack IDs from the historical shared map until 0.4.x remotes are\n // outside the compatibility window.\n return Object.fromEntries(\n Object.entries(remoteShared).map(([id, module]) => [\n id.replace('[app-ssr]', '[app-client]'),\n module,\n ]),\n );\n}\n\n/**\n * Returns a shared module for the given scope and module ID.\n * Shared modules are common dependencies like React that are provided by the host.\n */\nexport function getSharedModule(\n scope: RemoteScope,\n id: string | number,\n): unknown {\n const idStr = String(id);\n\n // Exact match first (covers both string and numeric IDs)\n if (scope.sharedModules[idStr] !== undefined) {\n return scope.sharedModules[idStr];\n }\n\n // Fallback: the id may be a bundle-prefixed string like \"[bundle] /react/index.js\"\n // or a Turbopack dev id like \"[project]/node_modules/react/index.js [client]\".\n // Only path-like keys use the dev-id qualifier match to avoid \"react\"\n // matching \"react-dom\".\n for (const [key, value] of Object.entries(scope.sharedModules)) {\n if (\n typeof value !== 'undefined' &&\n idStr !== key &&\n matchesSharedModuleKey(idStr, key)\n ) {\n return value;\n }\n }\n\n return null;\n}\n\nfunction matchesSharedModuleKey(id: string, key: string): boolean {\n if (id.endsWith(key)) return true;\n if (!key.includes('/') && !key.endsWith('.js')) return false;\n\n const index = id.lastIndexOf(key);\n if (index < 0) return false;\n\n const afterKey = id.slice(index + key.length);\n return /^\\s+(?:\\[[^\\]]+\\]\\s*)?(?:\\([^)]*\\))?$/.test(afterKey);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAIO;AACP,2BAMO;AAEP,oBAA4C;AAC5C,oBAAqE;AACrE,sBAOO;AACP,0BAAiD;AAEjD,MAAM,wBACJ;AAMF,MAAM,0BACJ;AAaK,SAAS,oBAAoB,OAA2C;AAC7E,MAAI,MAAM,iBAAiB,SAAS,GAAG;AACrC,WAAO,MAAM;AAAA,EACf;AAGA,QAAM,OAAO;AACb,QAAM,MAAM,KAAK,aAAa,MAAM,WAAW;AAC/C,MAAI,CAAC;AAAK,WAAO;AA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,CAAC;AAAA,EACH;AACF;AAMO,SAAS,gBACd,OACA,IACS;AACT,QAAM,QAAQ,OAAO,EAAE;AAGvB,MAAI,MAAM,cAAc,KAAK,MAAM,QAAW;AAC5C,WAAO,MAAM,cAAc,KAAK;AAAA,EAClC;AAMA,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,aAAa,GAAG;AAC9D,QACE,OAAO,UAAU,eACjB,UAAU,OACV,uBAAuB,OAAO,GAAG,GACjC;AACA,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,uBAAuB,IAAY,KAAsB;AAChE,MAAI,GAAG,SAAS,GAAG;AAAG,WAAO;AAC7B,MAAI,CAAC,IAAI,SAAS,GAAG,KAAK,CAAC,IAAI,SAAS,KAAK;AAAG,WAAO;AAEvD,QAAM,QAAQ,GAAG,YAAY,GAAG;AAChC,MAAI,QAAQ;AAAG,WAAO;AAEtB,QAAM,WAAW,GAAG,MAAM,QAAQ,IAAI,MAAM;AAC5C,SAAO,wCAAwC,KAAK,QAAQ;AAC9D;","names":["module"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
buildSharedProviderPlan,
|
|
3
|
+
getSharedProviderModule,
|
|
4
|
+
installSharedProviderEntry
|
|
5
|
+
} from "#internal/host/shared/provider";
|
|
6
|
+
import {
|
|
4
7
|
isSharedModuleManifest,
|
|
5
8
|
SHARED_MODULE_MANIFEST_PROTOCOL
|
|
6
9
|
} from "#internal/host/shared/shared-broker";
|
|
@@ -184,33 +187,26 @@ function stripQuotes(value) {
|
|
|
184
187
|
return value;
|
|
185
188
|
}
|
|
186
189
|
function installSharedModules(scope, hostShared, sharedModuleIds, missingMessage) {
|
|
187
|
-
|
|
190
|
+
return buildSharedProviderPlan({
|
|
188
191
|
bundle: scope.name,
|
|
189
192
|
hostShared,
|
|
190
193
|
remoteShared: sharedModuleIds,
|
|
191
194
|
scope: `remote:${scope.scopedName}`,
|
|
192
|
-
callerTag: "SharedModules"
|
|
193
|
-
});
|
|
194
|
-
for (const entry of plan.entries) {
|
|
195
|
-
if (entry.status === "resolved") {
|
|
196
|
-
delete scope.moduleCache[entry.id];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return installSharedModulePlan({
|
|
200
|
-
plan,
|
|
201
|
-
target: scope.sharedModules,
|
|
202
195
|
callerTag: "SharedModules",
|
|
203
196
|
onMissing: (entry) => {
|
|
204
197
|
logError("SharedModules", missingMessage(entry.id, entry.specifier));
|
|
205
198
|
}
|
|
206
|
-
}).then(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
199
|
+
}).then(
|
|
200
|
+
(results) => results.entries.map((entry) => {
|
|
201
|
+
installSharedProviderEntry(entry);
|
|
202
|
+
scope.sharedModules[entry.id] = getSharedProviderModule({
|
|
203
|
+
scope: entry.scope,
|
|
204
|
+
specifier: entry.specifier
|
|
205
|
+
});
|
|
206
|
+
delete scope.moduleCache[entry.id];
|
|
207
|
+
return void 0;
|
|
208
|
+
})
|
|
209
|
+
);
|
|
214
210
|
}
|
|
215
211
|
function preferSharedManifest(sharedModuleIds, remoteShared) {
|
|
216
212
|
if (!isSharedModuleManifest(remoteShared))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/shared-modules.ts"],"sourcesContent":["import {\n createSharedModulePlan,\n installSharedModulePlan,\n isSharedModuleManifest,\n type RemoteSharedModules,\n SHARED_MODULE_MANIFEST_PROTOCOL,\n type SharedModuleFactory,\n type SharedModuleManifest,\n} from '#internal/host/shared/shared-broker';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { findModuleInit, handleTurbopackModule, requireModule } from './module';\nimport {\n ASYNC_MODULE_CALLBACK_RE,\n ASYNC_MODULE_LOADER_RE,\n extractGroup,\n normalizeModuleId,\n REMOTE_SHARED_ASSIGNMENT_RE,\n REMOTE_SHARED_MARKER_RE,\n} from './patterns';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\n\nconst DEDUPLICATION_WARNING =\n 'This module will not be deduplicated — the remote may load its own copy, ' +\n 'which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).';\n// `asyncSharedModuleId` accepts: quoted string, integer, or integer in\n// scientific notation (e.g. `35e3`). Production minifiers occasionally\n// emit the scientific form; see normalizeModuleId() / MODULE_ID_PATTERN\n// in ./patterns.ts for the matching marker-extraction path.\nconst INLINE_REMOTE_SHARED_RE =\n /[\"']?__remote_shared_module_(?<specifier>[^\"':]+)[\"']?\\s*:\\s*\\(\\)\\s*=>\\s*(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>\"[^\"]+\"|[0-9]+e[0-9]+|[0-9]+)\\)/g;\n\n/**\n * Returns the flat module list for a scope.\n *\n * The primary source is `scope.turbopackModules` — a flat array populated by\n * the push interceptor in handleTurbopackChunk. This is immune to the\n * turbopack runtime replacing the TURBOPACK global (canary builds swap the\n * array for a deferred-loading dispatcher object).\n *\n * Falls back to reading the global for pre-populated bundles where the push\n * interceptor was never installed.\n */\nexport function getTurbopackModules(scope: RemoteScope): unknown[] | undefined {\n if (scope.turbopackModules.length > 0) {\n return scope.turbopackModules;\n }\n\n // Fallback: read the global for pre-populated bundles or legacy setups.\n const self = globalThis as GlobalScope;\n const raw = self[`TURBOPACK_${scope.globalKey}`];\n if (!raw) return undefined;\n\n if (Array.isArray(raw)) {\n return (raw as unknown[]).flat();\n }\n return Object.entries(raw as Record<string, unknown>).flat();\n}\n\n/**\n * Initializes shared modules between the host application and remote components.\n * This enables sharing of common dependencies like React to avoid duplicate instances.\n *\n * The function works by:\n * 1. Looking for a shared module initializer in the Turbopack bundle\n * 2. Extracting module IDs from the initializer\n * 3. Loading the corresponding host modules and mapping them to the remote's expected IDs\n */\nexport async function initializeSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory> = {},\n remoteShared: RemoteSharedModules = {},\n // biome-ignore lint/suspicious/noConfusingVoidType: Runtime is undefined but in TS land service it is void\n): Promise<void[]> {\n const allModules = getTurbopackModules(scope);\n\n logDebug(\n 'SharedModules',\n `initializeSharedModules: scope=\"${scope.scopedName}\", ` +\n `allModules=${allModules ? allModules.length : 'null'}, ` +\n `hostShared=[${Object.keys(hostShared).join(', ')}], ` +\n `remoteShared=${JSON.stringify(remoteShared)}`,\n );\n\n let sharedModuleInitializer: Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }> | null = null;\n\n // find the shared module initializer in the Turbopack bundle\n if (allModules) {\n // find the shared module initializer module id by looking for\n // a function that contains the TURBOPACK_REMOTE_SHARED pattern\n const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {\n if (typeof idOrFunc !== 'function') {\n return false;\n }\n const funcCode = idOrFunc.toString();\n return REMOTE_SHARED_MARKER_RE.test(funcCode);\n });\n\n // if found, extract the shared module initializer\n // first element in the array is always the source script element\n if (sharedModuleInitializerIndex > 0) {\n const sharedModuleInitializerCode = (\n allModules[sharedModuleInitializerIndex] as () => unknown\n ).toString();\n const sharedModuleInitializerId = allModules[\n sharedModuleInitializerIndex - 1\n ] as string | number;\n // extract the shared module id from the function code\n const sharedModuleId = extractGroup(\n REMOTE_SHARED_ASSIGNMENT_RE,\n sharedModuleInitializerCode,\n 'sharedModuleId',\n );\n // Load the shared-module-initializer module. Turbopack emits its\n // factory body as\n // ctx.v((parentImport) => Promise.all([...]).then(() => parentImport(id)))\n // so `module.exports` IS the loader function (upstream `exportValue`\n // semantics). Earlier versions of remote-components' `ctx.v` eagerly\n // invoked the function and stored the resulting Promise on\n // `exports.default` — that shape is preserved here as a fallback for\n // bundles built against the old runtime, but the primary path now\n // invokes the loader explicitly with `requireModule` as the parent\n // import (the actual scope-bound require).\n if (sharedModuleId) {\n const moduleExports = handleTurbopackModule(\n scope,\n sharedModuleId,\n formatRemoteId(scope, String(sharedModuleInitializerId)),\n );\n type Loader = (\n parentImport: (id: string | number) => unknown,\n ) => Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n const loaderCandidate =\n typeof moduleExports === 'function'\n ? moduleExports\n : (moduleExports as { default?: unknown })?.default;\n if (typeof loaderCandidate === 'function') {\n sharedModuleInitializer = (loaderCandidate as Loader)((parentId) =>\n requireModule(scope, parentId),\n );\n } else if (\n loaderCandidate &&\n typeof (loaderCandidate as { then?: unknown }).then === 'function'\n ) {\n sharedModuleInitializer = loaderCandidate as Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n }\n }\n }\n\n // if we have a shared module initializer, load the shared modules from the host application\n if (sharedModuleInitializer) {\n const { shared } = await sharedModuleInitializer;\n // map shared module ids to their initializer functions\n const sharedModuleIds = extractSharedModuleIds(shared, scope);\n logDebug(\n 'SharedModules',\n `Resolved shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(sharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(sharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n const inlineSharedModuleIds = extractInlineSharedModuleIds(\n allModules,\n scope,\n );\n if (Object.keys(inlineSharedModuleIds).length > 0) {\n logDebug(\n 'SharedModules',\n `Resolved inline shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(inlineSharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(inlineSharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for inline ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n logWarn(\n 'SharedModules',\n `No shared module initializer found in bundle for scope=\"${scope.scopedName}\" — falling back to remoteShared mapping`,\n );\n } else {\n logWarn(\n 'SharedModules',\n `No TURBOPACK modules found for scope=\"${scope.scopedName}\" (TURBOPACK_${scope.globalKey} is empty)`,\n );\n }\n\n const normalizedRemoteShared =\n normalizeRemoteSharedForTurbopackFallback(remoteShared);\n return installSharedModules(\n scope,\n hostShared,\n normalizedRemoteShared,\n (_id, module) =>\n `Shared module \"${module}\" not found for \"${scope.name}\". ${DEDUPLICATION_WARNING}`,\n );\n}\n\n/**\n * Extracts shared module IDs from the shared module initializer functions.\n * This parses the minified Turbopack code to find the module ID mappings.\n */\nfunction extractSharedModuleIds(\n shared: Record<string, string | (() => Promise<unknown>)>,\n scope: RemoteScope,\n): Record<string, string> {\n return Object.entries(shared)\n .filter(([, value]) => typeof value === 'function')\n .reduce<Record<string, string>>((acc, [key, value]) => {\n const asyncSharedModuleId = extractGroup(\n ASYNC_MODULE_LOADER_RE,\n value.toString(),\n 'asyncSharedModuleId',\n );\n\n if (asyncSharedModuleId) {\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (asyncSharedModule) {\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n // map the shared module id to the actual module name\n acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(\n '__remote_shared_module_',\n '',\n );\n }\n }\n return acc;\n }, {});\n}\n\nfunction extractInlineSharedModuleIds(\n allModules: unknown[],\n scope: RemoteScope,\n): Record<string, string> {\n const sharedModuleIds: Record<string, string> = {};\n\n for (const idOrFunc of allModules) {\n if (typeof idOrFunc !== 'function') continue;\n\n const funcCode = idOrFunc.toString();\n if (!funcCode.includes('__remote_shared_module_')) continue;\n\n INLINE_REMOTE_SHARED_RE.lastIndex = 0;\n for (const match of funcCode.matchAll(INLINE_REMOTE_SHARED_RE)) {\n const specifier = match.groups?.specifier;\n const rawAsyncSharedModuleId = stripQuotes(\n match.groups?.asyncSharedModuleId,\n );\n const asyncSharedModuleId = rawAsyncSharedModuleId\n ? normalizeModuleId(rawAsyncSharedModuleId)\n : undefined;\n if (!specifier || !asyncSharedModuleId) continue;\n\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (!asyncSharedModule) continue;\n\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n sharedModuleIds[sharedModuleId ?? asyncSharedModuleId] = specifier;\n }\n }\n\n return sharedModuleIds;\n}\n\nfunction stripQuotes(value: string | undefined): string | undefined {\n if (value?.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\nfunction installSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory>,\n sharedModuleIds: RemoteSharedModules,\n missingMessage: (id: string, module: string) => string,\n): Promise<undefined[]> {\n const plan = createSharedModulePlan({\n bundle: scope.name,\n hostShared,\n remoteShared: sharedModuleIds,\n scope: `remote:${scope.scopedName}`,\n callerTag: 'SharedModules',\n });\n\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n // Compatibility with the old shared-modules architecture: a remote\n // factory may have already cached its own implementation for this ID.\n // The broker-owned scope.sharedModules entry must replace it. Remove\n // this cache cleanup once Turbopack remotes cannot execute shared\n // factories before the scoped share plan is installed.\n delete scope.moduleCache[entry.id];\n }\n }\n\n return installSharedModulePlan({\n plan,\n target: scope.sharedModules,\n callerTag: 'SharedModules',\n onMissing: (entry) => {\n logError('SharedModules', missingMessage(entry.id, entry.specifier));\n },\n }).then((results) => {\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n delete scope.moduleCache[entry.id];\n }\n }\n return results;\n });\n}\n\nfunction preferSharedManifest(\n sharedModuleIds: Record<string, string>,\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (!isSharedModuleManifest(remoteShared)) return sharedModuleIds;\n\n const extractedIdBySpecifier = new Map(\n Object.entries(sharedModuleIds).map(([id, specifier]) => [specifier, id]),\n );\n\n return {\n protocol: SHARED_MODULE_MANIFEST_PROTOCOL,\n requirements: remoteShared.requirements.map((requirement) => {\n return {\n ...requirement,\n id: extractedIdBySpecifier.get(requirement.specifier) ?? requirement.id,\n };\n }),\n };\n}\n\nfunction normalizeRemoteSharedForTurbopackFallback(\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (isSharedModuleManifest(remoteShared)) {\n return {\n ...remoteShared,\n requirements: remoteShared.requirements.map((requirement) => ({\n ...requirement,\n id:\n typeof requirement.id === 'string'\n ? requirement.id.replace('[app-ssr]', '[app-client]')\n : requirement.id,\n })),\n } satisfies SharedModuleManifest;\n }\n\n // @legacy(remote-components<=0.4.x): normalize server-side generated\n // Turbopack IDs from the historical shared map until 0.4.x remotes are\n // outside the compatibility window.\n return Object.fromEntries(\n Object.entries(remoteShared).map(([id, module]) => [\n id.replace('[app-ssr]', '[app-client]'),\n module,\n ]),\n );\n}\n\n/**\n * Returns a shared module for the given scope and module ID.\n * Shared modules are common dependencies like React that are provided by the host.\n */\nexport function getSharedModule(\n scope: RemoteScope,\n id: string | number,\n): unknown {\n const idStr = String(id);\n\n // Exact match first (covers both string and numeric IDs)\n if (scope.sharedModules[idStr] !== undefined) {\n return scope.sharedModules[idStr];\n }\n\n // Fallback: the id may be a bundle-prefixed string like \"[bundle] /react/index.js\"\n // or a Turbopack dev id like \"[project]/node_modules/react/index.js [client]\".\n // Only path-like keys use the dev-id qualifier match to avoid \"react\"\n // matching \"react-dom\".\n for (const [key, value] of Object.entries(scope.sharedModules)) {\n if (\n typeof value !== 'undefined' &&\n idStr !== key &&\n matchesSharedModuleKey(idStr, key)\n ) {\n return value;\n }\n }\n\n return null;\n}\n\nfunction matchesSharedModuleKey(id: string, key: string): boolean {\n if (id.endsWith(key)) return true;\n if (!key.includes('/') && !key.endsWith('.js')) return false;\n\n const index = id.lastIndexOf(key);\n if (index < 0) return false;\n\n const afterKey = id.slice(index + key.length);\n return /^\\s+(?:\\[[^\\]]+\\]\\s*)?(?:\\([^)]*\\))?$/.test(afterKey);\n}\n"],"mappings":"AAAA;A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]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/shared-modules.ts"],"sourcesContent":["import {\n buildSharedProviderPlan,\n getSharedProviderModule,\n installSharedProviderEntry,\n} from '#internal/host/shared/provider';\nimport {\n isSharedModuleManifest,\n type RemoteSharedModules,\n SHARED_MODULE_MANIFEST_PROTOCOL,\n type SharedModuleFactory,\n type SharedModuleManifest,\n} from '#internal/host/shared/shared-broker';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { findModuleInit, handleTurbopackModule, requireModule } from './module';\nimport {\n ASYNC_MODULE_CALLBACK_RE,\n ASYNC_MODULE_LOADER_RE,\n extractGroup,\n normalizeModuleId,\n REMOTE_SHARED_ASSIGNMENT_RE,\n REMOTE_SHARED_MARKER_RE,\n} from './patterns';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\n\nconst DEDUPLICATION_WARNING =\n 'This module will not be deduplicated — the remote may load its own copy, ' +\n 'which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).';\n// `asyncSharedModuleId` accepts: quoted string, integer, or integer in\n// scientific notation (e.g. `35e3`). Production minifiers occasionally\n// emit the scientific form; see normalizeModuleId() / MODULE_ID_PATTERN\n// in ./patterns.ts for the matching marker-extraction path.\nconst INLINE_REMOTE_SHARED_RE =\n /[\"']?__remote_shared_module_(?<specifier>[^\"':]+)[\"']?\\s*:\\s*\\(\\)\\s*=>\\s*(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>\"[^\"]+\"|[0-9]+e[0-9]+|[0-9]+)\\)/g;\n\n/**\n * Returns the flat module list for a scope.\n *\n * The primary source is `scope.turbopackModules` — a flat array populated by\n * the push interceptor in handleTurbopackChunk. This is immune to the\n * turbopack runtime replacing the TURBOPACK global (canary builds swap the\n * array for a deferred-loading dispatcher object).\n *\n * Falls back to reading the global for pre-populated bundles where the push\n * interceptor was never installed.\n */\nexport function getTurbopackModules(scope: RemoteScope): unknown[] | undefined {\n if (scope.turbopackModules.length > 0) {\n return scope.turbopackModules;\n }\n\n // Fallback: read the global for pre-populated bundles or legacy setups.\n const self = globalThis as GlobalScope;\n const raw = self[`TURBOPACK_${scope.globalKey}`];\n if (!raw) return undefined;\n\n if (Array.isArray(raw)) {\n return (raw as unknown[]).flat();\n }\n return Object.entries(raw as Record<string, unknown>).flat();\n}\n\n/**\n * Initializes shared modules between the host application and remote components.\n * This enables sharing of common dependencies like React to avoid duplicate instances.\n *\n * The function works by:\n * 1. Looking for a shared module initializer in the Turbopack bundle\n * 2. Extracting module IDs from the initializer\n * 3. Loading the corresponding host modules and mapping them to the remote's expected IDs\n */\nexport async function initializeSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory> = {},\n remoteShared: RemoteSharedModules = {},\n // biome-ignore lint/suspicious/noConfusingVoidType: Runtime is undefined but in TS land service it is void\n): Promise<void[]> {\n const allModules = getTurbopackModules(scope);\n\n logDebug(\n 'SharedModules',\n `initializeSharedModules: scope=\"${scope.scopedName}\", ` +\n `allModules=${allModules ? allModules.length : 'null'}, ` +\n `hostShared=[${Object.keys(hostShared).join(', ')}], ` +\n `remoteShared=${JSON.stringify(remoteShared)}`,\n );\n\n let sharedModuleInitializer: Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }> | null = null;\n\n // find the shared module initializer in the Turbopack bundle\n if (allModules) {\n // find the shared module initializer module id by looking for\n // a function that contains the TURBOPACK_REMOTE_SHARED pattern\n const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {\n if (typeof idOrFunc !== 'function') {\n return false;\n }\n const funcCode = idOrFunc.toString();\n return REMOTE_SHARED_MARKER_RE.test(funcCode);\n });\n\n // if found, extract the shared module initializer\n // first element in the array is always the source script element\n if (sharedModuleInitializerIndex > 0) {\n const sharedModuleInitializerCode = (\n allModules[sharedModuleInitializerIndex] as () => unknown\n ).toString();\n const sharedModuleInitializerId = allModules[\n sharedModuleInitializerIndex - 1\n ] as string | number;\n // extract the shared module id from the function code\n const sharedModuleId = extractGroup(\n REMOTE_SHARED_ASSIGNMENT_RE,\n sharedModuleInitializerCode,\n 'sharedModuleId',\n );\n // Load the shared-module-initializer module. Turbopack emits its\n // factory body as\n // ctx.v((parentImport) => Promise.all([...]).then(() => parentImport(id)))\n // so `module.exports` IS the loader function (upstream `exportValue`\n // semantics). Earlier versions of remote-components' `ctx.v` eagerly\n // invoked the function and stored the resulting Promise on\n // `exports.default` — that shape is preserved here as a fallback for\n // bundles built against the old runtime, but the primary path now\n // invokes the loader explicitly with `requireModule` as the parent\n // import (the actual scope-bound require).\n if (sharedModuleId) {\n const moduleExports = handleTurbopackModule(\n scope,\n sharedModuleId,\n formatRemoteId(scope, String(sharedModuleInitializerId)),\n );\n type Loader = (\n parentImport: (id: string | number) => unknown,\n ) => Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n const loaderCandidate =\n typeof moduleExports === 'function'\n ? moduleExports\n : (moduleExports as { default?: unknown })?.default;\n if (typeof loaderCandidate === 'function') {\n sharedModuleInitializer = (loaderCandidate as Loader)((parentId) =>\n requireModule(scope, parentId),\n );\n } else if (\n loaderCandidate &&\n typeof (loaderCandidate as { then?: unknown }).then === 'function'\n ) {\n sharedModuleInitializer = loaderCandidate as Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n }\n }\n }\n\n // if we have a shared module initializer, load the shared modules from the host application\n if (sharedModuleInitializer) {\n const { shared } = await sharedModuleInitializer;\n // map shared module ids to their initializer functions\n const sharedModuleIds = extractSharedModuleIds(shared, scope);\n logDebug(\n 'SharedModules',\n `Resolved shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(sharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(sharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n const inlineSharedModuleIds = extractInlineSharedModuleIds(\n allModules,\n scope,\n );\n if (Object.keys(inlineSharedModuleIds).length > 0) {\n logDebug(\n 'SharedModules',\n `Resolved inline shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(inlineSharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(inlineSharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for inline ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n logWarn(\n 'SharedModules',\n `No shared module initializer found in bundle for scope=\"${scope.scopedName}\" — falling back to remoteShared mapping`,\n );\n } else {\n logWarn(\n 'SharedModules',\n `No TURBOPACK modules found for scope=\"${scope.scopedName}\" (TURBOPACK_${scope.globalKey} is empty)`,\n );\n }\n\n const normalizedRemoteShared =\n normalizeRemoteSharedForTurbopackFallback(remoteShared);\n return installSharedModules(\n scope,\n hostShared,\n normalizedRemoteShared,\n (_id, module) =>\n `Shared module \"${module}\" not found for \"${scope.name}\". ${DEDUPLICATION_WARNING}`,\n );\n}\n\n/**\n * Extracts shared module IDs from the shared module initializer functions.\n * This parses the minified Turbopack code to find the module ID mappings.\n */\nfunction extractSharedModuleIds(\n shared: Record<string, string | (() => Promise<unknown>)>,\n scope: RemoteScope,\n): Record<string, string> {\n return Object.entries(shared)\n .filter(([, value]) => typeof value === 'function')\n .reduce<Record<string, string>>((acc, [key, value]) => {\n const asyncSharedModuleId = extractGroup(\n ASYNC_MODULE_LOADER_RE,\n value.toString(),\n 'asyncSharedModuleId',\n );\n\n if (asyncSharedModuleId) {\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (asyncSharedModule) {\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n // map the shared module id to the actual module name\n acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(\n '__remote_shared_module_',\n '',\n );\n }\n }\n return acc;\n }, {});\n}\n\nfunction extractInlineSharedModuleIds(\n allModules: unknown[],\n scope: RemoteScope,\n): Record<string, string> {\n const sharedModuleIds: Record<string, string> = {};\n\n for (const idOrFunc of allModules) {\n if (typeof idOrFunc !== 'function') continue;\n\n const funcCode = idOrFunc.toString();\n if (!funcCode.includes('__remote_shared_module_')) continue;\n\n INLINE_REMOTE_SHARED_RE.lastIndex = 0;\n for (const match of funcCode.matchAll(INLINE_REMOTE_SHARED_RE)) {\n const specifier = match.groups?.specifier;\n const rawAsyncSharedModuleId = stripQuotes(\n match.groups?.asyncSharedModuleId,\n );\n const asyncSharedModuleId = rawAsyncSharedModuleId\n ? normalizeModuleId(rawAsyncSharedModuleId)\n : undefined;\n if (!specifier || !asyncSharedModuleId) continue;\n\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (!asyncSharedModule) continue;\n\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n sharedModuleIds[sharedModuleId ?? asyncSharedModuleId] = specifier;\n }\n }\n\n return sharedModuleIds;\n}\n\nfunction stripQuotes(value: string | undefined): string | undefined {\n if (value?.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\nfunction installSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory>,\n sharedModuleIds: RemoteSharedModules,\n missingMessage: (id: string, module: string) => string,\n): Promise<undefined[]> {\n return buildSharedProviderPlan({\n bundle: scope.name,\n hostShared,\n remoteShared: sharedModuleIds,\n scope: `remote:${scope.scopedName}`,\n callerTag: 'SharedModules',\n onMissing: (entry) => {\n logError('SharedModules', missingMessage(entry.id, entry.specifier));\n },\n }).then((results) =>\n results.entries.map((entry) => {\n installSharedProviderEntry(entry);\n scope.sharedModules[entry.id] = getSharedProviderModule({\n scope: entry.scope,\n specifier: entry.specifier,\n });\n // Compatibility with the old shared-modules architecture: a remote\n // factory may have already cached its own implementation for this ID.\n // The provider-owned scope.sharedModules entry must replace it. Remove\n // this cache cleanup once Turbopack remotes cannot execute shared\n // factories before the scoped provider plan is installed.\n delete scope.moduleCache[entry.id];\n return undefined;\n }),\n );\n}\n\nfunction preferSharedManifest(\n sharedModuleIds: Record<string, string>,\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (!isSharedModuleManifest(remoteShared)) return sharedModuleIds;\n\n const extractedIdBySpecifier = new Map(\n Object.entries(sharedModuleIds).map(([id, specifier]) => [specifier, id]),\n );\n\n return {\n protocol: SHARED_MODULE_MANIFEST_PROTOCOL,\n requirements: remoteShared.requirements.map((requirement) => {\n return {\n ...requirement,\n id: extractedIdBySpecifier.get(requirement.specifier) ?? requirement.id,\n };\n }),\n };\n}\n\nfunction normalizeRemoteSharedForTurbopackFallback(\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (isSharedModuleManifest(remoteShared)) {\n return {\n ...remoteShared,\n requirements: remoteShared.requirements.map((requirement) => ({\n ...requirement,\n id:\n typeof requirement.id === 'string'\n ? requirement.id.replace('[app-ssr]', '[app-client]')\n : requirement.id,\n })),\n } satisfies SharedModuleManifest;\n }\n\n // @legacy(remote-components<=0.4.x): normalize server-side generated\n // Turbopack IDs from the historical shared map until 0.4.x remotes are\n // outside the compatibility window.\n return Object.fromEntries(\n Object.entries(remoteShared).map(([id, module]) => [\n id.replace('[app-ssr]', '[app-client]'),\n module,\n ]),\n );\n}\n\n/**\n * Returns a shared module for the given scope and module ID.\n * Shared modules are common dependencies like React that are provided by the host.\n */\nexport function getSharedModule(\n scope: RemoteScope,\n id: string | number,\n): unknown {\n const idStr = String(id);\n\n // Exact match first (covers both string and numeric IDs)\n if (scope.sharedModules[idStr] !== undefined) {\n return scope.sharedModules[idStr];\n }\n\n // Fallback: the id may be a bundle-prefixed string like \"[bundle] /react/index.js\"\n // or a Turbopack dev id like \"[project]/node_modules/react/index.js [client]\".\n // Only path-like keys use the dev-id qualifier match to avoid \"react\"\n // matching \"react-dom\".\n for (const [key, value] of Object.entries(scope.sharedModules)) {\n if (\n typeof value !== 'undefined' &&\n idStr !== key &&\n matchesSharedModuleKey(idStr, key)\n ) {\n return value;\n }\n }\n\n return null;\n}\n\nfunction matchesSharedModuleKey(id: string, key: string): boolean {\n if (id.endsWith(key)) return true;\n if (!key.includes('/') && !key.endsWith('.js')) return false;\n\n const index = id.lastIndexOf(key);\n if (index < 0) return false;\n\n const afterKey = id.slice(index + key.length);\n return /^\\s+(?:\\[[^\\]]+\\]\\s*)?(?:\\([^)]*\\))?$/.test(afterKey);\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EAEA;AAAA,OAGK;AAEP,SAAS,UAAU,UAAU,eAAe;AAC5C,SAAS,gBAAgB,uBAAuB,qBAAqB;AACrE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAwC;AAEjD,MAAM,wBACJ;AAMF,MAAM,0BACJ;AAaK,SAAS,oBAAoB,OAA2C;AAC7E,MAAI,MAAM,iBAAiB,SAAS,GAAG;AACrC,WAAO,MAAM;AAAA,EACf;AAGA,QAAM,OAAO;AACb,QAAM,MAAM,KAAK,aAAa,MAAM,WAAW;AAC/C,MAAI,CAAC;AAAK,WAAO;AAEjB,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAQ,IAAkB,KAAK;AAAA,EACjC;AACA,SAAO,OAAO,QAAQ,GAA8B,EAAE,KAAK;AAC7D;AAWA,eAAsB,wBACpB,OACA,aAAkD,CAAC,GACnD,eAAoC,CAAC,GAEpB;AACjB,QAAM,aAAa,oBAAoB,KAAK;AAE5C;AAAA,IACE;AAAA,IACA,mCAAmC,MAAM,2BACzB,aAAa,WAAW,SAAS,uBAChC,OAAO,KAAK,UAAU,EAAE,KAAK,IAAI,oBAChC,KAAK,UAAU,YAAY;AAAA,EAC/C;AAEA,MAAI,0BA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SAAS,GAAG;AAAG,WAAO;AAC7B,MAAI,CAAC,IAAI,SAAS,GAAG,KAAK,CAAC,IAAI,SAAS,KAAK;AAAG,WAAO;AAEvD,QAAM,QAAQ,GAAG,YAAY,GAAG;AAChC,MAAI,QAAQ;AAAG,WAAO;AAEtB,QAAM,WAAW,GAAG,MAAM,QAAQ,IAAI,MAAM;AAC5C,SAAO,wCAAwC,KAAK,QAAQ;AAC9D;","names":[]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
setupRemoteScope
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GR5FN73U.js";
|
|
4
4
|
import {
|
|
5
5
|
applySharedModules,
|
|
6
6
|
initializeSharedModules,
|
|
7
7
|
nextClientPagesLoader
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-VFK4HGZT.js";
|
|
9
9
|
import {
|
|
10
10
|
buildCoreShared,
|
|
11
11
|
buildHostShared
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-3PR3SWYZ.js";
|
|
13
13
|
import "./chunk-D5GNZB6O.js";
|
|
14
14
|
import "./chunk-STIJO4AG.js";
|
|
15
15
|
import "./chunk-ULXU6XWH.js";
|
|
@@ -20,7 +20,7 @@ import "./chunk-ENYGL5CO.js";
|
|
|
20
20
|
async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClientUrl) {
|
|
21
21
|
const self = globalThis;
|
|
22
22
|
const hostShared = buildHostShared(shared, resolveClientUrl, {
|
|
23
|
-
|
|
23
|
+
includePagesClientSharedGlobal: true
|
|
24
24
|
});
|
|
25
25
|
await setupRemoteScope("turbopack", [], url, bundle, resolveClientUrl);
|
|
26
26
|
const {
|
|
@@ -53,4 +53,4 @@ async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClient
|
|
|
53
53
|
export {
|
|
54
54
|
turbopackRuntime
|
|
55
55
|
};
|
|
56
|
-
//# sourceMappingURL=turbopack-
|
|
56
|
+
//# sourceMappingURL=turbopack-6BSS3SYN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/host/html/runtime/turbopack.ts"],"sourcesContent":["import { applySharedModules } from '#internal/config/webpack/apply-shared-modules';\nimport { nextClientPagesLoader } from '#internal/config/webpack/next-client-pages-loader';\nimport type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { RemoteSharedModules } from '#internal/host/shared/shared-broker';\nimport {\n buildCoreShared,\n buildHostShared,\n} from '#internal/host/shared/shared-module-resolver';\nimport { setupRemoteScope } from '#internal/runtime/turbopack/remote-scope-setup';\nimport { initializeSharedModules } from '#internal/runtime/turbopack/shared-modules';\nimport type { MountUnmountFunctions, RSCKey } from '#internal/runtime/types';\n\n// initializer for the turbopack runtime to be able to access modules\n// required to run exposed client components of the remote component\nexport async function turbopackRuntime(\n url: URL,\n bundle?: string,\n shared?: Record<string, () => Promise<unknown>>,\n remoteShared?: RemoteSharedModules,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack runtime globals\n __webpack_require__: (remoteId: string) => unknown;\n // webpack remote module loading function scoped for each bundle\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string) => unknown) & {\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n // conditional flag to disable webpack exec\n __DISABLE_WEBPACK_EXEC__: boolean;\n // webpack chunk loading function\n __webpack_chunk_load__: () => Promise<[]>;\n } & MountUnmountFunctions &\n Record<RSCKey, string[]>;\n\n const hostShared = buildHostShared(shared, resolveClientUrl, {\n includePagesClientSharedGlobal: true,\n });\n\n // Phase 1: Set up globals (__webpack_require__, __webpack_chunk_load__).\n // Called with empty scripts because we need the globals to exist before\n // importing react-server-dom-webpack. Shared module initialization is\n // deferred to preloadScripts where turbopack chunks are actually loaded.\n await setupRemoteScope('turbopack', [], url, bundle, resolveClientUrl);\n\n // we can only import react-server-dom-webpack after initializing the __webpack_require__ and __webpack_chunk_load__ functions\n const {\n default: { createFromReadableStream },\n } = await import('react-server-dom-webpack/client.browser');\n\n async function preloadScripts(scripts: HTMLScriptElement[], __: URL) {\n // Phase 2: Load turbopack chunks (scope is reused from phase 1).\n const scope = await setupRemoteScope(\n 'turbopack',\n scripts.map((script) => ({\n src:\n script.getAttribute('src') ||\n script.getAttribute('data-src') ||\n script.src,\n })),\n url,\n bundle,\n resolveClientUrl,\n );\n\n // Phase 3: Initialize shared modules now that turbopackModules is\n // populated. This uses the primary bundle-introspection path which\n // maps shared modules by numeric turbopack ID — unlike the fallback\n // path that uses file-path keys which can't match at runtime.\n await initializeSharedModules(\n scope,\n buildCoreShared(hostShared),\n remoteShared ?? {},\n );\n }\n\n return {\n self,\n createFromReadableStream,\n applySharedModules,\n nextClientPagesLoader,\n preloadScripts,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAcA,eAAsB,iBACpB,KACA,QACA,QACA,cACA,kBACA;AAEA,QAAM,OAAO;AAmBb,QAAM,aAAa,gBAAgB,QAAQ,kBAAkB;AAAA,IAC3D,gCAAgC;AAAA,EAClC,CAAC;AAMD,QAAM,iBAAiB,aAAa,CAAC,GAAG,KAAK,QAAQ,gBAAgB;AAGrE,QAAM;AAAA,IACJ,SAAS,EAAE,yBAAyB;AAAA,EACtC,IAAI,MAAM,OAAO,yCAAyC;AAE1D,iBAAe,eAAe,SAA8B,IAAS;AAEnE,UAAM,QAAQ,MAAM;AAAA,MAClB;AAAA,MACA,QAAQ,IAAI,CAAC,YAAY;AAAA,QACvB,KACE,OAAO,aAAa,KAAK,KACzB,OAAO,aAAa,UAAU,KAC9B,OAAO;AAAA,MACX,EAAE;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAMA,UAAM;AAAA,MACJ;AAAA,MACA,gBAAgB,UAAU;AAAA,MAC1B,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,15 +1,15 @@
|
|
|
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(); } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkRZ224NSHcjs = require('./chunk-RZ224NSH.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkPCHSF5LHcjs = require('./chunk-PCHSF5LH.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunk6PZEDIAKcjs = require('./chunk-6PZEDIAK.cjs');
|
|
13
13
|
require('./chunk-Z2SLBFQL.cjs');
|
|
14
14
|
require('./chunk-5KTAEO52.cjs');
|
|
15
15
|
require('./chunk-BBXVML3D.cjs');
|
|
@@ -19,15 +19,15 @@ require('./chunk-SHFJ5OQA.cjs');
|
|
|
19
19
|
// src/host/html/runtime/turbopack.ts
|
|
20
20
|
async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClientUrl) {
|
|
21
21
|
const self = globalThis;
|
|
22
|
-
const hostShared =
|
|
23
|
-
|
|
22
|
+
const hostShared = _chunk6PZEDIAKcjs.buildHostShared.call(void 0, shared, resolveClientUrl, {
|
|
23
|
+
includePagesClientSharedGlobal: true
|
|
24
24
|
});
|
|
25
|
-
await
|
|
25
|
+
await _chunkRZ224NSHcjs.setupRemoteScope.call(void 0, "turbopack", [], url, bundle, resolveClientUrl);
|
|
26
26
|
const {
|
|
27
27
|
default: { createFromReadableStream }
|
|
28
28
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require("react-server-dom-webpack/client.browser")));
|
|
29
29
|
async function preloadScripts(scripts, __) {
|
|
30
|
-
const scope = await
|
|
30
|
+
const scope = await _chunkRZ224NSHcjs.setupRemoteScope.call(void 0,
|
|
31
31
|
"turbopack",
|
|
32
32
|
scripts.map((script) => ({
|
|
33
33
|
src: script.getAttribute("src") || script.getAttribute("data-src") || script.src
|
|
@@ -36,21 +36,21 @@ async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClient
|
|
|
36
36
|
bundle,
|
|
37
37
|
resolveClientUrl
|
|
38
38
|
);
|
|
39
|
-
await
|
|
39
|
+
await _chunkPCHSF5LHcjs.initializeSharedModules.call(void 0,
|
|
40
40
|
scope,
|
|
41
|
-
|
|
41
|
+
_chunk6PZEDIAKcjs.buildCoreShared.call(void 0, hostShared),
|
|
42
42
|
_nullishCoalesce(remoteShared, () => ( {}))
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
45
|
return {
|
|
46
46
|
self,
|
|
47
47
|
createFromReadableStream,
|
|
48
|
-
applySharedModules:
|
|
49
|
-
nextClientPagesLoader:
|
|
48
|
+
applySharedModules: _chunkPCHSF5LHcjs.applySharedModules,
|
|
49
|
+
nextClientPagesLoader: _chunkPCHSF5LHcjs.nextClientPagesLoader,
|
|
50
50
|
preloadScripts
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
exports.turbopackRuntime = turbopackRuntime;
|
|
56
|
-
//# sourceMappingURL=turbopack-
|
|
56
|
+
//# sourceMappingURL=turbopack-UMJ7SLJL.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/host/html/runtime/turbopack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAcA,eAAsB,iBACpB,KACA,QACA,QACA,cACA,kBACA;AAEA,QAAM,OAAO;AAmBb,QAAM,aAAa,gBAAgB,QAAQ,kBAAkB;AAAA,IAC3D,
|
|
1
|
+
{"version":3,"sources":["../src/host/html/runtime/turbopack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAcA,eAAsB,iBACpB,KACA,QACA,QACA,cACA,kBACA;AAEA,QAAM,OAAO;AAmBb,QAAM,aAAa,gBAAgB,QAAQ,kBAAkB;AAAA,IAC3D,gCAAgC;AAAA,EAClC,CAAC;AAMD,QAAM,iBAAiB,aAAa,CAAC,GAAG,KAAK,QAAQ,gBAAgB;AAGrE,QAAM;AAAA,IACJ,SAAS,EAAE,yBAAyB;AAAA,EACtC,IAAI,MAAM,OAAO,yCAAyC;AAE1D,iBAAe,eAAe,SAA8B,IAAS;AAEnE,UAAM,QAAQ,MAAM;AAAA,MAClB;AAAA,MACA,QAAQ,IAAI,CAAC,YAAY;AAAA,QACvB,KACE,OAAO,aAAa,KAAK,KACzB,OAAO,aAAa,UAAU,KAC9B,OAAO;AAAA,MACX,EAAE;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAMA,UAAM;AAAA,MACJ;AAAA,MACA,gBAAgB,UAAU;AAAA,MAC1B,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF","sourcesContent":["import { applySharedModules } from '#internal/config/webpack/apply-shared-modules';\nimport { nextClientPagesLoader } from '#internal/config/webpack/next-client-pages-loader';\nimport type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { RemoteSharedModules } from '#internal/host/shared/shared-broker';\nimport {\n buildCoreShared,\n buildHostShared,\n} from '#internal/host/shared/shared-module-resolver';\nimport { setupRemoteScope } from '#internal/runtime/turbopack/remote-scope-setup';\nimport { initializeSharedModules } from '#internal/runtime/turbopack/shared-modules';\nimport type { MountUnmountFunctions, RSCKey } from '#internal/runtime/types';\n\n// initializer for the turbopack runtime to be able to access modules\n// required to run exposed client components of the remote component\nexport async function turbopackRuntime(\n url: URL,\n bundle?: string,\n shared?: Record<string, () => Promise<unknown>>,\n remoteShared?: RemoteSharedModules,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack runtime globals\n __webpack_require__: (remoteId: string) => unknown;\n // webpack remote module loading function scoped for each bundle\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string) => unknown) & {\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n // conditional flag to disable webpack exec\n __DISABLE_WEBPACK_EXEC__: boolean;\n // webpack chunk loading function\n __webpack_chunk_load__: () => Promise<[]>;\n } & MountUnmountFunctions &\n Record<RSCKey, string[]>;\n\n const hostShared = buildHostShared(shared, resolveClientUrl, {\n includePagesClientSharedGlobal: true,\n });\n\n // Phase 1: Set up globals (__webpack_require__, __webpack_chunk_load__).\n // Called with empty scripts because we need the globals to exist before\n // importing react-server-dom-webpack. Shared module initialization is\n // deferred to preloadScripts where turbopack chunks are actually loaded.\n await setupRemoteScope('turbopack', [], url, bundle, resolveClientUrl);\n\n // we can only import react-server-dom-webpack after initializing the __webpack_require__ and __webpack_chunk_load__ functions\n const {\n default: { createFromReadableStream },\n } = await import('react-server-dom-webpack/client.browser');\n\n async function preloadScripts(scripts: HTMLScriptElement[], __: URL) {\n // Phase 2: Load turbopack chunks (scope is reused from phase 1).\n const scope = await setupRemoteScope(\n 'turbopack',\n scripts.map((script) => ({\n src:\n script.getAttribute('src') ||\n script.getAttribute('data-src') ||\n script.src,\n })),\n url,\n bundle,\n resolveClientUrl,\n );\n\n // Phase 3: Initialize shared modules now that turbopackModules is\n // populated. This uses the primary bundle-introspection path which\n // maps shared modules by numeric turbopack ID — unlike the fallback\n // path that uses file-path keys which can't match at runtime.\n await initializeSharedModules(\n scope,\n buildCoreShared(hostShared),\n remoteShared ?? {},\n );\n }\n\n return {\n self,\n createFromReadableStream,\n applySharedModules,\n nextClientPagesLoader,\n preloadScripts,\n };\n}\n"]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadScripts
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-M6ACTSVB.js";
|
|
4
4
|
import {
|
|
5
5
|
applySharedModules,
|
|
6
|
+
buildWebpackResolve,
|
|
6
7
|
nextClientPagesLoader
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-VFK4HGZT.js";
|
|
8
9
|
import {
|
|
9
10
|
NEXT_BUNDLE_PATH_RE,
|
|
10
|
-
buildHostShared
|
|
11
|
-
|
|
12
|
-
} from "./chunk-JZRA6DPE.js";
|
|
11
|
+
buildHostShared
|
|
12
|
+
} from "./chunk-3PR3SWYZ.js";
|
|
13
13
|
import "./chunk-D5GNZB6O.js";
|
|
14
14
|
import "./chunk-STIJO4AG.js";
|
|
15
15
|
import {
|
|
@@ -63,7 +63,9 @@ async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
|
|
|
63
63
|
];
|
|
64
64
|
});
|
|
65
65
|
await loadScripts(scriptSrcs, resolveClientUrl);
|
|
66
|
-
const hostShared = buildHostShared(shared, resolveClientUrl
|
|
66
|
+
const hostShared = buildHostShared(shared, resolveClientUrl, {
|
|
67
|
+
includePagesClientSharedGlobal: true
|
|
68
|
+
});
|
|
67
69
|
const resolve = await buildWebpackResolve(
|
|
68
70
|
hostShared,
|
|
69
71
|
remoteShared ?? {},
|
|
@@ -90,4 +92,4 @@ async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
|
|
|
90
92
|
export {
|
|
91
93
|
webpackRuntime
|
|
92
94
|
};
|
|
93
|
-
//# sourceMappingURL=webpack-
|
|
95
|
+
//# sourceMappingURL=webpack-4QYGIVE6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/host/html/runtime/webpack.ts"],"sourcesContent":["import { applySharedModules } from '#internal/config/webpack/apply-shared-modules';\nimport { nextClientPagesLoader } from '#internal/config/webpack/next-client-pages-loader';\nimport { buildWebpackResolve } from '#internal/config/webpack/shared-module-resolver';\nimport type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { RemoteSharedModules } from '#internal/host/shared/shared-broker';\nimport { buildHostShared } from '#internal/host/shared/shared-module-resolver';\nimport { loadScripts } from '#internal/runtime/loaders/script-loader';\nimport { NEXT_BUNDLE_PATH_RE } from '#internal/runtime/patterns';\nimport type { MountUnmountFunctions, RSCKey } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\n// initializer for the webpack runtime to be able to access modules\n// required to run exposed client components of the remote component\nexport async function webpackRuntime(\n bundle: string,\n shared?: Record<string, () => Promise<unknown>>,\n remoteShared?: RemoteSharedModules,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack runtime globals\n __webpack_require__: (remoteId: string) => unknown;\n // webpack remote module loading function scoped for each bundle\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string) => unknown) & {\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n // conditional flag to disable webpack exec\n __DISABLE_WEBPACK_EXEC__?: Record<string, boolean>;\n // webpack chunk loading function\n __webpack_chunk_load__: () => Promise<[]>;\n __webpack_require_type__: 'webpack' | 'turbopack';\n } & MountUnmountFunctions &\n Record<RSCKey, string[]>;\n\n // disable webpack exec to prevent automatically executing the entry module\n if (!self.__DISABLE_WEBPACK_EXEC__) {\n self.__DISABLE_WEBPACK_EXEC__ = {};\n }\n self.__DISABLE_WEBPACK_EXEC__[bundle] = true;\n // add a custom webpack require function to load remote components from multiple bundles / zones\n if (\n typeof self.__webpack_require__ !== 'function' &&\n self.__webpack_require_type__ !== 'turbopack'\n ) {\n self.__webpack_require__ = (remoteId: string) => {\n const re = /\\[(?<bundle>[^\\]]+)\\] (?<id>.*)/;\n const match = re.exec(remoteId);\n const remoteBundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && remoteBundle)) {\n throw new RemoteComponentsError(\n `Remote Component module \"${remoteId}\" not found. Did you forget to wrap the Next.js config with \\`withRemoteComponentsConfig\\` on both host and remote?`,\n );\n }\n if (\n typeof self.__remote_webpack_require__?.[remoteBundle] !== 'function'\n ) {\n throw new RemoteComponentsError(\n `Remote Components are not available in \"${remoteBundle}\". Did you forget to wrap the Next.js config with \\`withRemoteComponentsConfig\\` on both host and remote?`,\n );\n }\n return self.__remote_webpack_require__[remoteBundle](id);\n };\n // not used but required by react-server-dom-webpack\n self.__webpack_chunk_load__ = () => {\n return Promise.resolve([]);\n };\n }\n // we can only import react-server-dom-webpack after initializing the __webpack_require__ and __webpack_chunk_load__ functions\n const {\n default: { createFromReadableStream },\n } = await import('react-server-dom-webpack/client.browser');\n\n async function preloadScripts(\n scripts: HTMLScriptElement[],\n url: URL,\n remoteBundle: string,\n _: string,\n ) {\n // Build absolute src URLs for each script and remove originals from the\n // parsed doc to prevent re-execution when the doc is later inserted into\n // the shadow DOM.\n const scriptSrcs = scripts.flatMap((script) => {\n const scriptSrc =\n script.getAttribute('src') || script.getAttribute('data-src');\n script.parentElement?.removeChild(script);\n if (!scriptSrc) return [];\n return [\n {\n src: new URL(scriptSrc.replace(NEXT_BUNDLE_PATH_RE, '/_next/'), url)\n .href,\n },\n ];\n });\n\n await loadScripts(scriptSrcs, resolveClientUrl);\n\n const hostShared = buildHostShared(shared, resolveClientUrl, {\n includePagesClientSharedGlobal: true,\n });\n const resolve = await buildWebpackResolve(\n hostShared,\n remoteShared ?? {},\n remoteBundle,\n {\n '/react/index.js': (await import('react')).default,\n '/react/jsx-dev-runtime.js': (await import('react/jsx-dev-runtime'))\n .default,\n '/react/jsx-runtime.js': (await import('react/jsx-runtime')).default,\n '/react-dom/index.js': (await import('react-dom')).default,\n '/react-dom/client.js': (await import('react-dom/client')).default,\n },\n 'WebpackRuntime',\n );\n\n // apply shared modules to the bundle\n applySharedModules(remoteBundle, resolve);\n }\n\n return {\n self,\n createFromReadableStream,\n applySharedModules,\n nextClientPagesLoader,\n preloadScripts,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAaA,eAAsB,eACpB,QACA,QACA,cACA,kBACA;AAEA,QAAM,OAAO;AAqBb,MAAI,CAAC,KAAK,0BAA0B;AAClC,SAAK,2BAA2B,CAAC;AAAA,EACnC;AACA,OAAK,yBAAyB,MAAM,IAAI;AAExC,MACE,OAAO,KAAK,wBAAwB,cACpC,KAAK,6BAA6B,aAClC;AACA,SAAK,sBAAsB,CAAC,aAAqB;AAC/C,YAAM,KAAK;AACX,YAAM,QAAQ,GAAG,KAAK,QAAQ;AAC9B,YAAM,eAAe,OAAO,QAAQ;AACpC,YAAM,KAAK,OAAO,QAAQ;AAC1B,UAAI,EAAE,MAAM,eAAe;AACzB,cAAM,IAAI;AAAA,UACR,4BAA4B;AAAA,QAC9B;AAAA,MACF;AACA,UACE,OAAO,KAAK,6BAA6B,YAAY,MAAM,YAC3D;AACA,cAAM,IAAI;AAAA,UACR,2CAA2C;AAAA,QAC7C;AAAA,MACF;AACA,aAAO,KAAK,2BAA2B,YAAY,EAAE,EAAE;AAAA,IACzD;AAEA,SAAK,yBAAyB,MAAM;AAClC,aAAO,QAAQ,QAAQ,CAAC,CAAC;AAAA,IAC3B;AAAA,EACF;AAEA,QAAM;AAAA,IACJ,SAAS,EAAE,yBAAyB;AAAA,EACtC,IAAI,MAAM,OAAO,yCAAyC;AAE1D,iBAAe,eACb,SACA,KACA,cACA,GACA;AAIA,UAAM,aAAa,QAAQ,QAAQ,CAAC,WAAW;AAC7C,YAAM,YACJ,OAAO,aAAa,KAAK,KAAK,OAAO,aAAa,UAAU;AAC9D,aAAO,eAAe,YAAY,MAAM;AACxC,UAAI,CAAC;AAAW,eAAO,CAAC;AACxB,aAAO;AAAA,QACL;AAAA,UACE,KAAK,IAAI,IAAI,UAAU,QAAQ,qBAAqB,SAAS,GAAG,GAAG,EAChE;AAAA,QACL;AAAA,MACF;AAAA,IACF,CAAC;AAED,UAAM,YAAY,YAAY,gBAAgB;AAE9C,UAAM,aAAa,gBAAgB,QAAQ,kBAAkB;AAAA,MAC3D,gCAAgC;AAAA,IAClC,CAAC;AACD,UAAM,UAAU,MAAM;AAAA,MACpB;AAAA,MACA,gBAAgB,CAAC;AAAA,MACjB;AAAA,MACA;AAAA,QACE,oBAAoB,MAAM,OAAO,OAAO,GAAG;AAAA,QAC3C,8BAA8B,MAAM,OAAO,uBAAuB,GAC/D;AAAA,QACH,0BAA0B,MAAM,OAAO,mBAAmB,GAAG;AAAA,QAC7D,wBAAwB,MAAM,OAAO,WAAW,GAAG;AAAA,QACnD,yBAAyB,MAAM,OAAO,kBAAkB,GAAG;AAAA,MAC7D;AAAA,MACA;AAAA,IACF;AAGA,uBAAmB,cAAc,OAAO;AAAA,EAC1C;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,15 +1,15 @@
|
|
|
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; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkXWRB6CEAcjs = require('./chunk-XWRB6CEA.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var _chunkYJJFRORQcjs = require('./chunk-YJJFRORQ.cjs');
|
|
8
7
|
|
|
8
|
+
var _chunkPCHSF5LHcjs = require('./chunk-PCHSF5LH.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunk6PZEDIAKcjs = require('./chunk-6PZEDIAK.cjs');
|
|
13
13
|
require('./chunk-Z2SLBFQL.cjs');
|
|
14
14
|
require('./chunk-5KTAEO52.cjs');
|
|
15
15
|
|
|
@@ -58,13 +58,15 @@ async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
|
|
|
58
58
|
return [];
|
|
59
59
|
return [
|
|
60
60
|
{
|
|
61
|
-
src: new URL(scriptSrc.replace(
|
|
61
|
+
src: new URL(scriptSrc.replace(_chunk6PZEDIAKcjs.NEXT_BUNDLE_PATH_RE, "/_next/"), url).href
|
|
62
62
|
}
|
|
63
63
|
];
|
|
64
64
|
});
|
|
65
|
-
await
|
|
66
|
-
const hostShared =
|
|
67
|
-
|
|
65
|
+
await _chunkXWRB6CEAcjs.loadScripts.call(void 0, scriptSrcs, resolveClientUrl);
|
|
66
|
+
const hostShared = _chunk6PZEDIAKcjs.buildHostShared.call(void 0, shared, resolveClientUrl, {
|
|
67
|
+
includePagesClientSharedGlobal: true
|
|
68
|
+
});
|
|
69
|
+
const resolve = await _chunkPCHSF5LHcjs.buildWebpackResolve.call(void 0,
|
|
68
70
|
hostShared,
|
|
69
71
|
_nullishCoalesce(remoteShared, () => ( {})),
|
|
70
72
|
remoteBundle,
|
|
@@ -77,17 +79,17 @@ async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
|
|
|
77
79
|
},
|
|
78
80
|
"WebpackRuntime"
|
|
79
81
|
);
|
|
80
|
-
|
|
82
|
+
_chunkPCHSF5LHcjs.applySharedModules.call(void 0, remoteBundle, resolve);
|
|
81
83
|
}
|
|
82
84
|
return {
|
|
83
85
|
self,
|
|
84
86
|
createFromReadableStream,
|
|
85
|
-
applySharedModules:
|
|
86
|
-
nextClientPagesLoader:
|
|
87
|
+
applySharedModules: _chunkPCHSF5LHcjs.applySharedModules,
|
|
88
|
+
nextClientPagesLoader: _chunkPCHSF5LHcjs.nextClientPagesLoader,
|
|
87
89
|
preloadScripts
|
|
88
90
|
};
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
|
|
92
94
|
exports.webpackRuntime = webpackRuntime;
|
|
93
|
-
//# sourceMappingURL=webpack-
|
|
95
|
+
//# sourceMappingURL=webpack-65BVWX2U.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/host/html/runtime/webpack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAaA,eAAsB,eACpB,QACA,QACA,cACA,kBACA;AAEA,QAAM,OAAO;AAqBb,MAAI,CAAC,KAAK,0BAA0B;AAClC,SAAK,2BAA2B,CAAC;AAAA,EACnC;AACA,OAAK,yBAAyB,MAAM,IAAI;AAExC,MACE,OAAO,KAAK,wBAAwB,cACpC,KAAK,6BAA6B,aAClC;AACA,SAAK,sBAAsB,CAAC,aAAqB;AAC/C,YAAM,KAAK;AACX,YAAM,QAAQ,GAAG,KAAK,QAAQ;AAC9B,YAAM,eAAe,OAAO,QAAQ;AACpC,YAAM,KAAK,OAAO,QAAQ;AAC1B,UAAI,EAAE,MAAM,eAAe;AACzB,cAAM,IAAI;AAAA,UACR,4BAA4B;AAAA,QAC9B;AAAA,MACF;AACA,UACE,OAAO,KAAK,6BAA6B,YAAY,MAAM,YAC3D;AACA,cAAM,IAAI;AAAA,UACR,2CAA2C;AAAA,QAC7C;AAAA,MACF;AACA,aAAO,KAAK,2BAA2B,YAAY,EAAE,EAAE;AAAA,IACzD;AAEA,SAAK,yBAAyB,MAAM;AAClC,aAAO,QAAQ,QAAQ,CAAC,CAAC;AAAA,IAC3B;AAAA,EACF;AAEA,QAAM;AAAA,IACJ,SAAS,EAAE,yBAAyB;AAAA,EACtC,IAAI,MAAM,OAAO,yCAAyC;AAE1D,iBAAe,eACb,SACA,KACA,cACA,GACA;AAIA,UAAM,aAAa,QAAQ,QAAQ,CAAC,WAAW;AAC7C,YAAM,YACJ,OAAO,aAAa,KAAK,KAAK,OAAO,aAAa,UAAU;AAC9D,aAAO,eAAe,YAAY,MAAM;AACxC,UAAI,CAAC;AAAW,eAAO,CAAC;AACxB,aAAO;AAAA,QACL;AAAA,UACE,KAAK,IAAI,IAAI,UAAU,QAAQ,qBAAqB,SAAS,GAAG,GAAG,EAChE;AAAA,QACL;AAAA,MACF;AAAA,IACF,CAAC;AAED,UAAM,YAAY,YAAY,gBAAgB;AAE9C,UAAM,aAAa,gBAAgB,QAAQ,kBAAkB;AAAA,MAC3D,gCAAgC;AAAA,IAClC,CAAC;AACD,UAAM,UAAU,MAAM;AAAA,MACpB;AAAA,MACA,gBAAgB,CAAC;AAAA,MACjB;AAAA,MACA;AAAA,QACE,oBAAoB,MAAM,OAAO,OAAO,GAAG;AAAA,QAC3C,8BAA8B,MAAM,OAAO,uBAAuB,GAC/D;AAAA,QACH,0BAA0B,MAAM,OAAO,mBAAmB,GAAG;AAAA,QAC7D,wBAAwB,MAAM,OAAO,WAAW,GAAG;AAAA,QACnD,yBAAyB,MAAM,OAAO,kBAAkB,GAAG;AAAA,MAC7D;AAAA,MACA;AAAA,IACF;AAGA,uBAAmB,cAAc,OAAO;AAAA,EAC1C;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF","sourcesContent":["import { applySharedModules } from '#internal/config/webpack/apply-shared-modules';\nimport { nextClientPagesLoader } from '#internal/config/webpack/next-client-pages-loader';\nimport { buildWebpackResolve } from '#internal/config/webpack/shared-module-resolver';\nimport type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { RemoteSharedModules } from '#internal/host/shared/shared-broker';\nimport { buildHostShared } from '#internal/host/shared/shared-module-resolver';\nimport { loadScripts } from '#internal/runtime/loaders/script-loader';\nimport { NEXT_BUNDLE_PATH_RE } from '#internal/runtime/patterns';\nimport type { MountUnmountFunctions, RSCKey } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\n// initializer for the webpack runtime to be able to access modules\n// required to run exposed client components of the remote component\nexport async function webpackRuntime(\n bundle: string,\n shared?: Record<string, () => Promise<unknown>>,\n remoteShared?: RemoteSharedModules,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack runtime globals\n __webpack_require__: (remoteId: string) => unknown;\n // webpack remote module loading function scoped for each bundle\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string) => unknown) & {\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n // conditional flag to disable webpack exec\n __DISABLE_WEBPACK_EXEC__?: Record<string, boolean>;\n // webpack chunk loading function\n __webpack_chunk_load__: () => Promise<[]>;\n __webpack_require_type__: 'webpack' | 'turbopack';\n } & MountUnmountFunctions &\n Record<RSCKey, string[]>;\n\n // disable webpack exec to prevent automatically executing the entry module\n if (!self.__DISABLE_WEBPACK_EXEC__) {\n self.__DISABLE_WEBPACK_EXEC__ = {};\n }\n self.__DISABLE_WEBPACK_EXEC__[bundle] = true;\n // add a custom webpack require function to load remote components from multiple bundles / zones\n if (\n typeof self.__webpack_require__ !== 'function' &&\n self.__webpack_require_type__ !== 'turbopack'\n ) {\n self.__webpack_require__ = (remoteId: string) => {\n const re = /\\[(?<bundle>[^\\]]+)\\] (?<id>.*)/;\n const match = re.exec(remoteId);\n const remoteBundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && remoteBundle)) {\n throw new RemoteComponentsError(\n `Remote Component module \"${remoteId}\" not found. Did you forget to wrap the Next.js config with \\`withRemoteComponentsConfig\\` on both host and remote?`,\n );\n }\n if (\n typeof self.__remote_webpack_require__?.[remoteBundle] !== 'function'\n ) {\n throw new RemoteComponentsError(\n `Remote Components are not available in \"${remoteBundle}\". Did you forget to wrap the Next.js config with \\`withRemoteComponentsConfig\\` on both host and remote?`,\n );\n }\n return self.__remote_webpack_require__[remoteBundle](id);\n };\n // not used but required by react-server-dom-webpack\n self.__webpack_chunk_load__ = () => {\n return Promise.resolve([]);\n };\n }\n // we can only import react-server-dom-webpack after initializing the __webpack_require__ and __webpack_chunk_load__ functions\n const {\n default: { createFromReadableStream },\n } = await import('react-server-dom-webpack/client.browser');\n\n async function preloadScripts(\n scripts: HTMLScriptElement[],\n url: URL,\n remoteBundle: string,\n _: string,\n ) {\n // Build absolute src URLs for each script and remove originals from the\n // parsed doc to prevent re-execution when the doc is later inserted into\n // the shadow DOM.\n const scriptSrcs = scripts.flatMap((script) => {\n const scriptSrc =\n script.getAttribute('src') || script.getAttribute('data-src');\n script.parentElement?.removeChild(script);\n if (!scriptSrc) return [];\n return [\n {\n src: new URL(scriptSrc.replace(NEXT_BUNDLE_PATH_RE, '/_next/'), url)\n .href,\n },\n ];\n });\n\n await loadScripts(scriptSrcs, resolveClientUrl);\n\n const hostShared = buildHostShared(shared, resolveClientUrl, {\n includePagesClientSharedGlobal: true,\n });\n const resolve = await buildWebpackResolve(\n hostShared,\n remoteShared ?? {},\n remoteBundle,\n {\n '/react/index.js': (await import('react')).default,\n '/react/jsx-dev-runtime.js': (await import('react/jsx-dev-runtime'))\n .default,\n '/react/jsx-runtime.js': (await import('react/jsx-runtime')).default,\n '/react-dom/index.js': (await import('react-dom')).default,\n '/react-dom/client.js': (await import('react-dom/client')).default,\n },\n 'WebpackRuntime',\n );\n\n // apply shared modules to the bundle\n applySharedModules(remoteBundle, resolve);\n }\n\n return {\n self,\n createFromReadableStream,\n applySharedModules,\n nextClientPagesLoader,\n preloadScripts,\n };\n}\n"]}
|