1
1
import type { PackageJson } from '#p/types/package-json.js' ;
2
2
import type { IsPluginEnabled , Plugin , PluginOptions , ResolveConfig , ResolveEntryPaths } from '#p/types/plugins.js' ;
3
- import { isAbsolute , join , relative } from '#p/util/path.js' ;
4
- import { hasDependency , tryResolve } from '#p/util/plugin.js' ;
3
+ import { join } from '#p/util/path.js' ;
4
+ import { hasDependency , resolveEntry } from '#p/util/plugin.js' ;
5
5
import { toEntryPattern } from '#p/util/protocols.js' ;
6
6
import { getEnvPackageName , getExternalReporters } from './helpers.js' ;
7
7
import type { COMMAND , MODE , ViteConfig , ViteConfigOrFn , VitestWorkspaceConfig } from './types.js' ;
@@ -18,15 +18,6 @@ const config = ['vitest*.config.{js,mjs,ts,cjs,mts,cts}', 'vitest.{workspace,pro
18
18
19
19
const entry = [ '**/*.{bench,test,test-d,spec}.?(c|m)[jt]s?(x)' ] ;
20
20
21
- const resolveEntry = ( options : PluginOptions , rootDir : string , specifier : string ) => {
22
- const { configFileDir, configFileName } = options ;
23
- const resolvedPath = isAbsolute ( specifier )
24
- ? specifier
25
- : tryResolve ( join ( configFileDir , rootDir , specifier ) , join ( configFileDir , rootDir , configFileName ) ) ;
26
- if ( resolvedPath ) return toEntryPattern ( relative ( configFileDir , resolvedPath ) ) ;
27
- return specifier ;
28
- } ;
29
-
30
21
const isVitestCoverageCommand = / v i t e s t ( .+ ) - - c o v e r a g e (?: \. e n a b l e d (?: = t r u e ) ? ) ? / ;
31
22
32
23
const hasScriptWithCoverage = ( scripts : PackageJson [ 'scripts' ] ) =>
@@ -51,8 +42,9 @@ const findConfigDependencies = (localConfig: ViteConfig, options: PluginOptions)
51
42
const coverage = hasCoverageEnabled ? [ `@vitest/coverage-${ testConfig . coverage ?. provider ?? 'v8' } ` ] : [ ] ;
52
43
53
44
const rootDir = testConfig . root ?? '.' ;
54
- const setupFiles = [ testConfig . setupFiles ?? [ ] ] . flat ( ) . map ( v => resolveEntry ( options , rootDir , v ) ) ;
55
- const globalSetup = [ testConfig . globalSetup ?? [ ] ] . flat ( ) . map ( v => resolveEntry ( options , rootDir , v ) ) ;
45
+ const setupFiles = [ testConfig . setupFiles ?? [ ] ] . flat ( ) . map ( specifier => resolveEntry ( options , specifier , rootDir ) ) ;
46
+ const globalSetup = [ testConfig . globalSetup ?? [ ] ] . flat ( ) . map ( specifier => resolveEntry ( options , specifier , rootDir ) ) ;
47
+
56
48
return [ ...environments , ...reporters , ...coverage , ...setupFiles , ...globalSetup ] ;
57
49
} ;
58
50
@@ -101,7 +93,7 @@ export const resolveConfig: ResolveConfig<ViteConfigOrFn | VitestWorkspaceConfig
101
93
const entry = cfg . build ?. lib ?. entry ?? [ ] ;
102
94
const rootDir = cfg . test ?. root ?? '.' ;
103
95
const deps = ( typeof entry === 'string' ? [ entry ] : Object . values ( entry ) ) . map ( specifier =>
104
- resolveEntry ( options , rootDir , specifier )
96
+ resolveEntry ( options , specifier , rootDir )
105
97
) ;
106
98
for ( const dependency of deps ) dependencies . add ( dependency ) ;
107
99
}
0 commit comments