@@ -5,6 +5,17 @@ import mapToRelative from './mapToRelative';
55import normalizeOptions from './normalizeOptions' ;
66import { nodeResolvePath , replaceExtension , toLocalPath , toPosixPath } from './utils' ;
77
8+ function getRelativePath ( sourcePath , currentFile , absFileInRoot , opts ) {
9+ const realSourceFileExtension = path . extname ( absFileInRoot ) ;
10+ const sourceFileExtension = path . extname ( sourcePath ) ;
11+
12+ let relativePath = mapToRelative ( opts . cwd , currentFile , absFileInRoot ) ;
13+ if ( realSourceFileExtension !== sourceFileExtension ) {
14+ relativePath = replaceExtension ( relativePath , opts ) ;
15+ }
16+
17+ return toLocalPath ( toPosixPath ( relativePath ) ) ;
18+ }
819
920function findPathInRoots ( sourcePath , { extensions, root } ) {
1021 // Search the source path inside every custom root directory
@@ -25,16 +36,7 @@ function resolvePathFromRootConfig(sourcePath, currentFile, opts) {
2536 return null ;
2637 }
2738
28- const realSourceFileExtension = path . extname ( absFileInRoot ) ;
29- const sourceFileExtension = path . extname ( sourcePath ) ;
30-
31- // Map the source and keep its extension if the import/require had one
32- const ext = realSourceFileExtension === sourceFileExtension ? realSourceFileExtension : '' ;
33- return toLocalPath ( toPosixPath ( replaceExtension (
34- mapToRelative ( opts . cwd , currentFile , absFileInRoot ) ,
35- ext ,
36- opts ,
37- ) ) ) ;
39+ return getRelativePath ( sourcePath , currentFile , absFileInRoot , opts ) ;
3840}
3941
4042function checkIfPackageExists ( modulePath , currentFile , extensions ) {
0 commit comments