From ef7b53528f8f7e2226127a4bdc1223f1c677b042 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 23 Mar 2022 18:33:47 -0400 Subject: [PATCH] Fix `next info` accidentally printing stderr (#35556) I noticed a few issues that had "Output from `next info`" with the first line as ``` /bin/sh: pnpm: command not found ``` This was because `execSync()` was still printing to stderr when a command was not found. Changing to `execFileSync()` fixed it so we no longer print to stderr when a command is not found. --- packages/next/cli/next-info.ts | 5 ++++- test/integration/cli/test/index.test.js | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/next/cli/next-info.ts b/packages/next/cli/next-info.ts index 4fd15e44dfc5..9ac5cb350225 100755 --- a/packages/next/cli/next-info.ts +++ b/packages/next/cli/next-info.ts @@ -99,7 +99,10 @@ function getPackageVersion(packageName: string) { function getBinaryVersion(binaryName: string) { try { - return childProcess.execSync(`${binaryName} --version`).toString().trim() + return childProcess + .execFileSync(binaryName, ['--version']) + .toString() + .trim() } catch { return 'N/A' } diff --git a/test/integration/cli/test/index.test.js b/test/integration/cli/test/index.test.js index 2fbae8c6ce2c..c3d7aad3092b 100644 --- a/test/integration/cli/test/index.test.js +++ b/test/integration/cli/test/index.test.js @@ -489,7 +489,9 @@ describe('CLI Usage', () => { test('should print output', async () => { const info = await runNextCommand(['info'], { stdout: true, + stderr: true, }) + expect(info.stderr || '').toBe('') expect(info.stdout).toMatch( new RegExp(` Operating System: