@pandacss/config 0.0.0-dev-20240212091357 → 0.0.0-dev-20240212185235

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.js CHANGED
@@ -496,6 +496,7 @@ async function getResolvedConfig(config, cwd) {
496
496
  }
497
497
 
498
498
  // src/resolve-config.ts
499
+ var import_logger3 = require("@pandacss/logger");
499
500
  var import_shared8 = require("@pandacss/shared");
500
501
 
501
502
  // src/bundled-preset.ts
@@ -593,17 +594,11 @@ var validateRecipes = (options) => {
593
594
  // src/validation/validate-tokens.ts
594
595
  var import_shared6 = require("@pandacss/shared");
595
596
 
596
- // src/validation/get-final-paths.ts
597
- var getFinalPaths = (paths) => {
598
- paths.forEach((path2) => {
599
- paths.forEach((potentialExtension) => {
600
- if (potentialExtension.startsWith(path2 + ".")) {
601
- paths.delete(path2);
602
- }
603
- });
604
- });
605
- return paths;
606
- };
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 = ".";
607
602
 
608
603
  // src/validation/validate-token-references.ts
609
604
  var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
@@ -613,17 +608,23 @@ var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
613
608
  }
614
609
  const stack = [path2];
615
610
  while (stack.length > 0) {
616
- const current = stack.pop();
617
- const value = valueAtPath.get(current);
611
+ const currentPath = stack.pop();
612
+ const value = valueAtPath.get(currentPath);
618
613
  if (!value) {
619
- addError("tokens", `Missing token: \`${current}\` used in \`config.semanticTokens.${path2}\``);
614
+ addError("tokens", `Missing token: \`${currentPath}\` used in \`config.semanticTokens.${path2}\``);
620
615
  }
621
- 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);
622
620
  if (!deps)
623
621
  continue;
624
622
  for (const transitiveDep of deps) {
625
623
  if (path2 === transitiveDep) {
626
- addError("tokens", `Circular token reference: \`${transitiveDep}\` -> \`${current}\` -> ... -> \`${path2}\``);
624
+ addError(
625
+ "tokens",
626
+ `Circular token reference: \`${transitiveDep}\` -> \`${currentPath}\` -> ... -> \`${path2}\``
627
+ );
627
628
  break;
628
629
  }
629
630
  stack.push(transitiveDep);
@@ -643,43 +644,65 @@ var validateTokens = (options) => {
643
644
  return;
644
645
  const { tokenNames, semanticTokenNames, valueAtPath, refsByPath } = tokens2;
645
646
  if (theme.tokens) {
646
- (0, import_shared6.traverse)(theme.tokens, (node) => {
647
- if (node.depth >= 1) {
648
- tokenNames.add(node.path);
649
- 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
650
658
  }
651
- });
652
- const finalPaths = getFinalPaths(tokenNames);
653
- finalPaths.forEach((path2) => {
654
- if (!path2.includes("value")) {
655
- 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;
656
666
  }
657
- const atPath = valueAtPath.get(path2);
658
- if (typeof atPath === "string" && atPath.startsWith("{")) {
659
- refsByPath.set(path2, /* @__PURE__ */ new Set([]));
667
+ if (isTokenReference(value)) {
668
+ refsByPath.set(formattedPath, /* @__PURE__ */ new Set([]));
660
669
  }
661
670
  });
662
671
  }
663
672
  if (theme.semanticTokens) {
664
- (0, import_shared6.traverse)(theme.semanticTokens, (node) => {
665
- if (node.depth >= 1) {
666
- semanticTokenNames.add(node.path);
667
- valueAtPath.set(node.path, node.value);
668
- if (typeof node.value === "string" && node.value.startsWith("{") && node.path.includes("value")) {
669
- const tokenPath = node.path.split(".value")[0];
670
- if (!refsByPath.has(tokenPath)) {
671
- 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);
672
694
  }
673
- const values = refsByPath.get(tokenPath);
674
- const tokenRef = node.value.slice(1, -1);
675
- values.add(tokenRef);
676
- }
695
+ });
696
+ },
697
+ {
698
+ stop: isValidToken
677
699
  }
678
- });
679
- const finalPaths = getFinalPaths(semanticTokenNames);
680
- finalPaths.forEach((path2) => {
681
- if (!path2.includes("value")) {
682
- 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}\``);
683
706
  }
684
707
  });
685
708
  validateTokenReferences(valueAtPath, refsByPath, addError);
@@ -692,11 +715,7 @@ var validateConfig = (config) => {
692
715
  return;
693
716
  const warnings = /* @__PURE__ */ new Set();
694
717
  const addError = (scope, message) => {
695
- if (config.validation === "warn") {
696
- warnings.add(`[${scope}]: ` + message);
697
- } else {
698
- throw new import_shared7.PandaError("CONFIG_ERROR", `[${scope}]: ` + message);
699
- }
718
+ warnings.add(`[${scope}] ` + message);
700
719
  };
701
720
  validateBreakpoints(config.theme?.breakpoints, addError);
702
721
  validateConditions(config.conditions, addError);
@@ -718,12 +737,13 @@ var validateConfig = (config) => {
718
737
  validatePatterns(config.patterns, artifacts);
719
738
  validateArtifactNames(artifacts, addError);
720
739
  if (warnings.size) {
721
- import_logger2.logger.warn(
722
- "config",
723
- `\u26A0\uFE0F Invalid config:
740
+ const errors = `\u26A0\uFE0F Invalid config:
724
741
  ${Array.from(warnings).map((err) => "- " + err).join("\n")}
725
- `
726
- );
742
+ `;
743
+ if (config.validation === "error") {
744
+ throw new import_shared7.PandaError("CONFIG_ERROR", errors);
745
+ }
746
+ import_logger2.logger.warn("config", errors);
727
747
  return warnings;
728
748
  }
729
749
  };
@@ -743,6 +763,9 @@ async function resolveConfig(result, cwd) {
743
763
  }
744
764
  result.config.presets = Array.from(presets);
745
765
  const config = await getResolvedConfig(result.config, cwd);
766
+ if (config.logLevel) {
767
+ import_logger3.logger.level = config.logLevel;
768
+ }
746
769
  validateConfig(config);
747
770
  const { hooks = {} } = result.config;
748
771
  const loadConfigResult = {
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}\``);
338
333
  }
339
- const deps = refsByPath.get(current);
334
+ if (isTokenReference(value) && !refsByPath.has(value)) {
335
+ addError("tokens", `Unknown token reference: \`${currentPath}\` used in \`${value}\``);
336
+ }
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 = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/config",
3
- "version": "0.0.0-dev-20240212091357",
3
+ "version": "0.0.0-dev-20240212185235",
4
4
  "description": "Find and load panda config",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -64,11 +64,11 @@
64
64
  "merge-anything": "5.1.7",
65
65
  "microdiff": "1.3.2",
66
66
  "typescript": "5.3.3",
67
- "@pandacss/logger": "0.0.0-dev-20240212091357",
68
- "@pandacss/preset-base": "0.0.0-dev-20240212091357",
69
- "@pandacss/preset-panda": "0.0.0-dev-20240212091357",
70
- "@pandacss/shared": "0.0.0-dev-20240212091357",
71
- "@pandacss/types": "0.0.0-dev-20240212091357"
67
+ "@pandacss/logger": "0.0.0-dev-20240212185235",
68
+ "@pandacss/preset-base": "0.0.0-dev-20240212185235",
69
+ "@pandacss/preset-panda": "0.0.0-dev-20240212185235",
70
+ "@pandacss/shared": "0.0.0-dev-20240212185235",
71
+ "@pandacss/types": "0.0.0-dev-20240212185235"
72
72
  },
73
73
  "devDependencies": {
74
74
  "pkg-types": "1.0.3"