File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -35,16 +35,27 @@ if (require.main === module) {
35
35
}
36
36
}
37
37
38
- const tsProgram = ts . createProgram ( [ 'src/index.ts' ] , {
39
- ...ts . getDefaultCompilerOptions ( ) ,
38
+ // Based on https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#getting-the-dts-from-a-javascript-file
39
+ const tsConfig = require ( '../tsconfig.json' ) ;
40
+ assert (
41
+ tsConfig . compilerOptions ,
42
+ '"tsconfig.json" should have `compilerOptions`' ,
43
+ ) ;
44
+ const tsOptions = {
45
+ ...tsConfig . compilerOptions ,
46
+ noEmit : false ,
40
47
declaration : true ,
41
48
declarationDir : './npmDist' ,
42
49
emitDeclarationOnly : true ,
43
- } ) ;
50
+ } ;
44
51
45
- const tsResult = tsProgram . emit ( undefined , ( filepath , body ) => {
52
+ const tsHost = ts . createCompilerHost ( tsOptions ) ;
53
+ tsHost . writeFile = ( filepath , body ) => {
46
54
writeGeneratedFile ( filepath , body ) ;
47
- } ) ;
55
+ }
56
+
57
+ const tsProgram = ts . createProgram ( [ 'src/index.ts' ] , tsOptions , tsHost ) ;
58
+ const tsResult = tsProgram . emit ( ) ;
48
59
assert (
49
60
! tsResult . emitSkipped ,
50
61
'Fail to generate `*.d.ts` files, please run `npm run check`' ,
You can’t perform that action at this time.
0 commit comments