Skip to content

Commit fa6d94e

Browse files
relignsongruigang
andauthored
fix: . and ./ incorrectly converted (#409)
* fix: `.` and `./` incorrectly converted * fix: supplementary test cases --------- Co-authored-by: songruigang <songruigang@meituan.com>
1 parent 6131552 commit fa6d94e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/resolvePath.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ function resolvePathFromAliasConfig(sourcePath, currentFile, opts) {
9797
const resolvers = [resolvePathFromAliasConfig, resolvePathFromRootConfig];
9898

9999
export default function resolvePath(sourcePath, currentFile, opts) {
100-
if (isRelativePath(sourcePath)) {
100+
// `.` and `./` are specific paths, we can't transfrom them
101+
if (isRelativePath(sourcePath) || sourcePath === '.' || sourcePath === './') {
101102
return sourcePath;
102103
}
103104

test/index.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ describe('module-resolver', () => {
2525

2626
expect(result).toBe('./app');
2727
});
28+
29+
it('should not change a single dot import', () => {
30+
const opts = {
31+
root: ['./test/testproject/src/components'],
32+
};
33+
const result = resolvePath('.', './test/testproject/src/components/SideBar/Footer', opts);
34+
35+
expect(result).toBe('.');
36+
});
2837
});
2938
});
3039

0 commit comments

Comments
 (0)