From f48d256f7b05d4c4cf6e121332bdc60d3e31c5bd Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 25 Oct 2024 20:54:20 -0400 Subject: [PATCH 1/6] Add tests for `config()` --- .../tailwindcss/src/compat/plugin-api.test.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/tailwindcss/src/compat/plugin-api.test.ts b/packages/tailwindcss/src/compat/plugin-api.test.ts index 9d5fea5911e2..c3bc0c896fd8 100644 --- a/packages/tailwindcss/src/compat/plugin-api.test.ts +++ b/packages/tailwindcss/src/compat/plugin-api.test.ts @@ -3791,3 +3791,51 @@ describe('prefix()', () => { expect(fn).toHaveBeenCalledWith('btn') }) }) + +describe('config()', () => { + 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') + }) +}) From 7d391a86a94e70a0df0111a83f426b4ac4213826 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 25 Oct 2024 20:54:50 -0400 Subject: [PATCH 2/6] Make `config()` path arg optional --- .../tailwindcss/src/compat/plugin-api.test.ts | 27 +++++++++++++++++++ packages/tailwindcss/src/compat/plugin-api.ts | 4 ++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/tailwindcss/src/compat/plugin-api.test.ts b/packages/tailwindcss/src/compat/plugin-api.test.ts index c3bc0c896fd8..c4da90503419 100644 --- a/packages/tailwindcss/src/compat/plugin-api.test.ts +++ b/packages/tailwindcss/src/compat/plugin-api.test.ts @@ -3793,6 +3793,33 @@ describe('prefix()', () => { }) 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( diff --git a/packages/tailwindcss/src/compat/plugin-api.ts b/packages/tailwindcss/src/compat/plugin-api.ts index 54fd8e00a27a..a03b05a13b5e 100644 --- a/packages/tailwindcss/src/compat/plugin-api.ts +++ b/packages/tailwindcss/src/compat/plugin-api.ts @@ -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 } @@ -399,6 +399,8 @@ export function buildPluginApi( config(path, defaultValue) { let obj: Record = resolvedConfig + if (!path) return obj + let keypath = toKeyPath(path) for (let i = 0; i < keypath.length; ++i) { From f12f83ff2c1dbda24e3c3c034312a23b3669f45f Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 25 Oct 2024 20:58:02 -0400 Subject: [PATCH 3/6] Add `future` config key --- packages/tailwindcss/src/compat/config/resolve-config.ts | 1 + packages/tailwindcss/src/compat/config/types.ts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/packages/tailwindcss/src/compat/config/resolve-config.ts b/packages/tailwindcss/src/compat/config/resolve-config.ts index 9b09ad63fa77..c486de8ae33d 100644 --- a/packages/tailwindcss/src/compat/config/resolve-config.ts +++ b/packages/tailwindcss/src/compat/config/resolve-config.ts @@ -29,6 +29,7 @@ interface ResolutionContext { let minimal: ResolvedConfig = { blocklist: [], + future: {}, prefix: '', important: false, darkMode: null, diff --git a/packages/tailwindcss/src/compat/config/types.ts b/packages/tailwindcss/src/compat/config/types.ts index 313a7dba8b9b..b1e6e6820a6c 100644 --- a/packages/tailwindcss/src/compat/config/types.ts +++ b/packages/tailwindcss/src/compat/config/types.ts @@ -96,3 +96,12 @@ export interface UserConfig { export interface ResolvedConfig { important: boolean | string } + +// `future` key support +export interface UserConfig { + future: 'all' | Record +} + +export interface ResolvedConfig { + future: Record +} From 0ae9c2e39b5003878a2779694a8f0f8dd9586a51 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 25 Oct 2024 21:17:49 -0400 Subject: [PATCH 4/6] update --- packages/tailwindcss/src/compat/config/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tailwindcss/src/compat/config/types.ts b/packages/tailwindcss/src/compat/config/types.ts index b1e6e6820a6c..9d01052e06cd 100644 --- a/packages/tailwindcss/src/compat/config/types.ts +++ b/packages/tailwindcss/src/compat/config/types.ts @@ -99,7 +99,7 @@ export interface ResolvedConfig { // `future` key support export interface UserConfig { - future: 'all' | Record + future?: 'all' | Record } export interface ResolvedConfig { From dd4fb7828a584d3169439e7b62cd99e6c4e33dcc Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 28 Oct 2024 10:22:44 -0400 Subject: [PATCH 5/6] Update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 547ed68b054e..5f6a5a1af7fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- Nothing yet! +### Fixed + +- Make `config()` path argument optional in v4 plugin API for backwards compat ([#14799](https://github.com/tailwindlabs/tailwindcss/pull/14799)) ## [4.0.0-alpha.30] - 2024-10-24 From f9fc5cb7ebdec7ac92eaf89da94cbfdc3fae305c Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Mon, 28 Oct 2024 11:44:15 -0400 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f6a5a1af7fe..3d054b026933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Make `config()` path argument optional in v4 plugin API for backwards compat ([#14799](https://github.com/tailwindlabs/tailwindcss/pull/14799)) +- Support calling `config()` with no arguments in plugin API ([#14799](https://github.com/tailwindlabs/tailwindcss/pull/14799)) ## [4.0.0-alpha.30] - 2024-10-24