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

Support the color property in JS theme configuration callbacks #14651

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

philipp-spiess
Copy link
Member

While working on some fixes for #14639 I noticed that the following v3 configuration file would not load properly in v4:

import { type Config } from 'tailwindcss'

export default {
  content: ['./src/**/*.{js,jsx,ts,tsx}'],
  theme: {
    extend: {
      colors: ({ colors }) => ({
        gray: colors.neutral,
      }),
  },
} satisfies Config

The reason for this is that we did not pass the colors property to the callback function. Since we have colors available now, we can easily add it.

@philipp-spiess philipp-spiess force-pushed the fix/resolve-js-theme-with-colors branch from 5d70c19 to 3cd6c6b Compare October 11, 2024 15:10
CHANGELOG.md Outdated Show resolved Hide resolved
@philipp-spiess philipp-spiess merged commit c009c9c into next Oct 11, 2024
1 check passed
@philipp-spiess philipp-spiess deleted the fix/resolve-js-theme-with-colors branch October 11, 2024 16:08
philipp-spiess added a commit that referenced this pull request Oct 14, 2024
This PR builds on top of the new [JS config to CSS
migration](#14651) and
extends it to support migrating _static_ plugins.

What are _static_ plugins you might ask? Static plugins are plugins
where we can statically determine that these are coming from a different
file (so there is nothing inside the JS config that creates them). An
example for this is this config file:

```js
import typographyPlugin from '@tailwindcss/typography'
import { type Config } from 'tailwindcss'

export default {
  content: ['./src/**/*.{js,jsx,ts,tsx}'],
  darkMode: 'selector',
  plugins: [typographyPlugin],
} satisfies Config
```

Here, the `plugins` array only has one element and it is a static import
from the `@tailwindcss/typography` module. In this PR we attempt to
parse the config file via Tree-sitter to extract the following
information from this file:

- What are the contents of the `plugins` array
- What are statically imported resources from the file

We then check if _all_ entries in the `plugins` array are either static
resources or _strings_ (something I saw working in some tests but I’m
not sure it still does). We migrate the JS config file to CSS if all
plugins are static and we can migrate them to CSS `@plugin` calls.

## Todo

This will need to be rebased after the updated tests in #14648
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants