import path from 'node:path' import type { ExistingRawSourceMap, RolldownOutput } from 'rolldown' /** * Resolve a path inside `tests/fixtures` */ export function fixture(...paths: string[]): string { return path.resolve(import.meta.dirname, 'fixtures', ...paths) } /** * Find and parse a source map from the output chunks */ export function findSourceMapChunk( chunks: RolldownOutput['output'], fileName: string, ): ExistingRawSourceMap { const chunk = chunks.find((chunk) => chunk.fileName === fileName) if (!chunk) { throw new Error( `Unable to find file ${fileName} from the following chunks: ${chunks.map((chunk) => chunk.fileName).join(', ')}`, ) } if (chunk.type !== 'asset') { throw new Error('Sourcemap chunk is not an asset') } if (typeof chunk.source !== 'string') { throw new TypeError('Sourcemap chunk source is not a string') } const map = JSON.parse(chunk.source) as ExistingRawSourceMap return map }