@module-federation/webpack-bundler-runtime 0.0.0-next-20240103035759 → 0.0.0-next-20240104093320

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present zhanghang(2heal1)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ export * from "./src/constant";
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
6
+ var FEDERATION_SUPPORTED_TYPES = [
7
+ "script"
8
+ ];
9
+
10
+ exports.ENCODE_NAME_PREFIX = ENCODE_NAME_PREFIX;
11
+ exports.FEDERATION_SUPPORTED_TYPES = FEDERATION_SUPPORTED_TYPES;
@@ -0,0 +1,6 @@
1
+ var ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
2
+ var FEDERATION_SUPPORTED_TYPES = [
3
+ "script"
4
+ ];
5
+
6
+ export { ENCODE_NAME_PREFIX, FEDERATION_SUPPORTED_TYPES };
package/dist/index.cjs.js CHANGED
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var runtime = require('@module-federation/runtime');
4
+ var sdk = require('@module-federation/sdk');
5
+ var constant = require('./constant.cjs.js');
4
6
 
5
7
  function _interopNamespace(e) {
6
8
  if (e && e.__esModule) return e;
@@ -22,8 +24,17 @@ function _interopNamespace(e) {
22
24
 
23
25
  var runtime__namespace = /*#__PURE__*/_interopNamespace(runtime);
24
26
 
27
+ function attachShareScopeMap(webpackRequire) {
28
+ if (!webpackRequire.S || webpackRequire.federation.hasAttachShareScopeMap || !webpackRequire.federation.instance || !webpackRequire.federation.instance.shareScopeMap) {
29
+ return;
30
+ }
31
+ webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;
32
+ webpackRequire.federation.hasAttachShareScopeMap = true;
33
+ }
34
+
25
35
  function remotes(options) {
26
- var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire;
36
+ var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire, idToRemoteMap = options.idToRemoteMap;
37
+ attachShareScopeMap(webpackRequire);
27
38
  if (webpackRequire.o(chunkMapping, chunkId)) {
28
39
  chunkMapping[chunkId].forEach(function(id) {
29
40
  var getScope = webpackRequire.R;
@@ -31,6 +42,7 @@ function remotes(options) {
31
42
  getScope = [];
32
43
  }
33
44
  var data = idToExternalAndNameMapping[id];
45
+ var remoteInfos = idToRemoteMap[id];
34
46
  // @ts-ignore seems not work
35
47
  if (getScope.indexOf(data) >= 0) {
36
48
  return;
@@ -78,9 +90,6 @@ function remotes(options) {
78
90
  var onInitialized = function(_, external, first) {
79
91
  return handleFunction(external.get, data[1], getScope, 0, onFactory, first);
80
92
  };
81
- var useRuntimeLoad = [
82
- "script"
83
- ].includes(data[3]) && data[4];
84
93
  // eslint-disable-next-line no-var
85
94
  var onFactory = function(factory) {
86
95
  data.p = 1;
@@ -90,14 +99,19 @@ function remotes(options) {
90
99
  };
91
100
  var onRemoteLoaded = function() {
92
101
  try {
93
- var remoteModuleName = data[4] + data[1].slice(1);
102
+ var remoteName = sdk.decodeName(remoteInfos[0].name, constant.ENCODE_NAME_PREFIX);
103
+ var remoteModuleName = remoteName + data[1].slice(1);
94
104
  return webpackRequire.federation.instance.loadRemote(remoteModuleName, {
95
- loadFactory: false
105
+ loadFactory: false,
106
+ from: "build"
96
107
  });
97
108
  } catch (error) {
98
109
  onError(error);
99
110
  }
100
111
  };
112
+ var useRuntimeLoad = remoteInfos.length === 1 && [
113
+ "script"
114
+ ].includes(remoteInfos[0].externalType) && remoteInfos[0].name;
101
115
  if (useRuntimeLoad) {
102
116
  handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);
103
117
  } else {
@@ -107,25 +121,9 @@ function remotes(options) {
107
121
  }
108
122
  }
109
123
 
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
124
  function consumes(options) {
127
125
  var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
128
- proxyShareScopeMap(webpackRequire);
126
+ attachShareScopeMap(webpackRequire);
129
127
  if (webpackRequire.o(chunkMapping, chunkId)) {
130
128
  chunkMapping[chunkId].forEach(function(id) {
131
129
  if (webpackRequire.o(installedModules, id)) {
@@ -170,8 +168,61 @@ function consumes(options) {
170
168
  }
171
169
  }
172
170
 
173
- function initializeSharing(shareScopeName, webpackRequire) {
174
- return webpackRequire.federation.instance.initializeSharing(shareScopeName);
171
+ function initializeSharing(param) {
172
+ var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
173
+ if (!initScope) initScope = [];
174
+ // handling circular init calls
175
+ var initToken = initTokens[shareScopeName];
176
+ if (!initToken) initToken = initTokens[shareScopeName] = {};
177
+ if (initScope.indexOf(initToken) >= 0) return;
178
+ initScope.push(initToken);
179
+ var promise = initPromises[shareScopeName];
180
+ if (promise) return promise;
181
+ var warn = function(msg) {
182
+ return typeof console !== "undefined" && console.warn && console.warn(msg);
183
+ };
184
+ var initExternal = function(id) {
185
+ var handleError = function(err) {
186
+ return warn("Initialization of sharing external failed: " + err);
187
+ };
188
+ try {
189
+ var module = webpackRequire(id);
190
+ if (!module) return;
191
+ var initFn = function(module) {
192
+ return module && module.init && module.init(webpackRequire.S[shareScopeName], initScope);
193
+ };
194
+ if (module.then) return promises.push(module.then(initFn, handleError));
195
+ var initResult = initFn(module);
196
+ // @ts-ignore
197
+ if (initResult && typeof initResult !== "boolean" && initResult.then) // @ts-ignore
198
+ return promises.push(initResult["catch"](handleError));
199
+ } catch (err) {
200
+ handleError(err);
201
+ }
202
+ };
203
+ var promises = webpackRequire.federation.instance.initializeSharing(shareScopeName);
204
+ attachShareScopeMap(webpackRequire);
205
+ var bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
206
+ if (bundlerRuntimeRemotesOptions) {
207
+ Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(function(moduleId) {
208
+ var info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
209
+ var externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
210
+ if (info.length > 1) {
211
+ initExternal(externalModuleId);
212
+ } else if (info.length === 1) {
213
+ var remoteInfo = info[0];
214
+ if (!constant.FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
215
+ initExternal(externalModuleId);
216
+ }
217
+ }
218
+ });
219
+ }
220
+ if (!promises.length) {
221
+ return initPromises[shareScopeName] = true;
222
+ }
223
+ return initPromises[shareScopeName] = Promise.all(promises).then(function() {
224
+ return initPromises[shareScopeName] = true;
225
+ });
175
226
  }
176
227
 
177
228
  function handleInitialConsumes(options) {
@@ -181,10 +232,7 @@ function handleInitialConsumes(options) {
181
232
  throw new Error("Federation instance not found!");
182
233
  }
183
234
  var _moduleToHandlerMapping_moduleId = moduleToHandlerMapping[moduleId], shareKey = _moduleToHandlerMapping_moduleId.shareKey, shareInfo = _moduleToHandlerMapping_moduleId.shareInfo;
184
- if (!shareInfo.shareConfig.eager) {
185
- throw new Error('Shared: "'.concat(shareKey, '" cannot be loaded synchronously unless "eager:true" is set or async entry is enabled.'));
186
- }
187
- return federationInstance.loadShareSync(shareKey);
235
+ return federationInstance.loadShareSync(shareKey, shareInfo);
188
236
  }
189
237
  function installInitialConsumes(options) {
190
238
  var moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire, installedModules = options.installedModules, initialConsumes = options.initialConsumes;
@@ -206,6 +254,40 @@ function installInitialConsumes(options) {
206
254
  });
207
255
  }
208
256
 
257
+ function isLegacyHost(shareScope) {
258
+ if ("version" in shareScope && typeof shareScope["version"] !== "object") {
259
+ return true;
260
+ }
261
+ if ("region" in shareScope && typeof shareScope["region"] !== "object") {
262
+ return true;
263
+ }
264
+ return false;
265
+ }
266
+ function initContainerEntry(options) {
267
+ var webpackRequire = options.webpackRequire, shareScope = options.shareScope, initScope = options.initScope, shareScopeKey = options.shareScopeKey;
268
+ if (!webpackRequire.S) return;
269
+ if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
270
+ var name = shareScopeKey || "default";
271
+ webpackRequire.federation.instance.initOptions({
272
+ name: webpackRequire.federation.initOptions.name,
273
+ remotes: []
274
+ });
275
+ if (isLegacyHost(shareScope)) {
276
+ var prevShareScope = globalThis.__FEDERATION__.__SHARE__["default"];
277
+ if (prevShareScope) {
278
+ webpackRequire.federation.instance.initShareScopeMap(name, prevShareScope);
279
+ }
280
+ } else {
281
+ webpackRequire.federation.instance.initShareScopeMap(name, shareScope);
282
+ }
283
+ webpackRequire.S[name] = shareScope;
284
+ if (webpackRequire.federation.attachShareScopeMap) {
285
+ webpackRequire.federation.attachShareScopeMap(webpackRequire);
286
+ }
287
+ // @ts-ignore
288
+ return webpackRequire.I(name, initScope);
289
+ }
290
+
209
291
  var federation = {
210
292
  runtime: runtime__namespace,
211
293
  instance: undefined,
@@ -215,8 +297,11 @@ var federation = {
215
297
  consumes: consumes,
216
298
  I: initializeSharing,
217
299
  S: {},
218
- installInitialConsumes: installInitialConsumes
219
- }
300
+ installInitialConsumes: installInitialConsumes,
301
+ initContainerEntry: initContainerEntry
302
+ },
303
+ attachShareScopeMap: attachShareScopeMap,
304
+ bundlerRuntimeOptions: {}
220
305
  };
221
306
 
222
307
  module.exports = federation;
package/dist/index.esm.js CHANGED
@@ -1,7 +1,18 @@
1
1
  import * as runtime from '@module-federation/runtime';
2
+ import { decodeName } from '@module-federation/sdk';
3
+ import { ENCODE_NAME_PREFIX, FEDERATION_SUPPORTED_TYPES } from './constant.esm.js';
4
+
5
+ function attachShareScopeMap(webpackRequire) {
6
+ if (!webpackRequire.S || webpackRequire.federation.hasAttachShareScopeMap || !webpackRequire.federation.instance || !webpackRequire.federation.instance.shareScopeMap) {
7
+ return;
8
+ }
9
+ webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;
10
+ webpackRequire.federation.hasAttachShareScopeMap = true;
11
+ }
2
12
 
3
13
  function remotes(options) {
4
- var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire;
14
+ var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire, idToRemoteMap = options.idToRemoteMap;
15
+ attachShareScopeMap(webpackRequire);
5
16
  if (webpackRequire.o(chunkMapping, chunkId)) {
6
17
  chunkMapping[chunkId].forEach(function(id) {
7
18
  var getScope = webpackRequire.R;
@@ -9,6 +20,7 @@ function remotes(options) {
9
20
  getScope = [];
10
21
  }
11
22
  var data = idToExternalAndNameMapping[id];
23
+ var remoteInfos = idToRemoteMap[id];
12
24
  // @ts-ignore seems not work
13
25
  if (getScope.indexOf(data) >= 0) {
14
26
  return;
@@ -56,9 +68,6 @@ function remotes(options) {
56
68
  var onInitialized = function(_, external, first) {
57
69
  return handleFunction(external.get, data[1], getScope, 0, onFactory, first);
58
70
  };
59
- var useRuntimeLoad = [
60
- "script"
61
- ].includes(data[3]) && data[4];
62
71
  // eslint-disable-next-line no-var
63
72
  var onFactory = function(factory) {
64
73
  data.p = 1;
@@ -68,14 +77,19 @@ function remotes(options) {
68
77
  };
69
78
  var onRemoteLoaded = function() {
70
79
  try {
71
- var remoteModuleName = data[4] + data[1].slice(1);
80
+ var remoteName = decodeName(remoteInfos[0].name, ENCODE_NAME_PREFIX);
81
+ var remoteModuleName = remoteName + data[1].slice(1);
72
82
  return webpackRequire.federation.instance.loadRemote(remoteModuleName, {
73
- loadFactory: false
83
+ loadFactory: false,
84
+ from: "build"
74
85
  });
75
86
  } catch (error) {
76
87
  onError(error);
77
88
  }
78
89
  };
90
+ var useRuntimeLoad = remoteInfos.length === 1 && [
91
+ "script"
92
+ ].includes(remoteInfos[0].externalType) && remoteInfos[0].name;
79
93
  if (useRuntimeLoad) {
80
94
  handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);
81
95
  } else {
@@ -85,25 +99,9 @@ function remotes(options) {
85
99
  }
86
100
  }
87
101
 
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
102
  function consumes(options) {
105
103
  var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
106
- proxyShareScopeMap(webpackRequire);
104
+ attachShareScopeMap(webpackRequire);
107
105
  if (webpackRequire.o(chunkMapping, chunkId)) {
108
106
  chunkMapping[chunkId].forEach(function(id) {
109
107
  if (webpackRequire.o(installedModules, id)) {
@@ -148,8 +146,61 @@ function consumes(options) {
148
146
  }
149
147
  }
150
148
 
151
- function initializeSharing(shareScopeName, webpackRequire) {
152
- return webpackRequire.federation.instance.initializeSharing(shareScopeName);
149
+ function initializeSharing(param) {
150
+ var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
151
+ if (!initScope) initScope = [];
152
+ // handling circular init calls
153
+ var initToken = initTokens[shareScopeName];
154
+ if (!initToken) initToken = initTokens[shareScopeName] = {};
155
+ if (initScope.indexOf(initToken) >= 0) return;
156
+ initScope.push(initToken);
157
+ var promise = initPromises[shareScopeName];
158
+ if (promise) return promise;
159
+ var warn = function(msg) {
160
+ return typeof console !== "undefined" && console.warn && console.warn(msg);
161
+ };
162
+ var initExternal = function(id) {
163
+ var handleError = function(err) {
164
+ return warn("Initialization of sharing external failed: " + err);
165
+ };
166
+ try {
167
+ var module = webpackRequire(id);
168
+ if (!module) return;
169
+ var initFn = function(module) {
170
+ return module && module.init && module.init(webpackRequire.S[shareScopeName], initScope);
171
+ };
172
+ if (module.then) return promises.push(module.then(initFn, handleError));
173
+ var initResult = initFn(module);
174
+ // @ts-ignore
175
+ if (initResult && typeof initResult !== "boolean" && initResult.then) // @ts-ignore
176
+ return promises.push(initResult["catch"](handleError));
177
+ } catch (err) {
178
+ handleError(err);
179
+ }
180
+ };
181
+ var promises = webpackRequire.federation.instance.initializeSharing(shareScopeName);
182
+ attachShareScopeMap(webpackRequire);
183
+ var bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
184
+ if (bundlerRuntimeRemotesOptions) {
185
+ Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(function(moduleId) {
186
+ var info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
187
+ var externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
188
+ if (info.length > 1) {
189
+ initExternal(externalModuleId);
190
+ } else if (info.length === 1) {
191
+ var remoteInfo = info[0];
192
+ if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
193
+ initExternal(externalModuleId);
194
+ }
195
+ }
196
+ });
197
+ }
198
+ if (!promises.length) {
199
+ return initPromises[shareScopeName] = true;
200
+ }
201
+ return initPromises[shareScopeName] = Promise.all(promises).then(function() {
202
+ return initPromises[shareScopeName] = true;
203
+ });
153
204
  }
154
205
 
155
206
  function handleInitialConsumes(options) {
@@ -159,10 +210,7 @@ function handleInitialConsumes(options) {
159
210
  throw new Error("Federation instance not found!");
160
211
  }
161
212
  var _moduleToHandlerMapping_moduleId = moduleToHandlerMapping[moduleId], shareKey = _moduleToHandlerMapping_moduleId.shareKey, shareInfo = _moduleToHandlerMapping_moduleId.shareInfo;
162
- if (!shareInfo.shareConfig.eager) {
163
- throw new Error('Shared: "'.concat(shareKey, '" cannot be loaded synchronously unless "eager:true" is set or async entry is enabled.'));
164
- }
165
- return federationInstance.loadShareSync(shareKey);
213
+ return federationInstance.loadShareSync(shareKey, shareInfo);
166
214
  }
167
215
  function installInitialConsumes(options) {
168
216
  var moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire, installedModules = options.installedModules, initialConsumes = options.initialConsumes;
@@ -184,6 +232,40 @@ function installInitialConsumes(options) {
184
232
  });
185
233
  }
186
234
 
235
+ function isLegacyHost(shareScope) {
236
+ if ("version" in shareScope && typeof shareScope["version"] !== "object") {
237
+ return true;
238
+ }
239
+ if ("region" in shareScope && typeof shareScope["region"] !== "object") {
240
+ return true;
241
+ }
242
+ return false;
243
+ }
244
+ function initContainerEntry(options) {
245
+ var webpackRequire = options.webpackRequire, shareScope = options.shareScope, initScope = options.initScope, shareScopeKey = options.shareScopeKey;
246
+ if (!webpackRequire.S) return;
247
+ if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
248
+ var name = shareScopeKey || "default";
249
+ webpackRequire.federation.instance.initOptions({
250
+ name: webpackRequire.federation.initOptions.name,
251
+ remotes: []
252
+ });
253
+ if (isLegacyHost(shareScope)) {
254
+ var prevShareScope = globalThis.__FEDERATION__.__SHARE__["default"];
255
+ if (prevShareScope) {
256
+ webpackRequire.federation.instance.initShareScopeMap(name, prevShareScope);
257
+ }
258
+ } else {
259
+ webpackRequire.federation.instance.initShareScopeMap(name, shareScope);
260
+ }
261
+ webpackRequire.S[name] = shareScope;
262
+ if (webpackRequire.federation.attachShareScopeMap) {
263
+ webpackRequire.federation.attachShareScopeMap(webpackRequire);
264
+ }
265
+ // @ts-ignore
266
+ return webpackRequire.I(name, initScope);
267
+ }
268
+
187
269
  var federation = {
188
270
  runtime: runtime,
189
271
  instance: undefined,
@@ -193,8 +275,11 @@ var federation = {
193
275
  consumes: consumes,
194
276
  I: initializeSharing,
195
277
  S: {},
196
- installInitialConsumes: installInitialConsumes
197
- }
278
+ installInitialConsumes: installInitialConsumes,
279
+ initContainerEntry: initContainerEntry
280
+ },
281
+ attachShareScopeMap: attachShareScopeMap,
282
+ bundlerRuntimeOptions: {}
198
283
  };
199
284
 
200
285
  export { 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.5",
4
+ "version": "0.0.7",
5
5
  "license": "MIT",
6
6
  "description": "Module Federation Runtime for webpack",
7
7
  "keywords": [
@@ -18,8 +18,30 @@
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:*"
25
+ },
26
+ "exports": {
27
+ ".": {
28
+ "import": "./dist/index.esm.js",
29
+ "require": "./dist/index.cjs.js"
30
+ },
31
+ "./constant": {
32
+ "import": "./dist/constant.esm.js",
33
+ "require": "./dist/constant.cjs.js"
34
+ },
35
+ "./*": "./*"
36
+ },
37
+ "typesVersions": {
38
+ "*": {
39
+ ".": [
40
+ "./dist/index.cjs.d.ts"
41
+ ],
42
+ "constant": [
43
+ "./dist/constant.cjs.d.ts"
44
+ ]
45
+ }
24
46
  }
25
47
  }
@@ -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 ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
2
+ export declare const FEDERATION_SUPPORTED_TYPES: string[];
@@ -1,3 +1,4 @@
1
1
  import { Federation } from './types';
2
+ export * from './types';
2
3
  declare const federation: Federation;
3
4
  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
+ name: 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-20240103035759",
4
+ "version": "0.0.0-next-20240104093320",
5
5
  "license": "MIT",
6
6
  "description": "Module Federation Runtime for webpack",
7
7
  "keywords": [
@@ -16,10 +16,32 @@
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-20240103035759"
23
+ "@module-federation/runtime": "0.0.0-next-20240104093320",
24
+ "@module-federation/sdk": "0.0.0-next-20240104093320"
25
+ },
26
+ "exports": {
27
+ ".": {
28
+ "import": "./dist/index.esm.js",
29
+ "require": "./dist/index.cjs.js"
30
+ },
31
+ "./constant": {
32
+ "import": "./dist/constant.esm.js",
33
+ "require": "./dist/constant.cjs.js"
34
+ },
35
+ "./*": "./*"
36
+ },
37
+ "typesVersions": {
38
+ "*": {
39
+ ".": [
40
+ "./dist/index.cjs.d.ts"
41
+ ],
42
+ "constant": [
43
+ "./dist/constant.cjs.d.ts"
44
+ ]
45
+ }
24
46
  }
25
47
  }