@module-federation/runtime 0.6.15 → 0.7.0
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/helpers.cjs.js +0 -2
- package/dist/{helpers.esm.js → helpers.esm.mjs} +1 -3
- package/dist/index.cjs.js +60 -61
- package/dist/{index.esm.js → index.esm.mjs} +63 -64
- package/dist/package.json +7 -6
- package/dist/share.cjs.js +13 -5
- package/dist/{share.esm.js → share.esm.mjs} +15 -7
- package/dist/src/core.d.ts +1 -0
- package/dist/src/remote/index.d.ts +1 -1
- package/dist/src/shared/index.d.ts +1 -0
- package/package.json +8 -7
- /package/dist/{embedded.esm.js → embedded.esm.mjs} +0 -0
- /package/dist/{polyfills.esm.js → polyfills.esm.mjs} +0 -0
- /package/dist/{types.esm.js → types.esm.mjs} +0 -0
package/dist/helpers.cjs.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { g as getRegisteredShare, a as getGlobalShareScope, G as Global, n as nativeGlobal, r as resetFederationGlobalInfo, b as getGlobalFederationInstance, s as setGlobalFederationInstance, c as getGlobalFederationConstructor, d as setGlobalFederationConstructor, e as getInfoWithoutType, f as getGlobalSnapshot, h as getTargetSnapshotInfoByModuleInfo, i as getGlobalSnapshotInfoByModuleInfo, j as setGlobalSnapshotInfoByModuleInfo, k as addGlobalSnapshot, l as getRemoteEntryExports, m as registerGlobalPlugins, o as getGlobalHostPlugins, p as getPreloaded, q as setPreloaded } from './share.esm.
|
|
2
|
-
import './polyfills.esm.js';
|
|
3
|
-
import '@module-federation/sdk';
|
|
1
|
+
import { g as getRegisteredShare, a as getGlobalShareScope, G as Global, n as nativeGlobal, r as resetFederationGlobalInfo, b as getGlobalFederationInstance, s as setGlobalFederationInstance, c as getGlobalFederationConstructor, d as setGlobalFederationConstructor, e as getInfoWithoutType, f as getGlobalSnapshot, h as getTargetSnapshotInfoByModuleInfo, i as getGlobalSnapshotInfoByModuleInfo, j as setGlobalSnapshotInfoByModuleInfo, k as addGlobalSnapshot, l as getRemoteEntryExports, m as registerGlobalPlugins, o as getGlobalHostPlugins, p as getPreloaded, q as setPreloaded } from './share.esm.mjs';
|
|
4
2
|
|
|
5
3
|
const ShareUtils = {
|
|
6
4
|
getRegisteredShare,
|
package/dist/index.cjs.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var polyfills = require('./polyfills.cjs.js');
|
|
4
4
|
var sdk = require('@module-federation/sdk');
|
|
5
5
|
var share = require('./share.cjs.js');
|
|
6
|
+
var errorCodes = require('@module-federation/error-codes');
|
|
6
7
|
|
|
7
8
|
// Function to match a remote with its name and expose
|
|
8
9
|
// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
|
|
@@ -123,7 +124,7 @@ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
|
123
124
|
}
|
|
124
125
|
});
|
|
125
126
|
}
|
|
126
|
-
async function loadEntryScript({ name, globalName, entry,
|
|
127
|
+
async function loadEntryScript({ name, globalName, entry, loaderHook }) {
|
|
127
128
|
const { entryExports: remoteEntryExports } = share.getRemoteEntryExports(name, globalName);
|
|
128
129
|
if (remoteEntryExports) {
|
|
129
130
|
return remoteEntryExports;
|
|
@@ -131,7 +132,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
131
132
|
return sdk.loadScript(entry, {
|
|
132
133
|
attrs: {},
|
|
133
134
|
createScriptHook: (url, attrs)=>{
|
|
134
|
-
const res =
|
|
135
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
135
136
|
url,
|
|
136
137
|
attrs
|
|
137
138
|
});
|
|
@@ -146,18 +147,17 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
146
147
|
}
|
|
147
148
|
}).then(()=>{
|
|
148
149
|
const { remoteEntryKey, entryExports } = share.getRemoteEntryExports(name, globalName);
|
|
149
|
-
share.assert(entryExports,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
`);
|
|
150
|
+
share.assert(entryExports, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_001, errorCodes.runtimeDescMap, {
|
|
151
|
+
remoteName: name,
|
|
152
|
+
remoteEntryUrl: entry,
|
|
153
|
+
remoteEntryKey
|
|
154
|
+
}));
|
|
155
155
|
return entryExports;
|
|
156
156
|
}).catch((e)=>{
|
|
157
157
|
throw e;
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
|
-
async function loadEntryDom({ remoteInfo, remoteEntryExports,
|
|
160
|
+
async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook }) {
|
|
161
161
|
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
162
162
|
switch(type){
|
|
163
163
|
case 'esm':
|
|
@@ -176,11 +176,11 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, createScriptHook }
|
|
|
176
176
|
entry,
|
|
177
177
|
globalName,
|
|
178
178
|
name,
|
|
179
|
-
|
|
179
|
+
loaderHook
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
async function loadEntryNode({ remoteInfo,
|
|
183
|
+
async function loadEntryNode({ remoteInfo, loaderHook }) {
|
|
184
184
|
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
185
185
|
const { entryExports: remoteEntryExports } = share.getRemoteEntryExports(name, globalName);
|
|
186
186
|
if (remoteEntryExports) {
|
|
@@ -192,25 +192,26 @@ async function loadEntryNode({ remoteInfo, createScriptHook }) {
|
|
|
192
192
|
globalName,
|
|
193
193
|
type
|
|
194
194
|
},
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
195
|
+
loaderHook: {
|
|
196
|
+
createScriptHook: (url, attrs = {})=>{
|
|
197
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
198
|
+
url,
|
|
199
|
+
attrs
|
|
200
|
+
});
|
|
201
|
+
if (!res) return;
|
|
202
|
+
if ('url' in res) {
|
|
203
|
+
return res;
|
|
204
|
+
}
|
|
205
|
+
return;
|
|
203
206
|
}
|
|
204
|
-
return;
|
|
205
207
|
}
|
|
206
208
|
}).then(()=>{
|
|
207
209
|
const { remoteEntryKey, entryExports } = share.getRemoteEntryExports(name, globalName);
|
|
208
|
-
share.assert(entryExports,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
`);
|
|
210
|
+
share.assert(entryExports, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_001, errorCodes.runtimeDescMap, {
|
|
211
|
+
remoteName: name,
|
|
212
|
+
remoteEntryUrl: entry,
|
|
213
|
+
remoteEntryKey
|
|
214
|
+
}));
|
|
214
215
|
return entryExports;
|
|
215
216
|
}).catch((e)=>{
|
|
216
217
|
throw e;
|
|
@@ -227,9 +228,10 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
|
|
|
227
228
|
}
|
|
228
229
|
if (!share.globalLoading[uniqueKey]) {
|
|
229
230
|
const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
|
|
230
|
-
|
|
231
|
+
origin.loaderHook.lifecycle.createScript;
|
|
232
|
+
const loaderHook = origin.loaderHook;
|
|
231
233
|
share.globalLoading[uniqueKey] = loadEntryHook.emit({
|
|
232
|
-
|
|
234
|
+
loaderHook,
|
|
233
235
|
remoteInfo,
|
|
234
236
|
remoteEntryExports
|
|
235
237
|
}).then((res)=>{
|
|
@@ -239,10 +241,10 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
|
|
|
239
241
|
return sdk.isBrowserEnv() ? loadEntryDom({
|
|
240
242
|
remoteInfo,
|
|
241
243
|
remoteEntryExports,
|
|
242
|
-
|
|
244
|
+
loaderHook
|
|
243
245
|
}) : loadEntryNode({
|
|
244
246
|
remoteInfo,
|
|
245
|
-
|
|
247
|
+
loaderHook
|
|
246
248
|
});
|
|
247
249
|
});
|
|
248
250
|
}
|
|
@@ -305,7 +307,11 @@ let Module = class Module {
|
|
|
305
307
|
origin: this.host
|
|
306
308
|
});
|
|
307
309
|
if (typeof (remoteEntryExports == null ? void 0 : remoteEntryExports.init) === 'undefined') {
|
|
308
|
-
share.
|
|
310
|
+
share.error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_002, errorCodes.runtimeDescMap, {
|
|
311
|
+
remoteName: name,
|
|
312
|
+
remoteEntryUrl: this.remoteInfo.entry,
|
|
313
|
+
remoteEntryKey: this.remoteInfo.entryGlobalName
|
|
314
|
+
}));
|
|
309
315
|
}
|
|
310
316
|
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
311
317
|
await this.host.hooks.lifecycle.initContainer.emit(polyfills._extends({}, initContainerOptions, {
|
|
@@ -1109,12 +1115,11 @@ class SnapshotHandler {
|
|
|
1109
1115
|
globalSnapshot: globalSnapshotRes
|
|
1110
1116
|
};
|
|
1111
1117
|
} else {
|
|
1112
|
-
share.error(
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
`);
|
|
1118
|
+
share.error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_007, errorCodes.runtimeDescMap, {
|
|
1119
|
+
hostName: moduleInfo.name,
|
|
1120
|
+
hostVersion: moduleInfo.version,
|
|
1121
|
+
globalSnapshot: JSON.stringify(globalSnapshotRes)
|
|
1122
|
+
}));
|
|
1118
1123
|
}
|
|
1119
1124
|
}
|
|
1120
1125
|
}
|
|
@@ -1138,9 +1143,10 @@ class SnapshotHandler {
|
|
|
1138
1143
|
return manifestJson;
|
|
1139
1144
|
} catch (err) {
|
|
1140
1145
|
delete this.manifestLoading[manifestUrl];
|
|
1141
|
-
share.error(
|
|
1142
|
-
|
|
1143
|
-
|
|
1146
|
+
share.error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_003, errorCodes.runtimeDescMap, {
|
|
1147
|
+
manifestUrl,
|
|
1148
|
+
moduleName: moduleInfo.name
|
|
1149
|
+
}, `${err}`));
|
|
1144
1150
|
}
|
|
1145
1151
|
};
|
|
1146
1152
|
const asyncLoadProcess = async ()=>{
|
|
@@ -1443,12 +1449,11 @@ class SharedHandler {
|
|
|
1443
1449
|
if (shareInfo.get) {
|
|
1444
1450
|
const module = shareInfo.get();
|
|
1445
1451
|
if (module instanceof Promise) {
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
`);
|
|
1452
|
+
const errorCode = (extraOptions == null ? void 0 : extraOptions.from) === 'build' ? errorCodes.RUNTIME_005 : errorCodes.RUNTIME_006;
|
|
1453
|
+
throw new Error(errorCodes.getShortErrorMsg(errorCode, errorCodes.runtimeDescMap, {
|
|
1454
|
+
hostName: host.options.name,
|
|
1455
|
+
sharedPkgName: pkgName
|
|
1456
|
+
}));
|
|
1452
1457
|
}
|
|
1453
1458
|
shareInfo.lib = module;
|
|
1454
1459
|
this.setShared({
|
|
@@ -1460,12 +1465,10 @@ class SharedHandler {
|
|
|
1460
1465
|
});
|
|
1461
1466
|
return shareInfo.lib;
|
|
1462
1467
|
}
|
|
1463
|
-
throw new Error(
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
2. The ${pkgName} share was not registered with the 'lib' attribute.\n
|
|
1468
|
-
`);
|
|
1468
|
+
throw new Error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_006, errorCodes.runtimeDescMap, {
|
|
1469
|
+
hostName: host.options.name,
|
|
1470
|
+
sharedPkgName: pkgName
|
|
1471
|
+
}));
|
|
1469
1472
|
}
|
|
1470
1473
|
initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
|
|
1471
1474
|
const { host } = this;
|
|
@@ -1685,14 +1688,10 @@ class RemoteHandler {
|
|
|
1685
1688
|
}
|
|
1686
1689
|
const { id: idRes } = loadRemoteArgs;
|
|
1687
1690
|
const remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
|
|
1688
|
-
share.assert(remoteSplitInfo,
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
3. ${idRes} is not online, injected, or loaded.
|
|
1693
|
-
4. ${idRes} cannot be accessed on the expected.
|
|
1694
|
-
5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${idRes}.
|
|
1695
|
-
`);
|
|
1691
|
+
share.assert(remoteSplitInfo, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_004, errorCodes.runtimeDescMap, {
|
|
1692
|
+
hostName: host.options.name,
|
|
1693
|
+
requestId: idRes
|
|
1694
|
+
}));
|
|
1696
1695
|
const { remote: rawRemote } = remoteSplitInfo;
|
|
1697
1696
|
const remoteInfo = getRemoteInfo(rawRemote);
|
|
1698
1697
|
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(polyfills._extends({
|
|
@@ -2000,7 +1999,7 @@ class FederationHost {
|
|
|
2000
1999
|
// maybe will change, temporarily for internal use only
|
|
2001
2000
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2002
2001
|
});
|
|
2003
|
-
this.version = "0.
|
|
2002
|
+
this.version = "0.7.0";
|
|
2004
2003
|
this.moduleCache = new Map();
|
|
2005
2004
|
this.loaderHook = new PluginSystem({
|
|
2006
2005
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { a as _extends, _ as _object_without_properties_loose } from './polyfills.esm.
|
|
1
|
+
import { a as _extends, _ as _object_without_properties_loose } from './polyfills.esm.mjs';
|
|
2
2
|
import { isBrowserEnv, loadScriptNode, composeKeyWithSeparator, loadScript, safeToString, createLink, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1 } from '@module-federation/sdk';
|
|
3
3
|
export { loadScript, loadScriptNode } from '@module-federation/sdk';
|
|
4
|
-
import { o as getGlobalHostPlugins, t as globalLoading, D as DEFAULT_REMOTE_TYPE, u as DEFAULT_SCOPE, l as getRemoteEntryExports, v as assert, w as
|
|
5
|
-
export { m as registerGlobalPlugins } from './share.esm.
|
|
4
|
+
import { o as getGlobalHostPlugins, t as globalLoading, D as DEFAULT_REMOTE_TYPE, u as DEFAULT_SCOPE, l as getRemoteEntryExports, v as assert, w as error, x as getFMId, y as isObject, z as warn, A as isPlainObject, B as isRemoteInfoWithEntry, C as isPureRemoteEntry, E as getRemoteEntryInfoFromSnapshot, e as getInfoWithoutType, p as getPreloaded, q as setPreloaded, g as getRegisteredShare, F as arrayOptions, i as getGlobalSnapshotInfoByModuleInfo, k as addGlobalSnapshot, j as setGlobalSnapshotInfoByModuleInfo, G as Global, f as getGlobalSnapshot, H as formatShareConfigs, I as getTargetSharedOptions, a as getGlobalShareScope, J as addUniqueItem, K as logger, L as getBuilderId, d as setGlobalFederationConstructor, b as getGlobalFederationInstance, c as getGlobalFederationConstructor, s as setGlobalFederationInstance } from './share.esm.mjs';
|
|
5
|
+
export { m as registerGlobalPlugins } from './share.esm.mjs';
|
|
6
|
+
import { getShortErrorMsg, RUNTIME_001, runtimeDescMap, RUNTIME_002, RUNTIME_007, RUNTIME_003, RUNTIME_005, RUNTIME_006, RUNTIME_004 } from '@module-federation/error-codes';
|
|
6
7
|
|
|
7
8
|
// Function to match a remote with its name and expose
|
|
8
9
|
// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
|
|
@@ -123,7 +124,7 @@ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
|
123
124
|
}
|
|
124
125
|
});
|
|
125
126
|
}
|
|
126
|
-
async function loadEntryScript({ name, globalName, entry,
|
|
127
|
+
async function loadEntryScript({ name, globalName, entry, loaderHook }) {
|
|
127
128
|
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
128
129
|
if (remoteEntryExports) {
|
|
129
130
|
return remoteEntryExports;
|
|
@@ -131,7 +132,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
131
132
|
return loadScript(entry, {
|
|
132
133
|
attrs: {},
|
|
133
134
|
createScriptHook: (url, attrs)=>{
|
|
134
|
-
const res =
|
|
135
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
135
136
|
url,
|
|
136
137
|
attrs
|
|
137
138
|
});
|
|
@@ -146,18 +147,17 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
146
147
|
}
|
|
147
148
|
}).then(()=>{
|
|
148
149
|
const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
|
|
149
|
-
assert(entryExports,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
`);
|
|
150
|
+
assert(entryExports, getShortErrorMsg(RUNTIME_001, runtimeDescMap, {
|
|
151
|
+
remoteName: name,
|
|
152
|
+
remoteEntryUrl: entry,
|
|
153
|
+
remoteEntryKey
|
|
154
|
+
}));
|
|
155
155
|
return entryExports;
|
|
156
156
|
}).catch((e)=>{
|
|
157
157
|
throw e;
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
|
-
async function loadEntryDom({ remoteInfo, remoteEntryExports,
|
|
160
|
+
async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook }) {
|
|
161
161
|
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
162
162
|
switch(type){
|
|
163
163
|
case 'esm':
|
|
@@ -176,11 +176,11 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, createScriptHook }
|
|
|
176
176
|
entry,
|
|
177
177
|
globalName,
|
|
178
178
|
name,
|
|
179
|
-
|
|
179
|
+
loaderHook
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
async function loadEntryNode({ remoteInfo,
|
|
183
|
+
async function loadEntryNode({ remoteInfo, loaderHook }) {
|
|
184
184
|
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
185
185
|
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
186
186
|
if (remoteEntryExports) {
|
|
@@ -192,25 +192,26 @@ async function loadEntryNode({ remoteInfo, createScriptHook }) {
|
|
|
192
192
|
globalName,
|
|
193
193
|
type
|
|
194
194
|
},
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
195
|
+
loaderHook: {
|
|
196
|
+
createScriptHook: (url, attrs = {})=>{
|
|
197
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
198
|
+
url,
|
|
199
|
+
attrs
|
|
200
|
+
});
|
|
201
|
+
if (!res) return;
|
|
202
|
+
if ('url' in res) {
|
|
203
|
+
return res;
|
|
204
|
+
}
|
|
205
|
+
return;
|
|
203
206
|
}
|
|
204
|
-
return;
|
|
205
207
|
}
|
|
206
208
|
}).then(()=>{
|
|
207
209
|
const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
|
|
208
|
-
assert(entryExports,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
`);
|
|
210
|
+
assert(entryExports, getShortErrorMsg(RUNTIME_001, runtimeDescMap, {
|
|
211
|
+
remoteName: name,
|
|
212
|
+
remoteEntryUrl: entry,
|
|
213
|
+
remoteEntryKey
|
|
214
|
+
}));
|
|
214
215
|
return entryExports;
|
|
215
216
|
}).catch((e)=>{
|
|
216
217
|
throw e;
|
|
@@ -227,9 +228,10 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
|
|
|
227
228
|
}
|
|
228
229
|
if (!globalLoading[uniqueKey]) {
|
|
229
230
|
const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
|
|
230
|
-
|
|
231
|
+
origin.loaderHook.lifecycle.createScript;
|
|
232
|
+
const loaderHook = origin.loaderHook;
|
|
231
233
|
globalLoading[uniqueKey] = loadEntryHook.emit({
|
|
232
|
-
|
|
234
|
+
loaderHook,
|
|
233
235
|
remoteInfo,
|
|
234
236
|
remoteEntryExports
|
|
235
237
|
}).then((res)=>{
|
|
@@ -239,10 +241,10 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
|
|
|
239
241
|
return isBrowserEnv() ? loadEntryDom({
|
|
240
242
|
remoteInfo,
|
|
241
243
|
remoteEntryExports,
|
|
242
|
-
|
|
244
|
+
loaderHook
|
|
243
245
|
}) : loadEntryNode({
|
|
244
246
|
remoteInfo,
|
|
245
|
-
|
|
247
|
+
loaderHook
|
|
246
248
|
});
|
|
247
249
|
});
|
|
248
250
|
}
|
|
@@ -305,7 +307,11 @@ let Module = class Module {
|
|
|
305
307
|
origin: this.host
|
|
306
308
|
});
|
|
307
309
|
if (typeof (remoteEntryExports == null ? void 0 : remoteEntryExports.init) === 'undefined') {
|
|
308
|
-
|
|
310
|
+
error(getShortErrorMsg(RUNTIME_002, runtimeDescMap, {
|
|
311
|
+
remoteName: name,
|
|
312
|
+
remoteEntryUrl: this.remoteInfo.entry,
|
|
313
|
+
remoteEntryKey: this.remoteInfo.entryGlobalName
|
|
314
|
+
}));
|
|
309
315
|
}
|
|
310
316
|
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
311
317
|
await this.host.hooks.lifecycle.initContainer.emit(_extends({}, initContainerOptions, {
|
|
@@ -1109,12 +1115,11 @@ class SnapshotHandler {
|
|
|
1109
1115
|
globalSnapshot: globalSnapshotRes
|
|
1110
1116
|
};
|
|
1111
1117
|
} else {
|
|
1112
|
-
error(
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
`);
|
|
1118
|
+
error(getShortErrorMsg(RUNTIME_007, runtimeDescMap, {
|
|
1119
|
+
hostName: moduleInfo.name,
|
|
1120
|
+
hostVersion: moduleInfo.version,
|
|
1121
|
+
globalSnapshot: JSON.stringify(globalSnapshotRes)
|
|
1122
|
+
}));
|
|
1118
1123
|
}
|
|
1119
1124
|
}
|
|
1120
1125
|
}
|
|
@@ -1138,9 +1143,10 @@ class SnapshotHandler {
|
|
|
1138
1143
|
return manifestJson;
|
|
1139
1144
|
} catch (err) {
|
|
1140
1145
|
delete this.manifestLoading[manifestUrl];
|
|
1141
|
-
error(
|
|
1142
|
-
|
|
1143
|
-
|
|
1146
|
+
error(getShortErrorMsg(RUNTIME_003, runtimeDescMap, {
|
|
1147
|
+
manifestUrl,
|
|
1148
|
+
moduleName: moduleInfo.name
|
|
1149
|
+
}, `${err}`));
|
|
1144
1150
|
}
|
|
1145
1151
|
};
|
|
1146
1152
|
const asyncLoadProcess = async ()=>{
|
|
@@ -1443,12 +1449,11 @@ class SharedHandler {
|
|
|
1443
1449
|
if (shareInfo.get) {
|
|
1444
1450
|
const module = shareInfo.get();
|
|
1445
1451
|
if (module instanceof Promise) {
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
`);
|
|
1452
|
+
const errorCode = (extraOptions == null ? void 0 : extraOptions.from) === 'build' ? RUNTIME_005 : RUNTIME_006;
|
|
1453
|
+
throw new Error(getShortErrorMsg(errorCode, runtimeDescMap, {
|
|
1454
|
+
hostName: host.options.name,
|
|
1455
|
+
sharedPkgName: pkgName
|
|
1456
|
+
}));
|
|
1452
1457
|
}
|
|
1453
1458
|
shareInfo.lib = module;
|
|
1454
1459
|
this.setShared({
|
|
@@ -1460,12 +1465,10 @@ class SharedHandler {
|
|
|
1460
1465
|
});
|
|
1461
1466
|
return shareInfo.lib;
|
|
1462
1467
|
}
|
|
1463
|
-
throw new Error(
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
2. The ${pkgName} share was not registered with the 'lib' attribute.\n
|
|
1468
|
-
`);
|
|
1468
|
+
throw new Error(getShortErrorMsg(RUNTIME_006, runtimeDescMap, {
|
|
1469
|
+
hostName: host.options.name,
|
|
1470
|
+
sharedPkgName: pkgName
|
|
1471
|
+
}));
|
|
1469
1472
|
}
|
|
1470
1473
|
initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
|
|
1471
1474
|
const { host } = this;
|
|
@@ -1685,14 +1688,10 @@ class RemoteHandler {
|
|
|
1685
1688
|
}
|
|
1686
1689
|
const { id: idRes } = loadRemoteArgs;
|
|
1687
1690
|
const remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
|
|
1688
|
-
assert(remoteSplitInfo,
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
3. ${idRes} is not online, injected, or loaded.
|
|
1693
|
-
4. ${idRes} cannot be accessed on the expected.
|
|
1694
|
-
5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${idRes}.
|
|
1695
|
-
`);
|
|
1691
|
+
assert(remoteSplitInfo, getShortErrorMsg(RUNTIME_004, runtimeDescMap, {
|
|
1692
|
+
hostName: host.options.name,
|
|
1693
|
+
requestId: idRes
|
|
1694
|
+
}));
|
|
1696
1695
|
const { remote: rawRemote } = remoteSplitInfo;
|
|
1697
1696
|
const remoteInfo = getRemoteInfo(rawRemote);
|
|
1698
1697
|
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends({
|
|
@@ -2000,7 +1999,7 @@ class FederationHost {
|
|
|
2000
1999
|
// maybe will change, temporarily for internal use only
|
|
2001
2000
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2002
2001
|
});
|
|
2003
|
-
this.version = "0.
|
|
2002
|
+
this.version = "0.7.0";
|
|
2004
2003
|
this.moduleCache = new Map();
|
|
2005
2004
|
this.loaderHook = new PluginSystem({
|
|
2006
2005
|
// FIXME: may not be suitable , not open to the public yet
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./index.cjs.js",
|
|
6
6
|
"module": "./index.esm.js",
|
|
@@ -16,22 +16,22 @@
|
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./dist/index.cjs.d.ts",
|
|
19
|
-
"import": "./dist/index.esm.
|
|
19
|
+
"import": "./dist/index.esm.mjs",
|
|
20
20
|
"require": "./dist/index.cjs.js"
|
|
21
21
|
},
|
|
22
22
|
"./helpers": {
|
|
23
23
|
"types": "./dist/helpers.cjs.d.ts",
|
|
24
|
-
"import": "./dist/helpers.esm.
|
|
24
|
+
"import": "./dist/helpers.esm.mjs",
|
|
25
25
|
"require": "./dist/helpers.cjs.js"
|
|
26
26
|
},
|
|
27
27
|
"./types": {
|
|
28
28
|
"types": "./dist/types.cjs.d.ts",
|
|
29
|
-
"import": "./dist/types.esm.
|
|
29
|
+
"import": "./dist/types.esm.mjs",
|
|
30
30
|
"require": "./dist/types.cjs.js"
|
|
31
31
|
},
|
|
32
32
|
"./embedded": {
|
|
33
33
|
"types": "./dist/embedded.cjs.d.ts",
|
|
34
|
-
"import": "./dist/embedded.esm.
|
|
34
|
+
"import": "./dist/embedded.esm.mjs",
|
|
35
35
|
"require": "./dist/embedded.cjs.js"
|
|
36
36
|
},
|
|
37
37
|
"./*": "./*"
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@module-federation/sdk": "workspace:*"
|
|
53
|
+
"@module-federation/sdk": "workspace:*",
|
|
54
|
+
"@module-federation/error-codes": "workspace:*"
|
|
54
55
|
}
|
|
55
56
|
}
|
package/dist/share.cjs.js
CHANGED
|
@@ -92,8 +92,10 @@ function getRemoteEntryInfoFromSnapshot(snapshot) {
|
|
|
92
92
|
|
|
93
93
|
const nativeGlobal = (()=>{
|
|
94
94
|
try {
|
|
95
|
-
|
|
95
|
+
// get real window (incase of sandbox)
|
|
96
|
+
return document.defaultView;
|
|
96
97
|
} catch (e) {
|
|
98
|
+
// node env
|
|
97
99
|
return globalThis;
|
|
98
100
|
}
|
|
99
101
|
})();
|
|
@@ -177,7 +179,7 @@ function getGlobalFederationConstructor() {
|
|
|
177
179
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = sdk.isDebugMode()) {
|
|
178
180
|
if (isDebug) {
|
|
179
181
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
180
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.
|
|
182
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.7.0";
|
|
181
183
|
}
|
|
182
184
|
}
|
|
183
185
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -763,6 +765,9 @@ const findVersion = (shareVersionMap, cb)=>{
|
|
|
763
765
|
const isLoaded = (shared)=>{
|
|
764
766
|
return Boolean(shared.loaded) || typeof shared.lib === 'function';
|
|
765
767
|
};
|
|
768
|
+
const isLoading = (shared)=>{
|
|
769
|
+
return Boolean(shared.loading);
|
|
770
|
+
};
|
|
766
771
|
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
767
772
|
const versions = shareScopeMap[scope][pkgName];
|
|
768
773
|
const callback = function(prev, cur) {
|
|
@@ -773,14 +778,17 @@ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
|
773
778
|
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
774
779
|
const versions = shareScopeMap[scope][pkgName];
|
|
775
780
|
const callback = function(prev, cur) {
|
|
776
|
-
|
|
777
|
-
|
|
781
|
+
const isLoadingOrLoaded = (shared)=>{
|
|
782
|
+
return isLoaded(shared) || isLoading(shared);
|
|
783
|
+
};
|
|
784
|
+
if (isLoadingOrLoaded(versions[cur])) {
|
|
785
|
+
if (isLoadingOrLoaded(versions[prev])) {
|
|
778
786
|
return Boolean(versionLt(prev, cur));
|
|
779
787
|
} else {
|
|
780
788
|
return true;
|
|
781
789
|
}
|
|
782
790
|
}
|
|
783
|
-
if (
|
|
791
|
+
if (isLoadingOrLoaded(versions[prev])) {
|
|
784
792
|
return false;
|
|
785
793
|
}
|
|
786
794
|
return versionLt(prev, cur);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as _object_without_properties_loose, a as _extends } from './polyfills.esm.
|
|
1
|
+
import { _ as _object_without_properties_loose, a as _extends } from './polyfills.esm.mjs';
|
|
2
2
|
import { createLogger, isBrowserEnv, isDebugMode } from '@module-federation/sdk';
|
|
3
3
|
|
|
4
4
|
function getBuilderId() {
|
|
@@ -90,8 +90,10 @@ function getRemoteEntryInfoFromSnapshot(snapshot) {
|
|
|
90
90
|
|
|
91
91
|
const nativeGlobal = (()=>{
|
|
92
92
|
try {
|
|
93
|
-
|
|
93
|
+
// get real window (incase of sandbox)
|
|
94
|
+
return document.defaultView;
|
|
94
95
|
} catch (e) {
|
|
96
|
+
// node env
|
|
95
97
|
return globalThis;
|
|
96
98
|
}
|
|
97
99
|
})();
|
|
@@ -175,7 +177,7 @@ function getGlobalFederationConstructor() {
|
|
|
175
177
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
176
178
|
if (isDebug) {
|
|
177
179
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
178
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.
|
|
180
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.7.0";
|
|
179
181
|
}
|
|
180
182
|
}
|
|
181
183
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -761,6 +763,9 @@ const findVersion = (shareVersionMap, cb)=>{
|
|
|
761
763
|
const isLoaded = (shared)=>{
|
|
762
764
|
return Boolean(shared.loaded) || typeof shared.lib === 'function';
|
|
763
765
|
};
|
|
766
|
+
const isLoading = (shared)=>{
|
|
767
|
+
return Boolean(shared.loading);
|
|
768
|
+
};
|
|
764
769
|
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
765
770
|
const versions = shareScopeMap[scope][pkgName];
|
|
766
771
|
const callback = function(prev, cur) {
|
|
@@ -771,14 +776,17 @@ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
|
771
776
|
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
772
777
|
const versions = shareScopeMap[scope][pkgName];
|
|
773
778
|
const callback = function(prev, cur) {
|
|
774
|
-
|
|
775
|
-
|
|
779
|
+
const isLoadingOrLoaded = (shared)=>{
|
|
780
|
+
return isLoaded(shared) || isLoading(shared);
|
|
781
|
+
};
|
|
782
|
+
if (isLoadingOrLoaded(versions[cur])) {
|
|
783
|
+
if (isLoadingOrLoaded(versions[prev])) {
|
|
776
784
|
return Boolean(versionLt(prev, cur));
|
|
777
785
|
} else {
|
|
778
786
|
return true;
|
|
779
787
|
}
|
|
780
788
|
}
|
|
781
|
-
if (
|
|
789
|
+
if (isLoadingOrLoaded(versions[prev])) {
|
|
782
790
|
return false;
|
|
783
791
|
}
|
|
784
792
|
return versionLt(prev, cur);
|
|
@@ -867,4 +875,4 @@ function getTargetSharedOptions(options) {
|
|
|
867
875
|
return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
|
|
868
876
|
}
|
|
869
877
|
|
|
870
|
-
export {
|
|
878
|
+
export { isPlainObject as A, isRemoteInfoWithEntry as B, isPureRemoteEntry as C, DEFAULT_REMOTE_TYPE as D, getRemoteEntryInfoFromSnapshot as E, arrayOptions as F, Global as G, formatShareConfigs as H, getTargetSharedOptions as I, addUniqueItem as J, logger as K, getBuilderId as L, getGlobalShareScope as a, getGlobalFederationInstance as b, getGlobalFederationConstructor as c, setGlobalFederationConstructor as d, getInfoWithoutType as e, getGlobalSnapshot as f, getRegisteredShare as g, getTargetSnapshotInfoByModuleInfo as h, getGlobalSnapshotInfoByModuleInfo as i, setGlobalSnapshotInfoByModuleInfo as j, addGlobalSnapshot as k, getRemoteEntryExports as l, registerGlobalPlugins as m, nativeGlobal as n, getGlobalHostPlugins as o, getPreloaded as p, setPreloaded as q, resetFederationGlobalInfo as r, setGlobalFederationInstance as s, globalLoading as t, DEFAULT_SCOPE as u, assert as v, error as w, getFMId as x, isObject as y, warn as z };
|
package/dist/src/core.d.ts
CHANGED
|
@@ -74,6 +74,7 @@ export declare class FederationHost {
|
|
|
74
74
|
}): Promise<false | (() => T | undefined)>;
|
|
75
75
|
loadShareSync<T>(pkgName: string, extraOptions?: {
|
|
76
76
|
customShareInfo?: Partial<Shared>;
|
|
77
|
+
from?: 'build' | 'runtime';
|
|
77
78
|
resolver?: (sharedOptions: ShareInfos[string]) => Shared;
|
|
78
79
|
}): () => T | never;
|
|
79
80
|
initializeSharing(shareScopeName?: string, extraOptions?: {
|
|
@@ -79,7 +79,7 @@ export declare class RemoteHandler {
|
|
|
79
79
|
origin: FederationHost;
|
|
80
80
|
}, false | void | Promise<false | void>>;
|
|
81
81
|
loadEntry: AsyncHook<[{
|
|
82
|
-
|
|
82
|
+
loaderHook: FederationHost["loaderHook"];
|
|
83
83
|
remoteInfo: RemoteInfo;
|
|
84
84
|
remoteEntryExports?: RemoteEntryExports;
|
|
85
85
|
}], Promise<RemoteEntryExports>>;
|
|
@@ -54,6 +54,7 @@ export declare class SharedHandler {
|
|
|
54
54
|
strategy?: ShareStrategy;
|
|
55
55
|
}): Array<Promise<void>>;
|
|
56
56
|
loadShareSync<T>(pkgName: string, extraOptions?: {
|
|
57
|
+
from?: 'build' | 'runtime';
|
|
57
58
|
customShareInfo?: Partial<Shared>;
|
|
58
59
|
resolver?: (sharedOptions: ShareInfos[string]) => Shared;
|
|
59
60
|
}): () => T | never;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
|
-
"module": "./dist/index.esm.
|
|
6
|
+
"module": "./dist/index.esm.mjs",
|
|
7
7
|
"types": "./dist/index.cjs.d.ts",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"publishConfig": {
|
|
@@ -16,22 +16,22 @@
|
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./dist/index.cjs.d.ts",
|
|
19
|
-
"import": "./dist/index.esm.
|
|
19
|
+
"import": "./dist/index.esm.mjs",
|
|
20
20
|
"require": "./dist/index.cjs.js"
|
|
21
21
|
},
|
|
22
22
|
"./helpers": {
|
|
23
23
|
"types": "./dist/helpers.cjs.d.ts",
|
|
24
|
-
"import": "./dist/helpers.esm.
|
|
24
|
+
"import": "./dist/helpers.esm.mjs",
|
|
25
25
|
"require": "./dist/helpers.cjs.js"
|
|
26
26
|
},
|
|
27
27
|
"./types": {
|
|
28
28
|
"types": "./dist/types.cjs.d.ts",
|
|
29
|
-
"import": "./dist/types.esm.
|
|
29
|
+
"import": "./dist/types.esm.mjs",
|
|
30
30
|
"require": "./dist/types.cjs.js"
|
|
31
31
|
},
|
|
32
32
|
"./embedded": {
|
|
33
33
|
"types": "./dist/embedded.cjs.d.ts",
|
|
34
|
-
"import": "./dist/embedded.esm.
|
|
34
|
+
"import": "./dist/embedded.esm.mjs",
|
|
35
35
|
"require": "./dist/embedded.cjs.js"
|
|
36
36
|
},
|
|
37
37
|
"./*": "./*"
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@module-federation/sdk": "0.
|
|
53
|
+
"@module-federation/sdk": "0.7.0",
|
|
54
|
+
"@module-federation/error-codes": "0.7.0"
|
|
54
55
|
}
|
|
55
56
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|