append sourceMappingURL when using bin/6to5 and output sourcemaps - fixes #183

This commit is contained in:
Sebastian McKenzie 2014-11-17 14:22:25 +11:00
parent a3a4a7645c
commit c0b03e8126
8 changed files with 21 additions and 2 deletions

View File

@ -1,3 +1,7 @@
# 1.12.20
* Append `sourceMappingURL` when using `bin/6to5` and output sourcemaps.
# 1.12.19
* Add `comments` option and `--remove-comments` flag. Thanks @[webpro](htps://github.com/webpro)!

View File

@ -19,7 +19,9 @@ module.exports = function (commander, filenames, opts) {
mkdirp.sync(up);
if (commander.sourceMaps) {
fs.writeFileSync(dest + ".map", JSON.stringify(data.map));
var mapLoc = dest + ".map";
data.code = util.addSourceMappingUrl(data.code, mapLoc);
fs.writeFileSync(mapLoc, JSON.stringify(data.map));
}
fs.writeFileSync(dest, data.code);

View File

@ -56,7 +56,9 @@ module.exports = function (commander, filenames) {
if (commander.outFile) {
if (commander.sourceMaps) {
fs.writeFileSync(commander.outFile + ".map", JSON.stringify(result.map));
var mapLoc = commander.outFile + ".map";
result.code = util.addSourceMappingUrl(result.code, mapLoc);
fs.writeFileSync(mapLoc, JSON.stringify(result.map));
}
fs.writeFileSync(commander.outFile, result.code);

View File

@ -1,6 +1,7 @@
var readdir = require("fs-readdir-recursive");
var index = require("./index");
var util = require("../../lib/6to5/util");
var path = require("path");
var to5 = require("../../lib/6to5");
var fs = require("fs");
var _ = require("lodash");
@ -11,6 +12,10 @@ exports.readdirFilter = function (filename) {
});
};
exports.addSourceMappingUrl = function (code, loc) {
return code + "\n//# sourceMappingURL=" + path.basename(loc);
};
exports.transform = function (filename, code, opts) {
opts = _.extend(opts || {}, index.opts);
opts.filename = filename;

View File

@ -1,3 +1,4 @@
"use strict";
var Test = function Test() {};
//# sourceMappingURL=bar.js.map

View File

@ -3,3 +3,4 @@
arr.map(function (x) {
return x * MULTIPLIER;
});
//# sourceMappingURL=foo.js.map

View File

@ -6,3 +6,5 @@ var Test = function Test() {};
arr.map(function (x) {
return x * MULTIPLIER;
});
//# sourceMappingURL=script3.js.map

View File

@ -3,3 +3,5 @@
arr.map(function (x) {
return x * x;
});
//# sourceMappingURL=test.js.map