Skip to content

Commit

Permalink
fix: avoid codegen when configuration changes (#81)
Browse files Browse the repository at this point in the history
* fix: avoid codegen when configuration changes

* fixup!

remove some things that I added to reproduce/test
  • Loading branch information
literalpie authored Mar 1, 2025
1 parent 0aaf41e commit 9dd8957
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 11 additions & 4 deletions packages/unplugin/src/plugin/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ export interface PandaPluginOptions extends Partial<PandaPluginHooks>, Pick<Tran
* Generate a styled-system folder on server start.
*
* @default true
* @deprecated Use 'codegen' instead
*/
codeGen?: boolean
/**
* Generate a styled-system folder on server start.
*
* @default true
*/
codegen?: boolean
}

interface SourceFileHookArgs {
Expand Down Expand Up @@ -115,7 +122,7 @@ export const unpluginFactory: UnpluginFactory<PandaPluginOptions | undefined> =
// @ts-expect-error
initPromise = loadConfig({ cwd: options.cwd, file: options.configPath }).then(async (conf: LoadConfigResult) => {
conf.config.cwd = options.cwd
_ctx = createContext({ root: options.cwd, conf })
_ctx = createContext({ root: options.cwd, conf, codegen: options.codegen })
if (options.contextCreated) {
await options.contextCreated({ context: _ctx.panda })
}
Expand Down Expand Up @@ -251,7 +258,7 @@ export const unpluginFactory: UnpluginFactory<PandaPluginOptions | undefined> =
}

// (re) generate the `styled-system` (outdir) on server (re)start
if (options.codeGen) {
if (options.codegen) {
const { msg } = await codegen(ctx.panda)
}
// console.log(options)
Expand Down Expand Up @@ -303,7 +310,7 @@ export const unpluginFactory: UnpluginFactory<PandaPluginOptions | undefined> =
}
}

const resolveOptions = (options: PandaPluginOptions): RequiredBy<PandaPluginOptions, 'cwd'> => {
const resolveOptions = (options: PandaPluginOptions): RequiredBy<PandaPluginOptions, 'cwd'|'codegen'> => {
let optimizeJs = options.optimizeJs ?? 'auto'
if (typeof optimizeJs === 'object') {
optimizeJs = {
Expand All @@ -326,6 +333,6 @@ const resolveOptions = (options: PandaPluginOptions): RequiredBy<PandaPluginOpti
optimizeCss: options.optimizeCss ?? true,
minifyCss: options.minifyCss ?? false,
optimizeJs: options.optimizeJs ?? 'macro',
codeGen: options.codeGen ?? true,
codegen: options.codegen ?? options.codeGen ?? true,
}
}
5 changes: 4 additions & 1 deletion packages/unplugin/src/plugin/create-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ensureAbsolute } from './ensure-absolute'
export interface ContextOptions {
root: string
conf: LoadConfigResult
codegen?: boolean
}

export const createContext = (options: ContextOptions) => {
Expand Down Expand Up @@ -61,7 +62,9 @@ export const createContext = (options: ContextOptions) => {

// logger.info('ctx:updated', 'config rebuilt ✅')
await panda.hooks['config:change']?.({ config: panda.config, changes: affecteds })
await codegen(panda, Array.from(affecteds.artifacts))
if(options.codegen) {
await codegen(panda, Array.from(affecteds.artifacts))
}

return panda
},
Expand Down

0 comments on commit 9dd8957

Please sign in to comment.