Skip to content

Commit 2b3d6e4

Browse files
authored
Prepare generic runtime overlay packs (#1234)
1 parent ef6226c commit 2b3d6e4

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

packages/cli/src/recipe-sources.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,17 +501,45 @@ export async function prepareRecipeRuntimeOverlays(recipe: WorkspaceRecipe, reci
501501
if (!descriptor) {
502502
throw new Error(`Unsupported runtime overlay: ${overlay.kind}/${overlay.library}/${overlay.strategy}`)
503503
}
504-
if (!descriptor.prepare) {
505-
throw new Error(`Runtime overlay descriptor has no CLI preparer: ${overlay.kind}/${overlay.library}/${overlay.strategy}`)
506-
}
507504

508-
const prepared = await descriptor.prepare(overlay, recipeDirectory, index)
505+
const prepared = descriptor.prepare
506+
? await descriptor.prepare(overlay, recipeDirectory, index)
507+
: await prepareDeclaredRuntimeOverlayPack(overlay, recipeDirectory, index, descriptor.defaultTarget)
509508
overlays.push(prepared)
510509
}
511510

512511
return overlays
513512
}
514513

514+
async function prepareDeclaredRuntimeOverlayPack(overlay: WorkspaceRecipeRuntimeOverlay, recipeDirectory: string, index: number, defaultTarget: string): Promise<PreparedRuntimeOverlay> {
515+
const source = resolve(recipeDirectory, overlay.source)
516+
await validateExistingDirectoryForOverlay(source, overlay.source)
517+
const target = overlay.target ?? defaultTarget
518+
const digest = await directoryContentDigest(source)
519+
520+
return {
521+
source,
522+
target,
523+
type: "directory",
524+
mode: "readonly",
525+
cleanupPaths: [],
526+
metadata: {
527+
kind: "runtime-overlay",
528+
index,
529+
overlayKind: overlay.kind,
530+
library: overlay.library,
531+
strategy: overlay.strategy,
532+
source: overlay.source,
533+
target,
534+
preparedPath: source,
535+
preparedPathKind: "local",
536+
digest: { sha256: digest },
537+
...(overlay.bundle ? { bundle: overlay.bundle } : {}),
538+
...(overlay.metadata ? { userMetadata: overlay.metadata } : {}),
539+
},
540+
}
541+
}
542+
515543
async function preparePhpAiClientOverlay(overlay: WorkspaceRecipeRuntimeOverlay, recipeDirectory: string, index: number): Promise<PreparedRuntimeOverlay> {
516544
const source = resolve(recipeDirectory, overlay.source)
517545
await validateExistingDirectoryForOverlay(source, overlay.source)

tests/runtime-overlay-descriptors.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { mkdir, writeFile } from "node:fs/promises"
33
import { join } from "node:path"
44

55
import { parseWorkspaceRecipeJson, validateWorkspaceRecipeShape } from "../packages/cli/src/recipe-validation.js"
6+
import { prepareRecipeRuntimeOverlays } from "../packages/cli/src/recipe-sources.js"
67
import { loadConfiguredRuntimeOverlayDescriptors, registeredRuntimeOverlayDescriptors, runtimeOverlayDescriptor } from "../packages/cli/src/runtime-overlay-registry.js"
78
import { discoverRuntimeOverlayDescriptorManifests, runtimeOverlayDescriptorManifest } from "../packages/runtime-core/src/index.js"
89
import { withTempDir } from "../scripts/test-kit.js"
@@ -31,12 +32,21 @@ await withTempDir("wp-codebox-runtime-overlay-descriptors-", async (root) => {
3132
loadConfiguredRuntimeOverlayDescriptors(descriptorDirectory)
3233
assert.ok(registeredRuntimeOverlayDescriptors().some((descriptor) => descriptor.library === "example-provider"))
3334

35+
await mkdir(join(root, "overlays", "example"), { recursive: true })
36+
await writeFile(join(root, "overlays", "example", "runtime.php"), "<?php\n")
37+
3438
const recipe = parseWorkspaceRecipeJson(JSON.stringify({
3539
schema: "wp-codebox/workspace-recipe/v1",
3640
runtime: { overlays: [{ kind: "provider-runtime", library: "example-provider", strategy: "provider-owned-bundle", source: "overlays/example" }] },
3741
workflow: { steps: [{ command: "noop" }] },
3842
}))
3943
validateWorkspaceRecipeShape(recipe, join(root, "recipe.json"))
44+
const [prepared] = await prepareRecipeRuntimeOverlays(recipe, root)
45+
assert.equal(prepared.source, join(root, "overlays", "example"))
46+
assert.equal(prepared.target, "/wordpress/wp-content/mu-plugins/example-provider-runtime")
47+
assert.equal(prepared.mode, "readonly")
48+
assert.equal(prepared.metadata.preparedPathKind, "local")
49+
assert.equal(typeof (prepared.metadata.digest as { sha256?: unknown }).sha256, "string")
4050

4151
await writeFile(join(descriptorDirectory, "wp-codebox-runtime-overlays.json"), JSON.stringify({
4252
schema: "wp-codebox/runtime-overlay-descriptors/v1",

0 commit comments

Comments
 (0)