-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
chore(deps): update chokidar to v4 #5374
base: master
Are you sure you want to change the base?
Conversation
@Fuzzyma Can you rebase? |
@alexander-akait i am still waiting for the chokidar issue to be resolved. So this isn't passing tests atm anyway. That said, surely can rebase :) |
In order to replace chokidars removed glob functionality, we have to use some trickery. - `glob-parent` is used to get the common ancenstor dir that needs to be watched. - `picomatch` is used as ignore-filter to make sure that only files/dirs are watched that match the given glob - `is-glob` is used to only use glob logic when needed In total this adds 4 direct or transitive dependencies. However, the update to chokidar v4 removes 12. So its a net positive I also added a test to ensure that creation of nested directories is detected properly.
7969fd4
to
184588d
Compare
@alexander-akait I saw that when I run the tests a lot of them fail - unrelated to my changes. What is that about? |
lib/Server.js
Outdated
|
||
ignoredArr.push(ignoreFunc); | ||
|
||
watchOptions.ignored = ignoredArr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fuzzyma Can we simplify this and rewrite it into a more understandable logic, here one array is derived from the second and the second from the third, it is very difficult to read, I mean:
watchOptions.ignored = []
.concat(watchPathArr.map(item => isGlob(item) ? generateIgnoreMatcher(item) : false))
.concat(watchOptions.ignored.map(item => { isGlob(item) ? generateIgnoreMatcher(item) : item }))
.filter(Boolean)
This is an approximate pseudocode, but it is easy to understand where everything comes from and how it is formed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to finish this soon and make a release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
As long as chokidar is not handling the issue linked in the first post, this is blocked anyway. As alternative we have to filter out undefined options ourselves before passing them to chokidar. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexander-akait I tried it your way. But there is one detail that might end up being performance sensitive.
I dont want to generate multiple matchers (one for each glob) if one is sufficient for all globs. Therefore I need to filter out the glob strings twice.
I tried to simplify the code further and think the code that I have now is easy enough to understand. I made it so that everything ends up in the ignoreArr.
Also fixed a bug while I was at it.
We need tests for the ignore case though! I am not quite sure how to do the ignore case. I need to take a look.
Also I made the snapshots break because ignore is an array now when passied to chokidar. Need to fix that as well
@alexander-akait so there are 2 remaining issues:
|
I.e. our logic is broken somewhere? Because I don't think someone write
There is a test - https://github.com/webpack/webpack-dev-server/blob/master/test/e2e/watch-files.test.js#L160, just add a several cases where we have In fact, this is one of the reasons why we moved away from Another solution that I am considering is the implementation of this function fundamentally in webpack (based on |
@alexander-akait no your logic is not broken. It is usually totally acceptable to pass undefined options to functions because typescripts optional type is However, yes, we do create undefineds when calling getInterval and no interval or poll is defined: webpack-dev-server/lib/Server.js Lines 899 to 911 in 55220a8
If they dont fix it, we have to fix it on our side. For the tests: I already added tests there for the globs. But again: how do you test if something does not happen because it is ignored? |
👍 Do they have a pr?
maybe |
Yeah, mine: paulmillr/chokidar#1396 Well since chokidar doesnt support globbing anymore, everything that touches globs, we have to test on our side. |
Yeah, maybe Let's first try to simplify everything in the code, maybe we can even use unit testing here and one or two integrations to understand that everything really works |
Then I will pull out the creation of the ignore functions into own units. The we can simply test those. |
This has to be done because of an issue on chokidars site: paulmillr/chokidar#1394
@alexander-akait I added tests for the glob matching and also added wrapper code to support chokidars weird behavior with undefined values. It can be removed once they make up their mind. This should work now and is ready for review |
Are there any blockers to this pull request? |
Not from my side |
I maybe found an issue with negated glob patterns. I need to figure out if everything is alright before merge |
@Fuzzyma Sorry for long delay (there were complicated personal things), what is current status? What we need to improve or wait? Will be great to landing it |
@alexander-akait the problem i encountered was, that I was filtering out potential nested directories because i couldn't partially match glob patterns. The new idea is, to wrap chokidar and emit only the events that match the passed glob pattern. Because that is such a delicate topic, I created a package chokidar-glob that re-implements glob watching. It passes all old (v3) chokidar tests for globbing except for some windows tests which I cant debug on my machine. According to james, even with this approach it should perform good enough. The situation is not ideal. I don't feel comfortable recommending chokidar-glob yet (at minimum I have to fix the windows tests). I am open to suggestions on how to approach this topic further. |
Honestly, one of the reasons why we stopped using |
@Fuzzyma I see your problem... A possible solution is to also abandon the use of globes in favor of |
The problem with |
We don't have roadmap for it current...
I am if we don't find solution for globing I prefer to use |
@alexander-akait as far as I can see watchpak also doesn't support globs for watched files. Only the ignore prop supports globs (at least that's what I grasped from their docs and tests) |
Just a couple of comments: Chokidar does have support. I joined as a maintainer last year and have been very active maintaining it, responding to issues, etc Shipping glob support in a FS watcher doesn't make much sense. It makes more sense to be able to combine an fs watcher with a glob library (also what fdir does). We did the right thing removing glob support from chokidar but it may make sense to have a higher level library soon that combines them with it Chokidar exists to deal with the various inconsistencies between file systems and to add a higher level interface to FS watch. It doesn't exist to provide you globs If you need any help, here I am. It's possible the pr for undefined options will get merged at some point, but you should really solve that here too. It seems odd to be passing that |
It looks strange because if you look at most libraries/tools/etc that use The problem is that no matter how many versions of chokidar we used in webpack, we encountered similar problems with almost every major version, although at some point we were almost one of the most popular tools that used Perhaps this is how you see the approach to supporting the tool, and I have no right to argue here, because this is your vision, but speaking as a user and as a developer who uses the tool, such an approach unfortunately does not suit me, you have the right to disagree again. Some time ago I already wrote about this, unfortunately I can't find where, yes this is my view on this problem, because every time an update is painful, as a minimum for software it is normal to first declare something obsolete/deprecated, and then delete it (i.e. one major release with deprecation and then remove it), which gives time to prepare - find other approaches to the solution, or find another tool, or try to take part of the code and logic into your code base.
We can't control developers options here and making extra operation to remove |
I'm not saying we won't merge the change to chokidar to deal with undefined options, just that it is worth looking on your end too at why this is a thing. From what I understood, it wasn't the user passing undefined, it was webpack. But I may have misunderstood Removing globs was a big change. But I do believed it is the right thing to do, since chokidar should focus on being a file watcher rather than a glob library. I'm not sure yet if we should have a library which joins the two or we should let you pass one in. One or the other should exist to make this easier in future though I think For now, it really shouldn't be so difficult to bring your own. So I'd like to understand what the difficulties are a bit better. That will help me with the end solution too |
@43081j passing one in sounds interesting. But then again: maybe just give me more control. e.g. an event filter to effectively ignore events but not ignore watching. We talked about this at some point that chokidars kinda needs 2 types of ignore. Then we could easily just filter the events by a glob. Right now, I need a whole chokidar wrapper for that. I think until this is figured out, a library that combines chokidar and glob makes sense. Also useful for people that don't want to wire this up themselves. To the undefined problem: Yes, the one undefined came from something internally. But I think webpack-dev-server allows the user to pass arbitrary watcher options. So if they pass undefined, it will break even if the one occurrence in webpack-dev-server is fixed. |
I understand but one doesn't justify the other. We should still fix the code here to stop passing undefined. Even if a user can forcefully do it themselves I'll have a deeper think about how best to solve this glob stuff and get back to you soon |
Oh yeah definitely! |
This PR aims to close #5368
In order to replace chokidars removed glob functionality, we have to use some trickery.
glob-parent
is used to get the common ancenstor dir that needs to be watched.picomatch
is used as ignore-filter to make sure that only files/dirs are watched that match the given globis-glob
is used to only use glob logic when neededIn total this adds 4 direct or transitive dependencies. However, the update to chokidar v4 removes 12. So its a net positive
I also added a test to ensure that creation of nested directories is detected properly.
NOTE: This PR needs to wait for paulmillr/chokidar#1394. If that issue is not resolved, we have to make sure to not let undefined values slip through for watcher options.
I didn't add this change to this PR because it would add more changed lined and it might be not needed after all.
That's why this PR is still draft