fix(cli): cdk watch glob pattern support broken after chokidar v3 -> v4 upgrade#1134
Merged
fix(cli): cdk watch glob pattern support broken after chokidar v3 -> v4 upgrade#1134
Conversation
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1134 +/- ##
==========================================
+ Coverage 87.71% 87.72% +0.01%
==========================================
Files 72 72
Lines 10116 10129 +13
Branches 1337 1337
==========================================
+ Hits 8873 8886 +13
Misses 1217 1217
Partials 26 26
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
new-app.zip |
svidgen
approved these changes
Feb 12, 2026
github-merge-queue bot
pushed a commit
that referenced
this pull request
Feb 25, 2026
Tests #1134 ### Description of tests #### `cdk watch` in CLI - Test: Detects file changes for watched files - Test: Does NOT detect file changes for unwatched files #### `Toolkit.watch()` - Test: Detects file changes for watched files - Test: Does NOT detect file changes for unwatched files We used AI 🤖 to help with this contribution. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.
Fixes #1146
Description
The
cdk watchcommand stopped working correctly after upgrading to CDK CLI v2.1100.1+. File changes were not being detected, causing watch mode to appear broken.Root Cause
Chokidar v4 removed built-in glob pattern support. The CDK CLI was passing glob patterns like
**,**/*.tsdirectly tochokidar.watch(), which no longer expands them. Instead, chokidar v4 treats these as literal file paths.Solution
Use
picomatchlibrary to handle glob pattern matching. The fix created acreateIgnoreMatcherutility in toolkit-lib that:rootDirmy-dir→my-dir/**) for backward compatibilitytoolkit-libandaws-cdk:chokidar.watch(patterns, ...)tochokidar.watch('.', { ignored: fn, cwd: rootDir })Fixed default include pattern in aws-cdk:
**glob patternThis is a backwards-compatible change and there were no changes to the public API. Users continue to configure watch the same way in
cdk.json:{ "watch": { "include": ["**/*.ts", "**/*.js"], "exclude": ["node_modules/**", "cdk.out/**"] } }Testing
cdkbinary; verified that the currently released version does not work, then verified the new changes function as expected, and behave the same as versions before 2.1100.1 (see logs)createIgnoreMatcherincluding pattern normalizationtoolkit-libaws-cdkto verify filtering behaviorLogs
Tested on MacOS. Initialized a new CDK app and ran
cdk watchusing CDK CLI v2.1100.0 (version beforecdk watchstopped working). See annotated logs.Logs from
cdk watchusing CDK CLI v2.1100.0 (previously working version) in a sample projectHere, I create a new file called
track-me-please, to verifywatchredeploys the appHere, I make a change to lib/new-app-stack.ts to verify
watchredeploys the appDuring this run, I also create a file called
.dont-track-meand make a change totest/new-app.test.ts. Neither of these changes result in a deployment. This validates that these files are properly ignored.Then, I ran
cdk watchusing my locally builtcdk(new changes). See annotated logs.Logs from
cdk watchusing locally built CDK CLI in a sample projectNote that these logs immediately follow the logs above.
Here, I create a new file called
track-me-too.watchdeploys, as expected.Here, I make a change to
lib/new-app-stack.ts, which triggers a deployment, as expected.I also verified that the latest version of the CDK CLI does not track files correctly. Below are the logs, which show no activity, even though I made several file changes. The logs also do not indicate that
watchis tracking any files.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license