Add CSS codemod for missing @layer#14504
Merged
Merged
Conversation
RobinMalfait
commented
Sep 24, 2024
| import { expect, it } from 'vitest' | ||
| import { formatNodes } from './format-nodes' | ||
|
|
||
| function markPretty(): Plugin { |
Member
Author
There was a problem hiding this comment.
Just a quick plugin to mark the nodes with tailwind_pretty
| walk(root, (child) => { | ||
| if (child.raws.tailwind_pretty) { | ||
| nodesToFormat.push(child) | ||
| return WalkAction.Skip |
Member
Author
There was a problem hiding this comment.
Using the custom walk implementation so that we can skip going inside of the node, once we found a node with tailwind_pretty.
e361319 to
7abb3fd
Compare
5f46eb2 to
266fffb
Compare
Base automatically changed from
feat/css-codemods-at-layer-utilities
to
next
September 24, 2024 16:17
This way we can ensure that all migrations run in order as expected.
This allows us to re-use the logic, the only thing we have to do is mark a node with `raws.tailwind_pretty = true`
We will convert `@tailwind` directives in one step to `@import` at-rules. These could now exist in the middle of the CSS. This step hoists them to the top in a separate pass.
We don't need this, the migrate directives already takes care of this by prepending at-rules to the top.
Instead of crafting a bad input, we can just not do it.
266fffb to
e5e07f9
Compare
thecrypticace
approved these changes
Sep 24, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a codemod that ensures that some parts of your stylesheet are wrapped in an
@layer.This is a follow-up PR of #14411, in that PR we migrate
@tailwinddirectives to imports.As a quick summary, that will turn this:
Into:
But there are a few issues with that if we have additional CSS on the page. For example let's imagine we had this:
This will now be turned into:
But in v4 we use real layers, in v3 we used to replace the directive with the result of that layer. This means that now the
bodyand.btnstyles are in the incorrect spot.To solve this, we have to wrap them in a layer. The
bodyshould go in an@layer base, and the.btnshould be in an@layer componentsto make sure it's in the same spot as it was before.That's what this PR does, the original input will now be turned into:
There are a few internal refactors going on as well, but those are less important.