|
1 | 1 | import fs from 'node:fs/promises' |
2 | 2 | import path, { extname } from 'node:path' |
| 3 | +import { parseCandidate } from '../../../../tailwindcss/src/candidate' |
3 | 4 | import type { Config } from '../../../../tailwindcss/src/compat/plugin-api' |
4 | 5 | import type { DesignSystem } from '../../../../tailwindcss/src/design-system' |
5 | 6 | import { spliceChangesIntoString, type StringChange } from '../../utils/splice-changes-into-string' |
6 | | -import { extractRawCandidates } from './candidates' |
| 7 | +import { extractRawCandidates, printCandidate } from './candidates' |
7 | 8 | import { migrateArbitraryValueToBareValue } from './migrate-arbitrary-value-to-bare-value' |
8 | 9 | import { migrateAutomaticVarInjection } from './migrate-automatic-var-injection' |
9 | 10 | import { migrateBgGradient } from './migrate-bg-gradient' |
@@ -56,9 +57,22 @@ export async function migrateCandidate( |
56 | 57 | end: number |
57 | 58 | }, |
58 | 59 | ): Promise<string> { |
| 60 | + let original = rawCandidate |
59 | 61 | for (let migration of DEFAULT_MIGRATIONS) { |
60 | 62 | rawCandidate = await migration(designSystem, userConfig, rawCandidate, location) |
61 | 63 | } |
| 64 | + |
| 65 | + // If nothing changed, let's parse it again and re-print it. This will migrate |
| 66 | + // pretty print candidates to the new format. If it did change, we already had |
| 67 | + // to re-print it. |
| 68 | + // |
| 69 | + // E.g.: `bg-red-500/[var(--my-opacity)]` -> `bg-red-500/(--my-opacity)` |
| 70 | + if (rawCandidate === original) { |
| 71 | + for (let candidate of parseCandidate(rawCandidate, designSystem)) { |
| 72 | + return printCandidate(designSystem, candidate) |
| 73 | + } |
| 74 | + } |
| 75 | + |
62 | 76 | return rawCandidate |
63 | 77 | } |
64 | 78 |
|
|
0 commit comments