Skip to content

Commit 385b6ff

Browse files
committed
chore(postinstall): add postinstall script to automatically run lint checks
1 parent db12ac5 commit 385b6ff

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"dev": "turbo run dev",
1616
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
1717
"lint": "turbo run lint",
18-
"lint:fix": "eslint . --fix"
18+
"lint:fix": "eslint . --fix",
19+
"postinstall": "tsx script/postinstall.ts"
1920
},
2021
"devDependencies": {
2122
"@soybean-react-ui/tailwind-plugin": "workspace:*",

script/postinstall.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { execSync } from 'node:child_process';
2+
import fs from 'node:fs';
3+
import path from 'node:path';
4+
5+
const cwd = process.env.INIT_CWD || process.cwd();
6+
const pkgPath = path.join(cwd, 'package.json');
7+
8+
if (fs.existsSync(pkgPath)) {
9+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
10+
11+
console.log('process.env.npm_package_name', process.env.npm_package_name);
12+
13+
console.log(`🔥 postinstall running for package: ${pkg.name}`);
14+
15+
execSync(`pnpm --filter ${pkg.name} run lint:pkg`, {
16+
cwd,
17+
// 指定子包 cwd,避免跑到 root
18+
stdio: 'inherit'
19+
});
20+
} else {
21+
console.log('⚠️ no package.json found in INIT_CWD', cwd);
22+
}

0 commit comments

Comments
 (0)