Skip to content

Commit dcd5dca

Browse files
fatfisztleunen
authored andcommitted
fix: Fix path resolution when the alias is not a proper sub path (#177)
1 parent d4d464f commit dcd5dca

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/normalizeOptions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function normalizeAlias(opts) {
8383
opts.alias = aliasKeys.map(key => (
8484
isRegExp(key) ?
8585
getAliasPair(key, alias[key]) :
86-
getAliasPair(`^${key}((?:/|).*)`, `${alias[key]}\\1`)
86+
getAliasPair(`^${key}(/.*|)$`, `${alias[key]}\\1`)
8787
));
8888
} else {
8989
opts.alias = [];

test/index.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ describe('module-resolver', () => {
274274
);
275275
});
276276

277+
it('should not alias if there is no proper sub path', () => {
278+
testWithImport(
279+
'components_dummy',
280+
'components_dummy',
281+
aliasTransformerOpts,
282+
);
283+
});
284+
277285
it('should alias the sub file path', () => {
278286
testWithImport(
279287
'test/tools',
@@ -292,6 +300,14 @@ describe('module-resolver', () => {
292300
);
293301
});
294302

303+
it('should not alias if there is no proper sub path', () => {
304+
testWithImport(
305+
'awesome/componentss',
306+
'awesome/componentss',
307+
aliasTransformerOpts,
308+
);
309+
});
310+
295311
it('should alias the sub file path', () => {
296312
testWithImport(
297313
'awesome/components/Header',

0 commit comments

Comments
 (0)