Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/tailwindcss/src/compat/config/resolve-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface ResolutionContext {

let minimal: ResolvedConfig = {
blocklist: [],
future: {},
prefix: '',
important: false,
darkMode: null,
Expand Down
9 changes: 9 additions & 0 deletions packages/tailwindcss/src/compat/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,12 @@ export interface UserConfig {
export interface ResolvedConfig {
important: boolean | string
}

// `future` key support
export interface UserConfig {
future?: 'all' | Record<string, boolean>
}

export interface ResolvedConfig {
future: Record<string, boolean>
}
75 changes: 75 additions & 0 deletions packages/tailwindcss/src/compat/plugin-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3791,3 +3791,78 @@ describe('prefix()', () => {
expect(fn).toHaveBeenCalledWith('btn')
})
})

describe('config()', () => {
test('can return the resolved config when passed no arguments', async () => {
let fn = vi.fn()
await compile(
css`
@plugin "my-plugin";
`,
{
async loadModule(id, base) {
return {
base,
module: ({ config }: PluginAPI) => {
fn(config())
},
}
},
},
)

expect(fn).toHaveBeenCalledWith(
expect.objectContaining({
theme: expect.objectContaining({
spacing: expect.any(Object),
}),
}),
)
})

test('can return part of the config', async () => {
let fn = vi.fn()
await compile(
css`
@plugin "my-plugin";
`,
{
async loadModule(id, base) {
return {
base,
module: ({ config }: PluginAPI) => {
fn(config('theme'))
},
}
},
},
)

expect(fn).toHaveBeenCalledWith(
expect.objectContaining({
spacing: expect.any(Object),
}),
)
})

test('falls back to default value if requested path does not exist', async () => {
let fn = vi.fn()
await compile(
css`
@plugin "my-plugin";
`,
{
async loadModule(id, base) {
return {
base,
module: ({ config }: PluginAPI) => {
fn(config('somekey', 'defaultvalue'))
},
}
},
},
)

expect(fn).toHaveBeenCalledWith('defaultvalue')
})
})
4 changes: 3 additions & 1 deletion packages/tailwindcss/src/compat/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type PluginAPI = {
): void

theme(path: string, defaultValue?: any): any
config(path: string, defaultValue?: any): any
config(path?: string, defaultValue?: any): any
prefix(className: string): string
}

Expand Down Expand Up @@ -399,6 +399,8 @@ export function buildPluginApi(
config(path, defaultValue) {
let obj: Record<any, any> = resolvedConfig

if (!path) return obj

let keypath = toKeyPath(path)

for (let i = 0; i < keypath.length; ++i) {
Expand Down