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