@granite-js/micro-frontend 2.0.2 → 2.1.1

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +129 -55
  3. package/dist/module/host/pendingHostComponentStore.js +33 -14
  4. package/dist/module/host/pendingHostComponentStore.js.map +1 -1
  5. package/dist/module/index.js.map +1 -1
  6. package/dist/module/plugin/disposeBabelPlugin.js +38 -0
  7. package/dist/module/plugin/disposeBabelPlugin.js.map +1 -0
  8. package/dist/module/plugin/disposeTransform.js +37 -0
  9. package/dist/module/plugin/disposeTransform.js.map +1 -0
  10. package/dist/module/plugin/globalContextScript.js +121 -0
  11. package/dist/module/plugin/globalContextScript.js.map +1 -0
  12. package/dist/module/plugin/microFrontendPlugin.js +12 -1
  13. package/dist/module/plugin/microFrontendPlugin.js.map +1 -1
  14. package/dist/module/plugin/prelude.js +4 -2
  15. package/dist/module/plugin/prelude.js.map +1 -1
  16. package/dist/module/plugin/resolver.js +1 -1
  17. package/dist/module/plugin/resolver.js.map +1 -1
  18. package/dist/module/runtime/containerModuleExposure.js +79 -0
  19. package/dist/module/runtime/containerModuleExposure.js.map +1 -0
  20. package/dist/module/runtime/containerPairing.js +86 -0
  21. package/dist/module/runtime/containerPairing.js.map +1 -0
  22. package/dist/module/runtime/containerRegistry.js +190 -0
  23. package/dist/module/runtime/containerRegistry.js.map +1 -0
  24. package/dist/module/runtime/createMicroFrontendRuntime.js +11 -6
  25. package/dist/module/runtime/createMicroFrontendRuntime.js.map +1 -1
  26. package/dist/module/runtime/globalContext.js +89 -0
  27. package/dist/module/runtime/globalContext.js.map +1 -0
  28. package/dist/module/runtime/nativeComponentRegistryCompatibility.js +53 -0
  29. package/dist/module/runtime/nativeComponentRegistryCompatibility.js.map +1 -0
  30. package/dist/module/runtime/registry.js +103 -45
  31. package/dist/module/runtime/registry.js.map +1 -1
  32. package/dist/module/session/useMicroFrontendSessions.js +23 -1
  33. package/dist/module/session/useMicroFrontendSessions.js.map +1 -1
  34. package/dist/typescript/index.d.ts +1 -0
  35. package/dist/typescript/plugin/disposeBabelPlugin.d.ts +8 -0
  36. package/dist/typescript/plugin/disposeTransform.d.ts +3 -0
  37. package/dist/typescript/plugin/globalContextScript.d.ts +1 -0
  38. package/dist/typescript/runtime/containerModuleExposure.d.ts +2 -0
  39. package/dist/typescript/runtime/containerPairing.d.ts +18 -0
  40. package/dist/typescript/runtime/containerRegistry.d.ts +6 -0
  41. package/dist/typescript/runtime/globalContext.d.ts +17 -0
  42. package/dist/typescript/runtime/nativeComponentRegistryCompatibility.d.ts +1 -0
  43. package/dist/typescript/runtime/registry.d.ts +10 -8
  44. package/package.json +7 -4
  45. package/src/host/pendingHostComponentStore.ts +58 -29
  46. package/src/index.ts +1 -0
  47. package/src/plugin/disposeBabelPlugin.ts +51 -0
  48. package/src/plugin/disposeTransform.ts +43 -0
  49. package/src/plugin/globalContextScript.ts +118 -0
  50. package/src/plugin/microFrontendPlugin.ts +13 -1
  51. package/src/plugin/prelude.ts +160 -20
  52. package/src/plugin/resolver.ts +1 -1
  53. package/src/runtime/containerModuleExposure.ts +92 -0
  54. package/src/runtime/containerPairing.ts +120 -0
  55. package/src/runtime/containerRegistry.ts +239 -0
  56. package/src/runtime/createMicroFrontendRuntime.ts +10 -2
  57. package/src/runtime/globalContext.ts +164 -0
  58. package/src/runtime/nativeComponentRegistryCompatibility.ts +60 -0
  59. package/src/runtime/registry.ts +151 -58
  60. package/src/session/useMicroFrontendSessions.ts +26 -16
@@ -3,6 +3,7 @@
3
3
  import * as fs from 'fs';
4
4
  import * as path from 'path';
5
5
  import { prepareLocalDirectory } from '@granite-js/utils';
6
+ import { transformDisposeOwnership } from "./disposeTransform.js";
6
7
  import { intoShared } from "./intoShared.js";
7
8
  import { getPreludeConfig } from "./prelude.js";
8
9
  import { createSharedResolverConfig } from "./resolver.js";
@@ -14,10 +15,15 @@ export async function microFrontend(options = {}) {
14
15
  };
15
16
  const nonEagerEntries = Object.entries(shared ?? {}).filter(([, config]) => config.eager !== true);
16
17
  const localDirectory = prepareLocalDirectory(process.cwd());
17
- const preludePath = path.join(localDirectory, 'micro-frontend-runtime.js');
18
+ // Keep this path distinct from @granite-js/plugin-micro-frontend's generated prelude.
19
+ // Both plugins can coexist while consumers migrate, and sharing a path makes the
20
+ // later plugin overwrite the earlier plugin's runtime registrations.
21
+ const preludePath = path.join(localDirectory, 'granite-micro-frontend-runtime.js');
18
22
  const prelude = getPreludeConfig(normalizedOptions);
19
23
  const resolver = createSharedResolverConfig(nonEagerEntries);
24
+ const disposeOwnershipOptions = {};
20
25
  function writePrelude(appName) {
26
+ disposeOwnershipOptions.appName = appName;
21
27
  const config = getPreludeConfig(normalizedOptions, appName);
22
28
  fs.writeFileSync(preludePath, config.preludeScript, 'utf8');
23
29
  }
@@ -46,6 +52,11 @@ export async function microFrontend(options = {}) {
46
52
  skipReactNativePolyfills: true
47
53
  } : undefined,
48
54
  resolver,
55
+ transformer: {
56
+ transformSync(id, code) {
57
+ return transformDisposeOwnership(id, code, disposeOwnershipOptions);
58
+ }
59
+ },
49
60
  esbuild: {
50
61
  prelude: [preludePath],
51
62
  banner: {
@@ -1 +1 @@
1
- {"version":3,"names":["fs","path","prepareLocalDirectory","intoShared","getPreludeConfig","createSharedResolverConfig","microFrontend","options","shared","normalizedOptions","nonEagerEntries","Object","entries","filter","config","eager","localDirectory","process","cwd","preludePath","join","prelude","resolver","writePrelude","appName","writeFileSync","preludeScript","name","dev","order","handler","build","extra","some","moduleName","skipReactNativeInitializeCore","skipReactNativePolyfills","undefined","esbuild","banner","js"],"sourceRoot":"../../../src","sources":["plugin/microFrontendPlugin.ts"],"mappings":";;AAAA,OAAO,KAAKA,EAAE,MAAM,IAAI;AACxB,OAAO,KAAKC,IAAI,MAAM,MAAM;AAE5B,SAASC,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,UAAU,QAAQ,iBAAc;AACzC,SAASC,gBAA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AAE;MACNkB,KAAK,EAAEtB,eAAe,CAACuB,IAAI,CAAC,CAAC,CAACC,UAAU,CAAC,KAAKA,UAAU,KAAK,cAAc,CAAC,GACxE;QACEC,6BAA6B,EAAE,IAAI;QACnCC,wBAAwB,EAAE;MAC5B,CAAC,GACDC,SAAS;MACbf,QAAQ;MACRgB,OAAO,EAAE;QACPjB,OAAO,EAAE,CAACF,WAAW,CAAC;QACtBoB,MAAM,EAAE;UAAEC,EAAE,EAAEnB,OAAO,CAACkB;QAAO;MAC/B;IACF;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["fs","path","prepareLocalDirectory","transformDisposeOwnership","intoShared","getPreludeConfig","createSharedResolverConfig","microFrontend","options","shared","normalizedOptions","nonEagerEntries","Object","entries","filter","config","eager","localDirectory","process","cwd","preludePath","join","prelude","resolver","disposeOwnershipOptions","writePrelude","appName","writeFileSync","preludeScript","name","dev","order","handler","build","extra","some","moduleName","skipReactNativeInitializeCore","skipReactNativePolyfills","undefined","transformer","transformSync","id","code","esbuild","banner","js"],"sourceRoot":"../../../src","sources":["plugin/microFrontendPlugin.ts"],"mappings":";;AAAA,OAAO,KAAKA,EAAE,MAAM,IAAI;AACxB,OAAO,KAAKC,IAAI,MAAM,MAAM;AAE5B,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,SAASC,yBAAyB,QAAQ,uBAAoB;AAC9D,SAASC,UAAU,QAAQ,iBAAc;AACzC,SAASC,gBAAgB,QAAQ,cAAW;AAC5C,SAASC,0BAA0B,QAAQ,eAAY;AAGvD,OAAO,eAAeC,aAAaA,CAACC,OAAmC,GAAG,CAAC,CAAC,EAA8B;EACxG,MAAMC,MAAM,GAAGL,UAAU,CAACI,OAAO,CAACC,MAAM,CAAC;EACzC,MAAMC,iBAA6C,GAAG;IACpD,GAAGF,OAAO;IACVC;EACF,CAAC;EACD,MAAME,eAAe,GAAGC,MAAM,CAACC,OAAO,CAACJ,MAAM,IAAI,CAAC,CAAC,CAAC,CAACK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aA,CAACC,EAAE,EAAEC,IAAI,EAAE;UACtB,OAAOxC,yBAAyB,CAACuC,EAAE,EAAEC,IAAI,EAAEnB,uBAAuB,CAAC;QACrE;MACF,CAAC;MACDoB,OAAO,EAAE;QACPtB,OAAO,EAAE,CAACF,WAAW,CAAC;QACtByB,MAAM,EAAE;UAAEC,EAAE,EAAExB,OAAO,CAACuB;QAAO;MAC/B;IACF;EACF,CAAC;AACH","ignoreList":[]}
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  import path from 'path';
4
+ import { globalContextScript } from "./globalContextScript.js";
5
+ import { CONTAINER_PAIRING_KEY } from "../runtime/containerPairing.js";
4
6
  export function getPreludeConfig(options, appName) {
5
7
  const eagerSharedModules = Object.entries(options.shared ?? {}).filter(([, config]) => !Array.isArray(options.shared) && config.eager === true);
6
8
  const registerStatements = eagerSharedModules.map(([moduleName], index) => {
@@ -16,8 +18,8 @@ export function getPreludeConfig(options, appName) {
16
18
  });
17
19
  const containerName = appName == null ? 'global.__granite.app.name' : JSON.stringify(appName);
18
20
  return {
19
- banner: ['global._graniteMicroFrontend = global._graniteMicroFrontend || {', ' containers: {},', ' sharedModules: {},', '};'].join('\n'),
20
- preludeScript: ['function createContainer(appName, config) {', ' const containers = global._graniteMicroFrontend.containers;', ' if (containers[appName] != null) {', ' throw new Error(`App container \'${appName}\' is already registered`);', ' }', ' const container = { appName, config, exposedModules: {} };', ' containers[appName] = container;', ' return container;', '}', 'function exposeModule(container, exposedModule, moduleValue) {', " const normalizedModule = exposedModule.startsWith('./') ? exposedModule : `./${exposedModule}`;", ' if (container.exposedModules[normalizedModule] != null) {', ' throw new Error(`Exposed module \'${normalizedModule}\' is already registered in app container \'${container.appName}\'`);', ' }', ' container.exposedModules[normalizedModule] = moduleValue;', '}', 'function registerShared(moduleName, moduleValue) {', ' const sharedModules = global._graniteMicroFrontend.sharedModules;', ' const existingModule = sharedModules[moduleName];', ' if (existingModule != null) {', ' if (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')
21
+ 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')
21
23
  };
22
24
  }
23
25
  //# sourceMappingURL=prelude.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["path","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;AAQvB,OAAO,SAASC,gBAAgBA,CAC9BC,OAAmC,EACnCC,OAAgB,EACY;EAC5B,MAAMC,kBAAkB,GAAGC,MAAM,CAACC,OAAO,CAACJ,OAAO,CAACK,MAAM,IAAI,CAAC,CAAC,CAAC,CAACC,MAAM,CACpE,CAAC,GAAGC,MAAM,CAAC,KAAK,CAACC,KAAK,CAACC,OAAO,CAACT,OAAO,CAACK,MAAM,CAAC,IAAIE,MAAM,CAACG,KAAK,KAAK,IACrE,CAAC;EACD,MAAMC,kBAAkB,GA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BAAqB,EACrB,GAAG,EACH,gEAAgE,EAChE,mGAAmG,EACnG,6DAA6D,EAC7D,gIAAgI,EAChI,KAAK,EACL,6DAA6D,EAC7D,GAAG,EACH,oDAAoD,EACpD,qEAAqE,EACrE,qDAAqD,EACrD,iCAAiC,EACjC,yDAAyD,EACzD,eAAe,EACf,OAAO,EACP,+EAA+E,EAC/E,KAAK,EACL,yEAAyE,EACzE,GAAG,EACH,uCAAuCF,aAAa,KAAKD,eAAe,IAAI,EAC5E,GAAGb,kBAAkB,EACrB,GAAGQ,gBAAgB,CACpB,CAACD,IAAI,CAAC,IAAI;EACb,CAAC;AACH","ignoreList":[]}
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;AAOnE,OAAO,SAASC,gBAAgBA,CAACC,OAAmC,EAAEC,OAAgB,EAA8B;EAClH,MAAMC,kBAAkB,GAAGC,MAAM,CAACC,OAAO,CAACJ,OAAO,CAACK,MAAM,IAAI,CAAC,CAAC,CAAC,CAACC,MAAM,CACpE,CAAC,GAAGC,MAAM,CAAC,KAAK,CAACC,KAAK,CAACC,OAAO,CAACT,OAAO,CAACK,MAAM,CAAC,IAAIE,MAAM,CAACG,KAAK,KAAK,IACrE,CAAC;EACD,MAAMC,kBAAkB,GAAGT,kBAAkB,CAACU,GAAG,CAAC,CAAC,CAACC,UAAU,CAAC,EAAEC,KAAK,KAAK;IACzE,MAAMC,UAAU,GAAG,WAAWD,KAAK,EAAE;IACrC,OAAO,CACL,eAAeC,UAAU,SAASC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+E,EAC/E,aAAa,EACb,8DAA8D,EAC9D,sEAAsE,EACtE,mBAAmB,EACnB,SAAS,EACT,2FAA2F,EAC3F,iGAAiG,EACjG,gHAAgH,EAChH,sFAAsF,EACtF,mBAAmB,EACnB,SAAS,EACT,oEAAoE,EACpE,kDAAkD,EAClD,4EAA4E,EAC5E,aAAa,EACb,4GAA4G,EAC5G,SAAS,EACT,OAAO,EACP,gGAAgG,EAChG,kDAAkD,EAClD,oCAAoC,EACpC,kBAAkB,EAClB,2BAA2B,EAC3B,+BAA+B,EAC/B,yEAAyE,EACzE,kDAAkD,EAClD,UAAU,EACV,SAAS,EACT,KAAK,EACL,SAAS,EACT,yGAAyG,EACzG,0GAA0G,EAC1G,OAAO,EACP,oCAAoC,EACpC,wEAAwE,EACxE,6BAA6B,EAC7B,2BAA2B,EAC3B,yDAAyD,EACzD,WAAW,EACX,OAAO,EACP,qBAAqB,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,uCAAuC2B,aAAa,KAAKD,eAAe,IAAI,EAC5E,GAAGb,kBAAkB,EACrB,GAAGQ,gBAAgB,CACpB,CAACD,IAAI,CAAC,IAAI;EACb,CAAC;AACH","ignoreList":[]}
@@ -15,7 +15,7 @@ export function createSharedResolverConfig(moduleEntries) {
15
15
  const moduleName = JSON.stringify(args.path);
16
16
  return {
17
17
  loader: 'js',
18
- contents: [`var sharedModule = global._graniteMicroFrontend.sharedModules[${moduleName}];`, 'if (sharedModule == null) {', ` throw new Error('Shared module ' + ${moduleName} + ' is not registered');`, '}', 'var sharedExports = sharedModule.get();', 'var moduleExports = {};', 'if (sharedExports != null) {', ' var sharedKeys = Reflect.ownKeys(sharedExports);', ' for (var i = 0; i < sharedKeys.length; i++) {', ' var sharedKey = sharedKeys[i];', ' var sharedDescriptor = Object.getOwnPropertyDescriptor(sharedExports, sharedKey);', ' if (sharedDescriptor == null || sharedDescriptor.enumerable !== true) {', ' continue;', ' }', ' (function (key) {', ' Object.defineProperty(moduleExports, key, {', ' enumerable: true,', ' configurable: true,', ' get: function () {', ' return sharedExports[key];', ' },', ' set: function (value) {', ' Object.defineProperty(moduleExports, key, {', ' enumerable: true,', ' configurable: true,', ' writable: true,', ' value: value,', ' });', ' },', ' });', ' })(sharedKey);', ' }', '}', "Object.defineProperty(moduleExports, '__esModule', {", ' enumerable: true,', ' configurable: true,', ' writable: true,', ' value: true,', '});', 'module.exports = moduleExports;'].join('\n')
18
+ contents: [`var sharedModule = global.__MICRO_FRONTEND__.__SHARED__[${moduleName}];`, 'if (sharedModule == null) {', ` throw new Error('Shared module ' + ${moduleName} + ' is not registered');`, '}', 'var sharedExports = sharedModule.get();', 'var moduleExports = {};', 'if (sharedExports != null) {', ' var sharedKeys = Reflect.ownKeys(sharedExports);', ' for (var i = 0; i < sharedKeys.length; i++) {', ' var sharedKey = sharedKeys[i];', ' var sharedDescriptor = Object.getOwnPropertyDescriptor(sharedExports, sharedKey);', ' if (sharedDescriptor == null || sharedDescriptor.enumerable !== true) {', ' continue;', ' }', ' (function (key) {', ' Object.defineProperty(moduleExports, key, {', ' enumerable: true,', ' configurable: true,', ' get: function () {', ' return sharedExports[key];', ' },', ' set: function (value) {', ' Object.defineProperty(moduleExports, key, {', ' enumerable: true,', ' configurable: true,', ' writable: true,', ' value: value,', ' });', ' },', ' });', ' })(sharedKey);', ' }', '}', "Object.defineProperty(moduleExports, '__esModule', {", ' enumerable: true,', ' configurable: true,', ' writable: true,', ' value: true,', '});', 'module.exports = moduleExports;'].join('\n')
19
19
  };
20
20
  }
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"names":["VIRTUAL_SHARED_PROTOCOL","createSharedResolverConfig","moduleEntries","alias","map","moduleName","exact","from","to","protocols","length","undefined","load","args","JSON","stringify","path","loader","contents","join"],"sourceRoot":"../../../src","sources":["plugin/resolver.ts"],"mappings":";;AAGA,MAAMA,uBAAuB,GAAG,+BAA+B;AAE/D,OAAO,SAASC,0BAA0BA,CACxCC,aAAiE,EACpB;EAC7C,MAAMC,KAA8B,GAAGD,aAAa,CAACE,GAAG,CAAC,CAAC,CAACC,UAAU,CAAC,MAAM;IAC1EC,KAAK,EAAE,IAAI;IACXC,IAAI,EAAEF,UAAU;IAChBG,EAAE,EAAE,GAAGR,uBAAuB,IAAIK,UAAU;EAC9C,CAAC,CAAC,CAAC;EAEH,OAAO;IACLF,KAAK;IACLM,SAAS,EACPN,KAAK,CAACO,MAAM,KAAK,CAAC,GACdC,SAAS,GACT;MACE,CAACX,uBAAuB,GAAG;QACzBY,IAAIA,CAACC,IAA+B,EAAE;UACpC,MAAMR,UAAU,GAAGS,IAAI,CAACC,SAAS,CAACF,IAAI,CAACG,IAAI,CAAC;UAC5C,OAAO;YACLC,MAAM,EAAE,IAAI;YACZC,QAAQ,EAAE,CACR,iEAAiEb,UAAU,IAAI,EAC/E,6BAA6B,EAC7B,wCAAwCA,UAAU,2BAA2B,EAC7E,GAAG,EACH,yCAAyC,EACzC,yBAAyB,EACzB,8BAA8B,EAC9B,oDAAoD,EACpD,iDAAiD,EACjD,oCAAoC,EACpC,uFAAuF,EACvF,6EAA6E,EAC7E,iBAAiB,EACjB,OAAO,EACP,uBAAuB,EACvB,mDAAmD,EACnD,2BAA2B,EAC3B,6BAA6B,EAC7B,4BAA4B,EAC5B,sCAAsC,EACtC,YAAY,EACZ,iCAAiC,EACjC,uDAAuD,EACvD,+BAA+B,EAC/B,iCAAiC,EACjC,6BAA6B,EAC7B,2BAA2B,EAC3B,eAAe,EACf,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,KAAK,EACL,GAAG,EACH,sDAAsD,EACtD,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,EACL,iCAAiC,CAClC,CAACc,IAAI,CAAC,IAAI;UACb,CAAC;QACH;MACF;IACF;EACR,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["VIRTUAL_SHARED_PROTOCOL","createSharedResolverConfig","moduleEntries","alias","map","moduleName","exact","from","to","protocols","length","undefined","load","args","JSON","stringify","path","loader","contents","join"],"sourceRoot":"../../../src","sources":["plugin/resolver.ts"],"mappings":";;AAGA,MAAMA,uBAAuB,GAAG,+BAA+B;AAE/D,OAAO,SAASC,0BAA0BA,CACxCC,aAAiE,EACpB;EAC7C,MAAMC,KAA8B,GAAGD,aAAa,CAACE,GAAG,CAAC,CAAC,CAACC,UAAU,CAAC,MAAM;IAC1EC,KAAK,EAAE,IAAI;IACXC,IAAI,EAAEF,UAAU;IAChBG,EAAE,EAAE,GAAGR,uBAAuB,IAAIK,UAAU;EAC9C,CAAC,CAAC,CAAC;EAEH,OAAO;IACLF,KAAK;IACLM,SAAS,EACPN,KAAK,CAACO,MAAM,KAAK,CAAC,GACdC,SAAS,GACT;MACE,CAACX,uBAAuB,GAAG;QACzBY,IAAIA,CAACC,IAA+B,EAAE;UACpC,MAAMR,UAAU,GAAGS,IAAI,CAACC,SAAS,CAACF,IAAI,CAACG,IAAI,CAAC;UAC5C,OAAO;YACLC,MAAM,EAAE,IAAI;YACZC,QAAQ,EAAE,CACR,2DAA2Db,UAAU,IAAI,EACzE,6BAA6B,EAC7B,wCAAwCA,UAAU,2BAA2B,EAC7E,GAAG,EACH,yCAAyC,EACzC,yBAAyB,EACzB,8BAA8B,EAC9B,oDAAoD,EACpD,iDAAiD,EACjD,oCAAoC,EACpC,uFAAuF,EACvF,6EAA6E,EAC7E,iBAAiB,EACjB,OAAO,EACP,uBAAuB,EACvB,mDAAmD,EACnD,2BAA2B,EAC3B,6BAA6B,EAC7B,4BAA4B,EAC5B,sCAAsC,EACtC,YAAY,EACZ,iCAAiC,EACjC,uDAAuD,EACvD,+BAA+B,EAC/B,iCAAiC,EACjC,6BAA6B,EAC7B,2BAA2B,EAC3B,eAAe,EACf,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,KAAK,EACL,GAAG,EACH,sDAAsD,EACtD,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,EACL,iCAAiC,CAClC,CAACc,IAAI,CAAC,IAAI;UACb,CAAC;QACH;MACF;IACF;EACR,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ import { getLegacyContainerPair } from "./containerPairing.js";
4
+ import { ExposedModuleAlreadyRegisteredError } from "./errors.js";
5
+ import { getMicroFrontendGlobalContext, MicroFrontendGlobalContextCompatibilityError } from "./globalContext.js";
6
+ export function exposeContainerModule(container, exposedModule, module) {
7
+ const normalizedModule = normalizeExposedModule(exposedModule);
8
+ const legacyModule = normalizeLegacyModule(exposedModule);
9
+ const legacyContainer = getLegacyContainerPair(container);
10
+ if (Reflect.has(container.exposedModules, normalizedModule) || legacyContainer != null && Reflect.has(legacyContainer.exposeMap, legacyModule)) {
11
+ throw new ExposedModuleAlreadyRegisteredError(container.appName, normalizedModule);
12
+ }
13
+ const ownsModernContainer = Object.is(Reflect.get(getMicroFrontendGlobalContext().__CONTAINERS__, container.appName), container);
14
+ const legacyModuleValue = legacyContainer == null ? module : toLegacyEsm(module);
15
+ try {
16
+ if (ownsModernContainer && !Reflect.set(container.exposedModules, normalizedModule, module)) {
17
+ throw new MicroFrontendGlobalContextCompatibilityError('registry-is-not-extensible');
18
+ }
19
+ if (legacyContainer != null && !Reflect.defineProperty(legacyContainer.exposeMap, legacyModule, {
20
+ configurable: true,
21
+ enumerable: true,
22
+ get: () => legacyModuleValue
23
+ })) {
24
+ throw new MicroFrontendGlobalContextCompatibilityError('registry-is-not-extensible');
25
+ }
26
+ } catch (error) {
27
+ if (ownsModernContainer) {
28
+ Reflect.deleteProperty(container.exposedModules, normalizedModule);
29
+ }
30
+ if (legacyContainer != null) {
31
+ Reflect.deleteProperty(legacyContainer.exposeMap, legacyModule);
32
+ }
33
+ throw error;
34
+ }
35
+ }
36
+ function toLegacyEsm(module) {
37
+ if ((typeof module !== 'object' || module == null) && typeof module !== 'function') {
38
+ return module;
39
+ }
40
+ if (Reflect.get(module, '__esModule') === true) {
41
+ return module;
42
+ }
43
+ const legacyModule = typeof module === 'function' ? function (...args) {
44
+ return Reflect.apply(module, this, args);
45
+ } : {};
46
+ for (const exportName of Reflect.ownKeys(module)) {
47
+ if (exportName === '__esModule' || exportName === 'default') {
48
+ continue;
49
+ }
50
+ const sourceDescriptor = Reflect.getOwnPropertyDescriptor(module, exportName);
51
+ const facadeDescriptor = Reflect.getOwnPropertyDescriptor(legacyModule, exportName);
52
+ if (sourceDescriptor == null || facadeDescriptor?.configurable === false) {
53
+ // Callable facades keep intrinsic non-configurable slots such as prototype.
54
+ continue;
55
+ }
56
+ Reflect.defineProperty(legacyModule, exportName, {
57
+ enumerable: sourceDescriptor.enumerable,
58
+ get: () => Reflect.get(module, exportName)
59
+ });
60
+ }
61
+ const hasDefaultExport = Reflect.getOwnPropertyDescriptor(module, 'default') != null;
62
+ Object.defineProperties(legacyModule, {
63
+ __esModule: {
64
+ value: true
65
+ },
66
+ default: {
67
+ enumerable: true,
68
+ get: hasDefaultExport ? () => Reflect.get(module, 'default') : () => module
69
+ }
70
+ });
71
+ return legacyModule;
72
+ }
73
+ function normalizeExposedModule(exposedModule) {
74
+ return exposedModule.startsWith('./') ? exposedModule : `./${exposedModule}`;
75
+ }
76
+ function normalizeLegacyModule(exposedModule) {
77
+ return exposedModule.startsWith('./') ? exposedModule.slice(2) : exposedModule;
78
+ }
79
+ //# sourceMappingURL=containerModuleExposure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getLegacyContainerPair","ExposedModuleAlreadyRegisteredError","getMicroFrontendGlobalContext","MicroFrontendGlobalContextCompatibilityError","exposeContainerModule","container","exposedModule","module","normalizedModule","normalizeExposedModule","legacyModule","normalizeLegacyModule","legacyContainer","Reflect","has","exposedModules","exposeMap","appName","ownsModernContainer","Object","is","get","__CONTAINERS__","legacyModuleValue","toLegacyEsm","set","defineProperty","configurable","enumerable","error","deleteProperty","args","apply","exportName","ownKeys","sourceDescriptor","getOwnPropertyDescriptor","facadeDescriptor","hasDefaultExport","defineProperties","__esModule","value","default","startsWith","slice"],"sourceRoot":"../../../src","sources":["runtime/containerModuleExposure.ts"],"mappings":";;AAAA,SAASA,sBAAsB,QAAQ,uBAAoB;AAC3D,SAASC,mCAAmC,QAAQ,aAAU;AAC9D,SAASC,6BAA6B,EAAEC,4CAA4C,QAAQ,oBAAiB;AAG7G,OAAO,SAASC,qBAAqBA,CAACC,SAAuB,EAAEC,aAAqB,EAAEC,MAAe,EAAQ;EAC3G,MAAMC,gBAAgB,GAAGC,sBAAsB,CAACH,aAAa,CAAC;EAC9D,MAAMI,YAAY,GAAGC,qBAAqB,CAACL,aAAa,CAAC;EACzD,MAAMM,eAAe,GAAGZ,sBAAsB,CAACK,SAAS,CAAC;EACzD,IACEQ,OAAO,CAACC,GAAG,CAACT,SAAS,CAACU,cAAc,EAAEP,gBAAgB,CAAC,IACtDI,eAAe,IAAI,IAAI,IAAIC,OAAO,CAACC,GAAG,CAACF,eAAe,CAACI,SAAS,EAAEN,YAAY,CAAE,EACjF;IACA,MAAM,IAAIT,mCAAmC,CAACI,SAAS,CAACY,OAAO,EAAET,gBAAgB,CAAC;EACpF;EAEA,MAAMU,mBAAmB,GAAGC,MAAM,CAACC,EAAE,CACnCP,OAAO,CAACQ,GAAG,CAACnB,6BAA6B,CAAC,CAAC,CAACoB,cAAc,EAAEjB,SAAS,CAACY,OAAO,CAAC,EAC9EZ,SACF,CAAC;EACD,MAAMkB,iBAAiB,GAAGX,eAAe,IAAI,IAAI,GAAGL,MAAM,GAAGiB,WAAW,CAACjB,MAAM,C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,aAAa,CAACsC,KAAK,CAAC,CAAC,CAAC,GAAGtC,aAAa;AAChF","ignoreList":[]}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ export const CONTAINER_PAIRING_KEY = 'granite.micro-frontend.container-pair';
4
+ const containerPairingSymbol = Symbol.for(CONTAINER_PAIRING_KEY);
5
+ const pairedLegacyByModern = new WeakMap();
6
+ const pairedModernByLegacy = new WeakMap();
7
+ const legacyAdapters = new WeakSet();
8
+ export function defineContainerPair(first, second) {
9
+ try {
10
+ if (!definePairMarker(first, second) || !definePairMarker(second, first)) {
11
+ clearContainerPair(first, second);
12
+ return false;
13
+ }
14
+ } catch (error) {
15
+ clearContainerPair(first, second);
16
+ throw error;
17
+ }
18
+ return true;
19
+ }
20
+ export function isContainerPair(first, second) {
21
+ return hasPairMarker(first, second) && hasPairMarker(second, first);
22
+ }
23
+ export function getContainerPair(container) {
24
+ const descriptor = Reflect.getOwnPropertyDescriptor(container, containerPairingSymbol);
25
+ if (!isPairDescriptor(descriptor) || !isObject(descriptor.value)) {
26
+ return null;
27
+ }
28
+ return hasPairMarker(descriptor.value, container) ? descriptor.value : null;
29
+ }
30
+ export function clearContainerPair(first, second) {
31
+ Reflect.deleteProperty(first, containerPairingSymbol);
32
+ Reflect.deleteProperty(second, containerPairingSymbol);
33
+ }
34
+ export function rememberContainerPair(modern, legacy) {
35
+ pairedLegacyByModern.set(modern, legacy);
36
+ pairedModernByLegacy.set(legacy, modern);
37
+ }
38
+ export function rememberLegacyAdapterPair(modern, legacy) {
39
+ rememberContainerPair(modern, legacy);
40
+ legacyAdapters.add(modern);
41
+ }
42
+ export function getLegacyContainerPair(modern) {
43
+ const markedPair = getContainerPair(modern);
44
+ if (isLegacyAppContainer(markedPair) && markedPair.name === modern.appName) {
45
+ rememberContainerPair(modern, markedPair);
46
+ return markedPair;
47
+ }
48
+ return legacyAdapters.has(modern) ? pairedLegacyByModern.get(modern) : undefined;
49
+ }
50
+ export function getModernContainerPair(legacy) {
51
+ return pairedModernByLegacy.get(legacy);
52
+ }
53
+ export function forgetContainerPair(modern, legacy) {
54
+ if (modern != null) {
55
+ pairedLegacyByModern.delete(modern);
56
+ legacyAdapters.delete(modern);
57
+ }
58
+ if (legacy != null) {
59
+ pairedModernByLegacy.delete(legacy);
60
+ }
61
+ }
62
+ export function isLegacyAppContainer(value) {
63
+ return isObjectRecord(value) && typeof Reflect.get(value, 'name') === 'string' && isObjectRecord(Reflect.get(value, 'config')) && isObjectRecord(Reflect.get(value, 'exposeMap'));
64
+ }
65
+ function definePairMarker(container, pair) {
66
+ return Reflect.defineProperty(container, containerPairingSymbol, {
67
+ configurable: true,
68
+ enumerable: false,
69
+ value: pair,
70
+ writable: false
71
+ });
72
+ }
73
+ function hasPairMarker(container, pair) {
74
+ const descriptor = Reflect.getOwnPropertyDescriptor(container, containerPairingSymbol);
75
+ return isPairDescriptor(descriptor) && Object.is(descriptor.value, pair);
76
+ }
77
+ function isPairDescriptor(descriptor) {
78
+ return descriptor != null && descriptor.configurable === true && descriptor.enumerable === false && descriptor.writable === false && Reflect.has(descriptor, 'value');
79
+ }
80
+ export function isObjectRecord(value) {
81
+ return typeof value === 'object' && value != null && !Array.isArray(value);
82
+ }
83
+ function isObject(value) {
84
+ return typeof value === 'object' && value != null || typeof value === 'function';
85
+ }
86
+ //# sourceMappingURL=containerPairing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CONTAINER_PAIRING_KEY","containerPairingSymbol","Symbol","for","pairedLegacyByModern","WeakMap","pairedModernByLegacy","legacyAdapters","WeakSet","defineContainerPair","first","second","definePairMarker","clearContainerPair","error","isContainerPair","hasPairMarker","getContainerPair","container","descriptor","Reflect","getOwnPropertyDescriptor","isPairDescriptor","isObject","value","deleteProperty","rememberContainerPair","modern","legacy","set","rememberLegacyAdapterPair","add","getLegacyContainerPair","markedPair","isLegacyAppContainer","name","appName","has","get","undefined","getModernContainerPair","forgetContainerPair","delete","isObjectRecord","pair","defineProperty","configurable","enumerable","writable","Object","is","Array","isArray"],"sourceRoot":"../../../src","sources":["runtime/containerPairing.ts"],"mappings":";;AAEA,OAAO,MAAMA,qBAAqB,GAAG,uCAAgD;AAErF,MAAMC,sBAAsB,GAAGC,MAAM,CAACC,GAAG,CAACH,qBAAqB,CAAC;AAChE,MAAMI,oBAAoB,GAAG,IAAIC,OAAO,CAAmC,CAAC;AAC5E,MAAMC,oBAAoB,GAAG,IAAID,OAAO,CAAmC,CAAC;AAC5E,MAAME,cAAc,GAAG,IAAIC,OAAO,CAAe,CAAC;AAQlD,OAAO,SAASC,mBAAmBA,CAACC,KAAa,EAAEC,MAAc,EAAW;EAC1E,IAAI;IACF,IAAI,CAACC,gBAAgB,CAACF,KAAK,EAAEC,MAAM,CAAC,IAAI,CAACC,gBAAgB,CAACD,MAAM,EAAED,KAAK,CAAC,EAAE;MACxEG,kBAAkB,CAACH,KAAK,EAAEC,MAAM,CAAC;MACjC,OAAO,KAAK;IACd;EACF,CAAC,CAAC,OAAOG,KAAK,EAAE;IACdD,kBAAkB,CAACH,KAAK,EAAEC,MAAM,CAAC;IACjC,MAAMG,KAAK;EACb;EACA,OAAO,IAAI;AACb;AAEA,OAAO,SAASC,eAAeA,CAACL,KAAa,EAAEC,MAAc,EAAW;EACtE,OAAOK,aAAa,CAACN,KAAK,EAAEC,MAAM,CAAC,IAAIK,aAAa,CAACL,MAAM,EAAED,KAAK,CAAC;AACrE;AAEA,OAAO,SAASO,gBAAgBA,CAACC,SAAiB,EAAiB;EACjE,MAAMC,UAAU,GAAGC,OAAO,CAACC,wBAAwB,CAACH,SAAS,EAAEjB,sBAAsB,CAAC;EACtF,IAAI,CAACqB,gBAAgB,CAACH,UAAU,CAAC,IAAI,CAACI,QAAQ,CAACJ,UAAU,CAACK,KAAK,CAAC,EAAE;IAChE,OAAO,IAAI;EACb;EACA,OAAOR,aAAa,CAACG,UAAU,CAACK,KAAK,EAAEN,SAAS,CAAC,GAAGC,UAAU,CAACK,KAAK,GAAG,IAAI;AAC7E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AcA,CAACnB,KAAc,EAAoC;EAC/E,OAAO,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,IAAI,IAAI,IAAI,CAAC2B,KAAK,CAACC,OAAO,CAAC5B,KAAK,CAAC;AAC5E;AAEA,SAASD,QAAQA,CAACC,KAAc,EAAmB;EACjD,OAAQ,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,IAAI,IAAI,IAAK,OAAOA,KAAK,KAAK,UAAU;AACpF","ignoreList":[]}
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+
3
+ import { clearContainerPair, defineContainerPair, forgetContainerPair, getLegacyContainerPair, getModernContainerPair, isLegacyAppContainer, isContainerPair, isObjectRecord, rememberContainerPair, rememberLegacyAdapterPair } from "./containerPairing.js";
4
+ import { AppContainerAlreadyRegisteredError } from "./errors.js";
5
+ import { getMicroFrontendGlobalContext, MicroFrontendGlobalContextCompatibilityError } from "./globalContext.js";
6
+ export { exposeContainerModule as exposeModule } from "./containerModuleExposure.js";
7
+ export function createContainer(appName, config = {}) {
8
+ const context = getMicroFrontendGlobalContext();
9
+ const canonicalValue = Reflect.get(context.__CONTAINERS__, appName);
10
+ const legacyIndex = Reflect.get(context.__INSTANCES__, appName);
11
+ if (canonicalValue != null || typeof legacyIndex === 'number') {
12
+ throw new AppContainerAlreadyRegisteredError(appName);
13
+ }
14
+ if (!Reflect.isExtensible(context.__CONTAINERS__) || !Reflect.isExtensible(context.__INSTANCES__)) {
15
+ throw new MicroFrontendGlobalContextCompatibilityError('registry-is-not-extensible');
16
+ }
17
+ const modernContainer = {
18
+ appName,
19
+ config,
20
+ exposedModules: {}
21
+ };
22
+ const legacyContainer = {
23
+ name: appName,
24
+ config,
25
+ exposeMap: {}
26
+ };
27
+ const containerIndex = context.__INSTANCES__.length;
28
+ try {
29
+ if (!Reflect.defineProperty(context.__INSTANCES__, appName, {
30
+ configurable: true,
31
+ enumerable: false,
32
+ value: containerIndex,
33
+ writable: false
34
+ })) {
35
+ throw new MicroFrontendGlobalContextCompatibilityError('registry-is-not-extensible');
36
+ }
37
+ context.__INSTANCES__.push(legacyContainer);
38
+ if (!Reflect.set(context.__CONTAINERS__, appName, modernContainer) || !defineContainerPair(modernContainer, legacyContainer)) {
39
+ throw new MicroFrontendGlobalContextCompatibilityError('registry-is-not-extensible');
40
+ }
41
+ } catch (error) {
42
+ if (Object.is(context.__INSTANCES__[context.__INSTANCES__.length - 1], legacyContainer)) {
43
+ context.__INSTANCES__.pop();
44
+ }
45
+ Reflect.deleteProperty(context.__INSTANCES__, appName);
46
+ Reflect.deleteProperty(context.__CONTAINERS__, appName);
47
+ clearContainerPair(modernContainer, legacyContainer);
48
+ throw error;
49
+ }
50
+ rememberContainerPair(modernContainer, legacyContainer);
51
+ return modernContainer;
52
+ }
53
+ export function getContainer(appName) {
54
+ const context = getMicroFrontendGlobalContext();
55
+ const canonicalValue = Reflect.get(context.__CONTAINERS__, appName);
56
+ const modernContainer = isAppContainer(canonicalValue) ? canonicalValue : null;
57
+ const legacyContainer = getLegacyContainer(context.__INSTANCES__, appName);
58
+ if (modernContainer != null && legacyContainer != null) {
59
+ if (!isContainerPair(modernContainer, legacyContainer)) {
60
+ throw new AppContainerAlreadyRegisteredError(appName);
61
+ }
62
+ return modernContainer;
63
+ }
64
+ if (modernContainer != null) {
65
+ return modernContainer;
66
+ }
67
+ if (legacyContainer != null) {
68
+ return getLegacyAdapter(legacyContainer);
69
+ }
70
+ return null;
71
+ }
72
+ export function getExposedModule(container, exposedModule) {
73
+ const module = Reflect.get(container.exposedModules, normalizeExposedModule(exposedModule));
74
+ const legacyContainer = getLegacyContainerPair(container);
75
+ return module ?? (legacyContainer == null ? undefined : Reflect.get(legacyContainer.exposeMap, normalizeLegacyModule(exposedModule)));
76
+ }
77
+ export function removeContainer(appName) {
78
+ const context = getMicroFrontendGlobalContext();
79
+ const canonicalValue = Reflect.get(context.__CONTAINERS__, appName);
80
+ const modernContainer = isAppContainer(canonicalValue) ? canonicalValue : null;
81
+ const legacyContainer = getLegacyContainer(context.__INSTANCES__, appName);
82
+ if (modernContainer != null && legacyContainer != null && !isContainerPair(modernContainer, legacyContainer)) {
83
+ throw new AppContainerAlreadyRegisteredError(appName);
84
+ }
85
+ if (modernContainer == null && legacyContainer == null) {
86
+ return;
87
+ }
88
+ const nextInstances = createLegacyInstancesWithout(context.__INSTANCES__, legacyContainer);
89
+ if (legacyContainer != null && !Reflect.set(context, '__INSTANCES__', nextInstances)) {
90
+ throw new MicroFrontendGlobalContextCompatibilityError('registry-is-not-extensible');
91
+ }
92
+ if (modernContainer != null) {
93
+ clearRegistry(modernContainer.exposedModules);
94
+ Reflect.deleteProperty(context.__CONTAINERS__, appName);
95
+ }
96
+ if (legacyContainer != null) {
97
+ clearLegacyModules(legacyContainer);
98
+ }
99
+ if (modernContainer != null) {
100
+ if (legacyContainer != null) {
101
+ clearContainerPair(modernContainer, legacyContainer);
102
+ }
103
+ }
104
+ forgetContainerPair(modernContainer, legacyContainer);
105
+ }
106
+ function getLegacyAdapter(legacyContainer) {
107
+ const existingAdapter = getModernContainerPair(legacyContainer);
108
+ if (existingAdapter != null) {
109
+ return existingAdapter;
110
+ }
111
+ const adapter = {
112
+ appName: legacyContainer.name,
113
+ config: isAppContainerConfig(legacyContainer.config) ? legacyContainer.config : {},
114
+ exposedModules: createNormalizedExposedModules(legacyContainer)
115
+ };
116
+ rememberLegacyAdapterPair(adapter, legacyContainer);
117
+ return adapter;
118
+ }
119
+ function createNormalizedExposedModules(container) {
120
+ return new Proxy({}, {
121
+ get: (_target, property, receiver) => Reflect.get(container.exposeMap, typeof property === 'string' ? normalizeLegacyModule(property) : property, receiver),
122
+ ownKeys: () => Reflect.ownKeys(container.exposeMap).map(key => typeof key === 'string' ? normalizeExposedModule(key) : key),
123
+ getOwnPropertyDescriptor: (_target, property) => {
124
+ const moduleName = typeof property === 'string' ? normalizeLegacyModule(property) : property;
125
+ return Reflect.has(container.exposeMap, moduleName) ? {
126
+ configurable: true,
127
+ enumerable: true,
128
+ value: Reflect.get(container.exposeMap, moduleName)
129
+ } : undefined;
130
+ }
131
+ });
132
+ }
133
+ function getLegacyContainer(instances, appName) {
134
+ const index = Reflect.get(instances, appName);
135
+ if (typeof index !== 'number' || !Number.isInteger(index) || index < 0) {
136
+ return null;
137
+ }
138
+ const value = instances[index];
139
+ return isLegacyAppContainer(value) && value.name === appName ? value : null;
140
+ }
141
+ function createLegacyInstancesWithout(instances, removed) {
142
+ const nextInstances = removed == null ? Array.from(instances) : instances.filter(entry => !Object.is(entry, removed));
143
+ const registeredNames = new Set();
144
+ for (const [index, entry] of nextInstances.entries()) {
145
+ if (!isLegacyAppContainer(entry)) {
146
+ continue;
147
+ }
148
+ if (registeredNames.has(entry.name) || typeof Reflect.get(nextInstances, entry.name) === 'number') {
149
+ throw new AppContainerAlreadyRegisteredError(entry.name);
150
+ }
151
+ registeredNames.add(entry.name);
152
+ if (!Reflect.defineProperty(nextInstances, entry.name, {
153
+ configurable: true,
154
+ enumerable: false,
155
+ value: index,
156
+ writable: false
157
+ })) {
158
+ throw new MicroFrontendGlobalContextCompatibilityError('registry-is-not-extensible');
159
+ }
160
+ }
161
+ return nextInstances;
162
+ }
163
+ function clearRegistry(registry) {
164
+ for (const key of Object.keys(registry)) {
165
+ Reflect.deleteProperty(registry, key);
166
+ }
167
+ }
168
+ function clearLegacyModules(container) {
169
+ clearRegistry(container.exposeMap);
170
+ if (Object.keys(container.exposeMap).length > 0 && !Reflect.set(container, 'exposeMap', {})) {
171
+ throw new MicroFrontendGlobalContextCompatibilityError('registry-is-not-extensible');
172
+ }
173
+ }
174
+ function normalizeExposedModule(exposedModule) {
175
+ return exposedModule.startsWith('./') ? exposedModule : `./${exposedModule}`;
176
+ }
177
+ function normalizeLegacyModule(exposedModule) {
178
+ return exposedModule.startsWith('./') ? exposedModule.slice(2) : exposedModule;
179
+ }
180
+ function isAppContainer(value) {
181
+ return isObjectRecord(value) && typeof Reflect.get(value, 'appName') === 'string' && isAppContainerConfig(Reflect.get(value, 'config')) && isObjectRecord(Reflect.get(value, 'exposedModules'));
182
+ }
183
+ function isAppContainerConfig(value) {
184
+ if (!isObjectRecord(value)) {
185
+ return false;
186
+ }
187
+ const shared = Reflect.get(value, 'shared');
188
+ return shared == null || isObjectRecord(shared);
189
+ }
190
+ //# sourceMappingURL=containerRegistry.js.map
@@ -0,0 +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;AAG7G,SAASC,qBAAqB,IAAIC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AAIrF,cAAc,CAACqF,MAAM,CAAC;AACjD","ignoreList":[]}
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  import { AppContainerNotFoundError, InvalidAppNameError } from "./errors.js";
4
+ import { getMicroFrontendGlobalContext } from "./globalContext.js";
5
+ import { installNativeComponentRegistryCompatibility } from "./nativeComponentRegistryCompatibility.js";
4
6
  import { parseAppRequest } from "./parseAppRequest.js";
5
7
  export function createMicroFrontendRuntimeWithDependencies(dependencies) {
6
8
  // A fulfilled promise is the evaluated-state cache. Rejected evaluations remove themselves.
@@ -22,6 +24,13 @@ export function createMicroFrontendRuntimeWithDependencies(dependencies) {
22
24
  appEvaluations.set(appName, evaluation);
23
25
  return evaluation;
24
26
  }
27
+ function evaluateScript(filePath) {
28
+ getMicroFrontendGlobalContext();
29
+ installNativeComponentRegistryCompatibility();
30
+ return dependencies.nativeRuntime.evaluateScript({
31
+ filePath
32
+ });
33
+ }
25
34
  async function evaluateApp(appName) {
26
35
  try {
27
36
  const {
@@ -29,9 +38,7 @@ export function createMicroFrontendRuntimeWithDependencies(dependencies) {
29
38
  } = await dependencies.adapter.loadBundle({
30
39
  appName
31
40
  });
32
- await dependencies.nativeRuntime.evaluateScript({
33
- filePath
34
- });
41
+ await evaluateScript(filePath);
35
42
  if (!dependencies.registry.hasContainer(appName)) {
36
43
  throw new AppContainerNotFoundError(appName);
37
44
  }
@@ -41,9 +48,7 @@ export function createMicroFrontendRuntimeWithDependencies(dependencies) {
41
48
  }
42
49
  }
43
50
  return {
44
- evaluateScript: filePath => dependencies.nativeRuntime.evaluateScript({
45
- filePath
46
- }),
51
+ evaluateScript,
47
52
  preloadApp,
48
53
  async importApp(request) {
49
54
  const {
@@ -1 +1 @@
1
- {"version":3,"names":["AppContainerNotFoundError","InvalidAppNameError","parseAppRequest","createMicroFrontendRuntimeWithDependencies","dependencies","appEvaluations","Map","resetFailedEvaluation","appName","delete","registry","removeContainer","removePendingHostComponentRoutes","preloadApp","length","Promise","reject","existingEvaluation","get","evaluation","evaluateApp","set","filePath","adapter","loadBundle","nativeRuntime","evaluateScript","hasContainer","error","importApp","request","importModule","onEvent","listener","subscription","event","parsedEvent","parseEvent","name","params","catch","onPreloadError","exhaustiveEvent","startEventDelivery"],"sourceRoot":"../../../src","sources":["runtime/createMicroFrontendRuntime.ts"],"mappings":";;AAOA,SAASA,yBAAyB,EAAEC,mBAAmB,QAAQ,aAAU;AACzE,SAASC,eAAe,QAAQ,sBAAmB;AAmCnD,OAAO,SAASC,0CAA0CA,CACxDC,YAAoD,EAC3B;EACzB;EACA,MAAMC,cAAc,GAAG,IAAIC,GAAG,CAAwB,CAAC;EAEvD,SAASC,qBAAqBA,CAACC,OAAe,EAAE;IAC9CH,cAAc,CAACI,MAAM,CAACD,OAAO,CAAC;IAC9BJ,YAAY,CAACM,QAAQ,CAACC,eAAe,CAACH,OAAO,CAAC;IAC9CJ,YAAY,CAACQ,gCAAgC,CAACJ,OAAO,CAAC;EACxD;EAEA,SAASK,UAAUA,CAACL,OAAe,EAAiB;IAClD,IAAIA,OAAO,CAACM,MAAM,KAAK,CAAC,EAAE;MACxB,OAAOC,OAAO,CAACC,MAAM,CAAC,IAAIf,mBAAmB,CAACO,OAAO,CAAC,CAAC;IACzD;IAEA,MAAMS,kBAAkB,GAAGZ,cAAc,CAACa,GAAG,CAACV,OAAO,CAAC;IACtD,IAAIS,kBAAkB,IAAI,IAAI,EAAE;MAC9B,OAAOA,kBAAkB;IAC3B;IAEA,MAAME,UAAU,GAAGC,WAAW,CAACZ,OAAO,CAAC;IACvCH,cAAc,CAACgB,GAAG,CAACb,OAAO,EAAEW,UAAU,CAAC;IACvC,OAAOA,UAAU;EACnB;EAEA,eAAeC,WAAWA,CAACZ,OAAe,EAAiB;IACzD,IAAI;MACF,MAAM;QAAEc;MAAS,CAAC,GAAG,MAAMlB,YAAY,CAACmB,OAAO,CAACC,UAAU,CAAC;QAAEhB;MAAQ,CAAC,CAAC;MACvE,MAAMJ,YAAY,CAAC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AAOT,YAAY;IACrB;EACF,CAAC;AACH","ignoreList":[]}
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":";;AAOA,SAASA,yBAAyB,EAAEC,mBAAmB,QAAQ,aAAU;AACzE,SAASC,6BAA6B,QAAQ,oBAAiB;AAC/D,SAASC,2CAA2C,QAAQ,2CAAwC;AACpG,SAASC,eAAe,QAAQ,sBAAmB;AAmCnD,OAAO,SAASC,0CAA0CA,CACxDC,YAAoD,EAC3B;EACzB;EACA,MAAMC,cAAc,GAAG,IAAIC,GAAG,CAAwB,CAAC;EAEvD,SAASC,qBAAqBA,CAACC,OAAe,EAAE;IAC9CH,cAAc,CAACI,MAAM,CAACD,OAAO,CAAC;IAC9BJ,YAAY,CAACM,QAAQ,CAACC,eAAe,CAACH,OAAO,CAAC;IAC9CJ,YAAY,CAACQ,gCAAgC,CAACJ,OAAO,CAAC;EACxD;EAEA,SAASK,UAAUA,CAACL,OAAe,EAAiB;IAClD,IAAIA,OAAO,CAACM,MAAM,KAAK,CAAC,EAAE;MACxB,OAAOC,OAAO,CAACC,MAAM,CAAC,IAAIjB,mBAAmB,CAACS,OAAO,CAAC,CAAC;IACzD;IAEA,MAAMS,kBAAkB,GAAGZ,cAAc,CAACa,GAAG,CAACV,OAAO,CAAC;IACtD,IAAIS,kBAAkB,IAAI,IAAI,EAAE;MAC9B,OAAOA,kBAAkB;IAC3B;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