@module-federation/webpack-bundler-runtime 0.0.0-next-20231220085130 → 0.0.0-next-20231221094341

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
@@ -1,6 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var runtime = require('@module-federation/runtime');
6
+ var sdk = require('@module-federation/sdk');
4
7
 
5
8
  function _interopNamespace(e) {
6
9
  if (e && e.__esModule) return e;
@@ -22,8 +25,68 @@ function _interopNamespace(e) {
22
25
 
23
26
  var runtime__namespace = /*#__PURE__*/_interopNamespace(runtime);
24
27
 
28
+ function attachShareScopeMap(webpackRequire) {
29
+ if (!webpackRequire.S || webpackRequire.federation.hasAttachShareScopeMap || !webpackRequire.federation.instance || !webpackRequire.federation.instance.shareScopeMap) {
30
+ return;
31
+ }
32
+ webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;
33
+ webpackRequire.federation.hasAttachShareScopeMap = true;
34
+ }
35
+
36
+ var FEDERATION_SUPPORTED_TYPES = [
37
+ "script"
38
+ ];
39
+ var ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
40
+
41
+ function _array_like_to_array(arr, len) {
42
+ if (len == null || len > arr.length) len = arr.length;
43
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
44
+ return arr2;
45
+ }
46
+ function _array_with_holes(arr) {
47
+ if (Array.isArray(arr)) return arr;
48
+ }
49
+ function _iterable_to_array_limit(arr, i) {
50
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
51
+ if (_i == null) return;
52
+ var _arr = [];
53
+ var _n = true;
54
+ var _d = false;
55
+ var _s, _e;
56
+ try {
57
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
58
+ _arr.push(_s.value);
59
+ if (i && _arr.length === i) break;
60
+ }
61
+ } catch (err) {
62
+ _d = true;
63
+ _e = err;
64
+ } finally{
65
+ try {
66
+ if (!_n && _i["return"] != null) _i["return"]();
67
+ } finally{
68
+ if (_d) throw _e;
69
+ }
70
+ }
71
+ return _arr;
72
+ }
73
+ function _non_iterable_rest() {
74
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
75
+ }
76
+ function _sliced_to_array(arr, i) {
77
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
78
+ }
79
+ function _unsupported_iterable_to_array(o, minLen) {
80
+ if (!o) return;
81
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
82
+ var n = Object.prototype.toString.call(o).slice(8, -1);
83
+ if (n === "Object" && o.constructor) n = o.constructor.name;
84
+ if (n === "Map" || n === "Set") return Array.from(n);
85
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
86
+ }
25
87
  function remotes(options) {
26
- var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire;
88
+ var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire, idToRemoteMap = options.idToRemoteMap;
89
+ attachShareScopeMap(webpackRequire);
27
90
  if (webpackRequire.o(chunkMapping, chunkId)) {
28
91
  chunkMapping[chunkId].forEach(function(id) {
29
92
  var getScope = webpackRequire.R;
@@ -31,6 +94,7 @@ function remotes(options) {
31
94
  getScope = [];
32
95
  }
33
96
  var data = idToExternalAndNameMapping[id];
97
+ var remoteInfos = idToRemoteMap[id];
34
98
  // @ts-ignore seems not work
35
99
  if (getScope.indexOf(data) >= 0) {
36
100
  return;
@@ -78,9 +142,6 @@ function remotes(options) {
78
142
  var onInitialized = function(_, external, first) {
79
143
  return handleFunction(external.get, data[1], getScope, 0, onFactory, first);
80
144
  };
81
- var useRuntimeLoad = [
82
- "script"
83
- ].includes(data[3]) && data[4];
84
145
  // eslint-disable-next-line no-var
85
146
  var onFactory = function(factory) {
86
147
  data.p = 1;
@@ -88,9 +149,21 @@ function remotes(options) {
88
149
  module.exports = factory();
89
150
  };
90
151
  };
152
+ var extractUrlAndGlobal = function(urlAndGlobal) {
153
+ var index = urlAndGlobal.indexOf("@");
154
+ if (index <= 0 || index === urlAndGlobal.length - 1) {
155
+ throw new Error('Invalid request "'.concat(urlAndGlobal, '"'));
156
+ }
157
+ return [
158
+ urlAndGlobal.substring(index + 1),
159
+ urlAndGlobal.substring(0, index)
160
+ ];
161
+ };
91
162
  var onRemoteLoaded = function() {
92
163
  try {
93
- var remoteModuleName = data[4] + data[1].slice(1);
164
+ var _extractUrlAndGlobal = _sliced_to_array(extractUrlAndGlobal(remoteInfos[0].request), 2), _entryUrl = _extractUrlAndGlobal[0], globalName = _extractUrlAndGlobal[1];
165
+ var remoteName = sdk.decodeName(globalName, ENCODE_NAME_PREFIX);
166
+ var remoteModuleName = remoteName + data[1].slice(1);
94
167
  return webpackRequire.federation.instance.loadRemote(remoteModuleName, {
95
168
  loadFactory: false
96
169
  });
@@ -98,6 +171,9 @@ function remotes(options) {
98
171
  onError(error);
99
172
  }
100
173
  };
174
+ var useRuntimeLoad = remoteInfos.length === 1 && [
175
+ "script"
176
+ ].includes(remoteInfos[0].externalType) && remoteInfos[0].request;
101
177
  if (useRuntimeLoad) {
102
178
  handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);
103
179
  } else {
@@ -107,25 +183,9 @@ function remotes(options) {
107
183
  }
108
184
  }
109
185
 
110
- function proxyShareScopeMap(__webpack_require__) {
111
- if (!__webpack_require__.S) {
112
- return;
113
- }
114
- // @ts-ignore FIXME: ideal situation is import type from @module-federation/runtime/type ,but the compile will throw error
115
- __webpack_require__.S = new Proxy(globalThis.__VMOK__.__SHARE__, {
116
- get: function get(target, prop, receiver) {
117
- return globalThis.__VMOK__.__SHARE__[prop];
118
- },
119
- set: function set(target, prop, value) {
120
- globalThis.__VMOK__.__SHARE__[prop] = value;
121
- return true;
122
- }
123
- });
124
- }
125
-
126
186
  function consumes(options) {
127
187
  var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
128
- proxyShareScopeMap(webpackRequire);
188
+ attachShareScopeMap(webpackRequire);
129
189
  if (webpackRequire.o(chunkMapping, chunkId)) {
130
190
  chunkMapping[chunkId].forEach(function(id) {
131
191
  if (webpackRequire.o(installedModules, id)) {
@@ -170,8 +230,61 @@ function consumes(options) {
170
230
  }
171
231
  }
172
232
 
173
- function initializeSharing(shareScopeName, webpackRequire) {
174
- return webpackRequire.federation.instance.initializeSharing(shareScopeName);
233
+ function initializeSharing(param) {
234
+ var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
235
+ if (!initScope) initScope = [];
236
+ // handling circular init calls
237
+ var initToken = initTokens[shareScopeName];
238
+ if (!initToken) initToken = initTokens[shareScopeName] = {};
239
+ if (initScope.indexOf(initToken) >= 0) return;
240
+ initScope.push(initToken);
241
+ var promise = initPromises[shareScopeName];
242
+ if (promise) return promise;
243
+ var warn = function(msg) {
244
+ return typeof console !== "undefined" && console.warn && console.warn(msg);
245
+ };
246
+ var initExternal = function(id) {
247
+ var handleError = function(err) {
248
+ return warn("Initialization of sharing external failed: " + err);
249
+ };
250
+ try {
251
+ var module = webpackRequire(id);
252
+ if (!module) return;
253
+ var initFn = function(module) {
254
+ return module && module.init && module.init(webpackRequire.S[shareScopeName], initScope);
255
+ };
256
+ if (module.then) return promises.push(module.then(initFn, handleError));
257
+ var initResult = initFn(module);
258
+ // @ts-ignore
259
+ if (initResult && typeof initResult !== "boolean" && initResult.then) // @ts-ignore
260
+ return promises.push(initResult["catch"](handleError));
261
+ } catch (err) {
262
+ handleError(err);
263
+ }
264
+ };
265
+ var promises = webpackRequire.federation.instance.initializeSharing(shareScopeName);
266
+ attachShareScopeMap(webpackRequire);
267
+ var bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
268
+ if (bundlerRuntimeRemotesOptions) {
269
+ Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(function(moduleId) {
270
+ var info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
271
+ var externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
272
+ if (info.length > 1) {
273
+ initExternal(externalModuleId);
274
+ } else if (info.length === 1) {
275
+ var remoteInfo = info[0];
276
+ if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
277
+ initExternal(externalModuleId);
278
+ }
279
+ }
280
+ });
281
+ }
282
+ if (!promises.length) {
283
+ return initPromises[shareScopeName] = true;
284
+ }
285
+ return initPromises[shareScopeName] = Promise.all(promises).then(function() {
286
+ return initPromises[shareScopeName] = true;
287
+ });
175
288
  }
176
289
 
177
290
  function handleInitialConsumes(options) {
@@ -206,6 +319,28 @@ function installInitialConsumes(options) {
206
319
  });
207
320
  }
208
321
 
322
+ function initContainerEntry(options) {
323
+ var webpackRequire = options.webpackRequire, shareScope = options.shareScope, initScope = options.initScope, shareScopeKey = options.shareScopeKey;
324
+ if (!webpackRequire.S) return;
325
+ if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
326
+ var name = shareScopeKey || "default";
327
+ webpackRequire.federation.instance.initOptions({
328
+ name: webpackRequire.federation.initOptions.name,
329
+ remotes: []
330
+ });
331
+ webpackRequire.federation.instance.initShareScopeMap(name, shareScope);
332
+ var prevShareScope = globalThis.__FEDERATION__.__SHARE__["default"];
333
+ if (prevShareScope) {
334
+ webpackRequire.federation.instance.initShareScopeMap(name, prevShareScope);
335
+ }
336
+ webpackRequire.S[name] = shareScope;
337
+ if (webpackRequire.federation.attachShareScopeMap) {
338
+ webpackRequire.federation.attachShareScopeMap(webpackRequire);
339
+ }
340
+ // @ts-ignore
341
+ return webpackRequire.I(name, initScope);
342
+ }
343
+
209
344
  var federation = {
210
345
  runtime: runtime__namespace,
211
346
  instance: undefined,
@@ -215,8 +350,12 @@ var federation = {
215
350
  consumes: consumes,
216
351
  I: initializeSharing,
217
352
  S: {},
218
- installInitialConsumes: installInitialConsumes
219
- }
353
+ installInitialConsumes: installInitialConsumes,
354
+ initContainerEntry: initContainerEntry
355
+ },
356
+ attachShareScopeMap: attachShareScopeMap,
357
+ bundlerRuntimeOptions: {}
220
358
  };
221
359
 
222
- module.exports = federation;
360
+ exports.ENCODE_NAME_PREFIX = ENCODE_NAME_PREFIX;
361
+ exports["default"] = federation;
package/dist/index.esm.js CHANGED
@@ -1,7 +1,68 @@
1
1
  import * as runtime from '@module-federation/runtime';
2
+ import { decodeName } from '@module-federation/sdk';
2
3
 
4
+ function attachShareScopeMap(webpackRequire) {
5
+ if (!webpackRequire.S || webpackRequire.federation.hasAttachShareScopeMap || !webpackRequire.federation.instance || !webpackRequire.federation.instance.shareScopeMap) {
6
+ return;
7
+ }
8
+ webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;
9
+ webpackRequire.federation.hasAttachShareScopeMap = true;
10
+ }
11
+
12
+ var FEDERATION_SUPPORTED_TYPES = [
13
+ "script"
14
+ ];
15
+ var ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
16
+
17
+ function _array_like_to_array(arr, len) {
18
+ if (len == null || len > arr.length) len = arr.length;
19
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
20
+ return arr2;
21
+ }
22
+ function _array_with_holes(arr) {
23
+ if (Array.isArray(arr)) return arr;
24
+ }
25
+ function _iterable_to_array_limit(arr, i) {
26
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
27
+ if (_i == null) return;
28
+ var _arr = [];
29
+ var _n = true;
30
+ var _d = false;
31
+ var _s, _e;
32
+ try {
33
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
34
+ _arr.push(_s.value);
35
+ if (i && _arr.length === i) break;
36
+ }
37
+ } catch (err) {
38
+ _d = true;
39
+ _e = err;
40
+ } finally{
41
+ try {
42
+ if (!_n && _i["return"] != null) _i["return"]();
43
+ } finally{
44
+ if (_d) throw _e;
45
+ }
46
+ }
47
+ return _arr;
48
+ }
49
+ function _non_iterable_rest() {
50
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
51
+ }
52
+ function _sliced_to_array(arr, i) {
53
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
54
+ }
55
+ function _unsupported_iterable_to_array(o, minLen) {
56
+ if (!o) return;
57
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
58
+ var n = Object.prototype.toString.call(o).slice(8, -1);
59
+ if (n === "Object" && o.constructor) n = o.constructor.name;
60
+ if (n === "Map" || n === "Set") return Array.from(n);
61
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
62
+ }
3
63
  function remotes(options) {
4
- var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire;
64
+ var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire, idToRemoteMap = options.idToRemoteMap;
65
+ attachShareScopeMap(webpackRequire);
5
66
  if (webpackRequire.o(chunkMapping, chunkId)) {
6
67
  chunkMapping[chunkId].forEach(function(id) {
7
68
  var getScope = webpackRequire.R;
@@ -9,6 +70,7 @@ function remotes(options) {
9
70
  getScope = [];
10
71
  }
11
72
  var data = idToExternalAndNameMapping[id];
73
+ var remoteInfos = idToRemoteMap[id];
12
74
  // @ts-ignore seems not work
13
75
  if (getScope.indexOf(data) >= 0) {
14
76
  return;
@@ -56,9 +118,6 @@ function remotes(options) {
56
118
  var onInitialized = function(_, external, first) {
57
119
  return handleFunction(external.get, data[1], getScope, 0, onFactory, first);
58
120
  };
59
- var useRuntimeLoad = [
60
- "script"
61
- ].includes(data[3]) && data[4];
62
121
  // eslint-disable-next-line no-var
63
122
  var onFactory = function(factory) {
64
123
  data.p = 1;
@@ -66,9 +125,21 @@ function remotes(options) {
66
125
  module.exports = factory();
67
126
  };
68
127
  };
128
+ var extractUrlAndGlobal = function(urlAndGlobal) {
129
+ var index = urlAndGlobal.indexOf("@");
130
+ if (index <= 0 || index === urlAndGlobal.length - 1) {
131
+ throw new Error('Invalid request "'.concat(urlAndGlobal, '"'));
132
+ }
133
+ return [
134
+ urlAndGlobal.substring(index + 1),
135
+ urlAndGlobal.substring(0, index)
136
+ ];
137
+ };
69
138
  var onRemoteLoaded = function() {
70
139
  try {
71
- var remoteModuleName = data[4] + data[1].slice(1);
140
+ var _extractUrlAndGlobal = _sliced_to_array(extractUrlAndGlobal(remoteInfos[0].request), 2), _entryUrl = _extractUrlAndGlobal[0], globalName = _extractUrlAndGlobal[1];
141
+ var remoteName = decodeName(globalName, ENCODE_NAME_PREFIX);
142
+ var remoteModuleName = remoteName + data[1].slice(1);
72
143
  return webpackRequire.federation.instance.loadRemote(remoteModuleName, {
73
144
  loadFactory: false
74
145
  });
@@ -76,6 +147,9 @@ function remotes(options) {
76
147
  onError(error);
77
148
  }
78
149
  };
150
+ var useRuntimeLoad = remoteInfos.length === 1 && [
151
+ "script"
152
+ ].includes(remoteInfos[0].externalType) && remoteInfos[0].request;
79
153
  if (useRuntimeLoad) {
80
154
  handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);
81
155
  } else {
@@ -85,25 +159,9 @@ function remotes(options) {
85
159
  }
86
160
  }
87
161
 
88
- function proxyShareScopeMap(__webpack_require__) {
89
- if (!__webpack_require__.S) {
90
- return;
91
- }
92
- // @ts-ignore FIXME: ideal situation is import type from @module-federation/runtime/type ,but the compile will throw error
93
- __webpack_require__.S = new Proxy(globalThis.__VMOK__.__SHARE__, {
94
- get: function get(target, prop, receiver) {
95
- return globalThis.__VMOK__.__SHARE__[prop];
96
- },
97
- set: function set(target, prop, value) {
98
- globalThis.__VMOK__.__SHARE__[prop] = value;
99
- return true;
100
- }
101
- });
102
- }
103
-
104
162
  function consumes(options) {
105
163
  var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
106
- proxyShareScopeMap(webpackRequire);
164
+ attachShareScopeMap(webpackRequire);
107
165
  if (webpackRequire.o(chunkMapping, chunkId)) {
108
166
  chunkMapping[chunkId].forEach(function(id) {
109
167
  if (webpackRequire.o(installedModules, id)) {
@@ -148,8 +206,61 @@ function consumes(options) {
148
206
  }
149
207
  }
150
208
 
151
- function initializeSharing(shareScopeName, webpackRequire) {
152
- return webpackRequire.federation.instance.initializeSharing(shareScopeName);
209
+ function initializeSharing(param) {
210
+ var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
211
+ if (!initScope) initScope = [];
212
+ // handling circular init calls
213
+ var initToken = initTokens[shareScopeName];
214
+ if (!initToken) initToken = initTokens[shareScopeName] = {};
215
+ if (initScope.indexOf(initToken) >= 0) return;
216
+ initScope.push(initToken);
217
+ var promise = initPromises[shareScopeName];
218
+ if (promise) return promise;
219
+ var warn = function(msg) {
220
+ return typeof console !== "undefined" && console.warn && console.warn(msg);
221
+ };
222
+ var initExternal = function(id) {
223
+ var handleError = function(err) {
224
+ return warn("Initialization of sharing external failed: " + err);
225
+ };
226
+ try {
227
+ var module = webpackRequire(id);
228
+ if (!module) return;
229
+ var initFn = function(module) {
230
+ return module && module.init && module.init(webpackRequire.S[shareScopeName], initScope);
231
+ };
232
+ if (module.then) return promises.push(module.then(initFn, handleError));
233
+ var initResult = initFn(module);
234
+ // @ts-ignore
235
+ if (initResult && typeof initResult !== "boolean" && initResult.then) // @ts-ignore
236
+ return promises.push(initResult["catch"](handleError));
237
+ } catch (err) {
238
+ handleError(err);
239
+ }
240
+ };
241
+ var promises = webpackRequire.federation.instance.initializeSharing(shareScopeName);
242
+ attachShareScopeMap(webpackRequire);
243
+ var bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
244
+ if (bundlerRuntimeRemotesOptions) {
245
+ Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(function(moduleId) {
246
+ var info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
247
+ var externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
248
+ if (info.length > 1) {
249
+ initExternal(externalModuleId);
250
+ } else if (info.length === 1) {
251
+ var remoteInfo = info[0];
252
+ if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
253
+ initExternal(externalModuleId);
254
+ }
255
+ }
256
+ });
257
+ }
258
+ if (!promises.length) {
259
+ return initPromises[shareScopeName] = true;
260
+ }
261
+ return initPromises[shareScopeName] = Promise.all(promises).then(function() {
262
+ return initPromises[shareScopeName] = true;
263
+ });
153
264
  }
154
265
 
155
266
  function handleInitialConsumes(options) {
@@ -184,6 +295,28 @@ function installInitialConsumes(options) {
184
295
  });
185
296
  }
186
297
 
298
+ function initContainerEntry(options) {
299
+ var webpackRequire = options.webpackRequire, shareScope = options.shareScope, initScope = options.initScope, shareScopeKey = options.shareScopeKey;
300
+ if (!webpackRequire.S) return;
301
+ if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
302
+ var name = shareScopeKey || "default";
303
+ webpackRequire.federation.instance.initOptions({
304
+ name: webpackRequire.federation.initOptions.name,
305
+ remotes: []
306
+ });
307
+ webpackRequire.federation.instance.initShareScopeMap(name, shareScope);
308
+ var prevShareScope = globalThis.__FEDERATION__.__SHARE__["default"];
309
+ if (prevShareScope) {
310
+ webpackRequire.federation.instance.initShareScopeMap(name, prevShareScope);
311
+ }
312
+ webpackRequire.S[name] = shareScope;
313
+ if (webpackRequire.federation.attachShareScopeMap) {
314
+ webpackRequire.federation.attachShareScopeMap(webpackRequire);
315
+ }
316
+ // @ts-ignore
317
+ return webpackRequire.I(name, initScope);
318
+ }
319
+
187
320
  var federation = {
188
321
  runtime: runtime,
189
322
  instance: undefined,
@@ -193,8 +326,11 @@ var federation = {
193
326
  consumes: consumes,
194
327
  I: initializeSharing,
195
328
  S: {},
196
- installInitialConsumes: installInitialConsumes
197
- }
329
+ installInitialConsumes: installInitialConsumes,
330
+ initContainerEntry: initContainerEntry
331
+ },
332
+ attachShareScopeMap: attachShareScopeMap,
333
+ bundlerRuntimeOptions: {}
198
334
  };
199
335
 
200
- export { federation as default };
336
+ export { ENCODE_NAME_PREFIX, federation as default };
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.0.3",
4
+ "version": "0.0.4",
5
5
  "license": "MIT",
6
6
  "description": "Module Federation Runtime for webpack",
7
7
  "keywords": [
@@ -18,8 +18,9 @@
18
18
  "author": "zhanghang <hanric.zhang@gmail.com>",
19
19
  "main": "./index.cjs.js",
20
20
  "module": "./index.esm.js",
21
- "types": "./index.cjs.d.ts",
21
+ "types": "./dist/index.cjs.d.ts",
22
22
  "dependencies": {
23
- "@module-federation/runtime": "workspace:*"
23
+ "@module-federation/runtime": "workspace:*",
24
+ "@module-federation/sdk": "workspace:*"
24
25
  }
25
26
  }
@@ -0,0 +1,2 @@
1
+ import { WebpackRequire } from './types';
2
+ export declare function attachShareScopeMap(webpackRequire: WebpackRequire): void;
@@ -0,0 +1,2 @@
1
+ export declare const FEDERATION_SUPPORTED_TYPES: string[];
2
+ export declare const ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
@@ -1,3 +1,5 @@
1
1
  import { Federation } from './types';
2
+ export * from './types';
3
+ export { ENCODE_NAME_PREFIX } from './constant';
2
4
  declare const federation: Federation;
3
5
  export default federation;
@@ -0,0 +1,2 @@
1
+ import { InitContainerEntryOptions, WebpackRequire } from './types';
2
+ export declare function initContainerEntry(options: InitContainerEntryOptions): WebpackRequire['I'] | void;
@@ -1,2 +1,2 @@
1
- import { WebpackRequire } from './types';
2
- export declare function initializeSharing(shareScopeName: string, webpackRequire: WebpackRequire): Promise<boolean> | boolean;
1
+ import { InitializeSharingOptions } from './types';
2
+ export declare function initializeSharing({ shareScopeName, webpackRequire, initPromises, initTokens, initScope, }: InitializeSharingOptions): Promise<boolean> | boolean | void;
@@ -1,5 +1,7 @@
1
1
  import * as runtime from '@module-federation/runtime';
2
2
  import { initializeSharing } from './initializeSharing';
3
+ import { attachShareScopeMap } from './attachShareScopeMap';
4
+ import { initContainerEntry } from './initContainerEntry';
3
5
  type ExcludeUndefined<T> = T extends undefined ? never : T;
4
6
  type NonUndefined<T = Shared> = ExcludeUndefined<T>;
5
7
  type InitOptions = Parameters<typeof runtime.init>[0];
@@ -8,6 +10,15 @@ type SharedConfig = NonUndefined<NonUndefined[string]['shareConfig']>;
8
10
  type ModuleCache = runtime.FederationHost['moduleCache'];
9
11
  type InferModule<T> = T extends Map<string, infer U> ? U : never;
10
12
  type InferredModule = InferModule<ModuleCache>;
13
+ export type ShareScopeMap = runtime.FederationHost['shareScopeMap'];
14
+ type InitToken = Record<string, Record<string, any>>;
15
+ export interface InitializeSharingOptions {
16
+ shareScopeName: string;
17
+ webpackRequire: WebpackRequire;
18
+ initPromises: Record<string, Promise<boolean> | boolean>;
19
+ initTokens: InitToken;
20
+ initScope: InitToken[];
21
+ }
11
22
  export type RemoteEntryExports = NonUndefined<InferredModule['remoteEntryExports']>;
12
23
  type ExtractInitParameters<T> = T extends {
13
24
  init: (shareScope: infer U, ...args: any[]) => void;
@@ -16,13 +27,7 @@ type InferredShareScope = ExtractInitParameters<RemoteEntryExports>;
16
27
  type InferredGlobalShareScope = {
17
28
  [scope: string]: InferredShareScope;
18
29
  };
19
- type IdToExternalAndNameMappingItem = [
20
- string,
21
- string,
22
- string | number,
23
- string,
24
- string
25
- ];
30
+ type IdToExternalAndNameMappingItem = [string, string, string | number];
26
31
  interface IdToExternalAndNameMappingItemWithPromise extends IdToExternalAndNameMappingItem {
27
32
  p?: Promise<any> | number;
28
33
  }
@@ -32,7 +37,7 @@ export interface WebpackRequire {
32
37
  R: Array<string | number>;
33
38
  m: Record<string, (mod: any) => any>;
34
39
  c: Record<string, any>;
35
- I: typeof initializeSharing;
40
+ I: (scopeName: string, initScope?: InitializeSharingOptions['initScope']) => ReturnType<typeof initializeSharing>;
36
41
  S?: InferredGlobalShareScope;
37
42
  federation: Federation;
38
43
  }
@@ -45,11 +50,17 @@ interface ModuleToHandlerMappingItem {
45
50
  shareInfo: ShareInfo;
46
51
  shareKey: string;
47
52
  }
53
+ interface IdToRemoteMapItem {
54
+ externalType: string;
55
+ request: string;
56
+ externalModuleId?: string | number;
57
+ }
48
58
  export interface RemotesOptions {
49
59
  chunkId: string | number;
50
60
  promises: Promise<any>[];
51
61
  chunkMapping: Record<string, Array<string | number>>;
52
62
  idToExternalAndNameMapping: Record<string, IdToExternalAndNameMappingItemWithPromise>;
63
+ idToRemoteMap: Record<string, IdToRemoteMapItem[]>;
53
64
  webpackRequire: WebpackRequire;
54
65
  }
55
66
  export interface HandleInitialConsumesOptions {
@@ -71,6 +82,12 @@ export interface ConsumesOptions {
71
82
  moduleToHandlerMapping: Record<string, ModuleToHandlerMappingItem>;
72
83
  webpackRequire: WebpackRequire;
73
84
  }
85
+ export interface InitContainerEntryOptions {
86
+ shareScope: ShareScopeMap[string];
87
+ shareScopeKey: string;
88
+ webpackRequire: WebpackRequire;
89
+ initScope?: InitializeSharingOptions['initScope'];
90
+ }
74
91
  export interface Federation {
75
92
  runtime?: typeof runtime;
76
93
  instance?: runtime.FederationHost;
@@ -79,9 +96,15 @@ export interface Federation {
79
96
  bundlerRuntime?: {
80
97
  remotes: (options: RemotesOptions) => void;
81
98
  consumes: (options: ConsumesOptions) => void;
82
- I: (name: string, webpackRequire: WebpackRequire) => Promise<boolean> | boolean;
99
+ I: typeof initializeSharing;
83
100
  S: InferredGlobalShareScope;
84
101
  installInitialConsumes: (options: InstallInitialConsumesOptions) => any;
102
+ initContainerEntry: typeof initContainerEntry;
103
+ };
104
+ bundlerRuntimeOptions: {
105
+ remotes?: Exclude<RemotesOptions, 'chunkId' | 'promises'>;
85
106
  };
107
+ attachShareScopeMap?: typeof attachShareScopeMap;
108
+ hasAttachShareScopeMap?: boolean;
86
109
  }
87
110
  export {};
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.0.0-next-20231220085130",
4
+ "version": "0.0.0-next-20231221094341",
5
5
  "license": "MIT",
6
6
  "description": "Module Federation Runtime for webpack",
7
7
  "keywords": [
@@ -16,10 +16,11 @@
16
16
  "access": "public"
17
17
  },
18
18
  "author": "zhanghang <hanric.zhang@gmail.com>",
19
- "main": "./index.cjs.js",
20
- "module": "./index.esm.js",
21
- "types": "./index.cjs.d.ts",
19
+ "main": "./dist/index.cjs.js",
20
+ "module": "./dist/index.esm.js",
21
+ "types": "./dist/index.cjs.d.ts",
22
22
  "dependencies": {
23
- "@module-federation/runtime": "0.0.0-next-20231220085130"
23
+ "@module-federation/runtime": "0.0.0-next-20231221094341",
24
+ "@module-federation/sdk": "0.0.0-next-20231221094341"
24
25
  }
25
26
  }