-
Notifications
You must be signed in to change notification settings - Fork 441
feat(package-managers): add bun support #3258
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
awaiden
wants to merge
1
commit into
nestjs:master
Choose a base branch
from
awaiden:feat/add-bun-package-manager
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { Runner, RunnerFactory } from '../runners'; | ||
| import { BunRunner } from '../runners/bun.runner'; | ||
| import { AbstractPackageManager } from './abstract.package-manager'; | ||
| import { PackageManager } from './package-manager'; | ||
| import { PackageManagerCommands } from './package-manager-commands'; | ||
|
|
||
| export class BunPackageManager extends AbstractPackageManager { | ||
| constructor() { | ||
| super(RunnerFactory.create(Runner.BUN) as BunRunner); | ||
| } | ||
|
|
||
| public get name() { | ||
| return PackageManager.BUN.toUpperCase(); | ||
| } | ||
|
|
||
| get cli(): PackageManagerCommands { | ||
| return { | ||
| install: 'install', | ||
| add: 'add', | ||
| update: 'update', | ||
| remove: 'remove', | ||
| saveFlag: '--save', | ||
| saveDevFlag: '--dev', | ||
| silentFlag: '--silent', | ||
awaiden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ export enum PackageManager { | |
| NPM = 'npm', | ||
| YARN = 'yarn', | ||
| PNPM = 'pnpm', | ||
| BUN = 'bun', | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { AbstractRunner } from './abstract.runner'; | ||
|
|
||
| export class BunRunner extends AbstractRunner { | ||
| constructor() { | ||
| super('bun'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ export enum Runner { | |
| NPM, | ||
| YARN, | ||
| PNPM, | ||
| BUN, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { join } from 'path'; | ||
| import { | ||
| BunPackageManager, | ||
| PackageManagerCommands, | ||
| } from '../../../lib/package-managers'; | ||
| import { BunRunner } from '../../../lib/runners/bun.runner'; | ||
|
|
||
| jest.mock('../../../lib/runners/bun.runner'); | ||
|
|
||
| describe('BunPackageManager', () => { | ||
| let packageManager: BunPackageManager; | ||
| beforeEach(() => { | ||
| (BunRunner as any).mockClear(); | ||
| (BunRunner as any).mockImplementation(() => { | ||
| return { | ||
| run: (): Promise<void> => Promise.resolve(), | ||
| }; | ||
| }); | ||
| packageManager = new BunPackageManager(); | ||
| }); | ||
| it('should be created', () => { | ||
| expect(packageManager).toBeInstanceOf(BunPackageManager); | ||
| }); | ||
| it('should have the correct cli commands', () => { | ||
| const expectedValues: PackageManagerCommands = { | ||
| install: 'install', | ||
| add: 'add', | ||
| update: 'update', | ||
| remove: 'remove', | ||
| saveFlag: '--save', | ||
| saveDevFlag: '--dev', | ||
| silentFlag: '--silent', | ||
| }; | ||
| expect(packageManager.cli).toMatchObject(expectedValues); | ||
| }); | ||
| describe('install', () => { | ||
| it('should use the proper command for installing', () => { | ||
| const spy = jest.spyOn((packageManager as any).runner, 'run'); | ||
| const dirName = '/tmp'; | ||
| const testDir = join(process.cwd(), dirName); | ||
| packageManager.install(dirName, 'npm'); | ||
| expect(spy).toBeCalledWith('install --silent', true, testDir); | ||
awaiden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| }); | ||
| describe('addProduction', () => { | ||
| it('should use the proper command for adding production dependencies', () => { | ||
| const spy = jest.spyOn((packageManager as any).runner, 'run'); | ||
| const dependencies = ['@nestjs/common', '@nestjs/core']; | ||
| const tag = '5.0.0'; | ||
| const command = `add --save ${dependencies | ||
| .map((dependency) => `${dependency}@${tag}`) | ||
| .join(' ')}`; | ||
| packageManager.addProduction(dependencies, tag); | ||
| expect(spy).toBeCalledWith(command, true); | ||
awaiden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| }); | ||
| describe('addDevelopment', () => { | ||
| it('should use the proper command for adding development dependencies', () => { | ||
| const spy = jest.spyOn((packageManager as any).runner, 'run'); | ||
| const dependencies = ['@nestjs/common', '@nestjs/core']; | ||
| const tag = '5.0.0'; | ||
| const command = `add --dev ${dependencies | ||
| .map((dependency) => `${dependency}@${tag}`) | ||
| .join(' ')}`; | ||
| packageManager.addDevelopment(dependencies, tag); | ||
| expect(spy).toBeCalledWith(command, true); | ||
| }); | ||
| }); | ||
| describe('updateProduction', () => { | ||
| it('should use the proper command for updating production dependencies', () => { | ||
| const spy = jest.spyOn((packageManager as any).runner, 'run'); | ||
| const dependencies = ['@nestjs/common', '@nestjs/core']; | ||
| const command = `update ${dependencies.join(' ')}`; | ||
| packageManager.updateProduction(dependencies); | ||
| expect(spy).toBeCalledWith(command, true); | ||
| }); | ||
| }); | ||
| describe('updateDevelopment', () => { | ||
| it('should use the proper command for updating development dependencies', () => { | ||
| const spy = jest.spyOn((packageManager as any).runner, 'run'); | ||
| const dependencies = ['@nestjs/common', '@nestjs/core']; | ||
| const command = `update ${dependencies.join(' ')}`; | ||
| packageManager.updateDevelopment(dependencies); | ||
| expect(spy).toBeCalledWith(command, true); | ||
| }); | ||
| }); | ||
| describe('upgradeProduction', () => { | ||
| it('should use the proper command for upgrading production dependencies', () => { | ||
| const spy = jest.spyOn((packageManager as any).runner, 'run'); | ||
| const dependencies = ['@nestjs/common', '@nestjs/core']; | ||
| const tag = '5.0.0'; | ||
| const uninstallCommand = `remove --save ${dependencies.join(' ')}`; | ||
awaiden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const installCommand = `add --save ${dependencies | ||
| .map((dependency) => `${dependency}@${tag}`) | ||
| .join(' ')}`; | ||
awaiden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return packageManager.upgradeProduction(dependencies, tag).then(() => { | ||
| expect(spy.mock.calls).toEqual([ | ||
| [uninstallCommand, true], | ||
| [installCommand, true], | ||
| ]); | ||
| }); | ||
| }); | ||
| }); | ||
| describe('upgradeDevelopment', () => { | ||
| it('should use the proper command for upgrading development dependencies', () => { | ||
| const spy = jest.spyOn((packageManager as any).runner, 'run'); | ||
| const dependencies = ['@nestjs/common', '@nestjs/core']; | ||
| const tag = '5.0.0'; | ||
| const uninstallCommand = `remove --dev ${dependencies.join(' ')}`; | ||
|
|
||
| const installCommand = `add --dev ${dependencies | ||
| .map((dependency) => `${dependency}@${tag}`) | ||
| .join(' ')}`; | ||
|
|
||
| return packageManager.upgradeDevelopment(dependencies, tag).then(() => { | ||
| expect(spy.mock.calls).toEqual([ | ||
| [uninstallCommand, true], | ||
| [installCommand, true], | ||
| ]); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.