Skip to content

Commit

Permalink
Parse all source maps as JSON before writing
Browse files Browse the repository at this point in the history
Using types from Terser for the Source Map Revision 3 spec
  • Loading branch information
colinrotherham committed Apr 20, 2023
1 parent b7acb29 commit cbc2a20
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions shared/tasks/assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ export async function write (filePath, result) {
const writeTasks = []

// Files to write
/** @type {SourceMap | undefined} */
const map = result.map ? JSON.parse(result.map.toString()) : undefined
const code = 'css' in result ? result.css : result.code
const map = result.map?.toString()

// 1. Write code (example.js)
writeTasks.push(writeFile(filePath, code))

// 2. Write source map (example.js.map)
if (map) {
writeTasks.push(writeFile(`${filePath}.map`, map))
writeTasks.push(writeFile(`${filePath}.map`, JSON.stringify(map)))
}

await Promise.all(writeTasks)
Expand Down Expand Up @@ -70,3 +71,11 @@ export async function write (filePath, result) {
*
* @typedef {import('rollup').OutputChunk | import('terser').MinifyOutput | import('postcss').Result} AssetOutput
*/

/**
* Asset source maps
*
* {@link https://github.com/source-map/source-map-spec}
*
* @typedef {import('@jridgewell/source-map').DecodedSourceMap | import('@jridgewell/source-map').EncodedSourceMap} SourceMap
*/

0 comments on commit cbc2a20

Please sign in to comment.