Making babel able to run in node_modules directory (while still ignoring node_modules packages)

In case if app is installed by npm install <git tarball url> which is very comfortable thing (postinstall hooks, automatic package installation and so on) babel is unable to run over packages, e.g.
```
 ~/node_modules/some_app$ node-babel app.js
  ```
 is crashing as babel do not want in node_modules directory.

 relative path gives ability to check whether lib is in node_modules _relative_ to current app, so that if app is ran in node_modules by itself it will not be captured.
This commit is contained in:
Vsevolod Rodionov 2015-06-01 11:46:25 -07:00
parent b1273cb774
commit e66109f9d0

View File

@ -6,6 +6,7 @@ import * as babel from "../node";
import each from "lodash/collection/each";
import * as util from "../../util";
import fs from "fs";
import path from "path";
sourceMapSupport.install({
handleUncaughtExceptions: false,
@ -37,6 +38,12 @@ var only;
var oldHandlers = {};
var maps = {};
var cwd = require.main ? require.main.filename : process.cwd();
var getRelativePath = function (filename){
return path.relative(cwd, filename);
};
var mtime = function (filename) {
return +fs.statSync(filename).mtime;
};
@ -81,7 +88,7 @@ var compile = function (filename) {
var shouldIgnore = function (filename) {
if (!ignore && !only) {
return /node_modules/.test(filename);
return /node_modules/.test(getRelativePath(filename));
} else {
return util.shouldIgnore(filename, ignore || [], only || []);
}