Skip to content

Commit

Permalink
Don't change structure of ResolvedConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-spiess committed Dec 2, 2024
1 parent cbfb848 commit df4d4ae
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
5 changes: 1 addition & 4 deletions packages/tailwindcss/src/compat/apply-compat-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,7 @@ function upgradeToFullPluginSupport({
},
})

for (let {
plugin: { handler },
reference,
} of resolvedConfig.plugins) {
for (let { handler, reference } of resolvedConfig.plugins) {
handler(reference ? { ...pluginApi, addBase: () => {} } : pluginApi)
}

Expand Down
14 changes: 7 additions & 7 deletions packages/tailwindcss/src/compat/config/resolve-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface ConfigFile {
interface ResolutionContext {
design: DesignSystem
configs: UserConfig[]
plugins: { plugin: PluginWithConfig; reference: boolean }[]
plugins: PluginWithConfig[]
content: ResolvedContentConfig
theme: Record<string, ThemeValue>
extend: Record<string, ThemeValue[]>
Expand Down Expand Up @@ -133,24 +133,24 @@ function extractConfigs(
ctx: ResolutionContext,
{ config, base, path, reference }: ConfigFile,
): void {
let plugins: { plugin: PluginWithConfig; reference: boolean }[] = []
let plugins: PluginWithConfig[] = []

// Normalize plugins so they share the same shape
for (let plugin of config.plugins ?? []) {
if ('__isOptionsFunction' in plugin) {
// Happens with `plugin.withOptions()` when no options were passed:
// e.g. `require("my-plugin")` instead of `require("my-plugin")(options)`
plugins.push({ plugin: plugin(), reference })
plugins.push({ ...plugin(), reference })
} else if ('handler' in plugin) {
// Happens with `plugin(…)`:
// e.g. `require("my-plugin")`
//
// or with `plugin.withOptions()` when the user passed options:
// e.g. `require("my-plugin")(options)`
plugins.push({ plugin, reference })
plugins.push({ ...plugin, reference })
} else {
// Just a plain function without using the plugin(…) API
plugins.push({ plugin: { handler: plugin }, reference })
plugins.push({ handler: plugin, reference })
}
}

Expand All @@ -169,8 +169,8 @@ function extractConfigs(
for (let plugin of plugins) {
ctx.plugins.push(plugin)

if (plugin.plugin.config) {
extractConfigs(ctx, { path, base, config: plugin.plugin.config, reference })
if (plugin.config) {
extractConfigs(ctx, { path, base, config: plugin.config, reference: plugin.reference })
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tailwindcss/src/compat/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type ThemeConfig = Record<string, ThemeValue> & {

export interface ResolvedConfig {
theme: Record<string, Record<string, unknown>>
plugins: { plugin: PluginWithConfig; reference: boolean }[]
plugins: PluginWithConfig[]
}

// Content support
Expand Down
2 changes: 1 addition & 1 deletion packages/tailwindcss/src/compat/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as SelectorParser from './selector-parser'

export type Config = UserConfig
export type PluginFn = (api: PluginAPI) => void
export type PluginWithConfig = { handler: PluginFn; config?: UserConfig }
export type PluginWithConfig = { handler: PluginFn; config?: UserConfig; reference: boolean }
export type PluginWithOptions<T> = {
(options?: T): PluginWithConfig
__isOptionsFunction: true
Expand Down

0 comments on commit df4d4ae

Please sign in to comment.