@@ -17,7 +17,7 @@ namespace ts.moduleSpecifiers {
17
17
redirectTargetsMap : RedirectTargetsMap ,
18
18
) : string {
19
19
const info = getInfo ( compilerOptions , importingSourceFile , importingSourceFileName , host ) ;
20
- const modulePaths = getAllModulePaths ( files , toFileName , info . getCanonicalFileName , host , redirectTargetsMap ) ;
20
+ const modulePaths = getAllModulePaths ( files , importingSourceFileName , toFileName , info . getCanonicalFileName , host , redirectTargetsMap ) ;
21
21
return firstDefined ( modulePaths , moduleFileName => getGlobalModuleSpecifier ( moduleFileName , info , host , compilerOptions ) ) ||
22
22
first ( getLocalModuleSpecifiers ( toFileName , info , compilerOptions , preferences ) ) ;
23
23
}
@@ -40,7 +40,7 @@ namespace ts.moduleSpecifiers {
40
40
return Debug . fail ( "Files list must be present to resolve symlinks in specifier resolution" ) ;
41
41
}
42
42
const moduleSourceFile = getSourceFileOfNode ( moduleSymbol . valueDeclaration ) ;
43
- const modulePaths = getAllModulePaths ( files , moduleSourceFile . fileName , info . getCanonicalFileName , host , redirectTargetsMap ) ;
43
+ const modulePaths = getAllModulePaths ( files , importingSourceFile . path , moduleSourceFile . fileName , info . getCanonicalFileName , host , redirectTargetsMap ) ;
44
44
45
45
const global = mapDefined ( modulePaths , moduleFileName => getGlobalModuleSpecifier ( moduleFileName , info , host , compilerOptions ) ) ;
46
46
return global . length ? global . map ( g => [ g ] ) : modulePaths . map ( moduleFileName =>
@@ -176,7 +176,7 @@ namespace ts.moduleSpecifiers {
176
176
* Looks for existing imports that use symlinks to this module.
177
177
* Symlinks will be returned first so they are preferred over the real path.
178
178
*/
179
- function getAllModulePaths ( files : ReadonlyArray < SourceFile > , importedFileName : string , getCanonicalFileName : ( file : string ) => string , host : ModuleSpecifierResolutionHost , redirectTargetsMap : RedirectTargetsMap ) : ReadonlyArray < string > {
179
+ function getAllModulePaths ( files : ReadonlyArray < SourceFile > , importingFileName : string , importedFileName : string , getCanonicalFileName : GetCanonicalFileName , host : ModuleSpecifierResolutionHost , redirectTargetsMap : RedirectTargetsMap ) : ReadonlyArray < string > {
180
180
const redirects = redirectTargetsMap . get ( importedFileName ) ;
181
181
const importedFileNames = redirects ? [ ...redirects , importedFileName ] : [ importedFileName ] ;
182
182
const cwd = host . getCurrentDirectory ? host . getCurrentDirectory ( ) : "" ;
@@ -186,6 +186,10 @@ namespace ts.moduleSpecifiers {
186
186
const result : string [ ] = [ ] ;
187
187
const compareStrings = ( ! host . useCaseSensitiveFileNames || host . useCaseSensitiveFileNames ( ) ) ? compareStringsCaseSensitive : compareStringsCaseInsensitive ;
188
188
links . forEach ( ( resolved , path ) => {
189
+ if ( startsWithDirectory ( importingFileName , resolved , getCanonicalFileName ) ) {
190
+ return ; // Don't want to a package to globally import from itself
191
+ }
192
+
189
193
const target = targets . find ( t => compareStrings ( t . slice ( 0 , resolved . length + 1 ) , resolved + "/" ) === Comparison . EqualTo ) ;
190
194
if ( target === undefined ) return ;
191
195
0 commit comments