From 7aada32e97cba62784c5ada13db5d686f7d9d9ef Mon Sep 17 00:00:00 2001 From: fatfisz Date: Tue, 16 May 2017 00:11:20 +0200 Subject: [PATCH 1/2] Fix a case when the alias is not a proper sub path --- src/normalizeOptions.js | 2 +- test/index.test.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/normalizeOptions.js b/src/normalizeOptions.js index 51f7ce1..d02cbc4 100644 --- a/src/normalizeOptions.js +++ b/src/normalizeOptions.js @@ -83,7 +83,7 @@ function normalizeAlias(opts) { opts.alias = aliasKeys.map(key => ( isRegExp(key) ? getAliasPair(key, alias[key]) : - getAliasPair(`^${key}((?:/|).*)`, `${alias[key]}\\1`) + getAliasPair(`^${key}((?:/|$).*)`, `${alias[key]}\\1`) )); } else { opts.alias = []; diff --git a/test/index.test.js b/test/index.test.js index 395eac9..a0dc88f 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -274,6 +274,14 @@ describe('module-resolver', () => { ); }); + it('should not alias if there is no proper sub path', () => { + testWithImport( + 'components_dummy', + 'components_dummy', + aliasTransformerOpts, + ); + }); + it('should alias the sub file path', () => { testWithImport( 'test/tools', @@ -292,6 +300,14 @@ describe('module-resolver', () => { ); }); + it('should not alias if there is no proper sub path', () => { + testWithImport( + 'awesome/componentss', + 'awesome/componentss', + aliasTransformerOpts, + ); + }); + it('should alias the sub file path', () => { testWithImport( 'awesome/components/Header', From 41d9744e27ef6f3bee34892da2e827bf9cf06f69 Mon Sep 17 00:00:00 2001 From: fatfisz Date: Tue, 16 May 2017 00:15:21 +0200 Subject: [PATCH 2/2] Simplify the alias regular expression --- src/normalizeOptions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/normalizeOptions.js b/src/normalizeOptions.js index d02cbc4..88e08df 100644 --- a/src/normalizeOptions.js +++ b/src/normalizeOptions.js @@ -83,7 +83,7 @@ function normalizeAlias(opts) { opts.alias = aliasKeys.map(key => ( isRegExp(key) ? getAliasPair(key, alias[key]) : - getAliasPair(`^${key}((?:/|$).*)`, `${alias[key]}\\1`) + getAliasPair(`^${key}(/.*|)$`, `${alias[key]}\\1`) )); } else { opts.alias = [];