Skip to content

Commit 48a5b43

Browse files
authored
Merge pull request #14 from iHildy/fix/opencode-synced-0.4.2
fix: harden plugin loading and add pack test
2 parents 97ef032 + 9435fae commit 48a5b43

6 files changed

Lines changed: 92 additions & 18 deletions

File tree

.mise/tasks/local-pack-test

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
#MISE description="Install packed plugin into OpenCode cache (production-like test)"
3+
set -euo pipefail
4+
5+
PLUGIN_LOCAL_FILE="${HOME}/.config/opencode/plugin/opencode-synced-local.ts"
6+
CACHE_DIR="${HOME}/.cache/opencode"
7+
PACKAGE_DIR="$(pwd)"
8+
VERSION="$(node -p "require('./package.json').version")"
9+
10+
if [ -f "${PLUGIN_LOCAL_FILE}" ]; then
11+
rm -f "${PLUGIN_LOCAL_FILE}"
12+
fi
13+
14+
TARBALL="$(npm pack | tail -n 1)"
15+
16+
rm -rf "${CACHE_DIR}/node_modules/opencode-synced"
17+
18+
if [ -f "${CACHE_DIR}/package.json" ]; then
19+
python - <<PY
20+
import json, re
21+
from pathlib import Path
22+
version = "${VERSION}"
23+
path = Path("${CACHE_DIR}") / "package.json"
24+
text = path.read_text()
25+
deps = dict(re.findall(r'\"([^\\\"]+)\"\\s*:\\s*\"([^\\\"]+)\"', text))
26+
deps["opencode-synced"] = version
27+
path.write_text(json.dumps({"dependencies": deps}, indent=2) + "\\n")
28+
PY
29+
fi
30+
31+
(cd "${CACHE_DIR}" && npm install --no-save "${PACKAGE_DIR}/${TARBALL}")
32+
33+
echo "Installed ${TARBALL} (${VERSION}) into ${CACHE_DIR}"

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.4.1"
2+
".": "0.4.2"
33
}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to this project will be documented here by Release Please.
44

5+
## [0.4.2](https://github.com/iHildy/opencode-synced/compare/v0.3.0...v0.4.2) (2025-12-31)
6+
7+
8+
### Bug Fixes
9+
10+
* harden plugin load when command assets are missing and broaden module exports
11+
* add production-like local pack test script
12+
513
## [0.4.1](https://github.com/iHildy/opencode-synced/compare/v0.4.0...v0.4.1) (2025-12-31)
614

715

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,25 @@ bun -e '
247247
- `bun run test`
248248
- `bun run lint`
249249

250+
### Local testing (production-like)
251+
252+
To test the same artifact that would be published, install from a packed tarball
253+
into OpenCode's cache:
254+
255+
```bash
256+
mise run local-pack-test
257+
```
258+
259+
Then set `~/.config/opencode/opencode.json` to use:
260+
261+
```jsonc
262+
{
263+
"plugin": ["opencode-synced"]
264+
}
265+
```
266+
267+
Restart OpenCode to pick up the cached install.
268+
250269

251270
## Prefer a CLI version?
252271

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
22
"name": "opencode-synced",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "Sync global OpenCode config across machines via GitHub.",
55
"author": {
66
"name": "Ian Hildebrand"
77
},
88
"type": "module",
9+
"main": "./dist/index.js",
10+
"types": "./dist/index.d.ts",
911
"exports": {
1012
".": {
13+
"import": "./dist/index.js",
1114
"types": "./dist/index.d.ts",
1215
"default": "./dist/index.js"
1316
}
@@ -19,9 +22,7 @@
1922
"publishConfig": {
2023
"access": "public"
2124
},
22-
"files": [
23-
"dist"
24-
],
25+
"files": ["dist"],
2526
"dependencies": {
2627
"@opencode-ai/plugin": "1.0.85"
2728
},
@@ -38,6 +39,7 @@
3839
},
3940
"scripts": {
4041
"build": "rm -rf dist && tsc -p tsconfig.build.json && cp -r src/command dist/command",
42+
"prepack": "bun run build",
4143
"test": "vitest run",
4244
"test:watch": "vitest",
4345
"lint": "biome lint .",
@@ -47,8 +49,6 @@
4749
"prepare": "husky"
4850
},
4951
"lint-staged": {
50-
"*.{js,ts,json}": [
51-
"biome check --write --no-errors-on-unmatched"
52-
]
52+
"*.{js,ts,json}": ["biome check --write --no-errors-on-unmatched"]
5353
}
5454
}

src/index.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,29 @@ async function loadCommands(): Promise<ParsedCommand[]> {
8181
const commands: ParsedCommand[] = [];
8282
const commandDir = path.join(getModuleDir(), 'command');
8383

84+
try {
85+
const stats = await fs.stat(commandDir);
86+
if (!stats.isDirectory()) {
87+
return commands;
88+
}
89+
} catch {
90+
return commands;
91+
}
92+
8493
const files = await scanMdFiles(commandDir);
8594
for (const file of files) {
86-
const content = await fs.readFile(file, 'utf-8');
87-
const { frontmatter, body } = parseFrontmatter(content);
88-
const relativePath = path.relative(commandDir, file);
89-
const name = relativePath.replace(/\.md$/, '').replace(/\//g, '-');
90-
91-
commands.push({
92-
name,
93-
frontmatter,
94-
template: body,
95-
});
95+
try {
96+
const content = await fs.readFile(file, 'utf-8');
97+
const { frontmatter, body } = parseFrontmatter(content);
98+
const relativePath = path.relative(commandDir, file);
99+
const name = relativePath.replace(/\.md$/, '').replace(/\//g, '-');
100+
101+
commands.push({
102+
name,
103+
frontmatter,
104+
template: body,
105+
});
106+
} catch {}
96107
}
97108

98109
return commands;
@@ -210,6 +221,9 @@ export const OpencodeConfigSync: Plugin = async (ctx) => {
210221
};
211222
};
212223

224+
export const OpencodeSynced = OpencodeConfigSync;
225+
export default OpencodeConfigSync;
226+
213227
function formatError(error: unknown): string {
214228
if (error instanceof Error) return error.message;
215229
return String(error);

0 commit comments

Comments
 (0)