Skip to content

fix: respect npm config cwd for plugin installs#22765

Open
j4ng5y wants to merge 1 commit intoanomalyco:devfrom
j4ng5y:fix/plugin-npm-config
Open

fix: respect npm config cwd for plugin installs#22765
j4ng5y wants to merge 1 commit intoanomalyco:devfrom
j4ng5y:fix/plugin-npm-config

Conversation

@j4ng5y
Copy link
Copy Markdown

@j4ng5y j4ng5y commented Apr 16, 2026

Issue for this PR

Closes #21123

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This fixes plugin installs using the wrong cwd for npm config lookup.

I ran into issues trying to install a custom plugin from a private (Artifactory) npm registry. I assumed I wasn't the only one and was correct.

When I was reproducing #21123, the main issue I hit was that plugin/package installs could end up reading npm config from the ambient process.cwd() instead of the OpenCode instance/config directory that actually declared the plugin or provider. That meant private registry settings from .npmrc could get ignored.

While tracing that through, I also found the same problem affecting relative plugin paths like ./some-plugin, which could resolve from the wrong directory for the same reason.

This change makes those install flows use the instance/config directory explicitly instead of relying on whatever the current shell cwd happens to be. It also updates relative/path plugin resolution to use the directory that declared the plugin.

I added tests around the npm config path itself, plugin install flows, provider installs, config installs, and relative plugin resolution.

I think this works because it fixes the actual source of the problem: the install context was wrong. Once the right cwd gets threaded through, npm config resolution and relative plugin resolution both happen in the place they were meant to.

How did you verify your code works?

I ran targeted tests for the affected paths and typecheck (sorry for the mise pollution, but it's how I run things):

mise exec bun@1.3.11 -- bun --cwd packages/opencode test test/npm/npm.test.ts test/plugin/shared.test.ts test/plugin/install.test.ts test/plugin/loader-shared.test.ts test/cli/tui/plugin-install.test.ts --timeout 30000
mise exec bun@1.3.11 -- bun --cwd packages/opencode test test/provider/provider.test.ts test/config/config.test.ts --timeout 30000
mise exec bun@1.3.11 -- bun run --cwd packages/opencode typecheck

Those all passed locally.

Also ... I used it and it fixed my issues 😄

Screenshots / recordings

n/a - not a UI change

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Load npm config from the active instance/config directory when installing plugin and provider packages so project .npmrc settings and env precedence are preserved for cached installs.

Refs anomalyco#21123, anomalyco#21324, anomalyco#21436, anomalyco#21697, anomalyco#22025.
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PRs Found

PR #22025: fix(plugin): load npm config before Arborist installs

PR #21697: fix(opencode): resolve npmrc with @npmcli/config

These PRs appear to be addressing similar issues around npm configuration and plugin installation. Recommend checking their status and scope to ensure there's no overlap.

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.

Plugin install ignores scoped registries from ~/.npmrc and fetches from registry.npmjs.org

1 participant