* Reads and validates the local `vercel` package metadata file.
( realPackageDirectory: string )
| 680 | * Reads and validates the local `vercel` package metadata file. |
| 681 | */ |
| 682 | async 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. |
no test coverage detected