Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohannes Ewald <johannes.ewald@peerigon.com>2018-04-09 18:53:21 +0300
committerJohannes Ewald <johannes.ewald@peerigon.com>2018-04-09 18:53:21 +0300
commitcbb2802ea5e30b47003298f2756c62ce20b41bb0 (patch)
treefbafd7b78ce9ca5b9516f4a660fe66ff0ab22b7f /lib
parent5adaa1d26dac48b500d0a592b2be0ee601f6ee79 (diff)
Refactor babel plugin initialization in moduleEnv.js
Diffstat (limited to 'lib')
-rw-r--r--lib/moduleEnv.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/moduleEnv.js b/lib/moduleEnv.js
index cbd5e25..6754273 100644
--- a/lib/moduleEnv.js
+++ b/lib/moduleEnv.js
@@ -3,14 +3,15 @@
var Module = require("module"),
fs = require("fs"),
babelCore = require("babel-core"),
- // Requiring the babel plugin here because otherwise it will be lazy-loaded by Babel during rewire()
- transformBlockScoping = require("babel-plugin-transform-es2015-block-scoping"),
coffee;
var moduleWrapper0 = Module.wrapper[0],
moduleWrapper1 = Module.wrapper[1],
originalExtensions = {},
- matchCoffeeExt = /\.coffee$/,
+ babelPlugins = [
+ "babel-plugin-transform-es2015-block-scoping",
+ "babel-plugin-transform-object-rest-spread"
+ ],
nodeRequire,
currentModule;
@@ -76,10 +77,7 @@ function jsExtension(module, filename) {
module._compile = function (content, filename) {
content = babelCore.transform(content, {
- plugins: [
- require.resolve("babel-plugin-transform-es2015-block-scoping"),
- require.resolve("babel-plugin-transform-object-rest-spread")
- ],
+ plugins: babelPlugins,
retainLines: true,
filename: filename,
babelrc: false
@@ -115,6 +113,9 @@ function stripBOM(content) {
return content;
}
+// Prepopulate require.cache with babel plugins because otherwise it will be lazy-loaded by Babel during rewire()
+babelPlugins.forEach(require);
+
try {
coffee = require("coffee-script");
} catch (err) {