@pandacss/config 0.30.2 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _pandacss_types from '@pandacss/types';
2
- import { Config, ConfigTsOptions } from '@pandacss/types';
2
+ import { Config, ConfigTsOptions, LoadConfigResult } from '@pandacss/types';
3
3
  export { diffConfigs } from './diff-config.mjs';
4
4
  import { P as PathMapping } from './ts-config-paths-2lh9mwzL.mjs';
5
5
  export { c as convertTsPathsToRegexes } from './ts-config-paths-2lh9mwzL.mjs';
@@ -49,4 +49,11 @@ declare function getResolvedConfig(config: ExtendableConfig, cwd: string): Promi
49
49
  */
50
50
  declare function loadConfig(options: ConfigFileOptions): Promise<_pandacss_types.LoadConfigResult>;
51
51
 
52
- export { type BundleConfigResult, type GetDepsOptions, bundleConfig, findConfig, getConfigDependencies, getResolvedConfig, loadConfig };
52
+ /**
53
+ * Resolve the final config (including presets)
54
+ * @pandacss/preset-base: ALWAYS included if NOT using eject: true
55
+ * @pandacss/preset-panda: only included by default if no presets
56
+ */
57
+ declare function resolveConfig(result: BundleConfigResult, cwd: string): Promise<LoadConfigResult>;
58
+
59
+ export { type BundleConfigResult, type GetDepsOptions, bundleConfig, findConfig, getConfigDependencies, getResolvedConfig, loadConfig, resolveConfig };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _pandacss_types from '@pandacss/types';
2
- import { Config, ConfigTsOptions } from '@pandacss/types';
2
+ import { Config, ConfigTsOptions, LoadConfigResult } from '@pandacss/types';
3
3
  export { diffConfigs } from './diff-config.js';
4
4
  import { P as PathMapping } from './ts-config-paths-2lh9mwzL.js';
5
5
  export { c as convertTsPathsToRegexes } from './ts-config-paths-2lh9mwzL.js';
@@ -49,4 +49,11 @@ declare function getResolvedConfig(config: ExtendableConfig, cwd: string): Promi
49
49
  */
50
50
  declare function loadConfig(options: ConfigFileOptions): Promise<_pandacss_types.LoadConfigResult>;
51
51
 
52
- export { type BundleConfigResult, type GetDepsOptions, bundleConfig, findConfig, getConfigDependencies, getResolvedConfig, loadConfig };
52
+ /**
53
+ * Resolve the final config (including presets)
54
+ * @pandacss/preset-base: ALWAYS included if NOT using eject: true
55
+ * @pandacss/preset-panda: only included by default if no presets
56
+ */
57
+ declare function resolveConfig(result: BundleConfigResult, cwd: string): Promise<LoadConfigResult>;
58
+
59
+ export { type BundleConfigResult, type GetDepsOptions, bundleConfig, findConfig, getConfigDependencies, getResolvedConfig, loadConfig, resolveConfig };
package/dist/index.js CHANGED
@@ -37,7 +37,8 @@ __export(src_exports, {
37
37
  getConfigDependencies: () => getConfigDependencies,
38
38
  getResolvedConfig: () => getResolvedConfig,
39
39
  loadConfig: () => loadConfig,
40
- mergeConfigs: () => mergeConfigs
40
+ mergeConfigs: () => mergeConfigs,
41
+ resolveConfig: () => resolveConfig
41
42
  });
42
43
  module.exports = __toCommonJS(src_exports);
43
44
 
@@ -495,6 +496,7 @@ async function getResolvedConfig(config, cwd) {
495
496
  }
496
497
 
497
498
  // src/resolve-config.ts
499
+ var import_logger3 = require("@pandacss/logger");
498
500
  var import_shared8 = require("@pandacss/shared");
499
501
 
500
502
  // src/bundled-preset.ts
@@ -592,17 +594,11 @@ var validateRecipes = (options) => {
592
594
  // src/validation/validate-tokens.ts
593
595
  var import_shared6 = require("@pandacss/shared");
594
596
 
595
- // src/validation/get-final-paths.ts
596
- var getFinalPaths = (paths) => {
597
- paths.forEach((path2) => {
598
- paths.forEach((potentialExtension) => {
599
- if (potentialExtension.startsWith(path2 + ".")) {
600
- paths.delete(path2);
601
- }
602
- });
603
- });
604
- return paths;
605
- };
597
+ // src/validation/utils.ts
598
+ var isValidToken = (token) => Object.hasOwnProperty.call(token, "value");
599
+ var isTokenReference = (value) => typeof value === "string" && value.startsWith("{");
600
+ var formatPath = (path2) => path2;
601
+ var SEP = ".";
606
602
 
607
603
  // src/validation/validate-token-references.ts
608
604
  var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
@@ -612,17 +608,23 @@ var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
612
608
  }
613
609
  const stack = [path2];
614
610
  while (stack.length > 0) {
615
- const current = stack.pop();
616
- const value = valueAtPath.get(current);
611
+ const currentPath = stack.pop();
612
+ const value = valueAtPath.get(currentPath);
617
613
  if (!value) {
618
- addError("tokens", `Missing token: \`${current}\` used in \`config.semanticTokens.${path2}\``);
614
+ addError("tokens", `Missing token: \`${currentPath}\` used in \`config.semanticTokens.${path2}\``);
619
615
  }
620
- const deps = refsByPath.get(current);
616
+ if (isTokenReference(value) && !refsByPath.has(value)) {
617
+ addError("tokens", `Unknown token reference: \`${currentPath}\` used in \`${value}\``);
618
+ }
619
+ const deps = refsByPath.get(currentPath);
621
620
  if (!deps)
622
621
  continue;
623
622
  for (const transitiveDep of deps) {
624
623
  if (path2 === transitiveDep) {
625
- addError("tokens", `Circular token reference: \`${transitiveDep}\` -> \`${current}\` -> ... -> \`${path2}\``);
624
+ addError(
625
+ "tokens",
626
+ `Circular token reference: \`${transitiveDep}\` -> \`${currentPath}\` -> ... -> \`${path2}\``
627
+ );
626
628
  break;
627
629
  }
628
630
  stack.push(transitiveDep);
@@ -642,43 +644,65 @@ var validateTokens = (options) => {
642
644
  return;
643
645
  const { tokenNames, semanticTokenNames, valueAtPath, refsByPath } = tokens2;
644
646
  if (theme.tokens) {
645
- (0, import_shared6.traverse)(theme.tokens, (node) => {
646
- if (node.depth >= 1) {
647
- tokenNames.add(node.path);
648
- valueAtPath.set(node.path, node.value);
647
+ const tokenPaths = /* @__PURE__ */ new Set();
648
+ (0, import_shared6.walkObject)(
649
+ theme.tokens,
650
+ (value, paths) => {
651
+ const path2 = paths.join(SEP);
652
+ tokenNames.add(path2);
653
+ tokenPaths.add(path2);
654
+ valueAtPath.set(path2, value);
655
+ },
656
+ {
657
+ stop: isValidToken
649
658
  }
650
- });
651
- const finalPaths = getFinalPaths(tokenNames);
652
- finalPaths.forEach((path2) => {
653
- if (!path2.includes("value")) {
654
- addError("tokens", `Token paths must end with 'value': \`theme.tokens.${path2}\``);
659
+ );
660
+ tokenPaths.forEach((path2) => {
661
+ const value = valueAtPath.get(path2);
662
+ const formattedPath = formatPath(path2);
663
+ if (!isValidToken(value)) {
664
+ addError("tokens", `Token must contain 'value': \`theme.tokens.${formattedPath}\``);
665
+ return;
655
666
  }
656
- const atPath = valueAtPath.get(path2);
657
- if (typeof atPath === "string" && atPath.startsWith("{")) {
658
- refsByPath.set(path2, /* @__PURE__ */ new Set([]));
667
+ if (isTokenReference(value)) {
668
+ refsByPath.set(formattedPath, /* @__PURE__ */ new Set([]));
659
669
  }
660
670
  });
661
671
  }
662
672
  if (theme.semanticTokens) {
663
- (0, import_shared6.traverse)(theme.semanticTokens, (node) => {
664
- if (node.depth >= 1) {
665
- semanticTokenNames.add(node.path);
666
- valueAtPath.set(node.path, node.value);
667
- if (typeof node.value === "string" && node.value.startsWith("{") && node.path.includes("value")) {
668
- const tokenPath = node.path.split(".value")[0];
669
- if (!refsByPath.has(tokenPath)) {
670
- refsByPath.set(tokenPath, /* @__PURE__ */ new Set());
673
+ const tokenPaths = /* @__PURE__ */ new Set();
674
+ (0, import_shared6.walkObject)(
675
+ theme.semanticTokens,
676
+ (value, paths) => {
677
+ const path2 = paths.join(SEP);
678
+ semanticTokenNames.add(path2);
679
+ valueAtPath.set(path2, value);
680
+ tokenPaths.add(path2);
681
+ if (!isValidToken(value))
682
+ return;
683
+ (0, import_shared6.walkObject)(value, (itemValue) => {
684
+ if (isTokenReference(itemValue)) {
685
+ const formattedPath = formatPath(path2);
686
+ if (!refsByPath.has(formattedPath)) {
687
+ refsByPath.set(formattedPath, /* @__PURE__ */ new Set());
688
+ }
689
+ const references = refsByPath.get(formattedPath);
690
+ if (!references)
691
+ return;
692
+ const reference = itemValue.slice(1, -1);
693
+ references.add(reference);
671
694
  }
672
- const values = refsByPath.get(tokenPath);
673
- const tokenRef = node.value.slice(1, -1);
674
- values.add(tokenRef);
675
- }
695
+ });
696
+ },
697
+ {
698
+ stop: isValidToken
676
699
  }
677
- });
678
- const finalPaths = getFinalPaths(semanticTokenNames);
679
- finalPaths.forEach((path2) => {
680
- if (!path2.includes("value")) {
681
- addError("tokens", `Semantic token paths must contain 'value': \`theme.semanticTokens.${path2}\``);
700
+ );
701
+ tokenPaths.forEach((path2) => {
702
+ const formattedPath = formatPath(path2);
703
+ const value = valueAtPath.get(path2);
704
+ if (!(0, import_shared6.isObject)(value) && !path2.includes("value")) {
705
+ addError("tokens", `Token must contain 'value': \`theme.semanticTokens.${formattedPath}\``);
682
706
  }
683
707
  });
684
708
  validateTokenReferences(valueAtPath, refsByPath, addError);
@@ -691,11 +715,7 @@ var validateConfig = (config) => {
691
715
  return;
692
716
  const warnings = /* @__PURE__ */ new Set();
693
717
  const addError = (scope, message) => {
694
- if (config.validation === "warn") {
695
- warnings.add(`[${scope}]: ` + message);
696
- } else {
697
- throw new import_shared7.PandaError("CONFIG_ERROR", `[${scope}]: ` + message);
698
- }
718
+ warnings.add(`[${scope}] ` + message);
699
719
  };
700
720
  validateBreakpoints(config.theme?.breakpoints, addError);
701
721
  validateConditions(config.conditions, addError);
@@ -717,12 +737,13 @@ var validateConfig = (config) => {
717
737
  validatePatterns(config.patterns, artifacts);
718
738
  validateArtifactNames(artifacts, addError);
719
739
  if (warnings.size) {
720
- import_logger2.logger.warn(
721
- "config",
722
- `\u26A0\uFE0F Invalid config:
740
+ const errors = `\u26A0\uFE0F Invalid config:
723
741
  ${Array.from(warnings).map((err) => "- " + err).join("\n")}
724
- `
725
- );
742
+ `;
743
+ if (config.validation === "error") {
744
+ throw new import_shared7.PandaError("CONFIG_ERROR", errors);
745
+ }
746
+ import_logger2.logger.warn("config", errors);
726
747
  return warnings;
727
748
  }
728
749
  };
@@ -742,6 +763,9 @@ async function resolveConfig(result, cwd) {
742
763
  }
743
764
  result.config.presets = Array.from(presets);
744
765
  const config = await getResolvedConfig(result.config, cwd);
766
+ if (config.logLevel) {
767
+ import_logger3.logger.level = config.logLevel;
768
+ }
745
769
  validateConfig(config);
746
770
  const { hooks = {} } = result.config;
747
771
  const loadConfigResult = {
@@ -778,5 +802,6 @@ async function loadConfig(options) {
778
802
  getConfigDependencies,
779
803
  getResolvedConfig,
780
804
  loadConfig,
781
- mergeConfigs
805
+ mergeConfigs,
806
+ resolveConfig
782
807
  });
package/dist/index.mjs CHANGED
@@ -214,6 +214,7 @@ async function getResolvedConfig(config, cwd) {
214
214
  }
215
215
 
216
216
  // src/resolve-config.ts
217
+ import { logger as logger3 } from "@pandacss/logger";
217
218
  import { parseJson, stringifyJson } from "@pandacss/shared";
218
219
 
219
220
  // src/bundled-preset.ts
@@ -309,19 +310,13 @@ var validateRecipes = (options) => {
309
310
  };
310
311
 
311
312
  // src/validation/validate-tokens.ts
312
- import { traverse } from "@pandacss/shared";
313
+ import { isObject, walkObject } from "@pandacss/shared";
313
314
 
314
- // src/validation/get-final-paths.ts
315
- var getFinalPaths = (paths) => {
316
- paths.forEach((path2) => {
317
- paths.forEach((potentialExtension) => {
318
- if (potentialExtension.startsWith(path2 + ".")) {
319
- paths.delete(path2);
320
- }
321
- });
322
- });
323
- return paths;
324
- };
315
+ // src/validation/utils.ts
316
+ var isValidToken = (token) => Object.hasOwnProperty.call(token, "value");
317
+ var isTokenReference = (value) => typeof value === "string" && value.startsWith("{");
318
+ var formatPath = (path2) => path2;
319
+ var SEP = ".";
325
320
 
326
321
  // src/validation/validate-token-references.ts
327
322
  var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
@@ -331,17 +326,23 @@ var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
331
326
  }
332
327
  const stack = [path2];
333
328
  while (stack.length > 0) {
334
- const current = stack.pop();
335
- const value = valueAtPath.get(current);
329
+ const currentPath = stack.pop();
330
+ const value = valueAtPath.get(currentPath);
336
331
  if (!value) {
337
- addError("tokens", `Missing token: \`${current}\` used in \`config.semanticTokens.${path2}\``);
332
+ addError("tokens", `Missing token: \`${currentPath}\` used in \`config.semanticTokens.${path2}\``);
333
+ }
334
+ if (isTokenReference(value) && !refsByPath.has(value)) {
335
+ addError("tokens", `Unknown token reference: \`${currentPath}\` used in \`${value}\``);
338
336
  }
339
- const deps = refsByPath.get(current);
337
+ const deps = refsByPath.get(currentPath);
340
338
  if (!deps)
341
339
  continue;
342
340
  for (const transitiveDep of deps) {
343
341
  if (path2 === transitiveDep) {
344
- addError("tokens", `Circular token reference: \`${transitiveDep}\` -> \`${current}\` -> ... -> \`${path2}\``);
342
+ addError(
343
+ "tokens",
344
+ `Circular token reference: \`${transitiveDep}\` -> \`${currentPath}\` -> ... -> \`${path2}\``
345
+ );
345
346
  break;
346
347
  }
347
348
  stack.push(transitiveDep);
@@ -361,43 +362,65 @@ var validateTokens = (options) => {
361
362
  return;
362
363
  const { tokenNames, semanticTokenNames, valueAtPath, refsByPath } = tokens;
363
364
  if (theme.tokens) {
364
- traverse(theme.tokens, (node) => {
365
- if (node.depth >= 1) {
366
- tokenNames.add(node.path);
367
- valueAtPath.set(node.path, node.value);
365
+ const tokenPaths = /* @__PURE__ */ new Set();
366
+ walkObject(
367
+ theme.tokens,
368
+ (value, paths) => {
369
+ const path2 = paths.join(SEP);
370
+ tokenNames.add(path2);
371
+ tokenPaths.add(path2);
372
+ valueAtPath.set(path2, value);
373
+ },
374
+ {
375
+ stop: isValidToken
368
376
  }
369
- });
370
- const finalPaths = getFinalPaths(tokenNames);
371
- finalPaths.forEach((path2) => {
372
- if (!path2.includes("value")) {
373
- addError("tokens", `Token paths must end with 'value': \`theme.tokens.${path2}\``);
377
+ );
378
+ tokenPaths.forEach((path2) => {
379
+ const value = valueAtPath.get(path2);
380
+ const formattedPath = formatPath(path2);
381
+ if (!isValidToken(value)) {
382
+ addError("tokens", `Token must contain 'value': \`theme.tokens.${formattedPath}\``);
383
+ return;
374
384
  }
375
- const atPath = valueAtPath.get(path2);
376
- if (typeof atPath === "string" && atPath.startsWith("{")) {
377
- refsByPath.set(path2, /* @__PURE__ */ new Set([]));
385
+ if (isTokenReference(value)) {
386
+ refsByPath.set(formattedPath, /* @__PURE__ */ new Set([]));
378
387
  }
379
388
  });
380
389
  }
381
390
  if (theme.semanticTokens) {
382
- traverse(theme.semanticTokens, (node) => {
383
- if (node.depth >= 1) {
384
- semanticTokenNames.add(node.path);
385
- valueAtPath.set(node.path, node.value);
386
- if (typeof node.value === "string" && node.value.startsWith("{") && node.path.includes("value")) {
387
- const tokenPath = node.path.split(".value")[0];
388
- if (!refsByPath.has(tokenPath)) {
389
- refsByPath.set(tokenPath, /* @__PURE__ */ new Set());
391
+ const tokenPaths = /* @__PURE__ */ new Set();
392
+ walkObject(
393
+ theme.semanticTokens,
394
+ (value, paths) => {
395
+ const path2 = paths.join(SEP);
396
+ semanticTokenNames.add(path2);
397
+ valueAtPath.set(path2, value);
398
+ tokenPaths.add(path2);
399
+ if (!isValidToken(value))
400
+ return;
401
+ walkObject(value, (itemValue) => {
402
+ if (isTokenReference(itemValue)) {
403
+ const formattedPath = formatPath(path2);
404
+ if (!refsByPath.has(formattedPath)) {
405
+ refsByPath.set(formattedPath, /* @__PURE__ */ new Set());
406
+ }
407
+ const references = refsByPath.get(formattedPath);
408
+ if (!references)
409
+ return;
410
+ const reference = itemValue.slice(1, -1);
411
+ references.add(reference);
390
412
  }
391
- const values = refsByPath.get(tokenPath);
392
- const tokenRef = node.value.slice(1, -1);
393
- values.add(tokenRef);
394
- }
413
+ });
414
+ },
415
+ {
416
+ stop: isValidToken
395
417
  }
396
- });
397
- const finalPaths = getFinalPaths(semanticTokenNames);
398
- finalPaths.forEach((path2) => {
399
- if (!path2.includes("value")) {
400
- addError("tokens", `Semantic token paths must contain 'value': \`theme.semanticTokens.${path2}\``);
418
+ );
419
+ tokenPaths.forEach((path2) => {
420
+ const formattedPath = formatPath(path2);
421
+ const value = valueAtPath.get(path2);
422
+ if (!isObject(value) && !path2.includes("value")) {
423
+ addError("tokens", `Token must contain 'value': \`theme.semanticTokens.${formattedPath}\``);
401
424
  }
402
425
  });
403
426
  validateTokenReferences(valueAtPath, refsByPath, addError);
@@ -410,11 +433,7 @@ var validateConfig = (config) => {
410
433
  return;
411
434
  const warnings = /* @__PURE__ */ new Set();
412
435
  const addError = (scope, message) => {
413
- if (config.validation === "warn") {
414
- warnings.add(`[${scope}]: ` + message);
415
- } else {
416
- throw new PandaError3("CONFIG_ERROR", `[${scope}]: ` + message);
417
- }
436
+ warnings.add(`[${scope}] ` + message);
418
437
  };
419
438
  validateBreakpoints(config.theme?.breakpoints, addError);
420
439
  validateConditions(config.conditions, addError);
@@ -436,12 +455,13 @@ var validateConfig = (config) => {
436
455
  validatePatterns(config.patterns, artifacts);
437
456
  validateArtifactNames(artifacts, addError);
438
457
  if (warnings.size) {
439
- logger2.warn(
440
- "config",
441
- `\u26A0\uFE0F Invalid config:
458
+ const errors = `\u26A0\uFE0F Invalid config:
442
459
  ${Array.from(warnings).map((err) => "- " + err).join("\n")}
443
- `
444
- );
460
+ `;
461
+ if (config.validation === "error") {
462
+ throw new PandaError3("CONFIG_ERROR", errors);
463
+ }
464
+ logger2.warn("config", errors);
445
465
  return warnings;
446
466
  }
447
467
  };
@@ -461,6 +481,9 @@ async function resolveConfig(result, cwd) {
461
481
  }
462
482
  result.config.presets = Array.from(presets);
463
483
  const config = await getResolvedConfig(result.config, cwd);
484
+ if (config.logLevel) {
485
+ logger3.level = config.logLevel;
486
+ }
464
487
  validateConfig(config);
465
488
  const { hooks = {} } = result.config;
466
489
  const loadConfigResult = {
@@ -496,5 +519,6 @@ export {
496
519
  getConfigDependencies,
497
520
  getResolvedConfig,
498
521
  loadConfig,
499
- mergeConfigs
522
+ mergeConfigs,
523
+ resolveConfig
500
524
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/config",
3
- "version": "0.30.2",
3
+ "version": "0.31.0",
4
4
  "description": "Find and load panda config",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -60,15 +60,15 @@
60
60
  ],
61
61
  "dependencies": {
62
62
  "bundle-n-require": "1.1.1",
63
- "escalade": "3.1.1",
63
+ "escalade": "3.1.2",
64
64
  "merge-anything": "5.1.7",
65
65
  "microdiff": "1.3.2",
66
66
  "typescript": "5.3.3",
67
- "@pandacss/logger": "0.30.2",
68
- "@pandacss/preset-base": "0.30.2",
69
- "@pandacss/preset-panda": "0.30.2",
70
- "@pandacss/shared": "0.30.2",
71
- "@pandacss/types": "0.30.2"
67
+ "@pandacss/logger": "0.31.0",
68
+ "@pandacss/preset-base": "0.31.0",
69
+ "@pandacss/preset-panda": "0.31.0",
70
+ "@pandacss/shared": "0.31.0",
71
+ "@pandacss/types": "0.31.0"
72
72
  },
73
73
  "devDependencies": {
74
74
  "pkg-types": "1.0.3"