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

Function readLocalVercelPackageJson

packages/cli-exec/src/lookup.ts:682–719  ·  view source on GitHub ↗

* Reads and validates the local `vercel` package metadata file.

(
  realPackageDirectory: string
)

Source from the content-addressed store, hash-verified

680 * Reads and validates the local `vercel` package metadata file.
681 */
682async function readLocalVercelPackageJson(
683 realPackageDirectory: string
684): Promise<
685 { packageJson: { name?: unknown; bin?: unknown } } | { reason: string }
686> {
687 const packageJsonPath = path.join(realPackageDirectory, 'package.json');
688 const realPackageJsonPath = await realpath(packageJsonPath);
689
690 if (!isSubpath(realPackageDirectory, realPackageJsonPath)) {
691 return { reason: 'local vercel package.json resolves outside package' };
692 }
693
694 const unsafePackageJsonReason = await getUnsafePackageFileReason(
695 realPackageDirectory,
696 realPackageJsonPath
697 );
698
699 if (unsafePackageJsonReason) {
700 return {
701 reason: `local vercel package.json is unsafe: ${unsafePackageJsonReason}`,
702 };
703 }
704
705 const packageJson = JSON.parse(
706 await readFile(realPackageJsonPath, 'utf8')
707 ) as {
708 name?: unknown;
709 bin?: unknown;
710 };
711
712 if (packageJson.name !== 'vercel') {
713 return {
714 reason: 'local vercel package.json does not have name "vercel"',
715 };
716 }
717
718 return { packageJson };
719}
720
721/**
722 * Resolves and validates the bin declared by the local `vercel` package.

Callers 1

getLocalVercelPackageBinFunction · 0.85

Calls 5

isSubpathFunction · 0.90
readFileFunction · 0.50
joinMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected