Skip to content

Commit 5e1118c

Browse files
authored
build dist before npm publish (#12)
1 parent 30f1e46 commit 5e1118c

5 files changed

Lines changed: 74 additions & 10 deletions

File tree

.github/workflows/publish.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ jobs:
1717
with:
1818
fetch-depth: 0
1919

20+
- uses: oven-sh/setup-bun@v2
21+
with:
22+
bun-version: 1.3.11
23+
2024
- uses: actions/setup-node@v4
2125
with:
2226
node-version: 22
2327
registry-url: https://registry.npmjs.org
2428

29+
- name: Install dependencies
30+
run: bun install
31+
2532
- name: Release
2633
run: npx semantic-release@25
2734
env:

AGENTS.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ If you rename or change exports in `paths.ts` or `memory.ts`, check all downstre
5656

5757
- **ESM `.js` imports**: All TypeScript imports use `.js` extension (`import { foo } from "./bar.js"`)
5858
- **No linter/formatter**: No eslintrc, prettierrc — no enforced style
59-
- **No build**: `main` and `exports` in package.json point to `src/index.ts` directly
59+
- **Published package is built**: `tsc` emits `dist/`, and npm publishes the compiled output
6060
- **Tests via Bun**: `bun test` runs all `test/*.test.ts` files
6161
- **Silent catch blocks**: Intentional — file operations fail gracefully (file may not exist)
6262
- **`@opencode-ai/plugin`** is a peerDependency, `bun-types` provides Node globals
@@ -91,15 +91,16 @@ If you rename or change exports in `paths.ts` or `memory.ts`, check all downstre
9191
## Commands
9292

9393
```bash
94-
# No build needed — raw TS consumed by OpenCode
95-
9694
# Run tests
9795
bun test
9896

97+
# Build published artifacts
98+
bun run build
99+
99100
# Release: push to main triggers semantic-release → npm publish
100101
git push origin main
101102

102-
# Local dev: just edit src/ and test with opencode directly
103+
# Local dev: edit src/, then run build if you need the packaged entrypoints
103104
```
104105

105106
## Notes

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ Supported memory types:
230230
# Run tests
231231
bun test
232232

233-
# No build needed — raw TS consumed by OpenCode
233+
# Build published artifacts
234+
bun run build
235+
234236
# Release: push to main triggers semantic-release → npm publish
235237
```
236238

package.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
"version": "0.0.0-semantically-released",
44
"type": "module",
55
"description": "Claude Code-compatible memory compatibility layer for OpenCode — zero config, local-first, no migration",
6-
"main": "src/index.ts",
6+
"main": "dist/index.js",
7+
"types": "dist/index.d.ts",
78
"bin": {
89
"opencode-memory": "./bin/opencode-memory"
910
},
1011
"exports": {
11-
".": "./src/index.ts"
12+
".": {
13+
"types": "./dist/index.d.ts",
14+
"import": "./dist/index.js",
15+
"default": "./dist/index.js"
16+
}
1217
},
1318
"files": [
14-
"src",
15-
"bin"
19+
"dist"
1620
],
21+
"scripts": {
22+
"build": "tsc -p tsconfig.json",
23+
"prepack": "npm run build"
24+
},
1725
"repository": {
1826
"type": "git",
1927
"url": "git+https://github.com/kuitos/opencode-claude-memory.git"
@@ -36,6 +44,7 @@
3644
},
3745
"devDependencies": {
3846
"bun-types": "^1.3.11",
39-
"@opencode-ai/plugin": "^1.3.10"
47+
"@opencode-ai/plugin": "^1.3.10",
48+
"typescript": "^6.0.2"
4049
}
4150
}

test/publish-config.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { existsSync, readFileSync } from "fs"
3+
import { join } from "path"
4+
5+
const packagePath = join(process.cwd(), "package.json")
6+
const releaseWorkflowPath = join(process.cwd(), ".github", "workflows", "publish.yml")
7+
8+
type PackageJson = {
9+
main?: string
10+
types?: string
11+
exports?: unknown
12+
files?: string[]
13+
scripts?: Record<string, string>
14+
}
15+
16+
describe("package publish config", () => {
17+
test("publishes compiled entrypoints from dist and builds before packing", () => {
18+
expect(existsSync(packagePath)).toBe(true)
19+
20+
const pkg = JSON.parse(readFileSync(packagePath, "utf-8")) as PackageJson
21+
22+
expect(pkg.main).toBe("dist/index.js")
23+
expect(pkg.types).toBe("dist/index.d.ts")
24+
expect(pkg.exports).toEqual({
25+
".": {
26+
types: "./dist/index.d.ts",
27+
import: "./dist/index.js",
28+
default: "./dist/index.js",
29+
},
30+
})
31+
expect(pkg.files).toEqual(["dist"])
32+
expect(pkg.scripts?.build).toBe("tsc -p tsconfig.json")
33+
expect(pkg.scripts?.prepack).toBe("npm run build")
34+
})
35+
36+
test("installs dependencies before semantic-release publishes", () => {
37+
expect(existsSync(releaseWorkflowPath)).toBe(true)
38+
39+
const workflow = readFileSync(releaseWorkflowPath, "utf-8")
40+
41+
expect(workflow).toContain("oven-sh/setup-bun")
42+
expect(workflow).toContain("bun install")
43+
expect(workflow).toContain("npx semantic-release@25")
44+
})
45+
})

0 commit comments

Comments
 (0)