11import path from 'node:path'
2- import postcss , { AtRule , type Plugin , Root } from 'postcss'
2+ import postcss , { AtRule , type Plugin } from 'postcss'
33import { normalizePath } from '../../../@tailwindcss-node/src/normalize-path'
44import type { JSConfigMigration } from '../migrate-js-config'
55import type { Stylesheet } from '../stylesheet'
@@ -13,7 +13,9 @@ export function migrateConfig(
1313 jsConfigMigration,
1414 } : { configFilePath : string ; jsConfigMigration : JSConfigMigration } ,
1515) : Plugin {
16- function injectInto ( sheet : Stylesheet ) {
16+ function migrate ( ) {
17+ if ( ! sheet . isTailwindRoot ) return
18+
1719 let alreadyInjected = ALREADY_INJECTED . get ( sheet )
1820 if ( alreadyInjected && alreadyInjected . includes ( configFilePath ) ) {
1921 return
@@ -82,41 +84,6 @@ export function migrateConfig(
8284 root . append ( cssConfig . nodes )
8385 }
8486
85- function migrate ( root : Root ) {
86- // We can only migrate if there is an `@import "tailwindcss"` (or sub-import)
87- let hasTailwindImport = false
88- let hasFullTailwindImport = false
89- root . walkAtRules ( 'import' , ( node ) => {
90- if ( node . params . match ( / [ ' " ] t a i l w i n d c s s [ ' " ] / ) ) {
91- hasTailwindImport = true
92- hasFullTailwindImport = true
93- return false
94- } else if ( node . params . match ( / [ ' " ] t a i l w i n d c s s \/ .* ?[ ' " ] / ) ) {
95- hasTailwindImport = true
96- }
97- } )
98-
99- if ( ! hasTailwindImport ) return
100-
101- // If a full `@import "tailwindcss"` is present or this is the root
102- // stylesheet, we can inject the `@config` directive directly into this
103- // file.
104- if ( hasFullTailwindImport || sheet . parents . size <= 0 ) {
105- injectInto ( sheet )
106- return
107- }
108-
109- // Otherwise, if we are not the root file, we need to inject the `@config`
110- // into the root file.
111- if ( sheet . parents . size > 0 ) {
112- for ( let parent of sheet . ancestors ( ) ) {
113- if ( parent . parents . size === 0 ) {
114- injectInto ( parent )
115- }
116- }
117- }
118- }
119-
12087 return {
12188 postcssPlugin : '@tailwindcss/upgrade/migrate-config' ,
12289 OnceExit : migrate ,
0 commit comments