@module-federation/webpack-bundler-runtime 0.0.0-next-20231225064454 → 0.0.0-next-20231225073141

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 FEDERATION_SUPPORTED_TYPES = [
6
+ "script"
7
+ ];
8
+ var ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
9
+
10
+ exports.ENCODE_NAME_PREFIX = ENCODE_NAME_PREFIX;
11
+ exports.FEDERATION_SUPPORTED_TYPES = FEDERATION_SUPPORTED_TYPES;
@@ -0,0 +1,6 @@
1
+ var FEDERATION_SUPPORTED_TYPES = [
2
+ "script"
3
+ ];
4
+ var ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
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,7 +99,8 @@ 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
105
  loadFactory: false
96
106
  });
@@ -98,6 +108,9 @@ function remotes(options) {
98
108
  onError(error);
99
109
  }
100
110
  };
111
+ var useRuntimeLoad = remoteInfos.length === 1 && [
112
+ "script"
113
+ ].includes(remoteInfos[0].externalType) && remoteInfos[0].name;
101
114
  if (useRuntimeLoad) {
102
115
  handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);
103
116
  } else {
@@ -107,25 +120,9 @@ function remotes(options) {
107
120
  }
108
121
  }
109
122
 
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
123
  function consumes(options) {
127
124
  var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
128
- proxyShareScopeMap(webpackRequire);
125
+ attachShareScopeMap(webpackRequire);
129
126
  if (webpackRequire.o(chunkMapping, chunkId)) {
130
127
  chunkMapping[chunkId].forEach(function(id) {
131
128
  if (webpackRequire.o(installedModules, id)) {
@@ -170,8 +167,61 @@ function consumes(options) {
170
167
  }
171
168
  }
172
169
 
173
- function initializeSharing(shareScopeName, webpackRequire) {
174
- return webpackRequire.federation.instance.initializeSharing(shareScopeName);
170
+ function initializeSharing(param) {
171
+ var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
172
+ if (!initScope) initScope = [];
173
+ // handling circular init calls
174
+ var initToken = initTokens[shareScopeName];
175
+ if (!initToken) initToken = initTokens[shareScopeName] = {};
176
+ if (initScope.indexOf(initToken) >= 0) return;
177
+ initScope.push(initToken);
178
+ var promise = initPromises[shareScopeName];
179
+ if (promise) return promise;
180
+ var warn = function(msg) {
181
+ return typeof console !== "undefined" && console.warn && console.warn(msg);
182
+ };
183
+ var initExternal = function(id) {
184
+ var handleError = function(err) {
185
+ return warn("Initialization of sharing external failed: " + err);
186
+ };
187
+ try {
188
+ var module = webpackRequire(id);
189
+ if (!module) return;
190
+ var initFn = function(module) {
191
+ return module && module.init && module.init(webpackRequire.S[shareScopeName], initScope);
192
+ };
193
+ if (module.then) return promises.push(module.then(initFn, handleError));
194
+ var initResult = initFn(module);
195
+ // @ts-ignore
196
+ if (initResult && typeof initResult !== "boolean" && initResult.then) // @ts-ignore
197
+ return promises.push(initResult["catch"](handleError));
198
+ } catch (err) {
199
+ handleError(err);
200
+ }
201
+ };
202
+ var promises = webpackRequire.federation.instance.initializeSharing(shareScopeName);
203
+ attachShareScopeMap(webpackRequire);
204
+ var bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
205
+ if (bundlerRuntimeRemotesOptions) {
206
+ Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(function(moduleId) {
207
+ var info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
208
+ var externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
209
+ if (info.length > 1) {
210
+ initExternal(externalModuleId);
211
+ } else if (info.length === 1) {
212
+ var remoteInfo = info[0];
213
+ if (!constant.FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
214
+ initExternal(externalModuleId);
215
+ }
216
+ }
217
+ });
218
+ }
219
+ if (!promises.length) {
220
+ return initPromises[shareScopeName] = true;
221
+ }
222
+ return initPromises[shareScopeName] = Promise.all(promises).then(function() {
223
+ return initPromises[shareScopeName] = true;
224
+ });
175
225
  }
176
226
 
177
227
  function handleInitialConsumes(options) {
@@ -206,6 +256,40 @@ function installInitialConsumes(options) {
206
256
  });
207
257
  }
208
258
 
259
+ function isLegacyHost(shareScope) {
260
+ if ("version" in shareScope && typeof shareScope["version"] !== "object") {
261
+ return true;
262
+ }
263
+ if ("region" in shareScope && typeof shareScope["region"] !== "object") {
264
+ return true;
265
+ }
266
+ return false;
267
+ }
268
+ function initContainerEntry(options) {
269
+ var webpackRequire = options.webpackRequire, shareScope = options.shareScope, initScope = options.initScope, shareScopeKey = options.shareScopeKey;
270
+ if (!webpackRequire.S) return;
271
+ if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
272
+ var name = shareScopeKey || "default";
273
+ webpackRequire.federation.instance.initOptions({
274
+ name: webpackRequire.federation.initOptions.name,
275
+ remotes: []
276
+ });
277
+ if (isLegacyHost(shareScope)) {
278
+ var prevShareScope = globalThis.__FEDERATION__.__SHARE__["default"];
279
+ if (prevShareScope) {
280
+ webpackRequire.federation.instance.initShareScopeMap(name, prevShareScope);
281
+ }
282
+ } else {
283
+ webpackRequire.federation.instance.initShareScopeMap(name, shareScope);
284
+ }
285
+ webpackRequire.S[name] = shareScope;
286
+ if (webpackRequire.federation.attachShareScopeMap) {
287
+ webpackRequire.federation.attachShareScopeMap(webpackRequire);
288
+ }
289
+ // @ts-ignore
290
+ return webpackRequire.I(name, initScope);
291
+ }
292
+
209
293
  var federation = {
210
294
  runtime: runtime__namespace,
211
295
  instance: undefined,
@@ -215,8 +299,11 @@ var federation = {
215
299
  consumes: consumes,
216
300
  I: initializeSharing,
217
301
  S: {},
218
- installInitialConsumes: installInitialConsumes
219
- }
302
+ installInitialConsumes: installInitialConsumes,
303
+ initContainerEntry: initContainerEntry
304
+ },
305
+ attachShareScopeMap: attachShareScopeMap,
306
+ bundlerRuntimeOptions: {}
220
307
  };
221
308
 
222
309
  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,7 +77,8 @@ 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
83
  loadFactory: false
74
84
  });
@@ -76,6 +86,9 @@ function remotes(options) {
76
86
  onError(error);
77
87
  }
78
88
  };
89
+ var useRuntimeLoad = remoteInfos.length === 1 && [
90
+ "script"
91
+ ].includes(remoteInfos[0].externalType) && remoteInfos[0].name;
79
92
  if (useRuntimeLoad) {
80
93
  handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);
81
94
  } else {
@@ -85,25 +98,9 @@ function remotes(options) {
85
98
  }
86
99
  }
87
100
 
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
101
  function consumes(options) {
105
102
  var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
106
- proxyShareScopeMap(webpackRequire);
103
+ attachShareScopeMap(webpackRequire);
107
104
  if (webpackRequire.o(chunkMapping, chunkId)) {
108
105
  chunkMapping[chunkId].forEach(function(id) {
109
106
  if (webpackRequire.o(installedModules, id)) {
@@ -148,8 +145,61 @@ function consumes(options) {
148
145
  }
149
146
  }
150
147
 
151
- function initializeSharing(shareScopeName, webpackRequire) {
152
- return webpackRequire.federation.instance.initializeSharing(shareScopeName);
148
+ function initializeSharing(param) {
149
+ var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
150
+ if (!initScope) initScope = [];
151
+ // handling circular init calls
152
+ var initToken = initTokens[shareScopeName];
153
+ if (!initToken) initToken = initTokens[shareScopeName] = {};
154
+ if (initScope.indexOf(initToken) >= 0) return;
155
+ initScope.push(initToken);
156
+ var promise = initPromises[shareScopeName];
157
+ if (promise) return promise;
158
+ var warn = function(msg) {
159
+ return typeof console !== "undefined" && console.warn && console.warn(msg);
160
+ };
161
+ var initExternal = function(id) {
162
+ var handleError = function(err) {
163
+ return warn("Initialization of sharing external failed: " + err);
164
+ };
165
+ try {
166
+ var module = webpackRequire(id);
167
+ if (!module) return;
168
+ var initFn = function(module) {
169
+ return module && module.init && module.init(webpackRequire.S[shareScopeName], initScope);
170
+ };
171
+ if (module.then) return promises.push(module.then(initFn, handleError));
172
+ var initResult = initFn(module);
173
+ // @ts-ignore
174
+ if (initResult && typeof initResult !== "boolean" && initResult.then) // @ts-ignore
175
+ return promises.push(initResult["catch"](handleError));
176
+ } catch (err) {
177
+ handleError(err);
178
+ }
179
+ };
180
+ var promises = webpackRequire.federation.instance.initializeSharing(shareScopeName);
181
+ attachShareScopeMap(webpackRequire);
182
+ var bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
183
+ if (bundlerRuntimeRemotesOptions) {
184
+ Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(function(moduleId) {
185
+ var info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
186
+ var externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
187
+ if (info.length > 1) {
188
+ initExternal(externalModuleId);
189
+ } else if (info.length === 1) {
190
+ var remoteInfo = info[0];
191
+ if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
192
+ initExternal(externalModuleId);
193
+ }
194
+ }
195
+ });
196
+ }
197
+ if (!promises.length) {
198
+ return initPromises[shareScopeName] = true;
199
+ }
200
+ return initPromises[shareScopeName] = Promise.all(promises).then(function() {
201
+ return initPromises[shareScopeName] = true;
202
+ });
153
203
  }
154
204
 
155
205
  function handleInitialConsumes(options) {
@@ -184,6 +234,40 @@ function installInitialConsumes(options) {
184
234
  });
185
235
  }
186
236
 
237
+ function isLegacyHost(shareScope) {
238
+ if ("version" in shareScope && typeof shareScope["version"] !== "object") {
239
+ return true;
240
+ }
241
+ if ("region" in shareScope && typeof shareScope["region"] !== "object") {
242
+ return true;
243
+ }
244
+ return false;
245
+ }
246
+ function initContainerEntry(options) {
247
+ var webpackRequire = options.webpackRequire, shareScope = options.shareScope, initScope = options.initScope, shareScopeKey = options.shareScopeKey;
248
+ if (!webpackRequire.S) return;
249
+ if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
250
+ var name = shareScopeKey || "default";
251
+ webpackRequire.federation.instance.initOptions({
252
+ name: webpackRequire.federation.initOptions.name,
253
+ remotes: []
254
+ });
255
+ if (isLegacyHost(shareScope)) {
256
+ var prevShareScope = globalThis.__FEDERATION__.__SHARE__["default"];
257
+ if (prevShareScope) {
258
+ webpackRequire.federation.instance.initShareScopeMap(name, prevShareScope);
259
+ }
260
+ } else {
261
+ webpackRequire.federation.instance.initShareScopeMap(name, shareScope);
262
+ }
263
+ webpackRequire.S[name] = shareScope;
264
+ if (webpackRequire.federation.attachShareScopeMap) {
265
+ webpackRequire.federation.attachShareScopeMap(webpackRequire);
266
+ }
267
+ // @ts-ignore
268
+ return webpackRequire.I(name, initScope);
269
+ }
270
+
187
271
  var federation = {
188
272
  runtime: runtime,
189
273
  instance: undefined,
@@ -193,8 +277,11 @@ var federation = {
193
277
  consumes: consumes,
194
278
  I: initializeSharing,
195
279
  S: {},
196
- installInitialConsumes: installInitialConsumes
197
- }
280
+ installInitialConsumes: installInitialConsumes,
281
+ initContainerEntry: initContainerEntry
282
+ },
283
+ attachShareScopeMap: attachShareScopeMap,
284
+ bundlerRuntimeOptions: {}
198
285
  };
199
286
 
200
287
  export { federation as default };
package/dist/package.json CHANGED
@@ -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 FEDERATION_SUPPORTED_TYPES: string[];
2
+ export declare const ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
@@ -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-20231225064454",
4
+ "version": "0.0.0-next-20231225073141",
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-20231225064454"
23
+ "@module-federation/runtime": "0.0.0-next-20231225073141",
24
+ "@module-federation/sdk": "0.0.0-next-20231225073141"
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
  }