From 69a9b1e6c8ce2e8499592a3be5a22efe1db7acbf Mon Sep 17 00:00:00 2001 From: amorscher Date: Fri, 27 Oct 2023 15:40:02 +0200 Subject: [PATCH 1/2] fix(run): inherit stdio for running npm scripts - supports handling of user prompts in npm scripts --- libs/core/src/lib/npm-run-script.spec.ts | 5 +++++ libs/core/src/lib/npm-run-script.ts | 1 + 2 files changed, 6 insertions(+) diff --git a/libs/core/src/lib/npm-run-script.spec.ts b/libs/core/src/lib/npm-run-script.spec.ts index da665d8886..da0fb64f72 100644 --- a/libs/core/src/lib/npm-run-script.spec.ts +++ b/libs/core/src/lib/npm-run-script.spec.ts @@ -27,6 +27,7 @@ describe("npm-run-script", () => { env: {}, pkg: config.pkg, reject: true, + stdio: "inherit", windowsHide: false, }); }); @@ -49,6 +50,7 @@ describe("npm-run-script", () => { env: {}, pkg: config.pkg, reject: false, + stdio: "inherit", windowsHide: false, }); }); @@ -70,6 +72,7 @@ describe("npm-run-script", () => { env: {}, pkg: config.pkg, reject: true, + stdio: "inherit", windowsHide: false, }); }); @@ -100,6 +103,7 @@ describe("npm-run-script", () => { }, pkg: config.pkg, reject: true, + stdio: "inherit", windowsHide: false, }, config.pkg.name @@ -130,6 +134,7 @@ describe("npm-run-script", () => { }, pkg: config.pkg, reject: false, + stdio: "inherit", windowsHide: false, }, undefined diff --git a/libs/core/src/lib/npm-run-script.ts b/libs/core/src/lib/npm-run-script.ts index e17831d8db..3f1a700a4e 100644 --- a/libs/core/src/lib/npm-run-script.ts +++ b/libs/core/src/lib/npm-run-script.ts @@ -28,6 +28,7 @@ export function npmRunScriptStreaming(script: string, { args, npmClient, pkg, pr function makeOpts(pkg: { name: any; location: string }, reject: any) { return Object.assign(getNpmExecOpts(pkg), { windowsHide: false, + stdio: "inherit" /*to support interactive prompts */, reject, }); } From a4ae532dab442d07d454c6a151d2a28ba434e5d0 Mon Sep 17 00:00:00 2001 From: amorscher Date: Fri, 24 Nov 2023 00:06:23 +0100 Subject: [PATCH 2/2] do not print output as stdio is inherited --- libs/commands/run/src/index.ts | 2 -- libs/commands/run/src/lib/run-command.spec.ts | 8 +++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/commands/run/src/index.ts b/libs/commands/run/src/index.ts index 6d53d868dc..e430410919 100644 --- a/libs/commands/run/src/index.ts +++ b/libs/commands/run/src/index.ts @@ -7,7 +7,6 @@ import { getPackage, npmRunScript, npmRunScriptStreaming, - output, Package, Profiler, ProjectGraphProjectNodeWithPackage, @@ -250,7 +249,6 @@ export class RunCommand extends Command { pkg.name, (getElapsed() / 1000).toFixed(1) ); - output(result.stdout); return result; }); diff --git a/libs/commands/run/src/lib/run-command.spec.ts b/libs/commands/run/src/lib/run-command.spec.ts index b5d1632d9c..ac74fa8620 100644 --- a/libs/commands/run/src/lib/run-command.spec.ts +++ b/libs/commands/run/src/lib/run-command.spec.ts @@ -45,9 +45,10 @@ const ranInPackagesStreaming = (testDir: string) => ); describe("RunCommand", () => { - npmRunScript.mockImplementation((script: string, { pkg }: { pkg: Package }) => - Promise.resolve({ exitCode: 0, stdout: pkg.name }) - ); + npmRunScript.mockImplementation((script: string, { pkg }: { pkg: Package }) => { + output(pkg.name); + return Promise.resolve({ exitCode: 0, stdout: pkg.name }); + }); npmRunScriptStreaming.mockImplementation(() => Promise.resolve({ exitCode: 0 })); afterEach(() => { @@ -166,6 +167,7 @@ describe("RunCommand", () => { err.exitCode = 456; err.stdout = pkg.name; + output(pkg.name); return Promise.resolve(err); });