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
package/dist/config/nextjs.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunk6PZEDIAKcjs = require('../chunk-6PZEDIAK.cjs');
|
|
6
6
|
require('../chunk-Z2SLBFQL.cjs');
|
|
7
7
|
require('../chunk-5KTAEO52.cjs');
|
|
8
8
|
|
|
@@ -155,7 +155,7 @@ function withRemoteComponentsConfig(nextConfig, options) {
|
|
|
155
155
|
".remote-components/shared/pages-host.tsx"
|
|
156
156
|
);
|
|
157
157
|
const appShared = /* @__PURE__ */ new Set([
|
|
158
|
-
...
|
|
158
|
+
..._chunk6PZEDIAKcjs.CORE_REACT_SHARED_KEYS,
|
|
159
159
|
"next/navigation",
|
|
160
160
|
"next/dist/client/components/navigation",
|
|
161
161
|
"next/link",
|
|
@@ -169,7 +169,7 @@ function withRemoteComponentsConfig(nextConfig, options) {
|
|
|
169
169
|
..._nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.shared]), () => ( []))
|
|
170
170
|
]);
|
|
171
171
|
const pagesShared = /* @__PURE__ */ new Set([
|
|
172
|
-
...
|
|
172
|
+
..._chunk6PZEDIAKcjs.CORE_REACT_SHARED_KEYS,
|
|
173
173
|
"next/router",
|
|
174
174
|
"next/link",
|
|
175
175
|
"next/dist/shared/lib/image-loader",
|
|
@@ -177,7 +177,7 @@ function withRemoteComponentsConfig(nextConfig, options) {
|
|
|
177
177
|
"next/form",
|
|
178
178
|
..._nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.shared]), () => ( []))
|
|
179
179
|
]);
|
|
180
|
-
const vendorShared = { ...
|
|
180
|
+
const vendorShared = { ..._chunk6PZEDIAKcjs.VENDOR_SHARED };
|
|
181
181
|
const resolve = _enhancedresolve2.default.create.sync({
|
|
182
182
|
conditionNames: ["browser", "import", "module", "require"],
|
|
183
183
|
..._fs.existsSync.call(void 0, _path.join.call(void 0, process.cwd(), "tsconfig.json")) ? {
|
|
@@ -248,7 +248,7 @@ ${sharedManifest ? `export const sharedManifest = ${sharedManifest};
|
|
|
248
248
|
).join(",\n");
|
|
249
249
|
return generateSharedModule({
|
|
250
250
|
sharedEntries,
|
|
251
|
-
sharedManifest: `{ protocol: '${
|
|
251
|
+
sharedManifest: `{ protocol: '${_chunk6PZEDIAKcjs.SHARED_MODULE_MANIFEST_PROTOCOL}', requirements: [
|
|
252
252
|
${requirements}
|
|
253
253
|
] }`
|
|
254
254
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config/nextjs/index.ts","../../src/utils/project-id.ts","../../src/utils/project-id-env.ts","../../src/config/webpack/nextjs.ts"],"names":["readFileSync","join","findUpSync"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,WAAW,gBAAAA,eAAc,qBAAqB;AACnE,SAAS,qBAAqB;AAC9B,SAAS,UAAU,SAAS,QAAAC,OAAM,gBAAgB;AAClD,OAAO,qBAAqB;AAC5B,SAAS,cAAAC,mBAAkB;AAE3B,OAAO,gCAAgC;;;ACNvC,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;;;ACGpB,SAAS,0BAA8C;AAC5D,SACE,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI,qBACZ;AAEJ;;;ADFO,SAAS,iBAAiB,aAA6B;AAC5D,QAAM,UAAU,wBAAwB;AACxC,MAAI;AAAS,WAAO;AAEpB,MAAI;AACF,UAAM,cAAc,WAAW,wBAAwB;AAAA,MACrD,KAAK,QAAQ,IAAI;AAAA,IACnB,CAAC;AACD,QAAI,aAAa;AACf,aACE,KAAK,MAAM,aAAa,aAA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,UAAU;AAAA,QACR,cAAc;AAAA,UACZ,8BAA8B;AAAA,QAChC;AAAA,MACF;AAAA,IACF,CAAC,EAAE,SACH;AACA;AAAA,QACE;AAAA,QACA;AAAA,MAEF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,UAAM,8BACJ,oBAAoB,UACpB,8BAA8B,eAAe;AAI/C,UAAM,0BAA0B,yCAAyC;AACzE,QAAI,6BAA6B;AAC/B;AAAA,QACE;AAAA,QACA,wCAAwC;AAAA,MAE1C;AAAA,IACF,OAAO;AACL;AAAA,QACE;AAAA,QACA;AAAA,MAEF;AAAA,IACF;AACA,eAAW,YAAY;AAAA,MACrB,GAAG,WAAW;AAAA,MACd,cAAc;AAAA,QACZ,GAAG,WAAW,WAAW;AAAA,QACzB,GAAG;AAAA,MACL;AAAA,MACA,GAAI,8BACA,EAAE,oBAAoB,wBAAwB,IAC9C,CAAC;AAAA,IACP;AACA,eAAW,WAAW;AAAA,MACpB,GAAG,WAAW;AAAA,MACd,cAAc;AAAA,QACZ,GAAG,WAAW,UAAU;AAAA,QACxB,4CAA4C;AAAA,MAC9C;AAAA,IACF;AACA,oBAAgB;AAChB,WAAO;AAAA,EACT;AAGA,SAAO,UAAiB,YAAY;AAAA,IAClC,KAAK,EAAE,MAAM,UAAU;AAAA,IACvB;AAAA,IACA;AAAA,EACF,CAAC;AACH","sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { basename, dirname, join, relative } from 'node:path';\nimport enhancedResolve from 'enhanced-resolve';\nimport { findUpSync } from 'find-up';\nimport type { NextConfig } from 'next';\nimport TsConfigPathsWebpackPlugin from 'tsconfig-paths-webpack-plugin';\nimport { SHARED_MODULE_MANIFEST_PROTOCOL } from '#internal/host/shared/shared-broker';\nimport {\n CORE_REACT_SHARED_KEYS,\n VENDOR_SHARED,\n} from '#internal/host/shared/shared-module-resolver';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { resolveProjectId } from '#internal/utils/project-id';\nimport { transform as webpackTransform } from '../webpack/nextjs';\n\nfunction getNextMajorVersion(): number | undefined {\n try {\n const nextPkgPath = findUpSync('node_modules/next/package.json', {\n cwd: process.cwd(),\n });\n if (!nextPkgPath) return undefined;\n const { version } = JSON.parse(readFileSync(nextPkgPath, 'utf8')) as {\n version: string;\n };\n const major = version.split('.')[0];\n return major ? Number.parseInt(major, 10) : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction hasPagesDirectory(): boolean {\n return (\n existsSync(join(process.cwd(), 'pages')) ||\n existsSync(join(process.cwd(), 'src/pages'))\n );\n}\n\ninterface ZodSchema {\n safeParse: (data: unknown) => { success: boolean };\n}\n\n/**\n * Returns true when the installed Next.js version's config schema accepts\n * `turbopack.chunkLoadingGlobal`. The turbopack schema uses `z.strictObject`\n * so unrecognised keys fail — a successful parse means the field is present.\n *\n * Exported for unit testing.\n */\nexport function isChunkLoadingGlobalSupported(schema: ZodSchema): boolean {\n return schema.safeParse({ turbopack: { chunkLoadingGlobal: '__test__' } })\n .success;\n}\n\n/**\n * Loads `next/dist/server/config-schema.js` from the consuming app's own\n * `node_modules` (resolved from `process.cwd()`), not from the location of\n * this package. This ensures the schema reflects the exact Next.js version\n * installed in the app rather than whatever is hoisted to the workspace root.\n */\nfunction loadAppConfigSchema(): ZodSchema | undefined {\n try {\n const appRequire = createRequire(join(process.cwd(), 'package.json'));\n const mod = appRequire('next/dist/server/config-schema.js') as {\n configSchema: ZodSchema;\n };\n return mod.configSchema;\n } catch {\n return undefined;\n }\n}\n\nfunction readProjectPackageJson(): { name: string; type: string } {\n const defaults = { name: basename(process.cwd()), type: 'module' };\n try {\n const packageJsonPath = findUpSync('package.json', {\n cwd: process.cwd(),\n });\n if (packageJsonPath) {\n return {\n ...defaults,\n ...(JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {\n name: string;\n type: string;\n }),\n };\n }\n } catch {\n // noop\n }\n return defaults;\n}\n\ninterface WithRemoteComponentsOptions {\n /**\n * An array of package names that should be shared between the host and remote components.\n * This is useful for ensuring that both the host and remote components use the same version\n * of shared libraries.\n *\n * Essential packages are included by default: `react`, `react-dom`, `next/navigation`, `next/link`, `next/form`, `next/image` (loader only), and `next/script`.\n */\n shared?: string[];\n}\n\n/**\n * This function configures Next.js to support Remote Components.\n * You need to also use the `withMicrofrontends` function to extend your Next.js configuration.\n *\n * @param nextConfig - The Next.js configuration object.\n * @param options - Optional configuration for remote components.\n * @returns The modified Next.js configuration object with remote components support.\n *\n * @example\n *\n * ```js\n * import { withMicrofrontends } from '@vercel/microfrontends/next/config';\n * import { withRemoteComponentsConfig } from 'remote-components/config/nextjs';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponentsConfig(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponentsConfig(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentAppSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/app-remote.tsx',\n );\n const virtualRemoteComponentPagesSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/pages-remote.tsx',\n );\n const virtualRemoteComponentAppSharedHost = join(\n process.cwd(),\n '.remote-components/shared/app-host.tsx',\n );\n const virtualRemoteComponentPagesSharedHost = join(\n process.cwd(),\n '.remote-components/shared/pages-host.tsx',\n );\n\n const appShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/navigation',\n 'next/dist/client/components/navigation',\n 'next/link',\n 'next/dist/client/app-dir/link',\n 'next/form',\n 'next/dist/client/app-dir/form',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/dist/client/script',\n 'next/dist/build/polyfills/process',\n ...(options?.shared ?? []),\n ]);\n const pagesShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/router',\n 'next/link',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/form',\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared = { ...VENDOR_SHARED };\n\n // resolve using enhanced-resolve\n // named import does not work with enhanced-resolve when using cjs\n // eslint-disable-next-line import/no-named-as-default-member\n const resolve = enhancedResolve.create.sync({\n conditionNames: ['browser', 'import', 'module', 'require'],\n ...(existsSync(join(process.cwd(), 'tsconfig.json'))\n ? {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n plugins: [\n new TsConfigPathsWebpackPlugin({\n configFile: join(process.cwd(), 'tsconfig.json'),\n }) as unknown as enhancedResolve.Plugin,\n ],\n }\n : {}),\n });\n\n const packageJson = readProjectPackageJson();\n\n const generateSharedModule = ({\n sharedEntries,\n sharedManifest,\n }: {\n sharedEntries: string[];\n sharedManifest?: string;\n }) => {\n const shared = sharedEntries.join('\\n');\n\n if (packageJson.type !== 'module') {\n const exports = [`shared: {\\n${shared}\\n}`];\n if (sharedManifest) {\n exports.push(`sharedManifest: ${sharedManifest}`);\n }\n return `'use client';\\nmodule.exports = {\\n${exports.join(',\\n')}\\n};\\n`;\n }\n\n return `'use client';\\nexport const shared = {\\n${shared}\\n};\\n${\n sharedManifest ? `export const sharedManifest = ${sharedManifest};\\n` : ''\n }`;\n };\n\n const resolveSharedPath = (moduleName: string): string | undefined => {\n try {\n const resolved = resolve(process.cwd(), moduleName);\n if (resolved) {\n return relative(process.cwd(), resolved).replace(\n /^(?<relative>\\.\\.\\/)+/,\n '',\n );\n }\n } catch {\n // if module resolution using enhanced-resolve fails, fallback to require.resolve called in the shared/remote file\n }\n };\n\n const sharedKeyExpression = (moduleName: string): string => {\n const path = resolveSharedPath(moduleName);\n return (\n vendorShared[moduleName] ??\n (path ? `'${path}'` : `require.resolve('${moduleName}')`)\n );\n };\n\n const generateSharedRemote = (sharedRemote: Set<string>) => {\n const sharedEntries = Array.from(sharedRemote).reduce<string[]>(\n (acc, curr) => {\n const id = sharedKeyExpression(curr);\n // @legacy(remote-components<=0.4.x): keep emitting the historical\n // shared map until hosts on 0.4.x are outside the compatibility window.\n acc.push(`[${id}]: '${curr}',`);\n acc.push(\n `['__remote_shared_module_${curr}']: () => import('${curr}'),`,\n );\n return acc;\n },\n [],\n );\n const requirements = Array.from(sharedRemote)\n .map(\n (curr) =>\n `{ id: ${sharedKeyExpression(curr)}, specifier: '${curr}', required: true, singleton: true }`,\n )\n .join(',\\n');\n return generateSharedModule({\n sharedEntries,\n sharedManifest: `{ protocol: '${SHARED_MODULE_MANIFEST_PROTOCOL}', requirements: [\\n${requirements}\\n] }`,\n });\n };\n const generateSharedHost = (sharedHost: Set<string>) =>\n generateSharedModule({\n sharedEntries: Array.from(sharedHost).reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, []),\n });\n\n const appSharedRemote = generateSharedRemote(appShared);\n const pagesSharedRemote = generateSharedRemote(pagesShared);\n\n const appSharedHost = generateSharedHost(appShared);\n const pagesSharedHost = generateSharedHost(pagesShared);\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentAppSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(\n virtualRemoteComponentAppSharedRemote,\n appSharedRemote,\n 'utf-8',\n );\n writeFileSync(\n virtualRemoteComponentPagesSharedRemote,\n pagesSharedRemote,\n 'utf-8',\n );\n writeFileSync(virtualRemoteComponentAppSharedHost, appSharedHost, 'utf-8');\n writeFileSync(\n virtualRemoteComponentPagesSharedHost,\n pagesSharedHost,\n 'utf-8',\n );\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components',\n ];\n\n nextConfig.env = {\n ...nextConfig.env,\n REMOTE_COMPONENTS_CONFIGURED: '1',\n };\n\n const alias = {\n '#remote-components/remote/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedRemote,\n )}`,\n '#remote-components/remote/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedRemote,\n )}`,\n '#remote-components/host/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedHost,\n )}`,\n '#remote-components/host/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedHost,\n )}`,\n };\n\n const projectId = resolveProjectId(packageJson.name);\n process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;\n\n if (hasPagesDirectory()) {\n // Log instead of throwing for the version check because\n // withRemoteComponentsConfig is shared by both hosts and remotes.\n // Only Pages Router hosts are broken on Next.js < 16 — remotes\n // work fine and must not have their builds blocked.\n const nextMajor = getNextMajorVersion();\n if (nextMajor !== undefined && nextMajor < 16) {\n const log =\n process.env.NODE_ENV !== 'production' ||\n process.env.VERCEL_ENV === 'preview'\n ? logWarn\n : logDebug;\n log(\n 'Config',\n `Remote Components does not support Pages Router hosts on Next.js ${nextMajor}. ` +\n 'Pages Router remotes are unaffected. Upgrade to Next.js 16+ for host support.',\n );\n }\n }\n\n if (process.env.TURBOPACK) {\n const appConfigSchema = loadAppConfigSchema();\n if (\n !appConfigSchema?.safeParse({\n turbopack: {\n resolveAlias: {\n ...alias,\n },\n },\n compiler: {\n defineServer: {\n REMOTE_COMPONENTS_PROJECT_ID: projectId,\n },\n },\n }).success\n ) {\n logError(\n 'Config',\n 'Turbopack support requires a Next.js version that includes `compiler.defineServer`. ' +\n 'Upgrade Next.js to continue using Remote Components with Turbopack.',\n );\n process.exit(1);\n }\n const chunkLoadingGlobalSupported =\n appConfigSchema !== undefined &&\n isChunkLoadingGlobalSupported(appConfigSchema);\n // Next.js auto-prefixes chunkLoadingGlobal with \"TURBOPACK_\" when the value\n // doesn't already start with it. We set the prefix ourselves so the final\n // global name is predictable: TURBOPACK_remote_chunk_loading_global_<id>.\n const chunkLoadingGlobalValue = `TURBOPACK_remote_chunk_loading_global_${projectId}`;\n if (chunkLoadingGlobalSupported) {\n logDebug(\n 'Config',\n `Turbopack chunkLoadingGlobal set to \"${chunkLoadingGlobalValue}\" — ` +\n 'chunks will use a build-time scoped global (no runtime TURBOPACK rename needed).',\n );\n } else {\n logDebug(\n 'Config',\n 'Turbopack chunkLoadingGlobal not supported by this Next.js version — ' +\n 'falling back to runtime TURBOPACK global rename.',\n );\n }\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n ...alias,\n },\n ...(chunkLoadingGlobalSupported\n ? { chunkLoadingGlobal: chunkLoadingGlobalValue }\n : {}),\n };\n nextConfig.compiler = {\n ...nextConfig.compiler,\n defineServer: {\n ...nextConfig.compiler?.defineServer,\n 'process.env.REMOTE_COMPONENTS_PROJECT_ID': projectId,\n },\n };\n emitSharedFiles();\n return nextConfig;\n }\n\n // apply the webpack transform\n return webpackTransform(nextConfig, {\n app: { name: projectId },\n alias,\n emitSharedFiles,\n });\n}\n","import { readFileSync } from 'node:fs';\nimport { findUpSync } from 'find-up';\nimport { resolveProjectIdFromEnv } from './project-id-env';\n\n/**\n * Resolves the project ID using environment variables first, then\n * falling back to `.vercel/project.json` and finally the package name.\n * Node-only — requires file system access.\n */\nexport function resolveProjectId(packageName: string): string {\n const fromEnv = resolveProjectIdFromEnv();\n if (fromEnv) return fromEnv;\n\n try {\n const projectPath = findUpSync('.vercel/project.json', {\n cwd: process.cwd(),\n });\n if (projectPath) {\n return (\n JSON.parse(readFileSync(projectPath, 'utf8')) as { projectId: string }\n ).projectId;\n }\n } catch {\n // fallback below\n }\n\n return packageName;\n}\n","/**\n * Resolves the project ID from environment variables only.\n * Safe for edge/browser contexts where file system access is unavailable.\n */\nexport function resolveProjectIdFromEnv(): string | undefined {\n return (\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID ||\n undefined\n );\n}\n","import { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { PatchRequirePlugin } from './plugins/patch-require';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\n\nexport function transform(\n nextConfig: NextConfig,\n {\n app,\n alias = {},\n emitSharedFiles = () => {\n // no-op by default\n },\n }: {\n app: { name: string };\n alias?: Record<string, string>;\n emitSharedFiles?: () => void;\n },\n) {\n const webpackConfig = nextConfig.webpack;\n\n nextConfig.webpack = (\n baseConfig: WebpackOptionsNormalized,\n webpackContext,\n ) => {\n // execute the client config first, otherwise their config may accidentally\n // overwrite our required config - leading to unexpected errors.\n const config = (\n typeof webpackConfig === 'function'\n ? (webpackConfig(baseConfig, webpackContext) ?? baseConfig)\n : baseConfig\n ) as WebpackOptionsNormalized;\n\n // remote component specific plugins\n config.plugins.push(\n new RemoteWebpackRequirePlugin(app.name),\n new ModuleIdEmbedPlugin(app.name, { isServer: webpackContext.isServer }),\n new ConditionalExecPlugin(app.name),\n new PatchRequirePlugin(app.name),\n );\n if (!webpackContext.isServer) {\n // change the chunk loading global to avoid conflicts with other remote components\n config.output.chunkLoadingGlobal = `__remote_chunk_loading_global_${app.name}__`;\n }\n\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve.alias,\n ...Object.fromEntries(\n Object.entries(alias).map(([key, value]) => [\n key,\n join(process.cwd(), value),\n ]),\n ),\n },\n };\n\n emitSharedFiles();\n return config;\n };\n\n return nextConfig;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/config/nextjs/index.ts","../../src/utils/project-id.ts","../../src/utils/project-id-env.ts","../../src/config/webpack/nextjs.ts"],"names":["readFileSync","join","findUpSync"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,WAAW,gBAAAA,eAAc,qBAAqB;AACnE,SAAS,qBAAqB;AAC9B,SAAS,UAAU,SAAS,QAAAC,OAAM,gBAAgB;AAClD,OAAO,qBAAqB;AAC5B,SAAS,cAAAC,mBAAkB;AAE3B,OAAO,gCAAgC;;;ACNvC,SAAS,oBAAoB;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ileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { basename, dirname, join, relative } from 'node:path';\nimport enhancedResolve from 'enhanced-resolve';\nimport { findUpSync } from 'find-up';\nimport type { NextConfig } from 'next';\nimport TsConfigPathsWebpackPlugin from 'tsconfig-paths-webpack-plugin';\nimport { SHARED_MODULE_MANIFEST_PROTOCOL } from '#internal/host/shared/shared-broker';\nimport {\n CORE_REACT_SHARED_KEYS,\n VENDOR_SHARED,\n} from '#internal/host/shared/shared-module-resolver';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { resolveProjectId } from '#internal/utils/project-id';\nimport { transform as webpackTransform } from '../webpack/nextjs';\n\nfunction getNextMajorVersion(): number | undefined {\n try {\n const nextPkgPath = findUpSync('node_modules/next/package.json', {\n cwd: process.cwd(),\n });\n if (!nextPkgPath) return undefined;\n const { version } = JSON.parse(readFileSync(nextPkgPath, 'utf8')) as {\n version: string;\n };\n const major = version.split('.')[0];\n return major ? Number.parseInt(major, 10) : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction hasPagesDirectory(): boolean {\n return (\n existsSync(join(process.cwd(), 'pages')) ||\n existsSync(join(process.cwd(), 'src/pages'))\n );\n}\n\ninterface ZodSchema {\n safeParse: (data: unknown) => { success: boolean };\n}\n\n/**\n * Returns true when the installed Next.js version's config schema accepts\n * `turbopack.chunkLoadingGlobal`. The turbopack schema uses `z.strictObject`\n * so unrecognised keys fail — a successful parse means the field is present.\n *\n * Exported for unit testing.\n */\nexport function isChunkLoadingGlobalSupported(schema: ZodSchema): boolean {\n return schema.safeParse({ turbopack: { chunkLoadingGlobal: '__test__' } })\n .success;\n}\n\n/**\n * Loads `next/dist/server/config-schema.js` from the consuming app's own\n * `node_modules` (resolved from `process.cwd()`), not from the location of\n * this package. This ensures the schema reflects the exact Next.js version\n * installed in the app rather than whatever is hoisted to the workspace root.\n */\nfunction loadAppConfigSchema(): ZodSchema | undefined {\n try {\n const appRequire = createRequire(join(process.cwd(), 'package.json'));\n const mod = appRequire('next/dist/server/config-schema.js') as {\n configSchema: ZodSchema;\n };\n return mod.configSchema;\n } catch {\n return undefined;\n }\n}\n\nfunction readProjectPackageJson(): { name: string; type: string } {\n const defaults = { name: basename(process.cwd()), type: 'module' };\n try {\n const packageJsonPath = findUpSync('package.json', {\n cwd: process.cwd(),\n });\n if (packageJsonPath) {\n return {\n ...defaults,\n ...(JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {\n name: string;\n type: string;\n }),\n };\n }\n } catch {\n // noop\n }\n return defaults;\n}\n\ninterface WithRemoteComponentsOptions {\n /**\n * An array of package names that should be shared between the host and remote components.\n * This is useful for ensuring that both the host and remote components use the same version\n * of shared libraries.\n *\n * Essential packages are included by default: `react`, `react-dom`, `next/navigation`, `next/link`, `next/form`, `next/image` (loader only), and `next/script`.\n */\n shared?: string[];\n}\n\n/**\n * This function configures Next.js to support Remote Components.\n * You need to also use the `withMicrofrontends` function to extend your Next.js configuration.\n *\n * @param nextConfig - The Next.js configuration object.\n * @param options - Optional configuration for remote components.\n * @returns The modified Next.js configuration object with remote components support.\n *\n * @example\n *\n * ```js\n * import { withMicrofrontends } from '@vercel/microfrontends/next/config';\n * import { withRemoteComponentsConfig } from 'remote-components/config/nextjs';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponentsConfig(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponentsConfig(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentAppSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/app-remote.tsx',\n );\n const virtualRemoteComponentPagesSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/pages-remote.tsx',\n );\n const virtualRemoteComponentAppSharedHost = join(\n process.cwd(),\n '.remote-components/shared/app-host.tsx',\n );\n const virtualRemoteComponentPagesSharedHost = join(\n process.cwd(),\n '.remote-components/shared/pages-host.tsx',\n );\n\n const appShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/navigation',\n 'next/dist/client/components/navigation',\n 'next/link',\n 'next/dist/client/app-dir/link',\n 'next/form',\n 'next/dist/client/app-dir/form',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/dist/client/script',\n 'next/dist/build/polyfills/process',\n ...(options?.shared ?? []),\n ]);\n const pagesShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/router',\n 'next/link',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/form',\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared = { ...VENDOR_SHARED };\n\n // resolve using enhanced-resolve\n // named import does not work with enhanced-resolve when using cjs\n // eslint-disable-next-line import/no-named-as-default-member\n const resolve = enhancedResolve.create.sync({\n conditionNames: ['browser', 'import', 'module', 'require'],\n ...(existsSync(join(process.cwd(), 'tsconfig.json'))\n ? {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n plugins: [\n new TsConfigPathsWebpackPlugin({\n configFile: join(process.cwd(), 'tsconfig.json'),\n }) as unknown as enhancedResolve.Plugin,\n ],\n }\n : {}),\n });\n\n const packageJson = readProjectPackageJson();\n\n const generateSharedModule = ({\n sharedEntries,\n sharedManifest,\n }: {\n sharedEntries: string[];\n sharedManifest?: string;\n }) => {\n const shared = sharedEntries.join('\\n');\n\n if (packageJson.type !== 'module') {\n const exports = [`shared: {\\n${shared}\\n}`];\n if (sharedManifest) {\n exports.push(`sharedManifest: ${sharedManifest}`);\n }\n return `'use client';\\nmodule.exports = {\\n${exports.join(',\\n')}\\n};\\n`;\n }\n\n return `'use client';\\nexport const shared = {\\n${shared}\\n};\\n${\n sharedManifest ? `export const sharedManifest = ${sharedManifest};\\n` : ''\n }`;\n };\n\n const resolveSharedPath = (moduleName: string): string | undefined => {\n try {\n const resolved = resolve(process.cwd(), moduleName);\n if (resolved) {\n return relative(process.cwd(), resolved).replace(\n /^(?<relative>\\.\\.\\/)+/,\n '',\n );\n }\n } catch {\n // if module resolution using enhanced-resolve fails, fallback to require.resolve called in the shared/remote file\n }\n };\n\n const sharedKeyExpression = (moduleName: string): string => {\n const path = resolveSharedPath(moduleName);\n return (\n vendorShared[moduleName] ??\n (path ? `'${path}'` : `require.resolve('${moduleName}')`)\n );\n };\n\n const generateSharedRemote = (sharedRemote: Set<string>) => {\n const sharedEntries = Array.from(sharedRemote).reduce<string[]>(\n (acc, curr) => {\n const id = sharedKeyExpression(curr);\n // @legacy(remote-components<=0.4.x): keep emitting the historical\n // [module id]: specifier shared map until hosts on 0.4.x are outside\n // the compatibility window. The sharedManifest below is the primary\n // contract for new hosts.\n acc.push(`[${id}]: '${curr}',`);\n acc.push(\n `['__remote_shared_module_${curr}']: () => import('${curr}'),`,\n );\n return acc;\n },\n [],\n );\n const requirements = Array.from(sharedRemote)\n .map(\n (curr) =>\n `{ id: ${sharedKeyExpression(curr)}, specifier: '${curr}', required: true, singleton: true }`,\n )\n .join(',\\n');\n return generateSharedModule({\n sharedEntries,\n sharedManifest: `{ protocol: '${SHARED_MODULE_MANIFEST_PROTOCOL}', requirements: [\\n${requirements}\\n] }`,\n });\n };\n const generateSharedHost = (sharedHost: Set<string>) =>\n generateSharedModule({\n sharedEntries: Array.from(sharedHost).reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, []),\n });\n\n const appSharedRemote = generateSharedRemote(appShared);\n const pagesSharedRemote = generateSharedRemote(pagesShared);\n\n const appSharedHost = generateSharedHost(appShared);\n const pagesSharedHost = generateSharedHost(pagesShared);\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentAppSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(\n virtualRemoteComponentAppSharedRemote,\n appSharedRemote,\n 'utf-8',\n );\n writeFileSync(\n virtualRemoteComponentPagesSharedRemote,\n pagesSharedRemote,\n 'utf-8',\n );\n writeFileSync(virtualRemoteComponentAppSharedHost, appSharedHost, 'utf-8');\n writeFileSync(\n virtualRemoteComponentPagesSharedHost,\n pagesSharedHost,\n 'utf-8',\n );\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components',\n ];\n\n nextConfig.env = {\n ...nextConfig.env,\n REMOTE_COMPONENTS_CONFIGURED: '1',\n };\n\n const alias = {\n '#remote-components/remote/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedRemote,\n )}`,\n '#remote-components/remote/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedRemote,\n )}`,\n '#remote-components/host/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedHost,\n )}`,\n '#remote-components/host/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedHost,\n )}`,\n };\n\n const projectId = resolveProjectId(packageJson.name);\n process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;\n\n if (hasPagesDirectory()) {\n // Log instead of throwing for the version check because\n // withRemoteComponentsConfig is shared by both hosts and remotes.\n // Only Pages Router hosts are broken on Next.js < 16 — remotes\n // work fine and must not have their builds blocked.\n const nextMajor = getNextMajorVersion();\n if (nextMajor !== undefined && nextMajor < 16) {\n const log =\n process.env.NODE_ENV !== 'production' ||\n process.env.VERCEL_ENV === 'preview'\n ? logWarn\n : logDebug;\n log(\n 'Config',\n `Remote Components does not support Pages Router hosts on Next.js ${nextMajor}. ` +\n 'Pages Router remotes are unaffected. Upgrade to Next.js 16+ for host support.',\n );\n }\n }\n\n if (process.env.TURBOPACK) {\n const appConfigSchema = loadAppConfigSchema();\n if (\n !appConfigSchema?.safeParse({\n turbopack: {\n resolveAlias: {\n ...alias,\n },\n },\n compiler: {\n defineServer: {\n REMOTE_COMPONENTS_PROJECT_ID: projectId,\n },\n },\n }).success\n ) {\n logError(\n 'Config',\n 'Turbopack support requires a Next.js version that includes `compiler.defineServer`. ' +\n 'Upgrade Next.js to continue using Remote Components with Turbopack.',\n );\n process.exit(1);\n }\n const chunkLoadingGlobalSupported =\n appConfigSchema !== undefined &&\n isChunkLoadingGlobalSupported(appConfigSchema);\n // Next.js auto-prefixes chunkLoadingGlobal with \"TURBOPACK_\" when the value\n // doesn't already start with it. We set the prefix ourselves so the final\n // global name is predictable: TURBOPACK_remote_chunk_loading_global_<id>.\n const chunkLoadingGlobalValue = `TURBOPACK_remote_chunk_loading_global_${projectId}`;\n if (chunkLoadingGlobalSupported) {\n logDebug(\n 'Config',\n `Turbopack chunkLoadingGlobal set to \"${chunkLoadingGlobalValue}\" — ` +\n 'chunks will use a build-time scoped global (no runtime TURBOPACK rename needed).',\n );\n } else {\n logDebug(\n 'Config',\n 'Turbopack chunkLoadingGlobal not supported by this Next.js version — ' +\n 'falling back to runtime TURBOPACK global rename.',\n );\n }\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n ...alias,\n },\n ...(chunkLoadingGlobalSupported\n ? { chunkLoadingGlobal: chunkLoadingGlobalValue }\n : {}),\n };\n nextConfig.compiler = {\n ...nextConfig.compiler,\n defineServer: {\n ...nextConfig.compiler?.defineServer,\n 'process.env.REMOTE_COMPONENTS_PROJECT_ID': projectId,\n },\n };\n emitSharedFiles();\n return nextConfig;\n }\n\n // apply the webpack transform\n return webpackTransform(nextConfig, {\n app: { name: projectId },\n alias,\n emitSharedFiles,\n });\n}\n","import { readFileSync } from 'node:fs';\nimport { findUpSync } from 'find-up';\nimport { resolveProjectIdFromEnv } from './project-id-env';\n\n/**\n * Resolves the project ID using environment variables first, then\n * falling back to `.vercel/project.json` and finally the package name.\n * Node-only — requires file system access.\n */\nexport function resolveProjectId(packageName: string): string {\n const fromEnv = resolveProjectIdFromEnv();\n if (fromEnv) return fromEnv;\n\n try {\n const projectPath = findUpSync('.vercel/project.json', {\n cwd: process.cwd(),\n });\n if (projectPath) {\n return (\n JSON.parse(readFileSync(projectPath, 'utf8')) as { projectId: string }\n ).projectId;\n }\n } catch {\n // fallback below\n }\n\n return packageName;\n}\n","/**\n * Resolves the project ID from environment variables only.\n * Safe for edge/browser contexts where file system access is unavailable.\n */\nexport function resolveProjectIdFromEnv(): string | undefined {\n return (\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID ||\n undefined\n );\n}\n","import { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { PatchRequirePlugin } from './plugins/patch-require';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\n\nexport function transform(\n nextConfig: NextConfig,\n {\n app,\n alias = {},\n emitSharedFiles = () => {\n // no-op by default\n },\n }: {\n app: { name: string };\n alias?: Record<string, string>;\n emitSharedFiles?: () => void;\n },\n) {\n const webpackConfig = nextConfig.webpack;\n\n nextConfig.webpack = (\n baseConfig: WebpackOptionsNormalized,\n webpackContext,\n ) => {\n // execute the client config first, otherwise their config may accidentally\n // overwrite our required config - leading to unexpected errors.\n const config = (\n typeof webpackConfig === 'function'\n ? (webpackConfig(baseConfig, webpackContext) ?? baseConfig)\n : baseConfig\n ) as WebpackOptionsNormalized;\n\n // remote component specific plugins\n config.plugins.push(\n new RemoteWebpackRequirePlugin(app.name),\n new ModuleIdEmbedPlugin(app.name, { isServer: webpackContext.isServer }),\n new ConditionalExecPlugin(app.name),\n new PatchRequirePlugin(app.name),\n );\n if (!webpackContext.isServer) {\n // change the chunk loading global to avoid conflicts with other remote components\n config.output.chunkLoadingGlobal = `__remote_chunk_loading_global_${app.name}__`;\n }\n\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve.alias,\n ...Object.fromEntries(\n Object.entries(alias).map(([key, value]) => [\n key,\n join(process.cwd(), value),\n ]),\n ),\n },\n };\n\n emitSharedFiles();\n return config;\n };\n\n return nextConfig;\n}\n"]}
|
package/dist/config/nextjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config/nextjs/index.ts","../../src/utils/project-id.ts","../../src/utils/project-id-env.ts","../../src/config/webpack/nextjs.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { basename, dirname, join, relative } from 'node:path';\nimport enhancedResolve from 'enhanced-resolve';\nimport { findUpSync } from 'find-up';\nimport type { NextConfig } from 'next';\nimport TsConfigPathsWebpackPlugin from 'tsconfig-paths-webpack-plugin';\nimport { SHARED_MODULE_MANIFEST_PROTOCOL } from '#internal/host/shared/shared-broker';\nimport {\n CORE_REACT_SHARED_KEYS,\n VENDOR_SHARED,\n} from '#internal/host/shared/shared-module-resolver';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { resolveProjectId } from '#internal/utils/project-id';\nimport { transform as webpackTransform } from '../webpack/nextjs';\n\nfunction getNextMajorVersion(): number | undefined {\n try {\n const nextPkgPath = findUpSync('node_modules/next/package.json', {\n cwd: process.cwd(),\n });\n if (!nextPkgPath) return undefined;\n const { version } = JSON.parse(readFileSync(nextPkgPath, 'utf8')) as {\n version: string;\n };\n const major = version.split('.')[0];\n return major ? Number.parseInt(major, 10) : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction hasPagesDirectory(): boolean {\n return (\n existsSync(join(process.cwd(), 'pages')) ||\n existsSync(join(process.cwd(), 'src/pages'))\n );\n}\n\ninterface ZodSchema {\n safeParse: (data: unknown) => { success: boolean };\n}\n\n/**\n * Returns true when the installed Next.js version's config schema accepts\n * `turbopack.chunkLoadingGlobal`. The turbopack schema uses `z.strictObject`\n * so unrecognised keys fail — a successful parse means the field is present.\n *\n * Exported for unit testing.\n */\nexport function isChunkLoadingGlobalSupported(schema: ZodSchema): boolean {\n return schema.safeParse({ turbopack: { chunkLoadingGlobal: '__test__' } })\n .success;\n}\n\n/**\n * Loads `next/dist/server/config-schema.js` from the consuming app's own\n * `node_modules` (resolved from `process.cwd()`), not from the location of\n * this package. This ensures the schema reflects the exact Next.js version\n * installed in the app rather than whatever is hoisted to the workspace root.\n */\nfunction loadAppConfigSchema(): ZodSchema | undefined {\n try {\n const appRequire = createRequire(join(process.cwd(), 'package.json'));\n const mod = appRequire('next/dist/server/config-schema.js') as {\n configSchema: ZodSchema;\n };\n return mod.configSchema;\n } catch {\n return undefined;\n }\n}\n\nfunction readProjectPackageJson(): { name: string; type: string } {\n const defaults = { name: basename(process.cwd()), type: 'module' };\n try {\n const packageJsonPath = findUpSync('package.json', {\n cwd: process.cwd(),\n });\n if (packageJsonPath) {\n return {\n ...defaults,\n ...(JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {\n name: string;\n type: string;\n }),\n };\n }\n } catch {\n // noop\n }\n return defaults;\n}\n\ninterface WithRemoteComponentsOptions {\n /**\n * An array of package names that should be shared between the host and remote components.\n * This is useful for ensuring that both the host and remote components use the same version\n * of shared libraries.\n *\n * Essential packages are included by default: `react`, `react-dom`, `next/navigation`, `next/link`, `next/form`, `next/image` (loader only), and `next/script`.\n */\n shared?: string[];\n}\n\n/**\n * This function configures Next.js to support Remote Components.\n * You need to also use the `withMicrofrontends` function to extend your Next.js configuration.\n *\n * @param nextConfig - The Next.js configuration object.\n * @param options - Optional configuration for remote components.\n * @returns The modified Next.js configuration object with remote components support.\n *\n * @example\n *\n * ```js\n * import { withMicrofrontends } from '@vercel/microfrontends/next/config';\n * import { withRemoteComponentsConfig } from 'remote-components/config/nextjs';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponentsConfig(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponentsConfig(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentAppSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/app-remote.tsx',\n );\n const virtualRemoteComponentPagesSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/pages-remote.tsx',\n );\n const virtualRemoteComponentAppSharedHost = join(\n process.cwd(),\n '.remote-components/shared/app-host.tsx',\n );\n const virtualRemoteComponentPagesSharedHost = join(\n process.cwd(),\n '.remote-components/shared/pages-host.tsx',\n );\n\n const appShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/navigation',\n 'next/dist/client/components/navigation',\n 'next/link',\n 'next/dist/client/app-dir/link',\n 'next/form',\n 'next/dist/client/app-dir/form',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/dist/client/script',\n 'next/dist/build/polyfills/process',\n ...(options?.shared ?? []),\n ]);\n const pagesShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/router',\n 'next/link',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/form',\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared = { ...VENDOR_SHARED };\n\n // resolve using enhanced-resolve\n // named import does not work with enhanced-resolve when using cjs\n // eslint-disable-next-line import/no-named-as-default-member\n const resolve = enhancedResolve.create.sync({\n conditionNames: ['browser', 'import', 'module', 'require'],\n ...(existsSync(join(process.cwd(), 'tsconfig.json'))\n ? {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n plugins: [\n new TsConfigPathsWebpackPlugin({\n configFile: join(process.cwd(), 'tsconfig.json'),\n }) as unknown as enhancedResolve.Plugin,\n ],\n }\n : {}),\n });\n\n const packageJson = readProjectPackageJson();\n\n const generateSharedModule = ({\n sharedEntries,\n sharedManifest,\n }: {\n sharedEntries: string[];\n sharedManifest?: string;\n }) => {\n const shared = sharedEntries.join('\\n');\n\n if (packageJson.type !== 'module') {\n const exports = [`shared: {\\n${shared}\\n}`];\n if (sharedManifest) {\n exports.push(`sharedManifest: ${sharedManifest}`);\n }\n return `'use client';\\nmodule.exports = {\\n${exports.join(',\\n')}\\n};\\n`;\n }\n\n return `'use client';\\nexport const shared = {\\n${shared}\\n};\\n${\n sharedManifest ? `export const sharedManifest = ${sharedManifest};\\n` : ''\n }`;\n };\n\n const resolveSharedPath = (moduleName: string): string | undefined => {\n try {\n const resolved = resolve(process.cwd(), moduleName);\n if (resolved) {\n return relative(process.cwd(), resolved).replace(\n /^(?<relative>\\.\\.\\/)+/,\n '',\n );\n }\n } catch {\n // if module resolution using enhanced-resolve fails, fallback to require.resolve called in the shared/remote file\n }\n };\n\n const sharedKeyExpression = (moduleName: string): string => {\n const path = resolveSharedPath(moduleName);\n return (\n vendorShared[moduleName] ??\n (path ? `'${path}'` : `require.resolve('${moduleName}')`)\n );\n };\n\n const generateSharedRemote = (sharedRemote: Set<string>) => {\n const sharedEntries = Array.from(sharedRemote).reduce<string[]>(\n (acc, curr) => {\n const id = sharedKeyExpression(curr);\n // @legacy(remote-components<=0.4.x): keep emitting the historical\n // shared map until hosts on 0.4.x are outside the compatibility window.\n acc.push(`[${id}]: '${curr}',`);\n acc.push(\n `['__remote_shared_module_${curr}']: () => import('${curr}'),`,\n );\n return acc;\n },\n [],\n );\n const requirements = Array.from(sharedRemote)\n .map(\n (curr) =>\n `{ id: ${sharedKeyExpression(curr)}, specifier: '${curr}', required: true, singleton: true }`,\n )\n .join(',\\n');\n return generateSharedModule({\n sharedEntries,\n sharedManifest: `{ protocol: '${SHARED_MODULE_MANIFEST_PROTOCOL}', requirements: [\\n${requirements}\\n] }`,\n });\n };\n const generateSharedHost = (sharedHost: Set<string>) =>\n generateSharedModule({\n sharedEntries: Array.from(sharedHost).reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, []),\n });\n\n const appSharedRemote = generateSharedRemote(appShared);\n const pagesSharedRemote = generateSharedRemote(pagesShared);\n\n const appSharedHost = generateSharedHost(appShared);\n const pagesSharedHost = generateSharedHost(pagesShared);\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentAppSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(\n virtualRemoteComponentAppSharedRemote,\n appSharedRemote,\n 'utf-8',\n );\n writeFileSync(\n virtualRemoteComponentPagesSharedRemote,\n pagesSharedRemote,\n 'utf-8',\n );\n writeFileSync(virtualRemoteComponentAppSharedHost, appSharedHost, 'utf-8');\n writeFileSync(\n virtualRemoteComponentPagesSharedHost,\n pagesSharedHost,\n 'utf-8',\n );\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components',\n ];\n\n nextConfig.env = {\n ...nextConfig.env,\n REMOTE_COMPONENTS_CONFIGURED: '1',\n };\n\n const alias = {\n '#remote-components/remote/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedRemote,\n )}`,\n '#remote-components/remote/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedRemote,\n )}`,\n '#remote-components/host/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedHost,\n )}`,\n '#remote-components/host/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedHost,\n )}`,\n };\n\n const projectId = resolveProjectId(packageJson.name);\n process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;\n\n if (hasPagesDirectory()) {\n // Log instead of throwing for the version check because\n // withRemoteComponentsConfig is shared by both hosts and remotes.\n // Only Pages Router hosts are broken on Next.js < 16 — remotes\n // work fine and must not have their builds blocked.\n const nextMajor = getNextMajorVersion();\n if (nextMajor !== undefined && nextMajor < 16) {\n const log =\n process.env.NODE_ENV !== 'production' ||\n process.env.VERCEL_ENV === 'preview'\n ? logWarn\n : logDebug;\n log(\n 'Config',\n `Remote Components does not support Pages Router hosts on Next.js ${nextMajor}. ` +\n 'Pages Router remotes are unaffected. Upgrade to Next.js 16+ for host support.',\n );\n }\n }\n\n if (process.env.TURBOPACK) {\n const appConfigSchema = loadAppConfigSchema();\n if (\n !appConfigSchema?.safeParse({\n turbopack: {\n resolveAlias: {\n ...alias,\n },\n },\n compiler: {\n defineServer: {\n REMOTE_COMPONENTS_PROJECT_ID: projectId,\n },\n },\n }).success\n ) {\n logError(\n 'Config',\n 'Turbopack support requires a Next.js version that includes `compiler.defineServer`. ' +\n 'Upgrade Next.js to continue using Remote Components with Turbopack.',\n );\n process.exit(1);\n }\n const chunkLoadingGlobalSupported =\n appConfigSchema !== undefined &&\n isChunkLoadingGlobalSupported(appConfigSchema);\n // Next.js auto-prefixes chunkLoadingGlobal with \"TURBOPACK_\" when the value\n // doesn't already start with it. We set the prefix ourselves so the final\n // global name is predictable: TURBOPACK_remote_chunk_loading_global_<id>.\n const chunkLoadingGlobalValue = `TURBOPACK_remote_chunk_loading_global_${projectId}`;\n if (chunkLoadingGlobalSupported) {\n logDebug(\n 'Config',\n `Turbopack chunkLoadingGlobal set to \"${chunkLoadingGlobalValue}\" — ` +\n 'chunks will use a build-time scoped global (no runtime TURBOPACK rename needed).',\n );\n } else {\n logDebug(\n 'Config',\n 'Turbopack chunkLoadingGlobal not supported by this Next.js version — ' +\n 'falling back to runtime TURBOPACK global rename.',\n );\n }\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n ...alias,\n },\n ...(chunkLoadingGlobalSupported\n ? { chunkLoadingGlobal: chunkLoadingGlobalValue }\n : {}),\n };\n nextConfig.compiler = {\n ...nextConfig.compiler,\n defineServer: {\n ...nextConfig.compiler?.defineServer,\n 'process.env.REMOTE_COMPONENTS_PROJECT_ID': projectId,\n },\n };\n emitSharedFiles();\n return nextConfig;\n }\n\n // apply the webpack transform\n return webpackTransform(nextConfig, {\n app: { name: projectId },\n alias,\n emitSharedFiles,\n });\n}\n","import { readFileSync } from 'node:fs';\nimport { findUpSync } from 'find-up';\nimport { resolveProjectIdFromEnv } from './project-id-env';\n\n/**\n * Resolves the project ID using environment variables first, then\n * falling back to `.vercel/project.json` and finally the package name.\n * Node-only — requires file system access.\n */\nexport function resolveProjectId(packageName: string): string {\n const fromEnv = resolveProjectIdFromEnv();\n if (fromEnv) return fromEnv;\n\n try {\n const projectPath = findUpSync('.vercel/project.json', {\n cwd: process.cwd(),\n });\n if (projectPath) {\n return (\n JSON.parse(readFileSync(projectPath, 'utf8')) as { projectId: string }\n ).projectId;\n }\n } catch {\n // fallback below\n }\n\n return packageName;\n}\n","/**\n * Resolves the project ID from environment variables only.\n * Safe for edge/browser contexts where file system access is unavailable.\n */\nexport function resolveProjectIdFromEnv(): string | undefined {\n return (\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID ||\n undefined\n );\n}\n","import { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { PatchRequirePlugin } from './plugins/patch-require';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\n\nexport function transform(\n nextConfig: NextConfig,\n {\n app,\n alias = {},\n emitSharedFiles = () => {\n // no-op by default\n },\n }: {\n app: { name: string };\n alias?: Record<string, string>;\n emitSharedFiles?: () => void;\n },\n) {\n const webpackConfig = nextConfig.webpack;\n\n nextConfig.webpack = (\n baseConfig: WebpackOptionsNormalized,\n webpackContext,\n ) => {\n // execute the client config first, otherwise their config may accidentally\n // overwrite our required config - leading to unexpected errors.\n const config = (\n typeof webpackConfig === 'function'\n ? (webpackConfig(baseConfig, webpackContext) ?? baseConfig)\n : baseConfig\n ) as WebpackOptionsNormalized;\n\n // remote component specific plugins\n config.plugins.push(\n new RemoteWebpackRequirePlugin(app.name),\n new ModuleIdEmbedPlugin(app.name, { isServer: webpackContext.isServer }),\n new ConditionalExecPlugin(app.name),\n new PatchRequirePlugin(app.name),\n );\n if (!webpackContext.isServer) {\n // change the chunk loading global to avoid conflicts with other remote components\n config.output.chunkLoadingGlobal = `__remote_chunk_loading_global_${app.name}__`;\n }\n\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve.alias,\n ...Object.fromEntries(\n Object.entries(alias).map(([key, value]) => [\n key,\n join(process.cwd(), value),\n ]),\n ),\n },\n };\n\n emitSharedFiles();\n return config;\n };\n\n return nextConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,WAAW,gBAAAA,eAAc,qBAAqB;AACnE,SAAS,qBAAqB;AAC9B,SAAS,UAAU,SAAS,QAAAC,OAAM,gBAAgB;AAClD,OAAO,qBAAqB;AAC5B,SAAS,cAAAC,mBAAkB;AAE3B,OAAO,gCAAgC;;;ACNvC,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;;;ACGpB,SAAS,0BAA8C;AAC5D,SACE,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI,qBACZ;AAEJ;;;ADFO,SAAS,iBAAiB,aAA6B;AAC5D,QAAM,UAAU,wBAAwB;AACxC,MAAI;AAAS,WAAO;AAEpB,MAAI;AACF,UAAM,cAAc,WAAW,wBAAwB;AAAA,MACrD,KAAK,QAAQ,IAAI;AAAA,IACnB,CAAC;AACD,QAAI,aAAa;AACf,aACE,KAAK,MAAM,aAAa,aAAa,MAAM,CAAC,EAC5C;AAAA,IACJ;AAAA,EACF,QAAE;AAAA,EAEF;AAEA,SAAO;AACT;;;AE3BA,SAAS,YAAY;AAQd,SAAS,UACd,YACA;AAAA,EACE;AAAA,EACA,QAAQ,CAAC;AAAA,EACT,kBAAkB,MAAM;AAAA,EAExB;AACF,GAKA;AACA,QAAM,gBAAgB,WAAW;AAEjC,aAAW,UAAU,CACnB,YACA,mBACG;AAGH,UAAM,SACJ,OAAO,kBAAkB,aACpB,cAAc,YAAY,cAAc,KAAK,aAC9C;AAIN,WAAO,QAAQ;AAAA,MACb,IAAI,2BAA2B,IAAI,IAAI;AAAA,MACvC,IAAI,oBAAoB,IAAI,MAAM,EAAE,UAAU,eAAe,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Z,GAAG,WAAW,WAAW;AAAA,QACzB,GAAG;AAAA,MACL;AAAA,MACA,GAAI,8BACA,EAAE,oBAAoB,wBAAwB,IAC9C,CAAC;AAAA,IACP;AACA,eAAW,WAAW;AAAA,MACpB,GAAG,WAAW;AAAA,MACd,cAAc;AAAA,QACZ,GAAG,WAAW,UAAU;AAAA,QACxB,4CAA4C;AAAA,MAC9C;AAAA,IACF;AACA,oBAAgB;AAChB,WAAO;AAAA,EACT;AAGA,SAAO,UAAiB,YAAY;AAAA,IAClC,KAAK,EAAE,MAAM,UAAU;AAAA,IACvB;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["readFileSync","join","findUpSync","findUpSync","readFileSync","join"]}
|
|
1
|
+
{"version":3,"sources":["../../src/config/nextjs/index.ts","../../src/utils/project-id.ts","../../src/utils/project-id-env.ts","../../src/config/webpack/nextjs.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { basename, dirname, join, relative } from 'node:path';\nimport enhancedResolve from 'enhanced-resolve';\nimport { findUpSync } from 'find-up';\nimport type { NextConfig } from 'next';\nimport TsConfigPathsWebpackPlugin from 'tsconfig-paths-webpack-plugin';\nimport { SHARED_MODULE_MANIFEST_PROTOCOL } from '#internal/host/shared/shared-broker';\nimport {\n CORE_REACT_SHARED_KEYS,\n VENDOR_SHARED,\n} from '#internal/host/shared/shared-module-resolver';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { resolveProjectId } from '#internal/utils/project-id';\nimport { transform as webpackTransform } from '../webpack/nextjs';\n\nfunction getNextMajorVersion(): number | undefined {\n try {\n const nextPkgPath = findUpSync('node_modules/next/package.json', {\n cwd: process.cwd(),\n });\n if (!nextPkgPath) return undefined;\n const { version } = JSON.parse(readFileSync(nextPkgPath, 'utf8')) as {\n version: string;\n };\n const major = version.split('.')[0];\n return major ? Number.parseInt(major, 10) : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction hasPagesDirectory(): boolean {\n return (\n existsSync(join(process.cwd(), 'pages')) ||\n existsSync(join(process.cwd(), 'src/pages'))\n );\n}\n\ninterface ZodSchema {\n safeParse: (data: unknown) => { success: boolean };\n}\n\n/**\n * Returns true when the installed Next.js version's config schema accepts\n * `turbopack.chunkLoadingGlobal`. The turbopack schema uses `z.strictObject`\n * so unrecognised keys fail — a successful parse means the field is present.\n *\n * Exported for unit testing.\n */\nexport function isChunkLoadingGlobalSupported(schema: ZodSchema): boolean {\n return schema.safeParse({ turbopack: { chunkLoadingGlobal: '__test__' } })\n .success;\n}\n\n/**\n * Loads `next/dist/server/config-schema.js` from the consuming app's own\n * `node_modules` (resolved from `process.cwd()`), not from the location of\n * this package. This ensures the schema reflects the exact Next.js version\n * installed in the app rather than whatever is hoisted to the workspace root.\n */\nfunction loadAppConfigSchema(): ZodSchema | undefined {\n try {\n const appRequire = createRequire(join(process.cwd(), 'package.json'));\n const mod = appRequire('next/dist/server/config-schema.js') as {\n configSchema: ZodSchema;\n };\n return mod.configSchema;\n } catch {\n return undefined;\n }\n}\n\nfunction readProjectPackageJson(): { name: string; type: string } {\n const defaults = { name: basename(process.cwd()), type: 'module' };\n try {\n const packageJsonPath = findUpSync('package.json', {\n cwd: process.cwd(),\n });\n if (packageJsonPath) {\n return {\n ...defaults,\n ...(JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {\n name: string;\n type: string;\n }),\n };\n }\n } catch {\n // noop\n }\n return defaults;\n}\n\ninterface WithRemoteComponentsOptions {\n /**\n * An array of package names that should be shared between the host and remote components.\n * This is useful for ensuring that both the host and remote components use the same version\n * of shared libraries.\n *\n * Essential packages are included by default: `react`, `react-dom`, `next/navigation`, `next/link`, `next/form`, `next/image` (loader only), and `next/script`.\n */\n shared?: string[];\n}\n\n/**\n * This function configures Next.js to support Remote Components.\n * You need to also use the `withMicrofrontends` function to extend your Next.js configuration.\n *\n * @param nextConfig - The Next.js configuration object.\n * @param options - Optional configuration for remote components.\n * @returns The modified Next.js configuration object with remote components support.\n *\n * @example\n *\n * ```js\n * import { withMicrofrontends } from '@vercel/microfrontends/next/config';\n * import { withRemoteComponentsConfig } from 'remote-components/config/nextjs';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponentsConfig(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponentsConfig(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentAppSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/app-remote.tsx',\n );\n const virtualRemoteComponentPagesSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/pages-remote.tsx',\n );\n const virtualRemoteComponentAppSharedHost = join(\n process.cwd(),\n '.remote-components/shared/app-host.tsx',\n );\n const virtualRemoteComponentPagesSharedHost = join(\n process.cwd(),\n '.remote-components/shared/pages-host.tsx',\n );\n\n const appShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/navigation',\n 'next/dist/client/components/navigation',\n 'next/link',\n 'next/dist/client/app-dir/link',\n 'next/form',\n 'next/dist/client/app-dir/form',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/dist/client/script',\n 'next/dist/build/polyfills/process',\n ...(options?.shared ?? []),\n ]);\n const pagesShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/router',\n 'next/link',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/form',\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared = { ...VENDOR_SHARED };\n\n // resolve using enhanced-resolve\n // named import does not work with enhanced-resolve when using cjs\n // eslint-disable-next-line import/no-named-as-default-member\n const resolve = enhancedResolve.create.sync({\n conditionNames: ['browser', 'import', 'module', 'require'],\n ...(existsSync(join(process.cwd(), 'tsconfig.json'))\n ? {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n plugins: [\n new TsConfigPathsWebpackPlugin({\n configFile: join(process.cwd(), 'tsconfig.json'),\n }) as unknown as enhancedResolve.Plugin,\n ],\n }\n : {}),\n });\n\n const packageJson = readProjectPackageJson();\n\n const generateSharedModule = ({\n sharedEntries,\n sharedManifest,\n }: {\n sharedEntries: string[];\n sharedManifest?: string;\n }) => {\n const shared = sharedEntries.join('\\n');\n\n if (packageJson.type !== 'module') {\n const exports = [`shared: {\\n${shared}\\n}`];\n if (sharedManifest) {\n exports.push(`sharedManifest: ${sharedManifest}`);\n }\n return `'use client';\\nmodule.exports = {\\n${exports.join(',\\n')}\\n};\\n`;\n }\n\n return `'use client';\\nexport const shared = {\\n${shared}\\n};\\n${\n sharedManifest ? `export const sharedManifest = ${sharedManifest};\\n` : ''\n }`;\n };\n\n const resolveSharedPath = (moduleName: string): string | undefined => {\n try {\n const resolved = resolve(process.cwd(), moduleName);\n if (resolved) {\n return relative(process.cwd(), resolved).replace(\n /^(?<relative>\\.\\.\\/)+/,\n '',\n );\n }\n } catch {\n // if module resolution using enhanced-resolve fails, fallback to require.resolve called in the shared/remote file\n }\n };\n\n const sharedKeyExpression = (moduleName: string): string => {\n const path = resolveSharedPath(moduleName);\n return (\n vendorShared[moduleName] ??\n (path ? `'${path}'` : `require.resolve('${moduleName}')`)\n );\n };\n\n const generateSharedRemote = (sharedRemote: Set<string>) => {\n const sharedEntries = Array.from(sharedRemote).reduce<string[]>(\n (acc, curr) => {\n const id = sharedKeyExpression(curr);\n // @legacy(remote-components<=0.4.x): keep emitting the historical\n // [module id]: specifier shared map until hosts on 0.4.x are outside\n // the compatibility window. The sharedManifest below is the primary\n // contract for new hosts.\n acc.push(`[${id}]: '${curr}',`);\n acc.push(\n `['__remote_shared_module_${curr}']: () => import('${curr}'),`,\n );\n return acc;\n },\n [],\n );\n const requirements = Array.from(sharedRemote)\n .map(\n (curr) =>\n `{ id: ${sharedKeyExpression(curr)}, specifier: '${curr}', required: true, singleton: true }`,\n )\n .join(',\\n');\n return generateSharedModule({\n sharedEntries,\n sharedManifest: `{ protocol: '${SHARED_MODULE_MANIFEST_PROTOCOL}', requirements: [\\n${requirements}\\n] }`,\n });\n };\n const generateSharedHost = (sharedHost: Set<string>) =>\n generateSharedModule({\n sharedEntries: Array.from(sharedHost).reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, []),\n });\n\n const appSharedRemote = generateSharedRemote(appShared);\n const pagesSharedRemote = generateSharedRemote(pagesShared);\n\n const appSharedHost = generateSharedHost(appShared);\n const pagesSharedHost = generateSharedHost(pagesShared);\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentAppSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(\n virtualRemoteComponentAppSharedRemote,\n appSharedRemote,\n 'utf-8',\n );\n writeFileSync(\n virtualRemoteComponentPagesSharedRemote,\n pagesSharedRemote,\n 'utf-8',\n );\n writeFileSync(virtualRemoteComponentAppSharedHost, appSharedHost, 'utf-8');\n writeFileSync(\n virtualRemoteComponentPagesSharedHost,\n pagesSharedHost,\n 'utf-8',\n );\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components',\n ];\n\n nextConfig.env = {\n ...nextConfig.env,\n REMOTE_COMPONENTS_CONFIGURED: '1',\n };\n\n const alias = {\n '#remote-components/remote/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedRemote,\n )}`,\n '#remote-components/remote/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedRemote,\n )}`,\n '#remote-components/host/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedHost,\n )}`,\n '#remote-components/host/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedHost,\n )}`,\n };\n\n const projectId = resolveProjectId(packageJson.name);\n process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;\n\n if (hasPagesDirectory()) {\n // Log instead of throwing for the version check because\n // withRemoteComponentsConfig is shared by both hosts and remotes.\n // Only Pages Router hosts are broken on Next.js < 16 — remotes\n // work fine and must not have their builds blocked.\n const nextMajor = getNextMajorVersion();\n if (nextMajor !== undefined && nextMajor < 16) {\n const log =\n process.env.NODE_ENV !== 'production' ||\n process.env.VERCEL_ENV === 'preview'\n ? logWarn\n : logDebug;\n log(\n 'Config',\n `Remote Components does not support Pages Router hosts on Next.js ${nextMajor}. ` +\n 'Pages Router remotes are unaffected. Upgrade to Next.js 16+ for host support.',\n );\n }\n }\n\n if (process.env.TURBOPACK) {\n const appConfigSchema = loadAppConfigSchema();\n if (\n !appConfigSchema?.safeParse({\n turbopack: {\n resolveAlias: {\n ...alias,\n },\n },\n compiler: {\n defineServer: {\n REMOTE_COMPONENTS_PROJECT_ID: projectId,\n },\n },\n }).success\n ) {\n logError(\n 'Config',\n 'Turbopack support requires a Next.js version that includes `compiler.defineServer`. ' +\n 'Upgrade Next.js to continue using Remote Components with Turbopack.',\n );\n process.exit(1);\n }\n const chunkLoadingGlobalSupported =\n appConfigSchema !== undefined &&\n isChunkLoadingGlobalSupported(appConfigSchema);\n // Next.js auto-prefixes chunkLoadingGlobal with \"TURBOPACK_\" when the value\n // doesn't already start with it. We set the prefix ourselves so the final\n // global name is predictable: TURBOPACK_remote_chunk_loading_global_<id>.\n const chunkLoadingGlobalValue = `TURBOPACK_remote_chunk_loading_global_${projectId}`;\n if (chunkLoadingGlobalSupported) {\n logDebug(\n 'Config',\n `Turbopack chunkLoadingGlobal set to \"${chunkLoadingGlobalValue}\" — ` +\n 'chunks will use a build-time scoped global (no runtime TURBOPACK rename needed).',\n );\n } else {\n logDebug(\n 'Config',\n 'Turbopack chunkLoadingGlobal not supported by this Next.js version — ' +\n 'falling back to runtime TURBOPACK global rename.',\n );\n }\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n ...alias,\n },\n ...(chunkLoadingGlobalSupported\n ? { chunkLoadingGlobal: chunkLoadingGlobalValue }\n : {}),\n };\n nextConfig.compiler = {\n ...nextConfig.compiler,\n defineServer: {\n ...nextConfig.compiler?.defineServer,\n 'process.env.REMOTE_COMPONENTS_PROJECT_ID': projectId,\n },\n };\n emitSharedFiles();\n return nextConfig;\n }\n\n // apply the webpack transform\n return webpackTransform(nextConfig, {\n app: { name: projectId },\n alias,\n emitSharedFiles,\n });\n}\n","import { readFileSync } from 'node:fs';\nimport { findUpSync } from 'find-up';\nimport { resolveProjectIdFromEnv } from './project-id-env';\n\n/**\n * Resolves the project ID using environment variables first, then\n * falling back to `.vercel/project.json` and finally the package name.\n * Node-only — requires file system access.\n */\nexport function resolveProjectId(packageName: string): string {\n const fromEnv = resolveProjectIdFromEnv();\n if (fromEnv) return fromEnv;\n\n try {\n const projectPath = findUpSync('.vercel/project.json', {\n cwd: process.cwd(),\n });\n if (projectPath) {\n return (\n JSON.parse(readFileSync(projectPath, 'utf8')) as { projectId: string }\n ).projectId;\n }\n } catch {\n // fallback below\n }\n\n return packageName;\n}\n","/**\n * Resolves the project ID from environment variables only.\n * Safe for edge/browser contexts where file system access is unavailable.\n */\nexport function resolveProjectIdFromEnv(): string | undefined {\n return (\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID ||\n undefined\n );\n}\n","import { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { PatchRequirePlugin } from './plugins/patch-require';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\n\nexport function transform(\n nextConfig: NextConfig,\n {\n app,\n alias = {},\n emitSharedFiles = () => {\n // no-op by default\n },\n }: {\n app: { name: string };\n alias?: Record<string, string>;\n emitSharedFiles?: () => void;\n },\n) {\n const webpackConfig = nextConfig.webpack;\n\n nextConfig.webpack = (\n baseConfig: WebpackOptionsNormalized,\n webpackContext,\n ) => {\n // execute the client config first, otherwise their config may accidentally\n // overwrite our required config - leading to unexpected errors.\n const config = (\n typeof webpackConfig === 'function'\n ? (webpackConfig(baseConfig, webpackContext) ?? baseConfig)\n : baseConfig\n ) as WebpackOptionsNormalized;\n\n // remote component specific plugins\n config.plugins.push(\n new RemoteWebpackRequirePlugin(app.name),\n new ModuleIdEmbedPlugin(app.name, { isServer: webpackContext.isServer }),\n new ConditionalExecPlugin(app.name),\n new PatchRequirePlugin(app.name),\n );\n if (!webpackContext.isServer) {\n // change the chunk loading global to avoid conflicts with other remote components\n config.output.chunkLoadingGlobal = `__remote_chunk_loading_global_${app.name}__`;\n }\n\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve.alias,\n ...Object.fromEntries(\n Object.entries(alias).map(([key, value]) => [\n key,\n join(process.cwd(), value),\n ]),\n ),\n },\n };\n\n emitSharedFiles();\n return config;\n };\n\n return nextConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,WAAW,gBAAAA,eAAc,qBAAqB;AACnE,SAAS,qBAAqB;AAC9B,SAAS,UAAU,SAAS,QAAAC,OAAM,gBAAgB;AAClD,OAAO,qBAAqB;AAC5B,SAAS,cAAAC,mBAAkB;AAE3B,OAAO,gCAAgC;;;ACNvC,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;;;ACGpB,SAAS,0BAA8C;AAC5D,SACE,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI,qBACZ;AAEJ;;;ADFO,SAAS,iBAAiB,aAA6B;AAC5D,QAAM,UAAU,wBAAwB;AACxC,MAAI;AAAS,WAAO;AAEpB,MAAI;AACF,UAAM,cAAc,WAAW,wBAAwB;AAAA,MACrD,KAAK,QAAQ,IAAI;AAAA,IACnB,CAAC;AACD,QAAI,aAAa;AACf,aACE,KAAK,MAAM,aAAa,aAAa,MAAM,CAAC,EAC5C;AAAA,IACJ;AAAA,E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8B;AAAA,QAChC;AAAA,MACF;AAAA,IACF,CAAC,EAAE,SACH;AACA;AAAA,QACE;AAAA,QACA;AAAA,MAEF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,UAAM,8BACJ,oBAAoB,UACpB,8BAA8B,eAAe;AAI/C,UAAM,0BAA0B,yCAAyC;AACzE,QAAI,6BAA6B;AAC/B;AAAA,QACE;AAAA,QACA,wCAAwC;AAAA,MAE1C;AAAA,IACF,OAAO;AACL;AAAA,QACE;AAAA,QACA;AAAA,MAEF;AAAA,IACF;AACA,eAAW,YAAY;AAAA,MACrB,GAAG,WAAW;AAAA,MACd,cAAc;AAAA,QACZ,GAAG,WAAW,WAAW;AAAA,QACzB,GAAG;AAAA,MACL;AAAA,MACA,GAAI,8BACA,EAAE,oBAAoB,wBAAwB,IAC9C,CAAC;AAAA,IACP;AACA,eAAW,WAAW;AAAA,MACpB,GAAG,WAAW;AAAA,MACd,cAAc;AAAA,QACZ,GAAG,WAAW,UAAU;AAAA,QACxB,4CAA4C;AAAA,MAC9C;AAAA,IACF;AACA,oBAAgB;AAChB,WAAO;AAAA,EACT;AAGA,SAAO,UAAiB,YAAY;AAAA,IAClC,KAAK,EAAE,MAAM,UAAU;AAAA,IACvB;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["readFileSync","join","findUpSync","findUpSync","readFileSync","join"]}
|
package/dist/host/html.cjs
CHANGED
|
@@ -7,16 +7,16 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
require('../chunk-
|
|
12
|
-
require('../chunk-
|
|
13
|
-
require('../chunk-
|
|
10
|
+
var _chunkHZP4FWPGcjs = require('../chunk-HZP4FWPG.cjs');
|
|
11
|
+
require('../chunk-XWRB6CEA.cjs');
|
|
12
|
+
require('../chunk-RZ224NSH.cjs');
|
|
13
|
+
require('../chunk-PCHSF5LH.cjs');
|
|
14
14
|
require('../chunk-3AX5WLZD.cjs');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _chunk6PZEDIAKcjs = require('../chunk-6PZEDIAK.cjs');
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
var _chunkZ2SLBFQLcjs = require('../chunk-Z2SLBFQL.cjs');
|
|
@@ -125,10 +125,10 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
if (type === "webpack") {
|
|
128
|
-
const { webpackRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../webpack-
|
|
128
|
+
const { webpackRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../webpack-65BVWX2U.cjs")));
|
|
129
129
|
return webpackRuntime(bundle, shared, remoteShared, resolveClientUrl);
|
|
130
130
|
} else if (type === "turbopack") {
|
|
131
|
-
const { turbopackRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../turbopack-
|
|
131
|
+
const { turbopackRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../turbopack-UMJ7SLJL.cjs")));
|
|
132
132
|
return turbopackRuntime(
|
|
133
133
|
url,
|
|
134
134
|
bundle,
|
|
@@ -149,15 +149,15 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
|
|
|
149
149
|
var _jsxruntime = require('react/jsx-runtime');
|
|
150
150
|
if (typeof HTMLElement !== "undefined") {
|
|
151
151
|
class RemoteComponent extends HTMLElement {constructor(...args) { super(...args); RemoteComponent.prototype.__init.call(this);RemoteComponent.prototype.__init2.call(this);RemoteComponent.prototype.__init3.call(this);RemoteComponent.prototype.__init4.call(this);RemoteComponent.prototype.__init5.call(this);RemoteComponent.prototype.__init6.call(this);RemoteComponent.prototype.__init7.call(this); }
|
|
152
|
-
__init() {this.name =
|
|
153
|
-
__init2() {this.bundle =
|
|
152
|
+
__init() {this.name = _chunk6PZEDIAKcjs.DEFAULT_COMPONENT_NAME}
|
|
153
|
+
__init2() {this.bundle = _chunk6PZEDIAKcjs.DEFAULT_BUNDLE_NAME}
|
|
154
154
|
|
|
155
155
|
__init3() {this.__next = null}
|
|
156
156
|
__init4() {this.fouc = null}
|
|
157
|
-
__init5() {this.hostState =
|
|
157
|
+
__init5() {this.hostState = _chunkHZP4FWPGcjs.createHostState.call(void 0, )}
|
|
158
158
|
__init6() {this.root = null}
|
|
159
159
|
|
|
160
|
-
__init7() {this.emitter =
|
|
160
|
+
__init7() {this.emitter = _chunkHZP4FWPGcjs.makeEventEmitter.call(void 0, this)}
|
|
161
161
|
|
|
162
162
|
|
|
163
163
|
|
|
@@ -279,10 +279,10 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
279
279
|
let url = null;
|
|
280
280
|
let html = this.innerHTML;
|
|
281
281
|
if (src) {
|
|
282
|
-
url =
|
|
283
|
-
this.name =
|
|
282
|
+
url = _chunkHZP4FWPGcjs.getClientOrServerUrl.call(void 0, src, window.location.href);
|
|
283
|
+
this.name = _chunkHZP4FWPGcjs.resolveNameFromSrc.call(void 0, src, this.name);
|
|
284
284
|
}
|
|
285
|
-
const resolveClientUrl = url ?
|
|
285
|
+
const resolveClientUrl = url ? _chunkHZP4FWPGcjs.bindResolveClientUrl.call(void 0, this.resolveClientUrl, url.href) : void 0;
|
|
286
286
|
if (!remoteComponentChild && url) {
|
|
287
287
|
const fetchInit = {
|
|
288
288
|
credentials: this.credentials || "same-origin"
|
|
@@ -293,7 +293,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
293
293
|
);
|
|
294
294
|
let res;
|
|
295
295
|
try {
|
|
296
|
-
res = await
|
|
296
|
+
res = await _chunkHZP4FWPGcjs.fetchWithHooks.call(void 0, resolvedUrl, fetchInit, {
|
|
297
297
|
onRequest: this.onRequest,
|
|
298
298
|
onResponse: this.onResponse,
|
|
299
299
|
abortController: this.hostState.abortController
|
|
@@ -320,7 +320,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
const effectiveUrl = _nullishCoalesce(url, () => ( new URL(window.location.href)));
|
|
323
|
-
const { doc, parsed } =
|
|
323
|
+
const { doc, parsed } = _chunkHZP4FWPGcjs.preparePipeline.call(void 0, {
|
|
324
324
|
html,
|
|
325
325
|
name: this.name,
|
|
326
326
|
url: effectiveUrl,
|
|
@@ -553,9 +553,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
553
553
|
};
|
|
554
554
|
if (rsc) {
|
|
555
555
|
_optionalChain([rsc, 'access', _62 => _62.parentElement, 'optionalAccess', _63 => _63.removeChild, 'call', _64 => _64(rsc)]);
|
|
556
|
-
const rscName = `__remote_component_rsc_${
|
|
556
|
+
const rscName = `__remote_component_rsc_${_chunk6PZEDIAKcjs.escapeString.call(void 0,
|
|
557
557
|
url.href
|
|
558
|
-
)}_${
|
|
558
|
+
)}_${_chunk6PZEDIAKcjs.escapeString.call(void 0, this.name)}`;
|
|
559
559
|
const rscClone = document.createElement("script");
|
|
560
560
|
rscClone.id = `${rscName}_rsc`;
|
|
561
561
|
rscClone.textContent = _nullishCoalesce(_optionalChain([rsc, 'access', _65 => _65.textContent, 'optionalAccess', _66 => _66.replace, 'call', _67 => _67(
|
|
@@ -568,7 +568,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
568
568
|
name,
|
|
569
569
|
initial
|
|
570
570
|
}) => {
|
|
571
|
-
const stream =
|
|
571
|
+
const stream = _chunkHZP4FWPGcjs.createRSCStream.call(void 0,
|
|
572
572
|
rscName,
|
|
573
573
|
_nullishCoalesce(self[rscName], () => ( [`0:[null]
|
|
574
574
|
`]))
|
package/dist/host/html.js
CHANGED
|
@@ -7,16 +7,16 @@ import {
|
|
|
7
7
|
makeEventEmitter,
|
|
8
8
|
preparePipeline,
|
|
9
9
|
resolveNameFromSrc
|
|
10
|
-
} from "../chunk-
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-
|
|
13
|
-
import "../chunk-
|
|
10
|
+
} from "../chunk-N6AJM72A.js";
|
|
11
|
+
import "../chunk-M6ACTSVB.js";
|
|
12
|
+
import "../chunk-GR5FN73U.js";
|
|
13
|
+
import "../chunk-VFK4HGZT.js";
|
|
14
14
|
import "../chunk-LEKG4YWI.js";
|
|
15
15
|
import {
|
|
16
16
|
DEFAULT_BUNDLE_NAME,
|
|
17
17
|
DEFAULT_COMPONENT_NAME,
|
|
18
18
|
escapeString
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-3PR3SWYZ.js";
|
|
20
20
|
import {
|
|
21
21
|
getNamespace
|
|
22
22
|
} from "../chunk-D5GNZB6O.js";
|
|
@@ -125,10 +125,10 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
if (type === "webpack") {
|
|
128
|
-
const { webpackRuntime } = await import("../webpack-
|
|
128
|
+
const { webpackRuntime } = await import("../webpack-4QYGIVE6.js");
|
|
129
129
|
return webpackRuntime(bundle, shared, remoteShared, resolveClientUrl);
|
|
130
130
|
} else if (type === "turbopack") {
|
|
131
|
-
const { turbopackRuntime } = await import("../turbopack-
|
|
131
|
+
const { turbopackRuntime } = await import("../turbopack-6BSS3SYN.js");
|
|
132
132
|
return turbopackRuntime(
|
|
133
133
|
url,
|
|
134
134
|
bundle,
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkOSSMJQFEcjs = require('../../../chunk-OSSMJQFE.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
8
|
-
require('../../../chunk-
|
|
9
|
-
require('../../../chunk-
|
|
10
|
-
require('../../../chunk-
|
|
7
|
+
var _chunkHZP4FWPGcjs = require('../../../chunk-HZP4FWPG.cjs');
|
|
8
|
+
require('../../../chunk-XWRB6CEA.cjs');
|
|
9
|
+
require('../../../chunk-RZ224NSH.cjs');
|
|
10
|
+
require('../../../chunk-PCHSF5LH.cjs');
|
|
11
11
|
require('../../../chunk-3AX5WLZD.cjs');
|
|
12
12
|
require('../../../chunk-N3SQTOSE.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _chunk6PZEDIAKcjs = require('../../../chunk-6PZEDIAK.cjs');
|
|
17
17
|
require('../../../chunk-Z2SLBFQL.cjs');
|
|
18
18
|
require('../../../chunk-5KTAEO52.cjs');
|
|
19
19
|
|
|
@@ -31,8 +31,8 @@ var _react = require('react');
|
|
|
31
31
|
function resolveForBundle(unbound, bundle) {
|
|
32
32
|
if (!unbound)
|
|
33
33
|
return void 0;
|
|
34
|
-
const remoteSrc = _nullishCoalesce(_optionalChain([
|
|
35
|
-
return
|
|
34
|
+
const remoteSrc = _nullishCoalesce(_optionalChain([_chunk6PZEDIAKcjs.getScope.call(void 0, bundle), 'optionalAccess', _2 => _2.url, 'access', _3 => _3.href]), () => ( ""));
|
|
35
|
+
return _chunkHZP4FWPGcjs.bindResolveClientUrl.call(void 0, unbound, remoteSrc);
|
|
36
36
|
}
|
|
37
37
|
function createImageLoaderSharedEntries({
|
|
38
38
|
bound,
|
|
@@ -41,13 +41,13 @@ function createImageLoaderSharedEntries({
|
|
|
41
41
|
const loaderEntry = (bundle) => {
|
|
42
42
|
const resolveClientUrl = _nullishCoalesce(bound, () => ( resolveForBundle(unbound, bundle)));
|
|
43
43
|
return Promise.resolve({
|
|
44
|
-
default:
|
|
44
|
+
default: _chunk6PZEDIAKcjs.createRemoteImageLoader.call(void 0, bundle, resolveClientUrl),
|
|
45
45
|
__esModule: true
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
48
|
const imageEntry = async (bundle) => {
|
|
49
49
|
const resolveClientUrl = _nullishCoalesce(bound, () => ( resolveForBundle(unbound, bundle)));
|
|
50
|
-
const rawLoader =
|
|
50
|
+
const rawLoader = _chunk6PZEDIAKcjs.createRemoteImageLoader.call(void 0, bundle, resolveClientUrl);
|
|
51
51
|
const remoteLoader = Object.assign(
|
|
52
52
|
(p) => rawLoader({ ...p, config: { path: "/_next/image" } }),
|
|
53
53
|
{ __next_img_default: true }
|
|
@@ -191,7 +191,7 @@ function ConsumeRemoteComponent2(props) {
|
|
|
191
191
|
return _nullishCoalesce(props.children, () => ( null));
|
|
192
192
|
}
|
|
193
193
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
194
|
-
|
|
194
|
+
_chunkOSSMJQFEcjs.ConsumeRemoteComponent,
|
|
195
195
|
{
|
|
196
196
|
...props,
|
|
197
197
|
shared: sharedModules(props.shared, props.resolveClientUrl)
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
ConsumeRemoteComponent
|
|
4
|
-
} from "../../../chunk-
|
|
4
|
+
} from "../../../chunk-RHRDUJ3K.js";
|
|
5
5
|
import {
|
|
6
6
|
bindResolveClientUrl
|
|
7
|
-
} from "../../../chunk-
|
|
8
|
-
import "../../../chunk-
|
|
9
|
-
import "../../../chunk-
|
|
10
|
-
import "../../../chunk-
|
|
7
|
+
} from "../../../chunk-N6AJM72A.js";
|
|
8
|
+
import "../../../chunk-M6ACTSVB.js";
|
|
9
|
+
import "../../../chunk-GR5FN73U.js";
|
|
10
|
+
import "../../../chunk-VFK4HGZT.js";
|
|
11
11
|
import "../../../chunk-LEKG4YWI.js";
|
|
12
12
|
import "../../../chunk-RHGEBXPL.js";
|
|
13
13
|
import {
|
|
14
14
|
createRemoteImageLoader,
|
|
15
15
|
getScope
|
|
16
|
-
} from "../../../chunk-
|
|
16
|
+
} from "../../../chunk-3PR3SWYZ.js";
|
|
17
17
|
import "../../../chunk-D5GNZB6O.js";
|
|
18
18
|
import "../../../chunk-STIJO4AG.js";
|
|
19
19
|
import {
|
|
@@ -34,6 +34,9 @@ module.exports = __toCommonJS(pages_client_exports);
|
|
|
34
34
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
35
|
var import_react = require("react");
|
|
36
36
|
var import_pages = require("#remote-components/host/defaults/pages");
|
|
37
|
+
function isPromiseLikeShared(value) {
|
|
38
|
+
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
39
|
+
}
|
|
37
40
|
function ConsumeRemoteComponent({
|
|
38
41
|
src,
|
|
39
42
|
children,
|
|
@@ -43,27 +46,51 @@ function ConsumeRemoteComponent({
|
|
|
43
46
|
onLoad,
|
|
44
47
|
onRequest,
|
|
45
48
|
onResponse,
|
|
46
|
-
resolveClientUrl
|
|
49
|
+
resolveClientUrl,
|
|
50
|
+
shared: sharedProp
|
|
47
51
|
}) {
|
|
48
52
|
const elementRef = (0, import_react.useRef)(null);
|
|
53
|
+
const onErrorRef = (0, import_react.useRef)(onError);
|
|
54
|
+
onErrorRef.current = onError;
|
|
49
55
|
(0, import_react.useEffect)(() => {
|
|
56
|
+
let cancelled = false;
|
|
50
57
|
const self = globalThis;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
const syncElement = async () => {
|
|
59
|
+
try {
|
|
60
|
+
const userShared = isPromiseLikeShared(sharedProp) ? await sharedProp : sharedProp;
|
|
61
|
+
if (cancelled)
|
|
62
|
+
return;
|
|
63
|
+
self.__remote_component_shared__ = {
|
|
64
|
+
...import_pages.shared,
|
|
65
|
+
...userShared
|
|
66
|
+
};
|
|
67
|
+
await import("remote-components/host/html");
|
|
68
|
+
if (cancelled)
|
|
69
|
+
return;
|
|
70
|
+
const element = elementRef.current;
|
|
71
|
+
if (!element)
|
|
72
|
+
return;
|
|
73
|
+
element.onRequest = onRequest;
|
|
74
|
+
element.onResponse = onResponse;
|
|
75
|
+
element.resolveClientUrl = resolveClientUrl;
|
|
76
|
+
if (element.getAttribute("src") !== src) {
|
|
77
|
+
element.setAttribute("src", src);
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (!cancelled) {
|
|
81
|
+
onErrorRef.current?.(error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
void syncElement();
|
|
86
|
+
return () => {
|
|
87
|
+
cancelled = true;
|
|
88
|
+
};
|
|
89
|
+
}, [src, onRequest, onResponse, resolveClientUrl, sharedProp]);
|
|
54
90
|
(0, import_react.useEffect)(() => {
|
|
55
91
|
const element = elementRef.current;
|
|
56
92
|
if (!element)
|
|
57
93
|
return;
|
|
58
|
-
if (onRequest) {
|
|
59
|
-
element.onRequest = onRequest;
|
|
60
|
-
}
|
|
61
|
-
if (onResponse) {
|
|
62
|
-
element.onResponse = onResponse;
|
|
63
|
-
}
|
|
64
|
-
if (resolveClientUrl !== void 0) {
|
|
65
|
-
element.resolveClientUrl = resolveClientUrl;
|
|
66
|
-
}
|
|
67
94
|
const handleBeforeLoad = (e) => {
|
|
68
95
|
const customEvent = e;
|
|
69
96
|
onBeforeLoad?.(customEvent.src ?? src);
|
|
@@ -103,17 +130,8 @@ function ConsumeRemoteComponent({
|
|
|
103
130
|
if (onChange)
|
|
104
131
|
element.removeEventListener("change", handleChange);
|
|
105
132
|
};
|
|
106
|
-
}, [
|
|
107
|
-
|
|
108
|
-
onBeforeLoad,
|
|
109
|
-
onChange,
|
|
110
|
-
onError,
|
|
111
|
-
onLoad,
|
|
112
|
-
onRequest,
|
|
113
|
-
onResponse,
|
|
114
|
-
resolveClientUrl
|
|
115
|
-
]);
|
|
116
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("remote-component", { ref: elementRef, src, children });
|
|
133
|
+
}, [src, onBeforeLoad, onChange, onError, onLoad]);
|
|
134
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("remote-component", { ref: elementRef, children });
|
|
117
135
|
}
|
|
118
136
|
// Annotate the CommonJS export names for ESM import in node:
|
|
119
137
|
0 && (module.exports = {
|