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(BREAKING): rm config.eject & automatic import of built-in pr… #2694

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions .changeset/tame-cooks-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
'@pandacss/config': minor
'@pandacss/types': minor
'@pandacss/node': minor
'@pandacss/dev': minor
---

- BREAKING: The built-in presets `@pandacss/preset-base` and `@pandacss/preset-panda` are no longer automatically
included, if you are not using `presets` or `eject` in your config you can add them manually as shown below:

```diff
// panda.config.ts
import { defineConfig } from '@pandacss/dev'

export default defineConfig({
+ presets: ['@pandacss/preset-base', '@pandacss/preset-panda'],
})
```

This allows you to control more explicitely which presets are included in your project.

- BREAKING: The `config.eject` option has been removed. Simply remove it from your config and the result will be the
same.

```diff
// panda.config.ts
import { defineConfig } from '@pandacss/dev'

export default defineConfig({
- eject: true,
})
```
7 changes: 6 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,18 @@
"*.d.ts",
"postcss.js"
],
"bundleDependencies": [
"@pandacss/preset-base",
"@pandacss/preset-panda"
],
"dependencies": {
"@clack/prompts": "0.7.0",
"@pandacss/config": "workspace:*",
"@pandacss/logger": "workspace:*",
"@pandacss/node": "workspace:*",
"@pandacss/postcss": "workspace:*",
"@pandacss/preset-base": "workspace:*",
"@pandacss/preset-panda": "workspace:*",
"@pandacss/postcss": "workspace:*",
"@pandacss/shared": "workspace:*",
"@pandacss/token-dictionary": "workspace:*",
"@pandacss/types": "workspace:*",
Expand Down
24 changes: 16 additions & 8 deletions packages/config/__tests__/bundle-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe('bundle config', () => {
"name": "__panda.config__",
"preflight": true,
"presets": [
"@pandacss/dev/presets",
"@pandacss/preset-base",
"@pandacss/preset-panda",
],
"theme": {
"extend": {
Expand Down Expand Up @@ -62,7 +63,8 @@ describe('bundle config', () => {
"name": "__panda.config__",
"preflight": true,
"presets": [
"@pandacss/dev/presets",
"@pandacss/preset-base",
"@pandacss/preset-panda",
],
"theme": {
"extend": {
Expand Down Expand Up @@ -103,7 +105,8 @@ describe('bundle config', () => {
"name": "__panda.config__",
"preflight": true,
"presets": [
"@pandacss/dev/presets",
"@pandacss/preset-base",
"@pandacss/preset-panda",
{
"name": "ts-import-preset",
"theme": {
Expand Down Expand Up @@ -192,7 +195,8 @@ describe('bundle config', () => {
"name": "__panda.config__",
"preflight": true,
"presets": [
"@pandacss/dev/presets",
"@pandacss/preset-base",
"@pandacss/preset-panda",
],
"theme": {
"extend": {
Expand Down Expand Up @@ -233,7 +237,8 @@ describe('bundle config', () => {
"name": "__panda.config__",
"preflight": true,
"presets": [
"@pandacss/dev/presets",
"@pandacss/preset-base",
"@pandacss/preset-panda",
],
"theme": {
"extend": {
Expand Down Expand Up @@ -274,7 +279,8 @@ describe('bundle config', () => {
"name": "__panda.config__",
"preflight": true,
"presets": [
"@pandacss/dev/presets",
"@pandacss/preset-base",
"@pandacss/preset-panda",
],
"theme": {
"extend": {
Expand Down Expand Up @@ -315,7 +321,8 @@ describe('bundle config', () => {
"name": "__panda.config__",
"preflight": true,
"presets": [
"@pandacss/dev/presets",
"@pandacss/preset-base",
"@pandacss/preset-panda",
],
"theme": {
"extend": {
Expand Down Expand Up @@ -356,7 +363,8 @@ describe('bundle config', () => {
"name": "__panda.config__",
"preflight": true,
"presets": [
"@pandacss/dev/presets",
"@pandacss/preset-base",
"@pandacss/preset-panda",
],
"theme": {
"extend": {
Expand Down
2 changes: 1 addition & 1 deletion packages/config/__tests__/samples/cjs/panda.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { tokens } = require('../common/tokens')

module.exports = defineConfig({
preflight: true,
presets: ['@pandacss/dev/presets'],
presets: ['@pandacss/preset-base', '@pandacss/preset-panda'],
include: ['./src/**/*.{ts,tsx,jsx}'],
exclude: [],
hash: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/__tests__/samples/cts/panda.config.cts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { tokens } from '../common/tokens'

export default defineConfig({
preflight: true,
presets: ['@pandacss/dev/presets'],
presets: ['@pandacss/preset-base', '@pandacss/preset-panda'],
include: ['./src/**/*.{ts,tsx,jsx}'],
exclude: [],
hash: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/__tests__/samples/js/panda.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { tokens } from '../common/tokens'

export default defineConfig({
preflight: true,
presets: ['@pandacss/dev/presets'],
presets: ['@pandacss/preset-base', '@pandacss/preset-panda'],
include: ['./src/**/*.{ts,tsx,jsx}'],
exclude: [],
hash: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/__tests__/samples/mts/panda.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { tokens } from '../common/tokens'

export default defineConfig({
preflight: true,
presets: ['@pandacss/dev/presets'],
presets: ['@pandacss/preset-base', '@pandacss/preset-panda'],
include: ['./src/**/*.{ts,tsx,jsx}'],
exclude: [],
hash: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { themeTokens } from './src'

export default defineConfig({
preflight: true,
presets: ['@pandacss/dev/presets'],
presets: ['@pandacss/preset-base', '@pandacss/preset-panda'],
include: ['./src/**/*.{ts,tsx,jsx}'],
exclude: [],
hash: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from '@pandacss/dev'

export default defineConfig({
preflight: false,
presets: ['@pandacss/dev/presets'],
presets: ['@pandacss/preset-base', '@pandacss/preset-panda'],
include: ['./ts-import-map.js'],
exclude: [],
hash: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from '@pandacss/dev'

export default defineConfig({
preflight: false,
presets: ['@pandacss/dev/presets'],
presets: ['@pandacss/preset-base', '@pandacss/preset-panda'],
include: ['./ts-import-map.js'],
exclude: [],
hash: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/__tests__/samples/ts/panda.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { tokens } from '../common/tokens'

export default defineConfig({
preflight: true,
presets: ['@pandacss/dev/presets'],
presets: ['@pandacss/preset-base', '@pandacss/preset-panda'],
include: ['./src/**/*.{ts,tsx,jsx}'],
exclude: [],
hash: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { tsImportPreset } from './src/ts-import-preset'

export default defineConfig({
preflight: true,
presets: ['@pandacss/dev/presets', tsImportPreset, require('./src/required-preset')],
presets: ['@pandacss/preset-base', '@pandacss/preset-panda', tsImportPreset, require('./src/required-preset')],
include: ['./src/**/*.{ts,tsx,jsx}'],
exclude: [],
hash: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { themeTokens } from '@/theme/tokens'

export default defineConfig({
preflight: true,
presets: ['@pandacss/dev/presets'],
presets: ['@pandacss/preset-base', '@pandacss/preset-panda'],
include: ['./src/**/*.{ts,tsx,jsx}'],
exclude: [],
hash: false,
Expand Down
5 changes: 1 addition & 4 deletions packages/config/src/bundled-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ const bundledPresets = {

const bundledPresetsNames = Object.keys(bundledPresets)

export const isBundledPreset = (preset: string): preset is keyof typeof bundledPresets =>
bundledPresetsNames.includes(preset)
const isBundledPreset = (preset: string): preset is keyof typeof bundledPresets => bundledPresetsNames.includes(preset)

export const getBundledPreset = (preset: unknown) => {
return typeof preset === 'string' && isBundledPreset(preset) ? bundledPresets[preset] : undefined
}

export { presetBase, presetPanda }
12 changes: 1 addition & 11 deletions packages/config/src/resolve-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logger } from '@pandacss/logger'
import { PANDA_CONFIG_NAME, omit, parseJson, stringifyJson, traverse } from '@pandacss/shared'
import type { LoadConfigResult, UserConfig } from '@pandacss/types'
import { getBundledPreset, presetBase, presetPanda } from './bundled-preset'
import { getBundledPreset } from './bundled-preset'
import { getResolvedConfig } from './get-resolved-config'
import type { BundleConfigResult } from './types'
import { validateConfig } from './validate-config'
Expand All @@ -13,24 +13,14 @@ const hookUtils = {

/**
* Resolve the final config (including presets)
* @pandacss/preset-base: ALWAYS included if NOT using eject: true
* @pandacss/preset-panda: only included by default if no presets
*/
export async function resolveConfig(result: BundleConfigResult, cwd: string): Promise<LoadConfigResult> {
const presets = new Set<any>()

if (!result.config.eject) {
presets.add(presetBase)
}

if (result.config.presets) {
//
result.config.presets.forEach((preset: any) => {
presets.add(getBundledPreset(preset) ?? preset)
})
//
} else if (!result.config.eject) {
presets.add(presetPanda)
}

result.config.presets = Array.from(presets)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/__tests__/breakpoints.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { fixturePreset } from '@pandacss/fixture'
import { builtInPresets } from '@pandacss/fixture'
import postcss from 'postcss'
import { describe, expect, test } from 'vitest'
import { Breakpoints } from '../src/breakpoints'

const breakpoints = fixturePreset.theme.breakpoints!
const breakpoints = builtInPresets.panda.theme.breakpoints!
const parse = (value: string) => {
const root = postcss.parse(value)
const bp = new Breakpoints(breakpoints)
Expand Down
6 changes: 3 additions & 3 deletions packages/core/__tests__/classname.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ describe('generate classnames', () => {
css({
top: { sm: { _rtl: '20px', _hover: '50px' }, lg: '120px' },
}),
).toMatchInlineSnapshot('"sm:rtl:top_20px sm:hover:top_50px lg:top_120px"')
).toMatchInlineSnapshot(`"sm:rtl:top_20px sm:hover:top_50px lg:top_120px"`)

expect(
css({
left: { base: '20px', md: '40px' },
}),
).toMatchInlineSnapshot('"left_20px md:left_40px"')
).toMatchInlineSnapshot(`"left_20px md:left_40px"`)
})

test('should expand shorthand before processing', () => {
Expand All @@ -59,7 +59,7 @@ describe('generate classnames', () => {
css({
_hover: { width: '40px', w: '90px' },
}),
).toMatchInlineSnapshot('"hover:w_90px"')
).toMatchInlineSnapshot(`"hover:w_90px"`)
})

test('should respect important', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/__tests__/color-mix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ describe('color-mix', () => {
expect(css({ gradientFrom: 'red/33' })).toMatchInlineSnapshot(`
{
"className": [
"from_red\\/33",
"grad-from_red\\/33",
],
"css": "@layer utilities {
.from_red\\/33 {
.grad-from_red\\/33 {
--mix---gradient-from: color-mix(in srgb, red 33%, transparent);
--gradient-from: var(--mix---gradient-from, red);
}
Expand Down
12 changes: 9 additions & 3 deletions packages/core/__tests__/conditions.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { fixturePreset } from '@pandacss/fixture'
import { builtInPresets } from '@pandacss/fixture'
import { describe, expect, test } from 'vitest'
import { Conditions } from '../src/conditions'
import { compareAtRuleOrMixed as _compareAtRuleOrMixed } from '../src/sort-style-rules'

describe('Conditions', () => {
test('condition transformation', () => {
const css = new Conditions({ conditions: fixturePreset.conditions!, breakpoints: fixturePreset.theme.breakpoints })
const css = new Conditions({
conditions: builtInPresets.base.conditions!,
breakpoints: builtInPresets.panda.theme.breakpoints,
})
expect(css.normalize('@media (min-width: 768px)')).toMatchInlineSnapshot(`
{
"name": "media",
Expand Down Expand Up @@ -76,7 +79,10 @@ describe('Conditions', () => {
})

test('conditions sorting', () => {
const css = new Conditions({ conditions: fixturePreset.conditions!, breakpoints: fixturePreset.theme.breakpoints })
const css = new Conditions({
conditions: builtInPresets.base.conditions!,
breakpoints: builtInPresets.panda.theme.breakpoints,
})
const conditions = ['sm', 'md', 'lg', '_hover', '_focus', '_focus-visible', '_focus-within', '_active']
expect(css.sort(conditions).map((c) => c.raw)).toMatchInlineSnapshot(`
[
Expand Down
5 changes: 3 additions & 2 deletions packages/core/__tests__/static-css.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fixtureDefaults } from '@pandacss/fixture'
import { fixtureDefaults, fixtureMergedConfig } from '@pandacss/fixture'
import { type StaticCssOptions } from '@pandacss/types'
import { describe, expect, test } from 'vitest'
import { Context } from '../src/context'
Expand All @@ -11,7 +11,8 @@ describe('static-css', () => {
...defaults,
config: {
...defaults.config,
theme: JSON.parse(JSON.stringify(defaults.config.theme)),
...fixtureMergedConfig,
theme: JSON.parse(JSON.stringify(fixtureMergedConfig.theme)),
},
} as typeof fixtureDefaults

Expand Down
4 changes: 2 additions & 2 deletions packages/core/__tests__/utility.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { fixturePreset } from '@pandacss/fixture'
import { fixtureMergedConfig } from '@pandacss/fixture'
import { TokenDictionary } from '@pandacss/token-dictionary'
import { describe, expect, test } from 'vitest'
import { Utility } from '../src/utility'

const { tokens, semanticTokens } = fixturePreset.theme
const { tokens, semanticTokens } = fixtureMergedConfig.theme!

describe('Utility', () => {
test('should resolve hideFrom and hideBelow', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@pandacss/shared": "workspace:*",
"@pandacss/token-dictionary": "workspace:*",
"@pandacss/types": "workspace:*",
"browserslist": "4.23.3",
"browserslist": "4.23.0",
"hookable": "5.5.3",
"lightningcss": "1.25.1",
"lodash.merge": "4.6.2",
Expand Down
Loading
Loading