fix: derive package name from package.json under Yarn nodeLinker: pnpm store#1852
Merged
webpro merged 1 commit intoJul 4, 2026
Merged
Conversation
Yarn's nodeLinker: pnpm lays packages out as node_modules/.store/<flattened-locator>/package/ with no nested node_modules/<pkg>, so getPackageNameFromFilePath derived the last node_modules segment as '.store', surfacing bogus unlisted deps. Read the store package's own package.json name field, which is authoritative. The folder name (<flatIdent>-<protocol>-<reference>-<hash>) can't be parsed unambiguously: flattened scopes (@remix-run-router) and protocol markers colliding with real name segments (write-file-atomic).
commit: |
Member
|
Thanks Ben! |
Member
|
🚀 This pull request is included in v6.25.0. See Release 6.25.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
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.
Fixes #1851
Problem
Under Yarn Berry with
nodeLinker: pnpm, Knip reports bogus unlisted dependencies named.store.getPackageNameFromFilePathderives the package name from the lastnode_modules/segment. That holds for the pnpm CLI (node_modules/<pkg>/), but Yarn's pnpm linker lays packages out in a content-addressed store instead:There is no nested
node_modules/<pkg>, so the derived name is literally.store. It typically surfaces via plugins that resolve config files through store realpaths (e.g. Storybook/Babel addons viadirname(require.resolve('<addon>/package.json'))).Why not parse the folder name
The store folder is
<flatIdent>-<protocol>-<reference>-<hash>with scopes flattened (@scope/name→@scope-name), which is ambiguous two ways:@remix-run-routercould be@remix-run/routeror@remix/run-router.npm/virtual/patch/file/http/portal) are indistinguishable from real name segments (@dmsnell/diff-match-patch,write-file-atomic,@types/http-errors,is-npm).So the folder name can't be parsed back to a package name reliably. The store package's own
package.jsonnamefield is authoritative, so this reads that instead.Change
In
getPackageNameFromFilePath, when — and only when — the derived last segment is.store, resolve the name from the store package'spackage.json:…/node_modules/.store/<locator>/packagewith a(?:\/|$)boundary so it handles both paths that continue past/package/…and paths that end exactly at…/package(e.g. addon dirs fromdirname(require.resolve('<addon>/package.json'))).node_moduleslayouts never hit the filesystem and each store package is read at most once..store(prior behavior) if thepackage.jsonis missing/unreadable.This mirrors the existing sync-read +
Mapcache pattern insrc/manifest/helpers.ts.Tests
Added a fixture (
fixtures/yarn-pnpm-store) laid out as a Yarn pnpm store and unit tests intest/util/modules.test.tscovering:@remix-run/routerwrite-file-atomic/packagewith no trailing slash.storewhen nopackage.jsonexistsnode_modulespaths (including nested)pnpm build(tsgo),oxlint,oxfmt --check, and the module tests pass locally (node + bun). The approach is validated in a production repo usingnodeLinker: pnpm.