[PR #4958] fix: respect npm registry #11187

Closed
opened 2026-02-16 18:15:59 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4958

State: closed
Merged: Yes


Summary

I've successfully fixed the hardcoded registry issue in packages/opencode/src/installation/index.ts. Here's what was changed:

Changes made:

  1. Added getRegistryUrl() function (lines 165-169): This function retrieves the user's configured npm registry using npm config get registry. If no registry is configured, it defaults to https://registry.npmjs.org.

  2. Updated latest() function (lines 171-194):

    • Now calls getRegistryUrl() to get the user's configured registry
    • Normalizes the registry URL by removing trailing slashes (to prevent double slashes in the final URL)
    • Attempts to fetch the latest version from the configured registry
    • Fallback mechanism: If the configured registry fails (e.g., a network error or 404), and it's not already the default registry, it falls back to registry.npmjs.org
    • If both the configured registry and the fallback fail, it throws an error

Key features:

  • Respects user's npm configuration
  • Falls back to registry.npmjs.org if the configured registry fails
  • Handles trailing slashes in registry URLs properly
  • Maintains backward compatibility with the default registry

Closes #4830

New%20session%20-%202025-12-01T22%3A46%3A35.945Z
opencode session  |  github run

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4958 **State:** closed **Merged:** Yes --- ## Summary I've successfully fixed the hardcoded registry issue in `packages/opencode/src/installation/index.ts`. Here's what was changed: ### Changes made: 1. **Added `getRegistryUrl()` function** (lines 165-169): This function retrieves the user's configured npm registry using `npm config get registry`. If no registry is configured, it defaults to `https://registry.npmjs.org`. 2. **Updated `latest()` function** (lines 171-194): - Now calls `getRegistryUrl()` to get the user's configured registry - Normalizes the registry URL by removing trailing slashes (to prevent double slashes in the final URL) - Attempts to fetch the latest version from the configured registry - **Fallback mechanism**: If the configured registry fails (e.g., a network error or 404), and it's not already the default registry, it falls back to `registry.npmjs.org` - If both the configured registry and the fallback fail, it throws an error ### Key features: - ✅ Respects user's npm configuration - ✅ Falls back to registry.npmjs.org if the configured registry fails - ✅ Handles trailing slashes in registry URLs properly - ✅ Maintains backward compatibility with the default registry Closes #4830 <a href="https://opencode.ai/s/mB7p7gBm"><img width="200" alt="New%20session%20-%202025-12-01T22%3A46%3A35.945Z" src="https://social-cards.sst.dev/opencode-share/TmV3IHNlc3Npb24gLSAyMDI1LTEyLTAxVDIyOjQ2OjM1Ljk0NVo=.png?model=opencode/claude-haiku-4-5&version=1.0.126&id=mB7p7gBm" /></a> [opencode session](https://opencode.ai/s/mB7p7gBm)&nbsp;&nbsp;|&nbsp;&nbsp;[github run](/sst/opencode/actions/runs/19840077688)
yindo added the pull-request label 2026-02-16 18:15:59 -05:00
yindo closed this issue 2026-02-16 18:15:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11187