@granite-js/micro-frontend 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/GraniteMicroFrontendRuntime.podspec +40 -0
  2. package/LICENSE +202 -0
  3. package/LICENSE.react-native-teleport +21 -0
  4. package/NOTICE +17 -0
  5. package/README.md +508 -0
  6. package/android/CMakeLists.txt +34 -0
  7. package/android/build.gradle +74 -0
  8. package/android/gradle.properties +4 -0
  9. package/android/src/main/AndroidManifest.xml +1 -0
  10. package/android/src/main/cpp/BundleEvaluator.cpp +64 -0
  11. package/android/src/main/cpp/BundleEvaluator.h +20 -0
  12. package/android/src/main/cpp/FileReader.cpp +92 -0
  13. package/android/src/main/cpp/FileReader.h +27 -0
  14. package/android/src/main/cpp/onLoad.cpp +9 -0
  15. package/android/src/main/java/com/teleport/extensions/Float.kt +12 -0
  16. package/android/src/main/java/com/teleport/extensions/View.kt +10 -0
  17. package/android/src/main/java/com/teleport/global/PortalRegistry.kt +117 -0
  18. package/android/src/main/java/com/teleport/host/PortalHostView.kt +97 -0
  19. package/android/src/main/java/com/teleport/host/PortalHostViewManager.kt +41 -0
  20. package/android/src/main/java/com/teleport/host/PortalReactRootView.kt +116 -0
  21. package/android/src/main/java/com/teleport/managers/TeleportViewManager.kt +27 -0
  22. package/android/src/main/java/com/teleport/portal/PortalLayoutStateController.kt +107 -0
  23. package/android/src/main/java/com/teleport/portal/PortalView.kt +309 -0
  24. package/android/src/main/java/com/teleport/portal/PortalViewManager.kt +51 -0
  25. package/android/src/main/java/run/granite/microfrontend/ActivitySessionBinding.kt +87 -0
  26. package/android/src/main/java/run/granite/microfrontend/BundleEvaluator.kt +46 -0
  27. package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendEvent.kt +62 -0
  28. package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendRuntimeEventRouter.kt +186 -0
  29. package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendRuntimeHost.kt +42 -0
  30. package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendRuntimeModule.kt +56 -0
  31. package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendRuntimePackage.kt +35 -0
  32. package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendSessionStore.kt +116 -0
  33. package/android/src/main/jni/CMakeLists.txt +64 -0
  34. package/android/src/test/cpp/CMakeLists.txt +35 -0
  35. package/android/src/test/cpp/FileReaderTest.cpp +44 -0
  36. package/android/src/test/java/com/teleport/host/PortalReactRootViewContractTest.kt +76 -0
  37. package/android/src/test/java/run/granite/microfrontend/GraniteMicroFrontendRuntimeEventRouterTest.kt +216 -0
  38. package/android/src/test/java/run/granite/microfrontend/GraniteMicroFrontendSessionStoreTest.kt +190 -0
  39. package/android/test-cpp.sh +12 -0
  40. package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/ComponentDescriptors.h +24 -0
  41. package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/PortalShadowRegistry.cpp +31 -0
  42. package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/PortalShadowRegistry.h +29 -0
  43. package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalHostViewComponentDescriptor.h +22 -0
  44. package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalHostViewShadowNode.cpp +7 -0
  45. package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalHostViewShadowNode.h +43 -0
  46. package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalHostViewState.h +21 -0
  47. package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalViewComponentDescriptor.h +54 -0
  48. package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalViewShadowNode.cpp +7 -0
  49. package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalViewShadowNode.h +51 -0
  50. package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalViewState.h +43 -0
  51. package/dist/module/createMicroFrontendRuntime.js +18 -0
  52. package/dist/module/createMicroFrontendRuntime.js.map +1 -0
  53. package/dist/module/createRoute.js +43 -0
  54. package/dist/module/createRoute.js.map +1 -0
  55. package/dist/module/host/PendingHostComponent.js +70 -0
  56. package/dist/module/host/PendingHostComponent.js.map +1 -0
  57. package/dist/module/host/index.js +6 -0
  58. package/dist/module/host/index.js.map +1 -0
  59. package/dist/module/host/pendingHostComponentStore.js +164 -0
  60. package/dist/module/host/pendingHostComponentStore.js.map +1 -0
  61. package/dist/module/host/resolveParams.js +60 -0
  62. package/dist/module/host/resolveParams.js.map +1 -0
  63. package/dist/module/host/routeMatcher.js +92 -0
  64. package/dist/module/host/routeMatcher.js.map +1 -0
  65. package/dist/module/host/types.js +4 -0
  66. package/dist/module/host/types.js.map +1 -0
  67. package/dist/module/index.js +12 -0
  68. package/dist/module/index.js.map +1 -0
  69. package/dist/module/package.json +1 -0
  70. package/dist/module/plugin/index.js +4 -0
  71. package/dist/module/plugin/index.js.map +1 -0
  72. package/dist/module/plugin/intoShared.js +32 -0
  73. package/dist/module/plugin/intoShared.js.map +1 -0
  74. package/dist/module/plugin/microFrontendPlugin.js +58 -0
  75. package/dist/module/plugin/microFrontendPlugin.js.map +1 -0
  76. package/dist/module/plugin/prelude.js +23 -0
  77. package/dist/module/plugin/prelude.js.map +1 -0
  78. package/dist/module/plugin/resolver.js +25 -0
  79. package/dist/module/plugin/resolver.js.map +1 -0
  80. package/dist/module/plugin/types.js +4 -0
  81. package/dist/module/plugin/types.js.map +1 -0
  82. package/dist/module/runtime/createMicroFrontendRuntime.js +79 -0
  83. package/dist/module/runtime/createMicroFrontendRuntime.js.map +1 -0
  84. package/dist/module/runtime/errors.js +63 -0
  85. package/dist/module/runtime/errors.js.map +1 -0
  86. package/dist/module/runtime/parseAppRequest.js +16 -0
  87. package/dist/module/runtime/parseAppRequest.js.map +1 -0
  88. package/dist/module/runtime/parseNativeRuntimeEvent.js +54 -0
  89. package/dist/module/runtime/parseNativeRuntimeEvent.js.map +1 -0
  90. package/dist/module/runtime/registry.js +87 -0
  91. package/dist/module/runtime/registry.js.map +1 -0
  92. package/dist/module/session/MicroFrontendSessionContext.js +32 -0
  93. package/dist/module/session/MicroFrontendSessionContext.js.map +1 -0
  94. package/dist/module/session/useMicroFrontendSessions.js +47 -0
  95. package/dist/module/session/useMicroFrontendSessions.js.map +1 -0
  96. package/dist/module/specs/NativeGraniteMicroFrontendRuntime.js +21 -0
  97. package/dist/module/specs/NativeGraniteMicroFrontendRuntime.js.map +1 -0
  98. package/dist/module/specs/PortalHostViewNativeComponent.ts +9 -0
  99. package/dist/module/specs/PortalViewNativeComponent.ts +9 -0
  100. package/dist/module/types.js +2 -0
  101. package/dist/module/types.js.map +1 -0
  102. package/dist/typescript/createMicroFrontendRuntime.d.ts +6 -0
  103. package/dist/typescript/createRoute.d.ts +23 -0
  104. package/dist/typescript/host/PendingHostComponent.d.ts +14 -0
  105. package/dist/typescript/host/index.d.ts +5 -0
  106. package/dist/typescript/host/pendingHostComponentStore.d.ts +11 -0
  107. package/dist/typescript/host/resolveParams.d.ts +10 -0
  108. package/dist/typescript/host/routeMatcher.d.ts +7 -0
  109. package/dist/typescript/host/types.d.ts +32 -0
  110. package/dist/typescript/index.d.ts +16 -0
  111. package/dist/typescript/plugin/index.d.ts +2 -0
  112. package/dist/typescript/plugin/intoShared.d.ts +3 -0
  113. package/dist/typescript/plugin/microFrontendPlugin.d.ts +3 -0
  114. package/dist/typescript/plugin/prelude.d.ts +6 -0
  115. package/dist/typescript/plugin/resolver.d.ts +3 -0
  116. package/dist/typescript/plugin/types.d.ts +5 -0
  117. package/dist/typescript/runtime/createMicroFrontendRuntime.d.ts +31 -0
  118. package/dist/typescript/runtime/errors.d.ts +35 -0
  119. package/dist/typescript/runtime/parseAppRequest.d.ts +6 -0
  120. package/dist/typescript/runtime/parseNativeRuntimeEvent.d.ts +3 -0
  121. package/dist/typescript/runtime/registry.d.ts +35 -0
  122. package/dist/typescript/session/MicroFrontendSessionContext.d.ts +13 -0
  123. package/dist/typescript/session/useMicroFrontendSessions.d.ts +8 -0
  124. package/dist/typescript/specs/NativeGraniteMicroFrontendRuntime.d.ts +21 -0
  125. package/dist/typescript/specs/PortalHostViewNativeComponent.d.ts +6 -0
  126. package/dist/typescript/specs/PortalViewNativeComponent.d.ts +6 -0
  127. package/dist/typescript/types.d.ts +49 -0
  128. package/ios/GraniteMicroFrontendRuntimeHost+Internal.h +18 -0
  129. package/ios/GraniteMicroFrontendRuntimeHost.h +34 -0
  130. package/ios/GraniteMicroFrontendRuntimeHost.mm +485 -0
  131. package/ios/GraniteMicroFrontendRuntimeModule.h +6 -0
  132. package/ios/GraniteMicroFrontendRuntimeModule.mm +138 -0
  133. package/ios/PortalHostContainerView.h +56 -0
  134. package/ios/PortalHostContainerView.mm +133 -0
  135. package/ios/PortalHostView.h +39 -0
  136. package/ios/PortalHostView.mm +153 -0
  137. package/ios/PortalRegistry.h +38 -0
  138. package/ios/PortalRegistry.mm +228 -0
  139. package/ios/PortalView.h +32 -0
  140. package/ios/PortalView.mm +426 -0
  141. package/package.json +113 -0
  142. package/react-native.config.js +13 -0
  143. package/src/createMicroFrontendRuntime.ts +22 -0
  144. package/src/createRoute.ts +84 -0
  145. package/src/host/PendingHostComponent.tsx +92 -0
  146. package/src/host/index.ts +26 -0
  147. package/src/host/pendingHostComponentStore.ts +241 -0
  148. package/src/host/resolveParams.ts +70 -0
  149. package/src/host/routeMatcher.ts +117 -0
  150. package/src/host/types.ts +45 -0
  151. package/src/index.ts +57 -0
  152. package/src/plugin/index.ts +2 -0
  153. package/src/plugin/intoShared.ts +50 -0
  154. package/src/plugin/microFrontendPlugin.ts +57 -0
  155. package/src/plugin/prelude.ts +73 -0
  156. package/src/plugin/resolver.ts +73 -0
  157. package/src/plugin/types.ts +6 -0
  158. package/src/runtime/createMicroFrontendRuntime.ts +115 -0
  159. package/src/runtime/errors.ts +86 -0
  160. package/src/runtime/parseAppRequest.ts +22 -0
  161. package/src/runtime/parseNativeRuntimeEvent.ts +54 -0
  162. package/src/runtime/registry.ts +131 -0
  163. package/src/session/MicroFrontendSessionContext.tsx +45 -0
  164. package/src/session/useMicroFrontendSessions.ts +73 -0
  165. package/src/specs/NativeGraniteMicroFrontendRuntime.ts +44 -0
  166. package/src/specs/PortalHostViewNativeComponent.ts +9 -0
  167. package/src/specs/PortalViewNativeComponent.ts +9 -0
  168. package/src/types.ts +55 -0
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ const SHARED_PRESETS = {
4
+ react: ['react/jsx-runtime', 'react/jsx-dev-runtime'],
5
+ 'react-native': ['react-native/Libraries/BatchedBridge/BatchedBridge', 'react-native/Libraries/BatchedBridge/NativeModules', 'react-native/Libraries/BatchedBridge/MessageQueue', 'react-native/Libraries/NativeComponent/NativeComponentRegistry', 'react-native/Libraries/NativeComponent/NativeComponentRegistryUnstable', 'react-native/Libraries/NativeComponent/ViewConfigIgnore', 'react-native/Libraries/ReactNative/RendererProxy', 'react-native/Libraries/StyleSheet/PlatformColorValueTypes', 'react-native/Libraries/StyleSheet/normalizeColor', 'react-native/Libraries/StyleSheet/processColor', 'react-native/Libraries/TurboModule/TurboModuleRegistry', 'react-native/Libraries/Utilities/NativePlatformConstantsIOS', 'react-native/Libraries/Utilities/Platform', 'react-native/Libraries/Utilities/defineLazyObjectProperty']
6
+ };
7
+ export function intoShared(shared) {
8
+ if (shared == null) {
9
+ return undefined;
10
+ }
11
+ const normalized = {};
12
+ if (Array.isArray(shared)) {
13
+ for (const moduleName of shared) {
14
+ normalized[moduleName] = {};
15
+ }
16
+ } else {
17
+ Object.assign(normalized, shared);
18
+ }
19
+ for (const [moduleName, subpaths] of Object.entries(SHARED_PRESETS)) {
20
+ const moduleConfig = normalized[moduleName];
21
+ if (moduleConfig == null) {
22
+ continue;
23
+ }
24
+ for (const subpath of subpaths) {
25
+ normalized[subpath] ??= {
26
+ ...moduleConfig
27
+ };
28
+ }
29
+ }
30
+ return normalized;
31
+ }
32
+ //# sourceMappingURL=intoShared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SHARED_PRESETS","react","intoShared","shared","undefined","normalized","Array","isArray","moduleName","Object","assign","subpaths","entries","moduleConfig","subpath"],"sourceRoot":"../../../src","sources":["plugin/intoShared.ts"],"mappings":";;AAGA,MAAMA,cAAc,GAAG;EACrBC,KAAK,EAAE,CAAC,mBAAmB,EAAE,uBAAuB,CAAC;EACrD,cAAc,EAAE,CACd,oDAAoD,EACpD,oDAAoD,EACpD,mDAAmD,EACnD,gEAAgE,EAChE,wEAAwE,EACxE,yDAAyD,EACzD,kDAAkD,EAClD,2DAA2D,EAC3D,kDAAkD,EAClD,gDAAgD,EAChD,wDAAwD,EACxD,6DAA6D,EAC7D,2CAA2C,EAC3C,2DAA2D;AAE/D,CAAU;AAEV,OAAO,SAASC,UAAUA,CAACC,MAA4C,EAA4B;EACjG,IAAIA,MAAM,IAAI,IAAI,EAAE;IAClB,OAAOC,SAAS;EAClB;EAEA,MAAMC,UAA8C,GAAG,CAAC,CAAC;EACzD,IAAIC,KAAK,CAACC,OAAO,CAACJ,MAAM,CAAC,EAAE;IACzB,KAAK,MAAMK,UAAU,IAAIL,MAAM,EAAE;MAC/BE,UAAU,CAACG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B;EACF,CAAC,MAAM;IACLC,MAAM,CAACC,MAAM,CAACL,UAAU,EAAEF,MAAM,CAAC;EACnC;EAEA,KAAK,MAAM,CAACK,UAAU,EAAEG,QAAQ,CAAC,IAAIF,MAAM,CAACG,OAAO,CAACZ,cAAc,CAAC,EAAE;IACnE,MAAMa,YAAY,GAAGR,UAAU,CAACG,UAAU,CAAC;IAC3C,IAAIK,YAAY,IAAI,IAAI,EAAE;MACxB;IACF;IAEA,KAAK,MAAMC,OAAO,IAAIH,QAAQ,EAAE;MAC9BN,UAAU,CAACS,OAAO,CAAC,KAAK;QAAE,GAAGD;MAAa,CAAC;IAC7C;EACF;EAEA,OAAOR,UAAU;AACnB","ignoreList":[]}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ import * as fs from 'fs';
4
+ import * as path from 'path';
5
+ import { prepareLocalDirectory } from '@granite-js/utils';
6
+ import { intoShared } from "./intoShared.js";
7
+ import { getPreludeConfig } from "./prelude.js";
8
+ import { createSharedResolverConfig } from "./resolver.js";
9
+ export async function microFrontend(options = {}) {
10
+ const shared = intoShared(options.shared);
11
+ const normalizedOptions = {
12
+ ...options,
13
+ shared
14
+ };
15
+ const nonEagerEntries = Object.entries(shared ?? {}).filter(([, config]) => config.eager !== true);
16
+ const localDirectory = prepareLocalDirectory(process.cwd());
17
+ const preludePath = path.join(localDirectory, 'micro-frontend-runtime.js');
18
+ const prelude = getPreludeConfig(normalizedOptions);
19
+ const resolver = createSharedResolverConfig(nonEagerEntries);
20
+ function writePrelude(appName) {
21
+ const config = getPreludeConfig(normalizedOptions, appName);
22
+ fs.writeFileSync(preludePath, config.preludeScript, 'utf8');
23
+ }
24
+ writePrelude();
25
+ return {
26
+ name: 'micro-frontend',
27
+ dev: {
28
+ order: 'pre',
29
+ handler({
30
+ appName
31
+ }) {
32
+ writePrelude(appName);
33
+ }
34
+ },
35
+ build: {
36
+ order: 'pre',
37
+ handler({
38
+ appName
39
+ }) {
40
+ writePrelude(appName);
41
+ }
42
+ },
43
+ config: {
44
+ extra: nonEagerEntries.some(([moduleName]) => moduleName === 'react-native') ? {
45
+ skipReactNativeInitializeCore: true,
46
+ skipReactNativePolyfills: true
47
+ } : undefined,
48
+ resolver,
49
+ esbuild: {
50
+ prelude: [preludePath],
51
+ banner: {
52
+ js: prelude.banner
53
+ }
54
+ }
55
+ }
56
+ };
57
+ }
58
+ //# sourceMappingURL=microFrontendPlugin.js.map
@@ -0,0 +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,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,MAAM,CAAC,CAAC,GAAGC,MAAM,CAAC,KAAKA,MAAM,CAACC,KAAK,KAAK,IAAI,CAAC;EAClG,MAAMC,cAAc,GAAGd,qBAAqB,CAACe,OAAO,CAACC,GAAG,CAAC,CAAC,CAAC;EAC3D,MAAMC,WAAW,GAAGlB,IAAI,CAACmB,IAAI,CAACJ,cAAc,EAAE,2BAA2B,CAAC;EAC1E,MAAMK,OAAO,GAAGjB,gBAAgB,CAACK,iBAAiB,CAAC;EACnD,MAAMa,QAAQ,GAAGjB,0BAA0B,CAACK,eAAe,CAAC;EAE5D,SAASa,YAAYA,CAACC,OAAgB,EAAE;IACtC,MAAMV,MAAM,GAAGV,gBAAgB,CAACK,iBAAiB,EAAEe,OAAO,CAAC;IAC3DxB,EAAE,CAACyB,aAAa,CAACN,WAAW,EAAEL,MAAM,CAACY,aAAa,EAAE,MAAM,CAAC;EAC7D;EAEAH,YAAY,CAAC,CAAC;EAEd,OAAO;IACLI,IAAI,EAAE,gBAAgB;IACtBC,GAAG,EAAE;MACHC,KAAK,EAAE,KAAK;MACZC,OAAOA,CAAC;QAAEN;MAAQ,CAAC,EAAE;QACnBD,YAAY,CAACC,OAAO,CAAC;MACvB;IACF,CAAC;IACDO,KAAK,EAAE;MACLF,KAAK,EAAE,KAAK;MACZC,OAAOA,CAAC;QAAEN;MAAQ,CAAC,EAAE;QACnBD,YAAY,CAACC,OAAO,CAAC;MACvB;IACF,CAAC;IACDV,MAAM,EAAE;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":[]}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ import path from 'path';
4
+ export function getPreludeConfig(options, appName) {
5
+ const eagerSharedModules = Object.entries(options.shared ?? {}).filter(([, config]) => !Array.isArray(options.shared) && config.eager === true);
6
+ const registerStatements = eagerSharedModules.map(([moduleName], index) => {
7
+ const identifier = `__shared${index}`;
8
+ return [`import * as ${identifier} from ${JSON.stringify(moduleName)};`, `registerShared(${JSON.stringify(moduleName)}, ${identifier});`].join('\n');
9
+ });
10
+ const exposeStatements = Object.entries(options.exposes ?? {}).map(([exposedModule, modulePath], index) => {
11
+ const identifier = `__expose${index}`;
12
+ return [`import * as ${identifier} from ${JSON.stringify(path.resolve(modulePath))};`, `exposeModule(__container, ${JSON.stringify(exposedModule)}, ${identifier});`].join('\n');
13
+ });
14
+ const containerConfig = JSON.stringify({
15
+ shared: options.shared
16
+ });
17
+ const containerName = appName == null ? 'global.__granite.app.name' : JSON.stringify(appName);
18
+ 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
+ };
22
+ }
23
+ //# sourceMappingURL=prelude.js.map
@@ -0,0 +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;E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AAChB,OAAO,CAAC;EAE7F,OAAO;IACLyB,MAAM,EAAE,CACN,kEAAkE,EAClE,mBAAmB,EACnB,sBAAsB,EACtB,IAAI,CACL,CAACR,IAAI,CAAC,IAAI,CAAC;IACZS,aAAa,EAAE,CACb,6CAA6C,EAC7C,+DAA+D,EAC/D,sCAAsC,EACtC,4EAA4E,EAC5E,KAAK,EACL,8DAA8D,EAC9D,oCAAoC,EACpC,qBAAqB,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":[]}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ const VIRTUAL_SHARED_PROTOCOL = 'granite-micro-frontend-shared';
4
+ export function createSharedResolverConfig(moduleEntries) {
5
+ const alias = moduleEntries.map(([moduleName]) => ({
6
+ exact: true,
7
+ from: moduleName,
8
+ to: `${VIRTUAL_SHARED_PROTOCOL}:${moduleName}`
9
+ }));
10
+ return {
11
+ alias,
12
+ protocols: alias.length === 0 ? undefined : {
13
+ [VIRTUAL_SHARED_PROTOCOL]: {
14
+ load(args) {
15
+ const moduleName = JSON.stringify(args.path);
16
+ return {
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')
19
+ };
20
+ }
21
+ }
22
+ }
23
+ };
24
+ }
25
+ //# sourceMappingURL=resolver.js.map
@@ -0,0 +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":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["plugin/types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ import { AppContainerNotFoundError, InvalidAppNameError } from "./errors.js";
4
+ import { parseAppRequest } from "./parseAppRequest.js";
5
+ export function createMicroFrontendRuntimeWithDependencies(dependencies) {
6
+ // A fulfilled promise is the evaluated-state cache. Rejected evaluations remove themselves.
7
+ const appEvaluations = new Map();
8
+ function resetFailedEvaluation(appName) {
9
+ appEvaluations.delete(appName);
10
+ dependencies.registry.removeContainer(appName);
11
+ dependencies.removePendingHostComponentRoutes(appName);
12
+ }
13
+ function preloadApp(appName) {
14
+ if (appName.length === 0) {
15
+ return Promise.reject(new InvalidAppNameError(appName));
16
+ }
17
+ const existingEvaluation = appEvaluations.get(appName);
18
+ if (existingEvaluation != null) {
19
+ return existingEvaluation;
20
+ }
21
+ const evaluation = evaluateApp(appName);
22
+ appEvaluations.set(appName, evaluation);
23
+ return evaluation;
24
+ }
25
+ async function evaluateApp(appName) {
26
+ try {
27
+ const {
28
+ filePath
29
+ } = await dependencies.adapter.loadBundle({
30
+ appName
31
+ });
32
+ await dependencies.nativeRuntime.evaluateScript({
33
+ filePath
34
+ });
35
+ if (!dependencies.registry.hasContainer(appName)) {
36
+ throw new AppContainerNotFoundError(appName);
37
+ }
38
+ } catch (error) {
39
+ resetFailedEvaluation(appName);
40
+ throw error;
41
+ }
42
+ }
43
+ return {
44
+ evaluateScript: filePath => dependencies.nativeRuntime.evaluateScript({
45
+ filePath
46
+ }),
47
+ preloadApp,
48
+ async importApp(request) {
49
+ const {
50
+ appName
51
+ } = parseAppRequest(request);
52
+ await preloadApp(appName);
53
+ return dependencies.registry.importModule(request);
54
+ },
55
+ onEvent(listener) {
56
+ const subscription = dependencies.nativeRuntime.onEvent(event => {
57
+ const parsedEvent = dependencies.parseEvent(event);
58
+ switch (parsedEvent.name) {
59
+ case 'preloadApp':
60
+ void preloadApp(parsedEvent.params.appName).catch(dependencies.onPreloadError);
61
+ return;
62
+ case 'openApp':
63
+ case 'closeApp':
64
+ case 'sessionVisibilityChanged':
65
+ listener(parsedEvent);
66
+ return;
67
+ default:
68
+ {
69
+ const exhaustiveEvent = parsedEvent;
70
+ return exhaustiveEvent;
71
+ }
72
+ }
73
+ });
74
+ dependencies.nativeRuntime.startEventDelivery();
75
+ return subscription;
76
+ }
77
+ };
78
+ }
79
+ //# sourceMappingURL=createMicroFrontendRuntime.js.map
@@ -0,0 +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,CAACm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ACF,CAAC,CAAC;MACFtC,YAAY,CAACqB,aAAa,CAACkB,kBAAkB,CAAC,CAAC;MAC/C,OAAOT,YAAY;IACrB;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ export class InvalidAppRequestError extends Error {
4
+ constructor(request) {
5
+ super(`Invalid micro-frontend app request: '${request}'`);
6
+ this.name = 'InvalidAppRequestError';
7
+ this.request = request;
8
+ }
9
+ }
10
+ export class InvalidAppNameError extends Error {
11
+ constructor(appName) {
12
+ super('Micro-frontend app name must not be empty');
13
+ this.name = 'InvalidAppNameError';
14
+ this.appName = appName;
15
+ }
16
+ }
17
+ export class AppContainerNotFoundError extends Error {
18
+ constructor(appName) {
19
+ super(`App container '${appName}' was not registered after bundle evaluation`);
20
+ this.name = 'AppContainerNotFoundError';
21
+ this.appName = appName;
22
+ }
23
+ }
24
+ export class AppContainerAlreadyRegisteredError extends Error {
25
+ constructor(appName) {
26
+ super(`App container '${appName}' is already registered`);
27
+ this.name = 'AppContainerAlreadyRegisteredError';
28
+ this.appName = appName;
29
+ }
30
+ }
31
+ export class ExposedModuleNotFoundError extends Error {
32
+ constructor(appName, exposedModule) {
33
+ super(`Could not resolve '${exposedModule}' from app container '${appName}'`);
34
+ this.name = 'ExposedModuleNotFoundError';
35
+ this.appName = appName;
36
+ this.exposedModule = exposedModule;
37
+ }
38
+ }
39
+ export class ExposedModuleAlreadyRegisteredError extends Error {
40
+ constructor(appName, exposedModule) {
41
+ super(`Exposed module '${exposedModule}' is already registered in app container '${appName}'`);
42
+ this.name = 'ExposedModuleAlreadyRegisteredError';
43
+ this.appName = appName;
44
+ this.exposedModule = exposedModule;
45
+ }
46
+ }
47
+ export class SharedModuleAlreadyRegisteredError extends Error {
48
+ constructor(moduleName) {
49
+ super(`Shared module '${moduleName}' is already registered`);
50
+ this.name = 'SharedModuleAlreadyRegisteredError';
51
+ this.moduleName = moduleName;
52
+ }
53
+ }
54
+ export class InvalidNativeRuntimeEventError extends Error {
55
+ constructor(eventName, fieldName) {
56
+ const detail = fieldName == null ? '' : `: missing or invalid '${fieldName}'`;
57
+ super(`Invalid native micro-frontend event '${eventName}'${detail}`);
58
+ this.name = 'InvalidNativeRuntimeEventError';
59
+ this.eventName = eventName;
60
+ this.fieldName = fieldName;
61
+ }
62
+ }
63
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["InvalidAppRequestError","Error","constructor","request","name","InvalidAppNameError","appName","AppContainerNotFoundError","AppContainerAlreadyRegisteredError","ExposedModuleNotFoundError","exposedModule","ExposedModuleAlreadyRegisteredError","SharedModuleAlreadyRegisteredError","moduleName","InvalidNativeRuntimeEventError","eventName","fieldName","detail"],"sourceRoot":"../../../src","sources":["runtime/errors.ts"],"mappings":";;AAAA,OAAO,MAAMA,sBAAsB,SAASC,KAAK,CAAC;EAGhDC,WAAWA,CAACC,OAAe,EAAE;IAC3B,KAAK,CAAC,wCAAwCA,OAAO,GAAG,CAAC;IACzD,IAAI,CAACC,IAAI,GAAG,wBAAwB;IACpC,IAAI,CAACD,OAAO,GAAGA,OAAO;EACxB;AACF;AAEA,OAAO,MAAME,mBAAmB,SAASJ,KAAK,CAAC;EAG7CC,WAAWA,CAACI,OAAe,EAAE;IAC3B,KAAK,CAAC,2CAA2C,CAAC;IAClD,IAAI,CAACF,IAAI,GAAG,qBAAqB;IACjC,IAAI,CAACE,OAAO,GAAGA,OAAO;EACxB;AACF;AAEA,OAAO,MAAMC,yBAAyB,SAASN,KAAK,CAAC;EAGnDC,WAAWA,CAACI,OAAe,EAAE;IAC3B,KAAK,CAAC,kBAAkBA,OAAO,8CAA8C,CAAC;IAC9E,IAAI,CAACF,IAAI,GAAG,2BAA2B;IACvC,IAAI,CAACE,OAAO,GAAGA,OAAO;EACxB;AACF;AAEA,OAAO,MAAME,kCAAkC,SAASP,KAAK,CAAC;EAG5DC,WAAWA,CAACI,OAAe,EAAE;IAC3B,KAAK,CAAC,kBAAkBA,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AGA,SAAS;EAC5B;AACF","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ import { InvalidAppRequestError } from "./errors.js";
4
+ export function parseAppRequest(request) {
5
+ const separatorIndex = request.indexOf('/');
6
+ const appName = request.slice(0, separatorIndex);
7
+ const moduleName = request.slice(separatorIndex + 1);
8
+ if (separatorIndex <= 0 || moduleName.length === 0) {
9
+ throw new InvalidAppRequestError(request);
10
+ }
11
+ return {
12
+ appName,
13
+ exposedModule: moduleName.startsWith('./') ? moduleName : `./${moduleName}`
14
+ };
15
+ }
16
+ //# sourceMappingURL=parseAppRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["InvalidAppRequestError","parseAppRequest","request","separatorIndex","indexOf","appName","slice","moduleName","length","exposedModule","startsWith"],"sourceRoot":"../../../src","sources":["runtime/parseAppRequest.ts"],"mappings":";;AACA,SAASA,sBAAsB,QAAQ,aAAU;AAOjD,OAAO,SAASC,eAAeA,CAACC,OAAmB,EAAoB;EACrE,MAAMC,cAAc,GAAGD,OAAO,CAACE,OAAO,CAAC,GAAG,CAAC;EAC3C,MAAMC,OAAO,GAAGH,OAAO,CAACI,KAAK,CAAC,CAAC,EAAEH,cAAc,CAAC;EAChD,MAAMI,UAAU,GAAGL,OAAO,CAACI,KAAK,CAACH,cAAc,GAAG,CAAC,CAAC;EAEpD,IAAIA,cAAc,IAAI,CAAC,IAAII,UAAU,CAACC,MAAM,KAAK,CAAC,EAAE;IAClD,MAAM,IAAIR,sBAAsB,CAACE,OAAO,CAAC;EAC3C;EAEA,OAAO;IACLG,OAAO;IACPI,aAAa,EAAEF,UAAU,CAACG,UAAU,CAAC,IAAI,CAAC,GAAGH,UAAU,GAAG,KAAKA,UAAU;EAC3E,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ import { InvalidNativeRuntimeEventError } from "./errors.js";
4
+ function requireString(event, fieldName) {
5
+ const value = event.params[fieldName];
6
+ if (typeof value !== 'string' || value.length === 0) {
7
+ throw new InvalidNativeRuntimeEventError(event.name, fieldName);
8
+ }
9
+ return value;
10
+ }
11
+ export function parseNativeRuntimeEvent(event) {
12
+ switch (event.name) {
13
+ case 'preloadApp':
14
+ return {
15
+ name: 'preloadApp',
16
+ params: {
17
+ appName: requireString(event, 'appName')
18
+ }
19
+ };
20
+ case 'openApp':
21
+ return {
22
+ name: 'openApp',
23
+ params: {
24
+ appName: requireString(event, 'appName'),
25
+ scheme: requireString(event, 'scheme'),
26
+ sessionId: requireString(event, 'sessionId')
27
+ }
28
+ };
29
+ case 'closeApp':
30
+ return {
31
+ name: 'closeApp',
32
+ params: {
33
+ sessionId: requireString(event, 'sessionId')
34
+ }
35
+ };
36
+ case 'sessionVisibilityChanged':
37
+ {
38
+ const isVisible = event.params.isVisible;
39
+ if (typeof isVisible !== 'boolean') {
40
+ throw new InvalidNativeRuntimeEventError(event.name, 'isVisible');
41
+ }
42
+ return {
43
+ name: 'sessionVisibilityChanged',
44
+ params: {
45
+ isVisible,
46
+ sessionId: requireString(event, 'sessionId')
47
+ }
48
+ };
49
+ }
50
+ default:
51
+ throw new InvalidNativeRuntimeEventError(event.name);
52
+ }
53
+ }
54
+ //# sourceMappingURL=parseNativeRuntimeEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["InvalidNativeRuntimeEventError","requireString","event","fieldName","value","params","length","name","parseNativeRuntimeEvent","appName","scheme","sessionId","isVisible"],"sourceRoot":"../../../src","sources":["runtime/parseNativeRuntimeEvent.ts"],"mappings":";;AAEA,SAASA,8BAA8B,QAAQ,aAAU;AAEzD,SAASC,aAAaA,CAACC,KAAsC,EAAEC,SAA6C,EAAU;EACpH,MAAMC,KAAK,GAAGF,KAAK,CAACG,MAAM,CAACF,SAAS,CAAC;EACrC,IAAI,OAAOC,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACE,MAAM,KAAK,CAAC,EAAE;IACnD,MAAM,IAAIN,8BAA8B,CAACE,KAAK,CAACK,IAAI,EAAEJ,SAAS,CAAC;EACjE;EACA,OAAOC,KAAK;AACd;AAEA,OAAO,SAASI,uBAAuBA,CAACN,KAAsC,EAA6B;EACzG,QAAQA,KAAK,CAACK,IAAI;IAChB,KAAK,YAAY;MACf,OAAO;QACLA,IAAI,EAAE,YAAY;QAClBF,MAAM,EAAE;UAAEI,OAAO,EAAER,aAAa,CAACC,KAAK,EAAE,SAAS;QAAE;MACrD,CAAC;IAEH,KAAK,SAAS;MACZ,OAAO;QACLK,IAAI,EAAE,SAAS;QACfF,MAAM,EAAE;UACNI,OAAO,EAAER,aAAa,CAACC,KAAK,EAAE,SAAS,CAAC;UACxCQ,MAAM,EAAET,aAAa,CAACC,KAAK,EAAE,QAAQ,CAAC;UACtCS,SAAS,EAAEV,aAAa,CAACC,KAAK,EAAE,WAAW;QAC7C;MACF,CAAC;IAEH,KAAK,UAAU;MACb,OAAO;QACLK,IAAI,EAAE,UAAU;QAChBF,MAAM,EAAE;UAAEM,SAAS,EAAEV,aAAa,CAACC,KAAK,EAAE,WAAW;QAAE;MACzD,CAAC;IAEH,KAAK,0BAA0B;MAAE;QAC/B,MAAMU,SAAS,GAAGV,KAAK,CAACG,MAAM,CAACO,SAAS;QACxC,IAAI,OAAOA,SAAS,KAAK,SAAS,EAAE;UAClC,MAAM,IAAIZ,8BAA8B,CAACE,KAAK,CAACK,IAAI,EAAE,WAAW,CAAC;QACnE;QACA,OAAO;UACLA,IAAI,EAAE,0BAA0B;UAChCF,MAAM,EAAE;YACNO,SAAS;YACTD,SAAS,EAAEV,aAAa,CAACC,KAAK,EAAE,WAAW;UAC7C;QACF,CAAC;MACH;IAEA;MACE,MAAM,IAAIF,8BAA8B,CAACE,KAAK,CAACK,IAAI,CAAC;EACxD;AACF","ignoreList":[]}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ import { AppContainerAlreadyRegisteredError, ExposedModuleAlreadyRegisteredError, ExposedModuleNotFoundError, SharedModuleAlreadyRegisteredError } from "./errors.js";
4
+ import { parseAppRequest } from "./parseAppRequest.js";
5
+ export function getMicroFrontendRuntimeContext() {
6
+ const existingContext = globalThis._graniteMicroFrontend;
7
+ if (existingContext != null) {
8
+ return existingContext;
9
+ }
10
+ const context = {
11
+ containers: {},
12
+ sharedModules: {}
13
+ };
14
+ globalThis._graniteMicroFrontend = context;
15
+ return context;
16
+ }
17
+ export function createContainer(appName, config = {}) {
18
+ const containers = getMicroFrontendRuntimeContext().containers;
19
+ if (containers[appName] != null) {
20
+ throw new AppContainerAlreadyRegisteredError(appName);
21
+ }
22
+ const container = {
23
+ appName,
24
+ config,
25
+ exposedModules: {}
26
+ };
27
+ containers[appName] = container;
28
+ return container;
29
+ }
30
+ export function exposeModule(container, exposedModule, module) {
31
+ const normalizedModule = normalizeExposedModule(exposedModule);
32
+ if (container.exposedModules[normalizedModule] != null) {
33
+ throw new ExposedModuleAlreadyRegisteredError(container.appName, normalizedModule);
34
+ }
35
+ container.exposedModules[normalizedModule] = module;
36
+ }
37
+ export function registerShared(moduleName, module) {
38
+ const sharedModules = getMicroFrontendRuntimeContext().sharedModules;
39
+ const existingModule = sharedModules[moduleName];
40
+ if (existingModule != null) {
41
+ if (Object.is(existingModule.get(), module)) {
42
+ return;
43
+ }
44
+ throw new SharedModuleAlreadyRegisteredError(moduleName);
45
+ }
46
+ sharedModules[moduleName] = {
47
+ get: () => module,
48
+ loaded: true
49
+ };
50
+ }
51
+ export function getContainer(appName) {
52
+ return getMicroFrontendRuntimeContext().containers[appName] ?? null;
53
+ }
54
+ export function removeContainer(appName) {
55
+ const containers = getMicroFrontendRuntimeContext().containers;
56
+ const container = containers[appName];
57
+ if (container == null) {
58
+ return;
59
+ }
60
+ for (const exposedModule of Object.keys(container.exposedModules)) {
61
+ Reflect.deleteProperty(container.exposedModules, exposedModule);
62
+ }
63
+ Reflect.deleteProperty(containers, appName);
64
+ }
65
+ export function hasContainer(appName) {
66
+ return getContainer(appName) != null;
67
+ }
68
+ export function importModule(request) {
69
+ const {
70
+ appName,
71
+ exposedModule
72
+ } = parseAppRequest(request);
73
+ const module = getContainer(appName)?.exposedModules[exposedModule];
74
+ if (module == null) {
75
+ throw new ExposedModuleNotFoundError(appName, exposedModule);
76
+ }
77
+ return module;
78
+ }
79
+ function normalizeExposedModule(exposedModule) {
80
+ return exposedModule.startsWith('./') ? exposedModule : `./${exposedModule}`;
81
+ }
82
+ export const microFrontendModuleRegistry = {
83
+ hasContainer,
84
+ importModule,
85
+ removeContainer
86
+ };
87
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AppContainerAlreadyRegisteredError","ExposedModuleAlreadyRegisteredError","ExposedModuleNotFoundError","SharedModuleAlreadyRegisteredError","parseAppRequest","getMicroFrontendRuntimeContext","existingContext","globalThis","_graniteMicroFrontend","context","containers","sharedModules","createContainer","appName","config","container","exposedModules","exposeModule","exposedModule","module","normalizedModule","normalizeExposedModule","registerShared","moduleName","existingModule","Object","is","get","loaded","getContainer","removeContainer","keys","Reflect","deleteProperty","hasContainer","importModule","request","startsWith","microFrontendModuleRegistry"],"sourceRoot":"../../../src","sources":["runtime/registry.ts"],"mappings":";;AAEA,SACEA,kCAAkC,EAClCC,mCAAmC,EACnCC,0BAA0B,EAC1BC,kCAAkC,QAC7B,aAAU;AACjB,SAASC,eAAe,QAAQ,sBAAmB;AAgCnD,OAAO,SAASC,8BAA8BA,CAAA,EAAgC;EAC5E,MAAMC,eAAe,GAAGC,UAAU,CAACC,qBAAqB;EACxD,IAAIF,eAAe,IAAI,IAAI,EAAE;IAC3B,OAAOA,eAAe;EACxB;EAEA,MAAMG,OAAoC,GAAG;IAC3CC,UAAU,EAAE,CAAC,CAAC;IACdC,aAAa,EAAE,CAAC;EAClB,CAAC;EACDJ,UAAU,CAACC,qBAAqB,GAAGC,OAAO;EAC1C,OAAOA,OAAO;AAChB;AAEA,OAAO,SAASG,eAAeA,CAACC,OAAe,EAAEC,MAA0B,GAAG,CAAC,CAAC,EAAgB;EAC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UAAU,CAACG,OAAO,CAAC,IAAI,IAAI;AACrE;AAEA,OAAO,SAASiB,eAAeA,CAACjB,OAAe,EAAQ;EACrD,MAAMH,UAAU,GAAGL,8BAA8B,CAAC,CAAC,CAACK,UAAU;EAC9D,MAAMK,SAAS,GAAGL,UAAU,CAACG,OAAO,CAAC;EACrC,IAAIE,SAAS,IAAI,IAAI,EAAE;IACrB;EACF;EAEA,KAAK,MAAMG,aAAa,IAAIO,MAAM,CAACM,IAAI,CAAChB,SAAS,CAACC,cAAc,CAAC,EAAE;IACjEgB,OAAO,CAACC,cAAc,CAAClB,SAAS,CAACC,cAAc,EAAEE,aAAa,CAAC;EACjE;EACAc,OAAO,CAACC,cAAc,CAACvB,UAAU,EAAEG,OAAO,CAAC;AAC7C;AAEA,OAAO,SAASqB,YAAYA,CAACrB,OAAe,EAAW;EACrD,OAAOgB,YAAY,CAAChB,OAAO,CAAC,IAAI,IAAI;AACtC;AAEA,OAAO,SAASsB,YAAYA,CAAUC,OAAmB,EAAW;EAClE,MAAM;IAAEvB,OAAO;IAAEK;EAAc,CAAC,GAAGd,eAAe,CAACgC,OAAO,CAAC;EAC3D,MAAMjB,MAAM,GAAGU,YAAY,CAAChB,OAAO,CAAC,EAAEG,cAAc,CAACE,aAAa,CAAC;EACnE,IAAIC,MAAM,IAAI,IAAI,EAAE;IAClB,MAAM,IAAIjB,0BAA0B,CAACW,OAAO,EAAEK,aAAa,CAAC;EAC9D;EACA,OAAOC,MAAM;AACf;AAEA,SAASE,sBAAsBA,CAACH,aAAqB,EAAU;EAC7D,OAAOA,aAAa,CAACmB,UAAU,CAAC,IAAI,CAAC,GAAGnB,aAAa,GAAG,KAAKA,aAAa,EAAE;AAC9E;AAEA,OAAO,MAAMoB,2BAAwD,GAAG;EACtEJ,YAAY;EACZC,YAAY;EACZL;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ import { VisibilityChangedProvider } from '@granite-js/react-native';
4
+ import { createContext, useContext, useMemo } from 'react';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const MicroFrontendSessionContext = /*#__PURE__*/createContext(null);
7
+ export class MissingMicroFrontendSessionError extends Error {
8
+ constructor() {
9
+ super('useMicroFrontendSession must be used inside MicroFrontendSessionProvider');
10
+ this.name = 'MissingMicroFrontendSessionError';
11
+ }
12
+ }
13
+ export function MicroFrontendSessionProvider(props) {
14
+ const value = useMemo(() => ({
15
+ sessionId: props.sessionId
16
+ }), [props.sessionId]);
17
+ return /*#__PURE__*/_jsx(MicroFrontendSessionContext.Provider, {
18
+ value: value,
19
+ children: /*#__PURE__*/_jsx(VisibilityChangedProvider, {
20
+ isVisible: props.presentationVisibility,
21
+ children: props.children
22
+ })
23
+ });
24
+ }
25
+ export function useMicroFrontendSession() {
26
+ const session = useContext(MicroFrontendSessionContext);
27
+ if (session == null) {
28
+ throw new MissingMicroFrontendSessionError();
29
+ }
30
+ return session;
31
+ }
32
+ //# sourceMappingURL=MicroFrontendSessionContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["VisibilityChangedProvider","createContext","useContext","useMemo","jsx","_jsx","MicroFrontendSessionContext","MissingMicroFrontendSessionError","Error","constructor","name","MicroFrontendSessionProvider","props","value","sessionId","Provider","children","isVisible","presentationVisibility","useMicroFrontendSession","session"],"sourceRoot":"../../../src","sources":["session/MicroFrontendSessionContext.tsx"],"mappings":";;AAAA,SAASA,yBAAyB,QAAQ,0BAA0B;AACpE,SAASC,aAAa,EAAEC,UAAU,EAAEC,OAAO,QAA2C,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAW9F,MAAMC,2BAA2B,gBAAGL,aAAa,CAA8B,IAAI,CAAC;AAEpF,OAAO,MAAMM,gCAAgC,SAASC,KAAK,CAAC;EAC1DC,WAAWA,CAAA,EAAG;IACZ,KAAK,CAAC,0EAA0E,CAAC;IACjF,IAAI,CAACC,IAAI,GAAG,kCAAkC;EAChD;AACF;AAEA,OAAO,SAASC,4BAA4BA,CAACC,KAAwC,EAAgB;EACnG,MAAMC,KAAK,GAAGV,OAAO,CACnB,OAAO;IACLW,SAAS,EAAEF,KAAK,CAACE;EACnB,CAAC,CAAC,EACF,CAACF,KAAK,CAACE,SAAS,CAClB,CAAC;EAED,oBACET,IAAA,CAACC,2BAA2B,CAACS,QAAQ;IAACF,KAAK,EAAEA,KAAM;IAAAG,QAAA,eACjDX,IAAA,CAACL,yBAAyB;MAACiB,SAAS,EAAEL,KAAK,CAACM,sBAAuB;MAAAF,QAAA,EAChEJ,KAAK,CAACI;IAAQ,CACU;EAAC,CACQ,CAAC;AAE3C;AAEA,OAAO,SAASG,uBAAuBA,CAAA,EAAyB;EAC9D,MAAMC,OAAO,GAAGlB,UAAU,CAACI,2BAA2B,CAAC;EACvD,IAAIc,OAAO,IAAI,IAAI,EAAE;IACnB,MAAM,IAAIb,gCAAgC,CAAC,CAAC;EAC9C;EACA,OAAOa,OAAO;AAChB","ignoreList":[]}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ import { useLayoutEffect, useReducer } from 'react';
4
+ import { installPendingHostComponentBridge, resetPendingHostComponent } from "../host/pendingHostComponentStore.js";
5
+ const INITIAL_SESSIONS = [];
6
+ function reduceMicroFrontendSessions(sessions, event) {
7
+ switch (event.name) {
8
+ case 'openApp':
9
+ return sessions.some(({
10
+ sessionId
11
+ }) => sessionId === event.params.sessionId) ? sessions : [...sessions, {
12
+ appName: event.params.appName,
13
+ sessionId: event.params.sessionId,
14
+ scheme: event.params.scheme,
15
+ isVisible: false
16
+ }];
17
+ case 'closeApp':
18
+ return sessions.filter(({
19
+ sessionId
20
+ }) => sessionId !== event.params.sessionId);
21
+ case 'sessionVisibilityChanged':
22
+ return sessions.map(session => session.sessionId === event.params.sessionId ? {
23
+ ...session,
24
+ isVisible: event.params.isVisible
25
+ } : session);
26
+ default:
27
+ {
28
+ const exhaustiveEvent = event;
29
+ return exhaustiveEvent;
30
+ }
31
+ }
32
+ }
33
+ export function useMicroFrontendSessions(runtime) {
34
+ const [sessions, dispatch] = useReducer(reduceMicroFrontendSessions, INITIAL_SESSIONS);
35
+ useLayoutEffect(() => {
36
+ installPendingHostComponentBridge();
37
+ const subscription = runtime.onEvent(event => {
38
+ if (event.name === 'openApp') {
39
+ resetPendingHostComponent();
40
+ }
41
+ dispatch(event);
42
+ });
43
+ return () => subscription.remove();
44
+ }, [runtime]);
45
+ return sessions;
46
+ }
47
+ //# sourceMappingURL=useMicroFrontendSessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useLayoutEffect","useReducer","installPendingHostComponentBridge","resetPendingHostComponent","INITIAL_SESSIONS","reduceMicroFrontendSessions","sessions","event","name","some","sessionId","params","appName","scheme","isVisible","filter","map","session","exhaustiveEvent","useMicroFrontendSessions","runtime","dispatch","subscription","onEvent","remove"],"sourceRoot":"../../../src","sources":["session/useMicroFrontendSessions.ts"],"mappings":";;AAAA,SAASA,eAAe,EAAEC,UAAU,QAAQ,OAAO;AACnD,SACEC,iCAAiC,EACjCC,yBAAyB,QACpB,sCAAmC;AAa1C,MAAMC,gBAAsD,GAAG,EAAE;AAEjE,SAASC,2BAA2BA,CAClCC,QAA8C,EAC9CC,KAAgC,EACM;EACtC,QAAQA,KAAK,CAACC,IAAI;IAChB,KAAK,SAAS;MACZ,OAAOF,QAAQ,CAACG,IAAI,CAAC,CAAC;QAAEC;MAAU,CAAC,KAAKA,SAAS,KAAKH,KAAK,CAACI,MAAM,CAACD,SAAS,CAAC,GACzEJ,QAAQ,GACR,CACE,GAAGA,QAAQ,EACX;QACEM,OAAO,EAAEL,KAAK,CAACI,MAAM,CAACC,OAAO;QAC7BF,SAAS,EAAEH,KAAK,CAACI,MAAM,CAACD,SAAS;QACjCG,MAAM,EAAEN,KAAK,CAACI,MAAM,CAACE,MAAM;QAC3BC,SAAS,EAAE;MACb,CAAC,CACF;IACP,KAAK,UAAU;MACb,OAAOR,QAAQ,CAACS,MAAM,CAAC,CAAC;QAAEL;MAAU,CAAC,KAAKA,SAAS,KAAKH,KAAK,CAACI,MAAM,CAACD,SAAS,CAAC;IACjF,KAAK,0BAA0B;MAC7B,OAAOJ,QAAQ,CAACU,GAAG,CAAEC,OAAO,IAC1BA,OAAO,CAACP,SAAS,KAAKH,KAAK,CAACI,MAAM,CAACD,SAAS,GACxC;QAAE,GAAGO,OAAO;QAAEH,SAAS,EAAEP,KAAK,CAACI,MAAM,CAACG;MAAU,CAAC,GACjDG,OACN,CAAC;IACH;MAAS;QACP,MAAMC,eAAsB,GAAGX,KAAK;QACpC,OAAOW,eAAe;MACxB;EACF;AACF;AAEA,OAAO,SAASC,wBAAwBA,CACtCC,OAAiD,EACX;EACtC,MAAM,CAACd,QAAQ,EAAEe,QAAQ,CAAC,GAAGpB,UAAU,CACrCI,2BAA2B,EAC3BD,gBACF,CAAC;EAEDJ,eAAe,CAAC,MAAM;IACpBE,iCAAiC,CAAC,CAAC;IACnC,MAAMoB,YAAY,GAAGF,OAAO,CAACG,OAAO,CAAEhB,KAAK,IAAK;MAC9C,IAAIA,KAAK,CAACC,IAAI,KAAK,SAAS,EAAE;QAC5BL,yBAAyB,CAAC,CAAC;MAC7B;MACAkB,QAAQ,CAACd,KAAK,CAAC;IACjB,CAAC,CAAC;IAEF,OAAO,MAAMe,YAAY,CAACE,MAAM,CAAC,CAAC;EACpC,CAAC,EAAE,CAACJ,OAAO,CAAC,CAAC;EAEb,OAAOd,QAAQ;AACjB","ignoreList":[]}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ let nativeModule = null;
5
+ function getNativeModule() {
6
+ nativeModule ??= TurboModuleRegistry.getEnforcing('GraniteMicroFrontendRuntime');
7
+ return nativeModule;
8
+ }
9
+ const NativeGraniteMicroFrontendRuntime = {
10
+ evaluateScript(request) {
11
+ return getNativeModule().evaluateScript(request);
12
+ },
13
+ startEventDelivery() {
14
+ getNativeModule().startEventDelivery();
15
+ },
16
+ onEvent(listener) {
17
+ return getNativeModule().onEvent(listener);
18
+ }
19
+ };
20
+ export default NativeGraniteMicroFrontendRuntime;
21
+ //# sourceMappingURL=NativeGraniteMicroFrontendRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","nativeModule","getNativeModule","getEnforcing","NativeGraniteMicroFrontendRuntime","evaluateScript","request","startEventDelivery","onEvent","listener"],"sourceRoot":"../../../src","sources":["specs/NativeGraniteMicroFrontendRuntime.ts"],"mappings":";;AAAA,SAA8CA,mBAAmB,QAAQ,cAAc;AAwBvF,IAAIC,YAAyB,GAAG,IAAI;AAEpC,SAASC,eAAeA,CAAA,EAAG;EACzBD,YAAY,KAAKD,mBAAmB,CAACG,YAAY,CAAO,6BAA6B,CAAC;EACtF,OAAOF,YAAY;AACrB;AAEA,MAAMG,iCAAuC,GAAG;EAC9CC,cAAcA,CAACC,OAAO,EAAE;IACtB,OAAOJ,eAAe,CAAC,CAAC,CAACG,cAAc,CAACC,OAAO,CAAC;EAClD,CAAC;EACDC,kBAAkBA,CAAA,EAAG;IACnBL,eAAe,CAAC,CAAC,CAACK,kBAAkB,CAAC,CAAC;EACxC,CAAC;EACDC,OAAOA,CAACC,QAAQ,EAAE;IAChB,OAAOP,eAAe,CAAC,CAAC,CAACM,OAAO,CAACC,QAAQ,CAAC;EAC5C;AACF,CAAC;AAED,eAAeL,iCAAiC","ignoreList":[]}