Skip to content

Commit 85270e1

Browse files
author
Tommy Leunen
committed
feat: Export manipulateOptions
1 parent 1bff74f commit 85270e1

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

src/index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ export function mapModule(sourcePath, currentFile, pluginOpts, cwd) {
1818
extensions: pluginOpts.extensions || defaultExtensions,
1919
});
2020
}
21+
export function manipulatePluginOptions(pluginOpts) {
22+
if (pluginOpts.root) {
23+
// eslint-disable-next-line no-param-reassign
24+
pluginOpts.root = pluginOpts.root.reduce((resolvedDirs, dirPath) => {
25+
if (glob.hasMagic(dirPath)) {
26+
return resolvedDirs.concat(glob.sync(dirPath));
27+
}
28+
return resolvedDirs.concat(dirPath);
29+
}, []);
30+
}
31+
32+
return pluginOpts;
33+
}
2134

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

123136
return {
124137
manipulateOptions(babelOptions) {
125-
const findPluginOptions = babelOptions.plugins.find(plugin => plugin[0] === this)[1];
126-
if (findPluginOptions.root) {
127-
findPluginOptions.root = findPluginOptions.root.reduce((resolvedDirs, dirPath) => {
128-
if (glob.hasMagic(dirPath)) {
129-
return resolvedDirs.concat(glob.sync(dirPath));
130-
}
131-
return resolvedDirs.concat(dirPath);
132-
}, []);
133-
}
138+
let findPluginOptions = babelOptions.plugins.find(plugin => plugin[0] === this)[1];
139+
findPluginOptions = manipulatePluginOptions(findPluginOptions);
134140

135141
this.customCWD = findPluginOptions.cwd;
136142
},

0 commit comments

Comments
 (0)