@pandacss/config 0.0.0-dev-20240128131310 → 0.0.0-dev-20240128182812
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/diff-config.d.mts +0 -2
- package/dist/diff-config.d.ts +0 -2
- package/dist/diff-config.mjs +1 -1
- package/dist/index.d.mts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +254 -19
- package/dist/index.mjs +249 -14
- package/package.json +6 -7
- /package/dist/{chunk-TP2SOWHU.mjs → chunk-DQCK3AP6.mjs} +0 -0
package/dist/diff-config.d.mts
CHANGED
package/dist/diff-config.d.ts
CHANGED
package/dist/diff-config.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as _pandacss_types from '@pandacss/types';
|
|
2
2
|
import { Config, ConfigTsOptions } from '@pandacss/types';
|
|
3
|
-
export { DiffConfigResult } from '@pandacss/types';
|
|
4
3
|
export { diffConfigs } from './diff-config.mjs';
|
|
5
4
|
import { P as PathMapping } from './ts-config-paths-2lh9mwzL.mjs';
|
|
6
5
|
export { c as convertTsPathsToRegexes } from './ts-config-paths-2lh9mwzL.mjs';
|
|
@@ -11,15 +10,15 @@ interface ConfigFileOptions {
|
|
|
11
10
|
cwd: string;
|
|
12
11
|
file?: string;
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
interface BundleConfigResult<T = Config> {
|
|
16
14
|
config: T;
|
|
17
15
|
dependencies: string[];
|
|
18
16
|
path: string;
|
|
19
17
|
}
|
|
18
|
+
|
|
20
19
|
declare function bundleConfig(options: ConfigFileOptions): Promise<BundleConfigResult>;
|
|
21
20
|
|
|
22
|
-
declare function findConfig(
|
|
21
|
+
declare function findConfig(options: Partial<ConfigFileOptions>): string;
|
|
23
22
|
|
|
24
23
|
interface GetDepsOptions {
|
|
25
24
|
filename: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as _pandacss_types from '@pandacss/types';
|
|
2
2
|
import { Config, ConfigTsOptions } from '@pandacss/types';
|
|
3
|
-
export { DiffConfigResult } from '@pandacss/types';
|
|
4
3
|
export { diffConfigs } from './diff-config.js';
|
|
5
4
|
import { P as PathMapping } from './ts-config-paths-2lh9mwzL.js';
|
|
6
5
|
export { c as convertTsPathsToRegexes } from './ts-config-paths-2lh9mwzL.js';
|
|
@@ -11,15 +10,15 @@ interface ConfigFileOptions {
|
|
|
11
10
|
cwd: string;
|
|
12
11
|
file?: string;
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
interface BundleConfigResult<T = Config> {
|
|
16
14
|
config: T;
|
|
17
15
|
dependencies: string[];
|
|
18
16
|
path: string;
|
|
19
17
|
}
|
|
18
|
+
|
|
20
19
|
declare function bundleConfig(options: ConfigFileOptions): Promise<BundleConfigResult>;
|
|
21
20
|
|
|
22
|
-
declare function findConfig(
|
|
21
|
+
declare function findConfig(options: Partial<ConfigFileOptions>): string;
|
|
23
22
|
|
|
24
23
|
interface GetDepsOptions {
|
|
25
24
|
filename: string;
|
package/dist/index.js
CHANGED
|
@@ -42,22 +42,34 @@ __export(src_exports, {
|
|
|
42
42
|
module.exports = __toCommonJS(src_exports);
|
|
43
43
|
|
|
44
44
|
// src/bundle-config.ts
|
|
45
|
-
var import_error = require("@pandacss/error");
|
|
46
45
|
var import_logger = require("@pandacss/logger");
|
|
46
|
+
var import_shared2 = require("@pandacss/shared");
|
|
47
47
|
var import_bundle_n_require = require("bundle-n-require");
|
|
48
48
|
|
|
49
49
|
// src/find-config.ts
|
|
50
|
+
var import_shared = require("@pandacss/shared");
|
|
50
51
|
var import_sync = __toESM(require("escalade/sync"));
|
|
51
52
|
var import_path = require("path");
|
|
53
|
+
|
|
54
|
+
// src/is-panda-config.ts
|
|
52
55
|
var configs = [".ts", ".js", ".mts", ".mjs", ".cts", ".cjs"];
|
|
53
56
|
var pandaConfigRegex = new RegExp(`panda.config(${configs.join("|")})$`);
|
|
54
57
|
var isPandaConfig = (file) => pandaConfigRegex.test(file);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
|
|
59
|
+
// src/find-config.ts
|
|
60
|
+
function findConfig(options) {
|
|
61
|
+
const { cwd = process.cwd(), file } = options;
|
|
62
|
+
if (file) {
|
|
58
63
|
return (0, import_path.resolve)(cwd, file);
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
}
|
|
65
|
+
const configPath = (0, import_sync.default)(cwd, (_dir, paths) => paths.find(isPandaConfig));
|
|
66
|
+
if (!configPath) {
|
|
67
|
+
throw new import_shared.PandaError(
|
|
68
|
+
"CONFIG_NOT_FOUND",
|
|
69
|
+
`Cannot find config file \`panda.config.{ts,js,mjs,mts}\`. Did you forget to run \`panda init\`?`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return configPath;
|
|
61
73
|
}
|
|
62
74
|
|
|
63
75
|
// src/bundle-config.ts
|
|
@@ -74,15 +86,13 @@ async function bundle(filepath, cwd) {
|
|
|
74
86
|
async function bundleConfig(options) {
|
|
75
87
|
const { cwd, file } = options;
|
|
76
88
|
const filePath = findConfig({ cwd, file });
|
|
77
|
-
if (!filePath) {
|
|
78
|
-
throw new import_error.ConfigNotFoundError();
|
|
79
|
-
}
|
|
80
89
|
import_logger.logger.debug("config:path", filePath);
|
|
81
90
|
const result = await bundle(filePath, cwd);
|
|
82
91
|
if (typeof result.config !== "object") {
|
|
83
|
-
throw new
|
|
92
|
+
throw new import_shared2.PandaError("CONFIG_ERROR", `\u{1F4A5} Config must export or return an object.`);
|
|
84
93
|
}
|
|
85
94
|
result.config.outdir ??= "styled-system";
|
|
95
|
+
result.config.validation ??= "error";
|
|
86
96
|
return {
|
|
87
97
|
...result,
|
|
88
98
|
config: result.config,
|
|
@@ -91,7 +101,7 @@ async function bundleConfig(options) {
|
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
// src/diff-config.ts
|
|
94
|
-
var
|
|
104
|
+
var import_shared3 = require("@pandacss/shared");
|
|
95
105
|
var import_microdiff = __toESM(require("microdiff"));
|
|
96
106
|
|
|
97
107
|
// src/create-matcher.ts
|
|
@@ -182,11 +192,11 @@ function diffConfigs(config, prevConfig) {
|
|
|
182
192
|
if (!id)
|
|
183
193
|
return;
|
|
184
194
|
if (id === "recipes") {
|
|
185
|
-
const name = (0,
|
|
195
|
+
const name = (0, import_shared3.dashCase)(change.path.slice(1, 3).join("."));
|
|
186
196
|
affected.artifacts.add(name);
|
|
187
197
|
}
|
|
188
198
|
if (id === "patterns") {
|
|
189
|
-
const name = (0,
|
|
199
|
+
const name = (0, import_shared3.dashCase)(change.path.slice(0, 2).join("."));
|
|
190
200
|
affected.artifacts.add(name);
|
|
191
201
|
}
|
|
192
202
|
affected.artifacts.add(id);
|
|
@@ -448,7 +458,7 @@ async function getResolvedConfig(config, cwd) {
|
|
|
448
458
|
}
|
|
449
459
|
|
|
450
460
|
// src/resolve-config.ts
|
|
451
|
-
var
|
|
461
|
+
var import_shared7 = require("@pandacss/shared");
|
|
452
462
|
|
|
453
463
|
// src/bundled-preset.ts
|
|
454
464
|
var import_preset_base = require("@pandacss/preset-base");
|
|
@@ -464,6 +474,227 @@ var getBundledPreset = (preset) => {
|
|
|
464
474
|
return typeof preset === "string" && isBundledPreset(preset) ? bundledPresets[preset] : void 0;
|
|
465
475
|
};
|
|
466
476
|
|
|
477
|
+
// src/validate-config.ts
|
|
478
|
+
var import_logger2 = require("@pandacss/logger");
|
|
479
|
+
var import_shared6 = require("@pandacss/shared");
|
|
480
|
+
|
|
481
|
+
// src/validation/validate-artifact.ts
|
|
482
|
+
var validateArtifactNames = (names, addError) => {
|
|
483
|
+
names.recipes.forEach((recipeName) => {
|
|
484
|
+
if (names.slotRecipes.has(recipeName)) {
|
|
485
|
+
addError("recipes", `This recipe name is already used in \`config.theme.slotRecipes\`: ${recipeName}`);
|
|
486
|
+
}
|
|
487
|
+
if (names.patterns.has(recipeName)) {
|
|
488
|
+
addError("recipes", `This recipe name is already used in \`config.patterns\`: \`${recipeName}\``);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
names.slotRecipes.forEach((recipeName) => {
|
|
492
|
+
if (names.patterns.has(recipeName)) {
|
|
493
|
+
addError("recipes", `This recipe name is already used in \`config.patterns\`: ${recipeName}`);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
// src/validation/validate-breakpoints.ts
|
|
499
|
+
var import_shared4 = require("@pandacss/shared");
|
|
500
|
+
var validateBreakpoints = (breakpoints, addError) => {
|
|
501
|
+
if (!breakpoints)
|
|
502
|
+
return;
|
|
503
|
+
const units = /* @__PURE__ */ new Set();
|
|
504
|
+
const values = Object.values(breakpoints);
|
|
505
|
+
for (const value of values) {
|
|
506
|
+
const unit = (0, import_shared4.getUnit)(value) ?? "px";
|
|
507
|
+
units.add(unit);
|
|
508
|
+
}
|
|
509
|
+
if (units.size > 1) {
|
|
510
|
+
addError("breakpoints", `All breakpoints must use the same unit: \`${values.join(", ")}\``);
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
// src/validation/validate-condition.ts
|
|
515
|
+
var validateConditions = (conditions, addError) => {
|
|
516
|
+
if (!conditions)
|
|
517
|
+
return;
|
|
518
|
+
Object.values(conditions).forEach((condition) => {
|
|
519
|
+
if (!condition.startsWith("@") && !condition.includes("&")) {
|
|
520
|
+
addError("conditions", `Selectors should contain the \`&\` character: \`${condition}\``);
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// src/validation/validate-patterns.ts
|
|
526
|
+
var validatePatterns = (patterns, names) => {
|
|
527
|
+
if (!patterns)
|
|
528
|
+
return;
|
|
529
|
+
Object.keys(patterns).forEach((patternName) => {
|
|
530
|
+
names.patterns.add(patternName);
|
|
531
|
+
});
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// src/validation/validate-recipes.ts
|
|
535
|
+
var validateRecipes = (options) => {
|
|
536
|
+
const {
|
|
537
|
+
config: { theme },
|
|
538
|
+
artifacts
|
|
539
|
+
} = options;
|
|
540
|
+
if (!theme)
|
|
541
|
+
return;
|
|
542
|
+
if (theme.recipes) {
|
|
543
|
+
Object.keys(theme.recipes).forEach((recipeName) => {
|
|
544
|
+
artifacts.recipes.add(recipeName);
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
if (theme.slotRecipes) {
|
|
548
|
+
Object.keys(theme.slotRecipes).forEach((recipeName) => {
|
|
549
|
+
artifacts.slotRecipes.add(recipeName);
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
return artifacts;
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
// src/validation/validate-tokens.ts
|
|
556
|
+
var import_shared5 = require("@pandacss/shared");
|
|
557
|
+
|
|
558
|
+
// src/validation/get-final-paths.ts
|
|
559
|
+
var getFinalPaths = (paths) => {
|
|
560
|
+
paths.forEach((path2) => {
|
|
561
|
+
paths.forEach((potentialExtension) => {
|
|
562
|
+
if (potentialExtension.startsWith(path2 + ".")) {
|
|
563
|
+
paths.delete(path2);
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
return paths;
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
// src/validation/validate-token-references.ts
|
|
571
|
+
var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
|
|
572
|
+
refsByPath.forEach((refs, path2) => {
|
|
573
|
+
if (refs.has(path2)) {
|
|
574
|
+
addError("tokens", `Self token reference: \`${path2}\``);
|
|
575
|
+
}
|
|
576
|
+
const stack = [path2];
|
|
577
|
+
while (stack.length > 0) {
|
|
578
|
+
const current = stack.pop();
|
|
579
|
+
const value = valueAtPath.get(current);
|
|
580
|
+
if (!value) {
|
|
581
|
+
addError("tokens", `Missing token: \`${current}\` used in \`config.semanticTokens.${path2}\``);
|
|
582
|
+
}
|
|
583
|
+
const deps = refsByPath.get(current);
|
|
584
|
+
if (!deps)
|
|
585
|
+
continue;
|
|
586
|
+
for (const transitiveDep of deps) {
|
|
587
|
+
if (path2 === transitiveDep) {
|
|
588
|
+
addError("tokens", `Circular token reference: \`${transitiveDep}\` -> \`${current}\` -> ... -> \`${path2}\``);
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
stack.push(transitiveDep);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
// src/validation/validate-tokens.ts
|
|
598
|
+
var validateTokens = (options) => {
|
|
599
|
+
const {
|
|
600
|
+
config: { theme },
|
|
601
|
+
tokens: tokens2,
|
|
602
|
+
addError
|
|
603
|
+
} = options;
|
|
604
|
+
if (!theme)
|
|
605
|
+
return;
|
|
606
|
+
const { tokenNames, semanticTokenNames, valueAtPath, refsByPath } = tokens2;
|
|
607
|
+
if (theme.tokens) {
|
|
608
|
+
(0, import_shared5.traverse)(theme.tokens, (node) => {
|
|
609
|
+
if (node.depth >= 1) {
|
|
610
|
+
tokenNames.add(node.path);
|
|
611
|
+
valueAtPath.set(node.path, node.value);
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
const finalPaths = getFinalPaths(tokenNames);
|
|
615
|
+
finalPaths.forEach((path2) => {
|
|
616
|
+
if (!path2.includes("value")) {
|
|
617
|
+
addError("tokens", `Token paths must end with 'value': \`theme.tokens.${path2}\``);
|
|
618
|
+
}
|
|
619
|
+
const atPath = valueAtPath.get(path2);
|
|
620
|
+
if (typeof atPath === "string" && atPath.startsWith("{")) {
|
|
621
|
+
refsByPath.set(path2, /* @__PURE__ */ new Set([]));
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
if (theme.semanticTokens) {
|
|
626
|
+
(0, import_shared5.traverse)(theme.semanticTokens, (node) => {
|
|
627
|
+
if (node.depth >= 1) {
|
|
628
|
+
semanticTokenNames.add(node.path);
|
|
629
|
+
valueAtPath.set(node.path, node.value);
|
|
630
|
+
if (typeof node.value === "string" && node.value.startsWith("{") && node.path.includes("value")) {
|
|
631
|
+
const tokenPath = node.path.split(".value")[0];
|
|
632
|
+
if (!refsByPath.has(tokenPath)) {
|
|
633
|
+
refsByPath.set(tokenPath, /* @__PURE__ */ new Set());
|
|
634
|
+
}
|
|
635
|
+
const values = refsByPath.get(tokenPath);
|
|
636
|
+
const tokenRef = node.value.slice(1, -1);
|
|
637
|
+
values.add(tokenRef);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
const finalPaths = getFinalPaths(semanticTokenNames);
|
|
642
|
+
finalPaths.forEach((path2) => {
|
|
643
|
+
if (!path2.includes("value")) {
|
|
644
|
+
addError("tokens", `Semantic token paths must contain 'value': \`theme.semanticTokens.${path2}\``);
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
validateTokenReferences(valueAtPath, refsByPath, addError);
|
|
648
|
+
}
|
|
649
|
+
semanticTokenNames.forEach((semanticTokenName) => {
|
|
650
|
+
if (tokenNames.has(semanticTokenName)) {
|
|
651
|
+
addError("tokens", `This token name is already used in \`config.theme.token\`: \`${semanticTokenName}\``);
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
// src/validate-config.ts
|
|
657
|
+
var validateConfig = (config) => {
|
|
658
|
+
if (config.validation === "none")
|
|
659
|
+
return;
|
|
660
|
+
const warnings = /* @__PURE__ */ new Set();
|
|
661
|
+
const addError = (scope, message) => {
|
|
662
|
+
if (config.validation === "warn") {
|
|
663
|
+
warnings.add(`[${scope}]: ` + message);
|
|
664
|
+
} else {
|
|
665
|
+
throw new import_shared6.PandaError("CONFIG_ERROR", `[${scope}]: ` + message);
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
validateBreakpoints(config.theme?.breakpoints, addError);
|
|
669
|
+
validateConditions(config.conditions, addError);
|
|
670
|
+
const artifacts = {
|
|
671
|
+
recipes: /* @__PURE__ */ new Set(),
|
|
672
|
+
slotRecipes: /* @__PURE__ */ new Set(),
|
|
673
|
+
patterns: /* @__PURE__ */ new Set()
|
|
674
|
+
};
|
|
675
|
+
const tokens2 = {
|
|
676
|
+
tokenNames: /* @__PURE__ */ new Set(),
|
|
677
|
+
semanticTokenNames: /* @__PURE__ */ new Set(),
|
|
678
|
+
valueAtPath: /* @__PURE__ */ new Map(),
|
|
679
|
+
refsByPath: /* @__PURE__ */ new Map()
|
|
680
|
+
};
|
|
681
|
+
if (config.theme) {
|
|
682
|
+
validateTokens({ config, tokens: tokens2, addError });
|
|
683
|
+
validateRecipes({ config, tokens: tokens2, artifacts, addError });
|
|
684
|
+
}
|
|
685
|
+
validatePatterns(config.patterns, artifacts);
|
|
686
|
+
validateArtifactNames(artifacts, addError);
|
|
687
|
+
if (warnings.size) {
|
|
688
|
+
import_logger2.logger.warn(
|
|
689
|
+
"config",
|
|
690
|
+
`\u26A0\uFE0F Invalid config:
|
|
691
|
+
${Array.from(warnings).map((err) => "- " + err).join("\n")}
|
|
692
|
+
`
|
|
693
|
+
);
|
|
694
|
+
return warnings;
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
|
|
467
698
|
// src/resolve-config.ts
|
|
468
699
|
async function resolveConfig(result, cwd) {
|
|
469
700
|
const presets = /* @__PURE__ */ new Set();
|
|
@@ -478,12 +709,16 @@ async function resolveConfig(result, cwd) {
|
|
|
478
709
|
presets.add(import_preset_panda.preset);
|
|
479
710
|
}
|
|
480
711
|
result.config.presets = Array.from(presets);
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
const
|
|
712
|
+
const config = await getResolvedConfig(result.config, cwd);
|
|
713
|
+
validateConfig(config);
|
|
714
|
+
const { hooks = {} } = result.config;
|
|
715
|
+
const loadConfigResult = {
|
|
716
|
+
...result,
|
|
717
|
+
config
|
|
718
|
+
};
|
|
484
719
|
await hooks["config:resolved"]?.({ conf: loadConfigResult });
|
|
485
|
-
const serialized = (0,
|
|
486
|
-
const deserialize = () => (0,
|
|
720
|
+
const serialized = (0, import_shared7.stringifyJson)(loadConfigResult.config);
|
|
721
|
+
const deserialize = () => (0, import_shared7.parseJson)(serialized);
|
|
487
722
|
return { ...loadConfigResult, serialized, deserialize, hooks };
|
|
488
723
|
}
|
|
489
724
|
|
package/dist/index.mjs
CHANGED
|
@@ -3,28 +3,40 @@ import {
|
|
|
3
3
|
} from "./chunk-PROY5XLZ.mjs";
|
|
4
4
|
import {
|
|
5
5
|
diffConfigs
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-DQCK3AP6.mjs";
|
|
7
7
|
import {
|
|
8
8
|
resolveTsPathPattern
|
|
9
9
|
} from "./chunk-RPIVZP2I.mjs";
|
|
10
10
|
|
|
11
11
|
// src/bundle-config.ts
|
|
12
|
-
import { ConfigError, ConfigNotFoundError } from "@pandacss/error";
|
|
13
12
|
import { logger } from "@pandacss/logger";
|
|
13
|
+
import { PandaError as PandaError2 } from "@pandacss/shared";
|
|
14
14
|
import { bundleNRequire } from "bundle-n-require";
|
|
15
15
|
|
|
16
16
|
// src/find-config.ts
|
|
17
|
+
import { PandaError } from "@pandacss/shared";
|
|
17
18
|
import findUp from "escalade/sync";
|
|
18
19
|
import { resolve } from "path";
|
|
20
|
+
|
|
21
|
+
// src/is-panda-config.ts
|
|
19
22
|
var configs = [".ts", ".js", ".mts", ".mjs", ".cts", ".cjs"];
|
|
20
23
|
var pandaConfigRegex = new RegExp(`panda.config(${configs.join("|")})$`);
|
|
21
24
|
var isPandaConfig = (file) => pandaConfigRegex.test(file);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
|
|
26
|
+
// src/find-config.ts
|
|
27
|
+
function findConfig(options) {
|
|
28
|
+
const { cwd = process.cwd(), file } = options;
|
|
29
|
+
if (file) {
|
|
25
30
|
return resolve(cwd, file);
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
}
|
|
32
|
+
const configPath = findUp(cwd, (_dir, paths) => paths.find(isPandaConfig));
|
|
33
|
+
if (!configPath) {
|
|
34
|
+
throw new PandaError(
|
|
35
|
+
"CONFIG_NOT_FOUND",
|
|
36
|
+
`Cannot find config file \`panda.config.{ts,js,mjs,mts}\`. Did you forget to run \`panda init\`?`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return configPath;
|
|
28
40
|
}
|
|
29
41
|
|
|
30
42
|
// src/bundle-config.ts
|
|
@@ -41,15 +53,13 @@ async function bundle(filepath, cwd) {
|
|
|
41
53
|
async function bundleConfig(options) {
|
|
42
54
|
const { cwd, file } = options;
|
|
43
55
|
const filePath = findConfig({ cwd, file });
|
|
44
|
-
if (!filePath) {
|
|
45
|
-
throw new ConfigNotFoundError();
|
|
46
|
-
}
|
|
47
56
|
logger.debug("config:path", filePath);
|
|
48
57
|
const result = await bundle(filePath, cwd);
|
|
49
58
|
if (typeof result.config !== "object") {
|
|
50
|
-
throw new
|
|
59
|
+
throw new PandaError2("CONFIG_ERROR", `\u{1F4A5} Config must export or return an object.`);
|
|
51
60
|
}
|
|
52
61
|
result.config.outdir ??= "styled-system";
|
|
62
|
+
result.config.validation ??= "error";
|
|
53
63
|
return {
|
|
54
64
|
...result,
|
|
55
65
|
config: result.config,
|
|
@@ -218,6 +228,227 @@ var getBundledPreset = (preset) => {
|
|
|
218
228
|
return typeof preset === "string" && isBundledPreset(preset) ? bundledPresets[preset] : void 0;
|
|
219
229
|
};
|
|
220
230
|
|
|
231
|
+
// src/validate-config.ts
|
|
232
|
+
import { logger as logger2 } from "@pandacss/logger";
|
|
233
|
+
import { PandaError as PandaError3 } from "@pandacss/shared";
|
|
234
|
+
|
|
235
|
+
// src/validation/validate-artifact.ts
|
|
236
|
+
var validateArtifactNames = (names, addError) => {
|
|
237
|
+
names.recipes.forEach((recipeName) => {
|
|
238
|
+
if (names.slotRecipes.has(recipeName)) {
|
|
239
|
+
addError("recipes", `This recipe name is already used in \`config.theme.slotRecipes\`: ${recipeName}`);
|
|
240
|
+
}
|
|
241
|
+
if (names.patterns.has(recipeName)) {
|
|
242
|
+
addError("recipes", `This recipe name is already used in \`config.patterns\`: \`${recipeName}\``);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
names.slotRecipes.forEach((recipeName) => {
|
|
246
|
+
if (names.patterns.has(recipeName)) {
|
|
247
|
+
addError("recipes", `This recipe name is already used in \`config.patterns\`: ${recipeName}`);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// src/validation/validate-breakpoints.ts
|
|
253
|
+
import { getUnit } from "@pandacss/shared";
|
|
254
|
+
var validateBreakpoints = (breakpoints, addError) => {
|
|
255
|
+
if (!breakpoints)
|
|
256
|
+
return;
|
|
257
|
+
const units = /* @__PURE__ */ new Set();
|
|
258
|
+
const values = Object.values(breakpoints);
|
|
259
|
+
for (const value of values) {
|
|
260
|
+
const unit = getUnit(value) ?? "px";
|
|
261
|
+
units.add(unit);
|
|
262
|
+
}
|
|
263
|
+
if (units.size > 1) {
|
|
264
|
+
addError("breakpoints", `All breakpoints must use the same unit: \`${values.join(", ")}\``);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// src/validation/validate-condition.ts
|
|
269
|
+
var validateConditions = (conditions, addError) => {
|
|
270
|
+
if (!conditions)
|
|
271
|
+
return;
|
|
272
|
+
Object.values(conditions).forEach((condition) => {
|
|
273
|
+
if (!condition.startsWith("@") && !condition.includes("&")) {
|
|
274
|
+
addError("conditions", `Selectors should contain the \`&\` character: \`${condition}\``);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// src/validation/validate-patterns.ts
|
|
280
|
+
var validatePatterns = (patterns, names) => {
|
|
281
|
+
if (!patterns)
|
|
282
|
+
return;
|
|
283
|
+
Object.keys(patterns).forEach((patternName) => {
|
|
284
|
+
names.patterns.add(patternName);
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// src/validation/validate-recipes.ts
|
|
289
|
+
var validateRecipes = (options) => {
|
|
290
|
+
const {
|
|
291
|
+
config: { theme },
|
|
292
|
+
artifacts
|
|
293
|
+
} = options;
|
|
294
|
+
if (!theme)
|
|
295
|
+
return;
|
|
296
|
+
if (theme.recipes) {
|
|
297
|
+
Object.keys(theme.recipes).forEach((recipeName) => {
|
|
298
|
+
artifacts.recipes.add(recipeName);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
if (theme.slotRecipes) {
|
|
302
|
+
Object.keys(theme.slotRecipes).forEach((recipeName) => {
|
|
303
|
+
artifacts.slotRecipes.add(recipeName);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return artifacts;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// src/validation/validate-tokens.ts
|
|
310
|
+
import { traverse } from "@pandacss/shared";
|
|
311
|
+
|
|
312
|
+
// src/validation/get-final-paths.ts
|
|
313
|
+
var getFinalPaths = (paths) => {
|
|
314
|
+
paths.forEach((path2) => {
|
|
315
|
+
paths.forEach((potentialExtension) => {
|
|
316
|
+
if (potentialExtension.startsWith(path2 + ".")) {
|
|
317
|
+
paths.delete(path2);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
return paths;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// src/validation/validate-token-references.ts
|
|
325
|
+
var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
|
|
326
|
+
refsByPath.forEach((refs, path2) => {
|
|
327
|
+
if (refs.has(path2)) {
|
|
328
|
+
addError("tokens", `Self token reference: \`${path2}\``);
|
|
329
|
+
}
|
|
330
|
+
const stack = [path2];
|
|
331
|
+
while (stack.length > 0) {
|
|
332
|
+
const current = stack.pop();
|
|
333
|
+
const value = valueAtPath.get(current);
|
|
334
|
+
if (!value) {
|
|
335
|
+
addError("tokens", `Missing token: \`${current}\` used in \`config.semanticTokens.${path2}\``);
|
|
336
|
+
}
|
|
337
|
+
const deps = refsByPath.get(current);
|
|
338
|
+
if (!deps)
|
|
339
|
+
continue;
|
|
340
|
+
for (const transitiveDep of deps) {
|
|
341
|
+
if (path2 === transitiveDep) {
|
|
342
|
+
addError("tokens", `Circular token reference: \`${transitiveDep}\` -> \`${current}\` -> ... -> \`${path2}\``);
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
stack.push(transitiveDep);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
// src/validation/validate-tokens.ts
|
|
352
|
+
var validateTokens = (options) => {
|
|
353
|
+
const {
|
|
354
|
+
config: { theme },
|
|
355
|
+
tokens,
|
|
356
|
+
addError
|
|
357
|
+
} = options;
|
|
358
|
+
if (!theme)
|
|
359
|
+
return;
|
|
360
|
+
const { tokenNames, semanticTokenNames, valueAtPath, refsByPath } = tokens;
|
|
361
|
+
if (theme.tokens) {
|
|
362
|
+
traverse(theme.tokens, (node) => {
|
|
363
|
+
if (node.depth >= 1) {
|
|
364
|
+
tokenNames.add(node.path);
|
|
365
|
+
valueAtPath.set(node.path, node.value);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
const finalPaths = getFinalPaths(tokenNames);
|
|
369
|
+
finalPaths.forEach((path2) => {
|
|
370
|
+
if (!path2.includes("value")) {
|
|
371
|
+
addError("tokens", `Token paths must end with 'value': \`theme.tokens.${path2}\``);
|
|
372
|
+
}
|
|
373
|
+
const atPath = valueAtPath.get(path2);
|
|
374
|
+
if (typeof atPath === "string" && atPath.startsWith("{")) {
|
|
375
|
+
refsByPath.set(path2, /* @__PURE__ */ new Set([]));
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
if (theme.semanticTokens) {
|
|
380
|
+
traverse(theme.semanticTokens, (node) => {
|
|
381
|
+
if (node.depth >= 1) {
|
|
382
|
+
semanticTokenNames.add(node.path);
|
|
383
|
+
valueAtPath.set(node.path, node.value);
|
|
384
|
+
if (typeof node.value === "string" && node.value.startsWith("{") && node.path.includes("value")) {
|
|
385
|
+
const tokenPath = node.path.split(".value")[0];
|
|
386
|
+
if (!refsByPath.has(tokenPath)) {
|
|
387
|
+
refsByPath.set(tokenPath, /* @__PURE__ */ new Set());
|
|
388
|
+
}
|
|
389
|
+
const values = refsByPath.get(tokenPath);
|
|
390
|
+
const tokenRef = node.value.slice(1, -1);
|
|
391
|
+
values.add(tokenRef);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
const finalPaths = getFinalPaths(semanticTokenNames);
|
|
396
|
+
finalPaths.forEach((path2) => {
|
|
397
|
+
if (!path2.includes("value")) {
|
|
398
|
+
addError("tokens", `Semantic token paths must contain 'value': \`theme.semanticTokens.${path2}\``);
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
validateTokenReferences(valueAtPath, refsByPath, addError);
|
|
402
|
+
}
|
|
403
|
+
semanticTokenNames.forEach((semanticTokenName) => {
|
|
404
|
+
if (tokenNames.has(semanticTokenName)) {
|
|
405
|
+
addError("tokens", `This token name is already used in \`config.theme.token\`: \`${semanticTokenName}\``);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
// src/validate-config.ts
|
|
411
|
+
var validateConfig = (config) => {
|
|
412
|
+
if (config.validation === "none")
|
|
413
|
+
return;
|
|
414
|
+
const warnings = /* @__PURE__ */ new Set();
|
|
415
|
+
const addError = (scope, message) => {
|
|
416
|
+
if (config.validation === "warn") {
|
|
417
|
+
warnings.add(`[${scope}]: ` + message);
|
|
418
|
+
} else {
|
|
419
|
+
throw new PandaError3("CONFIG_ERROR", `[${scope}]: ` + message);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
validateBreakpoints(config.theme?.breakpoints, addError);
|
|
423
|
+
validateConditions(config.conditions, addError);
|
|
424
|
+
const artifacts = {
|
|
425
|
+
recipes: /* @__PURE__ */ new Set(),
|
|
426
|
+
slotRecipes: /* @__PURE__ */ new Set(),
|
|
427
|
+
patterns: /* @__PURE__ */ new Set()
|
|
428
|
+
};
|
|
429
|
+
const tokens = {
|
|
430
|
+
tokenNames: /* @__PURE__ */ new Set(),
|
|
431
|
+
semanticTokenNames: /* @__PURE__ */ new Set(),
|
|
432
|
+
valueAtPath: /* @__PURE__ */ new Map(),
|
|
433
|
+
refsByPath: /* @__PURE__ */ new Map()
|
|
434
|
+
};
|
|
435
|
+
if (config.theme) {
|
|
436
|
+
validateTokens({ config, tokens, addError });
|
|
437
|
+
validateRecipes({ config, tokens, artifacts, addError });
|
|
438
|
+
}
|
|
439
|
+
validatePatterns(config.patterns, artifacts);
|
|
440
|
+
validateArtifactNames(artifacts, addError);
|
|
441
|
+
if (warnings.size) {
|
|
442
|
+
logger2.warn(
|
|
443
|
+
"config",
|
|
444
|
+
`\u26A0\uFE0F Invalid config:
|
|
445
|
+
${Array.from(warnings).map((err) => "- " + err).join("\n")}
|
|
446
|
+
`
|
|
447
|
+
);
|
|
448
|
+
return warnings;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
|
|
221
452
|
// src/resolve-config.ts
|
|
222
453
|
async function resolveConfig(result, cwd) {
|
|
223
454
|
const presets = /* @__PURE__ */ new Set();
|
|
@@ -232,9 +463,13 @@ async function resolveConfig(result, cwd) {
|
|
|
232
463
|
presets.add(presetPanda);
|
|
233
464
|
}
|
|
234
465
|
result.config.presets = Array.from(presets);
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
const
|
|
466
|
+
const config = await getResolvedConfig(result.config, cwd);
|
|
467
|
+
validateConfig(config);
|
|
468
|
+
const { hooks = {} } = result.config;
|
|
469
|
+
const loadConfigResult = {
|
|
470
|
+
...result,
|
|
471
|
+
config
|
|
472
|
+
};
|
|
238
473
|
await hooks["config:resolved"]?.({ conf: loadConfigResult });
|
|
239
474
|
const serialized = stringifyJson(loadConfigResult.config);
|
|
240
475
|
const deserialize = () => parseJson(serialized);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/config",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20240128182812",
|
|
4
4
|
"description": "Find and load panda config",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -64,12 +64,11 @@
|
|
|
64
64
|
"merge-anything": "^5.1.7",
|
|
65
65
|
"microdiff": "^1.3.2",
|
|
66
66
|
"typescript": "^5.3.3",
|
|
67
|
-
"@pandacss/
|
|
68
|
-
"@pandacss/
|
|
69
|
-
"@pandacss/preset-
|
|
70
|
-
"@pandacss/
|
|
71
|
-
"@pandacss/
|
|
72
|
-
"@pandacss/types": "0.0.0-dev-20240128131310"
|
|
67
|
+
"@pandacss/logger": "0.0.0-dev-20240128182812",
|
|
68
|
+
"@pandacss/preset-base": "0.0.0-dev-20240128182812",
|
|
69
|
+
"@pandacss/preset-panda": "0.0.0-dev-20240128182812",
|
|
70
|
+
"@pandacss/shared": "0.0.0-dev-20240128182812",
|
|
71
|
+
"@pandacss/types": "0.0.0-dev-20240128182812"
|
|
73
72
|
},
|
|
74
73
|
"devDependencies": {
|
|
75
74
|
"pkg-types": "1.0.3"
|
|
File without changes
|