Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(artifacts): ArtifactMap #2646

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cb50740
wip
astahmer May 15, 2024
761bf6b
wip 2
astahmer May 15, 2024
7951222
wip3
astahmer May 23, 2024
2b28f0f
wip4
astahmer May 29, 2024
655b6e6
wip5
astahmer May 30, 2024
34669d6
wip6
astahmer Jun 1, 2024
d0ddb43
starting to look pretty good
astahmer Jun 1, 2024
cdef33c
refactor(generator): use ArtifactMap
astahmer Jun 2, 2024
6fc9c40
chore: rename file
astahmer Jun 2, 2024
5e6e687
fix: disable transitive imports generation for HMR & some file names
astahmer Jun 2, 2024
c4a14cd
chore: specific treatment for `types/global.d.ts`
astahmer Jun 3, 2024
a8ae01b
fix: imports -> importsType for dts artifacts
astahmer Jun 3, 2024
e18022d
fix: dir/fileName mistakes
astahmer Jun 3, 2024
e195863
chore(studio): run panda --clean
astahmer Jun 3, 2024
049f507
Merge remote-tracking branch 'origin/main' into refactor/artifact-graph
astahmer Jun 3, 2024
a5cf16f
chore: update snapshots after fixes & merge
astahmer Jun 3, 2024
70674eb
chore: lint
astahmer Jun 3, 2024
203d360
feat(node): cleanup removed artifacts
astahmer Jun 3, 2024
001715e
chore(artifacts/patterns): more specific dependency
astahmer Jun 3, 2024
08189fd
chore: snapshots & fix diff test
astahmer Jun 4, 2024
44d97e1
chore: split test to avoid timeout
astahmer Jun 4, 2024
2c661b3
fix: playground & studio
astahmer Jun 4, 2024
8296ad6
chore: fix minor stuff / add a bunch of TODOs
astahmer Jun 8, 2024
654c871
chore: cherry pick recipe default variant annotation
astahmer Jun 8, 2024
4d56d00
Merge remote-tracking branch 'origin/main' into refactor/artifact-graph
astahmer Jul 6, 2024
c089faa
chore: updates after merge
astahmer Jul 6, 2024
b77e9c1
Merge remote-tracking branch 'origin' into refactor/artifact-graph
astahmer Aug 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/cli/__tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ describe('CLI', () => {
// init on existing project
const output2 = execSync(cmd, { cwd: testsCwd }).toString()
expect(output2.includes('It looks like you already have panda created')).toBe(true)
})

test('init --force', async () => {
const cmd = `node ${binPath} init --cwd="${testsCwd}" --force`

// init with --force
const output3 = execSync(cmd + ' --force --postcss --logfile="./panda.log"', { cwd: testsCwd }).toString()
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/cli-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ export async function main() {
if (watch) {
ctx.watchConfig(
async () => {
const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
const changes = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
ctx = new PandaContext(conf)
})

await ctx.hooks['config:change']?.({ config: ctx.config, changes: affecteds })
await codegen(ctx, Array.from(affecteds.artifacts))
await ctx.hooks['config:change']?.({ config: ctx.config, changes })
await codegen(ctx, changes)
logger.info('ctx:updated', 'config rebuilt ✅')
},
{ cwd, poll },
Expand Down Expand Up @@ -234,11 +234,11 @@ export async function main() {
//
ctx.watchConfig(
async () => {
const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
const changes = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
ctx = new PandaContext(conf)
})

await ctx.hooks['config:change']?.({ config: ctx.config, changes: affecteds })
await ctx.hooks['config:change']?.({ config: ctx.config, changes })
await cssgen(ctx, options)
logger.info('ctx:updated', 'config rebuilt ✅')
},
Expand Down Expand Up @@ -470,11 +470,11 @@ export async function main() {
if (watch) {
ctx.watchConfig(
async () => {
const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
const changes = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
ctx = new PandaContext(conf)
})

await ctx.hooks['config:change']?.({ config: ctx.config, changes: affecteds })
await ctx.hooks['config:change']?.({ config: ctx.config, changes })
await buildInfo(ctx, outfile)
logger.info('ctx:updated', 'config rebuilt ✅')
},
Expand Down
80 changes: 37 additions & 43 deletions packages/config/__tests__/merge-hooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'vitest'
import { mergeHooks } from '../src/merge-hooks'
import type { Artifact } from '@pandacss/types'
import type { ArtifactFileId, GeneratedArtifact } from '@pandacss/types'

describe('mergeConfigs / theme', () => {
test('should merge hooks and call sequentially async', async () => {
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('mergeConfigs / theme', () => {

test('should merge hooks and call sequentially using previous result: codegen:prepare', async () => {
const order: number[] = []
let original: Artifact[]
let original: GeneratedArtifact[]
const hooks = mergeHooks([
{
name: 'panda-plugin',
Expand All @@ -101,7 +101,7 @@ describe('mergeConfigs / theme', () => {
original = args.original!

return args.artifacts.map((art) => {
return { ...art, files: art.files.map((f) => ({ ...f, code: (f.code || '').replace('aaa', 'xxx') })) }
return { ...art, content: (art.content || '').replace('aaa', 'xxx') }
})
},
},
Expand All @@ -116,36 +116,33 @@ describe('mergeConfigs / theme', () => {
expect(args.original).toMatchInlineSnapshot(`
[
{
"files": [
{
"code": "aaa aaa aaa",
"file": "aaa.js",
},
],
"content": "aaa aaa aaa",
"id": "recipes.1",
"path": [
"recipes",
"aaa.js",
],
},
{
"files": [
{
"code": "bbb bbb bbb",
"file": "bbb.js",
},
],
"content": "bbb bbb bbb",
"id": "recipes.2",
"path": [
"recipes",
"bbb.js",
],
},
{
"files": [
{
"code": "ccc ccc ccc",
"file": "ccc.js",
},
],
"content": "ccc ccc ccc",
"id": "recipes.3",
"path": [
"recipes",
"ccc.js",
],
},
]
`)
return args.artifacts.map((art) => {
return { ...art, files: art.files.map((f) => ({ ...f, code: (f.code || '').replace('bbb', 'zzz') })) }
return { ...art, content: (art.content || '').replace('bbb', 'zzz') }
})
},
},
Expand All @@ -155,9 +152,9 @@ describe('mergeConfigs / theme', () => {
const result = await hooks['codegen:prepare']?.({
changed: [],
artifacts: [
{ id: 'recipes.1', files: [{ code: 'aaa aaa aaa', file: 'aaa.js' }] },
{ id: 'recipes.2', files: [{ code: 'bbb bbb bbb', file: 'bbb.js' }] },
{ id: 'recipes.3', files: [{ code: 'ccc ccc ccc', file: 'ccc.js' }] },
{ id: 'recipes.1' as ArtifactFileId, path: ['recipes', 'aaa.js'], content: 'aaa aaa aaa' },
{ id: 'recipes.2' as ArtifactFileId, path: ['recipes', 'bbb.js'], content: 'bbb bbb bbb' },
{ id: 'recipes.3' as ArtifactFileId, path: ['recipes', 'ccc.js'], content: 'ccc ccc ccc' },
],
})

Expand All @@ -170,31 +167,28 @@ describe('mergeConfigs / theme', () => {
expect(result).toMatchInlineSnapshot(`
[
{
"files": [
{
"code": "xxx aaa aaa",
"file": "aaa.js",
},
],
"content": "xxx aaa aaa",
"id": "recipes.1",
"path": [
"recipes",
"aaa.js",
],
},
{
"files": [
{
"code": "zzz bbb bbb",
"file": "bbb.js",
},
],
"content": "zzz bbb bbb",
"id": "recipes.2",
"path": [
"recipes",
"bbb.js",
],
},
{
"files": [
{
"code": "ccc ccc ccc",
"file": "ccc.js",
},
],
"content": "ccc ccc ccc",
"id": "recipes.3",
"path": [
"recipes",
"ccc.js",
],
},
]
`)
Expand Down
79 changes: 0 additions & 79 deletions packages/config/src/config-deps.ts

This file was deleted.

44 changes: 8 additions & 36 deletions packages/config/src/diff-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { dashCase } from '@pandacss/shared'
import type { ArtifactId, Config, DiffConfigResult } from '@pandacss/types'
import type { Config, DiffConfigResult } from '@pandacss/types'
import microdiff from 'microdiff'
import { artifactMatchers } from './config-deps'

type ConfigOrFn = Config | (() => Config)

Expand All @@ -12,50 +10,24 @@ const runIfFn = (fn: ConfigOrFn): Config => (typeof fn === 'function' ? fn() : f
*/
export function diffConfigs(config: ConfigOrFn, prevConfig: Config | undefined): DiffConfigResult {
//
const affected: DiffConfigResult = {
artifacts: new Set(),
const result: DiffConfigResult = {
hasConfigChanged: false,
diffs: [],
}

if (!prevConfig) {
affected.hasConfigChanged = true
return affected
result.hasConfigChanged = true
return result
}

const configDiff = microdiff(prevConfig, runIfFn(config))

if (!configDiff.length) {
return affected
return result
}

affected.hasConfigChanged = true
affected.diffs = configDiff
result.hasConfigChanged = true
result.diffs = configDiff

configDiff.forEach((change) => {
const changePath = change.path.join('.')

artifactMatchers.forEach((matcher) => {
const id = matcher(changePath) as ArtifactId | undefined
if (!id) return

// add `recipes.xxx-yyy` to specify which recipes were affected, and later avoid rewriting all recipes
// same for recipes, use dashCase since those will be used as filenames
if (id === 'recipes') {
// ['theme', 'recipes', 'xxx'] => recipes.xxx
const name = dashCase(change.path.slice(1, 3).join('.')) as ArtifactId
affected.artifacts.add(name)
}

if (id === 'patterns') {
// ['patterns', 'xxx'] => patterns.xxx
const name = dashCase(change.path.slice(0, 2).join('.')) as ArtifactId
affected.artifacts.add(name)
}

affected.artifacts.add(id)
})
})

return affected
return result
}
1 change: 1 addition & 0 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const defaults = (config: UserConfig): UserConfig => ({
outExtension: 'mjs',
shorthands: true,
syntax: 'object-literal',
separator: '_',
...config,
layers: {
reset: 'reset',
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as messages from './messages'
export { Breakpoints } from './breakpoints'
export { Conditions } from './conditions'
export { Context } from './context'
export { FileEngine } from './file'
export { FileMatcher } from './file-matcher'
export type { ImportResult } from './file-matcher'
export { ImportMap } from './import-map'
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/patterns.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { capitalize, createRegex, dashCase, getPatternStyles, isObject, memo, uncapitalize } from '@pandacss/shared'
import type { TokenDictionary } from '@pandacss/token-dictionary'
import type { ArtifactFilters, Dict, PatternConfig, PatternHelpers, UserConfig } from '@pandacss/types'
import type { Dict, PatternConfig, PatternHelpers, UserConfig } from '@pandacss/types'
import type { Utility } from './utility'

interface PatternOptions {
Expand Down Expand Up @@ -104,11 +104,6 @@ export class Patterns {
}
}

filterDetails(filters?: ArtifactFilters) {
const patternDiffs = filters?.affecteds?.patterns
return patternDiffs ? this.details.filter((pattern) => patternDiffs.includes(pattern.dashName)) : this.details
}

getPropertyValues = (patternName: string, property: string) => {
const patternConfig = this.getConfig(patternName)
if (!patternConfig) return []
Expand Down
Loading
Loading