-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Upgrade deprecated order-none
to order-0
#18126
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dbd9bdc
ignore deprecated utilities in pre computed utilities map
RobinMalfait 22fb458
migrate deprecated classes to their replacement
RobinMalfait 5b45c5b
add tests
RobinMalfait 1acb53c
update changelog
RobinMalfait f25c822
move `order-none` to `legacy-utilities.ts`
RobinMalfait f2b56f8
remove explicit check
RobinMalfait 038744b
Update packages/@tailwindcss-upgrade/src/codemods/template/migrate.te…
RobinMalfait File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
52 changes: 52 additions & 0 deletions
52
packages/@tailwindcss-upgrade/src/codemods/template/migrate-deprecated-utilities.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { Config } from '../../../../tailwindcss/src/compat/plugin-api' | ||
import type { DesignSystem } from '../../../../tailwindcss/src/design-system' | ||
import type { Writable } from '../../utils/types' | ||
import { baseCandidate, parseCandidate, printUnprefixedCandidate } from './candidates' | ||
import { computeUtilitySignature } from './signatures' | ||
|
||
const DEPRECATION_MAP = new Map([['order-none', 'order-0']]) | ||
|
||
export async function migrateDeprecatedUtilities( | ||
designSystem: DesignSystem, | ||
_userConfig: Config | null, | ||
rawCandidate: string, | ||
): Promise<string> { | ||
let signatures = computeUtilitySignature.get(designSystem) | ||
|
||
for (let readonlyCandidate of designSystem.parseCandidate(rawCandidate)) { | ||
// The below logic makes use of mutation. Since candidates in the | ||
// DesignSystem are cached, we can't mutate them directly. | ||
let candidate = structuredClone(readonlyCandidate) as Writable<typeof readonlyCandidate> | ||
|
||
// Create a basic stripped candidate without variants or important flag. We | ||
// will re-add those later but they are irrelevant for what we are trying to | ||
// do here (and will increase cache hits because we only have to deal with | ||
// the base utility, nothing more). | ||
let targetCandidate = baseCandidate(candidate) | ||
let targetCandidateString = printUnprefixedCandidate(designSystem, targetCandidate) | ||
|
||
let replacementString = DEPRECATION_MAP.get(targetCandidateString) ?? null | ||
if (replacementString === null) return rawCandidate | ||
|
||
let legacySignature = signatures.get(targetCandidateString) | ||
if (typeof legacySignature !== 'string') return rawCandidate | ||
|
||
let replacementSignature = signatures.get(replacementString) | ||
if (typeof replacementSignature !== 'string') return rawCandidate | ||
|
||
// Not the same signature, not safe to migrate | ||
if (legacySignature !== replacementSignature) return rawCandidate | ||
|
||
let [replacement] = parseCandidate(designSystem, replacementString) | ||
|
||
// Re-add the variants and important flag from the original candidate | ||
return designSystem.printCandidate( | ||
Object.assign(structuredClone(replacement), { | ||
variants: candidate.variants, | ||
important: candidate.important, | ||
}), | ||
) | ||
} | ||
|
||
return rawCandidate | ||
} |
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.