Skip to content

Commit

Permalink
fix: fix faulty keep modules
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jul 28, 2020
1 parent f4c75ff commit 22dd0d8
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@
// replacing `"(@babel.*)",` with `require("$1"),`
// replacing `module.exports = {(\s\S*)}` with `module.exports = () => {return $1}`

let keepModules = false // false by default

if (process.env.BABEL_ENV === "production") {
keepModules = true
console.warn("setting `BABEL_ENV` to `production` for bypassing ES6 module transformming is deprecated. Use BABEL_KEEP_MODULES=\"true\" instead.")
}

if (process.env.BABEL_ENV === "development") {
console.warn("setting `BABEL_ENV` to `development` for transforming ES6 modules is deprecated. Use BABEL_KEEP_MODULES=\"false\" instead.")
}

if (process.env.BABEL_KEEP_MODULES === "true") {
keepModules = true
}

let presets = [
[
require("@babel/preset-env"),
{
targets: {
electron: 5,
modules: keepModules
},
},
],
Expand Down Expand Up @@ -36,24 +52,17 @@ let plugins = [
require("@babel/plugin-proposal-json-strings"),
];

if (process.env.BABEL_ENV === "production") {
console.warn("setting `BABEL_ENV` to `production` for bypassing ES6 module transformming is deprecated. Use BABEL_KEEP_MODULES=\"true\" instead.")
}

if (process.env.BABEL_ENV === "development") {
console.warn("setting `BABEL_ENV` to `development` for transform ES6 modules is deprecated. Use BABEL_KEEP_MODULES=\"false\" instead.")
}

// tranform modules
if (process.env.BABEL_KEEP_MODULES === "false" || !(process.env.BABEL_KEEP_MODULES) || process.env.BABEL_ENV === "development" || !(process.env.BABEL_ENV)) {
// When without Rollup
// transform modules (e.g when without Rollup)
if (!keepModules) {
plugins.push(...[
require("@babel/plugin-transform-modules-commonjs"),
require("@babel/plugin-syntax-dynamic-import"),
require("babel-plugin-add-module-exports",{"addDefaultProperty": true}) // atom needs this
require("@babel/plugin-transform-modules-commonjs"),
require("@babel/plugin-syntax-dynamic-import"),
require("babel-plugin-add-module-exports",{"addDefaultProperty": true}) // atom needs this
]);
}


module.exports = () => {return {
presets: presets,
plugins: plugins,
Expand Down

0 comments on commit 22dd0d8

Please sign in to comment.