feat: run test script for all pkgs with changed files
This commit is contained in:
parent
83a7dd7ea1
commit
09a2f45ada
@ -70,6 +70,7 @@
|
||||
"testRegex": "\\.spec\\.js$"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*": "scripts/run-changed-pkgs.js test",
|
||||
"*.{{,c,m}j,t}s{,x}": [
|
||||
"prettier --write",
|
||||
"eslint --ignore-pattern '!*'",
|
||||
|
28
scripts/run-changed-pkgs.js
Executable file
28
scripts/run-changed-pkgs.js
Executable file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict'
|
||||
|
||||
const { join, relative, sep } = require('path')
|
||||
|
||||
const [, , script, ...files] = process.argv
|
||||
|
||||
const pkgs = new Set()
|
||||
const root = join(__dirname, '..')
|
||||
for (const file of files) {
|
||||
const parts = relative(root, file).split(sep)
|
||||
if ((parts.length > 2 && parts[0] === 'packages') || parts[0][0] === '@') {
|
||||
pkgs.add(parts.slice(0, 2).join(sep))
|
||||
}
|
||||
}
|
||||
|
||||
if (pkgs.size !== 0) {
|
||||
const args = ['run', '--if-present', script]
|
||||
for (const pkg of pkgs) {
|
||||
args.push('-w', pkg)
|
||||
}
|
||||
|
||||
const { status } = require('child_process').spawnSync('npm', args, { stdio: 'inherit' })
|
||||
if (status !== 0) {
|
||||
process.exit(status)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user