Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pluginContainer): implement watchChange hook #14822

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

developit
Copy link
Contributor

Description

This PR implements the watchChange plugin hook.

Additional context

Currently, observing file changes can only be done via server.watcher.on("change", ...), or somewhat lossily via the handleHotUpdate() plugin hook (operates on Modules rather than Files though, and doesn't run for deletions).

Since the Plugin TS definition and container implementation indicate watchChange() hook is available (it doesn't throw like emitFile), I figured it would make sense to add support for it.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Copy link

stackblitz bot commented Oct 31, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Makes sense to me. Looks like there's some linting issues that should be fixed by running pnpm format at root.

@bluwy bluwy changed the title feat(plugin api): implement watchChange hook feat(pluginContainer): implement watchChange hook Oct 31, 2023
@bluwy bluwy added the p2-nice-to-have Not breaking anything but nice to have (priority) label Oct 31, 2023
@sapphi-red sapphi-red linked an issue Oct 31, 2023 that may be closed by this pull request
7 tasks
@bluwy
Copy link
Member

bluwy commented Nov 1, 2023

We talked about this in the meeting today and are fine merging it 👍 It would be interesting to know if you have any usecase for using watchChange in dev too, so we'll have some guide if we have to change how watchChange works in the future.

@patak-dev
Copy link
Member

For future reference, this PR may break plugins that assume that watchChange is only being called during build. But I think this should be rare. It would be good merging it as part of the major though.

@bluwy bluwy merged commit 9369d8d into vitejs:main Nov 1, 2023
10 checks passed
@developit
Copy link
Contributor Author

Thanks for taking this on @patak-dev + @bluwy! I'm heads down landing our Vite switchover so I wasn't able to tweak the tests/formatting.

@developit developit deleted the feat/plugin-watch-change-hook branch November 3, 2023 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority) rollup plugin compat
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

watchChange is not triggered for this.addWatchFile
4 participants