-
Notifications
You must be signed in to change notification settings - Fork 3
chore: Update yarn to 4.13, add package age gate, fix pnpm linker path detection #198
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| nodeLinker: pnpm | ||
| compressionLevel: mixed | ||
|
|
||
| enableGlobalCache: true | ||
|
|
||
| yarnPath: .yarn/releases/yarn-3.6.3.cjs | ||
| nodeLinker: node-modules | ||
|
|
||
| npmMinimalAgeGate: 2880 | ||
|
|
||
| yarnPath: .yarn/releases/yarn-4.13.0.cjs |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * Checks if a URL or path string matches a specific package file, handling multiple | ||
| * node_modules layouts: | ||
| * - Classic (npm, pnpm, yarn classic): .../node_modules/{pkg}/{file} | ||
| * - Yarn 3 pnpm linker: .../node_modules/.store/{pkg}-npm-{ver}-{hash}/{pkg}/{file} | ||
| * - Yarn 4 pnpm linker: .../node_modules/.store/{pkg}-npm-{ver}-{hash}/package/{file} | ||
| */ | ||
| export function matchesPackageFile( | ||
| urlOrPath: string, | ||
| packageName: string, | ||
| filePath: string, | ||
| ): boolean { | ||
| if (urlOrPath.endsWith(`/${packageName}/${filePath}`)) return true; | ||
| // Yarn 4 pnpm linker uses 'package' as the subdirectory name inside .store entries | ||
| if (urlOrPath.endsWith(`/package/${filePath}`)) { | ||
| // Yarn 4 pnpm linker names store entries as: | ||
| // @scope/pkg → @scope-pkg-npm-ver-hash or @scope-pkg-virtual-hash | ||
| // pkg → pkg-npm-ver-hash or pkg-virtual-hash | ||
| const sanitized = packageName.replace("/", "-"); | ||
| if (urlOrPath.includes(`/.store/${sanitized}-`)) return true; | ||
| } | ||
| return false; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { spawnSync } from "node:child_process"; | ||
| import { existsSync } from "node:fs"; | ||
| import { resolve } from "node:path"; | ||
|
|
||
| import { integrationTest, readAppmaps, runAppmapNode } from "./helpers"; | ||
|
|
||
| // This test runs vitest in a separate project installed with yarn pnpm linker, | ||
| // verifying that matchesPackageFile() correctly identifies hook targets in the | ||
| // .store/pkg-npm-version-hash/package/ path format used by yarn 4 pnpm linker. | ||
|
|
||
| integrationTest("pnpm linker: vitest hooks instrument code in .store paths", () => { | ||
| const dir = resolve(__dirname, "pnpm-compat"); | ||
| if (!existsSync(resolve(dir, "node_modules"))) | ||
| spawnSync("yarn", ["install"], { | ||
| cwd: dir, | ||
| stdio: "inherit", | ||
| shell: process.platform === "win32", | ||
| }); | ||
|
Comment on lines
+11
to
+18
|
||
|
|
||
| expect(runAppmapNode("yarn", "vitest", "run").status).toBe(0); | ||
| expect(readAppmaps()).not.toEqual({}); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .yarn/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| nodeLinker: pnpm | ||
|
|
||
| enableGlobalCache: false | ||
|
|
||
| cacheFolder: ./.yarn/cache | ||
|
|
||
| globalFolder: ./.yarn/global | ||
|
|
||
| yarnPath: ../../.yarn/releases/yarn-4.13.0.cjs |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,4 @@ | ||||||
| name: pnpm-compat-appmap-node-test | ||||||
| packages: | ||||||
| - path: . | ||||||
|
Comment on lines
+2
to
+3
|
||||||
| packages: | |
| - path: . |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||||||
| { | ||||||||
| "name": "pnpm-compat-appmap-node-test", | ||||||||
| "private": true, | ||||||||
|
||||||||
| "private": true, | |
| "private": true, | |
| "packageManager": "yarn@4.13.0", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { expect, test } from "vitest"; | ||
|
|
||
| function sum(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| test("adds 1 + 2 to equal 3", () => { | ||
| expect(sum(1, 2)).toBe(3); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
| export default defineConfig({}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matchesPackageFile()can return false positives for Yarn 4 pnpm store paths because it checksincludes('/.store/${sanitized}-'). For example, packageNamevitewould also match a store entry likevite-node-...since it contains/.store/vite-. This could cause hooks to instrument/patch the wrong package file if the filePath suffix matches. Consider matching the store entry more strictly (e.g., require/.store/${sanitized}-(npm|virtual)-or otherwise enforce a delimiter after the package name).