diff --git a/src/packageManagers.test.ts b/src/packageManagers.test.ts index 9e97032..4536c67 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 b395932..e87f9ee 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 0000000..e69de29 diff --git a/test/bun/index.ts b/test/bun/index.ts new file mode 100644 index 0000000..a330557 --- /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 0000000..478c7c8 --- /dev/null +++ b/test/bun/package.json @@ -0,0 +1,3 @@ +{ + "name": "wrangler-action-npm-test", +} diff --git a/test/bun/wrangler.toml b/test/bun/wrangler.toml new file mode 100644 index 0000000..4c09785 --- /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