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 , AffectedTests , TestAll , TestName , TestPath , mergeAffected } from './affected' ;
18
+ import { List } from 'immutable' ;
19
+ import { minimatch } from 'minimatch' ; /* eslint-disable @typescript-eslint/no-explicit-any */
20
+ import { Affected , AffectedTests , TestAll , mergeAffected } from './affected' ;
21
21
22
22
type Args = {
23
23
root : string ;
@@ -52,9 +52,9 @@ export class Config {
52
52
this . match = List ( match || [ '**' ] ) ;
53
53
this . ignore = List ( ignore ) ;
54
54
this . packageFile = List ( packageFile ) ;
55
- this . _lint = lint || ( _ => { } ) ;
56
- this . _testAll = testAll || ( _ => { } ) ;
57
- this . _testSome = testSome || ( _ => { } ) ;
55
+ this . _lint = lint || ( _ => { } ) ;
56
+ this . _testAll = testAll || ( _ => { } ) ;
57
+ this . _testSome = testSome || ( _ => { } ) ;
58
58
}
59
59
60
60
affected = ( head : string , main : string ) : List < Affected > =>
@@ -69,28 +69,26 @@ export class Config {
69
69
. values ( )
70
70
) ;
71
71
72
- lint = ( affected : Affected ) => {
73
- const args = { root : git . root ( ) , path : affected . path } ;
74
- const cwd = process . cwd ( ) ;
75
- const dir = path . join ( args . root , affected . path ) ;
76
- console . log ( `> cd ${ dir } ` ) ;
77
- process . chdir ( dir ) ;
78
- this . _lint ( args ) ;
79
- process . chdir ( cwd ) ;
80
- } ;
72
+ lint = ( affected : Affected ) =>
73
+ this . withDir ( affected . path , args => this . _lint ( args ) ) ;
81
74
82
- test = ( affected : Affected ) => {
83
- const args = { root : git . root ( ) , path : affected . path } ;
75
+ test = ( affected : Affected ) =>
76
+ this . withDir ( affected . path , args => {
77
+ if ( 'TestAll' in affected ) {
78
+ this . _testAll ( args ) ;
79
+ }
80
+ if ( 'TestSome' in affected ) {
81
+ this . _testSome ( args , affected . TestSome ) ;
82
+ }
83
+ } ) ;
84
+
85
+ withDir = ( dir : string , f : ( args : Args ) => void ) => {
86
+ const args = { root : git . root ( ) , path : dir } ;
84
87
const cwd = process . cwd ( ) ;
85
- const dir = path . join ( args . root , affected . path ) ;
86
- console . log ( `> cd ${ dir } ` ) ;
87
- process . chdir ( dir ) ;
88
- if ( 'TestAll' in affected ) {
89
- this . _testAll ( args ) ;
90
- }
91
- if ( 'TestSome' in affected ) {
92
- this . _testSome ( args , affected . TestSome ) ;
93
- }
88
+ const absDir = path . join ( args . root , dir ) ;
89
+ console . log ( `> cd ${ absDir } ` ) ;
90
+ process . chdir ( absDir ) ;
91
+ f ( args ) ;
94
92
process . chdir ( cwd ) ;
95
93
} ;
96
94
0 commit comments