Skip to content

Commit 50b766d

Browse files
Remove variants related code (#5465)
* drop `variants` related resolveConfig functionality More AOT code that we could get rid of! * drop more files! I keep finding these unused files 😅 * Update setupContextUtils.js Co-authored-by: Adam Wathan <[email protected]>
1 parent 30badad commit 50b766d

File tree

7 files changed

+6
-741
lines changed

7 files changed

+6
-741
lines changed

src/lib/setupContextUtils.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,9 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
194194

195195
return getConfigValue(['corePlugins', path], true)
196196
},
197-
variants: (path, defaultValue) => {
198-
if (Array.isArray(tailwindConfig.variants)) {
199-
return tailwindConfig.variants
200-
}
201-
202-
return getConfigValue(['variants', path], defaultValue)
197+
variants: () => {
198+
// Preserved for backwards compatibility but not used in v3.0+
199+
return []
203200
},
204201
addUserCss(userCss) {
205202
for (let [identifier, rule] of withIdentifiers(userCss)) {

src/util/createUtilityPlugin.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function createUtilityPlugin(
1515
{ filterDefault = false, resolveArbitraryValue = asValue } = {}
1616
) {
1717
let transformValue = transformThemeValue(themeKey)
18-
return function ({ matchUtilities, variants, theme }) {
18+
return function ({ matchUtilities, theme }) {
1919
for (let utilityVariation of utilityVariations) {
2020
let group = Array.isArray(utilityVariation[0]) ? utilityVariation : [utilityVariation]
2121

@@ -38,7 +38,6 @@ export default function createUtilityPlugin(
3838
Object.entries(theme(themeKey) ?? {}).filter(([modifier]) => modifier !== 'DEFAULT')
3939
)
4040
: theme(themeKey),
41-
variants: variants(themeKey),
4241
type: asMap.get(resolveArbitraryValue) ?? 'any',
4342
}
4443
)

src/util/resolveConfig.js

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ import colors from '../../colors'
66
import log from './log'
77
import { defaults } from './defaults'
88
import { toPath } from './toPath'
9-
import dlv from 'dlv'
109

1110
function isFunction(input) {
1211
return typeof input === 'function'
1312
}
1413

15-
function uniq(input) {
16-
return Array.from(new Set(input))
17-
}
18-
1914
function isObject(input) {
2015
return typeof input === 'object' && input !== null
2116
}
@@ -186,90 +181,6 @@ function extractPluginConfigs(configs) {
186181
return allConfigs
187182
}
188183

189-
function mergeVariants(variants) {
190-
const mergedVariants = variants.reduce((resolved, variants) => {
191-
Object.entries(variants || {}).forEach(([plugin, pluginVariants]) => {
192-
if (isFunction(pluginVariants)) {
193-
resolved[plugin] = pluginVariants({
194-
variants(path) {
195-
return dlv(resolved, path, [])
196-
},
197-
before(toInsert, variant, existingPluginVariants = resolved?.[plugin] ?? []) {
198-
if (variant === undefined) {
199-
return [...toInsert, ...existingPluginVariants]
200-
}
201-
202-
const index = existingPluginVariants.indexOf(variant)
203-
204-
if (index === -1) {
205-
return [...existingPluginVariants, ...toInsert]
206-
}
207-
208-
return [
209-
...existingPluginVariants.slice(0, index),
210-
...toInsert,
211-
...existingPluginVariants.slice(index),
212-
]
213-
},
214-
after(toInsert, variant, existingPluginVariants = resolved?.[plugin] ?? []) {
215-
if (variant === undefined) {
216-
return [...existingPluginVariants, ...toInsert]
217-
}
218-
219-
const index = existingPluginVariants.indexOf(variant)
220-
221-
if (index === -1) {
222-
return [...toInsert, ...existingPluginVariants]
223-
}
224-
225-
return [
226-
...existingPluginVariants.slice(0, index + 1),
227-
...toInsert,
228-
...existingPluginVariants.slice(index + 1),
229-
]
230-
},
231-
without(toRemove, existingPluginVariants = resolved?.[plugin] ?? []) {
232-
return existingPluginVariants.filter((v) => !toRemove.includes(v))
233-
},
234-
})
235-
} else {
236-
resolved[plugin] = pluginVariants
237-
}
238-
})
239-
240-
return resolved
241-
}, {})
242-
243-
return {
244-
...mergedVariants,
245-
extend: collectExtends(variants),
246-
}
247-
}
248-
249-
function mergeVariantExtensions({ extend, ...variants }, variantOrder) {
250-
return mergeWith(variants, extend, (variantsValue, extensions) => {
251-
const merged = uniq([...(variantsValue || []), ...extensions].flat())
252-
253-
if (extensions.flat().length === 0) {
254-
return merged
255-
}
256-
257-
return merged.sort((a, z) => variantOrder.indexOf(a) - variantOrder.indexOf(z))
258-
})
259-
}
260-
261-
function resolveVariants([firstConfig, ...variantConfigs], variantOrder) {
262-
// Global variants configuration like `variants: ['hover', 'focus']`
263-
if (Array.isArray(firstConfig)) {
264-
return firstConfig
265-
}
266-
267-
return mergeVariantExtensions(
268-
mergeVariants([firstConfig, ...variantConfigs].reverse()),
269-
variantOrder
270-
)
271-
}
272-
273184
function resolveCorePlugins(corePluginConfigs) {
274185
const result = [...corePluginConfigs].reduceRight((resolved, corePluginConfig) => {
275186
if (isFunction(corePluginConfig)) {
@@ -299,18 +210,13 @@ export default function resolveConfig(configs) {
299210
variantOrder: defaultConfig.variantOrder,
300211
},
301212
]
302-
let { variantOrder } = allConfigs.find((c) => c.variantOrder)
303213

304214
return normalizeConfig(
305215
defaults(
306216
{
307217
theme: resolveFunctionKeys(
308218
mergeExtensions(mergeThemes(allConfigs.map((t) => t?.theme ?? {})))
309219
),
310-
variants: resolveVariants(
311-
allConfigs.map((c) => c?.variants ?? {}),
312-
variantOrder
313-
),
314220
corePlugins: resolveCorePlugins(allConfigs.map((c) => c.corePlugins)),
315221
plugins: resolvePluginLists(configs.map((c) => c?.plugins ?? [])),
316222
},

tests/custom-plugins.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,15 +1217,14 @@ test('plugins can be created using the `createPlugin` function', () => {
12171217
},
12181218
plugins: [
12191219
createPlugin(
1220-
function ({ addUtilities, theme, variants }) {
1220+
function ({ addUtilities, theme }) {
12211221
addUtilities(
12221222
Object.fromEntries(
12231223
Object.entries(theme('testPlugin')).map(([k, v]) => [
12241224
`.test-${k}`,
12251225
{ testProperty: v },
12261226
])
1227-
),
1228-
variants('testPlugin')
1227+
)
12291228
)
12301229
},
12311230
{
@@ -1404,9 +1403,6 @@ test('plugins created using `createPlugin.withOptions` do not need to be invoked
14041403
lg: '3rem',
14051404
},
14061405
},
1407-
variants: {
1408-
testPlugin: ['responsive', 'hover'],
1409-
},
14101406
}
14111407
}
14121408
)

0 commit comments

Comments
 (0)