From a89c5f36850cb12b435fcf7e82df3435a5ad94ef Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Tue, 27 Aug 2024 10:22:36 -0400 Subject: [PATCH] fix(class-name-updater): ignore css vars when running in v6 mode --- .../class-name-updater/src/classNameUpdate.ts | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/class-name-updater/src/classNameUpdate.ts b/packages/class-name-updater/src/classNameUpdate.ts index 957f79026..01ee76bbf 100644 --- a/packages/class-name-updater/src/classNameUpdate.ts +++ b/packages/class-name-updater/src/classNameUpdate.ts @@ -1,20 +1,33 @@ import { sync } from "glob"; -import { readFileSync, writeFileSync} from "fs"; +import { readFileSync, writeFileSync } from "fs"; import { join } from "path"; import { isDir } from "./utils"; import { printDiff } from "./printDiff"; -export async function classNameUpdate(globTarget: string, makeChange: boolean, fileTypesRegex: RegExp, excludeFiles: string[] = [], pfVersion: number) { - const acceptedFileTypesRegex = fileTypesRegex || /\.(s?css|less|(t|j)sx?|md)$/; - const previousVersion = pfVersion ? "-v" + (pfVersion - 1) : ""; +export async function classNameUpdate( + globTarget: string, + makeChange: boolean, + fileTypesRegex: RegExp, + excludeFiles: string[] = [], + pfVersion: number +) { + const acceptedFileTypesRegex = + fileTypesRegex || /\.(s?css|less|(t|j)sx?|md)$/; + const isPostV5 = pfVersion > 5; + const previousVersion = isPostV5 ? "-v" + (pfVersion - 1) : ""; + const classNameMatches = "[cul]"; + const cssVarMatches = `${classNameMatches}|global|theme|color`; + const bodyMatches = isPostV5 ? classNameMatches : cssVarMatches; const changeNeededRegex = new RegExp( - "(\\b|\\$)pf" + previousVersion + "-([cul]|global|theme|color)-", + "(\\b|\\$)pf" + previousVersion + `-(${bodyMatches})-`, "g" ); - const newVersion = pfVersion || 5 + const newVersion = pfVersion || 5; const files = sync(globTarget, { ignore: "**/node_modules/**" }); - const includedFiles = files.filter((filePath: string) => !excludeFiles.includes(filePath)) + const includedFiles = files.filter( + (filePath: string) => !excludeFiles.includes(filePath) + ); includedFiles.forEach(async (file: string) => { const filePath = join(process.cwd(), file);