-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Migrate at-apply utilites with template migrations #14574
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import type { AtRule, Plugin } from 'postcss' | ||
import type { Config } from 'tailwindcss' | ||
import type { DesignSystem } from '../../../tailwindcss/src/design-system' | ||
import { segment } from '../../../tailwindcss/src/utils/segment' | ||
import { migrateCandidate } from '../template/migrate' | ||
|
||
export function migrateAtApply(): Plugin { | ||
export function migrateAtApply({ | ||
designSystem, | ||
userConfig, | ||
}: { designSystem?: DesignSystem; userConfig?: Config } = {}): Plugin { | ||
function migrate(atRule: AtRule) { | ||
let utilities = atRule.params.split(/(\s+)/) | ||
let important = | ||
|
@@ -30,6 +36,12 @@ export function migrateAtApply(): Plugin { | |
return [...variants, utility].join(':') | ||
}) | ||
|
||
// If we have a valid designSystem and config setup, we can run all | ||
// candidate migrations on each utility | ||
if (designSystem && userConfig) { | ||
params = params.map((param) => migrateCandidate(designSystem, userConfig, param)) | ||
} | ||
Comment on lines
+39
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably consider making a JS config file input required. This way we can simplify this decision here and don't have a case where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but I think a better way is to try to figure out where the config file lives (similar to how Tailwind CSS v3 just finds the config file if it's a known file name + extension in the root). If you have a custom file (aka, we can't resolve one) then the Another tricky thing, but will be more related to the stuff I'm working on with @thecrypticace (where we handle stylesheets as graphs to figure out which file imports what), is the fact that in theory you can have multiple roots with different settings. Which means that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that makes sense! Adding a task |
||
|
||
atRule.params = params.join('').trim() | ||
} | ||
|
||
|
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.
It's so beautiful 🥹