@granite-js/micro-frontend 2.2.0 → 2.3.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.
- package/CHANGELOG.md +17 -0
- package/README.md +14 -3
- package/android/src/main/cpp/BundleEvaluator.cpp +24 -1
- package/android/src/main/cpp/BundleEvaluator.h +6 -0
- package/android/src/main/java/run/granite/microfrontend/BundleEvaluator.kt +50 -10
- package/android/src/test/java/run/granite/microfrontend/BundleEvaluatorTest.kt +42 -0
- package/dist/module/index.js +1 -0
- package/dist/module/index.js.map +1 -1
- package/dist/module/plugin/prelude.js +4 -1
- package/dist/module/plugin/prelude.js.map +1 -1
- package/dist/module/runtime/containerRegistry.js +8 -2
- package/dist/module/runtime/containerRegistry.js.map +1 -1
- package/dist/module/runtime/getAppName.js +37 -0
- package/dist/module/runtime/getAppName.js.map +1 -0
- package/dist/module/runtime/registry.js.map +1 -1
- package/dist/module/runtime/runtimeSourceURL.js +46 -0
- package/dist/module/runtime/runtimeSourceURL.js.map +1 -0
- package/dist/typescript/index.d.ts +2 -1
- package/dist/typescript/runtime/getAppName.d.ts +6 -0
- package/dist/typescript/runtime/registry.d.ts +4 -0
- package/dist/typescript/runtime/runtimeSourceURL.d.ts +5 -0
- package/dist/typescript/types.d.ts +1 -0
- package/package.json +4 -4
- package/src/index.ts +7 -1
- package/src/plugin/prelude.ts +6 -1
- package/src/runtime/containerRegistry.ts +11 -2
- package/src/runtime/getAppName.ts +46 -0
- package/src/runtime/registry.ts +5 -0
- package/src/runtime/runtimeSourceURL.ts +48 -0
- package/src/types.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @granite-js/micro-frontend
|
|
2
2
|
|
|
3
|
+
## 2.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 56a5ce8: Support evaluating Android bundles packaged under `assets://` locators.
|
|
8
|
+
- @granite-js/utils@2.3.1
|
|
9
|
+
|
|
10
|
+
## 2.3.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 6a8eae2: Expose each evaluated app container's source URL through `AppContainer.runtime.sourceURL`, resolve the current container with `getAppName()`, and exact-match externally captured source URLs with `findAppNameBySourceURL()`.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- @granite-js/utils@2.3.0
|
|
19
|
+
|
|
3
20
|
## 2.2.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -131,6 +131,15 @@ The durable owner is `global.__MICRO_FRONTEND__` with exactly this shape:
|
|
|
131
131
|
- A current container registration creates paired legacy/current views for the
|
|
132
132
|
same app name. The pair is transparent across separately evaluated bundles:
|
|
133
133
|
it is one remote-owned registration, not two independently owned copies.
|
|
134
|
+
- A current container exposes the evaluated bundle source through
|
|
135
|
+
`runtime.sourceURL`. The generated prelude captures it from the bundle's
|
|
136
|
+
evaluation stack once when registering the container. Legacy container
|
|
137
|
+
adapters omit `runtime` until a compatible bundle is evaluated.
|
|
138
|
+
- `getAppName()` resolves the current bundle's structured source URL against
|
|
139
|
+
the container registry. A host call returns the host container name, while a
|
|
140
|
+
remote call returns that remote's name without reading a last-evaluated
|
|
141
|
+
global value. `findAppNameBySourceURL(sourceURL)` exposes the same exact
|
|
142
|
+
registry lookup for runtimes that already provide a structured source URL.
|
|
134
143
|
- The dispose callback registry and registrar live on the same canonical
|
|
135
144
|
context as non-enumerable properties. They are reused across separately
|
|
136
145
|
evaluated bundles without changing the three-key enumerable registry shape.
|
|
@@ -159,7 +168,8 @@ app name exactly rather than routing it to another remote.
|
|
|
159
168
|
## JavaScript runtime
|
|
160
169
|
|
|
161
170
|
The adapter owns bundle selection, download, integrity verification, and
|
|
162
|
-
caching. It returns an absolute local bundle path
|
|
171
|
+
caching. It returns an absolute local bundle path, or an Android `assets://`
|
|
172
|
+
locator for a bundle packaged in the application.
|
|
163
173
|
|
|
164
174
|
```ts
|
|
165
175
|
import { createMicroFrontendRuntime } from '@granite-js/micro-frontend';
|
|
@@ -211,7 +221,7 @@ The public runtime API is:
|
|
|
211
221
|
| -------------------------- | --------------------------------------------------------------- |
|
|
212
222
|
| `preloadApp(appName)` | Load and evaluate one app without importing an exposed module. |
|
|
213
223
|
| `importApp(request)` | Ensure the app is evaluated and import `appName/exposedModule`. |
|
|
214
|
-
| `evaluateScript(filePath)` | Evaluate
|
|
224
|
+
| `evaluateScript(filePath)` | Evaluate a local file or Android packaged asset in the retained runtime. |
|
|
215
225
|
| `onEvent(listener)` | Subscribe to native open, close, and visibility events. |
|
|
216
226
|
|
|
217
227
|
The host can provide `onLifecycleEvent` when creating the runtime for logging
|
|
@@ -362,7 +372,8 @@ The brownfield application must:
|
|
|
362
372
|
boundary;
|
|
363
373
|
4. bind native screen lifecycle to the session APIs below;
|
|
364
374
|
5. install a Portal destination with the same `sessionId`;
|
|
365
|
-
6. provide `adapter.loadBundle()` and return an absolute verified bundle path
|
|
375
|
+
6. provide `adapter.loadBundle()` and return an absolute verified bundle path,
|
|
376
|
+
or an Android `assets://` locator for a verified packaged bundle;
|
|
366
377
|
7. keep the React tree mounted until native teardown emits `closeApp`; and
|
|
367
378
|
8. keep Granite's base brownfield view APIs, such as scheme resolution and
|
|
368
379
|
closing the current Granite view, in the Granite host integration. They are
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
namespace granite::microfrontend {
|
|
7
7
|
|
|
8
|
+
using facebook::jni::JArrayByte;
|
|
8
9
|
using facebook::jni::JString;
|
|
9
10
|
using facebook::jni::alias_ref;
|
|
10
11
|
using facebook::jsi::Runtime;
|
|
@@ -12,7 +13,29 @@ using facebook::jsi::StringBuffer;
|
|
|
12
13
|
|
|
13
14
|
void BundleEvaluator::registerNatives() {
|
|
14
15
|
registerHybrid(
|
|
15
|
-
{makeNativeMethod("evaluateFileSync", BundleEvaluator::evaluateFileSync)
|
|
16
|
+
{makeNativeMethod("evaluateFileSync", BundleEvaluator::evaluateFileSync),
|
|
17
|
+
makeNativeMethod("evaluateScriptSync", BundleEvaluator::evaluateScriptSync)});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void BundleEvaluator::evaluateScriptSync(
|
|
21
|
+
alias_ref<jhybridobject>,
|
|
22
|
+
jlong runtimePointer,
|
|
23
|
+
alias_ref<JArrayByte> scriptData,
|
|
24
|
+
alias_ref<JString> sourceUrl) {
|
|
25
|
+
if (runtimePointer == 0) {
|
|
26
|
+
facebook::jni::throwNewJavaException(
|
|
27
|
+
"java/lang/IllegalStateException", "JavaScript runtime is unavailable");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
auto pinnedScriptData = scriptData->pin();
|
|
32
|
+
std::string source{
|
|
33
|
+
reinterpret_cast<const char *>(pinnedScriptData.get()),
|
|
34
|
+
pinnedScriptData.size()};
|
|
35
|
+
auto *runtime = reinterpret_cast<Runtime *>(runtimePointer);
|
|
36
|
+
runtime->evaluateJavaScript(
|
|
37
|
+
std::make_shared<StringBuffer>(std::move(source)),
|
|
38
|
+
sourceUrl->toStdString());
|
|
16
39
|
}
|
|
17
40
|
|
|
18
41
|
void BundleEvaluator::evaluateFileSync(
|
|
@@ -15,6 +15,12 @@ struct BundleEvaluator : facebook::jni::HybridClass<BundleEvaluator> {
|
|
|
15
15
|
jlong runtimePointer,
|
|
16
16
|
facebook::jni::alias_ref<facebook::jni::JString> filePath,
|
|
17
17
|
facebook::jni::alias_ref<facebook::jni::JString> sourceUrl);
|
|
18
|
+
|
|
19
|
+
static void evaluateScriptSync(
|
|
20
|
+
facebook::jni::alias_ref<jhybridobject>,
|
|
21
|
+
jlong runtimePointer,
|
|
22
|
+
facebook::jni::alias_ref<facebook::jni::JArrayByte> scriptData,
|
|
23
|
+
facebook::jni::alias_ref<facebook::jni::JString> sourceUrl);
|
|
18
24
|
};
|
|
19
25
|
|
|
20
26
|
} // namespace granite::microfrontend
|
|
@@ -1,11 +1,48 @@
|
|
|
1
1
|
package run.granite.microfrontend
|
|
2
2
|
|
|
3
|
+
import android.content.res.AssetManager
|
|
3
4
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
5
|
import com.facebook.react.common.annotations.FrameworkAPI
|
|
5
6
|
import java.io.File
|
|
6
7
|
import java.io.FileNotFoundException
|
|
7
8
|
import java.io.IOException
|
|
8
9
|
|
|
10
|
+
internal sealed interface ResolvedBundleSource {
|
|
11
|
+
val sourceUrl: String
|
|
12
|
+
|
|
13
|
+
data class Asset(
|
|
14
|
+
val scriptData: ByteArray,
|
|
15
|
+
override val sourceUrl: String,
|
|
16
|
+
) : ResolvedBundleSource
|
|
17
|
+
|
|
18
|
+
data class FilePath(
|
|
19
|
+
val filePath: String,
|
|
20
|
+
override val sourceUrl: String,
|
|
21
|
+
) : ResolvedBundleSource
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
internal fun resolveBundleSource(assetManager: AssetManager, bundlePath: String): ResolvedBundleSource {
|
|
25
|
+
if (bundlePath.startsWith(ASSET_PREFIX)) {
|
|
26
|
+
val assetPath = bundlePath.removePrefix(ASSET_PREFIX)
|
|
27
|
+
require(assetPath.isNotBlank()) { "Bundle asset path must not be blank: $bundlePath" }
|
|
28
|
+
val scriptData = assetManager.open(assetPath).use { it.readBytes() }
|
|
29
|
+
if (scriptData.isEmpty()) {
|
|
30
|
+
throw IOException("Bundle asset is empty: $bundlePath")
|
|
31
|
+
}
|
|
32
|
+
return ResolvedBundleSource.Asset(scriptData, bundlePath)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
val file = File(bundlePath)
|
|
36
|
+
require(file.isAbsolute) { "Bundle path must be absolute: $bundlePath" }
|
|
37
|
+
if (!file.exists()) {
|
|
38
|
+
throw FileNotFoundException("Bundle file does not exist: $bundlePath")
|
|
39
|
+
}
|
|
40
|
+
if (!file.canRead()) {
|
|
41
|
+
throw IOException("Bundle file is not readable: $bundlePath")
|
|
42
|
+
}
|
|
43
|
+
return ResolvedBundleSource.FilePath(bundlePath, file.toURI().toString())
|
|
44
|
+
}
|
|
45
|
+
|
|
9
46
|
@OptIn(FrameworkAPI::class)
|
|
10
47
|
internal class BundleEvaluator(
|
|
11
48
|
private val reactContext: ReactApplicationContext,
|
|
@@ -22,20 +59,21 @@ internal class BundleEvaluator(
|
|
|
22
59
|
sourceUrl: String,
|
|
23
60
|
)
|
|
24
61
|
|
|
62
|
+
private external fun evaluateScriptSync(
|
|
63
|
+
runtimePointer: Long,
|
|
64
|
+
scriptData: ByteArray,
|
|
65
|
+
sourceUrl: String,
|
|
66
|
+
)
|
|
67
|
+
|
|
25
68
|
@Throws(FileNotFoundException::class, IOException::class)
|
|
26
69
|
fun evaluateFile(filePath: String) {
|
|
27
|
-
val
|
|
28
|
-
require(file.isAbsolute) { "Bundle path must be absolute: $filePath" }
|
|
29
|
-
if (!file.exists()) {
|
|
30
|
-
throw FileNotFoundException("Bundle file does not exist: $filePath")
|
|
31
|
-
}
|
|
32
|
-
if (!file.canRead()) {
|
|
33
|
-
throw IOException("Bundle file is not readable: $filePath")
|
|
34
|
-
}
|
|
35
|
-
|
|
70
|
+
val source = resolveBundleSource(reactContext.assets, filePath)
|
|
36
71
|
val runtimePointer = reactContext.javaScriptContextHolder?.get()
|
|
37
72
|
?: throw IllegalStateException("JavaScript runtime is unavailable")
|
|
38
|
-
|
|
73
|
+
when (source) {
|
|
74
|
+
is ResolvedBundleSource.Asset -> evaluateScriptSync(runtimePointer, source.scriptData, source.sourceUrl)
|
|
75
|
+
is ResolvedBundleSource.FilePath -> evaluateFileSync(runtimePointer, source.filePath, source.sourceUrl)
|
|
76
|
+
}
|
|
39
77
|
}
|
|
40
78
|
|
|
41
79
|
private companion object {
|
|
@@ -44,3 +82,5 @@ internal class BundleEvaluator(
|
|
|
44
82
|
}
|
|
45
83
|
}
|
|
46
84
|
}
|
|
85
|
+
|
|
86
|
+
private const val ASSET_PREFIX = "assets://"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
package run.granite.microfrontend
|
|
2
|
+
|
|
3
|
+
import android.content.res.AssetManager
|
|
4
|
+
import org.junit.Assert.assertArrayEquals
|
|
5
|
+
import org.junit.Assert.assertEquals
|
|
6
|
+
import org.junit.Assert.assertTrue
|
|
7
|
+
import org.junit.Test
|
|
8
|
+
import org.mockito.Mockito.mock
|
|
9
|
+
import org.mockito.Mockito.verify
|
|
10
|
+
import org.mockito.Mockito.`when`
|
|
11
|
+
import java.io.ByteArrayInputStream
|
|
12
|
+
import java.io.File
|
|
13
|
+
|
|
14
|
+
class BundleEvaluatorTest {
|
|
15
|
+
@Test
|
|
16
|
+
fun `asset bundle locator reads the built-in bundle through AssetManager`() {
|
|
17
|
+
val assetManager = mock(AssetManager::class.java)
|
|
18
|
+
val scriptData = "built-in bundle".toByteArray()
|
|
19
|
+
`when`(assetManager.open("bundles/example.hbc")).thenReturn(ByteArrayInputStream(scriptData))
|
|
20
|
+
|
|
21
|
+
val source = resolveBundleSource(assetManager, "assets://bundles/example.hbc")
|
|
22
|
+
|
|
23
|
+
assertTrue(source is ResolvedBundleSource.Asset)
|
|
24
|
+
assertArrayEquals(scriptData, (source as ResolvedBundleSource.Asset).scriptData)
|
|
25
|
+
assertEquals("assets://bundles/example.hbc", source.sourceUrl)
|
|
26
|
+
verify(assetManager).open("bundles/example.hbc")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Test
|
|
30
|
+
fun `absolute file path keeps filesystem bundle evaluation`() {
|
|
31
|
+
val bundleFile = File.createTempFile("granite-micro-frontend", ".hbc")
|
|
32
|
+
try {
|
|
33
|
+
val source = resolveBundleSource(mock(AssetManager::class.java), bundleFile.absolutePath)
|
|
34
|
+
|
|
35
|
+
assertTrue(source is ResolvedBundleSource.FilePath)
|
|
36
|
+
assertEquals(bundleFile.absolutePath, (source as ResolvedBundleSource.FilePath).filePath)
|
|
37
|
+
assertEquals(bundleFile.toURI().toString(), source.sourceUrl)
|
|
38
|
+
} finally {
|
|
39
|
+
bundleFile.delete()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
package/dist/module/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
export { createMicroFrontendRuntime } from "./createMicroFrontendRuntime.js";
|
|
4
4
|
export { createRoute } from "./createRoute.js";
|
|
5
|
+
export { findAppNameBySourceURL, getAppName } from "./runtime/getAppName.js";
|
|
5
6
|
export { PendingHostComponent, usePendingHostComponentController, useIsPendingHostComponentHidden, useResolvedPendingHostComponent } from "./host/PendingHostComponent.js";
|
|
6
7
|
export { createPendingHostComponentRoutePrefix, normalizeRoutePath } from "./host/routeMatcher.js";
|
|
7
8
|
export { hidePendingHostComponent, installPendingHostComponentBridge, registerPendingHostComponentRoute, resetPendingHostComponent, resolvePendingHostComponent } from "./host/pendingHostComponentStore.js";
|
package/dist/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createMicroFrontendRuntime","createRoute","PendingHostComponent","usePendingHostComponentController","useIsPendingHostComponentHidden","useResolvedPendingHostComponent","createPendingHostComponentRoutePrefix","normalizeRoutePath","hidePendingHostComponent","installPendingHostComponentBridge","registerPendingHostComponentRoute","resetPendingHostComponent","resolvePendingHostComponent","MicroFrontendSessionProvider","MissingMicroFrontendSessionError","useMicroFrontendSession","useMicroFrontendSessions","default","Portal","AppContainerNotFoundError","ExposedModuleNotFoundError","InvalidAppNameError","InvalidAppRequestError","InvalidNativeRuntimeEventError"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,0BAA0B,QAAQ,iCAA8B;AAEzE,SAASC,WAAW,QAAQ,kBAAe;
|
|
1
|
+
{"version":3,"names":["createMicroFrontendRuntime","createRoute","findAppNameBySourceURL","getAppName","PendingHostComponent","usePendingHostComponentController","useIsPendingHostComponentHidden","useResolvedPendingHostComponent","createPendingHostComponentRoutePrefix","normalizeRoutePath","hidePendingHostComponent","installPendingHostComponentBridge","registerPendingHostComponentRoute","resetPendingHostComponent","resolvePendingHostComponent","MicroFrontendSessionProvider","MissingMicroFrontendSessionError","useMicroFrontendSession","useMicroFrontendSessions","default","Portal","AppContainerNotFoundError","ExposedModuleNotFoundError","InvalidAppNameError","InvalidAppRequestError","InvalidNativeRuntimeEventError"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,0BAA0B,QAAQ,iCAA8B;AAEzE,SAASC,WAAW,QAAQ,kBAAe;AAE3C,SAASC,sBAAsB,EAAEC,UAAU,QAAQ,yBAAsB;AAEzE,SACEC,oBAAoB,EACpBC,iCAAiC,EACjCC,+BAA+B,EAC/BC,+BAA+B,QAC1B,gCAA6B;AASpC,SACEC,qCAAqC,EACrCC,kBAAkB,QACb,wBAAqB;AAC5B,SACEC,wBAAwB,EACxBC,iCAAiC,EACjCC,iCAAiC,EACjCC,yBAAyB,EACzBC,2BAA2B,QACtB,qCAAkC;AACzC,SACEC,4BAA4B,EAC5BC,gCAAgC,EAChCC,uBAAuB,QAClB,0CAAuC;AAE9C,SAASC,wBAAwB,QAAQ,uCAAoC;AAQ7E,SAASC,OAAO,IAAIC,MAAM,QAAQ,mCAAmC;AAerE,SACEC,yBAAyB,EACzBC,0BAA0B,EAC1BC,mBAAmB,EACnBC,sBAAsB,EACtBC,8BAA8B,QACzB,qBAAkB","ignoreList":[]}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { globalContextScript } from "./globalContextScript.js";
|
|
5
5
|
import { CONTAINER_PAIRING_KEY } from "../runtime/containerPairing.js";
|
|
6
|
+
import { captureStackFrames, resolveCurrentSourceURL } from "../runtime/runtimeSourceURL.js";
|
|
6
7
|
export function getPreludeConfig(options, appName) {
|
|
7
8
|
const eagerSharedModules = Object.entries(options.shared ?? {}).filter(([, config]) => !Array.isArray(options.shared) && config.eager === true);
|
|
8
9
|
const registerStatements = eagerSharedModules.map(([moduleName], index) => {
|
|
@@ -17,9 +18,11 @@ export function getPreludeConfig(options, appName) {
|
|
|
17
18
|
shared: options.shared
|
|
18
19
|
});
|
|
19
20
|
const containerName = appName == null ? 'global.__granite.app.name' : JSON.stringify(appName);
|
|
21
|
+
const captureFrames = captureStackFrames.toString();
|
|
22
|
+
const resolveSourceURL = resolveCurrentSourceURL.toString();
|
|
20
23
|
return {
|
|
21
24
|
banner: [globalContextScript, '(function installMicroFrontendLifecycle(context) {', ' const callbacksDescriptor = Object.getOwnPropertyDescriptor(context, "disposeCallbacksByApp");', ' const disposeDescriptor = Object.getOwnPropertyDescriptor(context, "dispose");', ' const disposeCallbacksByApp = callbacksDescriptor == null ? {} : callbacksDescriptor.value;', ' if (typeof disposeCallbacksByApp !== "object" || disposeCallbacksByApp == null || Array.isArray(disposeCallbacksByApp)) {', ' throw new Error("Cannot install micro-frontend lifecycle: invalid-dispose-callback-registry");', ' }', ' const dispose = disposeDescriptor == null ? function dispose(appName, callback) {', ' if (typeof appName !== "string" || typeof callback !== "function") {', ' throw new Error("dispose() must be compiled with the microFrontend plugin");', ' }', ' const callbacks = disposeCallbacksByApp[appName] ||= new Set();', ' callbacks.add(callback);', ' let isRegistered = true;', ' return function unregisterDispose() {', ' if (!isRegistered) { return; }', ' isRegistered = false;', ' callbacks.delete(callback);', ' };', ' } : disposeDescriptor.value;', ' if (typeof dispose !== "function") {', ' throw new Error("Cannot install micro-frontend lifecycle: invalid-dispose-registrar");', ' }', ' try {', ' if (!Reflect.defineProperty(context, "disposeCallbacksByApp", {', ' configurable: true, enumerable: false, value: disposeCallbacksByApp, writable: true,', ' }) || !Reflect.defineProperty(context, "dispose", {', ' configurable: true, enumerable: false, value: dispose, writable: true,', ' })) {', ' throw new Error("Cannot install micro-frontend lifecycle: canonical-context-is-locked");', ' }', ' } catch (error) {', ' if (callbacksDescriptor == null) {', ' Reflect.deleteProperty(context, "disposeCallbacksByApp");', ' } else {', ' Reflect.defineProperty(context, "disposeCallbacksByApp", callbacksDescriptor);', ' }', ' if (disposeDescriptor == null) {', ' Reflect.deleteProperty(context, "dispose");', ' } else {', ' Reflect.defineProperty(context, "dispose", disposeDescriptor);', ' }', ' throw error;', ' }', '})(global.__MICRO_FRONTEND__);'].join('\n'),
|
|
22
|
-
preludeScript: [`const __containerPairSymbol = Symbol.for(${JSON.stringify(CONTAINER_PAIRING_KEY)});`, 'const __legacyContainers = new WeakMap();', 'function createContainer(appName, config) {', ' const context = global.__MICRO_FRONTEND__;', ' const containers = context.__CONTAINERS__;', ' const instances = context.__INSTANCES__;', ' if (containers[appName] != null || typeof instances[appName] === "number") {', " throw new Error(`App container '${appName}' is already registered`);", ' }', ' if (!Object.isExtensible(containers) || !Object.isExtensible(instances)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' const modernContainer = { appName, config, exposedModules: {} };', ' const legacyContainer = { name: appName, config, exposeMap: {} };', ' try {', ' if (!Reflect.defineProperty(instances, appName, {', ' configurable: true, enumerable: false, value: instances.length, writable: false,', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' instances.push(legacyContainer);', ' if (!Reflect.set(containers, appName, modernContainer)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' if (!Reflect.defineProperty(modernContainer, __containerPairSymbol, {', ' configurable: true, enumerable: false, value: legacyContainer, writable: false,', ' }) || !Reflect.defineProperty(legacyContainer, __containerPairSymbol, {', ' configurable: true, enumerable: false, value: modernContainer, writable: false,', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' } catch (error) {', ' if (Object.is(instances[instances.length - 1], legacyContainer)) {', ' instances.pop();', ' }', ' Reflect.deleteProperty(instances, appName);', ' Reflect.deleteProperty(containers, appName);', ' Reflect.deleteProperty(modernContainer, __containerPairSymbol);', ' Reflect.deleteProperty(legacyContainer, __containerPairSymbol);', ' throw error;', ' }', ' __legacyContainers.set(modernContainer, legacyContainer);', ' return modernContainer;', '}', 'function exposeModule(container, exposedModule, moduleValue) {', " const normalizedModule = exposedModule.startsWith('./') ? exposedModule : `./${exposedModule}`;", " const legacyModule = exposedModule.startsWith('./') ? exposedModule.slice(2) : exposedModule;", ' const legacyContainer = __legacyContainers.get(container);', ' if (Reflect.has(container.exposedModules, normalizedModule) ||', ' (legacyContainer != null && Reflect.has(legacyContainer.exposeMap, legacyModule))) {', " throw new Error(`Exposed module '${normalizedModule}' is already registered in app container '${container.appName}'`);", ' }', ' const ownsModernContainer = Object.is(', ' global.__MICRO_FRONTEND__.__CONTAINERS__[container.appName],', ' container', ' );', ' let legacyModuleValue = moduleValue;', ' if (legacyContainer != null &&', ' ((typeof moduleValue === "object" && moduleValue != null) || typeof moduleValue === "function") &&', ' moduleValue.__esModule !== true) {', ' legacyModuleValue = typeof moduleValue === "function"', ' ? function (...args) { return Reflect.apply(moduleValue, this, args); }', ' : {};', ' for (const exportName of Reflect.ownKeys(moduleValue)) {', ' if (exportName === "__esModule" || exportName === "default") {', ' continue;', ' }', ' const sourceDescriptor = Reflect.getOwnPropertyDescriptor(moduleValue, exportName);', ' const facadeDescriptor = Reflect.getOwnPropertyDescriptor(legacyModuleValue, exportName);', ' if (sourceDescriptor == null || (facadeDescriptor != null && facadeDescriptor.configurable === false)) {', ' // Callable facades keep intrinsic non-configurable slots such as prototype.', ' continue;', ' }', ' if (!Reflect.defineProperty(legacyModuleValue, exportName, {', ' enumerable: sourceDescriptor.enumerable,', ' get: function () { return Reflect.get(moduleValue, exportName); },', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' }', ' const hasDefaultExport = Reflect.getOwnPropertyDescriptor(moduleValue, "default") != null;', ' Object.defineProperties(legacyModuleValue, {', ' __esModule: { value: true },', ' default: {', ' enumerable: true,', ' get: hasDefaultExport', ' ? function () { return Reflect.get(moduleValue, "default"); }', ' : function () { return moduleValue; },', ' },', ' });', ' }', ' try {', ' if (ownsModernContainer && !Reflect.set(container.exposedModules, normalizedModule, moduleValue)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' if (legacyContainer != null) {', ' Object.defineProperty(legacyContainer.exposeMap, legacyModule, {', ' configurable: true,', ' enumerable: true,', ' get: function () { return legacyModuleValue; },', ' });', ' }', ' } catch (error) {', ' if (ownsModernContainer) {', ' Reflect.deleteProperty(container.exposedModules, normalizedModule);', ' }', ' if (legacyContainer != null) {', ' Reflect.deleteProperty(legacyContainer.exposeMap, legacyModule);', ' }', ' throw error;', ' }', '}', 'function registerShared(moduleName, moduleValue) {', ' const sharedModules = global.__MICRO_FRONTEND__.__SHARED__;', ' const existingModule = sharedModules[moduleName];', ' if (existingModule != null) {', ' if (typeof existingModule === "object" &&', ' typeof existingModule.get === "function" &&', ' typeof existingModule.loaded === "boolean" &&', ' Object.is(existingModule.get(), moduleValue)) {', ' return;', ' }', " throw new Error(`Shared module '${moduleName}' is already registered`);", ' }', ' sharedModules[moduleName] = { get: () => moduleValue, loaded: true };', '}', `const __container = createContainer(${containerName}, ${containerConfig});`, ...registerStatements, ...exposeStatements].join('\n')
|
|
25
|
+
preludeScript: [`const __containerPairSymbol = Symbol.for(${JSON.stringify(CONTAINER_PAIRING_KEY)});`, 'const __legacyContainers = new WeakMap();', 'function createContainer(appName, config) {', ' const context = global.__MICRO_FRONTEND__;', ' const containers = context.__CONTAINERS__;', ' const instances = context.__INSTANCES__;', ' if (containers[appName] != null || typeof instances[appName] === "number") {', " throw new Error(`App container '${appName}' is already registered`);", ' }', ' if (!Object.isExtensible(containers) || !Object.isExtensible(instances)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ` const stackFrames = (${captureFrames})();`, ` const sourceURL = (${resolveSourceURL})(stackFrames);`, ' const modernContainer = { appName, config, exposedModules: {}, runtime: { sourceURL } };', ' const legacyContainer = { name: appName, config, exposeMap: {} };', ' try {', ' if (!Reflect.defineProperty(instances, appName, {', ' configurable: true, enumerable: false, value: instances.length, writable: false,', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' instances.push(legacyContainer);', ' if (!Reflect.set(containers, appName, modernContainer)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' if (!Reflect.defineProperty(modernContainer, __containerPairSymbol, {', ' configurable: true, enumerable: false, value: legacyContainer, writable: false,', ' }) || !Reflect.defineProperty(legacyContainer, __containerPairSymbol, {', ' configurable: true, enumerable: false, value: modernContainer, writable: false,', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' } catch (error) {', ' if (Object.is(instances[instances.length - 1], legacyContainer)) {', ' instances.pop();', ' }', ' Reflect.deleteProperty(instances, appName);', ' Reflect.deleteProperty(containers, appName);', ' Reflect.deleteProperty(modernContainer, __containerPairSymbol);', ' Reflect.deleteProperty(legacyContainer, __containerPairSymbol);', ' throw error;', ' }', ' __legacyContainers.set(modernContainer, legacyContainer);', ' return modernContainer;', '}', 'function exposeModule(container, exposedModule, moduleValue) {', " const normalizedModule = exposedModule.startsWith('./') ? exposedModule : `./${exposedModule}`;", " const legacyModule = exposedModule.startsWith('./') ? exposedModule.slice(2) : exposedModule;", ' const legacyContainer = __legacyContainers.get(container);', ' if (Reflect.has(container.exposedModules, normalizedModule) ||', ' (legacyContainer != null && Reflect.has(legacyContainer.exposeMap, legacyModule))) {', " throw new Error(`Exposed module '${normalizedModule}' is already registered in app container '${container.appName}'`);", ' }', ' const ownsModernContainer = Object.is(', ' global.__MICRO_FRONTEND__.__CONTAINERS__[container.appName],', ' container', ' );', ' let legacyModuleValue = moduleValue;', ' if (legacyContainer != null &&', ' ((typeof moduleValue === "object" && moduleValue != null) || typeof moduleValue === "function") &&', ' moduleValue.__esModule !== true) {', ' legacyModuleValue = typeof moduleValue === "function"', ' ? function (...args) { return Reflect.apply(moduleValue, this, args); }', ' : {};', ' for (const exportName of Reflect.ownKeys(moduleValue)) {', ' if (exportName === "__esModule" || exportName === "default") {', ' continue;', ' }', ' const sourceDescriptor = Reflect.getOwnPropertyDescriptor(moduleValue, exportName);', ' const facadeDescriptor = Reflect.getOwnPropertyDescriptor(legacyModuleValue, exportName);', ' if (sourceDescriptor == null || (facadeDescriptor != null && facadeDescriptor.configurable === false)) {', ' // Callable facades keep intrinsic non-configurable slots such as prototype.', ' continue;', ' }', ' if (!Reflect.defineProperty(legacyModuleValue, exportName, {', ' enumerable: sourceDescriptor.enumerable,', ' get: function () { return Reflect.get(moduleValue, exportName); },', ' })) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' }', ' const hasDefaultExport = Reflect.getOwnPropertyDescriptor(moduleValue, "default") != null;', ' Object.defineProperties(legacyModuleValue, {', ' __esModule: { value: true },', ' default: {', ' enumerable: true,', ' get: hasDefaultExport', ' ? function () { return Reflect.get(moduleValue, "default"); }', ' : function () { return moduleValue; },', ' },', ' });', ' }', ' try {', ' if (ownsModernContainer && !Reflect.set(container.exposedModules, normalizedModule, moduleValue)) {', ' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");', ' }', ' if (legacyContainer != null) {', ' Object.defineProperty(legacyContainer.exposeMap, legacyModule, {', ' configurable: true,', ' enumerable: true,', ' get: function () { return legacyModuleValue; },', ' });', ' }', ' } catch (error) {', ' if (ownsModernContainer) {', ' Reflect.deleteProperty(container.exposedModules, normalizedModule);', ' }', ' if (legacyContainer != null) {', ' Reflect.deleteProperty(legacyContainer.exposeMap, legacyModule);', ' }', ' throw error;', ' }', '}', 'function registerShared(moduleName, moduleValue) {', ' const sharedModules = global.__MICRO_FRONTEND__.__SHARED__;', ' const existingModule = sharedModules[moduleName];', ' if (existingModule != null) {', ' if (typeof existingModule === "object" &&', ' typeof existingModule.get === "function" &&', ' typeof existingModule.loaded === "boolean" &&', ' Object.is(existingModule.get(), moduleValue)) {', ' return;', ' }', " throw new Error(`Shared module '${moduleName}' is already registered`);", ' }', ' sharedModules[moduleName] = { get: () => moduleValue, loaded: true };', '}', `const __container = createContainer(${containerName}, ${containerConfig});`, ...registerStatements, ...exposeStatements].join('\n')
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
28
|
//# sourceMappingURL=prelude.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["path","globalContextScript","CONTAINER_PAIRING_KEY","getPreludeConfig","options","appName","eagerSharedModules","Object","entries","shared","filter","config","Array","isArray","eager","registerStatements","map","moduleName","index","identifier","JSON","stringify","join","exposeStatements","exposes","exposedModule","modulePath","resolve","containerConfig","containerName","banner","preludeScript"],"sourceRoot":"../../../src","sources":["plugin/prelude.ts"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,mBAAmB,QAAQ,0BAAuB;AAE3D,SAASC,qBAAqB,QAAQ,gCAA6B;
|
|
1
|
+
{"version":3,"names":["path","globalContextScript","CONTAINER_PAIRING_KEY","captureStackFrames","resolveCurrentSourceURL","getPreludeConfig","options","appName","eagerSharedModules","Object","entries","shared","filter","config","Array","isArray","eager","registerStatements","map","moduleName","index","identifier","JSON","stringify","join","exposeStatements","exposes","exposedModule","modulePath","resolve","containerConfig","containerName","captureFrames","toString","resolveSourceURL","banner","preludeScript"],"sourceRoot":"../../../src","sources":["plugin/prelude.ts"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,mBAAmB,QAAQ,0BAAuB;AAE3D,SAASC,qBAAqB,QAAQ,gCAA6B;AACnE,SAASC,kBAAkB,EAAEC,uBAAuB,QAAQ,gCAA6B;AAOzF,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,K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K,EACL,yEAAyE,EACzE,GAAG,EACH,uCAAuCH,aAAa,KAAKD,eAAe,IAAI,EAC5E,GAAGb,kBAAkB,EACrB,GAAGQ,gBAAgB,CACpB,CAACD,IAAI,CAAC,IAAI;EACb,CAAC;AACH","ignoreList":[]}
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
import { clearContainerPair, defineContainerPair, forgetContainerPair, getLegacyContainerPair, getModernContainerPair, isLegacyAppContainer, isContainerPair, isObjectRecord, rememberContainerPair, rememberLegacyAdapterPair } from "./containerPairing.js";
|
|
4
4
|
import { AppContainerAlreadyRegisteredError } from "./errors.js";
|
|
5
5
|
import { getMicroFrontendGlobalContext, MicroFrontendGlobalContextCompatibilityError } from "./globalContext.js";
|
|
6
|
+
import { captureStackFrames, resolveCurrentSourceURL } from "./runtimeSourceURL.js";
|
|
6
7
|
export { exposeContainerModule as exposeModule } from "./containerModuleExposure.js";
|
|
7
8
|
export function createContainer(appName, config = {}) {
|
|
9
|
+
const sourceURL = resolveCurrentSourceURL(captureStackFrames());
|
|
8
10
|
const context = getMicroFrontendGlobalContext();
|
|
9
11
|
const canonicalValue = Reflect.get(context.__CONTAINERS__, appName);
|
|
10
12
|
const legacyIndex = Reflect.get(context.__INSTANCES__, appName);
|
|
@@ -17,7 +19,10 @@ export function createContainer(appName, config = {}) {
|
|
|
17
19
|
const modernContainer = {
|
|
18
20
|
appName,
|
|
19
21
|
config,
|
|
20
|
-
exposedModules: {}
|
|
22
|
+
exposedModules: {},
|
|
23
|
+
runtime: {
|
|
24
|
+
sourceURL
|
|
25
|
+
}
|
|
21
26
|
};
|
|
22
27
|
const legacyContainer = {
|
|
23
28
|
name: appName,
|
|
@@ -178,7 +183,8 @@ function normalizeLegacyModule(exposedModule) {
|
|
|
178
183
|
return exposedModule.startsWith('./') ? exposedModule.slice(2) : exposedModule;
|
|
179
184
|
}
|
|
180
185
|
function isAppContainer(value) {
|
|
181
|
-
|
|
186
|
+
const runtime = isObjectRecord(value) ? Reflect.get(value, 'runtime') : null;
|
|
187
|
+
return isObjectRecord(value) && typeof Reflect.get(value, 'appName') === 'string' && isAppContainerConfig(Reflect.get(value, 'config')) && isObjectRecord(Reflect.get(value, 'exposedModules')) && (runtime == null || isObjectRecord(runtime) && typeof Reflect.get(runtime, 'sourceURL') === 'string');
|
|
182
188
|
}
|
|
183
189
|
function isAppContainerConfig(value) {
|
|
184
190
|
if (!isObjectRecord(value)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["clearContainerPair","defineContainerPair","forgetContainerPair","getLegacyContainerPair","getModernContainerPair","isLegacyAppContainer","isContainerPair","isObjectRecord","rememberContainerPair","rememberLegacyAdapterPair","AppContainerAlreadyRegisteredError","getMicroFrontendGlobalContext","MicroFrontendGlobalContextCompatibilityError","exposeContainerModule","exposeModule","createContainer","appName","config","context","canonicalValue","Reflect","get","__CONTAINERS__","legacyIndex","__INSTANCES__","isExtensible","modernContainer","exposedModules","legacyContainer","name","exposeMap","containerIndex","length","defineProperty","configurable","enumerable","value","writable","push","set","error","Object","is","pop","deleteProperty","getContainer","isAppContainer","getLegacyContainer","getLegacyAdapter","getExposedModule","container","exposedModule","module","normalizeExposedModule","undefined","normalizeLegacyModule","removeContainer","nextInstances","createLegacyInstancesWithout","clearRegistry","clearLegacyModules","existingAdapter","adapter","isAppContainerConfig","createNormalizedExposedModules","Proxy","_target","property","receiver","ownKeys","map","key","getOwnPropertyDescriptor","moduleName","has","instances","index","Number","isInteger","removed","Array","from","filter","entry","registeredNames","Set","entries","add","registry","keys","startsWith","slice","shared"],"sourceRoot":"../../../src","sources":["runtime/containerRegistry.ts"],"mappings":";;AAAA,SACEA,kBAAkB,EAClBC,mBAAmB,EACnBC,mBAAmB,EACnBC,sBAAsB,EACtBC,sBAAsB,EACtBC,oBAAoB,EACpBC,eAAe,EACfC,cAAc,EACdC,qBAAqB,EACrBC,yBAAyB,QAEpB,uBAAoB;AAC3B,SAASC,kCAAkC,QAAQ,aAAU;AAC7D,SAASC,6BAA6B,EAAEC,4CAA4C,QAAQ,oBAAiB;
|
|
1
|
+
{"version":3,"names":["clearContainerPair","defineContainerPair","forgetContainerPair","getLegacyContainerPair","getModernContainerPair","isLegacyAppContainer","isContainerPair","isObjectRecord","rememberContainerPair","rememberLegacyAdapterPair","AppContainerAlreadyRegisteredError","getMicroFrontendGlobalContext","MicroFrontendGlobalContextCompatibilityError","captureStackFrames","resolveCurrentSourceURL","exposeContainerModule","exposeModule","createContainer","appName","config","sourceURL","context","canonicalValue","Reflect","get","__CONTAINERS__","legacyIndex","__INSTANCES__","isExtensible","modernContainer","exposedModules","runtime","legacyContainer","name","exposeMap","containerIndex","length","defineProperty","configurable","enumerable","value","writable","push","set","error","Object","is","pop","deleteProperty","getContainer","isAppContainer","getLegacyContainer","getLegacyAdapter","getExposedModule","container","exposedModule","module","normalizeExposedModule","undefined","normalizeLegacyModule","removeContainer","nextInstances","createLegacyInstancesWithout","clearRegistry","clearLegacyModules","existingAdapter","adapter","isAppContainerConfig","createNormalizedExposedModules","Proxy","_target","property","receiver","ownKeys","map","key","getOwnPropertyDescriptor","moduleName","has","instances","index","Number","isInteger","removed","Array","from","filter","entry","registeredNames","Set","entries","add","registry","keys","startsWith","slice","shared"],"sourceRoot":"../../../src","sources":["runtime/containerRegistry.ts"],"mappings":";;AAAA,SACEA,kBAAkB,EAClBC,mBAAmB,EACnBC,mBAAmB,EACnBC,sBAAsB,EACtBC,sBAAsB,EACtBC,oBAAoB,EACpBC,eAAe,EACfC,cAAc,EACdC,qBAAqB,EACrBC,yBAAyB,QAEpB,uBAAoB;AAC3B,SAASC,kCAAkC,QAAQ,aAAU;AAC7D,SAASC,6BAA6B,EAAEC,4CAA4C,QAAQ,oBAAiB;AAE7G,SAASC,kBAAkB,EAAEC,uBAAuB,QAAQ,uBAAoB;AAEhF,SAASC,qBAAqB,IAAIC,YAAY,QAAQ,8BAA2B;AAEjF,OAAO,SAASC,eAAeA,CAACC,OAAe,EAAEC,MAA0B,GAAG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ACC,GAAG,CAACO,OAAO,EAAE,WAAW,CAAC,KAAK,QAAS,CAAC;AAE3G;AAEA,SAASoC,oBAAoBA,CAAC3B,KAAc,EAA+B;EACzE,IAAI,CAACjC,cAAc,CAACiC,KAAK,CAAC,EAAE;IAC1B,OAAO,KAAK;EACd;EACA,MAAMwD,MAAe,GAAGzE,OAAO,CAACC,GAAG,CAACgB,KAAK,EAAE,QAAQ,CAAC;EACpD,OAAOwD,MAAM,IAAI,IAAI,IAAIzF,cAAc,CAACyF,MAAM,CAAC;AACjD","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { getMicroFrontendRuntimeContext } from "./registry.js";
|
|
4
|
+
import { captureStackFrames, resolveCurrentSourceURL } from "./runtimeSourceURL.js";
|
|
5
|
+
export function resolveAppNameBySourceURL(sourceURL, containers) {
|
|
6
|
+
let resolvedAppName = null;
|
|
7
|
+
for (const container of Object.values(containers)) {
|
|
8
|
+
if (container.runtime?.sourceURL !== sourceURL) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (resolvedAppName != null && resolvedAppName !== container.appName) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
resolvedAppName = container.appName;
|
|
15
|
+
}
|
|
16
|
+
return resolvedAppName;
|
|
17
|
+
}
|
|
18
|
+
export function findAppNameBySourceURL(sourceURL) {
|
|
19
|
+
return resolveAppNameBySourceURL(sourceURL, getMicroFrontendRuntimeContext().containers);
|
|
20
|
+
}
|
|
21
|
+
export function resolveAppNameFromStackFrames(frames, containers) {
|
|
22
|
+
const sourceURL = resolveCurrentSourceURL(frames);
|
|
23
|
+
const appName = resolveAppNameBySourceURL(sourceURL, containers);
|
|
24
|
+
if (appName != null) {
|
|
25
|
+
return appName;
|
|
26
|
+
}
|
|
27
|
+
throw new Error('Cannot resolve the current micro-frontend app name');
|
|
28
|
+
}
|
|
29
|
+
export function getAppName() {
|
|
30
|
+
const sourceURL = resolveCurrentSourceURL(captureStackFrames());
|
|
31
|
+
const appName = findAppNameBySourceURL(sourceURL);
|
|
32
|
+
if (appName != null) {
|
|
33
|
+
return appName;
|
|
34
|
+
}
|
|
35
|
+
throw new Error('Cannot resolve the current micro-frontend app name');
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=getAppName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getMicroFrontendRuntimeContext","captureStackFrames","resolveCurrentSourceURL","resolveAppNameBySourceURL","sourceURL","containers","resolvedAppName","container","Object","values","runtime","appName","findAppNameBySourceURL","resolveAppNameFromStackFrames","frames","Error","getAppName"],"sourceRoot":"../../../src","sources":["runtime/getAppName.ts"],"mappings":";;AAAA,SAASA,8BAA8B,QAA2B,eAAY;AAC9E,SAASC,kBAAkB,EAAEC,uBAAuB,QAAgC,uBAAoB;AAExG,OAAO,SAASC,yBAAyBA,CACvCC,SAAiB,EACjBC,UAAkD,EACnC;EACf,IAAIC,eAA8B,GAAG,IAAI;EACzC,KAAK,MAAMC,SAAS,IAAIC,MAAM,CAACC,MAAM,CAACJ,UAAU,CAAC,EAAE;IACjD,IAAIE,SAAS,CAACG,OAAO,EAAEN,SAAS,KAAKA,SAAS,EAAE;MAC9C;IACF;IACA,IAAIE,eAAe,IAAI,IAAI,IAAIA,eAAe,KAAKC,SAAS,CAACI,OAAO,EAAE;MACpE,OAAO,IAAI;IACb;IACAL,eAAe,GAAGC,SAAS,CAACI,OAAO;EACrC;EACA,OAAOL,eAAe;AACxB;AAEA,OAAO,SAASM,sBAAsBA,CAACR,SAAiB,EAAiB;EACvE,OAAOD,yBAAyB,CAACC,SAAS,EAAEJ,8BAA8B,CAAC,CAAC,CAACK,UAAU,CAAC;AAC1F;AAEA,OAAO,SAASQ,6BAA6BA,CAC3CC,MAAoC,EACpCT,UAAkD,EAC1C;EACR,MAAMD,SAAS,GAAGF,uBAAuB,CAACY,MAAM,CAAC;EACjD,MAAMH,OAAO,GAAGR,yBAAyB,CAACC,SAAS,EAAEC,UAAU,CAAC;EAChE,IAAIM,OAAO,IAAI,IAAI,EAAE;IACnB,OAAOA,OAAO;EAChB;EAEA,MAAM,IAAII,KAAK,CAAC,oDAAoD,CAAC;AACvE;AAEA,OAAO,SAASC,UAAUA,CAAA,EAAW;EACnC,MAAMZ,SAAS,GAAGF,uBAAuB,CAACD,kBAAkB,CAAC,CAAC,CAAC;EAC/D,MAAMU,OAAO,GAAGC,sBAAsB,CAACR,SAAS,CAAC;EACjD,IAAIO,OAAO,IAAI,IAAI,EAAE;IACnB,OAAOA,OAAO;EAChB;EAEA,MAAM,IAAII,KAAK,CAAC,oDAAoD,CAAC;AACvE","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContainer","exposeModule","getContainer","getExposedModule","removeContainer","ExposedModuleNotFoundError","SharedModuleAlreadyRegisteredError","getMicroFrontendGlobalContext","parseAppRequest","getMicroFrontendRuntimeContext","context","ensureRuntimeContext","registerShared","moduleName","module","sharedModules","__SHARED__","existingModule","isSharedModule","Object","is","get","loaded","value","Reflect","disposeAppResources","appName","disposeCallbacks","disposeCallbacksByApp","runAppDisposeCallbacks","hasContainer","importModule","request","exposedModule","container","containers","__CONTAINERS__","propertyDescriptors","Map","runtimeProperties","dispose","isRegisterAppDispose","createRegisterAppDispose","isDisposeCallbackRegistry","property","ownKeys","set","getOwnPropertyDescriptor","defineProperty","configurable","enumerable","writable","Error","String","error","descriptor","Array","from","reverse","deleteProperty","isObjectRecord","isArray","values","every","isDisposeCallbackSet","Symbol","iterator","appNameOrCallback","callback","registerAppDisposeCallback","Set","add","isRegistered","delete","callbacks","firstDisposeError","didDisposeFail","microFrontendModuleRegistry"],"sourceRoot":"../../../src","sources":["runtime/registry.ts"],"mappings":";;AACA,SAASA,eAAe,EAAEC,YAAY,EAAEC,YAAY,EAAEC,gBAAgB,EAAEC,eAAe,QAAQ,wBAAqB;AAEpH,SAASC,0BAA0B,EAAEC,kCAAkC,QAAQ,aAAU;AACzF,SAASC,6BAA6B,QAAyC,oBAAiB;AAChG,SAASC,eAAe,QAAQ,sBAAmB;AACnD,SAASR,eAAe,EAAEC,YAAY,EAAEC,YAAY,EAAEE,eAAe;
|
|
1
|
+
{"version":3,"names":["createContainer","exposeModule","getContainer","getExposedModule","removeContainer","ExposedModuleNotFoundError","SharedModuleAlreadyRegisteredError","getMicroFrontendGlobalContext","parseAppRequest","getMicroFrontendRuntimeContext","context","ensureRuntimeContext","registerShared","moduleName","module","sharedModules","__SHARED__","existingModule","isSharedModule","Object","is","get","loaded","value","Reflect","disposeAppResources","appName","disposeCallbacks","disposeCallbacksByApp","runAppDisposeCallbacks","hasContainer","importModule","request","exposedModule","container","containers","__CONTAINERS__","propertyDescriptors","Map","runtimeProperties","dispose","isRegisterAppDispose","createRegisterAppDispose","isDisposeCallbackRegistry","property","ownKeys","set","getOwnPropertyDescriptor","defineProperty","configurable","enumerable","writable","Error","String","error","descriptor","Array","from","reverse","deleteProperty","isObjectRecord","isArray","values","every","isDisposeCallbackSet","Symbol","iterator","appNameOrCallback","callback","registerAppDisposeCallback","Set","add","isRegistered","delete","callbacks","firstDisposeError","didDisposeFail","microFrontendModuleRegistry"],"sourceRoot":"../../../src","sources":["runtime/registry.ts"],"mappings":";;AACA,SAASA,eAAe,EAAEC,YAAY,EAAEC,YAAY,EAAEC,gBAAgB,EAAEC,eAAe,QAAQ,wBAAqB;AAEpH,SAASC,0BAA0B,EAAEC,kCAAkC,QAAQ,aAAU;AACzF,SAASC,6BAA6B,QAAyC,oBAAiB;AAChG,SAASC,eAAe,QAAQ,sBAAmB;AACnD,SAASR,eAAe,EAAEC,YAAY,EAAEC,YAAY,EAAEE,eAAe;AA0CrE,OAAO,SAASK,8BAA8BA,CAAA,EAAgC;EAC5E,MAAMC,OAAO,GAAGH,6BAA6B,CAAC,CAAC;EAC/CI,oBAAoB,CAACD,OAAO,CAAC;EAC7B,OAAOA,OAAO;AAChB;AAEA,OA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,CAAC,CAAC;EACxD,IAAIiB,iBAA0B;EAC9B,IAAIC,cAAc,GAAG,KAAK;EAE1B,KAAK,MAAMpC,OAAO,IAAIkC,SAAS,EAAE;IAC/B,IAAI;MACF,MAAMlC,OAAO,CAAC,CAAC;IACjB,CAAC,CAAC,OAAOc,KAAK,EAAE;MACd,IAAI,CAACsB,cAAc,EAAE;QACnBD,iBAAiB,GAAGrB,KAAK;QACzBsB,cAAc,GAAG,IAAI;MACvB;IACF;EACF;EAEA,IAAIA,cAAc,EAAE;IAClB,MAAMD,iBAAiB;EACzB;AACF;AAEA,OAAO,MAAME,2BAAwD,GAAG;EACtE/C,YAAY;EACZC,YAAY;EACZ3B;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export function captureStackFrames() {
|
|
4
|
+
const prepareStackTraceDescriptor = Object.getOwnPropertyDescriptor(Error, 'prepareStackTrace');
|
|
5
|
+
Object.defineProperty(Error, 'prepareStackTrace', {
|
|
6
|
+
configurable: true,
|
|
7
|
+
value: (_error, callSites) => callSites,
|
|
8
|
+
writable: true
|
|
9
|
+
});
|
|
10
|
+
const frames = [];
|
|
11
|
+
try {
|
|
12
|
+
const callSites = new Error().stack;
|
|
13
|
+
if (!Array.isArray(callSites)) {
|
|
14
|
+
throw new Error('Cannot capture structured micro-frontend stack frames');
|
|
15
|
+
}
|
|
16
|
+
for (const callSite of callSites) {
|
|
17
|
+
if (typeof callSite !== 'object' || callSite == null) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (!('getFileName' in callSite)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const getFileName = 'getFileName' in callSite ? callSite.getFileName : undefined;
|
|
24
|
+
const sourceURL = typeof getFileName === 'function' ? getFileName.call(callSite) : null;
|
|
25
|
+
frames.push({
|
|
26
|
+
sourceURL: typeof sourceURL === 'string' ? sourceURL : null
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
} finally {
|
|
30
|
+
if (prepareStackTraceDescriptor == null) {
|
|
31
|
+
Reflect.deleteProperty(Error, 'prepareStackTrace');
|
|
32
|
+
} else {
|
|
33
|
+
Object.defineProperty(Error, 'prepareStackTrace', prepareStackTraceDescriptor);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return frames;
|
|
37
|
+
}
|
|
38
|
+
export function resolveCurrentSourceURL(frames) {
|
|
39
|
+
for (const frame of frames) {
|
|
40
|
+
if (frame.sourceURL != null && frame.sourceURL.length > 0) {
|
|
41
|
+
return frame.sourceURL;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw new Error('Cannot determine the caller micro-frontend sourceURL');
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=runtimeSourceURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["captureStackFrames","prepareStackTraceDescriptor","Object","getOwnPropertyDescriptor","Error","defineProperty","configurable","value","_error","callSites","writable","frames","stack","Array","isArray","callSite","getFileName","undefined","sourceURL","call","push","Reflect","deleteProperty","resolveCurrentSourceURL","frame","length"],"sourceRoot":"../../../src","sources":["runtime/runtimeSourceURL.ts"],"mappings":";;AAIA,OAAO,SAASA,kBAAkBA,CAAA,EAAiC;EACjE,MAAMC,2BAA2B,GAAGC,MAAM,CAACC,wBAAwB,CAACC,KAAK,EAAE,mBAAmB,CAAC;EAC/FF,MAAM,CAACG,cAAc,CAACD,KAAK,EAAE,mBAAmB,EAAE;IAChDE,YAAY,EAAE,IAAI;IAClBC,KAAK,EAAEA,CAACC,MAAe,EAAEC,SAA6B,KAAKA,SAAS;IACpEC,QAAQ,EAAE;EACZ,CAAC,CAAC;EAEF,MAAMC,MAA2B,GAAG,EAAE;EACtC,IAAI;IACF,MAAMF,SAAkB,GAAG,IAAIL,KAAK,CAAC,CAAC,CAACQ,KAAK;IAC5C,IAAI,CAACC,KAAK,CAACC,OAAO,CAACL,SAAS,CAAC,EAAE;MAC7B,MAAM,IAAIL,KAAK,CAAC,uDAAuD,CAAC;IAC1E;IACA,KAAK,MAAMW,QAAQ,IAAIN,SAAS,EAAE;MAChC,IAAI,OAAOM,QAAQ,KAAK,QAAQ,IAAIA,QAAQ,IAAI,IAAI,EAAE;QACpD;MACF;MACA,IAAI,EAAE,aAAa,IAAIA,QAAQ,CAAC,EAAE;QAChC;MACF;MACA,MAAMC,WAAoB,GAAG,aAAa,IAAID,QAAQ,GAAGA,QAAQ,CAACC,WAAW,GAAGC,SAAS;MACzF,MAAMC,SAAkB,GAAG,OAAOF,WAAW,KAAK,UAAU,GAAGA,WAAW,CAACG,IAAI,CAACJ,QAAQ,CAAC,GAAG,IAAI;MAChGJ,MAAM,CAACS,IAAI,CAAC;QAAEF,SAAS,EAAE,OAAOA,SAAS,KAAK,QAAQ,GAAGA,SAAS,GAAG;MAAK,CAAC,CAAC;IAC9E;EACF,CAAC,SAAS;IACR,IAAIjB,2BAA2B,IAAI,IAAI,EAAE;MACvCoB,OAAO,CAACC,cAAc,CAAClB,KAAK,EAAE,mBAAmB,CAAC;IACpD,CAAC,MAAM;MACLF,MAAM,CAACG,cAAc,CAACD,KAAK,EAAE,mBAAmB,EAAEH,2BAA2B,CAAC;IAChF;EACF;EAEA,OAAOU,MAAM;AACf;AAEA,OAAO,SAASY,uBAAuBA,CAACZ,MAAoC,EAAU;EACpF,KAAK,MAAMa,KAAK,IAAIb,MAAM,EAAE;IAC1B,IAAIa,KAAK,CAACN,SAAS,IAAI,IAAI,IAAIM,KAAK,CAACN,SAAS,CAACO,MAAM,GAAG,CAAC,EAAE;MACzD,OAAOD,KAAK,CAACN,SAAS;IACxB;EACF;EACA,MAAM,IAAId,KAAK,CAAC,sDAAsD,CAAC;AACzE","ignoreList":[]}
|
|
@@ -2,6 +2,7 @@ export { createMicroFrontendRuntime } from './createMicroFrontendRuntime';
|
|
|
2
2
|
export type { CreateMicroFrontendRuntimeOptions } from './createMicroFrontendRuntime';
|
|
3
3
|
export { createRoute } from './createRoute';
|
|
4
4
|
export type { MicroFrontendRouteOptions } from './createRoute';
|
|
5
|
+
export { findAppNameBySourceURL, getAppName } from './runtime/getAppName';
|
|
5
6
|
export type { PendingHostComponentController, PendingHostComponentProps } from './host/PendingHostComponent';
|
|
6
7
|
export { PendingHostComponent, usePendingHostComponentController, useIsPendingHostComponentHidden, useResolvedPendingHostComponent, } from './host/PendingHostComponent';
|
|
7
8
|
export type { PendingHostComponentAppConfig, PendingHostComponentRenderer, PendingHostComponentParams, PendingHostComponentRouteRequest, RegisterPendingHostComponentRouteOptions, ResolvedPendingHostComponent, } from './host/types';
|
|
@@ -11,7 +12,7 @@ export { MicroFrontendSessionProvider, MissingMicroFrontendSessionError, useMicr
|
|
|
11
12
|
export type { MicroFrontendSession, MicroFrontendSessionProviderProps } from './session/MicroFrontendSessionContext';
|
|
12
13
|
export { useMicroFrontendSessions } from './session/useMicroFrontendSessions';
|
|
13
14
|
export type { MicroFrontendSessionState } from './session/useMicroFrontendSessions';
|
|
14
|
-
export type { AppDisposeCallback, MicroFrontendRuntimeContext } from './runtime/registry';
|
|
15
|
+
export type { AppContainer, AppContainerRuntime, AppDisposeCallback, MicroFrontendRuntimeContext, } from './runtime/registry';
|
|
15
16
|
export { default as Portal } from './specs/PortalViewNativeComponent';
|
|
16
17
|
export type { AppRequest, MicroFrontendAppProps, MicroFrontendAdapter, MicroFrontendBundle, MicroFrontendBundleRequest, MicroFrontendLifecycleCallback, MicroFrontendLifecycleEvent, MicroFrontendLifecycleSession, MicroFrontendRuntimeApi, MicroFrontendRuntimeEvent, MicroFrontendRuntimeEventSubscription, MicroFrontendSessionEvent, } from './types';
|
|
17
18
|
export { AppContainerNotFoundError, ExposedModuleNotFoundError, InvalidAppNameError, InvalidAppRequestError, InvalidNativeRuntimeEventError, } from './runtime/errors';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type AppContainer } from './registry';
|
|
2
|
+
import { type RuntimeStackFrame } from './runtimeSourceURL';
|
|
3
|
+
export declare function resolveAppNameBySourceURL(sourceURL: string, containers: Readonly<Record<string, AppContainer>>): string | null;
|
|
4
|
+
export declare function findAppNameBySourceURL(sourceURL: string): string | null;
|
|
5
|
+
export declare function resolveAppNameFromStackFrames(frames: readonly RuntimeStackFrame[], containers: Readonly<Record<string, AppContainer>>): string;
|
|
6
|
+
export declare function getAppName(): string;
|
|
@@ -9,10 +9,14 @@ export type SharedConfig = Readonly<Record<string, SharedModuleConfig>>;
|
|
|
9
9
|
export interface AppContainerConfig {
|
|
10
10
|
readonly shared?: SharedConfig;
|
|
11
11
|
}
|
|
12
|
+
export interface AppContainerRuntime {
|
|
13
|
+
readonly sourceURL: string;
|
|
14
|
+
}
|
|
12
15
|
export interface AppContainer {
|
|
13
16
|
readonly appName: string;
|
|
14
17
|
readonly config: AppContainerConfig;
|
|
15
18
|
readonly exposedModules: Record<string, unknown>;
|
|
19
|
+
readonly runtime?: AppContainerRuntime;
|
|
16
20
|
}
|
|
17
21
|
export type AppDisposeCallback = () => void | Promise<void>;
|
|
18
22
|
export interface RegisterAppDispose {
|
|
@@ -3,6 +3,7 @@ export interface MicroFrontendBundleRequest {
|
|
|
3
3
|
readonly appName: string;
|
|
4
4
|
}
|
|
5
5
|
export interface MicroFrontendBundle {
|
|
6
|
+
/** An absolute local file path, or an Android `assets://` locator for a packaged bundle. */
|
|
6
7
|
readonly filePath: string;
|
|
7
8
|
}
|
|
8
9
|
export interface MicroFrontendAppProps {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/micro-frontend",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Micro-frontend build, runtime, session, and Portal contracts for Granite brownfield applications",
|
|
5
5
|
"main": "./dist/module/index.js",
|
|
6
6
|
"types": "./dist/typescript/index.d.ts",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@babel/core": "7.28.5",
|
|
59
|
-
"@granite-js/utils": "2.
|
|
59
|
+
"@granite-js/utils": "2.3.1",
|
|
60
60
|
"@standard-schema/spec": "^1.0.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@babel/types": "7.28.5",
|
|
75
|
-
"@granite-js/plugin-core": "2.
|
|
76
|
-
"@granite-js/react-native": "2.
|
|
75
|
+
"@granite-js/plugin-core": "2.3.1",
|
|
76
|
+
"@granite-js/react-native": "2.3.1",
|
|
77
77
|
"@types/babel__core": "^7.20.5",
|
|
78
78
|
"@types/node": "24.10.12",
|
|
79
79
|
"@types/react": "19.2.0",
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { createMicroFrontendRuntime } from './createMicroFrontendRuntime';
|
|
|
2
2
|
export type { CreateMicroFrontendRuntimeOptions } from './createMicroFrontendRuntime';
|
|
3
3
|
export { createRoute } from './createRoute';
|
|
4
4
|
export type { MicroFrontendRouteOptions } from './createRoute';
|
|
5
|
+
export { findAppNameBySourceURL, getAppName } from './runtime/getAppName';
|
|
5
6
|
export type { PendingHostComponentController, PendingHostComponentProps } from './host/PendingHostComponent';
|
|
6
7
|
export {
|
|
7
8
|
PendingHostComponent,
|
|
@@ -36,7 +37,12 @@ export {
|
|
|
36
37
|
export type { MicroFrontendSession, MicroFrontendSessionProviderProps } from './session/MicroFrontendSessionContext';
|
|
37
38
|
export { useMicroFrontendSessions } from './session/useMicroFrontendSessions';
|
|
38
39
|
export type { MicroFrontendSessionState } from './session/useMicroFrontendSessions';
|
|
39
|
-
export type {
|
|
40
|
+
export type {
|
|
41
|
+
AppContainer,
|
|
42
|
+
AppContainerRuntime,
|
|
43
|
+
AppDisposeCallback,
|
|
44
|
+
MicroFrontendRuntimeContext,
|
|
45
|
+
} from './runtime/registry';
|
|
40
46
|
export { default as Portal } from './specs/PortalViewNativeComponent';
|
|
41
47
|
export type {
|
|
42
48
|
AppRequest,
|
package/src/plugin/prelude.ts
CHANGED
|
@@ -2,6 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import { globalContextScript } from './globalContextScript';
|
|
3
3
|
import type { MicroFrontendPluginOptions } from './types';
|
|
4
4
|
import { CONTAINER_PAIRING_KEY } from '../runtime/containerPairing';
|
|
5
|
+
import { captureStackFrames, resolveCurrentSourceURL } from '../runtime/runtimeSourceURL';
|
|
5
6
|
|
|
6
7
|
export interface MicroFrontendPreludeConfig {
|
|
7
8
|
readonly banner: string;
|
|
@@ -28,6 +29,8 @@ export function getPreludeConfig(options: MicroFrontendPluginOptions, appName?:
|
|
|
28
29
|
});
|
|
29
30
|
const containerConfig = JSON.stringify({ shared: options.shared });
|
|
30
31
|
const containerName = appName == null ? 'global.__granite.app.name' : JSON.stringify(appName);
|
|
32
|
+
const captureFrames = captureStackFrames.toString();
|
|
33
|
+
const resolveSourceURL = resolveCurrentSourceURL.toString();
|
|
31
34
|
|
|
32
35
|
return {
|
|
33
36
|
banner: [
|
|
@@ -91,7 +94,9 @@ export function getPreludeConfig(options: MicroFrontendPluginOptions, appName?:
|
|
|
91
94
|
' if (!Object.isExtensible(containers) || !Object.isExtensible(instances)) {',
|
|
92
95
|
' throw new Error("Cannot establish the micro-frontend global context: registry-is-not-extensible");',
|
|
93
96
|
' }',
|
|
94
|
-
|
|
97
|
+
` const stackFrames = (${captureFrames})();`,
|
|
98
|
+
` const sourceURL = (${resolveSourceURL})(stackFrames);`,
|
|
99
|
+
' const modernContainer = { appName, config, exposedModules: {}, runtime: { sourceURL } };',
|
|
95
100
|
' const legacyContainer = { name: appName, config, exposeMap: {} };',
|
|
96
101
|
' try {',
|
|
97
102
|
' if (!Reflect.defineProperty(instances, appName, {',
|
|
@@ -14,10 +14,12 @@ import {
|
|
|
14
14
|
import { AppContainerAlreadyRegisteredError } from './errors';
|
|
15
15
|
import { getMicroFrontendGlobalContext, MicroFrontendGlobalContextCompatibilityError } from './globalContext';
|
|
16
16
|
import type { AppContainer, AppContainerConfig } from './registry';
|
|
17
|
+
import { captureStackFrames, resolveCurrentSourceURL } from './runtimeSourceURL';
|
|
17
18
|
|
|
18
19
|
export { exposeContainerModule as exposeModule } from './containerModuleExposure';
|
|
19
20
|
|
|
20
21
|
export function createContainer(appName: string, config: AppContainerConfig = {}): AppContainer {
|
|
22
|
+
const sourceURL = resolveCurrentSourceURL(captureStackFrames());
|
|
21
23
|
const context = getMicroFrontendGlobalContext();
|
|
22
24
|
const canonicalValue: unknown = Reflect.get(context.__CONTAINERS__, appName);
|
|
23
25
|
const legacyIndex: unknown = Reflect.get(context.__INSTANCES__, appName);
|
|
@@ -28,7 +30,12 @@ export function createContainer(appName: string, config: AppContainerConfig = {}
|
|
|
28
30
|
throw new MicroFrontendGlobalContextCompatibilityError('registry-is-not-extensible');
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
const modernContainer: AppContainer = {
|
|
33
|
+
const modernContainer: AppContainer = {
|
|
34
|
+
appName,
|
|
35
|
+
config,
|
|
36
|
+
exposedModules: {},
|
|
37
|
+
runtime: { sourceURL },
|
|
38
|
+
};
|
|
32
39
|
const legacyContainer: LegacyAppContainer = { name: appName, config, exposeMap: {} };
|
|
33
40
|
const containerIndex = context.__INSTANCES__.length;
|
|
34
41
|
|
|
@@ -222,11 +229,13 @@ function normalizeLegacyModule(exposedModule: string): string {
|
|
|
222
229
|
}
|
|
223
230
|
|
|
224
231
|
function isAppContainer(value: unknown): value is AppContainer {
|
|
232
|
+
const runtime: unknown = isObjectRecord(value) ? Reflect.get(value, 'runtime') : null;
|
|
225
233
|
return (
|
|
226
234
|
isObjectRecord(value) &&
|
|
227
235
|
typeof Reflect.get(value, 'appName') === 'string' &&
|
|
228
236
|
isAppContainerConfig(Reflect.get(value, 'config')) &&
|
|
229
|
-
isObjectRecord(Reflect.get(value, 'exposedModules'))
|
|
237
|
+
isObjectRecord(Reflect.get(value, 'exposedModules')) &&
|
|
238
|
+
(runtime == null || (isObjectRecord(runtime) && typeof Reflect.get(runtime, 'sourceURL') === 'string'))
|
|
230
239
|
);
|
|
231
240
|
}
|
|
232
241
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getMicroFrontendRuntimeContext, type AppContainer } from './registry';
|
|
2
|
+
import { captureStackFrames, resolveCurrentSourceURL, type RuntimeStackFrame } from './runtimeSourceURL';
|
|
3
|
+
|
|
4
|
+
export function resolveAppNameBySourceURL(
|
|
5
|
+
sourceURL: string,
|
|
6
|
+
containers: Readonly<Record<string, AppContainer>>
|
|
7
|
+
): string | null {
|
|
8
|
+
let resolvedAppName: string | null = null;
|
|
9
|
+
for (const container of Object.values(containers)) {
|
|
10
|
+
if (container.runtime?.sourceURL !== sourceURL) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
if (resolvedAppName != null && resolvedAppName !== container.appName) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
resolvedAppName = container.appName;
|
|
17
|
+
}
|
|
18
|
+
return resolvedAppName;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function findAppNameBySourceURL(sourceURL: string): string | null {
|
|
22
|
+
return resolveAppNameBySourceURL(sourceURL, getMicroFrontendRuntimeContext().containers);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function resolveAppNameFromStackFrames(
|
|
26
|
+
frames: readonly RuntimeStackFrame[],
|
|
27
|
+
containers: Readonly<Record<string, AppContainer>>
|
|
28
|
+
): string {
|
|
29
|
+
const sourceURL = resolveCurrentSourceURL(frames);
|
|
30
|
+
const appName = resolveAppNameBySourceURL(sourceURL, containers);
|
|
31
|
+
if (appName != null) {
|
|
32
|
+
return appName;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw new Error('Cannot resolve the current micro-frontend app name');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getAppName(): string {
|
|
39
|
+
const sourceURL = resolveCurrentSourceURL(captureStackFrames());
|
|
40
|
+
const appName = findAppNameBySourceURL(sourceURL);
|
|
41
|
+
if (appName != null) {
|
|
42
|
+
return appName;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
throw new Error('Cannot resolve the current micro-frontend app name');
|
|
46
|
+
}
|
package/src/runtime/registry.ts
CHANGED
|
@@ -16,10 +16,15 @@ export interface AppContainerConfig {
|
|
|
16
16
|
readonly shared?: SharedConfig;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export interface AppContainerRuntime {
|
|
20
|
+
readonly sourceURL: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
export interface AppContainer {
|
|
20
24
|
readonly appName: string;
|
|
21
25
|
readonly config: AppContainerConfig;
|
|
22
26
|
readonly exposedModules: Record<string, unknown>;
|
|
27
|
+
readonly runtime?: AppContainerRuntime;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
export type AppDisposeCallback = () => void | Promise<void>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface RuntimeStackFrame {
|
|
2
|
+
readonly sourceURL: string | null;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function captureStackFrames(): readonly RuntimeStackFrame[] {
|
|
6
|
+
const prepareStackTraceDescriptor = Object.getOwnPropertyDescriptor(Error, 'prepareStackTrace');
|
|
7
|
+
Object.defineProperty(Error, 'prepareStackTrace', {
|
|
8
|
+
configurable: true,
|
|
9
|
+
value: (_error: unknown, callSites: readonly unknown[]) => callSites,
|
|
10
|
+
writable: true,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const frames: RuntimeStackFrame[] = [];
|
|
14
|
+
try {
|
|
15
|
+
const callSites: unknown = new Error().stack;
|
|
16
|
+
if (!Array.isArray(callSites)) {
|
|
17
|
+
throw new Error('Cannot capture structured micro-frontend stack frames');
|
|
18
|
+
}
|
|
19
|
+
for (const callSite of callSites) {
|
|
20
|
+
if (typeof callSite !== 'object' || callSite == null) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (!('getFileName' in callSite)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const getFileName: unknown = 'getFileName' in callSite ? callSite.getFileName : undefined;
|
|
27
|
+
const sourceURL: unknown = typeof getFileName === 'function' ? getFileName.call(callSite) : null;
|
|
28
|
+
frames.push({ sourceURL: typeof sourceURL === 'string' ? sourceURL : null });
|
|
29
|
+
}
|
|
30
|
+
} finally {
|
|
31
|
+
if (prepareStackTraceDescriptor == null) {
|
|
32
|
+
Reflect.deleteProperty(Error, 'prepareStackTrace');
|
|
33
|
+
} else {
|
|
34
|
+
Object.defineProperty(Error, 'prepareStackTrace', prepareStackTraceDescriptor);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return frames;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function resolveCurrentSourceURL(frames: readonly RuntimeStackFrame[]): string {
|
|
42
|
+
for (const frame of frames) {
|
|
43
|
+
if (frame.sourceURL != null && frame.sourceURL.length > 0) {
|
|
44
|
+
return frame.sourceURL;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw new Error('Cannot determine the caller micro-frontend sourceURL');
|
|
48
|
+
}
|