[PM-34027] fix: use fileURLToPath for main module detection#168
[PM-34027] fix: use fileURLToPath for main module detection#168tecnologicachile wants to merge 2 commits intobitwarden:mainfrom
Conversation
The previous check using endsWith('index.js') fails when the server
is invoked via the npm binary wrapper (mcp-server-bitwarden), because
process.argv[1] points to the symlink rather than index.js.
Fixes bitwarden#158
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thank you for your contribution! We've added this to our internal tracking system for review. Details on our contribution process can be found here: https://contributing.bitwarden.com/contributing/pull-requests/community-pr-process. |
The previous fix using fileURLToPath alone still fails when Node.js invokes the script through the npm bin symlink, because process.argv[1] points to the symlink path while import.meta.url resolves to the real file. Using realpathSync ensures both paths resolve to the same target. Fixes bitwarden#158 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
withinfocus
left a comment
There was a problem hiding this comment.
Thanks for your contribution. We pin dependencies and you can remove your unrelated change.
| "prettier": "3.8.1", | ||
| "ts-jest": "29.4.6", | ||
| "typescript": "5.9.3", | ||
| "typescript": "^5.9.3", |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #168 +/- ##
=======================================
Coverage 51.92% 51.92%
=======================================
Files 12 12
Lines 909 909
Branches 197 197
=======================================
Hits 472 472
Misses 387 387
Partials 50 50 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
New Issues (1)Checkmarx found the following issues in this Pull Request
|





Summary
process.argv[1].endsWith('index.js')main module check withprocess.argv[1] === fileURLToPath(import.meta.url)import { fileURLToPath } from 'url'to support the new checkmcp-server-bitwarden), becauseprocess.argv[1]points to the symlink/wrapper script rather thanindex.js, so the server never startsTest plan
npm run buildcompiles successfullynpx mcp-server-bitwardenand verify the server starts (previously it would silently exit)node dist/index.jsdirectly and verify it still starts correctlyFixes #158
🤖 Generated with Claude Code