Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
},
"sdk": {
"name": "@codebuff/sdk",
"version": "0.1.33",
"version": "0.2.0",
"dependencies": {
"@vscode/ripgrep": "1.15.14",
"@vscode/tree-sitter-wasm": "0.1.4",
Expand Down
42 changes: 31 additions & 11 deletions sdk/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Build script for @codebuff/sdk using Bun's bundler with splitting
// Creates structured output with separate chunks for better Node.js compatibility
// Build script for @codebuff/sdk using Bun's bundler with dual package support
// Creates ESM + CJS bundles with TypeScript declarations

import { execSync } from 'child_process'
import { mkdir, cp } from 'fs/promises'
Expand Down Expand Up @@ -27,6 +27,21 @@ async function build() {
'util',
]

console.log('📦 Building ESM format...')
await Bun.build({
entrypoints: ['src/index.ts'],
outdir: 'dist',
target: 'node',
format: 'esm',
sourcemap: 'external',
minify: false,
external,
naming: '[dir]/index.mjs',
loader: {
'.scm': 'text',
},
})

console.log('📦 Building CJS format...')
await Bun.build({
entrypoints: ['src/index.ts'],
Expand All @@ -36,6 +51,7 @@ async function build() {
sourcemap: 'external',
minify: false,
external,
naming: '[dir]/index.cjs',
define: {
'import.meta.url': 'undefined',
'import.meta': 'undefined',
Expand All @@ -48,27 +64,31 @@ async function build() {
console.log('📝 Generating TypeScript declarations...')
try {
execSync('tsc -p tsconfig.build.json', { stdio: 'inherit' })
await createSimpleIndexTypes()
} catch (error) {
console.warn('⚠ TypeScript declaration generation failed, continuing...')
}

console.log('📂 Copying WASM files for tree-sitter...')
await copyWasmFiles()

console.log('📝 Creating colocated declaration files...')
await createColocatedDeclarations()

console.log('✅ Build complete!')
console.log(' 📄 dist/index.mjs (ESM)')
console.log(' 📄 dist/index.cjs (CJS)')
console.log(' 📄 dist/index.d.ts (Types)')
}

/**
* Create colocated declaration files for better TypeScript compatibility
* Create a simple index.d.ts that re-exports from the generated types
*/
async function createColocatedDeclarations() {
// Create index.d.ts that exports everything from ./sdk/src/index.d.ts
const indexDeclaration = 'export * from "./sdk/src/index";\n'
await Bun.write('dist/index.d.ts', indexDeclaration)
console.log(' ✓ Created dist/index.d.ts')
async function createSimpleIndexTypes() {
try {
const indexDeclaration = 'export * from "./sdk/src/index";\n'
await Bun.write('dist/index.d.ts', indexDeclaration)
console.log(' ✓ Created simple re-export types')
} catch (error) {
console.warn(' ⚠ Warning: Could not create index types:', error.message)
}
}

/**
Expand Down
16 changes: 10 additions & 6 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"version": "0.2.0",
"description": "Official SDK for Codebuff — AI coding agent & framework",
"license": "Apache-2.0",
"type": "commonjs",
"main": "./dist/index.js",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"typings": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"default": "./dist/index.js"
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./package.json": "./package.json"
},
Expand All @@ -25,14 +26,17 @@
],
"scripts": {
"build": "bun run build.ts",
"build:verify": "bun run build && bun run smoke-test && bun run smoke-test:dist",
"smoke-test": "bun run smoke-test.ts",
"build:types": "tsc -p tsconfig.build.json",
"build:verify": "bun run build && bun run smoke-test:dist && bun run test:cjs && bun run test:esm",
"smoke-test:dist": "bun run smoke-test-dist.ts",
"test:cjs": "cd test/cjs-compatibility && npm install --silent && npm run test:all",
"test:esm": "cd test/esm-compatibility && npm install --silent && npm run test:all",
"clean": "rm -rf dist",
"prepare-dist": "bun run scripts/publish.ts --dry-run",
"publish-sdk": "bun run scripts/publish.ts --public",
"publish-dry-run": "bun run build:verify && bun run scripts/publish.ts --dry-run",
"prepack": "bun run build",
"prepublishOnly": "bun run build",
"typecheck": "tsc --noEmit -p .",
"test": "bun test"
},
Expand Down
4 changes: 2 additions & 2 deletions sdk/smoke-test-dist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function testCJSDist() {
const testCode = `
try {
// Require from the built CJS dist files
const pkg = require('../dist/index.js');
const pkg = require('../dist/index.cjs');
console.log('CJS dist require successful');

// Verify basic structure
Expand Down Expand Up @@ -166,7 +166,7 @@ async function testCJSTreeSitter() {
const runTest = async () => {
try {
// Require tree-sitter functionality from built CJS dist
const { getFileTokenScores, setWasmDir } = require('../dist/index.js');
const { getFileTokenScores, setWasmDir } = require('../dist/index.cjs');
console.log('CJS tree-sitter imports successful');

// Set WASM directory to the correct location for dist tests
Expand Down
94 changes: 0 additions & 94 deletions sdk/smoke-test.ts

This file was deleted.

Loading