Skip to content

Commit 4e19188

Browse files
fatfisztleunen
authored andcommitted
fix: Fix the double plugin bug (#146)
1 parent ed54855 commit 4e19188

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

src/getRealPath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default function getRealPath(sourcePath, currentFile, opts) {
9898

9999
const { cwd, extensions, pluginOpts } = opts;
100100
const rootDirs = pluginOpts.root || [];
101-
const regExps = pluginOpts.regExps || [];
101+
const regExps = pluginOpts.regExps;
102102
const alias = pluginOpts.alias || {};
103103

104104
const sourceFileFromRoot = getRealPathFromRootConfig(

src/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,11 @@ export default ({ types: t }) => {
8282
};
8383

8484
return {
85-
manipulateOptions(babelOptions) {
86-
let findPluginOptions = babelOptions.plugins.find(plugin => plugin[0] === this)[1];
87-
findPluginOptions = manipulatePluginOptions(findPluginOptions);
85+
pre(file) {
86+
manipulatePluginOptions(this.opts);
8887

89-
this.customCWD = findPluginOptions.cwd;
90-
},
88+
let customCWD = this.opts.cwd;
9189

92-
pre(file) {
93-
let { customCWD } = this.plugin;
9490
if (customCWD === 'babelrc') {
9591
const startPath = (file.opts.filename === 'unknown')
9692
? './'

test/index.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,27 @@ describe('module-resolver', () => {
435435
);
436436
});
437437
});
438+
439+
describe('with the plugin applied twice', () => {
440+
const doubleAliasTransformerOpts = {
441+
plugins: [
442+
plugin,
443+
[plugin, {
444+
alias: {
445+
'^@namespace/foo-(.+)': 'packages/\\1',
446+
},
447+
}],
448+
],
449+
};
450+
451+
describe('should support replacing parts of a path', () => {
452+
testRequireImport(
453+
'@namespace/foo-bar',
454+
'packages/bar',
455+
doubleAliasTransformerOpts,
456+
);
457+
});
458+
});
438459
});
439460

440461
describe('with custom cwd', () => {

0 commit comments

Comments
 (0)