every-plugin 0.8.9 → 2.2.2
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 → _rolldown/runtime.cjs} +15 -1
- package/dist/_virtual/{rolldown_runtime.mjs → _rolldown/runtime.mjs} +15 -2
- package/dist/build/rspack/dev-server-middleware.cjs +15 -4
- package/dist/build/rspack/dev-server-middleware.cjs.map +1 -1
- package/dist/build/rspack/dev-server-middleware.mjs +15 -4
- package/dist/build/rspack/dev-server-middleware.mjs.map +1 -1
- package/dist/build/rspack/fix-mf-data-uri-plugin.cjs +44 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.cjs.map +1 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.d.cts +11 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.d.cts.map +1 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.d.mts +11 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.d.mts.map +1 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.mjs +43 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.mjs.map +1 -0
- package/dist/build/rspack/index.cjs +8 -6
- package/dist/build/rspack/index.d.cts +4 -3
- package/dist/build/rspack/index.d.mts +4 -3
- package/dist/build/rspack/index.mjs +4 -3
- package/dist/build/rspack/module-federation.cjs +3 -3
- package/dist/build/rspack/module-federation.cjs.map +1 -1
- package/dist/build/rspack/module-federation.mjs +1 -1
- package/dist/build/rspack/module-federation.mjs.map +1 -1
- package/dist/build/rspack/plugin.cjs +83 -5
- package/dist/build/rspack/plugin.cjs.map +1 -1
- package/dist/build/rspack/plugin.d.cts +12 -1
- package/dist/build/rspack/plugin.d.cts.map +1 -1
- package/dist/build/rspack/plugin.d.mts +12 -1
- package/dist/build/rspack/plugin.d.mts.map +1 -1
- package/dist/build/rspack/plugin.mjs +80 -5
- package/dist/build/rspack/plugin.mjs.map +1 -1
- package/dist/build/rspack/utils.cjs +5 -4
- package/dist/build/rspack/utils.cjs.map +1 -1
- package/dist/build/rspack/utils.mjs +3 -2
- package/dist/build/rspack/utils.mjs.map +1 -1
- package/dist/build/shared-deps.cjs +50 -65
- package/dist/build/shared-deps.cjs.map +1 -1
- package/dist/build/shared-deps.d.cts +27 -4
- package/dist/build/shared-deps.d.cts.map +1 -1
- package/dist/build/shared-deps.d.mts +27 -4
- package/dist/build/shared-deps.d.mts.map +1 -1
- package/dist/build/shared-deps.mjs +48 -64
- package/dist/build/shared-deps.mjs.map +1 -1
- package/dist/errors.cjs +1 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/orpc-client.cjs +17 -0
- package/dist/orpc-client.d.cts +2 -0
- package/dist/orpc-client.d.mts +2 -0
- package/dist/orpc-client.mjs +5 -0
- package/dist/orpc-openapi.cjs +17 -0
- package/dist/orpc-openapi.d.cts +2 -0
- package/dist/orpc-openapi.d.mts +2 -0
- package/dist/orpc-openapi.mjs +5 -0
- package/dist/orpc.cjs +8 -7
- package/dist/plugin.cjs +10 -9
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +28 -29
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts +28 -29
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +10 -10
- package/dist/plugin.mjs.map +1 -1
- package/dist/runtime/errors.cjs +2 -2
- package/dist/runtime/errors.cjs.map +1 -1
- package/dist/runtime/errors.d.cts +4 -4
- package/dist/runtime/errors.d.cts.map +1 -1
- package/dist/runtime/errors.d.mts +4 -4
- package/dist/runtime/errors.d.mts.map +1 -1
- package/dist/runtime/errors.mjs +1 -1
- package/dist/runtime/errors.mjs.map +1 -1
- package/dist/runtime/index.cjs +24 -20
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.d.cts +3 -3
- package/dist/runtime/index.d.cts.map +1 -1
- package/dist/runtime/index.d.mts +3 -3
- package/dist/runtime/index.d.mts.map +1 -1
- package/dist/runtime/index.mjs +12 -9
- package/dist/runtime/index.mjs.map +1 -1
- package/dist/runtime/mf-config.cjs +33 -0
- package/dist/runtime/mf-config.cjs.map +1 -0
- package/dist/runtime/mf-config.d.cts +41 -0
- package/dist/runtime/mf-config.d.cts.map +1 -0
- package/dist/runtime/mf-config.d.mts +41 -0
- package/dist/runtime/mf-config.d.mts.map +1 -0
- package/dist/runtime/mf-config.mjs +29 -0
- package/dist/runtime/mf-config.mjs.map +1 -0
- package/dist/runtime/services/module-federation.service.cjs +19 -56
- package/dist/runtime/services/module-federation.service.cjs.map +1 -1
- package/dist/runtime/services/module-federation.service.d.cts.map +1 -1
- package/dist/runtime/services/module-federation.service.d.mts.map +1 -1
- package/dist/runtime/services/module-federation.service.mjs +18 -55
- package/dist/runtime/services/module-federation.service.mjs.map +1 -1
- package/dist/runtime/services/normalize.cjs +3 -2
- package/dist/runtime/services/normalize.cjs.map +1 -1
- package/dist/runtime/services/normalize.d.cts.map +1 -1
- package/dist/runtime/services/normalize.d.mts.map +1 -1
- package/dist/runtime/services/normalize.mjs +2 -2
- package/dist/runtime/services/normalize.mjs.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.cjs +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.cjs.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.d.cts.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.d.mts.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.mjs.map +1 -1
- package/dist/runtime/services/plugin-loader.service.cjs +3 -3
- package/dist/runtime/services/plugin-loader.service.cjs.map +1 -1
- package/dist/runtime/services/plugin-loader.service.d.cts +1 -1
- package/dist/runtime/services/plugin-loader.service.d.cts.map +1 -1
- package/dist/runtime/services/plugin-loader.service.d.mts +1 -1
- package/dist/runtime/services/plugin-loader.service.d.mts.map +1 -1
- package/dist/runtime/services/plugin-loader.service.mjs +2 -2
- package/dist/runtime/services/plugin-loader.service.mjs.map +1 -1
- package/dist/runtime/services/plugin.service.cjs +1 -1
- package/dist/runtime/services/plugin.service.cjs.map +1 -1
- package/dist/runtime/services/plugin.service.d.cts +6 -7
- package/dist/runtime/services/plugin.service.d.cts.map +1 -1
- package/dist/runtime/services/plugin.service.d.mts +6 -7
- package/dist/runtime/services/plugin.service.d.mts.map +1 -1
- package/dist/runtime/services/plugin.service.mjs.map +1 -1
- package/dist/runtime/services/secrets.service.cjs +4 -4
- package/dist/runtime/services/secrets.service.cjs.map +1 -1
- package/dist/runtime/services/secrets.service.d.cts.map +1 -1
- package/dist/runtime/services/secrets.service.d.mts.map +1 -1
- package/dist/runtime/services/secrets.service.mjs +3 -3
- package/dist/runtime/services/secrets.service.mjs.map +1 -1
- package/dist/runtime/validation.cjs +1 -1
- package/dist/runtime/validation.cjs.map +1 -1
- package/dist/runtime/validation.mjs.map +1 -1
- package/dist/testing/index.cjs +2 -1
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +0 -2
- package/dist/testing/index.d.cts.map +1 -1
- package/dist/testing/index.d.mts +0 -2
- package/dist/testing/index.d.mts.map +1 -1
- package/dist/testing/index.mjs +1 -1
- package/dist/testing/index.mjs.map +1 -1
- package/dist/types.d.cts +22 -22
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +22 -22
- package/dist/types.d.mts.map +1 -1
- package/dist/zod.cjs +4 -3
- package/dist/zod.mjs +2 -2
- package/package.json +204 -194
- package/src/build/rspack/dev-server-middleware.ts +233 -0
- package/src/build/rspack/fix-mf-data-uri-plugin.ts +49 -0
- package/src/build/rspack/index.ts +14 -0
- package/src/build/rspack/module-federation.ts +6 -0
- package/src/build/rspack/plugin.ts +252 -0
- package/src/build/rspack/utils.ts +60 -0
- package/src/build/shared-deps.ts +79 -0
- package/src/effect.ts +1 -0
- package/src/errors.ts +140 -0
- package/src/index.ts +26 -0
- package/src/orpc-client.ts +2 -0
- package/src/orpc-openapi.ts +2 -0
- package/src/orpc.ts +9 -0
- package/src/plugin.ts +220 -0
- package/src/runtime/errors.ts +332 -0
- package/src/runtime/index.ts +258 -0
- package/src/runtime/mf-config.ts +29 -0
- package/src/runtime/services/module-federation.service.ts +181 -0
- package/src/runtime/services/normalize.ts +18 -0
- package/src/runtime/services/plugin-lifecycle.service.ts +86 -0
- package/src/runtime/services/plugin-loader.service.ts +254 -0
- package/src/runtime/services/plugin.service.ts +66 -0
- package/src/runtime/services/secrets.service.ts +74 -0
- package/src/runtime/services.ts +5 -0
- package/src/runtime/validation.ts +23 -0
- package/src/testing/index.ts +87 -0
- package/src/testing/mocks/module-federation.service.ts +41 -0
- package/src/types.ts +309 -0
- package/src/zod-core.ts +4 -0
- package/src/zod.ts +1 -0
- package/dist/package.cjs +0 -47
- package/dist/package.cjs.map +0 -1
- package/dist/package.mjs +0 -29
- package/dist/package.mjs.map +0 -1
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
2
2
|
const require_errors = require('../errors.cjs');
|
|
3
|
-
const
|
|
4
|
-
const require_shared_deps = require('../../build/shared-deps.cjs');
|
|
3
|
+
const require_runtime_mf_config = require('../mf-config.cjs');
|
|
5
4
|
const require_runtime_services_normalize = require('./normalize.cjs');
|
|
6
5
|
let effect = require("effect");
|
|
7
6
|
let _module_federation_enhanced_runtime = require("@module-federation/enhanced/runtime");
|
|
8
7
|
let _module_federation_runtime_core = require("@module-federation/runtime-core");
|
|
9
8
|
|
|
10
9
|
//#region src/runtime/services/module-federation.service.ts
|
|
10
|
+
const sharedModuleLoaders = {
|
|
11
|
+
"every-plugin": () => Promise.resolve().then(() => require("../../index.cjs")),
|
|
12
|
+
effect: () => import("effect"),
|
|
13
|
+
zod: () => import("zod")
|
|
14
|
+
};
|
|
11
15
|
const createModuleFederationInstance = effect.Effect.cached(effect.Effect.sync(() => {
|
|
12
16
|
try {
|
|
13
17
|
let instance = (0, _module_federation_enhanced_runtime.getInstance)();
|
|
@@ -15,58 +19,15 @@ const createModuleFederationInstance = effect.Effect.cached(effect.Effect.sync((
|
|
|
15
19
|
instance = (0, _module_federation_enhanced_runtime.createInstance)({
|
|
16
20
|
name: "host",
|
|
17
21
|
remotes: [],
|
|
18
|
-
shared: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
effect: {
|
|
30
|
-
version: require_package.dependencies.effect,
|
|
31
|
-
get: () => import("effect").then((mod) => () => mod),
|
|
32
|
-
shareConfig: {
|
|
33
|
-
singleton: true,
|
|
34
|
-
requiredVersion: require_shared_deps.getMajorMinorVersion(require_package.dependencies.effect),
|
|
35
|
-
eager: false,
|
|
36
|
-
strictVersion: false
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
zod: {
|
|
40
|
-
version: require_package.dependencies.zod,
|
|
41
|
-
get: () => import("zod").then((mod) => () => mod),
|
|
42
|
-
shareConfig: {
|
|
43
|
-
singleton: true,
|
|
44
|
-
requiredVersion: require_shared_deps.getMajorMinorVersion(require_package.dependencies.zod),
|
|
45
|
-
eager: false,
|
|
46
|
-
strictVersion: false
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
"@orpc/contract": {
|
|
50
|
-
version: require_package.dependencies["@orpc/contract"],
|
|
51
|
-
get: () => import("@orpc/contract").then((mod) => () => mod),
|
|
52
|
-
shareConfig: {
|
|
53
|
-
singleton: true,
|
|
54
|
-
requiredVersion: require_shared_deps.getMajorMinorVersion(require_package.dependencies["@orpc/contract"]),
|
|
55
|
-
eager: false,
|
|
56
|
-
strictVersion: false
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
"@orpc/server": {
|
|
60
|
-
version: require_package.dependencies["@orpc/server"],
|
|
61
|
-
get: () => import("@orpc/server").then((mod) => () => mod),
|
|
62
|
-
shareConfig: {
|
|
63
|
-
singleton: true,
|
|
64
|
-
requiredVersion: require_shared_deps.getMajorMinorVersion(require_package.dependencies["@orpc/server"]),
|
|
65
|
-
eager: false,
|
|
66
|
-
strictVersion: false
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
22
|
+
shared: Object.fromEntries(Object.entries(require_runtime_mf_config.MF_SHARED_DEPS).map(([name, config]) => {
|
|
23
|
+
const load = sharedModuleLoaders[name];
|
|
24
|
+
if (!load) throw new Error(`Missing shared module loader for ${name}`);
|
|
25
|
+
return [name, {
|
|
26
|
+
version: config.version,
|
|
27
|
+
get: () => load().then((mod) => () => mod),
|
|
28
|
+
shareConfig: config.shareConfig
|
|
29
|
+
}];
|
|
30
|
+
}))
|
|
70
31
|
});
|
|
71
32
|
(0, _module_federation_runtime_core.setGlobalFederationInstance)(instance);
|
|
72
33
|
}
|
|
@@ -81,10 +42,12 @@ var ModuleFederationService = class extends effect.Effect.Service()("ModuleFeder
|
|
|
81
42
|
registerRemote: (pluginId, url) => effect.Effect.gen(function* () {
|
|
82
43
|
console.log(`[MF] Registering ${pluginId}`);
|
|
83
44
|
const remoteName = require_runtime_services_normalize.getNormalizedRemoteName(pluginId);
|
|
45
|
+
const type = url.endsWith("/mf-manifest.json") ? "manifest" : url.endsWith("/remoteEntry.js") ? "script" : void 0;
|
|
84
46
|
yield* effect.Effect.try({
|
|
85
47
|
try: () => mf.registerRemotes([{
|
|
86
48
|
name: remoteName,
|
|
87
|
-
entry: url
|
|
49
|
+
entry: url,
|
|
50
|
+
...type ? { type } : {}
|
|
88
51
|
}]),
|
|
89
52
|
catch: (error) => new require_errors.ModuleFederationError({
|
|
90
53
|
pluginId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation.service.cjs","names":["Effect","getMajorMinorVersion","getNormalizedRemoteName","ModuleFederationError"],"sources":["../../../src/runtime/services/module-federation.service.ts"],"sourcesContent":["import {\n\tcreateInstance,\n\tgetInstance,\n} from \"@module-federation/enhanced/runtime\";\nimport { setGlobalFederationInstance } from \"@module-federation/runtime-core\";\nimport { Effect } from \"effect\";\nimport { getMajorMinorVersion } from \"../../build/shared-deps\";\nimport type { AnyPlugin } from \"../../types\";\nimport { ModuleFederationError } from \"../errors\";\nimport { getNormalizedRemoteName } from \"./normalize\";\n\ntype RemoteModule =\n\t| (new () => AnyPlugin)\n\t| { default: new () => AnyPlugin };\n\nimport pkg from \"../../../package.json\";\n\nconst createModuleFederationInstance = Effect.cached(\n\tEffect.sync(() => {\n\t\ttry {\n\t\t\tlet instance = getInstance();\n\n\t\t\tif (!instance) {\n\t\t\t\tinstance = createInstance({\n\t\t\t\t\tname: \"host\",\n\t\t\t\t\tremotes: [],\n\t\t\t\t\tshared: {\n\t\t\t\t\t\t\"every-plugin\": {\n\t\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t\t\tget: () => import(\"every-plugin\").then(mod => () => mod),\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: getMajorMinorVersion(pkg.version),\n\t\t\t\t\t\t\t\teager: false,\n\t\t\t\t\t\t\t\tstrictVersion: false,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\teffect: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.effect,\n\t\t\t\t\t\t\tget: () => import(\"effect\").then(mod => () => mod),\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: getMajorMinorVersion(pkg.dependencies.effect),\n\t\t\t\t\t\t\t\teager: false,\n\t\t\t\t\t\t\t\tstrictVersion: false,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tzod: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.zod,\n\t\t\t\t\t\t\tget: () => import(\"zod\").then(mod => () => mod),\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: getMajorMinorVersion(pkg.dependencies.zod),\n\t\t\t\t\t\t\t\teager: false,\n\t\t\t\t\t\t\t\tstrictVersion: false,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/contract\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/contract\"],\n\t\t\t\t\t\t\tget: () => import(\"@orpc/contract\").then(mod => () => mod),\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: getMajorMinorVersion(pkg.dependencies[\"@orpc/contract\"]),\n\t\t\t\t\t\t\t\teager: false,\n\t\t\t\t\t\t\t\tstrictVersion: false,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/server\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/server\"],\n\t\t\t\t\t\t\tget: () => import(\"@orpc/server\").then(mod => () => mod),\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: getMajorMinorVersion(pkg.dependencies[\"@orpc/server\"]),\n\t\t\t\t\t\t\t\teager: false,\n\t\t\t\t\t\t\t\tstrictVersion: false,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tsetGlobalFederationInstance(instance);\n\t\t\t}\n\n\t\t\treturn instance;\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to initialize Module Federation: ${error}`);\n\t\t}\n\t}),\n);\n\nexport class ModuleFederationService extends Effect.Service<ModuleFederationService>()(\"ModuleFederationService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst mf = yield* Effect.flatten(createModuleFederationInstance);\n\n\t\treturn {\n\t\t\tregisterRemote: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconsole.log(`[MF] Registering ${pluginId}`);\n\n\t\t\t\t\tconst remoteName = getNormalizedRemoteName(pluginId);\n\n\t\t\t\t\tyield* Effect.try({\n\t\t\t\t\t\ttry: () => mf.registerRemotes([{\n\t\t\t\t\t\t\tname: remoteName,\n\t\t\t\t\t\t\tentry: url,\n\t\t\t\t\t\t}]),\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\n\t\t\t\t\tconsole.log(`[MF] ✅ Registered ${pluginId}`);\n\t\t\t\t}),\n\n\t\t\tloadRemoteConstructor: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst remoteName = getNormalizedRemoteName(pluginId);\n\t\t\t\t\tconsole.log(`[MF] Loading remote ${remoteName}`);\n\t\t\t\t\tconst modulePath = `${remoteName}/plugin`;\n\n\t\t\t\t\treturn yield* Effect.tryPromise({\n\t\t\t\t\t\ttry: async () => {\n\n\t\t\t\t\t\t\tconst container = await mf.loadRemote<RemoteModule>(modulePath);\n\t\t\t\t\t\t\tif (!container) {\n\t\t\t\t\t\t\t\tthrow new Error(`No container returned for ${modulePath}`);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Support multiple export patterns: direct function, default export, named exports\n\t\t\t\t\t\t\tlet Constructor: any;\n\n\t\t\t\t\t\t\tif (typeof container === \"function\") {\n\t\t\t\t\t\t\t\t// Direct function export\n\t\t\t\t\t\t\t\tConstructor = container;\n\t\t\t\t\t\t\t} else if (container.default) {\n\t\t\t\t\t\t\t\t// Default export\n\t\t\t\t\t\t\t\tConstructor = container.default;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Named export fallback - prioritize exports with 'binding' property (plugin classes)\n\t\t\t\t\t\t\t\tConstructor = Object.values(container).find(\n\t\t\t\t\t\t\t\t\t(exp) => typeof exp === \"function\" && (exp as any).binding !== undefined\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Fallback to any function export if no binding found\n\t\t\t\t\t\t\t\tif (!Constructor) {\n\t\t\t\t\t\t\t\t\tConstructor = Object.values(container).find(\n\t\t\t\t\t\t\t\t\t\t(exp) => typeof exp === \"function\" && exp.prototype?.constructor === exp\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!Constructor || typeof Constructor !== \"function\") {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Available exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`No valid plugin constructor found for '${pluginId}'.\\n` +\n\t\t\t\t\t\t\t\t\t`Supported patterns:\\n` +\n\t\t\t\t\t\t\t\t\t` - export const YourPlugin = createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t` - export default createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Validate it looks like a plugin constructor (has binding property)\n\t\t\t\t\t\t\tif (!(Constructor as any).binding) {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Found exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`Invalid plugin constructor for '${pluginId}'. ` +\n\t\t\t\t\t\t\t\t\t`The exported value must be created with createPlugin(). ` +\n\t\t\t\t\t\t\t\t\t`Found a function but it's missing the required 'binding' property.\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconsole.log(`[MF] ✅ Loaded constructor for ${pluginId}`);\n\t\t\t\t\t\t\treturn Constructor;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t}),\n\t\t};\n\t}),\n}) { }\n"],"mappings":";;;;;;;;;;AAiBA,MAAM,iCAAiCA,cAAO,OAC7CA,cAAO,WAAW;AACjB,KAAI;EACH,IAAI,iEAAwB;AAE5B,MAAI,CAAC,UAAU;AACd,sEAA0B;IACzB,MAAM;IACN,SAAS,EAAE;IACX,QAAQ;KACP,gBAAgB;MACf;MACA,gDAAW,oBAAuB,MAAK,cAAa,IAAI;MACxD,aAAa;OACZ,WAAW;OACX,iBAAiBC,iEAAiC;OAClD,OAAO;OACP,eAAe;OACf;MACD;KACD,QAAQ;MACP,sCAA0B;MAC1B,WAAW,OAAO,UAAU,MAAK,cAAa,IAAI;MAClD,aAAa;OACZ,WAAW;OACX,iBAAiBA,sEAAsC,OAAO;OAC9D,OAAO;OACP,eAAe;OACf;MACD;KACD,KAAK;MACJ,sCAA0B;MAC1B,WAAW,OAAO,OAAO,MAAK,cAAa,IAAI;MAC/C,aAAa;OACZ,WAAW;O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AEhB,MAAM,YAAY,MAAM,GAAG,WAAyB,WAAW;AAC/D,SAAI,CAAC,UACJ,OAAM,IAAI,MAAM,6BAA6B,aAAa;KAI3D,IAAI;AAEJ,SAAI,OAAO,cAAc,WAExB,eAAc;cACJ,UAAU,QAEpB,eAAc,UAAU;UAClB;AAEN,oBAAc,OAAO,OAAO,UAAU,CAAC,MACrC,QAAQ,OAAO,QAAQ,cAAe,IAAY,YAAY,OAC/D;AAGD,UAAI,CAAC,YACJ,eAAc,OAAO,OAAO,UAAU,CAAC,MACrC,QAAQ,OAAO,QAAQ,cAAc,IAAI,WAAW,gBAAgB,IACrE;;AAIH,SAAI,CAAC,eAAe,OAAO,gBAAgB,YAAY;MACtD,MAAM,gBAAgB,OAAO,cAAc,WACxC,sBAAsB,OAAO,KAAK,UAAU,CAAC,KAAK,KAAK,KACvD,mBAAmB,OAAO;AAE7B,YAAM,IAAI,MACT,0CAA0C,SAAS,sHAIhD,gBACH;;AAIF,SAAI,CAAE,YAAoB,SAAS;MAClC,MAAM,gBAAgB,OAAO,cAAc,WACxC,kBAAkB,OAAO,KAAK,UAAU,CAAC,KAAK,KAAK,KACnD,mBAAmB,OAAO;AAE7B,YAAM,IAAI,MACT,mCAAmC,SAAS,iIAGzC,gBACH;;AAGF,aAAQ,IAAI,iCAAiC,WAAW;AACxD,YAAO;;IAER,QAAQ,UACP,IAAIG,qCAAsB;KACzB;KACA,WAAW;KACX,OACC,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;KAC1D,CAAC;IACH,CAAC;IACD;EACH;EACA,EACF,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"module-federation.service.cjs","names":["Effect","MF_SHARED_DEPS","getNormalizedRemoteName","ModuleFederationError"],"sources":["../../../src/runtime/services/module-federation.service.ts"],"sourcesContent":["import { createInstance, getInstance } from \"@module-federation/enhanced/runtime\";\nimport { setGlobalFederationInstance } from \"@module-federation/runtime-core\";\nimport { Effect } from \"effect\";\nimport type { AnyPlugin } from \"../../types\";\nimport { ModuleFederationError } from \"../errors\";\nimport { MF_SHARED_DEPS, type SharedDepName } from \"../mf-config\";\nimport { getNormalizedRemoteName } from \"./normalize\";\n\ntype RemoteModule = (new () => AnyPlugin) | { default: new () => AnyPlugin };\n\nconst sharedModuleLoaders = {\n \"every-plugin\": () => import(\"every-plugin\"),\n effect: () => import(\"effect\"),\n zod: () => import(\"zod\"),\n} satisfies Record<SharedDepName, () => Promise<unknown>>;\n\nconst createModuleFederationInstance = Effect.cached(\n Effect.sync(() => {\n try {\n let instance = getInstance();\n\n if (!instance) {\n const shared = Object.fromEntries(\n (\n Object.entries(MF_SHARED_DEPS) as [\n SharedDepName,\n (typeof MF_SHARED_DEPS)[SharedDepName],\n ][]\n ).map(([name, config]) => {\n const load = sharedModuleLoaders[name];\n\n if (!load) {\n throw new Error(`Missing shared module loader for ${name}`);\n }\n\n return [\n name,\n {\n version: config.version,\n get: () => load().then((mod) => () => mod),\n shareConfig: config.shareConfig,\n },\n ];\n }),\n );\n\n instance = createInstance({\n name: \"host\",\n remotes: [],\n shared,\n });\n\n setGlobalFederationInstance(instance);\n }\n\n return instance;\n } catch (error) {\n throw new Error(`Failed to initialize Module Federation: ${error}`);\n }\n }),\n);\n\nexport class ModuleFederationService extends Effect.Service<ModuleFederationService>()(\n \"ModuleFederationService\",\n {\n effect: Effect.gen(function* () {\n const mf = yield* Effect.flatten(createModuleFederationInstance);\n\n return {\n registerRemote: (pluginId: string, url: string) =>\n Effect.gen(function* () {\n console.log(`[MF] Registering ${pluginId}`);\n\n const remoteName = getNormalizedRemoteName(pluginId);\n const type = url.endsWith(\"/mf-manifest.json\")\n ? (\"manifest\" as const)\n : url.endsWith(\"/remoteEntry.js\")\n ? (\"script\" as const)\n : undefined;\n\n yield* Effect.try({\n try: () =>\n mf.registerRemotes([\n {\n name: remoteName,\n entry: url,\n ...(type ? { type } : {}),\n },\n ]),\n catch: (error): ModuleFederationError =>\n new ModuleFederationError({\n pluginId,\n remoteUrl: url,\n cause: error instanceof Error ? error : new Error(String(error)),\n }),\n });\n\n console.log(`[MF] ✅ Registered ${pluginId}`);\n }),\n\n loadRemoteConstructor: (pluginId: string, url: string) =>\n Effect.gen(function* () {\n const remoteName = getNormalizedRemoteName(pluginId);\n console.log(`[MF] Loading remote ${remoteName}`);\n const modulePath = `${remoteName}/plugin`;\n\n return yield* Effect.tryPromise({\n try: async () => {\n const container = await mf.loadRemote<RemoteModule>(modulePath);\n if (!container) {\n throw new Error(`No container returned for ${modulePath}`);\n }\n\n // Support multiple export patterns: direct function, default export, named exports\n let Constructor: any;\n\n if (typeof container === \"function\") {\n // Direct function export\n Constructor = container;\n } else if (container.default) {\n // Default export\n Constructor = container.default;\n } else {\n // Named export fallback - prioritize exports with 'binding' property (plugin classes)\n Constructor = Object.values(container).find(\n (exp) => typeof exp === \"function\" && (exp as any).binding !== undefined,\n );\n\n // Fallback to any function export if no binding found\n if (!Constructor) {\n Constructor = Object.values(container).find(\n (exp) => typeof exp === \"function\" && exp.prototype?.constructor === exp,\n );\n }\n }\n\n if (!Constructor || typeof Constructor !== \"function\") {\n const containerInfo =\n typeof container === \"object\"\n ? `Available exports: ${Object.keys(container).join(\", \")}`\n : `Container type: ${typeof container}`;\n\n throw new Error(\n `No valid plugin constructor found for '${pluginId}'.\\n` +\n `Supported patterns:\\n` +\n ` - export const YourPlugin = createPlugin({...})\\n` +\n ` - export default createPlugin({...})\\n` +\n `${containerInfo}`,\n );\n }\n\n // Validate it looks like a plugin constructor (has binding property)\n if (!(Constructor as any).binding) {\n const containerInfo =\n typeof container === \"object\"\n ? `Found exports: ${Object.keys(container).join(\", \")}`\n : `Container type: ${typeof container}`;\n\n throw new Error(\n `Invalid plugin constructor for '${pluginId}'. ` +\n `The exported value must be created with createPlugin(). ` +\n `Found a function but it's missing the required 'binding' property.\\n` +\n `${containerInfo}`,\n );\n }\n\n console.log(`[MF] ✅ Loaded constructor for ${pluginId}`);\n return Constructor;\n },\n catch: (error): ModuleFederationError =>\n new ModuleFederationError({\n pluginId,\n remoteUrl: url,\n cause: error instanceof Error ? error : new Error(String(error)),\n }),\n });\n }),\n };\n }),\n },\n) {}\n"],"mappings":";;;;;;;;;AAUA,MAAM,sBAAsB;CAC1B,2DAAsB;CACtB,cAAc,OAAO;CACrB,WAAW,OAAO;CACnB;AAED,MAAM,iCAAiCA,cAAO,OAC5CA,cAAO,WAAW;AAChB,KAAI;EACF,IAAI,iEAAwB;AAE5B,MAAI,CAAC,UAAU;AAyBb,sEAA0B;IACxB,MAAM;IACN,SAAS,EAAE;IACX,QA3Ba,OAAO,YAElB,OAAO,QAAQC,yCAAe,CAI9B,KAAK,CAAC,MAAM,YAAY;KACxB,MAAM,OAAO,oBAAoB;AAEjC,SAAI,CAAC,KACH,OAAM,IAAI,MAAM,oCAAoC,OAAO;AAG7D,YAAO,CACL,MACA;MACE,SAAS,OAAO;MAChB,WAAW,MAAM,CAAC,MAAM,cAAc,IAAI;MAC1C,aAAa,OAAO;MACrB,CACF;MACD,CACH;IAMA,CAAC;AAEF,oEAA4B,SAAS;;AAGvC,SAAO;UACA,OAAO;AACd,QAAM,IAAI,MAAM,2CAA2C,QAAQ;;EAErE,CACH;AAED,IAAa,0BAAb,cAA6CD,cAAO,SAAkC,CACpF,2BACA,EACE,QAAQA,cAAO,IAAI,aAAa;CAC9B,MAAM,KAAK,OAAOA,cAAO,QAAQ,+BAA+B;AAEhE,QAAO;EACL,iBAAiB,UAAkB,QACjCA,cAAO,IAAI,aAAa;AACtB,WAAQ,IAAI,oBAAoB,WAAW;GAE3C,MAAM,aAAaE,2DAAwB,SAAS;GACpD,MAAM,OAAO,IAAI,SAAS,oBAAoB,GACzC,aACD,IAAI,SAAS,kBAAkB,GAC5B,WACD;AAEN,UAAOF,cAAO,IAAI;IAChB,WACE,GAAG,gBAAgB,CACjB;KACE,MAAM;KACN,OAAO;KACP,GAAI,OAAO,EAAE,MAAM,GAAG,EAAE;KACzB,CACF,CAAC;IACJ,QAAQ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AW;KACX,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;KACjE,CAAC;IACL,CAAC;IACF;EACL;EACD,EACH,CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation.service.d.cts","names":[],"sources":["../../../src/runtime/services/module-federation.service.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"module-federation.service.d.cts","names":[],"sources":["../../../src/runtime/services/module-federation.service.ts"],"mappings":";;;;cAIkD,4BAAA;;uCAiET,GAAA,aAAa,MAAA,CAAA,MAAA,OAAA,qBAAA;8CA+BN,GAAA,aAAa,MAAA,CAAA,MAAA,MAAA,qBAAA;EAAA;AAAA;AAAA,cAtChD,uBAAA,SAAgC,4BAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation.service.d.mts","names":[],"sources":["../../../src/runtime/services/module-federation.service.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"module-federation.service.d.mts","names":[],"sources":["../../../src/runtime/services/module-federation.service.ts"],"mappings":";;;;cAIkD,4BAAA;;uCAiET,GAAA,aAAa,MAAA,CAAA,MAAA,OAAA,qBAAA;8CA+BN,GAAA,aAAa,MAAA,CAAA,MAAA,MAAA,qBAAA;EAAA;AAAA;AAAA,cAtChD,uBAAA,SAAgC,4BAAA"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { ModuleFederationError } from "../errors.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { getMajorMinorVersion } from "../../build/shared-deps.mjs";
|
|
2
|
+
import { MF_SHARED_DEPS } from "../mf-config.mjs";
|
|
4
3
|
import { getNormalizedRemoteName } from "./normalize.mjs";
|
|
5
4
|
import { Effect } from "effect";
|
|
6
5
|
import { createInstance, getInstance } from "@module-federation/enhanced/runtime";
|
|
7
6
|
import { setGlobalFederationInstance } from "@module-federation/runtime-core";
|
|
8
7
|
|
|
9
8
|
//#region src/runtime/services/module-federation.service.ts
|
|
9
|
+
const sharedModuleLoaders = {
|
|
10
|
+
"every-plugin": () => import("../../index.mjs"),
|
|
11
|
+
effect: () => import("effect"),
|
|
12
|
+
zod: () => import("zod")
|
|
13
|
+
};
|
|
10
14
|
const createModuleFederationInstance = Effect.cached(Effect.sync(() => {
|
|
11
15
|
try {
|
|
12
16
|
let instance = getInstance();
|
|
@@ -14,58 +18,15 @@ const createModuleFederationInstance = Effect.cached(Effect.sync(() => {
|
|
|
14
18
|
instance = createInstance({
|
|
15
19
|
name: "host",
|
|
16
20
|
remotes: [],
|
|
17
|
-
shared: {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
effect: {
|
|
29
|
-
version: dependencies.effect,
|
|
30
|
-
get: () => import("effect").then((mod) => () => mod),
|
|
31
|
-
shareConfig: {
|
|
32
|
-
singleton: true,
|
|
33
|
-
requiredVersion: getMajorMinorVersion(dependencies.effect),
|
|
34
|
-
eager: false,
|
|
35
|
-
strictVersion: false
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
zod: {
|
|
39
|
-
version: dependencies.zod,
|
|
40
|
-
get: () => import("zod").then((mod) => () => mod),
|
|
41
|
-
shareConfig: {
|
|
42
|
-
singleton: true,
|
|
43
|
-
requiredVersion: getMajorMinorVersion(dependencies.zod),
|
|
44
|
-
eager: false,
|
|
45
|
-
strictVersion: false
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
"@orpc/contract": {
|
|
49
|
-
version: dependencies["@orpc/contract"],
|
|
50
|
-
get: () => import("@orpc/contract").then((mod) => () => mod),
|
|
51
|
-
shareConfig: {
|
|
52
|
-
singleton: true,
|
|
53
|
-
requiredVersion: getMajorMinorVersion(dependencies["@orpc/contract"]),
|
|
54
|
-
eager: false,
|
|
55
|
-
strictVersion: false
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
"@orpc/server": {
|
|
59
|
-
version: dependencies["@orpc/server"],
|
|
60
|
-
get: () => import("@orpc/server").then((mod) => () => mod),
|
|
61
|
-
shareConfig: {
|
|
62
|
-
singleton: true,
|
|
63
|
-
requiredVersion: getMajorMinorVersion(dependencies["@orpc/server"]),
|
|
64
|
-
eager: false,
|
|
65
|
-
strictVersion: false
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
21
|
+
shared: Object.fromEntries(Object.entries(MF_SHARED_DEPS).map(([name, config]) => {
|
|
22
|
+
const load = sharedModuleLoaders[name];
|
|
23
|
+
if (!load) throw new Error(`Missing shared module loader for ${name}`);
|
|
24
|
+
return [name, {
|
|
25
|
+
version: config.version,
|
|
26
|
+
get: () => load().then((mod) => () => mod),
|
|
27
|
+
shareConfig: config.shareConfig
|
|
28
|
+
}];
|
|
29
|
+
}))
|
|
69
30
|
});
|
|
70
31
|
setGlobalFederationInstance(instance);
|
|
71
32
|
}
|
|
@@ -80,10 +41,12 @@ var ModuleFederationService = class extends Effect.Service()("ModuleFederationSe
|
|
|
80
41
|
registerRemote: (pluginId, url) => Effect.gen(function* () {
|
|
81
42
|
console.log(`[MF] Registering ${pluginId}`);
|
|
82
43
|
const remoteName = getNormalizedRemoteName(pluginId);
|
|
44
|
+
const type = url.endsWith("/mf-manifest.json") ? "manifest" : url.endsWith("/remoteEntry.js") ? "script" : void 0;
|
|
83
45
|
yield* Effect.try({
|
|
84
46
|
try: () => mf.registerRemotes([{
|
|
85
47
|
name: remoteName,
|
|
86
|
-
entry: url
|
|
48
|
+
entry: url,
|
|
49
|
+
...type ? { type } : {}
|
|
87
50
|
}]),
|
|
88
51
|
catch: (error) => new ModuleFederationError({
|
|
89
52
|
pluginId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation.service.mjs","names":["pkg.version"],"sources":["../../../src/runtime/services/module-federation.service.ts"],"sourcesContent":["import {\n\tcreateInstance,\n\tgetInstance,\n} from \"@module-federation/enhanced/runtime\";\nimport { setGlobalFederationInstance } from \"@module-federation/runtime-core\";\nimport { Effect } from \"effect\";\nimport { getMajorMinorVersion } from \"../../build/shared-deps\";\nimport type { AnyPlugin } from \"../../types\";\nimport { ModuleFederationError } from \"../errors\";\nimport { getNormalizedRemoteName } from \"./normalize\";\n\ntype RemoteModule =\n\t| (new () => AnyPlugin)\n\t| { default: new () => AnyPlugin };\n\nimport pkg from \"../../../package.json\";\n\nconst createModuleFederationInstance = Effect.cached(\n\tEffect.sync(() => {\n\t\ttry {\n\t\t\tlet instance = getInstance();\n\n\t\t\tif (!instance) {\n\t\t\t\tinstance = createInstance({\n\t\t\t\t\tname: \"host\",\n\t\t\t\t\tremotes: [],\n\t\t\t\t\tshared: {\n\t\t\t\t\t\t\"every-plugin\": {\n\t\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t\t\tget: () => import(\"every-plugin\").then(mod => () => mod),\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: getMajorMinorVersion(pkg.version),\n\t\t\t\t\t\t\t\teager: false,\n\t\t\t\t\t\t\t\tstrictVersion: false,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\teffect: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.effect,\n\t\t\t\t\t\t\tget: () => import(\"effect\").then(mod => () => mod),\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: getMajorMinorVersion(pkg.dependencies.effect),\n\t\t\t\t\t\t\t\teager: false,\n\t\t\t\t\t\t\t\tstrictVersion: false,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tzod: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.zod,\n\t\t\t\t\t\t\tget: () => import(\"zod\").then(mod => () => mod),\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: getMajorMinorVersion(pkg.dependencies.zod),\n\t\t\t\t\t\t\t\teager: false,\n\t\t\t\t\t\t\t\tstrictVersion: false,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/contract\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/contract\"],\n\t\t\t\t\t\t\tget: () => import(\"@orpc/contract\").then(mod => () => mod),\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: getMajorMinorVersion(pkg.dependencies[\"@orpc/contract\"]),\n\t\t\t\t\t\t\t\teager: false,\n\t\t\t\t\t\t\t\tstrictVersion: false,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/server\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/server\"],\n\t\t\t\t\t\t\tget: () => import(\"@orpc/server\").then(mod => () => mod),\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: getMajorMinorVersion(pkg.dependencies[\"@orpc/server\"]),\n\t\t\t\t\t\t\t\teager: false,\n\t\t\t\t\t\t\t\tstrictVersion: false,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tsetGlobalFederationInstance(instance);\n\t\t\t}\n\n\t\t\treturn instance;\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to initialize Module Federation: ${error}`);\n\t\t}\n\t}),\n);\n\nexport class ModuleFederationService extends Effect.Service<ModuleFederationService>()(\"ModuleFederationService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst mf = yield* Effect.flatten(createModuleFederationInstance);\n\n\t\treturn {\n\t\t\tregisterRemote: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconsole.log(`[MF] Registering ${pluginId}`);\n\n\t\t\t\t\tconst remoteName = getNormalizedRemoteName(pluginId);\n\n\t\t\t\t\tyield* Effect.try({\n\t\t\t\t\t\ttry: () => mf.registerRemotes([{\n\t\t\t\t\t\t\tname: remoteName,\n\t\t\t\t\t\t\tentry: url,\n\t\t\t\t\t\t}]),\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\n\t\t\t\t\tconsole.log(`[MF] ✅ Registered ${pluginId}`);\n\t\t\t\t}),\n\n\t\t\tloadRemoteConstructor: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst remoteName = getNormalizedRemoteName(pluginId);\n\t\t\t\t\tconsole.log(`[MF] Loading remote ${remoteName}`);\n\t\t\t\t\tconst modulePath = `${remoteName}/plugin`;\n\n\t\t\t\t\treturn yield* Effect.tryPromise({\n\t\t\t\t\t\ttry: async () => {\n\n\t\t\t\t\t\t\tconst container = await mf.loadRemote<RemoteModule>(modulePath);\n\t\t\t\t\t\t\tif (!container) {\n\t\t\t\t\t\t\t\tthrow new Error(`No container returned for ${modulePath}`);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Support multiple export patterns: direct function, default export, named exports\n\t\t\t\t\t\t\tlet Constructor: any;\n\n\t\t\t\t\t\t\tif (typeof container === \"function\") {\n\t\t\t\t\t\t\t\t// Direct function export\n\t\t\t\t\t\t\t\tConstructor = container;\n\t\t\t\t\t\t\t} else if (container.default) {\n\t\t\t\t\t\t\t\t// Default export\n\t\t\t\t\t\t\t\tConstructor = container.default;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Named export fallback - prioritize exports with 'binding' property (plugin classes)\n\t\t\t\t\t\t\t\tConstructor = Object.values(container).find(\n\t\t\t\t\t\t\t\t\t(exp) => typeof exp === \"function\" && (exp as any).binding !== undefined\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Fallback to any function export if no binding found\n\t\t\t\t\t\t\t\tif (!Constructor) {\n\t\t\t\t\t\t\t\t\tConstructor = Object.values(container).find(\n\t\t\t\t\t\t\t\t\t\t(exp) => typeof exp === \"function\" && exp.prototype?.constructor === exp\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!Constructor || typeof Constructor !== \"function\") {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Available exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`No valid plugin constructor found for '${pluginId}'.\\n` +\n\t\t\t\t\t\t\t\t\t`Supported patterns:\\n` +\n\t\t\t\t\t\t\t\t\t` - export const YourPlugin = createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t` - export default createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Validate it looks like a plugin constructor (has binding property)\n\t\t\t\t\t\t\tif (!(Constructor as any).binding) {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Found exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`Invalid plugin constructor for '${pluginId}'. ` +\n\t\t\t\t\t\t\t\t\t`The exported value must be created with createPlugin(). ` +\n\t\t\t\t\t\t\t\t\t`Found a function but it's missing the required 'binding' property.\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconsole.log(`[MF] ✅ Loaded constructor for ${pluginId}`);\n\t\t\t\t\t\t\treturn Constructor;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t}),\n\t\t};\n\t}),\n}) { }\n"],"mappings":";;;;;;;;;AAiBA,MAAM,iCAAiC,OAAO,OAC7C,OAAO,WAAW;AACjB,KAAI;EACH,IAAI,WAAW,aAAa;AAE5B,MAAI,CAAC,UAAU;AACd,cAAW,eAAe;IACzB,MAAM;IACN,SAAS,EAAE;IACX,QAAQ;KACP,gBAAgB;MACNA;MACT,WAAW,OAAO,mBAAgB,MAAK,cAAa,IAAI;MACxD,aAAa;OACZ,WAAW;OACX,iBAAiB,qBAAqBA,QAAY;OAClD,OAAO;OACP,eAAe;OACf;MACD;KACD,QAAQ;MACP,sBAA0B;MAC1B,WAAW,OAAO,UAAU,MAAK,cAAa,IAAI;MAClD,aAAa;OACZ,WAAW;OACX,iBAAiB,kCAAsC,OAAO;OAC9D,OAAO;OACP,eAAe;OACf;MACD;KACD,KAAK;MACJ,sBAA0B;MAC1B,WAAW,OAAO,OAAO,MAAK,cAAa,IAAI;MAC/C,aAAa;OACZ,WAAW;OACX,iBAAiB,kCAAsC,IAAI;OAC3D,OAAO;OACP,eAAe;OACf;MACD;KACD,kBAAkB;MACjB,sB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AAa;KAI3D,IAAI;AAEJ,SAAI,OAAO,cAAc,WAExB,eAAc;cACJ,UAAU,QAEpB,eAAc,UAAU;UAClB;AAEN,oBAAc,OAAO,OAAO,UAAU,CAAC,MACrC,QAAQ,OAAO,QAAQ,cAAe,IAAY,YAAY,OAC/D;AAGD,UAAI,CAAC,YACJ,eAAc,OAAO,OAAO,UAAU,CAAC,MACrC,QAAQ,OAAO,QAAQ,cAAc,IAAI,WAAW,gBAAgB,IACrE;;AAIH,SAAI,CAAC,eAAe,OAAO,gBAAgB,YAAY;MACtD,MAAM,gBAAgB,OAAO,cAAc,WACxC,sBAAsB,OAAO,KAAK,UAAU,CAAC,KAAK,KAAK,KACvD,mBAAmB,OAAO;AAE7B,YAAM,IAAI,MACT,0CAA0C,SAAS,sHAIhD,gBACH;;AAIF,SAAI,CAAE,YAAoB,SAAS;MAClC,MAAM,gBAAgB,OAAO,cAAc,WACxC,kBAAkB,OAAO,KAAK,UAAU,CAAC,KAAK,KAAK,KACnD,mBAAmB,OAAO;AAE7B,YAAM,IAAI,MACT,mCAAmC,SAAS,iIAGzC,gBACH;;AAGF,aAAQ,IAAI,iCAAiC,WAAW;AACxD,YAAO;;IAER,QAAQ,UACP,IAAI,sBAAsB;KACzB;KACA,WAAW;KACX,OACC,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;KAC1D,CAAC;IACH,CAAC;IACD;EACH;EACA,EACF,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"module-federation.service.mjs","names":[],"sources":["../../../src/runtime/services/module-federation.service.ts"],"sourcesContent":["import { createInstance, getInstance } from \"@module-federation/enhanced/runtime\";\nimport { setGlobalFederationInstance } from \"@module-federation/runtime-core\";\nimport { Effect } from \"effect\";\nimport type { AnyPlugin } from \"../../types\";\nimport { ModuleFederationError } from \"../errors\";\nimport { MF_SHARED_DEPS, type SharedDepName } from \"../mf-config\";\nimport { getNormalizedRemoteName } from \"./normalize\";\n\ntype RemoteModule = (new () => AnyPlugin) | { default: new () => AnyPlugin };\n\nconst sharedModuleLoaders = {\n \"every-plugin\": () => import(\"every-plugin\"),\n effect: () => import(\"effect\"),\n zod: () => import(\"zod\"),\n} satisfies Record<SharedDepName, () => Promise<unknown>>;\n\nconst createModuleFederationInstance = Effect.cached(\n Effect.sync(() => {\n try {\n let instance = getInstance();\n\n if (!instance) {\n const shared = Object.fromEntries(\n (\n Object.entries(MF_SHARED_DEPS) as [\n SharedDepName,\n (typeof MF_SHARED_DEPS)[SharedDepName],\n ][]\n ).map(([name, config]) => {\n const load = sharedModuleLoaders[name];\n\n if (!load) {\n throw new Error(`Missing shared module loader for ${name}`);\n }\n\n return [\n name,\n {\n version: config.version,\n get: () => load().then((mod) => () => mod),\n shareConfig: config.shareConfig,\n },\n ];\n }),\n );\n\n instance = createInstance({\n name: \"host\",\n remotes: [],\n shared,\n });\n\n setGlobalFederationInstance(instance);\n }\n\n return instance;\n } catch (error) {\n throw new Error(`Failed to initialize Module Federation: ${error}`);\n }\n }),\n);\n\nexport class ModuleFederationService extends Effect.Service<ModuleFederationService>()(\n \"ModuleFederationService\",\n {\n effect: Effect.gen(function* () {\n const mf = yield* Effect.flatten(createModuleFederationInstance);\n\n return {\n registerRemote: (pluginId: string, url: string) =>\n Effect.gen(function* () {\n console.log(`[MF] Registering ${pluginId}`);\n\n const remoteName = getNormalizedRemoteName(pluginId);\n const type = url.endsWith(\"/mf-manifest.json\")\n ? (\"manifest\" as const)\n : url.endsWith(\"/remoteEntry.js\")\n ? (\"script\" as const)\n : undefined;\n\n yield* Effect.try({\n try: () =>\n mf.registerRemotes([\n {\n name: remoteName,\n entry: url,\n ...(type ? { type } : {}),\n },\n ]),\n catch: (error): ModuleFederationError =>\n new ModuleFederationError({\n pluginId,\n remoteUrl: url,\n cause: error instanceof Error ? error : new Error(String(error)),\n }),\n });\n\n console.log(`[MF] ✅ Registered ${pluginId}`);\n }),\n\n loadRemoteConstructor: (pluginId: string, url: string) =>\n Effect.gen(function* () {\n const remoteName = getNormalizedRemoteName(pluginId);\n console.log(`[MF] Loading remote ${remoteName}`);\n const modulePath = `${remoteName}/plugin`;\n\n return yield* Effect.tryPromise({\n try: async () => {\n const container = await mf.loadRemote<RemoteModule>(modulePath);\n if (!container) {\n throw new Error(`No container returned for ${modulePath}`);\n }\n\n // Support multiple export patterns: direct function, default export, named exports\n let Constructor: any;\n\n if (typeof container === \"function\") {\n // Direct function export\n Constructor = container;\n } else if (container.default) {\n // Default export\n Constructor = container.default;\n } else {\n // Named export fallback - prioritize exports with 'binding' property (plugin classes)\n Constructor = Object.values(container).find(\n (exp) => typeof exp === \"function\" && (exp as any).binding !== undefined,\n );\n\n // Fallback to any function export if no binding found\n if (!Constructor) {\n Constructor = Object.values(container).find(\n (exp) => typeof exp === \"function\" && exp.prototype?.constructor === exp,\n );\n }\n }\n\n if (!Constructor || typeof Constructor !== \"function\") {\n const containerInfo =\n typeof container === \"object\"\n ? `Available exports: ${Object.keys(container).join(\", \")}`\n : `Container type: ${typeof container}`;\n\n throw new Error(\n `No valid plugin constructor found for '${pluginId}'.\\n` +\n `Supported patterns:\\n` +\n ` - export const YourPlugin = createPlugin({...})\\n` +\n ` - export default createPlugin({...})\\n` +\n `${containerInfo}`,\n );\n }\n\n // Validate it looks like a plugin constructor (has binding property)\n if (!(Constructor as any).binding) {\n const containerInfo =\n typeof container === \"object\"\n ? `Found exports: ${Object.keys(container).join(\", \")}`\n : `Container type: ${typeof container}`;\n\n throw new Error(\n `Invalid plugin constructor for '${pluginId}'. ` +\n `The exported value must be created with createPlugin(). ` +\n `Found a function but it's missing the required 'binding' property.\\n` +\n `${containerInfo}`,\n );\n }\n\n console.log(`[MF] ✅ Loaded constructor for ${pluginId}`);\n return Constructor;\n },\n catch: (error): ModuleFederationError =>\n new ModuleFederationError({\n pluginId,\n remoteUrl: url,\n cause: error instanceof Error ? error : new Error(String(error)),\n }),\n });\n }),\n };\n }),\n },\n) {}\n"],"mappings":";;;;;;;;AAUA,MAAM,sBA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
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1
2
|
|
|
2
3
|
//#region src/runtime/services/normalize.ts
|
|
3
4
|
/**
|
|
4
5
|
* Normalizes a package name into the module federation remote name.
|
|
5
6
|
* This function must produce identical results in both runtime and build contexts.
|
|
6
|
-
*
|
|
7
|
+
*
|
|
7
8
|
* Normalization rules:
|
|
8
9
|
* - Convert to lowercase
|
|
9
10
|
* - Strip a single leading '@' symbol
|
|
10
11
|
* - Replace '/' with '_'
|
|
11
12
|
* - Preserve hyphens and other characters
|
|
12
|
-
*
|
|
13
|
+
*
|
|
13
14
|
* Examples:
|
|
14
15
|
* - "@scope/my-plugin" → "scope_my-plugin"
|
|
15
16
|
* - "@SCOPE/Foo/Bar" → "scope_foo_bar"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.cjs","names":[],"sources":["../../../src/runtime/services/normalize.ts"],"sourcesContent":["/**\n * Normalizes a package name into the module federation remote name.\n * This function must produce identical results in both runtime and build contexts.\n
|
|
1
|
+
{"version":3,"file":"normalize.cjs","names":[],"sources":["../../../src/runtime/services/normalize.ts"],"sourcesContent":["/**\n * Normalizes a package name into the module federation remote name.\n * This function must produce identical results in both runtime and build contexts.\n *\n * Normalization rules:\n * - Convert to lowercase\n * - Strip a single leading '@' symbol\n * - Replace '/' with '_'\n * - Preserve hyphens and other characters\n *\n * Examples:\n * - \"@scope/my-plugin\" → \"scope_my-plugin\"\n * - \"@SCOPE/Foo/Bar\" → \"scope_foo_bar\"\n * - \"foo/bar\" → \"foo_bar\"\n * - \"simple-plugin\" → \"simple-plugin\"\n */\nexport const getNormalizedRemoteName = (name: string): string =>\n name.toLowerCase().replace(/^@/, \"\").replace(/\\//g, \"_\");\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,MAAa,2BAA2B,SACtC,KAAK,aAAa,CAAC,QAAQ,MAAM,GAAG,CAAC,QAAQ,OAAO,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.cts","names":[],"sources":["../../../src/runtime/services/normalize.ts"],"mappings":";;AAgBA;;;;;;;;;;;;;;;cAAa,uBAAA,
|
|
1
|
+
{"version":3,"file":"normalize.d.cts","names":[],"sources":["../../../src/runtime/services/normalize.ts"],"mappings":";;AAgBA;;;;;;;;;;;;;;;cAAa,uBAAA,GAA2B,IAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.mts","names":[],"sources":["../../../src/runtime/services/normalize.ts"],"mappings":";;AAgBA;;;;;;;;;;;;;;;cAAa,uBAAA,
|
|
1
|
+
{"version":3,"file":"normalize.d.mts","names":[],"sources":["../../../src/runtime/services/normalize.ts"],"mappings":";;AAgBA;;;;;;;;;;;;;;;cAAa,uBAAA,GAA2B,IAAA"}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Normalizes a package name into the module federation remote name.
|
|
4
4
|
* This function must produce identical results in both runtime and build contexts.
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* Normalization rules:
|
|
7
7
|
* - Convert to lowercase
|
|
8
8
|
* - Strip a single leading '@' symbol
|
|
9
9
|
* - Replace '/' with '_'
|
|
10
10
|
* - Preserve hyphens and other characters
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
12
|
* Examples:
|
|
13
13
|
* - "@scope/my-plugin" → "scope_my-plugin"
|
|
14
14
|
* - "@SCOPE/Foo/Bar" → "scope_foo_bar"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.mjs","names":[],"sources":["../../../src/runtime/services/normalize.ts"],"sourcesContent":["/**\n * Normalizes a package name into the module federation remote name.\n * This function must produce identical results in both runtime and build contexts.\n
|
|
1
|
+
{"version":3,"file":"normalize.mjs","names":[],"sources":["../../../src/runtime/services/normalize.ts"],"sourcesContent":["/**\n * Normalizes a package name into the module federation remote name.\n * This function must produce identical results in both runtime and build contexts.\n *\n * Normalization rules:\n * - Convert to lowercase\n * - Strip a single leading '@' symbol\n * - Replace '/' with '_'\n * - Preserve hyphens and other characters\n *\n * Examples:\n * - \"@scope/my-plugin\" → \"scope_my-plugin\"\n * - \"@SCOPE/Foo/Bar\" → \"scope_foo_bar\"\n * - \"foo/bar\" → \"foo_bar\"\n * - \"simple-plugin\" → \"simple-plugin\"\n */\nexport const getNormalizedRemoteName = (name: string): string =>\n name.toLowerCase().replace(/^@/, \"\").replace(/\\//g, \"_\");\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAa,2BAA2B,SACtC,KAAK,aAAa,CAAC,QAAQ,MAAM,GAAG,CAAC,QAAQ,OAAO,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-lifecycle.service.cjs","names":["Effect","Ref","toPluginRuntimeError"],"sources":["../../../src/runtime/services/plugin-lifecycle.service.ts"],"sourcesContent":["import { Effect, Ref } from \"effect\";\nimport type { AnyPlugin, InitializedPlugin } from \"../../types\";\nimport { toPluginRuntimeError } from \"../errors\";\n\nexport class PluginLifecycleService extends Effect.Service<PluginLifecycleService>()(\"PluginLifecycleService\"
|
|
1
|
+
{"version":3,"file":"plugin-lifecycle.service.cjs","names":["Effect","Ref","toPluginRuntimeError"],"sources":["../../../src/runtime/services/plugin-lifecycle.service.ts"],"sourcesContent":["import { Effect, Ref } from \"effect\";\nimport type { AnyPlugin, InitializedPlugin } from \"../../types\";\nimport { toPluginRuntimeError } from \"../errors\";\n\nexport class PluginLifecycleService extends Effect.Service<PluginLifecycleService>()(\n \"PluginLifecycleService\",\n {\n effect: Effect.gen(function* () {\n const activePlugins = yield* Ref.make(new Set<InitializedPlugin<AnyPlugin>>());\n\n return {\n register: <T extends AnyPlugin>(plugin: InitializedPlugin<T>) =>\n Ref.update(activePlugins, (plugins) =>\n new Set(plugins).add(plugin as InitializedPlugin<AnyPlugin>),\n ),\n\n unregister: (plugin: InitializedPlugin<AnyPlugin>) =>\n Ref.update(activePlugins, (plugins) => {\n const newSet = new Set(plugins);\n newSet.delete(plugin);\n return newSet;\n }),\n\n shutdown: (plugin: InitializedPlugin<AnyPlugin>) =>\n Effect.gen(function* () {\n // Remove from active plugins\n yield* Ref.update(activePlugins, (plugins) => {\n const newSet = new Set(plugins);\n newSet.delete(plugin);\n return newSet;\n });\n\n // Shutdown the plugin\n yield* plugin.plugin\n .shutdown()\n .pipe(\n Effect.mapError((error) =>\n toPluginRuntimeError(\n error,\n plugin.plugin.id,\n undefined,\n \"shutdown-plugin\",\n false,\n ),\n ),\n );\n }),\n\n cleanup: () =>\n Effect.gen(function* () {\n const plugins = yield* Ref.get(activePlugins);\n\n // Shutdown all active plugins concurrently\n yield* Effect.forEach(\n plugins,\n (plugin) =>\n plugin.plugin.shutdown().pipe(\n Effect.mapError((error) =>\n toPluginRuntimeError(\n error,\n plugin.plugin.id,\n undefined,\n \"cleanup-shutdown\",\n false,\n ),\n ),\n Effect.catchAll((error) =>\n Effect.logError(\n `Failed to shutdown plugin ${plugin.plugin.id} during cleanup`,\n error,\n { pluginId: plugin.plugin.id },\n ),\n ),\n ),\n { concurrency: \"unbounded\" },\n );\n\n // Clear the active plugins set\n yield* Ref.set(activePlugins, new Set());\n }).pipe(\n Effect.catchAll(() => Effect.void), // Convert errors to void for cleanup\n ),\n };\n }),\n },\n) {}\n"],"mappings":";;;;;AAIA,IAAa,yBAAb,cAA4CA,cAAO,SAAiC,CAClF,0BACA,EACE,QAAQA,cAAO,IAAI,aAAa;CAC9B,MAAM,gBAAgB,OAAOC,WAAI,qBAAK,IAAI,KAAmC,CAAC;AAE9E,QAAO;EACL,WAAgC,WAC9BA,WAAI,OAAO,gBAAgB,YACzB,IAAI,IAAI,QAAQ,CAAC,IAAI,OAAuC,CAC7D;EAEH,aAAa,WACXA,WAAI,OAAO,gBAAgB,YAAY;GACrC,MAAM,SAAS,IAAI,IAAI,QAAQ;AAC/B,UAAO,OAAO,OAAO;AACrB,UAAO;IACP;EAEJ,WAAW,WACTD,cAAO,IAAI,aAAa;AAEtB,UAAOC,WAAI,OAAO,gBAAgB,YAAY;IAC5C,MAAM,SAAS,IAAI,IAAI,QAAQ;AAC/B,WAAO,OAAO,OAAO;AACrB,WAAO;KACP;AAGF,UAAO,OAAO,OACX,UAAU,CACV,KACCD,cAAO,UAAU,UACfE,oCACE,OACA,OAAO,OAAO,IACd,QACA,mBACA,MACD,CACF,CACF;IACH;EAEJ,eACEF,cAAO,IAAI,aAAa;GACtB,MAAM,UAAU,OAAOC,WAAI,IAAI,cAAc;AAG7C,UAAOD,cAAO,QACZ,UACC,WACC,OAAO,OAAO,UAAU,CAAC,KACvBA,cAAO,UAAU,UACfE,oCACE,OACA,OAAO,OAAO,IACd,QACA,oBACA,MACD,CACF,EACDF,cAAO,UAAU,UACfA,cAAO,SACL,6BAA6B,OAAO,OAAO,GAAG,kBAC9C,OACA,EAAE,UAAU,OAAO,OAAO,IAAI,CAC/B,CACF,CACF,EACH,EAAE,aAAa,aAAa,CAC7B;AAGD,UAAOC,WAAI,IAAI,+BAAe,IAAI,KAAK,CAAC;IACxC,CAAC,KACDD,cAAO,eAAeA,cAAO,KAAK,CACnC;EACJ;EACD,EACH,CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-lifecycle.service.d.cts","names":[],"sources":["../../../src/runtime/services/plugin-lifecycle.service.ts"],"mappings":";;;;;cACgE,2BAAA;;
|
|
1
|
+
{"version":3,"file":"plugin-lifecycle.service.d.cts","names":[],"sources":["../../../src/runtime/services/plugin-lifecycle.service.ts"],"mappings":";;;;;cACgE,2BAAA;;yBAUnC,SAAA,EAAS,MAAA,EAAU,iBAAA,CAAkB,CAAA,MAAE,MAAA,CAAA,MAAA;yBAKvC,iBAAA,CAAkB,SAAA,MAAU,MAAA,CAAA,MAAA;uBAO9B,iBAAA,CAAkB,SAAA,MAAU,MAAA,CAAA,MAAA,OAAX,kBAAA;;;;cAnB/B,sBAAA,SAA+B,2BAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-lifecycle.service.d.mts","names":[],"sources":["../../../src/runtime/services/plugin-lifecycle.service.ts"],"mappings":";;;;;cACgE,2BAAA;;
|
|
1
|
+
{"version":3,"file":"plugin-lifecycle.service.d.mts","names":[],"sources":["../../../src/runtime/services/plugin-lifecycle.service.ts"],"mappings":";;;;;cACgE,2BAAA;;yBAUnC,SAAA,EAAS,MAAA,EAAU,iBAAA,CAAkB,CAAA,MAAE,MAAA,CAAA,MAAA;yBAKvC,iBAAA,CAAkB,SAAA,MAAU,MAAA,CAAA,MAAA;uBAO9B,iBAAA,CAAkB,SAAA,MAAU,MAAA,CAAA,MAAA,OAAX,kBAAA;;;;cAnB/B,sBAAA,SAA+B,2BAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-lifecycle.service.mjs","names":[],"sources":["../../../src/runtime/services/plugin-lifecycle.service.ts"],"sourcesContent":["import { Effect, Ref } from \"effect\";\nimport type { AnyPlugin, InitializedPlugin } from \"../../types\";\nimport { toPluginRuntimeError } from \"../errors\";\n\nexport class PluginLifecycleService extends Effect.Service<PluginLifecycleService>()(\"PluginLifecycleService\"
|
|
1
|
+
{"version":3,"file":"plugin-lifecycle.service.mjs","names":[],"sources":["../../../src/runtime/services/plugin-lifecycle.service.ts"],"sourcesContent":["import { Effect, Ref } from \"effect\";\nimport type { AnyPlugin, InitializedPlugin } from \"../../types\";\nimport { toPluginRuntimeError } from \"../errors\";\n\nexport class PluginLifecycleService extends Effect.Service<PluginLifecycleService>()(\n \"PluginLifecycleService\",\n {\n effect: Effect.gen(function* () {\n const activePlugins = yield* Ref.make(new Set<InitializedPlugin<AnyPlugin>>());\n\n return {\n register: <T extends AnyPlugin>(plugin: InitializedPlugin<T>) =>\n Ref.update(activePlugins, (plugins) =>\n new Set(plugins).add(plugin as InitializedPlugin<AnyPlugin>),\n ),\n\n unregister: (plugin: InitializedPlugin<AnyPlugin>) =>\n Ref.update(activePlugins, (plugins) => {\n const newSet = new Set(plugins);\n newSet.delete(plugin);\n return newSet;\n }),\n\n shutdown: (plugin: InitializedPlugin<AnyPlugin>) =>\n Effect.gen(function* () {\n // Remove from active plugins\n yield* Ref.update(activePlugins, (plugins) => {\n const newSet = new Set(plugins);\n newSet.delete(plugin);\n return newSet;\n });\n\n // Shutdown the plugin\n yield* plugin.plugin\n .shutdown()\n .pipe(\n Effect.mapError((error) =>\n toPluginRuntimeError(\n error,\n plugin.plugin.id,\n undefined,\n \"shutdown-plugin\",\n false,\n ),\n ),\n );\n }),\n\n cleanup: () =>\n Effect.gen(function* () {\n const plugins = yield* Ref.get(activePlugins);\n\n // Shutdown all active plugins concurrently\n yield* Effect.forEach(\n plugins,\n (plugin) =>\n plugin.plugin.shutdown().pipe(\n Effect.mapError((error) =>\n toPluginRuntimeError(\n error,\n plugin.plugin.id,\n undefined,\n \"cleanup-shutdown\",\n false,\n ),\n ),\n Effect.catchAll((error) =>\n Effect.logError(\n `Failed to shutdown plugin ${plugin.plugin.id} during cleanup`,\n error,\n { pluginId: plugin.plugin.id },\n ),\n ),\n ),\n { concurrency: \"unbounded\" },\n );\n\n // Clear the active plugins set\n yield* Ref.set(activePlugins, new Set());\n }).pipe(\n Effect.catchAll(() => Effect.void), // Convert errors to void for cleanup\n ),\n };\n }),\n },\n) {}\n"],"mappings":";;;;AAIA,IAAa,yBAAb,cAA4C,OAAO,SAAiC,CAClF,0BACA,EACE,QAAQ,OAAO,IAAI,aAAa;CAC9B,MAAM,gBAAgB,OAAO,IAAI,qBAAK,IAAI,KAAmC,CAAC;AAE9E,QAAO;EACL,WAAgC,WAC9B,IAAI,OAAO,gBAAgB,YACzB,IAAI,IAAI,QAAQ,CAAC,IAAI,OAAuC,CAC7D;EAEH,aAAa,WACX,IAAI,OAAO,gBAAgB,YAAY;GACrC,MAAM,SAAS,IAAI,IAAI,QAAQ;AAC/B,UAAO,OAAO,OAAO;AACrB,UAAO;IACP;EAEJ,WAAW,WACT,OAAO,IAAI,aAAa;AAEtB,UAAO,IAAI,OAAO,gBAAgB,YAAY;IAC5C,MAAM,SAAS,IAAI,IAAI,QAAQ;AAC/B,WAAO,OAAO,OAAO;AACrB,WAAO;KACP;AAGF,UAAO,OAAO,OACX,UAAU,CACV,KACC,OAAO,UAAU,UACf,qBACE,OACA,OAAO,OAAO,IACd,QACA,mBACA,MACD,CACF,CACF;IACH;EAEJ,eACE,OAAO,IAAI,aAAa;GACtB,MAAM,UAAU,OAAO,IAAI,IAAI,cAAc;AAG7C,UAAO,OAAO,QACZ,UACC,WACC,OAAO,OAAO,UAAU,CAAC,KACvB,OAAO,UAAU,UACf,qBACE,OACA,OAAO,OAAO,IACd,QACA,oBACA,MACD,CACF,EACD,OAAO,UAAU,UACf,OAAO,SACL,6BAA6B,OAAO,OAAO,GAAG,kBAC9C,OACA,EAAE,UAAU,OAAO,OAAO,IAAI,CAC/B,CACF,CACF,EACH,EAAE,aAAa,aAAa,CAC7B;AAGD,UAAO,IAAI,IAAI,+BAAe,IAAI,KAAK,CAAC;IACxC,CAAC,KACD,OAAO,eAAe,OAAO,KAAK,CACnC;EACJ;EACD,EACH,CACF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
2
2
|
const require_errors = require('../errors.cjs');
|
|
3
3
|
const require_module_federation_service = require('./module-federation.service.cjs');
|
|
4
4
|
const require_validation = require('../validation.cjs');
|
|
@@ -81,7 +81,7 @@ var PluginLoaderService = class extends effect.Effect.Service()("PluginLoaderSer
|
|
|
81
81
|
metadata: loadedPlugin.metadata
|
|
82
82
|
};
|
|
83
83
|
}),
|
|
84
|
-
initializePlugin: (pluginInstance, config) => effect.Effect.gen(function* () {
|
|
84
|
+
initializePlugin: (pluginInstance, config, plugins) => effect.Effect.gen(function* () {
|
|
85
85
|
const { plugin } = pluginInstance;
|
|
86
86
|
const validatedVariables = yield* require_validation.validate(plugin.configSchema.variables, config.variables, plugin.id, "config").pipe(effect.Effect.mapError((validationError) => new require_errors.PluginRuntimeError({
|
|
87
87
|
pluginId: plugin.id,
|
|
@@ -109,7 +109,7 @@ var PluginLoaderService = class extends effect.Effect.Service()("PluginLoaderSer
|
|
|
109
109
|
const context = yield* plugin.initialize({
|
|
110
110
|
variables: _variables,
|
|
111
111
|
secrets: hydratedConfig.secrets
|
|
112
|
-
}).pipe(effect.Effect.provideService(effect.Scope.Scope, scope), effect.Effect.mapError((error) => require_errors.toPluginRuntimeError(error, plugin.id, void 0, "initialize-plugin", false)));
|
|
112
|
+
}, plugins ?? {}).pipe(effect.Effect.provideService(effect.Scope.Scope, scope), effect.Effect.mapError((error) => require_errors.toPluginRuntimeError(error, plugin.id, void 0, "initialize-plugin", false)));
|
|
113
113
|
return {
|
|
114
114
|
plugin,
|
|
115
115
|
metadata: pluginInstance.metadata,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-loader.service.cjs","names":["Context","Effect","PluginRuntimeError","ModuleFederationService","SecretsService","toPluginRuntimeError","validate","Scope"],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":["import type { InferSchemaInput, InferSchemaOutput } from \"@orpc/contract\";\nimport { Context, Effect, Scope } from \"effect\";\nimport type { z } from \"zod\";\nimport type {\n\tAnyPlugin,\n\tAnyPluginConstructor,\n\tInitializedPlugin,\n\tLoadedPlugin,\n\tPluginInstance,\n\tPluginMetadata,\n\tPluginRegistry\n} from \"../../types\";\nimport { PluginRuntimeError, toPluginRuntimeError } from \"../errors\";\nimport { validate } from \"../validation\";\nimport { ModuleFederationService } from \"./module-federation.service\";\nimport { SecretsService } from \"./secrets.service\";\n\nexport class PluginRegistryTag extends Context.Tag(\"PluginRegistry\")<\n\tPluginRegistryTag,\n\tPluginRegistry\n>() { }\n\nexport class PluginMapTag extends Context.Tag(\"PluginMap\")<\n\tPluginMapTag,\n\tRecord<string, AnyPluginConstructor>\n>() { }\n\nexport class RegistryService extends Effect.Service<RegistryService>()(\"RegistryService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst registry = yield* PluginRegistryTag;\n\t\tconst pluginMap = yield* PluginMapTag;\n\n\t\treturn {\n\t\t\tget: (pluginId: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst entry = registry[pluginId];\n\t\t\t\t\t\n\t\t\t\t\tif (!entry) {\n\t\t\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\toperation: \"validate-plugin-id\",\n\t\t\t\t\t\t\t\tcause: new Error(`Plugin ${pluginId} not found in registry`),\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\"module\" in entry) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tconstructor: entry.module,\n\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\tremoteUrl: entry.remote || \"\",\n\t\t\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\t\t\t} as PluginMetadata,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tconstructor: null,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tremoteUrl: entry.remote,\n\t\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\t\t} as PluginMetadata,\n\t\t\t\t\t};\n\t\t\t\t}),\n\n\t\t\tgetModule: (pluginId: string) =>\n\t\t\t\tEffect.succeed(pluginMap[pluginId] || null),\n\t\t};\n\t}),\n}) { }\n\nexport class PluginLoaderService extends Effect.Service<PluginLoaderService>()(\"PluginLoaderService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst moduleFederationService = yield* ModuleFederationService;\n\t\tconst secretsService = yield* SecretsService;\n\t\tconst registryService = yield* RegistryService;\n\n\t\tconst resolveUrl = (baseUrl: string, version?: string): string =>\n\t\t\tversion && version !== \"latest\"\n\t\t\t\t? baseUrl.replace(\"@latest\", `@${version}`)\n\t\t\t\t: baseUrl;\n\n\t\treturn {\n\t\t\tloadPlugin: (pluginId: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst entry = yield* registryService.get(pluginId);\n\n\t\t\t\t\tif (entry.constructor) {\n\t\t\t\t\t\tyield* Effect.logDebug(\"Loading plugin from direct module\", { pluginId });\n\t\t\t\t\t\t\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tctor: entry.constructor,\n\t\t\t\t\t\t\tmetadata: entry.metadata,\n\t\t\t\t\t\t} satisfies LoadedPlugin;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst url = entry.metadata.remoteUrl;\n\t\t\t\t\tif (!url) {\n\t\t\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\toperation: \"load-plugin\",\n\t\t\t\t\t\t\t\tcause: new Error(`Plugin ${pluginId} has no module or remote URL configured`),\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst resolvedUrl = resolveUrl(url);\n\n\t\t\t\t\tyield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, pluginId, undefined, \"register-remote\", true),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\tyield* Effect.logDebug(\"Loading plugin from remote\", { pluginId, url: resolvedUrl });\n\n\t\t\t\t\tconst ctor = yield* moduleFederationService.loadRemoteConstructor(pluginId, resolvedUrl).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, pluginId, undefined, \"load-remote\", false),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tctor,\n\t\t\t\t\t\tmetadata: entry.metadata,\n\t\t\t\t\t} satisfies LoadedPlugin;\n\t\t\t\t}),\n\n\t\t\tinstantiatePlugin: <T extends AnyPlugin>(\n\t\t\t\tpluginId: string,\n\t\t\t\tloadedPlugin: LoadedPlugin<T>,\n\t\t\t) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\"instantiate-plugin\",\n\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t(instance.id as string) = pluginId;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tplugin: instance,\n\t\t\t\t\t\tmetadata: loadedPlugin.metadata,\n\t\t\t\t\t} satisfies PluginInstance<T>;\n\t\t\t\t}),\n\n\t\t\tinitializePlugin: <T extends AnyPlugin>(\n\t\t\t\tpluginInstance: PluginInstance<T>,\n\t\t\t\tconfig: { variables: InferSchemaInput<T[\"configSchema\"][\"variables\"]>; secrets: InferSchemaInput<T[\"configSchema\"][\"secrets\"]> },\n\t\t\t) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst { plugin } = pluginInstance;\n\n\t\t\t\t\t// Validate and hydrate config\n\t\t\t\t\tconst validatedVariables = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.variables as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"variables\"]>>,\n\t\t\t\t\t\tconfig.variables,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-config\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Validate secrets\n\t\t\t\t\tconst validatedSecrets = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.secrets as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"secrets\"]>>,\n\t\t\t\t\t\tconfig.secrets,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-secrets\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Hydrate secrets in variables\n\t\t\t\t\tconst hydratedConfig = yield* secretsService.hydrateSecrets({\n\t\t\t\t\t\tvariables: validatedVariables,\n\t\t\t\t\t\tsecrets: validatedSecrets,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst _variables = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.variables as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"variables\"]>>,\n\t\t\t\t\t\thydratedConfig.variables,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-hydrated-config\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Create a long-lived scope for this plugin instance\n\t\t\t\t\tconst scope = yield* Scope.make();\n\n\t\t\t\t\t// Initialize plugin within the scope\n\t\t\t\t\tconst context = yield* plugin.initialize({ variables: _variables, secrets: hydratedConfig.secrets }).pipe(\n\t\t\t\t\t\tEffect.provideService(Scope.Scope, scope),\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, plugin.id, undefined, \"initialize-plugin\", false),\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tplugin,\n\t\t\t\t\t\tmetadata: pluginInstance.metadata,\n\t\t\t\t\t\tconfig: { variables: _variables, secrets: hydratedConfig.secrets },\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t} satisfies InitializedPlugin<T>;\n\t\t\t\t}),\n\t\t};\n\t}),\n}) {\n}\n"],"mappings":";;;;;;;;AAiBA,IAAa,oBAAb,cAAuCA,eAAQ,IAAI,iBAAiB,EAGjE,CAAC;AAEJ,IAAa,eAAb,cAAkCA,eAAQ,IAAI,YAAY,EAGvD,CAAC;AAEJ,IAAa,kBAAb,cAAqCC,cAAO,SAA0B,CAAC,mBAAmB,EACzF,QAAQA,cAAO,IAAI,aAAa;CAC/B,MAAM,WAAW,OAAO;CACxB,MAAM,YAAY,OAAO;AAEzB,QAAO;EACN,MAAM,aACLA,cAAO,IAAI,aAAa;GACvB,MAAM,QAAQ,SAAS;AAEvB,OAAI,CAAC,MACJ,QAAO,OAAOA,cAAO,KACpB,IAAIC,kCAAmB;IACtB;IAC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CACD;GAGD,MAAM,QAAQ,OAAOK,aAAM,MAAM;GAGjC,MAAM,UAAU,OAAO,OAAO,WAAW;IAAE,WAAW;IAAY,SAAS,eAAe;IAAS,CAAC,CAAC,KACpGN,cAAO,eAAeM,aAAM,OAAO,MAAM,EACzCN,cAAO,UAAU,UAChBI,oCAAqB,OAAO,OAAO,IAAI,QAAW,qBAAqB,MAAM,CAC7E,CACD;AAED,UAAO;IACN;IACA,UAAU,eAAe;IACzB,QAAQ;KAAE,WAAW;KAAY,SAAS,eAAe;KAAS;IAClE;IACA;IACA;IACA;EACH;EACA,EACF,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"plugin-loader.service.cjs","names":["Context","Effect","PluginRuntimeError","ModuleFederationService","SecretsService","toPluginRuntimeError","validate","Scope"],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":["import type { InferSchemaInput, InferSchemaOutput } from \"@orpc/contract\";\nimport { Context, Effect, Scope } from \"effect\";\nimport type { z } from \"zod\";\nimport type {\n AnyPlugin,\n AnyPluginConstructor,\n InitializedPlugin,\n LoadedPlugin,\n PluginInstance,\n PluginMetadata,\n PluginRegistry,\n} from \"../../types\";\nimport { PluginRuntimeError, toPluginRuntimeError } from \"../errors\";\nimport { validate } from \"../validation\";\nimport { ModuleFederationService } from \"./module-federation.service\";\nimport { SecretsService } from \"./secrets.service\";\n\nexport class PluginRegistryTag extends Context.Tag(\"PluginRegistry\")<\n PluginRegistryTag,\n PluginRegistry\n>() {}\n\nexport class PluginMapTag extends Context.Tag(\"PluginMap\")<\n PluginMapTag,\n Record<string, AnyPluginConstructor>\n>() {}\n\nexport class RegistryService extends Effect.Service<RegistryService>()(\"RegistryService\", {\n effect: Effect.gen(function* () {\n const registry = yield* PluginRegistryTag;\n const pluginMap = yield* PluginMapTag;\n\n return {\n get: (pluginId: string) =>\n Effect.gen(function* () {\n const entry = registry[pluginId];\n\n if (!entry) {\n return yield* Effect.fail(\n new PluginRuntimeError({\n pluginId,\n operation: \"validate-plugin-id\",\n cause: new Error(`Plugin ${pluginId} not found in registry`),\n retryable: false,\n }),\n );\n }\n\n if (\"module\" in entry) {\n return {\n constructor: entry.module,\n metadata: {\n remoteUrl: entry.remote || \"\",\n version: entry.version,\n description: entry.description,\n } as PluginMetadata,\n };\n }\n\n return {\n constructor: null,\n metadata: {\n remoteUrl: entry.remote,\n version: entry.version,\n description: entry.description,\n } as PluginMetadata,\n };\n }),\n\n getModule: (pluginId: string) => Effect.succeed(pluginMap[pluginId] || null),\n };\n }),\n}) {}\n\nexport class PluginLoaderService extends Effect.Service<PluginLoaderService>()(\n \"PluginLoaderService\",\n {\n effect: Effect.gen(function* () {\n const moduleFederationService = yield* ModuleFederationService;\n const secretsService = yield* SecretsService;\n const registryService = yield* RegistryService;\n\n const resolveUrl = (baseUrl: string, version?: string): string =>\n version && version !== \"latest\" ? baseUrl.replace(\"@latest\", `@${version}`) : baseUrl;\n\n return {\n loadPlugin: (pluginId: string) =>\n Effect.gen(function* () {\n const entry = yield* registryService.get(pluginId);\n\n if (entry.constructor) {\n yield* Effect.logDebug(\"Loading plugin from direct module\", { pluginId });\n\n return {\n ctor: entry.constructor,\n metadata: entry.metadata,\n } satisfies LoadedPlugin;\n }\n\n const url = entry.metadata.remoteUrl;\n if (!url) {\n return yield* Effect.fail(\n new PluginRuntimeError({\n pluginId,\n operation: \"load-plugin\",\n cause: new Error(`Plugin ${pluginId} has no module or remote URL configured`),\n retryable: false,\n }),\n );\n }\n\n const resolvedUrl = resolveUrl(url);\n\n yield* moduleFederationService\n .registerRemote(pluginId, resolvedUrl)\n .pipe(\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"register-remote\", true),\n ),\n );\n\n yield* Effect.logDebug(\"Loading plugin from remote\", { pluginId, url: resolvedUrl });\n\n const ctor = yield* moduleFederationService\n .loadRemoteConstructor(pluginId, resolvedUrl)\n .pipe(\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"load-remote\", false),\n ),\n );\n\n return {\n ctor,\n metadata: entry.metadata,\n } satisfies LoadedPlugin;\n }),\n\n instantiatePlugin: <T extends AnyPlugin>(pluginId: string, loadedPlugin: LoadedPlugin<T>) =>\n Effect.gen(function* () {\n const instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"instantiate-plugin\", false),\n ),\n );\n\n (instance.id as string) = pluginId;\n\n return {\n plugin: instance,\n metadata: loadedPlugin.metadata,\n } satisfies PluginInstance<T>;\n }),\n\n initializePlugin: <T extends AnyPlugin>(\n pluginInstance: PluginInstance<T>,\n config: {\n variables: InferSchemaInput<T[\"configSchema\"][\"variables\"]>;\n secrets: InferSchemaInput<T[\"configSchema\"][\"secrets\"]>;\n },\n plugins?: Record<string, unknown>,\n ) =>\n Effect.gen(function* () {\n const { plugin } = pluginInstance;\n\n // Validate and hydrate config\n const validatedVariables = yield* validate(\n plugin.configSchema.variables as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"variables\"]>\n >,\n config.variables,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-config\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Validate secrets\n const validatedSecrets = yield* validate(\n plugin.configSchema.secrets as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"secrets\"]>\n >,\n config.secrets,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-secrets\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Hydrate secrets in variables\n const hydratedConfig = yield* secretsService.hydrateSecrets({\n variables: validatedVariables,\n secrets: validatedSecrets,\n });\n\n const _variables = yield* validate(\n plugin.configSchema.variables as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"variables\"]>\n >,\n hydratedConfig.variables,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-hydrated-config\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Create a long-lived scope for this plugin instance\n const scope = yield* Scope.make();\n\n // Initialize plugin within the scope\n const context = yield* plugin\n .initialize({ variables: _variables, secrets: hydratedConfig.secrets }, plugins ?? {})\n .pipe(\n Effect.provideService(Scope.Scope, scope),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, plugin.id, undefined, \"initialize-plugin\", false),\n ),\n );\n\n return {\n plugin,\n metadata: pluginInstance.metadata,\n config: { variables: _variables, secrets: hydratedConfig.secrets },\n context,\n scope,\n } satisfies InitializedPlugin<T>;\n }),\n };\n }),\n },\n) {}\n"],"mappings":";;;;;;;;AAiBA,IAAa,oBAAb,cAAuCA,eAAQ,IAAI,iBAAiB,EAGjE,CAAC;AAEJ,IAAa,eAAb,cAAkCA,eAAQ,IAAI,YAAY,EAGvD,CAAC;AAEJ,IAAa,kBAAb,cAAqCC,cAAO,SAA0B,CAAC,mBAAmB,EACxF,QAAQA,cAAO,IAAI,aAAa;CAC9B,MAAM,WAAW,OAAO;CACxB,MAAM,YAAY,OAAO;AAEzB,QAAO;EACL,MAAM,aACJA,cAAO,IAAI,aAAa;GACtB,MAAM,QAAQ,SAAS;AAEvB,OAAI,CAAC,MACH,QAAO,OAAOA,cAAO,KACnB,IAAIC,kCAAmB;IACrB;IACA,WAAW;IACX,uBAAO,IAAI,MAAM,UAAU,SAAS,wBAAwB;IAC5D,WAAW;IACZ,CAAC,CACH;AAGH,OAAI,YAAY,MACd,QAAO;IACL,aAAa,MAAM;IACnB,UAAU;KACR,WAAW,MAAM,UAAU;KAC3B,SAAS,MAAM;KACf,aAAa,MAAM;KACpB;IACF;AAGH,UAAO;IACL,aAAa;IACb,UAAU;KACR,WAAW,MAAM;KACjB,SAAS,MAAM;KACf,aAAa,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ACF;AAEH,UAAO;IACL;IACA,UAAU,eAAe;IACzB,QAAQ;KAAE,WAAW;KAAY,SAAS,eAAe;KAAS;IAClE;IACA;IACD;IACD;EACL;EACD,EACH,CACF,CAAC"}
|
|
@@ -36,7 +36,7 @@ declare const PluginLoaderService_base: Effect.Service.Class<PluginLoaderService
|
|
|
36
36
|
initializePlugin: <T extends AnyPlugin>(pluginInstance: PluginInstance<T>, config: {
|
|
37
37
|
variables: InferSchemaInput<T["configSchema"]["variables"]>;
|
|
38
38
|
secrets: InferSchemaInput<T["configSchema"]["secrets"]>;
|
|
39
|
-
}) => Effect.Effect<{
|
|
39
|
+
}, plugins?: Record<string, unknown>) => Effect.Effect<{
|
|
40
40
|
plugin: T;
|
|
41
41
|
metadata: PluginMetadata;
|
|
42
42
|
config: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-loader.service.d.cts","names":[],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"mappings":";;;;;;;;cAemD,sBAAA;cAEtC,iBAAA,SAA0B,sBAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"plugin-loader.service.d.cts","names":[],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"mappings":";;;;;;;;cAemD,sBAAA;cAEtC,iBAAA,SAA0B,sBAAA;AAAA,cAGjC,iBAAA;cAEO,YAAA,SAAqB,iBAAA;AAAA,cAG5B,oBAAA;;+BAQsB,MAAA,CAAA,MAAA;;gBAsBT,cAAA;IAAA;;gBAUF,cAAA;IAAA;qCAIiB,MAAA,CAAA,MAAA,CAAA,oBAAA;EAAA;;cA1CrB,eAAA,SAAwB,oBAAA;AAAA,cA6ChC,wBAAA;;sCAcgC,MAAA,CAAA,MAAA;;;;kCAmDC,SAAA,EAAS,QAAA,UAAkB,YAAA,EAAgB,YAAA,CAAa,CAAA,MAAE,MAAA,CAAA,MAAA;;;;iCAgB3D,SAAA,EAAS,cAAA,EACpB,cAAA,CAAe,CAAA,GAAE,MAAA;MAE/B,SAAA,EAAW,gBAAA,CAAiB,CAAA;MAC5B,OAAA,EAAS,gBAAA,CAAiB,CAAA;IAAA,GAC3B,OAAA,GACS,MAAA,sBAAuB,MAAA,CAAA,MAAA;;;;;;;;;;;;cArF9B,mBAAA,SAA4B,wBAAA"}
|
|
@@ -36,7 +36,7 @@ declare const PluginLoaderService_base: Effect.Service.Class<PluginLoaderService
|
|
|
36
36
|
initializePlugin: <T extends AnyPlugin>(pluginInstance: PluginInstance<T>, config: {
|
|
37
37
|
variables: InferSchemaInput<T["configSchema"]["variables"]>;
|
|
38
38
|
secrets: InferSchemaInput<T["configSchema"]["secrets"]>;
|
|
39
|
-
}) => Effect.Effect<{
|
|
39
|
+
}, plugins?: Record<string, unknown>) => Effect.Effect<{
|
|
40
40
|
plugin: T;
|
|
41
41
|
metadata: PluginMetadata;
|
|
42
42
|
config: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-loader.service.d.mts","names":[],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"mappings":";;;;;;;;cAemD,sBAAA;cAEtC,iBAAA,SAA0B,sBAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"plugin-loader.service.d.mts","names":[],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"mappings":";;;;;;;;cAemD,sBAAA;cAEtC,iBAAA,SAA0B,sBAAA;AAAA,cAGjC,iBAAA;cAEO,YAAA,SAAqB,iBAAA;AAAA,cAG5B,oBAAA;;+BAQsB,MAAA,CAAA,MAAA;;gBAsBT,cAAA;IAAA;;gBAUF,cAAA;IAAA;qCAIiB,MAAA,CAAA,MAAA,CAAA,oBAAA;EAAA;;cA1CrB,eAAA,SAAwB,oBAAA;AAAA,cA6ChC,wBAAA;;sCAcgC,MAAA,CAAA,MAAA;;;;kCAmDC,SAAA,EAAS,QAAA,UAAkB,YAAA,EAAgB,YAAA,CAAa,CAAA,MAAE,MAAA,CAAA,MAAA;;;;iCAgB3D,SAAA,EAAS,cAAA,EACpB,cAAA,CAAe,CAAA,GAAE,MAAA;MAE/B,SAAA,EAAW,gBAAA,CAAiB,CAAA;MAC5B,OAAA,EAAS,gBAAA,CAAiB,CAAA;IAAA,GAC3B,OAAA,GACS,MAAA,sBAAuB,MAAA,CAAA,MAAA;;;;;;;;;;;;cArF9B,mBAAA,SAA4B,wBAAA"}
|
|
@@ -80,7 +80,7 @@ var PluginLoaderService = class extends Effect.Service()("PluginLoaderService",
|
|
|
80
80
|
metadata: loadedPlugin.metadata
|
|
81
81
|
};
|
|
82
82
|
}),
|
|
83
|
-
initializePlugin: (pluginInstance, config) => Effect.gen(function* () {
|
|
83
|
+
initializePlugin: (pluginInstance, config, plugins) => Effect.gen(function* () {
|
|
84
84
|
const { plugin } = pluginInstance;
|
|
85
85
|
const validatedVariables = yield* validate(plugin.configSchema.variables, config.variables, plugin.id, "config").pipe(Effect.mapError((validationError) => new PluginRuntimeError({
|
|
86
86
|
pluginId: plugin.id,
|
|
@@ -108,7 +108,7 @@ var PluginLoaderService = class extends Effect.Service()("PluginLoaderService",
|
|
|
108
108
|
const context = yield* plugin.initialize({
|
|
109
109
|
variables: _variables,
|
|
110
110
|
secrets: hydratedConfig.secrets
|
|
111
|
-
}).pipe(Effect.provideService(Scope.Scope, scope), Effect.mapError((error) => toPluginRuntimeError(error, plugin.id, void 0, "initialize-plugin", false)));
|
|
111
|
+
}, plugins ?? {}).pipe(Effect.provideService(Scope.Scope, scope), Effect.mapError((error) => toPluginRuntimeError(error, plugin.id, void 0, "initialize-plugin", false)));
|
|
112
112
|
return {
|
|
113
113
|
plugin,
|
|
114
114
|
metadata: pluginInstance.metadata,
|