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

Function findAsset

packages/cli/src/util/dev/server.ts:3369–3399  ·  view source on GitHub ↗
(
  match: BuildMatch,
  requestPath: string,
  vercelConfig: VercelConfig
)

Source from the content-addressed store, hash-verified

3367}
3368
3369function 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
3401function dirnameWithoutDot(path: string): string {
3402 let dir = dirname(path);

Callers 2

DevServerClass · 0.85
shouldServeFunction · 0.85

Calls 3

isIndexFunction · 0.85
dirnameWithoutDotFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected