From 37a86e8188c09162129bcc22e3a4254ab5aacb33 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Sat, 25 Apr 2026 17:16:35 +0530 Subject: [PATCH 1/3] fix: bundle plugin to JS for server mode compatibility Bun's on-the-fly TypeScript transpilation fails to extract named exports from CJS modules (like @opentelemetry/*) when loaded via `await import()` in opencode's compiled binary. This causes plugins to fail in server/CLI mode while working fine in TUI mode. Fix by pre-bundling all dependencies into a single JavaScript file using `bun build`, which resolves imports at build time and avoids CJS/ESM interop issues at runtime. - Add `build` script: `bun build src/index.ts --outdir=./dist --target=node` - Update exports/main/module to point to `dist/index.js` - Add `prepublishOnly` to ensure build runs before npm publish - Add `./server` export for explicit server mode entry point Fixes #35 --- package.json | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9d489e8..661bb92 100644 --- a/package.json +++ b/package.json @@ -29,10 +29,11 @@ "eslint-plugin-jsdoc": "^50.6.11" }, "exports": { - ".": "./src/index.ts" + ".": "./dist/index.js", + "./server": "./dist/index.js" }, "files": [ - "src/" + "dist/" ], "homepage": "https://github.com/DEVtheOPS/opencode-plugin-otel#readme", "keywords": [ @@ -44,8 +45,8 @@ "observability" ], "license": "MPL-2.0", - "main": "src/index.ts", - "module": "src/index.ts", + "main": "dist/index.js", + "module": "dist/index.js", "name": "@devtheops/opencode-plugin-otel", "oc-plugin": [ "server" @@ -58,9 +59,11 @@ "url": "https://github.com/DEVtheOPS/opencode-plugin-otel.git" }, "scripts": { + "build": "bun build src/index.ts --outdir=./dist --target=node", "check:jsdoc-coverage": "bun scripts/check-jsdoc-coverage.mjs", "lint": "bun --bun eslint .", - "typecheck": "tsc --noEmit" + "typecheck": "tsc --noEmit", + "prepublishOnly": "bun run build" }, "type": "module", "version": "0.8.0" From ce22030d975777d43a21d4e15de2c29091c15d7d Mon Sep 17 00:00:00 2001 From: bendtherules Date: Sat, 25 Apr 2026 17:47:14 +0530 Subject: [PATCH 2/3] fix: emit TypeScript declarations alongside bundled JS Add tsconfig.build.json that emits only declaration files into dist/, so TypeScript consumers retain type information after the switch from source to bundled JS entry points. - Add tsconfig.build.json with emitDeclarationOnly + rootDir: ./src - Update build script to run tsc -p tsconfig.build.json after bundling - Add types field to package.json exports and top-level - Include .d.ts condition in export map for both . and ./server Addresses CodeRabbit review comment on PR #36 --- package.json | 13 ++++++++++--- tsconfig.build.json | 12 ++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tsconfig.build.json diff --git a/package.json b/package.json index 661bb92..201709e 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,14 @@ "eslint-plugin-jsdoc": "^50.6.11" }, "exports": { - ".": "./dist/index.js", - "./server": "./dist/index.js" + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "./server": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } }, "files": [ "dist/" @@ -47,6 +53,7 @@ "license": "MPL-2.0", "main": "dist/index.js", "module": "dist/index.js", + "types": "dist/index.d.ts", "name": "@devtheops/opencode-plugin-otel", "oc-plugin": [ "server" @@ -59,7 +66,7 @@ "url": "https://github.com/DEVtheOPS/opencode-plugin-otel.git" }, "scripts": { - "build": "bun build src/index.ts --outdir=./dist --target=node", + "build": "bun build src/index.ts --outdir=./dist --target=node && tsc -p tsconfig.build.json", "check:jsdoc-coverage": "bun scripts/check-jsdoc-coverage.mjs", "lint": "bun --bun eslint .", "typecheck": "tsc --noEmit", diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..dea68d1 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "./dist", + "rootDir": "./src" + }, + "include": ["src"], + "exclude": ["eslint.config.mjs", "dist", "scripts", "tests"] +} From bd7a4f9b57a6016113e14713e60c666f5bab95d3 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Sat, 25 Apr 2026 17:49:50 +0530 Subject: [PATCH 3/3] fix: use prepack instead of prepublishOnly prepack runs on both npm publish and npm pack (and when installing from git/tarball), whereas prepublishOnly only runs on npm publish. Since dist/ is gitignored, installing directly from git would produce a broken package without this change. Addresses CodeRabbit nitpick comment on PR #36 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 201709e..194d94b 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "check:jsdoc-coverage": "bun scripts/check-jsdoc-coverage.mjs", "lint": "bun --bun eslint .", "typecheck": "tsc --noEmit", - "prepublishOnly": "bun run build" + "prepack": "bun run build" }, "type": "module", "version": "0.8.0"