From 93fb751b1b62578028eb13a98930a660a93eb967 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 8 Nov 2023 11:26:13 -0300 Subject: [PATCH 1/3] add stdio option --- workspaces/libnpmexec/lib/run-script.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/workspaces/libnpmexec/lib/run-script.js b/workspaces/libnpmexec/lib/run-script.js index 89dcf2e653036..57dacf4645d6b 100644 --- a/workspaces/libnpmexec/lib/run-script.js +++ b/workspaces/libnpmexec/lib/run-script.js @@ -15,6 +15,7 @@ const run = async ({ binPaths, runPath, scriptShell, + stdio = 'inherit', }) => { // turn list of args into command string const script = call || args.shift() || scriptShell @@ -31,7 +32,9 @@ const run = async ({ }, } - npmlog.disableProgress() + if (stdio === 'inherit') { + npmlog.disableProgress() + } try { if (script === scriptShell) { @@ -60,11 +63,13 @@ const run = async ({ binPaths, event: 'npx', args, - stdio: 'inherit', + stdio, scriptShell, }) } finally { - npmlog.enableProgress() + if (stdio === 'inherit') { + npmlog.enableProgress() + } } } From e7ff14df6508835dee246e537cc210a4331de9e0 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 8 Nov 2023 11:28:16 -0300 Subject: [PATCH 2/3] add stdio option --- workspaces/libnpmexec/lib/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/workspaces/libnpmexec/lib/index.js b/workspaces/libnpmexec/lib/index.js index 34bb20769bc2c..34db0a2a43e4d 100644 --- a/workspaces/libnpmexec/lib/index.js +++ b/workspaces/libnpmexec/lib/index.js @@ -90,6 +90,7 @@ const exec = async (opts) => { path = '.', runPath = '.', scriptShell = isWindows ? process.env.ComSpec || 'cmd' : 'sh', + stdio, ...flatOptions } = opts @@ -104,6 +105,7 @@ const exec = async (opts) => { binPaths, runPath, scriptShell, + stdio, }) // interactive mode From e4cd2c6393827e2f5760aab731ed64cd2ab49c86 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 8 Nov 2023 17:51:35 -0300 Subject: [PATCH 3/3] add test --- workspaces/libnpmexec/lib/run-script.js | 4 +-- workspaces/libnpmexec/test/index.js | 14 +++++++++ workspaces/libnpmexec/test/run-script.js | 38 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/workspaces/libnpmexec/lib/run-script.js b/workspaces/libnpmexec/lib/run-script.js index 57dacf4645d6b..f41af91dfe8bf 100644 --- a/workspaces/libnpmexec/lib/run-script.js +++ b/workspaces/libnpmexec/lib/run-script.js @@ -32,9 +32,7 @@ const run = async ({ }, } - if (stdio === 'inherit') { - npmlog.disableProgress() - } + npmlog.disableProgress() try { if (script === scriptShell) { diff --git a/workspaces/libnpmexec/test/index.js b/workspaces/libnpmexec/test/index.js index 008560efc7018..d22716ad62e0e 100644 --- a/workspaces/libnpmexec/test/index.js +++ b/workspaces/libnpmexec/test/index.js @@ -14,3 +14,17 @@ t.test('no args', async t => { await exec() }) + +t.test('stdio value', async t => { + t.plan(1) + + const { exec } = setup(t, { + mocks: { + '../../lib/run-script': ({ stdio }) => { + t.equal(stdio, 'pipe', 'should use expected stdio value') + }, + }, + }) + + await exec({ stdio: 'pipe' }) +}) diff --git a/workspaces/libnpmexec/test/run-script.js b/workspaces/libnpmexec/test/run-script.js index b3289c6b15c4b..3f308eb2ef3f1 100644 --- a/workspaces/libnpmexec/test/run-script.js +++ b/workspaces/libnpmexec/test/run-script.js @@ -141,3 +141,41 @@ t.test('ci env', async t => { await runScript() }) + +t.test('stdio value', t => { + t.test('stdio default value', async t => { + const runScript = await mockRunScript(t, { + '@npmcli/run-script': (opt) => { + t.equal(opt.stdio, 'inherit', 'should use expected stdio value') + }, + npmlog: { + disableProgress () { + t.ok('should disable progress') + }, + enableProgress () { + t.ok('should enable progress') + }, + }, + }) + await runScript({ args: [], runPath: t.testDirName }) + }) + + t.test('stdio custom value', async t => { + const runScript = await mockRunScript(t, { + '@npmcli/run-script': (opt) => { + t.equal(opt.stdio, 'pipe', 'should use expected stdio value') + }, + npmlog: { + disableProgress () { + t.ok('should disable progress') + }, + enableProgress () { + t.fail('should not enable progress') + }, + }, + }) + await runScript({ args: [], stdio: 'pipe', runPath: t.testDirName }) + }) + + t.end() +})