11import { spawn } from 'node:child_process' ;
2- import fs from 'node:fs' ;
2+ import fsP from 'node:fs/promises ' ;
33import { createRequire } from 'node:module' ;
44import path from 'node:path' ;
55import { logger } from '@rsbuild/core' ;
66import color from 'picocolors' ;
7- import ts from 'typescript' ;
7+ import type ts from 'typescript' ;
88import type { DtsRedirect } from './index' ;
99import type { EmitDtsOptions } from './tsc' ;
1010import {
@@ -84,7 +84,7 @@ async function handleDiagnosticsAndProcessFiles(
8484 ] ) ;
8585 await Promise . all (
8686 dtsFiles . map ( async ( file ) => {
87- const contents = ts . sys . readFile ( file ) ?? '' ;
87+ const contents = await fsP . readFile ( file , 'utf8' ) ;
8888 const newFileName = renameDtsFile ( file , dtsExtension , bundle ) ;
8989 const newContents = updateDeclarationMapContent (
9090 file ,
@@ -94,12 +94,8 @@ async function handleDiagnosticsAndProcessFiles(
9494 tsConfigResult . options . declarationMap ,
9595 ) ;
9696 if ( file !== newFileName || contents !== newContents ) {
97- ts . sys . writeFile ( newFileName , newContents ) ;
98- if ( ts . sys . deleteFile ) {
99- ts . sys . deleteFile ( file ) ;
100- } else {
101- fs . unlinkSync ( file ) ;
102- }
97+ await fsP . writeFile ( newFileName , newContents ) ;
98+ await fsP . unlink ( file ) ;
10399 }
104100 } ) ,
105101 ) ;
0 commit comments