1
1
import type { IsPluginEnabled , Plugin , ResolveConfig , ResolveEntryPaths } from '../../types/config.js' ;
2
- import { type Input , toDeferResolveEntry , toDevDependency , toEntry } from '../../util/input.js' ;
3
- import { isInternal , join } from '../../util/path.js' ;
2
+ import { type Input , toEntry } from '../../util/input.js' ;
3
+ import { join } from '../../util/path.js' ;
4
4
import { hasDependency } from '../../util/plugin.js' ;
5
- import type { Config , ConfigOptions } from './types .js' ;
5
+ import { type ConfigFile , configFiles , inputsFromFrameworks , inputsFromPlugins , loadConfig } from './helpers .js' ;
6
6
7
7
// https://karma-runner.github.io/latest/config/configuration-file.html
8
8
@@ -12,50 +12,29 @@ const enablers = ['karma'];
12
12
13
13
const isEnabled : IsPluginEnabled = ( { dependencies } ) => hasDependency ( dependencies , enablers ) ;
14
14
15
- //👇 All but CoffeeScript ones. Low usage nowadays compared to the effort to implement support for those files
16
- const config = [ 'karma.conf.js' , 'karma.conf.ts' , '.config/karma.conf.js' , '.config/karma.conf.ts' ] ;
15
+ const config = configFiles ;
17
16
18
17
const entry : string [ ] = [ ] ;
19
18
20
- type ConfigFile = ( config : Config ) => void ;
21
-
22
19
const resolveConfig : ResolveConfig < ConfigFile > = async ( localConfig , options ) => {
23
20
const inputs = new Set < Input > ( ) ;
24
21
25
22
const config = loadConfig ( localConfig ) ;
23
+ if ( ! config ) return [ ] ;
26
24
27
25
if ( config . frameworks ) {
28
- for ( const framework of config . frameworks ) {
29
- inputs . add ( toDevDependency ( devDepForFramework ( framework ) ) ) ;
30
- }
31
- }
32
- if ( config . plugins ) {
33
- for ( const plugin of config . plugins ) {
34
- if ( typeof plugin !== 'string' ) continue ;
35
- if ( isInternal ( plugin ) ) {
36
- inputs . add ( toDeferResolveEntry ( plugin ) ) ;
37
- } else {
38
- inputs . add ( toDevDependency ( plugin ) ) ;
39
- }
40
- }
41
- } else {
42
- const karmaPluginDevDeps = Object . keys ( options . manifest . devDependencies ?? { } ) . filter ( name =>
43
- name . startsWith ( 'karma-' )
44
- ) ;
45
- for ( const karmaPluginDevDep of karmaPluginDevDeps ) {
46
- inputs . add ( toDevDependency ( karmaPluginDevDep ) ) ;
47
- }
26
+ inputsFromFrameworks ( config . frameworks ) . forEach ( inputs . add , inputs ) ;
48
27
}
28
+ inputsFromPlugins ( config . plugins , options . manifest . devDependencies ) . forEach ( inputs . add , inputs ) ;
49
29
50
30
return Array . from ( inputs ) ;
51
31
} ;
52
32
53
- const devDepForFramework = ( framework : string ) : string => ( framework === 'jasmine' ? 'jasmine-core' : framework ) ;
54
-
55
33
const resolveEntryPaths : ResolveEntryPaths < ConfigFile > = ( localConfig , options ) => {
56
34
const inputs = new Set < Input > ( ) ;
57
35
58
36
const config = loadConfig ( localConfig ) ;
37
+ if ( ! config ) return [ ] ;
59
38
60
39
const basePath = config . basePath ?? '' ;
61
40
if ( config . files ) {
@@ -73,28 +52,6 @@ const resolveEntryPaths: ResolveEntryPaths<ConfigFile> = (localConfig, options)
73
52
return Array . from ( inputs ) ;
74
53
} ;
75
54
76
- const loadConfig = ( configFile : ConfigFile ) : ConfigOptions => {
77
- const inMemoryConfig = new InMemoryConfig ( ) ;
78
- configFile ( inMemoryConfig ) ;
79
- return inMemoryConfig . config ?? { } ;
80
- } ;
81
-
82
- /**
83
- * Dummy configuration class with no default config options
84
- * Relevant config options' defaults are empty, so that's good enough
85
- * Real class: https://github.com/karma-runner/karma/blob/v6.4.4/lib/config.js#L275
86
- */
87
- class InMemoryConfig implements Config {
88
- config ?: ConfigOptions ;
89
- /**
90
- * Real method merges configurations with Lodash's `mergeWith`
91
- * https://github.com/karma-runner/karma/blob/v6.4.4/lib/config.js#L343
92
- */
93
- set ( config : ConfigOptions ) {
94
- this . config = config ;
95
- }
96
- }
97
-
98
55
export default {
99
56
title,
100
57
enablers,
0 commit comments