fix(awslint): use a default import for chalk#38110
Open
laazyj wants to merge 1 commit into
Open
Conversation
`bin/awslint.ts` imported chalk as a namespace (`import * as chalk from 'chalk'`) and accessed color functions as namespace members (`chalk.red`, `chalk.cyan`, `chalk.bold`, ...). Since aws#38058 set `esModuleInterop: true` and `module: "Node20"` on the awslint tsconfig, this compiles to `__importStar(require("chalk"))`; with chalk v4 (a CommonJS default-export function) the color methods live only on the wrapper's `.default`, so every `chalk.<color>` is `undefined` at runtime. The result: `awslint list` crashes (`TypeError: chalk.red is not a function`), and during a build every diagnostic is silently swallowed — the results printer is gated on `if (color)` where `color = chalk.red` is `undefined` — while `errors++` still sets a non-zero exit code, so builds fail at `cdk-awslint` with no output at all. Switch to a default import (`import chalk from 'chalk'`), which compiles to `chalk.default.<color>` and restores the color functions. Closes aws#38109
Author
|
Exemption Request: This fixes the |
aws-cdk-automation
requested changes
Jun 7, 2026
Collaborator
aws-cdk-automation
left a comment
There was a problem hiding this comment.
The pull request linter fails with the following errors:
❌ Fixes must contain a change to a test file.
❌ Fixes must contain a change to an integration test file and the resulting snapshot.
If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.
✅ A exemption request has been requested. Please wait for a maintainer's review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue # (if applicable)
Closes #38109.
Reason for this change
packages/awslintis broken onmain:awslint listcrashes withTypeError: chalk.red is not a function, and during a normal build every awslint diagnostic is silently swallowed while the build still fails at thecdk-awslintstep with no output, making failures undiagnosable.bin/awslint.tsimports chalk as a namespace (import * as chalk from 'chalk') and useschalk.red/chalk.cyan/chalk.boldas namespace members. Since #38058 setesModuleInterop: trueandmodule: "Node20"on the awslint tsconfig, this now compiles to__importStar(require("chalk")). chalk v4 is a CommonJS default-export function, so its color methods end up only on the wrapper's.default— everychalk.<color>isundefinedat runtime. In the results loop the print is gated onif (color)wherecolor = chalk.redisundefined, so nothing prints, yeterrors++still sets a non-zero exit code.Description of changes
Switch the namespace import to a default import:
This compiles to
chalk.default.<color>and restores the color functions. One line; no behavioural change beyond making chalk work again.Description of how you validated your changes
Rebuilt
packages/awslint(tsc -b && eslint && pkglint, clean) and ran the deterministic repro:node bin/awslint.js list→TypeError: chalk.red is not a function(exit 1).node bin/awslint.js list→ prints all 47 rules in colour (exit 0);awslintoveraws-cdk-libruns clean and now surfaces diagnostics through the samechalk.default.*path.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license