Skip to content

Conversation

@philipp-spiess
Copy link
Member

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

This PR changes the migration of content rules in the JS config to CSS codemods.

When a content rule is processed which matches files that are also matched by the automatic content discovery in v4, we do not need to emit CSS for that rule.

Take, for example this v3 configuration file:

import { type Config } from 'tailwindcss'

module.exports = {
  content: [
    './src/**/*.{html,js}', 
    './node_modules/my-external-lib/**/*.{html}'
  ],
} satisfies Config

Provided the base directories match up, the first rule will also be covered by the automatic content discovery in v4 and thus we only need to convert the second rule to CSS:

@import "tailwindcss";
@source '../node_modules/my-external-lib/**/*.{html}';

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @philipp-spiess and the rest of your teammates on Graphite Graphite

@philipp-spiess philipp-spiess marked this pull request as ready for review October 18, 2024 11:02
@philipp-spiess philipp-spiess requested a review from a team as a code owner October 18, 2024 11:02
@philipp-spiess
Copy link
Member Author

Yo what is this branch name, let me see if I can truncate this in Graphite 🙈

@philipp-spiess philipp-spiess force-pushed the 10-18-_content_rules_from_the_js_config_that_are_also_covered_by_the_automatic_source_detection_should_not_be_migrated_to_css branch from 49a0983 to 5c25f28 Compare October 18, 2024 11:06
Comment on lines 185 to 187
warn(
'The `content` configuration `${content}` is already included in the automatic content file discovery and will not be migrated.',
)
Copy link
Member

Choose a reason for hiding this comment

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

Actually seeing this I think I'd rather just not log anything, it almost reads like the upgrade couldn't be completed and I'm not sure how to say it more clearly without it being too verbose.

Copy link
Member Author

Choose a reason for hiding this comment

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

@adamwathan Yeah I think this makes sense.

Comment on lines 277 to 283
function listAutoContentFiles(base: string) {
let scanner = new Scanner({ detectSources: { base } })
scanner.scan()
return scanner.files
}

function listSourceContentFiles(source: { base: string; pattern: string }): string[] {
let scanner = new Scanner({ sources: [source] })
scanner.scan()
return scanner.files
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we avoid the word "content" for code that's just looking at the modern stuff?

Are these names clear enough?

Suggested change
function listAutoContentFiles(base: string) {
let scanner = new Scanner({ detectSources: { base } })
scanner.scan()
return scanner.files
}
function listSourceContentFiles(source: { base: string; pattern: string }): string[] {
let scanner = new Scanner({ sources: [source] })
scanner.scan()
return scanner.files
}
function autodetectedSourceFiles(base: string) {
let scanner = new Scanner({ detectSources: { base } })
scanner.scan()
return scanner.files
}
function patternSourceFiles(source: { base: string; pattern: string }): string[] {
let scanner = new Scanner({ sources: [source] })
scanner.scan()
return scanner.files
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good. I went with content in the first iteration since we are looking at the content array and this is the content field migration, but yeah in terms of v4, the term content does not really exists.

@philipp-spiess philipp-spiess force-pushed the 10-18-_content_rules_from_the_js_config_that_are_also_covered_by_the_automatic_source_detection_should_not_be_migrated_to_css branch from c54fc93 to eb7a747 Compare October 18, 2024 13:35
@philipp-spiess philipp-spiess force-pushed the 10-18-_content_rules_from_the_js_config_that_are_also_covered_by_the_automatic_source_detection_should_not_be_migrated_to_css branch from eb7a747 to c0de36d Compare October 18, 2024 13:37
@philipp-spiess philipp-spiess merged commit 5c1bfd3 into next Oct 18, 2024
@philipp-spiess philipp-spiess deleted the 10-18-_content_rules_from_the_js_config_that_are_also_covered_by_the_automatic_source_detection_should_not_be_migrated_to_css branch October 18, 2024 13:48
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.

3 participants