diff --git a/package.json b/package.json index dc090bb8..59c7d0a5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f11fd5db..555f560b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -82,6 +82,9 @@ devDependencies: execa: specifier: ^8.0.1 version: 8.0.1 + find-up: + specifier: ^7.0.0 + version: 7.0.0 get-port: specifier: ^6.1.2 version: 6.1.2 @@ -856,6 +859,7 @@ packages: resolution: {integrity: sha512-0fZBq27b+D7Ar5CQMofVN8sggOVhEtzFUwOwPppQt0k+VR+7UHMZZY4y+64WJ06XOhBTKXtQB/Sv0NwQMXyNAA==} cpu: [arm64] os: [linux] + libc: [glibc] requiresBuild: true dev: true optional: true @@ -864,6 +868,7 @@ packages: resolution: {integrity: sha512-eTvzUS3hhhlgeAv6bfigekzWZjaEX9xP9HhxB0Dvrdbkk5w/b+1Sxct2ZuDxNJKzsRStSq1EaEkVSEe7A7ipgQ==} cpu: [arm64] os: [linux] + libc: [musl] requiresBuild: true dev: true optional: true @@ -872,6 +877,7 @@ packages: resolution: {integrity: sha512-ix+qAB9qmrCRiaO71VFfY8rkiAZJL8zQRXveS27HS+pKdjwUfEhqo2+YF2oI+H/22Xsiski+qqwIBxVewLK7sw==} cpu: [riscv64] os: [linux] + libc: [glibc] requiresBuild: true dev: true optional: true @@ -880,6 +886,7 @@ packages: resolution: {integrity: sha512-TenQhZVOtw/3qKOPa7d+QgkeM6xY0LtwzR8OplmyL5LrgTWIXpTQg2Q2ycBf8jm+SFW2Wt/DTn1gf7nFp3ssVA==} cpu: [x64] os: [linux] + libc: [glibc] requiresBuild: true dev: true optional: true @@ -888,6 +895,7 @@ packages: resolution: {integrity: sha512-LfFdRhNnW0zdMvdCb5FNuWlls2WbbSridJvxOvYWgSBOYZtgBfW9UGNJG//rwMqTX1xQE9BAodvMH9tAusKDUw==} cpu: [x64] os: [linux] + libc: [musl] requiresBuild: true dev: true optional: true @@ -3057,6 +3065,15 @@ packages: path-exists: 4.0.0 dev: true + /find-up@7.0.0: + resolution: {integrity: sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g==} + engines: {node: '>=18'} + dependencies: + locate-path: 7.2.0 + path-exists: 5.0.0 + unicorn-magic: 0.1.0 + dev: true + /flat-cache@4.0.1: resolution: {integrity: sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==} engines: {node: '>=16'} @@ -3865,6 +3882,13 @@ packages: p-locate: 5.0.0 dev: true + /locate-path@7.2.0: + resolution: {integrity: sha512-gvVijfZvn7R+2qyPX8mAuKcFGDf6Nc61GdvGafQsHL0sBIxfKzA+usWn4GFC/bk+QdwPUD4kWFJLhElipq+0VA==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + p-locate: 6.0.0 + dev: true + /lodash.includes@4.3.0: resolution: {integrity: sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==} dev: true @@ -4369,6 +4393,13 @@ packages: yocto-queue: 0.1.0 dev: true + /p-limit@4.0.0: + resolution: {integrity: sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + yocto-queue: 1.1.1 + dev: true + /p-locate@4.1.0: resolution: {integrity: sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==} engines: {node: '>=8'} @@ -4383,6 +4414,13 @@ packages: p-limit: 3.1.0 dev: true + /p-locate@6.0.0: + resolution: {integrity: sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + p-limit: 4.0.0 + dev: true + /p-try@2.2.0: resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==} engines: {node: '>=6'} @@ -4467,6 +4505,11 @@ packages: engines: {node: '>=8'} dev: true + /path-exists@5.0.0: + resolution: {integrity: sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dev: true + /path-is-absolute@1.0.1: resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==} engines: {node: '>=0.10.0'} @@ -5447,6 +5490,11 @@ packages: engines: {node: '>=18.17'} dev: true + /unicorn-magic@0.1.0: + resolution: {integrity: sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==} + engines: {node: '>=18'} + dev: true + /unist-util-stringify-position@2.0.3: resolution: {integrity: sha512-3faScn5I+hy9VleOq/qNbAd6pAx7iH5jYBMS9I1HgQVijz/4mv5Bvw5iw1sC/90CODiKo81G/ps8AJrISn687g==} dependencies: @@ -5831,3 +5879,8 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} dev: true + + /yocto-queue@1.1.1: + resolution: {integrity: sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g==} + engines: {node: '>=12.20'} + dev: true diff --git a/src/api/child_process.ts b/src/api/child_process.ts index a4e2fcc7..68e19096 100644 --- a/src/api/child_process.ts +++ b/src/api/child_process.ts @@ -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' @@ -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, }, ) diff --git a/src/api/resolve.ts b/src/api/resolve.ts index f83ff649..2856954c 100644 --- a/src/api/resolve.ts +++ b/src/api/resolve.ts @@ -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' @@ -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,