Skip to content

Commit a7ebc9c

Browse files
Expose flattenColorPalette (#15318)
Resolves #15315 It looks like we implemented this in Core but forgot to expose it from the distributed package (the references are only used for testing plugins internally right now). This exposes `flattenColorPalette` under the old import path of `tailwindcss/lib/util/flattenColorPalette`. ## Test Plan Added the following plugin to the Vite example and ensured it works as expected: ```ts import flattenColorPalette from 'tailwindcss/lib/util/flattenColorPalette' import plugin from 'tailwindcss/plugin' export default plugin(({ matchUtilities, theme }) => { matchUtilities( { 'hover-bg': (value) => { return { '&:hover': { backgroundColor: value, }, } }, }, { values: flattenColorPalette(theme('colors')) }, ) }) ``` <img width="462" alt="Screenshot 2024-12-06 at 11 47 44" src="https://github.com/user-attachments/assets/11163390-053e-4c6e-8cb9-ae67184ad594">
1 parent 94a3cff commit a7ebc9c

File tree

7 files changed

+28
-5
lines changed

7 files changed

+28
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Added
11+
12+
- Add support for `tailwindcss/lib/util/flattenColorPalette` exports ([#15318](https://github.com/tailwindlabs/tailwindcss/pull/15318))
13+
14+
### Fixed
15+
16+
- Fix dependency related warnings when using `@tailwindcss/postcss` on Windows ([#15321](https://github.com/tailwindlabs/tailwindcss/pull/15321))
1117

1218
## [4.0.0-beta.6] - 2024-12-06
1319

1420
### Fixed
1521

1622
- Ensure `@import "…" reference` never generates utilities ([#15307](https://github.com/tailwindlabs/tailwindcss/pull/15307))
17-
- Fix dependency related warnings when using `@tailwindcss/postcss` on Windows
1823

1924
## [4.0.0-beta.5] - 2024-12-04
2025

packages/tailwindcss/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
"require": "./src/compat/colors.cts",
3232
"import": "./src/compat/colors.ts"
3333
},
34+
"./lib/util/flattenColorPalette": {
35+
"require": "./src/compat/flatten-color-palette.cts",
36+
"import": "./src/compat/flatten-color-palette.ts"
37+
},
3438
"./defaultTheme": {
3539
"require": "./src/compat/default-theme.cts",
3640
"import": "./src/compat/default-theme.ts"
@@ -91,6 +95,10 @@
9195
"require": "./dist/colors.js",
9296
"import": "./dist/colors.mjs"
9397
},
98+
"./lib/util/flattenColorPalette": {
99+
"require": "./dist/flatten-color-palette.js",
100+
"import": "./dist/flatten-color-palette.mjs"
101+
},
94102
"./package.json": "./package.json",
95103
"./index.css": "./index.css",
96104
"./index": "./index.css",

packages/tailwindcss/src/compat/config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, test, vi } from 'vitest'
22
import { compile, type Config } from '..'
33
import { default as plugin } from '../plugin'
4-
import { flattenColorPalette } from './flatten-color-palette'
4+
import flattenColorPalette from './flatten-color-palette'
55

66
const css = String.raw
77

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import flattenColorPalette from './flatten-color-palette.ts'
2+
3+
// This file exists so that `flatten-color-palette.ts` can be written one time
4+
// but be compatible with both CJS and ESM. Without it we get a `.default`
5+
// export when using `require` in CJS.
6+
7+
// @ts-ignore
8+
export = flattenColorPalette

packages/tailwindcss/src/compat/flatten-color-palette.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from 'vitest'
2-
import { flattenColorPalette } from './flatten-color-palette'
2+
import flattenColorPalette from './flatten-color-palette'
33

44
test('it should handle private __CSS_VALUES__ to resolve to the right value', () => {
55
expect(

packages/tailwindcss/src/compat/flatten-color-palette.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type Colors = {
44
[key: string | number]: string | Colors
55
}
66

7-
export function flattenColorPalette(colors: Colors) {
7+
export default function flattenColorPalette(colors: Colors) {
88
let result: Record<string, string> = {}
99

1010
for (let [root, children] of Object.entries(colors ?? {})) {

packages/tailwindcss/tsup.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default defineConfig([
1010
plugin: 'src/plugin.ts',
1111
colors: 'src/compat/colors.ts',
1212
'default-theme': 'src/compat/default-theme.ts',
13+
'flatten-color-palette': 'src/compat/flatten-color-palette.ts',
1314
},
1415
},
1516
{
@@ -21,6 +22,7 @@ export default defineConfig([
2122
lib: 'src/index.cts',
2223
colors: 'src/compat/colors.cts',
2324
'default-theme': 'src/compat/default-theme.cts',
25+
'flatten-color-palette': 'src/compat/flatten-color-palette.cts',
2426
},
2527
},
2628
])

0 commit comments

Comments
 (0)