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

Function validateRootDirectory

packages/cli/src/util/validate-paths.ts:11–47  ·  view source on GitHub ↗
(
  cwd: string,
  path: string,
  errorSuffix = ''
)

Source from the content-addressed store, hash-verified

9 * A helper function to validate the `rootDirectory` input.
10 */
11export async function validateRootDirectory(
12 cwd: string,
13 path: string,
14 errorSuffix = ''
15) {
16 const pathStat = await lstat(path).catch(() => null);
17 const suffix = errorSuffix ? ` ${errorSuffix}` : '';
18
19 if (!pathStat) {
20 output.error(
21 `The provided path ${chalk.cyan(
22 `“${toHumanPath(path)}”`
23 )} does not exist.${suffix}`
24 );
25 return false;
26 }
27
28 if (!pathStat.isDirectory()) {
29 output.error(
30 `The provided path ${chalk.cyan(
31 `“${toHumanPath(path)}”`
32 )} is a file, but expected a directory.${suffix}`
33 );
34 return false;
35 }
36
37 if (!path.startsWith(cwd)) {
38 output.error(
39 `The provided path ${chalk.cyan(
40 `“${toHumanPath(path)}”`
41 )} is outside of the project.${suffix}`
42 );
43 return false;
44 }
45
46 return true;
47}
48
49export default async function validatePaths(
50 client: Client,

Callers 4

handleInitDeploymentFunction · 0.90
handleDefaultDeployFunction · 0.90
setupAndLinkFunction · 0.90
inputRootDirectoryFunction · 0.90

Calls 2

errorMethod · 0.80
isDirectoryMethod · 0.45

Tested by

no test coverage detected