mirror of
https://github.com/cloudflare/wrangler-action.git
synced 2024-11-25 11:24:46 +01:00
Merge pull request #188 from simpleauthority/feat/add-bun-support
Add bun support
This commit is contained in:
commit
032a7248fa
8 changed files with 64 additions and 1 deletions
5
.changeset/forty-poets-guess.md
Normal file
5
.changeset/forty-poets-guess.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"wrangler-action": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Added support for Bun as a package manager
|
|
@ -42,6 +42,6 @@ inputs:
|
||||||
description: "A string of environment variable names, separated by newlines. These will be bound to your Worker using the values of matching environment variables declared in `env` of this workflow."
|
description: "A string of environment variable names, separated by newlines. These will be bound to your Worker using the values of matching environment variables declared in `env` of this workflow."
|
||||||
required: false
|
required: false
|
||||||
packageManager:
|
packageManager:
|
||||||
description: "The package manager you'd like to use to install and run wrangler. If not specified, a value will be inferred based on the presence of a lockfile. Valid values: [npm, pnpm, yarn]"
|
description: "The package manager you'd like to use to install and run wrangler. If not specified, a value will be inferred based on the presence of a lockfile. Valid values: [npm, pnpm, yarn, bun]"
|
||||||
required: false
|
required: false
|
||||||
default: npm
|
default: npm
|
||||||
|
|
|
@ -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-bun-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