remote-components 0.0.47 → 0.0.49

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.
Files changed (64) hide show
  1. package/dist/{component-loader-26b1f55e.d.ts → component-loader-1838f572.d.ts} +62 -8
  2. package/dist/html/host.cjs +165 -70
  3. package/dist/html/host.cjs.map +1 -1
  4. package/dist/html/host.js +165 -70
  5. package/dist/html/host.js.map +1 -1
  6. package/dist/internal/next/host/app-router-client.cjs +13 -50
  7. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  8. package/dist/internal/next/host/app-router-client.d.ts +1 -1
  9. package/dist/internal/next/host/app-router-client.js +14 -51
  10. package/dist/internal/next/host/app-router-client.js.map +1 -1
  11. package/dist/internal/next/host/remote-component-links.cjs +96 -0
  12. package/dist/internal/next/host/remote-component-links.cjs.map +1 -0
  13. package/dist/internal/next/host/remote-component-links.d.ts +25 -0
  14. package/dist/internal/next/host/remote-component-links.js +72 -0
  15. package/dist/internal/next/host/remote-component-links.js.map +1 -0
  16. package/dist/internal/shared/client/remote-component.cjs +17 -1
  17. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  18. package/dist/internal/shared/client/remote-component.d.ts +2 -2
  19. package/dist/internal/shared/client/remote-component.js +17 -1
  20. package/dist/internal/shared/client/remote-component.js.map +1 -1
  21. package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
  22. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
  23. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +13 -3
  24. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
  25. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +24 -13
  26. package/dist/internal/shared/ssr/fetch-with-hooks.js +13 -3
  27. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
  28. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs +6 -1
  29. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs.map +1 -1
  30. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.d.ts +3 -0
  31. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js +6 -1
  32. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js.map +1 -1
  33. package/dist/internal/shared/utils/abort.cjs +38 -0
  34. package/dist/internal/shared/utils/abort.cjs.map +1 -0
  35. package/dist/internal/shared/utils/abort.d.ts +7 -0
  36. package/dist/internal/shared/utils/abort.js +14 -0
  37. package/dist/internal/shared/utils/abort.js.map +1 -0
  38. package/dist/next/config.cjs +4 -2
  39. package/dist/next/config.cjs.map +1 -1
  40. package/dist/next/config.js +4 -2
  41. package/dist/next/config.js.map +1 -1
  42. package/dist/next/host/app-router-server.d.ts +1 -1
  43. package/dist/next/host/client/index.cjs +41 -8
  44. package/dist/next/host/client/index.cjs.map +1 -1
  45. package/dist/next/host/client/index.d.ts +1 -1
  46. package/dist/next/host/client/index.js +41 -8
  47. package/dist/next/host/client/index.js.map +1 -1
  48. package/dist/next/host/pages-router-client.d.ts +1 -1
  49. package/dist/next/host/pages-router-server.d.ts +1 -1
  50. package/dist/next/index.d.ts +1 -1
  51. package/dist/next/proxy.cjs.map +1 -1
  52. package/dist/next/proxy.js.map +1 -1
  53. package/dist/react/index.cjs +41 -8
  54. package/dist/react/index.cjs.map +1 -1
  55. package/dist/react/index.d.ts +2 -1
  56. package/dist/react/index.js +41 -8
  57. package/dist/react/index.js.map +1 -1
  58. package/dist/{types-6e4ba234.d.ts → types-cbe44b51.d.ts} +61 -7
  59. package/dist/webpack.cjs +274 -0
  60. package/dist/webpack.cjs.map +1 -0
  61. package/dist/webpack.d.ts +14 -0
  62. package/dist/webpack.js +247 -0
  63. package/dist/webpack.js.map +1 -0
  64. package/package.json +9 -1
@@ -42,17 +42,51 @@ interface RemoteComponentMetadata {
42
42
  id: string;
43
43
  type: 'nextjs' | 'remote-component' | 'unknown';
44
44
  }
45
+ /**
46
+ * Options object passed to hook functions containing abort capabilities.
47
+ * Uses standard AbortController/AbortSignal for compatibility with Web APIs.
48
+ *
49
+ * @example
50
+ * // Abort on redirect
51
+ * component.onResponse = (url, response, { signal, abort }) => {
52
+ * if (response.redirected) {
53
+ * abort();
54
+ * }
55
+ * };
56
+ *
57
+ * @example
58
+ * // Check if already aborted
59
+ * component.onRequest = (url, init, { signal }) => {
60
+ * if (signal.aborted) return;
61
+ * // ...
62
+ * };
63
+ *
64
+ * @example
65
+ * // Pass signal to fetch or other APIs
66
+ * component.onRequest = async (url, init, { signal }) => {
67
+ * const data = await fetch('/api/check', { signal });
68
+ * // ...
69
+ * };
70
+ */
71
+ interface HookOptions {
72
+ /** Standard AbortSignal - can be passed to fetch and other Web APIs */
73
+ signal: AbortSignal;
74
+ /** Abort loading - prevents further processing and DOM attachment */
75
+ abort(reason?: unknown): void;
76
+ }
45
77
  /**
46
78
  * Hook function that intercepts remote component fetch requests.
47
- * Can be used to modify request options, provide a custom response, or inspect the request.
79
+ * Can be used to modify request options, provide a custom response, inspect the request,
80
+ * or abort loading.
48
81
  *
49
82
  * @param url - The URL being fetched
50
83
  * @param init - The fetch init options being used
84
+ * @param options - Options object containing the abort signal
51
85
  * @returns Optional Response to use instead of fetching, or void/undefined to proceed with normal fetch
52
86
  *
53
87
  * @example
54
88
  * // Log all remote component requests
55
- * const onRequest = async (url, init) => {
89
+ * const onRequest = async (url, init, { abort }) => {
56
90
  * console.log('Fetching remote component from:', url.href);
57
91
  * };
58
92
  *
@@ -70,21 +104,32 @@ interface RemoteComponentMetadata {
70
104
  * return new Response(cached);
71
105
  * }
72
106
  * };
107
+ *
108
+ * @example
109
+ * // Block certain domains
110
+ * const onRequest = async (url, init, { abort }) => {
111
+ * if (isBlockedDomain(url)) {
112
+ * abort('Domain is blocked');
113
+ * }
114
+ * };
73
115
  */
74
- type OnRequestHook = (url: URL, init: RequestInit) => Promise<Response | undefined> | Response | undefined;
116
+ type OnRequestHook = (url: URL, init: RequestInit, options: HookOptions) => Promise<Response | undefined> | Response | undefined;
75
117
  /**
76
118
  * Hook function that is called after a remote component fetch completes.
77
- * Can be used to inspect the response, check for redirects, or transform the response.
119
+ * Can be used to inspect the response, check for redirects, transform the response,
120
+ * or abort loading.
78
121
  *
79
122
  * @param url - The original URL that was requested
80
123
  * @param response - The Response object from the fetch
124
+ * @param options - Options object containing the abort signal
81
125
  * @returns Optional Response to use instead of the original, or void/undefined to use the original response
82
126
  *
83
127
  * @example
84
- * // Check for redirects
85
- * const onResponse = async (url, response) => {
128
+ * // Check for redirects and abort
129
+ * const onResponse = async (url, response, { abort }) => {
86
130
  * if (response.redirected) {
87
131
  * console.log(`Redirected from ${url.href} to ${response.url}`);
132
+ * abort();
88
133
  * }
89
134
  * };
90
135
  *
@@ -102,8 +147,17 @@ type OnRequestHook = (url: URL, init: RequestInit) => Promise<Response | undefin
102
147
  * const modified = text.replace(/foo/g, 'bar');
103
148
  * return new Response(modified, response);
104
149
  * };
150
+ *
151
+ * @example
152
+ * // Abort on redirect to legacy routes
153
+ * const onResponse = async (url, response, { abort }) => {
154
+ * if (response.redirected && isLegacyRoute(response.url)) {
155
+ * window.location.href = toLegacyUrl(response.url);
156
+ * abort(); // Abort rendering - no flash!
157
+ * }
158
+ * };
105
159
  */
106
- type OnResponseHook = (url: URL, response: Response) => Promise<Response | undefined> | Response | undefined;
160
+ type OnResponseHook = (url: URL, response: Response, options: HookOptions) => Promise<Response | undefined> | Response | undefined;
107
161
  interface NextData {
108
162
  props: {
109
163
  pageProps: Record<string, unknown>;
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/webpack/index.ts
21
+ var webpack_exports = {};
22
+ __export(webpack_exports, {
23
+ RemoteComponentsWebpackPlugin: () => RemoteComponentsWebpackPlugin
24
+ });
25
+ module.exports = __toCommonJS(webpack_exports);
26
+
27
+ // src/next/config/webpack/plugins/conditional-exec.ts
28
+ var ConditionalExecPlugin = class {
29
+ appName;
30
+ constructor(appName) {
31
+ this.appName = appName;
32
+ }
33
+ apply(compiler) {
34
+ const { Compilation, sources } = compiler.webpack;
35
+ compiler.hooks.thisCompilation.tap(
36
+ "ConditionalExecPlugin",
37
+ (compilation) => {
38
+ compilation.hooks.processAssets.tap(
39
+ {
40
+ name: "ConditionalExecPlugin",
41
+ stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
42
+ },
43
+ (assets) => {
44
+ for (const [name, source] of Object.entries(assets)) {
45
+ if (name.endsWith(".js")) {
46
+ const patchedSource = source.source().toString().replace(
47
+ `var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))`,
48
+ `var __webpack_exec__ = (moduleId) => { if (globalThis.__DISABLE_WEBPACK_EXEC__ && globalThis.__DISABLE_WEBPACK_EXEC__["${this.appName}"]) return; return __webpack_require__(__webpack_require__.s = moduleId); }`
49
+ );
50
+ compilation.updateAsset(
51
+ name,
52
+ new sources.RawSource(patchedSource)
53
+ );
54
+ }
55
+ }
56
+ }
57
+ );
58
+ }
59
+ );
60
+ }
61
+ };
62
+
63
+ // src/next/config/webpack/plugins/module-id-embed.ts
64
+ var import_node_path = require("path");
65
+
66
+ // src/next/config/webpack/plugins/module-id-embed-runtime-module.ts
67
+ function createModuleIdEmbedRuntimeModule(webpack) {
68
+ return class ModuleIdEmbedRuntimeModule extends webpack.RuntimeModule {
69
+ appName;
70
+ moduleMap;
71
+ constructor(appName, moduleMap) {
72
+ super("remote-webpack-module-id-embed");
73
+ this.appName = appName;
74
+ this.moduleMap = moduleMap;
75
+ }
76
+ generate() {
77
+ return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__["${this.appName}"] = ${JSON.stringify(this.moduleMap)};`;
78
+ }
79
+ };
80
+ }
81
+
82
+ // src/next/config/webpack/plugins/module-id-embed.ts
83
+ var cwd = process.cwd();
84
+ var ModuleIdEmbedPlugin = class {
85
+ appName;
86
+ includeAllModules;
87
+ constructor(appName, options) {
88
+ this.appName = appName;
89
+ this.includeAllModules = options?.includeAllModules ?? false;
90
+ }
91
+ apply(compiler) {
92
+ const ModuleIdEmbedRuntimeModule = createModuleIdEmbedRuntimeModule(
93
+ compiler.webpack
94
+ );
95
+ compiler.hooks.thisCompilation.tap("ModuleIdEmbedPlugin", (compilation) => {
96
+ const moduleMap = {};
97
+ compilation.hooks.runtimeRequirementInTree.for(compiler.webpack.RuntimeGlobals.require).tap("ModuleIdEmbedPlugin", (chunk, set) => {
98
+ for (const [key, entry] of compilation.entrypoints) {
99
+ for (const entryChunk of entry.chunks) {
100
+ if (key.includes("nextjs-pages-remote")) {
101
+ for (const mod of compilation.chunkGraph.getChunkModulesIterable(
102
+ entryChunk
103
+ )) {
104
+ const id = compilation.chunkGraph.getModuleId(mod);
105
+ const normalModule = mod;
106
+ if (id && (normalModule.resource || normalModule.request)) {
107
+ moduleMap[(0, import_node_path.relative)(
108
+ cwd,
109
+ normalModule.resource || normalModule.request
110
+ )] = id;
111
+ }
112
+ }
113
+ }
114
+ }
115
+ }
116
+ for (const mod of compilation.modules) {
117
+ const id = compilation.chunkGraph.getModuleId(mod);
118
+ if (id && (this.includeAllModules || mod.layer?.endsWith("browser"))) {
119
+ const normalModule = mod;
120
+ if (normalModule.resource || normalModule.request) {
121
+ moduleMap[(0, import_node_path.relative)(cwd, normalModule.resource || normalModule.request)] = id;
122
+ }
123
+ }
124
+ }
125
+ if (Object.keys(moduleMap).length > 0) {
126
+ compilation.addRuntimeModule(
127
+ chunk,
128
+ new ModuleIdEmbedRuntimeModule(
129
+ this.appName,
130
+ moduleMap
131
+ )
132
+ );
133
+ set.add(compiler.webpack.RuntimeGlobals.require);
134
+ }
135
+ });
136
+ });
137
+ }
138
+ };
139
+
140
+ // src/next/config/webpack/plugins/patch-require.ts
141
+ var PatchRequirePlugin = class {
142
+ appName;
143
+ constructor(appName) {
144
+ this.appName = appName;
145
+ }
146
+ apply(compiler) {
147
+ const { sources } = compiler.webpack;
148
+ compiler.hooks.thisCompilation.tap("PatchRequirePlugin", (compilation) => {
149
+ compilation.mainTemplate.hooks.requireExtensions.tap(
150
+ "PatchRequirePlugin",
151
+ (source) => {
152
+ return new sources.ConcatSource(
153
+ source,
154
+ `const __webpack_require_orig__ = __webpack_require__;
155
+ const REMOTE_RE = /\\[(?<bundle>[^\\]]+)\\] (?<id>.*)/;
156
+ __webpack_require__ = function __remote_webpack_require__(remoteId) {
157
+ const match = REMOTE_RE.exec(remoteId);
158
+ const bundle = match?.groups?.bundle;
159
+ const id = match?.groups?.id;
160
+ if (!(id && bundle)) {
161
+ return __webpack_require_orig__(remoteId);
162
+ }
163
+ if (typeof self.__remote_webpack_require__?.[bundle] !== 'function') {
164
+ const error = new Error(\`Remote Components are not available in "\${bundle}". Did you forget to wrap the Next.js config with \\\`withRemoteComponents\\\` on both host and remote?\`);
165
+ error.name = 'RemoteComponentsError';
166
+ error.code = 'REMOTE_COMPONENTS_ERROR';
167
+ throw error;
168
+ }
169
+ return self.__remote_webpack_require__[bundle](self.__remote_webpack_require__[bundle].type === 'turbopack' ? remoteId : id);
170
+ };
171
+ Object.assign(__webpack_require__, __webpack_require_orig__);
172
+ const __webpack_require_l__ = __webpack_require__.l;
173
+ __webpack_require__.l = function __remote_webpack_require_l__(url, done, key, chunkId) {
174
+ const match = REMOTE_RE.exec(chunkId);
175
+ const bundle = match?.groups?.bundle;
176
+ const id = match?.groups?.id;
177
+ if (!(id && bundle)) {
178
+ return __webpack_require_l__(new URL(url, globalThis.__remote_bundle_url__?.["${this.appName}"] ?? location.origin).href, done, key, chunkId);
179
+ }
180
+ return done();
181
+ };
182
+ const __webpack_require_o__ = __webpack_require__.o;
183
+ __webpack_require__.o = function __remote_webpack_require_o__(installedChunks, chunkId) {
184
+ const match = REMOTE_RE.exec(chunkId);
185
+ const bundle = match?.groups?.bundle;
186
+ const id = match?.groups?.id;
187
+ if (!(id && bundle)) {
188
+ return __webpack_require_o__(installedChunks, chunkId);
189
+ }
190
+ return installedChunks[chunkId] = 0;
191
+ };
192
+ const __webpack_require_e__ = __webpack_require__.e;
193
+ __webpack_require__.e = function __remote_webpack_require_e__(chunkId) {
194
+ const match = REMOTE_RE.exec(chunkId);
195
+ const bundle = match?.groups?.bundle;
196
+ const id = match?.groups?.id;
197
+ if (!(id && bundle)) {
198
+ return __webpack_require_e__(chunkId);
199
+ }
200
+ return Promise.resolve([]);
201
+ };`
202
+ ).source().toString();
203
+ }
204
+ );
205
+ });
206
+ }
207
+ };
208
+
209
+ // src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts
210
+ function createRemoteWebpackRequireRuntimeModule(webpack) {
211
+ return class RemoteWebpackRequireRuntimeModule extends webpack.RuntimeModule {
212
+ appName;
213
+ constructor(appName) {
214
+ super("remote-webpack-require");
215
+ this.appName = appName;
216
+ }
217
+ generate() {
218
+ return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__["${this.appName}"] = __webpack_require__;`;
219
+ }
220
+ };
221
+ }
222
+
223
+ // src/next/config/webpack/plugins/remote-webpack-require.ts
224
+ var RemoteWebpackRequirePlugin = class {
225
+ appName;
226
+ constructor(appName) {
227
+ this.appName = appName;
228
+ }
229
+ apply(compiler) {
230
+ const RemoteWebpackRequireRuntimeModule = createRemoteWebpackRequireRuntimeModule(compiler.webpack);
231
+ compiler.hooks.thisCompilation.tap(
232
+ "RemoteWebpackRequirePlugin",
233
+ (compilation) => {
234
+ compilation.hooks.runtimeRequirementInTree.for("__webpack_require__").tap("RemoteWebpackRequirePlugin", (chunk) => {
235
+ compilation.addRuntimeModule(
236
+ chunk,
237
+ new RemoteWebpackRequireRuntimeModule(
238
+ this.appName
239
+ )
240
+ );
241
+ });
242
+ }
243
+ );
244
+ }
245
+ };
246
+
247
+ // src/webpack/index.ts
248
+ var RemoteComponentsWebpackPlugin = class {
249
+ appName;
250
+ chunkLoadingGlobal;
251
+ constructor({
252
+ appName,
253
+ chunkLoadingGlobal
254
+ }) {
255
+ this.appName = appName;
256
+ this.chunkLoadingGlobal = chunkLoadingGlobal;
257
+ }
258
+ apply(compiler) {
259
+ new RemoteWebpackRequirePlugin(this.appName).apply(compiler);
260
+ new ModuleIdEmbedPlugin(this.appName, { includeAllModules: true }).apply(
261
+ compiler
262
+ );
263
+ new ConditionalExecPlugin(this.appName).apply(compiler);
264
+ new PatchRequirePlugin(this.appName).apply(compiler);
265
+ if (compiler.options.output) {
266
+ compiler.options.output.chunkLoadingGlobal = this.chunkLoadingGlobal ?? compiler.options.output.chunkLoadingGlobal ?? `__remote_chunk_loading_global_${this.appName}__`;
267
+ }
268
+ }
269
+ };
270
+ // Annotate the CommonJS export names for ESM import in node:
271
+ 0 && (module.exports = {
272
+ RemoteComponentsWebpackPlugin
273
+ });
274
+ //# sourceMappingURL=webpack.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/webpack/index.ts","../src/next/config/webpack/plugins/conditional-exec.ts","../src/next/config/webpack/plugins/module-id-embed.ts","../src/next/config/webpack/plugins/module-id-embed-runtime-module.ts","../src/next/config/webpack/plugins/patch-require.ts","../src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts","../src/next/config/webpack/plugins/remote-webpack-require.ts"],"sourcesContent":["import type { Compiler } from 'webpack';\nimport { ConditionalExecPlugin } from '../next/config/webpack/plugins/conditional-exec';\nimport { ModuleIdEmbedPlugin } from '../next/config/webpack/plugins/module-id-embed';\nimport { PatchRequirePlugin } from '../next/config/webpack/plugins/patch-require';\nimport { RemoteWebpackRequirePlugin } from '../next/config/webpack/plugins/remote-webpack-require';\n\nexport type RemoteComponentsWebpackPluginOptions = {\n appName: string;\n chunkLoadingGlobal?: string;\n};\n\nexport class RemoteComponentsWebpackPlugin {\n private readonly appName: string;\n private readonly chunkLoadingGlobal?: string;\n\n constructor({\n appName,\n chunkLoadingGlobal,\n }: RemoteComponentsWebpackPluginOptions) {\n this.appName = appName;\n this.chunkLoadingGlobal = chunkLoadingGlobal;\n }\n\n apply(compiler: Compiler) {\n new RemoteWebpackRequirePlugin(this.appName).apply(compiler);\n new ModuleIdEmbedPlugin(this.appName, { includeAllModules: true }).apply(\n compiler,\n );\n new ConditionalExecPlugin(this.appName).apply(compiler);\n new PatchRequirePlugin(this.appName).apply(compiler);\n\n if (compiler.options.output) {\n compiler.options.output.chunkLoadingGlobal =\n this.chunkLoadingGlobal ??\n compiler.options.output.chunkLoadingGlobal ??\n `__remote_chunk_loading_global_${this.appName}__`;\n }\n }\n}\n","import type { Compiler } from 'webpack';\n\nexport class ConditionalExecPlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\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__ && globalThis.__DISABLE_WEBPACK_EXEC__[\"${this.appName}\"]) 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 { relative } from 'node:path';\nimport type { Compiler, NormalModule, RuntimeModule } from 'webpack';\nimport { createModuleIdEmbedRuntimeModule } from './module-id-embed-runtime-module';\n\nconst cwd = process.cwd();\n\nexport class ModuleIdEmbedPlugin {\n appName: string;\n includeAllModules: boolean;\n\n constructor(appName: string, options?: { includeAllModules?: boolean }) {\n this.appName = appName;\n this.includeAllModules = options?.includeAllModules ?? false;\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 && (normalModule.resource || normalModule.request)) {\n moduleMap[\n relative(\n cwd,\n normalModule.resource || normalModule.request,\n )\n ] = id;\n }\n }\n }\n }\n }\n for (const mod of compilation.modules) {\n const id = compilation.chunkGraph.getModuleId(mod);\n if (\n id &&\n (this.includeAllModules || mod.layer?.endsWith('browser'))\n ) {\n const normalModule = mod as NormalModule;\n if (normalModule.resource || normalModule.request) {\n moduleMap[\n relative(cwd, normalModule.resource || normalModule.request)\n ] = id;\n }\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","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 { Compiler } from 'webpack';\n\n// This plugin patches the webpack require function to support loading remote components in Next.js\nexport class PatchRequirePlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\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>[^\\\\]]+)\\\\] (?<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 const error = new Error(\\`Remote Components are not available in \"\\${bundle}\". Did you forget to wrap the Next.js config with \\\\\\`withRemoteComponents\\\\\\` on both host and remote?\\`);\n error.name = 'RemoteComponentsError';\n error.code = 'REMOTE_COMPONENTS_ERROR';\n throw error;\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__(new URL(url, globalThis.__remote_bundle_url__?.[\"${this.appName}\"] ?? location.origin).href, 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","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"],"mappings":"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","names":[]}
@@ -0,0 +1,14 @@
1
+ import { Compiler } from 'webpack';
2
+
3
+ type RemoteComponentsWebpackPluginOptions = {
4
+ appName: string;
5
+ chunkLoadingGlobal?: string;
6
+ };
7
+ declare class RemoteComponentsWebpackPlugin {
8
+ private readonly appName;
9
+ private readonly chunkLoadingGlobal?;
10
+ constructor({ appName, chunkLoadingGlobal, }: RemoteComponentsWebpackPluginOptions);
11
+ apply(compiler: Compiler): void;
12
+ }
13
+
14
+ export { RemoteComponentsWebpackPlugin, RemoteComponentsWebpackPluginOptions };
@@ -0,0 +1,247 @@
1
+ // src/next/config/webpack/plugins/conditional-exec.ts
2
+ var ConditionalExecPlugin = class {
3
+ appName;
4
+ constructor(appName) {
5
+ this.appName = appName;
6
+ }
7
+ apply(compiler) {
8
+ const { Compilation, sources } = compiler.webpack;
9
+ compiler.hooks.thisCompilation.tap(
10
+ "ConditionalExecPlugin",
11
+ (compilation) => {
12
+ compilation.hooks.processAssets.tap(
13
+ {
14
+ name: "ConditionalExecPlugin",
15
+ stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
16
+ },
17
+ (assets) => {
18
+ for (const [name, source] of Object.entries(assets)) {
19
+ if (name.endsWith(".js")) {
20
+ const patchedSource = source.source().toString().replace(
21
+ `var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))`,
22
+ `var __webpack_exec__ = (moduleId) => { if (globalThis.__DISABLE_WEBPACK_EXEC__ && globalThis.__DISABLE_WEBPACK_EXEC__["${this.appName}"]) return; return __webpack_require__(__webpack_require__.s = moduleId); }`
23
+ );
24
+ compilation.updateAsset(
25
+ name,
26
+ new sources.RawSource(patchedSource)
27
+ );
28
+ }
29
+ }
30
+ }
31
+ );
32
+ }
33
+ );
34
+ }
35
+ };
36
+
37
+ // src/next/config/webpack/plugins/module-id-embed.ts
38
+ import { relative } from "node:path";
39
+
40
+ // src/next/config/webpack/plugins/module-id-embed-runtime-module.ts
41
+ function createModuleIdEmbedRuntimeModule(webpack) {
42
+ return class ModuleIdEmbedRuntimeModule extends webpack.RuntimeModule {
43
+ appName;
44
+ moduleMap;
45
+ constructor(appName, moduleMap) {
46
+ super("remote-webpack-module-id-embed");
47
+ this.appName = appName;
48
+ this.moduleMap = moduleMap;
49
+ }
50
+ generate() {
51
+ return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__["${this.appName}"] = ${JSON.stringify(this.moduleMap)};`;
52
+ }
53
+ };
54
+ }
55
+
56
+ // src/next/config/webpack/plugins/module-id-embed.ts
57
+ var cwd = process.cwd();
58
+ var ModuleIdEmbedPlugin = class {
59
+ appName;
60
+ includeAllModules;
61
+ constructor(appName, options) {
62
+ this.appName = appName;
63
+ this.includeAllModules = options?.includeAllModules ?? false;
64
+ }
65
+ apply(compiler) {
66
+ const ModuleIdEmbedRuntimeModule = createModuleIdEmbedRuntimeModule(
67
+ compiler.webpack
68
+ );
69
+ compiler.hooks.thisCompilation.tap("ModuleIdEmbedPlugin", (compilation) => {
70
+ const moduleMap = {};
71
+ compilation.hooks.runtimeRequirementInTree.for(compiler.webpack.RuntimeGlobals.require).tap("ModuleIdEmbedPlugin", (chunk, set) => {
72
+ for (const [key, entry] of compilation.entrypoints) {
73
+ for (const entryChunk of entry.chunks) {
74
+ if (key.includes("nextjs-pages-remote")) {
75
+ for (const mod of compilation.chunkGraph.getChunkModulesIterable(
76
+ entryChunk
77
+ )) {
78
+ const id = compilation.chunkGraph.getModuleId(mod);
79
+ const normalModule = mod;
80
+ if (id && (normalModule.resource || normalModule.request)) {
81
+ moduleMap[relative(
82
+ cwd,
83
+ normalModule.resource || normalModule.request
84
+ )] = id;
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ for (const mod of compilation.modules) {
91
+ const id = compilation.chunkGraph.getModuleId(mod);
92
+ if (id && (this.includeAllModules || mod.layer?.endsWith("browser"))) {
93
+ const normalModule = mod;
94
+ if (normalModule.resource || normalModule.request) {
95
+ moduleMap[relative(cwd, normalModule.resource || normalModule.request)] = id;
96
+ }
97
+ }
98
+ }
99
+ if (Object.keys(moduleMap).length > 0) {
100
+ compilation.addRuntimeModule(
101
+ chunk,
102
+ new ModuleIdEmbedRuntimeModule(
103
+ this.appName,
104
+ moduleMap
105
+ )
106
+ );
107
+ set.add(compiler.webpack.RuntimeGlobals.require);
108
+ }
109
+ });
110
+ });
111
+ }
112
+ };
113
+
114
+ // src/next/config/webpack/plugins/patch-require.ts
115
+ var PatchRequirePlugin = class {
116
+ appName;
117
+ constructor(appName) {
118
+ this.appName = appName;
119
+ }
120
+ apply(compiler) {
121
+ const { sources } = compiler.webpack;
122
+ compiler.hooks.thisCompilation.tap("PatchRequirePlugin", (compilation) => {
123
+ compilation.mainTemplate.hooks.requireExtensions.tap(
124
+ "PatchRequirePlugin",
125
+ (source) => {
126
+ return new sources.ConcatSource(
127
+ source,
128
+ `const __webpack_require_orig__ = __webpack_require__;
129
+ const REMOTE_RE = /\\[(?<bundle>[^\\]]+)\\] (?<id>.*)/;
130
+ __webpack_require__ = function __remote_webpack_require__(remoteId) {
131
+ const match = REMOTE_RE.exec(remoteId);
132
+ const bundle = match?.groups?.bundle;
133
+ const id = match?.groups?.id;
134
+ if (!(id && bundle)) {
135
+ return __webpack_require_orig__(remoteId);
136
+ }
137
+ if (typeof self.__remote_webpack_require__?.[bundle] !== 'function') {
138
+ const error = new Error(\`Remote Components are not available in "\${bundle}". Did you forget to wrap the Next.js config with \\\`withRemoteComponents\\\` on both host and remote?\`);
139
+ error.name = 'RemoteComponentsError';
140
+ error.code = 'REMOTE_COMPONENTS_ERROR';
141
+ throw error;
142
+ }
143
+ return self.__remote_webpack_require__[bundle](self.__remote_webpack_require__[bundle].type === 'turbopack' ? remoteId : id);
144
+ };
145
+ Object.assign(__webpack_require__, __webpack_require_orig__);
146
+ const __webpack_require_l__ = __webpack_require__.l;
147
+ __webpack_require__.l = function __remote_webpack_require_l__(url, done, key, chunkId) {
148
+ const match = REMOTE_RE.exec(chunkId);
149
+ const bundle = match?.groups?.bundle;
150
+ const id = match?.groups?.id;
151
+ if (!(id && bundle)) {
152
+ return __webpack_require_l__(new URL(url, globalThis.__remote_bundle_url__?.["${this.appName}"] ?? location.origin).href, done, key, chunkId);
153
+ }
154
+ return done();
155
+ };
156
+ const __webpack_require_o__ = __webpack_require__.o;
157
+ __webpack_require__.o = function __remote_webpack_require_o__(installedChunks, chunkId) {
158
+ const match = REMOTE_RE.exec(chunkId);
159
+ const bundle = match?.groups?.bundle;
160
+ const id = match?.groups?.id;
161
+ if (!(id && bundle)) {
162
+ return __webpack_require_o__(installedChunks, chunkId);
163
+ }
164
+ return installedChunks[chunkId] = 0;
165
+ };
166
+ const __webpack_require_e__ = __webpack_require__.e;
167
+ __webpack_require__.e = function __remote_webpack_require_e__(chunkId) {
168
+ const match = REMOTE_RE.exec(chunkId);
169
+ const bundle = match?.groups?.bundle;
170
+ const id = match?.groups?.id;
171
+ if (!(id && bundle)) {
172
+ return __webpack_require_e__(chunkId);
173
+ }
174
+ return Promise.resolve([]);
175
+ };`
176
+ ).source().toString();
177
+ }
178
+ );
179
+ });
180
+ }
181
+ };
182
+
183
+ // src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts
184
+ function createRemoteWebpackRequireRuntimeModule(webpack) {
185
+ return class RemoteWebpackRequireRuntimeModule extends webpack.RuntimeModule {
186
+ appName;
187
+ constructor(appName) {
188
+ super("remote-webpack-require");
189
+ this.appName = appName;
190
+ }
191
+ generate() {
192
+ return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__["${this.appName}"] = __webpack_require__;`;
193
+ }
194
+ };
195
+ }
196
+
197
+ // src/next/config/webpack/plugins/remote-webpack-require.ts
198
+ var RemoteWebpackRequirePlugin = class {
199
+ appName;
200
+ constructor(appName) {
201
+ this.appName = appName;
202
+ }
203
+ apply(compiler) {
204
+ const RemoteWebpackRequireRuntimeModule = createRemoteWebpackRequireRuntimeModule(compiler.webpack);
205
+ compiler.hooks.thisCompilation.tap(
206
+ "RemoteWebpackRequirePlugin",
207
+ (compilation) => {
208
+ compilation.hooks.runtimeRequirementInTree.for("__webpack_require__").tap("RemoteWebpackRequirePlugin", (chunk) => {
209
+ compilation.addRuntimeModule(
210
+ chunk,
211
+ new RemoteWebpackRequireRuntimeModule(
212
+ this.appName
213
+ )
214
+ );
215
+ });
216
+ }
217
+ );
218
+ }
219
+ };
220
+
221
+ // src/webpack/index.ts
222
+ var RemoteComponentsWebpackPlugin = class {
223
+ appName;
224
+ chunkLoadingGlobal;
225
+ constructor({
226
+ appName,
227
+ chunkLoadingGlobal
228
+ }) {
229
+ this.appName = appName;
230
+ this.chunkLoadingGlobal = chunkLoadingGlobal;
231
+ }
232
+ apply(compiler) {
233
+ new RemoteWebpackRequirePlugin(this.appName).apply(compiler);
234
+ new ModuleIdEmbedPlugin(this.appName, { includeAllModules: true }).apply(
235
+ compiler
236
+ );
237
+ new ConditionalExecPlugin(this.appName).apply(compiler);
238
+ new PatchRequirePlugin(this.appName).apply(compiler);
239
+ if (compiler.options.output) {
240
+ compiler.options.output.chunkLoadingGlobal = this.chunkLoadingGlobal ?? compiler.options.output.chunkLoadingGlobal ?? `__remote_chunk_loading_global_${this.appName}__`;
241
+ }
242
+ }
243
+ };
244
+ export {
245
+ RemoteComponentsWebpackPlugin
246
+ };
247
+ //# sourceMappingURL=webpack.js.map