Skip to content
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

feat: detect bun as package manager #5306

Merged
merged 2 commits into from
Oct 9, 2023
Merged
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
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,38 @@ test('should use the `packageManager` property to detect yarn', async ({ fs }) =
expect(pkgManager?.name).toBe('yarn')
})

test('should 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')
})

test('should prefer yarn over bun when both lockfiles exist', async ({ fs }) => {
const cwd = mockFileSystem({
'package.json': '',
'yarn.lock': '',
'bun.lockb': '',
})
const project = new Project(fs, cwd)
const pkgManager = await detectPackageManager(project)
expect(pkgManager?.name).toBe('yarn')
})

test('should prefer pnpm over bun when both lockfiles exist', async ({ fs }) => {
const cwd = mockFileSystem({
'package.json': '',
'pnpm-lock.yaml': '',
'bun.lockb': '',
})
const project = new Project(fs, cwd)
const pkgManager = await detectPackageManager(project)
expect(pkgManager?.name).toBe('pnpm')
})

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]: {
kitop marked this conversation as resolved.
Show resolved Hide resolved
name: PkgManager.BUN,
installCommand: 'bun install',
runCommand: 'bun run',
lockFile: 'bun.lockb',
},
[PkgManager.NPM]: {
name: PkgManager.NPM,
installCommand: 'npm install',
Expand Down
Loading