Skip to content
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
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: '[email protected]' }),
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[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could potentially opt to support both fields for a short period of time while calling the old one deprecated (maybe raise a warning message in the logs?). That way we can understand the scope of affected systems before we look to drop the field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is limited number of things using @netlify/build-info directly, so I think we can skip on interim period - this package is not meant for public consumption per-se as it's quite Netlify specific, so I don't think it warrants extra effort to have a ~deprecation period. Instead maybe we just have a canary with this change that we adjust consumers of this package before we merge and publish this change so we can minimize "package upgrade downtime"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** 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
Loading