@squide/firefly-module-federation 1.1.2 → 2.0.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/CHANGELOG.md +12 -0
- package/dist/ModuleFederationPlugin.js +9 -12
- package/dist/ModuleFederationPlugin.js.map +1 -1
- package/dist/RemoteModuleRegistry.d.ts +13 -0
- package/dist/RemoteModuleRegistry.js.map +1 -1
- package/package.json +3 -3
- package/src/ModuleFederationPlugin.ts +19 -25
- package/src/RemoteModuleRegistry.ts +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @squide/firefly-module-federation
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#586](https://github.com/workleap/wl-squide/pull/586) [`f26a67f`](https://github.com/workleap/wl-squide/commit/f26a67f80984c50aaf9b3b550a8e1f25edcbb43e) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Added typed EventBus through module augmentation of EventMap.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`f26a67f`](https://github.com/workleap/wl-squide/commit/f26a67f80984c50aaf9b3b550a8e1f25edcbb43e)]:
|
|
12
|
+
- @squide/firefly@17.0.0
|
|
13
|
+
- @squide/core@7.0.0
|
|
14
|
+
|
|
3
15
|
## 1.1.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -42,7 +42,7 @@ class ModuleFederationPlugin extends Plugin {
|
|
|
42
42
|
addProtectedListener(this._runtime, RemoteModulesRegistrationStartedEvent, (payload)=>{
|
|
43
43
|
const bootstrappingSpan = getBootstrappingSpan();
|
|
44
44
|
const attributes = {
|
|
45
|
-
"app.squide.remote_count": payload
|
|
45
|
+
"app.squide.remote_count": payload?.remoteCount
|
|
46
46
|
};
|
|
47
47
|
if (bootstrappingSpan) {
|
|
48
48
|
bootstrappingSpan.addEvent("remote-module-registration-started", attributes);
|
|
@@ -61,7 +61,7 @@ class ModuleFederationPlugin extends Plugin {
|
|
|
61
61
|
const bootstrappingSpan = getBootstrappingSpan();
|
|
62
62
|
if (bootstrappingSpan) {
|
|
63
63
|
bootstrappingSpan.addEvent("remote-module-registration-completed", {
|
|
64
|
-
"app.squide.remote_count": payload
|
|
64
|
+
"app.squide.remote_count": payload?.remoteCount
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
if (remoteModuleRegistrationSpan) {
|
|
@@ -73,9 +73,8 @@ class ModuleFederationPlugin extends Plugin {
|
|
|
73
73
|
});
|
|
74
74
|
// Can occur multiple times.
|
|
75
75
|
addProtectedListener(this._runtime, RemoteModuleRegistrationFailedEvent, (payload)=>{
|
|
76
|
-
const registrationError = payload;
|
|
77
76
|
if (remoteModuleRegistrationSpan) {
|
|
78
|
-
traceError(remoteModuleRegistrationSpan,
|
|
77
|
+
traceError(remoteModuleRegistrationSpan, payload);
|
|
79
78
|
}
|
|
80
79
|
}, {
|
|
81
80
|
onError: handleUnmanagedError
|
|
@@ -83,7 +82,7 @@ class ModuleFederationPlugin extends Plugin {
|
|
|
83
82
|
addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationStartedEvent, (payload)=>{
|
|
84
83
|
const bootstrappingSpan = getBootstrappingSpan();
|
|
85
84
|
const attributes = {
|
|
86
|
-
"app.squide.registration_count": payload
|
|
85
|
+
"app.squide.registration_count": payload?.registrationCount
|
|
87
86
|
};
|
|
88
87
|
if (bootstrappingSpan) {
|
|
89
88
|
bootstrappingSpan.addEvent("remote-module-deferred-registration-started", attributes);
|
|
@@ -102,7 +101,7 @@ class ModuleFederationPlugin extends Plugin {
|
|
|
102
101
|
const bootstrappingSpan = getBootstrappingSpan();
|
|
103
102
|
if (bootstrappingSpan) {
|
|
104
103
|
bootstrappingSpan.addEvent("remote-module-deferred-registration-completed", {
|
|
105
|
-
"app.squide.registration_count": payload
|
|
104
|
+
"app.squide.registration_count": payload?.registrationCount
|
|
106
105
|
});
|
|
107
106
|
}
|
|
108
107
|
if (remoteModuleDeferredRegistrationSpan) {
|
|
@@ -114,9 +113,8 @@ class ModuleFederationPlugin extends Plugin {
|
|
|
114
113
|
});
|
|
115
114
|
// Can occur multiple times.
|
|
116
115
|
addProtectedListener(this._runtime, RemoteModuleDeferredRegistrationFailedEvent, (payload)=>{
|
|
117
|
-
const registrationError = payload;
|
|
118
116
|
if (remoteModuleDeferredRegistrationSpan) {
|
|
119
|
-
traceError(remoteModuleDeferredRegistrationSpan,
|
|
117
|
+
traceError(remoteModuleDeferredRegistrationSpan, payload);
|
|
120
118
|
}
|
|
121
119
|
}, {
|
|
122
120
|
onError: handleUnmanagedError
|
|
@@ -125,7 +123,7 @@ class ModuleFederationPlugin extends Plugin {
|
|
|
125
123
|
addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationsUpdateStartedEvent, (payload)=>{
|
|
126
124
|
const deferredRegistrationsUpdateSpan = getDeferredRegistrationsUpdateSpan();
|
|
127
125
|
const attributes = {
|
|
128
|
-
"app.squide.registration_count": payload
|
|
126
|
+
"app.squide.registration_count": payload?.registrationCount
|
|
129
127
|
};
|
|
130
128
|
if (deferredRegistrationsUpdateSpan) {
|
|
131
129
|
deferredRegistrationsUpdateSpan.addEvent("remote-module-deferred-registrations-update-started", attributes);
|
|
@@ -149,7 +147,7 @@ class ModuleFederationPlugin extends Plugin {
|
|
|
149
147
|
const deferredRegistrationsUpdateSpan = getDeferredRegistrationsUpdateSpan();
|
|
150
148
|
if (deferredRegistrationsUpdateSpan) {
|
|
151
149
|
deferredRegistrationsUpdateSpan.addEvent("remote-module-deferred-registrations-update-completed", {
|
|
152
|
-
"app.squide.registration_count": payload
|
|
150
|
+
"app.squide.registration_count": payload?.registrationCount
|
|
153
151
|
});
|
|
154
152
|
}
|
|
155
153
|
if (remoteModuleDeferredRegistrationsUpdateSpan) {
|
|
@@ -160,9 +158,8 @@ class ModuleFederationPlugin extends Plugin {
|
|
|
160
158
|
});
|
|
161
159
|
// Can occur multiple times.
|
|
162
160
|
addProtectedListener(this._runtime, RemoteModuleDeferredRegistrationUpdateFailedEvent, (payload)=>{
|
|
163
|
-
const registrationError = payload;
|
|
164
161
|
if (remoteModuleDeferredRegistrationsUpdateSpan) {
|
|
165
|
-
traceError(remoteModuleDeferredRegistrationsUpdateSpan.instance,
|
|
162
|
+
traceError(remoteModuleDeferredRegistrationsUpdateSpan.instance, payload);
|
|
166
163
|
}
|
|
167
164
|
}, {
|
|
168
165
|
onError: handleUnmanagedError
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleFederationPlugin.js","sources":["../src/ModuleFederationPlugin.ts"],"sourcesContent":["import { loadRemote as loadModuleFederationRemote } from \"@module-federation/enhanced/runtime\";\nimport { Span } from \"@opentelemetry/api\";\nimport { Plugin, RegisterModulesOptions, type Runtime } from \"@squide/core\";\nimport { FireflyPlugin, FireflyRuntime } from \"@squide/firefly\";\nimport { ActiveSpan, addProtectedListener, endActiveSpan, getTracer, HoneycombTrackingUnmanagedErrorHandler, startActiveChildSpan, startChildSpan, traceError, type GetSpanFunction } from \"@squide/firefly/internal\";\nimport { RemoteDefinition } from \"./RemoteDefinition.ts\";\nimport { RemoteModuleDeferredRegistrationFailedEvent, RemoteModuleDeferredRegistrationUpdateFailedEvent, RemoteModuleRegistrationError, RemoteModuleRegistrationFailedEvent, RemoteModuleRegistry, RemoteModuleRegistryId, RemoteModulesDeferredRegistrationCompletedEvent, RemoteModulesDeferredRegistrationCompletedEventPayload, RemoteModulesDeferredRegistrationStartedEvent, RemoteModulesDeferredRegistrationStartedEventPayload, RemoteModulesDeferredRegistrationsUpdateCompletedEvent, RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload, RemoteModulesDeferredRegistrationsUpdateStartedEvent, RemoteModulesDeferredRegistrationsUpdateStartedEventPayload, RemoteModulesRegistrationCompletedEvent, RemoteModulesRegistrationCompletedEventPayload, RemoteModulesRegistrationStartedEvent, RemoteModulesRegistrationStartedEventPayload } from \"./RemoteModuleRegistry.ts\";\n\nexport const ModuleFederationPluginName = \"module-federation-plugin\";\n\nexport class ModuleFederationPlugin extends Plugin<FireflyRuntime> implements FireflyPlugin {\n constructor(runtime: FireflyRuntime) {\n super(ModuleFederationPluginName, runtime);\n\n this._runtime.moduleManager.addModuleRegistry(new RemoteModuleRegistry((remoteName, moduleName) => loadModuleFederationRemote(`${remoteName}/${moduleName}`)));\n }\n\n registerRemoteModules<TContext = unknown>(remotes: RemoteDefinition[], options?: RegisterModulesOptions<TContext>) {\n return this._runtime.moduleManager.registerModules(remotes.map(x => ({\n definition: x,\n registryId: RemoteModuleRegistryId\n })), options);\n }\n\n registerHoneycombTrackingListeners(\n getBootstrappingSpan: GetSpanFunction,\n getDeferredRegistrationsUpdateSpan: GetSpanFunction,\n onUnmanagedError: HoneycombTrackingUnmanagedErrorHandler\n ) {\n let remoteModuleRegistrationSpan: Span;\n let remoteModuleDeferredRegistrationSpan: Span;\n let remoteModuleDeferredRegistrationsUpdateSpan: ActiveSpan;\n\n const handleUnmanagedError = (error: unknown) => {\n if (remoteModuleRegistrationSpan) {\n remoteModuleRegistrationSpan.end();\n }\n\n if (remoteModuleDeferredRegistrationSpan) {\n remoteModuleDeferredRegistrationSpan.end();\n }\n\n if (remoteModuleDeferredRegistrationsUpdateSpan) {\n remoteModuleDeferredRegistrationsUpdateSpan.instance.end();\n }\n\n onUnmanagedError(error);\n };\n\n addProtectedListener(this._runtime, RemoteModulesRegistrationStartedEvent, (payload: unknown) => {\n const bootstrappingSpan = getBootstrappingSpan();\n\n const attributes = {\n \"app.squide.remote_count\": (payload as RemoteModulesRegistrationStartedEventPayload).remoteCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-registration-started\", attributes);\n }\n\n remoteModuleRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"remote-module-registration\", { ...options, attributes }, context);\n });\n }, {\n once: true,\n onError: handleUnmanagedError\n });\n\n addProtectedListener(this._runtime, RemoteModulesRegistrationCompletedEvent, (payload: unknown) => {\n const bootstrappingSpan = getBootstrappingSpan();\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-registration-completed\", {\n \"app.squide.remote_count\": (payload as RemoteModulesRegistrationCompletedEventPayload).remoteCount\n });\n }\n\n if (remoteModuleRegistrationSpan) {\n remoteModuleRegistrationSpan.end();\n }\n }, {\n once: true,\n onError: handleUnmanagedError\n });\n\n // Can occur multiple times.\n addProtectedListener(this._runtime, RemoteModuleRegistrationFailedEvent, (payload: unknown) => {\n const registrationError = payload as RemoteModuleRegistrationError;\n\n if (remoteModuleRegistrationSpan) {\n traceError(remoteModuleRegistrationSpan, registrationError);\n }\n }, {\n onError: handleUnmanagedError\n });\n\n addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationStartedEvent, (payload: unknown) => {\n const bootstrappingSpan = getBootstrappingSpan();\n\n const attributes = {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationStartedEventPayload).registrationCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-deferred-registration-started\", attributes);\n }\n\n remoteModuleDeferredRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"remote-module-deferred-registration\", { ...options, attributes }, context);\n });\n }, {\n once: true,\n onError: handleUnmanagedError\n });\n\n addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationCompletedEvent, (payload: unknown) => {\n const bootstrappingSpan = getBootstrappingSpan();\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-deferred-registration-completed\", {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationCompletedEventPayload).registrationCount\n });\n }\n\n if (remoteModuleDeferredRegistrationSpan) {\n remoteModuleDeferredRegistrationSpan.end();\n }\n }, {\n once: true,\n onError: handleUnmanagedError\n });\n\n // Can occur multiple times.\n addProtectedListener(this._runtime, RemoteModuleDeferredRegistrationFailedEvent, (payload: unknown) => {\n const registrationError = payload as RemoteModuleRegistrationError;\n\n if (remoteModuleDeferredRegistrationSpan) {\n traceError(remoteModuleDeferredRegistrationSpan, registrationError);\n }\n }, {\n onError: handleUnmanagedError\n });\n\n // Can occur multiple times.\n addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationsUpdateStartedEvent, (payload: unknown) => {\n const deferredRegistrationsUpdateSpan = getDeferredRegistrationsUpdateSpan();\n\n const attributes = {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationsUpdateStartedEventPayload).registrationCount\n };\n\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"remote-module-deferred-registrations-update-started\", attributes);\n }\n\n remoteModuleDeferredRegistrationsUpdateSpan = startActiveChildSpan(deferredRegistrationsUpdateSpan, (options, context) => {\n const name = \"remote-module-deferred-registrations-update\";\n\n const span = getTracer().startSpan(name, {\n attributes,\n ...options\n }, context);\n\n return {\n name,\n span\n };\n });\n }, {\n onError: handleUnmanagedError\n });\n\n // Can occur multiple times.\n addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationsUpdateCompletedEvent, (payload: unknown) => {\n const deferredRegistrationsUpdateSpan = getDeferredRegistrationsUpdateSpan();\n\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"remote-module-deferred-registrations-update-completed\", {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload).registrationCount\n });\n }\n\n if (remoteModuleDeferredRegistrationsUpdateSpan) {\n endActiveSpan(remoteModuleDeferredRegistrationsUpdateSpan);\n }\n }, {\n onError: handleUnmanagedError\n });\n\n // Can occur multiple times.\n addProtectedListener(this._runtime, RemoteModuleDeferredRegistrationUpdateFailedEvent, (payload: unknown) => {\n const registrationError = payload as RemoteModuleRegistrationError;\n\n if (remoteModuleDeferredRegistrationsUpdateSpan) {\n traceError(remoteModuleDeferredRegistrationsUpdateSpan.instance, registrationError);\n }\n }, {\n onError: handleUnmanagedError\n });\n\n // Cleanup the spans if the root tracking is failing.\n return (error: unknown) => {\n handleUnmanagedError(error);\n };\n }\n}\n\nexport function getModuleFederationPlugin(runtime: Runtime) {\n const plugin = runtime.getPlugin(ModuleFederationPluginName, {\n throwOnNotFound: false\n }) as ModuleFederationPlugin;\n\n if (!plugin) {\n throw new Error(\"[squide] The getModuleFederationPlugin function is called but no ModuleFederationPlugin instance has been registered with the runtime. Did you import the initializeFirefly function from the \\\"@squide/firefly-module-federation\\\" package?\");\n }\n\n return plugin;\n}\n"],"names":["loadRemote","loadModuleFederationRemote","Plugin","addProtectedListener","endActiveSpan","getTracer","startActiveChildSpan","startChildSpan","traceError","RemoteModuleDeferredRegistrationFailedEvent","RemoteModuleDeferredRegistrationUpdateFailedEvent","RemoteModuleRegistrationFailedEvent","RemoteModuleRegistry","RemoteModuleRegistryId","RemoteModulesDeferredRegistrationCompletedEvent","RemoteModulesDeferredRegistrationStartedEvent","RemoteModulesDeferredRegistrationsUpdateCompletedEvent","RemoteModulesDeferredRegistrationsUpdateStartedEvent","RemoteModulesRegistrationCompletedEvent","RemoteModulesRegistrationStartedEvent","ModuleFederationPluginName","ModuleFederationPlugin","runtime","remoteName","moduleName","remotes","options","x","getBootstrappingSpan","getDeferredRegistrationsUpdateSpan","onUnmanagedError","remoteModuleRegistrationSpan","remoteModuleDeferredRegistrationSpan","remoteModuleDeferredRegistrationsUpdateSpan","handleUnmanagedError","error","payload","bootstrappingSpan","attributes","context","registrationError","deferredRegistrationsUpdateSpan","name","span","getModuleFederationPlugin","plugin","Error"],"mappings":";;;;;;;;;AAA+F;AAEnB;AAE0I;AAE6oB;AAE51B,MAAMoB,0BAA0BA,GAAG,2BAA2B;AAE9D,MAAMC,sBAAsBA,SAASnB,MAAMA;IAC9C,YAAYoB,OAAuB,CAAE;QACjC,KAAK,CAACF,0BAA0BA,EAAEE;QAElC,IAAI,CAAC,QAAQ,CAAC,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AIC,MAAM;IACpB;IAEA,OAAOD;AACX"}
|
|
1
|
+
{"version":3,"file":"ModuleFederationPlugin.js","sources":["../src/ModuleFederationPlugin.ts"],"sourcesContent":["import { loadRemote as loadModuleFederationRemote } from \"@module-federation/enhanced/runtime\";\nimport { Span } from \"@opentelemetry/api\";\nimport { Plugin, RegisterModulesOptions, type Runtime } from \"@squide/core\";\nimport { FireflyPlugin, FireflyRuntime } from \"@squide/firefly\";\nimport { ActiveSpan, addProtectedListener, endActiveSpan, getTracer, HoneycombTrackingUnmanagedErrorHandler, startActiveChildSpan, startChildSpan, traceError, type GetSpanFunction } from \"@squide/firefly/internal\";\nimport { RemoteDefinition } from \"./RemoteDefinition.ts\";\nimport { RemoteModuleDeferredRegistrationFailedEvent, RemoteModuleDeferredRegistrationUpdateFailedEvent, RemoteModuleRegistrationFailedEvent, RemoteModuleRegistry, RemoteModuleRegistryId, RemoteModulesDeferredRegistrationCompletedEvent, RemoteModulesDeferredRegistrationStartedEvent, RemoteModulesDeferredRegistrationsUpdateCompletedEvent, RemoteModulesDeferredRegistrationsUpdateStartedEvent, RemoteModulesRegistrationCompletedEvent, RemoteModulesRegistrationStartedEvent } from \"./RemoteModuleRegistry.ts\";\n\nexport const ModuleFederationPluginName = \"module-federation-plugin\";\n\nexport class ModuleFederationPlugin extends Plugin<FireflyRuntime> implements FireflyPlugin {\n constructor(runtime: FireflyRuntime) {\n super(ModuleFederationPluginName, runtime);\n\n this._runtime.moduleManager.addModuleRegistry(new RemoteModuleRegistry((remoteName, moduleName) => loadModuleFederationRemote(`${remoteName}/${moduleName}`)));\n }\n\n registerRemoteModules<TContext = unknown>(remotes: RemoteDefinition[], options?: RegisterModulesOptions<TContext>) {\n return this._runtime.moduleManager.registerModules(remotes.map(x => ({\n definition: x,\n registryId: RemoteModuleRegistryId\n })), options);\n }\n\n registerHoneycombTrackingListeners(\n getBootstrappingSpan: GetSpanFunction,\n getDeferredRegistrationsUpdateSpan: GetSpanFunction,\n onUnmanagedError: HoneycombTrackingUnmanagedErrorHandler\n ) {\n let remoteModuleRegistrationSpan: Span;\n let remoteModuleDeferredRegistrationSpan: Span;\n let remoteModuleDeferredRegistrationsUpdateSpan: ActiveSpan;\n\n const handleUnmanagedError = (error: unknown) => {\n if (remoteModuleRegistrationSpan) {\n remoteModuleRegistrationSpan.end();\n }\n\n if (remoteModuleDeferredRegistrationSpan) {\n remoteModuleDeferredRegistrationSpan.end();\n }\n\n if (remoteModuleDeferredRegistrationsUpdateSpan) {\n remoteModuleDeferredRegistrationsUpdateSpan.instance.end();\n }\n\n onUnmanagedError(error);\n };\n\n addProtectedListener(this._runtime, RemoteModulesRegistrationStartedEvent, payload => {\n const bootstrappingSpan = getBootstrappingSpan();\n\n const attributes = {\n \"app.squide.remote_count\": payload?.remoteCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-registration-started\", attributes);\n }\n\n remoteModuleRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"remote-module-registration\", { ...options, attributes }, context);\n });\n }, {\n once: true,\n onError: handleUnmanagedError\n });\n\n addProtectedListener(this._runtime, RemoteModulesRegistrationCompletedEvent, payload => {\n const bootstrappingSpan = getBootstrappingSpan();\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-registration-completed\", {\n \"app.squide.remote_count\": payload?.remoteCount\n });\n }\n\n if (remoteModuleRegistrationSpan) {\n remoteModuleRegistrationSpan.end();\n }\n }, {\n once: true,\n onError: handleUnmanagedError\n });\n\n // Can occur multiple times.\n addProtectedListener(this._runtime, RemoteModuleRegistrationFailedEvent, payload => {\n if (remoteModuleRegistrationSpan) {\n traceError(remoteModuleRegistrationSpan, payload as Error);\n }\n }, {\n onError: handleUnmanagedError\n });\n\n addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationStartedEvent, payload => {\n const bootstrappingSpan = getBootstrappingSpan();\n\n const attributes = {\n \"app.squide.registration_count\": payload?.registrationCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-deferred-registration-started\", attributes);\n }\n\n remoteModuleDeferredRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"remote-module-deferred-registration\", { ...options, attributes }, context);\n });\n }, {\n once: true,\n onError: handleUnmanagedError\n });\n\n addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationCompletedEvent, payload => {\n const bootstrappingSpan = getBootstrappingSpan();\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-deferred-registration-completed\", {\n \"app.squide.registration_count\": payload?.registrationCount\n });\n }\n\n if (remoteModuleDeferredRegistrationSpan) {\n remoteModuleDeferredRegistrationSpan.end();\n }\n }, {\n once: true,\n onError: handleUnmanagedError\n });\n\n // Can occur multiple times.\n addProtectedListener(this._runtime, RemoteModuleDeferredRegistrationFailedEvent, payload => {\n if (remoteModuleDeferredRegistrationSpan) {\n traceError(remoteModuleDeferredRegistrationSpan, payload as Error);\n }\n }, {\n onError: handleUnmanagedError\n });\n\n // Can occur multiple times.\n addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationsUpdateStartedEvent, payload => {\n const deferredRegistrationsUpdateSpan = getDeferredRegistrationsUpdateSpan();\n\n const attributes = {\n \"app.squide.registration_count\": payload?.registrationCount\n };\n\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"remote-module-deferred-registrations-update-started\", attributes);\n }\n\n remoteModuleDeferredRegistrationsUpdateSpan = startActiveChildSpan(deferredRegistrationsUpdateSpan, (options, context) => {\n const name = \"remote-module-deferred-registrations-update\";\n\n const span = getTracer().startSpan(name, {\n attributes,\n ...options\n }, context);\n\n return {\n name,\n span\n };\n });\n }, {\n onError: handleUnmanagedError\n });\n\n // Can occur multiple times.\n addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationsUpdateCompletedEvent, payload => {\n const deferredRegistrationsUpdateSpan = getDeferredRegistrationsUpdateSpan();\n\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"remote-module-deferred-registrations-update-completed\", {\n \"app.squide.registration_count\": payload?.registrationCount\n });\n }\n\n if (remoteModuleDeferredRegistrationsUpdateSpan) {\n endActiveSpan(remoteModuleDeferredRegistrationsUpdateSpan);\n }\n }, {\n onError: handleUnmanagedError\n });\n\n // Can occur multiple times.\n addProtectedListener(this._runtime, RemoteModuleDeferredRegistrationUpdateFailedEvent, payload => {\n if (remoteModuleDeferredRegistrationsUpdateSpan) {\n traceError(remoteModuleDeferredRegistrationsUpdateSpan.instance, payload as Error);\n }\n }, {\n onError: handleUnmanagedError\n });\n\n // Cleanup the spans if the root tracking is failing.\n return (error: unknown) => {\n handleUnmanagedError(error);\n };\n }\n}\n\nexport function getModuleFederationPlugin(runtime: Runtime) {\n const plugin = runtime.getPlugin(ModuleFederationPluginName, {\n throwOnNotFound: false\n }) as ModuleFederationPlugin;\n\n if (!plugin) {\n throw new Error(\"[squide] The getModuleFederationPlugin function is called but no ModuleFederationPlugin instance has been registered with the runtime. Did you import the initializeFirefly function from the \\\"@squide/firefly-module-federation\\\" package?\");\n }\n\n return plugin;\n}\n"],"names":["loadRemote","loadModuleFederationRemote","Plugin","addProtectedListener","endActiveSpan","getTracer","startActiveChildSpan","startChildSpan","traceError","RemoteModuleDeferredRegistrationFailedEvent","RemoteModuleDeferredRegistrationUpdateFailedEvent","RemoteModuleRegistrationFailedEvent","RemoteModuleRegistry","RemoteModuleRegistryId","RemoteModulesDeferredRegistrationCompletedEvent","RemoteModulesDeferredRegistrationStartedEvent","RemoteModulesDeferredRegistrationsUpdateCompletedEvent","RemoteModulesDeferredRegistrationsUpdateStartedEvent","RemoteModulesRegistrationCompletedEvent","RemoteModulesRegistrationStartedEvent","ModuleFederationPluginName","ModuleFederationPlugin","runtime","remoteName","moduleName","remotes","options","x","getBootstrappingSpan","getDeferredRegistrationsUpdateSpan","onUnmanagedError","remoteModuleRegistrationSpan","remoteModuleDeferredRegistrationSpan","remoteModuleDeferredRegistrationsUpdateSpan","handleUnmanagedError","error","payload","bootstrappingSpan","attributes","context","deferredRegistrationsUpdateSpan","name","span","getModuleFederationPlugin","plugin","Error"],"mappings":";;;;;;;;;AAA+F;AAEnB;AAE0I;AAEsS;AAErf,MAAMoB,0BAA0BA,GAAG,2BAA2B;AAE9D,MAAMC,sBAAsBA,SAASnB,MAAMA;IAC9C,YAAYoB,OAAuB,CAAE;QACjC,KAAK,CAACF,0BAA0BA,EAAEE;QAElC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,iBAAiB,CAAC,IAAIV,oBAAoBA,CAAC,CAACW,YAAYC,aAAevB,UAA0BA,CAAC,GAAGsB,WAAW,CAAC,EAAEC,YAAY;IAC/J;IAEA,sBAA0CC,OAA2B,EAAEC,OAA0C,EAAE;QAC/G,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,eAAe,CAACD,QAAQ,GAAG,CAACE,CAAAA,IAAM;gBACjE,YAAYA;gBACZ,YAAYd,sBAAsBA;YACtC,KAAKa;IACT;IAEA,mCACIE,oBAAqC,EACrCC,kCAAmD,EACnDC,gBAAwD,EAC1D;QACE,IAAIC;QACJ,IAAIC;QACJ,IAAIC;QAEJ,MAAMC,uBAAuB,CAACC;YAC1B,IAAIJ,8BAA8B;gBAC9BA,6BAA6B,GAAG;YACpC;YAEA,IAAIC,sCAAsC;gBACtCA,qCAAqC,GAAG;YAC5C;YAEA,IAAIC,6CAA6C;gBAC7CA,4CAA4C,QAAQ,CAAC,GAAG;YAC5D;YAEAH,iBAAiBK;QACrB;QAEAhC,oBAAoBA,CAAC,IAAI,CAAC,QAAQ,EAAEgB,qCAAqCA,EAAEiB,CAAAA;YACvE,MAAMC,oBAAoBT;YAE1B,MAAMU,aAAa;gBACf,2BAA2BF,SAAS;YACxC;YAEA,IAAIC,mBAAmB;gBACnBA,kBAAkB,QAAQ,CAAC,sCAAsCC;YACrE;YAEAP,+BAA+BxB,cAAcA,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;YACC,SAASF;QACb;QAEA,qDAAqD;QACrD,OAAO,CAACC;YACJD,qBAAqBC;QACzB;IACJ;AACJ;AAEO,SAASQ,yBAAyBA,CAACrB,OAAgB;IACtD,MAAMsB,SAAStB,QAAQ,SAAS,CAACF,0BAA0BA,EAAE;QACzD,iBAAiB;IACrB;IAEA,IAAI,CAACwB,QAAQ;QACT,MAAM,IAAIC,MAAM;IACpB;IAEA,OAAOD;AACX"}
|
|
@@ -28,6 +28,19 @@ export interface RemoteModulesDeferredRegistrationsUpdateStartedEventPayload {
|
|
|
28
28
|
export interface RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload {
|
|
29
29
|
registrationCount: number;
|
|
30
30
|
}
|
|
31
|
+
declare module "@squide/core" {
|
|
32
|
+
interface EventMap {
|
|
33
|
+
"squide-remote-modules-registration-started": RemoteModulesRegistrationStartedEventPayload;
|
|
34
|
+
"squide-remote-modules-registration-completed": RemoteModulesRegistrationCompletedEventPayload;
|
|
35
|
+
"squide-remote-module-registration-failed": ModuleRegistrationError;
|
|
36
|
+
"squide-remote-modules-deferred-registration-started": RemoteModulesDeferredRegistrationStartedEventPayload;
|
|
37
|
+
"squide-remote-modules-deferred-registration-completed": RemoteModulesDeferredRegistrationCompletedEventPayload;
|
|
38
|
+
"squide-some-remote-module-deferred-registration-failed": ModuleRegistrationError;
|
|
39
|
+
"squide-remote-modules-deferred-registrations-update-started": RemoteModulesDeferredRegistrationsUpdateStartedEventPayload;
|
|
40
|
+
"squide-remote-modules-deferred-registrations-update-completed-started": RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload;
|
|
41
|
+
"squide-remote-module-deferred-registration-update-failed": ModuleRegistrationError;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
31
44
|
type LoadRemoteFunction = (remoteName: string, moduleName: string) => Promise<any>;
|
|
32
45
|
export declare class RemoteModuleRegistrationError extends ModuleRegistrationError {
|
|
33
46
|
#private;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteModuleRegistry.js","sources":["../src/RemoteModuleRegistry.ts"],"sourcesContent":["import { ModuleDefinition, ModuleRegistrationError, registerModule, type DeferredRegistrationFunction, type ModuleRegistrationStatus, type ModuleRegistrationStatusChangedListener, type ModuleRegistry, type RegisterModulesOptions, type Runtime } from \"@squide/core\";\nimport { isFunction, isNil } from \"@squide/core/internal\";\nimport type { Logger, RootLogger } from \"@workleap/logging\";\nimport type { RemoteDefinition } from \"./RemoteDefinition.ts\";\n\nexport const RemoteModuleRegistryId = \"remote\";\n\nexport const RemoteModulesRegistrationStartedEvent = \"squide-remote-modules-registration-started\";\nexport const RemoteModulesRegistrationCompletedEvent = \"squide-remote-modules-registration-completed\";\nexport const RemoteModuleRegistrationFailedEvent = \"squide-remote-module-registration-failed\";\n\nexport const RemoteModulesDeferredRegistrationStartedEvent = \"squide-remote-modules-deferred-registration-started\";\nexport const RemoteModulesDeferredRegistrationCompletedEvent = \"squide-remote-modules-deferred-registration-completed\";\nexport const RemoteModuleDeferredRegistrationFailedEvent = \"squide-some-remote-module-deferred-registration-failed\";\n\nexport const RemoteModulesDeferredRegistrationsUpdateStartedEvent = \"squide-remote-modules-deferred-registrations-update-started\";\nexport const RemoteModulesDeferredRegistrationsUpdateCompletedEvent = \"squide-remote-modules-deferred-registrations-update-completed-started\";\nexport const RemoteModuleDeferredRegistrationUpdateFailedEvent = \"squide-remote-module-deferred-registration-update-failed\";\n\nexport interface RemoteModulesRegistrationStartedEventPayload {\n remoteCount: number;\n}\n\nexport interface RemoteModulesRegistrationCompletedEventPayload {\n remoteCount: number;\n}\n\nexport interface RemoteModulesDeferredRegistrationStartedEventPayload {\n registrationCount: number;\n}\n\nexport interface RemoteModulesDeferredRegistrationCompletedEventPayload {\n registrationCount: number;\n}\n\nexport interface RemoteModulesDeferredRegistrationsUpdateStartedEventPayload {\n registrationCount: number;\n}\n\nexport interface RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload {\n registrationCount: number;\n}\n\nconst RemoteRegisterModuleName = \"register\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype LoadRemoteFunction = (remoteName: string, moduleName: string) => Promise<any>;\n\ninterface DeferredRegistration<TRuntime extends Runtime = Runtime, TData = unknown> {\n remoteName: string;\n index: string;\n fct: DeferredRegistrationFunction<TRuntime, TData>;\n}\n\nexport class RemoteModuleRegistrationError extends ModuleRegistrationError {\n readonly #remoteName: string;\n readonly #moduleName: string;\n\n constructor(message: string, remoteName: string, moduleName: string, options?: ErrorOptions) {\n super(message, options);\n\n this.#remoteName = remoteName;\n this.#moduleName = moduleName;\n }\n\n get remoteName() {\n return this.#remoteName;\n }\n\n get moduleName() {\n return this.#moduleName;\n }\n}\n\nexport class RemoteModuleRegistry implements ModuleRegistry {\n #registrationStatus: ModuleRegistrationStatus = \"none\";\n\n readonly #deferredRegistrations: DeferredRegistration[] = [];\n readonly #loadRemote: LoadRemoteFunction;\n readonly #statusChangedListeners = new Set<ModuleRegistrationStatusChangedListener>();\n\n constructor(loadRemote: LoadRemoteFunction) {\n this.#loadRemote = loadRemote;\n }\n\n get id() {\n return RemoteModuleRegistryId;\n }\n\n #logSharedScope(logger: Logger) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (__webpack_share_scopes__) {\n logger.debug(\n \"[squide] Module Federation shared scope is available:\",\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n __webpack_share_scopes__.default\n );\n }\n }\n\n async registerModules<TRuntime extends Runtime = Runtime, TContext = unknown, TData = unknown>(runtime: TRuntime, remotes: RemoteDefinition[], { context }: RegisterModulesOptions<TContext> = {}) {\n const errors: RemoteModuleRegistrationError[] = [];\n\n if (this.#registrationStatus !== \"none\") {\n throw new Error(\"[squide] The registerRemoteModules function can only be called once.\");\n }\n\n if (remotes.length > 0) {\n runtime.logger.information(`[squide] Found ${remotes.length} remote module${remotes.length !== 1 ? \"s\" : \"\"} to register.`);\n\n this.#setRegistrationStatus(\"registering-modules\");\n\n runtime.eventBus.dispatch(RemoteModulesRegistrationStartedEvent, {\n remoteCount: remotes.length\n } satisfies RemoteModulesRegistrationStartedEventPayload);\n\n let completedCount = 0;\n\n await Promise.allSettled(remotes.map(async (x, index) => {\n const remoteName = x.name;\n const loggerScope = (runtime.logger as RootLogger).startScope(`[squide] ${index + 1}/${remotes.length} Loading module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`);\n const runtimeScope = runtime.startScope(loggerScope);\n\n try {\n const module = await this.#loadRemote(remoteName, RemoteRegisterModuleName);\n\n if (isNil(module.register)) {\n throw new Error(`[squide] A \"register\" function is not available for module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\". Make sure your remote \"./register.[js,jsx,ts.tsx]\" file export a function named \"register\".`);\n }\n\n loggerScope.debug(\"[squide] Registering module...\");\n\n const optionalDeferredRegistration = await registerModule<TRuntime, TContext, TData>(module.register, runtimeScope as TRuntime, context);\n\n if (isFunction(optionalDeferredRegistration)) {\n this.#deferredRegistrations.push({\n remoteName: x.name,\n index: `${index + 1}/${remotes.length}`,\n fct: optionalDeferredRegistration as DeferredRegistrationFunction\n });\n }\n\n completedCount += 1;\n\n loggerScope.information(\"[squide] Successfully registered remote module.\", {\n style: {\n color: \"green\"\n }\n });\n\n loggerScope.end({\n labelStyle: {\n color: \"green\"\n }\n });\n } catch (error: unknown) {\n loggerScope\n .withText(\"[squide] An error occured while registering the remote module.\")\n .withError(error as Error)\n .error();\n\n loggerScope.end({\n labelStyle: {\n color: \"red\"\n }\n });\n\n errors.push(\n new RemoteModuleRegistrationError(\n `An error occured while registering module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`,\n remoteName,\n RemoteRegisterModuleName,\n { cause: error }\n )\n );\n }\n }));\n\n if (errors.length > 0) {\n errors.forEach(x => {\n runtime.eventBus.dispatch(RemoteModuleRegistrationFailedEvent, x);\n });\n }\n\n // Must be dispatched before updating the registration status to ensure bootstrapping events sequencing.\n runtime.eventBus.dispatch(RemoteModulesRegistrationCompletedEvent, {\n remoteCount: completedCount\n } satisfies RemoteModulesRegistrationCompletedEventPayload);\n\n this.#setRegistrationStatus(this.#deferredRegistrations.length > 0 ? \"modules-registered\" : \"ready\");\n\n // After introducting the \"setRegistrationStatus\" method, TypeScript seems to think that the only possible\n // values for registrationStatus is \"none\" and now complains about the lack of overlapping between \"none\" and \"ready\".\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (this.#registrationStatus === \"ready\") {\n this.#logSharedScope(runtime.logger);\n }\n } else {\n // There's no modules to register, it can be considered as ready.\n this.#setRegistrationStatus(\"ready\");\n }\n\n return errors;\n }\n\n async registerDeferredRegistrations<TRuntime extends Runtime = Runtime, TData = unknown>(runtime: TRuntime, data?: TData) {\n const errors: RemoteModuleRegistrationError[] = [];\n\n if (this.#registrationStatus === \"ready\" && this.#deferredRegistrations.length === 0) {\n // No deferred registrations were returned by the remote modules, skip this phase.\n return errors;\n }\n\n if (this.#registrationStatus === \"none\" || this.#registrationStatus === \"registering-modules\") {\n throw new Error(\"[squide] The registerDeferredRegistrations function can only be called once the remote modules are registered.\");\n }\n\n if (this.#registrationStatus !== \"modules-registered\") {\n throw new Error(\"[squide] The registerDeferredRegistrations function can only be called once.\");\n }\n\n this.#setRegistrationStatus(\"registering-deferred-registration\");\n\n runtime.eventBus.dispatch(RemoteModulesDeferredRegistrationStartedEvent, {\n registrationCount: this.#deferredRegistrations.length\n } satisfies RemoteModulesDeferredRegistrationStartedEventPayload);\n\n let completedCount = 0;\n\n await Promise.allSettled(this.#deferredRegistrations.map(async ({ remoteName, index, fct: deferredRegister }) => {\n const loggerScope = (runtime.logger as RootLogger).startScope(`[squide] ${index} Registering the deferred registrations for module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`);\n const runtimeScope = runtime.startScope(loggerScope);\n\n loggerScope\n .withText(\"Data:\")\n .withObject(data)\n .debug();\n\n try {\n await deferredRegister(runtimeScope, data, \"register\");\n\n completedCount += 1;\n } catch (error: unknown) {\n loggerScope\n .withText(\"[squide] An error occured while registering the deferred registrations.\")\n .withError(error as Error)\n .error();\n\n loggerScope.end({\n labelStyle: {\n color: \"red\"\n }\n });\n\n errors.push(\n new RemoteModuleRegistrationError(\n `An error occured while registering the deferred registrations for module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`,\n remoteName,\n RemoteRegisterModuleName,\n { cause: error }\n )\n );\n }\n\n loggerScope.information(\"[squide] Successfully registered deferred registrations.\", {\n style: {\n color: \"green\"\n }\n });\n\n loggerScope.end({\n labelStyle: {\n color: \"green\"\n }\n });\n }));\n\n if (errors.length > 0) {\n errors.forEach(x => {\n runtime.eventBus.dispatch(RemoteModuleDeferredRegistrationFailedEvent, x);\n });\n }\n\n // Must be dispatched before updating the registration status to ensure bootstrapping events sequencing.\n runtime.eventBus.dispatch(RemoteModulesDeferredRegistrationCompletedEvent, {\n registrationCount: completedCount\n } satisfies RemoteModulesDeferredRegistrationCompletedEventPayload);\n\n this.#setRegistrationStatus(\"ready\");\n this.#logSharedScope(runtime.logger);\n\n return errors;\n }\n\n async updateDeferredRegistrations<TRuntime extends Runtime = Runtime, TData = unknown>(runtime: TRuntime, data?: TData) {\n const errors: RemoteModuleRegistrationError[] = [];\n\n if (this.#registrationStatus !== \"ready\") {\n throw new Error(\"[squide] The updateDeferredRegistrations function can only be called once the remote modules are ready.\");\n }\n\n runtime.eventBus.dispatch(RemoteModulesDeferredRegistrationsUpdateStartedEvent, {\n registrationCount: this.#deferredRegistrations.length\n } satisfies RemoteModulesDeferredRegistrationsUpdateStartedEventPayload);\n\n let completedCount = 0;\n\n await Promise.allSettled(this.#deferredRegistrations.map(async ({ remoteName, index, fct: deferredRegister }) => {\n const loggerScope = (runtime.logger as RootLogger).startScope(`[squide] ${index} Updating the deferred registrations for module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`);\n const runtimeScope = runtime.startScope(loggerScope);\n\n loggerScope\n .withText(\"Data:\")\n .withObject(data)\n .debug();\n\n try {\n await deferredRegister(runtimeScope, data, \"update\");\n\n completedCount += 1;\n } catch (error: unknown) {\n loggerScope\n .withText(\"[squide] An error occured while updating the deferred registrations.\")\n .withError(error as Error)\n .error();\n\n loggerScope.end({\n labelStyle: {\n color: \"red\"\n }\n });\n\n errors.push(\n new RemoteModuleRegistrationError(\n `An error occured while updating the deferred registrations for module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`,\n remoteName,\n RemoteRegisterModuleName,\n { cause: error }\n )\n );\n }\n\n loggerScope.information(\"[squide] Successfully updated the deferred registrations.\", {\n style: {\n color: \"green\"\n }\n });\n\n loggerScope.end({\n labelStyle: {\n color: \"green\"\n }\n });\n }));\n\n if (errors.length > 0) {\n errors.forEach(x => {\n runtime.eventBus.dispatch(RemoteModuleDeferredRegistrationUpdateFailedEvent, x);\n });\n }\n\n runtime.eventBus.dispatch(RemoteModulesDeferredRegistrationsUpdateCompletedEvent, {\n registrationCount: completedCount\n } satisfies RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload);\n\n return errors;\n }\n\n registerStatusChangedListener(callback: ModuleRegistrationStatusChangedListener) {\n this.#statusChangedListeners.add(callback);\n }\n\n removeStatusChangedListener(callback: ModuleRegistrationStatusChangedListener) {\n this.#statusChangedListeners.delete(callback);\n }\n\n setAsReady() {\n if (this.#registrationStatus !== \"none\") {\n throw new Error(`[squide] Cannot set a module registry as \"ready\" when registrations are already in progress. The registry current status is \"${this.#registrationStatus}\".`);\n }\n\n this.#setRegistrationStatus(\"ready\");\n }\n\n #setRegistrationStatus(status: ModuleRegistrationStatus) {\n this.#registrationStatus = status;\n\n this.#statusChangedListeners.forEach(x => {\n x();\n });\n }\n\n get registrationStatus() {\n return this.#registrationStatus;\n }\n}\n\nexport function toRemoteModuleDefinitions(remotes: (RemoteDefinition | undefined)[]): ModuleDefinition[] {\n return remotes\n .filter((x): x is RemoteDefinition => Boolean(x))\n .map(x => ({\n definition: x,\n registryId: RemoteModuleRegistryId\n }));\n}\n"],"names":["ModuleRegistrationError","registerModule","isFunction","isNil","RemoteModuleRegistryId","RemoteModulesRegistrationStartedEvent","RemoteModulesRegistrationCompletedEvent","RemoteModuleRegistrationFailedEvent","RemoteModulesDeferredRegistrationStartedEvent","RemoteModulesDeferredRegistrationCompletedEvent","RemoteModuleDeferredRegistrationFailedEvent","RemoteModulesDeferredRegistrationsUpdateStartedEvent","RemoteModulesDeferredRegistrationsUpdateCompletedEvent","RemoteModuleDeferredRegistrationUpdateFailedEvent","RemoteRegisterModuleName","RemoteModuleRegistrationError","message","remoteName","moduleName","options","RemoteModuleRegistry","Set","loadRemote","logger","__webpack_share_scopes__","runtime","remotes","context","errors","Error","completedCount","Promise","x","index","loggerScope","runtimeScope","module","optionalDeferredRegistration","error","data","deferredRegister","callback","status","toRemoteModuleDefinitions","Boolean"],"mappings":";;;;;;AAAyQ;AAC/M;AAInD,MAAMI,sBAAsBA,GAAG,SAAS;AAExC,MAAMC,qCAAqCA,GAAG,6CAA6C;AAC3F,MAAMC,uCAAuCA,GAAG,+CAA+C;AAC/F,MAAMC,mCAAmCA,GAAG,2CAA2C;AAEvF,MAAMC,6CAA6CA,GAAG,sDAAsD;AAC5G,MAAMC,+CAA+CA,GAAG,wDAAwD;AAChH,MAAMC,2CAA2CA,GAAG,yDAAyD;AAE7G,MAAMC,oDAAoDA,GAAG,8DAA8D;AAC3H,MAAMC,sDAAsDA,GAAG,wEAAwE;AACvI,MAAMC,iDAAiDA,GAAG,2DAA2D;AA0B5H,MAAMC,wBAAwBA,GAAG;AAW1B,MAAMC,6BAA6BA,SAASf,uBAAuBA;IAC7D,WAAW,CAAS;IACpB,WAAW,CAAS;IAE7B,YAAYgB,OAAe,EAAEC,UAAkB,EAAEC,UAAkB,EAAEC,OAAsB,CAAE;QACzF,KAAK,CAACH,SAASG;QAEf,IAAI,CAAC,WAAW,GAAGF;QACnB,IAAI,CAAC,WAAW,GAAGC;IACvB;IAEA,IAAI,aAAa;QACb,OAAO,IAAI,CAAC,WAAW;IAC3B;IA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Ba,QAAiD,EAAE;QAC7E,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAACA;IACrC;IAEA,4BAA4BA,QAAiD,EAAE;QAC3E,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAACA;IACxC;IAEA,aAAa;QACT,IAAI,IAAI,CAAC,mBAAmB,KAAK,QAAQ;YACrC,MAAM,IAAIZ,MAAM,CAAC,6HAA6H,EAAE,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAChL;QAEA,IAAI,CAAC,sBAAsB,CAAC;IAChC;IAEA,sBAAsB,CAACa,MAAgC;QACnD,IAAI,CAAC,mBAAmB,GAAGA;QAE3B,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAACV,CAAAA;YACjCA;QACJ;IACJ;IAEA,IAAI,qBAAqB;QACrB,OAAO,IAAI,CAAC,mBAAmB;IACnC;AACJ;AAEO,SAASW,yBAAyBA,CAACjB,OAAyC;IAC/E,OAAOA,QACF,MAAM,CAAC,CAACM,IAA6BY,QAAQZ,IAC7C,GAAG,CAACA,CAAAA,IAAM;YACP,YAAYA;YACZ,YAAY5B,sBAAsBA;QACtC;AACR"}
|
|
1
|
+
{"version":3,"file":"RemoteModuleRegistry.js","sources":["../src/RemoteModuleRegistry.ts"],"sourcesContent":["import { ModuleDefinition, ModuleRegistrationError, registerModule, type DeferredRegistrationFunction, type ModuleRegistrationStatus, type ModuleRegistrationStatusChangedListener, type ModuleRegistry, type RegisterModulesOptions, type Runtime } from \"@squide/core\";\nimport { isFunction, isNil } from \"@squide/core/internal\";\nimport type { Logger, RootLogger } from \"@workleap/logging\";\nimport type { RemoteDefinition } from \"./RemoteDefinition.ts\";\n\nexport const RemoteModuleRegistryId = \"remote\";\n\nexport const RemoteModulesRegistrationStartedEvent = \"squide-remote-modules-registration-started\";\nexport const RemoteModulesRegistrationCompletedEvent = \"squide-remote-modules-registration-completed\";\nexport const RemoteModuleRegistrationFailedEvent = \"squide-remote-module-registration-failed\";\n\nexport const RemoteModulesDeferredRegistrationStartedEvent = \"squide-remote-modules-deferred-registration-started\";\nexport const RemoteModulesDeferredRegistrationCompletedEvent = \"squide-remote-modules-deferred-registration-completed\";\nexport const RemoteModuleDeferredRegistrationFailedEvent = \"squide-some-remote-module-deferred-registration-failed\";\n\nexport const RemoteModulesDeferredRegistrationsUpdateStartedEvent = \"squide-remote-modules-deferred-registrations-update-started\";\nexport const RemoteModulesDeferredRegistrationsUpdateCompletedEvent = \"squide-remote-modules-deferred-registrations-update-completed-started\";\nexport const RemoteModuleDeferredRegistrationUpdateFailedEvent = \"squide-remote-module-deferred-registration-update-failed\";\n\nexport interface RemoteModulesRegistrationStartedEventPayload {\n remoteCount: number;\n}\n\nexport interface RemoteModulesRegistrationCompletedEventPayload {\n remoteCount: number;\n}\n\nexport interface RemoteModulesDeferredRegistrationStartedEventPayload {\n registrationCount: number;\n}\n\nexport interface RemoteModulesDeferredRegistrationCompletedEventPayload {\n registrationCount: number;\n}\n\nexport interface RemoteModulesDeferredRegistrationsUpdateStartedEventPayload {\n registrationCount: number;\n}\n\nexport interface RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload {\n registrationCount: number;\n}\n\ndeclare module \"@squide/core\" {\n interface EventMap {\n \"squide-remote-modules-registration-started\": RemoteModulesRegistrationStartedEventPayload;\n \"squide-remote-modules-registration-completed\": RemoteModulesRegistrationCompletedEventPayload;\n \"squide-remote-module-registration-failed\": ModuleRegistrationError;\n \"squide-remote-modules-deferred-registration-started\": RemoteModulesDeferredRegistrationStartedEventPayload;\n \"squide-remote-modules-deferred-registration-completed\": RemoteModulesDeferredRegistrationCompletedEventPayload;\n \"squide-some-remote-module-deferred-registration-failed\": ModuleRegistrationError;\n \"squide-remote-modules-deferred-registrations-update-started\": RemoteModulesDeferredRegistrationsUpdateStartedEventPayload;\n \"squide-remote-modules-deferred-registrations-update-completed-started\": RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload;\n \"squide-remote-module-deferred-registration-update-failed\": ModuleRegistrationError;\n }\n}\n\nconst RemoteRegisterModuleName = \"register\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype LoadRemoteFunction = (remoteName: string, moduleName: string) => Promise<any>;\n\ninterface DeferredRegistration<TRuntime extends Runtime = Runtime, TData = unknown> {\n remoteName: string;\n index: string;\n fct: DeferredRegistrationFunction<TRuntime, TData>;\n}\n\nexport class RemoteModuleRegistrationError extends ModuleRegistrationError {\n readonly #remoteName: string;\n readonly #moduleName: string;\n\n constructor(message: string, remoteName: string, moduleName: string, options?: ErrorOptions) {\n super(message, options);\n\n this.#remoteName = remoteName;\n this.#moduleName = moduleName;\n }\n\n get remoteName() {\n return this.#remoteName;\n }\n\n get moduleName() {\n return this.#moduleName;\n }\n}\n\nexport class RemoteModuleRegistry implements ModuleRegistry {\n #registrationStatus: ModuleRegistrationStatus = \"none\";\n\n readonly #deferredRegistrations: DeferredRegistration[] = [];\n readonly #loadRemote: LoadRemoteFunction;\n readonly #statusChangedListeners = new Set<ModuleRegistrationStatusChangedListener>();\n\n constructor(loadRemote: LoadRemoteFunction) {\n this.#loadRemote = loadRemote;\n }\n\n get id() {\n return RemoteModuleRegistryId;\n }\n\n #logSharedScope(logger: Logger) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (__webpack_share_scopes__) {\n logger.debug(\n \"[squide] Module Federation shared scope is available:\",\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n __webpack_share_scopes__.default\n );\n }\n }\n\n async registerModules<TRuntime extends Runtime = Runtime, TContext = unknown, TData = unknown>(runtime: TRuntime, remotes: RemoteDefinition[], { context }: RegisterModulesOptions<TContext> = {}) {\n const errors: RemoteModuleRegistrationError[] = [];\n\n if (this.#registrationStatus !== \"none\") {\n throw new Error(\"[squide] The registerRemoteModules function can only be called once.\");\n }\n\n if (remotes.length > 0) {\n runtime.logger.information(`[squide] Found ${remotes.length} remote module${remotes.length !== 1 ? \"s\" : \"\"} to register.`);\n\n this.#setRegistrationStatus(\"registering-modules\");\n\n runtime.eventBus.dispatch(RemoteModulesRegistrationStartedEvent, {\n remoteCount: remotes.length\n } satisfies RemoteModulesRegistrationStartedEventPayload);\n\n let completedCount = 0;\n\n await Promise.allSettled(remotes.map(async (x, index) => {\n const remoteName = x.name;\n const loggerScope = (runtime.logger as RootLogger).startScope(`[squide] ${index + 1}/${remotes.length} Loading module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`);\n const runtimeScope = runtime.startScope(loggerScope);\n\n try {\n const module = await this.#loadRemote(remoteName, RemoteRegisterModuleName);\n\n if (isNil(module.register)) {\n throw new Error(`[squide] A \"register\" function is not available for module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\". Make sure your remote \"./register.[js,jsx,ts.tsx]\" file export a function named \"register\".`);\n }\n\n loggerScope.debug(\"[squide] Registering module...\");\n\n const optionalDeferredRegistration = await registerModule<TRuntime, TContext, TData>(module.register, runtimeScope as TRuntime, context);\n\n if (isFunction(optionalDeferredRegistration)) {\n this.#deferredRegistrations.push({\n remoteName: x.name,\n index: `${index + 1}/${remotes.length}`,\n fct: optionalDeferredRegistration as DeferredRegistrationFunction\n });\n }\n\n completedCount += 1;\n\n loggerScope.information(\"[squide] Successfully registered remote module.\", {\n style: {\n color: \"green\"\n }\n });\n\n loggerScope.end({\n labelStyle: {\n color: \"green\"\n }\n });\n } catch (error: unknown) {\n loggerScope\n .withText(\"[squide] An error occured while registering the remote module.\")\n .withError(error as Error)\n .error();\n\n loggerScope.end({\n labelStyle: {\n color: \"red\"\n }\n });\n\n errors.push(\n new RemoteModuleRegistrationError(\n `An error occured while registering module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`,\n remoteName,\n RemoteRegisterModuleName,\n { cause: error }\n )\n );\n }\n }));\n\n if (errors.length > 0) {\n errors.forEach(x => {\n runtime.eventBus.dispatch(RemoteModuleRegistrationFailedEvent, x);\n });\n }\n\n // Must be dispatched before updating the registration status to ensure bootstrapping events sequencing.\n runtime.eventBus.dispatch(RemoteModulesRegistrationCompletedEvent, {\n remoteCount: completedCount\n } satisfies RemoteModulesRegistrationCompletedEventPayload);\n\n this.#setRegistrationStatus(this.#deferredRegistrations.length > 0 ? \"modules-registered\" : \"ready\");\n\n // After introducting the \"setRegistrationStatus\" method, TypeScript seems to think that the only possible\n // values for registrationStatus is \"none\" and now complains about the lack of overlapping between \"none\" and \"ready\".\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (this.#registrationStatus === \"ready\") {\n this.#logSharedScope(runtime.logger);\n }\n } else {\n // There's no modules to register, it can be considered as ready.\n this.#setRegistrationStatus(\"ready\");\n }\n\n return errors;\n }\n\n async registerDeferredRegistrations<TRuntime extends Runtime = Runtime, TData = unknown>(runtime: TRuntime, data?: TData) {\n const errors: RemoteModuleRegistrationError[] = [];\n\n if (this.#registrationStatus === \"ready\" && this.#deferredRegistrations.length === 0) {\n // No deferred registrations were returned by the remote modules, skip this phase.\n return errors;\n }\n\n if (this.#registrationStatus === \"none\" || this.#registrationStatus === \"registering-modules\") {\n throw new Error(\"[squide] The registerDeferredRegistrations function can only be called once the remote modules are registered.\");\n }\n\n if (this.#registrationStatus !== \"modules-registered\") {\n throw new Error(\"[squide] The registerDeferredRegistrations function can only be called once.\");\n }\n\n this.#setRegistrationStatus(\"registering-deferred-registration\");\n\n runtime.eventBus.dispatch(RemoteModulesDeferredRegistrationStartedEvent, {\n registrationCount: this.#deferredRegistrations.length\n } satisfies RemoteModulesDeferredRegistrationStartedEventPayload);\n\n let completedCount = 0;\n\n await Promise.allSettled(this.#deferredRegistrations.map(async ({ remoteName, index, fct: deferredRegister }) => {\n const loggerScope = (runtime.logger as RootLogger).startScope(`[squide] ${index} Registering the deferred registrations for module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`);\n const runtimeScope = runtime.startScope(loggerScope);\n\n loggerScope\n .withText(\"Data:\")\n .withObject(data)\n .debug();\n\n try {\n await deferredRegister(runtimeScope, data, \"register\");\n\n completedCount += 1;\n } catch (error: unknown) {\n loggerScope\n .withText(\"[squide] An error occured while registering the deferred registrations.\")\n .withError(error as Error)\n .error();\n\n loggerScope.end({\n labelStyle: {\n color: \"red\"\n }\n });\n\n errors.push(\n new RemoteModuleRegistrationError(\n `An error occured while registering the deferred registrations for module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`,\n remoteName,\n RemoteRegisterModuleName,\n { cause: error }\n )\n );\n }\n\n loggerScope.information(\"[squide] Successfully registered deferred registrations.\", {\n style: {\n color: \"green\"\n }\n });\n\n loggerScope.end({\n labelStyle: {\n color: \"green\"\n }\n });\n }));\n\n if (errors.length > 0) {\n errors.forEach(x => {\n runtime.eventBus.dispatch(RemoteModuleDeferredRegistrationFailedEvent, x);\n });\n }\n\n // Must be dispatched before updating the registration status to ensure bootstrapping events sequencing.\n runtime.eventBus.dispatch(RemoteModulesDeferredRegistrationCompletedEvent, {\n registrationCount: completedCount\n } satisfies RemoteModulesDeferredRegistrationCompletedEventPayload);\n\n this.#setRegistrationStatus(\"ready\");\n this.#logSharedScope(runtime.logger);\n\n return errors;\n }\n\n async updateDeferredRegistrations<TRuntime extends Runtime = Runtime, TData = unknown>(runtime: TRuntime, data?: TData) {\n const errors: RemoteModuleRegistrationError[] = [];\n\n if (this.#registrationStatus !== \"ready\") {\n throw new Error(\"[squide] The updateDeferredRegistrations function can only be called once the remote modules are ready.\");\n }\n\n runtime.eventBus.dispatch(RemoteModulesDeferredRegistrationsUpdateStartedEvent, {\n registrationCount: this.#deferredRegistrations.length\n } satisfies RemoteModulesDeferredRegistrationsUpdateStartedEventPayload);\n\n let completedCount = 0;\n\n await Promise.allSettled(this.#deferredRegistrations.map(async ({ remoteName, index, fct: deferredRegister }) => {\n const loggerScope = (runtime.logger as RootLogger).startScope(`[squide] ${index} Updating the deferred registrations for module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`);\n const runtimeScope = runtime.startScope(loggerScope);\n\n loggerScope\n .withText(\"Data:\")\n .withObject(data)\n .debug();\n\n try {\n await deferredRegister(runtimeScope, data, \"update\");\n\n completedCount += 1;\n } catch (error: unknown) {\n loggerScope\n .withText(\"[squide] An error occured while updating the deferred registrations.\")\n .withError(error as Error)\n .error();\n\n loggerScope.end({\n labelStyle: {\n color: \"red\"\n }\n });\n\n errors.push(\n new RemoteModuleRegistrationError(\n `An error occured while updating the deferred registrations for module \"${RemoteRegisterModuleName}\" of remote \"${remoteName}\".`,\n remoteName,\n RemoteRegisterModuleName,\n { cause: error }\n )\n );\n }\n\n loggerScope.information(\"[squide] Successfully updated the deferred registrations.\", {\n style: {\n color: \"green\"\n }\n });\n\n loggerScope.end({\n labelStyle: {\n color: \"green\"\n }\n });\n }));\n\n if (errors.length > 0) {\n errors.forEach(x => {\n runtime.eventBus.dispatch(RemoteModuleDeferredRegistrationUpdateFailedEvent, x);\n });\n }\n\n runtime.eventBus.dispatch(RemoteModulesDeferredRegistrationsUpdateCompletedEvent, {\n registrationCount: completedCount\n } satisfies RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload);\n\n return errors;\n }\n\n registerStatusChangedListener(callback: ModuleRegistrationStatusChangedListener) {\n this.#statusChangedListeners.add(callback);\n }\n\n removeStatusChangedListener(callback: ModuleRegistrationStatusChangedListener) {\n this.#statusChangedListeners.delete(callback);\n }\n\n setAsReady() {\n if (this.#registrationStatus !== \"none\") {\n throw new Error(`[squide] Cannot set a module registry as \"ready\" when registrations are already in progress. The registry current status is \"${this.#registrationStatus}\".`);\n }\n\n this.#setRegistrationStatus(\"ready\");\n }\n\n #setRegistrationStatus(status: ModuleRegistrationStatus) {\n this.#registrationStatus = status;\n\n this.#statusChangedListeners.forEach(x => {\n x();\n });\n }\n\n get registrationStatus() {\n return this.#registrationStatus;\n }\n}\n\nexport function toRemoteModuleDefinitions(remotes: (RemoteDefinition | undefined)[]): ModuleDefinition[] {\n return remotes\n .filter((x): x is RemoteDefinition => Boolean(x))\n .map(x => ({\n definition: x,\n registryId: RemoteModuleRegistryId\n }));\n}\n"],"names":["ModuleRegistrationError","registerModule","isFunction","isNil","RemoteModuleRegistryId","RemoteModulesRegistrationStartedEvent","RemoteModulesRegistrationCompletedEvent","RemoteModuleRegistrationFailedEvent","RemoteModulesDeferredRegistrationStartedEvent","RemoteModulesDeferredRegistrationCompletedEvent","RemoteModuleDeferredRegistrationFailedEvent","RemoteModulesDeferredRegistrationsUpdateStartedEvent","RemoteModulesDeferredRegistrationsUpdateCompletedEvent","RemoteModuleDeferredRegistrationUpdateFailedEvent","RemoteRegisterModuleName","RemoteModuleRegistrationError","message","remoteName","moduleName","options","RemoteModuleRegistry","Set","loadRemote","logger","__webpack_share_scopes__","runtime","remotes","context","errors","Error","completedCount","Promise","x","index","loggerScope","runtimeScope","module","optionalDeferredRegistration","error","data","deferredRegister","callback","status","toRemoteModuleDefinitions","Boolean"],"mappings":";;;;;;AAAyQ;AAC/M;AAInD,MAAMI,sBAAsBA,GAAG,SAAS;AAExC,MAAMC,qCAAqCA,GAAG,6CAA6C;AAC3F,MAAMC,uCAAuCA,GAAG,+CAA+C;AAC/F,MAAMC,mCAAmCA,GAAG,2CAA2C;AAEvF,MAAMC,6CAA6CA,GAAG,sDAAsD;AAC5G,MAAMC,+CAA+CA,GAAG,wDAAwD;AAChH,MAAMC,2CAA2CA,GAAG,yDAAyD;AAE7G,MAAMC,oDAAoDA,GAAG,8DAA8D;AAC3H,MAAMC,sDAAsDA,GAAG,wEAAwE;AACvI,MAAMC,iDAAiDA,GAAG,2DAA2D;AAwC5H,MAAMC,wBAAwBA,GAAG;AAW1B,MAAMC,6BAA6BA,SAASf,uBAAuBA;IAC7D,WAAW,CAAS;IACpB,WAAW,CAAS;IAE7B,YAAYgB,OAAe,EAAEC,UAAkB,EAAEC,UAAkB,EAAEC,OAAsB,CAAE;QACzF,KAAK,CAACH,SAASG;QAEf,IAAI,CAAC,WAAW,GAAGF;QACnB,IAAI,CAAC,WAAW,GAAGC;IACvB;IAEA,IAAI,aAAa;QACb,OAAO,IAAI,CA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F;IACX;IAEA,8BAA8Ba,QAAiD,EAAE;QAC7E,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAACA;IACrC;IAEA,4BAA4BA,QAAiD,EAAE;QAC3E,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAACA;IACxC;IAEA,aAAa;QACT,IAAI,IAAI,CAAC,mBAAmB,KAAK,QAAQ;YACrC,MAAM,IAAIZ,MAAM,CAAC,6HAA6H,EAAE,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAChL;QAEA,IAAI,CAAC,sBAAsB,CAAC;IAChC;IAEA,sBAAsB,CAACa,MAAgC;QACnD,IAAI,CAAC,mBAAmB,GAAGA;QAE3B,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAACV,CAAAA;YACjCA;QACJ;IACJ;IAEA,IAAI,qBAAqB;QACrB,OAAO,IAAI,CAAC,mBAAmB;IACnC;AACJ;AAEO,SAASW,yBAAyBA,CAACjB,OAAyC;IAC/E,OAAOA,QACF,MAAM,CAAC,CAACM,IAA6BY,QAAQZ,IAC7C,GAAG,CAACA,CAAAA,IAAM;YACP,YAAYA;YACZ,YAAY5B,sBAAsBA;QACtC;AACR"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squide/firefly-module-federation",
|
|
3
3
|
"author": "Workleap",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"description": "Add support for Module Federation to Squide firefly.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@module-federation/enhanced": "0.11.4",
|
|
39
39
|
"@rspack/core": "^1.7.11",
|
|
40
40
|
"@workleap/logging": "^1.3.7",
|
|
41
|
-
"@squide/core": "^
|
|
42
|
-
"@squide/firefly": "^
|
|
41
|
+
"@squide/core": "^7.0.0",
|
|
42
|
+
"@squide/firefly": "^17.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@eslint/js": "9.39.2",
|
|
@@ -4,7 +4,7 @@ import { Plugin, RegisterModulesOptions, type Runtime } from "@squide/core";
|
|
|
4
4
|
import { FireflyPlugin, FireflyRuntime } from "@squide/firefly";
|
|
5
5
|
import { ActiveSpan, addProtectedListener, endActiveSpan, getTracer, HoneycombTrackingUnmanagedErrorHandler, startActiveChildSpan, startChildSpan, traceError, type GetSpanFunction } from "@squide/firefly/internal";
|
|
6
6
|
import { RemoteDefinition } from "./RemoteDefinition.ts";
|
|
7
|
-
import { RemoteModuleDeferredRegistrationFailedEvent, RemoteModuleDeferredRegistrationUpdateFailedEvent,
|
|
7
|
+
import { RemoteModuleDeferredRegistrationFailedEvent, RemoteModuleDeferredRegistrationUpdateFailedEvent, RemoteModuleRegistrationFailedEvent, RemoteModuleRegistry, RemoteModuleRegistryId, RemoteModulesDeferredRegistrationCompletedEvent, RemoteModulesDeferredRegistrationStartedEvent, RemoteModulesDeferredRegistrationsUpdateCompletedEvent, RemoteModulesDeferredRegistrationsUpdateStartedEvent, RemoteModulesRegistrationCompletedEvent, RemoteModulesRegistrationStartedEvent } from "./RemoteModuleRegistry.ts";
|
|
8
8
|
|
|
9
9
|
export const ModuleFederationPluginName = "module-federation-plugin";
|
|
10
10
|
|
|
@@ -47,11 +47,11 @@ export class ModuleFederationPlugin extends Plugin<FireflyRuntime> implements Fi
|
|
|
47
47
|
onUnmanagedError(error);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
addProtectedListener(this._runtime, RemoteModulesRegistrationStartedEvent,
|
|
50
|
+
addProtectedListener(this._runtime, RemoteModulesRegistrationStartedEvent, payload => {
|
|
51
51
|
const bootstrappingSpan = getBootstrappingSpan();
|
|
52
52
|
|
|
53
53
|
const attributes = {
|
|
54
|
-
"app.squide.remote_count":
|
|
54
|
+
"app.squide.remote_count": payload?.remoteCount
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
if (bootstrappingSpan) {
|
|
@@ -66,12 +66,12 @@ export class ModuleFederationPlugin extends Plugin<FireflyRuntime> implements Fi
|
|
|
66
66
|
onError: handleUnmanagedError
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
addProtectedListener(this._runtime, RemoteModulesRegistrationCompletedEvent,
|
|
69
|
+
addProtectedListener(this._runtime, RemoteModulesRegistrationCompletedEvent, payload => {
|
|
70
70
|
const bootstrappingSpan = getBootstrappingSpan();
|
|
71
71
|
|
|
72
72
|
if (bootstrappingSpan) {
|
|
73
73
|
bootstrappingSpan.addEvent("remote-module-registration-completed", {
|
|
74
|
-
"app.squide.remote_count":
|
|
74
|
+
"app.squide.remote_count": payload?.remoteCount
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -84,21 +84,19 @@ export class ModuleFederationPlugin extends Plugin<FireflyRuntime> implements Fi
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
// Can occur multiple times.
|
|
87
|
-
addProtectedListener(this._runtime, RemoteModuleRegistrationFailedEvent,
|
|
88
|
-
const registrationError = payload as RemoteModuleRegistrationError;
|
|
89
|
-
|
|
87
|
+
addProtectedListener(this._runtime, RemoteModuleRegistrationFailedEvent, payload => {
|
|
90
88
|
if (remoteModuleRegistrationSpan) {
|
|
91
|
-
traceError(remoteModuleRegistrationSpan,
|
|
89
|
+
traceError(remoteModuleRegistrationSpan, payload as Error);
|
|
92
90
|
}
|
|
93
91
|
}, {
|
|
94
92
|
onError: handleUnmanagedError
|
|
95
93
|
});
|
|
96
94
|
|
|
97
|
-
addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationStartedEvent,
|
|
95
|
+
addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationStartedEvent, payload => {
|
|
98
96
|
const bootstrappingSpan = getBootstrappingSpan();
|
|
99
97
|
|
|
100
98
|
const attributes = {
|
|
101
|
-
"app.squide.registration_count":
|
|
99
|
+
"app.squide.registration_count": payload?.registrationCount
|
|
102
100
|
};
|
|
103
101
|
|
|
104
102
|
if (bootstrappingSpan) {
|
|
@@ -113,12 +111,12 @@ export class ModuleFederationPlugin extends Plugin<FireflyRuntime> implements Fi
|
|
|
113
111
|
onError: handleUnmanagedError
|
|
114
112
|
});
|
|
115
113
|
|
|
116
|
-
addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationCompletedEvent,
|
|
114
|
+
addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationCompletedEvent, payload => {
|
|
117
115
|
const bootstrappingSpan = getBootstrappingSpan();
|
|
118
116
|
|
|
119
117
|
if (bootstrappingSpan) {
|
|
120
118
|
bootstrappingSpan.addEvent("remote-module-deferred-registration-completed", {
|
|
121
|
-
"app.squide.registration_count":
|
|
119
|
+
"app.squide.registration_count": payload?.registrationCount
|
|
122
120
|
});
|
|
123
121
|
}
|
|
124
122
|
|
|
@@ -131,22 +129,20 @@ export class ModuleFederationPlugin extends Plugin<FireflyRuntime> implements Fi
|
|
|
131
129
|
});
|
|
132
130
|
|
|
133
131
|
// Can occur multiple times.
|
|
134
|
-
addProtectedListener(this._runtime, RemoteModuleDeferredRegistrationFailedEvent,
|
|
135
|
-
const registrationError = payload as RemoteModuleRegistrationError;
|
|
136
|
-
|
|
132
|
+
addProtectedListener(this._runtime, RemoteModuleDeferredRegistrationFailedEvent, payload => {
|
|
137
133
|
if (remoteModuleDeferredRegistrationSpan) {
|
|
138
|
-
traceError(remoteModuleDeferredRegistrationSpan,
|
|
134
|
+
traceError(remoteModuleDeferredRegistrationSpan, payload as Error);
|
|
139
135
|
}
|
|
140
136
|
}, {
|
|
141
137
|
onError: handleUnmanagedError
|
|
142
138
|
});
|
|
143
139
|
|
|
144
140
|
// Can occur multiple times.
|
|
145
|
-
addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationsUpdateStartedEvent,
|
|
141
|
+
addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationsUpdateStartedEvent, payload => {
|
|
146
142
|
const deferredRegistrationsUpdateSpan = getDeferredRegistrationsUpdateSpan();
|
|
147
143
|
|
|
148
144
|
const attributes = {
|
|
149
|
-
"app.squide.registration_count":
|
|
145
|
+
"app.squide.registration_count": payload?.registrationCount
|
|
150
146
|
};
|
|
151
147
|
|
|
152
148
|
if (deferredRegistrationsUpdateSpan) {
|
|
@@ -171,12 +167,12 @@ export class ModuleFederationPlugin extends Plugin<FireflyRuntime> implements Fi
|
|
|
171
167
|
});
|
|
172
168
|
|
|
173
169
|
// Can occur multiple times.
|
|
174
|
-
addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationsUpdateCompletedEvent,
|
|
170
|
+
addProtectedListener(this._runtime, RemoteModulesDeferredRegistrationsUpdateCompletedEvent, payload => {
|
|
175
171
|
const deferredRegistrationsUpdateSpan = getDeferredRegistrationsUpdateSpan();
|
|
176
172
|
|
|
177
173
|
if (deferredRegistrationsUpdateSpan) {
|
|
178
174
|
deferredRegistrationsUpdateSpan.addEvent("remote-module-deferred-registrations-update-completed", {
|
|
179
|
-
"app.squide.registration_count":
|
|
175
|
+
"app.squide.registration_count": payload?.registrationCount
|
|
180
176
|
});
|
|
181
177
|
}
|
|
182
178
|
|
|
@@ -188,11 +184,9 @@ export class ModuleFederationPlugin extends Plugin<FireflyRuntime> implements Fi
|
|
|
188
184
|
});
|
|
189
185
|
|
|
190
186
|
// Can occur multiple times.
|
|
191
|
-
addProtectedListener(this._runtime, RemoteModuleDeferredRegistrationUpdateFailedEvent,
|
|
192
|
-
const registrationError = payload as RemoteModuleRegistrationError;
|
|
193
|
-
|
|
187
|
+
addProtectedListener(this._runtime, RemoteModuleDeferredRegistrationUpdateFailedEvent, payload => {
|
|
194
188
|
if (remoteModuleDeferredRegistrationsUpdateSpan) {
|
|
195
|
-
traceError(remoteModuleDeferredRegistrationsUpdateSpan.instance,
|
|
189
|
+
traceError(remoteModuleDeferredRegistrationsUpdateSpan.instance, payload as Error);
|
|
196
190
|
}
|
|
197
191
|
}, {
|
|
198
192
|
onError: handleUnmanagedError
|
|
@@ -41,6 +41,20 @@ export interface RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload {
|
|
|
41
41
|
registrationCount: number;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
declare module "@squide/core" {
|
|
45
|
+
interface EventMap {
|
|
46
|
+
"squide-remote-modules-registration-started": RemoteModulesRegistrationStartedEventPayload;
|
|
47
|
+
"squide-remote-modules-registration-completed": RemoteModulesRegistrationCompletedEventPayload;
|
|
48
|
+
"squide-remote-module-registration-failed": ModuleRegistrationError;
|
|
49
|
+
"squide-remote-modules-deferred-registration-started": RemoteModulesDeferredRegistrationStartedEventPayload;
|
|
50
|
+
"squide-remote-modules-deferred-registration-completed": RemoteModulesDeferredRegistrationCompletedEventPayload;
|
|
51
|
+
"squide-some-remote-module-deferred-registration-failed": ModuleRegistrationError;
|
|
52
|
+
"squide-remote-modules-deferred-registrations-update-started": RemoteModulesDeferredRegistrationsUpdateStartedEventPayload;
|
|
53
|
+
"squide-remote-modules-deferred-registrations-update-completed-started": RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload;
|
|
54
|
+
"squide-remote-module-deferred-registration-update-failed": ModuleRegistrationError;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
44
58
|
const RemoteRegisterModuleName = "register";
|
|
45
59
|
|
|
46
60
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|