@@ -29,7 +29,7 @@ export function generateBundle(
2929 entryPoints : string [ ] ,
3030 compilerOptions : ts . CompilerOptions ,
3131 tsconfigPath ?: string ,
32- originalConfig : any = { } ,
32+ originalConfig ? : any ,
3333) {
3434 const commonOutDir = getHighestCommonDirectory ( entryPoints ) ;
3535
@@ -39,46 +39,60 @@ export function generateBundle(
3939 const postbundleOutDir = resolve ( compilerOptions . declarationDir ! , ".." ) ;
4040
4141 let shouldDeleteTsConfig = false ;
42- if ( ! tsconfigPath ) {
43- const tempid = randomBytes ( 20 ) . toString ( "hex" ) ;
42+ if ( ! tsconfigPath && originalConfig ) {
43+ const tempid = randomBytes ( 6 ) . toString ( "hex" ) ;
4444
4545 tsconfigPath = resolve ( process . cwd ( ) , `tsconfig.${ tempid } .json` ) ;
4646
47+ console . log ( originalConfig )
4748 writeFileSync (
4849 tsconfigPath ,
4950 JSON . stringify ( {
5051 ...originalConfig ,
51- compilerOptions,
52+ compilerOptions : {
53+ ...originalConfig . compilerOptions ,
54+ declaration : true ,
55+ emitDeclarationOnly : true ,
56+ declarationDir : postbundleOutDir ,
57+ } ,
5258 include : entryPoints ,
5359 } ) ,
5460 ) ;
5561
5662 shouldDeleteTsConfig = true ;
5763 }
5864
59- const bundles = generateDtsBundle (
60- relativeDeclarationPaths . map ( ( path ) => ( {
61- filePath : resolve ( compilerOptions . declarationDir ! , path ) ,
62- } ) ) ,
63- {
64- preferredConfigPath : tsconfigPath ,
65- } ,
66- ) ;
65+ try {
66+ const bundles = generateDtsBundle (
67+ relativeDeclarationPaths . map ( ( path ) => ( {
68+ filePath : resolve ( compilerOptions . declarationDir ! , path ) ,
69+ } ) ) ,
70+ {
71+ preferredConfigPath : tsconfigPath ,
72+ } ,
73+ ) ;
6774
68- for ( let i = 0 ; i < bundles . length ; i ++ ) {
69- const bundle = bundles [ i ] ;
70- const originalPath = relativeDeclarationPaths [ i ] ;
75+ for ( let i = 0 ; i < bundles . length ; i ++ ) {
76+ const bundle = bundles [ i ] ;
77+ const originalPath = relativeDeclarationPaths [ i ] ;
7178
72- const outputPath = resolve ( postbundleOutDir , originalPath ) ;
79+ const outputPath = resolve ( postbundleOutDir , originalPath ) ;
7380
74- writeFileSync ( outputPath , bundle ) ;
75- }
81+ writeFileSync ( outputPath , bundle ) ;
82+ }
7683
77- if ( compilerOptions . declarationDir ! . endsWith ( "dts-prebundle" ) ) {
78- rmSync ( compilerOptions . declarationDir ! , { recursive : true } ) ;
79- }
84+ if ( compilerOptions . declarationDir ! . endsWith ( "dts-prebundle" ) ) {
85+ rmSync ( compilerOptions . declarationDir ! , { recursive : true } ) ;
86+ }
87+
88+ if ( shouldDeleteTsConfig && tsconfigPath ) {
89+ rmSync ( tsconfigPath ) ;
90+ }
91+ } catch ( e ) {
92+ if ( shouldDeleteTsConfig && tsconfigPath ) {
93+ rmSync ( tsconfigPath ) ;
94+ }
8095
81- if ( shouldDeleteTsConfig ) {
82- rmSync ( tsconfigPath ) ;
96+ throw e ;
8397 }
8498}
0 commit comments