Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postcss: Bring back proper type exports #14256

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Bring back type exports for the cjs build of `@tailwindcss/postcss`. ([#14256](https://github.com/tailwindlabs/tailwindcss/pull/14256))

## [4.0.0-alpha.20] - 2024-08-23

Expand Down
7 changes: 7 additions & 0 deletions packages/@tailwindcss-postcss/src/index.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import tailwindcss from './index.ts'

// This is used instead of `export default` to work around a bug in
// `postcss-load-config`

// @ts-ignore
export = tailwindcss
5 changes: 2 additions & 3 deletions packages/@tailwindcss-postcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DefaultMap<T = string, V = any> extends Map<T, V> {
}
}

type PluginOptions = {
export type PluginOptions = {
// The base directory to scan for class candidates.
base?: string

Expand Down Expand Up @@ -209,5 +209,4 @@ function optimizeCss(
}).code.toString()
}

// This is used instead of `export default` to work around a bug in `postcss-load-config`
module.exports = Object.assign(tailwindcss, { postcss: true }) as PluginCreator<PluginOptions>
export default Object.assign(tailwindcss, { postcss: true }) as PluginCreator<PluginOptions>
27 changes: 18 additions & 9 deletions packages/@tailwindcss-postcss/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { defineConfig } from 'tsup'

export default defineConfig({
format: ['esm', 'cjs'],
clean: true,
minify: true,
cjsInterop: true,
dts: true,
entry: ['src/index.ts'],
noExternal: ['internal-postcss-fix-relative-paths'],
})
export default defineConfig([
{
format: ['esm'],
minify: true,
cjsInterop: true,
dts: true,
entry: ['src/index.ts'],
noExternal: ['internal-postcss-fix-relative-paths'],
},
{
format: ['cjs'],
minify: true,
cjsInterop: true,
dts: true,
entry: ['src/index.cts'],
noExternal: ['internal-postcss-fix-relative-paths'],
},
])
5 changes: 4 additions & 1 deletion packages/tailwindcss/src/compat/colors.cts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
module.exports = require('./colors.ts').default
import colors from './colors.ts'

// @ts-ignore
export = colors
5 changes: 4 additions & 1 deletion packages/tailwindcss/src/compat/default-theme.cts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
module.exports = require('./default-theme.ts').default
import defaultTheme from './default-theme.ts'

// @ts-ignore
export = defaultTheme
9 changes: 6 additions & 3 deletions packages/tailwindcss/src/plugin.cts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// This file exists so that `plugin.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.
import plugin from './plugin.ts'

// This file exists so that `plugin.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
module.exports = require('./plugin.ts').default
export = plugin
4 changes: 3 additions & 1 deletion playgrounds/nextjs/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import tailwindcss from '@tailwindcss/postcss'

module.exports = {
plugins: ['@tailwindcss/postcss'],
plugins: [tailwindcss()],
}