refactor(cli): discover app startup rows from injection
This commit is contained in:
@@ -39,7 +39,6 @@ export {
|
||||
PROFILES_DIR,
|
||||
readProfileManifest,
|
||||
resolveBundleDir,
|
||||
resolveEntrypoints,
|
||||
resolveProfileDir,
|
||||
writeProfileManifest,
|
||||
type DshBundleManifest,
|
||||
@@ -532,10 +531,10 @@ export async function mountRootInclude(
|
||||
* Re-apply the root include's patch list on a booted tree, and wait for the
|
||||
* result to settle.
|
||||
*
|
||||
* This is how a boot mounts its composition in phases: an app's entrypoint row
|
||||
* This is how a boot mounts its composition in phases: an app's startup row
|
||||
* resolves what the rest of the tree reads (`!!js ctx.get('webStartup')?.port`),
|
||||
* and a row's config expressions are evaluated when the include applies them —
|
||||
* so the rest of the composition must be applied after the entrypoints are
|
||||
* so the rest of the composition must be applied after the startup rows are
|
||||
* active, not before.
|
||||
* @param ctx - the booted context whose root include to re-apply.
|
||||
* @param patches - the full patch list for this generation.
|
||||
@@ -545,7 +544,7 @@ export async function mountRootInclude(
|
||||
export async function applyRootPatches(ctx: Context, patches: readonly PatchOptions[]): Promise<void> {
|
||||
const entry = bootstrapIncludes.get(ctx)
|
||||
if (entry === undefined) throw new Error('dsh: applying root patches requires the root Include entry')
|
||||
// A surface can dispose the whole tree while an entrypoint is still parsing
|
||||
// A surface can dispose the whole tree while a startup row is still parsing
|
||||
// (`--help`, or an early SIGTERM); there is then nothing left to mount.
|
||||
if (ctx.get('loader') === undefined) return
|
||||
const { patches: _previous, ...includeConfig } = entry.options.config as Include.Config
|
||||
|
||||
@@ -42,16 +42,6 @@ export const PROFILE_PATCH_FILENAME = 'cordis.patch.yml'
|
||||
export interface DshBundleManifest {
|
||||
/** The patch layer this bundle exports, relative to its package root. */
|
||||
patch: string
|
||||
/**
|
||||
* Id of the row in that patch which must run before every other row of the
|
||||
* composition — the app's entrypoint.
|
||||
*
|
||||
* An entrypoint resolves what the rest of the tree needs in order to be
|
||||
* configured at all (the command line an app was invoked with), and provides
|
||||
* it as a service. The boot mounts entrypoints alone first, so by the time
|
||||
* any other row's config is resolved, `ctx.get('<service>')` answers.
|
||||
*/
|
||||
entrypoint?: string
|
||||
}
|
||||
|
||||
/** The profile half of the `dsh` manifest section: what a profile directory composes. */
|
||||
@@ -89,37 +79,6 @@ export interface ProfileLayer {
|
||||
patchPath: string
|
||||
/** The parsed patch list. */
|
||||
patches: PatchOptions[]
|
||||
/** Row id this bundle declares as its entrypoint, when it has one. */
|
||||
entrypoint?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* The composition's entrypoint row ids, in bundle order.
|
||||
* @param binName - the diagnostic prefix on the thrown error.
|
||||
* @param profile - the loaded profile.
|
||||
* @param rows - the composed rows, so an entrypoint a later layer removed or
|
||||
* disabled is not mounted (the one-shot bundle takes over the web one this way).
|
||||
* @returns the row ids to mount before the rest of the tree.
|
||||
* @throws when a bundle declares an entrypoint its own patch never inserts.
|
||||
*/
|
||||
export function resolveEntrypoints(
|
||||
binName: string,
|
||||
profile: Profile,
|
||||
rows: readonly { id?: string; disabled?: boolean | null }[],
|
||||
): string[] {
|
||||
const entrypoints: string[] = []
|
||||
for (const layer of profile.layers) {
|
||||
if (layer.entrypoint === undefined) continue
|
||||
const row = rows.find(candidate => candidate.id === layer.entrypoint)
|
||||
if (row === undefined) {
|
||||
throw new Error(
|
||||
`${binName}: bundle ${JSON.stringify(layer.packageName)} declares entrypoint ${JSON.stringify(layer.entrypoint)}, `
|
||||
+ 'which the composed tree has no row for',
|
||||
)
|
||||
}
|
||||
if (row.disabled !== true) entrypoints.push(layer.entrypoint)
|
||||
}
|
||||
return entrypoints
|
||||
}
|
||||
|
||||
/** A loaded profile: resolved bundle layers plus the user's own patch layer. */
|
||||
@@ -432,14 +391,7 @@ export function loadProfile(
|
||||
throw new Error(`${binName}: profile bundle ${JSON.stringify(packageName)} declares no dsh.bundle in its package.json`)
|
||||
}
|
||||
const patchPath = join(packageDir, declared)
|
||||
const entrypoint = bundleManifest.dsh?.bundle?.entrypoint
|
||||
return {
|
||||
packageName,
|
||||
packageDir,
|
||||
patchPath,
|
||||
patches: loadOverlayPatches(binName, patchPath),
|
||||
...entrypoint === undefined ? {} : { entrypoint },
|
||||
}
|
||||
return { packageName, packageDir, patchPath, patches: loadOverlayPatches(binName, patchPath) }
|
||||
})
|
||||
const patchPath = join(dir, PROFILE_PATCH_FILENAME)
|
||||
const patches = options.userLayer !== false && existsSync(patchPath)
|
||||
|
||||
Reference in New Issue
Block a user