From 2d1ec996faed5031eba75a8b32885b343ecdda63 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Fri, 6 May 2022 12:23:48 +0300 Subject: [PATCH] diff-npm-packages: fix crash with ENOBUFS (#3560) --- resources/diff-npm-package.js | 12 ++---------- resources/utils.js | 3 ++- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/resources/diff-npm-package.js b/resources/diff-npm-package.js index c0d8d8c991..4dc0d15b16 100644 --- a/resources/diff-npm-package.js +++ b/resources/diff-npm-package.js @@ -3,7 +3,8 @@ const os = require('os'); const fs = require('fs'); const path = require('path'); -const cp = require('child_process'); + +const { exec } = require('./utils.js'); const LOCAL = 'local'; const localRepoDir = path.join(__dirname, '..'); @@ -93,12 +94,3 @@ function prepareNPMPackage(revision) { exec('npm --quiet run build:npm', { cwd: repoDir }); return path.join(repoDir, 'npmDist'); } - -function exec(command, options = {}) { - const result = cp.execSync(command, { - encoding: 'utf-8', - stdio: ['inherit', 'pipe', 'inherit'], - ...options, - }); - return result?.trimEnd(); -} diff --git a/resources/utils.js b/resources/utils.js index aa4be2c1ce..c0a09335e2 100644 --- a/resources/utils.js +++ b/resources/utils.js @@ -9,10 +9,11 @@ const prettier = require('prettier'); function exec(command, options) { const output = childProcess.execSync(command, { maxBuffer: 10 * 1024 * 1024, // 10MB + stdio: ['inherit', 'pipe', 'inherit'], encoding: 'utf-8', ...options, }); - return output && output.trimEnd(); + return output?.trimEnd(); } function readdirRecursive(dirPath, opts = {}) {