-
Notifications
You must be signed in to change notification settings - Fork 4
feat!: support pnpm global virtual store paths and upgrade pnpm to 10.32.1 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9cac784
feat: support pnpm global virtual store paths in replacePnpmInner
SoonIter d85d326
chore: upgrade pnpm to 10.32.1 and enable global virtual store
SoonIter 94c9173
feat: normalize pnpm inner path prefix for consistent snapshots
SoonIter 3e10236
fix: address PR review feedback
SoonIter 2a87049
refactor: extract pnpmInner from matcher pipeline into standalone fun…
SoonIter 02e487e
refactor: move pnpm logic into src/pnpm/ directory
SoonIter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| enable-global-virtual-store=true | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { createSnapshotSerializer } from 'path-serializer'; | ||
| import { expect, test } from 'vitest'; | ||
|
|
||
| expect.addSnapshotSerializer( | ||
| createSnapshotSerializer({ | ||
| root: '/Users/user/project', | ||
| }), | ||
| ); | ||
|
|
||
| test('should serialize pnpm global virtual store path (posix)', () => { | ||
| const filePath = | ||
| '/Users/user/project/node_modules/../../../../../../Library/pnpm/store/v10/links/react/19.2.4/5c6e83be0e5f1f15e83462f0b7655d9d9338d33338bad7cc29bc12f2daa11aa3/node_modules/react/index.js'; | ||
|
|
||
| expect(filePath).toMatchInlineSnapshot(`"<PNPM_INNER>/react/index.js"`); | ||
| }); | ||
|
|
||
| test('should serialize pnpm global virtual store path with cjs (posix)', () => { | ||
| const filePath = | ||
| '/Users/user/project/node_modules/../../../../../../Library/pnpm/store/v10/links/react/19.2.4/5c6e83be0e5f1f15e83462f0b7655d9d9338d33338bad7cc29bc12f2daa11aa3/node_modules/react/cjs/react.production.js'; | ||
|
|
||
| expect(filePath).toMatchInlineSnapshot( | ||
| `"<PNPM_INNER>/react/cjs/react.production.js"`, | ||
| ); | ||
| }); | ||
|
|
||
| test('should serialize pnpm global virtual store path with scoped package', () => { | ||
| const filePath = | ||
| '/Users/user/project/node_modules/../../../../../../Library/pnpm/store/v10/links/@babel/core/7.25.0/abc123def456/node_modules/@babel/core/lib/index.js'; | ||
|
|
||
| expect(filePath).toMatchInlineSnapshot( | ||
| `"<PNPM_INNER>/@babel/core/lib/index.js"`, | ||
| ); | ||
| }); | ||
|
|
||
| test('should serialize pnpm global virtual store path (win32)', () => { | ||
| const serializer = createSnapshotSerializer({ | ||
| root: 'D:\\user\\project', | ||
| features: { | ||
| transformWin32Path: true, | ||
| }, | ||
| }); | ||
|
|
||
| const filePath = | ||
| 'D:\\user\\project\\node_modules\\..\\..\\..\\..\\..\\..\\Library\\pnpm\\store\\v10\\links\\react\\19.2.4\\5c6e83be0e5f1f15e83462f0b7655d9d9338d33338bad7cc29bc12f2daa11aa3\\node_modules\\react\\index.js'; | ||
|
|
||
| expect(serializer.serialize(filePath)).toMatchInlineSnapshot( | ||
| `"\\"<PNPM_INNER>/react/index.js\\""`, | ||
| ); | ||
| }); |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { replacePnpmInnerPath } from './replacePnpmInnerPath'; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| const PNPM_INNER_TOKEN = '<PNPM_INNER>'; | ||
| const PNPM_INNER_DELIMITERS = /[\s!"']/; | ||
|
|
||
| // local virtual store: .pnpm/<pkg>@<ver>/node_modules | ||
| const LOCAL_PNPM_POSIX = /(?<=\/)(\.pnpm\/.+?\/node_modules)(?=\/)/g; | ||
| const LOCAL_PNPM_WIN32 = /(?<=\\)(\.pnpm\\.+?\\node_modules)(?=\\)/g; | ||
| // global virtual store: pnpm/store/<versions>/links/<pkg>/<ver>/<hash>/node_modules | ||
| const GLOBAL_PNPM_POSIX = | ||
| /(?<=\/)pnpm\/store\/.+?\/links\/.+?\/node_modules(?=\/)/g; | ||
|
|
||
| /** | ||
| * Replace pnpm virtual store paths with `<PNPM_INNER>` and strip | ||
| * the environment-dependent prefix so that local virtual store | ||
| * and global virtual store both normalize to `<PNPM_INNER>/pkg/...`. | ||
| */ | ||
| export function replacePnpmInnerPath(str: string): string { | ||
| const replaced = str | ||
| .replace(LOCAL_PNPM_POSIX, PNPM_INNER_TOKEN) | ||
| .replace(LOCAL_PNPM_WIN32, PNPM_INNER_TOKEN) | ||
| .replace(GLOBAL_PNPM_POSIX, PNPM_INNER_TOKEN); | ||
|
|
||
| // Strip environment-dependent prefix before <PNPM_INNER> | ||
| // e.g. <ROOT>/node_modules/<PNPM_INNER> → <PNPM_INNER> | ||
| // Uses string splitting instead of regex to avoid ReDoS. | ||
| const parts = replaced.split(PNPM_INNER_TOKEN); | ||
| if (parts.length <= 1) return replaced; | ||
|
|
||
| for (let i = 0; i < parts.length - 1; i++) { | ||
| const part = parts[i]; | ||
| let j = part.length - 1; | ||
| while (j >= 0 && !PNPM_INNER_DELIMITERS.test(part[j])) { | ||
| j--; | ||
| } | ||
| parts[i] = part.substring(0, j + 1); | ||
| } | ||
|
|
||
| return parts.join(PNPM_INNER_TOKEN); | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.