@module-federation/node 2.1.5 → 2.1.6
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/jest.config.d.ts +11 -0
- package/dist/jest.config.js +19 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/package.json +95 -0
- package/dist/src/filesystem/stratagies.d.ts +18 -0
- package/dist/src/filesystem/stratagies.js +117 -0
- package/dist/src/filesystem/stratagies.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +17 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.d.ts +9 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.js +38 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.js.map +1 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.d.ts +61 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.js +442 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.js.map +1 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.ts +17 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.js +121 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.js.map +1 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.ts +39 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +119 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.d.ts +13 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.js +41 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.js.map +1 -0
- package/dist/src/plugins/NodeFederationPlugin.d.ts +46 -0
- package/dist/src/plugins/NodeFederationPlugin.js +81 -0
- package/dist/src/plugins/NodeFederationPlugin.js.map +1 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.d.ts +10 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.js +132 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.js.map +1 -0
- package/dist/src/plugins/StreamingTargetPlugin.d.ts +28 -0
- package/dist/src/plugins/StreamingTargetPlugin.js +59 -0
- package/dist/src/plugins/StreamingTargetPlugin.js.map +1 -0
- package/dist/src/plugins/UniversalFederationPlugin.d.ts +43 -0
- package/dist/src/plugins/UniversalFederationPlugin.js +53 -0
- package/dist/src/plugins/UniversalFederationPlugin.js.map +1 -0
- package/dist/src/plugins/webpackChunkUtilities.d.ts +50 -0
- package/dist/src/plugins/webpackChunkUtilities.js +305 -0
- package/dist/src/plugins/webpackChunkUtilities.js.map +1 -0
- package/dist/src/types/index.d.ts +3 -0
- package/dist/src/types/index.js +3 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/flush-chunks.d.ts +11 -0
- package/dist/src/utils/flush-chunks.js +172 -0
- package/dist/src/utils/flush-chunks.js.map +1 -0
- package/dist/src/utils/hot-reload.d.ts +7 -0
- package/dist/src/utils/hot-reload.js +184 -0
- package/dist/src/utils/hot-reload.js.map +1 -0
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/index.js +19 -0
- package/dist/src/utils/index.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/**
|
|
7
|
+
* Importing necessary plugins and types
|
|
8
|
+
*/
|
|
9
|
+
const StreamingTargetPlugin_1 = __importDefault(require("./StreamingTargetPlugin"));
|
|
10
|
+
const NodeFederationPlugin_1 = __importDefault(require("./NodeFederationPlugin"));
|
|
11
|
+
const webpack_1 = require("@module-federation/enhanced/webpack");
|
|
12
|
+
const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
|
|
13
|
+
/**
|
|
14
|
+
* Class representing a UniversalFederationPlugin
|
|
15
|
+
*/
|
|
16
|
+
class UniversalFederationPlugin {
|
|
17
|
+
/**
|
|
18
|
+
* Create a UniversalFederationPlugin
|
|
19
|
+
* @param {NodeFederationOptions} options - The options for the plugin
|
|
20
|
+
* @param {NodeFederationContext} context - The context for the plugin
|
|
21
|
+
*/
|
|
22
|
+
constructor(options, context) {
|
|
23
|
+
this._options = options || {};
|
|
24
|
+
this.context = context || {};
|
|
25
|
+
this.name = 'ModuleFederationPlugin';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Apply the plugin to the compiler
|
|
29
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
30
|
+
*/
|
|
31
|
+
apply(compiler) {
|
|
32
|
+
const { isServer, debug, ...options } = this._options;
|
|
33
|
+
const { webpack } = compiler;
|
|
34
|
+
if (!process.env['FEDERATION_WEBPACK_PATH']) {
|
|
35
|
+
process.env['FEDERATION_WEBPACK_PATH'] = (0, normalize_webpack_path_1.getWebpackPath)(compiler);
|
|
36
|
+
}
|
|
37
|
+
if (isServer ||
|
|
38
|
+
compiler.options.name === 'server' ||
|
|
39
|
+
compiler.options.target === 'node' ||
|
|
40
|
+
compiler.options.target === 'async-node') {
|
|
41
|
+
new NodeFederationPlugin_1.default(options, this.context).apply(compiler);
|
|
42
|
+
new StreamingTargetPlugin_1.default({ ...options, debug }).apply(compiler);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
new webpack_1.ModuleFederationPlugin(options).apply(compiler);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Exporting UniversalFederationPlugin as default
|
|
51
|
+
*/
|
|
52
|
+
exports.default = UniversalFederationPlugin;
|
|
53
|
+
//# sourceMappingURL=UniversalFederationPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UniversalFederationPlugin.js","sourceRoot":"","sources":["../../../src/plug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EG;AACH,kBAAe,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Chunk, ChunkGraph } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* Generates the hot module replacement (HMR) code.
|
|
4
|
+
* @param {boolean} withHmr - Flag indicating whether HMR is enabled.
|
|
5
|
+
* @param {string} rootOutputDir - The root output directory.
|
|
6
|
+
* @returns {string} - The generated HMR code.
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateHmrCode(withHmr: boolean, rootOutputDir: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the initial chunk IDs.
|
|
11
|
+
* @param {Chunk} chunk - The chunk object.
|
|
12
|
+
* @param {ChunkGraph} chunkGraph - The chunk graph object.
|
|
13
|
+
* @param {any} chunkHasJs - Function to check if a chunk has JavaScript.
|
|
14
|
+
* @returns {Set} - The set of initial chunk IDs.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getInitialChunkIds(chunk: Chunk, chunkGraph: ChunkGraph, chunkHasJs: any): Set<string | number>;
|
|
17
|
+
/**
|
|
18
|
+
* Generates the loading code for chunks.
|
|
19
|
+
* @param {boolean} withLoading - Flag indicating whether chunk loading is enabled.
|
|
20
|
+
* @param {string} fn - The function name.
|
|
21
|
+
* @param {any} hasJsMatcher - Function to check if a chunk has JavaScript.
|
|
22
|
+
* @param {string} rootOutputDir - The root output directory.
|
|
23
|
+
* @param {Record<string, string>} remotes - The remotes object.
|
|
24
|
+
* @param {string | undefined} name - The name of the chunk.
|
|
25
|
+
* @returns {string} - The generated loading code.
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateLoadingCode(withLoading: boolean, fn: string, hasJsMatcher: any, rootOutputDir: string, remotes: Record<string, string>, name: string | undefined): string;
|
|
28
|
+
/**
|
|
29
|
+
* Generates the HMR manifest code.
|
|
30
|
+
* @param {boolean} withHmrManifest - Flag indicating whether HMR manifest is enabled.
|
|
31
|
+
* @param {string} rootOutputDir - The root output directory.
|
|
32
|
+
* @returns {string} - The generated HMR manifest code.
|
|
33
|
+
*/
|
|
34
|
+
export declare function generateHmrManifestCode(withHmrManifest: boolean, rootOutputDir: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Handles the on chunk load event.
|
|
37
|
+
* @param {boolean} withOnChunkLoad - Flag indicating whether on chunk load event is enabled.
|
|
38
|
+
* @param {any} runtimeTemplate - The runtime template.
|
|
39
|
+
* @returns {string} - The generated on chunk load event handler.
|
|
40
|
+
*/
|
|
41
|
+
export declare function handleOnChunkLoad(withOnChunkLoad: boolean, runtimeTemplate: any): string;
|
|
42
|
+
/**
|
|
43
|
+
* Generates the load script for server-side execution. This function creates a script that loads a remote module
|
|
44
|
+
* and executes it in the current context. It supports both browser and Node.js environments.
|
|
45
|
+
* @param {any} runtimeTemplate - The runtime template used to generate the load script.
|
|
46
|
+
* @returns {string} - The generated load script.
|
|
47
|
+
*/
|
|
48
|
+
export declare function generateLoadScript(runtimeTemplate: any): string;
|
|
49
|
+
export declare function generateInstallChunk(runtimeTemplate: any, withOnChunkLoad: boolean): string;
|
|
50
|
+
export declare function generateExternalInstallChunkCode(withExternalInstallChunk: boolean, debug: boolean | undefined): string;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateExternalInstallChunkCode = exports.generateInstallChunk = exports.generateLoadScript = exports.handleOnChunkLoad = exports.generateHmrManifestCode = exports.generateLoadingCode = exports.getInitialChunkIds = exports.generateHmrCode = void 0;
|
|
4
|
+
const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
|
|
5
|
+
const { RuntimeGlobals, Template } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
|
|
6
|
+
/**
|
|
7
|
+
* Generates the hot module replacement (HMR) code.
|
|
8
|
+
* @param {boolean} withHmr - Flag indicating whether HMR is enabled.
|
|
9
|
+
* @param {string} rootOutputDir - The root output directory.
|
|
10
|
+
* @returns {string} - The generated HMR code.
|
|
11
|
+
*/
|
|
12
|
+
function generateHmrCode(withHmr, rootOutputDir) {
|
|
13
|
+
if (!withHmr) {
|
|
14
|
+
return '// no HMR';
|
|
15
|
+
}
|
|
16
|
+
return Template.asString([
|
|
17
|
+
// Function to load updated chunk
|
|
18
|
+
'function loadUpdateChunk(chunkId, updatedModulesList) {',
|
|
19
|
+
Template.indent([
|
|
20
|
+
'return new Promise(function(resolve, reject) {',
|
|
21
|
+
Template.indent([
|
|
22
|
+
// Construct filename for the updated chunk
|
|
23
|
+
`var filename = require('path').join(__dirname, ${JSON.stringify(rootOutputDir)} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`,
|
|
24
|
+
// Read the updated chunk file
|
|
25
|
+
"require('fs').readFile(filename, 'utf-8', function(err, content) {",
|
|
26
|
+
Template.indent([
|
|
27
|
+
'if(err) return reject(err);',
|
|
28
|
+
'var update = {};',
|
|
29
|
+
// Execute the updated chunk in the current context
|
|
30
|
+
"require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)" +
|
|
31
|
+
"(update, require, require('path').dirname(filename), filename);",
|
|
32
|
+
'var updatedModules = update.modules;',
|
|
33
|
+
'var runtime = update.runtime;',
|
|
34
|
+
// Iterate over the updated modules
|
|
35
|
+
'for(var moduleId in updatedModules) {',
|
|
36
|
+
Template.indent([
|
|
37
|
+
`if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,
|
|
38
|
+
Template.indent([
|
|
39
|
+
`currentUpdate[moduleId] = updatedModules[moduleId];`,
|
|
40
|
+
'if(updatedModulesList) updatedModulesList.push(moduleId);',
|
|
41
|
+
]),
|
|
42
|
+
'}',
|
|
43
|
+
]),
|
|
44
|
+
'}',
|
|
45
|
+
'if(runtime) currentUpdateRuntime.push(runtime);',
|
|
46
|
+
'resolve();',
|
|
47
|
+
]),
|
|
48
|
+
'});',
|
|
49
|
+
]),
|
|
50
|
+
'});',
|
|
51
|
+
]),
|
|
52
|
+
'}',
|
|
53
|
+
'',
|
|
54
|
+
// Replace placeholders in the HMR runtime code
|
|
55
|
+
Template.getFunctionContent(
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
57
|
+
require('webpack/lib/hmr/JavascriptHotModuleReplacement.runtime.js'))
|
|
58
|
+
.replace(/\$key\$/g, 'readFileVm')
|
|
59
|
+
.replace(/\$installedChunks\$/g, 'installedChunks')
|
|
60
|
+
.replace(/\$loadUpdateChunk\$/g, 'loadUpdateChunk')
|
|
61
|
+
.replace(/\$moduleCache\$/g, RuntimeGlobals.moduleCache)
|
|
62
|
+
.replace(/\$moduleFactories\$/g, RuntimeGlobals.moduleFactories)
|
|
63
|
+
.replace(/\$ensureChunkHandlers\$/g, RuntimeGlobals.ensureChunkHandlers)
|
|
64
|
+
.replace(/\$hasOwnProperty\$/g, RuntimeGlobals.hasOwnProperty)
|
|
65
|
+
.replace(/\$hmrModuleData\$/g, RuntimeGlobals.hmrModuleData)
|
|
66
|
+
.replace(/\$hmrDownloadUpdateHandlers\$/g, RuntimeGlobals.hmrDownloadUpdateHandlers)
|
|
67
|
+
.replace(/\$hmrInvalidateModuleHandlers\$/g, RuntimeGlobals.hmrInvalidateModuleHandlers),
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
70
|
+
exports.generateHmrCode = generateHmrCode;
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves the initial chunk IDs.
|
|
73
|
+
* @param {Chunk} chunk - The chunk object.
|
|
74
|
+
* @param {ChunkGraph} chunkGraph - The chunk graph object.
|
|
75
|
+
* @param {any} chunkHasJs - Function to check if a chunk has JavaScript.
|
|
76
|
+
* @returns {Set} - The set of initial chunk IDs.
|
|
77
|
+
*/
|
|
78
|
+
function getInitialChunkIds(chunk, chunkGraph, chunkHasJs) {
|
|
79
|
+
const initialChunkIds = new Set(chunk.ids);
|
|
80
|
+
for (const c of chunk.getAllInitialChunks()) {
|
|
81
|
+
if (c === chunk || chunkHasJs(c, chunkGraph))
|
|
82
|
+
continue;
|
|
83
|
+
if (c.ids) {
|
|
84
|
+
for (const id of c.ids)
|
|
85
|
+
initialChunkIds.add(id);
|
|
86
|
+
}
|
|
87
|
+
for (const c of chunk.getAllAsyncChunks()) {
|
|
88
|
+
if (c === chunk || chunkHasJs(c, chunkGraph))
|
|
89
|
+
continue;
|
|
90
|
+
if (c.ids) {
|
|
91
|
+
for (const id of c.ids)
|
|
92
|
+
initialChunkIds.add(id);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return initialChunkIds;
|
|
97
|
+
}
|
|
98
|
+
exports.getInitialChunkIds = getInitialChunkIds;
|
|
99
|
+
/**
|
|
100
|
+
* Generates the loading code for chunks.
|
|
101
|
+
* @param {boolean} withLoading - Flag indicating whether chunk loading is enabled.
|
|
102
|
+
* @param {string} fn - The function name.
|
|
103
|
+
* @param {any} hasJsMatcher - Function to check if a chunk has JavaScript.
|
|
104
|
+
* @param {string} rootOutputDir - The root output directory.
|
|
105
|
+
* @param {Record<string, string>} remotes - The remotes object.
|
|
106
|
+
* @param {string | undefined} name - The name of the chunk.
|
|
107
|
+
* @returns {string} - The generated loading code.
|
|
108
|
+
*/
|
|
109
|
+
function generateLoadingCode(withLoading, fn, hasJsMatcher, rootOutputDir, remotes, name) {
|
|
110
|
+
if (!withLoading) {
|
|
111
|
+
return '// no chunk loading';
|
|
112
|
+
}
|
|
113
|
+
return Template.asString([
|
|
114
|
+
'// Dynamic filesystem chunk loading for javascript',
|
|
115
|
+
`${fn}.readFileVm = function(chunkId, promises) {`,
|
|
116
|
+
hasJsMatcher !== false
|
|
117
|
+
? Template.indent([
|
|
118
|
+
'var installedChunkData = installedChunks[chunkId];',
|
|
119
|
+
'if(installedChunkData !== 0) { // 0 means "already installed".',
|
|
120
|
+
Template.indent([
|
|
121
|
+
'// array of [resolve, reject, promise] means "currently loading"',
|
|
122
|
+
'if(installedChunkData) {',
|
|
123
|
+
Template.indent(['promises.push(installedChunkData[2]);']),
|
|
124
|
+
'} else {',
|
|
125
|
+
Template.indent([
|
|
126
|
+
hasJsMatcher === true
|
|
127
|
+
? 'if(true) { // all chunks have JS'
|
|
128
|
+
: `if(${hasJsMatcher('chunkId')}) {`,
|
|
129
|
+
Template.indent([
|
|
130
|
+
'// load the chunk and return promise to it',
|
|
131
|
+
'var promise = new Promise(async function(resolve, reject) {',
|
|
132
|
+
Template.indent([
|
|
133
|
+
'installedChunkData = installedChunks[chunkId] = [resolve, reject];',
|
|
134
|
+
'function installChunkCallback(error,chunk){',
|
|
135
|
+
Template.indent([
|
|
136
|
+
'if(error) return reject(error);',
|
|
137
|
+
'installChunk(chunk);',
|
|
138
|
+
]),
|
|
139
|
+
'}',
|
|
140
|
+
'var fs = typeof process !== "undefined" ? require(\'fs\') : false;',
|
|
141
|
+
`var filename = typeof process !== "undefined" ? require('path').join(__dirname, ${JSON.stringify(rootOutputDir)} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId)) : false;`,
|
|
142
|
+
'if(fs && fs.existsSync(filename)) {',
|
|
143
|
+
Template.indent([
|
|
144
|
+
`loadChunkStrategy('filesystem', chunkId, ${JSON.stringify(rootOutputDir)}, remotes, installChunkCallback);`,
|
|
145
|
+
]),
|
|
146
|
+
'} else { ',
|
|
147
|
+
Template.indent([
|
|
148
|
+
`var remotes = ${JSON.stringify(Object.values(remotes).reduce((acc, remote) => {
|
|
149
|
+
const [global, url] = remote.split('@');
|
|
150
|
+
acc[global] = url;
|
|
151
|
+
return acc;
|
|
152
|
+
}, {}))};`,
|
|
153
|
+
`var chunkName = ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
|
|
154
|
+
"const loadingStrategy = typeof process !== 'undefined' ? 'http-vm' : 'http-eval';",
|
|
155
|
+
`loadChunkStrategy(loadingStrategy, chunkName,${RuntimeGlobals.require}.federation.initOptions.name, ${RuntimeGlobals.require}.federation.initOptions.remotes, installChunkCallback);`,
|
|
156
|
+
]),
|
|
157
|
+
'}',
|
|
158
|
+
]),
|
|
159
|
+
'});',
|
|
160
|
+
'promises.push(installedChunkData[2] = promise);',
|
|
161
|
+
]),
|
|
162
|
+
'} else installedChunks[chunkId] = 0;',
|
|
163
|
+
]),
|
|
164
|
+
'}',
|
|
165
|
+
]),
|
|
166
|
+
'}',
|
|
167
|
+
])
|
|
168
|
+
: Template.indent(['installedChunks[chunkId] = 0;']),
|
|
169
|
+
'};',
|
|
170
|
+
]);
|
|
171
|
+
}
|
|
172
|
+
exports.generateLoadingCode = generateLoadingCode;
|
|
173
|
+
/**
|
|
174
|
+
* Generates the HMR manifest code.
|
|
175
|
+
* @param {boolean} withHmrManifest - Flag indicating whether HMR manifest is enabled.
|
|
176
|
+
* @param {string} rootOutputDir - The root output directory.
|
|
177
|
+
* @returns {string} - The generated HMR manifest code.
|
|
178
|
+
*/
|
|
179
|
+
function generateHmrManifestCode(withHmrManifest, rootOutputDir) {
|
|
180
|
+
if (!withHmrManifest) {
|
|
181
|
+
return '// no HMR manifest';
|
|
182
|
+
}
|
|
183
|
+
return Template.asString([
|
|
184
|
+
`${RuntimeGlobals.hmrDownloadManifest} = function() {`,
|
|
185
|
+
Template.indent([
|
|
186
|
+
'return new Promise(function(resolve, reject) {',
|
|
187
|
+
Template.indent([
|
|
188
|
+
`var filename = require('path').join(__dirname, ${JSON.stringify(rootOutputDir)} + ${RuntimeGlobals.getUpdateManifestFilename}());`,
|
|
189
|
+
"require('fs').readFile(filename, 'utf-8', function(err, content) {",
|
|
190
|
+
Template.indent([
|
|
191
|
+
'if(err) {',
|
|
192
|
+
Template.indent([
|
|
193
|
+
'if(err.code === "ENOENT") return resolve();',
|
|
194
|
+
'return reject(err);',
|
|
195
|
+
]),
|
|
196
|
+
'}',
|
|
197
|
+
'try { resolve(JSON.parse(content)); }',
|
|
198
|
+
'catch(e) { reject(e); }',
|
|
199
|
+
]),
|
|
200
|
+
'});',
|
|
201
|
+
]),
|
|
202
|
+
'});',
|
|
203
|
+
]),
|
|
204
|
+
'}',
|
|
205
|
+
]);
|
|
206
|
+
}
|
|
207
|
+
exports.generateHmrManifestCode = generateHmrManifestCode;
|
|
208
|
+
/**
|
|
209
|
+
* Handles the on chunk load event.
|
|
210
|
+
* @param {boolean} withOnChunkLoad - Flag indicating whether on chunk load event is enabled.
|
|
211
|
+
* @param {any} runtimeTemplate - The runtime template.
|
|
212
|
+
* @returns {string} - The generated on chunk load event handler.
|
|
213
|
+
*/
|
|
214
|
+
function handleOnChunkLoad(withOnChunkLoad, runtimeTemplate) {
|
|
215
|
+
if (withOnChunkLoad) {
|
|
216
|
+
return `${RuntimeGlobals.onChunksLoaded}.readFileVm = ${runtimeTemplate.returningFunction('installedChunks[chunkId] === 0', 'chunkId')};`;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
return '// no on chunks loaded';
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
exports.handleOnChunkLoad = handleOnChunkLoad;
|
|
223
|
+
/**
|
|
224
|
+
* Generates the load script for server-side execution. This function creates a script that loads a remote module
|
|
225
|
+
* and executes it in the current context. It supports both browser and Node.js environments.
|
|
226
|
+
* @param {any} runtimeTemplate - The runtime template used to generate the load script.
|
|
227
|
+
* @returns {string} - The generated load script.
|
|
228
|
+
*/
|
|
229
|
+
function generateLoadScript(runtimeTemplate) {
|
|
230
|
+
return Template.asString([
|
|
231
|
+
'// load script equivalent for server side',
|
|
232
|
+
`${RuntimeGlobals.loadScript} = ${runtimeTemplate.basicFunction('url, callback, chunkId', [
|
|
233
|
+
Template.indent([
|
|
234
|
+
`async function executeLoad(url, callback, name) {
|
|
235
|
+
if (!name) {
|
|
236
|
+
throw new Error('__webpack_require__.l name is required for ' + url);
|
|
237
|
+
}
|
|
238
|
+
const usesInternalRef = name.startsWith('__webpack_require__')
|
|
239
|
+
if (usesInternalRef) {
|
|
240
|
+
const regex = /__webpack_require__\\.federation\\.instance\\.moduleCache\\.get\\(([^)]+)\\)/;
|
|
241
|
+
const match = name.match(regex);
|
|
242
|
+
if (match) {
|
|
243
|
+
name = match[1].replace(/["']/g, '');
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const federation = ${RuntimeGlobals.require}.federation;
|
|
248
|
+
const res = await ${RuntimeGlobals.require}.federation.runtime.loadScriptNode(url, { attrs: {} });
|
|
249
|
+
const enhancedRemote = federation.instance.initRawContainer(name, url, res);
|
|
250
|
+
// use normal global assignment
|
|
251
|
+
if(!usesInternalRef && !globalThis[name]) {
|
|
252
|
+
globalThis[name] = enhancedRemote
|
|
253
|
+
}
|
|
254
|
+
callback(enhancedRemote);
|
|
255
|
+
} catch (error) {
|
|
256
|
+
callback(error);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
}`,
|
|
260
|
+
`executeLoad(url, callback, chunkId);`,
|
|
261
|
+
]),
|
|
262
|
+
])}`,
|
|
263
|
+
]);
|
|
264
|
+
}
|
|
265
|
+
exports.generateLoadScript = generateLoadScript;
|
|
266
|
+
function generateInstallChunk(runtimeTemplate, withOnChunkLoad) {
|
|
267
|
+
return `var installChunk = ${runtimeTemplate.basicFunction('chunk', [
|
|
268
|
+
'var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;',
|
|
269
|
+
'for(var moduleId in moreModules) {',
|
|
270
|
+
Template.indent([
|
|
271
|
+
`if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
|
|
272
|
+
Template.indent([
|
|
273
|
+
`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`,
|
|
274
|
+
]),
|
|
275
|
+
'}',
|
|
276
|
+
]),
|
|
277
|
+
'}',
|
|
278
|
+
'if(runtime) runtime(__webpack_require__);',
|
|
279
|
+
'for(var i = 0; i < chunkIds.length; i++) {',
|
|
280
|
+
Template.indent([
|
|
281
|
+
'if(installedChunks[chunkIds[i]]) {',
|
|
282
|
+
Template.indent(['installedChunks[chunkIds[i]][0]();']),
|
|
283
|
+
'}',
|
|
284
|
+
'installedChunks[chunkIds[i]] = 0;',
|
|
285
|
+
]),
|
|
286
|
+
'}',
|
|
287
|
+
withOnChunkLoad ? `${RuntimeGlobals.onChunksLoaded}();` : '',
|
|
288
|
+
])};`;
|
|
289
|
+
}
|
|
290
|
+
exports.generateInstallChunk = generateInstallChunk;
|
|
291
|
+
function generateExternalInstallChunkCode(withExternalInstallChunk, debug) {
|
|
292
|
+
if (!withExternalInstallChunk) {
|
|
293
|
+
return '// no external install chunk';
|
|
294
|
+
}
|
|
295
|
+
return Template.asString([
|
|
296
|
+
'module.exports = __webpack_require__;',
|
|
297
|
+
`${RuntimeGlobals.externalInstallChunk} = function(){`,
|
|
298
|
+
debug
|
|
299
|
+
? `console.debug('node: webpack installing to install chunk id:', arguments['0'].id);`
|
|
300
|
+
: '',
|
|
301
|
+
`return installChunk.apply(this, arguments)};`,
|
|
302
|
+
]);
|
|
303
|
+
}
|
|
304
|
+
exports.generateExternalInstallChunkCode = generateExternalInstallChunkCode;
|
|
305
|
+
//# sourceMappingURL=webpackChunkUtilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpackChunkUtilities.js","sourceRoot":"","sources":["../../../src/plugins/webpackChunkUtilities.ts"],"names":[],"mappings":";;;AAAA,0FAAqF;AACrF,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,OAAO,CAC1C,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAG9B;;;;;GAKG;AACH,SAAgB,eAAe,CAC7B,OAAgB,EAChB,aAAqB;IAErB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,OAAO,QAAQ,CAAC,QAAQ,CAAC;QACvB,iCAAiC;QACjC,yDAAyD;QACzD,QAAQ,CAAC,MAAM,CAAC;YACd,gDAAgD;YAChD,QAAQ,CAAC,MAAM,CAAC;gBACd,2CAA2C;gBAC3C,kDAAkD,IAAI,CAAC,SAAS,CAC9D,aAAa,C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C,EAAE;QACN,8CAA8C;KAC/C,CAAC,CAAC;AACL,CAAC;AAhBD,4EAgBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize usedChunks and share it globally.
|
|
3
|
+
* @type {Set}
|
|
4
|
+
*/
|
|
5
|
+
export declare const usedChunks: any;
|
|
6
|
+
export declare const getAllKnownRemotes: () => {};
|
|
7
|
+
/**
|
|
8
|
+
* Flush the chunks and return a deduplicated array of chunks.
|
|
9
|
+
* @returns {Promise<Array>} A promise that resolves to an array of deduplicated chunks.
|
|
10
|
+
*/
|
|
11
|
+
export declare const flushChunks: () => Promise<unknown[]>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-undef */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.flushChunks = exports.getAllKnownRemotes = exports.usedChunks = void 0;
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
if (!globalThis.usedChunks) {
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
globalThis.usedChunks = new Set();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Initialize usedChunks and share it globally.
|
|
12
|
+
* @type {Set}
|
|
13
|
+
*/
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
exports.usedChunks = globalThis.usedChunks;
|
|
16
|
+
/**
|
|
17
|
+
* Load hostStats from the JSON file.
|
|
18
|
+
* @returns {object} hostStats - An object containing host stats data.
|
|
19
|
+
*/
|
|
20
|
+
const loadHostStats = () => {
|
|
21
|
+
try {
|
|
22
|
+
//@ts-ignore
|
|
23
|
+
return __non_webpack_require__('../federated-stats.json');
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const getAllKnownRemotes = function () {
|
|
30
|
+
// Attempt to access the global federation controller safely
|
|
31
|
+
const federationController = new Function('return globalThis')()
|
|
32
|
+
.__FEDERATION__;
|
|
33
|
+
if (!federationController || !federationController.__INSTANCES__) {
|
|
34
|
+
// If the federation controller or instances are not defined, return an empty object
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
var collected = {};
|
|
38
|
+
// Use a for...of loop to iterate over all federation instances
|
|
39
|
+
for (const instance of federationController.__INSTANCES__) {
|
|
40
|
+
// Use another for...of loop to iterate over the module cache Map entries
|
|
41
|
+
for (const [key, cacheModule] of instance.moduleCache) {
|
|
42
|
+
// Check if the cacheModule has remoteInfo and use it to collect remote names
|
|
43
|
+
if (cacheModule.remoteInfo) {
|
|
44
|
+
//@ts-ignore
|
|
45
|
+
collected[cacheModule.remoteInfo.name] = cacheModule.remoteInfo;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return collected;
|
|
50
|
+
};
|
|
51
|
+
exports.getAllKnownRemotes = getAllKnownRemotes;
|
|
52
|
+
/**
|
|
53
|
+
* Create a shareMap based on the loaded modules.
|
|
54
|
+
* @returns {object} shareMap - An object containing the shareMap data.
|
|
55
|
+
*/
|
|
56
|
+
const createShareMap = () => {
|
|
57
|
+
// Check if __webpack_share_scopes__ is defined and has a default property
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
if (__webpack_share_scopes__?.default) {
|
|
60
|
+
// Reduce the keys of the default property to create the share map
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
return Object.keys(__webpack_share_scopes__.default).reduce((acc, key) => {
|
|
63
|
+
// Get the loaded modules for the current key
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
const loadedModules = Object.values(__webpack_share_scopes__.default[key])
|
|
66
|
+
// Filter out the modules that are not loaded
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
.filter((sharedModule) => sharedModule.loaded)
|
|
69
|
+
// Map the filtered modules to their 'from' properties
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
.map((sharedModule) => sharedModule.from);
|
|
72
|
+
// If there are any loaded modules, add them to the accumulator object
|
|
73
|
+
if (loadedModules.length > 0) {
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
acc[key] = loadedModules;
|
|
76
|
+
}
|
|
77
|
+
// Return the accumulator object for the next iteration
|
|
78
|
+
return acc;
|
|
79
|
+
}, {});
|
|
80
|
+
}
|
|
81
|
+
// If __webpack_share_scopes__ is not defined or doesn't have a default property, return an empty object
|
|
82
|
+
return {};
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Process a single chunk and return an array of updated chunks.
|
|
86
|
+
* @param {string} chunk - A chunk string containing remote and request data.
|
|
87
|
+
* @param {object} shareMap - An object containing the shareMap data.
|
|
88
|
+
* @param {object} hostStats - An object containing host stats data.
|
|
89
|
+
* @returns {Promise<Array>} A promise that resolves to an array of updated chunks.
|
|
90
|
+
*/
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
const processChunk = async (chunk, shareMap, hostStats) => {
|
|
93
|
+
const chunks = new Set();
|
|
94
|
+
const [remote, req] = chunk.split('/');
|
|
95
|
+
const request = './' + req;
|
|
96
|
+
const knownRemotes = (0, exports.getAllKnownRemotes)();
|
|
97
|
+
//@ts-ignore
|
|
98
|
+
if (!knownRemotes[remote]) {
|
|
99
|
+
console.error(`flush chunks: Remote ${remote} is not defined in the global config`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
//@ts-ignore
|
|
104
|
+
const remoteName = new URL(knownRemotes[remote].entry).pathname
|
|
105
|
+
.split('/')
|
|
106
|
+
.pop();
|
|
107
|
+
//@ts-ignore
|
|
108
|
+
const statsFile = knownRemotes[remote].entry
|
|
109
|
+
.replace(remoteName, 'federated-stats.json')
|
|
110
|
+
.replace('ssr', 'chunks');
|
|
111
|
+
let stats = {};
|
|
112
|
+
try {
|
|
113
|
+
stats = await fetch(statsFile).then((res) => res.json());
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
console.error('flush error', e);
|
|
117
|
+
}
|
|
118
|
+
//@ts-ignore
|
|
119
|
+
const [prefix] = knownRemotes[remote].entry.split('static/');
|
|
120
|
+
//@ts-ignore
|
|
121
|
+
if (stats.federatedModules) {
|
|
122
|
+
//@ts-ignore
|
|
123
|
+
stats.federatedModules.forEach((modules) => {
|
|
124
|
+
if (modules.exposes?.[request]) {
|
|
125
|
+
//@ts-ignore
|
|
126
|
+
modules.exposes[request].forEach((chunk) => {
|
|
127
|
+
chunks.add([prefix, chunk].join(''));
|
|
128
|
+
Object.values(chunk).forEach((chunk) => {
|
|
129
|
+
//@ts-ignore
|
|
130
|
+
if (chunk.files) {
|
|
131
|
+
//@ts-ignore
|
|
132
|
+
chunk.files.forEach((file) => {
|
|
133
|
+
chunks.add(prefix + file);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
//@ts-ignore
|
|
137
|
+
if (chunk.requiredModules) {
|
|
138
|
+
//@ts-ignore
|
|
139
|
+
chunk.requiredModules.forEach((module) => {
|
|
140
|
+
if (shareMap[module]) {
|
|
141
|
+
// If the module is from the host, log the host stats
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return Array.from(chunks);
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
console.error('flush error:', e);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Flush the chunks and return a deduplicated array of chunks.
|
|
158
|
+
* @returns {Promise<Array>} A promise that resolves to an array of deduplicated chunks.
|
|
159
|
+
*/
|
|
160
|
+
const flushChunks = async () => {
|
|
161
|
+
const hostStats = loadHostStats();
|
|
162
|
+
const shareMap = createShareMap();
|
|
163
|
+
const allFlushed = await Promise.all(Array.from(exports.usedChunks).map(async (chunk) => processChunk(chunk, shareMap, hostStats)));
|
|
164
|
+
// Deduplicate the chunks array
|
|
165
|
+
const dedupe = Array.from(new Set([...allFlushed.flat()]));
|
|
166
|
+
// Clear usedChunks
|
|
167
|
+
exports.usedChunks.clear();
|
|
168
|
+
// Filter out any undefined or null values
|
|
169
|
+
return dedupe.filter(Boolean);
|
|
170
|
+
};
|
|
171
|
+
exports.flushChunks = flushChunks;
|
|
172
|
+
//# sourceMappingURL=flush-chunks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flush-chunks.js","sourceRoot":"","sources":["../../../src/utils/flush-chunks.ts"],"names":[],"mappings":";AAAA,6BAA6B;;;AAE7B,aAAa;AACb,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;IAC3B,aAAa;IACb,UAAU,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;AACpC,CAAC;AACD;;;GAGG;AACH,aAAa;AACE,kBAAU,GAAK,UAAU,YAAC;AACzC;;;GAGG;AACH,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,IAAI,CAAC;QACH,YAAY;QACZ,OAAO,uBAAuB,CAAC,yBAAyB,CAAC,CAAC;IAC5D,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAEK,MAAM,kBAAkB,GAAG;IAChC,4DAA4D;IAC5D,MAAM,oBAAoB,GAAG,IAAI,QAAQ,CAAC,mBAAmB,CAAC,EAAE;SAC7D,cAAc,CAAC;IAClB,IAAI,CAAC,oBAAoB,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,CAAC;QACjE,oFAAoF;QACpF,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,+DAA+D;IAC/D,KAAK,MAAM,QAAQ,IAAI,oBAAoB,CAAC,aAAa,EAAE,CAAC;QAC1D,yEAAyE;QACzE,KAAK,MAAM,C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EAAE,CAAC,CAAC,CAAC;IACnC,CAAC;AACH,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,WAAW,GAAG,KAAK,IAAI,EAAE;IACpC,MAAM,SAAS,GAAG,aAAa,EAAE,CAAC;IAClC,MAAM,QAAQ,GAAG,cAAc,EAAE,CAAC;IAElC,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAClC,KAAK,CAAC,IAAI,CAAC,kBAAU,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CACzC,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,CACzC,CACF,CAAC;IAEF,+BAA+B;IAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAE3D,mBAAmB;IACnB,kBAAU,CAAC,KAAK,EAAE,CAAC;IACnB,0CAA0C;IAC1C,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAjBW,QAAA,WAAW,eAiBtB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const performReload: (shouldReload: any) => Promise<boolean>;
|
|
2
|
+
export declare const checkUnreachableRemote: (remoteScope: any) => boolean;
|
|
3
|
+
export declare const checkMedusaConfigChange: (remoteScope: any, fetchModule: any) => boolean;
|
|
4
|
+
export declare const checkFakeRemote: (remoteScope: any) => boolean;
|
|
5
|
+
export declare const fetchRemote: (remoteScope: any, fetchModule: any) => Promise<boolean>;
|
|
6
|
+
export declare const revalidate: (fetchModule?: any, force?: boolean) => Promise<boolean>;
|
|
7
|
+
export declare function getFetchModule(): any;
|