Skip to content
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

Fix glob import/require in Stylus assets #1845

Merged
merged 1 commit into from Aug 3, 2018
Merged

Fix glob import/require in Stylus assets #1845

merged 1 commit into from Aug 3, 2018

Conversation

prokopyl
Copy link
Contributor

@prokopyl prokopyl commented Aug 3, 2018

As said in #1816, Parcel currently overrides the Stylus resolver with its own, namely to support importing from node_modules and root imports. However, it currently fails to resolve glob imports, trying to resolve to files literally named **/* (which obviously don't exist, throwing ENOENT).

This PR works around the issue by detecting glob imports in the ahead-of-time Stylus ImportVisitor, applying fast-glob on the given path, and then associating multiple paths to the import instead of a single one.
During evaluation time, it will then replace the glob import statement with multiple ones (one for each resolved file) before passing them to Stylus, and then merging all the resulting node blocks into one.

This PR also adds a test case for Stylus glob import, to prevent future regressions.

This should fix #1816.

(Comments are obviously welcome, considering I don't really know the Parcel codebase there might be issues here and there.)

@DeMoorJasper
Copy link
Member

Awesome, thanks for this!

@DeMoorJasper DeMoorJasper merged commit dd99fa1 into parcel-bundler:master Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't import Stylus modules with file globbing
2 participants