@module-federation/node 0.0.1 → 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/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  const NodeFederationPlugin = require('./src/NodeFederationPlugin');
2
2
  const StreamingTargetPlugin = require('./src/StreamingTargetPlugin');
3
+ const UniversalFederationPlugin = require('./src/UniversalFederationPlugin');
3
4
 
4
5
  module.exports.NodeFederationPlugin = NodeFederationPlugin;
5
6
  module.exports.StreamingTargetPlugin = StreamingTargetPlugin;
7
+ module.exports.UniversalFederationPlugin = UniversalFederationPlugin;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@module-federation/node",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Module Federation for Node.js",
5
5
  "main": "index.js",
6
6
  "peerDependencies": {
7
- "webpack": "5.40.0",
8
- "node-fetch": "^3.2.10"
7
+ "node-fetch": "^3.2.10",
8
+ "webpack": "5.40.0"
9
9
  }
10
10
  }
@@ -352,7 +352,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
352
352
  '}',
353
353
  '',
354
354
  Template.getFunctionContent(
355
- require('../hmr/JavascriptHotModuleReplacement.runtime.js')
355
+ require('webpack/lib/hmr/JavascriptHotModuleReplacement.runtime.js')
356
356
  )
357
357
  .replace(/\$key\$/g, 'readFileVm')
358
358
  .replace(/\$installedChunks\$/g, 'installedChunks')
@@ -20,15 +20,14 @@
20
20
  // VMT is like Realms but better - easiest analogy would be like forking the main thread, without going off main thread
21
21
  // VMT allows for scope isolation, but still allows reflection and non-primitive memory pointers to be shared - perfect for MFP
22
22
 
23
- //TODO: should use extractUrlAndGlobal from internal.js
24
23
  //TODO: should use Template system like LoadFileChunk runtime does.
25
24
  //TODO: should use vm.runInThisContext instead of eval
26
25
  //TODO: global.webpackChunkLoad could use a better convention? I have to use a special http client to get out of my infra firewall
27
26
  const executeLoadTemplate = `
28
27
  function executeLoad(remoteUrl) {
29
28
  console.log('remoteUrl',remoteUrl)
30
- const scriptUrl = remoteUrl.split("@")[1];
31
- const moduleName = remoteUrl.split("@")[0];
29
+ const extractUrlAndGlobal = require('webpack/lib/util/extractUrlAndGlobal');
30
+ const [scriptUrl, moduleName] = extractUrlAndGlobal(remoteUrl);
32
31
  console.log("executing remote load", scriptUrl);
33
32
  return new Promise(function (resolve, reject) {
34
33
 
@@ -0,0 +1,28 @@
1
+ const NodeFederationPlugin = require("./NodeFederationPlugin");
2
+ const StreamingTargetPlugin = require("./StreamingTargetPlugin");
3
+
4
+ class UniversalFederationPlugin {
5
+
6
+ constructor({experiments, ...options}, context) {
7
+ this.options = options || {};
8
+ this.context = context || {};
9
+ this.experiments = experiments || {};
10
+ }
11
+
12
+ apply(compiler) {
13
+ const isServer = this.options.isServer || compiler.options.name === 'server';
14
+ const {webpack} = compiler;
15
+
16
+ if(isServer) {
17
+ new NodeFederationPlugin({experiments: this.experiments, ...this.options}).apply(compiler);
18
+ new StreamingTargetPlugin(this.options).apply(compiler);
19
+ } else {
20
+ new (this.context.ModuleFederationPlugin || (webpack && webpack.container.ModuleFederationPlugin) ||
21
+ require('webpack/lib/container/ModuleFederationPlugin'))(
22
+ this.options
23
+ ).apply(compiler);
24
+ }
25
+ }
26
+ }
27
+
28
+ module.exports = UniversalFederationPlugin;