-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
content rules from the JS config that are also covered by the automatic source detection should not be migrated to CSS
#14714
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
content rules from the JS config that are also covered by the autom…
…atic source detection should not be migrated to CSS
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| import { Scanner } from '@tailwindcss/oxide' | ||||||||||||||||||||||||||||||||||||||||||||||
| import fs from 'node:fs/promises' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { dirname } from 'path' | ||||||||||||||||||||||||||||||||||||||||||||||
| import type { Config } from 'tailwindcss' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { type Config } from 'tailwindcss' | ||||||||||||||||||||||||||||||||||||||||||||||
| import defaultTheme from 'tailwindcss/defaultTheme' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { fileURLToPath } from 'url' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { loadModule } from '../../@tailwindcss-node/src/compile' | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -15,7 +16,7 @@ import type { ThemeConfig } from '../../tailwindcss/src/compat/config/types' | |||||||||||||||||||||||||||||||||||||||||||||
| import { darkModePlugin } from '../../tailwindcss/src/compat/dark-mode' | ||||||||||||||||||||||||||||||||||||||||||||||
| import type { DesignSystem } from '../../tailwindcss/src/design-system' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { findStaticPlugins, type StaticPluginOptions } from './utils/extract-static-plugins' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { info } from './utils/renderer' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { info, warn } from './utils/renderer' | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const __filename = fileURLToPath(import.meta.url) | ||||||||||||||||||||||||||||||||||||||||||||||
| const __dirname = dirname(__filename) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -54,7 +55,7 @@ export async function migrateJsConfig( | |||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if ('content' in unresolvedConfig) { | ||||||||||||||||||||||||||||||||||||||||||||||
| sources = migrateContent(unresolvedConfig as any, base) | ||||||||||||||||||||||||||||||||||||||||||||||
| sources = await migrateContent(unresolvedConfig as any, base) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if ('theme' in unresolvedConfig) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -158,16 +159,35 @@ function createSectionKey(key: string[]): string { | |||||||||||||||||||||||||||||||||||||||||||||
| return sectionSegments.join('-') | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| function migrateContent( | ||||||||||||||||||||||||||||||||||||||||||||||
| async function migrateContent( | ||||||||||||||||||||||||||||||||||||||||||||||
| unresolvedConfig: Config & { content: any }, | ||||||||||||||||||||||||||||||||||||||||||||||
| base: string, | ||||||||||||||||||||||||||||||||||||||||||||||
| ): { base: string; pattern: string }[] { | ||||||||||||||||||||||||||||||||||||||||||||||
| ): Promise<{ base: string; pattern: string }[]> { | ||||||||||||||||||||||||||||||||||||||||||||||
| let autoContentFiles = listAutoContentFiles(base) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| let sources = [] | ||||||||||||||||||||||||||||||||||||||||||||||
| for (let content of unresolvedConfig.content) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (typeof content !== 'string') { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error('Unsupported content value: ' + content) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| sources.push({ base, pattern: content }) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| let sourceFiles = listSourceContentFiles({ base, pattern: content }) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| let autoContentContainsAllSourceFiles = true | ||||||||||||||||||||||||||||||||||||||||||||||
| for (let sourceFile of sourceFiles) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!autoContentFiles.includes(sourceFile)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| autoContentContainsAllSourceFiles = false | ||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (autoContentContainsAllSourceFiles) { | ||||||||||||||||||||||||||||||||||||||||||||||
| warn( | ||||||||||||||||||||||||||||||||||||||||||||||
| 'The `content` configuration `${content}` is already included in the automatic content file discovery and will not be migrated.', | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
philipp-spiess marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| sources.push({ base, pattern: content }) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return sources | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -253,3 +273,15 @@ function keyframesToCss(keyframes: Record<string, unknown>): string { | |||||||||||||||||||||||||||||||||||||||||||||
| let ast: AstNode[] = keyframesToRules({ theme: { keyframes } }) | ||||||||||||||||||||||||||||||||||||||||||||||
| return toCss(ast).trim() + '\n' | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| 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 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 | |
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.