remote-components 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-2VQGCACH.js → chunk-52BJ7VFA.js} +30 -18
- package/dist/chunk-52BJ7VFA.js.map +1 -0
- package/dist/{chunk-KKBEMQU7.cjs → chunk-AWWWK2ZY.cjs} +28 -28
- package/dist/{chunk-KEPHL25S.js → chunk-D5GNZB6O.js} +2 -1
- package/dist/chunk-D5GNZB6O.js.map +1 -0
- package/dist/{chunk-W5ESPGHH.js → chunk-GBFUPMMI.js} +5 -5
- package/dist/{chunk-ER73O65F.cjs → chunk-I47KE3EC.cjs} +23 -23
- package/dist/{chunk-6IUP26UK.cjs → chunk-LCXO7BUY.cjs} +3 -3
- package/dist/{chunk-OO4AMJWO.js → chunk-LQ7VQ74E.js} +2 -2
- package/dist/{chunk-42N2ZLE2.js → chunk-NZAB7REE.js} +6 -6
- package/dist/{chunk-KYJWRZ2B.js → chunk-QKB74MLO.js} +3 -3
- package/dist/{chunk-F44NODUS.cjs → chunk-RJW3EZJP.cjs} +26 -26
- package/dist/{chunk-HNZVEIKN.js → chunk-SJM7AAGU.js} +2 -2
- package/dist/{chunk-ZPMTZ3KJ.js → chunk-SZFCBE54.js} +2 -2
- package/dist/{chunk-XCFYWSLD.cjs → chunk-T64P7BAG.cjs} +31 -19
- package/dist/chunk-T64P7BAG.cjs.map +1 -0
- package/dist/{chunk-CREXMFMF.cjs → chunk-TZT7DLO5.cjs} +4 -4
- package/dist/{chunk-R4QFK5TN.cjs → chunk-X6W464D6.cjs} +4 -4
- package/dist/{chunk-7MVFHOIP.cjs → chunk-Z2SLBFQL.cjs} +2 -1
- package/dist/chunk-Z2SLBFQL.cjs.map +1 -0
- package/dist/config/nextjs.cjs +5 -11
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js +2 -8
- package/dist/config/nextjs.js.map +1 -1
- package/dist/host/html.cjs +27 -27
- package/dist/host/html.js +10 -10
- package/dist/host/nextjs/app/client-only.cjs +13 -13
- package/dist/host/nextjs/app/client-only.js +8 -8
- package/dist/host/react.cjs +9 -9
- package/dist/host/react.js +8 -8
- package/dist/internal/config/webpack/next-client-pages-loader.cjs +27 -15
- package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.d.ts +3 -5
- package/dist/internal/config/webpack/next-client-pages-loader.js +27 -15
- package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
- package/dist/internal/host/nextjs/app-client.d.ts +1 -1
- package/dist/internal/host/react/context.d.ts +2 -2
- package/dist/internal/host/shared/pipeline.d.ts +2 -2
- package/dist/internal/runtime/loaders/component-loader.d.ts +2 -2
- package/dist/internal/runtime/loaders/static-loader.d.ts +2 -1
- package/dist/internal/runtime/namespace.cjs +1 -0
- package/dist/internal/runtime/namespace.cjs.map +1 -1
- package/dist/internal/runtime/namespace.d.ts +2 -1
- package/dist/internal/runtime/namespace.js +1 -0
- package/dist/internal/runtime/namespace.js.map +1 -1
- package/dist/internal/runtime/types.d.ts +2 -1
- package/dist/remote/html.cjs +1 -1
- package/dist/remote/html.js +1 -1
- package/dist/{script-6W5JRBZK.cjs → script-D5AD7HLV.cjs} +4 -4
- package/dist/{script-IFEBOLIA.js → script-VPOI7ARP.js} +3 -3
- package/dist/{server-handoff-ce13bebc.d.ts → server-handoff-8c89b856.d.ts} +2 -2
- package/dist/{static-loader-X4TSF5KW.js → static-loader-OHSAUD62.js} +3 -3
- package/dist/static-loader-UDIXK5MV.cjs +11 -0
- package/dist/{turbopack-NPGO3MWS.js → turbopack-5LW6V6IT.js} +5 -5
- package/dist/{turbopack-WRMKPNN4.cjs → turbopack-KRKECGY2.cjs} +12 -12
- package/dist/{types-59251814.d.ts → types-8b0edd78.d.ts} +7 -0
- package/dist/{webpack-DUBHPYD6.js → webpack-NPZNXRNL.js} +5 -5
- package/dist/{webpack-KSCMCL7M.cjs → webpack-TTZDARNY.cjs} +12 -12
- package/package.json +1 -1
- package/dist/chunk-2VQGCACH.js.map +0 -1
- package/dist/chunk-7MVFHOIP.cjs.map +0 -1
- package/dist/chunk-KEPHL25S.js.map +0 -1
- package/dist/chunk-XCFYWSLD.cjs.map +0 -1
- package/dist/static-loader-ZYD5BO4D.cjs +0 -11
- /package/dist/{chunk-KKBEMQU7.cjs.map → chunk-AWWWK2ZY.cjs.map} +0 -0
- /package/dist/{chunk-W5ESPGHH.js.map → chunk-GBFUPMMI.js.map} +0 -0
- /package/dist/{chunk-ER73O65F.cjs.map → chunk-I47KE3EC.cjs.map} +0 -0
- /package/dist/{chunk-6IUP26UK.cjs.map → chunk-LCXO7BUY.cjs.map} +0 -0
- /package/dist/{chunk-OO4AMJWO.js.map → chunk-LQ7VQ74E.js.map} +0 -0
- /package/dist/{chunk-42N2ZLE2.js.map → chunk-NZAB7REE.js.map} +0 -0
- /package/dist/{chunk-KYJWRZ2B.js.map → chunk-QKB74MLO.js.map} +0 -0
- /package/dist/{chunk-F44NODUS.cjs.map → chunk-RJW3EZJP.cjs.map} +0 -0
- /package/dist/{chunk-HNZVEIKN.js.map → chunk-SJM7AAGU.js.map} +0 -0
- /package/dist/{chunk-ZPMTZ3KJ.js.map → chunk-SZFCBE54.js.map} +0 -0
- /package/dist/{chunk-CREXMFMF.cjs.map → chunk-TZT7DLO5.cjs.map} +0 -0
- /package/dist/{chunk-R4QFK5TN.cjs.map → chunk-X6W464D6.cjs.map} +0 -0
- /package/dist/{script-6W5JRBZK.cjs.map → script-D5AD7HLV.cjs.map} +0 -0
- /package/dist/{script-IFEBOLIA.js.map → script-VPOI7ARP.js.map} +0 -0
- /package/dist/{static-loader-X4TSF5KW.js.map → static-loader-OHSAUD62.js.map} +0 -0
- /package/dist/{static-loader-ZYD5BO4D.cjs.map → static-loader-UDIXK5MV.cjs.map} +0 -0
- /package/dist/{turbopack-NPGO3MWS.js.map → turbopack-5LW6V6IT.js.map} +0 -0
- /package/dist/{turbopack-WRMKPNN4.cjs.map → turbopack-KRKECGY2.cjs.map} +0 -0
- /package/dist/{webpack-DUBHPYD6.js.map → webpack-NPZNXRNL.js.map} +0 -0
- /package/dist/{webpack-KSCMCL7M.cjs.map → webpack-TTZDARNY.cjs.map} +0 -0
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
getScope,
|
|
9
9
|
parseRemoteId,
|
|
10
10
|
registerScope
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-SJM7AAGU.js";
|
|
12
12
|
import {
|
|
13
13
|
getNamespace
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-D5GNZB6O.js";
|
|
15
15
|
import {
|
|
16
16
|
RemoteComponentsError,
|
|
17
17
|
failedProxiedAssetError,
|
|
@@ -706,4 +706,4 @@ export {
|
|
|
706
706
|
initializeSharedModules,
|
|
707
707
|
setupRemoteScope
|
|
708
708
|
};
|
|
709
|
-
//# sourceMappingURL=chunk-
|
|
709
|
+
//# sourceMappingURL=chunk-QKB74MLO.js.map
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkX6W464D6cjs = require('./chunk-X6W464D6.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkZ2SLBFQLcjs = require('./chunk-Z2SLBFQL.cjs');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -55,13 +55,13 @@ function loadChunkWithScope(scope, chunkId) {
|
|
|
55
55
|
`loadChunkWithScope: "${chunkId}" (scope: "${scope.scopedName}")`
|
|
56
56
|
);
|
|
57
57
|
const self = globalThis;
|
|
58
|
-
const ns =
|
|
59
|
-
const { bundle, path, prefix } =
|
|
58
|
+
const ns = _chunkZ2SLBFQLcjs.getNamespace.call(void 0, );
|
|
59
|
+
const { bundle, path, prefix } = _chunkX6W464D6cjs.parseRemoteId.call(void 0, chunkId);
|
|
60
60
|
const remoteRuntime = _optionalChain([self, 'access', _5 => _5.__remote_webpack_require__, 'optionalAccess', _6 => _6[_nullishCoalesce(bundle, () => ( "default"))]]) ? _optionalChain([self, 'access', _7 => _7.__remote_webpack_require__, 'access', _8 => _8[_nullishCoalesce(bundle, () => ( "default"))], 'optionalAccess', _9 => _9.type]) || "webpack" : scope.runtime;
|
|
61
|
-
if (remoteRuntime ===
|
|
61
|
+
if (remoteRuntime === _chunkX6W464D6cjs.RUNTIME_WEBPACK) {
|
|
62
62
|
return Promise.resolve(void 0);
|
|
63
63
|
}
|
|
64
|
-
const rawPath = path ?
|
|
64
|
+
const rawPath = path ? _chunkX6W464D6cjs.collapseDoubleSlashes.call(void 0, `${prefix}${path}`) : "/";
|
|
65
65
|
const url = new URL(rawPath, scope.url).href;
|
|
66
66
|
if (url.endsWith(".css")) {
|
|
67
67
|
return;
|
|
@@ -95,9 +95,9 @@ function loadChunkWithScope(scope, chunkId) {
|
|
|
95
95
|
function createChunkDispatcher() {
|
|
96
96
|
return function __chunk_dispatcher__(chunkId, scriptBundle) {
|
|
97
97
|
_chunkRUWR74XQcjs.logDebug.call(void 0, "ChunkDispatcher", `Dispatching chunk: "${chunkId}"`);
|
|
98
|
-
const { bundle } =
|
|
98
|
+
const { bundle } = _chunkX6W464D6cjs.parseRemoteId.call(void 0, chunkId);
|
|
99
99
|
const bundleName = bundle || scriptBundle || "default";
|
|
100
|
-
const scope =
|
|
100
|
+
const scope = _chunkX6W464D6cjs.getScope.call(void 0, bundleName);
|
|
101
101
|
_chunkRUWR74XQcjs.logDebug.call(void 0,
|
|
102
102
|
"ChunkDispatcher",
|
|
103
103
|
`Scope resolution: bundle="${bundleName}", scope=${_nullishCoalesce(_optionalChain([scope, 'optionalAccess', _12 => _12.scopedName]), () => ( "null"))}`
|
|
@@ -207,7 +207,7 @@ async function handleTurbopackChunk(code, scope, url) {
|
|
|
207
207
|
const baseUrl = url.slice(0, url.indexOf("/_next"));
|
|
208
208
|
const chunkLoadResult = loadChunkWithScope(
|
|
209
209
|
scope,
|
|
210
|
-
|
|
210
|
+
_chunkX6W464D6cjs.formatRemoteId.call(void 0, scope, `${baseUrl}/_next/${id}`)
|
|
211
211
|
);
|
|
212
212
|
if (chunkLoadResult) {
|
|
213
213
|
loadChunkPromises.push(chunkLoadResult);
|
|
@@ -231,7 +231,7 @@ function requireModule(scope, moduleId, fullId) {
|
|
|
231
231
|
return handleTurbopackModule(
|
|
232
232
|
scope,
|
|
233
233
|
idStr,
|
|
234
|
-
_nullishCoalesce(fullId, () => (
|
|
234
|
+
_nullishCoalesce(fullId, () => ( _chunkX6W464D6cjs.formatRemoteId.call(void 0, scope, idStr)))
|
|
235
235
|
);
|
|
236
236
|
}
|
|
237
237
|
function handleTurbopackModule(scope, moduleId, id) {
|
|
@@ -301,7 +301,7 @@ function findModuleInit(modules, moduleId) {
|
|
|
301
301
|
return void 0;
|
|
302
302
|
}
|
|
303
303
|
function createTurbopackContext(scope, exports, moduleExports, modules, moduleInit, id) {
|
|
304
|
-
const scopedRequire = (moduleId) => requireModule(scope, moduleId,
|
|
304
|
+
const scopedRequire = (moduleId) => requireModule(scope, moduleId, _chunkX6W464D6cjs.formatRemoteId.call(void 0, scope, String(moduleId)));
|
|
305
305
|
return {
|
|
306
306
|
// HMR not implemented for Remote Components
|
|
307
307
|
k: {
|
|
@@ -430,7 +430,7 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
|
|
|
430
430
|
const nextIndex = scriptSrc.indexOf("/_next");
|
|
431
431
|
const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
|
|
432
432
|
const chunkUrl = `${baseUrl}/_next/${url}`;
|
|
433
|
-
return loadChunkWithScope(scope,
|
|
433
|
+
return loadChunkWithScope(scope, _chunkX6W464D6cjs.formatRemoteId.call(void 0, scope, chunkUrl));
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
436
|
throw new Error(
|
|
@@ -486,7 +486,7 @@ async function initializeSharedModules(scope, hostShared = {}, remoteShared = {}
|
|
|
486
486
|
const { default: sharedModuleInitializerInstance } = handleTurbopackModule(
|
|
487
487
|
scope,
|
|
488
488
|
sharedModuleId,
|
|
489
|
-
|
|
489
|
+
_chunkX6W464D6cjs.formatRemoteId.call(void 0, scope, String(sharedModuleInitializerId))
|
|
490
490
|
);
|
|
491
491
|
sharedModuleInitializer = sharedModuleInitializerInstance;
|
|
492
492
|
}
|
|
@@ -580,16 +580,16 @@ function getSharedModule(scope, id) {
|
|
|
580
580
|
// src/runtime/turbopack/remote-scope-setup.ts
|
|
581
581
|
async function setupRemoteScope(runtime, scripts = [], url = new URL(location.href), bundle, resolveClientUrl) {
|
|
582
582
|
const self = globalThis;
|
|
583
|
-
const ns =
|
|
583
|
+
const ns = _chunkZ2SLBFQLcjs.getNamespace.call(void 0, );
|
|
584
584
|
const bundleName = _nullishCoalesce(bundle, () => ( "default"));
|
|
585
|
-
const existingScope =
|
|
585
|
+
const existingScope = _chunkX6W464D6cjs.getScope.call(void 0, bundleName);
|
|
586
586
|
if (existingScope && existingScope.url.origin === url.origin) {
|
|
587
587
|
_chunkRUWR74XQcjs.logDebug.call(void 0,
|
|
588
588
|
"WebpackRuntime",
|
|
589
589
|
`Reusing scope "${existingScope.scopedName}" (turbopackModules=${existingScope.turbopackModules.length})`
|
|
590
590
|
);
|
|
591
591
|
existingScope.resolveClientUrl = resolveClientUrl;
|
|
592
|
-
if (runtime ===
|
|
592
|
+
if (runtime === _chunkX6W464D6cjs.RUNTIME_TURBOPACK) {
|
|
593
593
|
await Promise.allSettled(
|
|
594
594
|
scripts.map(
|
|
595
595
|
(script) => script.src ? loadChunkWithScope(existingScope, script.src) : Promise.resolve(void 0)
|
|
@@ -598,9 +598,9 @@ async function setupRemoteScope(runtime, scripts = [], url = new URL(location.hr
|
|
|
598
598
|
}
|
|
599
599
|
return existingScope;
|
|
600
600
|
}
|
|
601
|
-
const scope =
|
|
602
|
-
|
|
603
|
-
if (runtime ===
|
|
601
|
+
const scope = _chunkX6W464D6cjs.createScope.call(void 0, bundleName, url, runtime, resolveClientUrl);
|
|
602
|
+
_chunkX6W464D6cjs.registerScope.call(void 0, scope);
|
|
603
|
+
if (runtime === _chunkX6W464D6cjs.RUNTIME_WEBPACK && _optionalChain([self, 'access', _17 => _17.__remote_webpack_require__, 'optionalAccess', _18 => _18[bundleName]])) {
|
|
604
604
|
scope.webpackRequire = self.__remote_webpack_require__[bundleName];
|
|
605
605
|
}
|
|
606
606
|
ns.bundleUrls[bundleName] = url;
|
|
@@ -618,7 +618,7 @@ async function setupRemoteScope(runtime, scripts = [], url = new URL(location.hr
|
|
|
618
618
|
self.__webpack_require__ = createModuleDispatcher(runtime);
|
|
619
619
|
ns.dispatcherRuntime = runtime;
|
|
620
620
|
self.__webpack_require_type__ = runtime;
|
|
621
|
-
if (self.__remote_webpack_require__ && runtime ===
|
|
621
|
+
if (self.__remote_webpack_require__ && runtime === _chunkX6W464D6cjs.RUNTIME_TURBOPACK) {
|
|
622
622
|
self.__remote_webpack_require__[bundleName] = self.__webpack_require__;
|
|
623
623
|
self.__remote_webpack_require__[bundleName].type = "turbopack";
|
|
624
624
|
}
|
|
@@ -626,7 +626,7 @@ async function setupRemoteScope(runtime, scripts = [], url = new URL(location.hr
|
|
|
626
626
|
if (_optionalChain([self, 'access', _19 => _19.__remote_webpack_require__, 'optionalAccess', _20 => _20[bundleName]]) && scope.scopedName !== bundleName) {
|
|
627
627
|
self.__remote_webpack_require__[scope.scopedName] = self.__remote_webpack_require__[bundleName];
|
|
628
628
|
}
|
|
629
|
-
if (runtime ===
|
|
629
|
+
if (runtime === _chunkX6W464D6cjs.RUNTIME_TURBOPACK) {
|
|
630
630
|
const results = await Promise.allSettled(
|
|
631
631
|
scripts.map((script) => {
|
|
632
632
|
if (script.src) {
|
|
@@ -649,7 +649,7 @@ async function setupRemoteScope(runtime, scripts = [], url = new URL(location.hr
|
|
|
649
649
|
function createModuleDispatcher(runtime) {
|
|
650
650
|
return (id) => {
|
|
651
651
|
const self = globalThis;
|
|
652
|
-
const { bundle, id: moduleId } = _nullishCoalesce(_optionalChain([id, 'access', _21 => _21.match, 'call', _22 => _22(
|
|
652
|
+
const { bundle, id: moduleId } = _nullishCoalesce(_optionalChain([id, 'access', _21 => _21.match, 'call', _22 => _22(_chunkX6W464D6cjs.REMOTE_COMPONENT_REGEX), 'optionalAccess', _23 => _23.groups]), () => ( {
|
|
653
653
|
bundle: "default",
|
|
654
654
|
id
|
|
655
655
|
}));
|
|
@@ -660,13 +660,13 @@ function createModuleDispatcher(runtime) {
|
|
|
660
660
|
`Resolving "${id}" (bundle: "${bundleName}", runtime: "${remoteRuntime}")`
|
|
661
661
|
);
|
|
662
662
|
try {
|
|
663
|
-
if (remoteRuntime ===
|
|
664
|
-
const scope2 =
|
|
663
|
+
if (remoteRuntime === _chunkX6W464D6cjs.RUNTIME_WEBPACK && bundle && moduleId) {
|
|
664
|
+
const scope2 = _chunkX6W464D6cjs.getScope.call(void 0, bundle);
|
|
665
665
|
if (_optionalChain([scope2, 'optionalAccess', _29 => _29.webpackRequire]))
|
|
666
666
|
return scope2.webpackRequire(moduleId);
|
|
667
667
|
return _optionalChain([self, 'access', _30 => _30.__remote_webpack_require__, 'optionalAccess', _31 => _31[bundle], 'optionalCall', _32 => _32(moduleId)]);
|
|
668
668
|
}
|
|
669
|
-
const scope =
|
|
669
|
+
const scope = _chunkX6W464D6cjs.getScope.call(void 0, bundleName);
|
|
670
670
|
if (scope) {
|
|
671
671
|
return requireModule(scope, _nullishCoalesce(moduleId, () => ( id)), id);
|
|
672
672
|
}
|
|
@@ -706,4 +706,4 @@ function createModuleDispatcher(runtime) {
|
|
|
706
706
|
|
|
707
707
|
|
|
708
708
|
exports.initializeSharedModules = initializeSharedModules; exports.setupRemoteScope = setupRemoteScope;
|
|
709
|
-
//# sourceMappingURL=chunk-
|
|
709
|
+
//# sourceMappingURL=chunk-RJW3EZJP.cjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getNamespace
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-D5GNZB6O.js";
|
|
4
4
|
import {
|
|
5
5
|
logDebug,
|
|
6
6
|
logWarn
|
|
@@ -355,4 +355,4 @@ export {
|
|
|
355
355
|
buildHostShared,
|
|
356
356
|
buildWebpackResolve
|
|
357
357
|
};
|
|
358
|
-
//# sourceMappingURL=chunk-
|
|
358
|
+
//# sourceMappingURL=chunk-SJM7AAGU.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NEXT_BUNDLE_PATH_RE
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SJM7AAGU.js";
|
|
4
4
|
import {
|
|
5
5
|
RemoteComponentsError,
|
|
6
6
|
failedProxiedAssetError,
|
|
@@ -54,4 +54,4 @@ async function loadScripts(scripts, resolveClientUrl) {
|
|
|
54
54
|
export {
|
|
55
55
|
loadScripts
|
|
56
56
|
};
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
57
|
+
//# sourceMappingURL=chunk-SZFCBE54.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkX6W464D6cjs = require('./chunk-X6W464D6.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkZ2SLBFQLcjs = require('./chunk-Z2SLBFQL.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
@@ -22,7 +22,7 @@ function applySharedModules(bundle, resolve) {
|
|
|
22
22
|
`Shared modules to resolve: ${Object.keys(resolve)}`
|
|
23
23
|
);
|
|
24
24
|
const self = globalThis;
|
|
25
|
-
const scope =
|
|
25
|
+
const scope = _chunkX6W464D6cjs.getScope.call(void 0, bundle);
|
|
26
26
|
const webpackBundle = _nullishCoalesce(_optionalChain([scope, 'optionalAccess', _ => _.webpackRequire]), () => ( _optionalChain([self, 'access', _2 => _2.__remote_webpack_require__, 'optionalAccess', _3 => _3[bundle]])));
|
|
27
27
|
if (webpackBundle) {
|
|
28
28
|
const modulePaths = Object.keys(
|
|
@@ -76,6 +76,26 @@ function applySharedModules(bundle, resolve) {
|
|
|
76
76
|
// src/config/webpack/next-client-pages-loader.ts
|
|
77
77
|
function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
78
78
|
const self = globalThis;
|
|
79
|
+
const ns = _chunkZ2SLBFQLcjs.getNamespace.call(void 0, );
|
|
80
|
+
ns.pageComponentCache ??= {};
|
|
81
|
+
const cacheKey = `${bundle}:${route}`;
|
|
82
|
+
const applyBundleCss = () => {
|
|
83
|
+
const elements = _nullishCoalesce(ns.cssCache[bundle], () => ( []));
|
|
84
|
+
if (styleContainer) {
|
|
85
|
+
for (const el of elements) {
|
|
86
|
+
styleContainer.appendChild(el.cloneNode(true));
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
for (const el of elements) {
|
|
90
|
+
document.head.appendChild(el);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const cachedEntry = ns.pageComponentCache[cacheKey];
|
|
95
|
+
if (cachedEntry) {
|
|
96
|
+
applyBundleCss();
|
|
97
|
+
return cachedEntry;
|
|
98
|
+
}
|
|
79
99
|
const nextCssOriginal = document.querySelector(
|
|
80
100
|
`[id="__next_css__DO_NOT_USE__"]:not([data-bundle="${bundle}"][data-route="${route}"])`
|
|
81
101
|
);
|
|
@@ -137,9 +157,9 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
|
137
157
|
default: null
|
|
138
158
|
})
|
|
139
159
|
]));
|
|
140
|
-
const { default: Component } = componentLoader();
|
|
141
|
-
const { default: App } = appLoader();
|
|
142
|
-
const cssCache =
|
|
160
|
+
const { default: Component = null } = componentLoader();
|
|
161
|
+
const { default: App = null } = appLoader();
|
|
162
|
+
const cssCache = ns.cssCache;
|
|
143
163
|
if (!cssCache[bundle]) {
|
|
144
164
|
const cssRE = /\.s?css$/;
|
|
145
165
|
Object.keys(_nullishCoalesce(_optionalChain([self, 'access', _36 => _36.__remote_webpack_require__, 'optionalAccess', _37 => _37[bundle], 'optionalAccess', _38 => _38.m]), () => ( {}))).filter((id) => cssRE.test(id)).forEach((id) => {
|
|
@@ -160,17 +180,7 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
|
160
180
|
}
|
|
161
181
|
cssCache[bundle] = elements;
|
|
162
182
|
}
|
|
163
|
-
|
|
164
|
-
const elements = cssCache[bundle];
|
|
165
|
-
elements.forEach((el) => {
|
|
166
|
-
styleContainer.appendChild(el.cloneNode(true));
|
|
167
|
-
});
|
|
168
|
-
} else {
|
|
169
|
-
const elements = cssCache[bundle];
|
|
170
|
-
elements.forEach((el) => {
|
|
171
|
-
document.head.appendChild(el);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
183
|
+
applyBundleCss();
|
|
174
184
|
delete self.__NEXT_P;
|
|
175
185
|
self.__NEXT_P = __NEXT_P_ORIGINAL;
|
|
176
186
|
if (nextCssOriginal) {
|
|
@@ -178,7 +188,9 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
|
178
188
|
}
|
|
179
189
|
nextCss.remove();
|
|
180
190
|
nextCssEnd.remove();
|
|
181
|
-
|
|
191
|
+
const result = { Component, App };
|
|
192
|
+
ns.pageComponentCache[cacheKey] = result;
|
|
193
|
+
return result;
|
|
182
194
|
}
|
|
183
195
|
return { Component: null, App: null };
|
|
184
196
|
}
|
|
@@ -187,4 +199,4 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
|
187
199
|
|
|
188
200
|
|
|
189
201
|
exports.applySharedModules = applySharedModules; exports.nextClientPagesLoader = nextClientPagesLoader;
|
|
190
|
-
//# sourceMappingURL=chunk-
|
|
202
|
+
//# sourceMappingURL=chunk-T64P7BAG.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config/webpack/apply-shared-modules.ts","../src/config/webpack/next-client-pages-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;AASA,IAAM,wBACJ;AAEK,SAAS,mBACd,QACA,SACA;AACA;AAAA,IACE;AAAA,IACA,0CAA0C;AAAA,EAC5C;AACA;AAAA,IACE;AAAA,IACA,8BAA8B,OAAO,KAAK,OAAO;AAAA,EACnD;AAGA,QAAM,OAAO;AAab,QAAM,QAAQ,SAAS,MAAM;AAI7B,QAAM,gBACJ,OAAO,kBAAkB,KAAK,6BAA6B,MAAM;AAEnE,MAAI,eAAe;AACjB,UAAM,cAAc,OAAO;AAAA,MACzB,KAAK,gCAAgC,MAAM,KAAK,cAAc,KAAK,CAAC;AAAA,IACtE;AACA;AAAA,MACE;AAAA,MACA,sCAAsC,YAAY;AAAA,IACpD;AAGA,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,YAAM,WAAW,YAAY,OAAO,CAAC,MAAM,MAAM,GAAG;AACpD,YAAM,MACJ,SAAS,SAAS,IACd,WACA,YAAY,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC;AAE/C,UAAI,IAAI,WAAW,GAAG;AACpB;AAAA,UACE;AAAA,UACA,oDAAoD;AAAA,QACtD;AAAA,MACF;AAEA,iBAAW,MAAM,KAAK;AACpB,YAAI,cAAc,GAAG;AAGnB,gBAAM,aAAa,KAAK,gCAA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AC,OAAO,MAAM,KAAK,EAAE,CAAC,EAC7B,QAAQ,CAAC,OAAO;AACf,aAAK,6BAA6B,MAAM,IAAI,EAAE;AAAA,MAChD,CAAC;AAEH,aAAO,KAAK,KAAK,gCAAgC,MAAM,KAAK,CAAC,CAAC,EAC3D,OAAO,CAAC,SAAS,MAAM,KAAK,IAAI,CAAC,EACjC,QAAQ,CAAC,SAAS;AACjB,cAAM,KAAK,KAAK,gCAAgC,MAAM,IAAI,IAAI;AAC9D,YAAI,IAAI;AACN,eAAK,6BAA6B,MAAM,IAAI,EAAE;AAAA,QAChD;AAAA,MACF,CAAC;AAEH,YAAM,WAAW,CAAC;AAClB,UAAI,OAAO,QAAQ;AACnB,aAAO,QAAQ,SAAS,YAAY;AAClC,iBAAS,KAAK,IAAI;AAClB,aAAK,OAAO;AACZ,eAAO,QAAQ;AAAA,MACjB;AACA,eAAS,MAAM,IAAI;AAAA,IACrB;AAEA,mBAAe;AAGf,WAAO,KAAK;AACZ,SAAK,WAAW;AAGhB,QAAI,iBAAiB;AACnB,sBAAgB,YAAY,YAAY,eAAe;AAAA,IACzD;AAEA,YAAQ,OAAO;AACf,eAAW,OAAO;AAElB,UAAM,SAAS,EAAE,WAAW,IAAI;AAChC,OAAG,mBAAmB,QAAQ,IAAI;AAClC,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,WAAW,MAAM,KAAK,KAAK;AACtC","sourcesContent":["// Webpack shared module patching\n// used in multiple remote component host types\n// multiple host types includes: HTML custom element for remote components and Next.js host application\n// we are using this shared function to patch a Webpack module map\n// to use shared modules between the host application and the remote component\n\nimport { getScope } from '#internal/runtime/turbopack/remote-scope';\nimport { logDebug, logWarn } from '#internal/utils/logger';\n\nconst DEDUPLICATION_SKIPPED =\n 'shared module deduplication skipped. The remote may load its own copy of shared dependencies.';\n\nexport function applySharedModules(\n bundle: string,\n resolve: Record<string, unknown>,\n) {\n logDebug(\n 'SharedModules',\n `applySharedModules called for bundle: \"${bundle}\"`,\n );\n logDebug(\n 'SharedModules',\n `Shared modules to resolve: ${Object.keys(resolve)}`,\n );\n\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack remote module loading function scoped for each bundle\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string) => unknown) & {\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n } & Record<string, string[]>;\n\n // Prefer scope-based access when available.\n const scope = getScope(bundle);\n // @legacy(v0.3.4) — fall back to global __remote_webpack_require__ for hosts that\n // haven't run setupWebpackRuntime yet (e.g. HTML host's inline path).\n // Remove once all host types go through the shared pipeline (Phase 5).\n const webpackBundle =\n scope?.webpackRequire ?? self.__remote_webpack_require__?.[bundle];\n\n if (webpackBundle) {\n const modulePaths = Object.keys(\n self.__remote_webpack_module_map__?.[bundle] ?? webpackBundle.m ?? {},\n );\n logDebug(\n 'SharedModules',\n `Available module paths for bundle \"${bundle}\": ${modulePaths}`,\n );\n\n // patch all modules in the bundle to use the shared modules\n for (const [key, value] of Object.entries(resolve)) {\n const exactIds = modulePaths.filter((p) => p === key);\n const ids =\n exactIds.length > 0\n ? exactIds\n : modulePaths.filter((p) => p.includes(key));\n\n if (ids.length === 0) {\n logDebug(\n 'SharedModules',\n `No matching module path found for shared module \"${key}\"`,\n );\n }\n\n for (const id of ids) {\n if (webpackBundle.m) {\n // if we have a module map, we need to use the mapped id\n // this is required for production builds where the module ids are module id numbers\n const resolvedId = self.__remote_webpack_module_map__?.[bundle]?.[id]\n ? `${self.__remote_webpack_module_map__[bundle][id]}`\n : id;\n if (resolvedId !== id) {\n logDebug(\n 'SharedModules',\n `Mapped module id: \"${id}\" -> \"${resolvedId}\"`,\n );\n }\n // create a mock module which exports the shared module\n webpackBundle.m[resolvedId] = (module) => {\n module.exports = value;\n };\n } else {\n logWarn(\n 'SharedModules',\n `webpackBundle.m is not available for bundle \"${bundle}\" — ${DEDUPLICATION_SKIPPED}`,\n );\n }\n }\n }\n } else {\n logWarn(\n 'SharedModules',\n `No webpack require found for bundle \"${bundle}\" — ${DEDUPLICATION_SKIPPED}`,\n );\n logDebug(\n 'SharedModules',\n `Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`,\n );\n }\n}\n","import { getNamespace } from '#internal/runtime/namespace';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\n// module loader for Next.js Pages Router\nexport function nextClientPagesLoader(\n bundle: string,\n route: string,\n styleContainer: HTMLHeadElement | ShadowRoot | null = document.head,\n) {\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack remote module loading function scoped for each bundle\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string | number) => unknown) & {\n c?: Record<\n string | number,\n { id: string; parents: string[]; children: string[] }\n >;\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n type?: 'turbopack' | 'webpack';\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n // Next.js client pages loader reference storage\n __NEXT_P?: [\n (\n | [\n string,\n () => { default?: React.ComponentType<Record<string, unknown>> },\n ]\n | undefined\n ),\n (\n | [\n string,\n () => {\n default?: React.ComponentType<\n {\n Component: React.ComponentType<Record<string, unknown>>;\n } & Record<string, unknown>\n >;\n },\n ]\n | undefined\n ),\n (\n | [\n string,\n () => {\n default?: React.ComponentType<\n {\n Component: React.ComponentType<Record<string, unknown>>;\n } & Record<string, unknown>\n >;\n },\n ]\n | undefined\n ),\n ];\n };\n\n const ns = getNamespace();\n ns.pageComponentCache ??= {};\n const cacheKey = `${bundle}:${route}`;\n\n // Applies the cached CSS for `bundle` into the caller's styleContainer.\n // Mirrors the final CSS-attach step of the fresh-load path so that cache\n // hits and additional host instances (each with their own shadow root)\n // still receive the styles.\n const applyBundleCss = () => {\n const elements = ns.cssCache[bundle] ?? [];\n if (styleContainer) {\n for (const el of elements) {\n styleContainer.appendChild(el.cloneNode(true));\n }\n } else {\n for (const el of elements) {\n document.head.appendChild(el);\n }\n }\n };\n\n // On repeat loads (e.g. after history.back()) the next-client-pages-loader\n // chunk is already cached by webpack and its factory won't re-run, so\n // __NEXT_P wouldn't be populated. Reuse the Component/App extracted on the\n // first load, but still run the CSS attach below because the caller may be\n // a different host instance with its own styleContainer.\n const cachedEntry = ns.pageComponentCache[cacheKey];\n if (cachedEntry) {\n applyBundleCss();\n return cachedEntry;\n }\n\n // temporarily remove the original Next.js CSS loader\n const nextCssOriginal = document.querySelector(\n `[id=\"__next_css__DO_NOT_USE__\"]:not([data-bundle=\"${bundle}\"][data-route=\"${route}\"])`,\n );\n if (nextCssOriginal) {\n nextCssOriginal.parentNode?.removeChild(nextCssOriginal);\n }\n\n // create a new Next.js CSS loader element\n const nextCss = document.createElement('noscript');\n nextCss.id = '__next_css__DO_NOT_USE__';\n nextCss.setAttribute('data-bundle', bundle);\n nextCss.setAttribute('data-route', route);\n const nextCssEnd = document.createElement('noscript');\n nextCssEnd.id = '__next_css__DO_NOT_USE_END__';\n nextCssEnd.setAttribute('data-bundle', bundle);\n nextCssEnd.setAttribute('data-route', route);\n document.head.appendChild(nextCssEnd);\n document.head.appendChild(nextCss);\n\n // find the page component loader chunk\n const componentLoaderChunk =\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=${encodeURIComponent(route)}!`),\n ) ??\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n self.__remote_webpack_module_map__?.[bundle]?.[\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=${encodeURIComponent(route)}!`),\n ) ??\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n ''\n ] ??\n -1;\n\n // find the app loader chunk\n const appLoaderChunk =\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=%2F_app`),\n ) ??\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n self.__remote_webpack_module_map__?.[bundle]?.[\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=%2F_app`),\n ) ??\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n ''\n ] ??\n -1;\n\n // if we didn't find the component loader or app loader, throw an error\n if (!(componentLoaderChunk && appLoaderChunk)) {\n throw new RemoteComponentsError(\n `Next.js client pages loader not found in bundle \"${bundle}\".`,\n );\n }\n\n // temporarily store the original __NEXT_P reference\n // this is required to avoid conflicts with the Next.js client pages loader\n // which uses the same global variable to store the page components\n const __NEXT_P_ORIGINAL = self.__NEXT_P;\n const selfOriginal = self;\n delete selfOriginal.__NEXT_P;\n\n // load the component and app loader chunks\n self.__remote_webpack_require__?.[bundle]?.(\n self.__remote_webpack_require__[bundle].type !== 'turbopack'\n ? componentLoaderChunk\n : `[${bundle}] ${componentLoaderChunk}`,\n );\n if (\n typeof appLoaderChunk === 'string' ||\n (typeof appLoaderChunk === 'number' && appLoaderChunk !== -1)\n ) {\n self.__remote_webpack_require__?.[bundle]?.(\n self.__remote_webpack_require__[bundle].type !== 'turbopack'\n ? appLoaderChunk\n : `[${bundle}] ${appLoaderChunk}`,\n );\n }\n\n // if we have the __NEXT_P global variable, we can extract the component and app\n if (self.__NEXT_P) {\n const [, componentLoader] = self.__NEXT_P[0] ?? [\n undefined,\n () => ({ default: null }),\n ];\n const [, appLoader] = self.__NEXT_P[2] ?? [\n undefined,\n () => ({\n default: null,\n }),\n ];\n const { default: Component = null } = componentLoader();\n const { default: App = null } = appLoader();\n\n const cssCache = ns.cssCache;\n\n if (!cssCache[bundle]) {\n // load the CSS files from the remote bundle\n const cssRE = /\\.s?css$/;\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {})\n .filter((id) => cssRE.test(id))\n .forEach((id) => {\n self.__remote_webpack_require__?.[bundle]?.(id);\n });\n\n Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {})\n .filter((path) => cssRE.test(path))\n .forEach((path) => {\n const id = self.__remote_webpack_module_map__?.[bundle]?.[path];\n if (id) {\n self.__remote_webpack_require__?.[bundle]?.(id);\n }\n });\n\n const elements = [];\n let node = nextCss.previousSibling;\n while (node && node !== nextCssEnd) {\n elements.push(node);\n node.remove();\n node = nextCss.previousSibling;\n }\n cssCache[bundle] = elements;\n }\n\n applyBundleCss();\n\n // restore the original __NEXT_P reference\n delete self.__NEXT_P;\n self.__NEXT_P = __NEXT_P_ORIGINAL;\n\n // restore the original Next.js CSS loader\n if (nextCssOriginal) {\n nextCssOriginal.parentNode?.appendChild(nextCssOriginal);\n }\n\n nextCss.remove();\n nextCssEnd.remove();\n\n const result = { Component, App };\n ns.pageComponentCache[cacheKey] = result;\n return result;\n }\n\n return { Component: null, App: null };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkZ2SLBFQLcjs = require('./chunk-Z2SLBFQL.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -49,7 +49,7 @@ async function importViaCallback(absoluteSrc, resolveClientUrl) {
|
|
|
49
49
|
URL.revokeObjectURL(moduleBlobUrl);
|
|
50
50
|
URL.revokeObjectURL(wrapperBlobUrl);
|
|
51
51
|
}
|
|
52
|
-
const registry =
|
|
52
|
+
const registry = _chunkZ2SLBFQLcjs.getNamespace.call(void 0, ).moduleRegistry;
|
|
53
53
|
const mod = _nullishCoalesce(registry[absoluteSrc], () => ( {}));
|
|
54
54
|
delete registry[absoluteSrc];
|
|
55
55
|
return mod;
|
|
@@ -81,7 +81,7 @@ function resolveScriptSrc(script, url) {
|
|
|
81
81
|
return rawSrc;
|
|
82
82
|
}
|
|
83
83
|
async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
84
|
-
const ns =
|
|
84
|
+
const ns = _chunkZ2SLBFQLcjs.getNamespace.call(void 0, );
|
|
85
85
|
if (ns.mountFns[url.href]) {
|
|
86
86
|
ns.mountFns[url.href] = /* @__PURE__ */ new Set();
|
|
87
87
|
}
|
|
@@ -152,4 +152,4 @@ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
|
152
152
|
|
|
153
153
|
|
|
154
154
|
exports.loadStaticRemoteComponent = loadStaticRemoteComponent;
|
|
155
|
-
//# sourceMappingURL=chunk-
|
|
155
|
+
//# sourceMappingURL=chunk-TZT7DLO5.cjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkZ2SLBFQLcjs = require('./chunk-Z2SLBFQL.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -42,7 +42,7 @@ function collapseDoubleSlashes(path) {
|
|
|
42
42
|
|
|
43
43
|
// src/runtime/turbopack/remote-scope.ts
|
|
44
44
|
function getRegistry() {
|
|
45
|
-
return
|
|
45
|
+
return _chunkZ2SLBFQLcjs.getNamespace.call(void 0, ).scopes;
|
|
46
46
|
}
|
|
47
47
|
function createScope(name, url, runtime, resolveClientUrl) {
|
|
48
48
|
const scopedName = computeScopedName(name, { remoteHost: url.host });
|
|
@@ -122,7 +122,7 @@ function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
|
122
122
|
// src/host/shared/polyfill.tsx
|
|
123
123
|
var _jsxruntime = require('react/jsx-runtime');
|
|
124
124
|
function sharedPolyfills(shared, resolveClientUrl) {
|
|
125
|
-
const hostShared =
|
|
125
|
+
const hostShared = _chunkZ2SLBFQLcjs.getNamespace.call(void 0, ).hostSharedModules;
|
|
126
126
|
const polyfill = {
|
|
127
127
|
"next/dist/client/components/navigation": _nullishCoalesce(_nullishCoalesce(hostShared["next/navigation"], () => ( _optionalChain([shared, 'optionalAccess', _10 => _10["next/navigation"]]))), () => ( (() => Promise.resolve({
|
|
128
128
|
useRouter() {
|
|
@@ -355,4 +355,4 @@ async function buildWebpackResolve(hostShared, remoteShared, bundle, reactModule
|
|
|
355
355
|
|
|
356
356
|
|
|
357
357
|
exports.escapeString = escapeString; exports.attrToProp = attrToProp; exports.DEFAULT_BUNDLE_NAME = DEFAULT_BUNDLE_NAME; exports.DEFAULT_COMPONENT_NAME = DEFAULT_COMPONENT_NAME; exports.DEFAULT_ROUTE = DEFAULT_ROUTE; exports.RUNTIME_WEBPACK = RUNTIME_WEBPACK; exports.RUNTIME_TURBOPACK = RUNTIME_TURBOPACK; exports.RUNTIME_SCRIPT = RUNTIME_SCRIPT; exports.REMOTE_COMPONENT_REGEX = REMOTE_COMPONENT_REGEX; exports.NEXT_BUNDLE_PATH_RE = NEXT_BUNDLE_PATH_RE; exports.collapseDoubleSlashes = collapseDoubleSlashes; exports.createScope = createScope; exports.registerScope = registerScope; exports.getScope = getScope; exports.formatRemoteId = formatRemoteId; exports.parseRemoteId = parseRemoteId; exports.createRemoteImageLoader = createRemoteImageLoader; exports.CORE_REACT_SHARED_KEYS = CORE_REACT_SHARED_KEYS; exports.VENDOR_SHARED = VENDOR_SHARED; exports.buildCoreShared = buildCoreShared; exports.buildHostShared = buildHostShared; exports.buildWebpackResolve = buildWebpackResolve;
|
|
358
|
-
//# sourceMappingURL=chunk-
|
|
358
|
+
//# sourceMappingURL=chunk-X6W464D6.cjs.map
|
|
@@ -32,6 +32,7 @@ function getNamespace() {
|
|
|
32
32
|
dispatcherRuntime: void 0,
|
|
33
33
|
hostSharedModules: {},
|
|
34
34
|
cssCache: {},
|
|
35
|
+
pageComponentCache: {},
|
|
35
36
|
shadowRoots: {}
|
|
36
37
|
};
|
|
37
38
|
const nsRecord = ns;
|
|
@@ -57,4 +58,4 @@ function getNamespace() {
|
|
|
57
58
|
|
|
58
59
|
|
|
59
60
|
exports.getNamespace = getNamespace;
|
|
60
|
-
//# sourceMappingURL=chunk-
|
|
61
|
+
//# sourceMappingURL=chun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WAAW,kBAAkB,GAAG;AACtC,YAAM,SAAS,IAAI,MAAM,mBAAmB,MAAM;AAClD,SAAG,YAAY,MAAM,IAAI,QAAQ,GAAG;AACpC,aAAO,QAAQ,GAAG;AAAA,IACpB;AAAA,EACF;AAEA,IAAE,wBAAwB;AAC1B,SAAO;AACT","sourcesContent":["import type React from 'react';\nimport type { RemoteScope } from '#internal/runtime/turbopack/remote-scope';\nimport type {\n GlobalScope,\n MountOrUnmountFunction,\n MountUnmountFunctions,\n} from '#internal/runtime/types';\n\n/**\n * Typed namespace for all remote-components runtime state.\n *\n * Consolidates scattered `globalThis` globals into a single object at\n * `globalThis.__remote_components__`. Each property corresponds to a\n * previously independent global — see inline `@see` tags for the original\n * global name. Code that previously read from those globals still works\n * because each migration writes through to both the namespace and the\n * legacy global (pointing at the same underlying object).\n */\nexport interface RemoteComponentsNamespace {\n /** @see `__remote_component_scopes__` */\n scopes: Map<string, RemoteScope>;\n /** @see `__remote_components_turbopack_chunk_loader_promise__` */\n chunkCache: Record<string, Promise<unknown>>;\n /** @see `__remote_script_entrypoint_mount__` */\n mountFns: Record<string, Set<MountOrUnmountFunction>>;\n /** @see `__remote_script_entrypoint_unmount__` */\n unmountFns: Record<string, Set<MountOrUnmountFunction>>;\n /** @see `__remote_bundle_url__` */\n bundleUrls: Record<string, string | URL>;\n /** @see `__rc_module_registry__` */\n moduleRegistry: Record<string, unknown>;\n /** @see `__webpack_require_type__` */\n dispatcherRuntime: string | undefined;\n /** @see `__remote_component_host_shared_modules__` */\n hostSharedModules: Record<string, () => Promise<unknown>>;\n /** @see `__remote_next_css__` */\n cssCache: Record<string, ChildNode[]>;\n pageComponentCache?: Record<\n string,\n {\n Component: React.ComponentType<Record<string, unknown>> | null;\n App: React.ComponentType<\n { Component: React.ComponentType<Record<string, unknown>> } & Record<\n string,\n unknown\n >\n > | null;\n }\n >;\n /** @see `__remote_components_shadowroot_*` */\n shadowRoots: Record<string, ShadowRoot | null>;\n}\n\n/** Prefix for legacy per-key shadow root globals (`__remote_components_shadowroot_*`). */\nconst SHADOW_ROOT_PREFIX = '__remote_components_shadowroot_';\n\n/**\n * Backward-compat aliases for globals used in <=0.3.3.\n *\n * Only includes object/Map values that can be aliased by reference.\n * Primitives (`dispatcherRuntime`) must use write-through at their call sites.\n * Dynamic-key shadow root globals are adopted separately in `getNamespace()`.\n */\nconst LEGACY_ALIASES: ReadonlyArray<{\n global: string;\n prop: keyof RemoteComponentsNamespace;\n}> = [\n { global: '__remote_component_scopes__', prop: 'scopes' },\n {\n global: '__remote_components_turbopack_chunk_loader_promise__',\n prop: 'chunkCache',\n },\n { global: '__remote_script_entrypoint_mount__', prop: 'mountFns' },\n { global: '__remote_script_entrypoint_unmount__', prop: 'unmountFns' },\n { global: '__remote_bundle_url__', prop: 'bundleUrls' },\n { global: '__rc_module_registry__', prop: 'moduleRegistry' },\n {\n global: '__remote_component_host_shared_modules__',\n prop: 'hostSharedModules',\n },\n { global: '__remote_next_css__', prop: 'cssCache' },\n];\n\n/**\n * Returns the single shared `RemoteComponentsNamespace` instance, creating\n * it on first access. The namespace lives at `globalThis.__remote_components__`\n * so every module in the page shares the same state regardless of how many\n * copies of the library are loaded.\n *\n * On first initialization this function also handles backward compatibility\n * with legacy globals:\n * 1. **Adopt**: if a legacy global already exists (written by older code before\n * the namespace was created), its value becomes the initial namespace value.\n * 2. **Alias**: legacy globals are assigned to point at the namespace's objects,\n * so older code that reads the legacy global sees the same reference.\n */\nexport function getNamespace(): RemoteComponentsNamespace {\n const g = globalThis as GlobalScope & MountUnmountFunctions;\n const existing = g.__remote_components__;\n if (existing) {\n return existing;\n }\n\n const ns: RemoteComponentsNamespace = {\n scopes: new Map(),\n chunkCache: {},\n mountFns: {},\n unmountFns: {},\n bundleUrls: {},\n moduleRegistry: {},\n dispatcherRuntime: undefined,\n hostSharedModules: {},\n cssCache: {},\n pageComponentCache: {},\n shadowRoots: {},\n };\n\n // Adopt any pre-existing legacy globals, then alias them to the namespace.\n const nsRecord = ns as unknown as Record<string, unknown>;\n for (const { global, prop } of LEGACY_ALIASES) {\n const legacyValue = (g as Record<string, unknown>)[global];\n if (legacyValue != null) {\n nsRecord[prop] = legacyValue;\n }\n (g as Record<string, unknown>)[global] = ns[prop];\n }\n\n // Adopt per-key shadow root globals used in <=0.3.3\n // (e.g. `globalThis.__remote_components_shadowroot_<key> = root`).\n const gRecord = g as Record<string, unknown>;\n for (const key of Object.keys(gRecord)) {\n if (key.startsWith(SHADOW_ROOT_PREFIX)) {\n const suffix = key.slice(SHADOW_ROOT_PREFIX.length);\n ns.shadowRoots[suffix] = gRecord[key] as ShadowRoot | null;\n delete gRecord[key];\n }\n }\n\n g.__remote_components__ = ns;\n return ns;\n}\n"]}
|
package/dist/config/nextjs.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../chunk-
|
|
6
|
-
|
|
4
|
+
var _chunkX6W464D6cjs = require('../chunk-X6W464D6.cjs');
|
|
5
|
+
require('../chunk-Z2SLBFQL.cjs');
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
|
|
@@ -142,7 +141,7 @@ function withRemoteComponentsConfig(nextConfig, options) {
|
|
|
142
141
|
".remote-components/shared/pages-host.tsx"
|
|
143
142
|
);
|
|
144
143
|
const appShared = /* @__PURE__ */ new Set([
|
|
145
|
-
...
|
|
144
|
+
..._chunkX6W464D6cjs.CORE_REACT_SHARED_KEYS,
|
|
146
145
|
"next/navigation",
|
|
147
146
|
"next/dist/client/components/navigation",
|
|
148
147
|
"next/link",
|
|
@@ -156,7 +155,7 @@ function withRemoteComponentsConfig(nextConfig, options) {
|
|
|
156
155
|
..._nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.shared]), () => ( []))
|
|
157
156
|
]);
|
|
158
157
|
const pagesShared = /* @__PURE__ */ new Set([
|
|
159
|
-
...
|
|
158
|
+
..._chunkX6W464D6cjs.CORE_REACT_SHARED_KEYS,
|
|
160
159
|
"next/router",
|
|
161
160
|
"next/link",
|
|
162
161
|
"next/dist/shared/lib/image-loader",
|
|
@@ -164,7 +163,7 @@ function withRemoteComponentsConfig(nextConfig, options) {
|
|
|
164
163
|
"next/form",
|
|
165
164
|
..._nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.shared]), () => ( []))
|
|
166
165
|
]);
|
|
167
|
-
const vendorShared = { ...
|
|
166
|
+
const vendorShared = { ..._chunkX6W464D6cjs.VENDOR_SHARED };
|
|
168
167
|
const resolve = _enhancedresolve2.default.create.sync({
|
|
169
168
|
conditionNames: ["browser", "import", "module", "require"],
|
|
170
169
|
..._fs.existsSync.call(void 0, _path.join.call(void 0, process.cwd(), "tsconfig.json")) ? {
|
|
@@ -261,11 +260,6 @@ ${exportPre}${Array.from(sharedHost).reduce((acc, curr) => {
|
|
|
261
260
|
const projectId = resolveProjectId(packageJson.name);
|
|
262
261
|
process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;
|
|
263
262
|
if (hasPagesDirectory()) {
|
|
264
|
-
if (process.env.TURBOPACK) {
|
|
265
|
-
throw new (0, _chunkRUWR74XQcjs.RemoteComponentsError)(
|
|
266
|
-
"Remote Components does not support Next.js Pages Router with Turbopack. Use webpack instead (`next dev` / `next build` without `--turbo`)."
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
263
|
const nextMajor = getNextMajorVersion();
|
|
270
264
|
if (nextMajor !== void 0 && nextMajor < 16) {
|
|
271
265
|
const log = process.env.NODE_ENV !== "production" || process.env.VERCEL_ENV === "preview" ? _chunkRUWR74XQcjs.logWarn : _chunkRUWR74XQcjs.logDebug;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config/nextjs/index.ts","../../src/utils/project-id.ts","../../src/utils/project-id-env.ts","../../src/config/webpack/nextjs.ts"],"names":["readFileSync","join","findUpSync"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,WAAW,gBAAAA,eAAc,qBAAqB;AACnE,SAAS,UAAU,SAAS,QAAAC,OAAM,gBAAgB;AAClD,OAAO,qBAAqB;AAC5B,SAAS,cAAAC,mBAAkB;AAE3B,SAAS,oBAAoB;AAC7B,OAAO,gCAAgC;;;ACNvC,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;;;ACGpB,SAAS,0BAA8C;AAC5D,SACE,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI,qBACZ;AAEJ;;;ADFO,SAAS,iBAAiB,aAA6B;AAC5D,QAAM,UAAU,wBAAwB;AACxC,MAAI;AAAS,WAAO;AAEpB,MAAI;AACF,UAAM,cAAc,WAAW,wBAAwB;AAAA,MACrD,KAAK,QAAQ,IAAI;AAAA,IACnB,CAAC;AACD,QAAI,aAAa;AACf,aACE,KAAK,MAAM,aAAa,aAAa,MAAM,CAAC,EAC5C;AAAA,IACJ;AAAA,EACF,QAAE;AAAA,EAEF;AAEA,SAAO;AACT;;;AE3BA,SAAS,YAAY;AAQd,SAAS,UACd,YACA;AAAA,EACE;AAAA,EACA,QAAQ,CAAC;AAAA,EACT,kBAAkB,MAAM;AAAA,EAExB;AACF,GAKA;AACA,QAAM,gBAAgB,WAAW;AAEjC,aAAW,UAAU,CACnB,YACA,mBACG;AAGH,UAAM,SACJ,OAAO,kBAAk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AAA,UACZ,GAAG;AAAA,QACL;AAAA,MACF;AAAA,MACA,UAAU;AAAA,QACR,cAAc;AAAA,UACZ,8BAA8B;AAAA,QAChC;AAAA,MACF;AAAA,IACF,CAAC,EAAE,SACH;AACA;AAAA,QACE;AAAA,QACA;AAAA,MAEF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,eAAW,YAAY;AAAA,MACrB,GAAG,WAAW;AAAA,MACd,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","sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { basename, dirname, join, relative } from 'node:path';\nimport enhancedResolve from 'enhanced-resolve';\nimport { findUpSync } from 'find-up';\nimport type { NextConfig } from 'next';\nimport { configSchema } from 'next/dist/server/config-schema.js';\nimport TsConfigPathsWebpackPlugin from 'tsconfig-paths-webpack-plugin';\nimport {\n CORE_REACT_SHARED_KEYS,\n VENDOR_SHARED,\n} from '#internal/host/shared/shared-module-resolver';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { resolveProjectId } from '#internal/utils/project-id';\nimport { transform as webpackTransform } from '../webpack/nextjs';\n\nfunction getNextMajorVersion(): number | undefined {\n try {\n const nextPkgPath = findUpSync('node_modules/next/package.json', {\n cwd: process.cwd(),\n });\n if (!nextPkgPath) return undefined;\n const { version } = JSON.parse(readFileSync(nextPkgPath, 'utf8')) as {\n version: string;\n };\n const major = version.split('.')[0];\n return major ? Number.parseInt(major, 10) : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction hasPagesDirectory(): boolean {\n return (\n existsSync(join(process.cwd(), 'pages')) ||\n existsSync(join(process.cwd(), 'src/pages'))\n );\n}\n\ninterface ZodSchema {\n safeParse: (data: unknown) => { success: boolean };\n}\n\nfunction readProjectPackageJson(): { name: string; type: string } {\n const defaults = { name: basename(process.cwd()), type: 'module' };\n try {\n const packageJsonPath = findUpSync('package.json', {\n cwd: process.cwd(),\n });\n if (packageJsonPath) {\n return {\n ...defaults,\n ...(JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {\n name: string;\n type: string;\n }),\n };\n }\n } catch {\n // noop\n }\n return defaults;\n}\n\ninterface WithRemoteComponentsOptions {\n /**\n * An array of package names that should be shared between the host and remote components.\n * This is useful for ensuring that both the host and remote components use the same version\n * of shared libraries.\n *\n * Essential packages are included by default: `react`, `react-dom`, `next/navigation`, `next/link`, `next/form`, `next/image` (loader only), and `next/script`.\n */\n shared?: string[];\n}\n\n/**\n * This function configures Next.js to support Remote Components.\n * You need to also use the `withMicrofrontends` function to extend your Next.js configuration.\n *\n * @param nextConfig - The Next.js configuration object.\n * @param options - Optional configuration for remote components.\n * @returns The modified Next.js configuration object with remote components support.\n *\n * @example\n *\n * ```js\n * import { withMicrofrontends } from '@vercel/microfrontends/next/config';\n * import { withRemoteComponentsConfig } from 'remote-components/config/nextjs';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponentsConfig(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponentsConfig(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentAppSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/app-remote.tsx',\n );\n const virtualRemoteComponentPagesSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/pages-remote.tsx',\n );\n const virtualRemoteComponentAppSharedHost = join(\n process.cwd(),\n '.remote-components/shared/app-host.tsx',\n );\n const virtualRemoteComponentPagesSharedHost = join(\n process.cwd(),\n '.remote-components/shared/pages-host.tsx',\n );\n\n const appShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/navigation',\n 'next/dist/client/components/navigation',\n 'next/link',\n 'next/dist/client/app-dir/link',\n 'next/form',\n 'next/dist/client/app-dir/form',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/dist/client/script',\n 'next/dist/build/polyfills/process',\n ...(options?.shared ?? []),\n ]);\n const pagesShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/router',\n 'next/link',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/form',\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared = { ...VENDOR_SHARED };\n\n // resolve using enhanced-resolve\n // named import does not work with enhanced-resolve when using cjs\n // eslint-disable-next-line import/no-named-as-default-member\n const resolve = enhancedResolve.create.sync({\n conditionNames: ['browser', 'import', 'module', 'require'],\n ...(existsSync(join(process.cwd(), 'tsconfig.json'))\n ? {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n plugins: [\n new TsConfigPathsWebpackPlugin({\n configFile: join(process.cwd(), 'tsconfig.json'),\n }) as unknown as enhancedResolve.Plugin,\n ],\n }\n : {}),\n });\n\n const packageJson = readProjectPackageJson();\n\n const exportPre =\n packageJson.type !== 'module'\n ? 'module.exports = { shared: { '\n : 'export const shared = { ';\n const exportPost = packageJson.type !== 'module' ? '} };\\n' : '};\\n';\n\n const resolveSharedPath = (moduleName: string): string | undefined => {\n try {\n const resolved = resolve(process.cwd(), moduleName);\n if (resolved) {\n return relative(process.cwd(), resolved).replace(\n /^(?<relative>\\.\\.\\/)+/,\n '',\n );\n }\n } catch {\n // if module resolution using enhanced-resolve fails, fallback to require.resolve called in the shared/remote file\n }\n };\n\n const generateSharedRemote = (sharedRemote: Set<string>) =>\n `'use client';\\n${exportPre}${Array.from(sharedRemote)\n .reduce<string[]>((acc, curr) => {\n const path = resolveSharedPath(curr);\n acc.push(\n `[${\n vendorShared[curr] ??\n (path ? `'${path}'` : `require.resolve('${curr}')`)\n }]: '${curr}',`,\n );\n acc.push(\n `['__remote_shared_module_${curr}']: () => import('${curr}'),`,\n );\n return acc;\n }, [])\n .join('\\n')}${exportPost}`;\n const generateSharedHost = (sharedHost: Set<string>) =>\n `'use client';\\n${exportPre}${Array.from(sharedHost)\n .reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, [])\n .join('\\n')}${exportPost}`;\n\n const appSharedRemote = generateSharedRemote(appShared);\n const pagesSharedRemote = generateSharedRemote(pagesShared);\n\n const appSharedHost = generateSharedHost(appShared);\n const pagesSharedHost = generateSharedHost(pagesShared);\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentAppSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(\n virtualRemoteComponentAppSharedRemote,\n appSharedRemote,\n 'utf-8',\n );\n writeFileSync(\n virtualRemoteComponentPagesSharedRemote,\n pagesSharedRemote,\n 'utf-8',\n );\n writeFileSync(virtualRemoteComponentAppSharedHost, appSharedHost, 'utf-8');\n writeFileSync(\n virtualRemoteComponentPagesSharedHost,\n pagesSharedHost,\n 'utf-8',\n );\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components',\n ];\n\n nextConfig.env = {\n ...nextConfig.env,\n REMOTE_COMPONENTS_CONFIGURED: '1',\n };\n\n const alias = {\n '#remote-components/remote/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedRemote,\n )}`,\n '#remote-components/remote/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedRemote,\n )}`,\n '#remote-components/host/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedHost,\n )}`,\n '#remote-components/host/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedHost,\n )}`,\n };\n\n const projectId = resolveProjectId(packageJson.name);\n process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;\n\n if (hasPagesDirectory()) {\n if (process.env.TURBOPACK) {\n throw new RemoteComponentsError(\n 'Remote Components does not support Next.js Pages Router with Turbopack. ' +\n 'Use webpack instead (`next dev` / `next build` without `--turbo`).',\n );\n }\n // Log instead of throwing for the version check because\n // withRemoteComponentsConfig is shared by both hosts and remotes.\n // Only Pages Router hosts are broken on Next.js < 16 — remotes\n // work fine and must not have their builds blocked.\n const nextMajor = getNextMajorVersion();\n if (nextMajor !== undefined && nextMajor < 16) {\n const log =\n process.env.NODE_ENV !== 'production' ||\n process.env.VERCEL_ENV === 'preview'\n ? logWarn\n : logDebug;\n log(\n 'Config',\n `Remote Components does not support Pages Router hosts on Next.js ${nextMajor}. ` +\n 'Pages Router remotes are unaffected. Upgrade to Next.js 16+ for host support.',\n );\n }\n }\n\n if (process.env.TURBOPACK) {\n if (\n !(configSchema as ZodSchema).safeParse({\n turbopack: {\n resolveAlias: {\n ...alias,\n },\n },\n compiler: {\n defineServer: {\n REMOTE_COMPONENTS_PROJECT_ID: projectId,\n },\n },\n }).success\n ) {\n logError(\n 'Config',\n 'Turbopack support requires a Next.js version that includes `compiler.defineServer`. ' +\n 'Upgrade Next.js to continue using Remote Components with Turbopack.',\n );\n process.exit(1);\n }\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\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 { readFileSync } from 'node:fs';\nimport { findUpSync } from 'find-up';\nimport { resolveProjectIdFromEnv } from './project-id-env';\n\n/**\n * Resolves the project ID using environment variables first, then\n * falling back to `.vercel/project.json` and finally the package name.\n * Node-only — requires file system access.\n */\nexport function resolveProjectId(packageName: string): string {\n const fromEnv = resolveProjectIdFromEnv();\n if (fromEnv) return fromEnv;\n\n try {\n const projectPath = findUpSync('.vercel/project.json', {\n cwd: process.cwd(),\n });\n if (projectPath) {\n return (\n JSON.parse(readFileSync(projectPath, 'utf8')) as { projectId: string }\n ).projectId;\n }\n } catch {\n // fallback below\n }\n\n return packageName;\n}\n","/**\n * Resolves the project ID from environment variables only.\n * Safe for edge/browser contexts where file system access is unavailable.\n */\nexport function resolveProjectIdFromEnv(): string | undefined {\n return (\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID ||\n undefined\n );\n}\n","import { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { PatchRequirePlugin } from './plugins/patch-require';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\n\nexport function transform(\n nextConfig: NextConfig,\n {\n app,\n alias = {},\n emitSharedFiles = () => {\n // no-op by default\n },\n }: {\n app: { name: string };\n alias?: Record<string, string>;\n emitSharedFiles?: () => void;\n },\n) {\n const webpackConfig = nextConfig.webpack;\n\n nextConfig.webpack = (\n baseConfig: WebpackOptionsNormalized,\n webpackContext,\n ) => {\n // execute the client config first, otherwise their config may accidentally\n // overwrite our required config - leading to unexpected errors.\n const config = (\n typeof webpackConfig === 'function'\n ? (webpackConfig(baseConfig, webpackContext) ?? baseConfig)\n : baseConfig\n ) as WebpackOptionsNormalized;\n\n // remote component specific plugins\n config.plugins.push(\n new RemoteWebpackRequirePlugin(app.name),\n new ModuleIdEmbedPlugin(app.name, { isServer: webpackContext.isServer }),\n new ConditionalExecPlugin(app.name),\n new PatchRequirePlugin(app.name),\n );\n if (!webpackContext.isServer) {\n // change the chunk loading global to avoid conflicts with other remote components\n config.output.chunkLoadingGlobal = `__remote_chunk_loading_global_${app.name}__`;\n }\n\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve.alias,\n ...Object.fromEntries(\n Object.entries(alias).map(([key, value]) => [\n key,\n join(process.cwd(), value),\n ]),\n ),\n },\n };\n\n emitSharedFiles();\n return config;\n };\n\n return nextConfig;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/config/nextjs/index.ts","../../src/utils/project-id.ts","../../src/utils/project-id-env.ts","../../src/config/webpack/nextjs.ts"],"names":["readFileSync","join","findUpSync"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,WAAW,gBAAAA,eAAc,qBAAqB;AACnE,SAAS,UAAU,SAAS,QAAAC,OAAM,gBAAgB;AAClD,OAAO,qBAAqB;AAC5B,SAAS,cAAAC,mBAAkB;AAE3B,SAAS,oBAAoB;AAC7B,OAAO,gCAAgC;;;ACNvC,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;;;ACGpB,SAAS,0BAA8C;AAC5D,SACE,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI,qBACZ;AAEJ;;;ADFO,SAAS,iBAAiB,aAA6B;AAC5D,QAAM,UAAU,wBAAwB;AACxC,MAAI;AAAS,WAAO;AAEpB,MAAI;AACF,UAAM,cAAc,WAAW,wBAAwB;AAAA,MACrD,KAAK,QAAQ,IAAI;AAAA,IACnB,CAAC;AACD,QAAI,aAAa;AACf,aACE,KAAK,MAAM,aAAa,aAAa,MAAM,CAAC,EAC5C;AAAA,IACJ;AAAA,EACF,QAAE;AAAA,EAEF;AAEA,SAAO;AACT;;;AE3BA,SAAS,YAAY;AAQd,SAAS,UACd,YACA;AAAA,EACE;AAAA,EACA,QAAQ,CAAC;AAAA,EACT,kBAAkB,MAAM;AAAA,EAExB;AAC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AAAA,QACT,cAAc;AAAA,UACZ,GAAG;AAAA,QACL;AAAA,MACF;AAAA,MACA,UAAU;AAAA,QACR,cAAc;AAAA,UACZ,8BAA8B;AAAA,QAChC;AAAA,MACF;AAAA,IACF,CAAC,EAAE,SACH;AACA;AAAA,QACE;AAAA,QACA;AAAA,MAEF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,eAAW,YAAY;AAAA,MACrB,GAAG,WAAW;AAAA,MACd,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","sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { basename, dirname, join, relative } from 'node:path';\nimport enhancedResolve from 'enhanced-resolve';\nimport { findUpSync } from 'find-up';\nimport type { NextConfig } from 'next';\nimport { configSchema } from 'next/dist/server/config-schema.js';\nimport TsConfigPathsWebpackPlugin from 'tsconfig-paths-webpack-plugin';\nimport {\n CORE_REACT_SHARED_KEYS,\n VENDOR_SHARED,\n} from '#internal/host/shared/shared-module-resolver';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { resolveProjectId } from '#internal/utils/project-id';\nimport { transform as webpackTransform } from '../webpack/nextjs';\n\nfunction getNextMajorVersion(): number | undefined {\n try {\n const nextPkgPath = findUpSync('node_modules/next/package.json', {\n cwd: process.cwd(),\n });\n if (!nextPkgPath) return undefined;\n const { version } = JSON.parse(readFileSync(nextPkgPath, 'utf8')) as {\n version: string;\n };\n const major = version.split('.')[0];\n return major ? Number.parseInt(major, 10) : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction hasPagesDirectory(): boolean {\n return (\n existsSync(join(process.cwd(), 'pages')) ||\n existsSync(join(process.cwd(), 'src/pages'))\n );\n}\n\ninterface ZodSchema {\n safeParse: (data: unknown) => { success: boolean };\n}\n\nfunction readProjectPackageJson(): { name: string; type: string } {\n const defaults = { name: basename(process.cwd()), type: 'module' };\n try {\n const packageJsonPath = findUpSync('package.json', {\n cwd: process.cwd(),\n });\n if (packageJsonPath) {\n return {\n ...defaults,\n ...(JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {\n name: string;\n type: string;\n }),\n };\n }\n } catch {\n // noop\n }\n return defaults;\n}\n\ninterface WithRemoteComponentsOptions {\n /**\n * An array of package names that should be shared between the host and remote components.\n * This is useful for ensuring that both the host and remote components use the same version\n * of shared libraries.\n *\n * Essential packages are included by default: `react`, `react-dom`, `next/navigation`, `next/link`, `next/form`, `next/image` (loader only), and `next/script`.\n */\n shared?: string[];\n}\n\n/**\n * This function configures Next.js to support Remote Components.\n * You need to also use the `withMicrofrontends` function to extend your Next.js configuration.\n *\n * @param nextConfig - The Next.js configuration object.\n * @param options - Optional configuration for remote components.\n * @returns The modified Next.js configuration object with remote components support.\n *\n * @example\n *\n * ```js\n * import { withMicrofrontends } from '@vercel/microfrontends/next/config';\n * import { withRemoteComponentsConfig } from 'remote-components/config/nextjs';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponentsConfig(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponentsConfig(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentAppSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/app-remote.tsx',\n );\n const virtualRemoteComponentPagesSharedRemote = join(\n process.cwd(),\n '.remote-components/shared/pages-remote.tsx',\n );\n const virtualRemoteComponentAppSharedHost = join(\n process.cwd(),\n '.remote-components/shared/app-host.tsx',\n );\n const virtualRemoteComponentPagesSharedHost = join(\n process.cwd(),\n '.remote-components/shared/pages-host.tsx',\n );\n\n const appShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/navigation',\n 'next/dist/client/components/navigation',\n 'next/link',\n 'next/dist/client/app-dir/link',\n 'next/form',\n 'next/dist/client/app-dir/form',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/dist/client/script',\n 'next/dist/build/polyfills/process',\n ...(options?.shared ?? []),\n ]);\n const pagesShared = new Set([\n ...CORE_REACT_SHARED_KEYS,\n 'next/router',\n 'next/link',\n 'next/dist/shared/lib/image-loader',\n 'next/script',\n 'next/form',\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared = { ...VENDOR_SHARED };\n\n // resolve using enhanced-resolve\n // named import does not work with enhanced-resolve when using cjs\n // eslint-disable-next-line import/no-named-as-default-member\n const resolve = enhancedResolve.create.sync({\n conditionNames: ['browser', 'import', 'module', 'require'],\n ...(existsSync(join(process.cwd(), 'tsconfig.json'))\n ? {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n plugins: [\n new TsConfigPathsWebpackPlugin({\n configFile: join(process.cwd(), 'tsconfig.json'),\n }) as unknown as enhancedResolve.Plugin,\n ],\n }\n : {}),\n });\n\n const packageJson = readProjectPackageJson();\n\n const exportPre =\n packageJson.type !== 'module'\n ? 'module.exports = { shared: { '\n : 'export const shared = { ';\n const exportPost = packageJson.type !== 'module' ? '} };\\n' : '};\\n';\n\n const resolveSharedPath = (moduleName: string): string | undefined => {\n try {\n const resolved = resolve(process.cwd(), moduleName);\n if (resolved) {\n return relative(process.cwd(), resolved).replace(\n /^(?<relative>\\.\\.\\/)+/,\n '',\n );\n }\n } catch {\n // if module resolution using enhanced-resolve fails, fallback to require.resolve called in the shared/remote file\n }\n };\n\n const generateSharedRemote = (sharedRemote: Set<string>) =>\n `'use client';\\n${exportPre}${Array.from(sharedRemote)\n .reduce<string[]>((acc, curr) => {\n const path = resolveSharedPath(curr);\n acc.push(\n `[${\n vendorShared[curr] ??\n (path ? `'${path}'` : `require.resolve('${curr}')`)\n }]: '${curr}',`,\n );\n acc.push(\n `['__remote_shared_module_${curr}']: () => import('${curr}'),`,\n );\n return acc;\n }, [])\n .join('\\n')}${exportPost}`;\n const generateSharedHost = (sharedHost: Set<string>) =>\n `'use client';\\n${exportPre}${Array.from(sharedHost)\n .reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, [])\n .join('\\n')}${exportPost}`;\n\n const appSharedRemote = generateSharedRemote(appShared);\n const pagesSharedRemote = generateSharedRemote(pagesShared);\n\n const appSharedHost = generateSharedHost(appShared);\n const pagesSharedHost = generateSharedHost(pagesShared);\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentAppSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(\n virtualRemoteComponentAppSharedRemote,\n appSharedRemote,\n 'utf-8',\n );\n writeFileSync(\n virtualRemoteComponentPagesSharedRemote,\n pagesSharedRemote,\n 'utf-8',\n );\n writeFileSync(virtualRemoteComponentAppSharedHost, appSharedHost, 'utf-8');\n writeFileSync(\n virtualRemoteComponentPagesSharedHost,\n pagesSharedHost,\n 'utf-8',\n );\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components',\n ];\n\n nextConfig.env = {\n ...nextConfig.env,\n REMOTE_COMPONENTS_CONFIGURED: '1',\n };\n\n const alias = {\n '#remote-components/remote/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedRemote,\n )}`,\n '#remote-components/remote/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedRemote,\n )}`,\n '#remote-components/host/defaults/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedHost,\n )}`,\n '#remote-components/host/defaults/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedHost,\n )}`,\n };\n\n const projectId = resolveProjectId(packageJson.name);\n process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;\n\n if (hasPagesDirectory()) {\n // Log instead of throwing for the version check because\n // withRemoteComponentsConfig is shared by both hosts and remotes.\n // Only Pages Router hosts are broken on Next.js < 16 — remotes\n // work fine and must not have their builds blocked.\n const nextMajor = getNextMajorVersion();\n if (nextMajor !== undefined && nextMajor < 16) {\n const log =\n process.env.NODE_ENV !== 'production' ||\n process.env.VERCEL_ENV === 'preview'\n ? logWarn\n : logDebug;\n log(\n 'Config',\n `Remote Components does not support Pages Router hosts on Next.js ${nextMajor}. ` +\n 'Pages Router remotes are unaffected. Upgrade to Next.js 16+ for host support.',\n );\n }\n }\n\n if (process.env.TURBOPACK) {\n if (\n !(configSchema as ZodSchema).safeParse({\n turbopack: {\n resolveAlias: {\n ...alias,\n },\n },\n compiler: {\n defineServer: {\n REMOTE_COMPONENTS_PROJECT_ID: projectId,\n },\n },\n }).success\n ) {\n logError(\n 'Config',\n 'Turbopack support requires a Next.js version that includes `compiler.defineServer`. ' +\n 'Upgrade Next.js to continue using Remote Components with Turbopack.',\n );\n process.exit(1);\n }\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\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 { readFileSync } from 'node:fs';\nimport { findUpSync } from 'find-up';\nimport { resolveProjectIdFromEnv } from './project-id-env';\n\n/**\n * Resolves the project ID using environment variables first, then\n * falling back to `.vercel/project.json` and finally the package name.\n * Node-only — requires file system access.\n */\nexport function resolveProjectId(packageName: string): string {\n const fromEnv = resolveProjectIdFromEnv();\n if (fromEnv) return fromEnv;\n\n try {\n const projectPath = findUpSync('.vercel/project.json', {\n cwd: process.cwd(),\n });\n if (projectPath) {\n return (\n JSON.parse(readFileSync(projectPath, 'utf8')) as { projectId: string }\n ).projectId;\n }\n } catch {\n // fallback below\n }\n\n return packageName;\n}\n","/**\n * Resolves the project ID from environment variables only.\n * Safe for edge/browser contexts where file system access is unavailable.\n */\nexport function resolveProjectIdFromEnv(): string | undefined {\n return (\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID ||\n undefined\n );\n}\n","import { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { PatchRequirePlugin } from './plugins/patch-require';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\n\nexport function transform(\n nextConfig: NextConfig,\n {\n app,\n alias = {},\n emitSharedFiles = () => {\n // no-op by default\n },\n }: {\n app: { name: string };\n alias?: Record<string, string>;\n emitSharedFiles?: () => void;\n },\n) {\n const webpackConfig = nextConfig.webpack;\n\n nextConfig.webpack = (\n baseConfig: WebpackOptionsNormalized,\n webpackContext,\n ) => {\n // execute the client config first, otherwise their config may accidentally\n // overwrite our required config - leading to unexpected errors.\n const config = (\n typeof webpackConfig === 'function'\n ? (webpackConfig(baseConfig, webpackContext) ?? baseConfig)\n : baseConfig\n ) as WebpackOptionsNormalized;\n\n // remote component specific plugins\n config.plugins.push(\n new RemoteWebpackRequirePlugin(app.name),\n new ModuleIdEmbedPlugin(app.name, { isServer: webpackContext.isServer }),\n new ConditionalExecPlugin(app.name),\n new PatchRequirePlugin(app.name),\n );\n if (!webpackContext.isServer) {\n // change the chunk loading global to avoid conflicts with other remote components\n config.output.chunkLoadingGlobal = `__remote_chunk_loading_global_${app.name}__`;\n }\n\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve.alias,\n ...Object.fromEntries(\n Object.entries(alias).map(([key, value]) => [\n key,\n join(process.cwd(), value),\n ]),\n ),\n },\n };\n\n emitSharedFiles();\n return config;\n };\n\n return nextConfig;\n}\n"]}
|