11import * as path from 'path' ;
22import * as fs from 'fs' ;
3- import * as ts from 'typescript' ;
3+ import ts from 'typescript' ;
4+ import fg from 'fast-glob' ;
45import { cleanUp } from './clean-up' ;
56import { createBuildIn } from '../../src/core/method/create-build-in-helper.js' ;
67import { setBuildIn } from '../../src/core/method/set-build-in-helper.js' ;
78import { globalBuildIn } from '../../src/core/method/global-build-in-helper.js' ;
89import { rootBuildIn } from '../../src/core/method/root-build-in-helper.js' ;
9- const fg = require ( 'fast-glob' ) ;
1010
11- function isStyleClass ( filePath : string ) : boolean {
11+ function isCSSX ( filePath : string ) : boolean {
1212 const content = fs . readFileSync ( filePath , 'utf8' ) ;
1313 const sourceFile = ts . createSourceFile ( filePath , content , ts . ScriptTarget . Latest , true ) ;
1414
@@ -32,22 +32,18 @@ function isStyleClass(filePath: string): boolean {
3232 return isUsed ;
3333}
3434
35- ( async ( ) => {
36- await cleanUp ( ) ;
37- let appRoot = '' ;
35+ async function getAppRoot ( ) : Promise < string > {
3836 const threeLevelsUp = path . join ( process . cwd ( ) , '../../../../..' ) ;
3937 const pnpmExists = fs . existsSync ( path . join ( threeLevelsUp , 'node_modules/.pnpm' ) ) ;
4038
41- if ( pnpmExists ) {
42- appRoot = path . join ( process . cwd ( ) , '../../../../../' ) ;
43- } else {
44- appRoot = path . join ( process . cwd ( ) , '../../' ) ;
45- }
46- const pattern = [ path . join ( appRoot , '**/*.{ts,tsx}' ) ] ;
47- const files = ( await fg ( pattern ) ) as string [ ] ;
48- const styleFiles = files . filter ( file => {
49- return isStyleClass ( file ) ;
50- } ) ;
39+ return pnpmExists ? path . join ( process . cwd ( ) , '../../../../../' ) : path . join ( process . cwd ( ) , '../../' ) ;
40+ }
41+
42+ ( async ( ) => {
43+ await cleanUp ( ) ;
44+ const appRoot = await getAppRoot ( ) ;
45+ const files = await fg ( [ path . join ( appRoot , '**/*.{ts,tsx}' ) ] ) ;
46+ const styleFiles = files . filter ( isCSSX ) ;
5147 console . log ( '\n💬 The following CSS caches were accepted:\n' ) ;
5248 for ( const file of styleFiles ) {
5349 const filePath = path . resolve ( file ) ;
0 commit comments