@pandacss/config 2.0.0-beta.0 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +189 -126
- package/package.json +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -81,4 +81,4 @@ interface BundleConfigResult<T = Config> {
|
|
|
81
81
|
*/
|
|
82
82
|
declare function bundleConfig<T extends Config = Config>(filepath: string, cwd: string): Promise<BundleConfigResult<T>>;
|
|
83
83
|
|
|
84
|
-
export { type BundleConfigResult, ConfigSources, type LoadConfigOptions, type LoadConfigResult, bundleConfig, diffConfig, findConfig, loadConfig };
|
|
84
|
+
export { type BundleConfigResult, ConfigSources, type HostHooks, type LoadConfigOptions, type LoadConfigResult, bundleConfig, diffConfig, findConfig, loadConfig };
|
package/dist/index.js
CHANGED
|
@@ -14,48 +14,20 @@ import {
|
|
|
14
14
|
import { applyConfigDefaults } from "@pandacss/compiler-shared";
|
|
15
15
|
|
|
16
16
|
// src/bundle.ts
|
|
17
|
+
import { existsSync, realpathSync } from "fs";
|
|
18
|
+
import { mkdir, unlink, writeFile } from "fs/promises";
|
|
19
|
+
import { builtinModules } from "module";
|
|
20
|
+
import { tmpdir } from "os";
|
|
21
|
+
import { dirname, isAbsolute as isAbsolute2, join, normalize, relative } from "path";
|
|
22
|
+
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
23
|
+
import { rolldown } from "rolldown";
|
|
24
|
+
|
|
25
|
+
// src/bundle-plugins.ts
|
|
17
26
|
import { parse } from "acorn";
|
|
18
27
|
import { simple } from "acorn-walk";
|
|
19
28
|
import MagicString from "magic-string";
|
|
20
|
-
import {
|
|
21
|
-
import { builtinModules } from "module";
|
|
22
|
-
import { isAbsolute, normalize, relative } from "path";
|
|
29
|
+
import { isAbsolute } from "path";
|
|
23
30
|
import { pathToFileURL } from "url";
|
|
24
|
-
import { rolldown } from "rolldown";
|
|
25
|
-
var nodeBuiltins = /* @__PURE__ */ new Set([...builtinModules, ...builtinModules.map((mod) => `node:${mod}`)]);
|
|
26
|
-
async function bundleConfig(filepath, cwd) {
|
|
27
|
-
const build = await rolldown({
|
|
28
|
-
input: filepath,
|
|
29
|
-
cwd,
|
|
30
|
-
platform: "node",
|
|
31
|
-
external: (id) => nodeBuiltins.has(id),
|
|
32
|
-
treeshake: false,
|
|
33
|
-
plugins: [importMetaUrlPlugin()]
|
|
34
|
-
});
|
|
35
|
-
let chunks;
|
|
36
|
-
try {
|
|
37
|
-
chunks = await build.generate({ format: "esm", exports: "named", codeSplitting: false });
|
|
38
|
-
} finally {
|
|
39
|
-
await build.close?.();
|
|
40
|
-
}
|
|
41
|
-
const output = chunks.output.find((item) => item.type === "chunk");
|
|
42
|
-
if (!output || output.type !== "chunk") {
|
|
43
|
-
throw new PandaError("CONFIG_ERROR", "\u{1F4A5} Config bundle did not produce an executable module.");
|
|
44
|
-
}
|
|
45
|
-
const dependencies = collectDependencies(chunks.output, filepath, cwd);
|
|
46
|
-
const mod = await importBundledConfig(output.code);
|
|
47
|
-
const hasDefaultExport = Object.prototype.hasOwnProperty.call(mod ?? {}, "default");
|
|
48
|
-
const exported = hasDefaultExport ? mod.default : mod;
|
|
49
|
-
const config = hasDefaultExport && isPromiseLike(exported) ? await exported : exported;
|
|
50
|
-
return { config, dependencies };
|
|
51
|
-
}
|
|
52
|
-
async function importBundledConfig(code) {
|
|
53
|
-
const dataUrl = `data:text/javascript;base64,${Buffer.from(code).toString("base64")}`;
|
|
54
|
-
return import(
|
|
55
|
-
/* @vite-ignore */
|
|
56
|
-
dataUrl
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
31
|
function importMetaUrlPlugin() {
|
|
60
32
|
return {
|
|
61
33
|
name: "panda-import-meta-url",
|
|
@@ -95,6 +67,75 @@ function isIdentifier(value, name) {
|
|
|
95
67
|
function isNode(value, type) {
|
|
96
68
|
return !!value && typeof value === "object" && value.type === type;
|
|
97
69
|
}
|
|
70
|
+
|
|
71
|
+
// src/bundle.ts
|
|
72
|
+
var nodeBuiltins = /* @__PURE__ */ new Set([...builtinModules, ...builtinModules.map((mod) => `node:${mod}`)]);
|
|
73
|
+
async function bundleConfig(filepath, cwd) {
|
|
74
|
+
const build = await rolldown({
|
|
75
|
+
input: filepath,
|
|
76
|
+
cwd,
|
|
77
|
+
platform: "node",
|
|
78
|
+
external: (id) => nodeBuiltins.has(id),
|
|
79
|
+
treeshake: false,
|
|
80
|
+
plugins: [importMetaUrlPlugin()]
|
|
81
|
+
});
|
|
82
|
+
let chunks;
|
|
83
|
+
try {
|
|
84
|
+
chunks = await build.generate({ format: "esm", exports: "named", codeSplitting: false });
|
|
85
|
+
} finally {
|
|
86
|
+
await build.close?.();
|
|
87
|
+
}
|
|
88
|
+
const output = chunks.output.find((item) => item.type === "chunk");
|
|
89
|
+
if (!output || output.type !== "chunk") {
|
|
90
|
+
throw new PandaError("CONFIG_ERROR", "\u{1F4A5} Config bundle did not produce an executable module.");
|
|
91
|
+
}
|
|
92
|
+
const dependencies = collectDependencies(chunks.output, filepath, cwd);
|
|
93
|
+
const mod = await loadBundledModule(filepath, output.code);
|
|
94
|
+
const hasDefaultExport = Object.prototype.hasOwnProperty.call(mod ?? {}, "default");
|
|
95
|
+
const exported = hasDefaultExport ? mod.default : mod;
|
|
96
|
+
const config = hasDefaultExport && isPromiseLike(exported) ? await exported : exported;
|
|
97
|
+
return { config, dependencies };
|
|
98
|
+
}
|
|
99
|
+
async function loadBundledModule(filepath, code) {
|
|
100
|
+
const target = tempTargetFor(filepath);
|
|
101
|
+
if (target) {
|
|
102
|
+
try {
|
|
103
|
+
await mkdir(dirname(target), { recursive: true });
|
|
104
|
+
await writeFile(target, code);
|
|
105
|
+
try {
|
|
106
|
+
return await import(
|
|
107
|
+
/* @vite-ignore */
|
|
108
|
+
pathToFileURL2(target).href
|
|
109
|
+
);
|
|
110
|
+
} finally {
|
|
111
|
+
void unlink(target).catch(() => void 0);
|
|
112
|
+
}
|
|
113
|
+
} catch {
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const dataUrl = `data:text/javascript;base64,${Buffer.from(code).toString("base64")}`;
|
|
117
|
+
return await import(
|
|
118
|
+
/* @vite-ignore */
|
|
119
|
+
dataUrl
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
function tempTargetFor(filepath) {
|
|
123
|
+
const unique = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
124
|
+
const name = `panda.config.bundled.${unique}.mjs`;
|
|
125
|
+
const nodeModules = nearestNodeModules(dirname(filepath));
|
|
126
|
+
const base = nodeModules ? join(nodeModules, ".panda") : join(tmpdir(), "panda-config");
|
|
127
|
+
return join(base, name);
|
|
128
|
+
}
|
|
129
|
+
function nearestNodeModules(start) {
|
|
130
|
+
let current = start;
|
|
131
|
+
while (true) {
|
|
132
|
+
const candidate = join(current, "node_modules");
|
|
133
|
+
if (existsSync(candidate)) return candidate;
|
|
134
|
+
const parent = dirname(current);
|
|
135
|
+
if (parent === current) return void 0;
|
|
136
|
+
current = parent;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
98
139
|
function isPromiseLike(value) {
|
|
99
140
|
return value != null && typeof value === "object" && typeof value.then === "function";
|
|
100
141
|
}
|
|
@@ -105,10 +146,10 @@ function collectDependencies(output, entry, cwd) {
|
|
|
105
146
|
for (const item of output) {
|
|
106
147
|
if (item.type !== "chunk") continue;
|
|
107
148
|
Object.keys(item.modules ?? {}).forEach((id) => {
|
|
108
|
-
if (
|
|
149
|
+
if (isAbsolute2(id)) add(id);
|
|
109
150
|
});
|
|
110
151
|
}
|
|
111
|
-
if (
|
|
152
|
+
if (isAbsolute2(entry)) add(entry);
|
|
112
153
|
return Array.from(dependencies);
|
|
113
154
|
}
|
|
114
155
|
function canonical(filepath) {
|
|
@@ -121,7 +162,7 @@ function canonical(filepath) {
|
|
|
121
162
|
|
|
122
163
|
// src/find.ts
|
|
123
164
|
import { readdirSync } from "fs";
|
|
124
|
-
import { dirname, resolve } from "path";
|
|
165
|
+
import { dirname as dirname2, resolve } from "path";
|
|
125
166
|
var configFiles = /* @__PURE__ */ new Set([
|
|
126
167
|
"panda.config.ts",
|
|
127
168
|
"panda.config.js",
|
|
@@ -142,7 +183,7 @@ function findUp(cwd) {
|
|
|
142
183
|
}
|
|
143
184
|
const match = entries.find(isPandaConfig);
|
|
144
185
|
if (match) return resolve(dir, match);
|
|
145
|
-
const parent =
|
|
186
|
+
const parent = dirname2(dir);
|
|
146
187
|
if (parent === dir) return void 0;
|
|
147
188
|
dir = parent;
|
|
148
189
|
}
|
|
@@ -162,6 +203,111 @@ function findConfig(options) {
|
|
|
162
203
|
return configPath;
|
|
163
204
|
}
|
|
164
205
|
|
|
206
|
+
// src/hook-utils.ts
|
|
207
|
+
var configResolvedUtils = {
|
|
208
|
+
omit(obj, paths) {
|
|
209
|
+
const clone = cloneValue(obj);
|
|
210
|
+
for (const path of paths) {
|
|
211
|
+
deleteAtPath(clone, path);
|
|
212
|
+
}
|
|
213
|
+
return clone;
|
|
214
|
+
},
|
|
215
|
+
pick(obj, paths) {
|
|
216
|
+
const result = {};
|
|
217
|
+
for (const path of paths) {
|
|
218
|
+
const value = getAtPath(obj, path);
|
|
219
|
+
if (value !== void 0) {
|
|
220
|
+
setAtPath(result, path, value);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
},
|
|
225
|
+
traverse(obj, callback, options = {}) {
|
|
226
|
+
traverseValue(obj, callback, options);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
function cloneValue(value) {
|
|
230
|
+
if (Array.isArray(value)) {
|
|
231
|
+
const len = value.length;
|
|
232
|
+
const out2 = new Array(len);
|
|
233
|
+
for (let i = 0; i < len; i++) out2[i] = cloneValue(value[i]);
|
|
234
|
+
return out2;
|
|
235
|
+
}
|
|
236
|
+
if (!isPlainObject(value)) return value;
|
|
237
|
+
const source = value;
|
|
238
|
+
const out = {};
|
|
239
|
+
const keys = Object.keys(source);
|
|
240
|
+
for (let i = 0; i < keys.length; i++) {
|
|
241
|
+
const key = keys[i];
|
|
242
|
+
out[key] = cloneValue(source[key]);
|
|
243
|
+
}
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
function pathParts(path) {
|
|
247
|
+
return path.split(".").filter(Boolean);
|
|
248
|
+
}
|
|
249
|
+
function getAtPath(value, path) {
|
|
250
|
+
let current = value;
|
|
251
|
+
for (const part of pathParts(path)) {
|
|
252
|
+
if (!isPlainObject(current) && !Array.isArray(current)) return void 0;
|
|
253
|
+
current = current[part];
|
|
254
|
+
}
|
|
255
|
+
return current;
|
|
256
|
+
}
|
|
257
|
+
function setAtPath(target, path, value) {
|
|
258
|
+
const parts = pathParts(path);
|
|
259
|
+
let current = target;
|
|
260
|
+
parts.forEach((part, index) => {
|
|
261
|
+
if (index === parts.length - 1) {
|
|
262
|
+
current[part] = cloneValue(value);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const next = current[part];
|
|
266
|
+
if (!isPlainObject(next)) {
|
|
267
|
+
current[part] = {};
|
|
268
|
+
}
|
|
269
|
+
current = current[part];
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
function deleteAtPath(target, path) {
|
|
273
|
+
const parts = pathParts(path);
|
|
274
|
+
const key = parts.pop();
|
|
275
|
+
if (!key) return;
|
|
276
|
+
let current = target;
|
|
277
|
+
for (const part of parts) {
|
|
278
|
+
if (!isPlainObject(current) && !Array.isArray(current)) return;
|
|
279
|
+
current = current[part];
|
|
280
|
+
}
|
|
281
|
+
if (isPlainObject(current) || Array.isArray(current)) {
|
|
282
|
+
delete current[key];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function traverseValue(value, callback, options, parent, key, path = "", depth = 0) {
|
|
286
|
+
if (parent && key !== void 0) {
|
|
287
|
+
callback({ value, path, depth, parent, key });
|
|
288
|
+
}
|
|
289
|
+
if (options.maxDepth !== void 0 && depth >= options.maxDepth) return;
|
|
290
|
+
if (!isPlainObject(value) && !Array.isArray(value)) return;
|
|
291
|
+
const separator = options.separator ?? ".";
|
|
292
|
+
const container = value;
|
|
293
|
+
const keys = Object.keys(container);
|
|
294
|
+
for (let i = 0; i < keys.length; i++) {
|
|
295
|
+
const childKey = keys[i];
|
|
296
|
+
traverseValue(
|
|
297
|
+
container[childKey],
|
|
298
|
+
callback,
|
|
299
|
+
options,
|
|
300
|
+
container,
|
|
301
|
+
childKey,
|
|
302
|
+
joinPath(path, childKey, separator),
|
|
303
|
+
depth + 1
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function joinPath(parent, key, separator) {
|
|
308
|
+
return parent ? `${parent}${separator}${key}` : key;
|
|
309
|
+
}
|
|
310
|
+
|
|
165
311
|
// src/preset.ts
|
|
166
312
|
import { normalize as normalize2, relative as relative2 } from "path";
|
|
167
313
|
async function resolveAuthoredPresets(config, cwd, options = {}) {
|
|
@@ -238,7 +384,7 @@ async function runPresetResolvedHooks(preset, source, hooks) {
|
|
|
238
384
|
const name = source.name ?? source.specifier ?? presetName(current) ?? "unknown-preset";
|
|
239
385
|
for (const entry of hooks) {
|
|
240
386
|
const hook = normalizeHook(entry.value, "preset:resolved");
|
|
241
|
-
const next = await hook.handler({ preset: current, name });
|
|
387
|
+
const next = await hook.handler({ preset: current, name, utils: configResolvedUtils });
|
|
242
388
|
if (next !== void 0) {
|
|
243
389
|
current = ensureConfigObject(next, name);
|
|
244
390
|
}
|
|
@@ -342,89 +488,6 @@ async function runConfigResolvedHooks(config, path, dependencies) {
|
|
|
342
488
|
}
|
|
343
489
|
return current;
|
|
344
490
|
}
|
|
345
|
-
var configResolvedUtils = {
|
|
346
|
-
omit(obj, paths) {
|
|
347
|
-
const clone = cloneValue(obj);
|
|
348
|
-
for (const path of paths) {
|
|
349
|
-
deleteAtPath(clone, path);
|
|
350
|
-
}
|
|
351
|
-
return clone;
|
|
352
|
-
},
|
|
353
|
-
pick(obj, paths) {
|
|
354
|
-
const result = {};
|
|
355
|
-
for (const path of paths) {
|
|
356
|
-
const value = getAtPath(obj, path);
|
|
357
|
-
if (value !== void 0) {
|
|
358
|
-
setAtPath(result, path, value);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
return result;
|
|
362
|
-
},
|
|
363
|
-
traverse(obj, callback, options = {}) {
|
|
364
|
-
traverseValue(obj, callback, options);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
function cloneValue(value) {
|
|
368
|
-
if (Array.isArray(value)) return value.map((item) => cloneValue(item));
|
|
369
|
-
if (!isPlainObject(value)) return value;
|
|
370
|
-
return Object.fromEntries(
|
|
371
|
-
Object.entries(value).map(([key, child]) => [key, cloneValue(child)])
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
function pathParts(path) {
|
|
375
|
-
return path.split(".").filter(Boolean);
|
|
376
|
-
}
|
|
377
|
-
function getAtPath(value, path) {
|
|
378
|
-
let current = value;
|
|
379
|
-
for (const part of pathParts(path)) {
|
|
380
|
-
if (!isPlainObject(current) && !Array.isArray(current)) return void 0;
|
|
381
|
-
current = current[part];
|
|
382
|
-
}
|
|
383
|
-
return current;
|
|
384
|
-
}
|
|
385
|
-
function setAtPath(target, path, value) {
|
|
386
|
-
const parts = pathParts(path);
|
|
387
|
-
let current = target;
|
|
388
|
-
parts.forEach((part, index) => {
|
|
389
|
-
if (index === parts.length - 1) {
|
|
390
|
-
current[part] = cloneValue(value);
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
const next = current[part];
|
|
394
|
-
if (!isPlainObject(next)) {
|
|
395
|
-
current[part] = {};
|
|
396
|
-
}
|
|
397
|
-
current = current[part];
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
function deleteAtPath(target, path) {
|
|
401
|
-
const parts = pathParts(path);
|
|
402
|
-
const key = parts.pop();
|
|
403
|
-
if (!key) return;
|
|
404
|
-
let current = target;
|
|
405
|
-
for (const part of parts) {
|
|
406
|
-
if (!isPlainObject(current) && !Array.isArray(current)) return;
|
|
407
|
-
current = current[part];
|
|
408
|
-
}
|
|
409
|
-
if (isPlainObject(current) || Array.isArray(current)) {
|
|
410
|
-
delete current[key];
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
function traverseValue(value, callback, options, parent, key, path = "", depth = 0) {
|
|
414
|
-
if (parent && key !== void 0) {
|
|
415
|
-
callback({ value, path, depth, parent, key });
|
|
416
|
-
}
|
|
417
|
-
if (options.maxDepth !== void 0 && depth >= options.maxDepth) return;
|
|
418
|
-
if (!isPlainObject(value) && !Array.isArray(value)) return;
|
|
419
|
-
const separator = options.separator ?? ".";
|
|
420
|
-
const container = value;
|
|
421
|
-
Object.entries(value).forEach(([childKey, child]) => {
|
|
422
|
-
traverseValue(child, callback, options, container, childKey, joinPath(path, childKey, separator), depth + 1);
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
function joinPath(parent, key, separator) {
|
|
426
|
-
return parent ? `${parent}${separator}${key}` : key;
|
|
427
|
-
}
|
|
428
491
|
|
|
429
492
|
// src/diff.ts
|
|
430
493
|
import diff from "microdiff";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/config",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "Self-contained loader that bundles and serializes a Panda config for the Rust compiler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,8 +45,11 @@
|
|
|
45
45
|
"magic-string": "^0.30.21",
|
|
46
46
|
"microdiff": "1.5.0",
|
|
47
47
|
"rolldown": "1.0.0-rc.17",
|
|
48
|
-
"@pandacss/compiler-shared": "2.0.0-beta.
|
|
49
|
-
"@pandacss/types": "2.0.0-beta.
|
|
48
|
+
"@pandacss/compiler-shared": "2.0.0-beta.2",
|
|
49
|
+
"@pandacss/types": "2.0.0-beta.2"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=22"
|
|
50
53
|
},
|
|
51
54
|
"scripts": {
|
|
52
55
|
"build": "tsup --dts",
|