diff --git a/src/getRealPath.js b/src/getRealPath.js index 3039da5..6206624 100644 --- a/src/getRealPath.js +++ b/src/getRealPath.js @@ -98,7 +98,7 @@ export default function getRealPath(sourcePath, currentFile, opts) { const { cwd, extensions, pluginOpts } = opts; const rootDirs = pluginOpts.root || []; - const regExps = pluginOpts.regExps || []; + const regExps = pluginOpts.regExps; const alias = pluginOpts.alias || {}; const sourceFileFromRoot = getRealPathFromRootConfig( diff --git a/src/index.js b/src/index.js index 6618dcf..6d09bb9 100644 --- a/src/index.js +++ b/src/index.js @@ -82,15 +82,11 @@ export default ({ types: t }) => { }; return { - manipulateOptions(babelOptions) { - let findPluginOptions = babelOptions.plugins.find(plugin => plugin[0] === this)[1]; - findPluginOptions = manipulatePluginOptions(findPluginOptions); + pre(file) { + manipulatePluginOptions(this.opts); - this.customCWD = findPluginOptions.cwd; - }, + let customCWD = this.opts.cwd; - pre(file) { - let { customCWD } = this.plugin; if (customCWD === 'babelrc') { const startPath = (file.opts.filename === 'unknown') ? './' diff --git a/test/index.test.js b/test/index.test.js index d85e726..892979b 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -435,6 +435,27 @@ describe('module-resolver', () => { ); }); }); + + describe('with the plugin applied twice', () => { + const doubleAliasTransformerOpts = { + plugins: [ + plugin, + [plugin, { + alias: { + '^@namespace/foo-(.+)': 'packages/\\1', + }, + }], + ], + }; + + describe('should support replacing parts of a path', () => { + testRequireImport( + '@namespace/foo-bar', + 'packages/bar', + doubleAliasTransformerOpts, + ); + }); + }); }); describe('with custom cwd', () => {