-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
chalk.js doesn't seem to work on Windows when running inside a hook #350
Comments
same issue here with output of |
See #32 for related context. I agree that output from other sources than |
Can't seem to reproduce on macOS with the Terminal. Here's how I've tested:
// package.json
"husky": {
"hooks": {
"pre-commit": "node index.js"
}
} // index.js
const chalk = require('chalk')
console.log(chalk.green('hello world'))
process.exit(1) // make the commit fail so it can be tested multiple times
What's your OS? Which terminal are you using? |
@typicode Thanks for reply. I am using windows 10 with the system terminal |
Can try adding # ~/.huskyrc
export FORCE_COLOR=1 |
Chalk auto detects if color support is available in the current terminal. You can force it on. @typicode showed one way. They are all enumerated here: https://github.com/chalk/chalk#chalklevel Husky should still probably be improved to properly preserve the terminal type so that chalk can detect it correctly. :) |
@typicode Can I config that in the package.json file? |
@fancyboynet try this: "husky": {
"hooks": {
"pre-commit": "env FORCE_COLOR=1 node ./script/chalk.js"
}
} |
@typicode @cinderblock It works! Thanks for your work. |
@cinderblock Not sure how it could be done :/ Seems to be specifi to Git on Windows. For example, if I create a #!/usr/bin/env node
// .git/hooks/pre-commit
const chalk = require('chalk')
console.log(chalk.green('hello world'))
process.exit(1) git commit -m test It will show colors on macOS and Linux but not on Windows.
@fancyboynet as shown, yes it's possible. One downside though is that all your repo users will have colors forced. So if people clone your repo and use a Git client that doesn't support colors, they may get something like But if you're the main developer, or are working in a team and know the tools that are used, forcing it may be fine. |
The script source(
./script/chalk.js
)The config
If I run the script directly, the color will show.Anyone knows why? Thx.
The text was updated successfully, but these errors were encountered: