diff --git a/.gitignore b/.gitignore index 9857f71603c..0d809f401b4 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ ui-debug.log test_output.log scripts/emulator-tests/functions/index.js yarn.lock +bun.lock .npmrc .DS_Store diff --git a/src/emulator/apphosting/developmentServer.spec.ts b/src/emulator/apphosting/developmentServer.spec.ts index 215731f0e33..452f1fcae0b 100644 --- a/src/emulator/apphosting/developmentServer.spec.ts +++ b/src/emulator/apphosting/developmentServer.spec.ts @@ -51,4 +51,16 @@ describe("utils", () => { expect(await detectPackageManager("./")).to.equal("yarn"); }); + + it("returns bun if bun.lock file fond", async () => { + pathExistsStub.callsFake((...args) => { + if (args[0] === "bun.lock") { + return true; + } + + return false; + }); + + expect(await detectPackageManager("./")).to.equal("bun"); + }); }); diff --git a/src/emulator/apphosting/developmentServer.ts b/src/emulator/apphosting/developmentServer.ts index 71a1a1c9714..74624bbf67d 100644 --- a/src/emulator/apphosting/developmentServer.ts +++ b/src/emulator/apphosting/developmentServer.ts @@ -9,7 +9,7 @@ export const logger = EmulatorLogger.forEmulator(Emulators.APPHOSTING); /** * Supported package managers. This mirrors production. */ -export type PackageManager = "npm" | "yarn" | "pnpm"; +export type PackageManager = "npm" | "yarn" | "pnpm" | "bun"; /** * Returns the package manager used by the project @@ -21,6 +21,10 @@ export async function detectPackageManager(rootdir: string): Promise { expect(actual).to.equal(expected); }); + + it("should return bun package manager", async () => { + const fileSystem = new MockFileSystem({ + "bun.lock": "It is test file", + }); + const actual = await nodeJSRuntime.getPackageManager(fileSystem); + const expected = "bun"; + + expect(actual).to.equal(expected); + }); }); describe("getDependencies", () => { diff --git a/src/frameworks/compose/discover/runtime/node.ts b/src/frameworks/compose/discover/runtime/node.ts index 780ca2cb227..1a5dc313680 100644 --- a/src/frameworks/compose/discover/runtime/node.ts +++ b/src/frameworks/compose/discover/runtime/node.ts @@ -14,7 +14,7 @@ export interface PackageJSON { scripts?: Record; engines?: Record; } -type PackageManager = "npm" | "yarn"; +type PackageManager = "npm" | "yarn" | "bun"; const supportedNodeVersions: string[] = ["18"]; const NODE_RUNTIME_ID = "nodejs"; @@ -61,6 +61,9 @@ export class NodejsRuntime implements Runtime { if (await fs.exists(YARN_LOCK)) { return "yarn"; } + if (await fs.exists("bun.lock")) { + return "bun"; + } return "npm"; } catch (error: any) { @@ -78,6 +81,9 @@ export class NodejsRuntime implements Runtime { if (packageManager === "yarn") { packages.push("yarn"); } + if (packageManager === "bun") { + packages.push("bun"); + } if (!packages.length) { return undefined; } @@ -91,6 +97,9 @@ export class NodejsRuntime implements Runtime { if (packageManager === "yarn") { installCmd = "yarn install"; } + if (packageManager === "bun") { + installCmd = "bun install"; + } return installCmd; } @@ -116,6 +125,9 @@ export class NodejsRuntime implements Runtime { if (packageManager === "npm" || packageManager === "yarn") { command.cmd = "npx " + command.cmd; } + if (packageManager === "bun") { + command.cmd = "bun x " + command.cmd; + } return command; }