@@ -122,39 +122,39 @@ async function buildAll() {
122122 */
123123async function generateTypeScriptDeclarations ( ) {
124124 const fs = await import ( 'node:fs/promises' ) ;
125+ const { $ } = await import ( 'bun' ) ;
125126
126- console . log ( '📝 Setting up TypeScript declarations...' ) ;
127+ console . log ( '📝 Generating TypeScript declarations...' ) ;
127128 const startTime = Date . now ( ) ;
128129
129130 try {
130- // Since we're including src in the package, we can reference the TypeScript files directly
131- // This ensures types work in the monorepo and when published to NPM
132-
133- // Ensure dist directories exist
131+ // Generate real TypeScript declarations using tsc
132+ console . log ( ' Compiling TypeScript declarations...' ) ;
133+ await $ `tsc --project tsconfig.declarations.json` ;
134+
135+ // TypeScript has generated all the .d.ts files in dist/
136+ // Now we need to create the conditional export entry points
137+
138+ // Ensure directories exist
134139 await fs . mkdir ( 'dist/node' , { recursive : true } ) ;
135140 await fs . mkdir ( 'dist/browser' , { recursive : true } ) ;
136141
137- // Create the main index.d.ts that re-exports from the src folder
138- const mainTypeIndex = `// Type definitions for @elizaos/core
139- // Re-exports all types from the Node.js entry point
140- export * from '../src/index.node';
141- ` ;
142- await fs . writeFile ( 'dist/index.d.ts' , mainTypeIndex ) ;
143-
144- // For dist/node/index.d.ts - export from the source
142+ // For dist/node/index.d.ts - point to the compiled node types
145143 const nodeIndexDts = `// Type definitions for @elizaos/core (Node.js)
146- // Re-exports all types from the Node.js source entry point
147- export * from '../../src/ index.node';
144+ // Re-exports all types from the compiled Node.js declarations
145+ export * from '../index.node';
148146` ;
149147 await fs . writeFile ( 'dist/node/index.d.ts' , nodeIndexDts ) ;
150148
151- // For dist/browser/index.d.ts - export from the source
149+ // For dist/browser/index.d.ts - point to the compiled browser types
152150 const browserIndexDts = `// Type definitions for @elizaos/core (Browser)
153- // Re-exports all types from the Browser source entry point
154- export * from '../../src/ index.browser';
151+ // Re-exports all types from the compiled Browser declarations
152+ export * from '../index.browser';
155153` ;
156154 await fs . writeFile ( 'dist/browser/index.d.ts' , browserIndexDts ) ;
157155
156+ // The main index.d.ts is already generated by tsc, we don't need to overwrite it
157+
158158 // Create main index.js for fallback (JavaScript runtime entry)
159159 const mainIndex = `// Main entry point for @elizaos/core
160160// This file is not used directly - package.json conditional exports handle the routing
@@ -164,10 +164,10 @@ export * from './node/index.node.js';
164164 await fs . writeFile ( 'dist/index.js' , mainIndex ) ;
165165
166166 const duration = ( ( Date . now ( ) - startTime ) / 1000 ) . toFixed ( 2 ) ;
167- console . log ( `✅ TypeScript declarations setup in ${ duration } s` ) ;
168- console . log ( ' Note: Types are exported directly from the included src folder ' ) ;
167+ console . log ( `✅ TypeScript declarations generated in ${ duration } s` ) ;
168+ console . log ( ' Note: Using compiled TypeScript declarations (no src/ needed in package) ' ) ;
169169 } catch ( error ) {
170- console . error ( '❌ Failed to setup TypeScript declarations:' , error ) ;
170+ console . error ( '❌ Failed to generate TypeScript declarations:' , error ) ;
171171 throw error ;
172172 }
173173}
0 commit comments