Skip to content

Commit 5fdada0

Browse files
committed
fix: don't try to resolve relative paths where the path alias was a partial match
Fixes #10.
1 parent 9533a45 commit 5fdada0

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const typescriptPaths = ({
1818
}
1919

2020
const hasMatchingPath = Object.keys(compilerOptions.paths).some((path) =>
21-
new RegExp(path.replace('*', '\\w*')).test(importee),
21+
new RegExp('^' + path.replace('*', '.+') + '$').test(importee),
2222
);
2323

2424
if (!hasMatchingPath) {

test/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ try {
3434
// works with a directory with index file
3535
strictEqual(plugin.resolveId('@js', ''), join(__dirname, 'js', 'index.js'));
3636

37+
// works without the `@` prefix
38+
strictEqual(plugin.resolveId('bar/foo', ''), join(__dirname, 'bar', 'foo.js'));
39+
40+
// works with a different importer
41+
strictEqual(plugin.resolveId('bar/foo', join(__dirname, 'foo', 'bar.ts')), join(__dirname, 'bar', 'foo.js'));
42+
43+
// doesn't accidentally resolve relative paths that also have an alias
44+
strictEqual(plugin.resolveId('../bar/foo', join(__dirname, 'foo', 'bar.ts')), null);
45+
3746
// returns relative paths with option `absolute: false`
3847
strictEqual(pluginNonAbs.resolveId('@foobar', ''), join('test', 'foo', 'bar.js'));
3948

test/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"@foobar": ["foo/bar"],
77
"@foobar-react": ["foo/bar-react"],
88
"@bar/*": ["bar/*"],
9+
"bar/*": ["bar/*"],
910
"@js": ["js"]
1011
}
1112
}

0 commit comments

Comments
 (0)