chore(deps): replace chalk with native util.styleText#5949
chore(deps): replace chalk with native util.styleText#5949roli-lpci wants to merge 2 commits intomozilla:masterfrom
Conversation
Replace chalk dependency with Node.js native `util.styleText` API:
- chalk.red/yellow/blue → styleText('color', String(text))
- chalk.Instance({ enabled: false }) → String identity function
- Bump engines.node to >=20.12.0 (required for util.styleText)
Addresses mozilla#5932
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rob--W
left a comment
There was a problem hiding this comment.
Bumping the Node version would require a major version bump, which is too big of an ask for this refactor.
Please maintain support for older versions. I consider it to be an acceptable degradation of functionality by falling back to just printing the message as is without coloring (for simplicity), or including a simple, minimal set of escape sequences if you'd like to maintain the coloring on older Node.
Considering that Node 18 is already EOL for almost a year at this point, with Node 20 to follow soon (in less than 2 months), I think that we don't have to worry about old Node.
Therefore I'd be inclined to go with the simple approach: no coloring as a fallback.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5949 +/- ##
==========================================
- Coverage 98.79% 98.76% -0.04%
==========================================
Files 51 51
Lines 2905 2912 +7
Branches 895 898 +3
==========================================
+ Hits 2870 2876 +6
- Misses 35 36 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Use Node.js native styleText (19.10+) instead of chalk package for terminal color output. Removes unnecessary dependency while maintaining color output functionality. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rob--W
left a comment
There was a problem hiding this comment.
How did you generate the package-lock.json file? I see that it includes several changed, and it is unclear why these changes were made.
I checked the package-lock file to see if the removed dependency would disappear. While the entry is deleted from the dependencies, it is still listed. I checked mentions of chalk" in the lockfile and it seems that there is one dependent (eslint) that itself is a peer dependency, and others but those are just dev dependencies.
As the code changes itself seem to be AI-generated, I'd like to know whether the lock file was also AI-generated, or created by standard tooling. And if so, what versions did you use?
|
Thanks for the thorough review! Re: Node version support — The fallback is already in place in the current code. Both Re: package-lock.json — Generated by standard Happy to squash or make any other adjustments. |
|
I also asked for the versions of the tooling that you used, for reproducibility. In this case the Node and npm version. Are you an autonomous AI or is there a human in the loop? |
|
Node v25.2.1, npm 11.6.2. I am what many would call a nontechnical developer with a pipeline that is highly steered, monitored, submitting PRs while I learn proper orchestration, validation, testing, etc. If you would not like any more submissions from me, let me know and I can abstain going forward. Thanks! |
|
Hi Rob, my initial response didn't answer your question directly, so let me fix that. Yes, the code changes are AI-assisted. I use an AI coding assistant as part of my development workflow. I direct the work, review the output, test locally, and decide what to submit. I think maintainers should know what they're reviewing so they can calibrate their scrutiny accordingly. One finding from this migration that might be useful to the project regardless of whether this PR lands: If this PR isn't a fit given the AI-assisted workflow, or you'd rather I not submit to this repo going forward, no hard feelings at all. Rolando Bosch |
|
Hi Roland, thanks for the human reply and your additional finding. I appreciate it. I'm not opposed to AI-aided contributions when disclosed properly. I have mentored many contributions over the years, where I take time to explain and guide contributions. I noticed a recent trend where my feedback results in code changes or replies that are increasingly larger pieces of text, which takes more effort and time to review on my part. The PR you generated looks reasonable to me, as it is an improvement that drops an unnecessary dependency. I do wonder whether the shape of the patch is the desired outcome, because the current fix is a drop-in replacement for the original chalk API, and even retains the naming. Other options are to update the callers and/or put the code in a separate module to allow reuse by the current callers of Back to reflect on AI: |
|
@roli-lpci In the meantime we have bumped the minimum supported Node version to 20, just two days ago. We are willing to bump the minimum version to 20.12.0, to remove the need for having a fallback in the code. Could you please rebase your PR, and change This PR also migrates the use of |
Summary
chalkdependency with Node.js nativeutil.styleTextAPI>=18.0.0to>=20.12.0(required forutil.styleText)String()coercion for safe non-string handlingChanges
src/linter.js—chalk.Instance({ enabled })replaced with plain object of color functions that delegate tostyleText()or pass through viaStringin boring modetests/integration/run-as-production-env.js—chalk.red()/chalk.green()replaced withstyleText('red', ...)/styleText('green', ...)package.json— Removedchalk, bumpedengines.nodeandbrowserslistto>=20.12.0Testing
Addresses #5932