@granite-js/micro-frontend 2.1.1 → 2.3.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 +20 -0
- package/README.md +35 -0
- package/dist/module/createMicroFrontendRuntime.js +1 -0
- package/dist/module/createMicroFrontendRuntime.js.map +1 -1
- package/dist/module/index.js +1 -0
- package/dist/module/index.js.map +1 -1
- package/dist/module/plugin/prelude.js +4 -1
- package/dist/module/plugin/prelude.js.map +1 -1
- package/dist/module/runtime/containerRegistry.js +8 -2
- package/dist/module/runtime/containerRegistry.js.map +1 -1
- package/dist/module/runtime/createMicroFrontendRuntime.js +4 -1
- package/dist/module/runtime/createMicroFrontendRuntime.js.map +1 -1
- package/dist/module/runtime/getAppName.js +37 -0
- package/dist/module/runtime/getAppName.js.map +1 -0
- package/dist/module/runtime/lifecycle.js +22 -0
- package/dist/module/runtime/lifecycle.js.map +1 -0
- package/dist/module/runtime/registry.js.map +1 -1
- package/dist/module/runtime/runtimeSourceURL.js +46 -0
- package/dist/module/runtime/runtimeSourceURL.js.map +1 -0
- package/dist/module/session/useMicroFrontendSessions.js +35 -6
- package/dist/module/session/useMicroFrontendSessions.js.map +1 -1
- package/dist/typescript/createMicroFrontendRuntime.d.ts +2 -1
- package/dist/typescript/index.d.ts +3 -2
- package/dist/typescript/runtime/createMicroFrontendRuntime.d.ts +2 -1
- package/dist/typescript/runtime/getAppName.d.ts +6 -0
- package/dist/typescript/runtime/lifecycle.d.ts +3 -0
- package/dist/typescript/runtime/registry.d.ts +4 -0
- package/dist/typescript/runtime/runtimeSourceURL.d.ts +5 -0
- package/dist/typescript/types.d.ts +11 -0
- package/package.json +4 -4
- package/src/createMicroFrontendRuntime.ts +3 -1
- package/src/index.ts +10 -1
- package/src/plugin/prelude.ts +6 -1
- package/src/runtime/containerRegistry.ts +11 -2
- package/src/runtime/createMicroFrontendRuntime.ts +8 -1
- package/src/runtime/getAppName.ts +46 -0
- package/src/runtime/lifecycle.ts +28 -0
- package/src/runtime/registry.ts +5 -0
- package/src/runtime/runtimeSourceURL.ts +48 -0
- package/src/session/useMicroFrontendSessions.ts +61 -9
- package/src/types.ts +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @granite-js/micro-frontend
|
|
2
2
|
|
|
3
|
+
## 2.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6a8eae2: Expose each evaluated app container's source URL through `AppContainer.runtime.sourceURL`, resolve the current container with `getAppName()`, and exact-match externally captured source URLs with `findAppNameBySourceURL()`.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- @granite-js/utils@2.3.0
|
|
12
|
+
|
|
13
|
+
## 2.2.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- 2513bd8: Allow hosts to observe committed micro-frontend session mount and unmount transitions through an `onLifecycleEvent` runtime option with session metadata and an active-session snapshot.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- @granite-js/utils@2.2.0
|
|
22
|
+
|
|
3
23
|
## 2.1.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -131,6 +131,15 @@ The durable owner is `global.__MICRO_FRONTEND__` with exactly this shape:
|
|
|
131
131
|
- A current container registration creates paired legacy/current views for the
|
|
132
132
|
same app name. The pair is transparent across separately evaluated bundles:
|
|
133
133
|
it is one remote-owned registration, not two independently owned copies.
|
|
134
|
+
- A current container exposes the evaluated bundle source through
|
|
135
|
+
`runtime.sourceURL`. The generated prelude captures it from the bundle's
|
|
136
|
+
evaluation stack once when registering the container. Legacy container
|
|
137
|
+
adapters omit `runtime` until a compatible bundle is evaluated.
|
|
138
|
+
- `getAppName()` resolves the current bundle's structured source URL against
|
|
139
|
+
the container registry. A host call returns the host container name, while a
|
|
140
|
+
remote call returns that remote's name without reading a last-evaluated
|
|
141
|
+
global value. `findAppNameBySourceURL(sourceURL)` exposes the same exact
|
|
142
|
+
registry lookup for runtimes that already provide a structured source URL.
|
|
134
143
|
- The dispose callback registry and registrar live on the same canonical
|
|
135
144
|
context as non-enumerable properties. They are reused across separately
|
|
136
145
|
evaluated bundles without changing the three-key enumerable registry shape.
|
|
@@ -172,6 +181,9 @@ const runtime = createMicroFrontendRuntime({
|
|
|
172
181
|
return { filePath };
|
|
173
182
|
},
|
|
174
183
|
},
|
|
184
|
+
onLifecycleEvent(event) {
|
|
185
|
+
reportMicroFrontendLifecycle(event);
|
|
186
|
+
},
|
|
175
187
|
});
|
|
176
188
|
|
|
177
189
|
await runtime.preloadApp('cart');
|
|
@@ -211,6 +223,29 @@ The public runtime API is:
|
|
|
211
223
|
| `evaluateScript(filePath)` | Evaluate an already-local bundle in the retained runtime. |
|
|
212
224
|
| `onEvent(listener)` | Subscribe to native open, close, and visibility events. |
|
|
213
225
|
|
|
226
|
+
The host can provide `onLifecycleEvent` when creating the runtime for logging
|
|
227
|
+
and other observability integrations. Each event contains `session.id`,
|
|
228
|
+
`session.appName`, and the `activeSessions` snapshot when the callback is
|
|
229
|
+
emitted. The callback has the same lifetime as the runtime.
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
const runtime = createMicroFrontendRuntime({
|
|
233
|
+
adapter,
|
|
234
|
+
onLifecycleEvent(event) {
|
|
235
|
+
reportMicroFrontendLifecycle({
|
|
236
|
+
...event,
|
|
237
|
+
activeSessionCount: event.activeSessions.length,
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`mounted` is emitted after the session is committed to React state. `unmounted`
|
|
244
|
+
is emitted after the session is removed. When the session was the app's last
|
|
245
|
+
active session, Granite waits for the app's registered dispose callbacks before
|
|
246
|
+
emitting `unmounted`. Callback failures are reported without interrupting the
|
|
247
|
+
session lifecycle.
|
|
248
|
+
|
|
214
249
|
Remote code can register an idempotent callback for explicit app-level resource
|
|
215
250
|
cleanup:
|
|
216
251
|
|
|
@@ -9,6 +9,7 @@ export function createMicroFrontendRuntime(options) {
|
|
|
9
9
|
return createMicroFrontendRuntimeWithDependencies({
|
|
10
10
|
adapter: options.adapter,
|
|
11
11
|
nativeRuntime: NativeGraniteMicroFrontendRuntime,
|
|
12
|
+
onLifecycleEvent: options.onLifecycleEvent,
|
|
12
13
|
onPreloadError: options.onPreloadError ?? (() => undefined),
|
|
13
14
|
parseEvent: parseNativeRuntimeEvent,
|
|
14
15
|
registry: microFrontendModuleRegistry,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["removePendingHostComponentRoutes","createMicroFrontendRuntimeWithDependencies","parseNativeRuntimeEvent","microFrontendModuleRegistry","NativeGraniteMicroFrontendRuntime","createMicroFrontendRuntime","options","adapter","nativeRuntime","onPreloadError","undefined","parseEvent","registry"],"sourceRoot":"../../src","sources":["createMicroFrontendRuntime.ts"],"mappings":";;AAAA,SAASA,gCAAgC,QAAQ,qCAAkC;AACnF,SAASC,0CAA0C,QAAQ,yCAAsC;AACjG,SAASC,uBAAuB,QAAQ,sCAAmC;AAC3E,SAASC,2BAA2B,QAAQ,uBAAoB;AAChE,OAAOC,iCAAiC,MAAM,8CAA2C;
|
|
1
|
+
{"version":3,"names":["removePendingHostComponentRoutes","createMicroFrontendRuntimeWithDependencies","parseNativeRuntimeEvent","microFrontendModuleRegistry","NativeGraniteMicroFrontendRuntime","createMicroFrontendRuntime","options","adapter","nativeRuntime","onLifecycleEvent","onPreloadError","undefined","parseEvent","registry"],"sourceRoot":"../../src","sources":["createMicroFrontendRuntime.ts"],"mappings":";;AAAA,SAASA,gCAAgC,QAAQ,qCAAkC;AACnF,SAASC,0CAA0C,QAAQ,yCAAsC;AACjG,SAASC,uBAAuB,QAAQ,sCAAmC;AAC3E,SAASC,2BAA2B,QAAQ,uBAAoB;AAChE,OAAOC,iCAAiC,MAAM,8CAA2C;AASzF,OAAO,SAASC,0BAA0BA,CAACC,OAA0C,EAA2B;EAC9G,OAAOL,0CAA0C,CAAC;IAChDM,OAAO,EAAED,OAAO,CAACC,OAAO;IACxBC,aAAa,EAAEJ,iCAAiC;IAChDK,gBAAgB,EAAEH,OAAO,CAACG,gBAAgB;IAC1CC,cAAc,EAAEJ,OAAO,CAACI,cAAc,KAAK,MAAMC,SAAS,CAAC;IAC3DC,UAAU,EAAEV,uBAAuB;IACnCW,QAAQ,EAAEV,2BAA2B;IACrCH;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
|
package/dist/module/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
export { createMicroFrontendRuntime } from "./createMicroFrontendRuntime.js";
|
|
4
4
|
export { createRoute } from "./createRoute.js";
|
|
5
|
+
export { findAppNameBySourceURL, getAppName } from "./runtime/getAppName.js";
|
|
5
6
|
export { PendingHostComponent, usePendingHostComponentController, useIsPendingHostComponentHidden, useResolvedPendingHostComponent } from "./host/PendingHostComponent.js";
|
|
6
7
|
export { createPendingHostComponentRoutePrefix, normalizeRoutePath } from "./host/routeMatcher.js";
|
|
7
8
|
export { hidePendingHostComponent, installPendingHostComponentBridge, registerPendingHostComponentRoute, resetPendingHostComponent, resolvePendingHostComponent } from "./host/pendingHostComponentStore.js";
|
package/dist/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createMicroFrontendRuntime","createRoute","PendingHostComponent","usePendingHostComponentController","useIsPendingHostComponentHidden","useResolvedPendingHostComponent","createPendingHostComponentRoutePrefix","normalizeRoutePath","hidePendingHostComponent","installPendingHostComponentBridge","registerPendingHostComponentRoute","resetPendingHostComponent","resolvePendingHostComponent","MicroFrontendSessionProvider","MissingMicroFrontendSessionError","useMicroFrontendSession","useMicroFrontendSessions","default","Portal","AppContainerNotFoundError","ExposedModuleNotFoundError","InvalidAppNameError","InvalidAppRequestError","InvalidNativeRuntimeEventError"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,0BAA0B,QAAQ,iCAA8B;AAEzE,SAASC,WAAW,QAAQ,kBAAe;
|
|
1
|
+
{"version":3,"names":["createMicroFrontendRuntime","createRoute","findAppNameBySourceURL","getAppName","PendingHostComponent","usePendingHostComponentController","useIsPendingHostComponentHidden","useResolvedPendingHostComponent","createPendingHostComponentRoutePrefix","normalizeRoutePath","hidePendingHostComponent","installPendingHostComponentBridge","registerPendingHostComponentRoute","resetPendingHostComponent","resolvePendingHostComponent","MicroFrontendSessionProvider","MissingMicroFrontendSessionError","useMicroFrontendSession","useMicroFrontendSessions","default","Portal","AppContainerNotFoundError","ExposedModuleNotFoundError","InvalidAppNameError","InvalidAppRequestError","InvalidNativeRuntimeEventError"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,0BAA0B,QAAQ,iCAA8B;AAEzE,SAASC,WAAW,QAAQ,kBAAe;AAE3C,SAASC,sBAAsB,EAAEC,UAAU,QAAQ,yBAAsB;AAEzE,SACEC,oBAAoB,EACpBC,iCAAiC,EACjCC,+BAA+B,EAC/BC,+BAA+B,QAC1B,gCAA6B;AASpC,SACEC,qCAAqC,EACrCC,kBAAkB,QACb,wBAAqB;AAC5B,SACEC,wBAAwB,EACxBC,iCAAiC,EACjCC,iCAAiC,EACjCC,yBAAyB,EACzBC,2BAA2B,QACtB,qCAAkC;AACzC,SACEC,4BAA4B,EAC5BC,gCAAgC,EAChCC,uBAAuB,QAClB,0CAAuC;AAE9C,SAASC,wBAAwB,QAAQ,uCAAoC;AAQ7E,SAASC,OAAO,IAAIC,MAAM,QAAQ,mCAAmC;AAerE,SACEC,yBAAyB,EACzBC,0BAA0B,EAC1BC,mBAAmB,EACnBC,sBAAsB,EACtBC,8BAA8B,QACzB,qBAAkB","ignoreList":[]}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { globalContextScript } from "./globalContextScript.js";
|
|
5
5
|
import { CONTAINER_PAIRING_KEY } from "../runtime/containerPairing.js";
|
|
6
|
+
import { captureStackFrames, resolveCurrentSourceURL } from "../runtime/runtimeSourceURL.js";
|
|
6
7
|
export function getPreludeConfig(options, appName) {
|
|
7
8
|
const eagerSharedModules = Object.entries(options.shared ?? {}).filter(([, config]) => !Array.isArray(options.shared) && config.eager === true);
|
|
8
9
|
const registerStatements = eagerSharedModules.map(([moduleName], index) => {
|
|
@@ -17,9 +18,11 @@ export function getPreludeConfig(options, appName) {
|
|
|
17
18
|
shared: options.shared
|
|
18
19
|
});
|
|
19
20
|
const containerName = appName == null ? 'global.__granite.app.name' : JSON.stringify(appName);
|
|
21
|
+
const captureFrames = captureStackFrames.toString();
|
|
22
|
+
const resolveSourceURL = resolveCurrentSourceURL.toString();
|
|
20
23
|
return {
|
|
21
24
|
banner: [globalContextScript, '(function installMicroFrontendLifecycle(context) {', ' const callbacksDescriptor = Object.getOwnPropertyDescriptor(context, "disposeCallbacksByApp");', ' const disposeDescriptor = Object.getOwnPropertyDescriptor(context, "dispose");', ' const disposeCallbacksByApp = callbacksDescriptor == null ? {} : callbacksDescriptor.value;', ' if (typeof disposeCallbacksByApp !== "object" || disposeCallbacksByApp == null || Array.isArray(disposeCallbacksByApp)) {', ' throw new Error("Cannot install micro-frontend lifecycle: invalid-dispose-callback-registry");', ' }', ' const dispose = disposeDescriptor == null ? function dispose(appName, callback) {', ' if (typeof appName !== "string" || typeof callback !== "function") {', ' throw new Error("dispose() must be compiled with the microFrontend plugin");', ' }', ' const callbacks = disposeCallbacksByApp[appName] ||= new Set();', ' callbacks.add(callback);', ' let isRegistered = true;', ' return function unregisterDispose() {', ' if (!isRegistered) { return; }', ' isRegistered = false;', ' callbacks.delete(callback);', ' };', ' } : disposeDescriptor.value;', ' if (typeof dispose !== "function") {', ' throw new Error("Cannot install micro-frontend lifecycle: invalid-dispose-registrar");', ' }', ' try {', ' if (!Reflect.defineProperty(context, "disposeCallbacksByApp", {', ' configurable: true, enumerable: false, value: disposeCallbacksByApp, writable: true,', ' }) || !Reflect.defineProperty(context, "dispose", {', ' configurable: true, enumerable: false, value: dispose, writable: true,', ' })) {', ' throw new Error("Cannot install micro-frontend lifecycle: canonical-context-is-locked");', ' }', ' } catch (error) {', ' if (callbacksDescriptor == null) {', ' Reflect.deleteProperty(context, "disposeCallbacksByApp");', ' } else {', ' Reflect.defineProperty(context, "disposeCallbacksByApp", callbacksDescriptor);', ' }', ' if (disposeDescriptor == null) {', ' Reflect.deleteProperty(context, "dispose");', ' } else {', ' Reflect.defineProperty(context, "dispose", disposeDescriptor);', ' }', ' throw error;', ' }', '})(global.__MICRO_FRONTEND__);'].join('\n'),
|
|
22
|
-
preludeScript: [`const __containerPairSymbol = Symbol.for(${JSON.stringify(CONTAINER_PAIRING_KEY)});`, 'const __legacyContainers = new WeakMap();', 'function createContainer(appName, config) {', ' const context = global.__MICRO_FRONTEND__;', ' const containers = context.__CONTAINERS__;', ' const instances = context.__INSTANCES__;', ' if (containers[appName] != null || typeof instances[appName] === "number") {', " throw new Error(`App container '${appName}' is already registered`);", ' }', ' if (!Object.isExtensible(containers) || !Object.isExtensible(instances)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' const modernContainer = { appName, config, exposedModules: {} };', ' const legacyContainer = { name: appName, config, exposeMap: {} };', ' try {', ' if (!Reflect.defineProperty(instances, appName, {', ' configurable: true, enumerable: false, value: instances.length, writable: false,', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' instances.push(legacyContainer);', ' if (!Reflect.set(containers, appName, modernContainer)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' if (!Reflect.defineProperty(modernContainer, __containerPairSymbol, {', ' configurable: true, enumerable: false, value: legacyContainer, writable: false,', ' }) || !Reflect.defineProperty(legacyContainer, __containerPairSymbol, {', ' configurable: true, enumerable: false, value: modernContainer, writable: false,', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' } catch (error) {', ' if (Object.is(instances[instances.length - 1], legacyContainer)) {', ' instances.pop();', ' }', ' Reflect.deleteProperty(instances, appName);', ' Reflect.deleteProperty(containers, appName);', ' Reflect.deleteProperty(modernContainer, __containerPairSymbol);', ' Reflect.deleteProperty(legacyContainer, __containerPairSymbol);', ' throw error;', ' }', ' __legacyContainers.set(modernContainer, legacyContainer);', ' return modernContainer;', '}', 'function exposeModule(container, exposedModule, moduleValue) {', " const normalizedModule = exposedModule.startsWith('./') ? exposedModule : `./${exposedModule}`;", " const legacyModule = exposedModule.startsWith('./') ? exposedModule.slice(2) : exposedModule;", ' const legacyContainer = __legacyContainers.get(container);', ' if (Reflect.has(container.exposedModules, normalizedModule) ||', ' (legacyContainer != null && Reflect.has(legacyContainer.exposeMap, legacyModule))) {', " throw new Error(`Exposed module '${normalizedModule}' is already registered in app container '${container.appName}'`);", ' }', ' const ownsModernContainer = Object.is(', ' global.__MICRO_FRONTEND__.__CONTAINERS__[container.appName],', ' container', ' );', ' let legacyModuleValue = moduleValue;', ' if (legacyContainer != null &&', ' ((typeof moduleValue === "object" && moduleValue != null) || typeof moduleValue === "function") &&', ' moduleValue.__esModule !== true) {', ' legacyModuleValue = typeof moduleValue === "function"', ' ? function (...args) { return Reflect.apply(moduleValue, this, args); }', ' : {};', ' for (const exportName of Reflect.ownKeys(moduleValue)) {', ' if (exportName === "__esModule" || exportName === "default") {', ' continue;', ' }', ' const sourceDescriptor = Reflect.getOwnPropertyDescriptor(moduleValue, exportName);', ' const facadeDescriptor = Reflect.getOwnPropertyDescriptor(legacyModuleValue, exportName);', ' if (sourceDescriptor == null || (facadeDescriptor != null && facadeDescriptor.configurable === false)) {', ' // Callable facades keep intrinsic non-configurable slots such as prototype.', ' continue;', ' }', ' if (!Reflect.defineProperty(legacyModuleValue, exportName, {', ' enumerable: sourceDescriptor.enumerable,', ' get: function () { return Reflect.get(moduleValue, exportName); },', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' }', ' const hasDefaultExport = Reflect.getOwnPropertyDescriptor(moduleValue, "default") != null;', ' Object.defineProperties(legacyModuleValue, {', ' __esModule: { value: true },', ' default: {', ' enumerable: true,', ' get: hasDefaultExport', ' ? function () { return Reflect.get(moduleValue, "default"); }', ' : function () { return moduleValue; },', ' },', ' });', ' }', ' try {', ' if (ownsModernContainer && !Reflect.set(container.exposedModules, normalizedModule, moduleValue)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' if (legacyContainer != null) {', ' Object.defineProperty(legacyContainer.exposeMap, legacyModule, {', ' configurable: true,', ' enumerable: true,', ' get: function () { return legacyModuleValue; },', ' });', ' }', ' } catch (error) {', ' if (ownsModernContainer) {', ' Reflect.deleteProperty(container.exposedModules, normalizedModule);', ' }', ' if (legacyContainer != null) {', ' Reflect.deleteProperty(legacyContainer.exposeMap, legacyModule);', ' }', ' throw error;', ' }', '}', 'function registerShared(moduleName, moduleValue) {', ' const sharedModules = global.__MICRO_FRONTEND__.__SHARED__;', ' const existingModule = sharedModules[moduleName];', ' if (existingModule != null) {', ' if (typeof existingModule === "object" &&', ' typeof existingModule.get === "function" &&', ' typeof existingModule.loaded === "boolean" &&', ' Object.is(existingModule.get(), moduleValue)) {', ' return;', ' }', " throw new Error(`Shared module '${moduleName}' is already registered`);", ' }', ' sharedModules[moduleName] = { get: () => moduleValue, loaded: true };', '}', `const __container = createContainer(${containerName}, ${containerConfig});`, ...registerStatements, ...exposeStatements].join('\n')
|
|
25
|
+
preludeScript: [`const __containerPairSymbol = Symbol.for(${JSON.stringify(CONTAINER_PAIRING_KEY)});`, 'const __legacyContainers = new WeakMap();', 'function createContainer(appName, config) {', ' const context = global.__MICRO_FRONTEND__;', ' const containers = context.__CONTAINERS__;', ' const instances = context.__INSTANCES__;', ' if (containers[appName] != null || typeof instances[appName] === "number") {', " throw new Error(`App container '${appName}' is already registered`);", ' }', ' if (!Object.isExtensible(containers) || !Object.isExtensible(instances)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ` const stackFrames = (${captureFrames})();`, ` const sourceURL = (${resolveSourceURL})(stackFrames);`, ' const modernContainer = { appName, config, exposedModules: {}, runtime: { sourceURL } };', ' const legacyContainer = { name: appName, config, exposeMap: {} };', ' try {', ' if (!Reflect.defineProperty(instances, appName, {', ' configurable: true, enumerable: false, value: instances.length, writable: false,', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' instances.push(legacyContainer);', ' if (!Reflect.set(containers, appName, modernContainer)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' if (!Reflect.defineProperty(modernContainer, __containerPairSymbol, {', ' configurable: true, enumerable: false, value: legacyContainer, writable: false,', ' }) || !Reflect.defineProperty(legacyContainer, __containerPairSymbol, {', ' configurable: true, enumerable: false, value: modernContainer, writable: false,', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' } catch (error) {', ' if (Object.is(instances[instances.length - 1], legacyContainer)) {', ' instances.pop();', ' }', ' Reflect.deleteProperty(instances, appName);', ' Reflect.deleteProperty(containers, appName);', ' Reflect.deleteProperty(modernContainer, __containerPairSymbol);', ' Reflect.deleteProperty(legacyContainer, __containerPairSymbol);', ' throw error;', ' }', ' __legacyContainers.set(modernContainer, legacyContainer);', ' return modernContainer;', '}', 'function exposeModule(container, exposedModule, moduleValue) {', " const normalizedModule = exposedModule.startsWith('./') ? exposedModule : `./${exposedModule}`;", " const legacyModule = exposedModule.startsWith('./') ? exposedModule.slice(2) : exposedModule;", ' const legacyContainer = __legacyContainers.get(container);', ' if (Reflect.has(container.exposedModules, normalizedModule) ||', ' (legacyContainer != null && Reflect.has(legacyContainer.exposeMap, legacyModule))) {', " throw new Error(`Exposed module '${normalizedModule}' is already registered in app container '${container.appName}'`);", ' }', ' const ownsModernContainer = Object.is(', ' global.__MICRO_FRONTEND__.__CONTAINERS__[container.appName],', ' container', ' );', ' let legacyModuleValue = moduleValue;', ' if (legacyContainer != null &&', ' ((typeof moduleValue === "object" && moduleValue != null) || typeof moduleValue === "function") &&', ' moduleValue.__esModule !== true) {', ' legacyModuleValue = typeof moduleValue === "function"', ' ? function (...args) { return Reflect.apply(moduleValue, this, args); }', ' : {};', ' for (const exportName of Reflect.ownKeys(moduleValue)) {', ' if (exportName === "__esModule" || exportName === "default") {', ' continue;', ' }', ' const sourceDescriptor = Reflect.getOwnPropertyDescriptor(moduleValue, exportName);', ' const facadeDescriptor = Reflect.getOwnPropertyDescriptor(legacyModuleValue, exportName);', ' if (sourceDescriptor == null || (facadeDescriptor != null && facadeDescriptor.configurable === false)) {', ' // Callable facades keep intrinsic non-configurable slots such as prototype.', ' continue;', ' }', ' if (!Reflect.defineProperty(legacyModuleValue, exportName, {', ' enumerable: sourceDescriptor.enumerable,', ' get: function () { return Reflect.get(moduleValue, exportName); },', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' }', ' const hasDefaultExport = Reflect.getOwnPropertyDescriptor(moduleValue, "default") != null;', ' Object.defineProperties(legacyModuleValue, {', ' __esModule: { value: true },', ' default: {', ' enumerable: true,', ' get: hasDefaultExport', ' ? function () { return Reflect.get(moduleValue, "default"); }', ' : function () { return moduleValue; },', ' },', ' });', ' }', ' try {', ' if (ownsModernContainer && !Reflect.set(container.exposedModules, normalizedModule, moduleValue)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' if (legacyContainer != null) {', ' Object.defineProperty(legacyContainer.exposeMap, legacyModule, {', ' configurable: true,', ' enumerable: true,', ' get: function () { return legacyModuleValue; },', ' });', ' }', ' } catch (error) {', ' if (ownsModernContainer) {', ' Reflect.deleteProperty(container.exposedModules, normalizedModule);', ' }', ' if (legacyContainer != null) {', ' Reflect.deleteProperty(legacyContainer.exposeMap, legacyModule);', ' }', ' throw error;', ' }', '}', 'function registerShared(moduleName, moduleValue) {', ' const sharedModules = global.__MICRO_FRONTEND__.__SHARED__;', ' const existingModule = sharedModules[moduleName];', ' if (existingModule != null) {', ' if (typeof existingModule === "object" &&', ' typeof existingModule.get === "function" &&', ' typeof existingModule.loaded === "boolean" &&', ' Object.is(existingModule.get(), moduleValue)) {', ' return;', ' }', " throw new Error(`Shared module '${moduleName}' is already registered`);", ' }', ' sharedModules[moduleName] = { get: () => moduleValue, loaded: true };', '}', `const __container = createContainer(${containerName}, ${containerConfig});`, ...registerStatements, ...exposeStatements].join('\n')
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
28
|
//# sourceMappingURL=prelude.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["path","globalContextScript","CONTAINER_PAIRING_KEY","getPreludeConfig","options","appName","eagerSharedModules","Object","entries","shared","filter","config","Array","isArray","eager","registerStatements","map","moduleName","index","identifier","JSON","stringify","join","exposeStatements","exposes","exposedModule","modulePath","resolve","containerConfig","containerName","banner","preludeScript"],"sourceRoot":"../../../src","sources":["plugin/prelude.ts"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,mBAAmB,QAAQ,0BAAuB;AAE3D,SAASC,qBAAqB,QAAQ,gCAA6B;
|
|
1
|
+
{"version":3,"names":["path","globalContextScript","CONTAINER_PAIRING_KEY","captureStackFrames","resolveCurrentSourceURL","getPreludeConfig","options","appName","eagerSharedModules","Object","entries","shared","filter","config","Array","isArray","eager","registerStatements","map","moduleName","index","identifier","JSON","stringify","join","exposeStatements","exposes","exposedModule","modulePath","resolve","containerConfig","containerName","captureFrames","toString","resolveSourceURL","banner","preludeScript"],"sourceRoot":"../../../src","sources":["plugin/prelude.ts"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,mBAAmB,QAAQ,0BAAuB;AAE3D,SAASC,qBAAqB,QAAQ,gCAA6B;AACnE,SAASC,kBAAkB,EAAEC,uBAAuB,QAAQ,gCAA6B;AAOzF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B,EACrB,gCAAgC,EAChC,2EAA2E,EAC3E,OAAO,EACP,oCAAoC,EACpC,wEAAwE,EACxE,OAAO,EACP,kBAAkB,EAClB,KAAK,EACL,GAAG,EACH,oDAAoD,EACpD,+DAA+D,EAC/D,qDAAqD,EACrD,iCAAiC,EACjC,+CAA+C,EAC/C,qDAAqD,EACrD,uDAAuD,EACvD,yDAAyD,EACzD,eAAe,EACf,OAAO,EACP,6EAA6E,EAC7E,KAAK,EACL,yEAAyE,EACzE,GAAG,EACH,uCAAuCH,aAAa,KAAKD,eAAe,IAAI,EAC5E,GAAGb,kBAAkB,EACrB,GAAGQ,gBAAgB,CACpB,CAACD,IAAI,CAAC,IAAI;EACb,CAAC;AACH","ignoreList":[]}
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
import { clearContainerPair, defineContainerPair, forgetContainerPair, getLegacyContainerPair, getModernContainerPair, isLegacyAppContainer, isContainerPair, isObjectRecord, rememberContainerPair, rememberLegacyAdapterPair } from "./containerPairing.js";
|
|
4
4
|
import { AppContainerAlreadyRegisteredError } from "./errors.js";
|
|
5
5
|
import { getMicroFrontendGlobalContext, MicroFrontendGlobalContextCompatibilityError } from "./globalContext.js";
|
|
6
|
+
import { captureStackFrames, resolveCurrentSourceURL } from "./runtimeSourceURL.js";
|
|
6
7
|
export { exposeContainerModule as exposeModule } from "./containerModuleExposure.js";
|
|
7
8
|
export function createContainer(appName, config = {}) {
|
|
9
|
+
const sourceURL = resolveCurrentSourceURL(captureStackFrames());
|
|
8
10
|
const context = getMicroFrontendGlobalContext();
|
|
9
11
|
const canonicalValue = Reflect.get(context.__CONTAINERS__, appName);
|
|
10
12
|
const legacyIndex = Reflect.get(context.__INSTANCES__, appName);
|
|
@@ -17,7 +19,10 @@ export function createContainer(appName, config = {}) {
|
|
|
17
19
|
const modernContainer = {
|
|
18
20
|
appName,
|
|
19
21
|
config,
|
|
20
|
-
exposedModules: {}
|
|
22
|
+
exposedModules: {},
|
|
23
|
+
runtime: {
|
|
24
|
+
sourceURL
|
|
25
|
+
}
|
|
21
26
|
};
|
|
22
27
|
const legacyContainer = {
|
|
23
28
|
name: appName,
|
|
@@ -178,7 +183,8 @@ function normalizeLegacyModule(exposedModule) {
|
|
|
178
183
|
return exposedModule.startsWith('./') ? exposedModule.slice(2) : exposedModule;
|
|
179
184
|
}
|
|
180
185
|
function isAppContainer(value) {
|
|
181
|
-
|
|
186
|
+
const runtime = isObjectRecord(value) ? Reflect.get(value, 'runtime') : null;
|
|
187
|
+
return isObjectRecord(value) && typeof Reflect.get(value, 'appName') === 'string' && isAppContainerConfig(Reflect.get(value, 'config')) && isObjectRecord(Reflect.get(value, 'exposedModules')) && (runtime == null || isObjectRecord(runtime) && typeof Reflect.get(runtime, 'sourceURL') === 'string');
|
|
182
188
|
}
|
|
183
189
|
function isAppContainerConfig(value) {
|
|
184
190
|
if (!isObjectRecord(value)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["clearContainerPair","defineContainerPair","forgetContainerPair","getLegacyContainerPair","getModernContainerPair","isLegacyAppContainer","isContainerPair","isObjectRecord","rememberContainerPair","rememberLegacyAdapterPair","AppContainerAlreadyRegisteredError","getMicroFrontendGlobalContext","MicroFrontendGlobalContextCompatibilityError","exposeContainerModule","exposeModule","createContainer","appName","config","context","canonicalValue","Reflect","get","__CONTAINERS__","legacyIndex","__INSTANCES__","isExtensible","modernContainer","exposedModules","legacyContainer","name","exposeMap","containerIndex","length","defineProperty","configurable","enumerable","value","writable","push","set","error","Object","is","pop","deleteProperty","getContainer","isAppContainer","getLegacyContainer","getLegacyAdapter","getExposedModule","container","exposedModule","module","normalizeExposedModule","undefined","normalizeLegacyModule","removeContainer","nextInstances","createLegacyInstancesWithout","clearRegistry","clearLegacyModules","existingAdapter","adapter","isAppContainerConfig","createNormalizedExposedModules","Proxy","_target","property","receiver","ownKeys","map","key","getOwnPropertyDescriptor","moduleName","has","instances","index","Number","isInteger","removed","Array","from","filter","entry","registeredNames","Set","entries","add","registry","keys","startsWith","slice","shared"],"sourceRoot":"../../../src","sources":["runtime/containerRegistry.ts"],"mappings":";;AAAA,SACEA,kBAAkB,EAClBC,mBAAmB,EACnBC,mBAAmB,EACnBC,sBAAsB,EACtBC,sBAAsB,EACtBC,oBAAoB,EACpBC,eAAe,EACfC,cAAc,EACdC,qBAAqB,EACrBC,yBAAyB,QAEpB,uBAAoB;AAC3B,SAASC,kCAAkC,QAAQ,aAAU;AAC7D,SAASC,6BAA6B,EAAEC,4CAA4C,QAAQ,oBAAiB;
|
|
1
|
+
{"version":3,"names":["clearContainerPair","defineContainerPair","forgetContainerPair","getLegacyContainerPair","getModernContainerPair","isLegacyAppContainer","isContainerPair","isObjectRecord","rememberContainerPair","rememberLegacyAdapterPair","AppContainerAlreadyRegisteredError","getMicroFrontendGlobalContext","MicroFrontendGlobalContextCompatibilityError","captureStackFrames","resolveCurrentSourceURL","exposeContainerModule","exposeModule","createContainer","appName","config","sourceURL","context","canonicalValue","Reflect","get","__CONTAINERS__","legacyIndex","__INSTANCES__","isExtensible","modernContainer","exposedModules","runtime","legacyContainer","name","exposeMap","containerIndex","length","defineProperty","configurable","enumerable","value","writable","push","set","error","Object","is","pop","deleteProperty","getContainer","isAppContainer","getLegacyContainer","getLegacyAdapter","getExposedModule","container","exposedModule","module","normalizeExposedModule","undefined","normalizeLegacyModule","removeContainer","nextInstances","createLegacyInstancesWithout","clearRegistry","clearLegacyModules","existingAdapter","adapter","isAppContainerConfig","createNormalizedExposedModules","Proxy","_target","property","receiver","ownKeys","map","key","getOwnPropertyDescriptor","moduleName","has","instances","index","Number","isInteger","removed","Array","from","filter","entry","registeredNames","Set","entries","add","registry","keys","startsWith","slice","shared"],"sourceRoot":"../../../src","sources":["runtime/containerRegistry.ts"],"mappings":";;AAAA,SACEA,kBAAkB,EAClBC,mBAAmB,EACnBC,mBAAmB,EACnBC,sBAAsB,EACtBC,sBAAsB,EACtBC,oBAAoB,EACpBC,eAAe,EACfC,cAAc,EACdC,qBAA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ACgB,KAAK,EAAE,SAAS,CAAC,KAAK,QAAQ,IACjD2B,oBAAoB,CAAC5C,OAAO,CAACC,GAAG,CAACgB,KAAK,EAAE,QAAQ,CAAC,CAAC,IAClDjC,cAAc,CAACgB,OAAO,CAACC,GAAG,CAACgB,KAAK,EAAE,gBAAgB,CAAC,CAAC,KACnDT,OAAO,IAAI,IAAI,IAAKxB,cAAc,CAACwB,OAAO,CAAC,IAAI,OAAOR,OAAO,CAACC,GAAG,CAACO,OAAO,EAAE,WAAW,CAAC,KAAK,QAAS,CAAC;AAE3G;AAEA,SAASoC,oBAAoBA,CAAC3B,KAAc,EAA+B;EACzE,IAAI,CAACjC,cAAc,CAACiC,KAAK,CAAC,EAAE;IAC1B,OAAO,KAAK;EACd;EACA,MAAMwD,MAAe,GAAGzE,OAAO,CAACC,GAAG,CAACgB,KAAK,EAAE,QAAQ,CAAC;EACpD,OAAOwD,MAAM,IAAI,IAAI,IAAIzF,cAAc,CAACyF,MAAM,CAAC;AACjD","ignoreList":[]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { AppContainerNotFoundError, InvalidAppNameError } from "./errors.js";
|
|
4
4
|
import { getMicroFrontendGlobalContext } from "./globalContext.js";
|
|
5
|
+
import { setMicroFrontendLifecycleCallback } from "./lifecycle.js";
|
|
5
6
|
import { installNativeComponentRegistryCompatibility } from "./nativeComponentRegistryCompatibility.js";
|
|
6
7
|
import { parseAppRequest } from "./parseAppRequest.js";
|
|
7
8
|
export function createMicroFrontendRuntimeWithDependencies(dependencies) {
|
|
@@ -47,7 +48,7 @@ export function createMicroFrontendRuntimeWithDependencies(dependencies) {
|
|
|
47
48
|
throw error;
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
+
const runtime = {
|
|
51
52
|
evaluateScript,
|
|
52
53
|
preloadApp,
|
|
53
54
|
async importApp(request) {
|
|
@@ -80,5 +81,7 @@ export function createMicroFrontendRuntimeWithDependencies(dependencies) {
|
|
|
80
81
|
return subscription;
|
|
81
82
|
}
|
|
82
83
|
};
|
|
84
|
+
setMicroFrontendLifecycleCallback(runtime, dependencies.onLifecycleEvent);
|
|
85
|
+
return runtime;
|
|
83
86
|
}
|
|
84
87
|
//# sourceMappingURL=createMicroFrontendRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AppContainerNotFoundError","InvalidAppNameError","getMicroFrontendGlobalContext","installNativeComponentRegistryCompatibility","parseAppRequest","createMicroFrontendRuntimeWithDependencies","dependencies","appEvaluations","Map","resetFailedEvaluation","appName","delete","registry","removeContainer","removePendingHostComponentRoutes","preloadApp","length","Promise","reject","existingEvaluation","get","evaluation","evaluateApp","set","evaluateScript","filePath","nativeRuntime","adapter","loadBundle","hasContainer","error","importApp","request","importModule","onEvent","listener","subscription","event","parsedEvent","parseEvent","name","params","catch","onPreloadError","exhaustiveEvent","startEventDelivery"],"sourceRoot":"../../../src","sources":["runtime/createMicroFrontendRuntime.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"names":["AppContainerNotFoundError","InvalidAppNameError","getMicroFrontendGlobalContext","setMicroFrontendLifecycleCallback","installNativeComponentRegistryCompatibility","parseAppRequest","createMicroFrontendRuntimeWithDependencies","dependencies","appEvaluations","Map","resetFailedEvaluation","appName","delete","registry","removeContainer","removePendingHostComponentRoutes","preloadApp","length","Promise","reject","existingEvaluation","get","evaluation","evaluateApp","set","evaluateScript","filePath","nativeRuntime","adapter","loadBundle","hasContainer","error","runtime","importApp","request","importModule","onEvent","listener","subscription","event","parsedEvent","parseEvent","name","params","catch","onPreloadError","exhaustiveEvent","startEventDelivery","onLifecycleEvent"],"sourceRoot":"../../../src","sources":["runtime/createMicroFrontendRuntime.ts"],"mappings":";;AAQA,SAASA,yBAAyB,EAAEC,mBAAmB,QAAQ,aAAU;AACzE,SAASC,6BAA6B,QAAQ,oBAAiB;AAC/D,SAASC,iCAAiC,QAAQ,gBAAa;AAC/D,SAASC,2CAA2C,QAAQ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2
|
+
|
|
3
|
+
import { getMicroFrontendRuntimeContext } from "./registry.js";
|
|
4
|
+
import { captureStackFrames, resolveCurrentSourceURL } from "./runtimeSourceURL.js";
|
|
5
|
+
export function resolveAppNameBySourceURL(sourceURL, containers) {
|
|
6
|
+
let resolvedAppName = null;
|
|
7
|
+
for (const container of Object.values(containers)) {
|
|
8
|
+
if (container.runtime?.sourceURL !== sourceURL) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (resolvedAppName != null && resolvedAppName !== container.appName) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
resolvedAppName = container.appName;
|
|
15
|
+
}
|
|
16
|
+
return resolvedAppName;
|
|
17
|
+
}
|
|
18
|
+
export function findAppNameBySourceURL(sourceURL) {
|
|
19
|
+
return resolveAppNameBySourceURL(sourceURL, getMicroFrontendRuntimeContext().containers);
|
|
20
|
+
}
|
|
21
|
+
export function resolveAppNameFromStackFrames(frames, containers) {
|
|
22
|
+
const sourceURL = resolveCurrentSourceURL(frames);
|
|
23
|
+
const appName = resolveAppNameBySourceURL(sourceURL, containers);
|
|
24
|
+
if (appName != null) {
|
|
25
|
+
return appName;
|
|
26
|
+
}
|
|
27
|
+
throw new Error('Cannot resolve the current micro-frontend app name');
|
|
28
|
+
}
|
|
29
|
+
export function getAppName() {
|
|
30
|
+
const sourceURL = resolveCurrentSourceURL(captureStackFrames());
|
|
31
|
+
const appName = findAppNameBySourceURL(sourceURL);
|
|
32
|
+
if (appName != null) {
|
|
33
|
+
return appName;
|
|
34
|
+
}
|
|
35
|
+
throw new Error('Cannot resolve the current micro-frontend app name');
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=getAppName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getMicroFrontendRuntimeContext","captureStackFrames","resolveCurrentSourceURL","resolveAppNameBySourceURL","sourceURL","containers","resolvedAppName","container","Object","values","runtime","appName","findAppNameBySourceURL","resolveAppNameFromStackFrames","frames","Error","getAppName"],"sourceRoot":"../../../src","sources":["runtime/getAppName.ts"],"mappings":";;AAAA,SAASA,8BAA8B,QAA2B,eAAY;AAC9E,SAASC,kBAAkB,EAAEC,uBAAuB,QAAgC,uBAAoB;AAExG,OAAO,SAASC,yBAAyBA,CACvCC,SAAiB,EACjBC,UAAkD,EACnC;EACf,IAAIC,eAA8B,GAAG,IAAI;EACzC,KAAK,MAAMC,SAAS,IAAIC,MAAM,CAACC,MAAM,CAACJ,UAAU,CAAC,EAAE;IACjD,IAAIE,SAAS,CAACG,OAAO,EAAEN,SAAS,KAAKA,SAAS,EAAE;MAC9C;IACF;IACA,IAAIE,eAAe,IAAI,IAAI,IAAIA,eAAe,KAAKC,SAAS,CAACI,OAAO,EAAE;MACpE,OAAO,IAAI;IACb;IACAL,eAAe,GAAGC,SAAS,CAACI,OAAO;EACrC;EACA,OAAOL,eAAe;AACxB;AAEA,OAAO,SAASM,sBAAsBA,CAACR,SAAiB,EAAiB;EACvE,OAAOD,yBAAyB,CAACC,SAAS,EAAEJ,8BAA8B,CAAC,CAAC,CAACK,UAAU,CAAC;AAC1F;AAEA,OAAO,SAASQ,6BAA6BA,CAC3CC,MAAoC,EACpCT,UAAkD,EAC1C;EACR,MAAMD,SAAS,GAAGF,uBAAuB,CAACY,MAAM,CAAC;EACjD,MAAMH,OAAO,GAAGR,yBAAyB,CAACC,SAAS,EAAEC,UAAU,CAAC;EAChE,IAAIM,OAAO,IAAI,IAAI,EAAE;IACnB,OAAOA,OAAO;EAChB;EAEA,MAAM,IAAII,KAAK,CAAC,oDAAoD,CAAC;AACvE;AAEA,OAAO,SAASC,UAAUA,CAAA,EAAW;EACnC,MAAMZ,SAAS,GAAGF,uBAAuB,CAACD,kBAAkB,CAAC,CAAC,CAAC;EAC/D,MAAMU,OAAO,GAAGC,sBAAsB,CAACR,SAAS,CAAC;EACjD,IAAIO,OAAO,IAAI,IAAI,EAAE;IACnB,OAAOA,OAAO;EAChB;EAEA,MAAM,IAAII,KAAK,CAAC,oDAAoD,CAAC;AACvE","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const lifecycleCallbackByRuntime = new WeakMap();
|
|
4
|
+
export function setMicroFrontendLifecycleCallback(runtime, callback) {
|
|
5
|
+
if (callback == null) {
|
|
6
|
+
lifecycleCallbackByRuntime.delete(runtime);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
lifecycleCallbackByRuntime.set(runtime, callback);
|
|
10
|
+
}
|
|
11
|
+
export function emitMicroFrontendLifecycleEvent(runtime, event) {
|
|
12
|
+
const callback = lifecycleCallbackByRuntime.get(runtime);
|
|
13
|
+
if (callback == null) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
callback(event);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error('Failed to run a micro-frontend lifecycle callback', error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["lifecycleCallbackByRuntime","WeakMap","setMicroFrontendLifecycleCallback","runtime","callback","delete","set","emitMicroFrontendLifecycleEvent","event","get","error","console"],"sourceRoot":"../../../src","sources":["runtime/lifecycle.ts"],"mappings":";;AAEA,MAAMA,0BAA0B,GAAG,IAAIC,OAAO,CAAuD,CAAC;AAEtG,OAAO,SAASC,iCAAiCA,CAC/CC,OAAe,EACfC,QAAoE,EAC9D;EACN,IAAIA,QAAQ,IAAI,IAAI,EAAE;IACpBJ,0BAA0B,CAACK,MAAM,CAACF,OAAO,CAAC;IAC1C;EACF;EAEAH,0BAA0B,CAACM,GAAG,CAACH,OAAO,EAAEC,QAAQ,CAAC;AACnD;AAEA,OAAO,SAASG,+BAA+BA,CAACJ,OAAe,EAAEK,KAAkC,EAAQ;EACzG,MAAMJ,QAAQ,GAAGJ,0BAA0B,CAACS,GAAG,CAACN,OAAO,CAAC;EACxD,IAAIC,QAAQ,IAAI,IAAI,EAAE;IACpB;EACF;EAEA,IAAI;IACFA,QAAQ,CAACI,KAAK,CAAC;EACjB,CAAC,CAAC,OAAOE,KAAK,EAAE;IACdC,OAAO,CAACD,KAAK,CAAC,mDAAmD,EAAEA,KAAK,CAAC;EAC3E;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContainer","exposeModule","getContainer","getExposedModule","removeContainer","ExposedModuleNotFoundError","SharedModuleAlreadyRegisteredError","getMicroFrontendGlobalContext","parseAppRequest","getMicroFrontendRuntimeContext","context","ensureRuntimeContext","registerShared","moduleName","module","sharedModules","__SHARED__","existingModule","isSharedModule","Object","is","get","loaded","value","Reflect","disposeAppResources","appName","disposeCallbacks","disposeCallbacksByApp","runAppDisposeCallbacks","hasContainer","importModule","request","exposedModule","container","containers","__CONTAINERS__","propertyDescriptors","Map","runtimeProperties","dispose","isRegisterAppDispose","createRegisterAppDispose","isDisposeCallbackRegistry","property","ownKeys","set","getOwnPropertyDescriptor","defineProperty","configurable","enumerable","writable","Error","String","error","descriptor","Array","from","reverse","deleteProperty","isObjectRecord","isArray","values","every","isDisposeCallbackSet","Symbol","iterator","appNameOrCallback","callback","registerAppDisposeCallback","Set","add","isRegistered","delete","callbacks","firstDisposeError","didDisposeFail","microFrontendModuleRegistry"],"sourceRoot":"../../../src","sources":["runtime/registry.ts"],"mappings":";;AACA,SAASA,eAAe,EAAEC,YAAY,EAAEC,YAAY,EAAEC,gBAAgB,EAAEC,eAAe,QAAQ,wBAAqB;AAEpH,SAASC,0BAA0B,EAAEC,kCAAkC,QAAQ,aAAU;AACzF,SAASC,6BAA6B,QAAyC,oBAAiB;AAChG,SAASC,eAAe,QAAQ,sBAAmB;AACnD,SAASR,eAAe,EAAEC,YAAY,EAAEC,YAAY,EAAEE,eAAe;
|
|
1
|
+
{"version":3,"names":["createContainer","exposeModule","getContainer","getExposedModule","removeContainer","ExposedModuleNotFoundError","SharedModuleAlreadyRegisteredError","getMicroFrontendGlobalContext","parseAppRequest","getMicroFrontendRuntimeContext","context","ensureRuntimeContext","registerShared","moduleName","module","sharedModules","__SHARED__","existingModule","isSharedModule","Object","is","get","loaded","value","Reflect","disposeAppResources","appName","disposeCallbacks","disposeCallbacksByApp","runAppDisposeCallbacks","hasContainer","importModule","request","exposedModule","container","containers","__CONTAINERS__","propertyDescriptors","Map","runtimeProperties","dispose","isRegisterAppDispose","createRegisterAppDispose","isDisposeCallbackRegistry","property","ownKeys","set","getOwnPropertyDescriptor","defineProperty","configurable","enumerable","writable","Error","String","error","descriptor","Array","from","reverse","deleteProperty","isObjectRecord","isArray","values","every","isDisposeCallbackSet","Symbol","iterator","appNameOrCallback","callback","registerAppDisposeCallback","Set","add","isRegistered","delete","callbacks","firstDisposeError","didDisposeFail","microFrontendModuleRegistry"],"sourceRoot":"../../../src","sources":["runtime/registry.ts"],"mappings":";;AACA,SAASA,eAAe,EAAEC,YAAY,EAAEC,YAAY,EAAEC,gBAAgB,EAAEC,eAAe,QAAQ,wBAAqB;AAEpH,SAASC,0BAA0B,EAAEC,kCAAkC,QAAQ,aAAU;AACzF,SAASC,6BAA6B,QAAyC,oBAAiB;AAChG,SAASC,eAAe,QAAQ,sBAAmB;AACnD,SAASR,eAAe,EAAEC,YAAY,EAAEC,YAAY,EAAEE,eAAe;AA0CrE,OAAO,SAASK,8BAA8BA,CAAA,EAAgC;EAC5E,MAAMC,OAAO,GAAGH,6BAA6B,CAAC,CAAC;EAC/CI,oBAAoB,CAACD,OAAO,CAAC;EAC7B,OAAOA,OAAO;AAChB;AAEA,OAAO,SAASE,cAAcA,CAACC,UAAkB,EAAEC,MAAe,EAAQ;EACxE,MAAMC,aAAa,GAAGR,6BAA6B,CAAC,CAAC,CAACS,UAAU;EAChE,MAAMC,cAAc,GAAGF,aAAa,CAACF,UAAU,CAAC;EAChD,IAAII,cAAc,IAAI,IAAI,EAAE;IAC1B,IAAIC,cAAc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,cAAc,EAAE;QACnBD,iBAAiB,GAAGrB,KAAK;QACzBsB,cAAc,GAAG,IAAI;MACvB;IACF;EACF;EAEA,IAAIA,cAAc,EAAE;IAClB,MAAMD,iBAAiB;EACzB;AACF;AAEA,OAAO,MAAME,2BAAwD,GAAG;EACtE/C,YAAY;EACZC,YAAY;EACZ3B;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export function captureStackFrames() {
|
|
4
|
+
const prepareStackTraceDescriptor = Object.getOwnPropertyDescriptor(Error, 'prepareStackTrace');
|
|
5
|
+
Object.defineProperty(Error, 'prepareStackTrace', {
|
|
6
|
+
configurable: true,
|
|
7
|
+
value: (_error, callSites) => callSites,
|
|
8
|
+
writable: true
|
|
9
|
+
});
|
|
10
|
+
const frames = [];
|
|
11
|
+
try {
|
|
12
|
+
const callSites = new Error().stack;
|
|
13
|
+
if (!Array.isArray(callSites)) {
|
|
14
|
+
throw new Error('Cannot capture structured micro-frontend stack frames');
|
|
15
|
+
}
|
|
16
|
+
for (const callSite of callSites) {
|
|
17
|
+
if (typeof callSite !== 'object' || callSite == null) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (!('getFileName' in callSite)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const getFileName = 'getFileName' in callSite ? callSite.getFileName : undefined;
|
|
24
|
+
const sourceURL = typeof getFileName === 'function' ? getFileName.call(callSite) : null;
|
|
25
|
+
frames.push({
|
|
26
|
+
sourceURL: typeof sourceURL === 'string' ? sourceURL : null
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
} finally {
|
|
30
|
+
if (prepareStackTraceDescriptor == null) {
|
|
31
|
+
Reflect.deleteProperty(Error, 'prepareStackTrace');
|
|
32
|
+
} else {
|
|
33
|
+
Object.defineProperty(Error, 'prepareStackTrace', prepareStackTraceDescriptor);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return frames;
|
|
37
|
+
}
|
|
38
|
+
export function resolveCurrentSourceURL(frames) {
|
|
39
|
+
for (const frame of frames) {
|
|
40
|
+
if (frame.sourceURL != null && frame.sourceURL.length > 0) {
|
|
41
|
+
return frame.sourceURL;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw new Error('Cannot determine the caller micro-frontend sourceURL');
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=runtimeSourceURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["captureStackFrames","prepareStackTraceDescriptor","Object","getOwnPropertyDescriptor","Error","defineProperty","configurable","value","_error","callSites","writable","frames","stack","Array","isArray","callSite","getFileName","undefined","sourceURL","call","push","Reflect","deleteProperty","resolveCurrentSourceURL","frame","length"],"sourceRoot":"../../../src","sources":["runtime/runtimeSourceURL.ts"],"mappings":";;AAIA,OAAO,SAASA,kBAAkBA,CAAA,EAAiC;EACjE,MAAMC,2BAA2B,GAAGC,MAAM,CAACC,wBAAwB,CAACC,KAAK,EAAE,mBAAmB,CAAC;EAC/FF,MAAM,CAACG,cAAc,CAACD,KAAK,EAAE,mBAAmB,EAAE;IAChDE,YAAY,EAAE,IAAI;IAClBC,KAAK,EAAEA,CAACC,MAAe,EAAEC,SAA6B,KAAKA,SAAS;IACpEC,QAAQ,EAAE;EACZ,CAAC,CAAC;EAEF,MAAMC,MAA2B,GAAG,EAAE;EACtC,IAAI;IACF,MAAMF,SAAkB,GAAG,IAAIL,KAAK,CAAC,CAAC,CAACQ,KAAK;IAC5C,IAAI,CAACC,KAAK,CAACC,OAAO,CAACL,SAAS,CAAC,EAAE;MAC7B,MAAM,IAAIL,KAAK,CAAC,uDAAuD,CAAC;IAC1E;IACA,KAAK,MAAMW,QAAQ,IAAIN,SAAS,EAAE;MAChC,IAAI,OAAOM,QAAQ,KAAK,QAAQ,IAAIA,QAAQ,IAAI,IAAI,EAAE;QACpD;MACF;MACA,IAAI,EAAE,aAAa,IAAIA,QAAQ,CAAC,EAAE;QAChC;MACF;MACA,MAAMC,WAAoB,GAAG,aAAa,IAAID,QAAQ,GAAGA,QAAQ,CAACC,WAAW,GAAGC,SAAS;MACzF,MAAMC,SAAkB,GAAG,OAAOF,WAAW,KAAK,UAAU,GAAGA,WAAW,CAACG,IAAI,CAACJ,QAAQ,CAAC,GAAG,IAAI;MAChGJ,MAAM,CAACS,IAAI,CAAC;QAAEF,SAAS,EAAE,OAAOA,SAAS,KAAK,QAAQ,GAAGA,SAAS,GAAG;MAAK,CAAC,CAAC;IAC9E;EACF,CAAC,SAAS;IACR,IAAIjB,2BAA2B,IAAI,IAAI,EAAE;MACvCoB,OAAO,CAACC,cAAc,CAAClB,KAAK,EAAE,mBAAmB,CAAC;IACpD,CAAC,MAAM;MACLF,MAAM,CAACG,cAAc,CAACD,KAAK,EAAE,mBAAmB,EAAEH,2BAA2B,CAAC;IAChF;EACF;EAEA,OAAOU,MAAM;AACf;AAEA,OAAO,SAASY,uBAAuBA,CAACZ,MAAoC,EAAU;EACpF,KAAK,MAAMa,KAAK,IAAIb,MAAM,EAAE;IAC1B,IAAIa,KAAK,CAACN,SAAS,IAAI,IAAI,IAAIM,KAAK,CAACN,SAAS,CAACO,MAAM,GAAG,CAAC,EAAE;MACzD,OAAOD,KAAK,CAACN,SAAS;IACxB;EACF;EACA,MAAM,IAAId,KAAK,CAAC,sDAAsD,CAAC;AACzE","ignoreList":[]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useLayoutEffect, useReducer, useRef } from 'react';
|
|
4
4
|
import { installPendingHostComponentBridge, resetPendingHostComponent } from "../host/pendingHostComponentStore.js";
|
|
5
|
+
import { emitMicroFrontendLifecycleEvent } from "../runtime/lifecycle.js";
|
|
5
6
|
import { disposeAppResources } from "../runtime/registry.js";
|
|
6
7
|
const INITIAL_SESSIONS = [];
|
|
7
8
|
function reduceMicroFrontendSessions(sessions, event) {
|
|
@@ -43,17 +44,32 @@ export function useMicroFrontendSessions(runtime) {
|
|
|
43
44
|
const activeAppNames = new Set(sessions.map(({
|
|
44
45
|
appName
|
|
45
46
|
}) => appName));
|
|
46
|
-
const
|
|
47
|
+
const mountedSessions = sessions.filter(({
|
|
47
48
|
sessionId
|
|
48
|
-
}) => !
|
|
49
|
+
}) => !previousSessions.some(previousSession => previousSession.sessionId === sessionId));
|
|
50
|
+
const inactiveSessions = previousSessions.filter(({
|
|
51
|
+
sessionId
|
|
52
|
+
}) => !activeSessionIds.has(sessionId));
|
|
53
|
+
const inactiveAppNames = new Set(inactiveSessions.map(({
|
|
49
54
|
appName
|
|
50
55
|
}) => appName).filter(appName => !activeAppNames.has(appName)));
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
mountedSessions.forEach(session => {
|
|
57
|
+
emitMicroFrontendLifecycleEvent(runtime, createLifecycleEvent('mounted', session, sessions));
|
|
58
|
+
});
|
|
59
|
+
const appDisposals = new Map(Array.from(inactiveAppNames, appName => [appName, disposeAppResources(appName).catch(error => {
|
|
60
|
+
console.error(`Failed to dispose micro-frontend app resources for '${appName}'`, error);
|
|
61
|
+
})]));
|
|
62
|
+
inactiveSessions.forEach(session => {
|
|
63
|
+
const appDisposal = appDisposals.get(session.appName);
|
|
64
|
+
if (appDisposal == null) {
|
|
65
|
+
emitMicroFrontendLifecycleEvent(runtime, createLifecycleEvent('unmounted', session, sessions));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
void appDisposal.then(() => {
|
|
69
|
+
emitMicroFrontendLifecycleEvent(runtime, createLifecycleEvent('unmounted', session, previousSessionsRef.current));
|
|
54
70
|
});
|
|
55
71
|
});
|
|
56
|
-
}, [sessions]);
|
|
72
|
+
}, [runtime, sessions]);
|
|
57
73
|
useLayoutEffect(() => {
|
|
58
74
|
installPendingHostComponentBridge();
|
|
59
75
|
const subscription = runtime.onEvent(event => {
|
|
@@ -66,4 +82,17 @@ export function useMicroFrontendSessions(runtime) {
|
|
|
66
82
|
}, [runtime]);
|
|
67
83
|
return sessions;
|
|
68
84
|
}
|
|
85
|
+
function createLifecycleEvent(phase, session, activeSessions) {
|
|
86
|
+
return {
|
|
87
|
+
phase,
|
|
88
|
+
session: toLifecycleSession(session),
|
|
89
|
+
activeSessions: activeSessions.map(toLifecycleSession)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function toLifecycleSession(session) {
|
|
93
|
+
return {
|
|
94
|
+
appName: session.appName,
|
|
95
|
+
id: session.sessionId
|
|
96
|
+
};
|
|
97
|
+
}
|
|
69
98
|
//# sourceMappingURL=useMicroFrontendSessions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useLayoutEffect","useReducer","useRef","installPendingHostComponentBridge","resetPendingHostComponent","disposeAppResources","INITIAL_SESSIONS","reduceMicroFrontendSessions","sessions","event","name","some","sessionId","params","appName","scheme","isVisible","filter","map","session","exhaustiveEvent","useMicroFrontendSessions","runtime","dispatch","previousSessionsRef","previousSessions","current","activeSessionIds","Set","activeAppNames","
|
|
1
|
+
{"version":3,"names":["useEffect","useLayoutEffect","useReducer","useRef","installPendingHostComponentBridge","resetPendingHostComponent","emitMicroFrontendLifecycleEvent","disposeAppResources","INITIAL_SESSIONS","reduceMicroFrontendSessions","sessions","event","name","some","sessionId","params","appName","scheme","isVisible","filter","map","session","exhaustiveEvent","useMicroFrontendSessions","runtime","dispatch","previousSessionsRef","previousSessions","current","activeSessionIds","Set","activeAppNames","mountedSessions","previousSession","inactiveSessions","has","inactiveAppNames","forEach","createLifecycleEvent","appDisposals","Map","Array","from","catch","error","console","appDisposal","get","then","subscription","onEvent","remove","phase","activeSessions","toLifecycleSession","id"],"sourceRoot":"../../../src","sources":["session/useMicroFrontendSessions.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,eAAe,EAAEC,UAAU,EAAEC,MAAM,QAAQ,OAAO;AACtE,SAASC,iCAAiC,EAAEC,yBAAyB,QAAQ,sCAAmC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;AAEA,SAASA,kBAAkBA,CAACjC,OAAkC,EAAiC;EAC7F,OAAO;IACLL,OAAO,EAAEK,OAAO,CAACL,OAAO;IACxBuC,EAAE,EAAElC,OAAO,CAACP;EACd,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { MicroFrontendAdapter, MicroFrontendRuntimeApi } from './types';
|
|
1
|
+
import type { MicroFrontendAdapter, MicroFrontendLifecycleCallback, MicroFrontendRuntimeApi } from './types';
|
|
2
2
|
export interface CreateMicroFrontendRuntimeOptions {
|
|
3
3
|
readonly adapter: MicroFrontendAdapter;
|
|
4
|
+
readonly onLifecycleEvent?: MicroFrontendLifecycleCallback;
|
|
4
5
|
readonly onPreloadError?: (error: unknown) => void;
|
|
5
6
|
}
|
|
6
7
|
export declare function createMicroFrontendRuntime(options: CreateMicroFrontendRuntimeOptions): MicroFrontendRuntimeApi;
|
|
@@ -2,6 +2,7 @@ export { createMicroFrontendRuntime } from './createMicroFrontendRuntime';
|
|
|
2
2
|
export type { CreateMicroFrontendRuntimeOptions } from './createMicroFrontendRuntime';
|
|
3
3
|
export { createRoute } from './createRoute';
|
|
4
4
|
export type { MicroFrontendRouteOptions } from './createRoute';
|
|
5
|
+
export { findAppNameBySourceURL, getAppName } from './runtime/getAppName';
|
|
5
6
|
export type { PendingHostComponentController, PendingHostComponentProps } from './host/PendingHostComponent';
|
|
6
7
|
export { PendingHostComponent, usePendingHostComponentController, useIsPendingHostComponentHidden, useResolvedPendingHostComponent, } from './host/PendingHostComponent';
|
|
7
8
|
export type { PendingHostComponentAppConfig, PendingHostComponentRenderer, PendingHostComponentParams, PendingHostComponentRouteRequest, RegisterPendingHostComponentRouteOptions, ResolvedPendingHostComponent, } from './host/types';
|
|
@@ -11,7 +12,7 @@ export { MicroFrontendSessionProvider, MissingMicroFrontendSessionError, useMicr
|
|
|
11
12
|
export type { MicroFrontendSession, MicroFrontendSessionProviderProps } from './session/MicroFrontendSessionContext';
|
|
12
13
|
export { useMicroFrontendSessions } from './session/useMicroFrontendSessions';
|
|
13
14
|
export type { MicroFrontendSessionState } from './session/useMicroFrontendSessions';
|
|
14
|
-
export type { AppDisposeCallback, MicroFrontendRuntimeContext } from './runtime/registry';
|
|
15
|
+
export type { AppContainer, AppContainerRuntime, AppDisposeCallback, MicroFrontendRuntimeContext, } from './runtime/registry';
|
|
15
16
|
export { default as Portal } from './specs/PortalViewNativeComponent';
|
|
16
|
-
export type { AppRequest, MicroFrontendAppProps, MicroFrontendAdapter, MicroFrontendBundle, MicroFrontendBundleRequest, MicroFrontendRuntimeApi, MicroFrontendRuntimeEvent, MicroFrontendRuntimeEventSubscription, MicroFrontendSessionEvent, } from './types';
|
|
17
|
+
export type { AppRequest, MicroFrontendAppProps, MicroFrontendAdapter, MicroFrontendBundle, MicroFrontendBundleRequest, MicroFrontendLifecycleCallback, MicroFrontendLifecycleEvent, MicroFrontendLifecycleSession, MicroFrontendRuntimeApi, MicroFrontendRuntimeEvent, MicroFrontendRuntimeEventSubscription, MicroFrontendSessionEvent, } from './types';
|
|
17
18
|
export { AppContainerNotFoundError, ExposedModuleNotFoundError, InvalidAppNameError, InvalidAppRequestError, InvalidNativeRuntimeEventError, } from './runtime/errors';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AppRequest, MicroFrontendAdapter, MicroFrontendRuntimeApi, MicroFrontendRuntimeEvent, MicroFrontendRuntimeEventSubscription } from '../types';
|
|
1
|
+
import type { AppRequest, MicroFrontendAdapter, MicroFrontendLifecycleEvent, MicroFrontendRuntimeApi, MicroFrontendRuntimeEvent, MicroFrontendRuntimeEventSubscription } from '../types';
|
|
2
2
|
export interface NativeMicroFrontendRuntimeEvent {
|
|
3
3
|
readonly name: string;
|
|
4
4
|
readonly params: {
|
|
@@ -24,6 +24,7 @@ export interface CreateMicroFrontendRuntimeDependencies {
|
|
|
24
24
|
readonly adapter: MicroFrontendAdapter;
|
|
25
25
|
readonly nativeRuntime: NativeMicroFrontendRuntime;
|
|
26
26
|
readonly onPreloadError: (error: unknown) => void;
|
|
27
|
+
readonly onLifecycleEvent?: (event: MicroFrontendLifecycleEvent) => void;
|
|
27
28
|
readonly registry: MicroFrontendModuleRegistry;
|
|
28
29
|
readonly removePendingHostComponentRoutes: (appName: string) => void;
|
|
29
30
|
readonly parseEvent: (event: NativeMicroFrontendRuntimeEvent) => MicroFrontendRuntimeEvent;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type AppContainer } from './registry';
|
|
2
|
+
import { type RuntimeStackFrame } from './runtimeSourceURL';
|
|
3
|
+
export declare function resolveAppNameBySourceURL(sourceURL: string, containers: Readonly<Record<string, AppContainer>>): string | null;
|
|
4
|
+
export declare function findAppNameBySourceURL(sourceURL: string): string | null;
|
|
5
|
+
export declare function resolveAppNameFromStackFrames(frames: readonly RuntimeStackFrame[], containers: Readonly<Record<string, AppContainer>>): string;
|
|
6
|
+
export declare function getAppName(): string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MicroFrontendLifecycleEvent } from '../types';
|
|
2
|
+
export declare function setMicroFrontendLifecycleCallback(runtime: object, callback: ((event: MicroFrontendLifecycleEvent) => void) | undefined): void;
|
|
3
|
+
export declare function emitMicroFrontendLifecycleEvent(runtime: object, event: MicroFrontendLifecycleEvent): void;
|
|
@@ -9,10 +9,14 @@ export type SharedConfig = Readonly<Record<string, SharedModuleConfig>>;
|
|
|
9
9
|
export interface AppContainerConfig {
|
|
10
10
|
readonly shared?: SharedConfig;
|
|
11
11
|
}
|
|
12
|
+
export interface AppContainerRuntime {
|
|
13
|
+
readonly sourceURL: string;
|
|
14
|
+
}
|
|
12
15
|
export interface AppContainer {
|
|
13
16
|
readonly appName: string;
|
|
14
17
|
readonly config: AppContainerConfig;
|
|
15
18
|
readonly exposedModules: Record<string, unknown>;
|
|
19
|
+
readonly runtime?: AppContainerRuntime;
|
|
16
20
|
}
|
|
17
21
|
export type AppDisposeCallback = () => void | Promise<void>;
|
|
18
22
|
export interface RegisterAppDispose {
|
|
@@ -41,6 +41,17 @@ export type MicroFrontendSessionEvent = Exclude<MicroFrontendRuntimeEvent, {
|
|
|
41
41
|
export interface MicroFrontendRuntimeEventSubscription {
|
|
42
42
|
readonly remove: () => void;
|
|
43
43
|
}
|
|
44
|
+
export interface MicroFrontendLifecycleSession {
|
|
45
|
+
readonly appName: string;
|
|
46
|
+
readonly id: string;
|
|
47
|
+
}
|
|
48
|
+
export interface MicroFrontendLifecycleEvent {
|
|
49
|
+
readonly phase: 'mounted' | 'unmounted';
|
|
50
|
+
readonly session: MicroFrontendLifecycleSession;
|
|
51
|
+
/** Active sessions across every app when the callback is emitted. */
|
|
52
|
+
readonly activeSessions: readonly MicroFrontendLifecycleSession[];
|
|
53
|
+
}
|
|
54
|
+
export type MicroFrontendLifecycleCallback = (event: MicroFrontendLifecycleEvent) => void;
|
|
44
55
|
export interface MicroFrontendRuntimeApi {
|
|
45
56
|
readonly evaluateScript: (filePath: string) => Promise<void>;
|
|
46
57
|
readonly preloadApp: (appName: string) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/micro-frontend",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Micro-frontend build, runtime, session, and Portal contracts for Granite brownfield applications",
|
|
5
5
|
"main": "./dist/module/index.js",
|
|
6
6
|
"types": "./dist/typescript/index.d.ts",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@babel/core": "7.28.5",
|
|
59
|
-
"@granite-js/utils": "2.
|
|
59
|
+
"@granite-js/utils": "2.3.0",
|
|
60
60
|
"@standard-schema/spec": "^1.0.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@babel/types": "7.28.5",
|
|
75
|
-
"@granite-js/plugin-core": "2.
|
|
76
|
-
"@granite-js/react-native": "2.
|
|
75
|
+
"@granite-js/plugin-core": "2.3.0",
|
|
76
|
+
"@granite-js/react-native": "2.3.0",
|
|
77
77
|
"@types/babel__core": "^7.20.5",
|
|
78
78
|
"@types/node": "24.10.12",
|
|
79
79
|
"@types/react": "19.2.0",
|
|
@@ -3,10 +3,11 @@ import { createMicroFrontendRuntimeWithDependencies } from './runtime/createMicr
|
|
|
3
3
|
import { parseNativeRuntimeEvent } from './runtime/parseNativeRuntimeEvent';
|
|
4
4
|
import { microFrontendModuleRegistry } from './runtime/registry';
|
|
5
5
|
import NativeGraniteMicroFrontendRuntime from './specs/NativeGraniteMicroFrontendRuntime';
|
|
6
|
-
import type { MicroFrontendAdapter, MicroFrontendRuntimeApi } from './types';
|
|
6
|
+
import type { MicroFrontendAdapter, MicroFrontendLifecycleCallback, MicroFrontendRuntimeApi } from './types';
|
|
7
7
|
|
|
8
8
|
export interface CreateMicroFrontendRuntimeOptions {
|
|
9
9
|
readonly adapter: MicroFrontendAdapter;
|
|
10
|
+
readonly onLifecycleEvent?: MicroFrontendLifecycleCallback;
|
|
10
11
|
readonly onPreloadError?: (error: unknown) => void;
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -14,6 +15,7 @@ export function createMicroFrontendRuntime(options: CreateMicroFrontendRuntimeOp
|
|
|
14
15
|
return createMicroFrontendRuntimeWithDependencies({
|
|
15
16
|
adapter: options.adapter,
|
|
16
17
|
nativeRuntime: NativeGraniteMicroFrontendRuntime,
|
|
18
|
+
onLifecycleEvent: options.onLifecycleEvent,
|
|
17
19
|
onPreloadError: options.onPreloadError ?? (() => undefined),
|
|
18
20
|
parseEvent: parseNativeRuntimeEvent,
|
|
19
21
|
registry: microFrontendModuleRegistry,
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { createMicroFrontendRuntime } from './createMicroFrontendRuntime';
|
|
|
2
2
|
export type { CreateMicroFrontendRuntimeOptions } from './createMicroFrontendRuntime';
|
|
3
3
|
export { createRoute } from './createRoute';
|
|
4
4
|
export type { MicroFrontendRouteOptions } from './createRoute';
|
|
5
|
+
export { findAppNameBySourceURL, getAppName } from './runtime/getAppName';
|
|
5
6
|
export type { PendingHostComponentController, PendingHostComponentProps } from './host/PendingHostComponent';
|
|
6
7
|
export {
|
|
7
8
|
PendingHostComponent,
|
|
@@ -36,7 +37,12 @@ export {
|
|
|
36
37
|
export type { MicroFrontendSession, MicroFrontendSessionProviderProps } from './session/MicroFrontendSessionContext';
|
|
37
38
|
export { useMicroFrontendSessions } from './session/useMicroFrontendSessions';
|
|
38
39
|
export type { MicroFrontendSessionState } from './session/useMicroFrontendSessions';
|
|
39
|
-
export type {
|
|
40
|
+
export type {
|
|
41
|
+
AppContainer,
|
|
42
|
+
AppContainerRuntime,
|
|
43
|
+
AppDisposeCallback,
|
|
44
|
+
MicroFrontendRuntimeContext,
|
|
45
|
+
} from './runtime/registry';
|
|
40
46
|
export { default as Portal } from './specs/PortalViewNativeComponent';
|
|
41
47
|
export type {
|
|
42
48
|
AppRequest,
|
|
@@ -44,6 +50,9 @@ export type {
|
|
|
44
50
|
MicroFrontendAdapter,
|
|
45
51
|
MicroFrontendBundle,
|
|
46
52
|
MicroFrontendBundleRequest,
|
|
53
|
+
MicroFrontendLifecycleCallback,
|
|
54
|
+
MicroFrontendLifecycleEvent,
|
|
55
|
+
MicroFrontendLifecycleSession,
|
|
47
56
|
MicroFrontendRuntimeApi,
|
|
48
57
|
MicroFrontendRuntimeEvent,
|
|
49
58
|
MicroFrontendRuntimeEventSubscription,
|
package/src/plugin/prelude.ts
CHANGED
|
@@ -2,6 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import { globalContextScript } from './globalContextScript';
|
|
3
3
|
import type { MicroFrontendPluginOptions } from './types';
|
|
4
4
|
import { CONTAINER_PAIRING_KEY } from '../runtime/containerPairing';
|
|
5
|
+
import { captureStackFrames, resolveCurrentSourceURL } from '../runtime/runtimeSourceURL';
|
|
5
6
|
|
|
6
7
|
export interface MicroFrontendPreludeConfig {
|
|
7
8
|
readonly banner: string;
|
|
@@ -28,6 +29,8 @@ export function getPreludeConfig(options: MicroFrontendPluginOptions, appName?:
|
|
|
28
29
|
});
|
|
29
30
|
const containerConfig = JSON.stringify({ shared: options.shared });
|
|
30
31
|
const containerName = appName == null ? 'global.__granite.app.name' : JSON.stringify(appName);
|
|
32
|
+
const captureFrames = captureStackFrames.toString();
|
|
33
|
+
const resolveSourceURL = resolveCurrentSourceURL.toString();
|
|
31
34
|
|
|
32
35
|
return {
|
|
33
36
|
banner: [
|
|
@@ -91,7 +94,9 @@ export function getPreludeConfig(options: MicroFrontendPluginOptions, appName?:
|
|
|
91
94
|
' if (!Object.isExtensible(containers) || !Object.isExtensible(instances)) {',
|
|
92
95
|
' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");',
|
|
93
96
|
' }',
|
|
94
|
-
|
|
97
|
+
` const stackFrames = (${captureFrames})();`,
|
|
98
|
+
` const sourceURL = (${resolveSourceURL})(stackFrames);`,
|
|
99
|
+
' const modernContainer = { appName, config, exposedModules: {}, runtime: { sourceURL } };',
|
|
95
100
|
' const legacyContainer = { name: appName, config, exposeMap: {} };',
|
|
96
101
|
' try {',
|
|
97
102
|
' if (!Reflect.defineProperty(instances, appName, {',
|
|
@@ -14,10 +14,12 @@ import {
|
|
|
14
14
|
import { AppContainerAlreadyRegisteredError } from './errors';
|
|
15
15
|
import { getMicroFrontendGlobalContext, MicroFrontendGlobalContextCompatibilityError } from './globalContext';
|
|
16
16
|
import type { AppContainer, AppContainerConfig } from './registry';
|
|
17
|
+
import { captureStackFrames, resolveCurrentSourceURL } from './runtimeSourceURL';
|
|
17
18
|
|
|
18
19
|
export { exposeContainerModule as exposeModule } from './containerModuleExposure';
|
|
19
20
|
|
|
20
21
|
export function createContainer(appName: string, config: AppContainerConfig = {}): AppContainer {
|
|
22
|
+
const sourceURL = resolveCurrentSourceURL(captureStackFrames());
|
|
21
23
|
const context = getMicroFrontendGlobalContext();
|
|
22
24
|
const canonicalValue: unknown = Reflect.get(context.__CONTAINERS__, appName);
|
|
23
25
|
const legacyIndex: unknown = Reflect.get(context.__INSTANCES__, appName);
|
|
@@ -28,7 +30,12 @@ export function createContainer(appName: string, config: AppContainerConfig = {}
|
|
|
28
30
|
throw new MicroFrontendGlobalContextCompatibilityError('registry-is-not-extensible');
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
const modernContainer: AppContainer = {
|
|
33
|
+
const modernContainer: AppContainer = {
|
|
34
|
+
appName,
|
|
35
|
+
config,
|
|
36
|
+
exposedModules: {},
|
|
37
|
+
runtime: { sourceURL },
|
|
38
|
+
};
|
|
32
39
|
const legacyContainer: LegacyAppContainer = { name: appName, config, exposeMap: {} };
|
|
33
40
|
const containerIndex = context.__INSTANCES__.length;
|
|
34
41
|
|
|
@@ -222,11 +229,13 @@ function normalizeLegacyModule(exposedModule: string): string {
|
|
|
222
229
|
}
|
|
223
230
|
|
|
224
231
|
function isAppContainer(value: unknown): value is AppContainer {
|
|
232
|
+
const runtime: unknown = isObjectRecord(value) ? Reflect.get(value, 'runtime') : null;
|
|
225
233
|
return (
|
|
226
234
|
isObjectRecord(value) &&
|
|
227
235
|
typeof Reflect.get(value, 'appName') === 'string' &&
|
|
228
236
|
isAppContainerConfig(Reflect.get(value, 'config')) &&
|
|
229
|
-
isObjectRecord(Reflect.get(value, 'exposedModules'))
|
|
237
|
+
isObjectRecord(Reflect.get(value, 'exposedModules')) &&
|
|
238
|
+
(runtime == null || (isObjectRecord(runtime) && typeof Reflect.get(runtime, 'sourceURL') === 'string'))
|
|
230
239
|
);
|
|
231
240
|
}
|
|
232
241
|
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AppRequest,
|
|
3
3
|
MicroFrontendAdapter,
|
|
4
|
+
MicroFrontendLifecycleEvent,
|
|
4
5
|
MicroFrontendRuntimeApi,
|
|
5
6
|
MicroFrontendRuntimeEvent,
|
|
6
7
|
MicroFrontendRuntimeEventSubscription,
|
|
7
8
|
} from '../types';
|
|
8
9
|
import { AppContainerNotFoundError, InvalidAppNameError } from './errors';
|
|
9
10
|
import { getMicroFrontendGlobalContext } from './globalContext';
|
|
11
|
+
import { setMicroFrontendLifecycleCallback } from './lifecycle';
|
|
10
12
|
import { installNativeComponentRegistryCompatibility } from './nativeComponentRegistryCompatibility';
|
|
11
13
|
import { parseAppRequest } from './parseAppRequest';
|
|
12
14
|
|
|
@@ -38,6 +40,7 @@ export interface CreateMicroFrontendRuntimeDependencies {
|
|
|
38
40
|
readonly adapter: MicroFrontendAdapter;
|
|
39
41
|
readonly nativeRuntime: NativeMicroFrontendRuntime;
|
|
40
42
|
readonly onPreloadError: (error: unknown) => void;
|
|
43
|
+
readonly onLifecycleEvent?: (event: MicroFrontendLifecycleEvent) => void;
|
|
41
44
|
readonly registry: MicroFrontendModuleRegistry;
|
|
42
45
|
readonly removePendingHostComponentRoutes: (appName: string) => void;
|
|
43
46
|
readonly parseEvent: (event: NativeMicroFrontendRuntimeEvent) => MicroFrontendRuntimeEvent;
|
|
@@ -90,7 +93,7 @@ export function createMicroFrontendRuntimeWithDependencies(
|
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
|
|
93
|
-
|
|
96
|
+
const runtime: MicroFrontendRuntimeApi = {
|
|
94
97
|
evaluateScript,
|
|
95
98
|
preloadApp,
|
|
96
99
|
async importApp<TModule>(request: AppRequest): Promise<TModule> {
|
|
@@ -120,4 +123,8 @@ export function createMicroFrontendRuntimeWithDependencies(
|
|
|
120
123
|
return subscription;
|
|
121
124
|
},
|
|
122
125
|
};
|
|
126
|
+
|
|
127
|
+
setMicroFrontendLifecycleCallback(runtime, dependencies.onLifecycleEvent);
|
|
128
|
+
|
|
129
|
+
return runtime;
|
|
123
130
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getMicroFrontendRuntimeContext, type AppContainer } from './registry';
|
|
2
|
+
import { captureStackFrames, resolveCurrentSourceURL, type RuntimeStackFrame } from './runtimeSourceURL';
|
|
3
|
+
|
|
4
|
+
export function resolveAppNameBySourceURL(
|
|
5
|
+
sourceURL: string,
|
|
6
|
+
containers: Readonly<Record<string, AppContainer>>
|
|
7
|
+
): string | null {
|
|
8
|
+
let resolvedAppName: string | null = null;
|
|
9
|
+
for (const container of Object.values(containers)) {
|
|
10
|
+
if (container.runtime?.sourceURL !== sourceURL) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
if (resolvedAppName != null && resolvedAppName !== container.appName) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
resolvedAppName = container.appName;
|
|
17
|
+
}
|
|
18
|
+
return resolvedAppName;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function findAppNameBySourceURL(sourceURL: string): string | null {
|
|
22
|
+
return resolveAppNameBySourceURL(sourceURL, getMicroFrontendRuntimeContext().containers);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function resolveAppNameFromStackFrames(
|
|
26
|
+
frames: readonly RuntimeStackFrame[],
|
|
27
|
+
containers: Readonly<Record<string, AppContainer>>
|
|
28
|
+
): string {
|
|
29
|
+
const sourceURL = resolveCurrentSourceURL(frames);
|
|
30
|
+
const appName = resolveAppNameBySourceURL(sourceURL, containers);
|
|
31
|
+
if (appName != null) {
|
|
32
|
+
return appName;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw new Error('Cannot resolve the current micro-frontend app name');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getAppName(): string {
|
|
39
|
+
const sourceURL = resolveCurrentSourceURL(captureStackFrames());
|
|
40
|
+
const appName = findAppNameBySourceURL(sourceURL);
|
|
41
|
+
if (appName != null) {
|
|
42
|
+
return appName;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
throw new Error('Cannot resolve the current micro-frontend app name');
|
|
46
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MicroFrontendLifecycleEvent } from '../types';
|
|
2
|
+
|
|
3
|
+
const lifecycleCallbackByRuntime = new WeakMap<object, (event: MicroFrontendLifecycleEvent) => void>();
|
|
4
|
+
|
|
5
|
+
export function setMicroFrontendLifecycleCallback(
|
|
6
|
+
runtime: object,
|
|
7
|
+
callback: ((event: MicroFrontendLifecycleEvent) => void) | undefined
|
|
8
|
+
): void {
|
|
9
|
+
if (callback == null) {
|
|
10
|
+
lifecycleCallbackByRuntime.delete(runtime);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
lifecycleCallbackByRuntime.set(runtime, callback);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function emitMicroFrontendLifecycleEvent(runtime: object, event: MicroFrontendLifecycleEvent): void {
|
|
18
|
+
const callback = lifecycleCallbackByRuntime.get(runtime);
|
|
19
|
+
if (callback == null) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
callback(event);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error('Failed to run a micro-frontend lifecycle callback', error);
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/runtime/registry.ts
CHANGED
|
@@ -16,10 +16,15 @@ export interface AppContainerConfig {
|
|
|
16
16
|
readonly shared?: SharedConfig;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export interface AppContainerRuntime {
|
|
20
|
+
readonly sourceURL: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
export interface AppContainer {
|
|
20
24
|
readonly appName: string;
|
|
21
25
|
readonly config: AppContainerConfig;
|
|
22
26
|
readonly exposedModules: Record<string, unknown>;
|
|
27
|
+
readonly runtime?: AppContainerRuntime;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
export type AppDisposeCallback = () => void | Promise<void>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface RuntimeStackFrame {
|
|
2
|
+
readonly sourceURL: string | null;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function captureStackFrames(): readonly RuntimeStackFrame[] {
|
|
6
|
+
const prepareStackTraceDescriptor = Object.getOwnPropertyDescriptor(Error, 'prepareStackTrace');
|
|
7
|
+
Object.defineProperty(Error, 'prepareStackTrace', {
|
|
8
|
+
configurable: true,
|
|
9
|
+
value: (_error: unknown, callSites: readonly unknown[]) => callSites,
|
|
10
|
+
writable: true,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const frames: RuntimeStackFrame[] = [];
|
|
14
|
+
try {
|
|
15
|
+
const callSites: unknown = new Error().stack;
|
|
16
|
+
if (!Array.isArray(callSites)) {
|
|
17
|
+
throw new Error('Cannot capture structured micro-frontend stack frames');
|
|
18
|
+
}
|
|
19
|
+
for (const callSite of callSites) {
|
|
20
|
+
if (typeof callSite !== 'object' || callSite == null) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (!('getFileName' in callSite)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const getFileName: unknown = 'getFileName' in callSite ? callSite.getFileName : undefined;
|
|
27
|
+
const sourceURL: unknown = typeof getFileName === 'function' ? getFileName.call(callSite) : null;
|
|
28
|
+
frames.push({ sourceURL: typeof sourceURL === 'string' ? sourceURL : null });
|
|
29
|
+
}
|
|
30
|
+
} finally {
|
|
31
|
+
if (prepareStackTraceDescriptor == null) {
|
|
32
|
+
Reflect.deleteProperty(Error, 'prepareStackTrace');
|
|
33
|
+
} else {
|
|
34
|
+
Object.defineProperty(Error, 'prepareStackTrace', prepareStackTraceDescriptor);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return frames;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function resolveCurrentSourceURL(frames: readonly RuntimeStackFrame[]): string {
|
|
42
|
+
for (const frame of frames) {
|
|
43
|
+
if (frame.sourceURL != null && frame.sourceURL.length > 0) {
|
|
44
|
+
return frame.sourceURL;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw new Error('Cannot determine the caller micro-frontend sourceURL');
|
|
48
|
+
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { useEffect, useLayoutEffect, useReducer, useRef } from 'react';
|
|
2
2
|
import { installPendingHostComponentBridge, resetPendingHostComponent } from '../host/pendingHostComponentStore';
|
|
3
|
+
import { emitMicroFrontendLifecycleEvent } from '../runtime/lifecycle';
|
|
3
4
|
import { disposeAppResources } from '../runtime/registry';
|
|
4
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
MicroFrontendLifecycleEvent,
|
|
7
|
+
MicroFrontendLifecycleSession,
|
|
8
|
+
MicroFrontendRuntimeApi,
|
|
9
|
+
MicroFrontendSessionEvent,
|
|
10
|
+
} from '../types';
|
|
5
11
|
|
|
6
12
|
export interface MicroFrontendSessionState {
|
|
7
13
|
readonly appName: string;
|
|
@@ -53,19 +59,46 @@ export function useMicroFrontendSessions(
|
|
|
53
59
|
previousSessionsRef.current = sessions;
|
|
54
60
|
const activeSessionIds = new Set(sessions.map(({ sessionId }) => sessionId));
|
|
55
61
|
const activeAppNames = new Set(sessions.map(({ appName }) => appName));
|
|
62
|
+
const mountedSessions = sessions.filter(
|
|
63
|
+
({ sessionId }) => !previousSessions.some((previousSession) => previousSession.sessionId === sessionId)
|
|
64
|
+
);
|
|
65
|
+
const inactiveSessions = previousSessions.filter(({ sessionId }) => !activeSessionIds.has(sessionId));
|
|
56
66
|
const inactiveAppNames = new Set(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
inactiveSessions.map(({ appName }) => appName).filter((appName) => !activeAppNames.has(appName))
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
mountedSessions.forEach((session) => {
|
|
71
|
+
emitMicroFrontendLifecycleEvent(runtime, createLifecycleEvent('mounted', session, sessions));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const appDisposals = new Map<string, Promise<void>>(
|
|
75
|
+
Array.from(
|
|
76
|
+
inactiveAppNames,
|
|
77
|
+
(appName) =>
|
|
78
|
+
[
|
|
79
|
+
appName,
|
|
80
|
+
disposeAppResources(appName).catch((error) => {
|
|
81
|
+
console.error(`Failed to dispose micro-frontend app resources for '${appName}'`, error);
|
|
82
|
+
}),
|
|
83
|
+
] as const
|
|
84
|
+
)
|
|
61
85
|
);
|
|
62
86
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
87
|
+
inactiveSessions.forEach((session) => {
|
|
88
|
+
const appDisposal = appDisposals.get(session.appName);
|
|
89
|
+
if (appDisposal == null) {
|
|
90
|
+
emitMicroFrontendLifecycleEvent(runtime, createLifecycleEvent('unmounted', session, sessions));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
void appDisposal.then(() => {
|
|
95
|
+
emitMicroFrontendLifecycleEvent(
|
|
96
|
+
runtime,
|
|
97
|
+
createLifecycleEvent('unmounted', session, previousSessionsRef.current)
|
|
98
|
+
);
|
|
66
99
|
});
|
|
67
100
|
});
|
|
68
|
-
}, [sessions]);
|
|
101
|
+
}, [runtime, sessions]);
|
|
69
102
|
|
|
70
103
|
useLayoutEffect(() => {
|
|
71
104
|
installPendingHostComponentBridge();
|
|
@@ -81,3 +114,22 @@ export function useMicroFrontendSessions(
|
|
|
81
114
|
|
|
82
115
|
return sessions;
|
|
83
116
|
}
|
|
117
|
+
|
|
118
|
+
function createLifecycleEvent(
|
|
119
|
+
phase: MicroFrontendLifecycleEvent['phase'],
|
|
120
|
+
session: MicroFrontendSessionState,
|
|
121
|
+
activeSessions: readonly MicroFrontendSessionState[]
|
|
122
|
+
): MicroFrontendLifecycleEvent {
|
|
123
|
+
return {
|
|
124
|
+
phase,
|
|
125
|
+
session: toLifecycleSession(session),
|
|
126
|
+
activeSessions: activeSessions.map(toLifecycleSession),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function toLifecycleSession(session: MicroFrontendSessionState): MicroFrontendLifecycleSession {
|
|
131
|
+
return {
|
|
132
|
+
appName: session.appName,
|
|
133
|
+
id: session.sessionId,
|
|
134
|
+
};
|
|
135
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -47,6 +47,20 @@ export interface MicroFrontendRuntimeEventSubscription {
|
|
|
47
47
|
readonly remove: () => void;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
export interface MicroFrontendLifecycleSession {
|
|
51
|
+
readonly appName: string;
|
|
52
|
+
readonly id: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface MicroFrontendLifecycleEvent {
|
|
56
|
+
readonly phase: 'mounted' | 'unmounted';
|
|
57
|
+
readonly session: MicroFrontendLifecycleSession;
|
|
58
|
+
/** Active sessions across every app when the callback is emitted. */
|
|
59
|
+
readonly activeSessions: readonly MicroFrontendLifecycleSession[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type MicroFrontendLifecycleCallback = (event: MicroFrontendLifecycleEvent) => void;
|
|
63
|
+
|
|
50
64
|
export interface MicroFrontendRuntimeApi {
|
|
51
65
|
readonly evaluateScript: (filePath: string) => Promise<void>;
|
|
52
66
|
readonly preloadApp: (appName: string) => Promise<void>;
|