@pandacss/config 0.0.0-dev-20240128131310 → 0.0.0-dev-20240128205559
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/{chunk-TP2SOWHU.mjs → chunk-WJAK5RTK.mjs} +9 -1
- package/dist/diff-config.d.mts +0 -2
- package/dist/diff-config.d.ts +0 -2
- package/dist/diff-config.js +9 -1
- 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 +263 -20
- package/dist/index.mjs +249 -14
- package/package.json +6 -7
|
@@ -29,7 +29,15 @@ function createMatcher(id, patterns) {
|
|
|
29
29
|
// src/config-deps.ts
|
|
30
30
|
var all = ["outdir", "forceConsistentTypeExtension", "outExtension"];
|
|
31
31
|
var format = ["syntax", "hash", "prefix", "separator"];
|
|
32
|
-
var tokens = [
|
|
32
|
+
var tokens = [
|
|
33
|
+
"utilities",
|
|
34
|
+
"conditions",
|
|
35
|
+
"theme.tokens",
|
|
36
|
+
"theme.semanticTokens",
|
|
37
|
+
"theme.breakpoints",
|
|
38
|
+
"theme.containerNames",
|
|
39
|
+
"theme.containerSizes"
|
|
40
|
+
];
|
|
33
41
|
var jsx = ["jsxFramework", "jsxFactory", "jsxStyleProps", "syntax"];
|
|
34
42
|
var css = ["layers", "optimize", "minify"];
|
|
35
43
|
var common = tokens.concat(jsx, format);
|
package/dist/diff-config.d.mts
CHANGED
package/dist/diff-config.d.ts
CHANGED
package/dist/diff-config.js
CHANGED
|
@@ -63,7 +63,15 @@ function createMatcher(id, patterns) {
|
|
|
63
63
|
// src/config-deps.ts
|
|
64
64
|
var all = ["outdir", "forceConsistentTypeExtension", "outExtension"];
|
|
65
65
|
var format = ["syntax", "hash", "prefix", "separator"];
|
|
66
|
-
var tokens = [
|
|
66
|
+
var tokens = [
|
|
67
|
+
"utilities",
|
|
68
|
+
"conditions",
|
|
69
|
+
"theme.tokens",
|
|
70
|
+
"theme.semanticTokens",
|
|
71
|
+
"theme.breakpoints",
|
|
72
|
+
"theme.containerNames",
|
|
73
|
+
"theme.containerSizes"
|
|
74
|
+
];
|
|
67
75
|
var jsx = ["jsxFramework", "jsxFactory", "jsxStyleProps", "syntax"];
|
|
68
76
|
var css = ["layers", "optimize", "minify"];
|
|
69
77
|
var common = tokens.concat(jsx, format);
|
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
|
|
@@ -121,7 +131,15 @@ function createMatcher(id, patterns) {
|
|
|
121
131
|
// src/config-deps.ts
|
|
122
132
|
var all = ["outdir", "forceConsistentTypeExtension", "outExtension"];
|
|
123
133
|
var format = ["syntax", "hash", "prefix", "separator"];
|
|
124
|
-
var tokens = [
|
|
134
|
+
var tokens = [
|
|
135
|
+
"utilities",
|
|
136
|
+
"conditions",
|
|
137
|
+
"theme.tokens",
|
|
138
|
+
"theme.semanticTokens",
|
|
139
|
+
"theme.breakpoints",
|
|
140
|
+
"theme.containerNames",
|
|
141
|
+
"theme.containerSizes"
|
|
142
|
+
];
|
|
125
143
|
var jsx = ["jsxFramework", "jsxFactory", "jsxStyleProps", "syntax"];
|
|
126
144
|
var css = ["layers", "optimize", "minify"];
|
|
127
145
|
var common = tokens.concat(jsx, format);
|
|
@@ -182,11 +200,11 @@ function diffConfigs(config, prevConfig) {
|
|
|
182
200
|
if (!id)
|
|
183
201
|
return;
|
|
184
202
|
if (id === "recipes") {
|
|
185
|
-
const name = (0,
|
|
203
|
+
const name = (0, import_shared3.dashCase)(change.path.slice(1, 3).join("."));
|
|
186
204
|
affected.artifacts.add(name);
|
|
187
205
|
}
|
|
188
206
|
if (id === "patterns") {
|
|
189
|
-
const name = (0,
|
|
207
|
+
const name = (0, import_shared3.dashCase)(change.path.slice(0, 2).join("."));
|
|
190
208
|
affected.artifacts.add(name);
|
|
191
209
|
}
|
|
192
210
|
affected.artifacts.add(id);
|
|
@@ -448,7 +466,7 @@ async function getResolvedConfig(config, cwd) {
|
|
|
448
466
|
}
|
|
449
467
|
|
|
450
468
|
// src/resolve-config.ts
|
|
451
|
-
var
|
|
469
|
+
var import_shared7 = require("@pandacss/shared");
|
|
452
470
|
|
|
453
471
|
// src/bundled-preset.ts
|
|
454
472
|
var import_preset_base = require("@pandacss/preset-base");
|
|
@@ -464,6 +482,227 @@ var getBundledPreset = (preset) => {
|
|
|
464
482
|
return typeof preset === "string" && isBundledPreset(preset) ? bundledPresets[preset] : void 0;
|
|
465
483
|
};
|
|
466
484
|
|
|
485
|
+
// src/validate-config.ts
|
|
486
|
+
var import_logger2 = require("@pandacss/logger");
|
|
487
|
+
var import_shared6 = require("@pandacss/shared");
|
|
488
|
+
|
|
489
|
+
// src/validation/validate-artifact.ts
|
|
490
|
+
var validateArtifactNames = (names, addError) => {
|
|
491
|
+
names.recipes.forEach((recipeName) => {
|
|
492
|
+
if (names.slotRecipes.has(recipeName)) {
|
|
493
|
+
addError("recipes", `This recipe name is already used in \`config.theme.slotRecipes\`: ${recipeName}`);
|
|
494
|
+
}
|
|
495
|
+
if (names.patterns.has(recipeName)) {
|
|
496
|
+
addError("recipes", `This recipe name is already used in \`config.patterns\`: \`${recipeName}\``);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
names.slotRecipes.forEach((recipeName) => {
|
|
500
|
+
if (names.patterns.has(recipeName)) {
|
|
501
|
+
addError("recipes", `This recipe name is already used in \`config.patterns\`: ${recipeName}`);
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
// src/validation/validate-breakpoints.ts
|
|
507
|
+
var import_shared4 = require("@pandacss/shared");
|
|
508
|
+
var validateBreakpoints = (breakpoints, addError) => {
|
|
509
|
+
if (!breakpoints)
|
|
510
|
+
return;
|
|
511
|
+
const units = /* @__PURE__ */ new Set();
|
|
512
|
+
const values = Object.values(breakpoints);
|
|
513
|
+
for (const value of values) {
|
|
514
|
+
const unit = (0, import_shared4.getUnit)(value) ?? "px";
|
|
515
|
+
units.add(unit);
|
|
516
|
+
}
|
|
517
|
+
if (units.size > 1) {
|
|
518
|
+
addError("breakpoints", `All breakpoints must use the same unit: \`${values.join(", ")}\``);
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
// src/validation/validate-condition.ts
|
|
523
|
+
var validateConditions = (conditions, addError) => {
|
|
524
|
+
if (!conditions)
|
|
525
|
+
return;
|
|
526
|
+
Object.values(conditions).forEach((condition) => {
|
|
527
|
+
if (!condition.startsWith("@") && !condition.includes("&")) {
|
|
528
|
+
addError("conditions", `Selectors should contain the \`&\` character: \`${condition}\``);
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
// src/validation/validate-patterns.ts
|
|
534
|
+
var validatePatterns = (patterns, names) => {
|
|
535
|
+
if (!patterns)
|
|
536
|
+
return;
|
|
537
|
+
Object.keys(patterns).forEach((patternName) => {
|
|
538
|
+
names.patterns.add(patternName);
|
|
539
|
+
});
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
// src/validation/validate-recipes.ts
|
|
543
|
+
var validateRecipes = (options) => {
|
|
544
|
+
const {
|
|
545
|
+
config: { theme },
|
|
546
|
+
artifacts
|
|
547
|
+
} = options;
|
|
548
|
+
if (!theme)
|
|
549
|
+
return;
|
|
550
|
+
if (theme.recipes) {
|
|
551
|
+
Object.keys(theme.recipes).forEach((recipeName) => {
|
|
552
|
+
artifacts.recipes.add(recipeName);
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
if (theme.slotRecipes) {
|
|
556
|
+
Object.keys(theme.slotRecipes).forEach((recipeName) => {
|
|
557
|
+
artifacts.slotRecipes.add(recipeName);
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
return artifacts;
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
// src/validation/validate-tokens.ts
|
|
564
|
+
var import_shared5 = require("@pandacss/shared");
|
|
565
|
+
|
|
566
|
+
// src/validation/get-final-paths.ts
|
|
567
|
+
var getFinalPaths = (paths) => {
|
|
568
|
+
paths.forEach((path2) => {
|
|
569
|
+
paths.forEach((potentialExtension) => {
|
|
570
|
+
if (potentialExtension.startsWith(path2 + ".")) {
|
|
571
|
+
paths.delete(path2);
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
return paths;
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
// src/validation/validate-token-references.ts
|
|
579
|
+
var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
|
|
580
|
+
refsByPath.forEach((refs, path2) => {
|
|
581
|
+
if (refs.has(path2)) {
|
|
582
|
+
addError("tokens", `Self token reference: \`${path2}\``);
|
|
583
|
+
}
|
|
584
|
+
const stack = [path2];
|
|
585
|
+
while (stack.length > 0) {
|
|
586
|
+
const current = stack.pop();
|
|
587
|
+
const value = valueAtPath.get(current);
|
|
588
|
+
if (!value) {
|
|
589
|
+
addError("tokens", `Missing token: \`${current}\` used in \`config.semanticTokens.${path2}\``);
|
|
590
|
+
}
|
|
591
|
+
const deps = refsByPath.get(current);
|
|
592
|
+
if (!deps)
|
|
593
|
+
continue;
|
|
594
|
+
for (const transitiveDep of deps) {
|
|
595
|
+
if (path2 === transitiveDep) {
|
|
596
|
+
addError("tokens", `Circular token reference: \`${transitiveDep}\` -> \`${current}\` -> ... -> \`${path2}\``);
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
stack.push(transitiveDep);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
// src/validation/validate-tokens.ts
|
|
606
|
+
var validateTokens = (options) => {
|
|
607
|
+
const {
|
|
608
|
+
config: { theme },
|
|
609
|
+
tokens: tokens2,
|
|
610
|
+
addError
|
|
611
|
+
} = options;
|
|
612
|
+
if (!theme)
|
|
613
|
+
return;
|
|
614
|
+
const { tokenNames, semanticTokenNames, valueAtPath, refsByPath } = tokens2;
|
|
615
|
+
if (theme.tokens) {
|
|
616
|
+
(0, import_shared5.traverse)(theme.tokens, (node) => {
|
|
617
|
+
if (node.depth >= 1) {
|
|
618
|
+
tokenNames.add(node.path);
|
|
619
|
+
valueAtPath.set(node.path, node.value);
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
const finalPaths = getFinalPaths(tokenNames);
|
|
623
|
+
finalPaths.forEach((path2) => {
|
|
624
|
+
if (!path2.includes("value")) {
|
|
625
|
+
addError("tokens", `Token paths must end with 'value': \`theme.tokens.${path2}\``);
|
|
626
|
+
}
|
|
627
|
+
const atPath = valueAtPath.get(path2);
|
|
628
|
+
if (typeof atPath === "string" && atPath.startsWith("{")) {
|
|
629
|
+
refsByPath.set(path2, /* @__PURE__ */ new Set([]));
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
if (theme.semanticTokens) {
|
|
634
|
+
(0, import_shared5.traverse)(theme.semanticTokens, (node) => {
|
|
635
|
+
if (node.depth >= 1) {
|
|
636
|
+
semanticTokenNames.add(node.path);
|
|
637
|
+
valueAtPath.set(node.path, node.value);
|
|
638
|
+
if (typeof node.value === "string" && node.value.startsWith("{") && node.path.includes("value")) {
|
|
639
|
+
const tokenPath = node.path.split(".value")[0];
|
|
640
|
+
if (!refsByPath.has(tokenPath)) {
|
|
641
|
+
refsByPath.set(tokenPath, /* @__PURE__ */ new Set());
|
|
642
|
+
}
|
|
643
|
+
const values = refsByPath.get(tokenPath);
|
|
644
|
+
const tokenRef = node.value.slice(1, -1);
|
|
645
|
+
values.add(tokenRef);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
const finalPaths = getFinalPaths(semanticTokenNames);
|
|
650
|
+
finalPaths.forEach((path2) => {
|
|
651
|
+
if (!path2.includes("value")) {
|
|
652
|
+
addError("tokens", `Semantic token paths must contain 'value': \`theme.semanticTokens.${path2}\``);
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
validateTokenReferences(valueAtPath, refsByPath, addError);
|
|
656
|
+
}
|
|
657
|
+
semanticTokenNames.forEach((semanticTokenName) => {
|
|
658
|
+
if (tokenNames.has(semanticTokenName)) {
|
|
659
|
+
addError("tokens", `This token name is already used in \`config.theme.token\`: \`${semanticTokenName}\``);
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
// src/validate-config.ts
|
|
665
|
+
var validateConfig = (config) => {
|
|
666
|
+
if (config.validation === "none")
|
|
667
|
+
return;
|
|
668
|
+
const warnings = /* @__PURE__ */ new Set();
|
|
669
|
+
const addError = (scope, message) => {
|
|
670
|
+
if (config.validation === "warn") {
|
|
671
|
+
warnings.add(`[${scope}]: ` + message);
|
|
672
|
+
} else {
|
|
673
|
+
throw new import_shared6.PandaError("CONFIG_ERROR", `[${scope}]: ` + message);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
validateBreakpoints(config.theme?.breakpoints, addError);
|
|
677
|
+
validateConditions(config.conditions, addError);
|
|
678
|
+
const artifacts = {
|
|
679
|
+
recipes: /* @__PURE__ */ new Set(),
|
|
680
|
+
slotRecipes: /* @__PURE__ */ new Set(),
|
|
681
|
+
patterns: /* @__PURE__ */ new Set()
|
|
682
|
+
};
|
|
683
|
+
const tokens2 = {
|
|
684
|
+
tokenNames: /* @__PURE__ */ new Set(),
|
|
685
|
+
semanticTokenNames: /* @__PURE__ */ new Set(),
|
|
686
|
+
valueAtPath: /* @__PURE__ */ new Map(),
|
|
687
|
+
refsByPath: /* @__PURE__ */ new Map()
|
|
688
|
+
};
|
|
689
|
+
if (config.theme) {
|
|
690
|
+
validateTokens({ config, tokens: tokens2, addError });
|
|
691
|
+
validateRecipes({ config, tokens: tokens2, artifacts, addError });
|
|
692
|
+
}
|
|
693
|
+
validatePatterns(config.patterns, artifacts);
|
|
694
|
+
validateArtifactNames(artifacts, addError);
|
|
695
|
+
if (warnings.size) {
|
|
696
|
+
import_logger2.logger.warn(
|
|
697
|
+
"config",
|
|
698
|
+
`\u26A0\uFE0F Invalid config:
|
|
699
|
+
${Array.from(warnings).map((err) => "- " + err).join("\n")}
|
|
700
|
+
`
|
|
701
|
+
);
|
|
702
|
+
return warnings;
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
|
|
467
706
|
// src/resolve-config.ts
|
|
468
707
|
async function resolveConfig(result, cwd) {
|
|
469
708
|
const presets = /* @__PURE__ */ new Set();
|
|
@@ -478,12 +717,16 @@ async function resolveConfig(result, cwd) {
|
|
|
478
717
|
presets.add(import_preset_panda.preset);
|
|
479
718
|
}
|
|
480
719
|
result.config.presets = Array.from(presets);
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
const
|
|
720
|
+
const config = await getResolvedConfig(result.config, cwd);
|
|
721
|
+
validateConfig(config);
|
|
722
|
+
const { hooks = {} } = result.config;
|
|
723
|
+
const loadConfigResult = {
|
|
724
|
+
...result,
|
|
725
|
+
config
|
|
726
|
+
};
|
|
484
727
|
await hooks["config:resolved"]?.({ conf: loadConfigResult });
|
|
485
|
-
const serialized = (0,
|
|
486
|
-
const deserialize = () => (0,
|
|
728
|
+
const serialized = (0, import_shared7.stringifyJson)(loadConfigResult.config);
|
|
729
|
+
const deserialize = () => (0, import_shared7.parseJson)(serialized);
|
|
487
730
|
return { ...loadConfigResult, serialized, deserialize, hooks };
|
|
488
731
|
}
|
|
489
732
|
|
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-WJAK5RTK.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-20240128205559",
|
|
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-20240128205559",
|
|
68
|
+
"@pandacss/preset-base": "0.0.0-dev-20240128205559",
|
|
69
|
+
"@pandacss/preset-panda": "0.0.0-dev-20240128205559",
|
|
70
|
+
"@pandacss/shared": "0.0.0-dev-20240128205559",
|
|
71
|
+
"@pandacss/types": "0.0.0-dev-20240128205559"
|
|
73
72
|
},
|
|
74
73
|
"devDependencies": {
|
|
75
74
|
"pkg-types": "1.0.3"
|