1
- #!/usr/bin/env node
2
-
3
1
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
4
2
// See LICENSE in the project root for license information.
5
- const { execSync } = require ( 'child_process' ) ;
6
- const fs = require ( 'fs' ) ;
7
- const path = require ( 'path' ) ;
8
3
9
- function findPatchPath ( ) {
10
- let eslintrcPath ;
4
+ import { execSync } from 'child_process' ;
5
+ import * as process from 'process' ;
6
+ import * as fs from 'fs' ;
7
+ import * as path from 'path' ;
8
+
9
+ function findPatchPath ( ) : string {
10
+ let eslintrcPath : string ;
11
11
if ( fs . existsSync ( path . join ( process . cwd ( ) , '.eslintrc.js' ) ) ) {
12
12
eslintrcPath = '.eslintrc.js' ;
13
13
} else if ( fs . existsSync ( path . join ( process . cwd ( ) , '.eslintrc.cjs' ) ) ) {
@@ -19,24 +19,24 @@ function findPatchPath() {
19
19
process . exit ( 1 ) ;
20
20
}
21
21
22
- const env = { ...process . env , ESLINT_BULK_FIND : 'true' } ;
22
+ const env : { [ key : string ] : string } = { ...process . env , ESLINT_BULK_FIND : 'true' } ;
23
23
24
- let stdout ;
24
+ let stdout : Buffer ;
25
25
try {
26
26
stdout = execSync ( `echo "" | eslint --stdin --config ${ eslintrcPath } ` , { env, stdio : 'pipe' } ) ;
27
27
} catch ( e ) {
28
28
console . error ( '@rushstack/eslint-bulk: Error finding patch path: ' + e . message ) ;
29
29
process . exit ( 1 ) ;
30
30
}
31
31
32
- const startDelimiter = 'ESLINT_BULK_STDOUT_START' ;
33
- const endDelimiter = 'ESLINT_BULK_STDOUT_END' ;
32
+ const startDelimiter : string = 'ESLINT_BULK_STDOUT_START' ;
33
+ const endDelimiter : string = 'ESLINT_BULK_STDOUT_END' ;
34
34
35
- const regex = new RegExp ( `${ startDelimiter } (.*?)${ endDelimiter } ` ) ;
36
- const match = stdout . toString ( ) . match ( regex ) ;
35
+ const regex : RegExp = new RegExp ( `${ startDelimiter } (.*?)${ endDelimiter } ` ) ;
36
+ const match : RegExpMatchArray | null = stdout . toString ( ) . match ( regex ) ;
37
37
38
38
if ( match ) {
39
- const filePath = match [ 1 ] . trim ( ) ;
39
+ const filePath : string = match [ 1 ] . trim ( ) ;
40
40
return filePath ;
41
41
}
42
42
@@ -46,10 +46,10 @@ function findPatchPath() {
46
46
process . exit ( 1 ) ;
47
47
}
48
48
49
- const patchPath = findPatchPath ( ) ;
49
+ const patchPath : string = findPatchPath ( ) ;
50
50
try {
51
- const args = process . argv . slice ( 2 ) . join ( ' ' ) ;
52
- const command = `node ${ patchPath } ${ args } ` ;
51
+ const args : string = process . argv . slice ( 2 ) . join ( ' ' ) ;
52
+ const command : string = `node ${ patchPath } ${ args } ` ;
53
53
execSync ( command , { stdio : 'inherit' } ) ;
54
54
} catch ( e ) {
55
55
console . error ( `@rushstack/eslint-bulk: Error running patch at ${ patchPath } :\n` + e . message ) ;
0 commit comments