Created
September 19, 2015 16:56
-
-
Save theefer/db97cb1d8744a1b3e232 to your computer and use it in GitHub Desktop.
Helper script to validate sourcemaps
This file contains 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 | |
var validate = require('sourcemap-validator'), | |
fs = require('fs'), | |
assert = require('assert'); | |
var compiledSource = process.argv[2]; | |
if (! compiledSource) { | |
console.log("usage: validate.js <compiled-source.js>"); | |
process.exit(1); | |
} | |
var min = fs.readFileSync(compiledSource).toString(); | |
var minLastLine = min.trim().split("\n").slice(-1)[0]; | |
var m = minLastLine.match(/^\/\/# sourceMappingURL=(.+)$/); | |
var sourceMapUrl = m && m[1]; | |
// TODO: resolve path | |
var map = fs.readFileSync(sourceMapUrl).toString(); | |
var sources = JSON.parse(map).sources; | |
var sourcesContent = sources.reduce(function(contents, file) { | |
file = file.replace(/^file:\/\//, '') | |
contents[file] = fs.readFileSync(file).toString(); | |
return contents; | |
}, {}); | |
assert.doesNotThrow(function () { | |
validate(min, map, sourcesContent); | |
}, 'The sourcemap is not valid'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment