Skip to content

Commit 24f0c5f

Browse files
committed
add bun as a supported package manager
1 parent 3a663a1 commit 24f0c5f

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ui-debug.log
1818
test_output.log
1919
scripts/emulator-tests/functions/index.js
2020
yarn.lock
21+
bun.lock
2122
.npmrc
2223

2324
.DS_Store

src/emulator/apphosting/developmentServer.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,16 @@ describe("utils", () => {
5151

5252
expect(await detectPackageManager("./")).to.equal("yarn");
5353
});
54+
55+
it("returns bun if bun.lock file fond", async () => {
56+
pathExistsStub.callsFake((...args) => {
57+
if (args[0] === "bun.lock") {
58+
return true;
59+
}
60+
61+
return false;
62+
});
63+
64+
expect(await detectPackageManager("./")).to.equal("bun");
65+
});
5466
});

src/emulator/apphosting/developmentServer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const logger = EmulatorLogger.forEmulator(Emulators.APPHOSTING);
99
/**
1010
* Supported package managers. This mirrors production.
1111
*/
12-
export type PackageManager = "npm" | "yarn" | "pnpm";
12+
export type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
1313

1414
/**
1515
* Returns the package manager used by the project
@@ -21,6 +21,10 @@ export async function detectPackageManager(rootdir: string): Promise<PackageMana
2121
return "pnpm";
2222
}
2323

24+
if (await pathExists(join(rootdir, "bun.lock"))) {
25+
return "bun";
26+
}
27+
2428
if (await pathExists(join(rootdir, "yarn.lock"))) {
2529
return "yarn";
2630
}

src/frameworks/compose/discover/runtime/node.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ describe("NodejsRuntime", () => {
5454

5555
expect(actual).to.equal(expected);
5656
});
57+
58+
it("should return bun package manager", async () => {
59+
const fileSystem = new MockFileSystem({
60+
"bun.lock": "It is test file",
61+
});
62+
const actual = await nodeJSRuntime.getPackageManager(fileSystem);
63+
const expected = "bun";
64+
65+
expect(actual).to.equal(expected);
66+
});
5767
});
5868

5969
describe("getDependencies", () => {

src/frameworks/compose/discover/runtime/node.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface PackageJSON {
1414
scripts?: Record<string, string>;
1515
engines?: Record<string, string>;
1616
}
17-
type PackageManager = "npm" | "yarn";
17+
type PackageManager = "npm" | "yarn" | "bun";
1818

1919
const supportedNodeVersions: string[] = ["18"];
2020
const NODE_RUNTIME_ID = "nodejs";
@@ -61,6 +61,9 @@ export class NodejsRuntime implements Runtime {
6161
if (await fs.exists(YARN_LOCK)) {
6262
return "yarn";
6363
}
64+
if (await fs.exists("bun.lock")) {
65+
return "bun";
66+
}
6467

6568
return "npm";
6669
} catch (error: any) {
@@ -78,6 +81,9 @@ export class NodejsRuntime implements Runtime {
7881
if (packageManager === "yarn") {
7982
packages.push("yarn");
8083
}
84+
if (packageManager === "bun") {
85+
packages.push("bun");
86+
}
8187
if (!packages.length) {
8288
return undefined;
8389
}
@@ -91,6 +97,9 @@ export class NodejsRuntime implements Runtime {
9197
if (packageManager === "yarn") {
9298
installCmd = "yarn install";
9399
}
100+
if (packageManager === "bun") {
101+
installCmd = "bun install";
102+
}
94103

95104
return installCmd;
96105
}
@@ -116,6 +125,9 @@ export class NodejsRuntime implements Runtime {
116125
if (packageManager === "npm" || packageManager === "yarn") {
117126
command.cmd = "npx " + command.cmd;
118127
}
128+
if (packageManager === "bun") {
129+
command.cmd = "bun x " + command.cmd;
130+
}
119131

120132
return command;
121133
}

0 commit comments

Comments
 (0)