Skip to content

Commit 715a02b

Browse files
authored
fix: skip if eslint is not installed (#9)
1 parent b5ab939 commit 715a02b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/index.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
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+
}
212

313
export default (api: IApi) => {
414
// Compile break if export type without consistent
5-
api.onStart(() => {
15+
api.onStart(async () => {
616
if (api.name !== 'build') {
717
return;
818
}
919

1020
const inputFolder =
1121
api?.config?.esm?.input || api?.config?.esm?.input || 'src/';
1222

13-
const { execSync } = require('child_process');
14-
try {
23+
const isInstalled = await checkNpmPackageInstalled('eslint');
24+
if (isInstalled) {
1525
execSync(
1626
`npx eslint ${inputFolder} --ext .tsx,.ts --rule '@typescript-eslint/consistent-type-exports: error'`,
1727
{
@@ -21,7 +31,7 @@ export default (api: IApi) => {
2131
encoding: 'utf-8',
2232
},
2333
);
24-
} catch (error) {
34+
} else {
2535
console.log('ESLint is not installed, skip.');
2636
}
2737
});

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"strict": true,
4+
"lib": ["ES2015"],
45
"skipLibCheck": true,
56
"esModuleInterop": true,
67
"baseUrl": "./"

0 commit comments

Comments
 (0)