@module-federation/runtime-core 2.0.0 → 2.1.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/README.md +1 -1
- package/dist/_virtual/_rolldown/runtime.cjs +19 -0
- package/dist/_virtual/_rolldown/runtime.js +18 -0
- package/dist/constant.cjs +9 -0
- package/dist/constant.cjs.map +1 -0
- package/dist/constant.js +7 -0
- package/dist/constant.js.map +1 -0
- package/dist/core.cjs +153 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.ts +132 -0
- package/dist/core.js +153 -0
- package/dist/core.js.map +1 -0
- package/dist/global.cjs +160 -0
- package/dist/global.cjs.map +1 -0
- package/dist/global.d.ts +46 -0
- package/dist/global.js +142 -0
- package/dist/global.js.map +1 -0
- package/dist/helpers.cjs +44 -0
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.ts +32 -0
- package/dist/helpers.js +44 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.cjs +59 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +30 -1
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/module/index.cjs +128 -0
- package/dist/module/index.cjs.map +1 -0
- package/dist/module/index.d.ts +32 -0
- package/dist/module/index.js +128 -0
- package/dist/module/index.js.map +1 -0
- package/dist/plugins/generate-preload-assets.cjs +182 -0
- package/dist/plugins/generate-preload-assets.cjs.map +1 -0
- package/dist/plugins/generate-preload-assets.js +182 -0
- package/dist/plugins/generate-preload-assets.js.map +1 -0
- package/dist/plugins/snapshot/SnapshotHandler.cjs +184 -0
- package/dist/plugins/snapshot/SnapshotHandler.cjs.map +1 -0
- package/dist/plugins/snapshot/SnapshotHandler.d.ts +68 -0
- package/dist/plugins/snapshot/SnapshotHandler.js +183 -0
- package/dist/plugins/snapshot/SnapshotHandler.js.map +1 -0
- package/dist/plugins/snapshot/index.cjs +62 -0
- package/dist/plugins/snapshot/index.cjs.map +1 -0
- package/dist/plugins/snapshot/index.js +61 -0
- package/dist/plugins/snapshot/index.js.map +1 -0
- package/dist/remote/index.cjs +303 -0
- package/dist/remote/index.cjs.map +1 -0
- package/dist/remote/index.d.ts +121 -0
- package/dist/remote/index.js +303 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/shared/index.cjs +304 -0
- package/dist/shared/index.cjs.map +1 -0
- package/dist/shared/index.d.ts +85 -0
- package/dist/shared/index.js +304 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/type/config.d.ts +130 -0
- package/dist/type/index.cjs +13 -0
- package/dist/type/index.cjs.map +1 -0
- package/dist/type/index.d.ts +11 -0
- package/dist/type/index.js +8 -0
- package/dist/type/index.js.map +1 -0
- package/dist/type/plugin.d.ts +27 -0
- package/dist/type/preload.d.ts +31 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +5 -1
- package/dist/types.js +1 -0
- package/dist/utils/env.cjs +10 -0
- package/dist/utils/env.cjs.map +1 -0
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/env.js +10 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/hooks/asyncHook.cjs +23 -0
- package/dist/utils/hooks/asyncHook.cjs.map +1 -0
- package/dist/utils/hooks/asyncHook.d.ts +10 -0
- package/dist/utils/hooks/asyncHook.js +23 -0
- package/dist/utils/hooks/asyncHook.js.map +1 -0
- package/dist/utils/hooks/asyncWaterfallHooks.cjs +42 -0
- package/dist/utils/hooks/asyncWaterfallHooks.cjs.map +1 -0
- package/dist/utils/hooks/asyncWaterfallHooks.d.ts +12 -0
- package/dist/utils/hooks/asyncWaterfallHooks.js +42 -0
- package/dist/utils/hooks/asyncWaterfallHooks.js.map +1 -0
- package/dist/utils/hooks/index.cjs +5 -0
- package/dist/utils/hooks/index.d.ts +5 -0
- package/dist/utils/hooks/index.js +7 -0
- package/dist/utils/hooks/pluginSystem.cjs +37 -0
- package/dist/utils/hooks/pluginSystem.cjs.map +1 -0
- package/dist/utils/hooks/pluginSystem.d.ts +19 -0
- package/dist/utils/hooks/pluginSystem.js +37 -0
- package/dist/utils/hooks/pluginSystem.js.map +1 -0
- package/dist/utils/hooks/syncHook.cjs +36 -0
- package/dist/utils/hooks/syncHook.cjs.map +1 -0
- package/dist/utils/hooks/syncHook.d.ts +16 -0
- package/dist/utils/hooks/syncHook.js +35 -0
- package/dist/utils/hooks/syncHook.js.map +1 -0
- package/dist/utils/hooks/syncWaterfallHook.cjs +39 -0
- package/dist/utils/hooks/syncWaterfallHook.cjs.map +1 -0
- package/dist/utils/hooks/syncWaterfallHook.d.ts +11 -0
- package/dist/utils/hooks/syncWaterfallHook.js +38 -0
- package/dist/utils/hooks/syncWaterfallHook.js.map +1 -0
- package/dist/utils/index.cjs +7 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/load.cjs +177 -0
- package/dist/utils/load.cjs.map +1 -0
- package/dist/utils/load.d.ts +16 -0
- package/dist/utils/load.js +175 -0
- package/dist/utils/load.js.map +1 -0
- package/dist/utils/logger.cjs +28 -0
- package/dist/utils/logger.cjs.map +1 -0
- package/dist/utils/logger.d.ts +7 -0
- package/dist/utils/logger.js +25 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/manifest.cjs +51 -0
- package/dist/utils/manifest.cjs.map +1 -0
- package/dist/utils/manifest.d.ts +12 -0
- package/dist/utils/manifest.js +49 -0
- package/dist/utils/manifest.js.map +1 -0
- package/dist/utils/plugin.cjs +27 -0
- package/dist/utils/plugin.cjs.map +1 -0
- package/dist/utils/plugin.d.ts +2 -0
- package/dist/utils/plugin.js +27 -0
- package/dist/utils/plugin.js.map +1 -0
- package/dist/utils/preload.cjs +146 -0
- package/dist/utils/preload.cjs.map +1 -0
- package/dist/utils/preload.d.ts +10 -0
- package/dist/utils/preload.js +143 -0
- package/dist/utils/preload.js.map +1 -0
- package/dist/utils/semver/compare.cjs +48 -0
- package/dist/utils/semver/compare.cjs.map +1 -0
- package/dist/utils/semver/compare.js +47 -0
- package/dist/utils/semver/compare.js.map +1 -0
- package/dist/utils/semver/constants.cjs +41 -0
- package/dist/utils/semver/constants.cjs.map +1 -0
- package/dist/utils/semver/constants.js +31 -0
- package/dist/utils/semver/constants.js.map +1 -0
- package/dist/utils/semver/index.cjs +68 -0
- package/dist/utils/semver/index.cjs.map +1 -0
- package/dist/utils/semver/index.d.ts +5 -0
- package/dist/utils/semver/index.js +68 -0
- package/dist/utils/semver/index.js.map +1 -0
- package/dist/utils/semver/parser.cjs +104 -0
- package/dist/utils/semver/parser.cjs.map +1 -0
- package/dist/utils/semver/parser.js +96 -0
- package/dist/utils/semver/parser.js.map +1 -0
- package/dist/utils/semver/utils.cjs +28 -0
- package/dist/utils/semver/utils.cjs.map +1 -0
- package/dist/utils/semver/utils.js +24 -0
- package/dist/utils/semver/utils.js.map +1 -0
- package/dist/utils/share.cjs +284 -0
- package/dist/utils/share.cjs.map +1 -0
- package/dist/utils/share.d.ts +26 -0
- package/dist/utils/share.js +278 -0
- package/dist/utils/share.js.map +1 -0
- package/dist/utils/tool.cjs +82 -0
- package/dist/utils/tool.cjs.map +1 -0
- package/dist/utils/tool.d.ts +9 -0
- package/dist/utils/tool.js +71 -0
- package/dist/utils/tool.js.map +1 -0
- package/package.json +9 -9
- package/dist/index.cjs.cjs +0 -3428
- package/dist/index.cjs.cjs.map +0 -1
- package/dist/index.cjs.d.ts +0 -1
- package/dist/index.esm.js +0 -3404
- package/dist/index.esm.js.map +0 -1
- package/dist/src/constant.d.ts +0 -2
- package/dist/src/core.d.ts +0 -119
- package/dist/src/global.d.ts +0 -42
- package/dist/src/helpers.d.ts +0 -38
- package/dist/src/index.d.ts +0 -14
- package/dist/src/module/index.d.ts +0 -24
- package/dist/src/plugins/generate-preload-assets.d.ts +0 -8
- package/dist/src/plugins/snapshot/SnapshotHandler.d.ts +0 -60
- package/dist/src/plugins/snapshot/index.d.ts +0 -5
- package/dist/src/remote/index.d.ts +0 -109
- package/dist/src/shared/index.d.ts +0 -75
- package/dist/src/type/config.d.ts +0 -128
- package/dist/src/type/index.d.ts +0 -3
- package/dist/src/type/plugin.d.ts +0 -35
- package/dist/src/type/preload.d.ts +0 -26
- package/dist/src/types.d.ts +0 -1
- package/dist/src/utils/env.d.ts +0 -3
- package/dist/src/utils/hooks/asyncHook.d.ts +0 -6
- package/dist/src/utils/hooks/asyncWaterfallHooks.d.ts +0 -10
- package/dist/src/utils/hooks/index.d.ts +0 -6
- package/dist/src/utils/hooks/pluginSystem.d.ts +0 -16
- package/dist/src/utils/hooks/syncHook.d.ts +0 -12
- package/dist/src/utils/hooks/syncWaterfallHook.d.ts +0 -9
- package/dist/src/utils/index.d.ts +0 -6
- package/dist/src/utils/load.d.ts +0 -11
- package/dist/src/utils/logger.d.ts +0 -6
- package/dist/src/utils/manifest.d.ts +0 -7
- package/dist/src/utils/plugin.d.ts +0 -3
- package/dist/src/utils/preload.d.ts +0 -6
- package/dist/src/utils/semver/compare.d.ts +0 -9
- package/dist/src/utils/semver/constants.d.ts +0 -10
- package/dist/src/utils/semver/index.d.ts +0 -2
- package/dist/src/utils/semver/parser.d.ts +0 -9
- package/dist/src/utils/semver/utils.d.ts +0 -11
- package/dist/src/utils/share.d.ts +0 -45
- package/dist/src/utils/tool.d.ts +0 -18
- package/dist/types.cjs.cjs +0 -3
- package/dist/types.cjs.cjs.map +0 -1
- package/dist/types.cjs.d.ts +0 -1
- package/dist/types.esm.js +0 -2
- package/dist/types.esm.js.map +0 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
const require_logger = require('./logger.cjs');
|
|
2
|
+
const require_global = require('../global.cjs');
|
|
3
|
+
const require_constant = require('../constant.cjs');
|
|
4
|
+
let _module_federation_sdk = require("@module-federation/sdk");
|
|
5
|
+
let _module_federation_error_codes = require("@module-federation/error-codes");
|
|
6
|
+
|
|
7
|
+
//#region src/utils/load.ts
|
|
8
|
+
const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
|
|
9
|
+
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
try {
|
|
12
|
+
if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${entry}")${importCallback}`)([resolve, reject]);
|
|
13
|
+
else import(
|
|
14
|
+
/* webpackIgnore: true */
|
|
15
|
+
/* @vite-ignore */
|
|
16
|
+
entry
|
|
17
|
+
).then(resolve).catch(reject);
|
|
18
|
+
else resolve(remoteEntryExports);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
reject(e);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
try {
|
|
27
|
+
if (!remoteEntryExports) if (typeof __system_context__ === "undefined") System.import(entry).then(resolve).catch(reject);
|
|
28
|
+
else new Function("callbacks", `System.import("${entry}")${importCallback}`)([resolve, reject]);
|
|
29
|
+
else resolve(remoteEntryExports);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function handleRemoteEntryLoaded(name, globalName, entry) {
|
|
36
|
+
const { remoteEntryKey, entryExports } = require_global.getRemoteEntryExports(name, globalName);
|
|
37
|
+
require_logger.assert(entryExports, (0, _module_federation_error_codes.getShortErrorMsg)(_module_federation_error_codes.RUNTIME_001, _module_federation_error_codes.runtimeDescMap, {
|
|
38
|
+
remoteName: name,
|
|
39
|
+
remoteEntryUrl: entry,
|
|
40
|
+
remoteEntryKey
|
|
41
|
+
}));
|
|
42
|
+
return entryExports;
|
|
43
|
+
}
|
|
44
|
+
async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUrl }) {
|
|
45
|
+
const { entryExports: remoteEntryExports } = require_global.getRemoteEntryExports(name, globalName);
|
|
46
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
47
|
+
return (0, _module_federation_sdk.loadScript)(getEntryUrl ? getEntryUrl(entry) : entry, {
|
|
48
|
+
attrs: {},
|
|
49
|
+
createScriptHook: (url, attrs) => {
|
|
50
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
51
|
+
url,
|
|
52
|
+
attrs
|
|
53
|
+
});
|
|
54
|
+
if (!res) return;
|
|
55
|
+
if (res instanceof HTMLScriptElement) return res;
|
|
56
|
+
if ("script" in res || "timeout" in res) return res;
|
|
57
|
+
}
|
|
58
|
+
}).then(() => {
|
|
59
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
60
|
+
}).catch((e) => {
|
|
61
|
+
require_logger.assert(void 0, (0, _module_federation_error_codes.getShortErrorMsg)(_module_federation_error_codes.RUNTIME_008, _module_federation_error_codes.runtimeDescMap, {
|
|
62
|
+
remoteName: name,
|
|
63
|
+
resourceUrl: entry
|
|
64
|
+
}));
|
|
65
|
+
throw e;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl }) {
|
|
69
|
+
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
70
|
+
switch (type) {
|
|
71
|
+
case "esm":
|
|
72
|
+
case "module": return loadEsmEntry({
|
|
73
|
+
entry,
|
|
74
|
+
remoteEntryExports
|
|
75
|
+
});
|
|
76
|
+
case "system": return loadSystemJsEntry({
|
|
77
|
+
entry,
|
|
78
|
+
remoteEntryExports
|
|
79
|
+
});
|
|
80
|
+
default: return loadEntryScript({
|
|
81
|
+
entry,
|
|
82
|
+
globalName,
|
|
83
|
+
name,
|
|
84
|
+
loaderHook,
|
|
85
|
+
getEntryUrl
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function loadEntryNode({ remoteInfo, loaderHook }) {
|
|
90
|
+
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
91
|
+
const { entryExports: remoteEntryExports } = require_global.getRemoteEntryExports(name, globalName);
|
|
92
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
93
|
+
return (0, _module_federation_sdk.loadScriptNode)(entry, {
|
|
94
|
+
attrs: {
|
|
95
|
+
name,
|
|
96
|
+
globalName,
|
|
97
|
+
type
|
|
98
|
+
},
|
|
99
|
+
loaderHook: { createScriptHook: (url, attrs = {}) => {
|
|
100
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
101
|
+
url,
|
|
102
|
+
attrs
|
|
103
|
+
});
|
|
104
|
+
if (!res) return;
|
|
105
|
+
if ("url" in res) return res;
|
|
106
|
+
} }
|
|
107
|
+
}).then(() => {
|
|
108
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
109
|
+
}).catch((e) => {
|
|
110
|
+
throw e;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function getRemoteEntryUniqueKey(remoteInfo) {
|
|
114
|
+
const { entry, name } = remoteInfo;
|
|
115
|
+
return (0, _module_federation_sdk.composeKeyWithSeparator)(name, entry);
|
|
116
|
+
}
|
|
117
|
+
async function getRemoteEntry(params) {
|
|
118
|
+
const { origin, remoteEntryExports, remoteInfo, getEntryUrl, _inErrorHandling = false } = params;
|
|
119
|
+
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
120
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
121
|
+
if (!require_global.globalLoading[uniqueKey]) {
|
|
122
|
+
const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
|
|
123
|
+
const loaderHook = origin.loaderHook;
|
|
124
|
+
require_global.globalLoading[uniqueKey] = loadEntryHook.emit({
|
|
125
|
+
loaderHook,
|
|
126
|
+
remoteInfo,
|
|
127
|
+
remoteEntryExports
|
|
128
|
+
}).then((res) => {
|
|
129
|
+
if (res) return res;
|
|
130
|
+
return (typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : (0, _module_federation_sdk.isBrowserEnv)()) ? loadEntryDom({
|
|
131
|
+
remoteInfo,
|
|
132
|
+
remoteEntryExports,
|
|
133
|
+
loaderHook,
|
|
134
|
+
getEntryUrl
|
|
135
|
+
}) : loadEntryNode({
|
|
136
|
+
remoteInfo,
|
|
137
|
+
loaderHook
|
|
138
|
+
});
|
|
139
|
+
}).catch(async (err) => {
|
|
140
|
+
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
141
|
+
if (err instanceof Error && err.message.includes(_module_federation_error_codes.RUNTIME_008) && !_inErrorHandling) {
|
|
142
|
+
const wrappedGetRemoteEntry = (params) => {
|
|
143
|
+
return getRemoteEntry({
|
|
144
|
+
...params,
|
|
145
|
+
_inErrorHandling: true
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
const RemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
|
|
149
|
+
getRemoteEntry: wrappedGetRemoteEntry,
|
|
150
|
+
origin,
|
|
151
|
+
remoteInfo,
|
|
152
|
+
remoteEntryExports,
|
|
153
|
+
globalLoading: require_global.globalLoading,
|
|
154
|
+
uniqueKey
|
|
155
|
+
});
|
|
156
|
+
if (RemoteEntryExports) return RemoteEntryExports;
|
|
157
|
+
}
|
|
158
|
+
throw err;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return require_global.globalLoading[uniqueKey];
|
|
162
|
+
}
|
|
163
|
+
function getRemoteInfo(remote) {
|
|
164
|
+
return {
|
|
165
|
+
...remote,
|
|
166
|
+
entry: "entry" in remote ? remote.entry : "",
|
|
167
|
+
type: remote.type || require_constant.DEFAULT_REMOTE_TYPE,
|
|
168
|
+
entryGlobalName: remote.entryGlobalName || remote.name,
|
|
169
|
+
shareScope: remote.shareScope || require_constant.DEFAULT_SCOPE
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//#endregion
|
|
174
|
+
exports.getRemoteEntry = getRemoteEntry;
|
|
175
|
+
exports.getRemoteEntryUniqueKey = getRemoteEntryUniqueKey;
|
|
176
|
+
exports.getRemoteInfo = getRemoteInfo;
|
|
177
|
+
//# sourceMappingURL=load.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.cjs","names":["getRemoteEntryExports","RUNTIME_001","runtimeDescMap","RUNTIME_008","globalLoading","DEFAULT_REMOTE_TYPE","DEFAULT_SCOPE"],"sources":["../../src/utils/load.ts"],"sourcesContent":["import {\n loadScript,\n loadScriptNode,\n composeKeyWithSeparator,\n isBrowserEnv,\n} from '@module-federation/sdk';\nimport { DEFAULT_REMOTE_TYPE, DEFAULT_SCOPE } from '../constant';\nimport { ModuleFederation } from '../core';\nimport { globalLoading, getRemoteEntryExports } from '../global';\nimport { Remote, RemoteEntryExports, RemoteInfo } from '../type';\nimport { assert } from './logger';\nimport {\n RUNTIME_001,\n RUNTIME_008,\n getShortErrorMsg,\n runtimeDescMap,\n} from '@module-federation/error-codes';\n\n// Declare the ENV_TARGET constant that will be defined by DefinePlugin\ndeclare const ENV_TARGET: 'web' | 'node';\nconst importCallback = '.then(callbacks[0]).catch(callbacks[1])';\n\nasync function loadEsmEntry({\n entry,\n remoteEntryExports,\n}: {\n entry: string;\n remoteEntryExports: RemoteEntryExports | undefined;\n}): Promise<RemoteEntryExports> {\n return new Promise<RemoteEntryExports>((resolve, reject) => {\n try {\n if (!remoteEntryExports) {\n if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== 'undefined') {\n new Function('callbacks', `import(\"${entry}\")${importCallback}`)([\n resolve,\n reject,\n ]);\n } else {\n import(/* webpackIgnore: true */ /* @vite-ignore */ entry)\n .then(resolve)\n .catch(reject);\n }\n } else {\n resolve(remoteEntryExports);\n }\n } catch (e) {\n reject(e);\n }\n });\n}\n\nasync function loadSystemJsEntry({\n entry,\n remoteEntryExports,\n}: {\n entry: string;\n remoteEntryExports: RemoteEntryExports | undefined;\n}): Promise<RemoteEntryExports> {\n return new Promise<RemoteEntryExports>((resolve, reject) => {\n try {\n if (!remoteEntryExports) {\n //@ts-ignore\n if (typeof __system_context__ === 'undefined') {\n //@ts-ignore\n System.import(entry).then(resolve).catch(reject);\n } else {\n new Function(\n 'callbacks',\n `System.import(\"${entry}\")${importCallback}`,\n )([resolve, reject]);\n }\n } else {\n resolve(remoteEntryExports);\n }\n } catch (e) {\n reject(e);\n }\n });\n}\n\nfunction handleRemoteEntryLoaded(\n name: string,\n globalName: string,\n entry: string,\n): RemoteEntryExports {\n const { remoteEntryKey, entryExports } = getRemoteEntryExports(\n name,\n globalName,\n );\n\n assert(\n entryExports,\n getShortErrorMsg(RUNTIME_001, runtimeDescMap, {\n remoteName: name,\n remoteEntryUrl: entry,\n remoteEntryKey,\n }),\n );\n\n return entryExports;\n}\n\nasync function loadEntryScript({\n name,\n globalName,\n entry,\n loaderHook,\n getEntryUrl,\n}: {\n name: string;\n globalName: string;\n entry: string;\n loaderHook: ModuleFederation['loaderHook'];\n getEntryUrl?: (url: string) => string;\n}): Promise<RemoteEntryExports> {\n const { entryExports: remoteEntryExports } = getRemoteEntryExports(\n name,\n globalName,\n );\n\n if (remoteEntryExports) {\n return remoteEntryExports;\n }\n\n // if getEntryUrl is passed, use the getEntryUrl to get the entry url\n const url = getEntryUrl ? getEntryUrl(entry) : entry;\n return loadScript(url, {\n attrs: {},\n createScriptHook: (url, attrs) => {\n const res = loaderHook.lifecycle.createScript.emit({ url, attrs });\n\n if (!res) return;\n\n if (res instanceof HTMLScriptElement) {\n return res;\n }\n\n if ('script' in res || 'timeout' in res) {\n return res;\n }\n\n return;\n },\n })\n .then(() => {\n return handleRemoteEntryLoaded(name, globalName, entry);\n })\n .catch((e) => {\n assert(\n undefined,\n getShortErrorMsg(RUNTIME_008, runtimeDescMap, {\n remoteName: name,\n resourceUrl: entry,\n }),\n );\n throw e;\n });\n}\nasync function loadEntryDom({\n remoteInfo,\n remoteEntryExports,\n loaderHook,\n getEntryUrl,\n}: {\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports;\n loaderHook: ModuleFederation['loaderHook'];\n getEntryUrl?: (url: string) => string;\n}) {\n const { entry, entryGlobalName: globalName, name, type } = remoteInfo;\n switch (type) {\n case 'esm':\n case 'module':\n return loadEsmEntry({ entry, remoteEntryExports });\n case 'system':\n return loadSystemJsEntry({ entry, remoteEntryExports });\n default:\n return loadEntryScript({\n entry,\n globalName,\n name,\n loaderHook,\n getEntryUrl,\n });\n }\n}\n\nasync function loadEntryNode({\n remoteInfo,\n loaderHook,\n}: {\n remoteInfo: RemoteInfo;\n loaderHook: ModuleFederation['loaderHook'];\n}) {\n const { entry, entryGlobalName: globalName, name, type } = remoteInfo;\n const { entryExports: remoteEntryExports } = getRemoteEntryExports(\n name,\n globalName,\n );\n\n if (remoteEntryExports) {\n return remoteEntryExports;\n }\n\n return loadScriptNode(entry, {\n attrs: { name, globalName, type },\n loaderHook: {\n createScriptHook: (url: string, attrs: Record<string, any> = {}) => {\n const res = loaderHook.lifecycle.createScript.emit({ url, attrs });\n\n if (!res) return;\n\n if ('url' in res) {\n return res;\n }\n\n return;\n },\n },\n })\n .then(() => {\n return handleRemoteEntryLoaded(name, globalName, entry);\n })\n .catch((e) => {\n throw e;\n });\n}\n\nexport function getRemoteEntryUniqueKey(remoteInfo: RemoteInfo): string {\n const { entry, name } = remoteInfo;\n return composeKeyWithSeparator(name, entry);\n}\n\nexport async function getRemoteEntry(params: {\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports | undefined;\n getEntryUrl?: (url: string) => string;\n _inErrorHandling?: boolean; // Add flag to prevent recursion\n}): Promise<RemoteEntryExports | false | void> {\n const {\n origin,\n remoteEntryExports,\n remoteInfo,\n getEntryUrl,\n _inErrorHandling = false,\n } = params;\n const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);\n if (remoteEntryExports) {\n return remoteEntryExports;\n }\n\n if (!globalLoading[uniqueKey]) {\n const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;\n const loaderHook = origin.loaderHook;\n\n globalLoading[uniqueKey] = loadEntryHook\n .emit({\n loaderHook,\n remoteInfo,\n remoteEntryExports,\n })\n .then((res) => {\n if (res) {\n return res;\n }\n // Use ENV_TARGET if defined, otherwise fallback to isBrowserEnv, must keep this\n const isWebEnvironment =\n typeof ENV_TARGET !== 'undefined'\n ? ENV_TARGET === 'web'\n : isBrowserEnv();\n\n return isWebEnvironment\n ? loadEntryDom({\n remoteInfo,\n remoteEntryExports,\n loaderHook,\n getEntryUrl,\n })\n : loadEntryNode({ remoteInfo, loaderHook });\n })\n .catch(async (err) => {\n const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);\n const isScriptLoadError =\n err instanceof Error && err.message.includes(RUNTIME_008);\n\n if (isScriptLoadError && !_inErrorHandling) {\n const wrappedGetRemoteEntry = (\n params: Parameters<typeof getRemoteEntry>[0],\n ) => {\n return getRemoteEntry({ ...params, _inErrorHandling: true });\n };\n\n const RemoteEntryExports =\n await origin.loaderHook.lifecycle.loadEntryError.emit({\n getRemoteEntry: wrappedGetRemoteEntry,\n origin,\n remoteInfo: remoteInfo,\n remoteEntryExports,\n globalLoading,\n uniqueKey,\n });\n\n if (RemoteEntryExports) {\n return RemoteEntryExports;\n }\n }\n throw err;\n });\n }\n\n return globalLoading[uniqueKey];\n}\n\nexport function getRemoteInfo(remote: Remote): RemoteInfo {\n return {\n ...remote,\n entry: 'entry' in remote ? remote.entry : '',\n type: remote.type || DEFAULT_REMOTE_TYPE,\n entryGlobalName: remote.entryGlobalName || remote.name,\n shareScope: remote.shareScope || DEFAULT_SCOPE,\n };\n}\n"],"mappings":";;;;;;;AAoBA,MAAM,iBAAiB;AAEvB,eAAe,aAAa,EAC1B,OACA,sBAI8B;AAC9B,QAAO,IAAI,SAA6B,SAAS,WAAW;AAC1D,MAAI;AACF,OAAI,CAAC,mBACH,KAAI,OAAO,kCAAkC,YAC3C,KAAI,SAAS,aAAa,WAAW,MAAM,IAAI,iBAAiB,CAAC,CAC/D,SACA,OACD,CAAC;OAEF;;;IAAoD;EACjD,KAAK,QAAQ,C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D,CAAC,GACF,cAAc;IAAE;IAAY;IAAY,CAAC;IAC7C,CACD,MAAM,OAAO,QAAQ;GACpB,MAAM,YAAY,wBAAwB,WAAW;AAIrD,OAFE,eAAe,SAAS,IAAI,QAAQ,SAASD,2CAAY,IAElC,CAAC,kBAAkB;IAC1C,MAAM,yBACJ,WACG;AACH,YAAO,eAAe;MAAE,GAAG;MAAQ,kBAAkB;MAAM,CAAC;;IAG9D,MAAM,qBACJ,MAAM,OAAO,WAAW,UAAU,eAAe,KAAK;KACpD,gBAAgB;KAChB;KACY;KACZ;KACA;KACA;KACD,CAAC;AAEJ,QAAI,mBACF,QAAO;;AAGX,SAAM;IACN;;AAGN,QAAOC,6BAAc;;AAGvB,SAAgB,cAAc,QAA4B;AACxD,QAAO;EACL,GAAG;EACH,OAAO,WAAW,SAAS,OAAO,QAAQ;EAC1C,MAAM,OAAO,QAAQC;EACrB,iBAAiB,OAAO,mBAAmB,OAAO;EAClD,YAAY,OAAO,cAAcC;EAClC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ModuleFederation } from "../core.js";
|
|
2
|
+
import { Remote, RemoteEntryExports, RemoteInfo } from "../type/config.js";
|
|
3
|
+
import "../type/index.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/load.d.ts
|
|
6
|
+
declare function getRemoteEntry(params: {
|
|
7
|
+
origin: ModuleFederation;
|
|
8
|
+
remoteInfo: RemoteInfo;
|
|
9
|
+
remoteEntryExports?: RemoteEntryExports | undefined;
|
|
10
|
+
getEntryUrl?: (url: string) => string;
|
|
11
|
+
_inErrorHandling?: boolean;
|
|
12
|
+
}): Promise<RemoteEntryExports | false | void>;
|
|
13
|
+
declare function getRemoteInfo(remote: Remote): RemoteInfo;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getRemoteEntry, getRemoteInfo };
|
|
16
|
+
//# sourceMappingURL=load.d.ts.map
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { assert } from "./logger.js";
|
|
2
|
+
import { getRemoteEntryExports, globalLoading } from "../global.js";
|
|
3
|
+
import { DEFAULT_REMOTE_TYPE, DEFAULT_SCOPE } from "../constant.js";
|
|
4
|
+
import { composeKeyWithSeparator, isBrowserEnv, loadScript, loadScriptNode } from "@module-federation/sdk";
|
|
5
|
+
import { RUNTIME_001, RUNTIME_008, getShortErrorMsg, runtimeDescMap } from "@module-federation/error-codes";
|
|
6
|
+
|
|
7
|
+
//#region src/utils/load.ts
|
|
8
|
+
const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
|
|
9
|
+
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
try {
|
|
12
|
+
if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${entry}")${importCallback}`)([resolve, reject]);
|
|
13
|
+
else import(
|
|
14
|
+
/* webpackIgnore: true */
|
|
15
|
+
/* @vite-ignore */
|
|
16
|
+
entry
|
|
17
|
+
).then(resolve).catch(reject);
|
|
18
|
+
else resolve(remoteEntryExports);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
reject(e);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
try {
|
|
27
|
+
if (!remoteEntryExports) if (typeof __system_context__ === "undefined") System.import(entry).then(resolve).catch(reject);
|
|
28
|
+
else new Function("callbacks", `System.import("${entry}")${importCallback}`)([resolve, reject]);
|
|
29
|
+
else resolve(remoteEntryExports);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function handleRemoteEntryLoaded(name, globalName, entry) {
|
|
36
|
+
const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
|
|
37
|
+
assert(entryExports, getShortErrorMsg(RUNTIME_001, runtimeDescMap, {
|
|
38
|
+
remoteName: name,
|
|
39
|
+
remoteEntryUrl: entry,
|
|
40
|
+
remoteEntryKey
|
|
41
|
+
}));
|
|
42
|
+
return entryExports;
|
|
43
|
+
}
|
|
44
|
+
async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUrl }) {
|
|
45
|
+
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
46
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
47
|
+
return loadScript(getEntryUrl ? getEntryUrl(entry) : entry, {
|
|
48
|
+
attrs: {},
|
|
49
|
+
createScriptHook: (url, attrs) => {
|
|
50
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
51
|
+
url,
|
|
52
|
+
attrs
|
|
53
|
+
});
|
|
54
|
+
if (!res) return;
|
|
55
|
+
if (res instanceof HTMLScriptElement) return res;
|
|
56
|
+
if ("script" in res || "timeout" in res) return res;
|
|
57
|
+
}
|
|
58
|
+
}).then(() => {
|
|
59
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
60
|
+
}).catch((e) => {
|
|
61
|
+
assert(void 0, getShortErrorMsg(RUNTIME_008, runtimeDescMap, {
|
|
62
|
+
remoteName: name,
|
|
63
|
+
resourceUrl: entry
|
|
64
|
+
}));
|
|
65
|
+
throw e;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl }) {
|
|
69
|
+
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
70
|
+
switch (type) {
|
|
71
|
+
case "esm":
|
|
72
|
+
case "module": return loadEsmEntry({
|
|
73
|
+
entry,
|
|
74
|
+
remoteEntryExports
|
|
75
|
+
});
|
|
76
|
+
case "system": return loadSystemJsEntry({
|
|
77
|
+
entry,
|
|
78
|
+
remoteEntryExports
|
|
79
|
+
});
|
|
80
|
+
default: return loadEntryScript({
|
|
81
|
+
entry,
|
|
82
|
+
globalName,
|
|
83
|
+
name,
|
|
84
|
+
loaderHook,
|
|
85
|
+
getEntryUrl
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function loadEntryNode({ remoteInfo, loaderHook }) {
|
|
90
|
+
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
91
|
+
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
92
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
93
|
+
return loadScriptNode(entry, {
|
|
94
|
+
attrs: {
|
|
95
|
+
name,
|
|
96
|
+
globalName,
|
|
97
|
+
type
|
|
98
|
+
},
|
|
99
|
+
loaderHook: { createScriptHook: (url, attrs = {}) => {
|
|
100
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
101
|
+
url,
|
|
102
|
+
attrs
|
|
103
|
+
});
|
|
104
|
+
if (!res) return;
|
|
105
|
+
if ("url" in res) return res;
|
|
106
|
+
} }
|
|
107
|
+
}).then(() => {
|
|
108
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
109
|
+
}).catch((e) => {
|
|
110
|
+
throw e;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function getRemoteEntryUniqueKey(remoteInfo) {
|
|
114
|
+
const { entry, name } = remoteInfo;
|
|
115
|
+
return composeKeyWithSeparator(name, entry);
|
|
116
|
+
}
|
|
117
|
+
async function getRemoteEntry(params) {
|
|
118
|
+
const { origin, remoteEntryExports, remoteInfo, getEntryUrl, _inErrorHandling = false } = params;
|
|
119
|
+
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
120
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
121
|
+
if (!globalLoading[uniqueKey]) {
|
|
122
|
+
const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
|
|
123
|
+
const loaderHook = origin.loaderHook;
|
|
124
|
+
globalLoading[uniqueKey] = loadEntryHook.emit({
|
|
125
|
+
loaderHook,
|
|
126
|
+
remoteInfo,
|
|
127
|
+
remoteEntryExports
|
|
128
|
+
}).then((res) => {
|
|
129
|
+
if (res) return res;
|
|
130
|
+
return (typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : isBrowserEnv()) ? loadEntryDom({
|
|
131
|
+
remoteInfo,
|
|
132
|
+
remoteEntryExports,
|
|
133
|
+
loaderHook,
|
|
134
|
+
getEntryUrl
|
|
135
|
+
}) : loadEntryNode({
|
|
136
|
+
remoteInfo,
|
|
137
|
+
loaderHook
|
|
138
|
+
});
|
|
139
|
+
}).catch(async (err) => {
|
|
140
|
+
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
141
|
+
if (err instanceof Error && err.message.includes(RUNTIME_008) && !_inErrorHandling) {
|
|
142
|
+
const wrappedGetRemoteEntry = (params) => {
|
|
143
|
+
return getRemoteEntry({
|
|
144
|
+
...params,
|
|
145
|
+
_inErrorHandling: true
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
const RemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
|
|
149
|
+
getRemoteEntry: wrappedGetRemoteEntry,
|
|
150
|
+
origin,
|
|
151
|
+
remoteInfo,
|
|
152
|
+
remoteEntryExports,
|
|
153
|
+
globalLoading,
|
|
154
|
+
uniqueKey
|
|
155
|
+
});
|
|
156
|
+
if (RemoteEntryExports) return RemoteEntryExports;
|
|
157
|
+
}
|
|
158
|
+
throw err;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return globalLoading[uniqueKey];
|
|
162
|
+
}
|
|
163
|
+
function getRemoteInfo(remote) {
|
|
164
|
+
return {
|
|
165
|
+
...remote,
|
|
166
|
+
entry: "entry" in remote ? remote.entry : "",
|
|
167
|
+
type: remote.type || DEFAULT_REMOTE_TYPE,
|
|
168
|
+
entryGlobalName: remote.entryGlobalName || remote.name,
|
|
169
|
+
shareScope: remote.shareScope || DEFAULT_SCOPE
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//#endregion
|
|
174
|
+
export { getRemoteEntry, getRemoteEntryUniqueKey, getRemoteInfo };
|
|
175
|
+
//# sourceMappingURL=load.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.js","names":[],"sources":["../../src/utils/load.ts"],"sourcesContent":["import {\n loadScript,\n loadScriptNode,\n composeKeyWithSeparator,\n isBrowserEnv,\n} from '@module-federation/sdk';\nimport { DEFAULT_REMOTE_TYPE, DEFAULT_SCOPE } from '../constant';\nimport { ModuleFederation } from '../core';\nimport { globalLoading, getRemoteEntryExports } from '../global';\nimport { Remote, RemoteEntryExports, RemoteInfo } from '../type';\nimport { assert } from './logger';\nimport {\n RUNTIME_001,\n RUNTIME_008,\n getShortErrorMsg,\n runtimeDescMap,\n} from '@module-federation/error-codes';\n\n// Declare the ENV_TARGET constant that will be defined by DefinePlugin\ndeclare const ENV_TARGET: 'web' | 'node';\nconst importCallback = '.then(callbacks[0]).catch(callbacks[1])';\n\nasync function loadEsmEntry({\n entry,\n remoteEntryExports,\n}: {\n entry: string;\n remoteEntryExports: RemoteEntryExports | undefined;\n}): Promise<RemoteEntryExports> {\n return new Promise<RemoteEntryExports>((resolve, reject) => {\n try {\n if (!remoteEntryExports) {\n if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== 'undefined') {\n new Function('callbacks', `import(\"${entry}\")${importCallback}`)([\n resolve,\n reject,\n ]);\n } else {\n import(/* webpackIgnore: true */ /* @vite-ignore */ entry)\n .then(resolve)\n .catch(reject);\n }\n } else {\n resolve(remoteEntryExports);\n }\n } catch (e) {\n reject(e);\n }\n });\n}\n\nasync function loadSystemJsEntry({\n entry,\n remoteEntryExports,\n}: {\n entry: string;\n remoteEntryExports: RemoteEntryExports | undefined;\n}): Promise<RemoteEntryExports> {\n return new Promise<RemoteEntryExports>((resolve, reject) => {\n try {\n if (!remoteEntryExports) {\n //@ts-ignore\n if (typeof __system_context__ === 'undefined') {\n //@ts-ignore\n System.import(entry).then(resolve).catch(reject);\n } else {\n new Function(\n 'callbacks',\n `System.import(\"${entry}\")${importCallback}`,\n )([resolve, reject]);\n }\n } else {\n resolve(remoteEntryExports);\n }\n } catch (e) {\n reject(e);\n }\n });\n}\n\nfunction handleRemoteEntryLoaded(\n name: string,\n globalName: string,\n entry: string,\n): RemoteEntryExports {\n const { remoteEntryKey, entryExports } = getRemoteEntryExports(\n name,\n globalName,\n );\n\n assert(\n entryExports,\n getShortErrorMsg(RUNTIME_001, runtimeDescMap, {\n remoteName: name,\n remoteEntryUrl: entry,\n remoteEntryKey,\n }),\n );\n\n return entryExports;\n}\n\nasync function loadEntryScript({\n name,\n globalName,\n entry,\n loaderHook,\n getEntryUrl,\n}: {\n name: string;\n globalName: string;\n entry: string;\n loaderHook: ModuleFederation['loaderHook'];\n getEntryUrl?: (url: string) => string;\n}): Promise<RemoteEntryExports> {\n const { entryExports: remoteEntryExports } = getRemoteEntryExports(\n name,\n globalName,\n );\n\n if (remoteEntryExports) {\n return remoteEntryExports;\n }\n\n // if getEntryUrl is passed, use the getEntryUrl to get the entry url\n const url = getEntryUrl ? getEntryUrl(entry) : entry;\n return loadScript(url, {\n attrs: {},\n createScriptHook: (url, attrs) => {\n const res = loaderHook.lifecycle.createScript.emit({ url, attrs });\n\n if (!res) return;\n\n if (res instanceof HTMLScriptElement) {\n return res;\n }\n\n if ('script' in res || 'timeout' in res) {\n return res;\n }\n\n return;\n },\n })\n .then(() => {\n return handleRemoteEntryLoaded(name, globalName, entry);\n })\n .catch((e) => {\n assert(\n undefined,\n getShortErrorMsg(RUNTIME_008, runtimeDescMap, {\n remoteName: name,\n resourceUrl: entry,\n }),\n );\n throw e;\n });\n}\nasync function loadEntryDom({\n remoteInfo,\n remoteEntryExports,\n loaderHook,\n getEntryUrl,\n}: {\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports;\n loaderHook: ModuleFederation['loaderHook'];\n getEntryUrl?: (url: string) => string;\n}) {\n const { entry, entryGlobalName: globalName, name, type } = remoteInfo;\n switch (type) {\n case 'esm':\n case 'module':\n return loadEsmEntry({ entry, remoteEntryExports });\n case 'system':\n return loadSystemJsEntry({ entry, remoteEntryExports });\n default:\n return loadEntryScript({\n entry,\n globalName,\n name,\n loaderHook,\n getEntryUrl,\n });\n }\n}\n\nasync function loadEntryNode({\n remoteInfo,\n loaderHook,\n}: {\n remoteInfo: RemoteInfo;\n loaderHook: ModuleFederation['loaderHook'];\n}) {\n const { entry, entryGlobalName: globalName, name, type } = remoteInfo;\n const { entryExports: remoteEntryExports } = getRemoteEntryExports(\n name,\n globalName,\n );\n\n if (remoteEntryExports) {\n return remoteEntryExports;\n }\n\n return loadScriptNode(entry, {\n attrs: { name, globalName, type },\n loaderHook: {\n createScriptHook: (url: string, attrs: Record<string, any> = {}) => {\n const res = loaderHook.lifecycle.createScript.emit({ url, attrs });\n\n if (!res) return;\n\n if ('url' in res) {\n return res;\n }\n\n return;\n },\n },\n })\n .then(() => {\n return handleRemoteEntryLoaded(name, globalName, entry);\n })\n .catch((e) => {\n throw e;\n });\n}\n\nexport function getRemoteEntryUniqueKey(remoteInfo: RemoteInfo): string {\n const { entry, name } = remoteInfo;\n return composeKeyWithSeparator(name, entry);\n}\n\nexport async function getRemoteEntry(params: {\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports | undefined;\n getEntryUrl?: (url: string) => string;\n _inErrorHandling?: boolean; // Add flag to prevent recursion\n}): Promise<RemoteEntryExports | false | void> {\n const {\n origin,\n remoteEntryExports,\n remoteInfo,\n getEntryUrl,\n _inErrorHandling = false,\n } = params;\n const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);\n if (remoteEntryExports) {\n return remoteEntryExports;\n }\n\n if (!globalLoading[uniqueKey]) {\n const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;\n const loaderHook = origin.loaderHook;\n\n globalLoading[uniqueKey] = loadEntryHook\n .emit({\n loaderHook,\n remoteInfo,\n remoteEntryExports,\n })\n .then((res) => {\n if (res) {\n return res;\n }\n // Use ENV_TARGET if defined, otherwise fallback to isBrowserEnv, must keep this\n const isWebEnvironment =\n typeof ENV_TARGET !== 'undefined'\n ? ENV_TARGET === 'web'\n : isBrowserEnv();\n\n return isWebEnvironment\n ? loadEntryDom({\n remoteInfo,\n remoteEntryExports,\n loaderHook,\n getEntryUrl,\n })\n : loadEntryNode({ remoteInfo, loaderHook });\n })\n .catch(async (err) => {\n const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);\n const isScriptLoadError =\n err instanceof Error && err.message.includes(RUNTIME_008);\n\n if (isScriptLoadError && !_inErrorHandling) {\n const wrappedGetRemoteEntry = (\n params: Parameters<typeof getRemoteEntry>[0],\n ) => {\n return getRemoteEntry({ ...params, _inErrorHandling: true });\n };\n\n const RemoteEntryExports =\n await origin.loaderHook.lifecycle.loadEntryError.emit({\n getRemoteEntry: wrappedGetRemoteEntry,\n origin,\n remoteInfo: remoteInfo,\n remoteEntryExports,\n globalLoading,\n uniqueKey,\n });\n\n if (RemoteEntryExports) {\n return RemoteEntryExports;\n }\n }\n throw err;\n });\n }\n\n return globalLoading[uniqueKey];\n}\n\nexport function getRemoteInfo(remote: Remote): RemoteInfo {\n return {\n ...remote,\n entry: 'entry' in remote ? remote.entry : '',\n type: remote.type || DEFAULT_REMOTE_TYPE,\n entryGlobalName: remote.entryGlobalName || remote.name,\n shareScope: remote.shareScope || DEFAULT_SCOPE,\n };\n}\n"],"mappings":";;;;;;;AAoBA,MAAM,iBAAiB;AAEvB,eAAe,aAAa,EAC1B,OACA,sBAI8B;AAC9B,QAAO,IAAI,SAA6B,SAAS,WAAW;AAC1D,MAAI;AACF,OAAI,CAAC,mBACH,KAAI,OAAO,kCAAkC,YAC3C,KAAI,SAAS,aAAa,WAAW,MAAM,IAAI,iBAAiB,CAAC,CAC/D,SACA,OACD,CAAC;OAEF;;;IAAoD;EACjD,KAAK,QAAQ,CACb,MAAM,OAAO;OAGlB,SAAQ,mBA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c;IAAE;IAAY;IAAY,CAAC;IAC7C,CACD,MAAM,OAAO,QAAQ;GACpB,MAAM,YAAY,wBAAwB,WAAW;AAIrD,OAFE,eAAe,SAAS,IAAI,QAAQ,SAAS,YAAY,IAElC,CAAC,kBAAkB;IAC1C,MAAM,yBACJ,WACG;AACH,YAAO,eAAe;MAAE,GAAG;MAAQ,kBAAkB;MAAM,CAAC;;IAG9D,MAAM,qBACJ,MAAM,OAAO,WAAW,UAAU,eAAe,KAAK;KACpD,gBAAgB;KAChB;KACY;KACZ;KACA;KACA;KACD,CAAC;AAEJ,QAAI,mBACF,QAAO;;AAGX,SAAM;IACN;;AAGN,QAAO,cAAc;;AAGvB,SAAgB,cAAc,QAA4B;AACxD,QAAO;EACL,GAAG;EACH,OAAO,WAAW,SAAS,OAAO,QAAQ;EAC1C,MAAM,OAAO,QAAQ;EACrB,iBAAiB,OAAO,mBAAmB,OAAO;EAClD,YAAY,OAAO,cAAc;EAClC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
let _module_federation_sdk = require("@module-federation/sdk");
|
|
2
|
+
|
|
3
|
+
//#region src/utils/logger.ts
|
|
4
|
+
const LOG_CATEGORY = "[ Federation Runtime ]";
|
|
5
|
+
const logger = (0, _module_federation_sdk.createLogger)(LOG_CATEGORY);
|
|
6
|
+
function assert(condition, msg) {
|
|
7
|
+
if (!condition) error(msg);
|
|
8
|
+
}
|
|
9
|
+
function error(msg) {
|
|
10
|
+
if (msg instanceof Error) {
|
|
11
|
+
if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
12
|
+
throw msg;
|
|
13
|
+
}
|
|
14
|
+
throw new Error(`${LOG_CATEGORY}: ${msg}`);
|
|
15
|
+
}
|
|
16
|
+
function warn(msg) {
|
|
17
|
+
if (msg instanceof Error) {
|
|
18
|
+
if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
19
|
+
logger.warn(msg);
|
|
20
|
+
} else logger.warn(msg);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.assert = assert;
|
|
25
|
+
exports.error = error;
|
|
26
|
+
exports.logger = logger;
|
|
27
|
+
exports.warn = warn;
|
|
28
|
+
//# sourceMappingURL=logger.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.cjs","names":[],"sources":["../../src/utils/logger.ts"],"sourcesContent":["import { createLogger } from '@module-federation/sdk';\n\nconst LOG_CATEGORY = '[ Federation Runtime ]';\n// FIXME: pre-bundle ?\nconst logger = createLogger(LOG_CATEGORY);\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function assert(condition: any, msg: string): asserts condition {\n if (!condition) {\n error(msg);\n }\n}\n\nexport function error(msg: string | Error | unknown): never {\n if (msg instanceof Error) {\n // Check if the message already starts with the log category to avoid duplication\n if (!msg.message.startsWith(LOG_CATEGORY)) {\n msg.message = `${LOG_CATEGORY}: ${msg.message}`;\n }\n throw msg;\n }\n throw new Error(`${LOG_CATEGORY}: ${msg}`);\n}\n\nexport function warn(msg: Parameters<typeof console.warn>[0]): void {\n if (msg instanceof Error) {\n // Check if the message already starts with the log category to avoid duplication\n if (!msg.message.startsWith(LOG_CATEGORY)) {\n msg.message = `${LOG_CATEGORY}: ${msg.message}`;\n }\n logger.warn(msg);\n } else {\n logger.warn(msg);\n }\n}\n\nexport function log(...args: unknown[]) {\n logger.log(...args);\n}\n\nexport { logger };\n"],"mappings":";;;AAEA,MAAM,eAAe;AAErB,MAAM,kDAAsB,aAAa;AAGzC,SAAgB,OAAO,WAAgB,KAAgC;AACrE,KAAI,CAAC,UACH,OAAM,IAAI;;AAId,SAAgB,MAAM,KAAsC;AAC1D,KAAI,eAAe,OAAO;AAExB,MAAI,CAAC,IAAI,QAAQ,WAAW,aAAa,CACvC,KAAI,UAAU,GAAG,aAAa,IAAI,IAAI;AAExC,QAAM;;AAER,OAAM,IAAI,MAAM,GAAG,aAAa,IAAI,MAAM;;AAG5C,SAAgB,KAAK,KAA+C;AAClE,KAAI,eAAe,OAAO;AAExB,MAAI,CAAC,IAAI,QAAQ,WAAW,aAAa,CACvC,KAAI,UAAU,GAAG,aAAa,IAAI,IAAI;AAExC,SAAO,KAAK,IAAI;OAEhB,QAAO,KAAK,IAAI"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createLogger } from "@module-federation/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/logger.ts
|
|
4
|
+
const LOG_CATEGORY = "[ Federation Runtime ]";
|
|
5
|
+
const logger = createLogger(LOG_CATEGORY);
|
|
6
|
+
function assert(condition, msg) {
|
|
7
|
+
if (!condition) error(msg);
|
|
8
|
+
}
|
|
9
|
+
function error(msg) {
|
|
10
|
+
if (msg instanceof Error) {
|
|
11
|
+
if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
12
|
+
throw msg;
|
|
13
|
+
}
|
|
14
|
+
throw new Error(`${LOG_CATEGORY}: ${msg}`);
|
|
15
|
+
}
|
|
16
|
+
function warn$1(msg) {
|
|
17
|
+
if (msg instanceof Error) {
|
|
18
|
+
if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
19
|
+
logger.warn(msg);
|
|
20
|
+
} else logger.warn(msg);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { assert, error, logger, warn$1 as warn };
|
|
25
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","names":["warn"],"sources":["../../src/utils/logger.ts"],"sourcesContent":["import { createLogger } from '@module-federation/sdk';\n\nconst LOG_CATEGORY = '[ Federation Runtime ]';\n// FIXME: pre-bundle ?\nconst logger = createLogger(LOG_CATEGORY);\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function assert(condition: any, msg: string): asserts condition {\n if (!condition) {\n error(msg);\n }\n}\n\nexport function error(msg: string | Error | unknown): never {\n if (msg instanceof Error) {\n // Check if the message already starts with the log category to avoid duplication\n if (!msg.message.startsWith(LOG_CATEGORY)) {\n msg.message = `${LOG_CATEGORY}: ${msg.message}`;\n }\n throw msg;\n }\n throw new Error(`${LOG_CATEGORY}: ${msg}`);\n}\n\nexport function warn(msg: Parameters<typeof console.warn>[0]): void {\n if (msg instanceof Error) {\n // Check if the message already starts with the log category to avoid duplication\n if (!msg.message.startsWith(LOG_CATEGORY)) {\n msg.message = `${LOG_CATEGORY}: ${msg.message}`;\n }\n logger.warn(msg);\n } else {\n logger.warn(msg);\n }\n}\n\nexport function log(...args: unknown[]) {\n logger.log(...args);\n}\n\nexport { logger };\n"],"mappings":";;;AAEA,MAAM,eAAe;AAErB,MAAM,SAAS,aAAa,aAAa;AAGzC,SAAgB,OAAO,WAAgB,KAAgC;AACrE,KAAI,CAAC,UACH,OAAM,IAAI;;AAId,SAAgB,MAAM,KAAsC;AAC1D,KAAI,eAAe,OAAO;AAExB,MAAI,CAAC,IAAI,QAAQ,WAAW,aAAa,CACvC,KAAI,UAAU,GAAG,aAAa,IAAI,IAAI;AAExC,QAAM;;AAER,OAAM,IAAI,MAAM,GAAG,aAAa,IAAI,MAAM;;AAG5C,SAAgBA,OAAK,KAA+C;AAClE,KAAI,eAAe,OAAO;AAExB,MAAI,CAAC,IAAI,QAAQ,WAAW,aAAa,CACvC,KAAI,UAAU,GAAG,aAAa,IAAI,IAAI;AAExC,SAAO,KAAK,IAAI;OAEhB,QAAO,KAAK,IAAI"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/manifest.ts
|
|
3
|
+
function matchRemoteWithNameAndExpose(remotes, id) {
|
|
4
|
+
for (const remote of remotes) {
|
|
5
|
+
const isNameMatched = id.startsWith(remote.name);
|
|
6
|
+
let expose = id.replace(remote.name, "");
|
|
7
|
+
if (isNameMatched) {
|
|
8
|
+
if (expose.startsWith("/")) {
|
|
9
|
+
const pkgNameOrAlias = remote.name;
|
|
10
|
+
expose = `.${expose}`;
|
|
11
|
+
return {
|
|
12
|
+
pkgNameOrAlias,
|
|
13
|
+
expose,
|
|
14
|
+
remote
|
|
15
|
+
};
|
|
16
|
+
} else if (expose === "") return {
|
|
17
|
+
pkgNameOrAlias: remote.name,
|
|
18
|
+
expose: ".",
|
|
19
|
+
remote
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const isAliasMatched = remote.alias && id.startsWith(remote.alias);
|
|
23
|
+
let exposeWithAlias = remote.alias && id.replace(remote.alias, "");
|
|
24
|
+
if (remote.alias && isAliasMatched) {
|
|
25
|
+
if (exposeWithAlias && exposeWithAlias.startsWith("/")) {
|
|
26
|
+
const pkgNameOrAlias = remote.alias;
|
|
27
|
+
exposeWithAlias = `.${exposeWithAlias}`;
|
|
28
|
+
return {
|
|
29
|
+
pkgNameOrAlias,
|
|
30
|
+
expose: exposeWithAlias,
|
|
31
|
+
remote
|
|
32
|
+
};
|
|
33
|
+
} else if (exposeWithAlias === "") return {
|
|
34
|
+
pkgNameOrAlias: remote.alias,
|
|
35
|
+
expose: ".",
|
|
36
|
+
remote
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function matchRemote(remotes, nameOrAlias) {
|
|
42
|
+
for (const remote of remotes) {
|
|
43
|
+
if (nameOrAlias === remote.name) return remote;
|
|
44
|
+
if (remote.alias && nameOrAlias === remote.alias) return remote;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
exports.matchRemote = matchRemote;
|
|
50
|
+
exports.matchRemoteWithNameAndExpose = matchRemoteWithNameAndExpose;
|
|
51
|
+
//# sourceMappingURL=manifest.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.cjs","names":[],"sources":["../../src/utils/manifest.ts"],"sourcesContent":["import { Remote } from '../type';\n\n// Function to match a remote with its name and expose\n// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button\n// id: alias(app1) + expose(button) = app1/button\n// id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort\nexport function matchRemoteWithNameAndExpose(\n remotes: Array<Remote>,\n id: string,\n):\n | {\n pkgNameOrAlias: string;\n expose: string;\n remote: Remote;\n }\n | undefined {\n for (const remote of remotes) {\n // match pkgName\n const isNameMatched = id.startsWith(remote.name);\n let expose = id.replace(remote.name, '');\n if (isNameMatched) {\n if (expose.startsWith('/')) {\n const pkgNameOrAlias = remote.name;\n expose = `.${expose}`;\n return {\n pkgNameOrAlias,\n expose,\n remote,\n };\n } else if (expose === '') {\n return {\n pkgNameOrAlias: remote.name,\n expose: '.',\n remote,\n };\n }\n }\n\n // match alias\n const isAliasMatched = remote.alias && id.startsWith(remote.alias);\n let exposeWithAlias = remote.alias && id.replace(remote.alias, '');\n if (remote.alias && isAliasMatched) {\n if (exposeWithAlias && exposeWithAlias.startsWith('/')) {\n const pkgNameOrAlias = remote.alias;\n exposeWithAlias = `.${exposeWithAlias}`;\n return {\n pkgNameOrAlias,\n expose: exposeWithAlias,\n remote,\n };\n } else if (exposeWithAlias === '') {\n return {\n pkgNameOrAlias: remote.alias,\n expose: '.',\n remote,\n };\n }\n }\n }\n\n return;\n}\n\n// Function to match a remote with its name or alias\nexport function matchRemote(\n remotes: Array<Remote>,\n nameOrAlias: string,\n): Remote | undefined {\n for (const remote of remotes) {\n const isNameMatched = nameOrAlias === remote.name;\n if (isNameMatched) {\n return remote;\n }\n\n const isAliasMatched = remote.alias && nameOrAlias === remote.alias;\n if (isAliasMatched) {\n return remote;\n }\n }\n return;\n}\n"],"mappings":";;AAMA,SAAgB,6BACd,SACA,IAOY;AACZ,MAAK,MAAM,UAAU,SAAS;EAE5B,MAAM,gBAAgB,GAAG,WAAW,OAAO,KAAK;EAChD,IAAI,SAAS,GAAG,QAAQ,OAAO,MAAM,GAAG;AACxC,MAAI,eACF;OAAI,OAAO,WAAW,IAAI,EAAE;IAC1B,MAAM,iBAAiB,OAAO;AAC9B,aAAS,IAAI;AACb,WAAO;KACL;KACA;KACA;KACD;cACQ,WAAW,GACpB,QAAO;IACL,gBAAgB,OAAO;IACvB,QAAQ;IACR;IACD;;EAKL,MAAM,iBAAiB,OAAO,SAAS,GAAG,WAAW,OAAO,MAAM;EAClE,IAAI,kBAAkB,OAAO,SAAS,GAAG,QAAQ,OAAO,OAAO,GAAG;AAClE,MAAI,OAAO,SAAS,gBAClB;OAAI,mBAAmB,gBAAgB,WAAW,IAAI,EAAE;IACtD,MAAM,iBAAiB,OAAO;AAC9B,sBAAkB,IAAI;AACtB,WAAO;KACL;KACA,QAAQ;KACR;KACD;cACQ,oBAAoB,GAC7B,QAAO;IACL,gBAAgB,OAAO;IACvB,QAAQ;IACR;IACD;;;;AAST,SAAgB,YACd,SACA,aACoB;AACpB,MAAK,MAAM,UAAU,SAAS;AAE5B,MADsB,gBAAgB,OAAO,KAE3C,QAAO;AAIT,MADuB,OAAO,SAAS,gBAAgB,OAAO,MAE5D,QAAO"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Remote } from "../type/config.js";
|
|
2
|
+
import "../type/index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/manifest.d.ts
|
|
5
|
+
declare function matchRemoteWithNameAndExpose(remotes: Array<Remote>, id: string): {
|
|
6
|
+
pkgNameOrAlias: string;
|
|
7
|
+
expose: string;
|
|
8
|
+
remote: Remote;
|
|
9
|
+
} | undefined;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { matchRemoteWithNameAndExpose };
|
|
12
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/utils/manifest.ts
|
|
2
|
+
function matchRemoteWithNameAndExpose(remotes, id) {
|
|
3
|
+
for (const remote of remotes) {
|
|
4
|
+
const isNameMatched = id.startsWith(remote.name);
|
|
5
|
+
let expose = id.replace(remote.name, "");
|
|
6
|
+
if (isNameMatched) {
|
|
7
|
+
if (expose.startsWith("/")) {
|
|
8
|
+
const pkgNameOrAlias = remote.name;
|
|
9
|
+
expose = `.${expose}`;
|
|
10
|
+
return {
|
|
11
|
+
pkgNameOrAlias,
|
|
12
|
+
expose,
|
|
13
|
+
remote
|
|
14
|
+
};
|
|
15
|
+
} else if (expose === "") return {
|
|
16
|
+
pkgNameOrAlias: remote.name,
|
|
17
|
+
expose: ".",
|
|
18
|
+
remote
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const isAliasMatched = remote.alias && id.startsWith(remote.alias);
|
|
22
|
+
let exposeWithAlias = remote.alias && id.replace(remote.alias, "");
|
|
23
|
+
if (remote.alias && isAliasMatched) {
|
|
24
|
+
if (exposeWithAlias && exposeWithAlias.startsWith("/")) {
|
|
25
|
+
const pkgNameOrAlias = remote.alias;
|
|
26
|
+
exposeWithAlias = `.${exposeWithAlias}`;
|
|
27
|
+
return {
|
|
28
|
+
pkgNameOrAlias,
|
|
29
|
+
expose: exposeWithAlias,
|
|
30
|
+
remote
|
|
31
|
+
};
|
|
32
|
+
} else if (exposeWithAlias === "") return {
|
|
33
|
+
pkgNameOrAlias: remote.alias,
|
|
34
|
+
expose: ".",
|
|
35
|
+
remote
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function matchRemote(remotes, nameOrAlias) {
|
|
41
|
+
for (const remote of remotes) {
|
|
42
|
+
if (nameOrAlias === remote.name) return remote;
|
|
43
|
+
if (remote.alias && nameOrAlias === remote.alias) return remote;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { matchRemote, matchRemoteWithNameAndExpose };
|
|
49
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","names":[],"sources":["../../src/utils/manifest.ts"],"sourcesContent":["import { Remote } from '../type';\n\n// Function to match a remote with its name and expose\n// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button\n// id: alias(app1) + expose(button) = app1/button\n// id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort\nexport function matchRemoteWithNameAndExpose(\n remotes: Array<Remote>,\n id: string,\n):\n | {\n pkgNameOrAlias: string;\n expose: string;\n remote: Remote;\n }\n | undefined {\n for (const remote of remotes) {\n // match pkgName\n const isNameMatched = id.startsWith(remote.name);\n let expose = id.replace(remote.name, '');\n if (isNameMatched) {\n if (expose.startsWith('/')) {\n const pkgNameOrAlias = remote.name;\n expose = `.${expose}`;\n return {\n pkgNameOrAlias,\n expose,\n remote,\n };\n } else if (expose === '') {\n return {\n pkgNameOrAlias: remote.name,\n expose: '.',\n remote,\n };\n }\n }\n\n // match alias\n const isAliasMatched = remote.alias && id.startsWith(remote.alias);\n let exposeWithAlias = remote.alias && id.replace(remote.alias, '');\n if (remote.alias && isAliasMatched) {\n if (exposeWithAlias && exposeWithAlias.startsWith('/')) {\n const pkgNameOrAlias = remote.alias;\n exposeWithAlias = `.${exposeWithAlias}`;\n return {\n pkgNameOrAlias,\n expose: exposeWithAlias,\n remote,\n };\n } else if (exposeWithAlias === '') {\n return {\n pkgNameOrAlias: remote.alias,\n expose: '.',\n remote,\n };\n }\n }\n }\n\n return;\n}\n\n// Function to match a remote with its name or alias\nexport function matchRemote(\n remotes: Array<Remote>,\n nameOrAlias: string,\n): Remote | undefined {\n for (const remote of remotes) {\n const isNameMatched = nameOrAlias === remote.name;\n if (isNameMatched) {\n return remote;\n }\n\n const isAliasMatched = remote.alias && nameOrAlias === remote.alias;\n if (isAliasMatched) {\n return remote;\n }\n }\n return;\n}\n"],"mappings":";AAMA,SAAgB,6BACd,SACA,IAOY;AACZ,MAAK,MAAM,UAAU,SAAS;EAE5B,MAAM,gBAAgB,GAAG,WAAW,OAAO,KAAK;EAChD,IAAI,SAAS,GAAG,QAAQ,OAAO,MAAM,GAAG;AACxC,MAAI,eACF;OAAI,OAAO,WAAW,IAAI,EAAE;IAC1B,MAAM,iBAAiB,OAAO;AAC9B,aAAS,IAAI;AACb,WAAO;KACL;KACA;KACA;KACD;cACQ,WAAW,GACpB,QAAO;IACL,gBAAgB,OAAO;IACvB,QAAQ;IACR;IACD;;EAKL,MAAM,iBAAiB,OAAO,SAAS,GAAG,WAAW,OAAO,MAAM;EAClE,IAAI,kBAAkB,OAAO,SAAS,GAAG,QAAQ,OAAO,OAAO,GAAG;AAClE,MAAI,OAAO,SAAS,gBAClB;OAAI,mBAAmB,gBAAgB,WAAW,IAAI,EAAE;IACtD,MAAM,iBAAiB,OAAO;AAC9B,sBAAkB,IAAI;AACtB,WAAO;KACL;KACA,QAAQ;KACR;KACD;cACQ,oBAAoB,GAC7B,QAAO;IACL,gBAAgB,OAAO;IACvB,QAAQ;IACR;IACD;;;;AAST,SAAgB,YACd,SACA,aACoB;AACpB,MAAK,MAAM,UAAU,SAAS;AAE5B,MADsB,gBAAgB,OAAO,KAE3C,QAAO;AAIT,MADuB,OAAO,SAAS,gBAAgB,OAAO,MAE5D,QAAO"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const require_global = require('../global.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/utils/plugin.ts
|
|
4
|
+
function registerPlugins(plugins, instance) {
|
|
5
|
+
const globalPlugins = require_global.getGlobalHostPlugins();
|
|
6
|
+
const hookInstances = [
|
|
7
|
+
instance.hooks,
|
|
8
|
+
instance.remoteHandler.hooks,
|
|
9
|
+
instance.sharedHandler.hooks,
|
|
10
|
+
instance.snapshotHandler.hooks,
|
|
11
|
+
instance.loaderHook,
|
|
12
|
+
instance.bridgeHook
|
|
13
|
+
];
|
|
14
|
+
if (globalPlugins.length > 0) globalPlugins.forEach((plugin) => {
|
|
15
|
+
if (plugins?.find((item) => item.name !== plugin.name)) plugins.push(plugin);
|
|
16
|
+
});
|
|
17
|
+
if (plugins && plugins.length > 0) plugins.forEach((plugin) => {
|
|
18
|
+
hookInstances.forEach((hookInstance) => {
|
|
19
|
+
hookInstance.applyPlugin(plugin, instance);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
return plugins;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.registerPlugins = registerPlugins;
|
|
27
|
+
//# sourceMappingURL=plugin.cjs.map
|