@module-federation/nextjs-mf 5.4.1 → 5.5.1

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.
@@ -0,0 +1,94 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var LoadFileChunkLoadingRuntimeModule = require('./LoadFileChunkLoadingRuntimeModule.js');
6
+
7
+ const RuntimeGlobals = require('webpack/lib/RuntimeGlobals');
8
+ const StartupChunkDependenciesPlugin = require('webpack/lib/runtime/StartupChunkDependenciesPlugin');
9
+ // const ChunkLoadingRuntimeModule = require('webpack/lib/node/ReadFileChunkLoadingRuntimeModule')
10
+ class CommonJsChunkLoadingPlugin {
11
+ constructor(options) {
12
+ this.options = options || {};
13
+ this._asyncChunkLoading = this.options.asyncChunkLoading;
14
+ }
15
+
16
+ /**
17
+ * Apply the plugin
18
+ * @param {Compiler} compiler the compiler instance
19
+ * @returns {void}
20
+ */
21
+ apply(compiler) {
22
+ const chunkLoadingValue = this._asyncChunkLoading
23
+ ? 'async-node'
24
+ : 'require';
25
+ new StartupChunkDependenciesPlugin({
26
+ chunkLoading: chunkLoadingValue,
27
+ asyncChunkLoading: this._asyncChunkLoading,
28
+ }).apply(compiler);
29
+ compiler.hooks.thisCompilation.tap(
30
+ 'CommonJsChunkLoadingPlugin',
31
+ (compilation) => {
32
+ // Always enabled
33
+ const isEnabledForChunk = () => true;
34
+ const onceForChunkSet = new WeakSet();
35
+ const handler = (chunk, set) => {
36
+ if (onceForChunkSet.has(chunk)) return;
37
+ onceForChunkSet.add(chunk);
38
+ if (!isEnabledForChunk(chunk)) return;
39
+ set.add(RuntimeGlobals.moduleFactoriesAddOnly);
40
+ set.add(RuntimeGlobals.hasOwnProperty);
41
+ compilation.addRuntimeModule(
42
+ chunk,
43
+ new LoadFileChunkLoadingRuntimeModule["default"](set, this.options, {
44
+ webpack: compiler.webpack,
45
+ })
46
+ );
47
+ };
48
+
49
+ compilation.hooks.runtimeRequirementInTree
50
+ .for(RuntimeGlobals.ensureChunkHandlers)
51
+ .tap('CommonJsChunkLoadingPlugin', handler);
52
+ compilation.hooks.runtimeRequirementInTree
53
+ .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
54
+ .tap('CommonJsChunkLoadingPlugin', handler);
55
+ compilation.hooks.runtimeRequirementInTree
56
+ .for(RuntimeGlobals.hmrDownloadManifest)
57
+ .tap('CommonJsChunkLoadingPlugin', handler);
58
+ compilation.hooks.runtimeRequirementInTree
59
+ .for(RuntimeGlobals.baseURI)
60
+ .tap('CommonJsChunkLoadingPlugin', handler);
61
+ compilation.hooks.runtimeRequirementInTree
62
+ .for(RuntimeGlobals.externalInstallChunk)
63
+ .tap('CommonJsChunkLoadingPlugin', handler);
64
+ compilation.hooks.runtimeRequirementInTree
65
+ .for(RuntimeGlobals.onChunksLoaded)
66
+ .tap('CommonJsChunkLoadingPlugin', handler);
67
+
68
+ compilation.hooks.runtimeRequirementInTree
69
+ .for(RuntimeGlobals.ensureChunkHandlers)
70
+ .tap('CommonJsChunkLoadingPlugin', (chunk, set) => {
71
+ if (!isEnabledForChunk(chunk)) return;
72
+ set.add(RuntimeGlobals.getChunkScriptFilename);
73
+ });
74
+ compilation.hooks.runtimeRequirementInTree
75
+ .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
76
+ .tap('CommonJsChunkLoadingPlugin', (chunk, set) => {
77
+ if (!isEnabledForChunk(chunk)) return;
78
+ set.add(RuntimeGlobals.getChunkUpdateScriptFilename);
79
+ set.add(RuntimeGlobals.moduleCache);
80
+ set.add(RuntimeGlobals.hmrModuleData);
81
+ set.add(RuntimeGlobals.moduleFactoriesAddOnly);
82
+ });
83
+ compilation.hooks.runtimeRequirementInTree
84
+ .for(RuntimeGlobals.hmrDownloadManifest)
85
+ .tap('CommonJsChunkLoadingPlugin', (chunk, set) => {
86
+ if (!isEnabledForChunk(chunk)) return;
87
+ set.add(RuntimeGlobals.getUpdateManifestFilename);
88
+ });
89
+ }
90
+ );
91
+ }
92
+ }
93
+
94
+ exports["default"] = CommonJsChunkLoadingPlugin;
@@ -0,0 +1,414 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var loadScript = require('./loadScript.js');
6
+
7
+ /*
8
+ MIT License http://www.opensource.org/licenses/mit-license.php
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ const RuntimeGlobals = require('webpack/lib/RuntimeGlobals');
14
+ const RuntimeModule = require('webpack/lib/RuntimeModule');
15
+ const Template = require('webpack/lib/Template');
16
+ const compileBooleanMatcher = require('webpack/lib/util/compileBooleanMatcher');
17
+ const { getUndoPath } = require('webpack/lib/util/identifier');
18
+
19
+ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
20
+ constructor(runtimeRequirements, options, context) {
21
+ super('readFile chunk loading', RuntimeModule.STAGE_ATTACH);
22
+ this.runtimeRequirements = runtimeRequirements;
23
+ this.options = options;
24
+ this.context = context;
25
+ }
26
+
27
+ /**
28
+ * @private
29
+ * @param {Chunk} chunk chunk
30
+ * @param {string} rootOutputDir root output directory
31
+ * @returns {string} generated code
32
+ */
33
+ _generateBaseUri(chunk, rootOutputDir) {
34
+ const options = chunk.getEntryOptions();
35
+ if (options && options.baseUri) {
36
+ return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
37
+ }
38
+
39
+ return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
40
+ rootOutputDir
41
+ ? `__dirname + ${JSON.stringify('/' + rootOutputDir)}`
42
+ : '__filename'
43
+ });`;
44
+ }
45
+
46
+ /**
47
+ * @returns {string} runtime code
48
+ */
49
+ generate() {
50
+ // name in this context is always the current remote itself.
51
+ // this code below is in each webpack runtime, host and remotes
52
+ // remote entries handle their own loading of chunks, so i have fractal self awareness
53
+ // hosts will likely never run the http chunk loading runtime, they use fs.readFile
54
+ // remotes only use fs.readFile if we were to cache the chunks on disk after fetching - otherwise its always using http
55
+ // so for example, if im in hostA and require(remoteb/module) --> console.log of name in runtime code will return remoteb
56
+
57
+ const { baseURI, promiseBaseURI, remotes, name } = this.options;
58
+ const { webpack } = this.context;
59
+ const chunkHasJs =
60
+ (webpack && webpack.javascript.JavascriptModulesPlugin.chunkHasJs) ||
61
+ require('webpack/lib/javascript/JavascriptModulesPlugin').chunkHasJs;
62
+
63
+ // workaround for next.js
64
+ const getInitialChunkIds = (chunk, chunkGraph) => {
65
+ const initialChunkIds = new Set(chunk.ids);
66
+ for (const c of chunk.getAllInitialChunks()) {
67
+ if (c === chunk || chunkHasJs(c, chunkGraph)) continue;
68
+ for (const id of c.ids) initialChunkIds.add(id);
69
+ }
70
+ return initialChunkIds;
71
+ };
72
+
73
+ const { chunkGraph, chunk } = this;
74
+ const { runtimeTemplate } = this.compilation;
75
+ const fn = RuntimeGlobals.ensureChunkHandlers;
76
+ const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI);
77
+ const withExternalInstallChunk = this.runtimeRequirements.has(
78
+ RuntimeGlobals.externalInstallChunk
79
+ );
80
+ const withOnChunkLoad = this.runtimeRequirements.has(
81
+ RuntimeGlobals.onChunksLoaded
82
+ );
83
+ const withLoading = this.runtimeRequirements.has(
84
+ RuntimeGlobals.ensureChunkHandlers
85
+ );
86
+ const withHmr = this.runtimeRequirements.has(
87
+ RuntimeGlobals.hmrDownloadUpdateHandlers
88
+ );
89
+ const withHmrManifest = this.runtimeRequirements.has(
90
+ RuntimeGlobals.hmrDownloadManifest
91
+ );
92
+
93
+ const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
94
+ const hasJsMatcher = compileBooleanMatcher(conditionMap);
95
+ const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
96
+
97
+ const outputName = this.compilation.getPath(
98
+ (
99
+ (webpack &&
100
+ webpack.javascript.JavascriptModulesPlugin
101
+ .getChunkFilenameTemplate) ||
102
+ require('webpack/lib/javascript/JavascriptModulesPlugin')
103
+ .getChunkFilenameTemplate
104
+ )(chunk, this.compilation.outputOptions),
105
+ {
106
+ chunk,
107
+ contentHashType: 'javascript',
108
+ }
109
+ );
110
+ const rootOutputDir = getUndoPath(
111
+ outputName,
112
+ this.compilation.outputOptions.path,
113
+ false
114
+ );
115
+
116
+ const stateExpression = withHmr
117
+ ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_readFileVm`
118
+ : undefined;
119
+
120
+ return Template.asString([
121
+ withBaseURI
122
+ ? this._generateBaseUri(chunk, rootOutputDir)
123
+ : '// no baseURI',
124
+ '',
125
+ '// object to store loaded chunks',
126
+ '// "0" means "already loaded", Promise means loading',
127
+ `var installedChunks = ${
128
+ stateExpression ? `${stateExpression} = ${stateExpression} || ` : ''
129
+ }{`,
130
+ Template.indent(
131
+ Array.from(initialChunkIds, (id) => `${JSON.stringify(id)}: 0`).join(
132
+ ',\n'
133
+ )
134
+ ),
135
+ '};',
136
+ '',
137
+ withOnChunkLoad
138
+ ? `${
139
+ RuntimeGlobals.onChunksLoaded
140
+ }.readFileVm = ${runtimeTemplate.returningFunction(
141
+ 'installedChunks[chunkId] === 0',
142
+ 'chunkId'
143
+ )};`
144
+ : '// no on chunks loaded',
145
+ '',
146
+ withLoading || withExternalInstallChunk
147
+ ? `var installChunk = ${runtimeTemplate.basicFunction('chunk', [
148
+ 'var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;',
149
+ 'for(var moduleId in moreModules) {',
150
+ Template.indent([
151
+ `if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
152
+ Template.indent([
153
+ `${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`,
154
+ ]),
155
+ '}',
156
+ ]),
157
+ '}',
158
+ `if(runtime) runtime(__webpack_require__);`,
159
+ 'for(var i = 0; i < chunkIds.length; i++) {',
160
+ Template.indent([
161
+ 'if(installedChunks[chunkIds[i]]) {',
162
+ Template.indent(['installedChunks[chunkIds[i]][0]();']),
163
+ '}',
164
+ 'installedChunks[chunkIds[i]] = 0;',
165
+ ]),
166
+ '}',
167
+ withOnChunkLoad ? `${RuntimeGlobals.onChunksLoaded}();` : '',
168
+ ])};`
169
+ : '// no chunk install function needed',
170
+ '',
171
+ withLoading
172
+ ? Template.asString([
173
+ '// ReadFile + VM.run chunk loading for javascript',
174
+ `${fn}.readFileVm = function(chunkId, promises) {`,
175
+ hasJsMatcher !== false
176
+ ? Template.indent([
177
+ '',
178
+ 'var installedChunkData = installedChunks[chunkId];',
179
+ 'if(installedChunkData !== 0) { // 0 means "already installed".',
180
+ Template.indent([
181
+ '// array of [resolve, reject, promise] means "currently loading"',
182
+ 'if(installedChunkData) {',
183
+ Template.indent(['promises.push(installedChunkData[2]);']),
184
+ '} else {',
185
+ Template.indent([
186
+ hasJsMatcher === true
187
+ ? 'if(true) { // all chunks have JS'
188
+ : `if(${hasJsMatcher('chunkId')}) {`,
189
+ Template.indent([
190
+ '// load the chunk and return promise to it',
191
+ 'var promise = new Promise(async function(resolve, reject) {',
192
+ Template.indent([
193
+ 'installedChunkData = installedChunks[chunkId] = [resolve, reject];',
194
+ `var filename = require('path').join(__dirname, ${JSON.stringify(
195
+ rootOutputDir
196
+ )} + ${
197
+ RuntimeGlobals.getChunkScriptFilename
198
+ }(chunkId));`,
199
+ "var fs = require('fs');",
200
+ 'if(fs.existsSync(filename)) {',
201
+ Template.indent([
202
+ "fs.readFile(filename, 'utf-8', function(err, content) {",
203
+ Template.indent([
204
+ 'if(err) return reject(err);',
205
+ 'var chunk = {};',
206
+ "require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)" +
207
+ "(chunk, require, require('path').dirname(filename), filename);",
208
+ 'installChunk(chunk);',
209
+ ]),
210
+ '});',
211
+ ]),
212
+ '} else {',
213
+ Template.indent([
214
+ loadScript["default"],
215
+
216
+ `console.log('needs to load remote module from', ${JSON.stringify(
217
+ name
218
+ )});`,
219
+ `console.log('remotes known to', ${JSON.stringify(
220
+ name
221
+ )}, ${JSON.stringify(remotes)})`,
222
+ // keys are mostly useless here, we want to find remote by its global (unique name)
223
+ `var remotes = ${JSON.stringify(
224
+ Object.values(remotes).reduce((acc, remote) => {
225
+ //TODO: need to handle all other cases like when remote is not a @ syntax string
226
+ const [global, url] = remote.split('@');
227
+ acc[global] = url;
228
+ return acc;
229
+ }, {})
230
+ )};`,
231
+ "Object.assign(global.__remote_scope__._config, remotes)",
232
+ "const remoteRegistry = global.__remote_scope__._config",
233
+ /* TODO: keying by global should be ok, but need to verify - need to deal with when user passes promise new promise()
234
+ global will/should still exist - but can only be known at runtime */
235
+ `console.log('remotes keyed by global name',remotes)`,
236
+ `console.log('remote scope configs',global.__remote_scope__._config)`,
237
+
238
+ `console.log('global.__remote_scope__',global.__remote_scope__)`,
239
+ `console.log('global.__remote_scope__[${JSON.stringify(
240
+ name
241
+ )}]',global.__remote_scope__[${JSON.stringify(
242
+ name
243
+ )}])`,
244
+
245
+ /* TODO: this global.REMOTE_CONFIG doesnt work in this v5 core, not sure if i need to keep it or not
246
+ not deleting it yet since i might need this for tracking all the remote entries across systems
247
+ for now, im going to use locally known remote scope from remoteEntry config
248
+ update: We will most likely need this, since remote would not have its own config
249
+ id need to access the host system and find the known url
250
+ basically this is how i create publicPath: auto on servers.
251
+ `var requestedRemote = global.REMOTE_CONFIG[${JSON.stringify(
252
+ name
253
+ )}]`,
254
+ */
255
+ "console.log('about to derive remote making request')",
256
+ `var requestedRemote = remoteRegistry[${JSON.stringify(
257
+ name
258
+ )}]`,
259
+ "console.log('requested remote', requestedRemote)",
260
+ /*TODO: we need to support when user implements own promise new promise function
261
+ for example i have my own promise remotes, not global@remotename
262
+ so there could be cases where remote may be function still - not sure */
263
+
264
+ /*TODO: need to handle if chunk fetch fails/crashes - ensure server still can keep loading
265
+ right now if you throw an error in here, server will stall forever */
266
+
267
+ `if(typeof requestedRemote === 'function'){
268
+ requestedRemote = await requestedRemote()
269
+ }`,
270
+ `console.log('var requestedRemote',requestedRemote);`,
271
+
272
+ // example: uncomment this and server will never reply
273
+ // `var scriptUrl = new URL(requestedRemote.split("@")[1]);`,
274
+ // since im looping over remote and creating global at build time, i dont need to split string at runtime
275
+ // there may still be a use case for that with promise new promise, depending on how we design it.
276
+ `var scriptUrl = new URL(requestedRemote);`,
277
+
278
+ `var chunkName = ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
279
+
280
+ `console.log('chunkname to request',chunkName);`,
281
+ `var fileToReplace = require('path').basename(scriptUrl.pathname);`,
282
+ `scriptUrl.pathname = scriptUrl.pathname.replace(fileToReplace, chunkName);`,
283
+ `console.log('will load remote chunk', scriptUrl.toString());`,
284
+ `loadScript(scriptUrl.toString(), function(err, content) {`,
285
+ Template.indent([
286
+ "console.log('load script callback fired')",
287
+ "if(err) {console.error('error loading remote chunk', scriptUrl.toString(),'got',content); return reject(err);}",
288
+ 'var chunk = {};',
289
+ 'try {',
290
+ "require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)" +
291
+ "(chunk, require, require('path').dirname(filename), filename);",
292
+ '} catch (e) {',
293
+ "console.log('runInThisContext thew', e)",
294
+ '}',
295
+ 'installChunk(chunk);',
296
+ ]),
297
+ '});',
298
+ ]),
299
+ '}',
300
+ ]),
301
+ '});',
302
+ 'promises.push(installedChunkData[2] = promise);',
303
+ ]),
304
+ '} else installedChunks[chunkId] = 0;',
305
+ ]),
306
+ '}',
307
+ ]),
308
+ '}',
309
+ ])
310
+ : Template.indent(['installedChunks[chunkId] = 0;']),
311
+ '};',
312
+ ])
313
+ : '// no chunk loading',
314
+ '',
315
+ withExternalInstallChunk
316
+ ? Template.asString([
317
+ 'module.exports = __webpack_require__;',
318
+ `${RuntimeGlobals.externalInstallChunk} = installChunk;`,
319
+ ])
320
+ : '// no external install chunk',
321
+ '',
322
+ withHmr
323
+ ? Template.asString([
324
+ 'function loadUpdateChunk(chunkId, updatedModulesList) {',
325
+ Template.indent([
326
+ 'return new Promise(function(resolve, reject) {',
327
+ Template.indent([
328
+ `var filename = require('path').join(__dirname, ${JSON.stringify(
329
+ rootOutputDir
330
+ )} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`,
331
+ "require('fs').readFile(filename, 'utf-8', function(err, content) {",
332
+ Template.indent([
333
+ 'if(err) return reject(err);',
334
+ 'var update = {};',
335
+ "require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)" +
336
+ "(update, require, require('path').dirname(filename), filename);",
337
+ 'var updatedModules = update.modules;',
338
+ 'var runtime = update.runtime;',
339
+ 'for(var moduleId in updatedModules) {',
340
+ Template.indent([
341
+ `if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,
342
+ Template.indent([
343
+ `currentUpdate[moduleId] = updatedModules[moduleId];`,
344
+ 'if(updatedModulesList) updatedModulesList.push(moduleId);',
345
+ ]),
346
+ '}',
347
+ ]),
348
+ '}',
349
+ 'if(runtime) currentUpdateRuntime.push(runtime);',
350
+ 'resolve();',
351
+ ]),
352
+ '});',
353
+ ]),
354
+ '});',
355
+ ]),
356
+ '}',
357
+ '',
358
+ Template.getFunctionContent(
359
+ require('../hmr/JavascriptHotModuleReplacement.runtime.js')
360
+ )
361
+ .replace(/\$key\$/g, 'readFileVm')
362
+ .replace(/\$installedChunks\$/g, 'installedChunks')
363
+ .replace(/\$loadUpdateChunk\$/g, 'loadUpdateChunk')
364
+ .replace(/\$moduleCache\$/g, RuntimeGlobals.moduleCache)
365
+ .replace(/\$moduleFactories\$/g, RuntimeGlobals.moduleFactories)
366
+ .replace(
367
+ /\$ensureChunkHandlers\$/g,
368
+ RuntimeGlobals.ensureChunkHandlers
369
+ )
370
+ .replace(/\$hasOwnProperty\$/g, RuntimeGlobals.hasOwnProperty)
371
+ .replace(/\$hmrModuleData\$/g, RuntimeGlobals.hmrModuleData)
372
+ .replace(
373
+ /\$hmrDownloadUpdateHandlers\$/g,
374
+ RuntimeGlobals.hmrDownloadUpdateHandlers
375
+ )
376
+ .replace(
377
+ /\$hmrInvalidateModuleHandlers\$/g,
378
+ RuntimeGlobals.hmrInvalidateModuleHandlers
379
+ ),
380
+ ])
381
+ : '// no HMR',
382
+ '',
383
+ withHmrManifest
384
+ ? Template.asString([
385
+ `${RuntimeGlobals.hmrDownloadManifest} = function() {`,
386
+ Template.indent([
387
+ 'return new Promise(function(resolve, reject) {',
388
+ Template.indent([
389
+ `var filename = require('path').join(__dirname, ${JSON.stringify(
390
+ rootOutputDir
391
+ )} + ${RuntimeGlobals.getUpdateManifestFilename}());`,
392
+ "require('fs').readFile(filename, 'utf-8', function(err, content) {",
393
+ Template.indent([
394
+ 'if(err) {',
395
+ Template.indent([
396
+ 'if(err.code === "ENOENT") return resolve();',
397
+ 'return reject(err);',
398
+ ]),
399
+ '}',
400
+ 'try { resolve(JSON.parse(content)); }',
401
+ 'catch(e) { reject(e); }',
402
+ ]),
403
+ '});',
404
+ ]),
405
+ '});',
406
+ ]),
407
+ '}',
408
+ ])
409
+ : '// no HMR manifest',
410
+ ]);
411
+ }
412
+ }
413
+
414
+ exports["default"] = ReadFileChunkLoadingRuntimeModule;
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var CommonJsChunkLoadingPlugin = require('./CommonJsChunkLoadingPlugin.js');
6
+
7
+ class NodeSoftwareStreamRuntime {
8
+ constructor(options, context) {
9
+ this.options = options || {};
10
+ this.context = context || {};
11
+ }
12
+
13
+ apply(compiler) {
14
+ if (compiler.options.target) {
15
+ console.warn(
16
+ `target should be set to false while using NodeSoftwareStreamRuntime plugin, actual target: ${compiler.options.target}`
17
+ );
18
+ }
19
+
20
+ // When used with Next.js, context is needed to use Next.js webpack
21
+ const { webpack } = compiler;
22
+
23
+ // This will enable CommonJsChunkFormatPlugin
24
+ compiler.options.output.chunkFormat = 'commonjs';
25
+ // This will force async chunk loading
26
+ compiler.options.output.chunkLoading = 'async-node';
27
+ // Disable default config
28
+ compiler.options.output.enabledChunkLoadingTypes = false;
29
+
30
+ new ((webpack && webpack.node && webpack.node.NodeEnvironmentPlugin) ||
31
+ require('webpack/lib/node/NodeEnvironmentPlugin'))({
32
+ infrastructureLogging: compiler.options.infrastructureLogging,
33
+ }).apply(compiler);
34
+ new ((webpack && webpack.node && webpack.node.NodeTargetPlugin) ||
35
+ require('webpack/lib/node/NodeTargetPlugin'))().apply(compiler);
36
+ new CommonJsChunkLoadingPlugin["default"]({
37
+ asyncChunkLoading: true,
38
+ name: this.options.name,
39
+ remotes: this.options.remotes,
40
+ baseURI: compiler.options.output.publicPath,
41
+ promiseBaseURI: this.options.promiseBaseURI,
42
+ }).apply(compiler);
43
+ }
44
+ }
45
+
46
+ exports["default"] = NodeSoftwareStreamRuntime;
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('../../_virtual/_commonjsHelpers.js');
6
+
7
+ /**
8
+ * loadScript(baseURI, fileName, cb)
9
+ * loadScript(scriptUrl, cb)
10
+ */
11
+
12
+ var loadScript = `
13
+ function loadScript(url,cb,chunkID) {
14
+ var url;
15
+ var cb = arguments[arguments.length - 1];
16
+ if (typeof cb !== "function") {
17
+ throw new Error("last argument should be a function");
18
+ }
19
+ if (arguments.length === 2) {
20
+ url = arguments[0];
21
+ } else if (arguments.length === 3) {
22
+ url = new URL(arguments[1], arguments[0]).toString();
23
+ } else {
24
+ throw new Error("invalid number of arguments");
25
+ }
26
+ if(global.webpackChunkLoad){
27
+ global.webpackChunkLoad(url).then(function(resp){
28
+ return resp.text();
29
+ }).then(function(rawData){
30
+ cb(null, rawData);
31
+ }).catch(function(err){
32
+ console.error('Federated Chunk load failed', error);
33
+ return cb(error)
34
+ });
35
+ } else {
36
+ //TODO https support
37
+ let request = (url.startsWith('https') ? require('https') : require('http')).get(url, function (resp) {
38
+ if (resp.statusCode === 200) {
39
+ let rawData = '';
40
+ resp.setEncoding('utf8');
41
+ resp.on('data', chunk => {
42
+ rawData += chunk;
43
+ });
44
+ resp.on('end', () => {
45
+ cb(null, rawData);
46
+ });
47
+ } else {
48
+ cb(resp);
49
+ }
50
+ });
51
+ request.on('error', error => {
52
+ console.error('Federated Chunk load failed', error);
53
+ return cb(error)
54
+ });
55
+ }
56
+ }
57
+ `;
58
+
59
+ exports["default"] = loadScript;
package/lib/utils.js CHANGED
@@ -13,8 +13,6 @@ const extractUrlAndGlobal = (urlAndGlobal) => {
13
13
 
14
14
  const remoteVars = process.env.REMOTES || {};
15
15
 
16
- console.log(remoteVars);
17
-
18
16
  const runtimeRemotes = Object.entries(remoteVars).reduce(function (acc, item) {
19
17
  const [key, value] = item;
20
18
  if (typeof value === 'object' && typeof value.then === 'function') {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "@module-federation/nextjs-mf",
4
- "version": "5.4.1",
4
+ "version": "5.5.1",
5
5
  "description": "Module Federation helper for NextJS",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",