Skip to content

Commit 26469ee

Browse files
Merge pull request #5848 from elizaOS/fix/core-build-declarations
fix(core): fix TypeScript declarations in npm package
2 parents b0e26a7 + 0712757 commit 26469ee

File tree

6 files changed

+39
-966
lines changed

6 files changed

+39
-966
lines changed

bun.lock

Lines changed: 11 additions & 895 deletions
Large diffs are not rendered by default.

packages/core/build.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,39 +122,39 @@ async function buildAll() {
122122
*/
123123
async 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
}

packages/core/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
}
4040
},
4141
"files": [
42-
"dist",
43-
"src"
42+
"dist"
4443
],
4544
"scripts": {
4645
"build": "bun run build.ts",

packages/core/tsconfig.browser.json

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
{
2-
"extends": "./tsconfig.json",
2+
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"declaration": true,
5-
"declarationMap": true,
6-
"emitDeclarationOnly": true,
74
"outDir": "./dist",
85
"rootDir": "./src",
6+
"types": ["node", "bun"],
7+
"noEmit": false,
8+
"emitDeclarationOnly": true,
99
"composite": false,
10-
"incremental": true,
11-
"tsBuildInfoFile": "./dist/.tsbuildinfo"
10+
"incremental": false
1211
},
13-
"include": ["src/**/*"],
12+
"include": ["src/index.node.ts", "src/index.browser.ts"],
1413
"exclude": ["src/**/*.test.ts", "src/**/*.spec.ts", "src/__tests__/**/*"]
1514
}

packages/core/tsconfig.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)