Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: simplify 'exec' function #2978

Merged
merged 1 commit into from Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions integrationTests/integration-test.js
Expand Up @@ -8,11 +8,11 @@ const childProcess = require('child_process');
const { describe, it } = require('mocha');

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

describe('Integration Tests', () => {
Expand Down
22 changes: 1 addition & 21 deletions resources/utils.js
@@ -1,7 +1,6 @@
'use strict';

const fs = require('fs');
const util = require('util');
const path = require('path');
const childProcess = require('child_process');

Expand All @@ -11,25 +10,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 output && output.trimEnd();
}

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

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