Skip to content

Commit

Permalink
fix: postcss and emit failures in CI (#1577)
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo authored Oct 25, 2023
1 parent a76b279 commit 56299cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .changeset/beige-geese-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@pandacss/postcss': patch
'@pandacss/node': patch
---

Fix persistent error that causes CI builds to fail due to PostCSS plugin emitting artifacts in the middle of a build
process.
30 changes: 17 additions & 13 deletions packages/node/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const contentFilesCache = new WeakMap<PandaContext, ContentData>()

const limit = pLimit(20)

let setupCount = 0

export class Builder {
/**
* The current panda context
*/
context: PandaContext | undefined

hasEmitted = false

configDependencies: Set<string> = new Set()

writeFileCss = (file: string, css: string) => {
Expand Down Expand Up @@ -75,10 +75,6 @@ export class Builder {
delete require.cache[file]
}

if (setupCount > 0) {
logger.debug('builder', '⚙️ Config changed, reloading')
}

return { isModified: true, modifiedMap: newModified }
}

Expand All @@ -92,6 +88,8 @@ export class Builder {
return configPath
}

hasConfigChanged = false

setup = async (options: { configPath?: string; cwd?: string } = {}) => {
logger.debug('builder', '🚧 Setup')

Expand All @@ -106,13 +104,17 @@ export class Builder {
this.configDependencies = configDeps

const deps = this.checkConfigDeps(configPath, configDeps)
this.hasConfigChanged = deps.isModified

if (deps.isModified) {
await this.setupContext({
configPath,
depsModifiedMap: deps.modifiedMap,
})
const ctx = this.context!

const ctx = this.getContextOrThrow()

logger.debug('builder', '⚙️ Config changed, reloading')
await ctx.hooks.callHook('config:change', ctx.config)
}

Expand All @@ -129,20 +131,22 @@ export class Builder {
depsModifiedMap: deps.modifiedMap,
})
}
}

setupCount++
emit() {
// ensure emit is only called when the config is changed
if (this.hasEmitted && this.hasConfigChanged) {
emitArtifacts(this.getContextOrThrow())
}

this.hasEmitted = true
}

setupContext = async (options: { configPath: string; depsModifiedMap: Map<string, number> }) => {
const { configPath, depsModifiedMap } = options

this.context = await loadConfigAndCreateContext({ configPath })

// don't emit artifacts on first setup
if (setupCount > 0) {
emitArtifacts(this.context) // no need to await this
}

configCache.set(configPath, {
context: this.context,
deps: new Set(this.context.dependencies ?? []),
Expand Down
2 changes: 2 additions & 0 deletions packages/postcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const pandacss: PluginCreator<{ configPath?: string; cwd?: string }> = (o
return
}

builder.emit()

await builder.extract()

builder.registerDependency((dep) => {
Expand Down

3 comments on commit 56299cb

@vercel
Copy link

@vercel vercel bot commented on 56299cb Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 56299cb Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

panda-docs – ./website

panda-docs.vercel.app
panda-docs-git-main-chakra-ui.vercel.app
panda-docs-chakra-ui.vercel.app
panda-css.com

@vercel
Copy link

@vercel vercel bot commented on 56299cb Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

panda-studio – ./

panda-app.vercel.app
panda-studio-git-main-chakra-ui.vercel.app
panda-studio-chakra-ui.vercel.app

Please sign in to comment.