Skip to content

Commit

Permalink
fix(vitest): use fast-glob instead of tinyglobby in Vitest (#6688)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Oct 12, 2024
1 parent 502ecbf commit 70baaaa
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 112 deletions.
350 changes: 320 additions & 30 deletions packages/vitest/LICENSE.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"chai-subset": "^1.6.0",
"cli-truncate": "^4.0.0",
"expect-type": "^0.19.0",
"fast-glob": "3.3.2",
"find-up": "^6.3.0",
"flatted": "^3.3.1",
"get-tsconfig": "^4.7.6",
Expand All @@ -201,7 +202,6 @@
"pretty-format": "^29.7.0",
"prompts": "^2.4.2",
"strip-literal": "^2.1.0",
"tinyglobby": "^0.2.6",
"ws": "^8.18.0"
}
}
5 changes: 2 additions & 3 deletions packages/vitest/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import license from 'rollup-plugin-license'
import { globSync } from 'tinyglobby'
import fg from 'fast-glob'
import c from 'tinyrainbow'
import { defineConfig } from 'rollup'

Expand Down Expand Up @@ -198,8 +198,7 @@ function licensePlugin() {
preserveSymlinks: false,
}),
)
const [licenseFile] = globSync([`${pkgDir}/LICENSE*`], {
expandDirectories: false,
const [licenseFile] = fg.sync(`${pkgDir}/LICENSE*`, {
caseSensitiveMatch: false,
})
if (licenseFile) {
Expand Down
11 changes: 6 additions & 5 deletions packages/vitest/src/node/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
} from 'vite'
import { ViteNodeRunner } from 'vite-node/client'
import { ViteNodeServer } from 'vite-node/server'
import { glob } from 'tinyglobby'
import fg from 'fast-glob'
import type { Typechecker } from '../typecheck/typechecker'
import { deepMerge, nanoid } from '../utils/base'
import { setup } from '../api/setup'
Expand Down Expand Up @@ -296,13 +296,14 @@ export class WorkspaceProject {
}

async globFiles(include: string[], exclude: string[], cwd: string) {
return glob(include, {
absolute: true,
const globOptions: fg.Options = {
dot: true,
cwd,
ignore: exclude,
expandDirectories: false,
})
}

const files = await fg(include, globOptions)
return files.map(file => resolve(cwd, file))
}

async isTargetFile(id: string, source?: string): Promise<boolean> {
Expand Down
10 changes: 6 additions & 4 deletions packages/vitest/src/node/workspace/resolveWorkspace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync, promises as fs } from 'node:fs'
import { isMainThread } from 'node:worker_threads'
import { dirname, relative, resolve } from 'pathe'
import { type GlobOptions, glob } from 'tinyglobby'
import fg from 'fast-glob'
import { mergeConfig } from 'vite'
import type { Vitest } from '../core'
import type { UserConfig, UserWorkspaceConfig, WorkspaceProjectConfiguration } from '../types/config'
Expand Down Expand Up @@ -209,12 +209,14 @@ async function resolveWorkspaceProjectConfigs(
}

if (workspaceGlobMatches.length) {
const globOptions: GlobOptions = {
const globOptions: fg.Options = {
absolute: true,
dot: true,
onlyFiles: false,
cwd: vitest.config.root,
expandDirectories: false,
markDirectories: true,
// TODO: revert option when we go back to tinyglobby
// expandDirectories: false,
ignore: [
'**/node_modules/**',
// temporary vite config file
Expand All @@ -224,7 +226,7 @@ async function resolveWorkspaceProjectConfigs(
],
}

const workspacesFs = await glob(workspaceGlobMatches, globOptions)
const workspacesFs = await fg.glob(workspaceGlobMatches, globOptions)

await Promise.all(workspacesFs.map(async (filepath) => {
// directories are allowed with a glob like `packages/*`
Expand Down
Loading

0 comments on commit 70baaaa

Please sign in to comment.