File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 1
1
import type { IApi } from 'father' ;
2
+ import { exec , execSync } from 'child_process' ;
3
+
4
+ // 检查是否已安装 npm 包
5
+ function checkNpmPackageInstalled ( packageName : string ) {
6
+ return new Promise ( ( resolve ) => {
7
+ exec ( `npm list --depth=0 ${ packageName } ` , ( error : Error ) => {
8
+ resolve ( ! error ) ;
9
+ } ) ;
10
+ } ) ;
11
+ }
2
12
3
13
export default ( api : IApi ) => {
4
14
// Compile break if export type without consistent
5
- api . onStart ( ( ) => {
15
+ api . onStart ( async ( ) => {
6
16
if ( api . name !== 'build' ) {
7
17
return ;
8
18
}
9
19
10
20
const inputFolder =
11
21
api ?. config ?. esm ?. input || api ?. config ?. esm ?. input || 'src/' ;
12
22
13
- const { execSync } = require ( 'child_process ') ;
14
- try {
23
+ const isInstalled = await checkNpmPackageInstalled ( 'eslint ') ;
24
+ if ( isInstalled ) {
15
25
execSync (
16
26
`npx eslint ${ inputFolder } --ext .tsx,.ts --rule '@typescript-eslint/consistent-type-exports: error'` ,
17
27
{
@@ -21,7 +31,7 @@ export default (api: IApi) => {
21
31
encoding : 'utf-8' ,
22
32
} ,
23
33
) ;
24
- } catch ( error ) {
34
+ } else {
25
35
console . log ( 'ESLint is not installed, skip.' ) ;
26
36
}
27
37
} ) ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"compilerOptions" : {
3
3
"strict" : true ,
4
+ "lib" : [" ES2015" ],
4
5
"skipLibCheck" : true ,
5
6
"esModuleInterop" : true ,
6
7
"baseUrl" : " ./"
You can’t perform that action at this time.
0 commit comments