@bleedingdev/modern-js-runtime 3.9.0-ultramodern.2 → 3.9.0-ultramodern.20
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/dist/cjs/cli/code.js +3 -1
- package/dist/cjs/cli/ssr/index.js +2 -74
- package/dist/cjs/cli/ssr/loadable-bundler-plugin.js +2 -0
- package/dist/cjs/cli/template.server.js +1 -2
- package/dist/cjs/core/browser/hydrate.js +9 -10
- package/dist/cjs/core/browser/index.js +4 -5
- package/dist/cjs/core/context/index.js +12 -45
- package/dist/cjs/core/context/public.js +4 -7
- package/dist/cjs/core/context/runtime.js +10 -4
- package/dist/cjs/core/index.js +3 -3
- package/dist/cjs/core/plugin/index.js +2 -2
- package/dist/cjs/core/react/index.js +3 -3
- package/dist/cjs/core/react/wrapper.js +23 -67
- package/dist/cjs/core/server/helmet.js +5 -4
- package/dist/cjs/core/server/requestHandler.js +6 -7
- package/dist/cjs/core/server/requestResponse.js +4 -4
- package/dist/cjs/core/server/routerCleanup.js +2 -2
- package/dist/cjs/core/server/shared.js +171 -4
- package/dist/cjs/core/server/stream/afterTemplate.js +21 -16
- package/dist/cjs/core/server/stream/beforeTemplate.js +37 -28
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +30 -23
- package/dist/cjs/core/server/stream/createReadableStream.js +222 -125
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +171 -90
- package/dist/cjs/core/server/stream/deferredScript.js +3 -3
- package/dist/cjs/core/server/stream/shared.js +6 -2
- package/dist/cjs/core/server/string/index.js +104 -66
- package/dist/cjs/core/server/string/loadable.js +38 -23
- package/dist/cjs/core/server/string/ssrData.js +5 -12
- package/dist/cjs/core/server/utils.js +1 -2
- package/dist/cjs/exports/head.js +7 -14
- package/dist/cjs/internal.js +2 -2
- package/dist/cjs/router/cli/code/nestedRoutes.js +1 -2
- package/dist/cjs/router/cli/code/templates.js +1 -1
- package/dist/cjs/router/cli/code/utils.js +2 -2
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +10 -9
- package/dist/cjs/router/runtime/PrefetchLink.js +69 -125
- package/dist/cjs/router/runtime/hooks.js +13 -2
- package/dist/cjs/router/runtime/internal.js +7 -45
- package/dist/cjs/router/runtime/plugin.js +19 -34
- package/dist/cjs/router/runtime/plugin.node.js +9 -37
- package/dist/cjs/router/runtime/redirect.js +1 -1
- package/dist/esm/cli/code.mjs +3 -1
- package/dist/esm/cli/ssr/index.mjs +3 -72
- package/dist/esm/cli/ssr/loadable-bundler-plugin.mjs +2 -0
- package/dist/esm/cli/template.server.mjs +1 -2
- package/dist/esm/core/browser/hydrate.mjs +10 -11
- package/dist/esm/core/browser/index.mjs +1 -2
- package/dist/esm/core/context/index.mjs +2 -5
- package/dist/esm/core/context/public.mjs +1 -5
- package/dist/esm/core/context/runtime.mjs +6 -3
- package/dist/esm/core/index.mjs +1 -1
- package/dist/esm/core/plugin/index.mjs +1 -1
- package/dist/esm/core/react/index.mjs +1 -1
- package/dist/esm/core/react/wrapper.mjs +20 -67
- package/dist/esm/core/server/helmet.mjs +5 -4
- package/dist/esm/core/server/requestHandler.mjs +1 -2
- package/dist/esm/core/server/requestResponse.mjs +3 -3
- package/dist/esm/core/server/routerCleanup.mjs +1 -1
- package/dist/esm/core/server/shared.mjs +153 -1
- package/dist/esm/core/server/stream/afterTemplate.mjs +23 -18
- package/dist/esm/core/server/stream/beforeTemplate.mjs +40 -31
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +33 -26
- package/dist/esm/core/server/stream/createReadableStream.mjs +220 -123
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +161 -90
- package/dist/esm/core/server/stream/deferredScript.mjs +3 -3
- package/dist/esm/core/server/stream/shared.mjs +4 -3
- package/dist/esm/core/server/string/index.mjs +106 -68
- package/dist/esm/core/server/string/loadable.mjs +38 -23
- package/dist/esm/core/server/string/ssrData.mjs +5 -12
- package/dist/esm/core/server/utils.mjs +1 -2
- package/dist/esm/exports/head.mjs +7 -14
- package/dist/esm/internal.mjs +1 -1
- package/dist/esm/router/cli/code/nestedRoutes.mjs +1 -2
- package/dist/esm/router/cli/code/templates.mjs +1 -1
- package/dist/esm/router/cli/code/utils.mjs +2 -2
- package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +10 -9
- package/dist/esm/router/runtime/PrefetchLink.mjs +68 -124
- package/dist/esm/router/runtime/hooks.mjs +9 -1
- package/dist/esm/router/runtime/internal.mjs +2 -33
- package/dist/esm/router/runtime/plugin.mjs +10 -25
- package/dist/esm/router/runtime/plugin.node.mjs +3 -31
- package/dist/esm/router/runtime/redirect.mjs +1 -1
- package/dist/esm-node/cli/code.mjs +3 -1
- package/dist/esm-node/cli/ssr/index.mjs +3 -72
- package/dist/esm-node/cli/ssr/loadable-bundler-plugin.mjs +2 -0
- package/dist/esm-node/cli/template.server.mjs +1 -2
- package/dist/esm-node/core/browser/hydrate.mjs +10 -11
- package/dist/esm-node/core/browser/index.mjs +1 -2
- package/dist/esm-node/core/context/index.mjs +2 -5
- package/dist/esm-node/core/context/public.mjs +1 -5
- package/dist/esm-node/core/context/runtime.mjs +6 -3
- package/dist/esm-node/core/index.mjs +1 -1
- package/dist/esm-node/core/plugin/index.mjs +1 -1
- package/dist/esm-node/core/react/index.mjs +1 -1
- package/dist/esm-node/core/react/wrapper.mjs +20 -67
- package/dist/esm-node/core/server/helmet.mjs +5 -4
- package/dist/esm-node/core/server/requestHandler.mjs +1 -2
- package/dist/esm-node/core/server/requestResponse.mjs +3 -3
- package/dist/esm-node/core/server/routerCleanup.mjs +1 -1
- package/dist/esm-node/core/server/shared.mjs +153 -1
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +23 -18
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +40 -31
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +33 -26
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +220 -123
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +161 -90
- package/dist/esm-node/core/server/stream/deferredScript.mjs +3 -3
- package/dist/esm-node/core/server/stream/shared.mjs +4 -3
- package/dist/esm-node/core/server/string/index.mjs +106 -68
- package/dist/esm-node/core/server/string/loadable.mjs +38 -23
- package/dist/esm-node/core/server/string/ssrData.mjs +5 -12
- package/dist/esm-node/core/server/utils.mjs +1 -2
- package/dist/esm-node/exports/head.mjs +7 -14
- package/dist/esm-node/internal.mjs +1 -1
- package/dist/esm-node/router/cli/code/nestedRoutes.mjs +1 -2
- package/dist/esm-node/router/cli/code/templates.mjs +1 -1
- package/dist/esm-node/router/cli/code/utils.mjs +2 -2
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +10 -9
- package/dist/esm-node/router/runtime/PrefetchLink.mjs +68 -124
- package/dist/esm-node/router/runtime/hooks.mjs +9 -1
- package/dist/esm-node/router/runtime/internal.mjs +2 -33
- package/dist/esm-node/router/runtime/plugin.mjs +10 -25
- package/dist/esm-node/router/runtime/plugin.node.mjs +3 -31
- package/dist/esm-node/router/runtime/redirect.mjs +1 -1
- package/dist/types/cli/ssr/index.d.ts +0 -3
- package/dist/types/core/context/index.d.ts +4 -6
- package/dist/types/core/context/public.d.ts +1 -23
- package/dist/types/core/context/runtime.d.ts +26 -2
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/react/wrapper.d.ts +7 -1
- package/dist/types/core/server/helmet.d.ts +4 -5
- package/dist/types/core/server/requestHandler.d.ts +3 -3
- package/dist/types/core/server/requestResponse.d.ts +1 -1
- package/dist/types/core/server/routerCleanup.d.ts +1 -1
- package/dist/types/core/server/shared.d.ts +24 -1
- package/dist/types/core/server/stream/afterTemplate.d.ts +2 -1
- package/dist/types/core/server/stream/beforeTemplate.d.ts +4 -1
- package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +4 -1
- package/dist/types/core/server/stream/shared.d.ts +16 -2
- package/dist/types/core/server/string/loadable.d.ts +6 -3
- package/dist/types/core/server/string/ssrData.d.ts +2 -1
- package/dist/types/core/server/string/types.d.ts +1 -5
- package/dist/types/core/server/tracer.d.ts +1 -1
- package/dist/types/core/server/utils.d.ts +1 -1
- package/dist/types/core/types.d.ts +1 -2
- package/dist/types/exports/head.d.ts +2 -2
- package/dist/types/internal.d.ts +1 -1
- package/dist/types/router/runtime/PrefetchLink.d.ts +27 -2
- package/dist/types/router/runtime/hooks.d.ts +19 -2
- package/dist/types/router/runtime/internal.d.ts +4 -21
- package/dist/types/router/runtime/types.d.ts +2 -43
- package/package.json +18 -46
- package/rslib.config.mts +3 -0
- package/rstest.config.mts +28 -2
- package/dist/cjs/boundary-debugger/index.js +0 -317
- package/dist/cjs/core/context/extensions.js +0 -74
- package/dist/cjs/core/context/helmetContext.js +0 -54
- package/dist/cjs/core/server/federatedCss.js +0 -58
- package/dist/cjs/core/server/scriptOrder.js +0 -140
- package/dist/cjs/module-federation/consume-surface.js +0 -199
- package/dist/cjs/module-federation/distributed-ssr.js +0 -135
- package/dist/cjs/module-federation/index.js +0 -316
- package/dist/cjs/module-federation/last-known-good.js +0 -157
- package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +0 -129
- package/dist/cjs/module-federation/surface-resolution-types.js +0 -61
- package/dist/cjs/router/runtime/lifecycle.js +0 -167
- package/dist/cjs/router/runtime/provider.js +0 -153
- package/dist/cjs/rsc/server.worker.js +0 -62
- package/dist/esm/boundary-debugger/index.mjs +0 -277
- package/dist/esm/core/context/extensions.mjs +0 -33
- package/dist/esm/core/context/helmetContext.mjs +0 -13
- package/dist/esm/core/server/federatedCss.mjs +0 -20
- package/dist/esm/core/server/scriptOrder.mjs +0 -90
- package/dist/esm/module-federation/consume-surface.mjs +0 -158
- package/dist/esm/module-federation/distributed-ssr.mjs +0 -82
- package/dist/esm/module-federation/index.mjs +0 -115
- package/dist/esm/module-federation/last-known-good.mjs +0 -113
- package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +0 -89
- package/dist/esm/module-federation/surface-resolution-types.mjs +0 -8
- package/dist/esm/router/runtime/lifecycle.mjs +0 -105
- package/dist/esm/router/runtime/provider.mjs +0 -100
- package/dist/esm/rsc/server.worker.mjs +0 -1
- package/dist/esm-node/boundary-debugger/index.mjs +0 -278
- package/dist/esm-node/core/context/extensions.mjs +0 -34
- package/dist/esm-node/core/context/helmetContext.mjs +0 -14
- package/dist/esm-node/core/server/federatedCss.mjs +0 -21
- package/dist/esm-node/core/server/scriptOrder.mjs +0 -91
- package/dist/esm-node/module-federation/consume-surface.mjs +0 -159
- package/dist/esm-node/module-federation/distributed-ssr.mjs +0 -83
- package/dist/esm-node/module-federation/index.mjs +0 -116
- package/dist/esm-node/module-federation/last-known-good.mjs +0 -114
- package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +0 -90
- package/dist/esm-node/module-federation/surface-resolution-types.mjs +0 -9
- package/dist/esm-node/router/runtime/lifecycle.mjs +0 -106
- package/dist/esm-node/router/runtime/provider.mjs +0 -101
- package/dist/esm-node/rsc/server.worker.mjs +0 -2
- package/dist/types/boundary-debugger/index.d.ts +0 -28
- package/dist/types/core/context/extensions.d.ts +0 -35
- package/dist/types/core/context/helmetContext.d.ts +0 -10
- package/dist/types/core/server/federatedCss.d.ts +0 -5
- package/dist/types/core/server/scriptOrder.d.ts +0 -25
- package/dist/types/module-federation/consume-surface.d.ts +0 -104
- package/dist/types/module-federation/distributed-ssr.d.ts +0 -61
- package/dist/types/module-federation/index.d.ts +0 -71
- package/dist/types/module-federation/last-known-good.d.ts +0 -52
- package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +0 -25
- package/dist/types/module-federation/surface-resolution-types.d.ts +0 -23
- package/dist/types/router/runtime/lifecycle.d.ts +0 -27
- package/dist/types/router/runtime/provider.d.ts +0 -78
- package/dist/types/rsc/server.worker.d.ts +0 -1
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { createRuntimeContextExtension } from "../../core/context/extensions.mjs";
|
|
3
|
-
const routerRuntimeStateExtension = createRuntimeContextExtension('@modern-js/runtime:router-runtime-state');
|
|
4
|
-
const routerServerSnapshotExtension = createRuntimeContextExtension('@modern-js/runtime:router-server-snapshot');
|
|
5
|
-
function getRouterRuntimeState(runtimeContext) {
|
|
6
|
-
return routerRuntimeStateExtension.get(runtimeContext);
|
|
7
|
-
}
|
|
8
|
-
function getRouterServerSnapshot(runtimeContext) {
|
|
9
|
-
return routerServerSnapshotExtension.get(runtimeContext);
|
|
10
|
-
}
|
|
11
|
-
function toHydrationScripts(state) {
|
|
12
|
-
if (state.hydrationScripts?.length) return state.hydrationScripts;
|
|
13
|
-
return state.hydrationScript ? [
|
|
14
|
-
state.hydrationScript
|
|
15
|
-
] : void 0;
|
|
16
|
-
}
|
|
17
|
-
function getMatchedRouteIdsFromMatches(matches) {
|
|
18
|
-
const routeIds = matches?.map((match)=>match.assetRouteId ?? match.routeId).filter((routeId)=>'string' == typeof routeId);
|
|
19
|
-
return routeIds?.length ? routeIds : void 0;
|
|
20
|
-
}
|
|
21
|
-
function createRouterServerSnapshot(state) {
|
|
22
|
-
const hydrationScripts = toHydrationScripts(state);
|
|
23
|
-
const matchedRouteIds = state.matchedRouteIds ?? getMatchedRouteIdsFromMatches(state.matches);
|
|
24
|
-
return {
|
|
25
|
-
...state,
|
|
26
|
-
...hydrationScripts?.length ? {
|
|
27
|
-
hydrationScript: state.hydrationScript ?? hydrationScripts[0],
|
|
28
|
-
hydrationScripts
|
|
29
|
-
} : {},
|
|
30
|
-
...matchedRouteIds ? {
|
|
31
|
-
matchedRouteIds
|
|
32
|
-
} : {}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function createRouterRuntimeState(state) {
|
|
36
|
-
const hasSnapshotState = Boolean(state.serverSnapshot) || Boolean(state.hydrationScript) || Boolean(state.hydrationScripts?.length) || Boolean(state.matchedRouteIds?.length) || Boolean(state.matches?.length);
|
|
37
|
-
const serverSnapshot = state.serverSnapshot ? createRouterServerSnapshot({
|
|
38
|
-
...state.serverSnapshot,
|
|
39
|
-
framework: state.serverSnapshot.framework ?? state.framework,
|
|
40
|
-
basename: state.serverSnapshot.basename ?? state.basename,
|
|
41
|
-
hydrationScript: state.serverSnapshot.hydrationScript ?? state.hydrationScript,
|
|
42
|
-
hydrationScripts: state.serverSnapshot.hydrationScripts ?? state.hydrationScripts,
|
|
43
|
-
matchedRouteIds: state.serverSnapshot.matchedRouteIds ?? state.matchedRouteIds,
|
|
44
|
-
matches: state.serverSnapshot.matches ?? state.matches
|
|
45
|
-
}) : hasSnapshotState ? createRouterServerSnapshot({
|
|
46
|
-
framework: state.framework,
|
|
47
|
-
basename: state.basename,
|
|
48
|
-
hydrationScript: state.hydrationScript,
|
|
49
|
-
hydrationScripts: state.hydrationScripts,
|
|
50
|
-
matchedRouteIds: state.matchedRouteIds,
|
|
51
|
-
matches: state.matches
|
|
52
|
-
}) : void 0;
|
|
53
|
-
const hydrationScripts = toHydrationScripts({
|
|
54
|
-
hydrationScript: state.hydrationScript ?? serverSnapshot?.hydrationScript,
|
|
55
|
-
hydrationScripts: state.hydrationScripts ?? serverSnapshot?.hydrationScripts
|
|
56
|
-
});
|
|
57
|
-
const matchedRouteIds = state.matchedRouteIds ?? serverSnapshot?.matchedRouteIds ?? getMatchedRouteIdsFromMatches(state.matches);
|
|
58
|
-
return {
|
|
59
|
-
...state,
|
|
60
|
-
...hydrationScripts?.length ? {
|
|
61
|
-
hydrationScript: state.hydrationScript ?? hydrationScripts[0],
|
|
62
|
-
hydrationScripts
|
|
63
|
-
} : {},
|
|
64
|
-
...matchedRouteIds ? {
|
|
65
|
-
matchedRouteIds
|
|
66
|
-
} : {},
|
|
67
|
-
...serverSnapshot ? {
|
|
68
|
-
serverSnapshot
|
|
69
|
-
} : {}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function applyRouterRuntimeState(runtimeContext, state) {
|
|
73
|
-
const normalized = createRouterRuntimeState(state);
|
|
74
|
-
routerRuntimeStateExtension.set(runtimeContext, normalized);
|
|
75
|
-
if (normalized.serverSnapshot) routerServerSnapshotExtension.set(runtimeContext, normalized.serverSnapshot);
|
|
76
|
-
return runtimeContext;
|
|
77
|
-
}
|
|
78
|
-
function applyRouterServerPrepareResult(runtimeContext, result) {
|
|
79
|
-
const state = createRouterRuntimeState({
|
|
80
|
-
...result.state,
|
|
81
|
-
cleanup: result.cleanup ?? result.state.cleanup,
|
|
82
|
-
serverSnapshot: result.snapshot ?? result.state.serverSnapshot
|
|
83
|
-
});
|
|
84
|
-
applyRouterRuntimeState(runtimeContext, state);
|
|
85
|
-
return runtimeContext;
|
|
86
|
-
}
|
|
87
|
-
function getRouterHydrationScripts(runtimeContext) {
|
|
88
|
-
const serverSnapshot = getRouterServerSnapshot(runtimeContext);
|
|
89
|
-
const runtimeState = getRouterRuntimeState(runtimeContext);
|
|
90
|
-
return serverSnapshot?.hydrationScripts ?? toHydrationScripts({
|
|
91
|
-
hydrationScript: serverSnapshot?.hydrationScript
|
|
92
|
-
}) ?? runtimeState?.hydrationScripts ?? toHydrationScripts({
|
|
93
|
-
hydrationScript: runtimeState?.hydrationScript
|
|
94
|
-
}) ?? [];
|
|
95
|
-
}
|
|
96
|
-
function getRouterMatchedRouteIds(runtimeContext) {
|
|
97
|
-
const serverSnapshot = getRouterServerSnapshot(runtimeContext);
|
|
98
|
-
const runtimeState = getRouterRuntimeState(runtimeContext);
|
|
99
|
-
return serverSnapshot?.matchedRouteIds ?? getMatchedRouteIdsFromMatches(serverSnapshot?.matches) ?? runtimeState?.matchedRouteIds ?? getMatchedRouteIdsFromMatches(runtimeState?.matches);
|
|
100
|
-
}
|
|
101
|
-
async function cleanupRouterRuntimeState(runtimeContext) {
|
|
102
|
-
try {
|
|
103
|
-
await getRouterRuntimeState(runtimeContext)?.cleanup?.();
|
|
104
|
-
} catch {}
|
|
105
|
-
}
|
|
106
|
-
export { applyRouterRuntimeState, applyRouterServerPrepareResult, cleanupRouterRuntimeState, createRouterRuntimeState, createRouterServerSnapshot, getRouterHydrationScripts, getRouterMatchedRouteIds, getRouterRuntimeState, getRouterServerSnapshot };
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter } from "./hooks.mjs";
|
|
3
|
-
const routerProviderRegistryHooks = {
|
|
4
|
-
modifyRoutes: modifyRoutes,
|
|
5
|
-
onBeforeCreateRoutes: onBeforeCreateRoutes,
|
|
6
|
-
onBeforeCreateRouter: onBeforeCreateRouter,
|
|
7
|
-
onAfterCreateRouter: onAfterCreateRouter,
|
|
8
|
-
onBeforeHydrateRouter: onBeforeHydrateRouter,
|
|
9
|
-
onAfterHydrateRouter: onAfterHydrateRouter
|
|
10
|
-
};
|
|
11
|
-
function reportUnsupportedProviderRegistryHooks(providerPlugin) {
|
|
12
|
-
const unsupportedHookNames = Object.keys(providerPlugin.registryHooks ?? {}).filter((hookName)=>!(hookName in routerProviderRegistryHooks));
|
|
13
|
-
if (unsupportedHookNames.length > 0) console.warn(`[@modern-js/runtime] The router provider "${providerPlugin.name}" declares registry hooks outside the router hook contract: ${unsupportedHookNames.join(', ')}. These hooks are not registered when the provider is resolved through \`runtime.router.framework\` — declare them on a separate runtime plugin instead.`);
|
|
14
|
-
return unsupportedHookNames;
|
|
15
|
-
}
|
|
16
|
-
function createRouterProviderRealm(registrations) {
|
|
17
|
-
const providers = new Map();
|
|
18
|
-
let defaultProvider;
|
|
19
|
-
for (const registration of registrations){
|
|
20
|
-
if (0 === registration.name.length) throw new Error('[@modern-js/runtime] A router provider realm cannot contain an unnamed provider.');
|
|
21
|
-
if (providers.has(registration.name)) throw new Error(`[@modern-js/runtime] Router provider "${registration.name}" is declared more than once in the same runtime realm.`);
|
|
22
|
-
if (true === registration.isDefault && void 0 !== defaultProvider && defaultProvider !== registration.name) throw new Error(`[@modern-js/runtime] Router provider realm declares both "${defaultProvider}" and "${registration.name}" as defaults.`);
|
|
23
|
-
providers.set(registration.name, registration.factory);
|
|
24
|
-
if (true === registration.isDefault) defaultProvider = registration.name;
|
|
25
|
-
}
|
|
26
|
-
const providerNames = Object.freeze([
|
|
27
|
-
...providers.keys()
|
|
28
|
-
]);
|
|
29
|
-
return Object.freeze({
|
|
30
|
-
...void 0 !== defaultProvider ? {
|
|
31
|
-
defaultProvider
|
|
32
|
-
} : {},
|
|
33
|
-
get: (name)=>providers.get(name),
|
|
34
|
-
names: ()=>providerNames
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
const REGISTRY_SLOT = Symbol.for('@modern-js/runtime:router-providers:v3');
|
|
38
|
-
const LEGACY_V2_REGISTRY_SLOT = Symbol.for('@modern-js/runtime:router-providers:v2');
|
|
39
|
-
function getRegistry() {
|
|
40
|
-
const host = globalThis;
|
|
41
|
-
host[REGISTRY_SLOT] ??= {
|
|
42
|
-
providers: new Map(),
|
|
43
|
-
duplicateProviders: new Set(),
|
|
44
|
-
warnedDuplicates: new Set()
|
|
45
|
-
};
|
|
46
|
-
host[REGISTRY_SLOT].duplicateProviders ??= new Set();
|
|
47
|
-
host[REGISTRY_SLOT].warnedDuplicates ??= new Set();
|
|
48
|
-
return host[REGISTRY_SLOT];
|
|
49
|
-
}
|
|
50
|
-
function getLegacyV2Registry() {
|
|
51
|
-
const host = globalThis;
|
|
52
|
-
return host[LEGACY_V2_REGISTRY_SLOT];
|
|
53
|
-
}
|
|
54
|
-
function registerRouterProvider(name, factory, options = {}) {
|
|
55
|
-
const registry = getRegistry();
|
|
56
|
-
const existing = registry.providers.get(name);
|
|
57
|
-
if (void 0 !== existing) {
|
|
58
|
-
if (existing !== factory) registry.duplicateProviders.add(name);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (true === options.isDefault) registry.defaultProvider = name;
|
|
62
|
-
registry.providers.set(name, factory);
|
|
63
|
-
}
|
|
64
|
-
function resolveRouterProvider(framework, options = {}) {
|
|
65
|
-
if (void 0 !== options.realm) {
|
|
66
|
-
const name = framework || options.realm.defaultProvider;
|
|
67
|
-
const realmProviderNames = options.realm.names();
|
|
68
|
-
if (void 0 === name) throw new Error(`[@modern-js/runtime] The app-owned router provider realm does not declare a default provider. Available realm providers: ${realmProviderNames.join(', ') || '(none)'}.`);
|
|
69
|
-
const factory = options.realm.get(name);
|
|
70
|
-
if (void 0 === factory) throw new Error(`[@modern-js/runtime] Router provider "${name}" is not registered in the app-owned router provider realm. Available realm providers: ${realmProviderNames.join(', ') || '(none)'}. Compatibility registry fallback is disabled for app-owned realms.`);
|
|
71
|
-
return factory;
|
|
72
|
-
}
|
|
73
|
-
const registry = getRegistry();
|
|
74
|
-
const legacyV2Registry = getLegacyV2Registry();
|
|
75
|
-
const name = framework || options.localDefault?.name || registry.defaultProvider || legacyV2Registry?.defaultProvider;
|
|
76
|
-
if (void 0 === name) throw new Error('[@modern-js/runtime] No default router provider is registered. This is a bug in the runtime setup.');
|
|
77
|
-
if (void 0 !== options.localDefault && name === options.localDefault.name) return options.localDefault.factory;
|
|
78
|
-
const factory = registry.providers.get(name);
|
|
79
|
-
if (void 0 !== factory) {
|
|
80
|
-
if (registry.duplicateProviders.has(name) && !registry.warnedDuplicates.has(name)) {
|
|
81
|
-
registry.warnedDuplicates.add(name);
|
|
82
|
-
console.warn(`[@modern-js/runtime] The router provider "${name}" was registered more than once with different module instances, and a router wrapper without an app-owned provider realm is resolving the mixed-version compatibility fallback. The fallback is keeping the first registration. Modern router wrappers isolate app-owned realms automatically. For an older wrapper, share the provider runtime between Module Federation host and remotes or upgrade every app to a realm-aware runtime.`);
|
|
83
|
-
}
|
|
84
|
-
return factory;
|
|
85
|
-
}
|
|
86
|
-
const legacyV2Factory = legacyV2Registry?.providers.get(name);
|
|
87
|
-
if (void 0 !== legacyV2Factory) return legacyV2Factory;
|
|
88
|
-
if ('tanstack' === name) throw new Error("[@modern-js/runtime] `runtime.router.framework` is set to \"tanstack\", but no TanStack router provider is registered. Install @modern-js/plugin-tanstack, add `tanstackRouterPlugin()` to the `plugins` array in modern.config.ts, and make sure '@modern-js/plugin-tanstack/runtime' is imported (e.g. in modern.runtime.ts).");
|
|
89
|
-
throw new Error(`[@modern-js/runtime] Unknown router framework "${name}". Registered providers: ${[
|
|
90
|
-
...new Set([
|
|
91
|
-
...registry.providers.keys(),
|
|
92
|
-
...legacyV2Registry?.providers.keys() ?? []
|
|
93
|
-
])
|
|
94
|
-
].join(', ') || '(none)'}. Install and register the plugin that provides this router framework.`);
|
|
95
|
-
}
|
|
96
|
-
function unsafe_resetRouterProvidersForTesting() {
|
|
97
|
-
const host = globalThis;
|
|
98
|
-
delete host[REGISTRY_SLOT];
|
|
99
|
-
delete host[LEGACY_V2_REGISTRY_SLOT];
|
|
100
|
-
}
|
|
101
|
-
export { createRouterProviderRealm, registerRouterProvider, reportUnsupportedProviderRegistryHooks, resolveRouterProvider, routerProviderRegistryHooks, unsafe_resetRouterProvidersForTesting };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { RuntimePlugin } from '../common.js';
|
|
2
|
-
export type BoundaryDebugEntry = {
|
|
3
|
-
appId: string;
|
|
4
|
-
color?: string;
|
|
5
|
-
label?: string;
|
|
6
|
-
mfName: string;
|
|
7
|
-
ownerTeam?: string;
|
|
8
|
-
packageName?: string;
|
|
9
|
-
role?: 'host' | 'vertical';
|
|
10
|
-
};
|
|
11
|
-
export type BoundaryDebugMetadata = {
|
|
12
|
-
appId: string;
|
|
13
|
-
boundaries: BoundaryDebugEntry[];
|
|
14
|
-
schemaVersion: 1;
|
|
15
|
-
};
|
|
16
|
-
export type BoundaryDebuggerControlMode = 'visible' | 'hidden-when-off' | 'hidden';
|
|
17
|
-
export type BoundaryDebuggerPluginOptions = {
|
|
18
|
-
controlMode?: BoundaryDebuggerControlMode;
|
|
19
|
-
enabledByDefault?: boolean;
|
|
20
|
-
labels?: Record<string, {
|
|
21
|
-
toggle: string;
|
|
22
|
-
}>;
|
|
23
|
-
legacySelector?: string;
|
|
24
|
-
metadata: BoundaryDebugMetadata;
|
|
25
|
-
storageKey?: string;
|
|
26
|
-
};
|
|
27
|
-
export declare const ultramodernBoundaryDebuggerPlugin: (options: BoundaryDebuggerPluginOptions) => RuntimePlugin;
|
|
28
|
-
export default ultramodernBoundaryDebuggerPlugin;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fork-owned runtime-context extension mechanism.
|
|
3
|
-
*
|
|
4
|
-
* Plugins must not add ad-hoc fields to `TRuntimeContext` /
|
|
5
|
-
* `TInternalRuntimeContext`. Instead they store state in a single internal
|
|
6
|
-
* slot (a `Map` keyed by symbol) attached to the context object under a
|
|
7
|
-
* symbol property, so nothing leaks into string-key enumeration
|
|
8
|
-
* (`Object.keys`, `JSON.stringify`, `{ ...context }` rest patterns over
|
|
9
|
-
* named keys).
|
|
10
|
-
*
|
|
11
|
-
* `Symbol.for` is used for both the slot and the extension keys so that the
|
|
12
|
-
* mechanism stays coherent even if this module is instantiated twice
|
|
13
|
-
* (e.g. esm/cjs interop in test runners).
|
|
14
|
-
*/
|
|
15
|
-
export interface RuntimeContextExtension<T> {
|
|
16
|
-
/** Stable identity of this extension. */
|
|
17
|
-
readonly key: symbol;
|
|
18
|
-
get(context: object): T | undefined;
|
|
19
|
-
set(context: object, value: T): void;
|
|
20
|
-
remove(context: object): void;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Removes the extension slot from a context object.
|
|
24
|
-
*
|
|
25
|
-
* The symbol slot crosses object spreads while remaining absent from string-key
|
|
26
|
-
* enumeration and JSON. Callers can still explicitly clear the original context.
|
|
27
|
-
*/
|
|
28
|
-
export declare function stripRuntimeContextExtensions(context: object): void;
|
|
29
|
-
/**
|
|
30
|
-
* Creates a typed accessor pair over the shared extension slot.
|
|
31
|
-
*
|
|
32
|
-
* The `id` must be globally unique (it is interned via `Symbol.for`); use a
|
|
33
|
-
* package-prefixed name such as `@modern-js/plugin-tanstack:router-state`.
|
|
34
|
-
*/
|
|
35
|
-
export declare function createRuntimeContextExtension<T>(id: string): RuntimeContextExtension<T>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fork-owned helmet state, stored via the runtime-context extension slot
|
|
3
|
-
* instead of an ad-hoc `_helmetContext` field on `TInternalRuntimeContext`.
|
|
4
|
-
*/
|
|
5
|
-
import type { HelmetServerState } from 'react-helmet-async';
|
|
6
|
-
export interface HelmetContextSlot {
|
|
7
|
-
helmet?: HelmetServerState | null;
|
|
8
|
-
}
|
|
9
|
-
export declare function getHelmetContext(context: object): HelmetContextSlot | undefined;
|
|
10
|
-
export declare function ensureHelmetContext(context: object): HelmetContextSlot;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { TInternalRuntimeContext } from '../context/index.js';
|
|
2
|
-
type RouteAssetManifest = {
|
|
3
|
-
assets?: string[];
|
|
4
|
-
};
|
|
5
|
-
type RouteManifestLike = {
|
|
6
|
-
routeAssets?: Record<string, RouteAssetManifest | undefined>;
|
|
7
|
-
};
|
|
8
|
-
type ScriptChunkLike = {
|
|
9
|
-
filename?: string;
|
|
10
|
-
url?: string;
|
|
11
|
-
};
|
|
12
|
-
export declare function getMatchedRouteChunks<T>(runtimeContext: TInternalRuntimeContext, routeManifest: RouteManifestLike | undefined, routeAssetToChunk: (asset: string) => T): T[];
|
|
13
|
-
export declare const orderHydrationScriptChunks: <T extends ScriptChunkLike>({ asyncEntryChunks, collectedChunks, matchedRouteChunks, entryName, }: {
|
|
14
|
-
asyncEntryChunks: T[];
|
|
15
|
-
collectedChunks: T[];
|
|
16
|
-
matchedRouteChunks: T[];
|
|
17
|
-
entryName: string;
|
|
18
|
-
}) => T[];
|
|
19
|
-
export declare function injectBeforeHydrationEntryScript(template: string, scripts: string, entryName?: string): string;
|
|
20
|
-
export declare function replaceChunkJsPlaceholder(template: string, scripts: string, entryName?: string, placeholder?: string): string;
|
|
21
|
-
export declare function createRouteHydrationScriptTags(runtimeContext: TInternalRuntimeContext, entryName: string, options?: {
|
|
22
|
-
nonce?: string;
|
|
23
|
-
template?: string;
|
|
24
|
-
}): string;
|
|
25
|
-
export {};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* G22 — mandatory degraded consumption API.
|
|
3
|
-
*
|
|
4
|
-
* CONTEXT.md (Degraded State): "consuming a surface obliges the consumer to
|
|
5
|
-
* define a degraded state". This module turns that obligation into a
|
|
6
|
-
* compile-level one: {@link SurfaceConsumerOptions.degraded} is a REQUIRED
|
|
7
|
-
* field, so a call site that forgets its fallback does not type-check.
|
|
8
|
-
*
|
|
9
|
-
* The consumer wraps the loadRemote-ish flow (resolve a SurfaceRef through a
|
|
10
|
-
* provider, then load the execution artifact from the resolved record) and
|
|
11
|
-
* guarantees isolation: any discovery/load failure is caught, classified,
|
|
12
|
-
* reported through the existing MF fallback telemetry, and handed to the
|
|
13
|
-
* required degraded handler.
|
|
14
|
-
*
|
|
15
|
-
* Criticality (owner-default 5: unclassified consumption is `critical`). For a
|
|
16
|
-
* `noncritical` consumption the degraded handler's result is returned and the
|
|
17
|
-
* failure is swallowed, so one failing consumption can never propagate to a
|
|
18
|
-
* sibling (CONTEXT.md: faults isolate at the vertical boundary). For a
|
|
19
|
-
* `critical` consumption the degraded handler still runs — telemetry and
|
|
20
|
-
* fallback-UI obligations hold — but the returned promise then REJECTS with the
|
|
21
|
-
* typed failure so callers and rollout machinery observe it. Critical
|
|
22
|
-
* consumption during a rollout window should be driven by expand/contract, not
|
|
23
|
-
* by silent degrade.
|
|
24
|
-
*/
|
|
25
|
-
import { type ModuleFederationFallbackClassification, type ModuleFederationFallbackTelemetryEmitOptions, type ModuleFederationFallbackTelemetryPayload } from './index.js';
|
|
26
|
-
import { type DiscoveryError, type EnvironmentId, type ParsedSurfaceRef, type ResolvedDeliveryUnit, type SurfaceResolutionProvider } from './surface-resolution-types.js';
|
|
27
|
-
/** Where in the consumption lifecycle a failure was raised. */
|
|
28
|
-
export type SurfaceConsumptionPhase = 'discovery' | 'load' | 'mount';
|
|
29
|
-
/**
|
|
30
|
-
* The typed failure surfaced to the degraded handler. Exactly one of
|
|
31
|
-
* `discoveryError` (resolver returned a typed {@link DiscoveryError}) or
|
|
32
|
-
* `error` (something threw) is populated for a given failure.
|
|
33
|
-
*/
|
|
34
|
-
export type SurfaceConsumptionFailure = {
|
|
35
|
-
ref: ParsedSurfaceRef;
|
|
36
|
-
env: EnvironmentId;
|
|
37
|
-
phase: SurfaceConsumptionPhase;
|
|
38
|
-
classification: ModuleFederationFallbackClassification;
|
|
39
|
-
/** Present when discovery returned a typed error state. */
|
|
40
|
-
discoveryError?: DiscoveryError;
|
|
41
|
-
/** Present when a thrown error caused the failure. */
|
|
42
|
-
error?: unknown;
|
|
43
|
-
/** The resolved record, when discovery succeeded but load/mount failed. */
|
|
44
|
-
resolved?: ResolvedDeliveryUnit;
|
|
45
|
-
/** The fallback telemetry payload emitted for this failure. */
|
|
46
|
-
telemetry: ModuleFederationFallbackTelemetryPayload;
|
|
47
|
-
};
|
|
48
|
-
export type SurfaceLoadInput = {
|
|
49
|
-
resolved: ResolvedDeliveryUnit;
|
|
50
|
-
ref: ParsedSurfaceRef;
|
|
51
|
-
env: EnvironmentId;
|
|
52
|
-
};
|
|
53
|
-
export type SurfaceConsumerOptions<T> = {
|
|
54
|
-
/** The logical surface to consume (object or canonical string form). */
|
|
55
|
-
ref: ParsedSurfaceRef | string;
|
|
56
|
-
env: EnvironmentId;
|
|
57
|
-
/** The pluggable resolution seam (RESOLUTION-0001 §2.2). */
|
|
58
|
-
provider: SurfaceResolutionProvider;
|
|
59
|
-
/** Consumer app name, used for telemetry attribution. */
|
|
60
|
-
appName: string;
|
|
61
|
-
/**
|
|
62
|
-
* Loads the execution artifact from a resolved record — the loadRemote-ish
|
|
63
|
-
* flow. Receives the whole {@link ResolvedDeliveryUnit} so the adapter reads
|
|
64
|
-
* locations under one buildMarker (RESOLUTION-0001 §2.3).
|
|
65
|
-
*/
|
|
66
|
-
load: (input: SurfaceLoadInput) => Promise<T> | T;
|
|
67
|
-
/**
|
|
68
|
-
* REQUIRED degraded handler (G22 compile-level obligation). There is no
|
|
69
|
-
* default and no way to opt out at the type level: omitting this field is a
|
|
70
|
-
* compile error. Return the value to serve while the surface is unavailable
|
|
71
|
-
* or incompatible.
|
|
72
|
-
*/
|
|
73
|
-
degraded: (failure: SurfaceConsumptionFailure) => T | Promise<T>;
|
|
74
|
-
/**
|
|
75
|
-
* Consumption criticality (owner-default 5). Defaults to `'critical'` when
|
|
76
|
-
* omitted.
|
|
77
|
-
*
|
|
78
|
-
* - `'noncritical'`: the degraded handler's result is returned and the
|
|
79
|
-
* failure is swallowed — the promise never rejects.
|
|
80
|
-
* - `'critical'`: the degraded handler still runs (telemetry + fallback-UI
|
|
81
|
-
* obligations hold), but the returned promise then REJECTS with the typed
|
|
82
|
-
* failure so callers / rollout machinery observe it. Prefer expand/contract
|
|
83
|
-
* over silent degrade for critical surfaces during rollout windows.
|
|
84
|
-
*/
|
|
85
|
-
classification?: 'critical' | 'noncritical';
|
|
86
|
-
/** Optional telemetry emission options (endpoint/auth/fetch overrides). */
|
|
87
|
-
telemetry?: ModuleFederationFallbackTelemetryEmitOptions;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Consume one surface with a mandatory degraded fallback. On any discovery or
|
|
91
|
-
* load failure the required degraded handler runs (telemetry + fallback UI).
|
|
92
|
-
*
|
|
93
|
-
* For a `noncritical` consumption (see {@link SurfaceConsumerOptions.classification})
|
|
94
|
-
* this resolves to the degraded value and never rejects, so a failing
|
|
95
|
-
* consumption is isolated from any sibling. For a `critical` consumption (the
|
|
96
|
-
* default) it rejects with the typed failure AFTER the degraded handler has
|
|
97
|
-
* run, so callers / rollout machinery observe the failure.
|
|
98
|
-
*/
|
|
99
|
-
export declare function consumeSurface<T>(options: SurfaceConsumerOptions<T>): Promise<T>;
|
|
100
|
-
/**
|
|
101
|
-
* Build a reusable consumer bound to a provider/env/app, still requiring a
|
|
102
|
-
* degraded handler per call. Per-call options override the bound base.
|
|
103
|
-
*/
|
|
104
|
-
export declare function createSurfaceConsumer(base: Pick<SurfaceConsumerOptions<unknown>, 'provider' | 'env' | 'appName' | 'telemetry'>): <T>(options: Omit<SurfaceConsumerOptions<T>, keyof typeof base> & Partial<Pick<SurfaceConsumerOptions<T>, keyof typeof base>>) => Promise<T>;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { ComponentType, ReactNode } from 'react';
|
|
2
|
-
export declare const DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY = "__modernDistributedSsrFragments";
|
|
3
|
-
export declare const DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY = "__modernDistributedSsrFragmentRequest";
|
|
4
|
-
export type DistributedSsrFragment = {
|
|
5
|
-
boundaryId: string;
|
|
6
|
-
buildMarker?: string;
|
|
7
|
-
digest?: string;
|
|
8
|
-
expose: string;
|
|
9
|
-
html: string;
|
|
10
|
-
remote: string;
|
|
11
|
-
status: 'ready';
|
|
12
|
-
};
|
|
13
|
-
export type DistributedSsrFragmentFailure = {
|
|
14
|
-
boundaryId: string;
|
|
15
|
-
expose: string;
|
|
16
|
-
reason: string;
|
|
17
|
-
remote: string;
|
|
18
|
-
status: 'degraded';
|
|
19
|
-
};
|
|
20
|
-
type DistributedSsrFragmentResult = DistributedSsrFragment | DistributedSsrFragmentFailure;
|
|
21
|
-
export type DistributedSsrFragmentContext = {
|
|
22
|
-
fragments?: Record<string, DistributedSsrFragment | DistributedSsrFragmentFailure>;
|
|
23
|
-
required: true;
|
|
24
|
-
resolve?: (remote: string, expose: string, props: Record<string, unknown>) => DistributedSsrFragmentResult | PromiseLike<DistributedSsrFragmentResult>;
|
|
25
|
-
};
|
|
26
|
-
export type DistributedSsrBoundaryProps<Props extends object = Record<string, unknown>> = {
|
|
27
|
-
children: ReactNode;
|
|
28
|
-
expose: string;
|
|
29
|
-
fallback: ReactNode;
|
|
30
|
-
fragmentProps?: Props;
|
|
31
|
-
remote: string;
|
|
32
|
-
};
|
|
33
|
-
export type CreateDistributedSsrComponentOptions<Props extends object> = {
|
|
34
|
-
createComponent: () => ComponentType<Props>;
|
|
35
|
-
expose: string;
|
|
36
|
-
fallback: ReactNode;
|
|
37
|
-
remote: string;
|
|
38
|
-
};
|
|
39
|
-
export declare function distributedSsrFragmentKey(remote: string, expose: string): string;
|
|
40
|
-
export declare function useDistributedSsrFragmentProps<Props extends object>({ boundaryId, expose, }: {
|
|
41
|
-
boundaryId: string;
|
|
42
|
-
expose: string;
|
|
43
|
-
}): Props;
|
|
44
|
-
/**
|
|
45
|
-
* Keeps the browser on the native Module Federation component while allowing
|
|
46
|
-
* servers that cannot execute remote code (notably workerd) to render a
|
|
47
|
-
* trusted fragment produced by the remote Worker itself.
|
|
48
|
-
*
|
|
49
|
-
* Node SSR has no distributed-fragment context and therefore renders the
|
|
50
|
-
* child normally, preserving Module Federation's in-process SSR path.
|
|
51
|
-
*/
|
|
52
|
-
export declare function DistributedSsrBoundary<Props extends object = Record<string, unknown>>({ children, expose, fallback, fragmentProps, remote, }: DistributedSsrBoundaryProps<Props>): import("react").JSX.Element;
|
|
53
|
-
/**
|
|
54
|
-
* Defers creation of the native Module Federation component until React
|
|
55
|
-
* actually renders that child. A workerd request with a verified distributed
|
|
56
|
-
* fragment never constructs the native remote, so its module cannot perform
|
|
57
|
-
* forbidden global-scope network I/O. Browser and Node rendering keep using
|
|
58
|
-
* the native Module Federation component unchanged.
|
|
59
|
-
*/
|
|
60
|
-
export declare function createDistributedSsrComponent<Props extends object>({ createComponent, expose, fallback, remote, }: CreateDistributedSsrComponentOptions<Props>): (props: Props) => import("react").JSX.Element;
|
|
61
|
-
export {};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
export * from './consume-surface.js';
|
|
2
|
-
export * from './distributed-ssr.js';
|
|
3
|
-
export { DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY, useDistributedSsrFragmentProps, } from './distributed-ssr.js';
|
|
4
|
-
export * from './last-known-good.js';
|
|
5
|
-
export * from './manifest-recovery-runtime-plugin.js';
|
|
6
|
-
export * from './surface-resolution-types.js';
|
|
7
|
-
export declare const MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT = "modernjs:mf-runtime-fallback";
|
|
8
|
-
export declare const MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT = "modernjs:mf-runtime-recovery";
|
|
9
|
-
export declare const DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = "/_modern/contract-gates/runtime-fallback";
|
|
10
|
-
export declare const DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER = "x-modernjs-runtime-signal-token";
|
|
11
|
-
export type ModuleFederationFallbackClassification = 'timeout' | 'network' | 'contract' | 'version-skew' | 'remote-unavailable';
|
|
12
|
-
export type ModuleFederationFallbackStatus = 'degraded' | 'failed' | 'recovered';
|
|
13
|
-
export type ModuleFederationFallbackTelemetryInput = {
|
|
14
|
-
appName: string;
|
|
15
|
-
classification: ModuleFederationFallbackClassification;
|
|
16
|
-
entry?: string;
|
|
17
|
-
error?: unknown;
|
|
18
|
-
eventName?: string;
|
|
19
|
-
exportName?: string;
|
|
20
|
-
metadata?: Record<string, unknown>;
|
|
21
|
-
phase: 'discovery' | 'load' | 'mount' | 'hydrate' | 'recover';
|
|
22
|
-
remote: string;
|
|
23
|
-
runtimeDigest?: string;
|
|
24
|
-
status?: ModuleFederationFallbackStatus;
|
|
25
|
-
};
|
|
26
|
-
export type ModuleFederationFallbackTelemetryPayload = {
|
|
27
|
-
appName: string;
|
|
28
|
-
entry?: string;
|
|
29
|
-
eventName: string;
|
|
30
|
-
phase: ModuleFederationFallbackTelemetryInput['phase'];
|
|
31
|
-
reason: ModuleFederationFallbackClassification;
|
|
32
|
-
runtimeDigest?: string;
|
|
33
|
-
schemaVersion: 1;
|
|
34
|
-
metadata: {
|
|
35
|
-
classification: ModuleFederationFallbackClassification;
|
|
36
|
-
errorMessage?: string;
|
|
37
|
-
errorName?: string;
|
|
38
|
-
exportName?: string;
|
|
39
|
-
remote: string;
|
|
40
|
-
runtimeDigest?: string;
|
|
41
|
-
status: ModuleFederationFallbackStatus;
|
|
42
|
-
} & Record<string, unknown>;
|
|
43
|
-
};
|
|
44
|
-
export type ModuleFederationFallbackTelemetryEmitOptions = {
|
|
45
|
-
authHeaderName?: string;
|
|
46
|
-
authToken?: string;
|
|
47
|
-
endpoint?: string;
|
|
48
|
-
fetchImpl?: typeof fetch;
|
|
49
|
-
postSignal?: boolean;
|
|
50
|
-
};
|
|
51
|
-
export type ModuleFederationFallbackTelemetryEmitResult = {
|
|
52
|
-
dispatched: boolean;
|
|
53
|
-
posted: boolean;
|
|
54
|
-
postStatus?: number;
|
|
55
|
-
};
|
|
56
|
-
export declare class ModuleFederationRemoteLoadTimeoutError extends Error {
|
|
57
|
-
constructor(remote: string, timeoutMs: number);
|
|
58
|
-
}
|
|
59
|
-
export declare class ModuleFederationRemoteLoadError extends Error {
|
|
60
|
-
readonly remote: string;
|
|
61
|
-
readonly attempts: number;
|
|
62
|
-
readonly causeError: Error;
|
|
63
|
-
constructor(remote: string, attempts: number, causeError: Error);
|
|
64
|
-
}
|
|
65
|
-
export declare class ModuleFederationRemoteComponentContractError extends Error {
|
|
66
|
-
constructor(remote: string, exportName: string);
|
|
67
|
-
}
|
|
68
|
-
export declare function classifyModuleFederationFallback(error: unknown): ModuleFederationFallbackClassification;
|
|
69
|
-
export declare function createModuleFederationFallbackTelemetry(input: ModuleFederationFallbackTelemetryInput): ModuleFederationFallbackTelemetryPayload;
|
|
70
|
-
export declare function toModuleFederationFallbackAttributes(payload: ModuleFederationFallbackTelemetryPayload): Record<string, string>;
|
|
71
|
-
export declare function emitModuleFederationFallbackTelemetry(input: ModuleFederationFallbackTelemetryInput, options?: ModuleFederationFallbackTelemetryEmitOptions): Promise<ModuleFederationFallbackTelemetryEmitResult>;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { type ResolvedDeliveryUnit, type SurfaceResolutionProvider } from './surface-resolution-types.js';
|
|
2
|
-
export declare const LAST_KNOWN_GOOD_PROVIDER_NAME = "last-known-good";
|
|
3
|
-
/** One cached complete record plus the time it was stored. */
|
|
4
|
-
export type LkgRecord = {
|
|
5
|
-
resolved: ResolvedDeliveryUnit;
|
|
6
|
-
storedAt: number;
|
|
7
|
-
/**
|
|
8
|
-
* External-major selector the record was resolved against. Participates in
|
|
9
|
-
* lookup validation — a cached record is only served for a matching major —
|
|
10
|
-
* but never in the storage key, which is (unitId, env) so all surfaces of a
|
|
11
|
-
* unit share one atomically-swapped record.
|
|
12
|
-
*/
|
|
13
|
-
major?: number;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Pluggable storage hook. The default is an in-memory Map; callers may supply a
|
|
17
|
-
* durable store (KV, disk, etc). Reads/writes may be async. A store only ever
|
|
18
|
-
* receives whole records.
|
|
19
|
-
*/
|
|
20
|
-
export type LkgStorage = {
|
|
21
|
-
read(key: string): (LkgRecord | undefined) | Promise<LkgRecord | undefined>;
|
|
22
|
-
write(key: string, record: LkgRecord): void | Promise<void>;
|
|
23
|
-
};
|
|
24
|
-
export type LkgFreshnessPolicy = {
|
|
25
|
-
/**
|
|
26
|
-
* Maximum age, in ms, a stored record may be served after a provider
|
|
27
|
-
* failure. When omitted, a served record never expires by age. A record
|
|
28
|
-
* older than this yields a typed `stale-record` discovery error.
|
|
29
|
-
*/
|
|
30
|
-
maxStaleMs?: number;
|
|
31
|
-
};
|
|
32
|
-
export type LastKnownGoodOptions = {
|
|
33
|
-
/** The wrapped provider (env/static, Zephyr, or any other). */
|
|
34
|
-
provider: SurfaceResolutionProvider;
|
|
35
|
-
/** Pluggable storage; defaults to a process-local in-memory Map. */
|
|
36
|
-
storage?: LkgStorage;
|
|
37
|
-
freshness?: LkgFreshnessPolicy;
|
|
38
|
-
/** Clock injection for deterministic freshness tests. */
|
|
39
|
-
now?: () => number;
|
|
40
|
-
};
|
|
41
|
-
/** Default process-local in-memory storage. */
|
|
42
|
-
export declare function createInMemoryLkgStorage(): LkgStorage;
|
|
43
|
-
/**
|
|
44
|
-
* Wrap a provider with a last-known-good cache. On success the whole record is
|
|
45
|
-
* cached (atomic swap). On provider failure (typed discovery error or a thrown
|
|
46
|
-
* error) the last complete record is served, marked degraded — unless it has
|
|
47
|
-
* expired per {@link LkgFreshnessPolicy}, in which case a typed `stale-record`
|
|
48
|
-
* error is returned. If there is no cached record, the original failure is
|
|
49
|
-
* passed through (a thrown error becomes a `provider-unavailable` discovery
|
|
50
|
-
* error).
|
|
51
|
-
*/
|
|
52
|
-
export declare function createLastKnownGoodProvider(options: LastKnownGoodOptions): SurfaceResolutionProvider;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
type ErrorLoadRemoteArgs = {
|
|
2
|
-
id?: string;
|
|
3
|
-
error?: unknown;
|
|
4
|
-
lifecycle?: string;
|
|
5
|
-
};
|
|
6
|
-
export type ModuleFederationManifestRecoveryPluginOptions = {
|
|
7
|
-
attempts?: number;
|
|
8
|
-
retryDelayMs?: number;
|
|
9
|
-
timeoutMs?: number;
|
|
10
|
-
fetchImpl?: typeof fetch;
|
|
11
|
-
waitImpl?: (milliseconds: number) => Promise<void>;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Gives server-side manifest loading a small, bounded recovery window.
|
|
15
|
-
*
|
|
16
|
-
* Returning `undefined` deliberately hands control back to Module Federation:
|
|
17
|
-
* its runtime preserves the original typed RUNTIME-003 error and invalidates
|
|
18
|
-
* the rejected manifest promise. Parsed manifests are returned without schema
|
|
19
|
-
* interpretation so runtime-core remains the authority for RUNTIME-013.
|
|
20
|
-
*/
|
|
21
|
-
export declare const createModuleFederationManifestRecoveryPlugin: (options?: ModuleFederationManifestRecoveryPluginOptions) => {
|
|
22
|
-
name: string;
|
|
23
|
-
errorLoadRemote(args: ErrorLoadRemoteArgs): Promise<unknown>;
|
|
24
|
-
};
|
|
25
|
-
export default createModuleFederationManifestRecoveryPlugin;
|