-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Upgrade: Rewrite imports of relative files to use relative file paths #14755
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
Upgrade: Rewrite imports of relative files to use relative file paths #14755
Conversation
Your org has enabled the Graphite merge queue for merging into nextAdd the label “merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
|
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @philipp-spiess and the rest of your teammates on |
85407e1 to
462903b
Compare
RobinMalfait
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, we do bail when it starts with . which means that
@import "./foo"Stays as-is instead of resulting in:
@import "./foo.css"095f4b8 to
3b86506
Compare
Merge activity
|
…les_to_use_relative_file_paths
|
Can't quite tell from the changes — do we support this now or no? @import "some-relative-file.css";IMO we shouldn't if we do currently. |
…les_to_use_relative_file_paths
|
With this codemod, this will be converted to: @import "./some-relative-file.css";If the |
Yeah but say you don't run the codemod, does our @import "some-relative-file.css";IMO it should error. |
…les_to_use_relative_file_paths
|
@adamwathan Yeah this change removed the logic where it automatically appends the |
|
Both
Both is valid css import and should work though. Just found out that this broke bunch of imports in my css sice the update to latest beta. Should I create a new issue? |

When we implemented the CSS import resolution system, we found out a detail about CSS imports in that files without a relative path prefix would still be relative to the source file. E.g.:
Should first look for the file
foo.cssin the same directory. To make this cost as cheap as possible, we limited this by a heuristics to only apply the auto-relative imports for files with a file extension.Naturally, while testing v4 on more templates, we found that it's common for people to omit the file extension when loading css file. The above could also be written as such:
To improve this, we have two options:
@importmore expensive because we have to check for relative files.@importstatements to be explicitly relative.Because we really care about performance, we opted to go with the latter option. This PR adds the codemod and removes the heuristics so we resolve CSS files similar to how you would resolve JS files.