@@ -3,6 +3,7 @@ import * as path from "path";
33import * as ts from "typescript" ;
44import { parseConfigFileWithSystem } from "../cli/tsconfig" ;
55import { CompilerOptions } from "../CompilerOptions" ;
6+ import { normalizeSlashes } from "../utils" ;
67import { createEmitOutputCollector , TranspiledFile } from "./output-collector" ;
78import { EmitResult , Transpiler } from "./transpiler" ;
89
@@ -44,8 +45,12 @@ const libCache: { [key: string]: ts.SourceFile } = {};
4445
4546/** @internal */
4647export function createVirtualProgram ( input : Record < string , string > , options : CompilerOptions = { } ) : ts . Program {
48+ const normalizedFiles : Record < string , string > = { } ;
49+ for ( const [ path , file ] of Object . entries ( input ) ) {
50+ normalizedFiles [ normalizeSlashes ( path ) ] = file ;
51+ }
4752 const compilerHost : ts . CompilerHost = {
48- fileExists : fileName => fileName in input || ts . sys . fileExists ( fileName ) ,
53+ fileExists : fileName => fileName in normalizedFiles || ts . sys . fileExists ( fileName ) ,
4954 getCanonicalFileName : fileName => fileName ,
5055 getCurrentDirectory : ( ) => "" ,
5156 getDefaultLibFileName : ts . getDefaultLibFileName ,
@@ -55,8 +60,8 @@ export function createVirtualProgram(input: Record<string, string>, options: Com
5560 writeFile ( ) { } ,
5661
5762 getSourceFile ( fileName ) {
58- if ( fileName in input ) {
59- return ts . createSourceFile ( fileName , input [ fileName ] , ts . ScriptTarget . Latest , false ) ;
63+ if ( fileName in normalizedFiles ) {
64+ return ts . createSourceFile ( fileName , normalizedFiles [ fileName ] , ts . ScriptTarget . Latest , false ) ;
6065 }
6166
6267 let filePath : string | undefined ;
@@ -80,7 +85,7 @@ export function createVirtualProgram(input: Record<string, string>, options: Com
8085 } ,
8186 } ;
8287
83- return ts . createProgram ( Object . keys ( input ) , options , compilerHost ) ;
88+ return ts . createProgram ( Object . keys ( normalizedFiles ) , options , compilerHost ) ;
8489}
8590
8691export interface TranspileVirtualProjectResult {
0 commit comments