Skip to content

Detect and migrate static plugin usages #14648

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

Merged
merged 14 commits into from
Oct 14, 2024
Merged

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Oct 11, 2024

This PR builds on top of the new JS config to CSS migration 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:

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.

@philipp-spiess philipp-spiess changed the base branch from next to feat/migrate-js-config October 11, 2024 12:18
@philipp-spiess philipp-spiess force-pushed the feat/migrate-plugins branch 2 times, most recently from 19afa8f to ea0dc30 Compare October 11, 2024 13:14
@philipp-spiess philipp-spiess changed the title Feat/migrate plugins Detect and migrate static plugin usages Oct 11, 2024
@philipp-spiess philipp-spiess force-pushed the feat/migrate-plugins branch 2 times, most recently from dccb8a0 to dec4153 Compare October 11, 2024 13:21
Base automatically changed from feat/migrate-js-config to next October 11, 2024 13:27
@philipp-spiess philipp-spiess force-pushed the feat/migrate-plugins branch 2 times, most recently from 0ef9065 to 82c81ff Compare October 14, 2024 12:18
@philipp-spiess
Copy link
Member Author

(Purposely not adding a change log since it's still covered in the initial JS config => CSS change log entry)

@philipp-spiess philipp-spiess marked this pull request as ready for review October 14, 2024 13:53
switch (pluginDefinition.type) {
case 'identifier':
let source = imports[pluginDefinition.text]
if (!source || (source.export !== null && source.export !== '*')) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also be default

@philipp-spiess
Copy link
Member Author

philipp-spiess commented Oct 14, 2024

Will add support for this in a follow-up:

import typography from '@tailwindcss/typography'

plugins: [
  require('@tailwindcss/typography')({
      className: 'wysiwyg',
    }),
   typography({
      className: 'wysiwyg',
    })
]

@philipp-spiess philipp-spiess merged commit 468cb5e into next Oct 14, 2024
1 check passed
@philipp-spiess philipp-spiess deleted the feat/migrate-plugins branch October 14, 2024 15:45
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.

2 participants