webpack.js.org icon indicating copy to clipboard operation
webpack.js.org copied to clipboard

`snapshot.managedPaths` and `snapshot.immutablePaths`

Open vankop opened this issue 3 years ago • 10 comments

Feature to document

https://webpack.js.org/configuration/other-options/#immutablepaths https://webpack.js.org/configuration/other-options/#managedpaths

Could be a regexp with required capture group, which is path itself, e.g. defaults one https://github.com/webpack/webpack/blob/main/lib/config/defaults.js#L384

Author(s)

Additional information

[ ] I am willing to work on this issue and submit a pull request.

vankop avatar Jun 09 '22 15:06 vankop

Please make sure this documentation includes why a capture group is needed because it seems unnecessary and confusing.

SystemParadox avatar Jun 09 '22 16:06 SystemParadox

as I described it is path itself. e.g. in case

/^(.+?)[\\/]cache[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/

captured path will be (.+?)

vankop avatar Jun 09 '22 16:06 vankop

But what does that even mean?

My best guess is that the capture group is meant to be the cache key for the folder but you can also have the regex match only certain files to be included as "managed" within it. But I'm just guessing because this isn't explained anywhere.

SystemParadox avatar Jun 09 '22 16:06 SystemParadox

they described in docs.. both paths should point to directories. e.g. managesPaths ~~/.+?[\\/]node_modules[\\/]/~~ should be /(.+?[\\/]node_modules[\\/])/

vankop avatar Jun 09 '22 16:06 vankop

Sorry, that still doesn't explain what the capture group is actually for. And that example doesn't have a capture group either!

SystemParadox avatar Jun 09 '22 16:06 SystemParadox

I just checked the source code https://github.com/webpack/webpack/blob/2a58ce7883b42e1ebcfde617ec4a27c7feb035e6/lib/FileSystemInfo.js#L1997, capture group is required to work.

So I think the confusing part is why not just use a normal regexp to match paths in webpack source code?

chenxsan avatar Jun 18 '22 13:06 chenxsan

Yes indeed, the capture group seems completely unnecessary.

  • If is not needed then it should be removed as it's just confusing
  • If it is needed then the docs need to explain why and give an example of when you would use it - an example that couldn't just be covered with a normal regex match

SystemParadox avatar Jun 18 '22 21:06 SystemParadox

@SystemParadox I've tried to file a patch so we don't need the capture group.

But unfortunately this seems to be a breaking change. Maybe they can fix it in webpack v6 :)

chenxsan avatar Jun 21 '22 12:06 chenxsan

Since #15969 has been closed "because it is required", can we please get this documented as to why it is required and what it does.

SystemParadox avatar Jun 23 '22 15:06 SystemParadox

I've merged that pull request but will keep this issue open since it's valid concern in my opinion.

chenxsan avatar Jul 02 '22 06:07 chenxsan