Skip to content

Commit

Permalink
fix: Fix the double plugin bug (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatfisz authored and tleunen committed Mar 30, 2017
1 parent ed54855 commit 4e19188
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/getRealPath.js
Expand Up @@ -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(
Expand Down
10 changes: 3 additions & 7 deletions src/index.js
Expand Up @@ -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')
? './'
Expand Down
21 changes: 21 additions & 0 deletions test/index.test.js
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 4e19188

Please sign in to comment.