Skip to content

support Bun #70

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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',
},
Expand Down
38 changes: 17 additions & 21 deletions src/npm.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down