From 8eeaeda7457a9c4a2321c4d15a7568b827ead13a Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Fri, 6 Dec 2024 11:40:08 +0100 Subject: [PATCH 1/2] Expose flattenColorPalette --- CHANGELOG.md | 4 +++- packages/tailwindcss/package.json | 8 ++++++++ packages/tailwindcss/src/compat/config.test.ts | 2 +- packages/tailwindcss/src/compat/flatten-color-palette.cts | 8 ++++++++ .../tailwindcss/src/compat/flatten-color-palette.test.ts | 2 +- packages/tailwindcss/src/compat/flatten-color-palette.ts | 2 +- packages/tailwindcss/tsup.config.ts | 2 ++ 7 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 packages/tailwindcss/src/compat/flatten-color-palette.cts diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e7e13bff111..deca9e349bd7 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! +### Added + +- Add support for `tailwindcss/lib/util/flattenColorPalette` exports ([#15318](https://github.com/tailwindlabs/tailwindcss/pull/15318)) ## [4.0.0-beta.5] - 2024-12-04 diff --git a/packages/tailwindcss/package.json b/packages/tailwindcss/package.json index d2ba056c0afa..edb9deb90810 100644 --- a/packages/tailwindcss/package.json +++ b/packages/tailwindcss/package.json @@ -31,6 +31,10 @@ "require": "./src/compat/colors.cts", "import": "./src/compat/colors.ts" }, + "./lib/util/flattenColorPalette": { + "require": "./src/compat/flatten-color-palette.cts", + "import": "./src/compat/flatten-color-palette.ts" + }, "./defaultTheme": { "require": "./src/compat/default-theme.cts", "import": "./src/compat/default-theme.ts" @@ -91,6 +95,10 @@ "require": "./dist/colors.js", "import": "./dist/colors.mjs" }, + "./lib/util/flattenColorPalette": { + "require": "./dist/flattenColorPalette.js", + "import": "./dist/flattenColorPalette.mjs" + }, "./package.json": "./package.json", "./index.css": "./index.css", "./index": "./index.css", diff --git a/packages/tailwindcss/src/compat/config.test.ts b/packages/tailwindcss/src/compat/config.test.ts index b99bc405bc75..3747f8ae4f5d 100644 --- a/packages/tailwindcss/src/compat/config.test.ts +++ b/packages/tailwindcss/src/compat/config.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test, vi } from 'vitest' import { compile, type Config } from '..' import { default as plugin } from '../plugin' -import { flattenColorPalette } from './flatten-color-palette' +import flattenColorPalette from './flatten-color-palette' const css = String.raw diff --git a/packages/tailwindcss/src/compat/flatten-color-palette.cts b/packages/tailwindcss/src/compat/flatten-color-palette.cts new file mode 100644 index 000000000000..498308f8d7b6 --- /dev/null +++ b/packages/tailwindcss/src/compat/flatten-color-palette.cts @@ -0,0 +1,8 @@ +import flattenColorTheme from './flatten-color-palette.ts' + +// This file exists so that `default-theme.ts` can be written one time but be +// compatible with both CJS and ESM. Without it we get a `.default` export when +// using `require` in CJS. + +// @ts-ignore +export = flattenColorTheme diff --git a/packages/tailwindcss/src/compat/flatten-color-palette.test.ts b/packages/tailwindcss/src/compat/flatten-color-palette.test.ts index 3891bbece534..7ddda5bd461b 100644 --- a/packages/tailwindcss/src/compat/flatten-color-palette.test.ts +++ b/packages/tailwindcss/src/compat/flatten-color-palette.test.ts @@ -1,5 +1,5 @@ import { expect, test } from 'vitest' -import { flattenColorPalette } from './flatten-color-palette' +import flattenColorPalette from './flatten-color-palette' test('it should handle private __CSS_VALUES__ to resolve to the right value', () => { expect( diff --git a/packages/tailwindcss/src/compat/flatten-color-palette.ts b/packages/tailwindcss/src/compat/flatten-color-palette.ts index 03191e2da7e6..ca8845688508 100644 --- a/packages/tailwindcss/src/compat/flatten-color-palette.ts +++ b/packages/tailwindcss/src/compat/flatten-color-palette.ts @@ -4,7 +4,7 @@ type Colors = { [key: string | number]: string | Colors } -export function flattenColorPalette(colors: Colors) { +export default function flattenColorPalette(colors: Colors) { let result: Record = {} for (let [root, children] of Object.entries(colors ?? {})) { diff --git a/packages/tailwindcss/tsup.config.ts b/packages/tailwindcss/tsup.config.ts index 1a8e238873b8..f00e9e00430a 100644 --- a/packages/tailwindcss/tsup.config.ts +++ b/packages/tailwindcss/tsup.config.ts @@ -10,6 +10,7 @@ export default defineConfig([ plugin: 'src/plugin.ts', colors: 'src/compat/colors.ts', 'default-theme': 'src/compat/default-theme.ts', + flattenColorPalette: 'src/compat/flatten-color-palette.ts', }, }, { @@ -21,6 +22,7 @@ export default defineConfig([ lib: 'src/index.cts', colors: 'src/compat/colors.cts', 'default-theme': 'src/compat/default-theme.cts', + flattenColorPalette: 'src/compat/flatten-color-palette.cts', }, }, ]) From e7da88d5aef8873ad21d791d02c20bc51005baf4 Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Fri, 6 Dec 2024 11:40:08 +0100 Subject: [PATCH 2/2] Expose flattenColorPalette --- packages/tailwindcss/package.json | 4 ++-- .../tailwindcss/src/compat/flatten-color-palette.cts | 10 +++++----- packages/tailwindcss/tsup.config.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/tailwindcss/package.json b/packages/tailwindcss/package.json index edb9deb90810..56848a00151a 100644 --- a/packages/tailwindcss/package.json +++ b/packages/tailwindcss/package.json @@ -96,8 +96,8 @@ "import": "./dist/colors.mjs" }, "./lib/util/flattenColorPalette": { - "require": "./dist/flattenColorPalette.js", - "import": "./dist/flattenColorPalette.mjs" + "require": "./dist/flatten-color-palette.js", + "import": "./dist/flatten-color-palette.mjs" }, "./package.json": "./package.json", "./index.css": "./index.css", diff --git a/packages/tailwindcss/src/compat/flatten-color-palette.cts b/packages/tailwindcss/src/compat/flatten-color-palette.cts index 498308f8d7b6..d8b4be1442b4 100644 --- a/packages/tailwindcss/src/compat/flatten-color-palette.cts +++ b/packages/tailwindcss/src/compat/flatten-color-palette.cts @@ -1,8 +1,8 @@ -import flattenColorTheme from './flatten-color-palette.ts' +import flattenColorPalette from './flatten-color-palette.ts' -// This file exists so that `default-theme.ts` can be written one time but be -// compatible with both CJS and ESM. Without it we get a `.default` export when -// using `require` in CJS. +// This file exists so that `flatten-color-palette.ts` can be written one time +// but be compatible with both CJS and ESM. Without it we get a `.default` +// export when using `require` in CJS. // @ts-ignore -export = flattenColorTheme +export = flattenColorPalette diff --git a/packages/tailwindcss/tsup.config.ts b/packages/tailwindcss/tsup.config.ts index f00e9e00430a..59c8bdfa2906 100644 --- a/packages/tailwindcss/tsup.config.ts +++ b/packages/tailwindcss/tsup.config.ts @@ -10,7 +10,7 @@ export default defineConfig([ plugin: 'src/plugin.ts', colors: 'src/compat/colors.ts', 'default-theme': 'src/compat/default-theme.ts', - flattenColorPalette: 'src/compat/flatten-color-palette.ts', + 'flatten-color-palette': 'src/compat/flatten-color-palette.ts', }, }, { @@ -22,7 +22,7 @@ export default defineConfig([ lib: 'src/index.cts', colors: 'src/compat/colors.cts', 'default-theme': 'src/compat/default-theme.cts', - flattenColorPalette: 'src/compat/flatten-color-palette.cts', + 'flatten-color-palette': 'src/compat/flatten-color-palette.cts', }, }, ])