MCPcopy Create free account
hub / github.com/vercel/vercel / getPathForPackageManager

Function getPathForPackageManager

packages/build-utils/src/fs/run-user-scripts.ts:1439–1502  ·  view source on GitHub ↗
({
  cliType,
  lockfileVersion,
  env,
}: {
  cliType: CliType;
  lockfileVersion: number | undefined;
  env: { [x: string]: string | undefined };
})

Source from the content-addressed store, hash-verified

1437 * @deprecated use `getEnvForPackageManager` instead
1438 */
1439export function getPathForPackageManager({
1440 cliType,
1441 lockfileVersion,
1442 env,
1443}: {
1444 cliType: CliType;
1445 lockfileVersion: number | undefined;
1446 env: { [x: string]: string | undefined };
1447}): {
1448 /**
1449 * Which lockfile was detected.
1450 */
1451 detectedLockfile: string | undefined;
1452 /**
1453 * Detected package manager that generated the found lockfile.
1454 */
1455 detectedPackageManager: string | undefined;
1456 /**
1457 * Value of $PATH that includes the binaries for the detected package manager.
1458 * Undefined if no $PATH are necessary.
1459 */
1460 path: string | undefined;
1461 /**
1462 * Set if yarn was identified as package manager and `YARN_NODE_LINKER`
1463 * environment variable was not found on the input environment.
1464 */
1465 yarnNodeLinker: string | undefined;
1466} {
1467 // This is not the correct check for whether or not corepack is being used. For that, you'd have to check
1468 // the package.json's `packageManager` property. However, this deprecated function is keeping it's old,
1469 // broken behavior.
1470 const corepackEnabled = env.ENABLE_EXPERIMENTAL_COREPACK === '1';
1471
1472 let overrides = getPathOverrideForPackageManager({
1473 cliType,
1474 lockfileVersion,
1475 corepackPackageManager: undefined,
1476 });
1477
1478 if (corepackEnabled) {
1479 // this is essentially always overriding the value of `override`, but that's what was happening
1480 // in this deprecated function before
1481 overrides = NO_OVERRIDE;
1482 }
1483
1484 const alreadyInPath = (newPath: string) => {
1485 const oldPath = env.PATH ?? '';
1486 return oldPath.split(path.delimiter).includes(newPath);
1487 };
1488
1489 switch (true) {
1490 case cliType === 'yarn' && !env.YARN_NODE_LINKER:
1491 return { ...overrides, yarnNodeLinker: 'node-modules' };
1492 case alreadyInPath(overrides.path ?? ''):
1493 return {
1494 detectedLockfile: undefined,
1495 detectedPackageManager: undefined,
1496 path: undefined,

Calls 2

alreadyInPathFunction · 0.85

Tested by

no test coverage detected