diff --git a/src/index.ts b/src/index.ts index 741c36a..e07b875 100644 --- a/src/index.ts +++ b/src/index.ts @@ -63,7 +63,7 @@ export interface Options { /** Default value for package manager (default: `undefined`) * - * `npm`, `yarn` and `pnpm` are available. `undefined` to auto detect package manager. */ + * `npm`, `yarn`, `pnpm` and `bun` are available. `undefined` to auto detect package manager. */ defaultPackageManager?: PackageManager; /** Interactively asks users for a description */ @@ -312,7 +312,7 @@ export async function create(appName: string, options: Options) { 'node-pm': { type: 'list', describe: 'Package manager to use for installing packages from npm', - choices: ['npm', 'yarn', 'pnpm'], + choices: ['npm', 'yarn', 'pnpm', 'bun'], default: defaultPackageManager, // undefined by default, we'll try to guess pm later prompt: promptForPackageManager ? 'if-no-arg' : 'never', }, diff --git a/src/npm.ts b/src/npm.ts index bf8b83b..4b848eb 100644 --- a/src/npm.ts +++ b/src/npm.ts @@ -1,7 +1,7 @@ import { CLIError, printCommand } from '.'; import { spawnPromise } from './fs'; -export type PackageManager = 'npm' | 'yarn' | 'pnpm'; +export type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun'; // License for `whichPm` // The MIT License (MIT) @@ -27,27 +27,23 @@ export async function initPackage( pm: PackageManager; } ) { - let command: string; + const command: string = pm === 'yarn' ? 'yarnpkg' : pm; let args: string[]; switch (pm) { - case 'npm': { - command = 'npm'; + case 'npm': + case 'pnpm': + case 'bun': { args = ['init', '-y']; process.chdir(rootDir); break; } case 'yarn': { - command = 'yarnpkg'; args = ['init', '-y', '--cwd', rootDir]; break; } - case 'pnpm': { - command = 'pnpm'; - args = ['init', '-y']; - process.chdir(rootDir); - break; - } + default: + throw new CLIError(`Unsupported package manager: ${pm}`); } printCommand(command, ...args); @@ -60,26 +56,26 @@ export async function initPackage( } export async function installDeps(rootDir: string, pm: PackageManager) { - let command: string; + const command: string = pm === 'yarn' ? 'yarnpkg' : pm; let args: string[]; switch (pm) { - case 'npm': { - command = 'npm'; + case 'npm': + case 'bun': { args = ['install']; process.chdir(rootDir); break; } case 'yarn': { - command = 'yarnpkg'; args = ['install', '--cwd', rootDir]; break; } case 'pnpm': { - command = 'pnpm'; args = ['install', '--dir', rootDir]; break; } + default: + throw new CLIError(`Unsupported package manager: ${pm}`); } printCommand(command, ...args); @@ -102,26 +98,26 @@ export async function addDeps( pm: PackageManager; } ) { - let command: string; + const command: string = pm === 'yarn' ? 'yarnpkg' : pm; let args: string[]; switch (pm) { case 'npm': { - command = 'npm'; args = ['install', isDev ? '-D' : '-S', ...deps]; process.chdir(rootDir); break; } - case 'yarn': { - command = 'yarnpkg'; + case 'yarn': + case 'bun': { args = ['add', '--cwd', rootDir, ...deps, isDev ? '-D' : '']; break; } case 'pnpm': { - command = 'pnpm'; args = ['add', '--dir', rootDir, ...deps, isDev ? '-D' : '']; break; } + default: + throw new CLIError(`Unsupported package manager: ${pm}`); } printCommand(command, ...args);