@pandacss/compiler 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/binding.cjs +200 -85
- package/dist/chunk-CDATBPPB.js +1588 -0
- package/dist/index.d.ts +30 -152
- package/dist/index.js +5 -3
- package/dist/loader.d.ts +3 -2
- package/dist/loader.js +1 -1
- package/dist/tooling/index.d.ts +108 -0
- package/dist/tooling/index.js +1236 -0
- package/dist/types-CxQirxMo.d.ts +152 -0
- package/package.json +28 -18
- package/dist/chunk-QPHZ2RG2.js +0 -1043
|
@@ -0,0 +1,1236 @@
|
|
|
1
|
+
// src/tooling/create-project.ts
|
|
2
|
+
import { defaultConfig } from "@pandacss/compiler-shared";
|
|
3
|
+
import {
|
|
4
|
+
collectExportMissingDiagnostics,
|
|
5
|
+
collectNameCollisionDiagnostics,
|
|
6
|
+
loadConfig
|
|
7
|
+
} from "@pandacss/config";
|
|
8
|
+
|
|
9
|
+
// src/design-system.ts
|
|
10
|
+
import "@pandacss/compiler-shared";
|
|
11
|
+
import {
|
|
12
|
+
collectArtifactConflicts,
|
|
13
|
+
readPandaVersion
|
|
14
|
+
} from "@pandacss/config";
|
|
15
|
+
function artifactConflictDiagnostics(metadata) {
|
|
16
|
+
return collectArtifactConflicts(metadata).flatMap((conflict) => [
|
|
17
|
+
...conflict.recipes.map((name) => artifactConflict("Recipe", name, conflict.name)),
|
|
18
|
+
...conflict.patterns.map((name) => artifactConflict("Pattern", name, conflict.name))
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
function artifactConflict(kind, name, designSystem) {
|
|
22
|
+
return {
|
|
23
|
+
code: "design_system_artifact_conflict",
|
|
24
|
+
severity: "warning",
|
|
25
|
+
category: "designSystem",
|
|
26
|
+
message: `${kind} ${JSON.stringify(name)} is defined by both ${JSON.stringify(designSystem)} and this config; your definition is merged over the design system's.`
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function hydrateDesignSystem(compiler, options) {
|
|
30
|
+
const { chain, consumerTokenPaths = [], treeshake, importSelections } = options;
|
|
31
|
+
if (!chain || chain.length === 0) {
|
|
32
|
+
return { diagnostics: [], treeshakeKey: "" };
|
|
33
|
+
}
|
|
34
|
+
const pandaVersion = readPandaVersion();
|
|
35
|
+
const diagnostics = [];
|
|
36
|
+
const appSelections = treeshake ? importSelections ?? collectImportSelections(compiler, chain) : void 0;
|
|
37
|
+
const selections = appSelections && withDependencyImports(compiler, chain, appSelections);
|
|
38
|
+
for (let i = 0; i < chain.length; i++) {
|
|
39
|
+
const ds = chain[i];
|
|
40
|
+
const imports = selections ? selections[i] ?? void 0 : void 0;
|
|
41
|
+
diagnostics.push(...hydrateLevel(compiler, ds, pandaVersion, consumerTokenPaths, imports));
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
diagnostics,
|
|
45
|
+
treeshakeKey: treeshakeKeyFromSelections(chain, appSelections)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
var ALL_MODULES = { kind: "all" };
|
|
49
|
+
var NO_MODULES = { kind: "none" };
|
|
50
|
+
function withDependencyImports(compiler, chain, appSelections) {
|
|
51
|
+
const selections = appSelections.map(selectionFromScan);
|
|
52
|
+
for (let i = chain.length - 1; i > 0; i--) {
|
|
53
|
+
const selected = selections[i];
|
|
54
|
+
if (selected.kind === "none") continue;
|
|
55
|
+
const info = readBuildInfo(compiler, chain[i]);
|
|
56
|
+
for (let ancestorIndex = 0; ancestorIndex < i; ancestorIndex++) {
|
|
57
|
+
const imported = info ? compiler.designSystem.dependencyImports(info, selectionToImports(selected), chain[ancestorIndex].name) : void 0;
|
|
58
|
+
selections[ancestorIndex] = mergeSelection(selections[ancestorIndex], selectionFromImports(imported));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return selections.map(selectionToScan);
|
|
62
|
+
}
|
|
63
|
+
function selectionFromScan(selection) {
|
|
64
|
+
if (selection == null) return ALL_MODULES;
|
|
65
|
+
return selection.length === 0 ? NO_MODULES : { kind: "names", names: selection };
|
|
66
|
+
}
|
|
67
|
+
function selectionFromImports(imports) {
|
|
68
|
+
if (imports === void 0) return ALL_MODULES;
|
|
69
|
+
return imports.length === 0 ? NO_MODULES : { kind: "names", names: imports };
|
|
70
|
+
}
|
|
71
|
+
function selectionToImports(selection) {
|
|
72
|
+
if (selection.kind === "all") return void 0;
|
|
73
|
+
return selection.kind === "none" ? [] : selection.names;
|
|
74
|
+
}
|
|
75
|
+
function selectionToScan(selection) {
|
|
76
|
+
if (selection.kind === "all") return null;
|
|
77
|
+
return selection.kind === "none" ? [] : selection.names;
|
|
78
|
+
}
|
|
79
|
+
function mergeSelection(current, added) {
|
|
80
|
+
if (current.kind === "all" || added.kind === "all") return ALL_MODULES;
|
|
81
|
+
if (current.kind === "none") return added;
|
|
82
|
+
if (added.kind === "none") return current;
|
|
83
|
+
return { kind: "names", names: [.../* @__PURE__ */ new Set([...current.names, ...added.names])] };
|
|
84
|
+
}
|
|
85
|
+
function readBuildInfo(compiler, ds) {
|
|
86
|
+
if (ds.optionMismatch?.length) return void 0;
|
|
87
|
+
try {
|
|
88
|
+
const content = compiler.fs.readFile(ds.buildInfoPath);
|
|
89
|
+
if (content == null) return void 0;
|
|
90
|
+
const info = JSON.parse(content);
|
|
91
|
+
return compiler.buildInfo.validate(info).ok ? info : void 0;
|
|
92
|
+
} catch {
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function collectImportSelections(compiler, chain) {
|
|
97
|
+
return compiler.designSystemImportSelections(
|
|
98
|
+
chain.map((ds) => ({
|
|
99
|
+
packageRoots: getPackageRoots(ds),
|
|
100
|
+
excludeModules: getExcludedModules(ds)
|
|
101
|
+
}))
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
function treeshakeKeyFromSelections(chain, selections) {
|
|
105
|
+
if (!selections?.length) return "";
|
|
106
|
+
return chain.map((ds, i) => `${ds.name}:${JSON.stringify(selections[i] ?? null)}`).join("|");
|
|
107
|
+
}
|
|
108
|
+
var STYLED_SYSTEM_SUBPATHS = ["css", "recipes", "patterns", "jsx", "tokens"];
|
|
109
|
+
function getPackageRoots(ds) {
|
|
110
|
+
return [...new Set([ds.specifier, ds.name].filter((value) => Boolean(value)))];
|
|
111
|
+
}
|
|
112
|
+
function getExcludedModules(ds) {
|
|
113
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
114
|
+
for (const root of getPackageRoots(ds)) {
|
|
115
|
+
for (const sub of STYLED_SYSTEM_SUBPATHS) {
|
|
116
|
+
excluded.add(`${root}/${sub}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const map = ds.importMap;
|
|
120
|
+
if (map) {
|
|
121
|
+
for (const value of [map.css, map.recipes, map.patterns, map.jsx, map.tokens]) {
|
|
122
|
+
if (typeof value === "string" && value.length > 0) excluded.add(value);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return [...excluded];
|
|
126
|
+
}
|
|
127
|
+
function hydrateLevel(compiler, ds, pandaVersion, consumerTokenPaths, imports) {
|
|
128
|
+
const compat = compiler.designSystem.validate(ds.manifest, { pandaVersion });
|
|
129
|
+
if (!compat.ok) {
|
|
130
|
+
throw incompatibleManifestError(compiler, ds, compat.reason, pandaVersion);
|
|
131
|
+
}
|
|
132
|
+
const diagnostics = hydrateArtifacts(compiler, ds, pandaVersion, imports);
|
|
133
|
+
diagnostics.push(...tokenConflictDiagnostics(ds, consumerTokenPaths));
|
|
134
|
+
return diagnostics;
|
|
135
|
+
}
|
|
136
|
+
function hydrateArtifacts(compiler, ds, pandaVersion, imports) {
|
|
137
|
+
if (ds.optionMismatch && ds.optionMismatch.length > 0) {
|
|
138
|
+
const diagnostic = recoverFromSources(
|
|
139
|
+
compiler,
|
|
140
|
+
ds,
|
|
141
|
+
(sourceCount, severity) => optionMismatchDiagnostic(ds, sourceCount, severity)
|
|
142
|
+
);
|
|
143
|
+
return [diagnostic];
|
|
144
|
+
}
|
|
145
|
+
let buildInfo;
|
|
146
|
+
try {
|
|
147
|
+
const content = compiler.fs.readFile(ds.buildInfoPath);
|
|
148
|
+
if (content == null) {
|
|
149
|
+
throw new Error("file not found");
|
|
150
|
+
}
|
|
151
|
+
buildInfo = JSON.parse(content);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
const issue = { kind: "read", detail: errorMessage(error) };
|
|
154
|
+
const diagnostic = recoverFromSources(
|
|
155
|
+
compiler,
|
|
156
|
+
ds,
|
|
157
|
+
(sourceCount, severity) => buildInfoDiagnostic(ds, issue, sourceCount, severity)
|
|
158
|
+
);
|
|
159
|
+
return [diagnostic];
|
|
160
|
+
}
|
|
161
|
+
const result = compiler.designSystem.load(ds.manifest, {
|
|
162
|
+
buildInfo,
|
|
163
|
+
pandaVersion,
|
|
164
|
+
...imports !== void 0 ? { imports } : {}
|
|
165
|
+
});
|
|
166
|
+
if (!result.ok) {
|
|
167
|
+
const issue = result.reason === "schemaVersion" ? {
|
|
168
|
+
kind: "schemaVersion",
|
|
169
|
+
received: buildInfo.schemaVersion,
|
|
170
|
+
expected: compiler.buildInfo.schemaVersion
|
|
171
|
+
} : { kind: "corrupt" };
|
|
172
|
+
const diagnostic = recoverFromSources(
|
|
173
|
+
compiler,
|
|
174
|
+
ds,
|
|
175
|
+
(sourceCount, severity) => buildInfoDiagnostic(ds, issue, sourceCount, severity)
|
|
176
|
+
);
|
|
177
|
+
return [diagnostic];
|
|
178
|
+
}
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
function recoverFromSources(compiler, ds, createDiagnostic) {
|
|
182
|
+
const sources = extractFallbackSources(compiler, ds);
|
|
183
|
+
const severity = sources.length === 0 ? "error" : "warning";
|
|
184
|
+
const diagnostic = createDiagnostic(sources.length, severity);
|
|
185
|
+
if (sources.length === 0) {
|
|
186
|
+
throw diagnosticError(diagnostic);
|
|
187
|
+
}
|
|
188
|
+
compiler.parseFiles(sources);
|
|
189
|
+
return diagnostic;
|
|
190
|
+
}
|
|
191
|
+
function extractFallbackSources(compiler, ds) {
|
|
192
|
+
if (ds.files.length === 0) {
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
const filesCwd = compiler.path.resolve(compiler.path.join([compiler.path.dirname(ds.manifestPath), ".."]));
|
|
196
|
+
return compiler.scan({ include: ds.files, cwd: filesCwd });
|
|
197
|
+
}
|
|
198
|
+
function buildInfoDiagnostic(ds, issue, sourceCount, severity) {
|
|
199
|
+
const reason = buildInfoIssueMessage(issue);
|
|
200
|
+
const outcome = sourceCount > 0 ? ` Re-extracted ${sourceCount} source ${sourceCount === 1 ? "file" : "files"}.` : " No fallback source files were available.";
|
|
201
|
+
return {
|
|
202
|
+
code: "design_system_buildinfo_stale",
|
|
203
|
+
severity,
|
|
204
|
+
category: "designSystem",
|
|
205
|
+
file: ds.buildInfoPath,
|
|
206
|
+
message: `${JSON.stringify(ds.name)} build info ${reason}.${outcome}`,
|
|
207
|
+
help: [`Run \`panda lib\` in ${JSON.stringify(ds.name)} to rebuild panda/buildinfo.json.`]
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function buildInfoIssueMessage(issue) {
|
|
211
|
+
if (issue.kind === "schemaVersion") {
|
|
212
|
+
return `uses schemaVersion ${formatValue(issue.received)}; expected ${issue.expected}`;
|
|
213
|
+
}
|
|
214
|
+
if (issue.kind === "read") {
|
|
215
|
+
return `could not be read: ${issue.detail}`;
|
|
216
|
+
}
|
|
217
|
+
return "is malformed or corrupt";
|
|
218
|
+
}
|
|
219
|
+
function optionMismatchDiagnostic(ds, sourceCount, severity) {
|
|
220
|
+
const options = ds.optionMismatch?.join(", ") ?? "class-name options";
|
|
221
|
+
const outcome = sourceCount > 0 ? ` Re-extracted ${sourceCount} source ${sourceCount === 1 ? "file" : "files"} with the consumer options.` : " No fallback source files were available, so the prebuilt class names cannot be used safely.";
|
|
222
|
+
return {
|
|
223
|
+
code: "design_system_option_mismatch",
|
|
224
|
+
severity,
|
|
225
|
+
category: "designSystem",
|
|
226
|
+
file: ds.manifestPath,
|
|
227
|
+
message: `${JSON.stringify(ds.name)} was built with different ${options}.${outcome}`,
|
|
228
|
+
help: [`Match ${options} with ${JSON.stringify(ds.name)}, or rebuild it with \`panda lib\`.`]
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function tokenConflictDiagnostics(ds, consumerTokenPaths) {
|
|
232
|
+
if (consumerTokenPaths.length === 0 || ds.tokenPaths.length === 0) {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
const designSystemTokenPaths = new Set(ds.tokenPaths);
|
|
236
|
+
const conflicts = [...new Set(consumerTokenPaths.filter((path) => designSystemTokenPaths.has(path)))].sort();
|
|
237
|
+
if (conflicts.length === 0) {
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
const preview = conflicts.slice(0, 3).map((path) => JSON.stringify(path)).join(", ");
|
|
241
|
+
const remainder = conflicts.length > 3 ? ` and ${conflicts.length - 3} more` : "";
|
|
242
|
+
return [
|
|
243
|
+
{
|
|
244
|
+
code: "design_system_token_conflict",
|
|
245
|
+
severity: "info",
|
|
246
|
+
category: "designSystem",
|
|
247
|
+
file: ds.manifestPath,
|
|
248
|
+
message: `${conflicts.length} token ${conflicts.length === 1 ? "path is" : "paths are"} defined by both ${JSON.stringify(ds.name)} and this config (${preview}${remainder}); the local values win.`
|
|
249
|
+
}
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
function incompatibleManifestError(compiler, ds, reason, pandaVersion) {
|
|
253
|
+
if (reason === "schemaVersion") {
|
|
254
|
+
return diagnosticError({
|
|
255
|
+
code: "design_system_version_mismatch",
|
|
256
|
+
severity: "error",
|
|
257
|
+
category: "designSystem",
|
|
258
|
+
file: ds.manifestPath,
|
|
259
|
+
message: `${JSON.stringify(ds.name)} panda/lib.json uses schemaVersion ${ds.manifest.schemaVersion}; expected ${compiler.designSystem.schemaVersion}.`,
|
|
260
|
+
help: [`Upgrade ${JSON.stringify(ds.name)}, or rebuild it with a compatible version of Panda.`]
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
const running = pandaVersion ? `; the consumer uses ${pandaVersion}` : "";
|
|
264
|
+
return diagnosticError({
|
|
265
|
+
code: "design_system_peer_range_unsatisfied",
|
|
266
|
+
severity: "error",
|
|
267
|
+
category: "designSystem",
|
|
268
|
+
file: ds.manifestPath,
|
|
269
|
+
message: `${JSON.stringify(ds.name)} requires Panda ${ds.manifest.panda}${running}.`,
|
|
270
|
+
help: [`Install a compatible Panda version or update ${JSON.stringify(ds.name)}.`]
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function diagnosticError(diagnostic) {
|
|
274
|
+
const error = new Error(diagnostic.message);
|
|
275
|
+
error.diagnostics = [diagnostic];
|
|
276
|
+
return error;
|
|
277
|
+
}
|
|
278
|
+
function formatValue(value) {
|
|
279
|
+
return typeof value === "number" || typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
280
|
+
}
|
|
281
|
+
function errorMessage(error) {
|
|
282
|
+
return error instanceof Error ? error.message : String(error);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/index.ts
|
|
286
|
+
import {
|
|
287
|
+
assertProjectHooks,
|
|
288
|
+
assertProjectCallbacks,
|
|
289
|
+
BuildInfo as BuildInfo2,
|
|
290
|
+
DesignSystem as DesignSystem2,
|
|
291
|
+
inspectFile,
|
|
292
|
+
inspectFiles,
|
|
293
|
+
mergeCallbacks,
|
|
294
|
+
mergeHooks,
|
|
295
|
+
prepareCompilerConfig
|
|
296
|
+
} from "@pandacss/compiler-shared";
|
|
297
|
+
|
|
298
|
+
// src/callbacks.ts
|
|
299
|
+
import {
|
|
300
|
+
createTransformHelpers,
|
|
301
|
+
getPatternDefaultValueRefsByTransformId,
|
|
302
|
+
mergePatternDefaultValues,
|
|
303
|
+
PATTERN_HELPERS
|
|
304
|
+
} from "@pandacss/compiler-shared";
|
|
305
|
+
function registerCallbacks(project, callbacks, hooks, tokenDictionary) {
|
|
306
|
+
const utilityTransforms = callbacks["utility.transform"];
|
|
307
|
+
const hasUtilityTransforms = !!utilityTransforms && Object.keys(utilityTransforms).length > 0;
|
|
308
|
+
const patternTransforms = callbacks["pattern.transform"];
|
|
309
|
+
const hasPatternTransforms = !!patternTransforms && Object.keys(patternTransforms).length > 0;
|
|
310
|
+
const config = project.config();
|
|
311
|
+
const patternDefaultValues = callbacks["pattern.defaultValues"];
|
|
312
|
+
const patternDefaultValueRefs = config && patternDefaultValues ? getPatternDefaultValueRefsByTransformId(config) : /* @__PURE__ */ new Map();
|
|
313
|
+
const { token, utils } = createTransformHelpers(tokenDictionary);
|
|
314
|
+
if (hasPatternTransforms && !project.registerPatternTransform) {
|
|
315
|
+
throw new Error("Native project does not support pattern.transform callbacks");
|
|
316
|
+
}
|
|
317
|
+
if (project.registerPatternTransform && patternTransforms) {
|
|
318
|
+
for (const [id, callback] of Object.entries(patternTransforms)) {
|
|
319
|
+
const defaultValueId = patternDefaultValueRefs.get(id);
|
|
320
|
+
const defaultValue = defaultValueId ? patternDefaultValues?.[defaultValueId] : void 0;
|
|
321
|
+
project.registerPatternTransform(id, (props) => {
|
|
322
|
+
const input = props;
|
|
323
|
+
const nextProps = defaultValue ? mergePatternDefaultValues(defaultValue(input), input) : input;
|
|
324
|
+
return callback(nextProps, PATTERN_HELPERS);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (hasUtilityTransforms && !project.registerUtilityTransform) {
|
|
329
|
+
throw new Error("Native project does not support utility.transform callbacks");
|
|
330
|
+
}
|
|
331
|
+
if (project.registerUtilityTransform && utilityTransforms) {
|
|
332
|
+
for (const [id, callback] of Object.entries(utilityTransforms)) {
|
|
333
|
+
project.registerUtilityTransform(id, (resolved, original) => {
|
|
334
|
+
return callback(resolved, { raw: original, token, utils });
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const sourceTransforms = hooks?.["parser:before"];
|
|
339
|
+
if (sourceTransforms?.length && !project.registerSourceTransform) {
|
|
340
|
+
throw new Error("Native project does not support parser:before callbacks");
|
|
341
|
+
}
|
|
342
|
+
if (project.registerSourceTransform && sourceTransforms) {
|
|
343
|
+
for (const hook of sourceTransforms) {
|
|
344
|
+
const callback = callbacks["parser:before"]?.[hook.id];
|
|
345
|
+
if (!callback) continue;
|
|
346
|
+
project.registerSourceTransform(hook.id, hook.filter, (filePath, content) => {
|
|
347
|
+
const result = callback({ filePath: String(filePath), content: String(content), original: String(content) });
|
|
348
|
+
if (isPromiseLike(result)) {
|
|
349
|
+
throw new Error(`parser:before callback \`${hook.id}\` must be synchronous`);
|
|
350
|
+
}
|
|
351
|
+
return typeof result === "string" ? result : void 0;
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function isPromiseLike(value) {
|
|
357
|
+
return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/fallback.ts
|
|
361
|
+
import { BuildInfo, DesignSystem } from "@pandacss/compiler-shared";
|
|
362
|
+
var fallbackBuildInfo = new BuildInfo({
|
|
363
|
+
serializeBuildInfo: () => ({
|
|
364
|
+
schemaVersion: -1,
|
|
365
|
+
panda: "",
|
|
366
|
+
configFingerprint: "",
|
|
367
|
+
strings: [],
|
|
368
|
+
atoms: [],
|
|
369
|
+
modules: {}
|
|
370
|
+
}),
|
|
371
|
+
applyBuildInfo: () => false,
|
|
372
|
+
buildInfoSchemaVersion: () => -1,
|
|
373
|
+
configFingerprint: () => ""
|
|
374
|
+
});
|
|
375
|
+
var fallbackDesignSystem = new DesignSystem(
|
|
376
|
+
{
|
|
377
|
+
createManifest: (input) => ({ ...input, schemaVersion: -1 }),
|
|
378
|
+
manifestSchemaVersion: () => -1
|
|
379
|
+
},
|
|
380
|
+
fallbackBuildInfo
|
|
381
|
+
);
|
|
382
|
+
var FallbackExtractor = class {
|
|
383
|
+
extract() {
|
|
384
|
+
return { calls: [], jsx: [], diagnostics: [] };
|
|
385
|
+
}
|
|
386
|
+
extractDebug() {
|
|
387
|
+
return { imports: [], matched: [], calls: [], jsx: [], diagnostics: [] };
|
|
388
|
+
}
|
|
389
|
+
matchImports() {
|
|
390
|
+
return [];
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
var FallbackCompiler = class _FallbackCompiler {
|
|
394
|
+
fs = {
|
|
395
|
+
readFile: (_path) => void 0,
|
|
396
|
+
exists: (_path) => false
|
|
397
|
+
};
|
|
398
|
+
path = {
|
|
399
|
+
realpath: (path) => path,
|
|
400
|
+
resolve: (path, cwd) => this.resolvePath(path, cwd),
|
|
401
|
+
join: (parts) => this.joinPath(parts),
|
|
402
|
+
dirname: (path) => this.dirname(path)
|
|
403
|
+
};
|
|
404
|
+
static fromConfig() {
|
|
405
|
+
return new _FallbackCompiler();
|
|
406
|
+
}
|
|
407
|
+
serializeBuildInfo() {
|
|
408
|
+
return fallbackBuildInfo.create({ panda: "" });
|
|
409
|
+
}
|
|
410
|
+
applyBuildInfo() {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
buildInfoSchemaVersion() {
|
|
414
|
+
return -1;
|
|
415
|
+
}
|
|
416
|
+
configFingerprint() {
|
|
417
|
+
return "";
|
|
418
|
+
}
|
|
419
|
+
createDesignSystemManifest(input) {
|
|
420
|
+
return { ...input, schemaVersion: -1 };
|
|
421
|
+
}
|
|
422
|
+
designSystemManifestSchemaVersion() {
|
|
423
|
+
return -1;
|
|
424
|
+
}
|
|
425
|
+
config() {
|
|
426
|
+
return {};
|
|
427
|
+
}
|
|
428
|
+
extractFileSource() {
|
|
429
|
+
return { calls: [], jsx: [], diagnostics: [] };
|
|
430
|
+
}
|
|
431
|
+
parseFile(path) {
|
|
432
|
+
return { path, cssCalls: 0, cvaCalls: 0, svaCalls: 0, jsxUsages: 0, diagnostics: [] };
|
|
433
|
+
}
|
|
434
|
+
parseFileSource(path) {
|
|
435
|
+
return { path, cssCalls: 0, cvaCalls: 0, svaCalls: 0, jsxUsages: 0, diagnostics: [] };
|
|
436
|
+
}
|
|
437
|
+
refreshFile() {
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
refreshFileSource() {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
removeFile() {
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
affectedFiles() {
|
|
447
|
+
return [];
|
|
448
|
+
}
|
|
449
|
+
clear() {
|
|
450
|
+
}
|
|
451
|
+
scan() {
|
|
452
|
+
return [];
|
|
453
|
+
}
|
|
454
|
+
designSystemImportSelections() {
|
|
455
|
+
return [];
|
|
456
|
+
}
|
|
457
|
+
realpath(path) {
|
|
458
|
+
return path;
|
|
459
|
+
}
|
|
460
|
+
readFile(_path) {
|
|
461
|
+
return void 0;
|
|
462
|
+
}
|
|
463
|
+
exists(_path) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
resolvePath(path, cwd) {
|
|
467
|
+
if (!cwd || path.startsWith("/")) return path;
|
|
468
|
+
return `${cwd.replace(/\/$/, "")}/${path}`;
|
|
469
|
+
}
|
|
470
|
+
joinPath(parts) {
|
|
471
|
+
return parts.filter(Boolean).join("/");
|
|
472
|
+
}
|
|
473
|
+
dirname(path) {
|
|
474
|
+
const index = path.lastIndexOf("/");
|
|
475
|
+
return index <= 0 ? "" : path.slice(0, index);
|
|
476
|
+
}
|
|
477
|
+
isSourceFile() {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
parseFiles(_paths) {
|
|
481
|
+
return [];
|
|
482
|
+
}
|
|
483
|
+
layers() {
|
|
484
|
+
return { reset: "reset", base: "base", tokens: "tokens", recipes: "recipes", utilities: "utilities" };
|
|
485
|
+
}
|
|
486
|
+
hasLayerDeclaration() {
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
stripLayerOrderStatements(css) {
|
|
490
|
+
return css;
|
|
491
|
+
}
|
|
492
|
+
spec() {
|
|
493
|
+
return {
|
|
494
|
+
conditions: { keys: [], breakpoints: [], containers: [] },
|
|
495
|
+
tokens: { categories: {}, colorPalettes: [], values: {}, deprecated: {} },
|
|
496
|
+
utilities: { properties: {}, shorthands: {}, deprecated: {} },
|
|
497
|
+
keyframes: { keys: [] },
|
|
498
|
+
patterns: {},
|
|
499
|
+
recipes: {},
|
|
500
|
+
slotRecipes: {},
|
|
501
|
+
propertyOrder: []
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
sources() {
|
|
505
|
+
return [];
|
|
506
|
+
}
|
|
507
|
+
inspectFileSource(_path, _source) {
|
|
508
|
+
return { usages: [], diagnostics: [], calls: [], jsx: [], tokenRefs: [], componentEntries: [], styleEntries: [] };
|
|
509
|
+
}
|
|
510
|
+
transformSource(input) {
|
|
511
|
+
return {
|
|
512
|
+
code: input.source,
|
|
513
|
+
map: null,
|
|
514
|
+
changed: false,
|
|
515
|
+
bailed: false,
|
|
516
|
+
diagnostics: [],
|
|
517
|
+
dependencies: [],
|
|
518
|
+
helper: { needsCx: false, needsAttachRecipe: false, needsMemoRecipe: false }
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
inspectFile(input) {
|
|
522
|
+
return { ...this.inspectFileSource(input.path, input.source), path: input.path };
|
|
523
|
+
}
|
|
524
|
+
inspectFiles(files) {
|
|
525
|
+
return { sourceCount: files.length, files: files.map((file) => this.inspectFile(file)) };
|
|
526
|
+
}
|
|
527
|
+
resolveUtilityValue() {
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
530
|
+
suggestTokens() {
|
|
531
|
+
return [];
|
|
532
|
+
}
|
|
533
|
+
suggestSemanticTokens() {
|
|
534
|
+
return [];
|
|
535
|
+
}
|
|
536
|
+
writeArtifacts(_options) {
|
|
537
|
+
return [];
|
|
538
|
+
}
|
|
539
|
+
writeCss(options) {
|
|
540
|
+
return emptyWriteCssResult(options.outfile);
|
|
541
|
+
}
|
|
542
|
+
writeLayerCss(options) {
|
|
543
|
+
return emptyWriteCssResult(options.outfile);
|
|
544
|
+
}
|
|
545
|
+
writeSplitCss(options) {
|
|
546
|
+
return emptyWriteSplitCssResult(options.outdir ?? "");
|
|
547
|
+
}
|
|
548
|
+
isEmpty() {
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
atoms() {
|
|
552
|
+
return [];
|
|
553
|
+
}
|
|
554
|
+
recipes() {
|
|
555
|
+
return [];
|
|
556
|
+
}
|
|
557
|
+
slotRecipes() {
|
|
558
|
+
return [];
|
|
559
|
+
}
|
|
560
|
+
encodedRecipes() {
|
|
561
|
+
return { base: [], variants: [], atomic: [] };
|
|
562
|
+
}
|
|
563
|
+
staticPatternAtoms() {
|
|
564
|
+
return { atoms: [], diagnostics: [] };
|
|
565
|
+
}
|
|
566
|
+
getFile() {
|
|
567
|
+
return null;
|
|
568
|
+
}
|
|
569
|
+
fileManifest() {
|
|
570
|
+
return [];
|
|
571
|
+
}
|
|
572
|
+
summary() {
|
|
573
|
+
return { filesProcessed: 0, atomCount: 0, recipeCount: 0, slotRecipeCount: 0 };
|
|
574
|
+
}
|
|
575
|
+
compile() {
|
|
576
|
+
return emptyCompileOutput();
|
|
577
|
+
}
|
|
578
|
+
getLayerCss(_options) {
|
|
579
|
+
return emptyCompileOutput();
|
|
580
|
+
}
|
|
581
|
+
getKeyframeCss(_options) {
|
|
582
|
+
return emptyCompileOutput();
|
|
583
|
+
}
|
|
584
|
+
getSplitCss(_options) {
|
|
585
|
+
return { files: [], diagnostics: [] };
|
|
586
|
+
}
|
|
587
|
+
buildInfo = fallbackBuildInfo;
|
|
588
|
+
designSystem = fallbackDesignSystem;
|
|
589
|
+
generateArtifacts() {
|
|
590
|
+
return [];
|
|
591
|
+
}
|
|
592
|
+
generateArtifact() {
|
|
593
|
+
return void 0;
|
|
594
|
+
}
|
|
595
|
+
generateAffectedArtifacts() {
|
|
596
|
+
return [];
|
|
597
|
+
}
|
|
598
|
+
diagnostics() {
|
|
599
|
+
return [];
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
var fallback = {
|
|
603
|
+
startTracing() {
|
|
604
|
+
return false;
|
|
605
|
+
},
|
|
606
|
+
flushTracing() {
|
|
607
|
+
},
|
|
608
|
+
takeTimingsJson() {
|
|
609
|
+
return void 0;
|
|
610
|
+
},
|
|
611
|
+
shutdownTracing() {
|
|
612
|
+
return false;
|
|
613
|
+
},
|
|
614
|
+
compile() {
|
|
615
|
+
return emptyCompileOutput();
|
|
616
|
+
},
|
|
617
|
+
scanImports() {
|
|
618
|
+
return { imports: [], diagnostics: [] };
|
|
619
|
+
},
|
|
620
|
+
matchImports() {
|
|
621
|
+
return [];
|
|
622
|
+
},
|
|
623
|
+
extractCalls() {
|
|
624
|
+
return { calls: [], diagnostics: [] };
|
|
625
|
+
},
|
|
626
|
+
extractJsx() {
|
|
627
|
+
return { jsx: [], diagnostics: [] };
|
|
628
|
+
},
|
|
629
|
+
extract() {
|
|
630
|
+
return { calls: [], jsx: [], diagnostics: [] };
|
|
631
|
+
},
|
|
632
|
+
extractDebug() {
|
|
633
|
+
return { imports: [], matched: [], calls: [], jsx: [], diagnostics: [] };
|
|
634
|
+
},
|
|
635
|
+
Extractor: FallbackExtractor,
|
|
636
|
+
Compiler: FallbackCompiler
|
|
637
|
+
};
|
|
638
|
+
function emptyCompileOutput() {
|
|
639
|
+
return {
|
|
640
|
+
css: "",
|
|
641
|
+
manifest: { files: [], tokens: [] },
|
|
642
|
+
layerRanges: {},
|
|
643
|
+
diagnostics: []
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
function emptyWriteCssResult(path) {
|
|
647
|
+
return {
|
|
648
|
+
path,
|
|
649
|
+
...emptyCompileOutput()
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
function emptyWriteSplitCssResult(root) {
|
|
653
|
+
return {
|
|
654
|
+
root,
|
|
655
|
+
paths: [],
|
|
656
|
+
files: [],
|
|
657
|
+
diagnostics: []
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// src/load-binary.ts
|
|
662
|
+
import { execFileSync } from "node:child_process";
|
|
663
|
+
import { existsSync, mkdirSync, readFileSync, rmSync } from "node:fs";
|
|
664
|
+
import { createRequire } from "node:module";
|
|
665
|
+
import { dirname, join } from "node:path";
|
|
666
|
+
var webContainerWasiPackage = "@pandacss/compiler-wasm32-wasi";
|
|
667
|
+
function loadNativeBinding() {
|
|
668
|
+
const bindingPath = resolveBindingPath();
|
|
669
|
+
if (!bindingPath) return void 0;
|
|
670
|
+
const require2 = createRequire(bindingPath);
|
|
671
|
+
try {
|
|
672
|
+
return require2(bindingPath);
|
|
673
|
+
} catch (error) {
|
|
674
|
+
if (!isWebContainer()) throw error;
|
|
675
|
+
return loadWebContainerBinding(require2, bindingPath, error);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function resolveBindingPath(referrer = import.meta.url) {
|
|
679
|
+
const packageRoot = resolvePackageRoot(referrer);
|
|
680
|
+
if (packageRoot) {
|
|
681
|
+
const bindingPath = join(packageRoot, "binding.cjs");
|
|
682
|
+
if (existsSync(bindingPath)) return bindingPath;
|
|
683
|
+
}
|
|
684
|
+
return fallbackBindingPaths().find((path) => existsSync(path));
|
|
685
|
+
}
|
|
686
|
+
function resolvePackageRoot(referrer) {
|
|
687
|
+
try {
|
|
688
|
+
return dirname(createRequire(referrer).resolve("@pandacss/compiler/package.json"));
|
|
689
|
+
} catch {
|
|
690
|
+
return void 0;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
function fallbackBindingPaths() {
|
|
694
|
+
const cwd = process.cwd();
|
|
695
|
+
const paths = [join(cwd, "packages/compiler/binding.cjs")];
|
|
696
|
+
if (isCompilerPackageRoot(cwd)) {
|
|
697
|
+
paths.unshift(join(cwd, "binding.cjs"));
|
|
698
|
+
}
|
|
699
|
+
return paths;
|
|
700
|
+
}
|
|
701
|
+
function isCompilerPackageRoot(cwd) {
|
|
702
|
+
try {
|
|
703
|
+
const packageJson = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
|
|
704
|
+
return packageJson.name === "@pandacss/compiler";
|
|
705
|
+
} catch {
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
function isWebContainer() {
|
|
710
|
+
const versions = process.versions;
|
|
711
|
+
return Boolean(versions.webcontainer);
|
|
712
|
+
}
|
|
713
|
+
function resolveWebContainerBinding(version, root = "/tmp") {
|
|
714
|
+
const baseDir = join(root, `pandacss-compiler-${version}`);
|
|
715
|
+
return {
|
|
716
|
+
baseDir,
|
|
717
|
+
bindingPackage: `${webContainerWasiPackage}@${version}`,
|
|
718
|
+
bindingEntry: join(baseDir, "node_modules", webContainerWasiPackage, "compiler.wasi.cjs")
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
function loadWebContainerBinding(require2, bindingPath, nativeError) {
|
|
722
|
+
const version = readCompilerVersion(require2, dirname(bindingPath));
|
|
723
|
+
const { baseDir, bindingPackage, bindingEntry } = resolveWebContainerBinding(version);
|
|
724
|
+
if (!existsSync(bindingEntry)) {
|
|
725
|
+
rmSync(baseDir, { recursive: true, force: true });
|
|
726
|
+
mkdirSync(baseDir, { recursive: true });
|
|
727
|
+
execFileSync("pnpm", ["i", bindingPackage], {
|
|
728
|
+
cwd: baseDir,
|
|
729
|
+
stdio: "inherit"
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
try {
|
|
733
|
+
return require2(bindingEntry);
|
|
734
|
+
} catch (fallbackError) {
|
|
735
|
+
throw new Error("Failed to load @pandacss/compiler WebContainer WASI fallback", {
|
|
736
|
+
cause: chainError(nativeError, fallbackError)
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
function readCompilerVersion(require2, packageRoot) {
|
|
741
|
+
try {
|
|
742
|
+
const packageJsonPath = require2.resolve("@pandacss/compiler/package.json");
|
|
743
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
744
|
+
return packageJson.version;
|
|
745
|
+
} catch {
|
|
746
|
+
const packageJson = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
|
|
747
|
+
return packageJson.version;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
function chainError(primary, cause) {
|
|
751
|
+
if (primary instanceof Error) {
|
|
752
|
+
primary.cause = cause;
|
|
753
|
+
return primary;
|
|
754
|
+
}
|
|
755
|
+
return cause;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/index.ts
|
|
759
|
+
import { createUsageReport } from "@pandacss/compiler-shared";
|
|
760
|
+
var binding = loadNativeBinding() ?? fallback;
|
|
761
|
+
var nativeCompilerFromConfig = "fromConfig" in binding.Compiler && typeof binding.Compiler.fromConfig === "function" ? binding.Compiler.fromConfig.bind(binding.Compiler) : void 0;
|
|
762
|
+
function createCompilerFromSnapshot(snapshot, options) {
|
|
763
|
+
const callbacks = mergeCallbacks(snapshot.callbacks, options?.callbacks);
|
|
764
|
+
const hooks = mergeHooks(snapshot.hooks, options?.hooks);
|
|
765
|
+
return build(snapshot.config, callbacks, { ...options, hooks });
|
|
766
|
+
}
|
|
767
|
+
function assertNativeBinding(callbacks, hooks) {
|
|
768
|
+
if (binding !== fallback) return;
|
|
769
|
+
const needed = ["pattern.transform", "utility.transform"].filter(
|
|
770
|
+
(key) => Object.keys(callbacks[key] ?? {}).length > 0
|
|
771
|
+
);
|
|
772
|
+
if (hooks?.["parser:before"]?.length) needed.push("parser:before");
|
|
773
|
+
if (needed.length === 0) return;
|
|
774
|
+
throw new Error(
|
|
775
|
+
`Could not load the native @pandacss/compiler binding for ${process.platform}-${process.arch}, which ${needed.join(", ")} callbacks require. Reinstall your dependencies to fetch the platform package, or open an issue if your platform is unsupported.`
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
function build(config, callbacks, options) {
|
|
779
|
+
assertProjectCallbacks(config, callbacks);
|
|
780
|
+
assertProjectHooks(options?.hooks, callbacks);
|
|
781
|
+
if (!nativeCompilerFromConfig) {
|
|
782
|
+
throw new Error("createCompiler is not available in this binding");
|
|
783
|
+
}
|
|
784
|
+
assertNativeBinding(callbacks, options?.hooks);
|
|
785
|
+
const prepared = prepareCompilerConfig(config);
|
|
786
|
+
const compiler = nativeCompilerFromConfig(prepared, toNativeOptions(options), createUtilityValuesCallbacks(callbacks));
|
|
787
|
+
registerCallbacks(compiler, callbacks, options?.hooks, compiler.tokenDictionary?.());
|
|
788
|
+
attachFileSystem(compiler);
|
|
789
|
+
attachPathSystem(compiler);
|
|
790
|
+
attachBuildInfo(compiler);
|
|
791
|
+
attachDesignSystem(compiler);
|
|
792
|
+
attachInspection(compiler);
|
|
793
|
+
return compiler;
|
|
794
|
+
}
|
|
795
|
+
function attachFileSystem(compiler) {
|
|
796
|
+
Object.defineProperty(compiler, "fs", {
|
|
797
|
+
value: {
|
|
798
|
+
readFile: (path) => compiler.readFile(path),
|
|
799
|
+
exists: (path) => compiler.exists(path)
|
|
800
|
+
},
|
|
801
|
+
enumerable: false,
|
|
802
|
+
configurable: true
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
function attachPathSystem(compiler) {
|
|
806
|
+
Object.defineProperty(compiler, "path", {
|
|
807
|
+
value: {
|
|
808
|
+
realpath: (path) => compiler.realpath(path),
|
|
809
|
+
resolve: (path, cwd) => compiler.resolvePath(path, cwd),
|
|
810
|
+
join: (parts) => compiler.joinPath(parts),
|
|
811
|
+
dirname: (path) => compiler.dirname(path)
|
|
812
|
+
},
|
|
813
|
+
enumerable: false,
|
|
814
|
+
configurable: true
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
function attachBuildInfo(compiler) {
|
|
818
|
+
Object.defineProperty(compiler, "buildInfo", {
|
|
819
|
+
enumerable: false,
|
|
820
|
+
configurable: true,
|
|
821
|
+
get() {
|
|
822
|
+
const api = new BuildInfo2(compiler);
|
|
823
|
+
Object.defineProperty(compiler, "buildInfo", {
|
|
824
|
+
value: api,
|
|
825
|
+
enumerable: false,
|
|
826
|
+
configurable: true
|
|
827
|
+
});
|
|
828
|
+
return api;
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
function attachDesignSystem(compiler) {
|
|
833
|
+
Object.defineProperty(compiler, "designSystem", {
|
|
834
|
+
enumerable: false,
|
|
835
|
+
configurable: true,
|
|
836
|
+
get() {
|
|
837
|
+
const api = new DesignSystem2(toDesignSystemBinding(compiler), compiler.buildInfo);
|
|
838
|
+
Object.defineProperty(compiler, "designSystem", {
|
|
839
|
+
value: api,
|
|
840
|
+
enumerable: false,
|
|
841
|
+
configurable: true
|
|
842
|
+
});
|
|
843
|
+
return api;
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
function attachInspection(compiler) {
|
|
848
|
+
Object.defineProperty(compiler, "inspectFile", {
|
|
849
|
+
enumerable: false,
|
|
850
|
+
configurable: true,
|
|
851
|
+
value: (input) => inspectFile(compiler, input)
|
|
852
|
+
});
|
|
853
|
+
Object.defineProperty(compiler, "inspectFiles", {
|
|
854
|
+
enumerable: false,
|
|
855
|
+
configurable: true,
|
|
856
|
+
value: (files) => inspectFiles(compiler, files)
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
function toDesignSystemBinding(compiler) {
|
|
860
|
+
return {
|
|
861
|
+
createManifest: (input) => compiler.createDesignSystemManifest(input),
|
|
862
|
+
manifestSchemaVersion: () => compiler.designSystemManifestSchemaVersion()
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
function toNativeOptions(options) {
|
|
866
|
+
if (!options || options.crossFile === void 0) return void 0;
|
|
867
|
+
return { crossFile: options.crossFile };
|
|
868
|
+
}
|
|
869
|
+
function createUtilityValuesCallbacks(callbacks) {
|
|
870
|
+
const utilityValues = callbacks["utility.values"];
|
|
871
|
+
if (!utilityValues || Object.keys(utilityValues).length === 0) return void 0;
|
|
872
|
+
return utilityValues;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// src/tooling/create-project.ts
|
|
876
|
+
function treeshakeDesignSystemEnabled(config) {
|
|
877
|
+
const optimize = config.optimize;
|
|
878
|
+
return optimize?.treeshakeDesignSystem === true;
|
|
879
|
+
}
|
|
880
|
+
function createProjectFromLoadedConfig(loaded) {
|
|
881
|
+
const compiler = createCompilerFromSnapshot({
|
|
882
|
+
config: loaded.config,
|
|
883
|
+
callbacks: loaded.callbacks,
|
|
884
|
+
hooks: loaded.hooks
|
|
885
|
+
});
|
|
886
|
+
const hydrated = hydrateDesignSystem(compiler, {
|
|
887
|
+
chain: loaded.metadata?.designSystem,
|
|
888
|
+
consumerTokenPaths: loaded.metadata?.userTokenPaths ?? [],
|
|
889
|
+
treeshake: treeshakeDesignSystemEnabled(loaded.config)
|
|
890
|
+
});
|
|
891
|
+
const designSystemDiagnostics = [
|
|
892
|
+
...hydrated.diagnostics,
|
|
893
|
+
...artifactConflictDiagnostics(loaded.metadata),
|
|
894
|
+
...collectExportMissingDiagnostics(loaded.metadata),
|
|
895
|
+
...collectNameCollisionDiagnostics(loaded.metadata)
|
|
896
|
+
];
|
|
897
|
+
return {
|
|
898
|
+
compiler,
|
|
899
|
+
configPath: loaded.path,
|
|
900
|
+
dependencies: loaded.dependencies,
|
|
901
|
+
outdir: loaded.config.outdir ?? defaultConfig.outdir,
|
|
902
|
+
designSystemDiagnostics,
|
|
903
|
+
designSystemTreeshakeKey: hydrated.treeshakeKey
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
async function createProjectFromConfig(key) {
|
|
907
|
+
const loaded = await loadConfig({ cwd: key.cwd, file: key.configPath });
|
|
908
|
+
return createProjectFromLoadedConfig(loaded);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
// src/tooling/inspector.ts
|
|
912
|
+
var FileInspector = class {
|
|
913
|
+
#entries = /* @__PURE__ */ new WeakMap();
|
|
914
|
+
inspect(compiler, path, source) {
|
|
915
|
+
let byPath = this.#entries.get(compiler);
|
|
916
|
+
if (!byPath) {
|
|
917
|
+
byPath = /* @__PURE__ */ new Map();
|
|
918
|
+
this.#entries.set(compiler, byPath);
|
|
919
|
+
}
|
|
920
|
+
const sourceKey = sourceCacheKey(source);
|
|
921
|
+
const cached = byPath.get(path);
|
|
922
|
+
if (cached?.sourceKey === sourceKey) return cached.result;
|
|
923
|
+
const result = compiler.inspectFile({ path, source });
|
|
924
|
+
byPath.set(path, { sourceKey, result });
|
|
925
|
+
return result;
|
|
926
|
+
}
|
|
927
|
+
clear(compiler) {
|
|
928
|
+
if (compiler) {
|
|
929
|
+
this.#entries.delete(compiler);
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
this.#entries = /* @__PURE__ */ new WeakMap();
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
function sourceCacheKey(source) {
|
|
936
|
+
let hash = 2166136261;
|
|
937
|
+
for (let i = 0; i < source.length; i++) {
|
|
938
|
+
hash ^= source.charCodeAt(i);
|
|
939
|
+
hash = Math.imul(hash, 16777619);
|
|
940
|
+
}
|
|
941
|
+
return `${source.length}:${hash >>> 0}`;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// src/tooling/registry.ts
|
|
945
|
+
import { realpathSync, unwatchFile, watch, watchFile } from "node:fs";
|
|
946
|
+
import { dirname as dirname2, isAbsolute, join as join2, resolve } from "node:path";
|
|
947
|
+
import { findConfig } from "@pandacss/config";
|
|
948
|
+
var FILE_POLL_INTERVAL_MS = 1e3;
|
|
949
|
+
var ProjectRegistry = class {
|
|
950
|
+
#projects = /* @__PURE__ */ new Map();
|
|
951
|
+
#watchers = /* @__PURE__ */ new Map();
|
|
952
|
+
#watchedDirs = /* @__PURE__ */ new Map();
|
|
953
|
+
/** path → listener so `unwatchFile` doesn't clear other registries. */
|
|
954
|
+
#polledFiles = /* @__PURE__ */ new Map();
|
|
955
|
+
#createProject;
|
|
956
|
+
constructor(options = {}) {
|
|
957
|
+
this.#createProject = options.createProject ?? ((key) => createProjectFromConfig(key));
|
|
958
|
+
}
|
|
959
|
+
getProject(key) {
|
|
960
|
+
const resolvedPath = resolveConfigPath(key);
|
|
961
|
+
const cacheKey = resolvedPath ?? syntheticKey(key);
|
|
962
|
+
const cached = this.#projects.get(cacheKey);
|
|
963
|
+
if (cached) return cached;
|
|
964
|
+
if (resolvedPath) this.#watch(cacheKey, key.cwd, [resolvedPath]);
|
|
965
|
+
const project = this.#createProject(key);
|
|
966
|
+
project.then(
|
|
967
|
+
(resolved) => {
|
|
968
|
+
if (resolvedPath && this.#projects.get(cacheKey) === project) {
|
|
969
|
+
this.#watch(cacheKey, key.cwd, [resolvedPath, ...resolved.dependencies]);
|
|
970
|
+
}
|
|
971
|
+
},
|
|
972
|
+
() => this.#evict(cacheKey)
|
|
973
|
+
);
|
|
974
|
+
this.#projects.set(cacheKey, project);
|
|
975
|
+
return project;
|
|
976
|
+
}
|
|
977
|
+
invalidate(_changedPaths = []) {
|
|
978
|
+
for (const cacheKey of [...this.#watchers.keys(), ...this.#polledFiles.keys()]) {
|
|
979
|
+
this.#closeWatchers(cacheKey);
|
|
980
|
+
}
|
|
981
|
+
this.#watchers.clear();
|
|
982
|
+
this.#watchedDirs.clear();
|
|
983
|
+
this.#polledFiles.clear();
|
|
984
|
+
this.#projects.clear();
|
|
985
|
+
}
|
|
986
|
+
// Dir watch + `watchFile` poll; deps are cwd-relative like the driver.
|
|
987
|
+
#watch(cacheKey, cwd, paths) {
|
|
988
|
+
const filesByDir = /* @__PURE__ */ new Map();
|
|
989
|
+
for (const path of new Set(paths)) {
|
|
990
|
+
const absolute = isAbsolute(path) ? path : resolve(cwd, path);
|
|
991
|
+
const normalized = canonicalPath(absolute);
|
|
992
|
+
const dir = dirname2(normalized);
|
|
993
|
+
if (!filesByDir.has(dir)) filesByDir.set(dir, /* @__PURE__ */ new Set());
|
|
994
|
+
filesByDir.get(dir)?.add(normalized);
|
|
995
|
+
}
|
|
996
|
+
const watched = this.#watchedDirs.get(cacheKey) ?? /* @__PURE__ */ new Map();
|
|
997
|
+
const watchers = this.#watchers.get(cacheKey) ?? [];
|
|
998
|
+
for (const [dir, filesInDir] of filesByDir) {
|
|
999
|
+
const existing = watched.get(dir);
|
|
1000
|
+
if (existing) {
|
|
1001
|
+
for (const file of filesInDir) {
|
|
1002
|
+
if (existing.has(file)) continue;
|
|
1003
|
+
existing.add(file);
|
|
1004
|
+
this.#pollFile(cacheKey, file);
|
|
1005
|
+
}
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
const tracked = new Set(filesInDir);
|
|
1009
|
+
try {
|
|
1010
|
+
watchers.push(
|
|
1011
|
+
watch(dir, (_event, filename) => {
|
|
1012
|
+
if (!filename || tracked.has(join2(dir, filename))) this.#evict(cacheKey);
|
|
1013
|
+
})
|
|
1014
|
+
);
|
|
1015
|
+
watched.set(dir, tracked);
|
|
1016
|
+
} catch {
|
|
1017
|
+
}
|
|
1018
|
+
for (const file of tracked) this.#pollFile(cacheKey, file);
|
|
1019
|
+
}
|
|
1020
|
+
this.#watchedDirs.set(cacheKey, watched);
|
|
1021
|
+
this.#watchers.set(cacheKey, watchers);
|
|
1022
|
+
}
|
|
1023
|
+
#pollFile(cacheKey, file) {
|
|
1024
|
+
const polled = this.#polledFiles.get(cacheKey) ?? /* @__PURE__ */ new Map();
|
|
1025
|
+
if (polled.has(file)) return;
|
|
1026
|
+
const listener = () => this.#evict(cacheKey);
|
|
1027
|
+
polled.set(file, listener);
|
|
1028
|
+
this.#polledFiles.set(cacheKey, polled);
|
|
1029
|
+
watchFile(file, { interval: FILE_POLL_INTERVAL_MS }, listener);
|
|
1030
|
+
}
|
|
1031
|
+
#closeWatchers(cacheKey) {
|
|
1032
|
+
for (const watcher of this.#watchers.get(cacheKey) ?? []) watcher.close();
|
|
1033
|
+
for (const [file, listener] of this.#polledFiles.get(cacheKey) ?? []) {
|
|
1034
|
+
unwatchFile(file, listener);
|
|
1035
|
+
}
|
|
1036
|
+
this.#polledFiles.delete(cacheKey);
|
|
1037
|
+
}
|
|
1038
|
+
#evict(cacheKey) {
|
|
1039
|
+
this.#closeWatchers(cacheKey);
|
|
1040
|
+
this.#watchers.delete(cacheKey);
|
|
1041
|
+
this.#watchedDirs.delete(cacheKey);
|
|
1042
|
+
this.#projects.delete(cacheKey);
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
function canonicalPath(filepath) {
|
|
1046
|
+
try {
|
|
1047
|
+
return realpathSync(filepath);
|
|
1048
|
+
} catch {
|
|
1049
|
+
return filepath;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
function resolveConfigPath(key) {
|
|
1053
|
+
try {
|
|
1054
|
+
return canonicalPath(findConfig({ cwd: key.cwd, file: key.configPath }));
|
|
1055
|
+
} catch {
|
|
1056
|
+
return void 0;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
function syntheticKey(key) {
|
|
1060
|
+
return `${key.cwd}\0${key.configPath ?? ""}`;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// src/tooling/spec-index.ts
|
|
1064
|
+
var SpecIndex = class {
|
|
1065
|
+
spec;
|
|
1066
|
+
#categoryByProperty;
|
|
1067
|
+
#literalsByProperty;
|
|
1068
|
+
constructor(spec) {
|
|
1069
|
+
this.spec = spec;
|
|
1070
|
+
this.#categoryByProperty = buildCategoryByProperty(spec);
|
|
1071
|
+
this.#literalsByProperty = buildLiteralsByProperty(spec);
|
|
1072
|
+
}
|
|
1073
|
+
resolveTokenValue(path) {
|
|
1074
|
+
return this.spec.tokens.values[path];
|
|
1075
|
+
}
|
|
1076
|
+
resolveTokenPaths(prefix = "") {
|
|
1077
|
+
const paths = Object.keys(this.spec.tokens.values);
|
|
1078
|
+
return prefix ? paths.filter((path) => path.startsWith(prefix)) : paths;
|
|
1079
|
+
}
|
|
1080
|
+
resolveTokenDeprecation(path) {
|
|
1081
|
+
return this.spec.tokens.deprecated[path];
|
|
1082
|
+
}
|
|
1083
|
+
hasCondition(name) {
|
|
1084
|
+
return this.spec.conditions.keys.includes(name);
|
|
1085
|
+
}
|
|
1086
|
+
/** Bare style-object keys: named/custom conditions plus breakpoints (`sm`, `md`, ...). */
|
|
1087
|
+
resolveStyleObjectKeys() {
|
|
1088
|
+
return [.../* @__PURE__ */ new Set([...this.spec.conditions.keys, ...this.spec.conditions.breakpoints])];
|
|
1089
|
+
}
|
|
1090
|
+
// `property` may be a canonical utility name or one of its shorthands.
|
|
1091
|
+
resolveTokenCategoryForProperty(property) {
|
|
1092
|
+
return this.#categoryByProperty.get(property);
|
|
1093
|
+
}
|
|
1094
|
+
// Populated for fixed-literal utilities (e.g. `scrollbar: 'visible' | 'hidden'`) instead of a token category.
|
|
1095
|
+
resolveLiteralsForProperty(property) {
|
|
1096
|
+
return this.#literalsByProperty.get(property);
|
|
1097
|
+
}
|
|
1098
|
+
resolveKeyframeNames(prefix = "") {
|
|
1099
|
+
const names = this.spec.keyframes.keys;
|
|
1100
|
+
return prefix ? names.filter((name) => name.startsWith(prefix)) : names;
|
|
1101
|
+
}
|
|
1102
|
+
/** Token category names actually present in this config (`colors`, `spacing`, ...). */
|
|
1103
|
+
resolveTokenCategories(prefix = "") {
|
|
1104
|
+
const names = Object.keys(this.spec.tokens.categories);
|
|
1105
|
+
return prefix ? names.filter((name) => name.startsWith(prefix)) : names;
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
function buildCategoryByProperty(spec) {
|
|
1109
|
+
const map = /* @__PURE__ */ new Map();
|
|
1110
|
+
for (const [name, property] of Object.entries(spec.utilities.properties)) {
|
|
1111
|
+
if (property.tokenCategory) map.set(name, property.tokenCategory);
|
|
1112
|
+
}
|
|
1113
|
+
for (const [shorthand, canonical] of Object.entries(spec.utilities.shorthands)) {
|
|
1114
|
+
const category = map.get(canonical);
|
|
1115
|
+
if (category) map.set(shorthand, category);
|
|
1116
|
+
}
|
|
1117
|
+
return map;
|
|
1118
|
+
}
|
|
1119
|
+
function buildLiteralsByProperty(spec) {
|
|
1120
|
+
const map = /* @__PURE__ */ new Map();
|
|
1121
|
+
for (const [name, property] of Object.entries(spec.utilities.properties)) {
|
|
1122
|
+
if (property.literals.length > 0) map.set(name, property.literals);
|
|
1123
|
+
}
|
|
1124
|
+
for (const [shorthand, canonical] of Object.entries(spec.utilities.shorthands)) {
|
|
1125
|
+
const literals = map.get(canonical);
|
|
1126
|
+
if (literals) map.set(shorthand, literals);
|
|
1127
|
+
}
|
|
1128
|
+
return map;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
// src/tooling/config-tokens.ts
|
|
1132
|
+
var TOKEN_REF_PATTERN = /\{([a-zA-Z0-9_.]+)\}/g;
|
|
1133
|
+
function findConfigTokenRefs(text) {
|
|
1134
|
+
const refs = [];
|
|
1135
|
+
for (const match of text.matchAll(TOKEN_REF_PATTERN)) {
|
|
1136
|
+
const start = match.index;
|
|
1137
|
+
const path = match[1];
|
|
1138
|
+
const pathStart = start + 1;
|
|
1139
|
+
refs.push({ start, end: start + match[0].length, pathStart, pathEnd: pathStart + path.length, path });
|
|
1140
|
+
}
|
|
1141
|
+
return refs;
|
|
1142
|
+
}
|
|
1143
|
+
function findConfigTokenRefAt(text, position) {
|
|
1144
|
+
return findConfigTokenRefs(text).find((ref) => position >= ref.start && position <= ref.end);
|
|
1145
|
+
}
|
|
1146
|
+
function completeConfigTokenPath(prefix, index) {
|
|
1147
|
+
return index.resolveTokenPaths(prefix).filter((path) => index.resolveTokenDeprecation(path) === void 0);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// src/tooling/config-style-object.ts
|
|
1151
|
+
var CSS_WIDE_KEYWORDS = ["inherit", "initial", "revert", "revert-layer", "unset"];
|
|
1152
|
+
function completeConfigStyleObject(context, index) {
|
|
1153
|
+
const activeProperty = context.propertyPath.find((segment) => isKnownUtilityProperty(segment, index));
|
|
1154
|
+
if (context.cursorKind === "value") {
|
|
1155
|
+
return activeProperty ? completeStyleValue(activeProperty, context.prefix, index) : [];
|
|
1156
|
+
}
|
|
1157
|
+
if (activeProperty) {
|
|
1158
|
+
return completeConditionKey(context.existingKeys, context.prefix, index);
|
|
1159
|
+
}
|
|
1160
|
+
return completeStyleKey(context.existingKeys, context.prefix, index);
|
|
1161
|
+
}
|
|
1162
|
+
function completeStyleKey(existingKeys, prefix, index) {
|
|
1163
|
+
const used = new Set(existingKeys);
|
|
1164
|
+
const utilityNames = [
|
|
1165
|
+
...Object.keys(index.spec.utilities.properties),
|
|
1166
|
+
...Object.keys(index.spec.utilities.shorthands)
|
|
1167
|
+
];
|
|
1168
|
+
const utilities = utilityNames.filter((name) => !used.has(name) && name.startsWith(prefix)).map((name) => ({ name, kind: "utility" }));
|
|
1169
|
+
const conditions = index.resolveStyleObjectKeys().filter((name) => !used.has(name) && name.startsWith(prefix)).map((name) => ({ name, kind: "condition" }));
|
|
1170
|
+
return [...utilities, ...conditions];
|
|
1171
|
+
}
|
|
1172
|
+
function completeConditionKey(existingKeys, prefix, index) {
|
|
1173
|
+
const used = new Set(existingKeys);
|
|
1174
|
+
return index.resolveStyleObjectKeys().filter((name) => !used.has(name) && name.startsWith(prefix)).map((name) => ({ name, kind: "condition" }));
|
|
1175
|
+
}
|
|
1176
|
+
function completeStyleValue(property, prefix, index) {
|
|
1177
|
+
if (!isKnownUtilityProperty(property, index)) return [];
|
|
1178
|
+
const entries = resolvePropertyValues(property, prefix, index);
|
|
1179
|
+
const keywords = CSS_WIDE_KEYWORDS.filter((keyword) => keyword.startsWith(prefix)).map((name) => ({
|
|
1180
|
+
name,
|
|
1181
|
+
kind: "keyword"
|
|
1182
|
+
}));
|
|
1183
|
+
return [...entries, ...keywords];
|
|
1184
|
+
}
|
|
1185
|
+
function resolvePropertyValues(property, prefix, index) {
|
|
1186
|
+
const category = index.resolveTokenCategoryForProperty(property);
|
|
1187
|
+
if (category === "keyframes") {
|
|
1188
|
+
return index.resolveKeyframeNames(prefix).map((name) => ({ name, kind: "keyframe" }));
|
|
1189
|
+
}
|
|
1190
|
+
if (category) {
|
|
1191
|
+
const categoryPrefix = `${category}.`;
|
|
1192
|
+
return index.resolveTokenPaths(`${categoryPrefix}${prefix}`).filter((path) => index.resolveTokenDeprecation(path) === void 0).map((path) => ({ name: path.slice(categoryPrefix.length), kind: "token" }));
|
|
1193
|
+
}
|
|
1194
|
+
const literals = index.resolveLiteralsForProperty(property);
|
|
1195
|
+
if (literals) {
|
|
1196
|
+
return literals.filter((value) => value.startsWith(prefix)).map((value) => ({ name: value, kind: "literal" }));
|
|
1197
|
+
}
|
|
1198
|
+
return [];
|
|
1199
|
+
}
|
|
1200
|
+
function isKnownUtilityProperty(property, index) {
|
|
1201
|
+
return property in index.spec.utilities.properties || property in index.spec.utilities.shorthands;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
// src/tooling/config-semantic-tokens.ts
|
|
1205
|
+
function completeSemanticTokenObject(context, index) {
|
|
1206
|
+
const used = new Set(context.existingKeys);
|
|
1207
|
+
if (context.cursorKind === "category") {
|
|
1208
|
+
return index.resolveTokenCategories(context.prefix).filter((name) => !used.has(name)).map((name) => ({ name, kind: "category" }));
|
|
1209
|
+
}
|
|
1210
|
+
return ["base", ...index.resolveStyleObjectKeys()].filter((name) => !used.has(name) && name.startsWith(context.prefix)).map((name) => ({ name, kind: "condition" }));
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
// src/tooling/module-resolution.ts
|
|
1214
|
+
import { outdirBasename } from "@pandacss/compiler-shared";
|
|
1215
|
+
function resolveModuleTarget(specifier, importMap, options) {
|
|
1216
|
+
const outdirBase = outdirBasename(options.outdir);
|
|
1217
|
+
const roots = Object.values(importMap).flat();
|
|
1218
|
+
const usesBareOutdirConvention = roots.some((root) => root === outdirBase || root.startsWith(`${outdirBase}/`));
|
|
1219
|
+
if (!usesBareOutdirConvention) return void 0;
|
|
1220
|
+
if (specifier !== outdirBase && !specifier.startsWith(`${outdirBase}/`)) return void 0;
|
|
1221
|
+
return `./${options.outdir}${specifier.slice(outdirBase.length)}`;
|
|
1222
|
+
}
|
|
1223
|
+
export {
|
|
1224
|
+
FileInspector,
|
|
1225
|
+
ProjectRegistry,
|
|
1226
|
+
SpecIndex,
|
|
1227
|
+
completeConfigStyleObject,
|
|
1228
|
+
completeConfigTokenPath,
|
|
1229
|
+
completeSemanticTokenObject,
|
|
1230
|
+
createProjectFromConfig,
|
|
1231
|
+
createProjectFromLoadedConfig,
|
|
1232
|
+
findConfigTokenRefAt,
|
|
1233
|
+
findConfigTokenRefs,
|
|
1234
|
+
resolveModuleTarget,
|
|
1235
|
+
sourceCacheKey
|
|
1236
|
+
};
|