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

Function getSkippedNodeModulesReason

packages/cli-exec/src/safety.ts:9–53  ·  view source on GitHub ↗
(
  nodeModulesDirectory: string,
  parentDirectories?: string[]
)

Source from the content-addressed store, hash-verified

7 * Explains why a `node_modules` directory should be skipped, or `null` if safe.
8 */
9export async function getSkippedNodeModulesReason(
10 nodeModulesDirectory: string,
11 parentDirectories?: string[]
12): Promise<string | null> {
13 const parentDirectory = path.dirname(nodeModulesDirectory);
14 parentDirectories ??= [parentDirectory];
15
16 for (const directory of parentDirectories) {
17 let unsafeParentReason: string | null;
18
19 try {
20 unsafeParentReason = await getUnsafeDirectoryReason(directory);
21 } catch (error) {
22 unsafeParentReason = `could not inspect: ${getErrorMessage(error)}`;
23 }
24
25 if (unsafeParentReason) {
26 return `${directory} is ${unsafeParentReason}`;
27 }
28 }
29
30 const result = await statIfExists(nodeModulesDirectory);
31
32 if ('missing' in result) {
33 return null;
34 }
35
36 if ('reason' in result) {
37 return result.reason;
38 }
39
40 if (!result.stats.isDirectory()) {
41 return 'not a directory';
42 }
43
44 const unsafeNodeModulesReason = getUnsafeStatsReason(result.stats);
45
46 if (unsafeNodeModulesReason) {
47 return unsafeNodeModulesReason;
48 }
49
50 return await getSkippedLocalBinDirectoryReason(
51 path.join(nodeModulesDirectory, '.bin')
52 );
53}
54
55/**
56 * Explains why a `.bin` directory should be skipped, or `null` if safe.

Callers 2

getLocalBinSearchFunction · 0.90

Calls 7

getErrorMessageFunction · 0.90
statIfExistsFunction · 0.90
getUnsafeDirectoryReasonFunction · 0.85
getUnsafeStatsReasonFunction · 0.85
isDirectoryMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected