Skip to content

Commit 39b191a

Browse files
committed
perf(worker): fix the tests
1 parent 77f613f commit 39b191a

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

fixture/src/create-context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PandaContext } from '@pandacss/node'
44
import { stringifyJson, parseJson } from '@pandacss/shared'
55
import type { Config, LoadConfigResult, UserConfig } from '@pandacss/types'
66
import { fixturePreset } from './config'
7+
export { default as v9Config } from '../../sandbox/v9/panda.config'
78
import v9Config from '../../sandbox/v9/panda.config'
89

910
const config: UserConfig = {
@@ -28,7 +29,7 @@ export const fixtureDefaults = {
2829

2930
export const createGeneratorContext = (userConfig?: Config) => {
3031
const resolvedConfig = (
31-
userConfig ? mergeConfigs([userConfig, fixtureDefaults.config]) : fixtureDefaults.config
32+
userConfig ? mergeConfigs([fixtureDefaults.config, userConfig]) : fixtureDefaults.config
3233
) as UserConfig
3334

3435
return new Generator({ ...fixtureDefaults, config: resolvedConfig })

fixture/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './config'
22
export * from './create-context'
3+
export { v9Config } from './create-context'
34
export * from './layers'
45
export * from './recipes'
56
export * from './semantic-tokens'

plugin/src/utils/worker.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Generator } from '@pandacss/generator'
22
import { runAsWorker } from 'synckit'
3-
import { createContext } from 'fixture'
3+
import { createGeneratorContext, v9Config } from 'fixture'
44
import { resolveTsPathPattern } from '@pandacss/config/ts-path'
55
import { findConfig, loadConfig } from '@pandacss/config'
66
import path from 'path'
@@ -26,26 +26,31 @@ async function _getContext(configPath: string | undefined) {
2626

2727
export 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

4750
async 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

5156
export type DeprecatedToken =
@@ -80,8 +85,7 @@ async function isColorAttribute(ctx: Generator, _attr: string): Promise<boolean>
8085

8186
async 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[]
9599
async 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

107114
async 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
}
128136
async 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

136145
export function runAsync(action: 'filterInvalidTokens', opts: Opts, paths: string[]): Promise<string[]>

0 commit comments

Comments
 (0)