Skip to content
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

fix: broken Yarn PnP binary finder strategy #391

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: dev",
"sourceMapRenames": true
},
{
"name": "🧩 Debug Extension (yarn pnp)",
"type": "extensionHost",
"request": "launch",
"args": [
"--disable-extensions",
"--extensionDevelopmentKind=node",
"--extensionDevelopmentPath=${workspaceFolder}",
"${workspaceFolder}/test/fixtures/yarn-pnp"
],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: dev",
"sourceMapRenames": true
}
]
}
10 changes: 6 additions & 4 deletions src/binary-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const yarnPnpStrategy: LocatorStrategy = {
});

for (const extension of ["cjs", "js"]) {
const yarnPnpFile = Uri.file(`${path}/.pnp.${extension}`);
const yarnPnpFile = Uri.joinPath(path, `.pnp.${extension}`);

if (!(await fileExists(yarnPnpFile))) {
continue;
Expand All @@ -212,9 +212,11 @@ const yarnPnpStrategy: LocatorStrategy = {
continue;
}

return yarnPnpApi.resolveRequest(
`${platformSpecificNodePackageName}/${platformSpecificBinaryName}`,
biomePackage,
return Uri.file(
yarnPnpApi.resolveRequest(
`${platformSpecificNodePackageName}/${platformSpecificBinaryName}`,
biomePackage,
) as string,
);
} catch {
return undefined;
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/yarn-pnp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Swap the comments on the following lines if you wish to use zero-installs
# In that case, don't forget to run `yarn config set enableGlobalCache false`!
# Documentation here: https://yarnpkg.com/features/caching#zero-installs

#!.yarn/cache
.pnp.*
17 changes: 17 additions & 0 deletions test/fixtures/yarn-pnp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Yarn PnP

This folder contains an example single-root workspace used as a test fixture for
the Biome extension. The workspace folder is setup as a yarn pnp project.
ematipico marked this conversation as resolved.
Show resolved Hide resolved

## Expectations

When the workspace folder is opened in VS Code, the Biome extension should be active
and used the `biome.json` configuration file at the root of the workspace folder.

## Test protocol

1. Open the workspace in VS Code.
2. Run command `yarn`
3. Open the `index.js` file.
4. Run the `Format Document with...` command, and select the Biome extension.
5. Verify that the document gets formatted with `indentWidth` set to `2`. and `indentStyle` set to `space`.
1 change: 1 addition & 0 deletions test/fixtures/yarn-pnp/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions test/fixtures/yarn-pnp/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const a = 1;
8 changes: 8 additions & 0 deletions test/fixtures/yarn-pnp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "foo",
"version": "0.0.0",
"packageManager": "[email protected]",
"devDependencies": {
"@biomejs/biome": "1.8.3"
}
}
Empty file.