Created
February 28, 2020 11:54
-
-
Save prumand/73ae1a01d22029d7969ce8a5dcaa453d to your computer and use it in GitHub Desktop.
Prepend empty lines to existing source-map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const sourceMap = require('source-map') | |
const fs = require('fs') | |
const path = require('path') | |
/** | |
* Prepend six lines to source-map | |
*/ | |
const runSourceMapPrepend = async (sourceMapFile) => { | |
const sourceMapFileContent = fs.readFileSync(sourceMapFile, 'utf8') | |
const originalConsumer = await new sourceMap.SourceMapConsumer( | |
sourceMapFileContent, | |
) | |
const node = sourceMap.SourceNode.fromStringWithSourceMap( | |
sourceMapFileContent, | |
await new sourceMap.SourceMapConsumer(sourceMapFileContent), | |
) | |
// add six empty lines | |
node.prepend('\n\n\n\n\n') | |
const newConsumer = sourceMap.SourceNode.fromStringWithSourceMap( | |
sourceMapFileContent, | |
originalConsumer, | |
) | |
const generator = sourceMap.SourceMapGenerator.fromSourceMap(originalConsumer) | |
const newSourceMapFileName = 'prepended-' + path.basename(sourceMapFile) | |
fs.writeFileSync(newSourceMapFileName, generator.toString()) | |
console.log( | |
'Prepended 6 empty lines to source-map. Written to: ' + | |
newSourceMapFileName, | |
) | |
} | |
const fileSource = process.argv[2] | |
if (!fileSource) { | |
throw Error('No source for source-map-file given!') | |
} | |
runSourceMapPrepend(fileSource) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment