Skip to content

Commit

Permalink
fix: use node:path directly instead of pathe
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Oct 24, 2024
1 parent f6fbc26 commit 4ad6cd1
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 21 deletions.
4 changes: 1 addition & 3 deletions packages/vite-node/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { HotContext, ModuleCache, ViteNodeRunnerOptions } from './types'

import { createRequire } from 'node:module'
// we need native dirname, because windows __dirname has \\
import { dirname } from 'node:path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
import vm from 'node:vm'
import createDebug from 'debug'
import { resolve } from 'pathe'
import { extractSourceMap } from './source-map'
import {
cleanUrl,
Expand Down
8 changes: 0 additions & 8 deletions packages/vitest/src/node/cli/cac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,6 @@ function normalizeCliOptions(argv: CliOptions): CliOptions {
async function start(mode: VitestRunMode, cliFilters: string[], options: CliOptions): Promise<void> {
try {
process.title = 'node (vitest)'
// pathe always normalizes the drive letter to be uppercase
// if user runs Vitest from c:/, the built-in ESM loader in tests
// will resolve a different Vitest instance than the one in vite-node
// we can either
// 1. normalize the CWD so it works in the CLI, but might break when API is used directly
// 2. ask "pathe" to not normalize the drive letter
// 2. don't use "pathe" when resolving paths
process.chdir(normalize(process.cwd()))
}
catch {}

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/pools/forks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type { SerializedConfig } from '../types/config'
import type { WorkspaceProject } from '../workspace'
import EventEmitter from 'node:events'
import * as nodeos from 'node:os'
import { resolve } from 'node:path'
import v8 from 'node:v8'
import { createBirpc } from 'birpc'
import { resolve } from 'pathe'
import { Tinypool } from 'tinypool'
import { groupBy } from '../../utils/base'
import { wrapSerializableConfig } from '../../utils/config-helpers'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/pools/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type { SerializedConfig } from '../types/config'
import type { WorkerContext } from '../types/worker'
import type { WorkspaceProject } from '../workspace'
import * as nodeos from 'node:os'
import { resolve } from 'node:path'
import { MessageChannel } from 'node:worker_threads'
import { createBirpc } from 'birpc'
import { resolve } from 'pathe'
import Tinypool from 'tinypool'
import { groupBy } from '../../utils/base'
import { envsOrder, groupFilesByEnv } from '../../utils/test-helpers'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/pools/vmForks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type { ResolvedConfig, SerializedConfig } from '../types/config'
import type { WorkspaceProject } from '../workspace'
import EventEmitter from 'node:events'
import * as nodeos from 'node:os'
import { resolve } from 'node:path'
import v8 from 'node:v8'
import { createBirpc } from 'birpc'
import { resolve } from 'pathe'
import Tinypool from 'tinypool'
import { rootDir } from '../../paths'
import { wrapSerializableConfig } from '../../utils/config-helpers'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/pools/vmThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type { ResolvedConfig, SerializedConfig } from '../types/config'
import type { WorkerContext } from '../types/worker'
import type { WorkspaceProject } from '../workspace'
import * as nodeos from 'node:os'
import { resolve } from 'node:path'
import { MessageChannel } from 'node:worker_threads'
import { createBirpc } from 'birpc'
import { resolve } from 'pathe'
import Tinypool from 'tinypool'
import { rootDir } from '../../paths'
import { getWorkerMemoryLimit, stringToBytes } from '../../utils/memory-limit'
Expand Down
11 changes: 7 additions & 4 deletions packages/vitest/src/node/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import type {
import { promises as fs } from 'node:fs'
import { rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { deepMerge, nanoid } from '@vitest/utils'
import path from 'node:path'
import { deepMerge, nanoid, slash } from '@vitest/utils'
import fg from 'fast-glob'
import mm from 'micromatch'
import {
Expand All @@ -27,7 +28,6 @@ import {
join,
relative,
resolve,
toNamespacedPath,
} from 'pathe'
import { ViteNodeRunner } from 'vite-node/client'
import { ViteNodeServer } from 'vite-node/server'
Expand Down Expand Up @@ -302,7 +302,10 @@ export class WorkspaceProject {
}

const files = await fg(include, globOptions)
return files.map(file => resolve(cwd, file))
// keep the slashes consistent with Vite
// we are not using the pathe here because it normalizes the drive letter on Windows
// and we want to keep it the same as working dir
return files.map(file => slash(path.resolve(cwd, file)))
}

async isTargetFile(id: string, source?: string): Promise<boolean> {
Expand All @@ -329,7 +332,7 @@ export class WorkspaceProject {

filterFiles(testFiles: string[], filters: string[], dir: string) {
if (filters.length && process.platform === 'win32') {
filters = filters.map(f => toNamespacedPath(f))
filters = filters.map(f => path.toNamespacedPath(f))
}

if (filters.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/paths.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from 'node:path'
import url from 'node:url'
import { resolve } from 'pathe'

export const rootDir = resolve(url.fileURLToPath(import.meta.url), '../../')
export const distDir = resolve(
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/runners/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { VitestRunner, VitestRunnerConstructor } from '@vitest/runner'
import type { SerializedConfig } from '../config'
import type { VitestExecutor } from '../execute'
import { resolve } from 'pathe'
import { resolve } from 'node:path'
import { takeCoverageInsideWorker } from '../../integrations/coverage'
import { distDir } from '../../paths'
import { rpc } from '../rpc'
Expand Down

0 comments on commit 4ad6cd1

Please sign in to comment.