Skip to content

Commit

Permalink
internal: simplify 'exec' function
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Mar 20, 2021
1 parent 540f336 commit f67206a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 26 deletions.
2 changes: 1 addition & 1 deletion benchmark/benchmark.js
Expand Up @@ -35,7 +35,7 @@ function exec(command, options = {}) {
stdio: ['inherit', 'pipe', 'inherit'],
...options,
});
return result && result.trimEnd();
return result?.trimEnd();
}

// Build a benchmark-friendly environment for the given revision
Expand Down
8 changes: 3 additions & 5 deletions integrationTests/integration-test.js
Expand Up @@ -8,11 +8,9 @@ const childProcess = require('child_process');
const { describe, it } = require('mocha');

function exec(command, options = {}) {
const result = childProcess.execSync(command, {
encoding: 'utf-8',
...options,
});
return result != null ? result.trimEnd() : result;
return childProcess
.execSync(command, { encoding: 'utf-8', ...options })
?.trimEnd();
}

describe('Integration Tests', () => {
Expand Down
21 changes: 1 addition & 20 deletions resources/utils.js
Expand Up @@ -11,25 +11,7 @@ function exec(command, options) {
encoding: 'utf-8',
...options,
});
return removeTrailingNewLine(output);
}

const childProcessExec = util.promisify(childProcess.exec);
async function execAsync(command, options) {
const output = await childProcessExec(command, {
maxBuffer: 10 * 1024 * 1024, // 10MB
encoding: 'utf-8',
...options,
});
return removeTrailingNewLine(output.stdout);
}

function removeTrailingNewLine(str) {
if (str == null) {
return str;
}

return str.split('\n').slice(0, -1).join('\n');
return result && result.trimEnd();
}

function readdirRecursive(dirPath, opts = {}) {
Expand Down Expand Up @@ -101,7 +83,6 @@ function showDirStats(dirPath) {

module.exports = {
exec,
execAsync,
readdirRecursive,
showDirStats,
};

0 comments on commit f67206a

Please sign in to comment.