From 9b2cbd07fac72d743ac48e403e794b28fe9d509a Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Tue, 4 Sep 2018 16:50:58 -0700 Subject: [PATCH] Respect sourceMaps:false set in config files too. --- index.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 171d5fb..28a2bbc 100644 --- a/index.js +++ b/index.js @@ -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 { @@ -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. @@ -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); +}