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

Function buildFileTree

packages/client/src/utils/index.ts:84–235  ·  view source on GitHub ↗
(
  path: string | string[],
  {
    isDirectory,
    prebuilt,
    vercelOutputDir,
    rootDirectory,
    projectName,
    bulkRedirectsPath,
  }: Pick<
    VercelClientOptions,
    | 'isDirectory'
    | 'prebuilt'
    | 'vercelOutputDir'
    | 'rootDirectory'
    | 'projectName'
    | 'bulkRedirectsPath'
  >,
  debug: Debug
)

Source from the content-addressed store, hash-verified

82};
83
84export async function buildFileTree(
85 path: string | string[],
86 {
87 isDirectory,
88 prebuilt,
89 vercelOutputDir,
90 rootDirectory,
91 projectName,
92 bulkRedirectsPath,
93 }: Pick<
94 VercelClientOptions,
95 | 'isDirectory'
96 | 'prebuilt'
97 | 'vercelOutputDir'
98 | 'rootDirectory'
99 | 'projectName'
100 | 'bulkRedirectsPath'
101 >,
102 debug: Debug
103): Promise<{ fileList: string[]; ignoreList: string[] }> {
104 const ignoreList: string[] = [];
105 let fileList: string[];
106 let { ig, ignores } = await getVercelIgnore(path, prebuilt, vercelOutputDir);
107
108 debug(`Found ${ignores.length} rules in .vercelignore`);
109 debug('Building file tree...');
110
111 if (isDirectory && !Array.isArray(path)) {
112 // Directory path
113 const ignores = (absPath: string) => {
114 const rel = relative(path, absPath);
115 const ignored = ig.ignores(rel);
116 if (ignored) {
117 ignoreList.push(rel);
118 }
119 return ignored;
120 };
121 fileList = await readdir(path, [ignores]);
122
123 // Check for special files that should be included even if ignored
124 const refs = new Set<string>();
125
126 if (prebuilt) {
127 // Traverse over the `.vc-config.json` files and include
128 // the files referenced by the "filePathMap" properties
129 const vcConfigFilePaths = fileList.filter(
130 file => basename(file) === '.vc-config.json'
131 );
132 await Promise.all(
133 vcConfigFilePaths.map(async p => {
134 const configJson = await readFile(p, 'utf8');
135 const config = JSON.parse(configJson);
136 if (!config.filePathMap) return;
137 for (const v of Object.values(config.filePathMap) as string[]) {
138 refs.add(join(path, v));
139 }
140 })
141 );

Callers 3

continueDeploymentFunction · 0.90
collectDeploymentFilesFunction · 0.90
unit.utils.test.tsFile · 0.90

Calls 13

relativeFunction · 0.90
getVercelIgnoreFunction · 0.85
maybeReadFunction · 0.85
statFunction · 0.85
filterMethod · 0.80
readdirFunction · 0.70
debugFunction · 0.50
readFileFunction · 0.50
parseMethod · 0.45
valuesMethod · 0.45
addMethod · 0.45
isDirectoryMethod · 0.45

Tested by

no test coverage detected