@pandacss/compiler 2.0.0-beta.1 → 2.0.0-beta.11
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 +53 -52
- package/dist/chunk-73WPZHEX.js +1462 -0
- package/dist/index.d.ts +72 -142
- package/dist/index.js +9 -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 +1166 -0
- package/dist/types-DR9fSNfa.d.ts +155 -0
- package/package.json +32 -17
- package/dist/chunk-7OM4CBA4.js +0 -515
|
@@ -0,0 +1,1462 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
assertProjectHooks,
|
|
4
|
+
assertProjectCallbacks,
|
|
5
|
+
BuildInfo as BuildInfo2,
|
|
6
|
+
DesignSystem as DesignSystem2,
|
|
7
|
+
inspectFile,
|
|
8
|
+
inspectFiles,
|
|
9
|
+
mergeCallbacks,
|
|
10
|
+
mergeHooks,
|
|
11
|
+
prepareCompilerConfig
|
|
12
|
+
} from "@pandacss/compiler-shared";
|
|
13
|
+
|
|
14
|
+
// src/callbacks.ts
|
|
15
|
+
import {
|
|
16
|
+
createTransformHelpers,
|
|
17
|
+
getPatternDefaultValueRefsByTransformId,
|
|
18
|
+
mergePatternDefaultValues,
|
|
19
|
+
PATTERN_HELPERS
|
|
20
|
+
} from "@pandacss/compiler-shared";
|
|
21
|
+
function registerCallbacks(project, callbacks, hooks, tokenDictionary) {
|
|
22
|
+
const utilityTransforms = callbacks["utility.transform"];
|
|
23
|
+
const hasUtilityTransforms = !!utilityTransforms && Object.keys(utilityTransforms).length > 0;
|
|
24
|
+
const patternTransforms = callbacks["pattern.transform"];
|
|
25
|
+
const hasPatternTransforms = !!patternTransforms && Object.keys(patternTransforms).length > 0;
|
|
26
|
+
const config = project.config();
|
|
27
|
+
const patternDefaultValues = callbacks["pattern.defaultValues"];
|
|
28
|
+
const patternDefaultValueRefs = config && patternDefaultValues ? getPatternDefaultValueRefsByTransformId(config) : /* @__PURE__ */ new Map();
|
|
29
|
+
const { token, utils } = createTransformHelpers(tokenDictionary);
|
|
30
|
+
if (hasPatternTransforms && !project.registerPatternTransform) {
|
|
31
|
+
throw new Error("Native project does not support pattern.transform callbacks");
|
|
32
|
+
}
|
|
33
|
+
if (project.registerPatternTransform && patternTransforms) {
|
|
34
|
+
for (const [id, callback] of Object.entries(patternTransforms)) {
|
|
35
|
+
const defaultValueId = patternDefaultValueRefs.get(id);
|
|
36
|
+
const defaultValue = defaultValueId ? patternDefaultValues?.[defaultValueId] : void 0;
|
|
37
|
+
project.registerPatternTransform(id, (props) => {
|
|
38
|
+
const input = props;
|
|
39
|
+
const nextProps = defaultValue ? mergePatternDefaultValues(defaultValue(input), input) : input;
|
|
40
|
+
return callback(nextProps, PATTERN_HELPERS);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (hasUtilityTransforms && !project.registerUtilityTransform) {
|
|
45
|
+
throw new Error("Native project does not support utility.transform callbacks");
|
|
46
|
+
}
|
|
47
|
+
if (project.registerUtilityTransform && utilityTransforms) {
|
|
48
|
+
for (const [id, callback] of Object.entries(utilityTransforms)) {
|
|
49
|
+
project.registerUtilityTransform(id, (resolved, original) => {
|
|
50
|
+
return callback(resolved, { raw: original, token, utils });
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const sourceTransforms = hooks?.["parser:before"];
|
|
55
|
+
if (sourceTransforms?.length && !project.registerSourceTransform) {
|
|
56
|
+
throw new Error("Native project does not support parser:before callbacks");
|
|
57
|
+
}
|
|
58
|
+
if (project.registerSourceTransform && sourceTransforms) {
|
|
59
|
+
for (const hook of sourceTransforms) {
|
|
60
|
+
const callback = callbacks["parser:before"]?.[hook.id];
|
|
61
|
+
if (!callback) continue;
|
|
62
|
+
project.registerSourceTransform(hook.id, hook.filter, (filePath, content) => {
|
|
63
|
+
const result = callback({ filePath: String(filePath), content: String(content), original: String(content) });
|
|
64
|
+
if (isPromiseLike(result)) {
|
|
65
|
+
throw new Error(`parser:before callback \`${hook.id}\` must be synchronous`);
|
|
66
|
+
}
|
|
67
|
+
return typeof result === "string" ? result : void 0;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function isPromiseLike(value) {
|
|
73
|
+
return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/fallback.ts
|
|
77
|
+
import { BuildInfo, DesignSystem } from "@pandacss/compiler-shared";
|
|
78
|
+
var fallbackBuildInfo = new BuildInfo({
|
|
79
|
+
serializeBuildInfo: () => ({
|
|
80
|
+
schemaVersion: -1,
|
|
81
|
+
panda: "",
|
|
82
|
+
configFingerprint: "",
|
|
83
|
+
strings: [],
|
|
84
|
+
atoms: [],
|
|
85
|
+
modules: {}
|
|
86
|
+
}),
|
|
87
|
+
applyBuildInfo: () => false,
|
|
88
|
+
buildInfoSchemaVersion: () => -1,
|
|
89
|
+
configFingerprint: () => ""
|
|
90
|
+
});
|
|
91
|
+
var fallbackDesignSystem = new DesignSystem(
|
|
92
|
+
{
|
|
93
|
+
createManifest: (input) => ({ ...input, schemaVersion: -1 }),
|
|
94
|
+
manifestSchemaVersion: () => -1
|
|
95
|
+
},
|
|
96
|
+
fallbackBuildInfo
|
|
97
|
+
);
|
|
98
|
+
var FallbackExtractor = class {
|
|
99
|
+
extract() {
|
|
100
|
+
return { calls: [], jsx: [], diagnostics: [] };
|
|
101
|
+
}
|
|
102
|
+
extractDebug() {
|
|
103
|
+
return { imports: [], matched: [], calls: [], jsx: [], diagnostics: [] };
|
|
104
|
+
}
|
|
105
|
+
matchImports() {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var FallbackCompiler = class _FallbackCompiler {
|
|
110
|
+
fs = {
|
|
111
|
+
readFile: (_path) => void 0,
|
|
112
|
+
exists: (_path) => false
|
|
113
|
+
};
|
|
114
|
+
path = {
|
|
115
|
+
realpath: (path) => path,
|
|
116
|
+
resolve: (path, cwd) => this.resolvePath(path, cwd),
|
|
117
|
+
join: (parts) => this.joinPath(parts),
|
|
118
|
+
dirname: (path) => this.dirname(path)
|
|
119
|
+
};
|
|
120
|
+
static fromConfig() {
|
|
121
|
+
return new _FallbackCompiler();
|
|
122
|
+
}
|
|
123
|
+
serializeBuildInfo() {
|
|
124
|
+
return fallbackBuildInfo.create({ panda: "" });
|
|
125
|
+
}
|
|
126
|
+
applyBuildInfo() {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
buildInfoSchemaVersion() {
|
|
130
|
+
return -1;
|
|
131
|
+
}
|
|
132
|
+
configFingerprint() {
|
|
133
|
+
return "";
|
|
134
|
+
}
|
|
135
|
+
createDesignSystemManifest(input) {
|
|
136
|
+
return { ...input, schemaVersion: -1 };
|
|
137
|
+
}
|
|
138
|
+
designSystemManifestSchemaVersion() {
|
|
139
|
+
return -1;
|
|
140
|
+
}
|
|
141
|
+
config() {
|
|
142
|
+
return {};
|
|
143
|
+
}
|
|
144
|
+
extractFileSource() {
|
|
145
|
+
return { calls: [], jsx: [], diagnostics: [] };
|
|
146
|
+
}
|
|
147
|
+
parseFile(path) {
|
|
148
|
+
return { path, cssCalls: 0, cvaCalls: 0, svaCalls: 0, jsxUsages: 0, diagnostics: [] };
|
|
149
|
+
}
|
|
150
|
+
parseFileSource(path) {
|
|
151
|
+
return { path, cssCalls: 0, cvaCalls: 0, svaCalls: 0, jsxUsages: 0, diagnostics: [] };
|
|
152
|
+
}
|
|
153
|
+
refreshFile() {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
refreshFileSource() {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
removeFile() {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
clear() {
|
|
163
|
+
}
|
|
164
|
+
scan() {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
designSystemImportSelections() {
|
|
168
|
+
return [];
|
|
169
|
+
}
|
|
170
|
+
realpath(path) {
|
|
171
|
+
return path;
|
|
172
|
+
}
|
|
173
|
+
readFile(_path) {
|
|
174
|
+
return void 0;
|
|
175
|
+
}
|
|
176
|
+
exists(_path) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
resolvePath(path, cwd) {
|
|
180
|
+
if (!cwd || path.startsWith("/")) return path;
|
|
181
|
+
return `${cwd.replace(/\/$/, "")}/${path}`;
|
|
182
|
+
}
|
|
183
|
+
joinPath(parts) {
|
|
184
|
+
return parts.filter(Boolean).join("/");
|
|
185
|
+
}
|
|
186
|
+
dirname(path) {
|
|
187
|
+
const index = path.lastIndexOf("/");
|
|
188
|
+
return index <= 0 ? "" : path.slice(0, index);
|
|
189
|
+
}
|
|
190
|
+
isSourceFile() {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
parseFiles(_paths) {
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
layers() {
|
|
197
|
+
return { reset: "reset", base: "base", tokens: "tokens", recipes: "recipes", utilities: "utilities" };
|
|
198
|
+
}
|
|
199
|
+
hasLayerDeclaration() {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
stripLayerOrderStatements(css) {
|
|
203
|
+
return css;
|
|
204
|
+
}
|
|
205
|
+
spec() {
|
|
206
|
+
return {
|
|
207
|
+
conditions: { keys: [], breakpoints: [], containers: [] },
|
|
208
|
+
tokens: { categories: {}, colorPalettes: [], values: {}, deprecated: {} },
|
|
209
|
+
utilities: { properties: {}, shorthands: {}, deprecated: {} },
|
|
210
|
+
keyframes: { keys: [] },
|
|
211
|
+
patterns: {},
|
|
212
|
+
recipes: {},
|
|
213
|
+
slotRecipes: {},
|
|
214
|
+
propertyOrder: []
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
sources() {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
inspectFileSource(_path, _source) {
|
|
221
|
+
return { usages: [], diagnostics: [], calls: [], jsx: [], tokenRefs: [], componentEntries: [], styleEntries: [] };
|
|
222
|
+
}
|
|
223
|
+
transformSource(input) {
|
|
224
|
+
return {
|
|
225
|
+
code: input.source,
|
|
226
|
+
map: null,
|
|
227
|
+
changed: false,
|
|
228
|
+
bailed: false,
|
|
229
|
+
diagnostics: [],
|
|
230
|
+
dependencies: [],
|
|
231
|
+
helper: { needsCx: false, needsCva: false, needsSva: false }
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
inspectFile(input) {
|
|
235
|
+
return { ...this.inspectFileSource(input.path, input.source), path: input.path };
|
|
236
|
+
}
|
|
237
|
+
inspectFiles(files) {
|
|
238
|
+
return { sourceCount: files.length, files: files.map((file) => this.inspectFile(file)) };
|
|
239
|
+
}
|
|
240
|
+
resolveUtilityValue() {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
suggestTokens() {
|
|
244
|
+
return [];
|
|
245
|
+
}
|
|
246
|
+
suggestSemanticTokens() {
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
writeArtifacts(_options) {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
writeCss(options) {
|
|
253
|
+
return emptyWriteCssResult(options.outfile);
|
|
254
|
+
}
|
|
255
|
+
writeLayerCss(options) {
|
|
256
|
+
return emptyWriteCssResult(options.outfile);
|
|
257
|
+
}
|
|
258
|
+
writeSplitCss(options) {
|
|
259
|
+
return emptyWriteSplitCssResult(options.outdir ?? "");
|
|
260
|
+
}
|
|
261
|
+
isEmpty() {
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
atoms() {
|
|
265
|
+
return [];
|
|
266
|
+
}
|
|
267
|
+
recipes() {
|
|
268
|
+
return [];
|
|
269
|
+
}
|
|
270
|
+
slotRecipes() {
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
encodedRecipes() {
|
|
274
|
+
return { base: [], variants: [], atomic: [] };
|
|
275
|
+
}
|
|
276
|
+
staticPatternAtoms() {
|
|
277
|
+
return { atoms: [], diagnostics: [] };
|
|
278
|
+
}
|
|
279
|
+
getFile() {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
fileManifest() {
|
|
283
|
+
return [];
|
|
284
|
+
}
|
|
285
|
+
summary() {
|
|
286
|
+
return { filesProcessed: 0, atomCount: 0, recipeCount: 0, slotRecipeCount: 0 };
|
|
287
|
+
}
|
|
288
|
+
compile() {
|
|
289
|
+
return emptyCompileOutput();
|
|
290
|
+
}
|
|
291
|
+
getLayerCss(_options) {
|
|
292
|
+
return emptyCompileOutput();
|
|
293
|
+
}
|
|
294
|
+
getKeyframeCss(_options) {
|
|
295
|
+
return emptyCompileOutput();
|
|
296
|
+
}
|
|
297
|
+
getSplitCss(_options) {
|
|
298
|
+
return { files: [], diagnostics: [] };
|
|
299
|
+
}
|
|
300
|
+
buildInfo = fallbackBuildInfo;
|
|
301
|
+
designSystem = fallbackDesignSystem;
|
|
302
|
+
generateArtifacts() {
|
|
303
|
+
return [];
|
|
304
|
+
}
|
|
305
|
+
generateArtifact() {
|
|
306
|
+
return void 0;
|
|
307
|
+
}
|
|
308
|
+
generateAffectedArtifacts() {
|
|
309
|
+
return [];
|
|
310
|
+
}
|
|
311
|
+
diagnostics() {
|
|
312
|
+
return [];
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
var fallback = {
|
|
316
|
+
startTracing() {
|
|
317
|
+
return false;
|
|
318
|
+
},
|
|
319
|
+
flushTracing() {
|
|
320
|
+
},
|
|
321
|
+
takeTimingsJson() {
|
|
322
|
+
return void 0;
|
|
323
|
+
},
|
|
324
|
+
shutdownTracing() {
|
|
325
|
+
return false;
|
|
326
|
+
},
|
|
327
|
+
compile() {
|
|
328
|
+
return emptyCompileOutput();
|
|
329
|
+
},
|
|
330
|
+
scanImports() {
|
|
331
|
+
return { imports: [], diagnostics: [] };
|
|
332
|
+
},
|
|
333
|
+
matchImports() {
|
|
334
|
+
return [];
|
|
335
|
+
},
|
|
336
|
+
extractCalls() {
|
|
337
|
+
return { calls: [], diagnostics: [] };
|
|
338
|
+
},
|
|
339
|
+
extractJsx() {
|
|
340
|
+
return { jsx: [], diagnostics: [] };
|
|
341
|
+
},
|
|
342
|
+
extract() {
|
|
343
|
+
return { calls: [], jsx: [], diagnostics: [] };
|
|
344
|
+
},
|
|
345
|
+
extractDebug() {
|
|
346
|
+
return { imports: [], matched: [], calls: [], jsx: [], diagnostics: [] };
|
|
347
|
+
},
|
|
348
|
+
Extractor: FallbackExtractor,
|
|
349
|
+
Compiler: FallbackCompiler
|
|
350
|
+
};
|
|
351
|
+
function emptyCompileOutput() {
|
|
352
|
+
return {
|
|
353
|
+
css: "",
|
|
354
|
+
manifest: { files: [], tokens: [] },
|
|
355
|
+
layerRanges: {},
|
|
356
|
+
diagnostics: []
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function emptyWriteCssResult(path) {
|
|
360
|
+
return {
|
|
361
|
+
path,
|
|
362
|
+
...emptyCompileOutput()
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function emptyWriteSplitCssResult(root) {
|
|
366
|
+
return {
|
|
367
|
+
root,
|
|
368
|
+
paths: [],
|
|
369
|
+
files: [],
|
|
370
|
+
diagnostics: []
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// src/load-binary.ts
|
|
375
|
+
import { execFileSync } from "child_process";
|
|
376
|
+
import { existsSync, mkdirSync, readFileSync, rmSync } from "fs";
|
|
377
|
+
import { createRequire } from "module";
|
|
378
|
+
import { dirname, join } from "path";
|
|
379
|
+
import { fileURLToPath } from "url";
|
|
380
|
+
var bindingUrl = new URL("../binding.cjs", import.meta.url);
|
|
381
|
+
var webContainerWasiPackage = "@pandacss/compiler-wasm32-wasi";
|
|
382
|
+
function loadNativeBinding() {
|
|
383
|
+
const bindingPath = resolveBindingPath();
|
|
384
|
+
if (!bindingPath) return void 0;
|
|
385
|
+
const require2 = createRequire(bindingPath);
|
|
386
|
+
try {
|
|
387
|
+
return require2(bindingPath);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
if (!isWebContainer()) throw error;
|
|
390
|
+
return loadWebContainerBinding(require2, bindingPath, error);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function resolveBindingPath() {
|
|
394
|
+
if (bindingUrl.protocol === "file:") {
|
|
395
|
+
const bindingPath = fileURLToPath(bindingUrl);
|
|
396
|
+
if (existsSync(bindingPath)) return bindingPath;
|
|
397
|
+
}
|
|
398
|
+
return fallbackBindingPaths().find((path) => existsSync(path));
|
|
399
|
+
}
|
|
400
|
+
function fallbackBindingPaths() {
|
|
401
|
+
const cwd = process.cwd();
|
|
402
|
+
const paths = [join(cwd, "packages/compiler/binding.cjs")];
|
|
403
|
+
if (isCompilerPackageRoot(cwd)) {
|
|
404
|
+
paths.unshift(join(cwd, "binding.cjs"));
|
|
405
|
+
}
|
|
406
|
+
return paths;
|
|
407
|
+
}
|
|
408
|
+
function isCompilerPackageRoot(cwd) {
|
|
409
|
+
try {
|
|
410
|
+
const packageJson = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
|
|
411
|
+
return packageJson.name === "@pandacss/compiler";
|
|
412
|
+
} catch {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function isWebContainer() {
|
|
417
|
+
const versions = process.versions;
|
|
418
|
+
return Boolean(versions.webcontainer);
|
|
419
|
+
}
|
|
420
|
+
function resolveWebContainerBinding(version, root = "/tmp") {
|
|
421
|
+
const baseDir = join(root, `pandacss-compiler-${version}`);
|
|
422
|
+
return {
|
|
423
|
+
baseDir,
|
|
424
|
+
bindingPackage: `${webContainerWasiPackage}@${version}`,
|
|
425
|
+
bindingEntry: join(baseDir, "node_modules", webContainerWasiPackage, "compiler.wasi.cjs")
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function loadWebContainerBinding(require2, bindingPath, nativeError) {
|
|
429
|
+
const version = readCompilerVersion(require2, dirname(bindingPath));
|
|
430
|
+
const { baseDir, bindingPackage, bindingEntry } = resolveWebContainerBinding(version);
|
|
431
|
+
if (!existsSync(bindingEntry)) {
|
|
432
|
+
rmSync(baseDir, { recursive: true, force: true });
|
|
433
|
+
mkdirSync(baseDir, { recursive: true });
|
|
434
|
+
execFileSync("pnpm", ["i", bindingPackage], {
|
|
435
|
+
cwd: baseDir,
|
|
436
|
+
stdio: "inherit"
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
try {
|
|
440
|
+
return require2(bindingEntry);
|
|
441
|
+
} catch (fallbackError) {
|
|
442
|
+
throw new Error("Failed to load @pandacss/compiler WebContainer WASI fallback", {
|
|
443
|
+
cause: chainError(nativeError, fallbackError)
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function readCompilerVersion(require2, packageRoot) {
|
|
448
|
+
try {
|
|
449
|
+
const packageJsonPath = require2.resolve("@pandacss/compiler/package.json");
|
|
450
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
451
|
+
return packageJson.version;
|
|
452
|
+
} catch {
|
|
453
|
+
const packageJson = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
|
|
454
|
+
return packageJson.version;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function chainError(primary, cause) {
|
|
458
|
+
if (primary instanceof Error) {
|
|
459
|
+
primary.cause = cause;
|
|
460
|
+
return primary;
|
|
461
|
+
}
|
|
462
|
+
return cause;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// src/index.ts
|
|
466
|
+
import { createUsageReport } from "@pandacss/compiler-shared";
|
|
467
|
+
|
|
468
|
+
// src/driver.ts
|
|
469
|
+
import {
|
|
470
|
+
BaseDriver,
|
|
471
|
+
collectParseDiagnostics,
|
|
472
|
+
diagnosticsPass,
|
|
473
|
+
fromCodegenPrepareArtifacts,
|
|
474
|
+
normalizeDiagnostics
|
|
475
|
+
} from "@pandacss/compiler-shared";
|
|
476
|
+
import {
|
|
477
|
+
buildCodegenOverlay,
|
|
478
|
+
compilePreset,
|
|
479
|
+
defaultImportMap,
|
|
480
|
+
diffConfig,
|
|
481
|
+
filterPublishableLibFiles,
|
|
482
|
+
loadConfig as loadConfig2,
|
|
483
|
+
mergeExcludes,
|
|
484
|
+
readPackageIdentity,
|
|
485
|
+
readPandaVersion as readPandaVersion2,
|
|
486
|
+
resolvePublishedPandaRange,
|
|
487
|
+
resolveSmartInclude,
|
|
488
|
+
syncExports,
|
|
489
|
+
toPosixRelative,
|
|
490
|
+
toRelativeKey
|
|
491
|
+
} from "@pandacss/config";
|
|
492
|
+
import { statSync } from "fs";
|
|
493
|
+
import { dirname as dirname2, resolve as resolvePath } from "path";
|
|
494
|
+
|
|
495
|
+
// src/design-system.ts
|
|
496
|
+
import "@pandacss/compiler-shared";
|
|
497
|
+
import {
|
|
498
|
+
collectArtifactConflicts,
|
|
499
|
+
readPandaVersion
|
|
500
|
+
} from "@pandacss/config";
|
|
501
|
+
function artifactConflictDiagnostics(metadata) {
|
|
502
|
+
return collectArtifactConflicts(metadata).flatMap((conflict) => [
|
|
503
|
+
...conflict.recipes.map((name) => artifactConflict("Recipe", name, conflict.name)),
|
|
504
|
+
...conflict.patterns.map((name) => artifactConflict("Pattern", name, conflict.name))
|
|
505
|
+
]);
|
|
506
|
+
}
|
|
507
|
+
function artifactConflict(kind, name, designSystem) {
|
|
508
|
+
return {
|
|
509
|
+
code: "design_system_artifact_conflict",
|
|
510
|
+
severity: "warning",
|
|
511
|
+
category: "designSystem",
|
|
512
|
+
message: `${kind} ${JSON.stringify(name)} is defined by both ${JSON.stringify(designSystem)} and this config; your definition is merged over the design system's.`
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
function hydrateDesignSystem(compiler, options) {
|
|
516
|
+
const { chain, consumerTokenPaths = [], treeshake, importSelections } = options;
|
|
517
|
+
if (!chain || chain.length === 0) {
|
|
518
|
+
return { diagnostics: [], treeshakeKey: "" };
|
|
519
|
+
}
|
|
520
|
+
const pandaVersion = readPandaVersion();
|
|
521
|
+
const diagnostics = [];
|
|
522
|
+
const selections = treeshake ? importSelections ?? collectImportSelections(compiler, chain) : void 0;
|
|
523
|
+
for (let i = 0; i < chain.length; i++) {
|
|
524
|
+
const ds = chain[i];
|
|
525
|
+
const imports = selections ? selections[i] ?? void 0 : void 0;
|
|
526
|
+
diagnostics.push(...hydrateLevel(compiler, ds, pandaVersion, consumerTokenPaths, imports));
|
|
527
|
+
}
|
|
528
|
+
return {
|
|
529
|
+
diagnostics,
|
|
530
|
+
treeshakeKey: treeshakeKeyFromSelections(chain, selections)
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
function collectImportSelections(compiler, chain) {
|
|
534
|
+
return compiler.designSystemImportSelections(
|
|
535
|
+
chain.map((ds) => ({
|
|
536
|
+
packageRoots: getPackageRoots(ds),
|
|
537
|
+
excludeModules: getExcludedModules(ds)
|
|
538
|
+
}))
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
function treeshakeKeyFromSelections(chain, selections) {
|
|
542
|
+
if (!selections?.length) return "";
|
|
543
|
+
return chain.map((ds, i) => `${ds.name}:${JSON.stringify(selections[i] ?? null)}`).join("|");
|
|
544
|
+
}
|
|
545
|
+
var STYLED_SYSTEM_SUBPATHS = ["css", "recipes", "patterns", "jsx", "tokens"];
|
|
546
|
+
function getPackageRoots(ds) {
|
|
547
|
+
return [...new Set([ds.specifier, ds.name].filter((value) => Boolean(value)))];
|
|
548
|
+
}
|
|
549
|
+
function getExcludedModules(ds) {
|
|
550
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
551
|
+
for (const root of getPackageRoots(ds)) {
|
|
552
|
+
for (const sub of STYLED_SYSTEM_SUBPATHS) {
|
|
553
|
+
excluded.add(`${root}/${sub}`);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const map = ds.importMap;
|
|
557
|
+
if (map) {
|
|
558
|
+
for (const value of [map.css, map.recipes, map.patterns, map.jsx, map.tokens]) {
|
|
559
|
+
if (typeof value === "string" && value.length > 0) excluded.add(value);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return [...excluded];
|
|
563
|
+
}
|
|
564
|
+
function hydrateLevel(compiler, ds, pandaVersion, consumerTokenPaths, imports) {
|
|
565
|
+
const compat = compiler.designSystem.validate(ds.manifest, { pandaVersion });
|
|
566
|
+
if (!compat.ok) {
|
|
567
|
+
throw incompatibleManifestError(compiler, ds, compat.reason, pandaVersion);
|
|
568
|
+
}
|
|
569
|
+
const diagnostics = hydrateArtifacts(compiler, ds, pandaVersion, imports);
|
|
570
|
+
diagnostics.push(...tokenConflictDiagnostics(ds, consumerTokenPaths));
|
|
571
|
+
return diagnostics;
|
|
572
|
+
}
|
|
573
|
+
function hydrateArtifacts(compiler, ds, pandaVersion, imports) {
|
|
574
|
+
if (ds.optionMismatch && ds.optionMismatch.length > 0) {
|
|
575
|
+
const diagnostic = recoverFromSources(
|
|
576
|
+
compiler,
|
|
577
|
+
ds,
|
|
578
|
+
(sourceCount, severity) => optionMismatchDiagnostic(ds, sourceCount, severity)
|
|
579
|
+
);
|
|
580
|
+
return [diagnostic];
|
|
581
|
+
}
|
|
582
|
+
let buildInfo;
|
|
583
|
+
try {
|
|
584
|
+
const content = compiler.fs.readFile(ds.buildInfoPath);
|
|
585
|
+
if (content == null) {
|
|
586
|
+
throw new Error("file not found");
|
|
587
|
+
}
|
|
588
|
+
buildInfo = JSON.parse(content);
|
|
589
|
+
} catch (error) {
|
|
590
|
+
const issue = { kind: "read", detail: errorMessage(error) };
|
|
591
|
+
const diagnostic = recoverFromSources(
|
|
592
|
+
compiler,
|
|
593
|
+
ds,
|
|
594
|
+
(sourceCount, severity) => buildInfoDiagnostic(ds, issue, sourceCount, severity)
|
|
595
|
+
);
|
|
596
|
+
return [diagnostic];
|
|
597
|
+
}
|
|
598
|
+
const result = compiler.designSystem.load(ds.manifest, {
|
|
599
|
+
buildInfo,
|
|
600
|
+
pandaVersion,
|
|
601
|
+
...imports !== void 0 ? { imports } : {}
|
|
602
|
+
});
|
|
603
|
+
if (!result.ok) {
|
|
604
|
+
const issue = result.reason === "schemaVersion" ? {
|
|
605
|
+
kind: "schemaVersion",
|
|
606
|
+
received: buildInfo.schemaVersion,
|
|
607
|
+
expected: compiler.buildInfo.schemaVersion
|
|
608
|
+
} : { kind: "corrupt" };
|
|
609
|
+
const diagnostic = recoverFromSources(
|
|
610
|
+
compiler,
|
|
611
|
+
ds,
|
|
612
|
+
(sourceCount, severity) => buildInfoDiagnostic(ds, issue, sourceCount, severity)
|
|
613
|
+
);
|
|
614
|
+
return [diagnostic];
|
|
615
|
+
}
|
|
616
|
+
return [];
|
|
617
|
+
}
|
|
618
|
+
function recoverFromSources(compiler, ds, createDiagnostic) {
|
|
619
|
+
const sources = extractFallbackSources(compiler, ds);
|
|
620
|
+
const severity = sources.length === 0 ? "error" : "warning";
|
|
621
|
+
const diagnostic = createDiagnostic(sources.length, severity);
|
|
622
|
+
if (sources.length === 0) {
|
|
623
|
+
throw diagnosticError(diagnostic);
|
|
624
|
+
}
|
|
625
|
+
compiler.parseFiles(sources);
|
|
626
|
+
return diagnostic;
|
|
627
|
+
}
|
|
628
|
+
function extractFallbackSources(compiler, ds) {
|
|
629
|
+
if (ds.files.length === 0) {
|
|
630
|
+
return [];
|
|
631
|
+
}
|
|
632
|
+
const filesCwd = compiler.path.resolve(compiler.path.join([compiler.path.dirname(ds.manifestPath), ".."]));
|
|
633
|
+
return compiler.scan({ include: ds.files, cwd: filesCwd });
|
|
634
|
+
}
|
|
635
|
+
function buildInfoDiagnostic(ds, issue, sourceCount, severity) {
|
|
636
|
+
const reason = buildInfoIssueMessage(issue);
|
|
637
|
+
const outcome = sourceCount > 0 ? ` Re-extracted ${sourceCount} source ${sourceCount === 1 ? "file" : "files"}.` : " No fallback source files were available.";
|
|
638
|
+
return {
|
|
639
|
+
code: "design_system_buildinfo_stale",
|
|
640
|
+
severity,
|
|
641
|
+
category: "designSystem",
|
|
642
|
+
file: ds.buildInfoPath,
|
|
643
|
+
message: `${JSON.stringify(ds.name)} build info ${reason}.${outcome}`,
|
|
644
|
+
help: [`Run \`panda lib\` in ${JSON.stringify(ds.name)} to rebuild panda/buildinfo.json.`]
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
function buildInfoIssueMessage(issue) {
|
|
648
|
+
if (issue.kind === "schemaVersion") {
|
|
649
|
+
return `uses schemaVersion ${formatValue(issue.received)}; expected ${issue.expected}`;
|
|
650
|
+
}
|
|
651
|
+
if (issue.kind === "read") {
|
|
652
|
+
return `could not be read: ${issue.detail}`;
|
|
653
|
+
}
|
|
654
|
+
return "is malformed or corrupt";
|
|
655
|
+
}
|
|
656
|
+
function optionMismatchDiagnostic(ds, sourceCount, severity) {
|
|
657
|
+
const options = ds.optionMismatch?.join(", ") ?? "class-name options";
|
|
658
|
+
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.";
|
|
659
|
+
return {
|
|
660
|
+
code: "design_system_option_mismatch",
|
|
661
|
+
severity,
|
|
662
|
+
category: "designSystem",
|
|
663
|
+
file: ds.manifestPath,
|
|
664
|
+
message: `${JSON.stringify(ds.name)} was built with different ${options}.${outcome}`,
|
|
665
|
+
help: [`Match ${options} with ${JSON.stringify(ds.name)}, or rebuild it with \`panda lib\`.`]
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
function tokenConflictDiagnostics(ds, consumerTokenPaths) {
|
|
669
|
+
if (consumerTokenPaths.length === 0 || ds.tokenPaths.length === 0) {
|
|
670
|
+
return [];
|
|
671
|
+
}
|
|
672
|
+
const designSystemTokenPaths = new Set(ds.tokenPaths);
|
|
673
|
+
const conflicts = [...new Set(consumerTokenPaths.filter((path) => designSystemTokenPaths.has(path)))].sort();
|
|
674
|
+
if (conflicts.length === 0) {
|
|
675
|
+
return [];
|
|
676
|
+
}
|
|
677
|
+
const preview = conflicts.slice(0, 3).map((path) => JSON.stringify(path)).join(", ");
|
|
678
|
+
const remainder = conflicts.length > 3 ? ` and ${conflicts.length - 3} more` : "";
|
|
679
|
+
return [
|
|
680
|
+
{
|
|
681
|
+
code: "design_system_token_conflict",
|
|
682
|
+
severity: "info",
|
|
683
|
+
category: "designSystem",
|
|
684
|
+
file: ds.manifestPath,
|
|
685
|
+
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.`
|
|
686
|
+
}
|
|
687
|
+
];
|
|
688
|
+
}
|
|
689
|
+
function incompatibleManifestError(compiler, ds, reason, pandaVersion) {
|
|
690
|
+
if (reason === "schemaVersion") {
|
|
691
|
+
return diagnosticError({
|
|
692
|
+
code: "design_system_version_mismatch",
|
|
693
|
+
severity: "error",
|
|
694
|
+
category: "designSystem",
|
|
695
|
+
file: ds.manifestPath,
|
|
696
|
+
message: `${JSON.stringify(ds.name)} panda/lib.json uses schemaVersion ${ds.manifest.schemaVersion}; expected ${compiler.designSystem.schemaVersion}.`,
|
|
697
|
+
help: [`Upgrade ${JSON.stringify(ds.name)}, or rebuild it with a compatible version of Panda.`]
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
const running = pandaVersion ? `; the consumer uses ${pandaVersion}` : "";
|
|
701
|
+
return diagnosticError({
|
|
702
|
+
code: "design_system_peer_range_unsatisfied",
|
|
703
|
+
severity: "error",
|
|
704
|
+
category: "designSystem",
|
|
705
|
+
file: ds.manifestPath,
|
|
706
|
+
message: `${JSON.stringify(ds.name)} requires Panda ${ds.manifest.panda}${running}.`,
|
|
707
|
+
help: [`Install a compatible Panda version or update ${JSON.stringify(ds.name)}.`]
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
function diagnosticError(diagnostic) {
|
|
711
|
+
const error = new Error(diagnostic.message);
|
|
712
|
+
error.diagnostics = [diagnostic];
|
|
713
|
+
return error;
|
|
714
|
+
}
|
|
715
|
+
function formatValue(value) {
|
|
716
|
+
return typeof value === "number" || typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
717
|
+
}
|
|
718
|
+
function errorMessage(error) {
|
|
719
|
+
return error instanceof Error ? error.message : String(error);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// src/tooling/create-project.ts
|
|
723
|
+
import { defaultConfig } from "@pandacss/compiler-shared";
|
|
724
|
+
import {
|
|
725
|
+
collectExportMissingDiagnostics,
|
|
726
|
+
collectNameCollisionDiagnostics,
|
|
727
|
+
loadConfig
|
|
728
|
+
} from "@pandacss/config";
|
|
729
|
+
function treeshakeDesignSystemEnabled(config) {
|
|
730
|
+
const optimize = config.optimize;
|
|
731
|
+
return optimize?.treeshakeDesignSystem === true;
|
|
732
|
+
}
|
|
733
|
+
function createProjectFromLoadedConfig(loaded) {
|
|
734
|
+
const compiler = createCompilerFromSnapshot({
|
|
735
|
+
config: loaded.config,
|
|
736
|
+
callbacks: loaded.callbacks,
|
|
737
|
+
hooks: loaded.hooks
|
|
738
|
+
});
|
|
739
|
+
const hydrated = hydrateDesignSystem(compiler, {
|
|
740
|
+
chain: loaded.metadata?.designSystem,
|
|
741
|
+
consumerTokenPaths: loaded.metadata?.userTokenPaths ?? [],
|
|
742
|
+
treeshake: treeshakeDesignSystemEnabled(loaded.config)
|
|
743
|
+
});
|
|
744
|
+
const designSystemDiagnostics = [
|
|
745
|
+
...hydrated.diagnostics,
|
|
746
|
+
...artifactConflictDiagnostics(loaded.metadata),
|
|
747
|
+
...collectExportMissingDiagnostics(loaded.metadata),
|
|
748
|
+
...collectNameCollisionDiagnostics(loaded.metadata)
|
|
749
|
+
];
|
|
750
|
+
return {
|
|
751
|
+
compiler,
|
|
752
|
+
configPath: loaded.path,
|
|
753
|
+
dependencies: loaded.dependencies,
|
|
754
|
+
outdir: loaded.config.outdir ?? defaultConfig.outdir,
|
|
755
|
+
designSystemDiagnostics,
|
|
756
|
+
designSystemTreeshakeKey: hydrated.treeshakeKey
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// src/driver.ts
|
|
761
|
+
var DEFAULT_DESIGN_SYSTEM_LIB_OUTDIR = "dist";
|
|
762
|
+
var DEFAULT_DESIGN_SYSTEM_LIB_FILES = ["./**/*.{js,mjs}"];
|
|
763
|
+
async function createNodeDriver(options) {
|
|
764
|
+
const loaded = await loadConfig2({ cwd: options.cwd, file: options.configPath });
|
|
765
|
+
if (options.include?.length) applyIncludeOverride(loaded, options.cwd, options.include);
|
|
766
|
+
return new NodeDriver(options, loaded);
|
|
767
|
+
}
|
|
768
|
+
function applyIncludeOverride(loaded, cwd, include) {
|
|
769
|
+
const deps = new Set(loaded.dependencies);
|
|
770
|
+
const resolved = resolveSmartInclude(include, cwd, deps);
|
|
771
|
+
loaded.config.include = resolved.include;
|
|
772
|
+
if (resolved.excludes.length > 0) {
|
|
773
|
+
const existing = Array.isArray(loaded.config.exclude) ? loaded.config.exclude : void 0;
|
|
774
|
+
loaded.config.exclude = mergeExcludes(existing, resolved.excludes);
|
|
775
|
+
}
|
|
776
|
+
loaded.dependencies = Array.from(deps);
|
|
777
|
+
}
|
|
778
|
+
var NodeDriver = class extends BaseDriver {
|
|
779
|
+
#options;
|
|
780
|
+
#loaded;
|
|
781
|
+
#designSystemDiagnostics;
|
|
782
|
+
#designSystemPreset;
|
|
783
|
+
#designSystemArtifactSnapshot;
|
|
784
|
+
#designSystemWatchTargets;
|
|
785
|
+
#codegenOverlay;
|
|
786
|
+
#codegenOverlayResolved = false;
|
|
787
|
+
#designSystemTreeshakeKey;
|
|
788
|
+
#configFilePaths;
|
|
789
|
+
#designSystemFileKinds;
|
|
790
|
+
#sourceGeneration = 0;
|
|
791
|
+
#treeshakeSyncedGeneration = -1;
|
|
792
|
+
constructor(options, loaded) {
|
|
793
|
+
const built = createProjectFromLoadedConfig(loaded);
|
|
794
|
+
super(built.compiler);
|
|
795
|
+
this.#options = options;
|
|
796
|
+
this.#loaded = loaded;
|
|
797
|
+
this.#designSystemDiagnostics = built.designSystemDiagnostics;
|
|
798
|
+
this.#designSystemArtifactSnapshot = designSystemArtifactSnapshot(loaded);
|
|
799
|
+
this.#designSystemTreeshakeKey = built.designSystemTreeshakeKey ?? "";
|
|
800
|
+
}
|
|
801
|
+
get designSystemDiagnostics() {
|
|
802
|
+
return this.#designSystemDiagnostics;
|
|
803
|
+
}
|
|
804
|
+
codegenOverlay() {
|
|
805
|
+
if (!this.#codegenOverlayResolved) {
|
|
806
|
+
this.#codegenOverlay = buildCodegenOverlay(this.#loaded.metadata);
|
|
807
|
+
this.#codegenOverlayResolved = true;
|
|
808
|
+
}
|
|
809
|
+
return this.#codegenOverlay;
|
|
810
|
+
}
|
|
811
|
+
get config() {
|
|
812
|
+
return this.#loaded.config;
|
|
813
|
+
}
|
|
814
|
+
get configPath() {
|
|
815
|
+
return this.#loaded.path;
|
|
816
|
+
}
|
|
817
|
+
get configDependencies() {
|
|
818
|
+
return this.#loaded.dependencies;
|
|
819
|
+
}
|
|
820
|
+
designSystemWatchTargets() {
|
|
821
|
+
return this.#designSystemWatchTargets ??= (this.#loaded.metadata?.designSystem ?? []).map((ds) => {
|
|
822
|
+
const manifestDir = this.compiler.path.dirname(ds.manifestPath);
|
|
823
|
+
const presetPath = realpathIfExists(this.compiler, this.compiler.path.resolve(ds.manifest.preset, manifestDir));
|
|
824
|
+
const filesCwd = designSystemFilesCwd(this.compiler, ds.manifestPath);
|
|
825
|
+
const sourceFiles = ds.files.length > 0 ? this.compiler.scan({ include: ds.files, cwd: filesCwd }).map((file) => realpathIfExists(this.compiler, file)) : [];
|
|
826
|
+
return {
|
|
827
|
+
name: ds.name,
|
|
828
|
+
manifestPath: realpathIfExists(this.compiler, ds.manifestPath),
|
|
829
|
+
buildInfoPath: realpathIfExists(this.compiler, ds.buildInfoPath),
|
|
830
|
+
presetPath,
|
|
831
|
+
sourceFiles: [...new Set(sourceFiles)]
|
|
832
|
+
};
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
isDesignSystemFile(file) {
|
|
836
|
+
const kinds = this.#designSystemFileKinds ??= this.buildDesignSystemFileKinds();
|
|
837
|
+
return kinds.get(this.compiler.path.realpath(file)) ?? false;
|
|
838
|
+
}
|
|
839
|
+
buildDesignSystemFileKinds() {
|
|
840
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
841
|
+
for (const watchTarget of this.#designSystemWatchTargets ?? this.designSystemWatchTargets()) {
|
|
842
|
+
for (const path of [watchTarget.manifestPath, watchTarget.buildInfoPath, watchTarget.presetPath]) {
|
|
843
|
+
kinds.set(this.compiler.path.realpath(path), "artifact");
|
|
844
|
+
}
|
|
845
|
+
for (const path of watchTarget.sourceFiles) {
|
|
846
|
+
kinds.set(this.compiler.path.realpath(path), "source");
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return kinds;
|
|
850
|
+
}
|
|
851
|
+
async syncDesignSystemFileChange(change) {
|
|
852
|
+
const kind = this.isDesignSystemFile(change.path);
|
|
853
|
+
if (kind === "artifact") {
|
|
854
|
+
const diff = await this.reload();
|
|
855
|
+
if (diff.hasChanged) this.parseFiles();
|
|
856
|
+
return diff.hasChanged;
|
|
857
|
+
}
|
|
858
|
+
if (kind === "source") return this.applyChange(change);
|
|
859
|
+
return false;
|
|
860
|
+
}
|
|
861
|
+
syncDesignSystemSources() {
|
|
862
|
+
const changes = [];
|
|
863
|
+
const activeFiles = new Map(
|
|
864
|
+
this.compiler.fileManifest().map((file) => [this.compiler.path.realpath(file.path), file.path])
|
|
865
|
+
);
|
|
866
|
+
for (const target of this.designSystemWatchTargets()) {
|
|
867
|
+
for (const path of target.sourceFiles) {
|
|
868
|
+
const activePath = activeFiles.get(this.compiler.path.realpath(path));
|
|
869
|
+
if (!activePath) continue;
|
|
870
|
+
changes.push({ path: activePath, kind: this.compiler.fs.exists(path) ? "change" : "unlink" });
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
return this.applyChanges(changes);
|
|
874
|
+
}
|
|
875
|
+
async reload() {
|
|
876
|
+
const next = await loadConfig2({ cwd: this.#options.cwd, file: this.#options.configPath });
|
|
877
|
+
if (this.#options.include?.length) applyIncludeOverride(next, this.#options.cwd, this.#options.include);
|
|
878
|
+
const diff = diffConfig(this.#loaded, next);
|
|
879
|
+
const nextDesignSystemArtifactSnapshot = designSystemArtifactSnapshot(next);
|
|
880
|
+
const designSystemArtifactsChanged = this.#designSystemArtifactSnapshot !== nextDesignSystemArtifactSnapshot;
|
|
881
|
+
if (diff.hasChanged || designSystemArtifactsChanged) {
|
|
882
|
+
this.#loaded = next;
|
|
883
|
+
const built = createProjectFromLoadedConfig(next);
|
|
884
|
+
this.setCompiler(built.compiler);
|
|
885
|
+
this.#designSystemDiagnostics = built.designSystemDiagnostics;
|
|
886
|
+
this.#designSystemPreset = void 0;
|
|
887
|
+
this.#designSystemArtifactSnapshot = nextDesignSystemArtifactSnapshot;
|
|
888
|
+
this.#designSystemWatchTargets = void 0;
|
|
889
|
+
this.#codegenOverlay = void 0;
|
|
890
|
+
this.#codegenOverlayResolved = false;
|
|
891
|
+
this.#designSystemTreeshakeKey = built.designSystemTreeshakeKey ?? "";
|
|
892
|
+
this.#configFilePaths = void 0;
|
|
893
|
+
this.#designSystemFileKinds = void 0;
|
|
894
|
+
this.#sourceGeneration++;
|
|
895
|
+
this.#treeshakeSyncedGeneration = -1;
|
|
896
|
+
}
|
|
897
|
+
return designSystemArtifactsChanged && !diff.hasChanged ? { ...diff, hasChanged: true } : diff;
|
|
898
|
+
}
|
|
899
|
+
/** Re-hydrate when treeshake import set changes. */
|
|
900
|
+
syncDesignSystemTreeShake() {
|
|
901
|
+
if (!treeshakeDesignSystemEnabled(this.#loaded.config)) return false;
|
|
902
|
+
const chain = this.#loaded.metadata?.designSystem;
|
|
903
|
+
if (!chain?.length) return false;
|
|
904
|
+
if (this.#treeshakeSyncedGeneration === this.#sourceGeneration) return false;
|
|
905
|
+
const selections = collectImportSelections(this.compiler, chain);
|
|
906
|
+
const nextKey = treeshakeKeyFromSelections(chain, selections);
|
|
907
|
+
this.#treeshakeSyncedGeneration = this.#sourceGeneration;
|
|
908
|
+
if (nextKey === this.#designSystemTreeshakeKey) return false;
|
|
909
|
+
const hydrated = hydrateDesignSystem(this.compiler, {
|
|
910
|
+
chain,
|
|
911
|
+
consumerTokenPaths: this.#loaded.metadata?.userTokenPaths ?? [],
|
|
912
|
+
treeshake: true,
|
|
913
|
+
importSelections: selections
|
|
914
|
+
});
|
|
915
|
+
this.#designSystemDiagnostics = hydrated.diagnostics;
|
|
916
|
+
this.#designSystemTreeshakeKey = hydrated.treeshakeKey;
|
|
917
|
+
return true;
|
|
918
|
+
}
|
|
919
|
+
prepareCssOutput() {
|
|
920
|
+
this.syncDesignSystemTreeShake();
|
|
921
|
+
}
|
|
922
|
+
applyChange(change) {
|
|
923
|
+
this.#sourceGeneration++;
|
|
924
|
+
this.#treeshakeSyncedGeneration = -1;
|
|
925
|
+
if (change.kind === "unlink") {
|
|
926
|
+
return this.compiler.removeFile(change.path);
|
|
927
|
+
}
|
|
928
|
+
if (change.kind === "change") {
|
|
929
|
+
if (change.content == null) {
|
|
930
|
+
if (this.compiler.refreshFile(change.path)) return true;
|
|
931
|
+
this.compiler.parseFile(change.path);
|
|
932
|
+
return true;
|
|
933
|
+
}
|
|
934
|
+
if (this.compiler.refreshFileSource(change.path, change.content)) return true;
|
|
935
|
+
this.compiler.parseFileSource(change.path, change.content);
|
|
936
|
+
return true;
|
|
937
|
+
}
|
|
938
|
+
if (change.content == null) {
|
|
939
|
+
this.compiler.parseFile(change.path);
|
|
940
|
+
return true;
|
|
941
|
+
}
|
|
942
|
+
this.compiler.parseFileSource(change.path, change.content);
|
|
943
|
+
return true;
|
|
944
|
+
}
|
|
945
|
+
getOutdir(outdir) {
|
|
946
|
+
return this.compiler.path.resolve(this.getConfiguredOutdir(outdir));
|
|
947
|
+
}
|
|
948
|
+
async writeDesignSystemLib(options = {}) {
|
|
949
|
+
if (!this.#loaded.path) {
|
|
950
|
+
throw new Error(
|
|
951
|
+
"panda lib requires a resolved config file to compile the design system preset. Run `panda init`, or check --config/--cwd."
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
const parsed = this.parseDesignSystemLib();
|
|
955
|
+
if (!diagnosticsPass(parsed.diagnostics, { maxWarnings: options.maxWarnings }))
|
|
956
|
+
return skippedDesignSystemLib(parsed);
|
|
957
|
+
const preset = await this.compileDesignSystemPreset();
|
|
958
|
+
return this.writeDesignSystemLibArtifacts(options, preset, parsed);
|
|
959
|
+
}
|
|
960
|
+
codegen(options) {
|
|
961
|
+
const outdir = this.getOutdir(options?.outdir);
|
|
962
|
+
const cwd = options?.cwd ?? this.#options.cwd;
|
|
963
|
+
const prepareHooks = this.#loaded.hostHooks?.["codegen:prepare"] ?? [];
|
|
964
|
+
const doneHooks = this.#loaded.hostHooks?.["codegen:done"] ?? [];
|
|
965
|
+
const files = prepareHooks.length > 0 ? this.codegenWithPrepareHooks(prepareHooks, outdir, cwd, options) : super.codegen(options);
|
|
966
|
+
for (const entry of doneHooks) {
|
|
967
|
+
const handler = resolveHookHandler(entry.value, "codegen:done");
|
|
968
|
+
handler({ files, outdir, cwd });
|
|
969
|
+
}
|
|
970
|
+
return files;
|
|
971
|
+
}
|
|
972
|
+
cssgen(options) {
|
|
973
|
+
const output = super.cssgen(options);
|
|
974
|
+
this.runCssgenDone({
|
|
975
|
+
artifact: "styles.css",
|
|
976
|
+
content: output.css,
|
|
977
|
+
cwd: this.#options.cwd,
|
|
978
|
+
manifest: output.manifest,
|
|
979
|
+
layerRanges: output.layerRanges
|
|
980
|
+
});
|
|
981
|
+
return output;
|
|
982
|
+
}
|
|
983
|
+
writeCss(options) {
|
|
984
|
+
const result = super.writeCss(options);
|
|
985
|
+
this.runCssgenDone({
|
|
986
|
+
artifact: "styles.css",
|
|
987
|
+
content: result.css,
|
|
988
|
+
path: result.path,
|
|
989
|
+
outfile: options.outfile,
|
|
990
|
+
cwd: options.cwd ?? this.#options.cwd,
|
|
991
|
+
manifest: result.manifest,
|
|
992
|
+
layerRanges: result.layerRanges
|
|
993
|
+
});
|
|
994
|
+
return result;
|
|
995
|
+
}
|
|
996
|
+
writeLayerCss(options) {
|
|
997
|
+
const result = super.writeLayerCss(options);
|
|
998
|
+
this.runCssgenDone({
|
|
999
|
+
artifact: "styles.layer",
|
|
1000
|
+
content: result.css,
|
|
1001
|
+
path: result.path,
|
|
1002
|
+
outfile: options.outfile,
|
|
1003
|
+
cwd: options.cwd ?? this.#options.cwd,
|
|
1004
|
+
manifest: result.manifest,
|
|
1005
|
+
layerRanges: result.layerRanges
|
|
1006
|
+
});
|
|
1007
|
+
return result;
|
|
1008
|
+
}
|
|
1009
|
+
writeSplitCss(options) {
|
|
1010
|
+
const result = super.writeSplitCss(options);
|
|
1011
|
+
const cwd = options?.cwd ?? this.#options.cwd;
|
|
1012
|
+
const outdir = result.root;
|
|
1013
|
+
for (const file of result.files) {
|
|
1014
|
+
const path = this.compiler.path.join([result.root, file.path]);
|
|
1015
|
+
this.runCssgenDone({
|
|
1016
|
+
artifact: "styles.split",
|
|
1017
|
+
content: file.code,
|
|
1018
|
+
path,
|
|
1019
|
+
outdir,
|
|
1020
|
+
cwd
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
return result;
|
|
1024
|
+
}
|
|
1025
|
+
runCssgenDone(args) {
|
|
1026
|
+
const hooks = this.#loaded.hostHooks?.["cssgen:done"] ?? [];
|
|
1027
|
+
for (const entry of hooks) {
|
|
1028
|
+
const handler = resolveHookHandler(entry.value, "cssgen:done");
|
|
1029
|
+
handler(args);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
codegenWithPrepareHooks(hooks, outdir, cwd, options) {
|
|
1033
|
+
const overlay = this.codegenOverlay();
|
|
1034
|
+
let artifacts = this.compiler.generateArtifacts({ ...toGenerateArtifactOptions(options), overlay });
|
|
1035
|
+
for (const entry of hooks) {
|
|
1036
|
+
const handler = resolveHookHandler(entry.value, "codegen:prepare");
|
|
1037
|
+
const next = handler({ artifacts, outdir, cwd });
|
|
1038
|
+
if (next !== void 0) {
|
|
1039
|
+
if (!Array.isArray(next)) {
|
|
1040
|
+
throw new Error("Invalid codegen:prepare hook result. Expected an artifact array or undefined.");
|
|
1041
|
+
}
|
|
1042
|
+
artifacts = fromCodegenPrepareArtifacts(next);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
return this.compiler.writeArtifacts({
|
|
1046
|
+
outdir,
|
|
1047
|
+
cwd,
|
|
1048
|
+
forceImportExtension: options?.forceImportExtension,
|
|
1049
|
+
artifacts,
|
|
1050
|
+
overlay
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
isConfigFile(file) {
|
|
1054
|
+
const paths = this.#configFilePaths ??= this.buildConfigFilePaths();
|
|
1055
|
+
return paths.has(this.compiler.path.realpath(file));
|
|
1056
|
+
}
|
|
1057
|
+
buildConfigFilePaths() {
|
|
1058
|
+
const paths = /* @__PURE__ */ new Set();
|
|
1059
|
+
if (this.#loaded.path) {
|
|
1060
|
+
paths.add(this.compiler.path.realpath(this.#loaded.path));
|
|
1061
|
+
}
|
|
1062
|
+
for (const dependency of this.#loaded.dependencies) {
|
|
1063
|
+
const dependencyPath = this.compiler.path.resolve(dependency, this.#options.cwd);
|
|
1064
|
+
paths.add(this.compiler.path.realpath(dependencyPath));
|
|
1065
|
+
}
|
|
1066
|
+
return paths;
|
|
1067
|
+
}
|
|
1068
|
+
parseDesignSystemLib() {
|
|
1069
|
+
const parsed = this.parseFiles();
|
|
1070
|
+
const parseDiagnostics = collectParseDiagnostics(parsed, {
|
|
1071
|
+
normalizeFile: (file) => stabilizePath(this.#options.cwd, file)
|
|
1072
|
+
});
|
|
1073
|
+
const diagnostics = normalizeDiagnostics([...parseDiagnostics, ...this.compiler.diagnostics()], {
|
|
1074
|
+
normalizeFile: (file) => stabilizePath(this.#options.cwd, file)
|
|
1075
|
+
});
|
|
1076
|
+
return { parsedFileCount: parsed.length, diagnostics };
|
|
1077
|
+
}
|
|
1078
|
+
async compileDesignSystemPreset() {
|
|
1079
|
+
return this.#designSystemPreset ??= await compilePreset({
|
|
1080
|
+
configPath: this.#loaded.path,
|
|
1081
|
+
cwd: this.#options.cwd
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
writeDesignSystemLibArtifacts(options, preset, parsed) {
|
|
1085
|
+
const identity = readPackageIdentity(this.#options.cwd);
|
|
1086
|
+
const pandaRange = resolvePublishedPandaRange(options.panda ?? identity.pandaPeer, readPandaVersion2());
|
|
1087
|
+
const outdir = options.outdir ?? DEFAULT_DESIGN_SYSTEM_LIB_OUTDIR;
|
|
1088
|
+
const outRoot = this.compiler.path.resolve(outdir);
|
|
1089
|
+
const pandaDir = this.compiler.path.join([outRoot, "panda"]);
|
|
1090
|
+
const manifestPath = this.compiler.path.join([pandaDir, "lib.json"]);
|
|
1091
|
+
const buildInfoPath = this.compiler.path.join([pandaDir, "buildinfo.json"]);
|
|
1092
|
+
const presetPath = this.compiler.path.join([pandaDir, "preset.mjs"]);
|
|
1093
|
+
const info = this.compiler.buildInfo.create({ panda: pandaRange });
|
|
1094
|
+
const buildInfo = this.compiler.buildInfo.normalize(info, {
|
|
1095
|
+
mapModuleKey: (key) => toRelativeKey(key, this.#options.cwd)
|
|
1096
|
+
});
|
|
1097
|
+
const { files: libFiles, diagnostics: filesDiagnostics } = resolveDesignSystemLibFiles({
|
|
1098
|
+
explicit: options.files,
|
|
1099
|
+
compiler: this.compiler,
|
|
1100
|
+
cwd: this.#options.cwd,
|
|
1101
|
+
filesBase: outRoot,
|
|
1102
|
+
buildInfo,
|
|
1103
|
+
packageRoot: this.compiler.path.dirname(identity.packagePath),
|
|
1104
|
+
publishFiles: identity.publishFiles,
|
|
1105
|
+
packageName: identity.name
|
|
1106
|
+
});
|
|
1107
|
+
const manifest = this.compiler.designSystem.create({
|
|
1108
|
+
name: identity.name,
|
|
1109
|
+
version: identity.version,
|
|
1110
|
+
panda: pandaRange,
|
|
1111
|
+
preset: "./preset.mjs",
|
|
1112
|
+
buildInfo: "./buildinfo.json",
|
|
1113
|
+
importMap: defaultImportMap(identity.name),
|
|
1114
|
+
designSystem: typeof this.config.designSystem === "string" ? this.config.designSystem : void 0,
|
|
1115
|
+
files: libFiles
|
|
1116
|
+
});
|
|
1117
|
+
this.compiler.writeArtifacts({
|
|
1118
|
+
outdir,
|
|
1119
|
+
cwd: this.#options.cwd,
|
|
1120
|
+
artifacts: [
|
|
1121
|
+
{
|
|
1122
|
+
id: "design-system-lib",
|
|
1123
|
+
files: [
|
|
1124
|
+
{
|
|
1125
|
+
path: "panda/lib.json",
|
|
1126
|
+
code: `${JSON.stringify(manifest, null, 2)}
|
|
1127
|
+
`,
|
|
1128
|
+
dependencies: []
|
|
1129
|
+
},
|
|
1130
|
+
{
|
|
1131
|
+
path: "panda/buildinfo.json",
|
|
1132
|
+
code: JSON.stringify(buildInfo, null, options.minify ? 0 : 2),
|
|
1133
|
+
dependencies: []
|
|
1134
|
+
},
|
|
1135
|
+
{
|
|
1136
|
+
path: "panda/preset.mjs",
|
|
1137
|
+
code: preset.code,
|
|
1138
|
+
dependencies: []
|
|
1139
|
+
}
|
|
1140
|
+
]
|
|
1141
|
+
}
|
|
1142
|
+
]
|
|
1143
|
+
});
|
|
1144
|
+
const { changed: exportsChanged, conflicts } = syncPackageExports(this.compiler, identity.packagePath, {
|
|
1145
|
+
pandaDir,
|
|
1146
|
+
styledDir: this.getOutdir()
|
|
1147
|
+
});
|
|
1148
|
+
return {
|
|
1149
|
+
manifestPath,
|
|
1150
|
+
buildInfoPath,
|
|
1151
|
+
presetPath,
|
|
1152
|
+
exportsChanged,
|
|
1153
|
+
parsedFileCount: parsed.parsedFileCount,
|
|
1154
|
+
diagnostics: [...parsed.diagnostics, ...filesDiagnostics, ...exportConflictDiagnostics(identity.name, conflicts)]
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
function resolveDesignSystemLibFiles(options) {
|
|
1159
|
+
if (options.explicit) {
|
|
1160
|
+
return { files: options.explicit, diagnostics: [] };
|
|
1161
|
+
}
|
|
1162
|
+
const inferred = inferDesignSystemLibFiles(options.compiler, options.cwd, options.filesBase, options.buildInfo);
|
|
1163
|
+
const { files, unpublished } = filterPublishableLibFiles({
|
|
1164
|
+
files: inferred,
|
|
1165
|
+
packageRoot: options.packageRoot,
|
|
1166
|
+
outRoot: options.filesBase,
|
|
1167
|
+
publishFiles: options.publishFiles
|
|
1168
|
+
});
|
|
1169
|
+
if (unpublished.length === 0) {
|
|
1170
|
+
return { files, diagnostics: [] };
|
|
1171
|
+
}
|
|
1172
|
+
return {
|
|
1173
|
+
files,
|
|
1174
|
+
diagnostics: [unpublishedLibFilesDiagnostic(options.packageName, unpublished)]
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
function unpublishedLibFilesDiagnostic(name, unpublished) {
|
|
1178
|
+
const sample = unpublished.slice(0, 3).map((path) => JSON.stringify(path)).join(", ");
|
|
1179
|
+
const more = unpublished.length > 3 ? `, and ${unpublished.length - 3} more` : "";
|
|
1180
|
+
return {
|
|
1181
|
+
code: "design_system_files_not_publishable",
|
|
1182
|
+
severity: "warning",
|
|
1183
|
+
category: "designSystem",
|
|
1184
|
+
message: `\`panda lib\` omitted ${unpublished.length === 1 ? "a fallback file" : "fallback files"} from ${JSON.stringify(name)}'s manifest because package.json \`"files"\` would not publish ${sample}${more}. Happy-path consumers still hydrate build info. For dist-only recovery, re-run with \`panda lib --files './**/*.{js,mjs}'\` (or the globs you actually publish).`
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
function exportConflictDiagnostics(name, conflicts) {
|
|
1188
|
+
if (conflicts.length === 0) return [];
|
|
1189
|
+
const paths = conflicts.map((path) => JSON.stringify(path)).join(", ");
|
|
1190
|
+
const plural = conflicts.length > 1;
|
|
1191
|
+
return [
|
|
1192
|
+
{
|
|
1193
|
+
code: "design_system_export_overwritten",
|
|
1194
|
+
severity: "warning",
|
|
1195
|
+
category: "designSystem",
|
|
1196
|
+
message: `\`panda lib\` overwrote the existing ${paths} export${plural ? "s" : ""} in ${JSON.stringify(name)}'s package.json. Restore or rename ${plural ? "them" : "it"} if you still need the previous target${plural ? "s" : ""}.`
|
|
1197
|
+
}
|
|
1198
|
+
];
|
|
1199
|
+
}
|
|
1200
|
+
function resolveHookHandler(value, name) {
|
|
1201
|
+
if (typeof value === "function") return value;
|
|
1202
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1203
|
+
throw new Error(`Invalid ${name} hook. Expected a function or { filter, handler }.`);
|
|
1204
|
+
}
|
|
1205
|
+
const handler = value.handler;
|
|
1206
|
+
if (typeof handler !== "function") {
|
|
1207
|
+
throw new Error(`Invalid ${name} hook. Expected a function or { filter, handler }.`);
|
|
1208
|
+
}
|
|
1209
|
+
return handler;
|
|
1210
|
+
}
|
|
1211
|
+
function skippedDesignSystemLib(parsed) {
|
|
1212
|
+
return {
|
|
1213
|
+
manifestPath: "",
|
|
1214
|
+
buildInfoPath: "",
|
|
1215
|
+
presetPath: "",
|
|
1216
|
+
exportsChanged: false,
|
|
1217
|
+
parsedFileCount: parsed.parsedFileCount,
|
|
1218
|
+
diagnostics: parsed.diagnostics
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
var STYLED_SYSTEM_CATEGORIES = ["css", "recipes", "patterns", "jsx", "tokens", "helpers"];
|
|
1222
|
+
var DEEP_IMPORT_CATEGORIES = /* @__PURE__ */ new Set(["css", "recipes", "patterns", "jsx"]);
|
|
1223
|
+
var SINGLE_FILE_CATEGORIES = /* @__PURE__ */ new Set(["helpers"]);
|
|
1224
|
+
function syncPackageExports(compiler, packagePath, paths) {
|
|
1225
|
+
const base = compiler.path.dirname(packagePath);
|
|
1226
|
+
const pandaGlob = `${toPosixRelative(base, paths.pandaDir)}/*`;
|
|
1227
|
+
const entries = {
|
|
1228
|
+
"./panda/*": pandaGlob,
|
|
1229
|
+
...styledSystemExports(compiler, base, paths.styledDir)
|
|
1230
|
+
};
|
|
1231
|
+
const packageJson = compiler.fs.readFile(packagePath);
|
|
1232
|
+
if (packageJson == null) {
|
|
1233
|
+
throw new Error(`Could not read package.json at ${JSON.stringify(packagePath)}.`);
|
|
1234
|
+
}
|
|
1235
|
+
const result = syncExports({ packageJson, entries });
|
|
1236
|
+
if (result.changed) {
|
|
1237
|
+
compiler.writeArtifacts({
|
|
1238
|
+
outdir: base,
|
|
1239
|
+
artifacts: [
|
|
1240
|
+
{
|
|
1241
|
+
id: "design-system-lib-package",
|
|
1242
|
+
files: [{ path: "package.json", code: result.json, dependencies: [] }]
|
|
1243
|
+
}
|
|
1244
|
+
]
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
return { changed: result.changed, conflicts: result.conflicts };
|
|
1248
|
+
}
|
|
1249
|
+
function styledSystemExports(compiler, base, styledDir) {
|
|
1250
|
+
const rel = (path) => toPosixRelative(base, path);
|
|
1251
|
+
const find = (dir, names) => names.map((name) => compiler.path.join([dir, name])).find((path) => compiler.fs.readFile(path) != null);
|
|
1252
|
+
const entries = {};
|
|
1253
|
+
for (const category of STYLED_SYSTEM_CATEGORIES) {
|
|
1254
|
+
if (SINGLE_FILE_CATEGORIES.has(category)) {
|
|
1255
|
+
const runtime2 = find(styledDir, [`${category}.mjs`, `${category}.js`, `${category}.ts`]);
|
|
1256
|
+
if (!runtime2) continue;
|
|
1257
|
+
const types2 = find(styledDir, [`${category}.d.mts`, `${category}.d.ts`]);
|
|
1258
|
+
entries[`./${category}`] = types2 ? { types: rel(types2), default: rel(runtime2) } : rel(runtime2);
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
const dir = compiler.path.join([styledDir, category]);
|
|
1262
|
+
const runtime = find(dir, ["index.mjs", "index.js", "index.ts"]);
|
|
1263
|
+
if (!runtime) continue;
|
|
1264
|
+
const types = find(dir, ["index.d.mts", "index.d.ts"]);
|
|
1265
|
+
entries[`./${category}`] = types ? { types: rel(types), default: rel(runtime) } : rel(runtime);
|
|
1266
|
+
if (DEEP_IMPORT_CATEGORIES.has(category)) {
|
|
1267
|
+
const runtimeExt = runtime.endsWith(".mjs") ? "mjs" : runtime.endsWith(".ts") ? "ts" : "js";
|
|
1268
|
+
const runtimeGlob = `${rel(dir)}/*.${runtimeExt}`;
|
|
1269
|
+
const typesGlob = types ? `${rel(dir)}/*.${types.endsWith(".d.mts") ? "d.mts" : "d.ts"}` : void 0;
|
|
1270
|
+
entries[`./${category}/*`] = typesGlob ? { types: typesGlob, default: runtimeGlob } : runtimeGlob;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
return entries;
|
|
1274
|
+
}
|
|
1275
|
+
function stabilizePath(cwd, file) {
|
|
1276
|
+
const relativePath = toRelativeKey(file, cwd);
|
|
1277
|
+
return relativePath && !relativePath.startsWith("..") ? relativePath : file;
|
|
1278
|
+
}
|
|
1279
|
+
function designSystemArtifactSnapshot(loaded) {
|
|
1280
|
+
return JSON.stringify(
|
|
1281
|
+
loaded.metadata?.designSystem?.map((ds) => {
|
|
1282
|
+
const presetPath = resolvePath(dirname2(ds.manifestPath), ds.manifest.preset);
|
|
1283
|
+
return {
|
|
1284
|
+
name: ds.name,
|
|
1285
|
+
specifier: ds.specifier,
|
|
1286
|
+
manifest: ds.manifest,
|
|
1287
|
+
manifestPath: ds.manifestPath,
|
|
1288
|
+
buildInfoPath: ds.buildInfoPath,
|
|
1289
|
+
manifestStamp: diskFileStamp(ds.manifestPath),
|
|
1290
|
+
buildInfoStamp: diskFileStamp(ds.buildInfoPath),
|
|
1291
|
+
presetStamp: diskFileStamp(presetPath),
|
|
1292
|
+
files: ds.files,
|
|
1293
|
+
tokenPaths: ds.tokenPaths
|
|
1294
|
+
};
|
|
1295
|
+
}) ?? []
|
|
1296
|
+
);
|
|
1297
|
+
}
|
|
1298
|
+
function diskFileStamp(path) {
|
|
1299
|
+
try {
|
|
1300
|
+
const stat = statSync(path);
|
|
1301
|
+
return `${stat.mtimeMs}:${stat.size}`;
|
|
1302
|
+
} catch {
|
|
1303
|
+
return "missing";
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
function realpathIfExists(compiler, path) {
|
|
1307
|
+
return compiler.fs.exists(path) ? compiler.path.realpath(path) : path;
|
|
1308
|
+
}
|
|
1309
|
+
function designSystemFilesCwd(compiler, manifestPath) {
|
|
1310
|
+
return compiler.path.resolve(compiler.path.join([compiler.path.dirname(manifestPath), ".."]));
|
|
1311
|
+
}
|
|
1312
|
+
function inferDesignSystemLibFiles(compiler, cwd, filesBase, buildInfo) {
|
|
1313
|
+
const files = Object.keys(buildInfo.modules).filter((key) => !key.startsWith("buildinfo:")).map((key) => {
|
|
1314
|
+
const file = compiler.path.resolve(key, cwd);
|
|
1315
|
+
return toPosixRelative(filesBase, file);
|
|
1316
|
+
});
|
|
1317
|
+
return files.length > 0 ? [...new Set(files)] : DEFAULT_DESIGN_SYSTEM_LIB_FILES;
|
|
1318
|
+
}
|
|
1319
|
+
function toGenerateArtifactOptions(options) {
|
|
1320
|
+
return options?.forceImportExtension === void 0 ? void 0 : { forceImportExtension: options.forceImportExtension };
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
// src/index.ts
|
|
1324
|
+
var binding = loadNativeBinding() ?? fallback;
|
|
1325
|
+
var nativeCompilerFromConfig = "fromConfig" in binding.Compiler && typeof binding.Compiler.fromConfig === "function" ? binding.Compiler.fromConfig.bind(binding.Compiler) : void 0;
|
|
1326
|
+
function compile(input) {
|
|
1327
|
+
return binding.compile(input);
|
|
1328
|
+
}
|
|
1329
|
+
function startTracing(options) {
|
|
1330
|
+
return binding.startTracing?.(options) ?? false;
|
|
1331
|
+
}
|
|
1332
|
+
function flushTracing() {
|
|
1333
|
+
binding.flushTracing?.();
|
|
1334
|
+
}
|
|
1335
|
+
function takeTimingsJson() {
|
|
1336
|
+
return binding.takeTimingsJson?.() ?? void 0;
|
|
1337
|
+
}
|
|
1338
|
+
function shutdownTracing() {
|
|
1339
|
+
return binding.shutdownTracing?.() ?? false;
|
|
1340
|
+
}
|
|
1341
|
+
function createCompiler(config, options) {
|
|
1342
|
+
return build(config, options?.callbacks ?? {}, options);
|
|
1343
|
+
}
|
|
1344
|
+
function createCompilerFromSnapshot(snapshot, options) {
|
|
1345
|
+
const callbacks = mergeCallbacks(snapshot.callbacks, options?.callbacks);
|
|
1346
|
+
const hooks = mergeHooks(snapshot.hooks, options?.hooks);
|
|
1347
|
+
return build(snapshot.config, callbacks, { ...options, hooks });
|
|
1348
|
+
}
|
|
1349
|
+
function getBindingInfo() {
|
|
1350
|
+
return {
|
|
1351
|
+
native: binding !== fallback
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
function build(config, callbacks, options) {
|
|
1355
|
+
assertProjectCallbacks(config, callbacks);
|
|
1356
|
+
assertProjectHooks(options?.hooks, callbacks);
|
|
1357
|
+
if (!nativeCompilerFromConfig) {
|
|
1358
|
+
throw new Error("createCompiler is not available in this binding");
|
|
1359
|
+
}
|
|
1360
|
+
const prepared = prepareCompilerConfig(config);
|
|
1361
|
+
const compiler = nativeCompilerFromConfig(prepared, toNativeOptions(options), createUtilityValuesCallbacks(callbacks));
|
|
1362
|
+
registerCallbacks(compiler, callbacks, options?.hooks, compiler.token_dictionary?.());
|
|
1363
|
+
attachFileSystem(compiler);
|
|
1364
|
+
attachPathSystem(compiler);
|
|
1365
|
+
attachBuildInfo(compiler);
|
|
1366
|
+
attachDesignSystem(compiler);
|
|
1367
|
+
attachInspection(compiler);
|
|
1368
|
+
return compiler;
|
|
1369
|
+
}
|
|
1370
|
+
function attachFileSystem(compiler) {
|
|
1371
|
+
Object.defineProperty(compiler, "fs", {
|
|
1372
|
+
value: {
|
|
1373
|
+
readFile: (path) => compiler.readFile(path),
|
|
1374
|
+
exists: (path) => compiler.exists(path)
|
|
1375
|
+
},
|
|
1376
|
+
enumerable: false,
|
|
1377
|
+
configurable: true
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
function attachPathSystem(compiler) {
|
|
1381
|
+
Object.defineProperty(compiler, "path", {
|
|
1382
|
+
value: {
|
|
1383
|
+
realpath: (path) => compiler.realpath(path),
|
|
1384
|
+
resolve: (path, cwd) => compiler.resolvePath(path, cwd),
|
|
1385
|
+
join: (parts) => compiler.joinPath(parts),
|
|
1386
|
+
dirname: (path) => compiler.dirname(path)
|
|
1387
|
+
},
|
|
1388
|
+
enumerable: false,
|
|
1389
|
+
configurable: true
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
function attachBuildInfo(compiler) {
|
|
1393
|
+
Object.defineProperty(compiler, "buildInfo", {
|
|
1394
|
+
enumerable: false,
|
|
1395
|
+
configurable: true,
|
|
1396
|
+
get() {
|
|
1397
|
+
const api = new BuildInfo2(compiler);
|
|
1398
|
+
Object.defineProperty(compiler, "buildInfo", {
|
|
1399
|
+
value: api,
|
|
1400
|
+
enumerable: false,
|
|
1401
|
+
configurable: true
|
|
1402
|
+
});
|
|
1403
|
+
return api;
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
function attachDesignSystem(compiler) {
|
|
1408
|
+
Object.defineProperty(compiler, "designSystem", {
|
|
1409
|
+
enumerable: false,
|
|
1410
|
+
configurable: true,
|
|
1411
|
+
get() {
|
|
1412
|
+
const api = new DesignSystem2(toDesignSystemBinding(compiler), compiler.buildInfo);
|
|
1413
|
+
Object.defineProperty(compiler, "designSystem", {
|
|
1414
|
+
value: api,
|
|
1415
|
+
enumerable: false,
|
|
1416
|
+
configurable: true
|
|
1417
|
+
});
|
|
1418
|
+
return api;
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
function attachInspection(compiler) {
|
|
1423
|
+
Object.defineProperty(compiler, "inspectFile", {
|
|
1424
|
+
enumerable: false,
|
|
1425
|
+
configurable: true,
|
|
1426
|
+
value: (input) => inspectFile(compiler, input)
|
|
1427
|
+
});
|
|
1428
|
+
Object.defineProperty(compiler, "inspectFiles", {
|
|
1429
|
+
enumerable: false,
|
|
1430
|
+
configurable: true,
|
|
1431
|
+
value: (files) => inspectFiles(compiler, files)
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
function toDesignSystemBinding(compiler) {
|
|
1435
|
+
return {
|
|
1436
|
+
createManifest: (input) => compiler.createDesignSystemManifest(input),
|
|
1437
|
+
manifestSchemaVersion: () => compiler.designSystemManifestSchemaVersion()
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
function toNativeOptions(options) {
|
|
1441
|
+
if (!options || options.crossFile === void 0) return void 0;
|
|
1442
|
+
return { crossFile: options.crossFile };
|
|
1443
|
+
}
|
|
1444
|
+
function createUtilityValuesCallbacks(callbacks) {
|
|
1445
|
+
const utilityValues = callbacks["utility.values"];
|
|
1446
|
+
if (!utilityValues || Object.keys(utilityValues).length === 0) return void 0;
|
|
1447
|
+
return utilityValues;
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
export {
|
|
1451
|
+
createNodeDriver,
|
|
1452
|
+
NodeDriver,
|
|
1453
|
+
compile,
|
|
1454
|
+
startTracing,
|
|
1455
|
+
flushTracing,
|
|
1456
|
+
takeTimingsJson,
|
|
1457
|
+
shutdownTracing,
|
|
1458
|
+
createCompiler,
|
|
1459
|
+
createCompilerFromSnapshot,
|
|
1460
|
+
getBindingInfo,
|
|
1461
|
+
createUsageReport
|
|
1462
|
+
};
|