vercel / turborepo

Build system optimized for JavaScript and TypeScript, written in Rust
https://turbo.build/repo/docs
MIT License
26.3k stars 1.82k forks source link

Option to run scripts with npm's --silent flag #672

Open marklawlor opened 2 years ago

marklawlor commented 2 years ago

Describe the feature you'd like to request

Current output:

my-project:test:
my-project:test: > my-project@0.0.0 test
my-project:test: > echo 'hello-world'
my-project:test:
my-project:test: hello world

Output I'd like

my-project:test: hello world

Describe the solution you'd like

npm run has a --silent option that removes the extra lines added by npm when running a script. I would like an option in turbo.json to pass this flag to npm run.

Describe alternatives you've considered

Have an environment variable NPM_OPTIONS to pass extra command line flags to npm (similar to NODE_OPTIONS for node), or an npm-options attribute in turbo.json

andyjy commented 2 years ago

_Update: Using bare double-dash for this no longer works since #1405 (v1.3.0 release), which changes the behaviour to pass arguments after the double-dash through to the command run by npm in each workspace rather than npm itself - probably the more useful behaviour in any case. Alternative method using npm_config_loglevel posted in new comment below._

~~Appears to achieve the desired effect by passing --silent after a bare double-dash (thus passing the --silent flag through to the npm run command rather than interpreting as a flag for turbo) -~~

turbo run test -- --silent

Agree it would be pleasing to have this feature natively in Turborepo config to avoid the need for shell jitsu.

andyjy commented 2 years ago

Turns out npm supports passing config via environment variables using the npm_config_ prefix, so e.g. this does the trick:

npm_config_loglevel=silent turbo run test

https://docs.npmjs.com/cli/v8/using-npm/config#environment-variables https://docs.npmjs.com/cli/v8/using-npm/config#loglevel

leonsilicon commented 1 year ago

Has anybody found a solution that works for pnpm?

PacoSoftwerft commented 1 year ago

As I sometimes run turbo via npm it may be helpful to know you can chain the double dash. Example:

npm run xy -- -- --flag

What happens npm run xy -- -- --flag -> turbo run xy -- --flag -> xy --flag

net commented 2 weeks ago

For pnpm add

reporter=silent

to your .npmrc (https://pnpm.io/npmrc).

This setting is undocumented, but it's equivalent to --silent: https://github.com/pnpm/pnpm/blob/main/pnpm/src/shorthands.ts#L8

Unfortunately this silences all pnpm commands (including pnpm i).

See https://github.com/pnpm/pnpm/issues/4879.