remote-components 0.0.2 → 0.0.4

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.
@@ -25,22 +25,23 @@ __export(config_exports, {
25
25
  module.exports = __toCommonJS(config_exports);
26
26
  var import_node_path2 = require("path");
27
27
  var import_node_fs = require("fs");
28
- var import_server = require("@vercel/microfrontends/microfrontends/server");
28
+ var import_find_up = require("find-up");
29
29
 
30
30
  // src/next/config/webpack/index.ts
31
31
  var import_node_path = require("path");
32
32
 
33
33
  // src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts
34
- var import_webpack = require("webpack");
35
- var RemoteWebpackRequireRuntimeModule = class extends import_webpack.RuntimeModule {
36
- constructor(appName) {
37
- super("remote-webpack-require");
38
- this.appName = appName;
39
- }
40
- generate() {
41
- return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__["${this.appName}"] = __webpack_require__;`;
42
- }
43
- };
34
+ function createRemoteWebpackRequireRuntimeModule(webpack) {
35
+ return class RemoteWebpackRequireRuntimeModule extends webpack.RuntimeModule {
36
+ constructor(appName) {
37
+ super("remote-webpack-require");
38
+ this.appName = appName;
39
+ }
40
+ generate() {
41
+ return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__["${this.appName}"] = __webpack_require__;`;
42
+ }
43
+ };
44
+ }
44
45
 
45
46
  // src/next/config/webpack/plugins/remote-webpack-require.ts
46
47
  var RemoteWebpackRequirePlugin = class {
@@ -48,13 +49,16 @@ var RemoteWebpackRequirePlugin = class {
48
49
  this.appName = appName;
49
50
  }
50
51
  apply(compiler) {
52
+ const RemoteWebpackRequireRuntimeModule = createRemoteWebpackRequireRuntimeModule(compiler.webpack);
51
53
  compiler.hooks.thisCompilation.tap(
52
54
  "RemoteWebpackRequirePlugin",
53
55
  (compilation) => {
54
56
  compilation.hooks.runtimeRequirementInTree.for("__webpack_require__").tap("RemoteWebpackRequirePlugin", (chunk) => {
55
57
  compilation.addRuntimeModule(
56
58
  chunk,
57
- new RemoteWebpackRequireRuntimeModule(this.appName)
59
+ new RemoteWebpackRequireRuntimeModule(
60
+ this.appName
61
+ )
58
62
  );
59
63
  });
60
64
  }
@@ -63,17 +67,18 @@ var RemoteWebpackRequirePlugin = class {
63
67
  };
64
68
 
65
69
  // src/next/config/webpack/plugins/module-id-embed-runtime-module.ts
66
- var import_webpack2 = require("webpack");
67
- var ModuleIdEmbedRuntimeModule = class extends import_webpack2.RuntimeModule {
68
- constructor(appName, moduleMap) {
69
- super("remote-webpack-module-id-embed");
70
- this.appName = appName;
71
- this.moduleMap = moduleMap;
72
- }
73
- generate() {
74
- return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__["${this.appName}"] = ${JSON.stringify(this.moduleMap)};`;
75
- }
76
- };
70
+ function createModuleIdEmbedRuntimeModule(webpack) {
71
+ return class ModuleIdEmbedRuntimeModule extends webpack.RuntimeModule {
72
+ constructor(appName, moduleMap) {
73
+ super("remote-webpack-module-id-embed");
74
+ this.appName = appName;
75
+ this.moduleMap = moduleMap;
76
+ }
77
+ generate() {
78
+ return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__["${this.appName}"] = ${JSON.stringify(this.moduleMap)};`;
79
+ }
80
+ };
81
+ }
77
82
 
78
83
  // src/next/config/webpack/plugins/module-id-embed.ts
79
84
  var ModuleIdEmbedPlugin = class {
@@ -81,6 +86,9 @@ var ModuleIdEmbedPlugin = class {
81
86
  this.appName = appName;
82
87
  }
83
88
  apply(compiler) {
89
+ const ModuleIdEmbedRuntimeModule = createModuleIdEmbedRuntimeModule(
90
+ compiler.webpack
91
+ );
84
92
  compiler.hooks.thisCompilation.tap("ModuleIdEmbedPlugin", (compilation) => {
85
93
  const moduleMap = {};
86
94
  compilation.hooks.runtimeRequirementInTree.for(compiler.webpack.RuntimeGlobals.require).tap("ModuleIdEmbedPlugin", (chunk, set) => {
@@ -109,7 +117,10 @@ var ModuleIdEmbedPlugin = class {
109
117
  if (Object.keys(moduleMap).length > 0) {
110
118
  compilation.addRuntimeModule(
111
119
  chunk,
112
- new ModuleIdEmbedRuntimeModule(this.appName, moduleMap)
120
+ new ModuleIdEmbedRuntimeModule(
121
+ this.appName,
122
+ moduleMap
123
+ )
113
124
  );
114
125
  set.add(compiler.webpack.RuntimeGlobals.require);
115
126
  }
@@ -119,16 +130,16 @@ var ModuleIdEmbedPlugin = class {
119
130
  };
120
131
 
121
132
  // src/next/config/webpack/plugins/conditional-exec.ts
122
- var import_webpack3 = require("webpack");
123
133
  var ConditionalExecPlugin = class {
124
134
  apply(compiler) {
135
+ const { Compilation, sources } = compiler.webpack;
125
136
  compiler.hooks.thisCompilation.tap(
126
137
  "ConditionalExecPlugin",
127
138
  (compilation) => {
128
139
  compilation.hooks.processAssets.tap(
129
140
  {
130
141
  name: "ConditionalExecPlugin",
131
- stage: import_webpack3.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
142
+ stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
132
143
  },
133
144
  (assets) => {
134
145
  for (const [name, source] of Object.entries(assets)) {
@@ -139,7 +150,7 @@ var ConditionalExecPlugin = class {
139
150
  );
140
151
  compilation.updateAsset(
141
152
  name,
142
- new import_webpack3.sources.RawSource(patchedSource)
153
+ new sources.RawSource(patchedSource)
143
154
  );
144
155
  }
145
156
  }
@@ -153,11 +164,12 @@ var ConditionalExecPlugin = class {
153
164
  // src/next/config/webpack/plugins/patch-require.ts
154
165
  var PatchRequirePlugin = class {
155
166
  apply(compiler) {
167
+ const { sources } = compiler.webpack;
156
168
  compiler.hooks.thisCompilation.tap("PatchRequirePlugin", (compilation) => {
157
169
  compilation.mainTemplate.hooks.requireExtensions.tap(
158
170
  "PatchRequirePlugin",
159
171
  (source) => {
160
- return new compiler.webpack.sources.ConcatSource(
172
+ return new sources.ConcatSource(
161
173
  source,
162
174
  `const __webpack_require_orig__ = __webpack_require__;
163
175
  const REMOTE_RE = /\\[(?<bundle>[a-zA-Z0-9-_]+)\\] (?<id>.*)/;
@@ -323,6 +335,30 @@ module.exports = { shared: { ${Array.from(
323
335
  virtualRemoteComponentSharedHost
324
336
  )}`
325
337
  };
338
+ let projectId = process.env.REMOTE_COMPONENTS_PROJECT_ID || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || process.env.VERCEL_PROJECT_ID;
339
+ if (!projectId) {
340
+ try {
341
+ const projectPath = (0, import_find_up.findUpSync)(".vercel/project.json", {
342
+ cwd: process.cwd()
343
+ });
344
+ if (projectPath) {
345
+ projectId = JSON.parse((0, import_node_fs.readFileSync)(projectPath, "utf8")).projectId;
346
+ }
347
+ } catch {
348
+ }
349
+ }
350
+ if (!projectId) {
351
+ const packageJsonPath = (0, import_find_up.findUpSync)("package.json", {
352
+ cwd: process.cwd()
353
+ });
354
+ if (packageJsonPath) {
355
+ const packageJson = JSON.parse((0, import_node_fs.readFileSync)(packageJsonPath, "utf8"));
356
+ projectId = packageJson.name || (0, import_node_path2.basename)(process.cwd());
357
+ } else {
358
+ projectId = (0, import_node_path2.basename)(process.cwd());
359
+ }
360
+ }
361
+ process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;
326
362
  if (process.env.TURBOPACK) {
327
363
  nextConfig.turbopack = {
328
364
  ...nextConfig.turbopack,
@@ -332,13 +368,21 @@ module.exports = { shared: { ${Array.from(
332
368
  ...alias
333
369
  }
334
370
  };
371
+ nextConfig.compiler = {
372
+ ...nextConfig.compiler,
373
+ defineServer: {
374
+ ...nextConfig.compiler?.defineServer,
375
+ "process.env.REMOTE_COMPONENTS_PROJECT_ID": projectId
376
+ }
377
+ };
335
378
  emitSharedFiles();
336
379
  return nextConfig;
337
380
  }
338
- const { name: fromApp } = (0, import_server.getApplicationContext)();
339
- const microfrontends = import_server.MicrofrontendsServer.infer();
340
- const app = microfrontends.config.getApplication(fromApp);
341
- return transform(nextConfig, { app, alias, emitSharedFiles });
381
+ return transform(nextConfig, {
382
+ app: { name: projectId },
383
+ alias,
384
+ emitSharedFiles
385
+ });
342
386
  }
343
387
  // Annotate the CommonJS export names for ESM import in node:
344
388
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/config/index.ts","../../src/next/config/webpack/index.ts","../../src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts","../../src/next/config/webpack/plugins/remote-webpack-require.ts","../../src/next/config/webpack/plugins/module-id-embed-runtime-module.ts","../../src/next/config/webpack/plugins/module-id-embed.ts","../../src/next/config/webpack/plugins/conditional-exec.ts","../../src/next/config/webpack/plugins/patch-require.ts"],"sourcesContent":["import { dirname, join, relative } from 'node:path';\nimport { mkdirSync, writeFileSync } from 'node:fs';\nimport type { NextConfig } from 'next';\nimport {\n MicrofrontendsServer,\n getApplicationContext,\n} from '@vercel/microfrontends/microfrontends/server';\nimport { transform as webpackTransform } from './webpack';\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`, 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 { withRemoteComponents } from 'remote-components/next/config';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponents(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponents(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentSharedRemote = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/remote.tsx',\n );\n const virtualRemoteComponentSharedHost = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/host.tsx',\n );\n\n const shared = new Set([\n ...[\n 'react',\n 'react/jsx-dev-runtime',\n 'react/jsx-runtime',\n 'react-dom',\n 'react-dom/client',\n 'next/navigation',\n 'next/link',\n 'next/form',\n 'next/image',\n 'next/script',\n ],\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared: Record<string, string> = {\n react: `'/react/index.js'`,\n 'react/jsx-dev-runtime': `'/react/jsx-dev-runtime.js'`,\n 'react/jsx-runtime': `'/react/jsx-runtime.js'`,\n 'react-dom': `'/react-dom/index.js'`,\n };\n\n const sharedRemote = `'use client';\\nmodule.exports = { shared: { ${Array.from(\n shared,\n )\n .reduce<string[]>((acc, curr) => {\n acc.push(\n `[${vendorShared[curr] ?? `require.resolve('${curr}')`}]: '${curr}',`,\n );\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const sharedHost = `'use client';\\nmodule.exports = { shared: { ${Array.from(\n shared,\n )\n .reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(virtualRemoteComponentSharedRemote, sharedRemote, 'utf-8');\n writeFileSync(virtualRemoteComponentSharedHost, sharedHost, 'utf-8');\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components/next',\n 'remote-components/next/host',\n '@remote-component/shared/remote',\n '@remote-component/shared/host',\n ];\n\n const alias = {\n '@remote-component/shared/remote': `./${relative(\n process.cwd(),\n virtualRemoteComponentSharedRemote,\n )}`,\n '@remote-component/shared/host': `./${relative(\n process.cwd(),\n virtualRemoteComponentSharedHost,\n )}`,\n };\n if (process.env.TURBOPACK) {\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\n moduleIds: 'named',\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n ...alias,\n },\n };\n emitSharedFiles();\n return nextConfig;\n }\n\n const { name: fromApp } = getApplicationContext();\n const microfrontends = MicrofrontendsServer.infer();\n\n // fetch the config for the current app\n const app = microfrontends.config.getApplication(fromApp);\n\n // apply the webpack transform\n return webpackTransform(nextConfig, { app, alias, emitSharedFiles });\n}\n","import { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { PatchRequirePlugin } from './plugins/patch-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),\n new ConditionalExecPlugin(),\n new PatchRequirePlugin(),\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","import { RuntimeModule } from 'webpack';\n\nexport class RemoteWebpackRequireRuntimeModule extends RuntimeModule {\n appName: string;\n\n constructor(appName: string) {\n super('remote-webpack-require');\n this.appName = appName;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__[\"${this.appName}\"] = __webpack_require__;`;\n }\n}\n","import { type Compiler } from 'webpack';\nimport { RemoteWebpackRequireRuntimeModule } from './remote-webpack-require-runtime-module';\n\nexport class RemoteWebpackRequirePlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap(\n 'RemoteWebpackRequirePlugin',\n (compilation) => {\n compilation.hooks.runtimeRequirementInTree\n .for('__webpack_require__')\n .tap('RemoteWebpackRequirePlugin', (chunk) => {\n compilation.addRuntimeModule(\n chunk,\n new RemoteWebpackRequireRuntimeModule(this.appName),\n );\n });\n },\n );\n }\n}\n","import { RuntimeModule } from 'webpack';\n\nexport class ModuleIdEmbedRuntimeModule extends RuntimeModule {\n appName: string;\n moduleMap: Record<string | number, unknown>;\n\n constructor(appName: string, moduleMap: Record<string | number, unknown>) {\n super('remote-webpack-module-id-embed');\n this.appName = appName;\n this.moduleMap = moduleMap;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__[\"${this.appName}\"] = ${JSON.stringify(this.moduleMap)};`;\n }\n}\n","import type { NormalModule, Compiler } from 'webpack';\nimport { ModuleIdEmbedRuntimeModule } from './module-id-embed-runtime-module';\n\nexport class ModuleIdEmbedPlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap('ModuleIdEmbedPlugin', (compilation) => {\n const moduleMap = {} as Record<string, string | number>;\n\n compilation.hooks.runtimeRequirementInTree\n .for(compiler.webpack.RuntimeGlobals.require)\n .tap('ModuleIdEmbedPlugin', (chunk, set) => {\n for (const [key, entry] of compilation.entrypoints) {\n for (const entryChunk of entry.chunks) {\n if (key.includes('nextjs-pages-remote')) {\n for (const mod of compilation.chunkGraph.getChunkModulesIterable(\n entryChunk,\n )) {\n const id = compilation.chunkGraph.getModuleId(mod);\n const normalModule = mod as NormalModule;\n if (id) {\n moduleMap[normalModule.resource || normalModule.request] =\n id;\n }\n }\n }\n }\n }\n for (const mod of compilation.modules) {\n const id = compilation.chunkGraph.getModuleId(mod);\n if (id && mod.layer?.endsWith('browser')) {\n const normalModule = mod as NormalModule;\n moduleMap[normalModule.resource || normalModule.request] = id;\n }\n }\n\n if (Object.keys(moduleMap).length > 0) {\n compilation.addRuntimeModule(\n chunk,\n new ModuleIdEmbedRuntimeModule(this.appName, moduleMap),\n );\n\n set.add(compiler.webpack.RuntimeGlobals.require);\n }\n });\n });\n }\n}\n","import { type Compiler, Compilation, sources } from 'webpack';\n\nexport class ConditionalExecPlugin {\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap(\n 'ConditionalExecPlugin',\n (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'ConditionalExecPlugin',\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n (assets) => {\n for (const [name, source] of Object.entries(assets)) {\n if (name.endsWith('.js')) {\n const patchedSource = source\n .source()\n .toString()\n .replace(\n `var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))`,\n `var __webpack_exec__ = (moduleId) => { if (globalThis.__DISABLE_WEBPACK_EXEC__) return; return __webpack_require__(__webpack_require__.s = moduleId); }`,\n );\n compilation.updateAsset(\n name,\n new sources.RawSource(patchedSource),\n );\n }\n }\n },\n );\n },\n );\n }\n}\n","import { type Compiler } from 'webpack';\n\n// This plugin patches the webpack require function to support loading remote components in Next.js\nexport class PatchRequirePlugin {\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap('PatchRequirePlugin', (compilation) => {\n compilation.mainTemplate.hooks.requireExtensions.tap(\n 'PatchRequirePlugin',\n (source) => {\n return new compiler.webpack.sources.ConcatSource(\n source,\n `const __webpack_require_orig__ = __webpack_require__;\nconst REMOTE_RE = /\\\\[(?<bundle>[a-zA-Z0-9-_]+)\\\\] (?<id>.*)/;\n__webpack_require__ = function __remote_webpack_require__(remoteId) {\n const match = REMOTE_RE.exec(remoteId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_orig__(remoteId);\n }\n if (typeof self.__remote_webpack_require__?.[bundle] !== 'function') {\n throw new Error(\\`Remote component loading error: \"\\${bundle}\"\\`);\n }\n return self.__remote_webpack_require__[bundle](self.__remote_webpack_require__[bundle].type === 'turbopack' ? remoteId : id);\n};\nObject.assign(__webpack_require__, __webpack_require_orig__);\nconst __webpack_require_l__ = __webpack_require__.l;\n__webpack_require__.l = function __remote_webpack_require_l__(url, done, key, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_l__(url, done, key, chunkId);\n }\n return done();\n};\nconst __webpack_require_o__ = __webpack_require__.o;\n__webpack_require__.o = function __remote_webpack_require_o__(installedChunks, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_o__(installedChunks, chunkId);\n }\n return installedChunks[chunkId] = 0;\n};\nconst __webpack_require_e__ = __webpack_require__.e;\n__webpack_require__.e = function __remote_webpack_require_e__(chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_e__(chunkId);\n }\n return Promise.resolve([]);\n};`,\n )\n .source()\n .toString();\n },\n );\n });\n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B,CAAC,KAAK,SAAS;AAC/B,QAAI,KAAK,KAAK,yBAAyB,SAAS;AAChD,WAAO;AAAA,EACT,GAAG,CAAC,CAAC,EACJ,KAAK,IAAI;AAAA;AAEZ,QAAM,kBAAkB,MAAM;AAC5B,sCAAU,2BAAQ,kCAAkC,GAAG;AAAA,MACrD,WAAW;AAAA,IACb,CAAC;AAED,sCAAc,oCAAoC,cAAc,OAAO;AACvE,sCAAc,kCAAkC,YAAY,OAAO;AAAA,EACrE;AAEA,aAAW,oBAAoB;AAAA,IAC7B,GAAI,WAAW,qBAAqB,CAAC;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,QAAQ;AAAA,IACZ,mCAAmC,SAAK;AAAA,MACtC,QAAQ,IAAI;AAAA,MACZ;AAAA,IACF;AAAA,IACA,iCAAiC,SAAK;AAAA,MACpC,QAAQ,IAAI;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACA,MAAI,QAAQ,IAAI,WAAW;AACzB,eAAW,YAAY;AAAA,MACrB,GAAG,WAAW;AAAA,MACd,WAAW;AAAA,MACX,cAAc;AAAA,QACZ,GAAG,WAAW,WAAW;AAAA,QACzB,GAAG;AAAA,MACL;AAAA,IACF;AACA,oBAAgB;AAChB,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,MAAM,QAAQ,QAAI,qCAAsB;AAChD,QAAM,iBAAiB,mCAAqB,MAAM;AAGlD,QAAM,MAAM,eAAe,OAAO,eAAe,OAAO;AAGxD,SAAO,UAAiB,YAAY,EAAE,KAAK,OAAO,gBAAgB,CAAC;AACrE;","names":["import_node_path","import_webpack","import_webpack"]}
1
+ {"version":3,"sources":["../../src/next/config/index.ts","../../src/next/config/webpack/index.ts","../../src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts","../../src/next/config/webpack/plugins/remote-webpack-require.ts","../../src/next/config/webpack/plugins/module-id-embed-runtime-module.ts","../../src/next/config/webpack/plugins/module-id-embed.ts","../../src/next/config/webpack/plugins/conditional-exec.ts","../../src/next/config/webpack/plugins/patch-require.ts"],"sourcesContent":["import { basename, dirname, join, relative } from 'node:path';\nimport { mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { findUpSync } from 'find-up';\nimport type { NextConfig } from 'next';\nimport { transform as webpackTransform } from './webpack';\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`, 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 { withRemoteComponents } from 'remote-components/next/config';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponents(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponents(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentSharedRemote = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/remote.tsx',\n );\n const virtualRemoteComponentSharedHost = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/host.tsx',\n );\n\n const shared = new Set([\n ...[\n 'react',\n 'react/jsx-dev-runtime',\n 'react/jsx-runtime',\n 'react-dom',\n 'react-dom/client',\n 'next/navigation',\n 'next/link',\n 'next/form',\n 'next/image',\n 'next/script',\n ],\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared: Record<string, string> = {\n react: `'/react/index.js'`,\n 'react/jsx-dev-runtime': `'/react/jsx-dev-runtime.js'`,\n 'react/jsx-runtime': `'/react/jsx-runtime.js'`,\n 'react-dom': `'/react-dom/index.js'`,\n };\n\n const sharedRemote = `'use client';\\nmodule.exports = { shared: { ${Array.from(\n shared,\n )\n .reduce<string[]>((acc, curr) => {\n acc.push(\n `[${vendorShared[curr] ?? `require.resolve('${curr}')`}]: '${curr}',`,\n );\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const sharedHost = `'use client';\\nmodule.exports = { shared: { ${Array.from(\n shared,\n )\n .reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(virtualRemoteComponentSharedRemote, sharedRemote, 'utf-8');\n writeFileSync(virtualRemoteComponentSharedHost, sharedHost, 'utf-8');\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components/next',\n 'remote-components/next/host',\n '@remote-component/shared/remote',\n '@remote-component/shared/host',\n ];\n\n const alias = {\n '@remote-component/shared/remote': `./${relative(\n process.cwd(),\n virtualRemoteComponentSharedRemote,\n )}`,\n '@remote-component/shared/host': `./${relative(\n process.cwd(),\n virtualRemoteComponentSharedHost,\n )}`,\n };\n\n let projectId =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\n if (!projectId) {\n try {\n const projectPath = findUpSync('.vercel/project.json', {\n cwd: process.cwd(),\n });\n if (projectPath) {\n projectId = (\n JSON.parse(readFileSync(projectPath, 'utf8')) as { projectId: string }\n ).projectId;\n }\n } catch {\n // fallback to env‑var above\n }\n }\n\n if (!projectId) {\n const packageJsonPath = findUpSync('package.json', {\n cwd: process.cwd(),\n });\n if (packageJsonPath) {\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {\n name?: string;\n };\n projectId = packageJson.name || basename(process.cwd());\n } else {\n projectId = basename(process.cwd());\n }\n }\n\n process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;\n\n if (process.env.TURBOPACK) {\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\n moduleIds: 'named',\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n ...alias,\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 { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { PatchRequirePlugin } from './plugins/patch-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),\n new ConditionalExecPlugin(),\n new PatchRequirePlugin(),\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","export function createRemoteWebpackRequireRuntimeModule(webpack: {\n RuntimeModule: new (name: string, stage?: number) => object;\n}) {\n return class RemoteWebpackRequireRuntimeModule extends webpack.RuntimeModule {\n appName: string;\n\n constructor(appName: string) {\n super('remote-webpack-require');\n this.appName = appName;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__[\"${this.appName}\"] = __webpack_require__;`;\n }\n };\n}\n","import type { Compiler, RuntimeModule } from 'webpack';\nimport { createRemoteWebpackRequireRuntimeModule } from './remote-webpack-require-runtime-module';\n\nexport class RemoteWebpackRequirePlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const RemoteWebpackRequireRuntimeModule =\n createRemoteWebpackRequireRuntimeModule(compiler.webpack);\n\n compiler.hooks.thisCompilation.tap(\n 'RemoteWebpackRequirePlugin',\n (compilation) => {\n compilation.hooks.runtimeRequirementInTree\n .for('__webpack_require__')\n .tap('RemoteWebpackRequirePlugin', (chunk) => {\n compilation.addRuntimeModule(\n chunk,\n new RemoteWebpackRequireRuntimeModule(\n this.appName,\n ) as unknown as RuntimeModule,\n );\n });\n },\n );\n }\n}\n","export function createModuleIdEmbedRuntimeModule(webpack: {\n RuntimeModule: new (name: string, stage?: number) => object;\n}) {\n return class ModuleIdEmbedRuntimeModule extends webpack.RuntimeModule {\n appName: string;\n moduleMap: Record<string | number, unknown>;\n\n constructor(appName: string, moduleMap: Record<string | number, unknown>) {\n super('remote-webpack-module-id-embed');\n this.appName = appName;\n this.moduleMap = moduleMap;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__[\"${this.appName}\"] = ${JSON.stringify(this.moduleMap)};`;\n }\n };\n}\n","import type { NormalModule, Compiler, RuntimeModule } from 'webpack';\nimport { createModuleIdEmbedRuntimeModule } from './module-id-embed-runtime-module';\n\nexport class ModuleIdEmbedPlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const ModuleIdEmbedRuntimeModule = createModuleIdEmbedRuntimeModule(\n compiler.webpack,\n );\n\n compiler.hooks.thisCompilation.tap('ModuleIdEmbedPlugin', (compilation) => {\n const moduleMap = {} as Record<string, string | number>;\n\n compilation.hooks.runtimeRequirementInTree\n .for(compiler.webpack.RuntimeGlobals.require)\n .tap('ModuleIdEmbedPlugin', (chunk, set) => {\n for (const [key, entry] of compilation.entrypoints) {\n for (const entryChunk of entry.chunks) {\n if (key.includes('nextjs-pages-remote')) {\n for (const mod of compilation.chunkGraph.getChunkModulesIterable(\n entryChunk,\n )) {\n const id = compilation.chunkGraph.getModuleId(mod);\n const normalModule = mod as NormalModule;\n if (id) {\n moduleMap[normalModule.resource || normalModule.request] =\n id;\n }\n }\n }\n }\n }\n for (const mod of compilation.modules) {\n const id = compilation.chunkGraph.getModuleId(mod);\n if (id && mod.layer?.endsWith('browser')) {\n const normalModule = mod as NormalModule;\n moduleMap[normalModule.resource || normalModule.request] = id;\n }\n }\n\n if (Object.keys(moduleMap).length > 0) {\n compilation.addRuntimeModule(\n chunk,\n new ModuleIdEmbedRuntimeModule(\n this.appName,\n moduleMap,\n ) as unknown as RuntimeModule,\n );\n\n set.add(compiler.webpack.RuntimeGlobals.require);\n }\n });\n });\n }\n}\n","import type { Compiler } from 'webpack';\n\nexport class ConditionalExecPlugin {\n apply(compiler: Compiler) {\n const { Compilation, sources } = compiler.webpack;\n\n compiler.hooks.thisCompilation.tap(\n 'ConditionalExecPlugin',\n (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'ConditionalExecPlugin',\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n (assets) => {\n for (const [name, source] of Object.entries(assets)) {\n if (name.endsWith('.js')) {\n const patchedSource = source\n .source()\n .toString()\n .replace(\n `var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))`,\n `var __webpack_exec__ = (moduleId) => { if (globalThis.__DISABLE_WEBPACK_EXEC__) return; return __webpack_require__(__webpack_require__.s = moduleId); }`,\n );\n compilation.updateAsset(\n name,\n new sources.RawSource(patchedSource),\n );\n }\n }\n },\n );\n },\n );\n }\n}\n","import type { Compiler } from 'webpack';\n\n// This plugin patches the webpack require function to support loading remote components in Next.js\nexport class PatchRequirePlugin {\n apply(compiler: Compiler) {\n const { sources } = compiler.webpack;\n\n compiler.hooks.thisCompilation.tap('PatchRequirePlugin', (compilation) => {\n compilation.mainTemplate.hooks.requireExtensions.tap(\n 'PatchRequirePlugin',\n (source) => {\n return new sources.ConcatSource(\n source,\n `const __webpack_require_orig__ = __webpack_require__;\nconst REMOTE_RE = /\\\\[(?<bundle>[a-zA-Z0-9-_]+)\\\\] (?<id>.*)/;\n__webpack_require__ = function __remote_webpack_require__(remoteId) {\n const match = REMOTE_RE.exec(remoteId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_orig__(remoteId);\n }\n if (typeof self.__remote_webpack_require__?.[bundle] !== 'function') {\n throw new Error(\\`Remote component loading error: \"\\${bundle}\"\\`);\n }\n return self.__remote_webpack_require__[bundle](self.__remote_webpack_require__[bundle].type === 'turbopack' ? remoteId : id);\n};\nObject.assign(__webpack_require__, __webpack_require_orig__);\nconst __webpack_require_l__ = __webpack_require__.l;\n__webpack_require__.l = function __remote_webpack_require_l__(url, done, key, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_l__(url, done, key, chunkId);\n }\n return done();\n};\nconst __webpack_require_o__ = __webpack_require__.o;\n__webpack_require__.o = function __remote_webpack_require_o__(installedChunks, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_o__(installedChunks, chunkId);\n }\n return installedChunks[chunkId] = 0;\n};\nconst __webpack_require_e__ = __webpack_require__.e;\n__webpack_require__.e = function __remote_webpack_require_e__(chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_e__(chunkId);\n }\n return Promise.resolve([]);\n};`,\n )\n .source()\n .toString();\n },\n );\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,oBAAkD;AAClD,qBAAuD;AACvD,qBAA2B;;;ACF3B,uBAAqB;;;ACAd,SAAS,wCAAwC,SAErD;AACD,SAAO,MAAM,0CAA0C,QAAQ,cAAc;AAAA,IAG3E,YAAY,SAAiB;AAC3B,YAAM,wBAAwB;AAC9B,WAAK,UAAU;AAAA,IACjB;AAAA,IAEA,WAA0B;AACxB,aAAO,+HAA+H,KAAK;AAAA,IAC7I;AAAA,EACF;AACF;;;ACZO,IAAM,6BAAN,MAAiC;AAAA,EAGtC,YAAY,SAAiB;AAC3B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,UAAoB;AACxB,UAAM,oCACJ,wCAAwC,SAAS,OAAO;AAE1D,aAAS,MAAM,gBAAgB;AAAA,MAC7B;AAAA,MACA,CAAC,gBAAgB;AACf,oBAAY,MAAM,yBACf,IAAI,qBAAqB,EACzB,IAAI,8BAA8B,CAAC,UAAU;AAC5C,sBAAY;AAAA,YACV;AAAA,YACA,IAAI;AAAA,cACF,KAAK;AAAA,YACP;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACL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IAAI;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,MAAI,YACF,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI;AAEd,MAAI,CAAC,WAAW;AACd,QAAI;AACF,YAAM,kBAAc,2BAAW,wBAAwB;AAAA,QACrD,KAAK,QAAQ,IAAI;AAAA,MACnB,CAAC;AACD,UAAI,aAAa;AACf,oBACE,KAAK,UAAM,6BAAa,aAAa,MAAM,CAAC,EAC5C;AAAA,MACJ;AAAA,IACF,QAAE;AAAA,IAEF;AAAA,EACF;AAEA,MAAI,CAAC,WAAW;AACd,UAAM,sBAAkB,2BAAW,gBAAgB;AAAA,MACjD,KAAK,QAAQ,IAAI;AAAA,IACnB,CAAC;AACD,QAAI,iBAAiB;AACnB,YAAM,cAAc,KAAK,UAAM,6BAAa,iBAAiB,MAAM,CAAC;AAGpE,kBAAY,YAAY,YAAQ,4BAAS,QAAQ,IAAI,CAAC;AAAA,IACxD,OAAO;AACL,sBAAY,4BAAS,QAAQ,IAAI,CAAC;AAAA,IACpC;AAAA,EACF;AAEA,UAAQ,IAAI,+BAA+B;AAE3C,MAAI,QAAQ,IAAI,WAAW;AACzB,eAAW,YAAY;AAAA,MACrB,GAAG,WAAW;AAAA,MACd,WAAW;AAAA,MACX,cAAc;AAAA,QACZ,GAAG,WAAW,WAAW;AAAA,QACzB,GAAG;AAAA,MACL;AAAA,IACF;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":["import_node_path"]}
@@ -1,25 +1,23 @@
1
1
  // src/next/config/index.ts
2
- import { dirname, join as join2, relative } from "node:path";
3
- import { mkdirSync, writeFileSync } from "node:fs";
4
- import {
5
- MicrofrontendsServer,
6
- getApplicationContext
7
- } from "@vercel/microfrontends/microfrontends/server";
2
+ import { basename, dirname, join as join2, relative } from "node:path";
3
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { findUpSync } from "find-up";
8
5
 
9
6
  // src/next/config/webpack/index.ts
10
7
  import { join } from "node:path";
11
8
 
12
9
  // src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts
13
- import { RuntimeModule } from "webpack";
14
- var RemoteWebpackRequireRuntimeModule = class extends RuntimeModule {
15
- constructor(appName) {
16
- super("remote-webpack-require");
17
- this.appName = appName;
18
- }
19
- generate() {
20
- return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__["${this.appName}"] = __webpack_require__;`;
21
- }
22
- };
10
+ function createRemoteWebpackRequireRuntimeModule(webpack) {
11
+ return class RemoteWebpackRequireRuntimeModule extends webpack.RuntimeModule {
12
+ constructor(appName) {
13
+ super("remote-webpack-require");
14
+ this.appName = appName;
15
+ }
16
+ generate() {
17
+ return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__["${this.appName}"] = __webpack_require__;`;
18
+ }
19
+ };
20
+ }
23
21
 
24
22
  // src/next/config/webpack/plugins/remote-webpack-require.ts
25
23
  var RemoteWebpackRequirePlugin = class {
@@ -27,13 +25,16 @@ var RemoteWebpackRequirePlugin = class {
27
25
  this.appName = appName;
28
26
  }
29
27
  apply(compiler) {
28
+ const RemoteWebpackRequireRuntimeModule = createRemoteWebpackRequireRuntimeModule(compiler.webpack);
30
29
  compiler.hooks.thisCompilation.tap(
31
30
  "RemoteWebpackRequirePlugin",
32
31
  (compilation) => {
33
32
  compilation.hooks.runtimeRequirementInTree.for("__webpack_require__").tap("RemoteWebpackRequirePlugin", (chunk) => {
34
33
  compilation.addRuntimeModule(
35
34
  chunk,
36
- new RemoteWebpackRequireRuntimeModule(this.appName)
35
+ new RemoteWebpackRequireRuntimeModule(
36
+ this.appName
37
+ )
37
38
  );
38
39
  });
39
40
  }
@@ -42,17 +43,18 @@ var RemoteWebpackRequirePlugin = class {
42
43
  };
43
44
 
44
45
  // src/next/config/webpack/plugins/module-id-embed-runtime-module.ts
45
- import { RuntimeModule as RuntimeModule2 } from "webpack";
46
- var ModuleIdEmbedRuntimeModule = class extends RuntimeModule2 {
47
- constructor(appName, moduleMap) {
48
- super("remote-webpack-module-id-embed");
49
- this.appName = appName;
50
- this.moduleMap = moduleMap;
51
- }
52
- generate() {
53
- return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__["${this.appName}"] = ${JSON.stringify(this.moduleMap)};`;
54
- }
55
- };
46
+ function createModuleIdEmbedRuntimeModule(webpack) {
47
+ return class ModuleIdEmbedRuntimeModule extends webpack.RuntimeModule {
48
+ constructor(appName, moduleMap) {
49
+ super("remote-webpack-module-id-embed");
50
+ this.appName = appName;
51
+ this.moduleMap = moduleMap;
52
+ }
53
+ generate() {
54
+ return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__["${this.appName}"] = ${JSON.stringify(this.moduleMap)};`;
55
+ }
56
+ };
57
+ }
56
58
 
57
59
  // src/next/config/webpack/plugins/module-id-embed.ts
58
60
  var ModuleIdEmbedPlugin = class {
@@ -60,6 +62,9 @@ var ModuleIdEmbedPlugin = class {
60
62
  this.appName = appName;
61
63
  }
62
64
  apply(compiler) {
65
+ const ModuleIdEmbedRuntimeModule = createModuleIdEmbedRuntimeModule(
66
+ compiler.webpack
67
+ );
63
68
  compiler.hooks.thisCompilation.tap("ModuleIdEmbedPlugin", (compilation) => {
64
69
  const moduleMap = {};
65
70
  compilation.hooks.runtimeRequirementInTree.for(compiler.webpack.RuntimeGlobals.require).tap("ModuleIdEmbedPlugin", (chunk, set) => {
@@ -88,7 +93,10 @@ var ModuleIdEmbedPlugin = class {
88
93
  if (Object.keys(moduleMap).length > 0) {
89
94
  compilation.addRuntimeModule(
90
95
  chunk,
91
- new ModuleIdEmbedRuntimeModule(this.appName, moduleMap)
96
+ new ModuleIdEmbedRuntimeModule(
97
+ this.appName,
98
+ moduleMap
99
+ )
92
100
  );
93
101
  set.add(compiler.webpack.RuntimeGlobals.require);
94
102
  }
@@ -98,9 +106,9 @@ var ModuleIdEmbedPlugin = class {
98
106
  };
99
107
 
100
108
  // src/next/config/webpack/plugins/conditional-exec.ts
101
- import { Compilation, sources } from "webpack";
102
109
  var ConditionalExecPlugin = class {
103
110
  apply(compiler) {
111
+ const { Compilation, sources } = compiler.webpack;
104
112
  compiler.hooks.thisCompilation.tap(
105
113
  "ConditionalExecPlugin",
106
114
  (compilation) => {
@@ -132,11 +140,12 @@ var ConditionalExecPlugin = class {
132
140
  // src/next/config/webpack/plugins/patch-require.ts
133
141
  var PatchRequirePlugin = class {
134
142
  apply(compiler) {
143
+ const { sources } = compiler.webpack;
135
144
  compiler.hooks.thisCompilation.tap("PatchRequirePlugin", (compilation) => {
136
145
  compilation.mainTemplate.hooks.requireExtensions.tap(
137
146
  "PatchRequirePlugin",
138
147
  (source) => {
139
- return new compiler.webpack.sources.ConcatSource(
148
+ return new sources.ConcatSource(
140
149
  source,
141
150
  `const __webpack_require_orig__ = __webpack_require__;
142
151
  const REMOTE_RE = /\\[(?<bundle>[a-zA-Z0-9-_]+)\\] (?<id>.*)/;
@@ -302,6 +311,30 @@ module.exports = { shared: { ${Array.from(
302
311
  virtualRemoteComponentSharedHost
303
312
  )}`
304
313
  };
314
+ let projectId = process.env.REMOTE_COMPONENTS_PROJECT_ID || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || process.env.VERCEL_PROJECT_ID;
315
+ if (!projectId) {
316
+ try {
317
+ const projectPath = findUpSync(".vercel/project.json", {
318
+ cwd: process.cwd()
319
+ });
320
+ if (projectPath) {
321
+ projectId = JSON.parse(readFileSync(projectPath, "utf8")).projectId;
322
+ }
323
+ } catch {
324
+ }
325
+ }
326
+ if (!projectId) {
327
+ const packageJsonPath = findUpSync("package.json", {
328
+ cwd: process.cwd()
329
+ });
330
+ if (packageJsonPath) {
331
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
332
+ projectId = packageJson.name || basename(process.cwd());
333
+ } else {
334
+ projectId = basename(process.cwd());
335
+ }
336
+ }
337
+ process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;
305
338
  if (process.env.TURBOPACK) {
306
339
  nextConfig.turbopack = {
307
340
  ...nextConfig.turbopack,
@@ -311,13 +344,21 @@ module.exports = { shared: { ${Array.from(
311
344
  ...alias
312
345
  }
313
346
  };
347
+ nextConfig.compiler = {
348
+ ...nextConfig.compiler,
349
+ defineServer: {
350
+ ...nextConfig.compiler?.defineServer,
351
+ "process.env.REMOTE_COMPONENTS_PROJECT_ID": projectId
352
+ }
353
+ };
314
354
  emitSharedFiles();
315
355
  return nextConfig;
316
356
  }
317
- const { name: fromApp } = getApplicationContext();
318
- const microfrontends = MicrofrontendsServer.infer();
319
- const app = microfrontends.config.getApplication(fromApp);
320
- return transform(nextConfig, { app, alias, emitSharedFiles });
357
+ return transform(nextConfig, {
358
+ app: { name: projectId },
359
+ alias,
360
+ emitSharedFiles
361
+ });
321
362
  }
322
363
  export {
323
364
  withRemoteComponents
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/config/index.ts","../../src/next/config/webpack/index.ts","../../src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts","../../src/next/config/webpack/plugins/remote-webpack-require.ts","../../src/next/config/webpack/plugins/module-id-embed-runtime-module.ts","../../src/next/config/webpack/plugins/module-id-embed.ts","../../src/next/config/webpack/plugins/conditional-exec.ts","../../src/next/config/webpack/plugins/patch-require.ts"],"sourcesContent":["import { dirname, join, relative } from 'node:path';\nimport { mkdirSync, writeFileSync } from 'node:fs';\nimport type { NextConfig } from 'next';\nimport {\n MicrofrontendsServer,\n getApplicationContext,\n} from '@vercel/microfrontends/microfrontends/server';\nimport { transform as webpackTransform } from './webpack';\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`, 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 { withRemoteComponents } from 'remote-components/next/config';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponents(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponents(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentSharedRemote = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/remote.tsx',\n );\n const virtualRemoteComponentSharedHost = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/host.tsx',\n );\n\n const shared = new Set([\n ...[\n 'react',\n 'react/jsx-dev-runtime',\n 'react/jsx-runtime',\n 'react-dom',\n 'react-dom/client',\n 'next/navigation',\n 'next/link',\n 'next/form',\n 'next/image',\n 'next/script',\n ],\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared: Record<string, string> = {\n react: `'/react/index.js'`,\n 'react/jsx-dev-runtime': `'/react/jsx-dev-runtime.js'`,\n 'react/jsx-runtime': `'/react/jsx-runtime.js'`,\n 'react-dom': `'/react-dom/index.js'`,\n };\n\n const sharedRemote = `'use client';\\nmodule.exports = { shared: { ${Array.from(\n shared,\n )\n .reduce<string[]>((acc, curr) => {\n acc.push(\n `[${vendorShared[curr] ?? `require.resolve('${curr}')`}]: '${curr}',`,\n );\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const sharedHost = `'use client';\\nmodule.exports = { shared: { ${Array.from(\n shared,\n )\n .reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(virtualRemoteComponentSharedRemote, sharedRemote, 'utf-8');\n writeFileSync(virtualRemoteComponentSharedHost, sharedHost, 'utf-8');\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components/next',\n 'remote-components/next/host',\n '@remote-component/shared/remote',\n '@remote-component/shared/host',\n ];\n\n const alias = {\n '@remote-component/shared/remote': `./${relative(\n process.cwd(),\n virtualRemoteComponentSharedRemote,\n )}`,\n '@remote-component/shared/host': `./${relative(\n process.cwd(),\n virtualRemoteComponentSharedHost,\n )}`,\n };\n if (process.env.TURBOPACK) {\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\n moduleIds: 'named',\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n ...alias,\n },\n };\n emitSharedFiles();\n return nextConfig;\n }\n\n const { name: fromApp } = getApplicationContext();\n const microfrontends = MicrofrontendsServer.infer();\n\n // fetch the config for the current app\n const app = microfrontends.config.getApplication(fromApp);\n\n // apply the webpack transform\n return webpackTransform(nextConfig, { app, alias, emitSharedFiles });\n}\n","import { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { PatchRequirePlugin } from './plugins/patch-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),\n new ConditionalExecPlugin(),\n new PatchRequirePlugin(),\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","import { RuntimeModule } from 'webpack';\n\nexport class RemoteWebpackRequireRuntimeModule extends RuntimeModule {\n appName: string;\n\n constructor(appName: string) {\n super('remote-webpack-require');\n this.appName = appName;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__[\"${this.appName}\"] = __webpack_require__;`;\n }\n}\n","import { type Compiler } from 'webpack';\nimport { RemoteWebpackRequireRuntimeModule } from './remote-webpack-require-runtime-module';\n\nexport class RemoteWebpackRequirePlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap(\n 'RemoteWebpackRequirePlugin',\n (compilation) => {\n compilation.hooks.runtimeRequirementInTree\n .for('__webpack_require__')\n .tap('RemoteWebpackRequirePlugin', (chunk) => {\n compilation.addRuntimeModule(\n chunk,\n new RemoteWebpackRequireRuntimeModule(this.appName),\n );\n });\n },\n );\n }\n}\n","import { RuntimeModule } from 'webpack';\n\nexport class ModuleIdEmbedRuntimeModule extends RuntimeModule {\n appName: string;\n moduleMap: Record<string | number, unknown>;\n\n constructor(appName: string, moduleMap: Record<string | number, unknown>) {\n super('remote-webpack-module-id-embed');\n this.appName = appName;\n this.moduleMap = moduleMap;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__[\"${this.appName}\"] = ${JSON.stringify(this.moduleMap)};`;\n }\n}\n","import type { NormalModule, Compiler } from 'webpack';\nimport { ModuleIdEmbedRuntimeModule } from './module-id-embed-runtime-module';\n\nexport class ModuleIdEmbedPlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap('ModuleIdEmbedPlugin', (compilation) => {\n const moduleMap = {} as Record<string, string | number>;\n\n compilation.hooks.runtimeRequirementInTree\n .for(compiler.webpack.RuntimeGlobals.require)\n .tap('ModuleIdEmbedPlugin', (chunk, set) => {\n for (const [key, entry] of compilation.entrypoints) {\n for (const entryChunk of entry.chunks) {\n if (key.includes('nextjs-pages-remote')) {\n for (const mod of compilation.chunkGraph.getChunkModulesIterable(\n entryChunk,\n )) {\n const id = compilation.chunkGraph.getModuleId(mod);\n const normalModule = mod as NormalModule;\n if (id) {\n moduleMap[normalModule.resource || normalModule.request] =\n id;\n }\n }\n }\n }\n }\n for (const mod of compilation.modules) {\n const id = compilation.chunkGraph.getModuleId(mod);\n if (id && mod.layer?.endsWith('browser')) {\n const normalModule = mod as NormalModule;\n moduleMap[normalModule.resource || normalModule.request] = id;\n }\n }\n\n if (Object.keys(moduleMap).length > 0) {\n compilation.addRuntimeModule(\n chunk,\n new ModuleIdEmbedRuntimeModule(this.appName, moduleMap),\n );\n\n set.add(compiler.webpack.RuntimeGlobals.require);\n }\n });\n });\n }\n}\n","import { type Compiler, Compilation, sources } from 'webpack';\n\nexport class ConditionalExecPlugin {\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap(\n 'ConditionalExecPlugin',\n (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'ConditionalExecPlugin',\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n (assets) => {\n for (const [name, source] of Object.entries(assets)) {\n if (name.endsWith('.js')) {\n const patchedSource = source\n .source()\n .toString()\n .replace(\n `var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))`,\n `var __webpack_exec__ = (moduleId) => { if (globalThis.__DISABLE_WEBPACK_EXEC__) return; return __webpack_require__(__webpack_require__.s = moduleId); }`,\n );\n compilation.updateAsset(\n name,\n new sources.RawSource(patchedSource),\n );\n }\n }\n },\n );\n },\n );\n }\n}\n","import { type Compiler } from 'webpack';\n\n// This plugin patches the webpack require function to support loading remote components in Next.js\nexport class PatchRequirePlugin {\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap('PatchRequirePlugin', (compilation) => {\n compilation.mainTemplate.hooks.requireExtensions.tap(\n 'PatchRequirePlugin',\n (source) => {\n return new compiler.webpack.sources.ConcatSource(\n source,\n `const __webpack_require_orig__ = __webpack_require__;\nconst REMOTE_RE = /\\\\[(?<bundle>[a-zA-Z0-9-_]+)\\\\] (?<id>.*)/;\n__webpack_require__ = function __remote_webpack_require__(remoteId) {\n const match = REMOTE_RE.exec(remoteId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_orig__(remoteId);\n }\n if (typeof self.__remote_webpack_require__?.[bundle] !== 'function') {\n throw new Error(\\`Remote component loading error: \"\\${bundle}\"\\`);\n }\n return self.__remote_webpack_require__[bundle](self.__remote_webpack_require__[bundle].type === 'turbopack' ? remoteId : id);\n};\nObject.assign(__webpack_require__, __webpack_require_orig__);\nconst __webpack_require_l__ = __webpack_require__.l;\n__webpack_require__.l = function __remote_webpack_require_l__(url, done, key, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_l__(url, done, key, chunkId);\n }\n return done();\n};\nconst __webpack_require_o__ = __webpack_require__.o;\n__webpack_require__.o = function __remote_webpack_require_o__(installedChunks, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_o__(installedChunks, chunkId);\n }\n return installedChunks[chunkId] = 0;\n};\nconst __webpack_require_e__ = __webpack_require__.e;\n__webpack_require__.e = function __remote_webpack_require_e__(chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_e__(chunkId);\n }\n return Promise.resolve([]);\n};`,\n )\n .source()\n .toString();\n },\n );\n });\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS,QAAAA,OAAM,gBAAgB;AACxC,SAAS,WAAW,qBAAqB;AAEzC;AAAA,EACE;AAAA,EACA;AAAA,OACK;;;ACNP,SAAS,YAAY;;;ACArB,SAAS,qBAAqB;AAEvB,IAAM,oCAAN,cAAgD,cAAc;AAAA,EAGnE,YAAY,SAAiB;AAC3B,UAAM,wBAAwB;AAC9B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,WAA0B;AACxB,WAAO,+HAA+H,KAAK;AAAA,EAC7I;AACF;;;ACVO,IAAM,6BAAN,MAAiC;AAAA,EAGtC,YAAY,SAAiB;AAC3B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,UAAoB;AACxB,aAAS,MAAM,gBAAgB;AAAA,MAC7B;AAAA,MACA,CAAC,gBAAgB;AACf,oBAAY,MAAM,yBACf,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AiC,KAAK;AAAA,MACpC,QAAQ,IAAI;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACA,MAAI,QAAQ,IAAI,WAAW;AACzB,eAAW,YAAY;AAAA,MACrB,GAAG,WAAW;AAAA,MACd,WAAW;AAAA,MACX,cAAc;AAAA,QACZ,GAAG,WAAW,WAAW;AAAA,QACzB,GAAG;AAAA,MACL;AAAA,IACF;AACA,oBAAgB;AAChB,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,MAAM,QAAQ,IAAI,sBAAsB;AAChD,QAAM,iBAAiB,qBAAqB,MAAM;AAGlD,QAAM,MAAM,eAAe,OAAO,eAAe,OAAO;AAGxD,SAAO,UAAiB,YAAY,EAAE,KAAK,OAAO,gBAAgB,CAAC;AACrE;","names":["join","RuntimeModule","join"]}
1
+ {"version":3,"sources":["../../src/next/config/index.ts","../../src/next/config/webpack/index.ts","../../src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts","../../src/next/config/webpack/plugins/remote-webpack-require.ts","../../src/next/config/webpack/plugins/module-id-embed-runtime-module.ts","../../src/next/config/webpack/plugins/module-id-embed.ts","../../src/next/config/webpack/plugins/conditional-exec.ts","../../src/next/config/webpack/plugins/patch-require.ts"],"sourcesContent":["import { basename, dirname, join, relative } from 'node:path';\nimport { mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { findUpSync } from 'find-up';\nimport type { NextConfig } from 'next';\nimport { transform as webpackTransform } from './webpack';\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`, 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 { withRemoteComponents } from 'remote-components/next/config';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponents(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponents(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentSharedRemote = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/remote.tsx',\n );\n const virtualRemoteComponentSharedHost = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/host.tsx',\n );\n\n const shared = new Set([\n ...[\n 'react',\n 'react/jsx-dev-runtime',\n 'react/jsx-runtime',\n 'react-dom',\n 'react-dom/client',\n 'next/navigation',\n 'next/link',\n 'next/form',\n 'next/image',\n 'next/script',\n ],\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared: Record<string, string> = {\n react: `'/react/index.js'`,\n 'react/jsx-dev-runtime': `'/react/jsx-dev-runtime.js'`,\n 'react/jsx-runtime': `'/react/jsx-runtime.js'`,\n 'react-dom': `'/react-dom/index.js'`,\n };\n\n const sharedRemote = `'use client';\\nmodule.exports = { shared: { ${Array.from(\n shared,\n )\n .reduce<string[]>((acc, curr) => {\n acc.push(\n `[${vendorShared[curr] ?? `require.resolve('${curr}')`}]: '${curr}',`,\n );\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const sharedHost = `'use client';\\nmodule.exports = { shared: { ${Array.from(\n shared,\n )\n .reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(virtualRemoteComponentSharedRemote, sharedRemote, 'utf-8');\n writeFileSync(virtualRemoteComponentSharedHost, sharedHost, 'utf-8');\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components/next',\n 'remote-components/next/host',\n '@remote-component/shared/remote',\n '@remote-component/shared/host',\n ];\n\n const alias = {\n '@remote-component/shared/remote': `./${relative(\n process.cwd(),\n virtualRemoteComponentSharedRemote,\n )}`,\n '@remote-component/shared/host': `./${relative(\n process.cwd(),\n virtualRemoteComponentSharedHost,\n )}`,\n };\n\n let projectId =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\n if (!projectId) {\n try {\n const projectPath = findUpSync('.vercel/project.json', {\n cwd: process.cwd(),\n });\n if (projectPath) {\n projectId = (\n JSON.parse(readFileSync(projectPath, 'utf8')) as { projectId: string }\n ).projectId;\n }\n } catch {\n // fallback to env‑var above\n }\n }\n\n if (!projectId) {\n const packageJsonPath = findUpSync('package.json', {\n cwd: process.cwd(),\n });\n if (packageJsonPath) {\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {\n name?: string;\n };\n projectId = packageJson.name || basename(process.cwd());\n } else {\n projectId = basename(process.cwd());\n }\n }\n\n process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;\n\n if (process.env.TURBOPACK) {\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\n moduleIds: 'named',\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n ...alias,\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 { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { PatchRequirePlugin } from './plugins/patch-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),\n new ConditionalExecPlugin(),\n new PatchRequirePlugin(),\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","export function createRemoteWebpackRequireRuntimeModule(webpack: {\n RuntimeModule: new (name: string, stage?: number) => object;\n}) {\n return class RemoteWebpackRequireRuntimeModule extends webpack.RuntimeModule {\n appName: string;\n\n constructor(appName: string) {\n super('remote-webpack-require');\n this.appName = appName;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__[\"${this.appName}\"] = __webpack_require__;`;\n }\n };\n}\n","import type { Compiler, RuntimeModule } from 'webpack';\nimport { createRemoteWebpackRequireRuntimeModule } from './remote-webpack-require-runtime-module';\n\nexport class RemoteWebpackRequirePlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const RemoteWebpackRequireRuntimeModule =\n createRemoteWebpackRequireRuntimeModule(compiler.webpack);\n\n compiler.hooks.thisCompilation.tap(\n 'RemoteWebpackRequirePlugin',\n (compilation) => {\n compilation.hooks.runtimeRequirementInTree\n .for('__webpack_require__')\n .tap('RemoteWebpackRequirePlugin', (chunk) => {\n compilation.addRuntimeModule(\n chunk,\n new RemoteWebpackRequireRuntimeModule(\n this.appName,\n ) as unknown as RuntimeModule,\n );\n });\n },\n );\n }\n}\n","export function createModuleIdEmbedRuntimeModule(webpack: {\n RuntimeModule: new (name: string, stage?: number) => object;\n}) {\n return class ModuleIdEmbedRuntimeModule extends webpack.RuntimeModule {\n appName: string;\n moduleMap: Record<string | number, unknown>;\n\n constructor(appName: string, moduleMap: Record<string | number, unknown>) {\n super('remote-webpack-module-id-embed');\n this.appName = appName;\n this.moduleMap = moduleMap;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__[\"${this.appName}\"] = ${JSON.stringify(this.moduleMap)};`;\n }\n };\n}\n","import type { NormalModule, Compiler, RuntimeModule } from 'webpack';\nimport { createModuleIdEmbedRuntimeModule } from './module-id-embed-runtime-module';\n\nexport class ModuleIdEmbedPlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const ModuleIdEmbedRuntimeModule = createModuleIdEmbedRuntimeModule(\n compiler.webpack,\n );\n\n compiler.hooks.thisCompilation.tap('ModuleIdEmbedPlugin', (compilation) => {\n const moduleMap = {} as Record<string, string | number>;\n\n compilation.hooks.runtimeRequirementInTree\n .for(compiler.webpack.RuntimeGlobals.require)\n .tap('ModuleIdEmbedPlugin', (chunk, set) => {\n for (const [key, entry] of compilation.entrypoints) {\n for (const entryChunk of entry.chunks) {\n if (key.includes('nextjs-pages-remote')) {\n for (const mod of compilation.chunkGraph.getChunkModulesIterable(\n entryChunk,\n )) {\n const id = compilation.chunkGraph.getModuleId(mod);\n const normalModule = mod as NormalModule;\n if (id) {\n moduleMap[normalModule.resource || normalModule.request] =\n id;\n }\n }\n }\n }\n }\n for (const mod of compilation.modules) {\n const id = compilation.chunkGraph.getModuleId(mod);\n if (id && mod.layer?.endsWith('browser')) {\n const normalModule = mod as NormalModule;\n moduleMap[normalModule.resource || normalModule.request] = id;\n }\n }\n\n if (Object.keys(moduleMap).length > 0) {\n compilation.addRuntimeModule(\n chunk,\n new ModuleIdEmbedRuntimeModule(\n this.appName,\n moduleMap,\n ) as unknown as RuntimeModule,\n );\n\n set.add(compiler.webpack.RuntimeGlobals.require);\n }\n });\n });\n }\n}\n","import type { Compiler } from 'webpack';\n\nexport class ConditionalExecPlugin {\n apply(compiler: Compiler) {\n const { Compilation, sources } = compiler.webpack;\n\n compiler.hooks.thisCompilation.tap(\n 'ConditionalExecPlugin',\n (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'ConditionalExecPlugin',\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n (assets) => {\n for (const [name, source] of Object.entries(assets)) {\n if (name.endsWith('.js')) {\n const patchedSource = source\n .source()\n .toString()\n .replace(\n `var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))`,\n `var __webpack_exec__ = (moduleId) => { if (globalThis.__DISABLE_WEBPACK_EXEC__) return; return __webpack_require__(__webpack_require__.s = moduleId); }`,\n );\n compilation.updateAsset(\n name,\n new sources.RawSource(patchedSource),\n );\n }\n }\n },\n );\n },\n );\n }\n}\n","import type { Compiler } from 'webpack';\n\n// This plugin patches the webpack require function to support loading remote components in Next.js\nexport class PatchRequirePlugin {\n apply(compiler: Compiler) {\n const { sources } = compiler.webpack;\n\n compiler.hooks.thisCompilation.tap('PatchRequirePlugin', (compilation) => {\n compilation.mainTemplate.hooks.requireExtensions.tap(\n 'PatchRequirePlugin',\n (source) => {\n return new sources.ConcatSource(\n source,\n `const __webpack_require_orig__ = __webpack_require__;\nconst REMOTE_RE = /\\\\[(?<bundle>[a-zA-Z0-9-_]+)\\\\] (?<id>.*)/;\n__webpack_require__ = function __remote_webpack_require__(remoteId) {\n const match = REMOTE_RE.exec(remoteId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_orig__(remoteId);\n }\n if (typeof self.__remote_webpack_require__?.[bundle] !== 'function') {\n throw new Error(\\`Remote component loading error: \"\\${bundle}\"\\`);\n }\n return self.__remote_webpack_require__[bundle](self.__remote_webpack_require__[bundle].type === 'turbopack' ? remoteId : id);\n};\nObject.assign(__webpack_require__, __webpack_require_orig__);\nconst __webpack_require_l__ = __webpack_require__.l;\n__webpack_require__.l = function __remote_webpack_require_l__(url, done, key, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_l__(url, done, key, chunkId);\n }\n return done();\n};\nconst __webpack_require_o__ = __webpack_require__.o;\n__webpack_require__.o = function __remote_webpack_require_o__(installedChunks, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_o__(installedChunks, chunkId);\n }\n return installedChunks[chunkId] = 0;\n};\nconst __webpack_require_e__ = __webpack_require__.e;\n__webpack_require__.e = function __remote_webpack_require_e__(chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_e__(chunkId);\n }\n return Promise.resolve([]);\n};`,\n )\n .source()\n .toString();\n },\n );\n });\n }\n}\n"],"mappings":";AAAA,SAAS,UAAU,SAAS,QAAAA,OAAM,gBA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