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

fix(2148): don't remove ANSI colour codes from script output #4559

Merged
merged 5 commits into from
Jun 14, 2023

Conversation

woubuc
Copy link
Contributor

@woubuc woubuc commented Apr 12, 2022

Reflecting my comment in #2148, I've replaced the use of strip-ansi before truncating a line (which removed all colour codes in script output) with cli-truncate which is aware of ANSI escape codes.

@woubuc woubuc requested a review from zkochan as a code owner April 12, 2022 14:45
@welcome
Copy link

welcome bot commented Apr 12, 2022

💖 Thanks for opening this pull request! 💖
Please be patient and we will get back to you as soon as we can.

@woubuc woubuc changed the title Fix #2148 fix(2148): don't remove ANSI colour codes from script output Apr 12, 2022
@zkochan
Copy link
Member

zkochan commented Apr 12, 2022

I don't think it works.

@woubuc
Copy link
Contributor Author

woubuc commented Apr 12, 2022

I don't think it works.

The failed CI was due to a code style issue (my IDE inserted a semicolon when autocompleting the import). I've removed it so it should be okay now.

@zkochan
Copy link
Member

zkochan commented Apr 12, 2022

What command have you used to check if the colors are preserved? I tried to test it but the colors were not preserved.

@woubuc
Copy link
Contributor Author

woubuc commented Apr 12, 2022

What command have you used to check if the colors are preserved? I tried to test it but the colors were not preserved.

I noticed while trying to fix this issue, that pnpm seems to call its own binary pnpm to run scripts in a workspace (I couldn't figure out where). So when it runs the script of one of the packages in a monorepo uses the default global installation of pnpm instead of the development version. Which is a separate issue I think.

So I had to uninstall my existing pnpm installation and then use npm link in packages/pnpm to get the local dev version of pnpm in my PATH. Then it uses the dev code for the global pnpm command & it should work.

Could this be the reason you're not seeing the colours?

@zkochan
Copy link
Member

zkochan commented Apr 12, 2022

I am running node /home/zoltan/src/pnpm/pnpm/packages/pnpm/dist/pnpm.cjs -r test

I see this:

image

Although with color it should be like this:

image

@woubuc
Copy link
Contributor Author

woubuc commented Apr 13, 2022

Oh, I see where the confusion comes from. This fix just makes it so that colour information isn't stripped on pnpm's side. Other scripts can still detect that they're not running in an interactive shell and so they don't use colours by default.

Most packages use supports-color so setting the FORCE_COLOR=1 env var (or passing the --color flag to scripts) will make these scripts use colour output, and with this PR those ANSI codes will no longer be removed by pnpm.

I had FORCE_COLOR=1 set globally in my IDE so I forgot to mention it here, sorry! This command using cross-env should work for everyone:

npx cross-env FORCE_COLOR=1 node packages/pnpm/dist/pnpm.cjs -r test

image

Note: tsc doesn't support FORCE_COLOR so the compile output doesn't get colours, there is an issue in the Typescript repo microsoft/TypeScript#44233 but it hasn't seen any activity since being opened. In any case, this is not a pnpm issue, just something to be aware of. Other scripts now properly show colours (at least in my testing).

@zkochan
Copy link
Member

zkochan commented Apr 13, 2022

Makes sense. In that case, it works.

Please add some changesets. Run pnpm changeset in the repo root.

And looks like something is failing.

@zkochan
Copy link
Member

zkochan commented Apr 13, 2022

Should pnpm set FORCE_COLOR=1 for the scripts that it runs?

@zkochan
Copy link
Member

zkochan commented Apr 13, 2022

I see some issues though (use --reporter=append-only)

image

@fowled
Copy link

fowled commented Jul 7, 2022

Hey @woubuc, @zkochan - any update/workaround on that issue? I've been loving my experience with PNPM and how well it handles workspaces, but having a colorless output is kind of a problem for me.

@cayter
Copy link

cayter commented Jul 17, 2022

Would love to get an update on this if possible. Am running 4 different projects concurrently with pnpm --parallel dev and the missing colour hurts the eyes and productivity. Thanks.

@woubuc
Copy link
Contributor Author

woubuc commented Jul 17, 2022

If I recall correctly, the cause of the problem was identified and a fix for it should be implemented in this PR. I needed to look into the failing tests but couldn't get the tests to run properly on my machine and then this kinda fell by the wayside as other work picked up.

I don't have the bandwidth right now to dive back into this codebase. So if anyone wants to help out, feel free to take over. Otherwise it will just remain on my to-do list.

@zkochan
Copy link
Member

zkochan commented Jul 17, 2022

the cause of the problem was identified

so how to fix this broken output: #4559 (comment) ?

@zkochan zkochan force-pushed the fix/2148-script-output-color branch from be3bdb4 to 0271264 Compare June 14, 2023 04:54
@zkochan
Copy link
Member

zkochan commented Jun 14, 2023

I can merge it as it doesn't seem to break anything. However, the output doesn't always work as you can see in my comment: #4559 (comment)

@zkochan zkochan merged commit 100d03b into pnpm:main Jun 14, 2023
7 of 8 checks passed
@welcome
Copy link

welcome bot commented Jun 14, 2023

Congrats on merging your first pull request! 🎉🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants