mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
* Add support for `build.module` in `Bun.plugin` * Another test * Update docs * Update isBuiltinModule.cpp --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
39 lines
920 B
TypeScript
39 lines
920 B
TypeScript
import { plugin } from "bun";
|
|
plugin({
|
|
name: "i am virtual!",
|
|
setup(builder) {
|
|
builder.module("my-virtual-module-async", async () => {
|
|
// check
|
|
await Bun.sleep(1);
|
|
return {
|
|
exports: {
|
|
hello: "world",
|
|
},
|
|
loader: "object",
|
|
};
|
|
});
|
|
|
|
builder.module("my-virtual-module-sync", () => {
|
|
return {
|
|
exports: {
|
|
hello: "world",
|
|
},
|
|
loader: "object",
|
|
};
|
|
});
|
|
|
|
builder.onLoad({ filter: /.*/, namespace: "rejected-promise" }, async ({ path }) => {
|
|
throw new Error("Rejected Promise");
|
|
});
|
|
|
|
builder.onResolve({ filter: /.*/, namespace: "rejected-promise2" }, ({ path }) => ({
|
|
namespace: "rejected-promise2",
|
|
path,
|
|
}));
|
|
|
|
builder.onLoad({ filter: /.*/, namespace: "rejected-promise2" }, ({ path }) => {
|
|
return Promise.reject(new Error("Rejected Promise"));
|
|
});
|
|
},
|
|
});
|