diff --git a/packages/@tailwindcss-upgrade/src/migrate.ts b/packages/@tailwindcss-upgrade/src/migrate.ts index ca5eb6cc1..b1d5b5f13 100644 --- a/packages/@tailwindcss-upgrade/src/migrate.ts +++ b/packages/@tailwindcss-upgrade/src/migrate.ts @@ -125,6 +125,24 @@ export async function analyze(stylesheets: Stylesheet[]) { } } } + + // Step 3: Determine which config files are used by each stylesheet (if any) + for (let sheet of stylesheets) { + for (let node of sheet.configRules) { + let configPath = node.params.match(/['"](.*)['"]/)?.[1] + if (!configPath) continue + + sheet.configFiles.add(configPath) + } + } + + for (let sheet of stylesheets) { + for (let parent of sheet.ancestors) { + for (let file of parent.configFiles) { + sheet.configFiles.add(file) + } + } + } } export async function split(stylesheets: Stylesheet[]) { diff --git a/packages/@tailwindcss-upgrade/src/stylesheet.ts b/packages/@tailwindcss-upgrade/src/stylesheet.ts index 7f3d2af10..ce9833018 100644 --- a/packages/@tailwindcss-upgrade/src/stylesheet.ts +++ b/packages/@tailwindcss-upgrade/src/stylesheet.ts @@ -40,6 +40,11 @@ export class Stylesheet { */ layers = new Set() + /** + * The list of config files that this stylesheet uses + */ + configFiles = new Set() + static async load(filepath: string) { filepath = path.resolve(process.cwd(), filepath) @@ -75,6 +80,16 @@ export class Stylesheet { return imports } + get configRules() { + let rules = new Set() + + this.root.walkAtRules('config', (rule) => { + rules.add(rule) + }) + + return rules + } + get isEmpty() { return this.root.toString().trim() === '' }