Skip to content

Commit aae17fc

Browse files
authored
fix(core-utils): correctly fall back package manager lockfile (#3885)
1 parent a604f66 commit aae17fc

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/utils/core-utils/spec/package-manager.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('package-manager', () => {
9999
});
100100

101101
it('should use the package manager for the nearest ancestor lockfile if detected', async () => {
102-
vi.mocked(findUp).mockResolvedValue('yarn.lock');
102+
vi.mocked(findUp).mockResolvedValue('/Users/foo/bar/yarn.lock');
103103
await expect(resolvePackageManager()).resolves.toHaveProperty('executable', 'yarn');
104104
});
105105

packages/utils/core-utils/src/package-manager.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from 'node:path';
2+
13
import { CrossSpawnArgs, CrossSpawnOptions, spawn } from '@malept/cross-spawn-promise';
24
import chalk from 'chalk';
35
import debug from 'debug';
@@ -75,8 +77,12 @@ function pmFromUserAgent() {
7577
*/
7678
export const resolvePackageManager: () => Promise<PMDetails> = async () => {
7779
const executingPM = pmFromUserAgent();
80+
let lockfilePM;
7881
const lockfile = await findUp(['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'pnpm-workspace.yaml'], { type: 'file' });
79-
const lockfilePM = (lockfile && PM_FROM_LOCKFILE[lockfile]) ?? undefined;
82+
if (lockfile) {
83+
const lockfileName = path.basename(lockfile);
84+
lockfilePM = PM_FROM_LOCKFILE[lockfileName];
85+
}
8086
const installer = process.env.NODE_INSTALLER || executingPM?.name || lockfilePM;
8187

8288
// TODO(erickzhao): Remove NODE_INSTALLER environment variable for Forge 8
@@ -90,7 +96,7 @@ export const resolvePackageManager: () => Promise<PMDetails> = async () => {
9096
case 'npm':
9197
case 'pnpm':
9298
d(
93-
`Resolved package manager to ${installer}. (Derived from NODE_INSTALLER: ${process.env.NODE_INSTALLER}, npm_config_user_agent: ${executingPM}, lockfile: ${lockfilePM}.)`
99+
`Resolved package manager to ${installer}. (Derived from NODE_INSTALLER: ${process.env.NODE_INSTALLER}, npm_config_user_agent: ${process.env.npm_config_user_agent}, lockfile: ${lockfilePM})`
94100
);
95101
return { ...PACKAGE_MANAGERS[installer], version: executingPM?.version };
96102
default:

0 commit comments

Comments
 (0)