diff --git a/packages/babel-core/src/transformation/file/options/option-manager.js b/packages/babel-core/src/transformation/file/options/option-manager.js index f4b25206bcc5..4746260a3685 100644 --- a/packages/babel-core/src/transformation/file/options/option-manager.js +++ b/packages/babel-core/src/transformation/file/options/option-manager.js @@ -299,7 +299,7 @@ export default class OptionManager { (presetLoc || "a preset") + " which does not accept options."); } - if (typeof val === "function") val = val(context, options); + if (typeof val === "function") val = val(context, options, { dirname }); if (typeof val !== "object") { throw new Error(`Unsupported preset format: ${val}.`); diff --git a/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js b/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js index a1af16e41fac..e08f4b1c612d 100644 --- a/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js +++ b/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js @@ -1,5 +1,10 @@ -module.exports = { - plugins: [plugin], +module.exports = function preset (context, options, fileContext) { + if (/resolve-addons-relative-to-file$/.test(fileContext.dirname)) { + return { + plugins: [plugin], + }; + } + return {}; }; function plugin () {