@@ -285,12 +285,12 @@ function computeModuleSpecifiers(
285
285
return nodeModulesSpecifiers ! ;
286
286
}
287
287
288
- if ( ! specifier && ! modulePath . isRedirect ) {
288
+ if ( ! specifier ) {
289
289
const local = getLocalModuleSpecifier ( modulePath . path , info , compilerOptions , host , options . overrideImportMode || importingSourceFile . impliedNodeFormat , preferences ) ;
290
290
if ( pathIsBareSpecifier ( local ) ) {
291
291
pathsSpecifiers = append ( pathsSpecifiers , local ) ;
292
292
}
293
- else if ( ! importedFileIsInNodeModules || modulePath . isInNodeModules ) {
293
+ else if ( ! modulePath . isRedirect && ( ! importedFileIsInNodeModules || modulePath . isInNodeModules ) ) {
294
294
// Why this extra conditional, not just an `else`? If some path to the file contained
295
295
// 'node_modules', but we can't create a non-relative specifier (e.g. "@foo/bar/path/to/file"),
296
296
// that means we had to go through a *sibling's* node_modules, not one we can access directly.
@@ -338,16 +338,16 @@ function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOpt
338
338
}
339
339
340
340
const fromPaths = paths && tryGetModuleNameFromPaths ( relativeToBaseUrl , paths , getAllowedEndings ( ending , compilerOptions , importMode ) , host , compilerOptions ) ;
341
- const nonRelative = fromPaths === undefined && baseUrl !== undefined ? removeExtensionAndIndexPostFix ( relativeToBaseUrl , ending , compilerOptions ) : fromPaths ;
342
- if ( ! nonRelative ) {
341
+ const maybeNonRelative = fromPaths === undefined && baseUrl !== undefined ? removeExtensionAndIndexPostFix ( relativeToBaseUrl , ending , compilerOptions ) : fromPaths ;
342
+ if ( ! maybeNonRelative ) {
343
343
return relativePath ;
344
344
}
345
345
346
- if ( relativePreference === RelativePreference . NonRelative ) {
347
- return nonRelative ;
346
+ if ( relativePreference === RelativePreference . NonRelative && ! pathIsRelative ( maybeNonRelative ) ) {
347
+ return maybeNonRelative ;
348
348
}
349
349
350
- if ( relativePreference === RelativePreference . ExternalNonRelative ) {
350
+ if ( relativePreference === RelativePreference . ExternalNonRelative && ! pathIsRelative ( maybeNonRelative ) ) {
351
351
const projectDirectory = compilerOptions . configFilePath ?
352
352
toPath ( getDirectoryPath ( compilerOptions . configFilePath ) , host . getCurrentDirectory ( ) , info . getCanonicalFileName ) :
353
353
info . getCanonicalFileName ( host . getCurrentDirectory ( ) ) ;
@@ -363,7 +363,7 @@ function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOpt
363
363
// lib/ | (path crosses tsconfig.json)
364
364
// imported.ts <---
365
365
//
366
- return nonRelative ;
366
+ return maybeNonRelative ;
367
367
}
368
368
369
369
const nearestTargetPackageJson = getNearestAncestorDirectoryWithPackageJson ( host , getDirectoryPath ( modulePath ) ) ;
@@ -378,16 +378,14 @@ function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOpt
378
378
// package.json |
379
379
// component.ts <---
380
380
//
381
- return nonRelative ;
381
+ return maybeNonRelative ;
382
382
}
383
383
384
384
return relativePath ;
385
385
}
386
386
387
- if ( relativePreference !== RelativePreference . Shortest ) Debug . assertNever ( relativePreference ) ;
388
-
389
387
// Prefer a relative import over a baseUrl import if it has fewer components.
390
- return isPathRelativeToParent ( nonRelative ) || countPathComponents ( relativePath ) < countPathComponents ( nonRelative ) ? relativePath : nonRelative ;
388
+ return isPathRelativeToParent ( maybeNonRelative ) || countPathComponents ( relativePath ) < countPathComponents ( maybeNonRelative ) ? relativePath : maybeNonRelative ;
391
389
}
392
390
393
391
/** @internal */
0 commit comments