From 9a6593e6bf000e5bd05bfe722dfae44177bc02fd Mon Sep 17 00:00:00 2001 From: Juliano Leonardo Soares Date: Tue, 26 Sep 2023 16:23:54 -0300 Subject: [PATCH 1/2] feat: add bun as package manager --- src/new/cli.ts | 2 +- src/new/form.ts | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/new/cli.ts b/src/new/cli.ts index 30f7e90..6623bf1 100644 --- a/src/new/cli.ts +++ b/src/new/cli.ts @@ -23,7 +23,7 @@ const createProject = (): CommandModule => { .option("package-manager", { describe: "The package manager to use", type: "string", - choices: ["npm", "yarn", "pnpm"], + choices: ["npm", "yarn", "pnpm", "bun"], alias: "p", }) .option("directory", { diff --git a/src/new/form.ts b/src/new/form.ts index d6e1938..430766b 100644 --- a/src/new/form.ts +++ b/src/new/form.ts @@ -88,6 +88,7 @@ const enum PackageManager { npm = "npm", yarn = "yarn", pnpm = "pnpm", + bun = "bun", } const projectForm = async (projectName: string, args: any[]): Promise => { @@ -100,7 +101,12 @@ const projectForm = async (projectName: string, args: any[]): Promise => { // Resolving the argument order problem for (const arg of args) { if (args.length >= 3) { - if (arg === "npm" || arg === "yarn" || arg === "pnpm") { + if ( + arg === "npm" || + arg === "yarn" || + arg === "pnpm" || + arg === "bun" + ) { packageManager = arg as PackageManager; } else if (arg === "non-opinionated" || arg === "opinionated") { template = arg as keyof typeof Template; @@ -132,7 +138,7 @@ const projectForm = async (projectName: string, args: any[]): Promise => { type: "list", name: "packageManager", message: "Package manager", - choices: ["npm", "yarn", "pnpm"], + choices: ["npm", "yarn", "pnpm", "bun"], }, { type: "list", @@ -168,6 +174,15 @@ const projectForm = async (projectName: string, args: any[]): Promise => { }; if (answer.confirm) { + // Check if package manager is bun and OS is Windows + if (answer.packageManager === "bun" && process.platform === "win32") { + printError( + "bun is not supported on Windows. Please use", + "npm, yarn or pnpm", + ); + process.exit(1); + } + await checkIfPackageManagerExists(answer.packageManager); console.log("\n"); const progressBar = new SingleBar( @@ -241,6 +256,9 @@ const projectForm = async (projectName: string, args: any[]): Promise => { case "pnpm": console.log(chalk.bold.gray("$ pnpm run dev")); break; + case "bun": + console.log(chalk.bold.gray("$ bun dev")); + break; } console.log("\n"); From 2e665e30634172b5cc7d9ceeae5fd9398e687adc Mon Sep 17 00:00:00 2001 From: Richard Zampieri Date: Tue, 26 Sep 2023 18:42:12 -0700 Subject: [PATCH 2/2] fix: show bun option only on linux --- package.json | 18 +++++++++--------- src/new/cli.ts | 8 +++++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 84ee3fd..a6845a8 100644 --- a/package.json +++ b/package.json @@ -47,15 +47,15 @@ "test:coverage": "vitest run --coverage" }, "dependencies": { - "@expressots/boost-ts": "^1.1.1", - "chalk-animation": "^1", - "cli-progress": "^3.11.2", - "degit": "^2.8.4", - "glob": "^10.2.6", - "inquirer": "^8.0.0", - "mustache": "^4.2.0", - "ts-node": "^10.9.1", - "yargs": "^17.6.2" + "@expressots/boost-ts": "1.1.1", + "chalk-animation": "2.0.3", + "cli-progress": "3.11.2", + "degit": "2.8.4", + "glob": "10.2.6", + "inquirer": "8.0.0", + "mustache": "4.2.0", + "ts-node": "10.9.1", + "yargs": "17.6.2" }, "devDependencies": { "@commitlint/cli": "^17.7.1", diff --git a/src/new/cli.ts b/src/new/cli.ts index 6623bf1..1bf5702 100644 --- a/src/new/cli.ts +++ b/src/new/cli.ts @@ -5,6 +5,12 @@ import { projectForm } from "./form"; type CommandModuleArgs = {}; const createProject = (): CommandModule => { + const packageManagers: Array = ["npm", "yarn", "pnpm"]; + + if (process.platform !== "win32") { + packageManagers.push("bun"); + } + return { command: "new [package-manager] [template] [directory]", describe: "Create a new project", @@ -23,7 +29,7 @@ const createProject = (): CommandModule => { .option("package-manager", { describe: "The package manager to use", type: "string", - choices: ["npm", "yarn", "pnpm", "bun"], + choices: packageManagers, alias: "p", }) .option("directory", {