Skip to content

feat(compiler): improve file watching architecture and add external d…#6279

Merged
christian-bromann merged 3 commits intomainfrom
cb/watch-external-dir
Jun 10, 2025
Merged

feat(compiler): improve file watching architecture and add external d…#6279
christian-bromann merged 3 commits intomainfrom
cb/watch-external-dir

Conversation

@christian-bromann
Copy link
Copy Markdown
Member

@christian-bromann christian-bromann commented Jun 6, 2025

What is the current behavior?

fixes: #3151

Currently, the file watching system in Stencil uses separate functions (watchSrcDirectory and watchRootFiles) to handle watching different types of directories. The system only watches the source directory and root directory, with hardcoded exclusion patterns scattered throughout the code. The watch setup is also sequential, which can impact startup performance.

What is the new behavior?

This PR refactors the file watching architecture to:

  • Consolidates file watching logic: Replaces watchSrcDirectory and watchRootFiles with a single, more flexible watchFiles function
  • Adds external directory watching: Introduces a new watchExternalDirs config option that allows users to specify additional directories to watch (e.g., node_modules for development workflows)
  • Improves code organization: Extracts file and directory exclusion patterns into reusable constants (EXCLUDE_DIRS, EXCLUDE_EXTENSIONS)
  • Enhances performance: Uses Promise.all to set up file watchers concurrently instead of sequentially
  • Better documentation: Adds comprehensive JSDoc comments explaining the watching behavior
  • Code quality improvements: Refactors isWatchIgnorePath function with early returns for better readability

Documentation

The new watchExternalDirs configuration option is documented in the TypeScript interface with JSDoc comments.

Does this introduce a breaking change?

  • Yes
  • No

This is a non-breaking change. All existing functionality is preserved, and the new watchExternalDirs option is optional with a sensible default (empty array).

Testing

  • Verified that existing watch functionality continues to work as expected
  • Tested the new watchExternalDirs configuration option by adding external directories
  • Confirmed that file exclusion patterns work correctly with the new consolidated approach
  • Validated that the concurrent watch setup improves startup performance without affecting functionality

Other information

This refactoring lays the groundwork for more flexible file watching configurations and improved developer experience. The new watchExternalDirs option will be particularly useful for development workflows that need to watch dependencies or other external directories for changes.

A dev build is available at @stencil/core@4.33.1-dev.1749248891.8108e9b

…irectory support

- Consolidate watchSrcDirectory and watchRootFiles into a single watchFiles function
- Add support for watching external directories via new watchExternalDirs config option
- Extract file/directory exclusion patterns into reusable constants (EXCLUDE_DIRS, EXCLUDE_EXTENSIONS)
- Improve code documentation and comments for better maintainability
- Refactor isWatchIgnorePath function for better readability with early returns
- Use Promise.all for concurrent file watching setup to improve performance
@christian-bromann christian-bromann requested a review from a team as a code owner June 6, 2025 22:17
@christian-bromann christian-bromann merged commit 0844538 into main Jun 10, 2025
72 checks passed
@christian-bromann christian-bromann deleted the cb/watch-external-dir branch June 10, 2025 19:15
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.

feat: stencil compiler should be configurable to watch arbitrary files for change and recompile

1 participant