Skip to content

Commit ac11740

Browse files
committed
only compute the default design system once
1 parent 0697a7f commit ac11740

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/@tailwindcss-upgrade/src/template/codemods/legacy-classes.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path'
33
import url from 'node:url'
44
import type { Config } from 'tailwindcss'
55
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
6+
import { DefaultMap } from '../../../../tailwindcss/src/utils/default-map'
67
import { printCandidate } from '../candidates'
78

89
const __filename = url.fileURLToPath(import.meta.url)
@@ -46,24 +47,26 @@ const THEME_KEYS = {
4647
'blur-xs': '--blur-xs',
4748
}
4849

50+
const DESIGN_SYSTEMS = new DefaultMap((base) => {
51+
return __unstable__loadDesignSystem('@import "tailwindcss";', { base })
52+
})
4953
const SEEDED = new WeakSet<DesignSystem>()
5054

5155
export async function legacyClasses(
5256
designSystem: DesignSystem,
5357
_userConfig: Config,
5458
rawCandidate: string,
5559
): Promise<string> {
56-
// Prepare design system with the unknown legacy classes
60+
// Ensure the "old" classes exist as static utilities to make the migration
61+
// easier because the "root" will point to the full class.
5762
if (!SEEDED.has(designSystem)) {
5863
for (let old in LEGACY_CLASS_MAP) {
5964
designSystem.utilities.static(old, () => [])
6065
}
6166
SEEDED.add(designSystem)
6267
}
6368

64-
let defaultDesignSystem = await __unstable__loadDesignSystem('@import "tailwindcss";', {
65-
base: __dirname,
66-
})
69+
let defaultDesignSystem = await DESIGN_SYSTEMS.get(__dirname)
6770

6871
for (let candidate of designSystem.parseCandidate(rawCandidate)) {
6972
if (candidate.kind === 'static' && Object.hasOwn(LEGACY_CLASS_MAP, candidate.root)) {

0 commit comments

Comments
 (0)