add bun support

This commit is contained in:
Jacob Andersen 2023-10-07 02:25:35 -07:00
parent 556068fb59
commit 779191a652
No known key found for this signature in database
GPG key ID: D5677A2921F8E4BA
6 changed files with 58 additions and 0 deletions

View file

@ -26,6 +26,14 @@ describe("getPackageManager", () => {
"install": "pnpm add",
}
`);
expect(getPackageManager('bun', { workingDirectory: "test/bun" }))
.toMatchInlineSnapshot(`
{
"exec": "bunx",
"install": "bun i",
}
`);
});
test("should use npm if no value provided and package-lock.json exists", () => {
@ -58,6 +66,16 @@ describe("getPackageManager", () => {
`);
});
test("should use bun if no value provided and bun.lockb exists", () => {
expect(getPackageManager("", { workingDirectory: "test/bun" }))
.toMatchInlineSnapshot(`
{
"exec": "bunx",
"install": "bun i",
}
`);
});
test("should use npm if no value provided and no lockfile is present", () => {
expect(getPackageManager("", { workingDirectory: "test/empty" }))
.toMatchInlineSnapshot(`

View file

@ -19,6 +19,10 @@ const PACKAGE_MANAGERS = {
install: "pnpm add",
exec: "pnpm exec",
},
bun: {
install: "bun i",
exec: "bunx"
},
} as const satisfies Readonly<Record<string, PackageManager>>;
type PackageManagerValue = keyof typeof PACKAGE_MANAGERS;
@ -35,6 +39,9 @@ function detectPackageManager(
if (existsSync(path.join(workingDirectory, "pnpm-lock.yaml"))) {
return "pnpm";
}
if (existsSync(path.join(workingDirectory, "bun.lockb"))) {
return "bun";
}
return null;
}

0
test/bun/bun.lockb Executable file
View file

26
test/bun/index.ts Normal file
View file

@ -0,0 +1,26 @@
type Env = {
SECRET1?: string;
SECRET2?: string;
};
export default {
fetch(request: Request, env: Env) {
const url = new URL(request.url);
if (url.pathname === "/secret-health-check") {
const { SECRET1, SECRET2 } = env;
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
throw new Error("SECRET1 or SECRET2 is not defined");
}
return new Response("OK");
}
// @ts-expect-error
return Response.json({
...request,
headers: Object.fromEntries(request.headers),
});
},
};

3
test/bun/package.json Normal file
View file

@ -0,0 +1,3 @@
{
"name": "wrangler-action-npm-test",
}

4
test/bun/wrangler.toml Normal file
View file

@ -0,0 +1,4 @@
name = "wrangler-action-test"
main = "./index.ts"
compatibility_date = "2023-07-07"
workers_dev = true