fix: convert bin/opencode to ES module syntax and support local dev builds #6044
+15
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit addresses two issues with the bin/opencode wrapper script:
ES Module Compatibility: Converts CommonJS require() syntax to ES
module imports. The package.json specifies "type": "module", which
causes Node.js to treat .js files as ES modules. While Bun (the
project's primary runtime) allows require() in ES modules, Node.js
strictly enforces ES module syntax, causing failures for developers
using Node.js.
Local Development Support: Adds check for binaries in dist/ folder
before looking in node_modules/. When developers build locally with
'bun run build' and use npm link for testing, the compiled binaries
are placed in dist/, but the wrapper only searched node_modules/,
causing it to fail.
These changes improve the developer experience for contributors who:
The changes are backward compatible - production packages continue to
work as the wrapper still checks node_modules/ as a fallback.