( url: URL, basePath: string, buildId: string )
| 34 | * ${basePath}/$path -> ${basePath}/_next/data/$buildId/$path.json |
| 35 | */ |
| 36 | export function denormalizeNextDataUrl( |
| 37 | url: URL, |
| 38 | basePath: string, |
| 39 | buildId: string |
| 40 | ): URL { |
| 41 | const newUrl = new URL(url.toString()) |
| 42 | let pathname = newUrl.pathname |
| 43 | |
| 44 | // Only denormalize if it's not already a data URL |
| 45 | const dataPrefix = `${basePath}/_next/data/${buildId}/` |
| 46 | if (!pathname.startsWith(dataPrefix)) { |
| 47 | // Remove basePath if present |
| 48 | let pathWithoutBase = pathname |
| 49 | if (basePath && pathname.startsWith(basePath)) { |
| 50 | pathWithoutBase = pathname.slice(basePath.length) |
| 51 | } |
| 52 | |
| 53 | // Add the /_next/data/${buildId}/ prefix and .json extension |
| 54 | pathname = `${basePath}/_next/data/${buildId}${pathWithoutBase}.json` |
| 55 | newUrl.pathname = pathname |
| 56 | } |
| 57 | |
| 58 | return newUrl |
| 59 | } |
no test coverage detected
searching dependent graphs…