@module-federation/runtime-core 2.0.1 → 2.2.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/_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 +129 -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 +45 -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 +30 -0
- package/dist/helpers.js +44 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.cjs +60 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +29 -1
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/module/index.cjs +129 -0
- package/dist/module/index.cjs.map +1 -0
- package/dist/module/index.d.ts +31 -0
- package/dist/module/index.js +129 -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 +190 -0
- package/dist/plugins/snapshot/SnapshotHandler.cjs.map +1 -0
- package/dist/plugins/snapshot/SnapshotHandler.d.ts +66 -0
- package/dist/plugins/snapshot/SnapshotHandler.js +189 -0
- package/dist/plugins/snapshot/SnapshotHandler.js.map +1 -0
- package/dist/plugins/snapshot/index.cjs +63 -0
- package/dist/plugins/snapshot/index.cjs.map +1 -0
- package/dist/plugins/snapshot/index.js +62 -0
- package/dist/plugins/snapshot/index.js.map +1 -0
- package/dist/remote/index.cjs +304 -0
- package/dist/remote/index.cjs.map +1 -0
- package/dist/remote/index.d.ts +119 -0
- package/dist/remote/index.js +304 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/shared/index.cjs +303 -0
- package/dist/shared/index.cjs.map +1 -0
- package/dist/shared/index.d.ts +82 -0
- package/dist/shared/index.js +303 -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 +4 -1
- package/dist/types.js +1 -0
- package/dist/utils/context.cjs +45 -0
- package/dist/utils/context.cjs.map +1 -0
- package/dist/utils/context.d.ts +1 -0
- package/dist/utils/context.js +44 -0
- package/dist/utils/context.js.map +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 +8 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/load.cjs +179 -0
- package/dist/utils/load.cjs.map +1 -0
- package/dist/utils/load.d.ts +14 -0
- package/dist/utils/load.js +177 -0
- package/dist/utils/load.js.map +1 -0
- package/dist/utils/logger.cjs +34 -0
- package/dist/utils/logger.cjs.map +1 -0
- package/dist/utils/logger.d.ts +10 -0
- package/dist/utils/logger.js +31 -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 +10 -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 +1 -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 +8 -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 +23 -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 +8 -0
- package/dist/utils/tool.js +71 -0
- package/dist/utils/tool.js.map +1 -0
- package/package.json +16 -9
- package/dist/index.cjs.cjs +0 -3442
- package/dist/index.cjs.cjs.map +0 -1
- package/dist/index.cjs.d.ts +0 -1
- package/dist/index.esm.js +0 -3418
- 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 -25
- 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,44 @@
|
|
|
1
|
+
//#region src/utils/context.ts
|
|
2
|
+
function remoteToEntry(r) {
|
|
3
|
+
return {
|
|
4
|
+
name: r.name,
|
|
5
|
+
alias: r.alias,
|
|
6
|
+
entry: "entry" in r ? r.entry : void 0,
|
|
7
|
+
version: "version" in r ? r.version : void 0,
|
|
8
|
+
type: r.type,
|
|
9
|
+
entryGlobalName: r.entryGlobalName,
|
|
10
|
+
shareScope: r.shareScope
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build a partial MFContext from runtime Options.
|
|
15
|
+
* Used to enrich diagnostic entries with host context at error sites.
|
|
16
|
+
*/
|
|
17
|
+
function optionsToMFContext(options) {
|
|
18
|
+
const shared = {};
|
|
19
|
+
for (const [pkgName, versions] of Object.entries(options.shared)) {
|
|
20
|
+
const first = versions[0];
|
|
21
|
+
if (first) shared[pkgName] = {
|
|
22
|
+
version: first.version,
|
|
23
|
+
singleton: first.shareConfig?.singleton,
|
|
24
|
+
requiredVersion: first.shareConfig?.requiredVersion === false ? false : first.shareConfig?.requiredVersion,
|
|
25
|
+
eager: first.eager,
|
|
26
|
+
strictVersion: first.shareConfig?.strictVersion
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
project: {
|
|
31
|
+
name: options.name,
|
|
32
|
+
mfRole: options.remotes?.length > 0 ? "host" : "unknown"
|
|
33
|
+
},
|
|
34
|
+
mfConfig: {
|
|
35
|
+
name: options.name,
|
|
36
|
+
remotes: options.remotes?.map(remoteToEntry) ?? [],
|
|
37
|
+
shared
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { optionsToMFContext };
|
|
44
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../../src/utils/context.ts"],"sourcesContent":["import type { MFContext } from '@module-federation/error-codes';\nimport type { Options, Remote } from '../type';\n\nfunction remoteToEntry(\n r: Remote,\n): import('@module-federation/error-codes').MFRemoteEntry {\n return {\n name: r.name,\n alias: r.alias,\n entry: 'entry' in r ? (r as { entry: string }).entry : undefined,\n version: 'version' in r ? (r as { version: string }).version : undefined,\n type: r.type,\n entryGlobalName: r.entryGlobalName,\n shareScope: r.shareScope,\n };\n}\n\n/**\n * Build a partial MFContext from runtime Options.\n * Used to enrich diagnostic entries with host context at error sites.\n */\nexport function optionsToMFContext(options: Options): Partial<MFContext> {\n const shared: MFContext['mfConfig'] extends undefined\n ? never\n : NonNullable<MFContext['mfConfig']>['shared'] = {};\n\n for (const [pkgName, versions] of Object.entries(options.shared)) {\n const first = versions[0];\n if (first) {\n shared[pkgName] = {\n version: first.version,\n singleton: first.shareConfig?.singleton,\n requiredVersion:\n first.shareConfig?.requiredVersion === false\n ? false\n : first.shareConfig?.requiredVersion,\n eager: first.eager,\n strictVersion: first.shareConfig?.strictVersion,\n };\n }\n }\n\n return {\n project: {\n name: options.name,\n mfRole: options.remotes?.length > 0 ? 'host' : 'unknown',\n },\n mfConfig: {\n name: options.name,\n remotes: options.remotes?.map(remoteToEntry) ?? [],\n shared,\n },\n };\n}\n"],"mappings":";AAGA,SAAS,cACP,GACwD;AACxD,QAAO;EACL,MAAM,EAAE;EACR,OAAO,EAAE;EACT,OAAO,WAAW,IAAK,EAAwB,QAAQ;EACvD,SAAS,aAAa,IAAK,EAA0B,UAAU;EAC/D,MAAM,EAAE;EACR,iBAAiB,EAAE;EACnB,YAAY,EAAE;EACf;;;;;;AAOH,SAAgB,mBAAmB,SAAsC;CACvE,MAAM,SAE6C,EAAE;AAErD,MAAK,MAAM,CAAC,SAAS,aAAa,OAAO,QAAQ,QAAQ,OAAO,EAAE;EAChE,MAAM,QAAQ,SAAS;AACvB,MAAI,MACF,QAAO,WAAW;GAChB,SAAS,MAAM;GACf,WAAW,MAAM,aAAa;GAC9B,iBACE,MAAM,aAAa,oBAAoB,QACnC,QACA,MAAM,aAAa;GACzB,OAAO,MAAM;GACb,eAAe,MAAM,aAAa;GACnC;;AAIL,QAAO;EACL,SAAS;GACP,MAAM,QAAQ;GACd,QAAQ,QAAQ,SAAS,SAAS,IAAI,SAAS;GAChD;EACD,UAAU;GACR,MAAM,QAAQ;GACd,SAAS,QAAQ,SAAS,IAAI,cAAc,IAAI,EAAE;GAClD;GACD;EACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
let _module_federation_sdk = require("@module-federation/sdk");
|
|
2
|
+
|
|
3
|
+
//#region src/utils/env.ts
|
|
4
|
+
function getBuilderId() {
|
|
5
|
+
return typeof FEDERATION_BUILD_IDENTIFIER !== "undefined" ? FEDERATION_BUILD_IDENTIFIER : "";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.getBuilderId = getBuilderId;
|
|
10
|
+
//# sourceMappingURL=env.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.cjs","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["export {\n isBrowserEnv,\n isBrowserEnvValue,\n isDebugMode,\n} from '@module-federation/sdk';\n\nexport function isDevelopmentMode(): boolean {\n return true;\n}\n\nexport function getBuilderId(): string {\n //@ts-ignore\n return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined'\n ? //@ts-ignore\n FEDERATION_BUILD_IDENTIFIER\n : '';\n}\n"],"mappings":";;;AAUA,SAAgB,eAAuB;AAErC,QAAO,OAAO,gCAAgC,cAE1C,8BACA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "@module-federation/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/env.ts
|
|
4
|
+
function getBuilderId() {
|
|
5
|
+
return typeof FEDERATION_BUILD_IDENTIFIER !== "undefined" ? FEDERATION_BUILD_IDENTIFIER : "";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { getBuilderId };
|
|
10
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["export {\n isBrowserEnv,\n isBrowserEnvValue,\n isDebugMode,\n} from '@module-federation/sdk';\n\nexport function isDevelopmentMode(): boolean {\n return true;\n}\n\nexport function getBuilderId(): string {\n //@ts-ignore\n return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined'\n ? //@ts-ignore\n FEDERATION_BUILD_IDENTIFIER\n : '';\n}\n"],"mappings":";;;AAUA,SAAgB,eAAuB;AAErC,QAAO,OAAO,gCAAgC,cAE1C,8BACA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const require_syncHook = require('./syncHook.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/utils/hooks/asyncHook.ts
|
|
4
|
+
var AsyncHook = class extends require_syncHook.SyncHook {
|
|
5
|
+
emit(...data) {
|
|
6
|
+
let result;
|
|
7
|
+
const ls = Array.from(this.listeners);
|
|
8
|
+
if (ls.length > 0) {
|
|
9
|
+
let i = 0;
|
|
10
|
+
const call = (prev) => {
|
|
11
|
+
if (prev === false) return false;
|
|
12
|
+
else if (i < ls.length) return Promise.resolve(ls[i++].apply(null, data)).then(call);
|
|
13
|
+
else return prev;
|
|
14
|
+
};
|
|
15
|
+
result = call();
|
|
16
|
+
}
|
|
17
|
+
return Promise.resolve(result);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.AsyncHook = AsyncHook;
|
|
23
|
+
//# sourceMappingURL=asyncHook.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncHook.cjs","names":["SyncHook"],"sources":["../../../src/utils/hooks/asyncHook.ts"],"sourcesContent":["import { ArgsType, SyncHook } from './syncHook';\n\ntype CallbackReturnType = void | false | Promise<void | false>;\n\nexport class AsyncHook<\n T,\n ExternalEmitReturnType = CallbackReturnType,\n> extends SyncHook<T, ExternalEmitReturnType> {\n override emit(\n ...data: ArgsType<T>\n ): Promise<void | false | ExternalEmitReturnType> {\n let result;\n const ls = Array.from(this.listeners);\n if (ls.length > 0) {\n let i = 0;\n const call = (prev?: any): any => {\n if (prev === false) {\n return false; // Abort process\n } else if (i < ls.length) {\n return Promise.resolve(ls[i++].apply(null, data)).then(call);\n } else {\n return prev;\n }\n };\n result = call();\n }\n return Promise.resolve(result);\n }\n}\n"],"mappings":";;;AAIA,IAAa,YAAb,cAGUA,0BAAoC;CAC5C,AAAS,KACP,GAAG,MAC6C;EAChD,IAAI;EACJ,MAAM,KAAK,MAAM,KAAK,KAAK,UAAU;AACrC,MAAI,GAAG,SAAS,GAAG;GACjB,IAAI,IAAI;GACR,MAAM,QAAQ,SAAoB;AAChC,QAAI,SAAS,MACX,QAAO;aACE,IAAI,GAAG,OAChB,QAAO,QAAQ,QAAQ,GAAG,KAAK,MAAM,MAAM,KAAK,CAAC,CAAC,KAAK,KAAK;QAE5D,QAAO;;AAGX,YAAS,MAAM;;AAEjB,SAAO,QAAQ,QAAQ,OAAO"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ArgsType, SyncHook } from "./syncHook.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/hooks/asyncHook.d.ts
|
|
4
|
+
type CallbackReturnType = void | false | Promise<void | false>;
|
|
5
|
+
declare class AsyncHook<T, ExternalEmitReturnType = CallbackReturnType> extends SyncHook<T, ExternalEmitReturnType> {
|
|
6
|
+
emit(...data: ArgsType<T>): Promise<void | false | ExternalEmitReturnType>;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { AsyncHook };
|
|
10
|
+
//# sourceMappingURL=asyncHook.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SyncHook } from "./syncHook.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/hooks/asyncHook.ts
|
|
4
|
+
var AsyncHook = class extends SyncHook {
|
|
5
|
+
emit(...data) {
|
|
6
|
+
let result;
|
|
7
|
+
const ls = Array.from(this.listeners);
|
|
8
|
+
if (ls.length > 0) {
|
|
9
|
+
let i = 0;
|
|
10
|
+
const call = (prev) => {
|
|
11
|
+
if (prev === false) return false;
|
|
12
|
+
else if (i < ls.length) return Promise.resolve(ls[i++].apply(null, data)).then(call);
|
|
13
|
+
else return prev;
|
|
14
|
+
};
|
|
15
|
+
result = call();
|
|
16
|
+
}
|
|
17
|
+
return Promise.resolve(result);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { AsyncHook };
|
|
23
|
+
//# sourceMappingURL=asyncHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncHook.js","names":[],"sources":["../../../src/utils/hooks/asyncHook.ts"],"sourcesContent":["import { ArgsType, SyncHook } from './syncHook';\n\ntype CallbackReturnType = void | false | Promise<void | false>;\n\nexport class AsyncHook<\n T,\n ExternalEmitReturnType = CallbackReturnType,\n> extends SyncHook<T, ExternalEmitReturnType> {\n override emit(\n ...data: ArgsType<T>\n ): Promise<void | false | ExternalEmitReturnType> {\n let result;\n const ls = Array.from(this.listeners);\n if (ls.length > 0) {\n let i = 0;\n const call = (prev?: any): any => {\n if (prev === false) {\n return false; // Abort process\n } else if (i < ls.length) {\n return Promise.resolve(ls[i++].apply(null, data)).then(call);\n } else {\n return prev;\n }\n };\n result = call();\n }\n return Promise.resolve(result);\n }\n}\n"],"mappings":";;;AAIA,IAAa,YAAb,cAGU,SAAoC;CAC5C,AAAS,KACP,GAAG,MAC6C;EAChD,IAAI;EACJ,MAAM,KAAK,MAAM,KAAK,KAAK,UAAU;AACrC,MAAI,GAAG,SAAS,GAAG;GACjB,IAAI,IAAI;GACR,MAAM,QAAQ,SAAoB;AAChC,QAAI,SAAS,MACX,QAAO;aACE,IAAI,GAAG,OAChB,QAAO,QAAQ,QAAQ,GAAG,KAAK,MAAM,MAAM,KAAK,CAAC,CAAC,KAAK,KAAK;QAE5D,QAAO;;AAGX,YAAS,MAAM;;AAEjB,SAAO,QAAQ,QAAQ,OAAO"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const require_logger = require('../logger.cjs');
|
|
2
|
+
const require_tool = require('../tool.cjs');
|
|
3
|
+
const require_syncHook = require('./syncHook.cjs');
|
|
4
|
+
const require_syncWaterfallHook = require('./syncWaterfallHook.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/utils/hooks/asyncWaterfallHooks.ts
|
|
7
|
+
var AsyncWaterfallHook = class extends require_syncHook.SyncHook {
|
|
8
|
+
constructor(type) {
|
|
9
|
+
super();
|
|
10
|
+
this.onerror = require_logger.error;
|
|
11
|
+
this.type = type;
|
|
12
|
+
}
|
|
13
|
+
emit(data) {
|
|
14
|
+
if (!require_tool.isObject(data)) require_logger.error(`The response data for the "${this.type}" hook must be an object.`);
|
|
15
|
+
const ls = Array.from(this.listeners);
|
|
16
|
+
if (ls.length > 0) {
|
|
17
|
+
let i = 0;
|
|
18
|
+
const processError = (e) => {
|
|
19
|
+
require_logger.warn(e);
|
|
20
|
+
this.onerror(e);
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
const call = (prevData) => {
|
|
24
|
+
if (require_syncWaterfallHook.checkReturnData(data, prevData)) {
|
|
25
|
+
data = prevData;
|
|
26
|
+
if (i < ls.length) try {
|
|
27
|
+
return Promise.resolve(ls[i++](data)).then(call, processError);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return processError(e);
|
|
30
|
+
}
|
|
31
|
+
} else this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
34
|
+
return Promise.resolve(call(data));
|
|
35
|
+
}
|
|
36
|
+
return Promise.resolve(data);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.AsyncWaterfallHook = AsyncWaterfallHook;
|
|
42
|
+
//# sourceMappingURL=asyncWaterfallHooks.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncWaterfallHooks.cjs","names":["SyncHook","error","isObject","checkReturnData"],"sources":["../../../src/utils/hooks/asyncWaterfallHooks.ts"],"sourcesContent":["import { error, warn } from '../logger';\nimport { isObject } from '../tool';\nimport { SyncHook } from './syncHook';\nimport { checkReturnData } from './syncWaterfallHook';\n\ntype CallbackReturnType<T> = T | Promise<T>;\n\nexport class AsyncWaterfallHook<T extends Record<string, any>> extends SyncHook<\n [T],\n CallbackReturnType<T>\n> {\n onerror: (errMsg: string | Error | unknown) => void = error;\n constructor(type: string) {\n super();\n this.type = type;\n }\n\n override emit(data: T): Promise<T> {\n if (!isObject(data)) {\n error(`The response data for the \"${this.type}\" hook must be an object.`);\n }\n const ls = Array.from(this.listeners);\n\n if (ls.length > 0) {\n let i = 0;\n const processError = (e: any) => {\n warn(e);\n this.onerror(e);\n return data;\n };\n\n const call = (prevData: T): any => {\n if (checkReturnData(data, prevData)) {\n data = prevData as T;\n if (i < ls.length) {\n try {\n return Promise.resolve(ls[i++](data)).then(call, processError);\n } catch (e) {\n return processError(e);\n }\n }\n } else {\n this.onerror(\n `A plugin returned an incorrect value for the \"${this.type}\" type.`,\n );\n }\n return data;\n };\n return Promise.resolve(call(data));\n }\n return Promise.resolve(data);\n }\n}\n"],"mappings":";;;;;;AAOA,IAAa,qBAAb,cAAuEA,0BAGrE;CAEA,YAAY,MAAc;AACxB,SAAO;iBAF6CC;AAGpD,OAAK,OAAO;;CAGd,AAAS,KAAK,MAAqB;AACjC,MAAI,CAACC,sBAAS,KAAK,CACjB,sBAAM,8BAA8B,KAAK,KAAK,2BAA2B;EAE3E,MAAM,KAAK,MAAM,KAAK,KAAK,UAAU;AAErC,MAAI,GAAG,SAAS,GAAG;GACjB,IAAI,IAAI;GACR,MAAM,gBAAgB,MAAW;AAC/B,wBAAK,EAAE;AACP,SAAK,QAAQ,EAAE;AACf,WAAO;;GAGT,MAAM,QAAQ,aAAqB;AACjC,QAAIC,0CAAgB,MAAM,SAAS,EAAE;AACnC,YAAO;AACP,SAAI,IAAI,GAAG,OACT,KAAI;AACF,aAAO,QAAQ,QAAQ,GAAG,KAAK,KAAK,CAAC,CAAC,KAAK,MAAM,aAAa;cACvD,GAAG;AACV,aAAO,aAAa,EAAE;;UAI1B,MAAK,QACH,iDAAiD,KAAK,KAAK,SAC5D;AAEH,WAAO;;AAET,UAAO,QAAQ,QAAQ,KAAK,KAAK,CAAC;;AAEpC,SAAO,QAAQ,QAAQ,KAAK"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SyncHook } from "./syncHook.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/hooks/asyncWaterfallHooks.d.ts
|
|
4
|
+
type CallbackReturnType<T> = T | Promise<T>;
|
|
5
|
+
declare class AsyncWaterfallHook<T extends Record<string, any>> extends SyncHook<[T], CallbackReturnType<T>> {
|
|
6
|
+
onerror: (errMsg: string | Error | unknown) => void;
|
|
7
|
+
constructor(type: string);
|
|
8
|
+
emit(data: T): Promise<T>;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { AsyncWaterfallHook };
|
|
12
|
+
//# sourceMappingURL=asyncWaterfallHooks.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { error, warn } from "../logger.js";
|
|
2
|
+
import { isObject } from "../tool.js";
|
|
3
|
+
import { SyncHook } from "./syncHook.js";
|
|
4
|
+
import { checkReturnData } from "./syncWaterfallHook.js";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/hooks/asyncWaterfallHooks.ts
|
|
7
|
+
var AsyncWaterfallHook = class extends SyncHook {
|
|
8
|
+
constructor(type) {
|
|
9
|
+
super();
|
|
10
|
+
this.onerror = error;
|
|
11
|
+
this.type = type;
|
|
12
|
+
}
|
|
13
|
+
emit(data) {
|
|
14
|
+
if (!isObject(data)) error(`The response data for the "${this.type}" hook must be an object.`);
|
|
15
|
+
const ls = Array.from(this.listeners);
|
|
16
|
+
if (ls.length > 0) {
|
|
17
|
+
let i = 0;
|
|
18
|
+
const processError = (e) => {
|
|
19
|
+
warn(e);
|
|
20
|
+
this.onerror(e);
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
const call = (prevData) => {
|
|
24
|
+
if (checkReturnData(data, prevData)) {
|
|
25
|
+
data = prevData;
|
|
26
|
+
if (i < ls.length) try {
|
|
27
|
+
return Promise.resolve(ls[i++](data)).then(call, processError);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return processError(e);
|
|
30
|
+
}
|
|
31
|
+
} else this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
34
|
+
return Promise.resolve(call(data));
|
|
35
|
+
}
|
|
36
|
+
return Promise.resolve(data);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { AsyncWaterfallHook };
|
|
42
|
+
//# sourceMappingURL=asyncWaterfallHooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncWaterfallHooks.js","names":[],"sources":["../../../src/utils/hooks/asyncWaterfallHooks.ts"],"sourcesContent":["import { error, warn } from '../logger';\nimport { isObject } from '../tool';\nimport { SyncHook } from './syncHook';\nimport { checkReturnData } from './syncWaterfallHook';\n\ntype CallbackReturnType<T> = T | Promise<T>;\n\nexport class AsyncWaterfallHook<T extends Record<string, any>> extends SyncHook<\n [T],\n CallbackReturnType<T>\n> {\n onerror: (errMsg: string | Error | unknown) => void = error;\n constructor(type: string) {\n super();\n this.type = type;\n }\n\n override emit(data: T): Promise<T> {\n if (!isObject(data)) {\n error(`The response data for the \"${this.type}\" hook must be an object.`);\n }\n const ls = Array.from(this.listeners);\n\n if (ls.length > 0) {\n let i = 0;\n const processError = (e: any) => {\n warn(e);\n this.onerror(e);\n return data;\n };\n\n const call = (prevData: T): any => {\n if (checkReturnData(data, prevData)) {\n data = prevData as T;\n if (i < ls.length) {\n try {\n return Promise.resolve(ls[i++](data)).then(call, processError);\n } catch (e) {\n return processError(e);\n }\n }\n } else {\n this.onerror(\n `A plugin returned an incorrect value for the \"${this.type}\" type.`,\n );\n }\n return data;\n };\n return Promise.resolve(call(data));\n }\n return Promise.resolve(data);\n }\n}\n"],"mappings":";;;;;;AAOA,IAAa,qBAAb,cAAuE,SAGrE;CAEA,YAAY,MAAc;AACxB,SAAO;iBAF6C;AAGpD,OAAK,OAAO;;CAGd,AAAS,KAAK,MAAqB;AACjC,MAAI,CAAC,SAAS,KAAK,CACjB,OAAM,8BAA8B,KAAK,KAAK,2BAA2B;EAE3E,MAAM,KAAK,MAAM,KAAK,KAAK,UAAU;AAErC,MAAI,GAAG,SAAS,GAAG;GACjB,IAAI,IAAI;GACR,MAAM,gBAAgB,MAAW;AAC/B,SAAK,EAAE;AACP,SAAK,QAAQ,EAAE;AACf,WAAO;;GAGT,MAAM,QAAQ,aAAqB;AACjC,QAAI,gBAAgB,MAAM,SAAS,EAAE;AACnC,YAAO;AACP,SAAI,IAAI,GAAG,OACT,KAAI;AACF,aAAO,QAAQ,QAAQ,GAAG,KAAK,KAAK,CAAC,CAAC,KAAK,MAAM,aAAa;cACvD,GAAG;AACV,aAAO,aAAa,EAAE;;UAI1B,MAAK,QACH,iDAAiD,KAAK,KAAK,SAC5D;AAEH,WAAO;;AAET,UAAO,QAAQ,QAAQ,KAAK,KAAK,CAAC;;AAEpC,SAAO,QAAQ,QAAQ,KAAK"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const require_syncHook = require('./syncHook.cjs');
|
|
2
|
+
const require_asyncHook = require('./asyncHook.cjs');
|
|
3
|
+
const require_syncWaterfallHook = require('./syncWaterfallHook.cjs');
|
|
4
|
+
const require_asyncWaterfallHooks = require('./asyncWaterfallHooks.cjs');
|
|
5
|
+
const require_pluginSystem = require('./pluginSystem.cjs');
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SyncHook } from "./syncHook.js";
|
|
2
|
+
import { AsyncHook } from "./asyncHook.js";
|
|
3
|
+
import { SyncWaterfallHook } from "./syncWaterfallHook.js";
|
|
4
|
+
import { AsyncWaterfallHook } from "./asyncWaterfallHooks.js";
|
|
5
|
+
import { Plugin, PluginSystem } from "./pluginSystem.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SyncHook } from "./syncHook.js";
|
|
2
|
+
import { AsyncHook } from "./asyncHook.js";
|
|
3
|
+
import { SyncWaterfallHook } from "./syncWaterfallHook.js";
|
|
4
|
+
import { AsyncWaterfallHook } from "./asyncWaterfallHooks.js";
|
|
5
|
+
import { PluginSystem } from "./pluginSystem.js";
|
|
6
|
+
|
|
7
|
+
export { };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const require_logger = require('../logger.cjs');
|
|
2
|
+
const require_tool = require('../tool.cjs');
|
|
3
|
+
require('../index.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/utils/hooks/pluginSystem.ts
|
|
6
|
+
var PluginSystem = class {
|
|
7
|
+
constructor(lifecycle) {
|
|
8
|
+
this.registerPlugins = {};
|
|
9
|
+
this.lifecycle = lifecycle;
|
|
10
|
+
this.lifecycleKeys = Object.keys(lifecycle);
|
|
11
|
+
}
|
|
12
|
+
applyPlugin(plugin, instance) {
|
|
13
|
+
require_logger.assert(require_tool.isPlainObject(plugin), "Plugin configuration is invalid.");
|
|
14
|
+
const pluginName = plugin.name;
|
|
15
|
+
require_logger.assert(pluginName, "A name must be provided by the plugin.");
|
|
16
|
+
if (!this.registerPlugins[pluginName]) {
|
|
17
|
+
this.registerPlugins[pluginName] = plugin;
|
|
18
|
+
plugin.apply?.(instance);
|
|
19
|
+
Object.keys(this.lifecycle).forEach((key) => {
|
|
20
|
+
const pluginLife = plugin[key];
|
|
21
|
+
if (pluginLife) this.lifecycle[key].on(pluginLife);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
removePlugin(pluginName) {
|
|
26
|
+
require_logger.assert(pluginName, "A name is required.");
|
|
27
|
+
const plugin = this.registerPlugins[pluginName];
|
|
28
|
+
require_logger.assert(plugin, `The plugin "${pluginName}" is not registered.`);
|
|
29
|
+
Object.keys(plugin).forEach((key) => {
|
|
30
|
+
if (key !== "name") this.lifecycle[key].remove(plugin[key]);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.PluginSystem = PluginSystem;
|
|
37
|
+
//# sourceMappingURL=pluginSystem.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginSystem.cjs","names":["isPlainObject"],"sources":["../../../src/utils/hooks/pluginSystem.ts"],"sourcesContent":["import type { ModuleFederation } from '../../core';\nimport { assert, isPlainObject } from '../../utils';\n\nexport type Plugin<T extends Record<string, any>> = {\n [k in keyof T]?: Parameters<T[k]['on']>[0];\n} & {\n name: string;\n version?: string;\n apply?: (instance: ModuleFederation) => void;\n};\n\nexport class PluginSystem<T extends Record<string, any>> {\n lifecycle: T;\n lifecycleKeys: Array<keyof T>;\n registerPlugins: Record<string, Plugin<T>> = {};\n\n constructor(lifecycle: T) {\n this.lifecycle = lifecycle;\n this.lifecycleKeys = Object.keys(lifecycle);\n }\n\n applyPlugin(plugin: Plugin<T>, instance: ModuleFederation): void {\n assert(isPlainObject(plugin), 'Plugin configuration is invalid.');\n // The plugin's name is mandatory and must be unique\n const pluginName = plugin.name;\n assert(pluginName, 'A name must be provided by the plugin.');\n\n if (!this.registerPlugins[pluginName]) {\n this.registerPlugins[pluginName] = plugin;\n plugin.apply?.(instance);\n\n Object.keys(this.lifecycle).forEach((key) => {\n const pluginLife = plugin[key as string];\n if (pluginLife) {\n this.lifecycle[key].on(pluginLife);\n }\n });\n }\n }\n\n removePlugin(pluginName: string): void {\n assert(pluginName, 'A name is required.');\n const plugin = this.registerPlugins[pluginName];\n assert(plugin, `The plugin \"${pluginName}\" is not registered.`);\n\n Object.keys(plugin).forEach((key) => {\n if (key !== 'name') {\n this.lifecycle[key].remove(plugin[key as string]);\n }\n });\n }\n}\n"],"mappings":";;;;;AAWA,IAAa,eAAb,MAAyD;CAKvD,YAAY,WAAc;yBAFmB,EAAE;AAG7C,OAAK,YAAY;AACjB,OAAK,gBAAgB,OAAO,KAAK,UAAU;;CAG7C,YAAY,QAAmB,UAAkC;AAC/D,wBAAOA,2BAAc,OAAO,EAAE,mCAAmC;EAEjE,MAAM,aAAa,OAAO;AAC1B,wBAAO,YAAY,yCAAyC;AAE5D,MAAI,CAAC,KAAK,gBAAgB,aAAa;AACrC,QAAK,gBAAgB,cAAc;AACnC,UAAO,QAAQ,SAAS;AAExB,UAAO,KAAK,KAAK,UAAU,CAAC,SAAS,QAAQ;IAC3C,MAAM,aAAa,OAAO;AAC1B,QAAI,WACF,MAAK,UAAU,KAAK,GAAG,WAAW;KAEpC;;;CAIN,aAAa,YAA0B;AACrC,wBAAO,YAAY,sBAAsB;EACzC,MAAM,SAAS,KAAK,gBAAgB;AACpC,wBAAO,QAAQ,eAAe,WAAW,sBAAsB;AAE/D,SAAO,KAAK,OAAO,CAAC,SAAS,QAAQ;AACnC,OAAI,QAAQ,OACV,MAAK,UAAU,KAAK,OAAO,OAAO,KAAe;IAEnD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ModuleFederation } from "../../core.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/hooks/pluginSystem.d.ts
|
|
4
|
+
type Plugin<T extends Record<string, any>> = { [k in keyof T]?: Parameters<T[k]['on']>[0] } & {
|
|
5
|
+
name: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
apply?: (instance: ModuleFederation) => void;
|
|
8
|
+
};
|
|
9
|
+
declare class PluginSystem<T extends Record<string, any>> {
|
|
10
|
+
lifecycle: T;
|
|
11
|
+
lifecycleKeys: Array<keyof T>;
|
|
12
|
+
registerPlugins: Record<string, Plugin<T>>;
|
|
13
|
+
constructor(lifecycle: T);
|
|
14
|
+
applyPlugin(plugin: Plugin<T>, instance: ModuleFederation): void;
|
|
15
|
+
removePlugin(pluginName: string): void;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { PluginSystem };
|
|
19
|
+
//# sourceMappingURL=pluginSystem.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { assert } from "../logger.js";
|
|
2
|
+
import { isPlainObject } from "../tool.js";
|
|
3
|
+
import "../index.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/hooks/pluginSystem.ts
|
|
6
|
+
var PluginSystem = class {
|
|
7
|
+
constructor(lifecycle) {
|
|
8
|
+
this.registerPlugins = {};
|
|
9
|
+
this.lifecycle = lifecycle;
|
|
10
|
+
this.lifecycleKeys = Object.keys(lifecycle);
|
|
11
|
+
}
|
|
12
|
+
applyPlugin(plugin, instance) {
|
|
13
|
+
assert(isPlainObject(plugin), "Plugin configuration is invalid.");
|
|
14
|
+
const pluginName = plugin.name;
|
|
15
|
+
assert(pluginName, "A name must be provided by the plugin.");
|
|
16
|
+
if (!this.registerPlugins[pluginName]) {
|
|
17
|
+
this.registerPlugins[pluginName] = plugin;
|
|
18
|
+
plugin.apply?.(instance);
|
|
19
|
+
Object.keys(this.lifecycle).forEach((key) => {
|
|
20
|
+
const pluginLife = plugin[key];
|
|
21
|
+
if (pluginLife) this.lifecycle[key].on(pluginLife);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
removePlugin(pluginName) {
|
|
26
|
+
assert(pluginName, "A name is required.");
|
|
27
|
+
const plugin = this.registerPlugins[pluginName];
|
|
28
|
+
assert(plugin, `The plugin "${pluginName}" is not registered.`);
|
|
29
|
+
Object.keys(plugin).forEach((key) => {
|
|
30
|
+
if (key !== "name") this.lifecycle[key].remove(plugin[key]);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { PluginSystem };
|
|
37
|
+
//# sourceMappingURL=pluginSystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginSystem.js","names":[],"sources":["../../../src/utils/hooks/pluginSystem.ts"],"sourcesContent":["import type { ModuleFederation } from '../../core';\nimport { assert, isPlainObject } from '../../utils';\n\nexport type Plugin<T extends Record<string, any>> = {\n [k in keyof T]?: Parameters<T[k]['on']>[0];\n} & {\n name: string;\n version?: string;\n apply?: (instance: ModuleFederation) => void;\n};\n\nexport class PluginSystem<T extends Record<string, any>> {\n lifecycle: T;\n lifecycleKeys: Array<keyof T>;\n registerPlugins: Record<string, Plugin<T>> = {};\n\n constructor(lifecycle: T) {\n this.lifecycle = lifecycle;\n this.lifecycleKeys = Object.keys(lifecycle);\n }\n\n applyPlugin(plugin: Plugin<T>, instance: ModuleFederation): void {\n assert(isPlainObject(plugin), 'Plugin configuration is invalid.');\n // The plugin's name is mandatory and must be unique\n const pluginName = plugin.name;\n assert(pluginName, 'A name must be provided by the plugin.');\n\n if (!this.registerPlugins[pluginName]) {\n this.registerPlugins[pluginName] = plugin;\n plugin.apply?.(instance);\n\n Object.keys(this.lifecycle).forEach((key) => {\n const pluginLife = plugin[key as string];\n if (pluginLife) {\n this.lifecycle[key].on(pluginLife);\n }\n });\n }\n }\n\n removePlugin(pluginName: string): void {\n assert(pluginName, 'A name is required.');\n const plugin = this.registerPlugins[pluginName];\n assert(plugin, `The plugin \"${pluginName}\" is not registered.`);\n\n Object.keys(plugin).forEach((key) => {\n if (key !== 'name') {\n this.lifecycle[key].remove(plugin[key as string]);\n }\n });\n }\n}\n"],"mappings":";;;;;AAWA,IAAa,eAAb,MAAyD;CAKvD,YAAY,WAAc;yBAFmB,EAAE;AAG7C,OAAK,YAAY;AACjB,OAAK,gBAAgB,OAAO,KAAK,UAAU;;CAG7C,YAAY,QAAmB,UAAkC;AAC/D,SAAO,cAAc,OAAO,EAAE,mCAAmC;EAEjE,MAAM,aAAa,OAAO;AAC1B,SAAO,YAAY,yCAAyC;AAE5D,MAAI,CAAC,KAAK,gBAAgB,aAAa;AACrC,QAAK,gBAAgB,cAAc;AACnC,UAAO,QAAQ,SAAS;AAExB,UAAO,KAAK,KAAK,UAAU,CAAC,SAAS,QAAQ;IAC3C,MAAM,aAAa,OAAO;AAC1B,QAAI,WACF,MAAK,UAAU,KAAK,GAAG,WAAW;KAEpC;;;CAIN,aAAa,YAA0B;AACrC,SAAO,YAAY,sBAAsB;EACzC,MAAM,SAAS,KAAK,gBAAgB;AACpC,SAAO,QAAQ,eAAe,WAAW,sBAAsB;AAE/D,SAAO,KAAK,OAAO,CAAC,SAAS,QAAQ;AACnC,OAAI,QAAQ,OACV,MAAK,UAAU,KAAK,OAAO,OAAO,KAAe;IAEnD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/hooks/syncHook.ts
|
|
3
|
+
var SyncHook = class {
|
|
4
|
+
constructor(type) {
|
|
5
|
+
this.type = "";
|
|
6
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
7
|
+
if (type) this.type = type;
|
|
8
|
+
}
|
|
9
|
+
on(fn) {
|
|
10
|
+
if (typeof fn === "function") this.listeners.add(fn);
|
|
11
|
+
}
|
|
12
|
+
once(fn) {
|
|
13
|
+
const self = this;
|
|
14
|
+
this.on(function wrapper(...args) {
|
|
15
|
+
self.remove(wrapper);
|
|
16
|
+
return fn.apply(null, args);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
emit(...data) {
|
|
20
|
+
let result;
|
|
21
|
+
if (this.listeners.size > 0) this.listeners.forEach((fn) => {
|
|
22
|
+
result = fn(...data);
|
|
23
|
+
});
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
remove(fn) {
|
|
27
|
+
this.listeners.delete(fn);
|
|
28
|
+
}
|
|
29
|
+
removeAll() {
|
|
30
|
+
this.listeners.clear();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.SyncHook = SyncHook;
|
|
36
|
+
//# sourceMappingURL=syncHook.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncHook.cjs","names":[],"sources":["../../../src/utils/hooks/syncHook.ts"],"sourcesContent":["export type Callback<T, K> = (...args: ArgsType<T>) => K;\nexport type ArgsType<T> = T extends Array<any> ? T : Array<any>;\n\nexport class SyncHook<T, K> {\n type = '';\n listeners = new Set<Callback<T, K>>();\n\n constructor(type?: string) {\n if (type) {\n this.type = type;\n }\n }\n\n on(fn: Callback<T, K>): void {\n if (typeof fn === 'function') {\n this.listeners.add(fn);\n }\n }\n\n once(fn: Callback<T, K>): void {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n this.on(function wrapper(...args) {\n self.remove(wrapper);\n // eslint-disable-next-line prefer-spread\n return fn.apply(null, args);\n });\n }\n\n emit(...data: ArgsType<T>): void | K | Promise<any> {\n let result;\n if (this.listeners.size > 0) {\n // eslint-disable-next-line prefer-spread\n this.listeners.forEach((fn) => {\n result = fn(...data);\n });\n }\n return result;\n }\n\n remove(fn: Callback<T, K>): void {\n this.listeners.delete(fn);\n }\n\n removeAll(): void {\n this.listeners.clear();\n }\n}\n"],"mappings":";;AAGA,IAAa,WAAb,MAA4B;CAI1B,YAAY,MAAe;cAHpB;mCACK,IAAI,KAAqB;AAGnC,MAAI,KACF,MAAK,OAAO;;CAIhB,GAAG,IAA0B;AAC3B,MAAI,OAAO,OAAO,WAChB,MAAK,UAAU,IAAI,GAAG;;CAI1B,KAAK,IAA0B;EAE7B,MAAM,OAAO;AACb,OAAK,GAAG,SAAS,QAAQ,GAAG,MAAM;AAChC,QAAK,OAAO,QAAQ;AAEpB,UAAO,GAAG,MAAM,MAAM,KAAK;IAC3B;;CAGJ,KAAK,GAAG,MAA4C;EAClD,IAAI;AACJ,MAAI,KAAK,UAAU,OAAO,EAExB,MAAK,UAAU,SAAS,OAAO;AAC7B,YAAS,GAAG,GAAG,KAAK;IACpB;AAEJ,SAAO;;CAGT,OAAO,IAA0B;AAC/B,OAAK,UAAU,OAAO,GAAG;;CAG3B,YAAkB;AAChB,OAAK,UAAU,OAAO"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/utils/hooks/syncHook.d.ts
|
|
2
|
+
type Callback<T, K> = (...args: ArgsType<T>) => K;
|
|
3
|
+
type ArgsType<T> = T extends Array<any> ? T : Array<any>;
|
|
4
|
+
declare class SyncHook<T, K> {
|
|
5
|
+
type: string;
|
|
6
|
+
listeners: Set<Callback<T, K>>;
|
|
7
|
+
constructor(type?: string);
|
|
8
|
+
on(fn: Callback<T, K>): void;
|
|
9
|
+
once(fn: Callback<T, K>): void;
|
|
10
|
+
emit(...data: ArgsType<T>): void | K | Promise<any>;
|
|
11
|
+
remove(fn: Callback<T, K>): void;
|
|
12
|
+
removeAll(): void;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { ArgsType, SyncHook };
|
|
16
|
+
//# sourceMappingURL=syncHook.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/utils/hooks/syncHook.ts
|
|
2
|
+
var SyncHook = class {
|
|
3
|
+
constructor(type) {
|
|
4
|
+
this.type = "";
|
|
5
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
6
|
+
if (type) this.type = type;
|
|
7
|
+
}
|
|
8
|
+
on(fn) {
|
|
9
|
+
if (typeof fn === "function") this.listeners.add(fn);
|
|
10
|
+
}
|
|
11
|
+
once(fn) {
|
|
12
|
+
const self = this;
|
|
13
|
+
this.on(function wrapper(...args) {
|
|
14
|
+
self.remove(wrapper);
|
|
15
|
+
return fn.apply(null, args);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
emit(...data) {
|
|
19
|
+
let result;
|
|
20
|
+
if (this.listeners.size > 0) this.listeners.forEach((fn) => {
|
|
21
|
+
result = fn(...data);
|
|
22
|
+
});
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
remove(fn) {
|
|
26
|
+
this.listeners.delete(fn);
|
|
27
|
+
}
|
|
28
|
+
removeAll() {
|
|
29
|
+
this.listeners.clear();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { SyncHook };
|
|
35
|
+
//# sourceMappingURL=syncHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncHook.js","names":[],"sources":["../../../src/utils/hooks/syncHook.ts"],"sourcesContent":["export type Callback<T, K> = (...args: ArgsType<T>) => K;\nexport type ArgsType<T> = T extends Array<any> ? T : Array<any>;\n\nexport class SyncHook<T, K> {\n type = '';\n listeners = new Set<Callback<T, K>>();\n\n constructor(type?: string) {\n if (type) {\n this.type = type;\n }\n }\n\n on(fn: Callback<T, K>): void {\n if (typeof fn === 'function') {\n this.listeners.add(fn);\n }\n }\n\n once(fn: Callback<T, K>): void {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n this.on(function wrapper(...args) {\n self.remove(wrapper);\n // eslint-disable-next-line prefer-spread\n return fn.apply(null, args);\n });\n }\n\n emit(...data: ArgsType<T>): void | K | Promise<any> {\n let result;\n if (this.listeners.size > 0) {\n // eslint-disable-next-line prefer-spread\n this.listeners.forEach((fn) => {\n result = fn(...data);\n });\n }\n return result;\n }\n\n remove(fn: Callback<T, K>): void {\n this.listeners.delete(fn);\n }\n\n removeAll(): void {\n this.listeners.clear();\n }\n}\n"],"mappings":";AAGA,IAAa,WAAb,MAA4B;CAI1B,YAAY,MAAe;cAHpB;mCACK,IAAI,KAAqB;AAGnC,MAAI,KACF,MAAK,OAAO;;CAIhB,GAAG,IAA0B;AAC3B,MAAI,OAAO,OAAO,WAChB,MAAK,UAAU,IAAI,GAAG;;CAI1B,KAAK,IAA0B;EAE7B,MAAM,OAAO;AACb,OAAK,GAAG,SAAS,QAAQ,GAAG,MAAM;AAChC,QAAK,OAAO,QAAQ;AAEpB,UAAO,GAAG,MAAM,MAAM,KAAK;IAC3B;;CAGJ,KAAK,GAAG,MAA4C;EAClD,IAAI;AACJ,MAAI,KAAK,UAAU,OAAO,EAExB,MAAK,UAAU,SAAS,OAAO;AAC7B,YAAS,GAAG,GAAG,KAAK;IACpB;AAEJ,SAAO;;CAGT,OAAO,IAA0B;AAC/B,OAAK,UAAU,OAAO,GAAG;;CAG3B,YAAkB;AAChB,OAAK,UAAU,OAAO"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const require_logger = require('../logger.cjs');
|
|
2
|
+
const require_tool = require('../tool.cjs');
|
|
3
|
+
const require_syncHook = require('./syncHook.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/utils/hooks/syncWaterfallHook.ts
|
|
6
|
+
function checkReturnData(originalData, returnedData) {
|
|
7
|
+
if (!require_tool.isObject(returnedData)) return false;
|
|
8
|
+
if (originalData !== returnedData) {
|
|
9
|
+
for (const key in originalData) if (!(key in returnedData)) return false;
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
var SyncWaterfallHook = class extends require_syncHook.SyncHook {
|
|
14
|
+
constructor(type) {
|
|
15
|
+
super();
|
|
16
|
+
this.onerror = require_logger.error;
|
|
17
|
+
this.type = type;
|
|
18
|
+
}
|
|
19
|
+
emit(data) {
|
|
20
|
+
if (!require_tool.isObject(data)) require_logger.error(`The data for the "${this.type}" hook should be an object.`);
|
|
21
|
+
for (const fn of this.listeners) try {
|
|
22
|
+
const tempData = fn(data);
|
|
23
|
+
if (checkReturnData(data, tempData)) data = tempData;
|
|
24
|
+
else {
|
|
25
|
+
this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
} catch (e) {
|
|
29
|
+
require_logger.warn(e);
|
|
30
|
+
this.onerror(e);
|
|
31
|
+
}
|
|
32
|
+
return data;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.SyncWaterfallHook = SyncWaterfallHook;
|
|
38
|
+
exports.checkReturnData = checkReturnData;
|
|
39
|
+
//# sourceMappingURL=syncWaterfallHook.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncWaterfallHook.cjs","names":["isObject","SyncHook","error"],"sources":["../../../src/utils/hooks/syncWaterfallHook.ts"],"sourcesContent":["import { error, warn } from '../logger';\nimport { isObject } from '../tool';\nimport { SyncHook } from './syncHook';\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function checkReturnData(originalData: any, returnedData: any): boolean {\n if (!isObject(returnedData)) {\n return false;\n }\n if (originalData !== returnedData) {\n // eslint-disable-next-line no-restricted-syntax\n for (const key in originalData) {\n if (!(key in returnedData)) {\n return false;\n }\n }\n }\n return true;\n}\n\nexport class SyncWaterfallHook<T extends Record<string, any>> extends SyncHook<\n [T],\n T\n> {\n onerror: (errMsg: string | Error | unknown) => void = error;\n\n constructor(type: string) {\n super();\n this.type = type;\n }\n\n override emit(data: T): T {\n if (!isObject(data)) {\n error(`The data for the \"${this.type}\" hook should be an object.`);\n }\n for (const fn of this.listeners) {\n try {\n const tempData = fn(data);\n if (checkReturnData(data, tempData)) {\n data = tempData;\n } else {\n this.onerror(\n `A plugin returned an unacceptable value for the \"${this.type}\" type.`,\n );\n break;\n }\n } catch (e) {\n warn(e);\n this.onerror(e);\n }\n }\n return data;\n }\n}\n"],"mappings":";;;;;AAKA,SAAgB,gBAAgB,cAAmB,cAA4B;AAC7E,KAAI,CAACA,sBAAS,aAAa,CACzB,QAAO;AAET,KAAI,iBAAiB,cAEnB;OAAK,MAAM,OAAO,aAChB,KAAI,EAAE,OAAO,cACX,QAAO;;AAIb,QAAO;;AAGT,IAAa,oBAAb,cAAsEC,0BAGpE;CAGA,YAAY,MAAc;AACxB,SAAO;iBAH6CC;AAIpD,OAAK,OAAO;;CAGd,AAAS,KAAK,MAAY;AACxB,MAAI,CAACF,sBAAS,KAAK,CACjB,sBAAM,qBAAqB,KAAK,KAAK,6BAA6B;AAEpE,OAAK,MAAM,MAAM,KAAK,UACpB,KAAI;GACF,MAAM,WAAW,GAAG,KAAK;AACzB,OAAI,gBAAgB,MAAM,SAAS,CACjC,QAAO;QACF;AACL,SAAK,QACH,oDAAoD,KAAK,KAAK,SAC/D;AACD;;WAEK,GAAG;AACV,uBAAK,EAAE;AACP,QAAK,QAAQ,EAAE;;AAGnB,SAAO"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SyncHook } from "./syncHook.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/hooks/syncWaterfallHook.d.ts
|
|
4
|
+
declare class SyncWaterfallHook<T extends Record<string, any>> extends SyncHook<[T], T> {
|
|
5
|
+
onerror: (errMsg: string | Error | unknown) => void;
|
|
6
|
+
constructor(type: string);
|
|
7
|
+
emit(data: T): T;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { SyncWaterfallHook };
|
|
11
|
+
//# sourceMappingURL=syncWaterfallHook.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { error, warn } from "../logger.js";
|
|
2
|
+
import { isObject } from "../tool.js";
|
|
3
|
+
import { SyncHook } from "./syncHook.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/hooks/syncWaterfallHook.ts
|
|
6
|
+
function checkReturnData(originalData, returnedData) {
|
|
7
|
+
if (!isObject(returnedData)) return false;
|
|
8
|
+
if (originalData !== returnedData) {
|
|
9
|
+
for (const key in originalData) if (!(key in returnedData)) return false;
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
var SyncWaterfallHook = class extends SyncHook {
|
|
14
|
+
constructor(type) {
|
|
15
|
+
super();
|
|
16
|
+
this.onerror = error;
|
|
17
|
+
this.type = type;
|
|
18
|
+
}
|
|
19
|
+
emit(data) {
|
|
20
|
+
if (!isObject(data)) error(`The data for the "${this.type}" hook should be an object.`);
|
|
21
|
+
for (const fn of this.listeners) try {
|
|
22
|
+
const tempData = fn(data);
|
|
23
|
+
if (checkReturnData(data, tempData)) data = tempData;
|
|
24
|
+
else {
|
|
25
|
+
this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
} catch (e) {
|
|
29
|
+
warn(e);
|
|
30
|
+
this.onerror(e);
|
|
31
|
+
}
|
|
32
|
+
return data;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { SyncWaterfallHook, checkReturnData };
|
|
38
|
+
//# sourceMappingURL=syncWaterfallHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncWaterfallHook.js","names":[],"sources":["../../../src/utils/hooks/syncWaterfallHook.ts"],"sourcesContent":["import { error, warn } from '../logger';\nimport { isObject } from '../tool';\nimport { SyncHook } from './syncHook';\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function checkReturnData(originalData: any, returnedData: any): boolean {\n if (!isObject(returnedData)) {\n return false;\n }\n if (originalData !== returnedData) {\n // eslint-disable-next-line no-restricted-syntax\n for (const key in originalData) {\n if (!(key in returnedData)) {\n return false;\n }\n }\n }\n return true;\n}\n\nexport class SyncWaterfallHook<T extends Record<string, any>> extends SyncHook<\n [T],\n T\n> {\n onerror: (errMsg: string | Error | unknown) => void = error;\n\n constructor(type: string) {\n super();\n this.type = type;\n }\n\n override emit(data: T): T {\n if (!isObject(data)) {\n error(`The data for the \"${this.type}\" hook should be an object.`);\n }\n for (const fn of this.listeners) {\n try {\n const tempData = fn(data);\n if (checkReturnData(data, tempData)) {\n data = tempData;\n } else {\n this.onerror(\n `A plugin returned an unacceptable value for the \"${this.type}\" type.`,\n );\n break;\n }\n } catch (e) {\n warn(e);\n this.onerror(e);\n }\n }\n return data;\n }\n}\n"],"mappings":";;;;;AAKA,SAAgB,gBAAgB,cAAmB,cAA4B;AAC7E,KAAI,CAAC,SAAS,aAAa,CACzB,QAAO;AAET,KAAI,iBAAiB,cAEnB;OAAK,MAAM,OAAO,aAChB,KAAI,EAAE,OAAO,cACX,QAAO;;AAIb,QAAO;;AAGT,IAAa,oBAAb,cAAsE,SAGpE;CAGA,YAAY,MAAc;AACxB,SAAO;iBAH6C;AAIpD,OAAK,OAAO;;CAGd,AAAS,KAAK,MAAY;AACxB,MAAI,CAAC,SAAS,KAAK,CACjB,OAAM,qBAAqB,KAAK,KAAK,6BAA6B;AAEpE,OAAK,MAAM,MAAM,KAAK,UACpB,KAAI;GACF,MAAM,WAAW,GAAG,KAAK;AACzB,OAAI,gBAAgB,MAAM,SAAS,CACjC,QAAO;QACF;AACL,SAAK,QACH,oDAAoD,KAAK,KAAK,SAC/D;AACD;;WAEK,GAAG;AACV,QAAK,EAAE;AACP,QAAK,QAAQ,EAAE;;AAGnB,SAAO"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const require_logger = require('./logger.cjs');
|
|
2
|
+
const require_tool = require('./tool.cjs');
|
|
3
|
+
const require_env = require('./env.cjs');
|
|
4
|
+
const require_manifest = require('./manifest.cjs');
|
|
5
|
+
const require_plugin = require('./plugin.cjs');
|
|
6
|
+
const require_load = require('./load.cjs');
|
|
7
|
+
const require_context = require('./context.cjs');
|
|
8
|
+
let _module_federation_sdk = require("@module-federation/sdk");
|