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
diff options
context:
space:
mode:
Diffstat (limited to 'lib/moduleEnv.js')
-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) {