fix corepack detection for package manager version determination (#11596)

The previous logic was checking for the env var `ENABLE_EXPERIMENTAL_COREPACK` to determine if corepack was being used by a project. However, this value only means that the build system should consider corepack, not that it's actively being used.

We need to check that flag AND the existence of a `packageManager` property in the project's `package.json`.
This commit is contained in:
Sean Massa
2024-05-15 14:25:01 -05:00
committed by GitHub
parent 41c44d6594
commit ccd7eb1fb7
9 changed files with 95 additions and 23 deletions

View File

@@ -104,8 +104,13 @@ export const build: BuildV2 = async ({
meta
);
const { cliType, packageJsonPath, lockfileVersion, lockfilePath } =
await scanParentDirs(entrypointFsDirname);
const {
cliType,
packageJsonPath,
packageJson,
lockfileVersion,
lockfilePath,
} = await scanParentDirs(entrypointFsDirname, true);
if (!packageJsonPath) {
throw new Error('Failed to locate `package.json` file in your project');
@@ -125,6 +130,7 @@ export const build: BuildV2 = async ({
spawnOpts.env = getEnvForPackageManager({
cliType,
lockfileVersion,
packageJsonPackageManager: packageJson?.packageManager,
nodeVersion,
env: spawnOpts.env,
});

View File

@@ -99,6 +99,7 @@ export const build: BuildV2 = async ({
spawnOpts.env = getEnvForPackageManager({
cliType,
lockfileVersion,
packageJsonPackageManager: packageJson?.packageManager,
nodeVersion,
env: spawnOpts.env,
});