ES modules evaluate ALL static imports before any code executes.
ensureNativeBinary() was called but matrix-bot-sdk was already
loaded by the time it ran.
Solution: all imports are now dynamic (await import()). The setup
function calls ensureNativeBinary() first, then dynamically loads
everything else including matrix-bot-sdk transitively.
Changes:
- Remove all static imports from index.ts
- Move ensureNativeBinary() into async setup()
- Pass log/logError as parameters to runPlugin
- Make parseCodeModeTools async for dynamic acorn imports
- Add import type for MatrixEventContext (erased at compile time)
ES modules hoist all static imports before any code executes, so
matrix-bot-sdk was loaded BEFORE ensureNativeBinary() could download
the native binary. Using dynamic imports inside runPlugin ensures
the binary is downloaded first.
Add bootstrap-native.ts that downloads @matrix-org/matrix-sdk-crypto-nodejs
native binary before loading matrix-bot-sdk. This is needed because
opencode's npm doesn't run postinstall scripts, and the binary is required
for the Matrix SDK to work.
- Set noEmit to false in tsconfig.json
- Change main entry point from index.ts to dist/index.js
- Add files field to package.json
- Pre-compile TypeScript to JavaScript