Skip to content

Commit 7de0f33

Browse files
committed
only compute the default design system once
1 parent 0a64140 commit 7de0f33

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

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

Lines changed: 5 additions & 12 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,16 @@ const THEME_KEYS = {
4647
'blur-xs': '--blur-xs',
4748
}
4849

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

5154
export async function legacyClasses(
5255
designSystem: DesignSystem,
5356
_userConfig: Config,
5457
rawCandidate: string,
5558
): Promise<string> {
56-
// Prepare design system with the unknown legacy classes
57-
if (!SEEDED.has(designSystem)) {
58-
for (let old in LEGACY_CLASS_MAP) {
59-
designSystem.utilities.static(old, () => [])
60-
}
61-
SEEDED.add(designSystem)
62-
}
63-
64-
let defaultDesignSystem = await __unstable__loadDesignSystem('@import "tailwindcss";', {
65-
base: __dirname,
66-
})
59+
let defaultDesignSystem = await DESIGN_SYSTEMS.get(__dirname)
6760

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

0 commit comments

Comments
 (0)