@@ -3,7 +3,6 @@ import * as child_process from "child_process";
33import * as semver from "semver" ;
44import * as _ from "lodash" ;
55// TODO: can switch to file-system service
6- import { mkdirSync , readdirSync , existsSync , copyFileSync , rmSync } from "fs" ;
76import { EventEmitter } from "events" ;
87import { performanceLog } from "../../common/decorators" ;
98import {
@@ -868,19 +867,19 @@ export class BundlerCompilerService
868867 }
869868
870869 // Ensure destination directory exists
871- mkdirSync ( destDir , { recursive : true } ) ;
870+ this . $fs . createDirectory ( destDir ) ;
872871
873872 // Copy only the specified files
874873 for ( const file of specificFiles ) {
875874 const srcPath = path . join ( distOutput , file ) ;
876875 const destPath = path . join ( destDir , file ) ;
877876
878- if ( ! existsSync ( srcPath ) ) continue ;
877+ if ( ! this . $fs . exists ( srcPath ) ) continue ;
879878
880879 // create parent dirs
881- mkdirSync ( path . dirname ( destPath ) , { recursive : true } ) ;
880+ this . $fs . createDirectory ( path . dirname ( destPath ) ) ;
882881
883- copyFileSync ( srcPath , destPath ) ;
882+ this . $fs . copyFile ( srcPath , destPath ) ;
884883
885884 if ( debugLog ) {
886885 console . log ( `Copied ${ file } ` ) ;
@@ -893,13 +892,13 @@ export class BundlerCompilerService
893892 }
894893
895894 // Clean destination directory
896- if ( existsSync ( destDir ) ) {
897- rmSync ( destDir , { recursive : true , force : true } ) ;
895+ if ( this . $fs . exists ( destDir ) ) {
896+ this . $fs . deleteDirectory ( destDir ) ;
898897 }
899- mkdirSync ( destDir , { recursive : true } ) ;
898+ this . $fs . createDirectory ( destDir ) ;
900899
901900 // Copy all files from dist to platform destination
902- if ( existsSync ( distOutput ) ) {
901+ if ( this . $fs . exists ( distOutput ) ) {
903902 this . copyRecursiveSync ( distOutput , destDir ) ;
904903 } else {
905904 this . $logger . warn (
@@ -945,15 +944,21 @@ export class BundlerCompilerService
945944 }
946945
947946 private copyRecursiveSync ( src : string , dest : string ) {
948- for ( const entry of readdirSync ( src , { withFileTypes : true } ) ) {
949- const srcPath = path . join ( src , entry . name ) ;
950- const destPath = path . join ( dest , entry . name ) ;
947+ // Ensure destination exists
948+ this . $fs . createDirectory ( dest ) ;
951949
952- if ( entry . isDirectory ( ) ) {
953- mkdirSync ( destPath , { recursive : true } ) ;
950+ const entries = this . $fs . readDirectory ( src ) ;
951+ for ( const name of entries ) {
952+ const srcPath = path . join ( src , name ) ;
953+ const destPath = path . join ( dest , name ) ;
954+ const lstats = this . $fs . getLsStats ( srcPath ) ;
955+
956+ if ( lstats . isDirectory ( ) ) {
954957 this . copyRecursiveSync ( srcPath , destPath ) ;
955- } else if ( entry . isFile ( ) || entry . isSymbolicLink ( ) ) {
956- copyFileSync ( srcPath , destPath ) ;
958+ } else if ( lstats . isFile ( ) || lstats . isSymbolicLink ( ) ) {
959+ // create parent directory (copyFile will also ensure it, but keep explicit)
960+ this . $fs . createDirectory ( path . dirname ( destPath ) ) ;
961+ this . $fs . copyFile ( srcPath , destPath ) ;
957962 }
958963 }
959964 }
0 commit comments