Skip to content

Commit f0a013f

Browse files
authored
fix plugin publishing bug (#13)
1 parent a0ef6e8 commit f0a013f

5 files changed

Lines changed: 22 additions & 13 deletions

File tree

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "@warp-dot-dev/opencode-warp",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Warp terminal integration for OpenCode — native notifications and more",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"files": [
88
"dist"
99
],
1010
"scripts": {
11-
"build": "tsc",
11+
"build": "rm -rf dist && tsc",
1212
"typecheck": "tsc --noEmit",
1313
"test": "bun test",
1414
"dev": "echo 'Add to your opencode.json: \"plugin\": [\"file://'$(pwd)'/src/index.ts\"]' && echo 'Then run: opencode'",
15-
"prepublishOnly": "tsc"
15+
"prepublishOnly": "npm run build"
1616
},
1717
"keywords": [
1818
"opencode",

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import type { Plugin } from "@opencode-ai/plugin"
22
import type { Event, Part, Permission } from "@opencode-ai/sdk"
3+
import { readFileSync } from "node:fs"
34

45
import { buildPayload } from "./payload"
56
import { warpNotify } from "./notify"
6-
import pkg from "../package.json" with { type: "json" }
77

8-
const PLUGIN_VERSION = pkg.version
8+
// Read the version at runtime instead of `import pkg from "../package.json"`.
9+
// An import would pull package.json into tsc's compilation roots and shift
10+
// output paths (e.g. dist/src/index.js instead of dist/index.js).
11+
const pkg = JSON.parse(
12+
readFileSync(new URL("../package.json", import.meta.url), "utf8"),
13+
) as { version: string }
14+
export const PLUGIN_VERSION = pkg.version
15+
916
const NOTIFICATION_TITLE = "warp://cli-agent"
1017

1118
export function truncate(str: string, maxLen: number): string {

tests/index.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it } from "node:test"
22
import assert from "node:assert/strict"
3-
import { truncate, extractTextFromParts } from "../src/index"
3+
import { truncate, extractTextFromParts, PLUGIN_VERSION } from "../src/index"
44
import { buildPayload } from "../src/payload"
55

66
describe("truncate", () => {
@@ -64,11 +64,12 @@ describe("extractTextFromParts", () => {
6464
})
6565

6666
describe("PLUGIN_VERSION", () => {
67-
it("resolves to a valid semver string from package.json", async () => {
68-
const pkg = await import("../package.json", { with: { type: "json" } })
69-
const version = pkg.default.version
70-
assert.ok(typeof version === "string", "version should be a string")
71-
assert.match(version, /^\d+\.\d+\.\d+/, "version should be semver")
67+
it("resolves to a valid semver string from package.json", () => {
68+
assert.ok(
69+
typeof PLUGIN_VERSION === "string",
70+
"PLUGIN_VERSION should be a string",
71+
)
72+
assert.match(PLUGIN_VERSION, /^\d+\.\d+\.\d+/, "version should be semver")
7273
})
7374
})
7475

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"esModuleInterop": true,
77
"strict": true,
88
"resolveJsonModule": true,
9+
"rootDir": "src",
910
"outDir": "dist",
1011
"declaration": true,
1112
"declarationMap": true,

0 commit comments

Comments
 (0)