Skip to content

Commit 39bb7cb

Browse files
committed
bundle types for sdk into one index.d.ts
1 parent f3c07e6 commit 39bb7cb

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed

.agents/researcher/researcher-grok-4-fast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Take as many steps as you need to gather information first:
4040
4141
You should likely spawn the researcher-file-explorer agent to get a comprehensive understanding of the codebase. You should also spawn the researcher-web and researcher-docs agents to get up-to-date information from the web and docs, if relevant.
4242
43-
Finally, write up a research report that answers the user question to the best of your ability from the information gathered from the agents. Include all the relevant information. Mention which files are relevant to the user question. Be clear and concise.`,
43+
Finally, write up a research report that answers the user question to the best of your ability from the information gathered from the agents. Don't add any opinions or recommendations, just all the plain facts that are relevant. Mention which files are relevant to the user question. Be clear and concise.`,
4444
}
4545

4646
export default definition

bun.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"build": "bun run scripts/build.ts",
2626
"build:types": "tsc -p tsconfig.build.json",
2727
"build:verify": "bun run build && bun run smoke-test:dist && bun run test:cjs && bun run test:esm && bun run test:ripgrep",
28+
"test:typecheck-strict": "tsc --noEmit --strict dist/index.d.ts",
2829
"smoke-test:dist": "bun run smoke-test-dist.ts",
2930
"test:cjs": "cd test/cjs-compatibility && npm install --silent && npm run test:all",
3031
"test:esm": "cd test/esm-compatibility && npm install --silent && npm run test:all",
@@ -71,6 +72,7 @@
7172
"@types/diff": "8.0.0",
7273
"@types/node": "22",
7374
"adm-zip": "^0.5.12",
75+
"dts-bundle-generator": "^9.5.1",
7476
"node-fetch": "^3.3.2"
7577
},
7678
"author": ""

sdk/scripts/build.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Creates ESM + CJS bundles with TypeScript declarations
33

44
import { execSync } from 'child_process'
5-
import { mkdir, cp } from 'fs/promises'
5+
import { mkdir, cp, readFile, writeFile } from 'fs/promises'
66

77
async function build() {
88
console.log('🧹 Cleaning dist directory...')
@@ -70,12 +70,18 @@ async function build() {
7070
},
7171
})
7272

73-
console.log('📝 Generating TypeScript declarations...')
73+
console.log('📝 Generating and bundling TypeScript declarations...')
7474
try {
75-
execSync('tsc -p tsconfig.build.json', { stdio: 'inherit' })
76-
await createSimpleIndexTypes()
75+
execSync(
76+
'bunx dts-bundle-generator -o dist/index.d.ts --no-check --export-referenced-types=false src/index.ts',
77+
{ stdio: 'inherit' },
78+
)
79+
80+
// Fix duplicate imports in the generated file
81+
await fixDuplicateImports()
82+
console.log(' ✓ Created bundled type definitions')
7783
} catch (error) {
78-
console.warn('⚠ TypeScript declaration generation failed, continuing...')
84+
console.warn('⚠ TypeScript declaration bundling failed:', error.message)
7985
}
8086

8187
console.log('📂 Copying WASM files for tree-sitter...')
@@ -91,15 +97,32 @@ async function build() {
9197
}
9298

9399
/**
94-
* Create a simple index.d.ts that re-exports from the generated types
100+
* Fix duplicate imports in the generated index.d.ts file
95101
*/
96-
async function createSimpleIndexTypes() {
102+
async function fixDuplicateImports() {
97103
try {
98-
const indexDeclaration = 'export * from "./sdk/src/index";\n'
99-
await Bun.write('dist/index.d.ts', indexDeclaration)
100-
console.log(' ✓ Created simple re-export types')
104+
let content = await readFile('dist/index.d.ts', 'utf-8')
105+
106+
// Remove any duplicate zod default imports (handle various whitespace)
107+
const zodDefaultImportRegex = /import\s+z\s+from\s+['"]zod\/v4['"];?\n?/g
108+
const zodNamedImportRegex =
109+
/import\s+\{\s*z\s*\}\s+from\s+['"]zod\/v4['"];?/
110+
111+
// If we have both imports, remove all default imports and keep only the named one
112+
if (
113+
content.match(zodNamedImportRegex) &&
114+
content.match(zodDefaultImportRegex)
115+
) {
116+
content = content.replace(zodDefaultImportRegex, '')
117+
}
118+
119+
await writeFile('dist/index.d.ts', content)
120+
console.log(' ✓ Fixed duplicate imports in bundled types')
101121
} catch (error) {
102-
console.warn(' ⚠ Warning: Could not create index types:', error.message)
122+
console.warn(
123+
' ⚠ Warning: Could not fix duplicate imports:',
124+
error.message,
125+
)
103126
}
104127
}
105128

0 commit comments

Comments
 (0)