11import { logger } from '@rsbuild/core' ;
22import color from 'picocolors' ;
3- import ts from 'typescript' ;
3+ import type {
4+ CompilerHost ,
5+ CompilerOptions ,
6+ Diagnostic ,
7+ FormatDiagnosticsHost ,
8+ ParsedCommandLine ,
9+ Program ,
10+ System ,
11+ WatchStatusReporter ,
12+ } from 'typescript' ;
413import type { DtsRedirect } from './index' ;
514import {
615 getTimeCost ,
716 processDtsFiles ,
817 renameDtsFile ,
18+ ts ,
919 updateDeclarationMapContent ,
1020} from './utils' ;
1121
1222const logPrefixTsc = color . dim ( '[tsc]' ) ;
1323
14- const formatHost : ts . FormatDiagnosticsHost = {
24+ const formatHost : FormatDiagnosticsHost = {
1525 getCanonicalFileName : ( path ) => path ,
1626 getCurrentDirectory : ts . sys . getCurrentDirectory . bind ( ts . sys ) ,
1727 getNewLine : ( ) => ts . sys . newLine ,
@@ -21,7 +31,7 @@ export type EmitDtsOptions = {
2131 name : string ;
2232 cwd : string ;
2333 configPath : string ;
24- tsConfigResult : ts . ParsedCommandLine ;
34+ tsConfigResult : ParsedCommandLine ;
2535 declarationDir : string ;
2636 dtsExtension : string ;
2737 rootDir : string ;
@@ -32,7 +42,7 @@ export type EmitDtsOptions = {
3242} ;
3343
3444async function handleDiagnosticsAndProcessFiles (
35- diagnostics : readonly ts . Diagnostic [ ] ,
45+ diagnostics : readonly Diagnostic [ ] ,
3646 configPath : string ,
3747 bundle : boolean ,
3848 declarationDir : string ,
@@ -117,17 +127,17 @@ export async function emitDtsTsc(
117127
118128 const createProgram = ts . createSemanticDiagnosticsBuilderProgram ;
119129
120- const reportDiagnostic = ( diagnostic : ts . Diagnostic ) => {
130+ const reportDiagnostic = ( diagnostic : Diagnostic ) => {
121131 logger . error (
122132 logPrefixTsc ,
123133 ts . formatDiagnosticsWithColorAndContext ( [ diagnostic ] , formatHost ) ,
124134 ) ;
125135 } ;
126136
127- const reportWatchStatusChanged : ts . WatchStatusReporter = async (
128- diagnostic : ts . Diagnostic ,
137+ const reportWatchStatusChanged : WatchStatusReporter = async (
138+ diagnostic : Diagnostic ,
129139 _newLine : string ,
130- _options : ts . CompilerOptions ,
140+ _options : CompilerOptions ,
131141 errorCount ?: number ,
132142 ) => {
133143 const message = `${ ts . flattenDiagnosticMessageText (
@@ -179,7 +189,7 @@ export async function emitDtsTsc(
179189 }
180190 } ;
181191
182- const system : ts . System = {
192+ const system : System = {
183193 ...ts . sys ,
184194 writeFile : ( fileName , contents , writeByteOrderMark ) => {
185195 const newFileName = renameDtsFile ( fileName , dtsExtension , bundle ) ;
@@ -198,9 +208,8 @@ export async function emitDtsTsc(
198208 if ( ! isWatch ) {
199209 // normal build - npx tsc
200210 if ( ! build && ! compilerOptions . composite ) {
201- const originHost : ts . CompilerHost =
202- ts . createCompilerHost ( compilerOptions ) ;
203- const host : ts . CompilerHost = {
211+ const originHost : CompilerHost = ts . createCompilerHost ( compilerOptions ) ;
212+ const host : CompilerHost = {
204213 ...originHost ,
205214 writeFile : (
206215 fileName ,
@@ -227,7 +236,7 @@ export async function emitDtsTsc(
227236 } ,
228237 } ;
229238
230- const program : ts . Program = ts . createProgram ( {
239+ const program : Program = ts . createProgram ( {
231240 rootNames : fileNames ,
232241 options : compilerOptions ,
233242 projectReferences,
@@ -257,9 +266,9 @@ export async function emitDtsTsc(
257266 ) ;
258267 } else if ( ! build && compilerOptions . composite ) {
259268 // incremental build with composite true - npx tsc
260- const originHost : ts . CompilerHost =
269+ const originHost : CompilerHost =
261270 ts . createIncrementalCompilerHost ( compilerOptions ) ;
262- const host : ts . CompilerHost = {
271+ const host : CompilerHost = {
263272 ...originHost ,
264273 writeFile : (
265274 fileName ,
@@ -296,7 +305,7 @@ export async function emitDtsTsc(
296305 createProgram,
297306 } ) ;
298307
299- const allDiagnostics : ts . Diagnostic [ ] = [ ] ;
308+ const allDiagnostics : Diagnostic [ ] = [ ] ;
300309 allDiagnostics . push (
301310 ...program . getConfigFileParsingDiagnostics ( ) ,
302311 ...program . getSyntacticDiagnostics ( ) ,
0 commit comments