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

Add initial codemod tooling #14432

Closed
wants to merge 5 commits into from
Closed

Add initial codemod tooling #14432

wants to merge 5 commits into from

Conversation

RobinMalfait
Copy link
Member

This PR adds some initial tooling for codemods. We are currently only interested
in migrating CSS files, so we will be using PostCSS under the hood to do this.
This PR also implements the "migrate @apply" codemod from #14412.

The usage will look like this:

npx @tailwindcss/codemods

You can pass in CSS files to transform as arguments:

npx @tailwindcss/codemods src/**/*.css

But, if none are provided, it will search for CSS files in the current directory and its subdirectories.

≈ tailwindcss v4.0.0-alpha.24

│ No files provided. Searching for CSS files in the current
│ directory and its subdirectories…

│ Migration complete. Verify the changes and commit them to
│ your repository.

The tooling also requires the Git repository to be in a clean state. This is a common convention to ensure that everything is undo-able. If we detect that the git repository is dirty, we will abort the migration.

≈ tailwindcss v4.0.0-alpha.24

│ Git directory is not clean. Please stash or commit your
│ changes before migrating.

│ You may use the `--force` flag to override this safety
│ check.

+ add codemod for migrating `@apply`
Copied some utils from `@tailwindcss/cli`. Initially referenced them,
but we also rely on some dependencies that we have to install.

One solution is to move it to an internal package and import it so that
tsup can inline everything. This also has the same 'we need the correct
dependencies' problem.

Another solution is to create a proper `@tailwindcss/cli-utils` (or
similar) package that we can import as a dependency. However, this one
will require us to actually publish the package, and give it a proper
name.
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.

1 participant