Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Why is createFilter is scoped to process.cwd? #39

Closed
tivac opened this issue Aug 25, 2018 · 8 comments · Fixed by #61
Closed

Why is createFilter is scoped to process.cwd? #39

tivac opened this issue Aug 25, 2018 · 8 comments · Fixed by #61

Comments

@tivac
Copy link

tivac commented Aug 25, 2018

const getMatcher = id => ( isRegexp( id ) ? id : { test: mm.matcher( resolve( id ) ) } );

If you invoke createFilter() with a string for include or exclude it'll be run through path.resolve before it's passed to mm.matcher().

Why?

It means that unless you pass a regular expression matcher all globs will only match files underneath process.cwd(). This cropped up as I tried to move my fixtures to the system temp folder and suddenly my plugin's filters stopped matching anything because they're all scoped. It seems like it'd be more intuitive for the glob to be passed to mm.matcher() w/o the resolving.

const { createFilter } = require("rollup-pluginutils");

const filter = createFilter("**/*.css");

// Now filter() is matching against
`${process.cwd()}/**/*.css`

// instead of what I expected, which is
`**/*.css`
tivac added a commit to tivac/modular-css that referenced this issue Aug 26, 2018
See rollup/rollup-pluginutils#39 for more background. Using a regex overrides the automatic scoping.
@guybedford
Copy link
Contributor

I'd be open to changing this to something more sensible, but we need to be careful about backwards compat etc.

Would you be interested in working on a PR?

@tivac
Copy link
Author

tivac commented Aug 28, 2018

What would a sensible back-compat approach be? An options object as the third arg to createFilter() that could be { resolve : false } to disable the behavior?

For now I've worked around by using a RegExp instead of a glob. It's not a pressing concern, just something that really threw me for a bit when my tests were failing.

@Hexxeh
Copy link

Hexxeh commented Sep 24, 2018

This seems to have another unintended effect too, whereby the path of the current directory is considered as part of the match pattern. Therefore, if your current directory contains characters that have special meaning in regexp, you might not match the files you expected to.

@nandin-borjigin
Copy link

I have run into similar problem.
thgh/rollup-plugin-scss#22

This kinda situation may occur frequently in a monorepo since 3-rd party dependencies are tend to be hoisted to the root directory.

I understand that 3rd party files have better treated as externals and the problem would be resolved. But there still are circumstances where bundling certain dependencies is required (e.g. say rolling up the final output of the monorepo)

Hexxeh added a commit to Fitbit/fitbit-sdk-toolchain that referenced this issue Oct 18, 2018
Summary:
rollup-pluginutils scopes include/exclude patterns provided to the current directory by prefixing the pattern with the current path.
Unfortunately, if that path contains special characters that have an effect in regular expressions, they're not treated as literal.
There's a bug open against this behaviour: rollup/rollup-pluginutils#39
Workaround it by providing include/exclude as regular expressions, which doesn't trigger this behaviour.

Test Plan: Build in a directory named "qa^(2),2"

Reviewers: #developer_tools, Jupiter, csnider

Reviewed By: #developer_tools, Jupiter, csnider

Subscribers: csnider

JIRA Issues: IPD-102765

Differential Revision: https://phabricator.firmwareci.fitbit.com/D2258
@sormy
Copy link

sormy commented Dec 1, 2018

the workaround is to use minimatch patterns starting with / like "/**/*.css"

@tivac
Copy link
Author

tivac commented Feb 6, 2019

@sormy That workaround didn't work for me, it just mean that my plugin never matched any files.

For now I've been using /\.css$/i and that seems to be fine-ish. @guybedford or @lukastaegert I'd still be willing to do the work to get a PR up for this if you have a preferred approach so I don't flop around too much.

tivac added a commit to tivac/modular-css that referenced this issue Feb 6, 2019
@lukastaegert
Copy link
Member

I created #61 to address this (as I need this myself for package side-effects in rollup-plugin-node-resolve). I would still stick with the default as it currently provides a consistent experience across the rollup ecosystem. However if you have special needs, you can now configure it.

@hiendv
Copy link

hiendv commented Sep 12, 2019

For the record, #61 does not resolve the problem with monorepo setup where dependencies are hoisted. Use #39 (comment) instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants