Skip to content

Commit

Permalink
Respect sourceMaps:false set in config files too.
Browse files Browse the repository at this point in the history
  • Loading branch information
loganfsmyth committed Sep 4, 2018
1 parent 588bde8 commit 9b2cbd0
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Babelify.prototype._flush = function (callback) {
// to avoid corrupting multibyte characters.
const data = Buffer.concat(this._data).toString();

babel.transform(data, this._opts, (err, result) => {
transform(data, this._opts, (err, result) => {
if (err) {
this.emit("error", err);
} else {
Expand Down Expand Up @@ -112,10 +112,6 @@ function normalizeOptions(preconfiguredOpts, transformOpts, filename) {
),
filename: absoluteFilename,

// Since Browserify can only handle inline sourcemaps, we override any other
// values to force inline sourcemaps unless they've been disabled.
sourceMaps: opts.sourceMaps === false ? false : "inline",

// The default sourcemap path is the path of the file relative to the
// basedir. This should mirror Browserify's internal behavior when
// 'debug' is enabled.
Expand Down Expand Up @@ -150,3 +146,22 @@ function normalizeTransformOpts(opts) {

return opts;
}

function transform(data, inputOpts, done) {
let cfg;
try {
cfg = babel.loadPartialConfig(inputOpts);
if (!cfg) return done(null, null);
} catch (err) {
return done(err);
}
const opts = cfg.options;

// Since Browserify can only handle inline sourcemaps, we override any other
// values to force inline sourcemaps unless they've been disabled.
if (opts.sourceMaps !== false) {
opts.sourceMaps = "inline";
}

babel.transform(data, opts, done);
}

0 comments on commit 9b2cbd0

Please sign in to comment.