1
- import { LintTaskDesc } from '../SharedTypes' ;
2
- import { default as spawn } from 'cross-spawn' ;
1
+ import { default as spawn } from 'cross-spawn-promise' ;
3
2
import { default as Debug } from 'debug' ;
3
+
4
+ import { LintTaskDesc } from '../SharedTypes' ;
4
5
import { CONSUMING_ROOT } from '../Paths' ;
5
- import { SpawnSyncReturns } from 'child_process' ;
6
+
6
7
const dbg = Debug ( 'web-scripts:lint' ) ; // eslint-disable-line new-cap
7
8
8
- export function lintTask ( task : LintTaskDesc ) : SpawnSyncReturns < Buffer > {
9
+ export async function lintTask ( task : LintTaskDesc ) : Promise < string [ ] > {
10
+ const fns = [ eslintRun ] ;
11
+ if ( task . typecheck ) fns . push ( typeCheck ) ;
12
+
13
+ return await Promise . all (
14
+ fns . map ( async fn => {
15
+ dbg ( 'Beginning %s task' , fn . name ) ;
16
+ const stdout = await fn ( task ) ;
17
+ dbg ( 'Finished %s task' , fn . name ) ;
18
+ return stdout ;
19
+ } ) ,
20
+ ) ;
21
+ }
22
+
23
+ async function eslintRun ( task : LintTaskDesc ) : Promise < string > {
9
24
const cmd = 'npx' ;
10
25
const args = [
11
26
'--no-install' ,
@@ -24,5 +39,14 @@ export function lintTask(task: LintTaskDesc): SpawnSyncReturns<Buffer> {
24
39
...task . restOptions ,
25
40
] ;
26
41
dbg ( 'npx args %o' , args ) ;
27
- return spawn . sync ( cmd , args , { stdio : 'inherit' } ) ;
42
+
43
+ const stdout = await spawn ( cmd , args , { stdio : 'inherit' } ) ;
44
+ return ( stdout || '' ) . toString ( ) ;
45
+ }
46
+
47
+ async function typeCheck ( ) : Promise < string > {
48
+ const cmd = 'npx' ;
49
+ const args = [ 'tsc' , '--noEmit' ] ;
50
+ const stdout = await spawn ( cmd , args , { stdio : 'inherit' } ) ;
51
+ return ( stdout || '' ) . toString ( ) ;
28
52
}
0 commit comments