@module-federation/webpack-bundler-runtime 0.6.6 → 0.6.8

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/index.cjs.js CHANGED
@@ -3,9 +3,9 @@
3
3
  var runtime = require('@module-federation/runtime');
4
4
  var constant = require('./constant.cjs.js');
5
5
  var sdk = require('@module-federation/sdk');
6
+ var polyfills = require('./polyfills.cjs.js');
6
7
 
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
8
+ function _interopNamespaceDefault(e) {
9
9
  var n = Object.create(null);
10
10
  if (e) {
11
11
  Object.keys(e).forEach(function (k) {
@@ -18,11 +18,11 @@ function _interopNamespace(e) {
18
18
  }
19
19
  });
20
20
  }
21
- n["default"] = e;
21
+ n.default = e;
22
22
  return Object.freeze(n);
23
23
  }
24
24
 
25
- var runtime__namespace = /*#__PURE__*/_interopNamespace(runtime);
25
+ var runtime__namespace = /*#__PURE__*/_interopNamespaceDefault(runtime);
26
26
 
27
27
  function attachShareScopeMap(webpackRequire) {
28
28
  if (!webpackRequire.S || webpackRequire.federation.hasAttachShareScopeMap || !webpackRequire.federation.instance || !webpackRequire.federation.instance.shareScopeMap) {
@@ -33,16 +33,16 @@ function attachShareScopeMap(webpackRequire) {
33
33
  }
34
34
 
35
35
  function remotes(options) {
36
- var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire, idToRemoteMap = options.idToRemoteMap;
36
+ const { chunkId, promises, chunkMapping, idToExternalAndNameMapping, webpackRequire, idToRemoteMap } = options;
37
37
  attachShareScopeMap(webpackRequire);
38
38
  if (webpackRequire.o(chunkMapping, chunkId)) {
39
- chunkMapping[chunkId].forEach(function(id) {
40
- var getScope = webpackRequire.R;
39
+ chunkMapping[chunkId].forEach((id)=>{
40
+ let getScope = webpackRequire.R;
41
41
  if (!getScope) {
42
42
  getScope = [];
43
43
  }
44
- var data = idToExternalAndNameMapping[id];
45
- var remoteInfos = idToRemoteMap[id];
44
+ const data = idToExternalAndNameMapping[id];
45
+ const remoteInfos = idToRemoteMap[id];
46
46
  // @ts-ignore seems not work
47
47
  if (getScope.indexOf(data) >= 0) {
48
48
  return;
@@ -52,25 +52,23 @@ function remotes(options) {
52
52
  if (data.p) {
53
53
  return promises.push(data.p);
54
54
  }
55
- var onError = function(error) {
55
+ const onError = (error)=>{
56
56
  if (!error) {
57
57
  error = new Error('Container missing');
58
58
  }
59
59
  if (typeof error.message === 'string') {
60
- error.message += '\nwhile loading "'.concat(data[1], '" from ').concat(data[2]);
60
+ error.message += `\nwhile loading "${data[1]}" from ${data[2]}`;
61
61
  }
62
- webpackRequire.m[id] = function() {
62
+ webpackRequire.m[id] = ()=>{
63
63
  throw error;
64
64
  };
65
65
  data.p = 0;
66
66
  };
67
- var handleFunction = function(fn, arg1, arg2, d, next, first) {
67
+ const handleFunction = (fn, arg1, arg2, d, next, first)=>{
68
68
  try {
69
- var promise = fn(arg1, arg2);
69
+ const promise = fn(arg1, arg2);
70
70
  if (promise && promise.then) {
71
- var p = promise.then(function(result) {
72
- return next(result, d);
73
- }, onError);
71
+ const p = promise.then((result)=>next(result, d), onError);
74
72
  if (first) {
75
73
  promises.push(data.p = p);
76
74
  } else {
@@ -83,24 +81,20 @@ function remotes(options) {
83
81
  onError(error);
84
82
  }
85
83
  };
86
- var onExternal = function(external, _, first) {
87
- return external ? handleFunction(webpackRequire.I, data[0], 0, external, onInitialized, first) : onError();
88
- };
84
+ const onExternal = (external, _, first)=>external ? handleFunction(webpackRequire.I, data[0], 0, external, onInitialized, first) : onError();
89
85
  // eslint-disable-next-line no-var
90
- var onInitialized = function(_, external, first) {
91
- return handleFunction(external.get, data[1], getScope, 0, onFactory, first);
92
- };
86
+ var onInitialized = (_, external, first)=>handleFunction(external.get, data[1], getScope, 0, onFactory, first);
93
87
  // eslint-disable-next-line no-var
94
- var onFactory = function(factory) {
88
+ var onFactory = (factory)=>{
95
89
  data.p = 1;
96
- webpackRequire.m[id] = function(module) {
90
+ webpackRequire.m[id] = (module)=>{
97
91
  module.exports = factory();
98
92
  };
99
93
  };
100
- var onRemoteLoaded = function() {
94
+ const onRemoteLoaded = ()=>{
101
95
  try {
102
- var remoteName = sdk.decodeName(remoteInfos[0].name, sdk.ENCODE_NAME_PREFIX);
103
- var remoteModuleName = remoteName + data[1].slice(1);
96
+ const remoteName = sdk.decodeName(remoteInfos[0].name, sdk.ENCODE_NAME_PREFIX);
97
+ const remoteModuleName = remoteName + data[1].slice(1);
104
98
  return webpackRequire.federation.instance.loadRemote(remoteModuleName, {
105
99
  loadFactory: false,
106
100
  from: 'build'
@@ -109,7 +103,7 @@ function remotes(options) {
109
103
  onError(error);
110
104
  }
111
105
  };
112
- var useRuntimeLoad = remoteInfos.length === 1 && constant.FEDERATION_SUPPORTED_TYPES.includes(remoteInfos[0].externalType) && remoteInfos[0].name;
106
+ const useRuntimeLoad = remoteInfos.length === 1 && constant.FEDERATION_SUPPORTED_TYPES.includes(remoteInfos[0].externalType) && remoteInfos[0].name;
113
107
  if (useRuntimeLoad) {
114
108
  handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);
115
109
  } else {
@@ -120,36 +114,36 @@ function remotes(options) {
120
114
  }
121
115
 
122
116
  function consumes(options) {
123
- var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
117
+ const { chunkId, promises, chunkMapping, installedModules, moduleToHandlerMapping, webpackRequire } = options;
124
118
  attachShareScopeMap(webpackRequire);
125
119
  if (webpackRequire.o(chunkMapping, chunkId)) {
126
- chunkMapping[chunkId].forEach(function(id) {
120
+ chunkMapping[chunkId].forEach((id)=>{
127
121
  if (webpackRequire.o(installedModules, id)) {
128
122
  return promises.push(installedModules[id]);
129
123
  }
130
- var onFactory = function(factory) {
124
+ const onFactory = (factory)=>{
131
125
  installedModules[id] = 0;
132
- webpackRequire.m[id] = function(module) {
126
+ webpackRequire.m[id] = (module)=>{
133
127
  delete webpackRequire.c[id];
134
128
  module.exports = factory();
135
129
  };
136
130
  };
137
- var onError = function(error) {
131
+ const onError = (error)=>{
138
132
  delete installedModules[id];
139
- webpackRequire.m[id] = function(module) {
133
+ webpackRequire.m[id] = (module)=>{
140
134
  delete webpackRequire.c[id];
141
135
  throw error;
142
136
  };
143
137
  };
144
138
  try {
145
- var federationInstance = webpackRequire.federation.instance;
139
+ const federationInstance = webpackRequire.federation.instance;
146
140
  if (!federationInstance) {
147
141
  throw new Error('Federation instance not found!');
148
142
  }
149
- var _moduleToHandlerMapping_id = moduleToHandlerMapping[id], shareKey = _moduleToHandlerMapping_id.shareKey, getter = _moduleToHandlerMapping_id.getter, shareInfo = _moduleToHandlerMapping_id.shareInfo;
150
- var promise = federationInstance.loadShare(shareKey, {
143
+ const { shareKey, getter, shareInfo } = moduleToHandlerMapping[id];
144
+ const promise = federationInstance.loadShare(shareKey, {
151
145
  customShareInfo: shareInfo
152
- }).then(function(factory) {
146
+ }).then((factory)=>{
153
147
  if (factory === false) {
154
148
  return getter();
155
149
  }
@@ -168,10 +162,9 @@ function consumes(options) {
168
162
  }
169
163
  }
170
164
 
171
- function initializeSharing(param) {
172
- var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
165
+ function initializeSharing({ shareScopeName, webpackRequire, initPromises, initTokens, initScope }) {
173
166
  if (!initScope) initScope = [];
174
- var mfInstance = webpackRequire.federation.instance;
167
+ const mfInstance = webpackRequire.federation.instance;
175
168
  // handling circular init calls
176
169
  var initToken = initTokens[shareScopeName];
177
170
  if (!initToken) initToken = initTokens[shareScopeName] = {
@@ -179,22 +172,16 @@ function initializeSharing(param) {
179
172
  };
180
173
  if (initScope.indexOf(initToken) >= 0) return;
181
174
  initScope.push(initToken);
182
- var promise = initPromises[shareScopeName];
175
+ const promise = initPromises[shareScopeName];
183
176
  if (promise) return promise;
184
- var warn = function(msg) {
185
- return typeof console !== 'undefined' && console.warn && console.warn(msg);
186
- };
187
- var initExternal = function(id) {
188
- var handleError = function(err) {
189
- return warn('Initialization of sharing external failed: ' + err);
190
- };
177
+ var warn = (msg)=>typeof console !== 'undefined' && console.warn && console.warn(msg);
178
+ var initExternal = (id)=>{
179
+ var handleError = (err)=>warn('Initialization of sharing external failed: ' + err);
191
180
  try {
192
181
  var module = webpackRequire(id);
193
182
  if (!module) return;
194
- var initFn = function(module) {
195
- return module && module.init && // @ts-ignore compat legacy mf shared behavior
183
+ var initFn = (module)=>module && module.init && // @ts-ignore compat legacy mf shared behavior
196
184
  module.init(webpackRequire.S[shareScopeName], initScope);
197
- };
198
185
  if (module.then) return promises.push(module.then(initFn, handleError));
199
186
  var initResult = initFn(module);
200
187
  // @ts-ignore
@@ -204,21 +191,21 @@ function initializeSharing(param) {
204
191
  handleError(err);
205
192
  }
206
193
  };
207
- var promises = mfInstance.initializeSharing(shareScopeName, {
194
+ const promises = mfInstance.initializeSharing(shareScopeName, {
208
195
  strategy: mfInstance.options.shareStrategy,
209
- initScope: initScope,
196
+ initScope,
210
197
  from: 'build'
211
198
  });
212
199
  attachShareScopeMap(webpackRequire);
213
- var bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
200
+ const bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
214
201
  if (bundlerRuntimeRemotesOptions) {
215
- Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(function(moduleId) {
216
- var info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
217
- var externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
202
+ Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach((moduleId)=>{
203
+ const info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
204
+ const externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
218
205
  if (info.length > 1) {
219
206
  initExternal(externalModuleId);
220
207
  } else if (info.length === 1) {
221
- var remoteInfo = info[0];
208
+ const remoteInfo = info[0];
222
209
  if (!constant.FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
223
210
  initExternal(externalModuleId);
224
211
  }
@@ -228,18 +215,16 @@ function initializeSharing(param) {
228
215
  if (!promises.length) {
229
216
  return initPromises[shareScopeName] = true;
230
217
  }
231
- return initPromises[shareScopeName] = Promise.all(promises).then(function() {
232
- return initPromises[shareScopeName] = true;
233
- });
218
+ return initPromises[shareScopeName] = Promise.all(promises).then(()=>initPromises[shareScopeName] = true);
234
219
  }
235
220
 
236
221
  function handleInitialConsumes(options) {
237
- var moduleId = options.moduleId, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
238
- var federationInstance = webpackRequire.federation.instance;
222
+ const { moduleId, moduleToHandlerMapping, webpackRequire } = options;
223
+ const federationInstance = webpackRequire.federation.instance;
239
224
  if (!federationInstance) {
240
225
  throw new Error('Federation instance not found!');
241
226
  }
242
- var _moduleToHandlerMapping_moduleId = moduleToHandlerMapping[moduleId], shareKey = _moduleToHandlerMapping_moduleId.shareKey, shareInfo = _moduleToHandlerMapping_moduleId.shareInfo;
227
+ const { shareKey, shareInfo } = moduleToHandlerMapping[moduleId];
243
228
  try {
244
229
  return federationInstance.loadShareSync(shareKey, {
245
230
  customShareInfo: shareInfo
@@ -251,65 +236,37 @@ function handleInitialConsumes(options) {
251
236
  }
252
237
  }
253
238
  function installInitialConsumes(options) {
254
- var moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire, installedModules = options.installedModules, initialConsumes = options.initialConsumes;
255
- initialConsumes.forEach(function(id) {
256
- webpackRequire.m[id] = function(module) {
239
+ const { moduleToHandlerMapping, webpackRequire, installedModules, initialConsumes } = options;
240
+ initialConsumes.forEach((id)=>{
241
+ webpackRequire.m[id] = (module)=>{
257
242
  // Handle scenario when module is used synchronously
258
243
  installedModules[id] = 0;
259
244
  delete webpackRequire.c[id];
260
- var factory = handleInitialConsumes({
245
+ const factory = handleInitialConsumes({
261
246
  moduleId: id,
262
- moduleToHandlerMapping: moduleToHandlerMapping,
263
- webpackRequire: webpackRequire
247
+ moduleToHandlerMapping,
248
+ webpackRequire
264
249
  });
265
250
  if (typeof factory !== 'function') {
266
- throw new Error("Shared module is not available for eager consumption: ".concat(id));
251
+ throw new Error(`Shared module is not available for eager consumption: ${id}`);
267
252
  }
268
253
  module.exports = factory();
269
254
  };
270
255
  });
271
256
  }
272
257
 
273
- function _define_property(obj, key, value) {
274
- if (key in obj) {
275
- Object.defineProperty(obj, key, {
276
- value: value,
277
- enumerable: true,
278
- configurable: true,
279
- writable: true
280
- });
281
- } else {
282
- obj[key] = value;
283
- }
284
- return obj;
285
- }
286
- function _object_spread(target) {
287
- for(var i = 1; i < arguments.length; i++){
288
- var source = arguments[i] != null ? arguments[i] : {};
289
- var ownKeys = Object.keys(source);
290
- if (typeof Object.getOwnPropertySymbols === "function") {
291
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
292
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
293
- }));
294
- }
295
- ownKeys.forEach(function(key) {
296
- _define_property(target, key, source[key]);
297
- });
298
- }
299
- return target;
300
- }
301
258
  function initContainerEntry(options) {
302
- var webpackRequire = options.webpackRequire, shareScope = options.shareScope, initScope = options.initScope, shareScopeKey = options.shareScopeKey, remoteEntryInitOptions = options.remoteEntryInitOptions;
259
+ const { webpackRequire, shareScope, initScope, shareScopeKey, remoteEntryInitOptions } = options;
303
260
  if (!webpackRequire.S) return;
304
261
  if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
305
- var federationInstance = webpackRequire.federation.instance;
262
+ const federationInstance = webpackRequire.federation.instance;
306
263
  var name = shareScopeKey || 'default';
307
- federationInstance.initOptions(_object_spread({
264
+ federationInstance.initOptions(polyfills._extends({
308
265
  name: webpackRequire.federation.initOptions.name,
309
266
  remotes: []
310
267
  }, remoteEntryInitOptions));
311
268
  federationInstance.initShareScopeMap(name, shareScope, {
312
- hostShareScopeMap: (remoteEntryInitOptions === null || remoteEntryInitOptions === void 0 ? void 0 : remoteEntryInitOptions.shareScopeMap) || {}
269
+ hostShareScopeMap: (remoteEntryInitOptions == null ? void 0 : remoteEntryInitOptions.shareScopeMap) || {}
313
270
  });
314
271
  if (webpackRequire.federation.attachShareScopeMap) {
315
272
  webpackRequire.federation.attachShareScopeMap(webpackRequire);
@@ -321,19 +278,19 @@ function initContainerEntry(options) {
321
278
  return webpackRequire.I(name, initScope);
322
279
  }
323
280
 
324
- var federation = {
281
+ const federation = {
325
282
  runtime: runtime__namespace,
326
283
  instance: undefined,
327
284
  initOptions: undefined,
328
285
  bundlerRuntime: {
329
- remotes: remotes,
330
- consumes: consumes,
286
+ remotes,
287
+ consumes,
331
288
  I: initializeSharing,
332
289
  S: {},
333
- installInitialConsumes: installInitialConsumes,
334
- initContainerEntry: initContainerEntry
290
+ installInitialConsumes,
291
+ initContainerEntry
335
292
  },
336
- attachShareScopeMap: attachShareScopeMap,
293
+ attachShareScopeMap,
337
294
  bundlerRuntimeOptions: {}
338
295
  };
339
296
 
@@ -0,0 +1,2 @@
1
+ export * from "./src/index";
2
+ export { default } from "./src/index";