Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the double plugin bug #146

Merged
merged 1 commit into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/getRealPath.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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