Skip to content

Commit

Permalink
feat: Add Bun as supported package manager
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks committed Aug 7, 2023
1 parent 4cf3b18 commit 730bf66
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions actions/new.action.ts
Expand Up @@ -168,6 +168,7 @@ const askForPackageManager = async (): Promise<Answers> => {
PackageManager.NPM,
PackageManager.YARN,
PackageManager.PNPM,
PackageManager.BUN,
]),
];
const prompt = inquirer.createPromptModule();
Expand Down
1 change: 1 addition & 0 deletions lib/package-managers/index.ts
Expand Up @@ -4,5 +4,6 @@ export * from './abstract.package-manager';
export * from './npm.package-manager';
export * from './yarn.package-manager';
export * from './pnpm.package-manager';
export * from './bun.package-manager';
export * from './project.dependency';
export * from './package-manager-commands';
8 changes: 8 additions & 0 deletions lib/package-managers/package-manager.factory.ts
Expand Up @@ -4,6 +4,7 @@ import { NpmPackageManager } from './npm.package-manager';
import { PackageManager } from './package-manager';
import { YarnPackageManager } from './yarn.package-manager';
import { PnpmPackageManager } from './pnpm.package-manager';
import { BunPackageManager } from './bun.package-manager';

export class PackageManagerFactory {
public static create(name: PackageManager | string): AbstractPackageManager {
Expand All @@ -14,6 +15,8 @@ export class PackageManagerFactory {
return new YarnPackageManager();
case PackageManager.PNPM:
return new PnpmPackageManager();
case PackageManager.BUN:
return new BunPackageManager();
default:
throw new Error(`Package manager ${name} is not managed.`);
}
Expand All @@ -35,6 +38,11 @@ export class PackageManagerFactory {
return this.create(PackageManager.PNPM);
}

const hasBunLockFile = files.includes('bun.lockb');
if (hasBunLockFile) {
return this.create(PackageManager.BUN);
}

return this.create(DEFAULT_PACKAGE_MANAGER);
} catch (error) {
return this.create(DEFAULT_PACKAGE_MANAGER);
Expand Down
1 change: 1 addition & 0 deletions lib/package-managers/package-manager.ts
Expand Up @@ -2,4 +2,5 @@ export enum PackageManager {
NPM = 'npm',
YARN = 'yarn',
PNPM = 'pnpm',
BUN = 'bun',
}
4 changes: 4 additions & 0 deletions lib/runners/runner.factory.ts
Expand Up @@ -4,6 +4,7 @@ import { Runner } from './runner';
import { SchematicRunner } from './schematic.runner';
import { YarnRunner } from './yarn.runner';
import { PnpmRunner } from './pnpm.runner';
import { BunRunner } from './bun.runner';

export class RunnerFactory {
public static create(runner: Runner) {
Expand All @@ -20,6 +21,9 @@ export class RunnerFactory {
case Runner.PNPM:
return new PnpmRunner();

case Runner.BUN:
return new BunRunner();

default:
console.info(chalk.yellow(`[WARN] Unsupported runner: ${runner}`));
}
Expand Down
1 change: 1 addition & 0 deletions lib/runners/runner.ts
Expand Up @@ -3,4 +3,5 @@ export enum Runner {
NPM,
YARN,
PNPM,
BUN,
}
10 changes: 10 additions & 0 deletions test/lib/package-managers/package-manager.factory.spec.ts
Expand Up @@ -4,6 +4,7 @@ import {
PackageManagerFactory,
PnpmPackageManager,
YarnPackageManager,
BunPackageManager,
} from '../../../lib/package-managers';

jest.mock('fs', () => ({
Expand Down Expand Up @@ -45,6 +46,15 @@ describe('PackageManagerFactory', () => {
);
});

it('should return BunPackageManager when "bun.lockb" file is found', async () => {
(fs.promises.readdir as jest.Mock).mockResolvedValue(['bun.lockb']);

const whenPackageManager = PackageManagerFactory.find();
await expect(whenPackageManager).resolves.toBeInstanceOf(
BunPackageManager,
);
});

describe('when there are all supported lock files', () => {
it('should prioritize "yarn.lock" file over all the others lock files', async () => {
(fs.promises.readdir as jest.Mock).mockResolvedValue([
Expand Down

0 comments on commit 730bf66

Please sign in to comment.