15
15
import * as fs from 'node:fs' ;
16
16
import * as git from './git' ;
17
17
import * as path from 'path' ;
18
- import { List , Map , Set } from 'immutable' ;
19
- import { minimatch } from 'minimatch' ; /* eslint-disable @typescript-eslint/no-explicit-any */
20
- import { Affected , TestAll , TestName , TestPath , mergeAffected } from './affected' ;
18
+ import { List , Map , Set } from 'immutable' ;
19
+ import { minimatch } from 'minimatch' ; /* eslint-disable @typescript-eslint/no-explicit-any */
20
+ import { Affected , AffectedTests , TestAll , TestName , TestPath , mergeAffected } from './affected' ;
21
21
22
22
type Args = {
23
23
root : string ;
24
24
path : string ;
25
25
} ;
26
26
27
- type ArgsTestSome = {
28
- root : string ;
29
- path : string ;
30
- tests : Map < TestPath , Set < TestName > > ;
31
- } ;
32
-
33
27
const IGNORE_GLOBAL = [ 'README.md' ] ;
34
28
35
29
export class Config {
36
30
match : List < string > ;
37
31
ignore : List < string > ;
38
32
packageFile : List < string > ;
39
- _lint : ( _ : Args ) => void ;
40
- _testAll : ( _ : Args ) => void ;
41
- _testSome : ( _ : ArgsTestSome ) => void ;
33
+ _lint : ( args : Args ) => void ;
34
+ _testAll : ( args : Args ) => void ;
35
+ _testSome : ( args : Args , tests : AffectedTests ) => void ;
42
36
43
37
constructor ( {
44
38
match,
@@ -51,16 +45,16 @@ export class Config {
51
45
match ?: string [ ] ;
52
46
ignore ?: string [ ] ;
53
47
packageFile ?: string [ ] ;
54
- lint ?: ( _ : Args ) => void ;
55
- testAll ?: ( _ : Args ) => void ;
56
- testSome ?: ( _ : ArgsTestSome ) => void ;
48
+ lint ?: ( args : Args ) => void ;
49
+ testAll ?: ( args : Args ) => void ;
50
+ testSome ?: ( args : Args , tests : AffectedTests ) => void ;
57
51
} ) {
58
52
this . match = List ( match || [ '**' ] ) ;
59
53
this . ignore = List ( ignore ) ;
60
54
this . packageFile = List ( packageFile ) ;
61
- this . _lint = lint || ( _ => { } ) ;
62
- this . _testAll = testAll || ( _ => { } ) ;
63
- this . _testSome = testSome || ( _ => { } ) ;
55
+ this . _lint = lint || ( _ => { } ) ;
56
+ this . _testAll = testAll || ( _ => { } ) ;
57
+ this . _testSome = testSome || ( _ => { } ) ;
64
58
}
65
59
66
60
affected = ( head : string , main : string ) : List < Affected > =>
@@ -76,30 +70,26 @@ export class Config {
76
70
) ;
77
71
78
72
lint = ( affected : Affected ) => {
73
+ const args = { root : git . root ( ) , path : affected . path } ;
79
74
const cwd = process . cwd ( ) ;
80
- const root = git . root ( ) ;
81
- const dir = path . join ( root , affected . path ) ;
75
+ const dir = path . join ( args . root , affected . path ) ;
82
76
console . log ( `> cd ${ dir } ` ) ;
83
77
process . chdir ( dir ) ;
84
- this . _lint ( { root : root , path : affected . path } ) ;
78
+ this . _lint ( args ) ;
85
79
process . chdir ( cwd ) ;
86
80
} ;
87
81
88
82
test = ( affected : Affected ) => {
83
+ const args = { root : git . root ( ) , path : affected . path } ;
89
84
const cwd = process . cwd ( ) ;
90
- const root = git . root ( ) ;
91
- const dir = path . join ( root , affected . path ) ;
85
+ const dir = path . join ( args . root , affected . path ) ;
92
86
console . log ( `> cd ${ dir } ` ) ;
93
87
process . chdir ( dir ) ;
94
88
if ( 'TestAll' in affected ) {
95
- this . _testAll ( { root : root , path : affected . path } ) ;
89
+ this . _testAll ( args ) ;
96
90
}
97
91
if ( 'TestSome' in affected ) {
98
- this . _testSome ( {
99
- root : root ,
100
- path : affected . path ,
101
- tests : affected . TestSome ,
102
- } ) ;
92
+ this . _testSome ( args , affected . TestSome ) ;
103
93
}
104
94
process . chdir ( cwd ) ;
105
95
} ;
0 commit comments