Skip to content

Commit

Permalink
fix: better pnp.cjs resolution in workspace (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
ha1fstack authored Oct 8, 2024
1 parent 14eedaa commit b6a8696
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"changelogithub": "^0.13.3",
"eslint": "^9.7.0",
"execa": "^8.0.1",
"find-up": "^7.0.0",
"get-port": "^6.1.2",
"istanbul-to-vscode": "^2.1.0",
"micromatch": "^4.0.5",
Expand Down
53 changes: 53 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/api/child_process.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { type ChildProcess, fork } from 'node:child_process'
import { pathToFileURL } from 'node:url'
import { dirname } from 'node:path'
import * as vscode from 'vscode'
import { gte } from 'semver'
import { findNode, formatPkg, getNodeJsVersion, showVitestError } from '../utils'
Expand Down Expand Up @@ -55,7 +54,7 @@ async function createChildVitestProcess(pkg: VitestPackage) {
NODE_ENV: env.NODE_ENV ?? process.env.NODE_ENV ?? 'test',
},
stdio: 'overlapped',
cwd: pnp ? dirname(pnp) : pkg.cwd,
cwd: pkg.cwd,
},
)

Expand Down
10 changes: 6 additions & 4 deletions src/api/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type * as vscode from 'vscode'
import { dirname, resolve } from 'pathe'
import { findUpSync } from 'find-up'
import { getConfig } from '../config'
import { normalizeDriveLetter } from '../worker/utils'

Expand Down Expand Up @@ -52,14 +53,15 @@ export function resolveVitestPackagePath(cwd: string, folder: vscode.WorkspaceFo

export function resolveVitestPnpPackagePath(cwd: string) {
try {
const pnpPath = require.resolve('./.pnp.cjs', {
paths: [cwd],
})
const pnpPath = findUpSync(['.pnp.js', '.pnp.cjs'], { cwd })
if (pnpPath == null) {
return null
}
const pnpApi = _require(pnpPath)
const vitestNodePath = pnpApi.resolveRequest('vitest/node', normalizeDriveLetter(cwd))
return {
pnpLoader: require.resolve('./.pnp.loader.mjs', {
paths: [cwd],
paths: [dirname(pnpPath)],
}),
pnpPath,
vitestNodePath,
Expand Down

0 comments on commit b6a8696

Please sign in to comment.