diff --git a/src/normalizeOptions.js b/src/normalizeOptions.js index 51f7ce1..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 = []; 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',