Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ui-debug.log
test_output.log
scripts/emulator-tests/functions/index.js
yarn.lock
bun.lock
.npmrc

.DS_Store
Expand Down
12 changes: 12 additions & 0 deletions src/emulator/apphosting/developmentServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
6 changes: 5 additions & 1 deletion src/emulator/apphosting/developmentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,6 +21,10 @@ export async function detectPackageManager(rootdir: string): Promise<PackageMana
return "pnpm";
}

if (await pathExists(join(rootdir, "bun.lock"))) {
return "bun";
}

if (await pathExists(join(rootdir, "yarn.lock"))) {
return "yarn";
}
Expand Down
10 changes: 10 additions & 0 deletions src/frameworks/compose/discover/runtime/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ describe("NodejsRuntime", () => {

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", () => {
Expand Down
14 changes: 13 additions & 1 deletion src/frameworks/compose/discover/runtime/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface PackageJSON {
scripts?: Record<string, string>;
engines?: Record<string, string>;
}
type PackageManager = "npm" | "yarn";
type PackageManager = "npm" | "yarn" | "bun";

const supportedNodeVersions: string[] = ["18"];
const NODE_RUNTIME_ID = "nodejs";
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -91,6 +97,9 @@ export class NodejsRuntime implements Runtime {
if (packageManager === "yarn") {
installCmd = "yarn install";
}
if (packageManager === "bun") {
installCmd = "bun install";
}

return installCmd;
}
Expand All @@ -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;
}
Expand Down