Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libnpmexec: allow custom stdio option value. #6976

Open
wants to merge 3 commits into
base: latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions workspaces/libnpmexec/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const exec = async (opts) => {
path = '.',
runPath = '.',
scriptShell = isWindows ? process.env.ComSpec || 'cmd' : 'sh',
stdio,
...flatOptions
} = opts

Expand All @@ -104,6 +105,7 @@ const exec = async (opts) => {
binPaths,
runPath,
scriptShell,
stdio,
})

// interactive mode
Expand Down
11 changes: 8 additions & 3 deletions workspaces/libnpmexec/lib/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +32,9 @@ const run = async ({
},
}

npmlog.disableProgress()
if (stdio === 'inherit') {
npmlog.disableProgress()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done so that the output from npm doesn't interlace with the output of your script. We always want to disable progress bars during exec.

}

try {
if (script === scriptShell) {
Expand Down Expand Up @@ -60,11 +63,13 @@ const run = async ({
binPaths,
event: 'npx',
args,
stdio: 'inherit',
stdio,
scriptShell,
})
} finally {
npmlog.enableProgress()
if (stdio === 'inherit') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one needs to be removed also

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to make the libnpmexec don’t output npm logs.
npm log output is interlacing with the output of the application executing libnpmexec.
Just passing the stdio value through is not enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't npm log output, this is progress bars specifically.

To suppress all logging we need npmlog.pause and npmlog.resume, but these should be independent of enabling/disabling progress.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to install npmlog directly to pause it.
What about a flag to ignore npmlog?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have it

const npmlog = require('npmlog')

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, I have ora as progress bar.
npmlog and ora are mangling the output.
I need to install and import npmlog in my project to pause the npmlog.
And that does not guarantee that the npmlog is muted due to hoisting.

npmlog.enableProgress()
}
}
}

Expand Down