Skip to content

Commit

Permalink
feat: add Yarn PnP support (#134)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Hedger <nicolas@hedger.ch>
  • Loading branch information
roblillack and nhedger authored Feb 13, 2024
1 parent 1e2f1e1 commit 436d438
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,41 @@ async function getWorkspaceDependency(
outputChannel: OutputChannel,
): Promise<string | undefined> {
for (const workspaceFolder of workspace.workspaceFolders ?? []) {
// Check for Yarn PnP and try resolving the Biome binary without a node_modules
// folder first.
for (const ext of ["cjs", "js"]) {
const pnpFile = Uri.joinPath(workspaceFolder.uri, `.pnp.${ext}`);
if (!(await fileExists(pnpFile))) {
continue;
}

outputChannel.appendLine(
`Looks like a Yarn PnP workspace: ${workspaceFolder.uri.fsPath}`,
);
try {
const pnpApi = require(
Uri.joinPath(workspaceFolder.uri, ".pnp.cjs").fsPath,
);
const pkgPath = pnpApi.resolveRequest(
"@biomejs/biome/package.json",
workspaceFolder.uri.fsPath,
);
if (!pkgPath) {
throw new Error("No @biomejs/biome dependency configured");
}
return pnpApi.resolveRequest(
`@biomejs/cli-${process.platform}-${process.arch}/biome${
process.platform === "win32" ? ".exe" : ""
}`,
pkgPath,
);
} catch (err) {
outputChannel.appendLine(
`Could not resolve Biome using Yarn PnP in ${workspaceFolder.uri.fsPath}: ${err}`,
);
}
}

// To resolve the @biomejs/cli-*, which is a transitive dependency of the
// @biomejs/biome package, we need to create a custom require function that
// is scoped to @biomejs/biome. This allows us to reliably resolve the
Expand Down

0 comments on commit 436d438

Please sign in to comment.