diff --git a/packages/std/core/recipes/attach_resources.bri b/packages/std/core/recipes/attach_resources.bri new file mode 100644 index 0000000..551da61 --- /dev/null +++ b/packages/std/core/recipes/attach_resources.bri @@ -0,0 +1,28 @@ +import { BRIOCHE_VERSION } from "../runtime.bri"; +import { semverMatches } from "../semver.bri"; +import { assert } from "../utils.bri"; +import { type AsyncRecipe, type Recipe, createRecipe } from "./recipe.bri"; +import type { Directory } from "./directory.bri"; + +/** + * Attach resources to the files within a recipe by searching within + * directories named `brioche-resources.d`. This is useful when unarchiving + * a recipe that was archived using `collectReferences`. + */ +export function attachResources( + recipe: AsyncRecipe, +): Recipe { + return createRecipe(["directory"], { + sourceDepth: 1, + briocheSerialize: async (meta) => { + assert(semverMatches(BRIOCHE_VERSION, ">=0.1.4")); + + const serializedRecipe = await (await recipe).briocheSerialize(); + return { + meta, + type: "attach_resources", + recipe: serializedRecipe, + }; + }, + }); +} diff --git a/packages/std/core/recipes/index.bri b/packages/std/core/recipes/index.bri index 1727df3..afedea6 100644 --- a/packages/std/core/recipes/index.bri +++ b/packages/std/core/recipes/index.bri @@ -21,6 +21,7 @@ export { memo, createProxy } from "./proxy.bri"; export { symlink, type SymlinkOptions, Symlink } from "./symlink.bri"; export { sync } from "./sync.bri"; export { collectReferences } from "./collect_references.bri"; +export { attachResources } from "./attach_resources.bri"; export { glob } from "./glob.bri"; export { type AsyncRecipe, diff --git a/packages/std/core/recipes/recipe.bri b/packages/std/core/recipes/recipe.bri index 039f130..93c66c1 100644 --- a/packages/std/core/recipes/recipe.bri +++ b/packages/std/core/recipes/recipe.bri @@ -48,6 +48,7 @@ export type RecipeSerialization = runtime.WithMeta & | runtime.InsertRecipe | runtime.GlobRecipe | runtime.CollectReferencesRecipe + | runtime.AttachResourcesRecipe | runtime.ProxyRecipe | runtime.SyncRecipe : T extends Symlink diff --git a/packages/std/core/runtime.bri b/packages/std/core/runtime.bri index 3aac00d..86f1467 100644 --- a/packages/std/core/runtime.bri +++ b/packages/std/core/runtime.bri @@ -107,6 +107,7 @@ export type Recipe = | GlobRecipe | SetPermissionsRecipe | CollectReferencesRecipe + | AttachResourcesRecipe | ProxyRecipe | SyncRecipe; @@ -195,6 +196,11 @@ export type CollectReferencesRecipe = WithMeta & { recipe: Recipe; }; +export type AttachResourcesRecipe = WithMeta & { + type: "attach_resources"; + recipe: Recipe; +}; + export type ProxyRecipe = WithMeta & { type: "proxy"; recipe: RecipeHash;