Skip to content

Commit

Permalink
fix!: use bun as package manager when bun.lock is found
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Dec 27, 2024
1 parent ea093d0 commit e106db4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/build-info/e2e/browser-compatibility.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test('Should detect the package manager', async ({ page }) => {
expect(await page.evaluate(() => window.detectPackageManager(new window.project(window.fs, '/')))).toMatchObject({
forceEnvironment: 'NETLIFY_USE_PNPM',
installCommand: 'pnpm install',
lockFile: 'pnpm-lock.yaml',
lockFiles: ['pnpm-lock.yaml'],
name: 'pnpm',
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ exports[`should retrieve the build info for providing a rootDir 1`] = `
"packageManager": {
"forceEnvironment": "NETLIFY_USE_PNPM",
"installCommand": "pnpm install",
"lockFile": "pnpm-lock.yaml",
"lockFiles": [
"pnpm-lock.yaml",
],
"name": "pnpm",
"runCommand": "pnpm run",
"version": SemVer {
Expand Down Expand Up @@ -165,7 +167,9 @@ exports[`should retrieve the build info for providing a rootDir and a nested pro
"packageManager": {
"forceEnvironment": "NETLIFY_USE_PNPM",
"installCommand": "pnpm install",
"lockFile": "pnpm-lock.yaml",
"lockFiles": [
"pnpm-lock.yaml",
],
"name": "pnpm",
"runCommand": "pnpm run",
"version": SemVer {
Expand Down Expand Up @@ -239,7 +243,9 @@ exports[`should retrieve the build info for providing a rootDir and the same pro
"packageManager": {
"forceEnvironment": "NETLIFY_USE_PNPM",
"installCommand": "pnpm install",
"lockFile": "pnpm-lock.yaml",
"lockFiles": [
"pnpm-lock.yaml",
],
"name": "pnpm",
"runCommand": "pnpm run",
"version": SemVer {
Expand Down
4 changes: 3 additions & 1 deletion packages/build-info/src/node/get-build-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ test('should not crash on invalid projects', async (ctx) => {
expect(packageManager).toMatchInlineSnapshot(`
{
"installCommand": "npm install",
"lockFile": "package-lock.json",
"lockFiles": [
"package-lock.json",
],
"name": "npm",
"runCommand": "npm run",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ test('should use bun if there is a bun.lockb in the root', async ({ fs }) => {
expect(pkgManager?.name).toBe('bun')
})

test('should use bun if there is a bun.lock in the root', async ({ fs }) => {
const cwd = mockFileSystem({
'package.json': '{}',
'bun.lock': '',
})
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: 'yarn@3.2.1' }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export type PkgManagerFields = {
installCommand: string
/** The package managers run command prefix */
runCommand: string
/** The lock file a package manager is using */
lockFile: string
/** The lock files a package manager is using */
lockFiles: string[]
/** Environment variable that can be used to force the usage of a package manager even though there is no lock file or a different lock file */
forceEnvironment?: string
/** Flags that should be used for running the installation command */
Expand All @@ -34,27 +34,27 @@ export const AVAILABLE_PACKAGE_MANAGERS: Record<PkgManager, PkgManagerFields> =
name: PkgManager.YARN,
installCommand: 'yarn install',
runCommand: 'yarn run',
lockFile: 'yarn.lock',
lockFiles: ['yarn.lock'],
forceEnvironment: 'NETLIFY_USE_YARN',
},
[PkgManager.PNPM]: {
name: PkgManager.PNPM,
installCommand: 'pnpm install',
runCommand: 'pnpm run',
lockFile: 'pnpm-lock.yaml',
lockFiles: ['pnpm-lock.yaml'],
forceEnvironment: 'NETLIFY_USE_PNPM',
},
[PkgManager.NPM]: {
name: PkgManager.NPM,
installCommand: 'npm install',
runCommand: 'npm run',
lockFile: 'package-lock.json',
lockFiles: ['package-lock.json'],
},
[PkgManager.BUN]: {
name: PkgManager.BUN,
installCommand: 'bun install',
runCommand: 'bun run',
lockFile: 'bun.lockb',
lockFiles: ['bun.lockb', 'bun.lock'],
},
}

Expand All @@ -63,7 +63,7 @@ export const AVAILABLE_PACKAGE_MANAGERS: Record<PkgManager, PkgManagerFields> =
* this is to reduce the complexity in loops
*/
const lockFileMap = Object.values(AVAILABLE_PACKAGE_MANAGERS).reduce(
(cur, pkgManager) => ({ ...cur, [pkgManager.lockFile]: pkgManager }),
(cur, pkgManager) => pkgManager.lockFiles.reduce((cur, lockFile) => ({ ...cur, [lockFile]: pkgManager }), cur),
{} as Record<string, PkgManagerFields>,
)

Expand Down
4 changes: 3 additions & 1 deletion packages/build-info/tests/bin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ test('CLI does not print js-workspaces if given a project without it', async (ct
\\"name\\": \\"pnpm\\",
\\"installCommand\\": \\"pnpm install\\",
\\"runCommand\\": \\"pnpm run\\",
\\"lockFile\\": \\"pnpm-lock.yaml\\",
\\"lockFiles\\": [
\\"pnpm-lock.yaml\\"
],
\\"forceEnvironment\\": \\"NETLIFY_USE_PNPM\\"
}
}"
Expand Down

0 comments on commit e106db4

Please sign in to comment.