( match: BuildMatch, requestPath: string, vercelConfig: VercelConfig )
| 3367 | } |
| 3368 | |
| 3369 | function findAsset( |
| 3370 | match: BuildMatch, |
| 3371 | requestPath: string, |
| 3372 | vercelConfig: VercelConfig |
| 3373 | ): { asset: BuilderOutput; assetKey: string } | void { |
| 3374 | if (!match.buildOutput) { |
| 3375 | return; |
| 3376 | } |
| 3377 | let assetKey: string = requestPath.replace(/\/$/, ''); |
| 3378 | let asset = match.buildOutput[requestPath]; |
| 3379 | |
| 3380 | if (vercelConfig.trailingSlash && requestPath.endsWith('/')) { |
| 3381 | asset = match.buildOutput[requestPath.slice(0, -1)]; |
| 3382 | } |
| 3383 | |
| 3384 | // In the case of an index path, fall back to iterating over the |
| 3385 | // builder outputs and doing an "is index" check until a match is found. |
| 3386 | if (!asset) { |
| 3387 | for (const [name, a] of Object.entries(match.buildOutput)) { |
| 3388 | if (isIndex(name) && dirnameWithoutDot(name) === assetKey) { |
| 3389 | asset = a; |
| 3390 | assetKey = name; |
| 3391 | break; |
| 3392 | } |
| 3393 | } |
| 3394 | } |
| 3395 | |
| 3396 | if (asset) { |
| 3397 | return { asset, assetKey }; |
| 3398 | } |
| 3399 | } |
| 3400 | |
| 3401 | function dirnameWithoutDot(path: string): string { |
| 3402 | let dir = dirname(path); |
no test coverage detected