@@ -17,20 +17,24 @@ function getRelativePath(sourcePath, currentFile, absFileInRoot, opts) {
1717 return toLocalPath ( toPosixPath ( relativePath ) ) ;
1818}
1919
20- function findPathInRoots ( sourcePath , { extensions, root } ) {
20+ function findPathInRoots ( sourcePath , { extensions, root } , { isModulePath } ) {
2121 // Search the source path inside every custom root directory
2222 let resolvedSourceFile ;
2323
2424 root . some ( ( basedir ) => {
25- resolvedSourceFile = nodeResolvePath ( `./${ sourcePath } ` , basedir , extensions ) ;
25+ if ( isModulePath ) {
26+ resolvedSourceFile = nodeResolvePath ( `./${ sourcePath } ` , basedir , extensions ) ;
27+ } else {
28+ resolvedSourceFile = path . resolve ( basedir , `./${ sourcePath } ` ) ;
29+ }
2630 return resolvedSourceFile !== null ;
2731 } ) ;
2832
2933 return resolvedSourceFile ;
3034}
3135
32- function resolvePathFromRootConfig ( sourcePath , currentFile , opts ) {
33- const absFileInRoot = findPathInRoots ( sourcePath , opts ) ;
36+ function resolvePathFromRootConfig ( sourcePath , currentFile , opts , resolveOpts ) {
37+ const absFileInRoot = findPathInRoots ( sourcePath , opts , resolveOpts ) ;
3438
3539 if ( ! absFileInRoot ) {
3640 return null ;
@@ -46,7 +50,7 @@ function checkIfPackageExists(modulePath, currentFile, extensions, loglevel) {
4650 }
4751}
4852
49- function resolvePathFromAliasConfig ( sourcePath , currentFile , opts ) {
53+ function resolvePathFromAliasConfig ( sourcePath , currentFile , opts , { isModulePath = true } = { } ) {
5054 let aliasedSourceFile ;
5155
5256 opts . alias . find ( ( [ regExp , substitute ] ) => {
@@ -73,7 +77,10 @@ function resolvePathFromAliasConfig(sourcePath, currentFile, opts) {
7377 }
7478 return asf ;
7579 } )
76- . find ( src => nodeResolvePath ( src , path . dirname ( currentFile ) , opts . extensions ) ) ;
80+ . find ( src => {
81+ return ! isModulePath
82+ || nodeResolvePath ( src , path . dirname ( currentFile ) , opts . extensions ) ;
83+ } ) ;
7784 }
7885
7986 if ( isRelativePath ( aliasedSourceFile ) ) {
@@ -82,7 +89,7 @@ function resolvePathFromAliasConfig(sourcePath, currentFile, opts) {
8289 ) ;
8390 }
8491
85- if ( process . env . NODE_ENV !== 'production' ) {
92+ if ( isModulePath && process . env . NODE_ENV !== 'production' ) {
8693 checkIfPackageExists ( aliasedSourceFile , currentFile , opts . extensions , opts . loglevel ) ;
8794 }
8895
@@ -94,7 +101,9 @@ const resolvers = [
94101 resolvePathFromRootConfig ,
95102] ;
96103
97- export default function resolvePath ( sourcePath , currentFile , opts ) {
104+ export default function resolvePath (
105+ sourcePath , currentFile , opts , { isModulePath = true } = { } ,
106+ ) {
98107 if ( isRelativePath ( sourcePath ) ) {
99108 return sourcePath ;
100109 }
@@ -107,7 +116,8 @@ export default function resolvePath(sourcePath, currentFile, opts) {
107116 let resolvedPath = null ;
108117
109118 resolvers . some ( ( resolver ) => {
110- resolvedPath = resolver ( sourcePath , absoluteCurrentFile , normalizedOpts ) ;
119+ resolvedPath = resolver (
120+ sourcePath , absoluteCurrentFile , normalizedOpts , { isModulePath } ) ;
111121 return resolvedPath !== null ;
112122 } ) ;
113123
0 commit comments