Merge pull request #3350 from skevy/fix-babelrc-plugin-resolution
Make Babel actually resolve plugins relative to where they were specified (via .babelrc).
This commit is contained in:
commit
f4197cc77b
@ -1,4 +1,5 @@
|
||||
import Module from "module";
|
||||
import path from "path";
|
||||
|
||||
let relativeModules = {};
|
||||
|
||||
@ -10,6 +11,17 @@ export default function (loc: string, relative: string = process.cwd()): ?string
|
||||
|
||||
if (!relativeMod) {
|
||||
relativeMod = new Module;
|
||||
|
||||
// We need to define an id and filename on our "fake" relative` module so that
|
||||
// Node knows what "." means in the case of us trying to resolve a plugin
|
||||
// such as "./myPlugins/somePlugin.js". If we don't specify id and filename here,
|
||||
// Node presumes "." is process.cwd(), not our relative path.
|
||||
// Since this fake module is never "loaded", we don't have to worry about mutating
|
||||
// any global Node module cache state here.
|
||||
let filename = path.join(relative, ".babelrc");
|
||||
relativeMod.id = filename;
|
||||
relativeMod.filename = filename;
|
||||
|
||||
relativeMod.paths = Module._nodeModulePaths(relative);
|
||||
relativeModules[relative] = relativeMod;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user