@pandacss/config 2.0.0-beta.8 → 2.0.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/{chunk-YKIDLZNO.js → chunk-LDC4ZCDS.js} +56 -75
- package/dist/chunk-R4R5RHIS.js +73 -0
- package/dist/{chunk-VYX3JX5J.js → chunk-Y642H6DU.js} +54 -4
- package/dist/index.d.ts +82 -14
- package/dist/index.js +799 -231
- package/dist/{merge-DiBpncUC.d.ts → merge-EXcM0jFd.d.ts} +2 -3
- package/dist/merge.d.ts +1 -1
- package/dist/merge.js +2 -1
- package/dist/serialize.d.ts +1 -1
- package/dist/serialize.js +2 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
import {
|
|
2
|
-
PandaError,
|
|
3
|
-
createConfigDiagnostic,
|
|
4
|
-
createConfigError,
|
|
5
|
-
ensureConfigObject,
|
|
6
|
-
errorMessage,
|
|
7
|
-
isPlainObject,
|
|
8
2
|
mergeConfigs,
|
|
9
3
|
mergeConfigsWithSources
|
|
10
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LDC4ZCDS.js";
|
|
11
5
|
import {
|
|
12
6
|
collectPluginHookHandlers,
|
|
13
7
|
createConfigSnapshot,
|
|
14
8
|
normalizeHook
|
|
15
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-Y642H6DU.js";
|
|
10
|
+
import {
|
|
11
|
+
PandaError,
|
|
12
|
+
clone,
|
|
13
|
+
createConfigDiagnostic,
|
|
14
|
+
createConfigError,
|
|
15
|
+
ensureConfigObject,
|
|
16
|
+
errorMessage,
|
|
17
|
+
isPlainObject
|
|
18
|
+
} from "./chunk-R4R5RHIS.js";
|
|
16
19
|
|
|
17
20
|
// src/load.ts
|
|
18
|
-
import { applyConfigDefaults } from "@pandacss/compiler-shared";
|
|
21
|
+
import { applyConfigDefaults as applyConfigDefaults2 } from "@pandacss/compiler-shared";
|
|
19
22
|
|
|
20
23
|
// src/bundle.ts
|
|
21
|
-
import { existsSync, realpathSync } from "fs";
|
|
22
|
-
import { mkdir, unlink, writeFile } from "fs/promises";
|
|
23
|
-
import { builtinModules } from "module";
|
|
24
|
-
import { tmpdir } from "os";
|
|
25
|
-
import { dirname, isAbsolute as isAbsolute2, join, normalize, relative } from "path";
|
|
26
|
-
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
27
|
-
import { rolldown } from "rolldown";
|
|
24
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
25
|
+
import { mkdir, unlink, writeFile } from "node:fs/promises";
|
|
26
|
+
import { builtinModules } from "node:module";
|
|
27
|
+
import { tmpdir } from "node:os";
|
|
28
|
+
import { basename, dirname, isAbsolute as isAbsolute2, join, normalize, relative } from "node:path";
|
|
29
|
+
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
28
30
|
|
|
29
31
|
// src/bundle-plugins.ts
|
|
30
32
|
import { parse } from "acorn";
|
|
31
33
|
import { simple } from "acorn-walk";
|
|
32
34
|
import MagicString from "magic-string";
|
|
33
|
-
import { isAbsolute } from "path";
|
|
34
|
-
import { pathToFileURL } from "url";
|
|
35
|
+
import { isAbsolute } from "node:path";
|
|
36
|
+
import { pathToFileURL } from "node:url";
|
|
35
37
|
function importMetaUrlPlugin() {
|
|
36
38
|
return {
|
|
37
39
|
name: "panda-import-meta-url",
|
|
@@ -75,6 +77,7 @@ function isNode(value, type) {
|
|
|
75
77
|
// src/bundle.ts
|
|
76
78
|
var nodeBuiltins = /* @__PURE__ */ new Set([...builtinModules, ...builtinModules.map((mod) => `node:${mod}`)]);
|
|
77
79
|
async function bundleConfig(filepath, cwd) {
|
|
80
|
+
const { rolldown } = await import("rolldown");
|
|
78
81
|
const build = await rolldown({
|
|
79
82
|
input: filepath,
|
|
80
83
|
cwd,
|
|
@@ -102,6 +105,7 @@ async function bundleConfig(filepath, cwd) {
|
|
|
102
105
|
}
|
|
103
106
|
async function loadBundledModule(filepath, code) {
|
|
104
107
|
const target = tempTargetFor(filepath);
|
|
108
|
+
let evalError;
|
|
105
109
|
if (target) {
|
|
106
110
|
try {
|
|
107
111
|
await mkdir(dirname(target), { recursive: true });
|
|
@@ -114,14 +118,23 @@ async function loadBundledModule(filepath, code) {
|
|
|
114
118
|
} finally {
|
|
115
119
|
void unlink(target).catch(() => void 0);
|
|
116
120
|
}
|
|
117
|
-
} catch {
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (!isUnresolvedTempModule(error, target)) evalError = error;
|
|
118
123
|
}
|
|
119
124
|
}
|
|
120
125
|
const dataUrl = `data:text/javascript;base64,${Buffer.from(code).toString("base64")}`;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
126
|
+
try {
|
|
127
|
+
return await import(
|
|
128
|
+
/* @vite-ignore */
|
|
129
|
+
dataUrl
|
|
130
|
+
);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
throw evalError ?? error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function isUnresolvedTempModule(error, target) {
|
|
136
|
+
const message = error instanceof Error ? error.message : "";
|
|
137
|
+
return message.includes("Cannot find module") && message.includes(basename(target));
|
|
125
138
|
}
|
|
126
139
|
function tempTargetFor(filepath) {
|
|
127
140
|
const unique = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
@@ -165,8 +178,8 @@ function canonical(filepath) {
|
|
|
165
178
|
}
|
|
166
179
|
|
|
167
180
|
// src/find.ts
|
|
168
|
-
import { readdirSync } from "fs";
|
|
169
|
-
import { dirname as dirname2, resolve } from "path";
|
|
181
|
+
import { readdirSync } from "node:fs";
|
|
182
|
+
import { dirname as dirname2, resolve } from "node:path";
|
|
170
183
|
var configFiles = /* @__PURE__ */ new Set([
|
|
171
184
|
"panda.config.ts",
|
|
172
185
|
"panda.config.js",
|
|
@@ -210,11 +223,11 @@ function findConfig(options) {
|
|
|
210
223
|
// src/hook-utils.ts
|
|
211
224
|
var configResolvedUtils = {
|
|
212
225
|
omit(obj, paths) {
|
|
213
|
-
const
|
|
226
|
+
const next = clone(obj);
|
|
214
227
|
for (const path of paths) {
|
|
215
|
-
deleteAtPath(
|
|
228
|
+
deleteAtPath(next, path);
|
|
216
229
|
}
|
|
217
|
-
return
|
|
230
|
+
return next;
|
|
218
231
|
},
|
|
219
232
|
pick(obj, paths) {
|
|
220
233
|
const result = {};
|
|
@@ -230,23 +243,6 @@ var configResolvedUtils = {
|
|
|
230
243
|
traverseValue(obj, callback, options);
|
|
231
244
|
}
|
|
232
245
|
};
|
|
233
|
-
function cloneValue(value) {
|
|
234
|
-
if (Array.isArray(value)) {
|
|
235
|
-
const len = value.length;
|
|
236
|
-
const out2 = new Array(len);
|
|
237
|
-
for (let i = 0; i < len; i++) out2[i] = cloneValue(value[i]);
|
|
238
|
-
return out2;
|
|
239
|
-
}
|
|
240
|
-
if (!isPlainObject(value)) return value;
|
|
241
|
-
const source = value;
|
|
242
|
-
const out = {};
|
|
243
|
-
const keys = Object.keys(source);
|
|
244
|
-
for (let i = 0; i < keys.length; i++) {
|
|
245
|
-
const key = keys[i];
|
|
246
|
-
out[key] = cloneValue(source[key]);
|
|
247
|
-
}
|
|
248
|
-
return out;
|
|
249
|
-
}
|
|
250
246
|
function pathParts(path) {
|
|
251
247
|
return path.split(".").filter(Boolean);
|
|
252
248
|
}
|
|
@@ -263,7 +259,7 @@ function setAtPath(target, path, value) {
|
|
|
263
259
|
let current = target;
|
|
264
260
|
parts.forEach((part, index) => {
|
|
265
261
|
if (index === parts.length - 1) {
|
|
266
|
-
current[part] =
|
|
262
|
+
current[part] = clone(value);
|
|
267
263
|
return;
|
|
268
264
|
}
|
|
269
265
|
const next = current[part];
|
|
@@ -337,20 +333,121 @@ function attachRuntimeHooks(config, configs) {
|
|
|
337
333
|
return config;
|
|
338
334
|
}
|
|
339
335
|
|
|
336
|
+
// src/design-system/overlay-input.ts
|
|
337
|
+
import { applyConfigDefaults } from "@pandacss/compiler-shared";
|
|
338
|
+
|
|
339
|
+
// src/normalize.ts
|
|
340
|
+
var CLASS_NAME_OPTION_KEYS = ["hash", "prefix", "separator"];
|
|
341
|
+
function normalizeClassNameOptions(config) {
|
|
342
|
+
return {
|
|
343
|
+
hash: normalizeHash(config.hash),
|
|
344
|
+
prefix: normalizePrefix(config.prefix),
|
|
345
|
+
separator: config.separator ?? "_"
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
function diffClassNameOptions(consumer, designSystem, scope) {
|
|
349
|
+
const normalized = normalizeClassNameOptions(consumer);
|
|
350
|
+
return CLASS_NAME_OPTION_KEYS.filter((key) => {
|
|
351
|
+
if (scope === "explicit" && consumer[key] === void 0) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
if (key === "separator") {
|
|
355
|
+
return normalized.separator !== designSystem.separator;
|
|
356
|
+
}
|
|
357
|
+
return normalized[key].cssVar !== designSystem[key].cssVar || normalized[key].className !== designSystem[key].className;
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
function normalizeHash(value) {
|
|
361
|
+
if (typeof value === "boolean") {
|
|
362
|
+
return { cssVar: value, className: value };
|
|
363
|
+
}
|
|
364
|
+
if (value && typeof value === "object") {
|
|
365
|
+
return { cssVar: value.cssVar === true, className: value.className === true };
|
|
366
|
+
}
|
|
367
|
+
return { cssVar: false, className: false };
|
|
368
|
+
}
|
|
369
|
+
function normalizePrefix(value) {
|
|
370
|
+
if (typeof value === "string") {
|
|
371
|
+
return { cssVar: value, className: value };
|
|
372
|
+
}
|
|
373
|
+
if (value && typeof value === "object") {
|
|
374
|
+
return { cssVar: value.cssVar ?? "", className: value.className ?? "" };
|
|
375
|
+
}
|
|
376
|
+
return { cssVar: "", className: "" };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/design-system/overlay-input.ts
|
|
380
|
+
var CLASS_NAME_OPTION_KEYS2 = ["hash", "prefix", "separator"];
|
|
381
|
+
var RUNTIME_OPTION_KEYS = [
|
|
382
|
+
...CLASS_NAME_OPTION_KEYS2,
|
|
383
|
+
"jsxFramework",
|
|
384
|
+
"jsxFactory",
|
|
385
|
+
"jsxStyleProps",
|
|
386
|
+
"strictTokens",
|
|
387
|
+
"strictPropertyValues",
|
|
388
|
+
"shorthands"
|
|
389
|
+
];
|
|
390
|
+
function designSystemSourceIds(chain) {
|
|
391
|
+
const ids = /* @__PURE__ */ new Set();
|
|
392
|
+
for (const ds of chain) {
|
|
393
|
+
ids.add(ds.name);
|
|
394
|
+
ids.add(ds.specifier);
|
|
395
|
+
}
|
|
396
|
+
return ids;
|
|
397
|
+
}
|
|
398
|
+
function authoredByApp(sources, prefix, dsIds) {
|
|
399
|
+
return Object.entries(sources.paths).some(([path, ids]) => {
|
|
400
|
+
if (path !== prefix && !path.startsWith(`${prefix}.`)) return false;
|
|
401
|
+
const idList = Array.isArray(ids) ? ids : [ids];
|
|
402
|
+
return idList.some((id) => isAppSource(sources.entries[id], dsIds));
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
function isAppSource(entry, dsIds) {
|
|
406
|
+
if (!entry) return false;
|
|
407
|
+
if (entry.kind === "config") return true;
|
|
408
|
+
if (entry.kind !== "preset") return false;
|
|
409
|
+
return entry.specifier === void 0 || !dsIds.has(entry.specifier);
|
|
410
|
+
}
|
|
411
|
+
function buildOverlayInput(sources, appConfig, chain, leafPreset, cwd) {
|
|
412
|
+
const dsIds = designSystemSourceIds(chain);
|
|
413
|
+
const authored = {
|
|
414
|
+
conditions: authoredByApp(sources, "conditions", dsIds),
|
|
415
|
+
breakpoints: authoredByApp(sources, "theme.breakpoints", dsIds),
|
|
416
|
+
utilities: authoredByApp(sources, "utilities", dsIds),
|
|
417
|
+
tokens: authoredByApp(sources, "theme.tokens", dsIds) || authoredByApp(sources, "theme.semanticTokens", dsIds)
|
|
418
|
+
};
|
|
419
|
+
const mismatches = diffRuntimeOptions(appConfig, leafPreset, sources, dsIds, cwd);
|
|
420
|
+
return { authored, compatible: mismatches.length === 0 };
|
|
421
|
+
}
|
|
422
|
+
function diffRuntimeOptions(appConfig, leafPreset, sources, dsIds, cwd) {
|
|
423
|
+
const app = applyConfigDefaults({ ...appConfig }, cwd);
|
|
424
|
+
const ds = applyConfigDefaults({ ...leafPreset }, cwd);
|
|
425
|
+
const appClass = normalizeClassNameOptions(app);
|
|
426
|
+
const dsClass = normalizeClassNameOptions(ds);
|
|
427
|
+
return RUNTIME_OPTION_KEYS.filter((key) => {
|
|
428
|
+
if (!authoredByApp(sources, key, dsIds)) return false;
|
|
429
|
+
if (key === "hash" || key === "prefix" || key === "separator") {
|
|
430
|
+
if (key === "separator") return appClass.separator !== dsClass.separator;
|
|
431
|
+
return appClass[key].cssVar !== dsClass[key].cssVar || appClass[key].className !== dsClass[key].className;
|
|
432
|
+
}
|
|
433
|
+
return JSON.stringify(app[key]) !== JSON.stringify(ds[key]);
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
|
|
340
437
|
// src/preset.ts
|
|
341
|
-
import { normalize as normalize2, relative as
|
|
438
|
+
import { normalize as normalize2, relative as relative5 } from "node:path";
|
|
342
439
|
|
|
343
|
-
// src/design-system.ts
|
|
440
|
+
// src/design-system/chain.ts
|
|
344
441
|
import {
|
|
345
442
|
outdirBasename
|
|
346
443
|
} from "@pandacss/compiler-shared";
|
|
347
|
-
import { readFileSync, statSync } from "fs";
|
|
348
|
-
import { dirname as
|
|
349
|
-
import { pathToFileURL as pathToFileURL3 } from "url";
|
|
444
|
+
import { readFileSync as readFileSync2, statSync } from "node:fs";
|
|
445
|
+
import { dirname as dirname4, resolve as resolve4 } from "node:path";
|
|
446
|
+
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
350
447
|
|
|
351
448
|
// src/resolve.ts
|
|
352
|
-
import { createRequire } from "module";
|
|
353
|
-
import { resolve as resolve2 } from "path";
|
|
449
|
+
import { createRequire } from "node:module";
|
|
450
|
+
import { resolve as resolve2 } from "node:path";
|
|
354
451
|
function tryResolveFrom(request, fromDir) {
|
|
355
452
|
try {
|
|
356
453
|
return createRequire(resolve2(fromDir, "noop.js")).resolve(request, { paths: [fromDir] });
|
|
@@ -360,14 +457,218 @@ function tryResolveFrom(request, fromDir) {
|
|
|
360
457
|
}
|
|
361
458
|
}
|
|
362
459
|
function isResolveMiss(error) {
|
|
363
|
-
const code =
|
|
460
|
+
const code = errorCode(error);
|
|
364
461
|
return code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED";
|
|
365
462
|
}
|
|
463
|
+
function resolveFrom(request, fromDir) {
|
|
464
|
+
try {
|
|
465
|
+
return { kind: "resolved", path: createRequire(resolve2(fromDir, "noop.js")).resolve(request, { paths: [fromDir] }) };
|
|
466
|
+
} catch (error) {
|
|
467
|
+
const code = errorCode(error);
|
|
468
|
+
if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") return { kind: "not-exported" };
|
|
469
|
+
if (code === "MODULE_NOT_FOUND") return { kind: "not-installed" };
|
|
470
|
+
throw error;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
function errorCode(error) {
|
|
474
|
+
return typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// src/design-system/package.ts
|
|
478
|
+
import { existsSync as existsSync2, readFileSync } from "node:fs";
|
|
479
|
+
import { dirname as dirname3, join as join2 } from "node:path";
|
|
480
|
+
|
|
481
|
+
// src/design-system/publishable-files.ts
|
|
482
|
+
import { relative as relative3, resolve as resolve3 } from "node:path";
|
|
483
|
+
|
|
484
|
+
// src/paths.ts
|
|
485
|
+
import { isAbsolute as isAbsolute3, relative as relative2 } from "node:path";
|
|
486
|
+
function toPosixPath(path) {
|
|
487
|
+
return path.includes("\\") ? path.split("\\").join("/") : path;
|
|
488
|
+
}
|
|
489
|
+
function toPosixRelative(from, to) {
|
|
490
|
+
const rel = toPosixPath(relative2(from, to));
|
|
491
|
+
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
492
|
+
}
|
|
493
|
+
function toRelativeKey(key, cwd) {
|
|
494
|
+
return toPosixPath(isAbsolute3(key) ? relative2(cwd, key) : key);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// src/design-system/publishable-files.ts
|
|
498
|
+
var GLOB_START = /[*?{]/;
|
|
499
|
+
var HAS_WILDCARD = /[*?]/;
|
|
500
|
+
var TRAILING_SLASH = /\/$/;
|
|
501
|
+
var REGEX_META = /[.+^${}()|[\]\\]/g;
|
|
502
|
+
var GLOBSTAR = /\*\*/g;
|
|
503
|
+
var GLOB_STAR = /\*/g;
|
|
504
|
+
var GLOB_QMARK = /\?/g;
|
|
505
|
+
var GLOBSTAR_TOKEN = /<<<DS>>>/g;
|
|
506
|
+
function filterPublishableLibFiles(options) {
|
|
507
|
+
const { files, packageRoot, outRoot, publishFiles } = options;
|
|
508
|
+
if (!publishFiles?.length) {
|
|
509
|
+
return { files, unpublished: [] };
|
|
510
|
+
}
|
|
511
|
+
const rules = compilePackageFilesRules(publishFiles);
|
|
512
|
+
const kept = [];
|
|
513
|
+
const unpublished = [];
|
|
514
|
+
for (const file of files) {
|
|
515
|
+
const packageRelative = libFileToPackageRelative(file, packageRoot, outRoot);
|
|
516
|
+
if (packageRelative !== void 0 && matchesCompiledRules(packageRelative, rules)) {
|
|
517
|
+
kept.push(file);
|
|
518
|
+
} else {
|
|
519
|
+
unpublished.push(file);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return { files: kept, unpublished };
|
|
523
|
+
}
|
|
524
|
+
function readPublishFilesField(value) {
|
|
525
|
+
if (!Array.isArray(value) || value.length === 0) return void 0;
|
|
526
|
+
for (const entry of value) {
|
|
527
|
+
if (typeof entry !== "string") return void 0;
|
|
528
|
+
}
|
|
529
|
+
return value;
|
|
530
|
+
}
|
|
531
|
+
function libFileToPackageRelative(file, packageRoot, outRoot) {
|
|
532
|
+
const normalized = toPosixPath(file);
|
|
533
|
+
const withoutDot = normalized.startsWith("./") ? normalized.slice(2) : normalized;
|
|
534
|
+
const globAt = withoutDot.search(GLOB_START);
|
|
535
|
+
const literalPrefix = globAt === -1 ? withoutDot : withoutDot.slice(0, globAt);
|
|
536
|
+
const abs = resolve3(outRoot, literalPrefix || ".");
|
|
537
|
+
const rel = toPosixPath(relative3(packageRoot, abs));
|
|
538
|
+
if (rel === "") return "";
|
|
539
|
+
if (rel.startsWith("..")) return void 0;
|
|
540
|
+
return rel;
|
|
541
|
+
}
|
|
542
|
+
function compilePackageFilesRules(patterns) {
|
|
543
|
+
const rules = [];
|
|
544
|
+
for (const raw of patterns) {
|
|
545
|
+
const negated = raw.startsWith("!");
|
|
546
|
+
const pattern = toPosixPath(negated ? raw.slice(1) : raw);
|
|
547
|
+
const normalized = pattern.startsWith("./") ? pattern.slice(2) : pattern;
|
|
548
|
+
if (!normalized) continue;
|
|
549
|
+
if (!HAS_WILDCARD.test(normalized)) {
|
|
550
|
+
rules.push({ kind: "prefix", negated, value: normalized.replace(TRAILING_SLASH, "") });
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
const escaped = normalized.replace(REGEX_META, "\\$&").replace(GLOBSTAR, "<<<DS>>>").replace(GLOB_STAR, "[^/]*").replace(GLOB_QMARK, "[^/]").replace(GLOBSTAR_TOKEN, ".*");
|
|
554
|
+
rules.push({ kind: "regex", negated, value: new RegExp(`^${escaped}(?:/.*)?$`) });
|
|
555
|
+
}
|
|
556
|
+
return rules;
|
|
557
|
+
}
|
|
558
|
+
function matchesCompiledRules(packageRelativePath, rules) {
|
|
559
|
+
const path = packageRelativePath.startsWith("./") ? packageRelativePath.slice(2) : packageRelativePath;
|
|
560
|
+
let included = false;
|
|
561
|
+
for (const rule of rules) {
|
|
562
|
+
const hit = rule.kind === "prefix" ? path === rule.value || path.startsWith(`${rule.value}/`) : rule.value.test(path);
|
|
563
|
+
if (!hit) continue;
|
|
564
|
+
included = !rule.negated;
|
|
565
|
+
}
|
|
566
|
+
return included;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// src/design-system/package.ts
|
|
570
|
+
var PACKAGE_MANAGER_RANGE_PATTERN = /^(?:workspace|catalog):/;
|
|
571
|
+
var PORTABLE_WORKSPACE_RANGE_PATTERN = /^[~^]?\d/;
|
|
572
|
+
var VERSION_CORE_PATTERN = /^(\d+)\.(\d+)\.(\d+)/;
|
|
573
|
+
function resolvePublishedPandaRange(range, currentVersion) {
|
|
574
|
+
const authored = range?.trim();
|
|
575
|
+
if (!authored) return "*";
|
|
576
|
+
if (authored.startsWith("npm:")) {
|
|
577
|
+
return resolveNpmAliasRange(authored) ?? portableRangeFromInstalled(currentVersion, "^");
|
|
578
|
+
}
|
|
579
|
+
if (!PACKAGE_MANAGER_RANGE_PATTERN.test(authored)) return authored;
|
|
580
|
+
if (authored.startsWith("workspace:")) {
|
|
581
|
+
const workspaceRange = authored.slice("workspace:".length);
|
|
582
|
+
if (PORTABLE_WORKSPACE_RANGE_PATTERN.test(workspaceRange)) return workspaceRange;
|
|
583
|
+
}
|
|
584
|
+
const operator = authored === "workspace:~" ? "~" : "^";
|
|
585
|
+
return portableRangeFromInstalled(currentVersion, operator);
|
|
586
|
+
}
|
|
587
|
+
function resolveNpmAliasRange(spec) {
|
|
588
|
+
const at = spec.lastIndexOf("@");
|
|
589
|
+
if (at <= "npm:".length) return void 0;
|
|
590
|
+
return spec.slice(at + 1);
|
|
591
|
+
}
|
|
592
|
+
function portableRangeFromInstalled(currentVersion, operator) {
|
|
593
|
+
const core = currentVersion?.match(VERSION_CORE_PATTERN)?.[0];
|
|
594
|
+
return core ? `${operator}${core}` : "*";
|
|
595
|
+
}
|
|
596
|
+
function readPackageIdentity(cwd) {
|
|
597
|
+
const packagePath = nearestPackageJson(cwd);
|
|
598
|
+
if (packagePath === void 0) {
|
|
599
|
+
throw new Error(`Could not find a package.json from ${JSON.stringify(cwd)} to build the design system manifest.`);
|
|
600
|
+
}
|
|
601
|
+
const pkg = JSON.parse(readFileSync(packagePath, "utf8"));
|
|
602
|
+
const name = pkg.name;
|
|
603
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
604
|
+
throw new Error(`${JSON.stringify(packagePath)} has no "name"; a design system must be a named package.`);
|
|
605
|
+
}
|
|
606
|
+
const peer = pkg.peerDependencies?.["@pandacss/dev"];
|
|
607
|
+
return {
|
|
608
|
+
name,
|
|
609
|
+
version: typeof pkg.version === "string" ? pkg.version : void 0,
|
|
610
|
+
pandaPeer: typeof peer === "string" ? peer : void 0,
|
|
611
|
+
packagePath,
|
|
612
|
+
publishFiles: readPublishFilesField(pkg.files)
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function defaultImportMap(name) {
|
|
616
|
+
return {
|
|
617
|
+
css: `${name}/css`,
|
|
618
|
+
recipes: `${name}/recipes`,
|
|
619
|
+
patterns: `${name}/patterns`,
|
|
620
|
+
jsx: `${name}/jsx`,
|
|
621
|
+
tokens: `${name}/tokens`
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
function syncExports(options) {
|
|
625
|
+
const { packageJson, entries } = options;
|
|
626
|
+
const pkg = JSON.parse(packageJson);
|
|
627
|
+
const existing = normalizeExports(pkg.exports);
|
|
628
|
+
const merged = { ...existing };
|
|
629
|
+
const conflicts = [];
|
|
630
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
631
|
+
if (key in merged && !exportsValueEqual(merged[key], value)) {
|
|
632
|
+
conflicts.push(key);
|
|
633
|
+
}
|
|
634
|
+
merged[key] = value;
|
|
635
|
+
}
|
|
636
|
+
const changed = JSON.stringify(pkg.exports) !== JSON.stringify(merged);
|
|
637
|
+
const out = { ...pkg, exports: merged };
|
|
638
|
+
return { changed, json: `${JSON.stringify(out, null, 2)}
|
|
639
|
+
`, conflicts };
|
|
640
|
+
}
|
|
641
|
+
function exportsValueEqual(left, right) {
|
|
642
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
643
|
+
}
|
|
644
|
+
function normalizeExports(exports) {
|
|
645
|
+
if (exports === void 0) return {};
|
|
646
|
+
if (typeof exports === "string") return { ".": exports };
|
|
647
|
+
if (Array.isArray(exports)) return { ".": exports };
|
|
648
|
+
if (!isPlainObject(exports)) return {};
|
|
649
|
+
if (isSubpathExportMap(exports)) return exports;
|
|
650
|
+
return { ".": exports };
|
|
651
|
+
}
|
|
652
|
+
function isSubpathExportMap(exports) {
|
|
653
|
+
return Object.keys(exports).some((key) => key === "." || key.startsWith("./"));
|
|
654
|
+
}
|
|
655
|
+
function nearestPackageJson(start) {
|
|
656
|
+
let current = start;
|
|
657
|
+
while (true) {
|
|
658
|
+
const candidate = join2(current, "package.json");
|
|
659
|
+
if (existsSync2(candidate)) return candidate;
|
|
660
|
+
const parent = dirname3(current);
|
|
661
|
+
if (parent === current) return void 0;
|
|
662
|
+
current = parent;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
366
665
|
|
|
367
|
-
// src/design-system.ts
|
|
666
|
+
// src/design-system/chain.ts
|
|
667
|
+
var SPECIFIER_PROTOCOL = /^([a-z][a-z0-9+.-]*):/i;
|
|
368
668
|
async function loadDesignSystemChain(spec, cwd, deps) {
|
|
369
669
|
const levels = [];
|
|
370
670
|
const seenAt = /* @__PURE__ */ new Map();
|
|
671
|
+
const seenNames = /* @__PURE__ */ new Map();
|
|
371
672
|
let currentSpec = spec;
|
|
372
673
|
let fromDir = cwd;
|
|
373
674
|
let declaredBy;
|
|
@@ -383,10 +684,15 @@ async function loadDesignSystemChain(spec, cwd, deps) {
|
|
|
383
684
|
seenAt.set(manifestPath, levels.length);
|
|
384
685
|
deps.add(manifestPath);
|
|
385
686
|
const { level, parent } = await loadManifestLevel(currentSpec, manifestPath, deps);
|
|
687
|
+
const priorPath = seenNames.get(level.info.name);
|
|
688
|
+
if (priorPath !== void 0 && priorPath !== manifestPath) {
|
|
689
|
+
throw duplicateNameError(level.info.name, priorPath, manifestPath);
|
|
690
|
+
}
|
|
691
|
+
seenNames.set(level.info.name, manifestPath);
|
|
386
692
|
levels.push(level);
|
|
387
693
|
if (parent === void 0) break;
|
|
388
694
|
declaredBy = level.info.name;
|
|
389
|
-
fromDir =
|
|
695
|
+
fromDir = dirname4(manifestPath);
|
|
390
696
|
currentSpec = parent;
|
|
391
697
|
}
|
|
392
698
|
return levels.reverse();
|
|
@@ -398,43 +704,172 @@ function withDesignSystemImportMap(config, infos) {
|
|
|
398
704
|
);
|
|
399
705
|
return { ...config, importMap: [...roots, outdirBasename(config.outdir ?? "styled-system"), ...existing] };
|
|
400
706
|
}
|
|
707
|
+
function buildCodegenOverlay(metadata) {
|
|
708
|
+
const chain = metadata?.designSystem;
|
|
709
|
+
if (!chain || chain.length !== 1) return void 0;
|
|
710
|
+
if (metadata?.overlayInput && !metadata.overlayInput.compatible) return void 0;
|
|
711
|
+
const [ds] = chain;
|
|
712
|
+
const appRecipes = new Set(metadata?.userRecipeNames ?? []);
|
|
713
|
+
const appPatterns = new Set(metadata?.userPatternNames ?? []);
|
|
714
|
+
const authored = metadata?.overlayInput?.authored;
|
|
715
|
+
const runtimeDirty = !!(authored?.conditions || authored?.breakpoints || authored?.utilities || authored?.tokens);
|
|
716
|
+
return {
|
|
717
|
+
...overlayRoots(ds),
|
|
718
|
+
ownedRecipes: ds.recipeNames.filter((name) => !appRecipes.has(name)),
|
|
719
|
+
ownedPatterns: ds.patternNames.filter((name) => !appPatterns.has(name)),
|
|
720
|
+
virtualizeHelpers: true,
|
|
721
|
+
virtualizeCss: !runtimeDirty
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
function collectArtifactConflicts(metadata) {
|
|
725
|
+
const appRecipes = new Set(metadata?.userRecipeNames ?? []);
|
|
726
|
+
const appPatterns = new Set(metadata?.userPatternNames ?? []);
|
|
727
|
+
return (metadata?.designSystem ?? []).map((ds) => ({
|
|
728
|
+
name: ds.name,
|
|
729
|
+
recipes: ds.recipeNames.filter((name) => appRecipes.has(name)),
|
|
730
|
+
patterns: ds.patternNames.filter((name) => appPatterns.has(name))
|
|
731
|
+
})).filter((entry) => entry.recipes.length > 0 || entry.patterns.length > 0);
|
|
732
|
+
}
|
|
733
|
+
function collectExportMissingDiagnostics(metadata) {
|
|
734
|
+
const overlay = buildCodegenOverlay(metadata);
|
|
735
|
+
if (!overlay) return [];
|
|
736
|
+
const [ds] = metadata.designSystem;
|
|
737
|
+
const required = [];
|
|
738
|
+
if (overlay.virtualizeHelpers) required.push("./helpers");
|
|
739
|
+
if (overlay.virtualizeCss) {
|
|
740
|
+
required.push("./css", "./css/*");
|
|
741
|
+
}
|
|
742
|
+
if (overlay.ownedRecipes.length > 0) {
|
|
743
|
+
required.push("./recipes", "./recipes/*");
|
|
744
|
+
}
|
|
745
|
+
if (overlay.ownedPatterns.length > 0) {
|
|
746
|
+
required.push("./patterns", "./patterns/*");
|
|
747
|
+
}
|
|
748
|
+
const appPatterns = metadata?.userPatternNames?.length ?? 0;
|
|
749
|
+
const dsPatterns = ds.patternNames?.length ?? 0;
|
|
750
|
+
if (overlay.ownedPatterns.length > 0 || overlay.virtualizeCss && (appPatterns > 0 || dsPatterns > 0)) {
|
|
751
|
+
required.push("./jsx", "./jsx/*");
|
|
752
|
+
}
|
|
753
|
+
return required.filter((subpath) => !hasExport(ds.packageExports, subpath)).map((subpath) => exportMissingDiagnostic(ds.name, subpath));
|
|
754
|
+
}
|
|
755
|
+
function collectNameCollisionDiagnostics(metadata) {
|
|
756
|
+
const overlay = buildCodegenOverlay(metadata);
|
|
757
|
+
if (!overlay) return [];
|
|
758
|
+
return [
|
|
759
|
+
...identCollisions("recipe", [...overlay.ownedRecipes, ...metadata?.userRecipeNames ?? []]),
|
|
760
|
+
...identCollisions("pattern", [...overlay.ownedPatterns, ...metadata?.userPatternNames ?? []])
|
|
761
|
+
];
|
|
762
|
+
}
|
|
763
|
+
function jsIdent(value) {
|
|
764
|
+
let out = "";
|
|
765
|
+
for (let i = 0; i < value.length; i++) {
|
|
766
|
+
const code = value.charCodeAt(i);
|
|
767
|
+
const isIdent = code === 36 || // $
|
|
768
|
+
code === 95 || // _
|
|
769
|
+
code >= 48 && code <= 57 || // 0-9
|
|
770
|
+
code >= 65 && code <= 90 || // A-Z
|
|
771
|
+
code >= 97 && code <= 122;
|
|
772
|
+
if (isIdent) {
|
|
773
|
+
if (i === 0 && code >= 48 && code <= 57) out += "_";
|
|
774
|
+
out += value[i];
|
|
775
|
+
} else {
|
|
776
|
+
out += "_";
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return out === "" ? "_" : out;
|
|
780
|
+
}
|
|
781
|
+
function identCollisions(kind, names) {
|
|
782
|
+
const byIdent = /* @__PURE__ */ new Map();
|
|
783
|
+
for (const name of names) {
|
|
784
|
+
const ident = jsIdent(name);
|
|
785
|
+
const set = byIdent.get(ident) ?? /* @__PURE__ */ new Set();
|
|
786
|
+
set.add(name);
|
|
787
|
+
byIdent.set(ident, set);
|
|
788
|
+
}
|
|
789
|
+
const collisions = [];
|
|
790
|
+
for (const [ident, raw] of byIdent) {
|
|
791
|
+
if (raw.size < 2) continue;
|
|
792
|
+
const list = [...raw].map((name) => JSON.stringify(name)).join(", ");
|
|
793
|
+
const message = `${kind} names ${list} both generate the export ${JSON.stringify(ident)}; one would overwrite the other in the generated barrel. Rename one so they produce distinct identifiers.`;
|
|
794
|
+
collisions.push(createConfigDiagnostic("design_system_name_collision", message));
|
|
795
|
+
}
|
|
796
|
+
return collisions;
|
|
797
|
+
}
|
|
798
|
+
function hasExport(packageExports, subpath) {
|
|
799
|
+
return packageExports != null && Object.prototype.hasOwnProperty.call(packageExports, subpath);
|
|
800
|
+
}
|
|
801
|
+
function exportMissingDiagnostic(dsName, subpath) {
|
|
802
|
+
const message = `designSystem ${JSON.stringify(dsName)} doesn't export ${JSON.stringify(subpath)}, which this app's codegen needs. Rebuild it with \`panda lib\`.`;
|
|
803
|
+
return createConfigDiagnostic("design_system_export_missing", message, [
|
|
804
|
+
`Rebuild ${JSON.stringify(dsName)} with \`panda lib\` to add the ${JSON.stringify(subpath)} export.`
|
|
805
|
+
]);
|
|
806
|
+
}
|
|
807
|
+
function overlayRoots(ds) {
|
|
808
|
+
const map = ds.importMap;
|
|
809
|
+
const root = (value, subpath) => {
|
|
810
|
+
const resolved = Array.isArray(value) ? value[0] : value;
|
|
811
|
+
return resolved ?? `${ds.specifier}/${subpath}`;
|
|
812
|
+
};
|
|
813
|
+
return {
|
|
814
|
+
jsx: root(map?.jsx, "jsx"),
|
|
815
|
+
recipes: root(map?.recipes, "recipes"),
|
|
816
|
+
patterns: root(map?.patterns, "patterns"),
|
|
817
|
+
css: root(map?.css, "css"),
|
|
818
|
+
helpers: `${ds.specifier}/helpers`
|
|
819
|
+
};
|
|
820
|
+
}
|
|
401
821
|
function resolveManifestPath(spec, fromDir) {
|
|
822
|
+
const protocol = specifierProtocol(spec);
|
|
823
|
+
if (protocol) throw unsupportedSpecifierError(spec, protocol);
|
|
824
|
+
let outcome;
|
|
402
825
|
try {
|
|
403
|
-
|
|
826
|
+
outcome = resolveFrom(`${spec}/panda/lib.json`, fromDir);
|
|
404
827
|
} catch (error) {
|
|
405
828
|
const message = `Failed to resolve designSystem ${JSON.stringify(spec)} from ${JSON.stringify(fromDir)}: ${errorMessage(error)}`;
|
|
406
829
|
throw createConfigError(message, [createConfigDiagnostic("design_system_resolve_failed", message)]);
|
|
407
830
|
}
|
|
831
|
+
if (outcome.kind === "resolved") return outcome.path;
|
|
832
|
+
if (outcome.kind === "not-exported") throw manifestNotExportedError(spec);
|
|
833
|
+
return void 0;
|
|
834
|
+
}
|
|
835
|
+
function manifestNotExportedError(spec) {
|
|
836
|
+
const message = `designSystem ${JSON.stringify(spec)} is installed but doesn't expose \`./panda/*\` (missing \`panda/lib.json\`). If it's a Panda design system, rebuild it with \`panda lib\`; otherwise it can't be consumed as a design system.`;
|
|
837
|
+
return createConfigError(message, [
|
|
838
|
+
createConfigDiagnostic("design_system_manifest_not_exported", message, [
|
|
839
|
+
`Rebuild ${JSON.stringify(spec)} with \`panda lib\`, or check its package.json \`exports\` includes \`./panda/*\`.`
|
|
840
|
+
])
|
|
841
|
+
]);
|
|
408
842
|
}
|
|
409
843
|
async function loadManifestLevel(spec, manifestPath, deps) {
|
|
410
|
-
let
|
|
844
|
+
let parsed;
|
|
411
845
|
try {
|
|
412
|
-
|
|
846
|
+
parsed = JSON.parse(readFileSync2(manifestPath, "utf8"));
|
|
413
847
|
} catch (error) {
|
|
414
|
-
|
|
848
|
+
const message = `Failed to parse ${JSON.stringify(manifestPath)} as JSON: ${errorMessage(error)}. This file must be generated by \`panda lib\`, not hand-written or added to \`include\`.`;
|
|
849
|
+
throw createConfigError(message, [
|
|
850
|
+
{ ...createConfigDiagnostic("design_system_manifest_invalid", message), file: manifestPath }
|
|
851
|
+
]);
|
|
415
852
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
if (typeof manifest.buildInfo !== "string") {
|
|
420
|
-
throw invalidManifestError(spec, "buildInfo");
|
|
421
|
-
}
|
|
422
|
-
const presetPath = resolve3(dirname3(manifestPath), manifest.preset);
|
|
423
|
-
const buildInfoPath = resolve3(dirname3(manifestPath), manifest.buildInfo);
|
|
853
|
+
const manifest = validateManifest(spec, manifestPath, parsed);
|
|
854
|
+
const presetPath = resolve4(dirname4(manifestPath), manifest.preset);
|
|
855
|
+
const buildInfoPath = resolve4(dirname4(manifestPath), manifest.buildInfo);
|
|
424
856
|
deps.add(presetPath);
|
|
425
857
|
deps.add(buildInfoPath);
|
|
426
858
|
let preset;
|
|
427
859
|
try {
|
|
428
860
|
const mod = await import(presetImportUrl(presetPath));
|
|
429
|
-
preset = ensureConfigObject(mod.default
|
|
861
|
+
preset = ensureConfigObject("default" in mod ? mod.default : mod, manifest.name ?? spec);
|
|
430
862
|
} catch (error) {
|
|
431
|
-
if (error instanceof PandaError) throw error;
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
863
|
+
if (error instanceof PandaError && error.diagnostics?.length) throw error;
|
|
864
|
+
const message = `Failed to load the preset for designSystem ${JSON.stringify(spec)} (${JSON.stringify(manifest.preset)}): ${errorMessage(error)}`;
|
|
865
|
+
throw createConfigError(message, [
|
|
866
|
+
createConfigDiagnostic("design_system_preset_load_failed", message, [
|
|
867
|
+
`Check that ${JSON.stringify(manifest.preset)} is valid and rebuild ${JSON.stringify(spec)} with \`panda lib\`.`
|
|
868
|
+
])
|
|
869
|
+
]);
|
|
436
870
|
}
|
|
437
871
|
const parent = typeof manifest.designSystem === "string" && manifest.designSystem.length > 0 ? manifest.designSystem : void 0;
|
|
872
|
+
const packageExports = readPackageExports(manifestPath);
|
|
438
873
|
return {
|
|
439
874
|
parent,
|
|
440
875
|
level: {
|
|
@@ -447,11 +882,27 @@ async function loadManifestLevel(spec, manifestPath, deps) {
|
|
|
447
882
|
buildInfoPath,
|
|
448
883
|
files: manifest.files ?? [],
|
|
449
884
|
tokenPaths: [],
|
|
450
|
-
|
|
885
|
+
recipeNames: [],
|
|
886
|
+
patternNames: [],
|
|
887
|
+
...manifest.importMap ? { importMap: manifest.importMap } : {},
|
|
888
|
+
...packageExports ? { packageExports } : {}
|
|
451
889
|
}
|
|
452
890
|
}
|
|
453
891
|
};
|
|
454
892
|
}
|
|
893
|
+
function readPackageExports(manifestPath) {
|
|
894
|
+
try {
|
|
895
|
+
const packageJsonPath = nearestPackageJson(dirname4(manifestPath));
|
|
896
|
+
if (packageJsonPath === void 0) return void 0;
|
|
897
|
+
const pkg = JSON.parse(readFileSync2(packageJsonPath, "utf8"));
|
|
898
|
+
return isExportsMap(pkg.exports) ? pkg.exports : void 0;
|
|
899
|
+
} catch {
|
|
900
|
+
return void 0;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
function isExportsMap(value) {
|
|
904
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
905
|
+
}
|
|
455
906
|
function presetImportUrl(path) {
|
|
456
907
|
const url = pathToFileURL3(path);
|
|
457
908
|
url.searchParams.set("mtime", String(statSync(path).mtimeMs));
|
|
@@ -466,6 +917,53 @@ function designSystemImportMap(map, spec) {
|
|
|
466
917
|
tokens: map.tokens ?? `${spec}/tokens`
|
|
467
918
|
};
|
|
468
919
|
}
|
|
920
|
+
var IMPORT_MAP_FIELDS = ["css", "recipes", "patterns", "jsx", "tokens"];
|
|
921
|
+
function validateManifest(spec, manifestPath, value) {
|
|
922
|
+
if (!isPlainObject(value)) {
|
|
923
|
+
throw invalidManifestError(spec, manifestPath, ["must contain a JSON object"]);
|
|
924
|
+
}
|
|
925
|
+
const issues = [];
|
|
926
|
+
requiredString(value, "name", issues);
|
|
927
|
+
requiredString(value, "panda", issues);
|
|
928
|
+
requiredString(value, "preset", issues);
|
|
929
|
+
requiredString(value, "buildInfo", issues);
|
|
930
|
+
if (!Number.isInteger(value.schemaVersion) || value.schemaVersion < 1) {
|
|
931
|
+
issues.push('must contain a positive integer "schemaVersion" entry');
|
|
932
|
+
}
|
|
933
|
+
if (value.version !== void 0 && typeof value.version !== "string") {
|
|
934
|
+
issues.push('has a "version" entry that must be a string');
|
|
935
|
+
}
|
|
936
|
+
if (value.designSystem !== void 0 && !isNonEmptyString(value.designSystem)) {
|
|
937
|
+
issues.push('has a "designSystem" entry that must be a non-empty string');
|
|
938
|
+
}
|
|
939
|
+
if (value.files !== void 0 && (!Array.isArray(value.files) || !value.files.every((file) => isNonEmptyString(file)))) {
|
|
940
|
+
issues.push('has a "files" entry that must be an array of non-empty strings');
|
|
941
|
+
}
|
|
942
|
+
if (value.importMap !== void 0) {
|
|
943
|
+
if (!isPlainObject(value.importMap)) {
|
|
944
|
+
issues.push('has an "importMap" entry that must be an object');
|
|
945
|
+
} else {
|
|
946
|
+
for (const field of IMPORT_MAP_FIELDS) {
|
|
947
|
+
const entry = value.importMap[field];
|
|
948
|
+
if (entry !== void 0 && !isNonEmptyString(entry)) {
|
|
949
|
+
issues.push(`has an "importMap.${field}" entry that must be a non-empty string`);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
if (issues.length > 0) {
|
|
955
|
+
throw invalidManifestError(spec, manifestPath, issues);
|
|
956
|
+
}
|
|
957
|
+
return value;
|
|
958
|
+
}
|
|
959
|
+
function requiredString(value, field, issues) {
|
|
960
|
+
if (!isNonEmptyString(value[field])) {
|
|
961
|
+
issues.push(`is missing a "${field}" entry or it is empty`);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
function isNonEmptyString(value) {
|
|
965
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
966
|
+
}
|
|
469
967
|
function notResolvedError(spec) {
|
|
470
968
|
const message = `designSystem ${JSON.stringify(spec)} could not be resolved. Install it, or \u2014 if it isn't a Panda design system \u2014 build it with \`panda lib\`.`;
|
|
471
969
|
return createConfigError(message, [
|
|
@@ -486,22 +984,36 @@ function cycleError(cycle) {
|
|
|
486
984
|
const message = `Design-system cycle: ${cycle.join(" \u2192 ")}. A design system can't depend on itself.`;
|
|
487
985
|
return createConfigError(message, [createConfigDiagnostic("design_system_cycle", message)]);
|
|
488
986
|
}
|
|
489
|
-
function invalidManifestError(spec,
|
|
490
|
-
const message = `${JSON.stringify(spec)} manifest
|
|
987
|
+
function invalidManifestError(spec, manifestPath, issues) {
|
|
988
|
+
const message = `${JSON.stringify(spec)} manifest ${issues.join("; ")}.`;
|
|
491
989
|
return createConfigError(message, [
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
990
|
+
{
|
|
991
|
+
...createConfigDiagnostic("design_system_manifest_invalid", message, [
|
|
992
|
+
`Rebuild ${JSON.stringify(spec)} with \`panda lib\`.`
|
|
993
|
+
]),
|
|
994
|
+
file: manifestPath
|
|
995
|
+
}
|
|
495
996
|
]);
|
|
496
997
|
}
|
|
998
|
+
function duplicateNameError(name, firstPath, secondPath) {
|
|
999
|
+
const message = `Two different packages in the design-system chain are both named ${JSON.stringify(name)} (${JSON.stringify(firstPath)} and ${JSON.stringify(secondPath)}). Their styles would overwrite each other; give each package a unique name.`;
|
|
1000
|
+
return createConfigError(message, [createConfigDiagnostic("design_system_duplicate_name", message)]);
|
|
1001
|
+
}
|
|
1002
|
+
function specifierProtocol(spec) {
|
|
1003
|
+
const match = spec.match(SPECIFIER_PROTOCOL);
|
|
1004
|
+
return match ? match[1] : void 0;
|
|
1005
|
+
}
|
|
1006
|
+
function unsupportedSpecifierError(spec, protocol) {
|
|
1007
|
+
const message = `designSystem ${JSON.stringify(spec)} uses the "${protocol}:" protocol, which isn't supported. Use the published package name (e.g. "@acme/design-system") that resolves to its \`panda/lib.json\`.`;
|
|
1008
|
+
return createConfigError(message, [createConfigDiagnostic("design_system_unsupported_specifier", message)]);
|
|
1009
|
+
}
|
|
497
1010
|
|
|
498
|
-
// src/smart-include.ts
|
|
499
|
-
import { existsSync as
|
|
500
|
-
import { dirname as
|
|
1011
|
+
// src/design-system/smart-include.ts
|
|
1012
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
1013
|
+
import { dirname as dirname5, isAbsolute as isAbsolute4, join as join3, relative as relative4, resolve as resolve5, sep } from "node:path";
|
|
501
1014
|
var SMART_INCLUDE_EXTENSIONS = ["js", "mjs", "cjs", "jsx", "ts", "cts", "mts", "tsx", "vue", "svelte", "astro"];
|
|
502
|
-
var
|
|
1015
|
+
var MANIFEST_SUBPATH = "panda/lib.json";
|
|
503
1016
|
var PACKAGE_SPECIFIER = /^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/i;
|
|
504
|
-
var PATH_SEPARATOR = /[\\/]/;
|
|
505
1017
|
function resolveSmartInclude(include, cwd, deps) {
|
|
506
1018
|
const offenders = [];
|
|
507
1019
|
const next = [];
|
|
@@ -516,7 +1028,7 @@ function resolveSmartInclude(include, cwd, deps) {
|
|
|
516
1028
|
next.push(entry);
|
|
517
1029
|
continue;
|
|
518
1030
|
}
|
|
519
|
-
if (tryResolveFrom(`${entry}/${
|
|
1031
|
+
if (tryResolveFrom(`${entry}/${MANIFEST_SUBPATH}`, cwd) !== void 0) {
|
|
520
1032
|
offenders.push(entry);
|
|
521
1033
|
continue;
|
|
522
1034
|
}
|
|
@@ -525,11 +1037,11 @@ function resolveSmartInclude(include, cwd, deps) {
|
|
|
525
1037
|
next.push(entry);
|
|
526
1038
|
continue;
|
|
527
1039
|
}
|
|
528
|
-
if (
|
|
1040
|
+
if (existsSync3(join3(packageDir, ...MANIFEST_SUBPATH.split("/")))) {
|
|
529
1041
|
offenders.push(entry);
|
|
530
1042
|
continue;
|
|
531
1043
|
}
|
|
532
|
-
deps.add(
|
|
1044
|
+
deps.add(join3(packageDir, "package.json"));
|
|
533
1045
|
const base = globBase(packageDir, cwd);
|
|
534
1046
|
next.push(`${base}/**/*.{${SMART_INCLUDE_EXTENSIONS.join(",")}}`);
|
|
535
1047
|
excludes.push(`${base}/**/node_modules/**`);
|
|
@@ -548,11 +1060,11 @@ function mergeExcludes(existing, additions) {
|
|
|
548
1060
|
return [...existing ?? [], ...additions];
|
|
549
1061
|
}
|
|
550
1062
|
function isLocalPath(entry, cwd) {
|
|
551
|
-
return
|
|
1063
|
+
return existsSync3(isAbsolute4(entry) ? entry : resolve5(cwd, entry));
|
|
552
1064
|
}
|
|
553
1065
|
function resolvePackageDir(spec, cwd) {
|
|
554
1066
|
const fromPackageJson = tryResolve(`${spec}/package.json`, cwd);
|
|
555
|
-
if (fromPackageJson !== void 0) return
|
|
1067
|
+
if (fromPackageJson !== void 0) return dirname5(fromPackageJson);
|
|
556
1068
|
const fromEntry = tryResolve(spec, cwd);
|
|
557
1069
|
return fromEntry === void 0 ? void 0 : nearestPackageDir(fromEntry);
|
|
558
1070
|
}
|
|
@@ -566,30 +1078,27 @@ function tryResolve(request, cwd) {
|
|
|
566
1078
|
}
|
|
567
1079
|
function isInsideCwd(relativePath) {
|
|
568
1080
|
if (relativePath === "" || relativePath === "..") return false;
|
|
569
|
-
if (
|
|
1081
|
+
if (isAbsolute4(relativePath)) return false;
|
|
570
1082
|
return !relativePath.startsWith(`..${sep}`);
|
|
571
1083
|
}
|
|
572
1084
|
function nearestPackageDir(from) {
|
|
573
|
-
let dir =
|
|
1085
|
+
let dir = dirname5(from);
|
|
574
1086
|
while (true) {
|
|
575
|
-
if (
|
|
576
|
-
const parent =
|
|
1087
|
+
if (existsSync3(join3(dir, "package.json"))) return dir;
|
|
1088
|
+
const parent = dirname5(dir);
|
|
577
1089
|
if (parent === dir) return void 0;
|
|
578
1090
|
dir = parent;
|
|
579
1091
|
}
|
|
580
1092
|
}
|
|
581
1093
|
function globBase(packageDir, cwd) {
|
|
582
|
-
const rel =
|
|
1094
|
+
const rel = relative4(cwd, packageDir);
|
|
583
1095
|
const base = isInsideCwd(rel) ? rel : packageDir;
|
|
584
|
-
return
|
|
585
|
-
}
|
|
586
|
-
function toPosix(path) {
|
|
587
|
-
return path.split(PATH_SEPARATOR).join("/");
|
|
1096
|
+
return toPosixPath(base);
|
|
588
1097
|
}
|
|
589
1098
|
function inIncludeError(specs) {
|
|
590
1099
|
const list = specs.map((spec) => JSON.stringify(spec)).join(", ");
|
|
591
1100
|
const plural = specs.length > 1;
|
|
592
|
-
const message = `Design system${plural ? "s" : ""} in \`include\`: ${list}. ${plural ? "They each ship" : "It ships"} a ${
|
|
1101
|
+
const message = `Design system${plural ? "s" : ""} in \`include\`: ${list}. ${plural ? "They each ship" : "It ships"} a ${MANIFEST_SUBPATH}, so ${plural ? "they belong" : "it belongs"} in \`designSystem\`, not \`include\`. \`include\` is for files, not design systems.`;
|
|
593
1102
|
return createConfigError(
|
|
594
1103
|
message,
|
|
595
1104
|
specs.map(
|
|
@@ -602,18 +1111,46 @@ function inIncludeError(specs) {
|
|
|
602
1111
|
);
|
|
603
1112
|
}
|
|
604
1113
|
|
|
605
|
-
// src/token-paths.ts
|
|
1114
|
+
// src/design-system/token-paths.ts
|
|
1115
|
+
import { isDeepStrictEqual } from "node:util";
|
|
606
1116
|
function collectTokenPaths(config) {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
1117
|
+
return [...collectTokenEntries(config).keys()].sort();
|
|
1118
|
+
}
|
|
1119
|
+
function collectTokenEntries(config) {
|
|
1120
|
+
const entries = /* @__PURE__ */ new Map();
|
|
1121
|
+
if (!isPlainObject(config?.theme)) {
|
|
1122
|
+
return entries;
|
|
1123
|
+
}
|
|
1124
|
+
collect(config.theme.tokens, [], entries);
|
|
1125
|
+
collect(config.theme.semanticTokens, [], entries);
|
|
1126
|
+
return entries;
|
|
1127
|
+
}
|
|
1128
|
+
function resolveUserTokenPathsAfterHooks(userTokenPaths, beforeHooks, afterHooks) {
|
|
1129
|
+
const paths = new Set(userTokenPaths);
|
|
1130
|
+
const after = collectTokenEntries(afterHooks);
|
|
1131
|
+
for (const path of paths) {
|
|
1132
|
+
if (!after.has(path)) {
|
|
1133
|
+
paths.delete(path);
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
for (const [path, values] of after) {
|
|
1137
|
+
if (!beforeHooks.has(path) || !isDeepStrictEqual(beforeHooks.get(path), values)) {
|
|
1138
|
+
paths.add(path);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
611
1141
|
return [...paths].sort();
|
|
612
1142
|
}
|
|
613
1143
|
function collect(node, trail, out) {
|
|
614
|
-
if (!isPlainObject(node))
|
|
1144
|
+
if (!isPlainObject(node)) {
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
615
1147
|
if ("value" in node) {
|
|
616
|
-
if (trail.length > 0)
|
|
1148
|
+
if (trail.length > 0) {
|
|
1149
|
+
const path = trail.join(".");
|
|
1150
|
+
const entries = out.get(path) ?? [];
|
|
1151
|
+
entries.push(node.value);
|
|
1152
|
+
out.set(path, entries);
|
|
1153
|
+
}
|
|
617
1154
|
return;
|
|
618
1155
|
}
|
|
619
1156
|
for (const [key, child] of Object.entries(node)) {
|
|
@@ -621,59 +1158,115 @@ function collect(node, trail, out) {
|
|
|
621
1158
|
}
|
|
622
1159
|
}
|
|
623
1160
|
|
|
1161
|
+
// src/artifact-names.ts
|
|
1162
|
+
function collectRecipeNames(config) {
|
|
1163
|
+
const theme = config?.theme;
|
|
1164
|
+
if (!theme) return [];
|
|
1165
|
+
const names = /* @__PURE__ */ new Set([...Object.keys(theme.recipes ?? {}), ...Object.keys(theme.slotRecipes ?? {})]);
|
|
1166
|
+
return [...names].sort();
|
|
1167
|
+
}
|
|
1168
|
+
function collectPatternNames(config) {
|
|
1169
|
+
return Object.keys(config?.patterns ?? {}).sort();
|
|
1170
|
+
}
|
|
1171
|
+
|
|
624
1172
|
// src/preset.ts
|
|
625
|
-
async function
|
|
1173
|
+
async function resolveAuthoredPresetsForLoad(config, cwd, options = {}) {
|
|
1174
|
+
const designSystem = config.designSystem;
|
|
1175
|
+
const hasDesignSystem = typeof designSystem === "string" && designSystem.length > 0;
|
|
1176
|
+
const trackSources = options.trackSources ?? hasDesignSystem;
|
|
626
1177
|
const ctx = {
|
|
627
1178
|
cwd,
|
|
628
1179
|
configs: [],
|
|
629
1180
|
dependencies: /* @__PURE__ */ new Set(),
|
|
630
1181
|
presetResolvedHooks: [],
|
|
631
|
-
...
|
|
1182
|
+
...trackSources ? { sourcedConfigs: [] } : {}
|
|
632
1183
|
};
|
|
633
1184
|
const rootSource = { kind: "config" };
|
|
634
|
-
if (options.configFile)
|
|
635
|
-
|
|
1185
|
+
if (options.configFile) {
|
|
1186
|
+
rootSource.file = normalize2(relative5(cwd, options.configFile));
|
|
1187
|
+
}
|
|
636
1188
|
let dsChain = [];
|
|
637
|
-
|
|
1189
|
+
const designSystemCompatibility = [];
|
|
1190
|
+
if (hasDesignSystem) {
|
|
638
1191
|
dsChain = await loadDesignSystemChain(designSystem, cwd, ctx.dependencies);
|
|
639
1192
|
for (const level of dsChain) {
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
level.info.tokenPaths = collectTokenPaths(
|
|
648
|
-
|
|
1193
|
+
const dsSource = { kind: "preset", specifier: level.info.name, name: level.info.name };
|
|
1194
|
+
const resolution = await resolveConfigEntry(level.preset, dsSource, cwd, ctx.dependencies, trackSources);
|
|
1195
|
+
if (resolution.sourcedConfigs) {
|
|
1196
|
+
for (const sourced of resolution.sourcedConfigs) {
|
|
1197
|
+
sourced.source = dsSource;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
level.info.tokenPaths = collectTokenPaths(resolution.config);
|
|
1201
|
+
level.info.recipeNames = collectRecipeNames(resolution.config);
|
|
1202
|
+
level.info.patternNames = collectPatternNames(resolution.config);
|
|
1203
|
+
appendConfigResolution(ctx, resolution);
|
|
1204
|
+
designSystemCompatibility.push({
|
|
1205
|
+
designSystem: level.info,
|
|
1206
|
+
classNameOptions: normalizeClassNameOptions(mergeConfigs(ctx.configs)),
|
|
1207
|
+
presetConfig: resolution.config
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
const rootResolution = await resolveConfigEntry(config, rootSource, cwd, ctx.dependencies, trackSources);
|
|
1212
|
+
appendConfigResolution(ctx, rootResolution);
|
|
1213
|
+
for (const { designSystem: designSystem2, classNameOptions } of designSystemCompatibility) {
|
|
1214
|
+
const mismatch = diffClassNameOptions(rootResolution.config, classNameOptions, "explicit");
|
|
1215
|
+
if (mismatch.length > 0) {
|
|
1216
|
+
designSystem2.optionMismatch = mismatch;
|
|
649
1217
|
}
|
|
650
1218
|
}
|
|
651
|
-
const rootBlock = await collectConfigBlock(config, rootSource, cwd, ctx.dependencies, options.trackSources);
|
|
652
|
-
appendConfigBlock(ctx, rootBlock);
|
|
653
1219
|
const dsInfos = dsChain.map((level) => level.info);
|
|
654
1220
|
const finalize = (resolved) => {
|
|
655
1221
|
const withImportMap = dsInfos.length > 0 ? withDesignSystemImportMap(resolved, dsInfos) : resolved;
|
|
656
1222
|
return expandSmartInclude(withImportMap, cwd, ctx.dependencies);
|
|
657
1223
|
};
|
|
658
|
-
const
|
|
1224
|
+
const leafCompatibility = designSystemCompatibility[designSystemCompatibility.length - 1];
|
|
659
1225
|
if (ctx.sourcedConfigs) {
|
|
660
1226
|
const merged = mergeConfigsWithSources(ctx.sourcedConfigs);
|
|
661
|
-
if (options.preserveRuntimeHooks)
|
|
1227
|
+
if (options.preserveRuntimeHooks) {
|
|
1228
|
+
attachRuntimeHooks(merged.config, ctx.configs);
|
|
1229
|
+
}
|
|
1230
|
+
const finalized2 = finalize(merged.config);
|
|
1231
|
+
let overlayInput;
|
|
1232
|
+
if (leafCompatibility) {
|
|
1233
|
+
const input = buildOverlayInput(merged.sources, finalized2, dsInfos, leafCompatibility.presetConfig, cwd);
|
|
1234
|
+
const leafClassMismatch = leafCompatibility.designSystem.optionMismatch ?? [];
|
|
1235
|
+
overlayInput = {
|
|
1236
|
+
authored: input.authored,
|
|
1237
|
+
compatible: input.compatible && leafClassMismatch.length === 0
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
const dsMetadata2 = dsInfos.length > 0 ? {
|
|
1241
|
+
designSystem: dsInfos,
|
|
1242
|
+
userTokenPaths: collectTokenPaths(rootResolution.config),
|
|
1243
|
+
userRecipeNames: collectRecipeNames(rootResolution.config),
|
|
1244
|
+
userPatternNames: collectPatternNames(rootResolution.config),
|
|
1245
|
+
...overlayInput ? { overlayInput } : {}
|
|
1246
|
+
} : void 0;
|
|
662
1247
|
return {
|
|
663
|
-
config:
|
|
1248
|
+
config: finalized2,
|
|
664
1249
|
dependencies: Array.from(ctx.dependencies),
|
|
665
|
-
metadata: { sources: merged.sources, ...
|
|
1250
|
+
metadata: { sources: merged.sources, ...dsMetadata2 },
|
|
1251
|
+
designSystemCompatibility
|
|
666
1252
|
};
|
|
667
1253
|
}
|
|
1254
|
+
const mergedConfig = options.preserveRuntimeHooks ? attachRuntimeHooks(mergeConfigs(ctx.configs), ctx.configs) : mergeConfigs(ctx.configs);
|
|
1255
|
+
const finalized = finalize(mergedConfig);
|
|
1256
|
+
const dsMetadata = dsInfos.length > 0 ? {
|
|
1257
|
+
designSystem: dsInfos,
|
|
1258
|
+
userTokenPaths: collectTokenPaths(rootResolution.config),
|
|
1259
|
+
userRecipeNames: collectRecipeNames(rootResolution.config),
|
|
1260
|
+
userPatternNames: collectPatternNames(rootResolution.config)
|
|
1261
|
+
} : void 0;
|
|
668
1262
|
return {
|
|
669
|
-
config:
|
|
670
|
-
options.preserveRuntimeHooks ? attachRuntimeHooks(mergeConfigs(ctx.configs), ctx.configs) : mergeConfigs(ctx.configs)
|
|
671
|
-
),
|
|
1263
|
+
config: finalized,
|
|
672
1264
|
dependencies: Array.from(ctx.dependencies),
|
|
673
|
-
...dsMetadata ? { metadata: dsMetadata } : {}
|
|
1265
|
+
...dsMetadata ? { metadata: dsMetadata } : {},
|
|
1266
|
+
designSystemCompatibility
|
|
674
1267
|
};
|
|
675
1268
|
}
|
|
676
|
-
async function
|
|
1269
|
+
async function resolveConfigEntry(config, source, cwd, dependencies, trackSources) {
|
|
677
1270
|
const ctx = {
|
|
678
1271
|
cwd,
|
|
679
1272
|
configs: [],
|
|
@@ -685,13 +1278,13 @@ async function collectConfigBlock(config, source, cwd, dependencies, trackSource
|
|
|
685
1278
|
return {
|
|
686
1279
|
configs: ctx.configs,
|
|
687
1280
|
...ctx.sourcedConfigs ? { sourcedConfigs: ctx.sourcedConfigs } : {},
|
|
688
|
-
|
|
1281
|
+
config: mergeConfigs(ctx.configs)
|
|
689
1282
|
};
|
|
690
1283
|
}
|
|
691
|
-
function
|
|
692
|
-
ctx.configs.push(...
|
|
693
|
-
if (ctx.sourcedConfigs &&
|
|
694
|
-
ctx.sourcedConfigs.push(...
|
|
1284
|
+
function appendConfigResolution(ctx, resolution) {
|
|
1285
|
+
ctx.configs.push(...resolution.configs);
|
|
1286
|
+
if (ctx.sourcedConfigs && resolution.sourcedConfigs) {
|
|
1287
|
+
ctx.sourcedConfigs.push(...resolution.sourcedConfigs);
|
|
695
1288
|
}
|
|
696
1289
|
}
|
|
697
1290
|
async function collectConfigs(config, source, ctx, active) {
|
|
@@ -777,7 +1370,7 @@ async function loadConfig(options) {
|
|
|
777
1370
|
if (!isPlainObject(config)) {
|
|
778
1371
|
throw new PandaError("CONFIG_ERROR", "\u{1F4A5} Config must export or return an object.");
|
|
779
1372
|
}
|
|
780
|
-
const authored = await
|
|
1373
|
+
const authored = await resolveAuthoredPresetsForLoad(config, cwd, {
|
|
781
1374
|
configFile: path,
|
|
782
1375
|
trackSources: options.trackSources,
|
|
783
1376
|
preserveRuntimeHooks: true
|
|
@@ -785,8 +1378,16 @@ async function loadConfig(options) {
|
|
|
785
1378
|
const authoredDependencies = Array.from(
|
|
786
1379
|
/* @__PURE__ */ new Set([...dependencies, ...authored.dependencies, ...authored.config.dependencies ?? []])
|
|
787
1380
|
);
|
|
1381
|
+
const tokenEntriesBeforeHooks = collectTokenEntries(authored.config);
|
|
788
1382
|
const userConfig = await runConfigResolvedHooks(authored.config, path, authoredDependencies);
|
|
789
|
-
const resolved =
|
|
1383
|
+
const resolved = applyConfigDefaults2(userConfig, cwd);
|
|
1384
|
+
refreshDesignSystemMetadata(
|
|
1385
|
+
authored.metadata,
|
|
1386
|
+
authored.designSystemCompatibility,
|
|
1387
|
+
resolved,
|
|
1388
|
+
tokenEntriesBeforeHooks,
|
|
1389
|
+
cwd
|
|
1390
|
+
);
|
|
790
1391
|
const dependencyList = Array.from(
|
|
791
1392
|
/* @__PURE__ */ new Set([...dependencies, ...authored.dependencies, ...resolved.dependencies ?? []])
|
|
792
1393
|
);
|
|
@@ -798,12 +1399,40 @@ async function loadConfig(options) {
|
|
|
798
1399
|
...snapshot.hooks ? { hooks: snapshot.hooks } : {},
|
|
799
1400
|
hostHooks: {
|
|
800
1401
|
"codegen:prepare": collectPluginHookHandlers(resolved, "codegen:prepare"),
|
|
801
|
-
"codegen:done": collectPluginHookHandlers(resolved, "codegen:done")
|
|
1402
|
+
"codegen:done": collectPluginHookHandlers(resolved, "codegen:done"),
|
|
1403
|
+
"cssgen:done": collectPluginHookHandlers(resolved, "cssgen:done")
|
|
802
1404
|
},
|
|
803
1405
|
dependencies: dependencyList,
|
|
804
1406
|
...authored.metadata ? { metadata: authored.metadata } : {}
|
|
805
1407
|
};
|
|
806
1408
|
}
|
|
1409
|
+
function refreshDesignSystemMetadata(metadata, designSystemCompatibility, config, tokenEntriesBeforeHooks, cwd) {
|
|
1410
|
+
if (!metadata?.designSystem?.length) return;
|
|
1411
|
+
metadata.userTokenPaths = resolveUserTokenPathsAfterHooks(
|
|
1412
|
+
metadata.userTokenPaths ?? [],
|
|
1413
|
+
tokenEntriesBeforeHooks,
|
|
1414
|
+
config
|
|
1415
|
+
);
|
|
1416
|
+
const chain = metadata.designSystem;
|
|
1417
|
+
const sources = metadata.sources;
|
|
1418
|
+
const leaf = designSystemCompatibility[designSystemCompatibility.length - 1];
|
|
1419
|
+
for (const { designSystem, classNameOptions } of designSystemCompatibility) {
|
|
1420
|
+
const mismatch = diffClassNameOptions(config, classNameOptions, "effective");
|
|
1421
|
+
if (mismatch.length > 0) {
|
|
1422
|
+
designSystem.optionMismatch = mismatch;
|
|
1423
|
+
} else {
|
|
1424
|
+
delete designSystem.optionMismatch;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
if (sources && leaf) {
|
|
1428
|
+
const input = buildOverlayInput(sources, config, chain, leaf.presetConfig, cwd);
|
|
1429
|
+
const leafClassMismatch = leaf.designSystem.optionMismatch ?? [];
|
|
1430
|
+
metadata.overlayInput = {
|
|
1431
|
+
authored: input.authored,
|
|
1432
|
+
compatible: input.compatible && leafClassMismatch.length === 0
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
807
1436
|
async function runConfigResolvedHooks(config, path, dependencies) {
|
|
808
1437
|
let current = config;
|
|
809
1438
|
for (const entry of collectPluginHookHandlers(current, "config:resolved")) {
|
|
@@ -833,7 +1462,6 @@ var ALL_DEPENDENCIES = [
|
|
|
833
1462
|
"prefix",
|
|
834
1463
|
"recipes",
|
|
835
1464
|
"separator",
|
|
836
|
-
"syntax",
|
|
837
1465
|
"themes",
|
|
838
1466
|
"tokens",
|
|
839
1467
|
"utilities"
|
|
@@ -887,8 +1515,6 @@ function classify(path) {
|
|
|
887
1515
|
return { deps: ["patterns"], pattern: second };
|
|
888
1516
|
case "themes":
|
|
889
1517
|
return { deps: ["themes"] };
|
|
890
|
-
case "syntax":
|
|
891
|
-
return { deps: ["syntax"] };
|
|
892
1518
|
case "hash":
|
|
893
1519
|
return { deps: ["hash"] };
|
|
894
1520
|
case "prefix":
|
|
@@ -925,27 +1551,36 @@ function isConfigSnapshot(input) {
|
|
|
925
1551
|
}
|
|
926
1552
|
|
|
927
1553
|
// src/version.ts
|
|
928
|
-
import { readFileSync as
|
|
929
|
-
import { dirname as
|
|
930
|
-
import { fileURLToPath } from "url";
|
|
1554
|
+
import { readFileSync as readFileSync3 } from "node:fs";
|
|
1555
|
+
import { dirname as dirname6, join as join4 } from "node:path";
|
|
1556
|
+
import { fileURLToPath } from "node:url";
|
|
1557
|
+
var MAJOR_VERSION_RE = /\d+/;
|
|
1558
|
+
var STAMPABLE_PANDA_RANGE_RE = /^[v=><~^]|^\d/;
|
|
931
1559
|
function readPandaVersion() {
|
|
932
1560
|
try {
|
|
933
|
-
const pkgPath =
|
|
934
|
-
return JSON.parse(
|
|
1561
|
+
const pkgPath = join4(dirname6(fileURLToPath(import.meta.url)), "../package.json");
|
|
1562
|
+
return JSON.parse(readFileSync3(pkgPath, "utf8")).version;
|
|
935
1563
|
} catch {
|
|
936
1564
|
return void 0;
|
|
937
1565
|
}
|
|
938
1566
|
}
|
|
1567
|
+
function getPandaMajorRange() {
|
|
1568
|
+
const match = readPandaVersion()?.match(MAJOR_VERSION_RE);
|
|
1569
|
+
return match ? `^${match[0]}.0.0` : void 0;
|
|
1570
|
+
}
|
|
1571
|
+
function isStampablePandaRange(range) {
|
|
1572
|
+
return range !== void 0 && STAMPABLE_PANDA_RANGE_RE.test(range.trim());
|
|
1573
|
+
}
|
|
939
1574
|
|
|
940
|
-
// src/
|
|
941
|
-
import { builtinModules as builtinModules2 } from "module";
|
|
942
|
-
import { rolldown as rolldown2 } from "rolldown";
|
|
1575
|
+
// src/design-system/compile-preset.ts
|
|
1576
|
+
import { builtinModules as builtinModules2 } from "node:module";
|
|
943
1577
|
var APP_FIELDS = ["designSystem", "include", "exclude", "outdir", "cwd", "watch", "clean", "gitignore", "importMap"];
|
|
944
1578
|
var VIRTUAL_ENTRY = "\0panda-lib-preset-entry";
|
|
945
1579
|
var nodeBuiltins2 = /* @__PURE__ */ new Set([...builtinModules2, ...builtinModules2.map((mod) => `node:${mod}`)]);
|
|
946
1580
|
async function compilePreset(options) {
|
|
947
1581
|
const { configPath, cwd } = options;
|
|
948
|
-
const
|
|
1582
|
+
const { rolldown } = await import("rolldown");
|
|
1583
|
+
const build = await rolldown({
|
|
949
1584
|
input: VIRTUAL_ENTRY,
|
|
950
1585
|
cwd,
|
|
951
1586
|
platform: "node",
|
|
@@ -996,100 +1631,33 @@ async function validatePreset(code) {
|
|
|
996
1631
|
try {
|
|
997
1632
|
await import(`data:text/javascript;base64,${Buffer.from(code).toString("base64")}`);
|
|
998
1633
|
} catch (error) {
|
|
999
|
-
throw new PandaError("CONFIG_ERROR", `\u{1F4A5} Failed to compile design system preset: ${
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
function errorMessage2(error) {
|
|
1003
|
-
return error instanceof Error ? error.message : String(error);
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
// src/lib-manifest.ts
|
|
1007
|
-
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
1008
|
-
import { dirname as dirname6, isAbsolute as isAbsolute4, join as join4, relative as relative4 } from "path";
|
|
1009
|
-
function readPackageIdentity(cwd) {
|
|
1010
|
-
const packagePath = nearestPackageJson(cwd);
|
|
1011
|
-
if (packagePath === void 0) {
|
|
1012
|
-
throw new Error(`Could not find a package.json from ${JSON.stringify(cwd)} to build the design system manifest.`);
|
|
1013
|
-
}
|
|
1014
|
-
const pkg = JSON.parse(readFileSync3(packagePath, "utf8"));
|
|
1015
|
-
const name = pkg.name;
|
|
1016
|
-
if (typeof name !== "string" || name.length === 0) {
|
|
1017
|
-
throw new Error(`${JSON.stringify(packagePath)} has no "name"; a design system must be a named package.`);
|
|
1018
|
-
}
|
|
1019
|
-
const peer = pkg.peerDependencies?.["@pandacss/dev"];
|
|
1020
|
-
return {
|
|
1021
|
-
name,
|
|
1022
|
-
version: typeof pkg.version === "string" ? pkg.version : void 0,
|
|
1023
|
-
pandaPeer: typeof peer === "string" ? peer : void 0,
|
|
1024
|
-
packagePath
|
|
1025
|
-
};
|
|
1026
|
-
}
|
|
1027
|
-
function defaultImportMap(name) {
|
|
1028
|
-
return {
|
|
1029
|
-
css: `${name}/css`,
|
|
1030
|
-
recipes: `${name}/recipes`,
|
|
1031
|
-
patterns: `${name}/patterns`,
|
|
1032
|
-
jsx: `${name}/jsx`,
|
|
1033
|
-
tokens: `${name}/tokens`
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
function syncExports(options) {
|
|
1037
|
-
const { packageJson, entries } = options;
|
|
1038
|
-
const pkg = JSON.parse(packageJson);
|
|
1039
|
-
const existing = normalizeExports(pkg.exports);
|
|
1040
|
-
const merged = { ...existing };
|
|
1041
|
-
for (const [key, value] of Object.entries(entries)) merged[key] = value;
|
|
1042
|
-
const changed = JSON.stringify(pkg.exports) !== JSON.stringify(merged);
|
|
1043
|
-
const out = { ...pkg, exports: merged };
|
|
1044
|
-
return { changed, json: `${JSON.stringify(out, null, 2)}
|
|
1045
|
-
` };
|
|
1046
|
-
}
|
|
1047
|
-
function toPosixPath(path) {
|
|
1048
|
-
return path.split("\\").join("/");
|
|
1049
|
-
}
|
|
1050
|
-
function toPosixRelative(from, to) {
|
|
1051
|
-
const rel = toPosixPath(relative4(from, to));
|
|
1052
|
-
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
1053
|
-
}
|
|
1054
|
-
function toRelativeKey(key, cwd) {
|
|
1055
|
-
return toPosixPath(isAbsolute4(key) ? relative4(cwd, key) : key);
|
|
1056
|
-
}
|
|
1057
|
-
function isPlainObject2(value) {
|
|
1058
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1059
|
-
}
|
|
1060
|
-
function normalizeExports(exports) {
|
|
1061
|
-
if (exports === void 0) return {};
|
|
1062
|
-
if (typeof exports === "string") return { ".": exports };
|
|
1063
|
-
if (!isPlainObject2(exports)) return {};
|
|
1064
|
-
if (isSubpathExportMap(exports)) return exports;
|
|
1065
|
-
return { ".": exports };
|
|
1066
|
-
}
|
|
1067
|
-
function isSubpathExportMap(exports) {
|
|
1068
|
-
return Object.keys(exports).some((key) => key === "." || key.startsWith("./"));
|
|
1069
|
-
}
|
|
1070
|
-
function nearestPackageJson(start) {
|
|
1071
|
-
let current = start;
|
|
1072
|
-
while (true) {
|
|
1073
|
-
const candidate = join4(current, "package.json");
|
|
1074
|
-
if (existsSync3(candidate)) return candidate;
|
|
1075
|
-
const parent = dirname6(current);
|
|
1076
|
-
if (parent === current) return void 0;
|
|
1077
|
-
current = parent;
|
|
1634
|
+
throw new PandaError("CONFIG_ERROR", `\u{1F4A5} Failed to compile design system preset: ${errorMessage(error)}`);
|
|
1078
1635
|
}
|
|
1079
1636
|
}
|
|
1080
1637
|
export {
|
|
1638
|
+
buildCodegenOverlay,
|
|
1081
1639
|
bundleConfig,
|
|
1640
|
+
collectArtifactConflicts,
|
|
1641
|
+
collectExportMissingDiagnostics,
|
|
1642
|
+
collectNameCollisionDiagnostics,
|
|
1643
|
+
collectPatternNames,
|
|
1644
|
+
collectRecipeNames,
|
|
1082
1645
|
collectTokenPaths,
|
|
1083
1646
|
compilePreset,
|
|
1084
1647
|
createConfigSnapshot,
|
|
1085
1648
|
defaultImportMap,
|
|
1086
1649
|
diffConfig,
|
|
1650
|
+
filterPublishableLibFiles,
|
|
1087
1651
|
findConfig,
|
|
1652
|
+
getPandaMajorRange,
|
|
1653
|
+
isStampablePandaRange,
|
|
1088
1654
|
loadConfig,
|
|
1089
1655
|
mergeConfigs,
|
|
1090
1656
|
mergeExcludes,
|
|
1091
1657
|
readPackageIdentity,
|
|
1092
1658
|
readPandaVersion,
|
|
1659
|
+
readPublishFilesField,
|
|
1660
|
+
resolvePublishedPandaRange,
|
|
1093
1661
|
resolveSmartInclude,
|
|
1094
1662
|
syncExports,
|
|
1095
1663
|
toPosixPath,
|