@@ -11,13 +11,67 @@ const fs = require('fs');
1111const path = require ( 'path' ) ;
1212const { execSync } = require ( 'child_process' ) ;
1313
14+ // Diagnostic information
15+ console . log ( '🔍 Diagnostic Information:' ) ;
16+ console . log ( ' Node version:' , process . version ) ;
17+ console . log ( ' Platform:' , process . platform ) ;
18+ console . log ( ' Architecture:' , process . arch ) ;
19+ console . log ( ' Current directory:' , process . cwd ( ) ) ;
20+ console . log ( ' Script directory:' , __dirname ) ;
21+
22+ // Get TypeScript version
23+ try {
24+ const tscVersion = execSync ( 'npx tsc --version' , { encoding : 'utf8' } ) . trim ( ) ;
25+ console . log ( ' TypeScript version:' , tscVersion ) ;
26+ } catch ( e ) {
27+ console . log ( ' TypeScript version: Could not determine' ) ;
28+ }
29+
1430const distDir = path . join ( __dirname , '..' , 'dist' ) ;
1531const indexDtsPath = path . join ( distDir , 'index.d.ts' ) ;
1632
33+ // List what's in dist directory before trying fallbacks
34+ console . log ( '\n📁 Contents of dist directory:' ) ;
35+ if ( fs . existsSync ( distDir ) ) {
36+ const files = fs . readdirSync ( distDir ) ;
37+ files . forEach ( file => {
38+ const stats = fs . statSync ( path . join ( distDir , file ) ) ;
39+ console . log ( ` ${ file } (${ stats . isDirectory ( ) ? 'directory' : stats . size + ' bytes' } )` ) ;
40+ } ) ;
41+ } else {
42+ console . log ( ' dist directory does not exist!' ) ;
43+ }
44+
1745// Check if index.d.ts exists
1846if ( ! fs . existsSync ( indexDtsPath ) ) {
19- console . log ( '⚠️ Declaration files not generated by normal build.' ) ;
20- console . log ( '📝 Attempting alternative declaration generation...' ) ;
47+ console . log ( '\n⚠️ Declaration files not generated by normal build.' ) ;
48+
49+ // Run tsc with diagnostics to see what's happening
50+ console . log ( '\n🔍 Running TypeScript with diagnostics...' ) ;
51+ try {
52+ const diagnostics = execSync ( 'npx tsc --listFiles --noEmit' , {
53+ cwd : path . join ( __dirname , '..' ) ,
54+ encoding : 'utf8'
55+ } ) ;
56+ const fileCount = diagnostics . split ( '\n' ) . filter ( line => line . trim ( ) ) . length ;
57+ console . log ( ` TypeScript processed ${ fileCount } files` ) ;
58+ } catch ( e ) {
59+ console . log ( ' TypeScript diagnostics failed:' , e . message ) ;
60+ }
61+
62+ // Check for TypeScript errors
63+ console . log ( '\n🔍 Checking for TypeScript errors...' ) ;
64+ try {
65+ execSync ( 'npx tsc --noEmit' , {
66+ cwd : path . join ( __dirname , '..' ) ,
67+ stdio : 'pipe'
68+ } ) ;
69+ console . log ( ' No TypeScript errors found' ) ;
70+ } catch ( e ) {
71+ console . log ( ' TypeScript errors detected:' , e . stdout ? e . stdout . toString ( ) : e . message ) ;
72+ }
73+
74+ console . log ( '\n📝 Attempting alternative declaration generation...' ) ;
2175
2276 try {
2377 // Try building with different settings
@@ -31,25 +85,47 @@ if (!fs.existsSync(indexDtsPath)) {
3185 console . log ( '✅ Declaration files generated successfully via fallback!' ) ;
3286 } else {
3387 // If still no declarations, try one more approach
34- console . log ( ' Trying with allowJs and checkJs disabled ...' ) ;
35- execSync ( 'npx tsc --declaration --declarationMap --outDir dist --allowJs false --checkJs false ' , {
88+ console . log ( ' Trying with module commonjs ...' ) ;
89+ execSync ( 'npx tsc --declaration --module commonjs --outDir dist' , {
3690 cwd : path . join ( __dirname , '..' ) ,
3791 stdio : 'inherit'
3892 } ) ;
3993
4094 if ( fs . existsSync ( indexDtsPath ) ) {
4195 console . log ( '✅ Declaration files generated successfully via second fallback!' ) ;
4296 } else {
43- console . error ( '❌ Failed to generate declaration files after all attempts.' ) ;
44- process . exit ( 1 ) ;
97+ // Last resort - try with a minimal config
98+ console . log ( ' Trying with minimal config...' ) ;
99+ execSync ( 'npx tsc src/index.ts --declaration --outDir dist --moduleResolution node --module commonjs' , {
100+ cwd : path . join ( __dirname , '..' ) ,
101+ stdio : 'inherit'
102+ } ) ;
103+
104+ if ( fs . existsSync ( indexDtsPath ) ) {
105+ console . log ( '✅ Declaration files generated successfully via third fallback!' ) ;
106+ } else {
107+ console . error ( '\n❌ Failed to generate declaration files after all attempts.' ) ;
108+
109+ // Final diagnostic - list what files were actually created
110+ console . log ( '\n📁 Final contents of dist directory:' ) ;
111+ if ( fs . existsSync ( distDir ) ) {
112+ const files = fs . readdirSync ( distDir ) ;
113+ files . forEach ( file => {
114+ const stats = fs . statSync ( path . join ( distDir , file ) ) ;
115+ console . log ( ` ${ file } (${ stats . isDirectory ( ) ? 'directory' : stats . size + ' bytes' } )` ) ;
116+ } ) ;
117+ }
118+
119+ process . exit ( 1 ) ;
120+ }
45121 }
46122 }
47123 } catch ( error ) {
48124 console . error ( '❌ Error during fallback declaration generation:' , error . message ) ;
49125 process . exit ( 1 ) ;
50126 }
51127} else {
52- console . log ( '✅ Declaration files already exist.' ) ;
128+ console . log ( '\n ✅ Declaration files already exist.' ) ;
53129}
54130
55131// Verify all expected declaration files exist
@@ -63,18 +139,22 @@ const expectedFiles = [
63139 'models/index.d.ts'
64140] ;
65141
142+ console . log ( '\n📋 Verifying expected declaration files...' ) ;
66143let allFilesExist = true ;
67144for ( const file of expectedFiles ) {
68145 const filePath = path . join ( distDir , file ) ;
69146 if ( ! fs . existsSync ( filePath ) ) {
70- console . error ( `❌ Missing declaration file : ${ file } ` ) ;
147+ console . error ( ` ❌ Missing : ${ file } ` ) ;
71148 allFilesExist = false ;
149+ } else {
150+ const stats = fs . statSync ( filePath ) ;
151+ console . log ( ` ✅ Found: ${ file } (${ stats . size } bytes)` ) ;
72152 }
73153}
74154
75155if ( ! allFilesExist ) {
76- console . error ( '❌ Some declaration files are missing!' ) ;
156+ console . error ( '\n ❌ Some declaration files are missing!' ) ;
77157 process . exit ( 1 ) ;
78158}
79159
80- console . log ( '✅ All declaration files verified successfully!' ) ;
160+ console . log ( '\n ✅ All declaration files verified successfully!' ) ;
0 commit comments