File tree Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -38,16 +38,37 @@ export function ensureTempDeclarationDir(cwd: string, name: string): string {
3838 return dirPath ;
3939}
4040
41- export async function clearTempDeclarationDir ( cwd : string ) : Promise < void > {
42- const dirPath = path . join ( cwd , TEMP_DTS_DIR ) ;
41+ export async function pathExists ( path : string ) : Promise < boolean > {
42+ return fs . promises
43+ . access ( path )
44+ . then ( ( ) => true )
45+ . catch ( ( ) => false ) ;
46+ }
47+
48+ export async function emptyDir ( dir : string ) : Promise < void > {
49+ if ( ! ( await pathExists ( dir ) ) ) {
50+ return ;
51+ }
4352
4453 try {
45- await fsP . rm ( dirPath , { recursive : true , force : true } ) ;
46- } catch ( error ) {
47- logger . error ( `Error clearing temporary directory ${ dirPath } : ${ error } ` ) ;
54+ for ( const file of await fs . promises . readdir ( dir ) ) {
55+ await fs . promises . rm ( path . resolve ( dir , file ) , {
56+ recursive : true ,
57+ force : true ,
58+ } ) ;
59+ }
60+ } catch ( err ) {
61+ logger . debug ( `Failed to empty dir: ${ dir } ` ) ;
62+ logger . debug ( err ) ;
4863 }
4964}
5065
66+ export async function clearTempDeclarationDir ( cwd : string ) : Promise < void > {
67+ const dirPath = path . join ( cwd , TEMP_DTS_DIR ) ;
68+
69+ await emptyDir ( dirPath ) ;
70+ }
71+
5172export function getFileLoc (
5273 diagnostic : ts . Diagnostic ,
5374 configPath : string ,
Original file line number Diff line number Diff line change @@ -363,8 +363,8 @@ export async function createTempFiles(
363363 checkFile . push ( tempFileCjs , tempFileEsm ) ;
364364
365365 if ( bundle ) {
366- const tempDirRslib = join ( fixturePath , '.rslib/ declarations' , 'cjs' ) ;
367- const tempDirRslibEsm = join ( fixturePath , '.rslib/ declarations' , 'esm' ) ;
366+ const tempDirRslib = join ( fixturePath , '.rslib' , ' declarations', 'cjs' ) ;
367+ const tempDirRslibEsm = join ( fixturePath , '.rslib' , ' declarations', 'esm' ) ;
368368 const tempFileRslibCjs = join ( tempDirRslib , 'tempFile.d.ts' ) ;
369369 const tempFileRslibEsm = join ( tempDirRslibEsm , 'tempFile.d.ts' ) ;
370370
You can’t perform that action at this time.
0 commit comments