fix: respect npm config cwd for plugin installs#22765
Open
j4ng5y wants to merge 1 commit intoanomalyco:devfrom
Open
fix: respect npm config cwd for plugin installs#22765j4ng5y wants to merge 1 commit intoanomalyco:devfrom
j4ng5y wants to merge 1 commit intoanomalyco:devfrom
Conversation
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.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PRs FoundPR #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. |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #21123
Type of change
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.npmrccould 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):
Those all passed locally.
Also ... I used it and it fixed my issues 😄
Screenshots / recordings
n/a - not a UI change
Checklist