5.9 KiB
Plan: Package JS Entry for OpenCode Node Loader
Goal
Fix GitHub issue #6 by making the published opencode-working-memory package loadable through OpenCode's Node-based plugin loader. The package must not expose TypeScript source files as runtime entry points under node_modules.
Background
opencode-working-memory@1.6.6 currently publishes:
main: "index.ts"exports["."]: "./index.ts"exports["./server"]: "./index.ts"exports["./tui"]: "./src/tui-plugin.ts"
Node can import the local repo index.ts, but refuses to strip TypeScript types for files under node_modules. This means local path testing passes while npm/opencode package-cache loading fails.
Proposed Changes
-
Expand the existing dist build config into a full package build.
- Update
tsconfig.memory-diag.jsonto includeindex.ts,src/**/*.ts,scripts/memory-diag.ts, andscripts/memory-diag/**/*.ts. - Remove the current exclusions for runtime plugin dependencies:
src/plugin.ts,src/tui-plugin.ts,src/opencode.ts,src/session-state.ts,src/extractors.ts,src/pending-journal.ts,src/promotion-accounting.ts, andsrc/memory-visibility.ts. - Keep
rootDir: "."andoutDir: "dist"soindex.tsemits todist/index.jsandsrc/tui-plugin.tsemits todist/src/tui-plugin.js. - Keep
rewriteRelativeImportExtensions: trueso emitted ESM imports point at.js.
- Update
-
Update
package.jsonruntime entry points.mainshould point todist/index.js.exports["."]andexports["./server"]should point to./dist/index.js.exports["./tui"]should point to./dist/src/tui-plugin.js.
-
Update build scripts.
- Keep one clean build path that emits both plugin runtime JS and
memory-diagJS. - Preserve the existing
memory-diagbinary wrapper behavior. - Rename or alias the script so the unified dist build is not hidden behind a memory-diag-only name.
- Keep one clean build path that emits both plugin runtime JS and
-
Update packaging tests.
- Add a smoke test that builds/packs/installs the tarball into a temporary prefix and imports
opencode-working-memoryfromnode_modules. - Assert the default export id is
working-memory. - Assert
opencode-working-memory/serverimports and exposes the same default plugin id. - Assert
opencode-working-memory/tuiimports and exposes the TUI plugin id. - Assert package manifest entry points do not point at
.ts. - Use an isolated npm cache under
/private/tmpor the test temp root so local~/.npmpermissions do not affect the smoke test.
- Add a smoke test that builds/packs/installs the tarball into a temporary prefix and imports
-
Update package file allowlist if needed.
- Ensure
dist/,scripts/memory-diag-bin.cjs,README.md, andLICENSEare included. - Keeping TypeScript source files in the tarball is acceptable only if runtime entry points resolve to JS.
- Ensure
Affected Files
package.jsontsconfig.memory-diag.jsonor a new build tsconfigtests/smoke/memory-diag-packaging.test.tsor a new smoke test undertests/smoke/CHANGELOG.md- Possibly
package-lock.jsonif package metadata changes require npm to refresh it
Verification
Run:
npm run build
test -f dist/index.js
test -f dist/src/tui-plugin.js
node -e "import('./dist/index.js').then(m => console.log(m.default.id))"
node -e "import('./dist/src/tui-plugin.js').then(m => console.log(m.default.id))"
rg 'from\s+\".*\\.ts\"|import\s*\\(.*\\.ts' dist
npm run typecheck
npm test
npm run check:package-integrity
Package-path smoke:
rm -rf /private/tmp/owm-pack /private/tmp/owm-install /private/tmp/npm-cache
mkdir -p /private/tmp/owm-pack /private/tmp/owm-install /private/tmp/npm-cache
npm pack --cache /private/tmp/npm-cache --pack-destination /private/tmp/owm-pack
npm install --cache /private/tmp/npm-cache --prefix /private/tmp/owm-install /private/tmp/owm-pack/opencode-working-memory-*.tgz
node -e "import('/private/tmp/owm-install/node_modules/opencode-working-memory').then(m => console.log(m.default.id))"
node -e "import('/private/tmp/owm-install/node_modules/opencode-working-memory/server').then(m => console.log(m.default.id))"
node -e "import('/private/tmp/owm-install/node_modules/opencode-working-memory/tui').then(m => console.log(m.default.id))"
Expected output for both import checks:
working-memory
For the TUI import, expected output is:
working-memory-tui
Also inspect the installed package manifest and assert main, exports["."], exports["./server"], and exports["./tui"] all point to .js files.
Release Preparation
After implementation and verification:
- Inspect
git diff. - Confirm the working tree contains only this release fix plus the pre-existing unrelated untracked plan.
- Add a
CHANGELOG.mdentry for1.6.7describing the Node loader/package entry fix. - Run
npm version patchor otherwise bumppackage.jsonandpackage-lock.jsonto1.6.7consistently. - If publishing from
main, prepare the verified package for publish after the final git diff review.
Risks
- Build config may expose TypeScript type-check errors in files that were previously excluded from
tsconfig.memory-diag.json. - Package smoke tests that call
npm packcan fail on the developer machine if~/.npmhas permission problems; tests should use an isolated cache under/private/tmp. - OpenCode may resolve
./serveror./tuidifferently from bare package import, so both exports should be checked. npm run check:package-integritycurrently checks package-lock version alignment only; entry-point assertions must live in packaging tests or a new entry-point check.- Publishing both
src/anddist/increases tarball size, but runtime correctness depends on the JS entry points rather than removing sources.
Rollback
Revert the package entry/build changes and publish a corrected package if the JS entry causes a runtime regression. Existing local-path development remains unaffected by reverting because it can still import TypeScript from outside node_modules.