Skip to content

Commit 546986a

Browse files
authored
Replace child_process.exec() with execFile() (#288)
1 parent 61b51bb commit 546986a

5 files changed

Lines changed: 16 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.11.0
4+
5+
- Breaking Change: Replace export `childProcess.exec()` with `childProcess.execFile()`
6+
37
## 0.10.5
48

59
- Bump `glob` from `^12.0.0` to `^13.0.0`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/avocado",
3-
"version": "0.10.5",
3+
"version": "0.11.0",
44
"description": "A validator of OpenAPI configurations",
55
"type": "module",
66
"main": "dist/index.js",

src/child-process.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import * as childProcess from 'child_process'
55
import * as util from 'util'
66

7-
const nodeJsExec = util.promisify(childProcess.exec)
7+
const nodeJsExecFile = util.promisify(childProcess.execFile)
88

99
export type ExecResult = {
1010
/**
@@ -17,5 +17,8 @@ export type ExecResult = {
1717
readonly stderr: string
1818
}
1919

20-
export const exec = (command: string, options: childProcess.ExecOptionsWithStringEncoding): Promise<ExecResult> =>
21-
nodeJsExec(command, { maxBuffer: Infinity, ...options })
20+
export const execFile = (
21+
file: string,
22+
args: readonly string[],
23+
options: childProcess.ExecFileOptionsWithStringEncoding,
24+
): Promise<ExecResult> => nodeJsExecFile(file, args, { maxBuffer: Infinity, ...options })

src/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ export const repository =
3434
GIT_TERMINAL_PROMPT: '0',
3535
},
3636
}
37-
return childProcess.exec(`git ${cmd} ${args.join(' ')}`, options)
37+
return childProcess.execFile('git', [cmd, ...args], options)
3838
}

src/test/child-process-test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { childProcess } from '../index.js'
77
import { generate } from './generate-stdout.js'
88

99
describe('child-process', () => {
10-
it('exec maxBuffer', async () => {
10+
it('execFile maxBuffer', async () => {
1111
// call `generate-stdout.print()` as a separate process.
12-
const { stdout } = await childProcess.exec(
13-
'node -e "import { print } from \'./dist/test/generate-stdout.js\'; print();"',
12+
const { stdout } = await childProcess.execFile(
13+
'node',
14+
['-e', "import { print } from './dist/test/generate-stdout.js'; print();"],
1415
{},
1516
)
1617
const expected = generate()

0 commit comments

Comments
 (0)