From f67206a2130c6e98a9e000c9c7718823c454ebf5 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sat, 20 Mar 2021 20:24:36 +0200 Subject: [PATCH] internal: simplify 'exec' function --- benchmark/benchmark.js | 2 +- integrationTests/integration-test.js | 8 +++----- resources/utils.js | 21 +-------------------- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index 72796481dda..3bf13c20934 100644 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -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 diff --git a/integrationTests/integration-test.js b/integrationTests/integration-test.js index 2f2c90e8fe5..ad793b37ddd 100644 --- a/integrationTests/integration-test.js +++ b/integrationTests/integration-test.js @@ -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', () => { diff --git a/resources/utils.js b/resources/utils.js index 6ab659dc3b1..56cdc9a90f3 100644 --- a/resources/utils.js +++ b/resources/utils.js @@ -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 = {}) { @@ -101,7 +83,6 @@ function showDirStats(dirPath) { module.exports = { exec, - execAsync, readdirRecursive, showDirStats, };