diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 31b464b81cea4..b4ef62c6c3e22 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2330,7 +2330,9 @@ namespace ts { export function getSourceFilePathInNewDir(sourceFile: SourceFile, host: EmitHost, newDirPath: string) { let sourceFilePath = getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); - sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), ""); + const commonSourceDirectory = host.getCommonSourceDirectory(); + const isSourceFileInCommonSourceDirectory = host.getCanonicalFileName(sourceFilePath).indexOf(host.getCanonicalFileName(commonSourceDirectory)) === 0; + sourceFilePath = isSourceFileInCommonSourceDirectory ? sourceFilePath.substring(commonSourceDirectory.length) : sourceFilePath; return combinePaths(newDirPath, sourceFilePath); }