({ input, candidates, options }: RunOptions)
| 19 | } |
| 20 | |
| 21 | async function run({ input, candidates, options }: RunOptions) { |
| 22 | let source = new MagicString(input) |
| 23 | let root = path.resolve(__dirname, '../..') |
| 24 | |
| 25 | let compiler = await compile(source.toString(), { |
| 26 | from: 'input.css', |
| 27 | async loadStylesheet(id, base) { |
| 28 | let resolvedPath = path.resolve(root, id === 'tailwindcss' ? 'index.css' : id) |
| 29 | |
| 30 | return { |
| 31 | path: path.relative(root, resolvedPath), |
| 32 | base, |
| 33 | content: await fs.readFile(resolvedPath, 'utf-8'), |
| 34 | } |
| 35 | }, |
| 36 | ...options, |
| 37 | }) |
| 38 | |
| 39 | let css = compiler.build(candidates ?? []) |
| 40 | let decoded = compiler.buildSourceMap() |
| 41 | let rawMap = toRawSourceMap(decoded) |
| 42 | let combined = remapping(rawMap, () => null) |
| 43 | let map = JSON.parse(rawMap.toString()) as RawSourceMap |
| 44 | |
| 45 | let sources = combined.sources |
| 46 | let annotations = visualizeSourceMap(map, css) |
| 47 | |
| 48 | return { css, map, sources, annotations } |
| 49 | } |
| 50 | |
| 51 | function toRawSourceMap(map: DecodedSourceMap): string { |
| 52 | let generator = new SourceMapGenerator() |
no test coverage detected