fix(npm): resolve cached package name from install dir for non-registry specs#25744
fix(npm): resolve cached package name from install dir for non-registry specs#25744sjawhar wants to merge 1 commit into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
c04201e to
afbbdb5
Compare
86adf74 to
2cb4a61
Compare
…ry specs For non-registry specs (remote tarball URLs, git+https://, github: shorthand, file: paths), npa(pkg).name returns undefined - only registry packages have inferable names from the spec alone. Read the install-root package.json written by Arborist on the initial install to recover the actual installed package name from its first dependency entry. When the cache directory exists but is empty (no package.json), fall through to the Arborist install path instead of returning a likely-failing entrypoint resolution. This preserves upstream's anomalyco#25354 fix for empty cache dirs while adding the cached-name resolution for non-registry specs.
2cb4a61 to
26c9a51
Compare
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #23653
Type of change
What does this PR do?
Fixes the regression introduced in #18308 where
Npm.add()cached install dirs keyed onnpa(pkg).name, which returnsundefinedfor non-registry specs (remote tarball URLs,git+https://, GitHub shorthand likeEdison-A-N/opencode-preview,file:paths). On a cache hit the code then calledresolveEntryPoint(undefined, ...), breaking subsequent installs of these specs.The fix recovers the actual installed package name by reading the install-root
package.json(written by Arborist on the initial install) and using its first dependency entry — matching what the fresh-install path computes from the arborist tree below it.Why this works:
lodash@4),npa(pkg).namereturns the package name as before — unchanged.package.jsoncontains adependenciesmap whose first key is the actual installed package name (Arborist writes this when reifying). We read that name and resolve againstnode_modules/<actual-name>/correctly.How did you verify your code works?
packages/opencode/test/npm.test.tscovering:undefined)packages/opencodeandpackages/coretest suites run locally — passbun typecheckpasses on both packagesScreenshots / recordings
N/A — no UI changes.
Checklist