Skip to content

fix(tasks): update styles watcher to support chokidar v4#141

Open
Hugoer wants to merge 2 commits intoNetcentric:mainfrom
Hugoer:Update-chokidar-usage-to-support-v4
Open

fix(tasks): update styles watcher to support chokidar v4#141
Hugoer wants to merge 2 commits intoNetcentric:mainfrom
Hugoer:Update-chokidar-usage-to-support-v4

Conversation

@Hugoer
Copy link
Copy Markdown
Member

@Hugoer Hugoer commented Mar 11, 2026

This PR fixes an issue with SCSS file watchers caused by Chokidar version > 3. In versions 4+, Chokidar no longer supports glob patterns directly.

Description

Chokidar v4 removed support for glob patterns in watch().
This PR updates the styles watcher to handle that breaking change by pre-resolving SCSS files via fast-glob before passing them to chokidar.

Related Issue

Fixes #138

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • All new and existing tests passed.

@easingthemes
Copy link
Copy Markdown
Member

Issues Found

  1. Missing glob import (Blocker)
    The diff adds await glob(pattern, ...) but there’s no visible require('fast-glob') or const { glob } = require('fast-glob') import at the top of tasks/styles.js. The existing file only imports path, log, generateEntries, and renderStyles. This will throw a ReferenceError: glob is not defined at runtime.
    Fix needed: Add const { glob } = require('fast-glob'); (or const glob = require('fast-glob');) at the top of the file.
  2. async Promise constructor anti-pattern (Minor)
    The promise callback is changed to new Promise(async (resolve) => { ... }). This is a well-known anti-pattern because:
    ∙ Exceptions thrown inside an async executor are not caught by the Promise — they become unhandled rejections instead of rejecting the returned promise
    ∙ The existing try/catch mitigates this partially, but any error from await glob(...) that escapes the catch block will be silently swallowed
    Suggested improvement: Either:
    ∙ Move the async logic before the Promise constructor, or
    ∙ Use async/await throughout and remove the new Promise wrapper entirely (preferred — the function could just be module.exports = async (config) => { ... })
  3. Watcher won’t detect new SCSS files (Design consideration)
    Since fast-glob resolves files once at startup, newly created SCSS files won’t be watched. The old glob-based approach (when it worked) would have picked up new files. This may be acceptable given the EMFILE constraints mentioned in Update chokidar usage to support v4 (glob patterns removal) #138, but it’s worth documenting as a known limitation.
  4. Downgrade vs. upgrade reasoning (Minor)
    The PR description says “downgraded chokidar from v5 to v4” but the title of Update chokidar usage to support v4 (glob patterns removal) #138 says “support v4.” The commit message says “update chokidar to version 4.0.3.” Since v5 existed before, this is technically a downgrade. Worth clarifying in the PR description whether v5 introduced other issues (the EMFILE problems mentioned in the issue?).
    Verdict
    Changes requested — The missing glob import (Rename template vars with fe-build one #1) is a runtime blocker that must be fixed before merge. The async Promise anti-pattern (Add package code  #2) is worth addressing. Items Order imports alphabetically #3 and stylelint.config.js #4 are informational.

@Hugoer Hugoer changed the title fix(tasks): adjust styles watcher implementation fix(tasks): update styles watcher to support chokidar v4 Apr 15, 2026
@Hugoer
Copy link
Copy Markdown
Member Author

Hugoer commented Apr 15, 2026

Thanks for reviewing!

changes made:

  1. Removed new Promise(async ...) anti-pattern — the exported function is now async directly, so errors from await glob(...) and other async ops are properly propagated.
  2. Replaced Promise.allSettled(...).then(...) with await in the non-watch branch — consistent async/await throughout.
  3. Added a comment documenting the SCSS watcher limitation (new files not detected at runtime) as Dragan suggested.

The glob import was already present on line 2, so nothing to add there.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update chokidar usage to support v4 (glob patterns removal)

2 participants