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
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"opencode-supermemory": "./dist/cli.js"
},
"scripts": {
"build": "bun build ./src/index.ts --outdir ./dist --target node && bun build ./src/cli.ts --outfile ./dist/cli.js --target node && tsc --emitDeclarationOnly",
"generate:version": "node scripts/sync-version.mjs",
"build": "node scripts/sync-version.mjs && bun build ./src/index.ts --outdir ./dist --target node && bun build ./src/cli.ts --outfile ./dist/cli.js --target node && tsc --emitDeclarationOnly",
"dev": "tsc --watch",
"typecheck": "tsc --noEmit",
"test": "bun test"
"typecheck": "node scripts/sync-version.mjs && tsc --noEmit",
"test": "node scripts/sync-version.mjs && bun test"
},
"keywords": [
"opencode",
Expand Down
6 changes: 5 additions & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ echo "new version: $NEW_VERSION"

jq ".version = \"$NEW_VERSION\"" package.json > package.json.tmp && mv package.json.tmp package.json

git add package.json
# Keep src/version.ts (PLUGIN_VERSION) in sync with the bumped package.json so
# they cannot drift.
node scripts/sync-version.mjs

git add package.json src/version.ts
git commit -m "v$NEW_VERSION"
git tag "v$NEW_VERSION"

Expand Down
46 changes: 46 additions & 0 deletions scripts/sync-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env node
//
// Generates src/version.ts from the "version" field in package.json.
//
// The plugin version is needed at runtime (update check + telemetry metadata),
// but restating it in source lets it drift behind package.json. Deriving it from
// the single source of truth here makes that class of bug structurally impossible.
//
// Run automatically as part of `build` and the release script; it can also be
// invoked directly with `npm run generate:version`.

import { readFileSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const pkgPath = join(root, "package.json");
const outPath = join(root, "src", "version.ts");

const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
const version = pkg.version;

if (typeof version !== "string" || !version.trim()) {
console.error("sync-version: package.json has no valid \"version\" field");
process.exit(1);
}

const contents = `// AUTO-GENERATED by scripts/sync-version.mjs — do not edit by hand.
// Sourced from package.json "version" so the two cannot drift.
export const PLUGIN_VERSION = ${JSON.stringify(version)};
`;

const existing = (() => {
try {
return readFileSync(outPath, "utf-8");
} catch {
return null;
}
})();

if (existing !== contents) {
writeFileSync(outPath, contents);
console.log(`sync-version: wrote src/version.ts (PLUGIN_VERSION = ${version})`);
} else {
console.log(`sync-version: src/version.ts already up to date (${version})`);
}
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { stripJsoncComments } from "./services/jsonc.js";
import { loadCredentials } from "./services/auth.js";

const CONFIG_DIR = join(homedir(), ".config", "opencode");
export const PLUGIN_VERSION = "2.0.10";
export { PLUGIN_VERSION } from "./version.js";
const CONFIG_FILES = [
join(CONFIG_DIR, "supermemory.jsonc"),
join(CONFIG_DIR, "supermemory.json"),
Expand Down
3 changes: 2 additions & 1 deletion src/services/version-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function formatUpdateNotice(info: UpdateInfo): string {
return [
"[SUPERMEMORY UPDATE]",
`Supermemory update available: v${info.currentVersion} -> v${info.latestVersion}`,
`Run: ${info.updateCommand}`,
`Run (if you have a JS runtime): ${info.updateCommand}`,
`Otherwise (e.g. standalone opencode binary), pin "opencode-supermemory@${info.latestVersion}" in your opencode config and restart.`,
].join("\n");
}
3 changes: 3 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// AUTO-GENERATED by scripts/sync-version.mjs — do not edit by hand.
// Sourced from package.json "version" so the two cannot drift.
export const PLUGIN_VERSION = "2.0.11";
Loading