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:
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
parent5adaa1d26dac48b500d0a592b2be0ee601f6ee79 (diff)
Refactor babel plugin initialization in moduleEnv.js
-rw-r--r--lib/moduleEnv.js15
-rw-r--r--package-lock.json33
2 files changed, 17 insertions, 31 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) {
diff --git a/package-lock.json b/package-lock.json
index 19647ab..ef0eab7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -30,7 +30,7 @@
"integrity": "sha1-rzL3izGm/O8RnIew/Y2XU/A6C7g=",
"requires": {
"babel-code-frame": "6.26.0",
- "babel-generator": "6.26.0",
+ "babel-generator": "6.26.1",
"babel-helpers": "6.24.1",
"babel-messages": "6.23.0",
"babel-register": "6.26.0",
@@ -39,7 +39,7 @@
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
- "convert-source-map": "1.5.0",
+ "convert-source-map": "1.5.1",
"debug": "2.6.9",
"json5": "0.5.1",
"lodash": "4.17.4",
@@ -57,26 +57,13 @@
"requires": {
"ms": "2.0.0"
}
- },
- "minimatch": {
- "version": "3.0.4",
- "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
- "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
- "requires": {
- "brace-expansion": "1.1.8"
- }
- },
- "ms": {
- "version": "2.0.0",
- "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
- "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
}
},
"babel-generator": {
- "version": "6.26.0",
- "resolved": "https://registry.npmjs.org/babel-generator/-/babel-generator-6.26.0.tgz",
- "integrity": "sha1-rBriAHC3n248odMmlhMFN3TyDcU=",
+ "version": "6.26.1",
+ "resolved": "https://registry.npmjs.org/babel-generator/-/babel-generator-6.26.1.tgz",
+ "integrity": "sha512-HyfwY6ApZj7BYTcJURpM5tznulaBvyio7/0d4zFOeMPUmfxkCjHocCuoLa2SAGzBI8AREcH3eP3758F672DppA==",
"requires": {
"babel-messages": "6.23.0",
"babel-runtime": "6.26.0",
@@ -270,9 +257,9 @@
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"convert-source-map": {
- "version": "1.5.0",
- "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.5.0.tgz",
- "integrity": "sha1-ms1whRxtXf3ZPZKC5e35SgP/RrU="
+ "version": "1.5.1",
+ "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.5.1.tgz",
+ "integrity": "sha1-uCeAl7m8IpNl3lxiz1/K7YtVmeU="
},
"core-js": {
"version": "2.5.1",
@@ -442,7 +429,6 @@
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
- "dev": true,
"requires": {
"brace-expansion": "1.1.8"
}
@@ -489,8 +475,7 @@
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
- "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
- "dev": true
+ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"number-is-nan": {
"version": "1.0.1",