Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bun support. #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum PackageManager {
NPM = "npm",
Yarn = "yarn",
PNPM = "pnpm",
Bun = "bun",
}

interface PackageManagerCommands {
Expand All @@ -61,6 +62,11 @@ const packageManagerCommands: {
devInstall: "pnpm install --silent -D",
build: "pnpm run build",
},
[PackageManager.Bun]: {
init: "bun init -y",
acopier marked this conversation as resolved.
Show resolved Hide resolved
devInstall: "bun install --silent -D",
build: "bun run build",
},
};

function cmd(cmdStr: string, cwd: string) {
Expand Down Expand Up @@ -109,14 +115,15 @@ async function init(argv: yargs.Arguments<InitOptions>, initMode: InitMode) {

// Although npm is installed by default, it can be uninstalled
// and replaced by another manager, so check for it to make sure
const [npmAvailable, pnpmAvailable, yarnAvailable, gitAvailable] = (
await Promise.allSettled(["npm", "pnpm", "yarn", "git"].map(v => lookpath(v)))
const [npmAvailable, pnpmAvailable, yarnAvailable, bunAvailable, gitAvailable] = (
await Promise.allSettled(["npm", "pnpm", "yarn", "bun", "git"].map(v => lookpath(v)))
).map(v => (v.status === "fulfilled" ? v.value !== undefined : true));

const packageManagerExistance: { [K in PackageManager]: boolean } = {
[PackageManager.NPM]: npmAvailable,
[PackageManager.PNPM]: pnpmAvailable,
[PackageManager.Yarn]: yarnAvailable,
[PackageManager.Bun]: bunAvailable,
acopier marked this conversation as resolved.
Show resolved Hide resolved
};

const packageManagerCount = Object.values(packageManagerExistance).filter(exists => exists).length;
Expand Down Expand Up @@ -224,6 +231,10 @@ async function init(argv: yargs.Arguments<InitOptions>, initMode: InitMode) {

await benchmark("Initializing package.json..", async () => {
await cmd(selectedPackageManager.init, cwd);
if (selectedPackageManager === packageManagerCommands.bun) {
await fs.remove(`${cwd}/index.ts`);
await fs.remove(`${cwd}/README.md`);
}
acopier marked this conversation as resolved.
Show resolved Hide resolved
const pkgJson = await fs.readJson(paths.packageJson);
pkgJson.scripts = {
build: "rbxtsc",
Expand Down