Skip to content

fix: respect npm registry - #4958

Merged
rekram1-node merged 3 commits into
devfrom
opencode/issue4830-20251201224636
Dec 1, 2025
Merged

rekram1-node merged 3 commits into
devfrom
opencode/issue4830-20251201224636

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

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

Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
@rekram1-node

Copy link
Copy Markdown
Collaborator

/oc drop this: .catch(() => {
// Fallback to default registry if configured registry fails
if (registry !== "https://registry.npmjs.org") {
return fetch(https://registry.npmjs.org/opencode-ai/${channel})
.then((res) => {
if (!res.ok) throw new Error(res.statusText)
return res.json()
})
.then((data: any) => data.version)
}
throw new Error("Failed to fetch latest version")
})

  there isn't much of a reason for it

@opencode-agent

opencode-agent Bot commented Dec 1, 2025 •

Copy link
Copy Markdown
Contributor Author

Done! I've simplified the latest() function by removing the .catch() fallback block and converting it to use await instead of promise chains. The function now respects the user's npm configuration without the unnecessary fallback logic.

New%20session%20-%202025-12-01T22%3A51%3A45.837Z
opencode session  |  github run

opencode-agent Bot and others added 2 commits December 1, 2025 22:52
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
@rekram1-node rekram1-node changed the title Fixed hardcoded npm registry with fallback support fix: version shouldn't use hardcoded registry Dec 1, 2025
@rekram1-node rekram1-node changed the title fix: version shouldn't use hardcoded registry fix: respect npm registry Dec 1, 2025
@rekram1-node
rekram1-node merged commit 8e248ae into dev Dec 1, 2025
5 checks passed
@thdxr
thdxr deleted the opencode/issue4830-20251201224636 branch February 7, 2026 06:24
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request May 5, 2026
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request Jun 14, 2026
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
MarsQiu007 referenced this pull request in MarsQiu007/openNovel Jul 31, 2026
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
meSingh pushed a commit to meSingh/opencode that referenced this pull request Sep 6, 2026
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
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.

opencode upgrade has hardcoded registry

1 participant