jamiebuilds / workspaces-run

Run tasks/scripts across Yarn/Lerna/Bolt/etc workspaces.
MIT License
94 stars 2 forks source link

Support color in output #3

Open timjroberts opened 3 years ago

timjroberts commented 3 years ago

With yarn and npm@7 now supporting workspaces, and with monorepos becoming easier to manage because of it, packages like this are incredibly useful in helping to keep things really lean. I have a repo with several projects in it and I can now coordinate calls to tsc, eslint and jest all from the top level, even run my own scripts to perform other build related tasks.

The only thing missing is colored output that the executing commands may be generating. Could this be added as a feature?

jamiebuilds commented 3 years ago

I believe the issue is that this library doesn't spawn with stdio: "inherit" so the sub-processes dont get a TTY.

This function could be updated so that when shouldPrefix is false it switches to stdio: "inherit" https://github.com/jamiebuilds/workspaces-run/blob/master/src/utils/spawn.ts#L50-L60

timjroberts commented 3 years ago

Happy to take a look and open a PR? Could possibly look at testing for a TTY too and if not present don't use inherit. Keeps things clean in a CI setting.

timjroberts commented 3 years ago

Actually I think I've over thought this. If I add the --color option to both eslint and jest for example, then the colours are being output. If the child process is already testing for the presence of a TTY and there isn't a way to give one to it (other than using inherit), then there probably isn't much that can be done to force the child process to output its colours - other than using its command line options.

I think its safe to close this issue.

jamiebuilds commented 3 years ago

That's a good point. I have had tools get confused about having a TTY when they don't actually have one, and they end up doing things like prompting the user for input/etc.

Maybe a note about that in the README would be good. Could just list off common flags: FORCE_COLOR=true cmd COLOR=true cmd cmd --color etc