1
1
import { compact } from '../../util/array.js' ;
2
+ import { dirname , join } from '../../util/path.js' ;
2
3
import { timerify } from '../../util/Performance.js' ;
3
- import { hasDependency , load } from '../../util/plugin.js' ;
4
+ import { hasDependency , load , tryResolve } from '../../util/plugin.js' ;
4
5
import { toEntryPattern } from '../../util/protocols.js' ;
5
6
import { getEnvPackageName , getExternalReporters } from './helpers.js' ;
6
7
import type { ViteConfigOrFn , VitestWorkspaceConfig , ViteConfig , MODE , COMMAND } from './types.js' ;
@@ -24,7 +25,11 @@ export const CONFIG_FILE_PATTERNS = ['vitest.config.ts', 'vitest.{workspace,proj
24
25
/** @public */
25
26
export const ENTRY_FILE_PATTERNS = [ '**/*.{test,spec}.?(c|m)[jt]s?(x)' ] ;
26
27
27
- const findConfigDependencies = ( localConfig : ViteConfig , options : GenericPluginCallbackOptions ) => {
28
+ const findConfigDependencies = (
29
+ configFilePath : string ,
30
+ localConfig : ViteConfig ,
31
+ options : GenericPluginCallbackOptions
32
+ ) => {
28
33
const { isProduction, config } = options ;
29
34
const testConfig = localConfig . test ;
30
35
@@ -35,28 +40,33 @@ const findConfigDependencies = (localConfig: ViteConfig, options: GenericPluginC
35
40
const environments = testConfig . environment ? [ getEnvPackageName ( testConfig . environment ) ] : [ ] ;
36
41
const reporters = getExternalReporters ( testConfig . reporters ) ;
37
42
const coverage = testConfig . coverage ? [ `@vitest/coverage-${ testConfig . coverage . provider ?? 'v8' } ` ] : [ ] ;
38
- const setupFiles = testConfig . setupFiles ? [ testConfig . setupFiles ] . flat ( ) : [ ] ;
39
- const globalSetup = testConfig . globalSetup ? [ testConfig . globalSetup ] . flat ( ) : [ ] ;
43
+ const toPath = ( v : string ) => tryResolve ( join ( dirname ( configFilePath ) , v ) , configFilePath ) ?? v ;
44
+ const setupFiles = ( testConfig . setupFiles ? [ testConfig . setupFiles ] . flat ( ) : [ ] ) . map ( toPath ) ;
45
+ const globalSetup = ( testConfig . globalSetup ? [ testConfig . globalSetup ] . flat ( ) : [ ] ) . map ( toPath ) ;
40
46
return [ ...entryPatterns , ...environments , ...reporters , ...coverage , ...setupFiles , ...globalSetup ] ;
41
47
} ;
42
48
43
- export const findVitestDependencies = async ( localConfig : ViteConfigOrFn , options : GenericPluginCallbackOptions ) => {
49
+ export const findVitestDependencies = async (
50
+ configFilePath : string ,
51
+ localConfig : ViteConfigOrFn ,
52
+ options : GenericPluginCallbackOptions
53
+ ) => {
44
54
if ( ! localConfig ) return [ ] ;
45
55
46
56
if ( typeof localConfig === 'function' ) {
47
57
const dependencies = new Set < string > ( ) ;
48
58
for ( const command of [ 'dev' , 'serve' , 'build' ] as COMMAND [ ] ) {
49
59
for ( const mode of [ 'development' , 'production' ] as MODE [ ] ) {
50
60
const config = await localConfig ( { command, mode, ssrBuild : undefined } ) ;
51
- findConfigDependencies ( config , options ) . forEach ( dependency => dependencies . add ( dependency ) ) ;
61
+ findConfigDependencies ( configFilePath , config , options ) . forEach ( dependency => dependencies . add ( dependency ) ) ;
52
62
}
53
63
}
54
64
return Array . from ( dependencies ) ;
55
65
}
56
66
57
67
if ( ! localConfig . test ) return [ ] ;
58
68
59
- return findConfigDependencies ( localConfig , options ) ;
69
+ return findConfigDependencies ( configFilePath , localConfig , options ) ;
60
70
} ;
61
71
62
72
const findVitestWorkspaceDependencies : GenericPluginCallback = async ( configFilePath , options ) => {
@@ -65,7 +75,9 @@ const findVitestWorkspaceDependencies: GenericPluginCallback = async (configFile
65
75
const dependencies = new Set < string > ( ) ;
66
76
for ( const config of [ localConfig ] . flat ( ) ) {
67
77
if ( config && typeof config !== 'string' ) {
68
- ( await findVitestDependencies ( config , options ) ) . forEach ( dependency => dependencies . add ( dependency ) ) ;
78
+ ( await findVitestDependencies ( configFilePath , config , options ) ) . forEach ( dependency =>
79
+ dependencies . add ( dependency )
80
+ ) ;
69
81
}
70
82
}
71
83
return compact ( dependencies ) ;
0 commit comments