@@ -13,7 +13,34 @@ export async function emitDts(config: EmitDtsConfig) {
13
13
const { options, filenames } = loadTsconfig ( config , svelteMap ) ;
14
14
const host = await createTsCompilerHost ( options , svelteMap ) ;
15
15
const program = ts . createProgram ( filenames , options , host ) ;
16
- program . emit ( ) ;
16
+ const result = program . emit ( ) ;
17
+ const likely_failed_files = result . diagnostics . filter ( ( diagnostic ) => {
18
+ // List of errors which hint at a failed d.ts generation
19
+ // https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
20
+ return diagnostic . code === 2527 || ( diagnostic . code >= 4000 && diagnostic . code <= 4108 ) ;
21
+ } ) ;
22
+
23
+ if ( likely_failed_files . length > 0 ) {
24
+ const failed_by_file = new Map < string , string [ ] > ( ) ;
25
+ likely_failed_files . forEach ( ( diagnostic ) => {
26
+ const file = diagnostic . file ?. fileName ;
27
+ if ( file ) {
28
+ const errors = failed_by_file . get ( file ) || [ ] ;
29
+ errors . push ( ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ) ;
30
+ failed_by_file . set ( file , errors ) ;
31
+ }
32
+ } ) ;
33
+ console . warn (
34
+ 'd.ts type declaration files for the following files were likely not generated due to the following errors:'
35
+ ) ;
36
+ console . warn (
37
+ [ ...failed_by_file . entries ( ) ]
38
+ . map ( ( [ file , errors ] ) => {
39
+ return `${ file } \n${ errors . map ( ( error ) => ` - ${ error } ` ) . join ( '\n' ) } ` ;
40
+ } )
41
+ . join ( '\n' )
42
+ ) ;
43
+ }
17
44
}
18
45
19
46
function loadTsconfig ( config : EmitDtsConfig , svelteMap : SvelteMap ) {
0 commit comments