From 85e2eb4a3e8164c7a261bf9892d53d10f257d659 Mon Sep 17 00:00:00 2001 From: Dave Irvine Date: Fri, 28 Jan 2022 17:34:26 +0000 Subject: [PATCH] Specify stdio option when invoking package manager When this option isn't specified, `yarn` errors out (`npm` does not do this). ```js const exec = require('child_process').execSync; exec('yarn run postinstall', {}); ``` ``` node test.js || echo "Exit code: $?" child_process.js:866 throw err; ^ Error: Command failed: yarn run postinstall at checkExecSyncError (child_process.js:790:11) at execSync (child_process.js:863:15) at Object. (/tmp/test/test.js:3:1) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:12) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) at internal/main/run_main_module.js:17:47 { status: 1, signal: null, output: [ null, Buffer(0) [Uint8Array] [], Buffer(0) [Uint8Array] [] ], pid: 12204, stdout: Buffer(0) [Uint8Array] [], stderr: Buffer(0) [Uint8Array] [] } Exit code: 1 ``` ```js const exec = require('child_process').execSync; exec('yarn run postinstall', { stdio: 'ignore' }); ``` ``` node test.js && echo "Exit code: $?" Exit code: 0 ``` --- run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.js b/run.js index 5742730..53992b0 100644 --- a/run.js +++ b/run.js @@ -12,7 +12,7 @@ if (fs.existsSync(packageJsonPath)) { if (packageJson.scripts && packageJson.scripts.postinstall) { const pkgManager = shouldUseYarn() ? 'yarn' : 'npm'; - exec(`${pkgManager} run postinstall`, {cwd: appPath}) + exec(`${pkgManager} run postinstall`, {cwd: appPath, stdio: 'ignore'}) } }