Skip to content

feat(esm): Support running Tailwind setup in ESM projects#350

Merged
Tobbe merged 1 commit into
mainfrom
tobbe-esm-prep-2
Aug 9, 2025
Merged

feat(esm): Support running Tailwind setup in ESM projects#350
Tobbe merged 1 commit into
mainfrom
tobbe-esm-prep-2

Conversation

@Tobbe
Copy link
Copy Markdown
Member

@Tobbe Tobbe commented Aug 9, 2025

The code comment explains this pretty well

// `tailwindcss init` will generate ESM syntax when it detects
// `"type": "module"` in package.json, even though the config
// file is .cjs. So we change it back to CJS syntax after it's
// been generated.

This is part of the ESM prep work started in #349

@netlify
Copy link
Copy Markdown

netlify Bot commented Aug 9, 2025

Deploy Preview for cedarjs canceled.

Name Link
🔨 Latest commit dfa5ee1
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/6897483cf71d140008998a28

@Tobbe Tobbe added this to the next-release milestone Aug 9, 2025
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR addresses a specific issue with TailwindCSS configuration generation in ESM projects within the Cedar framework. The change modifies the tailwindcssHandler.js file to fix a behavioral quirk where TailwindCSS's init command automatically generates ESM syntax (export default {) when it detects "type": "module" in a project's package.json, even when targeting a .cjs configuration file.

The solution implements a simple string replacement that converts the generated ESM export syntax back to CommonJS (module.exports = {) after the Tailwind config file is created. This ensures that Cedar's .cjs configuration files maintain proper CommonJS syntax regardless of whether the project is configured for ESM or CJS modules.

This change fits into Cedar's broader ESM preparation work (referenced as part of #349) and maintains the framework's consistent approach of using .cjs files for configuration that need to work across both module systems. The fix is surgical and targeted, only affecting the specific case where TailwindCSS generates incompatible syntax, while preserving all other functionality of the Tailwind setup process.

Confidence score: 5/5

  • This PR is safe to merge with minimal risk as it addresses a specific compatibility issue with a simple, well-documented fix
  • Score reflects the targeted nature of the change, clear problem identification, and proper solution that maintains backward compatibility
  • No files require special attention as the change is isolated to a single handler with clear purpose and scope

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@Tobbe Tobbe merged commit b199b37 into main Aug 9, 2025
50 of 52 checks passed
@Tobbe Tobbe deleted the tobbe-esm-prep-2 branch August 9, 2025 13:22
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