@@ -888,7 +888,7 @@ namespace ts {
888888
889889 function computeCommonSourceDirectory ( sourceFiles : SourceFile [ ] ) : string {
890890 let commonPathComponents : string [ ] ;
891- forEach ( files , sourceFile => {
891+ const failed = forEach ( files , sourceFile => {
892892 // Each file contributes into common source file path
893893 if ( isDeclarationFile ( sourceFile ) ) {
894894 return ;
@@ -903,11 +903,12 @@ namespace ts {
903903 return ;
904904 }
905905
906+ const caseSensitive = host . useCaseSensitiveFileNames ( ) ;
906907 for ( let i = 0 , n = Math . min ( commonPathComponents . length , sourcePathComponents . length ) ; i < n ; i ++ ) {
907- if ( commonPathComponents [ i ] !== sourcePathComponents [ i ] ) {
908+ if ( caseSensitive ? commonPathComponents [ i ] !== sourcePathComponents [ i ] : commonPathComponents [ i ] . toLocaleLowerCase ( ) !== sourcePathComponents [ i ] . toLocaleLowerCase ( ) ) {
908909 if ( i === 0 ) {
909- programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_find_the_common_subdirectory_path_for_the_input_files ) ) ;
910- return ;
910+ // Failed to find any common path component
911+ return true ;
911912 }
912913
913914 // New common path found that is 0 -> i-1
@@ -922,6 +923,11 @@ namespace ts {
922923 }
923924 } ) ;
924925
926+ // A common path can not be found when paths span multiple drives on windows, for example
927+ if ( failed ) {
928+ return "" ;
929+ }
930+
925931 if ( ! commonPathComponents ) { // Can happen when all input files are .d.ts files
926932 return currentDirectory ;
927933 }
@@ -1045,6 +1051,10 @@ namespace ts {
10451051 else {
10461052 // Compute the commonSourceDirectory from the input files
10471053 commonSourceDirectory = computeCommonSourceDirectory ( files ) ;
1054+ // If we failed to find a good common directory, but outDir is specified and at least one of our files is on a windows drive/URL/other resource, add a failure
1055+ if ( options . outDir && commonSourceDirectory === "" && forEach ( files , file => getRootLength ( file . fileName ) > 1 ) ) {
1056+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_find_the_common_subdirectory_path_for_the_input_files ) ) ;
1057+ }
10481058 }
10491059
10501060 if ( commonSourceDirectory && commonSourceDirectory [ commonSourceDirectory . length - 1 ] !== directorySeparator ) {
0 commit comments