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

Function prependPathEntries

packages/cli-exec/src/envpath.ts:6–26  ·  view source on GitHub ↗
(
  pathValue: string,
  directories: string[]
)

Source from the content-addressed store, hash-verified

4 * Prepends path entries while preserving existing entries and order.
5 */
6export function prependPathEntries(
7 pathValue: string,
8 directories: string[]
9): string {
10 const pathParts = pathValue.split(path.delimiter).filter(Boolean);
11 const prepended: string[] = [];
12
13 for (const directory of directories) {
14 if (!pathParts.includes(directory) && !prepended.includes(directory)) {
15 prepended.push(directory);
16 }
17 }
18
19 if (prepended.length === 0) {
20 return pathValue;
21 }
22
23 return pathValue === '' || pathValue === path.delimiter
24 ? `${prepended.join(path.delimiter)}${pathValue}`
25 : [...prepended, pathValue].join(path.delimiter);
26}
27
28/**
29 * Splits a PATH value into non-empty directory entries.

Callers 3

resolveCliInvocationFunction · 0.90
prependLocalBinsToPathFunction · 0.90

Calls 4

filterMethod · 0.80
splitMethod · 0.80
pushMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected