@module-federation/node 0.6.7 → 0.7.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 CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ # [0.7.0](https://github.com/module-federation/nextjs-mf/compare/node-0.6.7...node-0.7.0) (2022-10-19)
6
+
7
+
8
+ ### Features
9
+
10
+ * consolidate promise factories in server ([#297](https://github.com/module-federation/nextjs-mf/issues/297)) ([55387ee](https://github.com/module-federation/nextjs-mf/commit/55387eeb952fb3164900d73ddcb0007f644c766f))
11
+
12
+
13
+
5
14
  ## [0.6.7](https://github.com/module-federation/nextjs-mf/compare/node-0.6.6...node-0.6.7) (2022-10-18)
6
15
 
7
16
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "@module-federation/node",
4
- "version": "0.6.7",
4
+ "version": "0.7.0",
5
5
  "type": "commonjs",
6
6
  "main": "src/index.js",
7
7
  "exports": {
@@ -6,6 +6,9 @@ interface NodeFederationOptions extends ModuleFederationPluginOptions {
6
6
  interface Context {
7
7
  ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
8
8
  }
9
+ export declare const parseRemotes: (remotes: Record<string, any>) => Record<string, string>;
10
+ export declare const generateRemoteTemplate: (url: string, global: any) => string;
11
+ export declare const parseRemoteSyntax: (remote: any) => any;
9
12
  declare class NodeFederationPlugin {
10
13
  private options;
11
14
  private context;
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseRemoteSyntax = exports.generateRemoteTemplate = exports.parseRemotes = void 0;
4
+ const utilities_1 = require("@module-federation/utilities");
3
5
  // possible remote evaluators
4
6
  // this depends on the chunk format selected.
5
7
  // commonjs2 - it think, is lazily evaluated - beware
@@ -81,19 +83,21 @@ const executeLoadTemplate = `
81
83
  })
82
84
  }
83
85
  `;
84
- function buildRemotes(mfConf, webpack) {
85
- return Object.entries(mfConf.remotes || {}).reduce((acc, [name, config]) => {
86
- // if its already been converted into promise, dont do it again
87
- if (config.startsWith('promise ') || config.startsWith('external ')) {
88
- acc.buildTime[name] = config;
86
+ const parseRemotes = (remotes) => {
87
+ return Object.entries(remotes).reduce((acc, remote) => {
88
+ if (!remote[1].startsWith('promise ') && remote[1].includes('@')) {
89
+ acc[remote[0]] = 'promise ' + (0, exports.parseRemoteSyntax)(remote[1]);
89
90
  return acc;
90
91
  }
91
- /*
92
- TODO: global remote scope object should go into webpack runtime as a runtime requirement
93
- this can be done by referencing my LoadFile, CommonJs plugins in this directory.
94
- */
95
- const [global, url] = config.split('@');
96
- const loadTemplate = `promise new Promise((resolve, reject)=>{
92
+ acc[remote[0]] = remote[1];
93
+ return acc;
94
+ }, {});
95
+ };
96
+ exports.parseRemotes = parseRemotes;
97
+ // server template to convert remote into promise new promise and use require.loadChunk to load the chunk
98
+ const generateRemoteTemplate = (url, global) => {
99
+ //language=JS
100
+ return `new Promise(function (resolve, reject) {
97
101
  if(!global.__remote_scope__) {
98
102
  // create a global scope for container, similar to how remotes are set on window in the browser
99
103
  global.__remote_scope__ = {
@@ -101,83 +105,104 @@ function buildRemotes(mfConf, webpack) {
101
105
  }
102
106
  }
103
107
 
108
+ if (typeof global.__remote_scope__[${JSON.stringify(global)}] !== 'undefined') return resolve(global.__remote_scope__[${JSON.stringify(global)}]);
104
109
  global.__remote_scope__._config[${JSON.stringify(global)}] = ${JSON.stringify(url)};
110
+ var __webpack_error__ = new Error();
105
111
 
106
- var __webpack_error__ = new Error();
107
- if (typeof global.__remote_scope__[${JSON.stringify(global)}] !== 'undefined') return resolve(global.__remote_scope__[${JSON.stringify(global)}]);
108
112
  __webpack_require__.l(
109
113
  ${JSON.stringify(url)},
110
114
  function (event) {
111
115
  if (typeof global.__remote_scope__[${JSON.stringify(global)}] !== 'undefined') return resolve(global.__remote_scope__[${JSON.stringify(global)}]);
112
- var realSrc = event && event.target && event.target.src;
113
- __webpack_error__.message =
114
- 'Loading script failed.\\n(' + event.message + ': ' + realSrc + ')';
116
+ var realSrc = event && event.target && event.target.src;
117
+ __webpack_error__.message = 'Loading script failed.\\n(' + event.message + ': ' + realSrc + ')';
115
118
  __webpack_error__.name = 'ScriptExternalLoadError';
116
119
  __webpack_error__.stack = event.stack;
117
120
  reject(__webpack_error__);
118
121
  },
119
122
  ${JSON.stringify(global)},
120
123
  );
121
- }).catch(()=>{
122
- console.warn(${JSON.stringify(global)},'is offline, returning fake remote')
123
-
124
- return {
125
- fake: true,
126
- get:(arg)=>{
127
- console.log('faking', arg,'module on', ${JSON.stringify(global)});
124
+ }).catch((e)=> {
125
+ console.error(${JSON.stringify(global)}, 'is offline, returning fake remote');
126
+ console.error(e);
128
127
 
129
- return Promise.resolve(()=>{
130
- return ()=>null
131
- });
132
- },
133
- init:()=>{}
134
- }
128
+ return {
129
+ fake: true,
130
+ get: (arg) => {
131
+ console.log('faking', arg, 'module on', ${JSON.stringify(global)});
135
132
 
136
- }).then(remote=>{
137
- if(remote.fake) {
138
- return remote;
133
+ return Promise.resolve(() => {
134
+ return () => null
135
+ });
136
+ },
137
+ init: () => {
139
138
  }
140
-
141
-
142
- const proxy = {
139
+ }
140
+ }).then(function (remote) {
141
+ if(remote.fake) {
142
+ return remote;
143
+ }
144
+ const proxy = {
143
145
  get: (arg)=>{
144
- if(!global.__remote_scope__[${JSON.stringify(global)}].__initialized) {
145
- try {
146
- global.__remote_scope__[${JSON.stringify(global)}].__initialized = true;
147
- proxy.init(__webpack_require__.S.default);
148
- } catch(e) {}
149
- }
146
+ // if(!global.__remote_scope__[${JSON.stringify(global)}].__initialized) {
147
+ // try {
148
+ // global.__remote_scope__[${JSON.stringify(global)}].__initialized = true;
149
+ // proxy.init(__webpack_require__.S.default);
150
+ // } catch(e) {}
151
+ // }
150
152
  return remote.get(arg).then((f)=>{
151
153
  const m = f();
152
154
  return ()=>new Proxy(m, {
153
155
  get: (target, prop)=>{
154
- if(global.usedChunks) global.usedChunks.add(${JSON.stringify(global)} + "->" + arg);
156
+ if(global.usedChunks) global.usedChunks.add(${JSON.stringify(global)} + "->" + arg);
155
157
  return target[prop];
156
158
  }
157
159
  })
158
160
  })
159
161
  },
160
- init: (args)=> {
161
- if(global.__remote_scope__[${JSON.stringify(global)}].__initialized) return Promise.resolve();
162
- global.__remote_scope__[${JSON.stringify(global)}].__initialized = true;
163
- return remote.init(new Proxy(args, {
164
- set: (target, prop, value)=>{
165
- if(global.usedChunks) global.usedChunks.add(${JSON.stringify(global)} + "->" + prop);
166
- target[prop] = value;
167
- return true;
162
+ init: function(shareScope) {
163
+ const handler = {
164
+ get(target, prop) {
165
+ if (target[prop]) {
166
+ Object.values(target[prop]).forEach(function(o) {
167
+ if(o.from === '_N_E') {
168
+ o.loaded = 1
169
+ }
170
+ })
171
+ }
172
+ return target[prop]
173
+ },
174
+ set(target, property, value) {
175
+ if(global.usedChunks) global.usedChunks.add(${JSON.stringify(global)} + "->" + property);
176
+ if (target[property]) {
177
+ return target[property]
168
178
  }
169
- }))
179
+ target[property] = value
180
+ return true
181
+ }
170
182
  }
171
- }
183
+ try {
184
+ global.__remote_scope__[${JSON.stringify(global)}].init(new Proxy(shareScope, handler))
185
+ } catch (e) {
172
186
 
173
- return proxy;
174
-
175
- });
176
- `;
177
- acc.buildTime[name] = loadTemplate;
178
- return acc;
179
- }, { runtime: {}, buildTime: {}, hot: {} });
180
- }
187
+ }
188
+ global.__remote_scope__[${JSON.stringify(global)}].__initialized = true
189
+ }
190
+ }
191
+ if (!global.__remote_scope__[${JSON.stringify(global)}].__initialized) {
192
+ proxy.init(__webpack_require__.S.default)
193
+ }
194
+ return proxy
195
+ })`;
196
+ };
197
+ exports.generateRemoteTemplate = generateRemoteTemplate;
198
+ const parseRemoteSyntax = (remote) => {
199
+ if (typeof remote === 'string' && remote.includes('@')) {
200
+ const [url, global] = (0, utilities_1.extractUrlAndGlobal)(remote);
201
+ return (0, exports.generateRemoteTemplate)(url, global);
202
+ }
203
+ return remote;
204
+ };
205
+ exports.parseRemoteSyntax = parseRemoteSyntax;
181
206
  class NodeFederationPlugin {
182
207
  constructor({ experiments, ...options }, context) {
183
208
  this.options = options || {};
@@ -187,17 +212,16 @@ class NodeFederationPlugin {
187
212
  apply(compiler) {
188
213
  // When used with Next.js, context is needed to use Next.js webpack
189
214
  const { webpack } = compiler;
190
- const { buildTime, runtime, hot } = buildRemotes(this.options, webpack || require('webpack'));
191
- const defs = {
192
- 'process.env.REMOTES': runtime,
193
- 'process.env.REMOTE_CONFIG': hot,
194
- };
215
+ // const defs = {
216
+ // 'process.env.REMOTES': runtime,
217
+ // 'process.env.REMOTE_CONFIG': hot,
218
+ // };
195
219
  // new ((webpack && webpack.DefinePlugin) || require("webpack").DefinePlugin)(
196
220
  // defs
197
221
  // ).apply(compiler);
198
222
  const pluginOptions = {
199
223
  ...this.options,
200
- remotes: buildTime,
224
+ remotes: (0, exports.parseRemotes)(this.options.remotes || {}),
201
225
  };
202
226
  new (this.context.ModuleFederationPlugin ||
203
227
  (webpack && webpack.container.ModuleFederationPlugin) ||
@@ -1 +1 @@
1
- {"version":3,"file":"NodeFederationPlugin.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/NodeFederationPlugin.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAeb,6BAA6B;AAC7B,6CAA6C;AAC7C,qDAAqD;AACrD,yFAAyF;AACzF,yDAAyD;AACzD,wEAAwE;AACxE,mEAAmE;AACnE,wDAAwD;AAExD,eAAe;AACf,oFAAoF;AACpF,iHAAiH;AACjH,oGAAoG;AACpG,0FAA0F;AAC1F,qFAAqF;AACrF,uGAAuG;AACvG,wCAAwC;AACxC,uGAAuG;AACvG,uHAAuH;AACvH,+HAA+H;AAE/H,uDAAuD;AACvD,mEAAmE;AACnE,mEAAmE;AACnE,kIAAkI;AAClI,MAAM,mBAAmB,GAAG;;;;;;;;;;;;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AAa,CACd,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;CACF;AAED,kBAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"NodeFederationPlugin.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/NodeFederationPlugin.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAIb,4DAAiE;AAYjE,6BAA6B;AAC7B,6CAA6C;AAC7C,qDAAqD;AACrD,yFAAyF;AACzF,yDAAyD;AACzD,wEAAwE;AACxE,mEAAmE;AACnE,wDAAwD;AAExD,eAAe;AACf,oFAAoF;AACpF,iHAAiH;AACjH,oGAAoG;AACpG,0FAA0F;AAC1F,qFAAqF;AACrF,uGAAuG;AACvG,wCAAwC;AACxC,uGAAuG;AACvG,uHAAuH;AACvH,+HAA+H;AAE/H,uDAAuD;AACvD,mEAAmE;AACnE,mEAAmE;AACnE,kIAAkI;AAClI,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyD3B,CAAC;AAEK,MAAM,YAAY,GAAG,CAAC,OAA4B,EAAE,EAAE;IAC3D,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;QACpD,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YAChE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,GAAG,IAAA,yBAAiB,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,OAAO,GAAG,CAAC;SACZ;QACD,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC3B,OAAO,GAAG,CAAC;IACb,CAA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C,GAAG,EAAE,MAAM,CAAC,GAAG,IAAA,+BAAmB,EAAC,MAAM,CAAC,CAAC;QAClD,OAAO,IAAA,8BAAsB,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;KAC5C;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAPW,QAAA,iBAAiB,qBAO5B;AAEF,MAAM,oBAAoB;IAKxB,YACE,EAAE,WAAW,EAAE,GAAG,OAAO,EAAyB,EAClD,OAAgB;QAEhB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAK,EAAoC,CAAC;QAChE,IAAI,CAAC,OAAO,GAAG,OAAO,IAAK,EAAc,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,EAAE,CAAC;IACvC,CAAC;IAID,KAAK,CAAC,QAAkB;QACtB,mEAAmE;QACnE,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;QAE7B,iBAAiB;QACjB,oCAAoC;QACpC,sCAAsC;QACtC,KAAK;QAEL,8EAA8E;QAC9E,WAAW;QACX,qBAAqB;QAErB,MAAM,aAAa,GAAG;YACpB,GAAG,IAAI,CAAC,OAAO;YACf,OAAO,EAAE,IAAA,oBAAY,EAAC,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAA6C;SAC9F,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB;YACtC,CAAC,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC,sBAAsB,CAAC;YACrD,OAAO,CAAC,8CAA8C,CAAC,CAAC,CACxD,aAAa,CACd,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;CACF;AAED,kBAAe,oBAAoB,CAAC"}
@@ -4,4 +4,4 @@
4
4
  */
5
5
  declare const _default: "\n function loadScript(url, cb, chunkID) {\n var url;\n var cb = arguments[arguments.length - 1];\n if (typeof cb !== \"function\") {\n throw new Error(\"last argument should be a function\");\n }\n if (arguments.length === 2) {\n url = arguments[0];\n } else if (arguments.length === 3) {\n url = new URL(arguments[1], arguments[0]).toString();\n } else {\n throw new Error(\"invalid number of arguments\");\n }\n if (global.webpackChunkLoad) {\n global.webpackChunkLoad(url).then(function (resp) {\n return resp.text();\n }).then(function (rawData) {\n cb(null, rawData);\n }).catch(function (err) {\n console.error('Federated Chunk load failed', error);\n return cb(error)\n });\n } else {\n //TODO https support\n let request = (url.startsWith('https') ? require('https') : require('http')).get(url, function (resp) {\n if (resp.statusCode === 200) {\n let rawData = '';\n resp.setEncoding('utf8');\n resp.on('data', chunk => {\n rawData += chunk;\n });\n resp.on('end', () => {\n cb(null, rawData);\n });\n } else {\n cb(resp);\n }\n });\n request.on('error', error => {\n console.error('Federated Chunk load failed', error);\n return cb(error)\n });\n }\n }\n";
6
6
  export default _default;
7
- export declare const executeLoadTemplate = "\n function executeLoad(url, callback, name) {\n if(!name) {\n throw new Error('__webpack_require__.l name is required for ' + url);\n }\n console.log(\"server require.l remote load\", url);\n if (typeof global.__remote_scope__[name] !== 'undefined') return callback(global.__remote_scope__[name]);\n const vm = require('vm');\n (global.webpackChunkLoad || global.fetch || require(\"node-fetch\"))(url).then(function (res) {\n return res.text();\n }).then(function (scriptContent) {\n try {\n const vmContext = {exports, require, module, global, __filename, __dirname, URL, ...global};\n const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'});\n global.__remote_scope__[name] = remote[name] || remote;\n global.__remote_scope__[name]._config[name] = url;\n callback(global.__remote_scope__[name])\n } catch (e) {\n e.target = {src: url};\n callback(e);\n }\n }).catch((e) => {\n e.target = {src: url};\n callback(e);\n });\n }\n";
7
+ export declare const executeLoadTemplate = "\n function executeLoad(url, callback, name) {\n if(!name) {\n throw new Error('__webpack_require__.l name is required for ' + url);\n }\n if (typeof global.__remote_scope__[name] !== 'undefined') return callback(global.__remote_scope__[name]);\n const vm = require('vm');\n (global.webpackChunkLoad || global.fetch || require(\"node-fetch\"))(url).then(function (res) {\n return res.text();\n }).then(function (scriptContent) {\n try {\n const vmContext = {exports, require, module, global, __filename, __dirname, URL,console,process,Buffer, ...global};\n const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'});\n global.__remote_scope__[name] = remote[name] || remote;\n global.__remote_scope__._config[name] = url;\n callback(global.__remote_scope__[name])\n } catch (e) {\n console.error('executeLoad hit catch block');\n e.target = {src: url};\n callback(e);\n }\n }).catch((e) => {\n e.target = {src: url};\n callback(e);\n });\n }\n";
@@ -59,19 +59,19 @@ exports.executeLoadTemplate = `
59
59
  if(!name) {
60
60
  throw new Error('__webpack_require__.l name is required for ' + url);
61
61
  }
62
- console.log("server require.l remote load", url);
63
62
  if (typeof global.__remote_scope__[name] !== 'undefined') return callback(global.__remote_scope__[name]);
64
63
  const vm = require('vm');
65
64
  (global.webpackChunkLoad || global.fetch || require("node-fetch"))(url).then(function (res) {
66
65
  return res.text();
67
66
  }).then(function (scriptContent) {
68
67
  try {
69
- const vmContext = {exports, require, module, global, __filename, __dirname, URL, ...global};
68
+ const vmContext = {exports, require, module, global, __filename, __dirname, URL,console,process,Buffer, ...global};
70
69
  const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'});
71
70
  global.__remote_scope__[name] = remote[name] || remote;
72
- global.__remote_scope__[name]._config[name] = url;
71
+ global.__remote_scope__._config[name] = url;
73
72
  callback(global.__remote_scope__[name])
74
73
  } catch (e) {
74
+ console.error('executeLoad hit catch block');
75
75
  e.target = {src: url};
76
76
  callback(e);
77
77
  }