make base option plugin/preset resolving happen relative to the input filename

This commit is contained in:
Sebastian McKenzie 2015-11-18 20:31:59 -08:00
parent 89d9db8648
commit 8fd543edae
2 changed files with 11 additions and 8 deletions

View File

@ -324,14 +324,16 @@ export default class OptionManager {
}
}
init(opts: Object): Object {
init(opts: Object = {}): Object {
let filename = opts.filename;
// resolve all .babelrc files
if (opts.babelrc !== false) {
this.findConfigs(opts.filename);
this.findConfigs(filename);
}
// merge in base options
this.mergeOptions(opts, "base");
this.mergeOptions(opts, "base", null, filename && path.dirname(filename));
// normalise
this.normaliseOptions(opts);

View File

@ -46,14 +46,15 @@ function mtime(filename) {
return +fs.statSync(filename).mtime;
}
function compile(filename, opts = {}) {
function compile(filename) {
let result;
opts.filename = filename;
let optsManager = new OptionManager;
optsManager.mergeOptions(deepClone(transformOpts));
opts = optsManager.init(opts);
// merge in base options and resolve all the plugins and presets relative to this file
optsManager.mergeOptions(deepClone(transformOpts), "base", null, path.dirname(filename));
let opts = optsManager.init({ filename });
let cacheKey = `${JSON.stringify(opts)}:${babel.version}`;