From ed8f94768553b9eed2802b3f9781ff2897ab6434 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 20 Aug 2024 11:42:37 +0200 Subject: [PATCH] feat: support yarn pnp (#456) --- package.json | 3 ++- patches/@vitest__runner@2.0.5.patch | 34 +++++++++++++++++++++++++++++ pnpm-lock.yaml | 10 ++++++--- src/api/pkg.ts | 1 - src/api/resolve.ts | 10 ++------- src/api/rpc.ts | 8 +++---- src/worker/collect.ts | 12 +++++----- 7 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 patches/@vitest__runner@2.0.5.patch diff --git a/package.json b/package.json index 653f514..cc6fe1c 100644 --- a/package.json +++ b/package.json @@ -232,7 +232,8 @@ }, "pnpm": { "patchedDependencies": { - "birpc@0.2.17": "patches/birpc@0.2.17.patch" + "birpc@0.2.17": "patches/birpc@0.2.17.patch", + "@vitest/runner@2.0.5": "patches/@vitest__runner@2.0.5.patch" } }, "lint-staged": { diff --git a/patches/@vitest__runner@2.0.5.patch b/patches/@vitest__runner@2.0.5.patch new file mode 100644 index 0000000..2f601f9 --- /dev/null +++ b/patches/@vitest__runner@2.0.5.patch @@ -0,0 +1,34 @@ +diff --git a/dist/chunk-tasks.js b/dist/chunk-tasks.js +index 8d5d39d8ecfa64017593b50327215c95b600467a..8fb7f0add58b4aa6f173a8b1655498bf401ab0a8 100644 +--- a/dist/chunk-tasks.js ++++ b/dist/chunk-tasks.js +@@ -1,4 +1,3 @@ +-import { processError } from '@vitest/utils/error'; + import { relative } from 'pathe'; + import { toArray } from '@vitest/utils'; + +@@ -103,14 +102,18 @@ function checkAllowOnly(task, allowOnly) { + if (allowOnly) { + return; + } +- const error = processError( +- new Error( +- "[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error" +- ) +- ); ++ const error = new Error( ++ "[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error" ++ ) + task.result = { + state: "fail", +- errors: [error] ++ errors: [ ++ { ++ name: error.name, ++ stack: error.stack, ++ message: error.message ++ } ++ ] + }; + } + function generateHash(str) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index acc83f6..dd8ad49 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false patchedDependencies: + '@vitest/runner@2.0.5': + hash: 3p7vko36hcqzkg3jwrwmmj7lvy + path: patches/@vitest__runner@2.0.5.patch birpc@0.2.17: hash: 76ascauag252sgpxpwh3k26eya path: patches/birpc@0.2.17.patch @@ -57,7 +60,7 @@ devDependencies: version: 8.5.10 '@vitest/runner': specifier: ^2.0.5 - version: 2.0.5 + version: 2.0.5(patch_hash=3p7vko36hcqzkg3jwrwmmj7lvy) '@vitest/utils': specifier: ^2.0.5 version: 2.0.5 @@ -1234,12 +1237,13 @@ packages: tinyrainbow: 1.2.0 dev: true - /@vitest/runner@2.0.5: + /@vitest/runner@2.0.5(patch_hash=3p7vko36hcqzkg3jwrwmmj7lvy): resolution: {integrity: sha512-TfRfZa6Bkk9ky4tW0z20WKXFEwwvWhRY+84CnSEtq4+3ZvDlJyY32oNTJtM7AW9ihW90tX/1Q78cb6FjoAs+ig==} dependencies: '@vitest/utils': 2.0.5 pathe: 1.1.2 dev: true + patched: true /@vitest/snapshot@2.0.5: resolution: {integrity: sha512-SgCPUeDFLaM0mIUHfaArq8fD2WbaXG/zVXjRupthYfYGzc8ztbFbu6dUNOblBG7XLMR1kEhS/DNnfCZ2IhdDew==} @@ -4625,7 +4629,7 @@ packages: '@types/node': 20.12.8 '@vitest/expect': 2.0.5 '@vitest/pretty-format': 2.0.5 - '@vitest/runner': 2.0.5 + '@vitest/runner': 2.0.5(patch_hash=3p7vko36hcqzkg3jwrwmmj7lvy) '@vitest/snapshot': 2.0.5 '@vitest/spy': 2.0.5 '@vitest/utils': 2.0.5 diff --git a/src/api/pkg.ts b/src/api/pkg.ts index 7f768f2..f6ce1f0 100644 --- a/src/api/pkg.ts +++ b/src/api/pkg.ts @@ -60,7 +60,6 @@ function resolveVitestConfig(showWarning: boolean, configOrWorkspaceFile: vscode const prefix = `${basename(dirname(id))}:${basename(id)}` if (vitest.pnp) { - // TODO: try to load vitest package version from pnp return { folder, id, diff --git a/src/api/resolve.ts b/src/api/resolve.ts index 9b8af80..fca68a6 100644 --- a/src/api/resolve.ts +++ b/src/api/resolve.ts @@ -27,8 +27,8 @@ export function resolveVitestPackage(cwd: string, folder: vscode.WorkspaceFolder if (!pnp) return null return { - vitestNodePath: resolveVitestNodePath(pnp.vitestPath), - vitestPackageJsonPath: pnp.vitestPath, + vitestNodePath: 'vitest/node', + vitestPackageJsonPath: 'vitest/package.json', pnp: { loaderPath: pnp.pnpLoader, pnpPath: pnp.pnpPath, @@ -55,16 +55,10 @@ export function resolveVitestPnpPackagePath(cwd: string) { const pnpPath = require.resolve('./.pnp.cjs', { paths: [cwd], }) - const pnp = _require(pnpPath) - const vitestPath = pnp.resolveToUnqualified( - 'vitest/package.json', - cwd, - ) as string return { pnpLoader: require.resolve('./.pnp.loader.mjs', { paths: [cwd], }), - vitestPath, pnpPath, } } diff --git a/src/api/rpc.ts b/src/api/rpc.ts index 9f1878c..db54549 100644 --- a/src/api/rpc.ts +++ b/src/api/rpc.ts @@ -1,6 +1,6 @@ import v8 from 'node:v8' import { type BirpcReturn, createBirpc } from 'birpc' -import type { File, TaskResultPack, UserConsoleLog } from 'vitest' +import type { RunnerTestFile, TaskResultPack, UserConsoleLog } from 'vitest' export interface VitestMethods { getFiles: () => Promise<[project: string, file: string][]> @@ -21,9 +21,9 @@ export interface VitestMethods { export interface VitestEvents { onConsoleLog: (log: UserConsoleLog) => void onTaskUpdate: (task: TaskResultPack[]) => void - onFinished: (files: File[], unhandledError: string, collecting?: boolean) => void - onCollected: (files?: File[], collecting?: boolean) => void - onWatcherStart: (files?: File[], errors?: unknown[], collecting?: boolean) => void + onFinished: (files: RunnerTestFile[], unhandledError: string, collecting?: boolean) => void + onCollected: (files?: RunnerTestFile[], collecting?: boolean) => void + onWatcherStart: (files?: RunnerTestFile[], errors?: unknown[], collecting?: boolean) => void onWatcherRerun: (files: string[], trigger?: string, collecting?: boolean) => void } diff --git a/src/worker/collect.ts b/src/worker/collect.ts index 886136c..0a0730b 100644 --- a/src/worker/collect.ts +++ b/src/worker/collect.ts @@ -81,7 +81,7 @@ export async function astCollectTests( const file: ParsedFile = { filepath, type: 'suite', - id: generateHash(`${testFilepath}${ctx.config.name || ''}`), + id: /* @__PURE__ */ generateHash(`${testFilepath}${ctx.config.name || ''}`), name: testFilepath, mode: 'run', tasks: [], @@ -193,7 +193,7 @@ export async function astCollectTests( }, }) const indexMap = createIndexMap(request.code) - const map = request.map && new TraceMap(request.map as any) + const map = /* @__PURE__ */ request.map && new TraceMap(request.map as any) let lastSuite: ParsedSuite = file const updateLatestSuite = (index: number) => { while (lastSuite.suite && lastSuite.end < index) { @@ -213,7 +213,7 @@ export async function astCollectTests( const processedLocation = indexMap.get(definition.start) let location: { line: number; column: number } | undefined if (map && processedLocation) { - const originalLocation = originalPositionFor(map, { + const originalLocation = /* @__PURE__ */ originalPositionFor(map, { line: processedLocation.line, column: processedLocation.column, }) @@ -272,9 +272,9 @@ export async function astCollectTests( definition.task = task latestSuite.tasks.push(task) }) - calculateSuiteHash(file) - const hasOnly = someTasksAreOnly(file) - interpretTaskModes( + /* @__PURE__ */ calculateSuiteHash(file) + const hasOnly = /* @__PURE__ */ someTasksAreOnly(file) + /* @__PURE__ */ interpretTaskModes( file, ctx.config.testNamePattern, hasOnly,