Skip to content

Commit

Permalink
feat: detect bun as package manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kitop committed Sep 29, 2023
1 parent 21cafcf commit 2cde21b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,22 @@ test('should repsect the NETLIFY_USE_PNPM if no lock file is there', async ({ fs
expect(pkgManager?.name).toBe('pnpm')
})

test('should favor the NETLIFY_USE_PNPM over a yarn.lock file', async ({ fs }) => {
test('should favor the NETLIFY_USE_PNPM over another lockfile', async ({ fs }) => {
const cwd = mockFileSystem({
'package.json': '{}',
'yarn.lock': '',
'bun.lockb': '',
})
const project = new Project(fs, cwd).setEnvironment({ NETLIFY_USE_PNPM: 'true' })
const pkgManager = await detectPackageManager(project)
expect(pkgManager?.name).toBe('pnpm')
})

test('should favor the NETLIFY_USE_YARN over a package-lock.json file', async ({ fs }) => {
test('should favor the NETLIFY_USE_YARN over another lockfile', async ({ fs }) => {
const cwd = mockFileSystem({
'package.json': '{}',
'package-lock.json': '',
'bun.lockb': '',
})
const project = new Project(fs, cwd).setEnvironment({ NETLIFY_USE_YARN: 'true' })
const pkgManager = await detectPackageManager(project)
Expand Down Expand Up @@ -98,6 +100,16 @@ test('should use pnpm if there is a pnpm-lock.yaml in the root', async ({ fs })
expect(pkgManager?.name).toBe('pnpm')
})

test('should use bun if there is a bun.lockb in the root', async ({ fs }) => {
const cwd = mockFileSystem({
'package.json': '{}',
'bun.lockb': '',
})
const project = new Project(fs, cwd)
const pkgManager = await detectPackageManager(project)
expect(pkgManager?.name).toBe('bun')
})

test('should use the `packageManager` property to detect yarn', async ({ fs }) => {
const cwd = mockFileSystem({
'package.json': JSON.stringify({ packageManager: '[email protected]' }),
Expand All @@ -107,6 +119,16 @@ test('should use the `packageManager` property to detect yarn', async ({ fs }) =
expect(pkgManager?.name).toBe('yarn')
})

test('should use the prefer the `packageManager` property over a lockfile', async ({ fs }) => {
const cwd = mockFileSystem({
'package.json': JSON.stringify({ packageManager: '[email protected]' }),
'bun.lockb': '',
})
const project = new Project(fs, cwd)
const pkgManager = await detectPackageManager(project)
expect(pkgManager?.name).toBe('yarn')
})

describe('workspaces package manager detection', () => {
test('should use pnpm if there is a pnpm-lock.yaml in the workspace root', async ({ fs }) => {
const cwd = mockFileSystem({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Project } from '../project.js'
export const enum PkgManager {
YARN = 'yarn',
PNPM = 'pnpm',
BUN = 'bun',
NPM = 'npm',
}

Expand Down Expand Up @@ -43,6 +44,12 @@ export const AVAILABLE_PACKAGE_MANAGERS: Record<PkgManager, PkgManagerFields> =
lockFile: 'pnpm-lock.yaml',
forceEnvironment: 'NETLIFY_USE_PNPM',
},
[PkgManager.BUN]: {
name: PkgManager.BUN,
installCommand: 'bun install',
runCommand: 'bun run',
lockFile: 'bun.lockb',
},
[PkgManager.NPM]: {
name: PkgManager.NPM,
installCommand: 'npm install',
Expand Down

0 comments on commit 2cde21b

Please sign in to comment.