Skip to content

Instantly share code, notes, and snippets.

@MonirAbuHilal
Created August 23, 2018 00:35
Show Gist options
  • Select an option

  • Save MonirAbuHilal/99d254851760c7bf6b6c886f3b3a9b5c to your computer and use it in GitHub Desktop.

Select an option

Save MonirAbuHilal/99d254851760c7bf6b6c886f3b3a9b5c to your computer and use it in GitHub Desktop.
A nodejs script for extracting source files from a sourcemap (.js.map) file
// yarn init .
// yarn add mkdirp
// node ./extract-sourcemap.js ./app-bundle.js.map
const fs = require("fs");
const path = require("path");
const mkdirp = require("mkdirp");
const OUTPUT_DIRECTORY = "./extracted/";
const args = process.argv.slice(2);
const sourceMapFilePath = args[0];
const parsedSourceMap = JSON.parse(fs.readFileSync(sourceMapFilePath, "utf8"));
const sources = parsedSourceMap.sources;
const contents = parsedSourceMap.sourcesContent;
for (let index = 0; index < sources.length; index++) {
const fileName = sources[index];
const fileContents = contents[index];
console.log(fileName);
const filePath = `${OUTPUT_DIRECTORY}${fileName}`;
const fileDirectory = path.dirname(filePath);
mkdirp.sync(fileDirectory);
fs.writeFileSync(filePath, fileContents);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment