Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[std] Add std.attachResources() recipe #146

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/std/core/recipes/attach_resources.bri
Original file line number Diff line number Diff line change
@@ -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<Directory>,
): Recipe<Directory> {
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,
};
},
});
}
1 change: 1 addition & 0 deletions packages/std/core/recipes/index.bri
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/std/core/recipes/recipe.bri
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type RecipeSerialization<T extends Artifact> = runtime.WithMeta &
| runtime.InsertRecipe
| runtime.GlobRecipe
| runtime.CollectReferencesRecipe
| runtime.AttachResourcesRecipe
| runtime.ProxyRecipe
| runtime.SyncRecipe
: T extends Symlink
Expand Down
6 changes: 6 additions & 0 deletions packages/std/core/runtime.bri
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export type Recipe =
| GlobRecipe
| SetPermissionsRecipe
| CollectReferencesRecipe
| AttachResourcesRecipe
| ProxyRecipe
| SyncRecipe;

Expand Down Expand Up @@ -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;
Expand Down