11import { Generator } from '@pandacss/generator'
22import { runAsWorker } from 'synckit'
3- import { createContext } from 'fixture'
3+ import { createGeneratorContext , v9Config } from 'fixture'
44import { resolveTsPathPattern } from '@pandacss/config/ts-path'
55import { findConfig , loadConfig } from '@pandacss/config'
66import path from 'path'
@@ -26,26 +26,31 @@ async function _getContext(configPath: string | undefined) {
2626
2727export async function getContext ( opts : Opts ) {
2828 if ( process . env . NODE_ENV === 'test' ) {
29- const ctx = createContext ( ) as unknown as Generator
30-
31- // Store cwd on the context for use in isValidFile
32- // @ts -expect-error - adding custom property
33- ctx . _cwd = cwd
29+ const ctx = createGeneratorContext ( {
30+ ...v9Config ,
31+ include : [ '**/*' ] ,
32+ exclude : [ '**/Invalid.tsx' , '**/panda.config.ts' ] ,
33+ importMap : './panda' ,
34+ jsxFactory : 'styled' ,
35+ } )
3436 return ctx
3537 } else {
3638 const configPath = findConfig ( { cwd : opts . configPath ?? opts . currentFile } )
39+ const cwd = path . dirname ( configPath )
3740
3841 // The context cache ensures we don't reload the same config multiple times
3942 if ( ! contextCache [ configPath ] ) {
4043 contextCache [ configPath ] = _getContext ( configPath )
4144 }
4245
43- return await contextCache [ configPath ]
46+ return contextCache [ configPath ]
4447 }
4548}
4649
4750async function filterInvalidTokens ( ctx : Generator , paths : string [ ] ) : Promise < string [ ] > {
48- return paths . filter ( ( path ) => ! ctx . utility . tokens . view . get ( path ) )
51+ const invalid = paths . filter ( ( path ) => ! ctx . utility . tokens . view . get ( path ) )
52+ console . error ( 'filterInvalidTokens' , { paths, invalid } )
53+ return invalid
4954}
5055
5156export type DeprecatedToken =
@@ -80,8 +85,7 @@ async function isColorAttribute(ctx: Generator, _attr: string): Promise<boolean>
8085
8186async function isValidFile ( ctx : Generator , fileName : string ) : Promise < boolean > {
8287 const { include, exclude } = ctx . config
83- // @ts -expect-error - using custom property
84- const cwd = ctx . _cwd || ctx . config . cwd || process . cwd ( )
88+ const cwd = ctx . config . cwd || process . cwd ( )
8589
8690 const relativePath = path . isAbsolute ( fileName ) ? path . relative ( cwd , fileName ) : fileName
8791
@@ -95,17 +99,21 @@ async function resolveShorthands(ctx: Generator, name: string): Promise<string[]
9599async function resolveLongHand ( ctx : Generator , name : string ) : Promise < string | undefined > {
96100 const reverseShorthandsMap = new Map ( )
97101
98- for ( const [ key , values ] of ctx . utility . getPropShorthandsMap ( ) ) {
102+ const shorthands = ctx . utility . getPropShorthandsMap ( )
103+
104+ for ( const [ key , values ] of shorthands ) {
99105 for ( const value of values ) {
100106 reverseShorthandsMap . set ( value , key )
101107 }
102108 }
103109
104- return reverseShorthandsMap . get ( name )
110+ const result = reverseShorthandsMap . get ( name )
111+ return result
105112}
106113
107114async function isValidProperty ( ctx : Generator , name : string , patternName ?: string ) {
108- if ( ctx . isValidProperty ( name ) ) return true
115+ const isValid = ctx . isValidProperty ( name )
116+ if ( isValid ) return true
109117 if ( ! patternName ) return
110118
111119 const pattern = ctx . patterns . details . find ( ( p ) => p . baseName === patternName || p . jsx . includes ( patternName ) ) ?. config
@@ -126,11 +134,12 @@ type MatchImportResult = {
126134 mod : string
127135}
128136async function matchImports ( ctx : Generator , result : MatchImportResult ) {
129- return ctx . imports . match ( result , ( mod ) => {
137+ const isMatch = ctx . imports . match ( result , ( mod ) => {
130138 const { tsOptions } = ctx . parserOptions
131139 if ( ! tsOptions ?. pathMappings ) return
132140 return resolveTsPathPattern ( tsOptions . pathMappings , mod )
133141 } )
142+ return isMatch
134143}
135144
136145export function runAsync ( action : 'filterInvalidTokens' , opts : Opts , paths : string [ ] ) : Promise < string [ ] >
0 commit comments