Skip to content

Commit

Permalink
[build-utils] log pnpm lockfile selection (#11591)
Browse files Browse the repository at this point in the history
Both `pnpm@6` and `pnpm@7` can parse lockfile versions `5.3` and `5.4`, but if there's a mismatch, `pnpm` will output a warning saying so. In order to prevent confusing warnings from being displayed to the user, this PR aligns the pnpm version with the exact lockfile verison.

It also adds a debug log to show which package manager version was determined based on the lockfile version.
  • Loading branch information
EndangeredMassa committed May 13, 2024
1 parent 67afc26 commit 2f7a6ed
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-zoos-drop.md
@@ -0,0 +1,5 @@
---
"@vercel/build-utils": patch
---

[build-utils] pnpm lockfile testing and fixing
14 changes: 13 additions & 1 deletion packages/build-utils/src/fs/run-user-scripts.ts
Expand Up @@ -594,6 +594,7 @@ export function getEnvForPackageManager({

type DetectedPnpmVersion =
| 'not found'
| 'pnpm 6'
| 'pnpm 7'
| 'pnpm 8'
| 'pnpm 9'
Expand All @@ -608,7 +609,9 @@ function detectPnpmVersion(
return 'corepack_enabled';
case lockfileVersion === undefined:
return 'not found';
case lockfileVersion === 5.3 || lockfileVersion === 5.4:
case lockfileVersion === 5.3:
return 'pnpm 6';
case lockfileVersion === 5.4:
return 'pnpm 7';
case lockfileVersion === 6.0 || lockfileVersion === 6.1:
return 'pnpm 8';
Expand Down Expand Up @@ -703,6 +706,7 @@ export function getPathOverrideForPackageManager({
detectedLockfile: 'pnpm-lock.yaml',
detectedPackageManager: 'pnpm 9',
};
case 'pnpm 6':
default:
return no_override;
}
Expand Down Expand Up @@ -764,6 +768,14 @@ export function getPathForPackageManager({
env,
});

debug(
`Detected ${
overrides.detectedPackageManager
} with lockfileVersion ${lockfileVersion} (${typeof lockfileVersion}): ${
overrides.path
}`
);

const alreadyInPath = (newPath: string) => {
const oldPath = env.PATH ?? '';
return oldPath.split(path.delimiter).includes(newPath);
Expand Down
17 changes: 17 additions & 0 deletions packages/build-utils/test/unit.get-env-for-package-manager.test.ts
Expand Up @@ -365,6 +365,23 @@ describe('Test `getPathOverrideForPackageManager()`', () => {
path: undefined,
},
},
{
name: 'should not set path if pnpm 6 is detected',
args: {
cliType: 'pnpm',
nodeVersion: { major: 16, range: '16.x', runtime: 'nodejs16.x' },
lockfileVersion: 5.3, // detects as pnpm@6, which is the default
env: {
FOO: 'bar',
PATH: 'foo',
},
},
want: {
detectedLockfile: undefined,
detectedPackageManager: undefined,
path: undefined,
},
},
{
name: 'should set path if pnpm 7+ is detected',
args: {
Expand Down
72 changes: 59 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f7a6ed

Please sign in to comment.