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: @import url() error in dependency resolver #2632

Merged
merged 2 commits into from Sep 22, 2021

Conversation

groenroos
Copy link
Collaborator

What: Fixes #2595

Why: Because @import url() returns an error for the .deps() / --deps flag

How: Add a check to DepsResolver.prototype.visitImport to skip url() imports from dependency resolver, and thus from dependency lists

Checklist:

  • Documentation
  • Unit Tests
  • Code complete

Comments

  • It may be argued whether url() should or should not be included in the deps list (the documentation is not explicit about this) - however I've opted to skip them from the deps list, since they'll be almost necessarily external to the consumer codebase
  • Replaces fix: DepsResolver.visitImport path isNull check #2627, as that solution causes other bugs in unit tests

@groenroos groenroos changed the title Fix/import url Fix: @import url() error in dependency resolver Sep 5, 2021
@iChenLei iChenLei self-requested a review September 5, 2021 14:13
Copy link
Member

@iChenLei iChenLei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developer.mozilla.org/en-US/docs/Web/CSS/@import#examples

Awesome pull request, thank you. I have a small request, can you add more complex unit test for this bugfix ? Current test case looks like function spec unit test, we can add more e2e-like tests, for example:

Input:

// import.url.styl
@import url('https://fonts.googleapis.com/css)
@import xxx;

// more code

Output:

// import.url.css
@import url('https://fonts.googleapis.com/css)

// gen code

There are many e2e-like tests in stylus/test/cases/*, more unit test cases is always a good thing, thank you again.

@groenroos
Copy link
Collaborator Author

@iChenLei Thanks for the review!

I reckoned the e2e tests were already covered by import.include.resolver.absolute.styl:

@import url('http://foo.com/foo.css')
@import url("http://foo.com/foo.css")
@import url('https://foo.com/foo.css')
@import url('//foo.com/foo.css')

In any case, this issue seems to be specific to generating the deps list with the --deps flag or the .deps() method - this issue seemed to never affect just parsing Stylus into CSS itself.

Let me know if there's some specific case that I should cover!

@iChenLei iChenLei changed the title Fix: @import url() error in dependency resolver Fix: @import url() error in dependency resolver Sep 6, 2021
lib/visitor/deps-resolver.js Show resolved Hide resolved
@groenroos
Copy link
Collaborator Author

@iChenLei Let me know if there is anything further to be done for this PR! I don't have write access so I cannot merge it myself.

@iChenLei
Copy link
Member

@groenroos Check your permission please, I think you can merge this pr by yourself now. If encount any issue please @ me again. Thanks! Anyway, every pull request need peer review ! We should ensure pull request's quality.

@groenroos groenroos merged commit d2cddcf into stylus:dev Sep 22, 2021
@groenroos groenroos deleted the fix/import-url branch September 22, 2021 12:54
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.

@import url() not working
2 participants