@module-federation/nextjs-mf 7.0.8 → 8.0.1-0
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/CHANGELOG.md +545 -411
- package/README.md +29 -15
- package/client/MFClient.js +1 -2
- package/client/MFClient.js.map +1 -1
- package/client/RemoteContainer.js +2 -1
- package/client/RemoteContainer.js.map +1 -1
- package/client/RemotePages.js +2 -1
- package/client/RemotePages.js.map +1 -1
- package/client/UrlNode.js +2 -10
- package/client/UrlNode.js.map +1 -1
- package/node.d.ts +1 -1
- package/node.js.map +1 -1
- package/package.json +7 -5
- package/src/default-delegate.js +64 -9
- package/src/default-delegate.js.map +1 -1
- package/src/federation-noop.js +13 -1
- package/src/federation-noop.js.map +1 -1
- package/src/index.d.ts +1 -1
- package/src/internal.d.ts +18 -12
- package/src/internal.js +83 -71
- package/src/internal.js.map +1 -1
- package/src/loaders/delegateLoader.d.ts +5 -2
- package/src/loaders/delegateLoader.js +19 -9
- package/src/loaders/delegateLoader.js.map +1 -1
- package/src/loaders/fixImageLoader.d.ts +12 -11
- package/src/loaders/fixImageLoader.js +17 -13
- package/src/loaders/fixImageLoader.js.map +1 -1
- package/src/loaders/fixUrlLoader.d.ts +7 -7
- package/src/loaders/fixUrlLoader.js +11 -11
- package/src/loaders/fixUrlLoader.js.map +1 -1
- package/src/loaders/helpers.d.ts +10 -3
- package/src/loaders/helpers.js +22 -13
- package/src/loaders/helpers.js.map +1 -1
- package/src/loaders/inject-hoist.d.ts +11 -0
- package/src/loaders/inject-hoist.js +7 -0
- package/src/loaders/inject-hoist.js.map +1 -1
- package/src/loaders/nextPageMapLoader.d.ts +12 -3
- package/src/loaders/nextPageMapLoader.js +45 -29
- package/src/loaders/nextPageMapLoader.js.map +1 -1
- package/src/loaders/patchDefaultSharedLoader.d.ts +9 -0
- package/src/loaders/patchDefaultSharedLoader.js +11 -0
- package/src/loaders/patchDefaultSharedLoader.js.map +1 -1
- package/src/loaders/patchNextClientPageLoader.d.ts +4 -2
- package/src/loaders/patchNextClientPageLoader.js +36 -18
- package/src/loaders/patchNextClientPageLoader.js.map +1 -1
- package/src/plugins/CopyFederationPlugin.d.ts +13 -0
- package/src/plugins/CopyFederationPlugin.js +40 -19
- package/src/plugins/CopyFederationPlugin.js.map +1 -1
- package/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +2 -3
- package/src/plugins/NextFederationPlugin/apply-client-plugins.js +9 -6
- package/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -1
- package/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +17 -10
- package/src/plugins/NextFederationPlugin/apply-server-plugins.js +35 -27
- package/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -1
- package/src/plugins/NextFederationPlugin/index.d.ts +18 -6
- package/src/plugins/NextFederationPlugin/index.js +108 -75
- package/src/plugins/NextFederationPlugin/index.js.map +1 -1
- package/src/plugins/NextFederationPlugin/next-fragments.d.ts +23 -17
- package/src/plugins/NextFederationPlugin/next-fragments.js +26 -18
- package/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -1
- package/src/plugins/NextFederationPlugin/regex-equal.d.ts +8 -8
- package/src/plugins/NextFederationPlugin/regex-equal.js +7 -7
- package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.d.ts +7 -0
- package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +20 -9
- package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +1 -1
- package/src/plugins/NextFederationPlugin/set-options.d.ts +6 -6
- package/src/plugins/NextFederationPlugin/set-options.js +10 -6
- package/src/plugins/NextFederationPlugin/set-options.js.map +1 -1
- package/src/plugins/NextFederationPlugin/validate-options.d.ts +13 -14
- package/src/plugins/NextFederationPlugin/validate-options.js +15 -15
- package/src/plugins/NextFederationPlugin/validate-options.js.map +1 -1
- package/src/plugins/container/EmbeddedContainerPlugin.d.ts +40 -0
- package/src/plugins/container/EmbeddedContainerPlugin.js +73 -0
- package/src/plugins/container/EmbeddedContainerPlugin.js.map +1 -0
- package/src/plugins/container/InvertedContainerPlugin.d.ts +21 -14
- package/src/plugins/container/InvertedContainerPlugin.js +21 -148
- package/src/plugins/container/InvertedContainerPlugin.js.map +1 -1
- package/src/plugins/container/InvertedContainerRuntimeModule.d.ts +3 -33
- package/src/plugins/container/InvertedContainerRuntimeModule.js +64 -518
- package/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -1
- package/src/plugins/container/ModuleFederationPlugin.d.ts +17 -0
- package/src/plugins/container/ModuleFederationPlugin.js +97 -0
- package/src/plugins/container/ModuleFederationPlugin.js.map +1 -0
- package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.d.ts +28 -6
- package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js +34 -57
- package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js.map +1 -1
- package/src/plugins/container/types.d.ts +1 -1
- package/src/types.d.ts +3 -0
- package/utilities.js.map +1 -1
- package/utils/Template.d.ts +1 -1
- package/utils/Template.js +23 -15
- package/utils/Template.js.map +1 -1
- package/utils/build-utils.d.ts +9 -0
- package/utils/build-utils.js +9 -0
- package/utils/build-utils.js.map +1 -1
- package/utils/flushedChunks.d.ts +15 -0
- package/utils/flushedChunks.js +8 -0
- package/utils/flushedChunks.js.map +1 -1
- package/utils/index.d.ts +27 -3
- package/utils/index.js +45 -1
- package/utils/index.js.map +1 -1
- package/src/plugins/JsonpChunkLoading.d.ts +0 -7
- package/src/plugins/JsonpChunkLoading.js +0 -43
- package/src/plugins/JsonpChunkLoading.js.map +0 -1
- package/src/plugins/container/custom-jsonp.d.ts +0 -2
- package/src/plugins/container/custom-jsonp.js +0 -90
- package/src/plugins/container/custom-jsonp.js.map +0 -1
|
@@ -3,12 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const webpack_1 = require("webpack");
|
|
9
|
-
const RemoveEagerModulesFromRuntimePlugin_1 = __importDefault(require("./RemoveEagerModulesFromRuntimePlugin"));
|
|
6
|
+
const EmbeddedContainerPlugin_1 = __importDefault(require("./EmbeddedContainerPlugin"));
|
|
7
|
+
const enhanced_1 = require("@module-federation/enhanced");
|
|
10
8
|
/**
|
|
11
9
|
* InvertedContainerPlugin is a Webpack plugin that handles loading of chunks in a federated module.
|
|
10
|
+
* @class
|
|
12
11
|
*/
|
|
13
12
|
class InvertedContainerPlugin {
|
|
14
13
|
/**
|
|
@@ -16,159 +15,33 @@ class InvertedContainerPlugin {
|
|
|
16
15
|
* @param {InvertedContainerOptions} options - Plugin configuration options.
|
|
17
16
|
*/
|
|
18
17
|
constructor(options) {
|
|
19
|
-
this.options = options
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Resolves the container module for the given compilation.
|
|
23
|
-
* @param {Compilation} compilation - Webpack compilation instance.
|
|
24
|
-
* @returns {Module | undefined} - The container module or undefined if not found.
|
|
25
|
-
*/
|
|
26
|
-
resolveContainerModule(compilation) {
|
|
27
|
-
if (!this.options.container) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
const container = compilation.entrypoints
|
|
31
|
-
.get(this.options.container)
|
|
32
|
-
?.getRuntimeChunk?.();
|
|
33
|
-
if (!container)
|
|
34
|
-
return undefined;
|
|
35
|
-
const entrymodule = compilation.chunkGraph.getChunkEntryModulesIterable(container);
|
|
36
|
-
for (const module of entrymodule) {
|
|
37
|
-
return module;
|
|
38
|
-
}
|
|
39
|
-
return undefined;
|
|
18
|
+
this.options = options;
|
|
40
19
|
}
|
|
41
20
|
/**
|
|
42
21
|
* Apply method for the Webpack plugin, handling the plugin logic and hooks.
|
|
43
22
|
* @param {Compiler} compiler - Webpack compiler instance.
|
|
44
23
|
*/
|
|
45
24
|
apply(compiler) {
|
|
46
|
-
new
|
|
25
|
+
new EmbeddedContainerPlugin_1.default({
|
|
26
|
+
runtime: this.options.runtime,
|
|
47
27
|
container: this.options.container,
|
|
48
|
-
|
|
28
|
+
chunkToEmbed: this.options.chunkToEmbed,
|
|
49
29
|
}).apply(compiler);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (chunk.hasRuntime()) {
|
|
64
|
-
// Add an InvertedContainerRuntimeModule to the chunk, which handles
|
|
65
|
-
// the runtime logic for loading remote modules.
|
|
66
|
-
compilation.addRuntimeModule(chunk, new InvertedContainerRuntimeModule_1.default(set, this.options, {
|
|
67
|
-
webpack: compiler.webpack,
|
|
68
|
-
debug: this.options.debug,
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
compilation.hooks.additionalChunkRuntimeRequirements.tap('InvertedContainerPlugin', handler);
|
|
73
|
-
compilation.hooks.optimizeChunks.tap('InvertedContainerPlugin', (chunks) => {
|
|
74
|
-
const containerEntryModule = this.resolveContainerModule(compilation);
|
|
75
|
-
if (!containerEntryModule)
|
|
76
|
-
return;
|
|
77
|
-
for (const chunk of chunks) {
|
|
78
|
-
if (!compilation.chunkGraph.isModuleInChunk(containerEntryModule, chunk) &&
|
|
79
|
-
chunk.hasRuntime()) {
|
|
80
|
-
compilation.chunkGraph.connectChunkAndModule(chunk, containerEntryModule);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
const hooks = javascript.JavascriptModulesPlugin.getCompilationHooks(compilation);
|
|
85
|
-
compilation.hooks.processAssets.tap({
|
|
86
|
-
name: 'InvertedContainerPlugin',
|
|
87
|
-
stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
|
88
|
-
}, (assets) => {
|
|
89
|
-
for (const chunk of compilation.chunks) {
|
|
90
|
-
for (const file of chunk.files) {
|
|
91
|
-
const asset = compilation.getAsset(file);
|
|
92
|
-
if (asset) {
|
|
93
|
-
let source = asset.source.source();
|
|
94
|
-
const chunkID = typeof chunk.id === 'string'
|
|
95
|
-
? JSON.stringify(chunk.id)
|
|
96
|
-
: chunk.id;
|
|
97
|
-
// Inject the chunk name at the beginning of the file
|
|
98
|
-
source = source
|
|
99
|
-
.toString()
|
|
100
|
-
//@ts-ignore
|
|
101
|
-
.replace('__INSERT_CH_ID__MF__', chunkID);
|
|
102
|
-
const updatedSource = new webpack_sources_1.RawSource(source);
|
|
103
|
-
//@ts-ignore
|
|
104
|
-
compilation.updateAsset(file, updatedSource);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
hooks.renderStartup.tap('InvertedContainerPlugin',
|
|
110
|
-
//@ts-ignore
|
|
111
|
-
(source, renderContext) => {
|
|
112
|
-
if (!renderContext ||
|
|
113
|
-
//@ts-ignore
|
|
114
|
-
renderContext?._name ||
|
|
115
|
-
!renderContext?.debugId ||
|
|
116
|
-
!compilation.chunkGraph.isEntryModule(renderContext) ||
|
|
117
|
-
//@ts-ignore
|
|
118
|
-
renderContext?.rawRequest?.includes('pages/api') ||
|
|
119
|
-
renderContext?.layer === 'api') {
|
|
120
|
-
// skip empty modules, container entry, and anything that doesnt have a moduleid or is not an entrypoint module.
|
|
121
|
-
return source;
|
|
122
|
-
}
|
|
123
|
-
const { runtimeTemplate } = compilation;
|
|
124
|
-
const replaceSource = source.source().toString().split('\n');
|
|
125
|
-
const searchString = '__webpack_exec__';
|
|
126
|
-
const replaceString = '__webpack_exec_proxy__';
|
|
127
|
-
const originalExec = replaceSource.findIndex((s) => s.includes(searchString));
|
|
128
|
-
if (originalExec === -1) {
|
|
129
|
-
return source;
|
|
130
|
-
}
|
|
131
|
-
const firstHalf = replaceSource.slice(0, originalExec + 1);
|
|
132
|
-
const secondHalf = replaceSource.slice(originalExec + 1, replaceSource.length);
|
|
133
|
-
const originalRuntimeCode = firstHalf
|
|
134
|
-
.join('\n')
|
|
135
|
-
.replace(searchString, replaceString);
|
|
136
|
-
const fancyTemplate = Template.asString([
|
|
137
|
-
runtimeTemplate.returningFunction(Template.asString([
|
|
138
|
-
'__webpack_require__.own_remote.then(',
|
|
139
|
-
runtimeTemplate.returningFunction(Template.asString([
|
|
140
|
-
'Promise.all([',
|
|
141
|
-
Template.indent([
|
|
142
|
-
'Promise.all(__webpack_require__.initRemotes)',
|
|
143
|
-
'Promise.all(__webpack_require__.initConsumes)',
|
|
144
|
-
].join(',\n')),
|
|
145
|
-
'])',
|
|
146
|
-
])),
|
|
147
|
-
').then(',
|
|
148
|
-
runtimeTemplate.returningFunction(Template.asString([`${replaceString}(moduleId)`])),
|
|
149
|
-
')',
|
|
150
|
-
].join('')), 'moduleId'),
|
|
151
|
-
]);
|
|
152
|
-
const wholeTem = Template.asString([
|
|
153
|
-
`var ${searchString} =`,
|
|
154
|
-
fancyTemplate,
|
|
155
|
-
]);
|
|
156
|
-
return Template.asString([
|
|
157
|
-
'',
|
|
158
|
-
'var currentChunkId = __INSERT_CH_ID__MF__;',
|
|
159
|
-
`if(currentChunkId) {`,
|
|
160
|
-
Template.indent([
|
|
161
|
-
`if(__webpack_require__.getEagerSharedForChunkId) {__webpack_require__.getEagerSharedForChunkId(currentChunkId,__webpack_require__.initConsumes)}`,
|
|
162
|
-
`if(__webpack_require__.getEagerRemotesForChunkId) {__webpack_require__.getEagerRemotesForChunkId(currentChunkId,__webpack_require__.initRemotes)}`,
|
|
163
|
-
]),
|
|
164
|
-
'}',
|
|
165
|
-
originalRuntimeCode,
|
|
166
|
-
wholeTem,
|
|
167
|
-
...secondHalf,
|
|
168
|
-
'',
|
|
169
|
-
]);
|
|
170
|
-
});
|
|
30
|
+
const asyncBoundaryPlugin = new enhanced_1.AsyncBoundaryPlugin();
|
|
31
|
+
asyncBoundaryPlugin.hooks.checkInvalidContext.tap('InvertedContainerPlugin', (renderContext, compilation) => {
|
|
32
|
+
return (!renderContext ||
|
|
33
|
+
//@ts-ignore
|
|
34
|
+
renderContext?._name ||
|
|
35
|
+
//@ts-ignore
|
|
36
|
+
!renderContext?.debugId ||
|
|
37
|
+
//@ts-ignore
|
|
38
|
+
!compilation.chunkGraph.isEntryModule(renderContext) ||
|
|
39
|
+
//@ts-ignore
|
|
40
|
+
renderContext?.rawRequest?.includes('pages/api') ||
|
|
41
|
+
//@ts-ignore
|
|
42
|
+
renderContext?.layer === 'api');
|
|
171
43
|
});
|
|
44
|
+
asyncBoundaryPlugin.apply(compiler);
|
|
172
45
|
}
|
|
173
46
|
}
|
|
174
47
|
exports.default = InvertedContainerPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InvertedContainerPlugin.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/container/InvertedContainerPlugin.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"InvertedContainerPlugin.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/container/InvertedContainerPlugin.ts"],"names":[],"mappings":";;;;;AAEA,wFAAgE;AAChE,0DAAkE;AAqBlE;;;GAGG;AACH,MAAM,uBAAuB;IAG3B;;;OAGG;IACH,YAAY,OAAiC;QAC3C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,QAAkB;QAC7B,IAAI,iCAAuB,CAAC;YAC1B,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;YAC7B,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;YACjC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;SACxC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEnB,MAAM,mBAAmB,GAAG,IAAI,8BAAmB,EAAE,CAAC;QACtD,mBAAmB,CAAC,KAAK,CAAC,mBAAmB,CAAC,GAAG,CAAC,yBAAyB,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,EAAE;YAC1G,OAAO,CACL,CAAC,aAAa;gBACd,YAAY;gBACZ,aAAa,EAAE,KAAK;gBACpB,YAAY;gBACZ,CAAC,aAAa,EAAE,OAAO;gBACvB,YAAY;gBACZ,CAAC,WAAW,CAAC,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC;gBACpD,YAAY;gBACZ,aAAa,EAAE,UAAU,EAAE,QAAQ,CAAC,WAAW,CAAC;gBAChD,YAAY;gBACZ,aAAa,EAAE,KAAK,KAAK,KAAK,CAC/B,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;CACF;AAED,kBAAe,uBAAuB,CAAC"}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RuntimeModule } from 'webpack';
|
|
3
|
-
/**
|
|
4
|
-
* Interface for InvertedContainerRuntimeModuleOptions, containing
|
|
5
|
-
* options for the InvertedContainerRuntimeModule class.
|
|
6
|
-
*/
|
|
1
|
+
import RuntimeModule from 'webpack/lib/RuntimeModule';
|
|
7
2
|
interface InvertedContainerRuntimeModuleOptions {
|
|
8
3
|
runtime: string;
|
|
9
4
|
remotes: Record<string, string>;
|
|
@@ -11,35 +6,10 @@ interface InvertedContainerRuntimeModuleOptions {
|
|
|
11
6
|
debug?: boolean;
|
|
12
7
|
container?: string;
|
|
13
8
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Interface for ChunkLoadingContext, containing Webpack-related properties.
|
|
16
|
-
*/
|
|
17
|
-
interface ChunkLoadingContext {
|
|
18
|
-
webpack: Compiler['webpack'];
|
|
19
|
-
debug?: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* InvertedContainerRuntimeModule is a Webpack runtime module that generates
|
|
23
|
-
* the runtime code needed for loading federated modules in an inverted container.
|
|
24
|
-
*/
|
|
25
9
|
declare class InvertedContainerRuntimeModule extends RuntimeModule {
|
|
26
|
-
private runtimeRequirements;
|
|
27
10
|
private options;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* Constructor for the InvertedContainerRuntimeModule.
|
|
31
|
-
* @param {Set<string>} runtimeRequirements - A set of runtime requirement strings.
|
|
32
|
-
* @param {InvertedContainerRuntimeModuleOptions} options - Runtime module options.
|
|
33
|
-
* @param {ChunkLoadingContext} chunkLoadingContext - Chunk loading context.
|
|
34
|
-
*/
|
|
35
|
-
constructor(runtimeRequirements: Set<string>, options: InvertedContainerRuntimeModuleOptions, chunkLoadingContext: ChunkLoadingContext);
|
|
36
|
-
resolveContainerModule(): Module | undefined;
|
|
37
|
-
mapShared(): string;
|
|
38
|
-
mapChunks(): string;
|
|
39
|
-
/**
|
|
40
|
-
* Generate method for the runtime module, producing the runtime code.
|
|
41
|
-
* @returns {string} runtime code
|
|
42
|
-
*/
|
|
11
|
+
constructor(options: InvertedContainerRuntimeModuleOptions);
|
|
12
|
+
private resolveContainerModule;
|
|
43
13
|
generate(): string;
|
|
44
14
|
}
|
|
45
15
|
export default InvertedContainerRuntimeModule;
|