mirror of
https://github.com/cloudflare/wrangler-action.git
synced 2024-11-24 19:04:46 +01:00
add bun support
This commit is contained in:
parent
556068fb59
commit
779191a652
6 changed files with 58 additions and 0 deletions
|
@ -26,6 +26,14 @@ describe("getPackageManager", () => {
|
||||||
"install": "pnpm add",
|
"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", () => {
|
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", () => {
|
test("should use npm if no value provided and no lockfile is present", () => {
|
||||||
expect(getPackageManager("", { workingDirectory: "test/empty" }))
|
expect(getPackageManager("", { workingDirectory: "test/empty" }))
|
||||||
.toMatchInlineSnapshot(`
|
.toMatchInlineSnapshot(`
|
||||||
|
|
|
@ -19,6 +19,10 @@ const PACKAGE_MANAGERS = {
|
||||||
install: "pnpm add",
|
install: "pnpm add",
|
||||||
exec: "pnpm exec",
|
exec: "pnpm exec",
|
||||||
},
|
},
|
||||||
|
bun: {
|
||||||
|
install: "bun i",
|
||||||
|
exec: "bunx"
|
||||||
|
},
|
||||||
} as const satisfies Readonly<Record<string, PackageManager>>;
|
} as const satisfies Readonly<Record<string, PackageManager>>;
|
||||||
|
|
||||||
type PackageManagerValue = keyof typeof PACKAGE_MANAGERS;
|
type PackageManagerValue = keyof typeof PACKAGE_MANAGERS;
|
||||||
|
@ -35,6 +39,9 @@ function detectPackageManager(
|
||||||
if (existsSync(path.join(workingDirectory, "pnpm-lock.yaml"))) {
|
if (existsSync(path.join(workingDirectory, "pnpm-lock.yaml"))) {
|
||||||
return "pnpm";
|
return "pnpm";
|
||||||
}
|
}
|
||||||
|
if (existsSync(path.join(workingDirectory, "bun.lockb"))) {
|
||||||
|
return "bun";
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
0
test/bun/bun.lockb
Executable file
0
test/bun/bun.lockb
Executable file
26
test/bun/index.ts
Normal file
26
test/bun/index.ts
Normal 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
3
test/bun/package.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"name": "wrangler-action-npm-test",
|
||||||
|
}
|
4
test/bun/wrangler.toml
Normal file
4
test/bun/wrangler.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
name = "wrangler-action-test"
|
||||||
|
main = "./index.ts"
|
||||||
|
compatibility_date = "2023-07-07"
|
||||||
|
workers_dev = true
|
Loading…
Reference in a new issue