Skip to content

Conversation

@stevenvo
Copy link

@stevenvo stevenvo commented Dec 23, 2025

This commit addresses two issues with the bin/opencode wrapper script:

  1. 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.

  2. 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:

  • Use Node.js instead of Bun for running the wrapper
  • Test local builds via npm link or similar methods

The changes are backward compatible - production packages continue to
work as the wrapper still checks node_modules/ as a fallback.

…uilds

This commit addresses two issues with the bin/opencode wrapper script:

1. **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.

2. **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:
- Use Node.js instead of Bun for running the wrapper
- Test local builds via npm link or similar methods

The changes are backward compatible - production packages continue to
work as the wrapper still checks node_modules/ as a fallback.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@rekram1-node
Copy link
Collaborator

/review


const scriptPath = fs.realpathSync(__filename)
const scriptDir = path.dirname(scriptPath)
const scriptDir = __dirname
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential behavioral change: The original code used path.dirname(fs.realpathSync(__filename)) for scriptDir, which resolves symlinks. The new code sets scriptDir = __dirname which does NOT resolve symlinks (only scriptPath does). This could cause different behavior when the bin script is symlinked (e.g., via npm link). Consider using path.dirname(scriptPath) instead of __dirname to preserve the original symlink-resolving behavior, or remove scriptPath if it is no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants