Skip to content

Instantly share code, notes, and snippets.

@theefer
Created September 19, 2015 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theefer/db97cb1d8744a1b3e232 to your computer and use it in GitHub Desktop.
Save theefer/db97cb1d8744a1b3e232 to your computer and use it in GitHub Desktop.
Helper script to validate sourcemaps
#!/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