Skip to content

Commit 9110135

Browse files
internal: simplify 'exec' function (#2978)
1 parent 540f336 commit 9110135

File tree

3 files changed

+4
-24
lines changed

3 files changed

+4
-24
lines changed

benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function exec(command, options = {}) {
3535
stdio: ['inherit', 'pipe', 'inherit'],
3636
...options,
3737
});
38-
return result && result.trimEnd();
38+
return result?.trimEnd();
3939
}
4040

4141
// Build a benchmark-friendly environment for the given revision

integrationTests/integration-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const childProcess = require('child_process');
88
const { describe, it } = require('mocha');
99

1010
function exec(command, options = {}) {
11-
const result = childProcess.execSync(command, {
11+
const output = childProcess.execSync(command, {
1212
encoding: 'utf-8',
1313
...options,
1414
});
15-
return result != null ? result.trimEnd() : result;
15+
return output && output.trimEnd();
1616
}
1717

1818
describe('Integration Tests', () => {

resources/utils.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const fs = require('fs');
4-
const util = require('util');
54
const path = require('path');
65
const childProcess = require('child_process');
76

@@ -11,25 +10,7 @@ function exec(command, options) {
1110
encoding: 'utf-8',
1211
...options,
1312
});
14-
return removeTrailingNewLine(output);
15-
}
16-
17-
const childProcessExec = util.promisify(childProcess.exec);
18-
async function execAsync(command, options) {
19-
const output = await childProcessExec(command, {
20-
maxBuffer: 10 * 1024 * 1024, // 10MB
21-
encoding: 'utf-8',
22-
...options,
23-
});
24-
return removeTrailingNewLine(output.stdout);
25-
}
26-
27-
function removeTrailingNewLine(str) {
28-
if (str == null) {
29-
return str;
30-
}
31-
32-
return str.split('\n').slice(0, -1).join('\n');
13+
return output && output.trimEnd();
3314
}
3415

3516
function readdirRecursive(dirPath, opts = {}) {
@@ -101,7 +82,6 @@ function showDirStats(dirPath) {
10182

10283
module.exports = {
10384
exec,
104-
execAsync,
10585
readdirRecursive,
10686
showDirStats,
10787
};

0 commit comments

Comments
 (0)