-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: invoke eslint as a process to pass arguments
- Loading branch information
Showing
3 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { exec } from 'child_process' | ||
|
||
const { | ||
MAX_EXEC_BUFFER_MB = '10', | ||
} = process.env | ||
|
||
const maxBuffer = 1024 * 1024 * parseFloat(MAX_EXEC_BUFFER_MB) | ||
|
||
export default async (command: string): Promise<string> => await new Promise((resolve, reject) => { | ||
exec(`cd "${process.cwd()}" && ${command}`, { shell: 'bash', maxBuffer }, (err, stdout, stderr) => { | ||
if (err) { | ||
// when `command` itself fails its error will be printed to stderr | ||
if (stderr) { | ||
return reject(new Error(stderr)) | ||
} | ||
// some apps (eslint) uses stdout even for errors | ||
// lets assume that exitcode 1 means there is a meaningful error from the command itself | ||
if (!err.killed && err.code === 1) { | ||
return reject(new Error(stdout)) | ||
} | ||
// when child_process.exec fails the source error will be in `err` | ||
return reject(err) | ||
} | ||
|
||
return resolve(stdout) | ||
}) | ||
}) |