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 {
38
38
return dirPath ;
39
39
}
40
40
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
+ }
43
52
44
53
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 ) ;
48
63
}
49
64
}
50
65
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
+
51
72
export function getFileLoc (
52
73
diagnostic : ts . Diagnostic ,
53
74
configPath : string ,
Original file line number Diff line number Diff line change @@ -363,8 +363,8 @@ export async function createTempFiles(
363
363
checkFile . push ( tempFileCjs , tempFileEsm ) ;
364
364
365
365
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' ) ;
368
368
const tempFileRslibCjs = join ( tempDirRslib , 'tempFile.d.ts' ) ;
369
369
const tempFileRslibEsm = join ( tempDirRslibEsm , 'tempFile.d.ts' ) ;
370
370
You can’t perform that action at this time.
0 commit comments