Skip to content

Do not throw errors when transforming excluded files #209

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

Closed
sthzg opened this issue Nov 16, 2018 · 6 comments
Closed

Do not throw errors when transforming excluded files #209

sthzg opened this issue Nov 16, 2018 · 6 comments

Comments

@sthzg
Copy link
Contributor

sthzg commented Nov 16, 2018

Thanks for your work on both of the great react-css-modules packages. I want to clarify if a behavior that we experience is expected or open to modification (or of course to be solved by other means).

I am excluding node_modules via the exclude option, which is respected in ImportDeclaration(...), but not in JSXElement(...). The latter will eventually make assertions on excluded files (in our case throwing an error if it finds a styleName prop but no supported imports).

Use case:
This affects us as we are maintaining a non-bundled internal component library that still uses the react-css-modules HOC (as well as a deprecated CSS preprocessor without a postcss syntax) and cannot be immediately refactored to the babel plugin. For the apps that make use of our internal dependency however we want to start using the babel plugin while gradually migrating the other parts over time.

As mentioned above I would like to clarify if opting out in the JSXElement transform if the component's path matches the exclude setting makes sense in your opinion.

// just a quick and dirty check to see if it works in our case
JSXElement(path, stats) {
  const filename = stats.file.opts.filename;

  if (stats.opts.exclude && filename.match(new RegExp(stats.opts.exclude))) {
    return;
  }  
  // ...
}
Repository owner deleted a comment from ioanlucut Nov 16, 2018
sthzg pushed a commit to sthzg/babel-plugin-react-css-modules that referenced this issue Nov 19, 2018
@sthzg
Copy link
Contributor Author

sthzg commented Nov 21, 2018

I pushed #215 for discussion if the approach of applying the exclude setting not only to the imported style files but also to the location of the JSXElements that request them is okay for the scope of this project.

@sthzg
Copy link
Contributor Author

sthzg commented Nov 30, 2018

hi @gajus - I don't mean to bother but wanted to check if something like #215 or a different implementation to a similar effect would be valuable to the project. As I need something like this I could invest some time either in refinement or working out a different implementation (hints or ideas appreciated). If not it's not a big deal, but it would be great to know as we need to base some decisions on it.

@gajus
Copy link
Owner

gajus commented Nov 30, 2018

The PR says it is WIP. If it is ready to merge, I am happy to merge it.

@sthzg
Copy link
Contributor Author

sthzg commented Nov 30, 2018

Sounds great - the commit in the PR is currently marked as a feature release - if you are fine with that I will remove the WIP so that it can be merged. Otherwise I can include a BREAKING info or downgrade it to a fix release.

I am not exactly sure about the scope as the original behavior is changed in the following way, which can also be seen as a breaking change.

  • old => scanning every file but ignoring imports on style files on excluded files
  • new => ignoring also js files that match a path in the exclude pattern.

@gajus
Copy link
Owner

gajus commented Nov 30, 2018

I think the proposed behaviour is a sane default behaviour. I doubt it would break anything, but seeing this is a change to the way the current logic works, I will release it as a breaking change. Thank you.

@gajus gajus closed this as completed Nov 30, 2018
@gajus
Copy link
Owner

gajus commented Nov 30, 2018

🎉 This issue has been resolved in version 5.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Nov 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants