diff --git a/.changeset/forty-poets-guess.md b/.changeset/forty-poets-guess.md new file mode 100644 index 00000000..9ebbb217 --- /dev/null +++ b/.changeset/forty-poets-guess.md @@ -0,0 +1,5 @@ +--- +"wrangler-action": minor +--- + +Added support for Bun as a package manager diff --git a/action.yml b/action.yml index 6974b315..657d76a9 100644 --- a/action.yml +++ b/action.yml @@ -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." required: false 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 default: npm diff --git a/src/packageManagers.test.ts b/src/packageManagers.test.ts index 9e970323..4536c67a 100644 --- a/src/packageManagers.test.ts +++ b/src/packageManagers.test.ts @@ -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(` diff --git a/src/packageManagers.ts b/src/packageManagers.ts index b3959329..e87f9eec 100644 --- a/src/packageManagers.ts +++ b/src/packageManagers.ts @@ -19,6 +19,10 @@ const PACKAGE_MANAGERS = { install: "pnpm add", exec: "pnpm exec", }, + bun: { + install: "bun i", + exec: "bunx" + }, } as const satisfies Readonly>; 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; } diff --git a/test/bun/bun.lockb b/test/bun/bun.lockb new file mode 100755 index 00000000..e69de29b diff --git a/test/bun/index.ts b/test/bun/index.ts new file mode 100644 index 00000000..a3305575 --- /dev/null +++ b/test/bun/index.ts @@ -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), + }); + }, +}; diff --git a/test/bun/package.json b/test/bun/package.json new file mode 100644 index 00000000..75d5eebd --- /dev/null +++ b/test/bun/package.json @@ -0,0 +1,3 @@ +{ + "name": "wrangler-action-bun-test", +} diff --git a/test/bun/wrangler.toml b/test/bun/wrangler.toml new file mode 100644 index 00000000..4c09785b --- /dev/null +++ b/test/bun/wrangler.toml @@ -0,0 +1,4 @@ +name = "wrangler-action-test" +main = "./index.ts" +compatibility_date = "2023-07-07" +workers_dev = true