refactor: 리펙토링
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { resolveRuntimeCapabilities } from "../contracts/runtime-capabilities.ts";
|
||||
import { INSTALLED_RUNTIME_CAPABILITIES } from "../features/installed-runtime-capabilities.ts";
|
||||
import { createCompositionRoot } from "./composition-root.ts";
|
||||
import { loadReleaseManifest } from "./load-release-manifest.ts";
|
||||
import { loadRuntimeConfig } from "./load-runtime-config.ts";
|
||||
import {
|
||||
createOptionalRuntimeHost,
|
||||
type OptionalRuntimeHost,
|
||||
} from "./optional-runtime-host.ts";
|
||||
import { createRuntimeAdapters } from "./runtime-adapters.ts";
|
||||
|
||||
export type RuntimeCompositionDependencies = Readonly<{
|
||||
@@ -8,10 +14,16 @@ export type RuntimeCompositionDependencies = Readonly<{
|
||||
host?: Record<string, unknown>;
|
||||
}>;
|
||||
|
||||
export function createRuntimeComposition(
|
||||
/**
|
||||
* §6.7 steps 7 and 14. The static capability selection is compiled against the
|
||||
* runtime overrides, and the optional host objects are created without any
|
||||
* start side effect. Nothing observable happens until the first committed React
|
||||
* effect calls `optional.startAfterMount()`.
|
||||
*/
|
||||
export async function createRuntimeComposition(
|
||||
dependencies: RuntimeCompositionDependencies = {},
|
||||
) {
|
||||
return createCompositionRoot({
|
||||
const root = await createCompositionRoot({
|
||||
loadConfig: () => loadRuntimeConfig({ fetcher: dependencies.fetcher }),
|
||||
loadRelease: (runtime) =>
|
||||
loadReleaseManifest(runtime, { fetcher: dependencies.fetcher }),
|
||||
@@ -23,6 +35,36 @@ export function createRuntimeComposition(
|
||||
host: dependencies.host,
|
||||
}),
|
||||
});
|
||||
|
||||
const capabilities = resolveRuntimeCapabilities(
|
||||
INSTALLED_RUNTIME_CAPABILITIES,
|
||||
root.config.config.CAPABILITY_OVERRIDES,
|
||||
);
|
||||
const optional: OptionalRuntimeHost = createOptionalRuntimeHost({
|
||||
capabilities,
|
||||
routerBasePath: root.config.build.routerBasePath,
|
||||
buildId: root.release.buildId,
|
||||
...(dependencies.host
|
||||
? {
|
||||
host: dependencies.host as Parameters<
|
||||
typeof createOptionalRuntimeHost
|
||||
>[0]["host"],
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
|
||||
return Object.freeze({
|
||||
...root,
|
||||
capabilities,
|
||||
optional,
|
||||
async dispose(): Promise<void> {
|
||||
// §20.3. Optional runtime first, then the base infrastructure: the query
|
||||
// cache is cleared only after realtime and worker admission has closed,
|
||||
// so a late effect cannot repopulate a cleared cache.
|
||||
await optional.stop("APPLICATION_SHUTDOWN");
|
||||
root.infrastructure.dispose();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export type RuntimeComposition = Awaited<
|
||||
|
||||
Reference in New Issue
Block a user