Skip to content

Commit b0bbb56

Browse files
committed
fix: support alias paths that are start with "./"
1 parent e49f5bb commit b0bbb56

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/rules/alias.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ tester.run('paths-alias', rule, {
5757
errors: ['Update import to @foo/x/y/z'],
5858
output: `import z from '@foo/x/y/z';`,
5959
},
60+
{
61+
name: 'relative named import from alias must be fixed',
62+
filename: path.resolve('./src/nested/index.ts'),
63+
code: `import { x } from '../qux/x/y/z';`,
64+
errors: ['Update import to @qux/x/y/z'],
65+
output: `import { x } from '@qux/x/y/z';`,
66+
},
6067
{
6168
name: 'absolute import from alias must be fixed',
6269
filename: path.resolve('./src/index.ts'),

src/rules/alias.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ function findAlias(
4949
// Remove basedir and slash in start
5050
const slicedImportPath = importPath
5151
.slice(baseDir.length + 1)
52-
.slice(path.dirname(matchedPath).length + 1);
53-
52+
.slice(path.dirname(matchedPath.replace(/^\.\//, '')).length + 1);
5453
// Remove asterisk from end of alias
5554
const replacedPathSegments = path
5655
.join(path.dirname(alias), slicedImportPath)

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"baseUrl": ".",
3434
"paths": {
3535
"@foo/*": ["src/foo/*"],
36-
"@bar/*": ["src/bar/*"]
36+
"@bar/*": ["src/bar/*"],
37+
"@qux/*": ["./src/qux/*"]
3738
}
3839
},
3940
"include": ["src/*.ts", "src/*.tsx", "src/**/*.ts", "src/**/*.tsx"]

0 commit comments

Comments
 (0)