Skip to content

fix(awslint): use a default import for chalk#38110

Open
laazyj wants to merge 1 commit into
aws:mainfrom
laazyj:awslint-chalk-default-import
Open

fix(awslint): use a default import for chalk#38110
laazyj wants to merge 1 commit into
aws:mainfrom
laazyj:awslint-chalk-default-import

Conversation

@laazyj
Copy link
Copy Markdown

@laazyj laazyj commented Jun 7, 2026

Issue # (if applicable)

Closes #38109.

Reason for this change

packages/awslint is broken on main: awslint list crashes with TypeError: chalk.red is not a function, and during a normal build every awslint diagnostic is silently swallowed while the build still fails at the cdk-awslint step with no output, making failures undiagnosable.

bin/awslint.ts imports chalk as a namespace (import * as chalk from 'chalk') and uses chalk.red / chalk.cyan / chalk.bold as namespace members. Since #38058 set esModuleInterop: true and module: "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 — every chalk.<color> is undefined at runtime. In the results loop the print is gated on if (color) where color = chalk.red is undefined, so nothing prints, yet errors++ still sets a non-zero exit code.

Description of changes

Switch the namespace import to a default import:

-import * as chalk from 'chalk';
+import chalk from 'chalk';

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:

  • Before: node bin/awslint.js listTypeError: chalk.red is not a function (exit 1).
  • After: node bin/awslint.js list → prints all 47 rules in colour (exit 0); awslint over aws-cdk-lib runs clean and now surfaces diagnostics through the same chalk.default.* path.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

`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
@github-actions github-actions Bot added p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Jun 7, 2026
@laazyj
Copy link
Copy Markdown
Author

laazyj commented Jun 7, 2026

Exemption Request: This fixes the packages/awslint build tool itself (a one-line chalk import change); no integration test is applicable. Validated by rebuilding awslint and the deterministic awslint list before/after repro described in the PR body. Requesting pr-linter/exempt-integ-test.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Jun 7, 2026
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(awslint): namespace import of chalk breaks under esModuleInterop — all lint diagnostics are silently swallowed and builds fail with no output

2 participants