(
path: string | string[],
{
isDirectory,
prebuilt,
vercelOutputDir,
rootDirectory,
projectName,
bulkRedirectsPath,
}: Pick<
VercelClientOptions,
| 'isDirectory'
| 'prebuilt'
| 'vercelOutputDir'
| 'rootDirectory'
| 'projectName'
| 'bulkRedirectsPath'
>,
debug: Debug
)
| 82 | }; |
| 83 | |
| 84 | export 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 | ); |
no test coverage detected