-
-
Notifications
You must be signed in to change notification settings - Fork 589
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
[pluginutils] strange behavior for include/exclude pattern #490
Comments
There's historical reasons for the way it works atm. I had the same questions working on that lib a while back. I can't recall what exactly the reasoning was, but I do remember I found it at the old repo. Follow the git blame road here https://github.com/rollup/rollup-pluginutils |
That is what the |
The resolve option isn't exposed from most plugins. The tough part with match patterns is that you don't really know if something is wrong. You set up a pattern and expect it to "just work". So even if we add an option, I don't think a lot of people would use it because they don't realize something is wrong. For example if my current working directory is /Users/me/foo/bar and I use a plugin like this: export default {
plugins: [
myPlugin({ include: ['**/*.css'], exclude: ['/Users/me/foo/node_modules/some-project/some-file.css'] })
]
} The I expect this to match all CSS files in the build, but in fact it's only matching CSS files under From the history I couldn't tell why the patterns are resolved, only that the resolve option was added to address this problem. Ideally resolve should default to false, with an option to opt into it. But it's hard to judge whether anyone relies on the resolve behavior. We could avoid resolving patterns that start with a |
I think the behaviour is meant to match what Rollup itself is doing. E.g. if you set
Feels like a very good idea to me, could be even considered a bug fix, at least I do not see where this would be breaking. Though I guess it should also be made to work for absolute windows paths. |
Rollup itself doesn't support globs though, but I understand what the intention is. We could not add it for Still, it's confusing to have different behavior than other matching libraries. Maybe we could also not add the current working directory to patterns starting with Alternatively there could be a separate |
my project:
third-part package like 'xxx'. I want to use
finnaly sry, third-party still fail...... |
I ran into this same issue today which really confused me for a while. I am trying to use an absolute path as my // createFilter doesn't match...
f = createFilter('/a/b/**/*')
f('/a/b/c.js') // false
// but minimatch does! :D
minimatch.match(['/a/b/c.js'], '/a/b/**/*') // ['/a/b/c.js'] IMO this could be fixed by adding support for absolute paths in The workaround for me for now involves using |
Expected Behavior / Situation
Include/exclude patterns work in an intuitive way
Actual Behavior / Situation
Include/exclude patterns don't work in an intuitive way
Modification Proposal
I spent quite some time trying to debug why my include/exclude patterns were not working correctly. Then I found out that here we are doing some magic by prefixing the current working directory to the user provided patterns: https://github.com/rollup/plugins/blob/master/packages/pluginutils/src/createFilter.ts#L15
This creates an invalid pattern when the pattern also includes the working directory. For example I was trying to pass on an explicit list of files to exclude from a plugin. The current working directory got prepended to that, resulting in a pattern that would never match.
For example
/Users/me/some/path/to/code.js
becomes/Users/me/some/path/Users/me/some/path/to/code.js
.Another problem I ran into is that this way it's impossible to match any files outside of the current working directory. I'm running rollup from a package in a monorepo, the node modules folder is actually two directories upwards.
We could add some magic to detect when to resolve patterns, but I'm wondering why it would be necessary. Could we not just follow the
minimatch
library logic here?The text was updated successfully, but these errors were encountered: