@@ -522,40 +522,21 @@ namespace ts {
522522 }
523523 }
524524
525- function recursiveCreateDirectory ( directoryPath : string , sys : System ) {
526- const basePath = getDirectoryPath ( directoryPath ) ;
527- const shouldCreateParent = basePath !== "" && directoryPath !== basePath && ! sys . directoryExists ( basePath ) ;
528- if ( shouldCreateParent ) {
529- recursiveCreateDirectory ( basePath , sys ) ;
530- }
531- if ( shouldCreateParent || ! sys . directoryExists ( directoryPath ) ) {
532- sys . createDirectory ( directoryPath ) ;
533- }
534- }
535-
536525 /**
537526 * patch writefile to create folder before writing the file
538527 */
539528 /*@internal */
540529 export function patchWriteFileEnsuringDirectory ( sys : System ) {
541530 // patch writefile to create folder before writing the file
542531 const originalWriteFile = sys . writeFile ;
543- sys . writeFile = ( path , data , writeBom ) => {
544- // PERF: Checking for directory existence is expensive.
545- // Instead, assume the directory exists and fall back
546- // to creating it if the file write fails.
547- try {
548- originalWriteFile . call ( sys , path , data , writeBom ) ;
549- }
550- catch {
551- const directoryPath = getDirectoryPath ( normalizeSlashes ( path ) ) ;
552- if ( directoryPath && ! sys . directoryExists ( directoryPath ) ) {
553- recursiveCreateDirectory ( directoryPath , sys ) ;
554- }
555-
556- originalWriteFile . call ( sys , path , data , writeBom ) ;
557- }
558- } ;
532+ sys . writeFile = ( path , data , writeBom ) =>
533+ writeFileEnsuringDirectories (
534+ path ,
535+ data ,
536+ writeBom ,
537+ ( p , d , w ) => originalWriteFile . call ( sys , p , d , w ) ,
538+ sys . createDirectory ,
539+ sys . directoryExists ) ;
559540 }
560541
561542 /*@internal */
0 commit comments