Skip to content

Commit

Permalink
feat: Export manipulateOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy Leunen committed Dec 23, 2016
1 parent 1bff74f commit 85270e1
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/index.js
Expand Up @@ -18,6 +18,19 @@ export function mapModule(sourcePath, currentFile, pluginOpts, cwd) {
extensions: pluginOpts.extensions || defaultExtensions,
});
}
export function manipulatePluginOptions(pluginOpts) {
if (pluginOpts.root) {
// eslint-disable-next-line no-param-reassign
pluginOpts.root = pluginOpts.root.reduce((resolvedDirs, dirPath) => {
if (glob.hasMagic(dirPath)) {
return resolvedDirs.concat(glob.sync(dirPath));
}
return resolvedDirs.concat(dirPath);
}, []);
}

return pluginOpts;
}

export default ({ types: t }) => {
function transformRequireCall(nodePath, state, cwd) {
Expand Down Expand Up @@ -122,15 +135,8 @@ export default ({ types: t }) => {

return {
manipulateOptions(babelOptions) {
const findPluginOptions = babelOptions.plugins.find(plugin => plugin[0] === this)[1];
if (findPluginOptions.root) {
findPluginOptions.root = findPluginOptions.root.reduce((resolvedDirs, dirPath) => {
if (glob.hasMagic(dirPath)) {
return resolvedDirs.concat(glob.sync(dirPath));
}
return resolvedDirs.concat(dirPath);
}, []);
}
let findPluginOptions = babelOptions.plugins.find(plugin => plugin[0] === this)[1];
findPluginOptions = manipulatePluginOptions(findPluginOptions);

this.customCWD = findPluginOptions.cwd;
},
Expand Down

0 comments on commit 85270e1

Please sign in to comment.