@pandacss/config 2.1.0 → 2.1.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/import-meta-url-SQ7JCEJ3.js +34 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +296 -128
- package/package.json +3 -3
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/import-meta-url.ts
|
|
2
|
+
import { parse } from "acorn";
|
|
3
|
+
import { simple } from "acorn-walk";
|
|
4
|
+
import MagicString from "magic-string";
|
|
5
|
+
function replaceImportMetaUrl(code, replacement) {
|
|
6
|
+
const ast = parse(code, {
|
|
7
|
+
ecmaVersion: "latest",
|
|
8
|
+
sourceType: "module"
|
|
9
|
+
});
|
|
10
|
+
const output = new MagicString(code);
|
|
11
|
+
let changed = false;
|
|
12
|
+
simple(ast, {
|
|
13
|
+
MemberExpression(node) {
|
|
14
|
+
if (!isImportMetaUrl(node)) return;
|
|
15
|
+
output.overwrite(node.start, node.end, replacement);
|
|
16
|
+
changed = true;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return changed ? output.toString() : code;
|
|
20
|
+
}
|
|
21
|
+
function isImportMetaUrl(node) {
|
|
22
|
+
if (node.computed || !isIdentifier(node.property, "url")) return false;
|
|
23
|
+
const object = node.object;
|
|
24
|
+
return isNode(object, "MetaProperty") && isIdentifier(object.meta, "import") && isIdentifier(object.property, "meta");
|
|
25
|
+
}
|
|
26
|
+
function isIdentifier(value, name) {
|
|
27
|
+
return isNode(value, "Identifier") && value.name === name;
|
|
28
|
+
}
|
|
29
|
+
function isNode(value, type) {
|
|
30
|
+
return !!value && typeof value === "object" && value.type === type;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
replaceImportMetaUrl
|
|
34
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ interface DesignSystemArtifactConflict {
|
|
|
53
53
|
patterns: string[];
|
|
54
54
|
}
|
|
55
55
|
declare function collectArtifactConflicts(metadata: DesignSystemMetadata | undefined): DesignSystemArtifactConflict[];
|
|
56
|
-
declare function collectExportMissingDiagnostics(metadata: DesignSystemMetadata | undefined): Diagnostic[];
|
|
56
|
+
declare function collectExportMissingDiagnostics(metadata: DesignSystemMetadata | undefined, jsxFramework?: string): Diagnostic[];
|
|
57
57
|
declare function collectNameCollisionDiagnostics(metadata: DesignSystemMetadata | undefined): Diagnostic[];
|
|
58
58
|
|
|
59
59
|
interface LoadConfigOptions {
|
package/dist/index.js
CHANGED
|
@@ -21,24 +21,23 @@ import {
|
|
|
21
21
|
import { applyConfigDefaults as applyConfigDefaults2 } from "@pandacss/compiler-shared";
|
|
22
22
|
|
|
23
23
|
// src/bundle.ts
|
|
24
|
-
import { existsSync, realpathSync } from "node:fs";
|
|
24
|
+
import { existsSync as existsSync3, realpathSync, statSync as statSync2 } from "node:fs";
|
|
25
25
|
import { mkdir, unlink, writeFile } from "node:fs/promises";
|
|
26
26
|
import { builtinModules } from "node:module";
|
|
27
27
|
import { tmpdir } from "node:os";
|
|
28
|
-
import { basename, dirname, isAbsolute as isAbsolute2, join, normalize, relative } from "node:path";
|
|
29
|
-
import { pathToFileURL as
|
|
28
|
+
import { basename, dirname as dirname3, extname as extname2, isAbsolute as isAbsolute2, join as join3, normalize, relative, sep as sep2 } from "node:path";
|
|
29
|
+
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
30
|
+
import { debuglog } from "node:util";
|
|
30
31
|
|
|
31
32
|
// src/bundle-plugins.ts
|
|
32
|
-
import { parse } from "acorn";
|
|
33
|
-
import { simple } from "acorn-walk";
|
|
34
|
-
import MagicString from "magic-string";
|
|
35
33
|
import { isAbsolute } from "node:path";
|
|
36
34
|
import { pathToFileURL } from "node:url";
|
|
37
35
|
function importMetaUrlPlugin() {
|
|
38
36
|
return {
|
|
39
37
|
name: "panda-import-meta-url",
|
|
40
|
-
transform(code, id) {
|
|
38
|
+
async transform(code, id) {
|
|
41
39
|
if (!isAbsolute(id) || !code.includes("import.meta.url")) return;
|
|
40
|
+
const { replaceImportMetaUrl } = await import("./import-meta-url-SQ7JCEJ3.js");
|
|
42
41
|
const replacement = JSON.stringify(pathToFileURL(id).href);
|
|
43
42
|
const patched = replaceImportMetaUrl(code, replacement);
|
|
44
43
|
if (patched === code) return;
|
|
@@ -46,37 +45,193 @@ function importMetaUrlPlugin() {
|
|
|
46
45
|
}
|
|
47
46
|
};
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
|
|
49
|
+
// src/resolve.ts
|
|
50
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
51
|
+
import { createRequire } from "node:module";
|
|
52
|
+
import { dirname, join, resolve } from "node:path";
|
|
53
|
+
function tryResolveFrom(request, fromDir) {
|
|
54
|
+
try {
|
|
55
|
+
return createRequire(resolve(fromDir, "noop.js")).resolve(request, { paths: [fromDir] });
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (isResolveMiss(error)) return void 0;
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function isResolveMiss(error) {
|
|
62
|
+
const code = errorCode(error);
|
|
63
|
+
return code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED";
|
|
64
|
+
}
|
|
65
|
+
function resolveFrom(request, fromDir) {
|
|
66
|
+
try {
|
|
67
|
+
return { kind: "resolved", path: createRequire(resolve(fromDir, "noop.js")).resolve(request, { paths: [fromDir] }) };
|
|
68
|
+
} catch (error) {
|
|
69
|
+
const code = errorCode(error);
|
|
70
|
+
if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") return { kind: "not-exported" };
|
|
71
|
+
if (code === "MODULE_NOT_FOUND") return { kind: "not-installed" };
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function errorCode(error) {
|
|
76
|
+
return typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
77
|
+
}
|
|
78
|
+
function nearestPackageType(start) {
|
|
79
|
+
let current = start;
|
|
80
|
+
while (true) {
|
|
81
|
+
const candidate = join(current, "package.json");
|
|
82
|
+
if (existsSync(candidate)) return JSON.parse(readFileSync(candidate, "utf8")).type;
|
|
83
|
+
const parent = dirname(current);
|
|
84
|
+
if (parent === current) return void 0;
|
|
85
|
+
current = parent;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/transpile-loader.ts
|
|
90
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, statSync } from "node:fs";
|
|
91
|
+
import * as nodeModule from "node:module";
|
|
92
|
+
import { dirname as dirname2, extname, join as join2, sep } from "node:path";
|
|
93
|
+
import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "node:url";
|
|
94
|
+
var SESSION_PARAM = "panda-config";
|
|
95
|
+
var TYPESCRIPT_EXTENSION = /\.[cm]?tsx?$/;
|
|
96
|
+
var RESOLVE_EXTENSIONS = [".ts", ".tsx", ".mts", ".js", ".mjs"];
|
|
97
|
+
var TranspileError = class extends Error {
|
|
98
|
+
name = "TranspileError";
|
|
99
|
+
};
|
|
100
|
+
var MODULE_LOAD_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
101
|
+
"ERR_IMPORT_ATTRIBUTE_MISSING",
|
|
102
|
+
"ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE",
|
|
103
|
+
"ERR_IMPORT_ATTRIBUTE_UNSUPPORTED",
|
|
104
|
+
"ERR_INVALID_MODULE_SPECIFIER",
|
|
105
|
+
"ERR_INVALID_PACKAGE_CONFIG",
|
|
106
|
+
"ERR_INVALID_PACKAGE_TARGET",
|
|
107
|
+
"ERR_MODULE_NOT_FOUND",
|
|
108
|
+
"ERR_PACKAGE_IMPORT_NOT_DEFINED",
|
|
109
|
+
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
|
110
|
+
"ERR_REQUIRE_ASYNC_MODULE",
|
|
111
|
+
"ERR_REQUIRE_CYCLE_MODULE",
|
|
112
|
+
"ERR_REQUIRE_ESM",
|
|
113
|
+
"ERR_UNKNOWN_FILE_EXTENSION",
|
|
114
|
+
"ERR_UNKNOWN_MODULE_FORMAT",
|
|
115
|
+
"ERR_UNSUPPORTED_DIR_IMPORT",
|
|
116
|
+
"ERR_UNSUPPORTED_ESM_URL_SCHEME",
|
|
117
|
+
"MODULE_NOT_FOUND"
|
|
118
|
+
]);
|
|
119
|
+
var COMMONJS_GLOBAL_MISSING = /^(require|module|exports|__dirname|__filename) is not defined\b/;
|
|
120
|
+
function isLoaderFailure(error) {
|
|
121
|
+
if (error instanceof TranspileError) return true;
|
|
122
|
+
const code = error?.code;
|
|
123
|
+
if (typeof code === "string" && MODULE_LOAD_ERROR_CODES.has(code)) return true;
|
|
124
|
+
if (error instanceof SyntaxError) return true;
|
|
125
|
+
return error instanceof ReferenceError && COMMONJS_GLOBAL_MISSING.test(error.message);
|
|
126
|
+
}
|
|
127
|
+
var sessions = /* @__PURE__ */ new Map();
|
|
128
|
+
var commonjsFiles = /* @__PURE__ */ new Set();
|
|
129
|
+
var requireCache = nodeModule.createRequire(import.meta.url).cache;
|
|
130
|
+
var hooksRegistered;
|
|
131
|
+
var nextSession = 0;
|
|
132
|
+
function canTranspile(file) {
|
|
133
|
+
return typeof nodeModule.registerHooks === "function" && !/\.c[jt]s$/.test(file);
|
|
134
|
+
}
|
|
135
|
+
async function importTranspiled(file, evaluate) {
|
|
136
|
+
hooksRegistered ??= registerTranspileHooks();
|
|
137
|
+
await hooksRegistered.catch((cause) => {
|
|
138
|
+
throw new TranspileError("Could not register the transpile hooks.", { cause });
|
|
53
139
|
});
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
140
|
+
for (const commonjsFile of commonjsFiles) delete requireCache[commonjsFile];
|
|
141
|
+
const id = String(++nextSession);
|
|
142
|
+
const session = { files: /* @__PURE__ */ new Set([file]), loaded: false };
|
|
143
|
+
sessions.set(id, session);
|
|
144
|
+
try {
|
|
145
|
+
const mod = await import(
|
|
146
|
+
/* @vite-ignore */
|
|
147
|
+
withSession(pathToFileURL2(file).href, id)
|
|
148
|
+
);
|
|
149
|
+
if (!session.loaded) throw new TranspileError("Config was not loaded through the Panda transpile hooks.");
|
|
150
|
+
return { value: await evaluate(mod), files: Array.from(session.files) };
|
|
151
|
+
} finally {
|
|
152
|
+
sessions.delete(id);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async function registerTranspileHooks() {
|
|
156
|
+
const { transformSync } = await import("rolldown/utils");
|
|
157
|
+
nodeModule.registerHooks({
|
|
158
|
+
resolve(specifier, context, nextResolve) {
|
|
159
|
+
const id = sessionId(context.parentURL);
|
|
160
|
+
if (!id || !context.parentURL) return nextResolve(specifier, context);
|
|
161
|
+
const tag = (file) => {
|
|
162
|
+
sessions.get(id)?.files.add(file);
|
|
163
|
+
return { url: withSession(pathToFileURL2(file).href, id), shortCircuit: true };
|
|
164
|
+
};
|
|
165
|
+
if (isRelative(specifier)) {
|
|
166
|
+
const file = resolveRelative(specifier, context.parentURL);
|
|
167
|
+
return file ? tag(file) : nextResolve(specifier, context);
|
|
168
|
+
}
|
|
169
|
+
const resolved = nextResolve(specifier, context);
|
|
170
|
+
const linked = linkedPackageFile(resolved.url);
|
|
171
|
+
if (linked) return tag(linked);
|
|
172
|
+
if (isCommonJs(resolved)) {
|
|
173
|
+
throw new TranspileError(`${specifier} is CommonJS, so the bundler loads this config.`);
|
|
174
|
+
}
|
|
175
|
+
return resolved;
|
|
176
|
+
},
|
|
177
|
+
load(url, context, nextLoad) {
|
|
178
|
+
const id = sessionId(url);
|
|
179
|
+
if (!id) return nextLoad(url, context);
|
|
180
|
+
const session = sessions.get(id);
|
|
181
|
+
if (session) session.loaded = true;
|
|
182
|
+
const file = fileURLToPath(url);
|
|
183
|
+
if (!TYPESCRIPT_EXTENSION.test(file)) {
|
|
184
|
+
const loaded = nextLoad(url, context);
|
|
185
|
+
if (loaded.format === "commonjs") commonjsFiles.add(file);
|
|
186
|
+
return loaded;
|
|
187
|
+
}
|
|
188
|
+
const result = transformSync(file, readFileSync2(file, "utf8"));
|
|
189
|
+
if (result.errors.length > 0) {
|
|
190
|
+
throw new TranspileError(`Could not transpile ${file}.`, { cause: result.errors[0] });
|
|
191
|
+
}
|
|
192
|
+
return { format: "module", source: result.code, shortCircuit: true };
|
|
61
193
|
}
|
|
62
194
|
});
|
|
63
|
-
return changed ? output.toString() : code;
|
|
64
195
|
}
|
|
65
|
-
function
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
196
|
+
function isCommonJs(resolved) {
|
|
197
|
+
if (resolved.format) return resolved.format === "commonjs";
|
|
198
|
+
if (!resolved.url.startsWith("file:")) return false;
|
|
199
|
+
const file = fileURLToPath(resolved.url);
|
|
200
|
+
if (file.endsWith(".cjs")) return true;
|
|
201
|
+
return file.endsWith(".js") && nearestPackageType(dirname2(file)) !== "module";
|
|
202
|
+
}
|
|
203
|
+
function sessionId(url) {
|
|
204
|
+
if (!url?.startsWith("file:") || !url.includes(`${SESSION_PARAM}=`)) return void 0;
|
|
205
|
+
return new URL(url).searchParams.get(SESSION_PARAM) ?? void 0;
|
|
206
|
+
}
|
|
207
|
+
function withSession(url, id) {
|
|
208
|
+
return `${url}?${SESSION_PARAM}=${id}`;
|
|
209
|
+
}
|
|
210
|
+
function isRelative(specifier) {
|
|
211
|
+
return specifier.startsWith("./") || specifier.startsWith("../");
|
|
212
|
+
}
|
|
213
|
+
function linkedPackageFile(url) {
|
|
214
|
+
if (!url.startsWith("file:")) return void 0;
|
|
215
|
+
const file = fileURLToPath(url);
|
|
216
|
+
return file.includes(`${sep}node_modules${sep}`) ? void 0 : file;
|
|
217
|
+
}
|
|
218
|
+
function resolveRelative(specifier, parentURL) {
|
|
219
|
+
const base = fileURLToPath(new URL(specifier, parentURL));
|
|
220
|
+
const candidates = [
|
|
221
|
+
base,
|
|
222
|
+
...RESOLVE_EXTENSIONS.map((extension) => base + extension),
|
|
223
|
+
...extname(base) === ".js" ? [base.slice(0, -3) + ".ts"] : [],
|
|
224
|
+
...RESOLVE_EXTENSIONS.map((extension) => join2(base, `index${extension}`))
|
|
225
|
+
];
|
|
226
|
+
return candidates.find((candidate) => existsSync2(candidate) && statSync(candidate).isFile());
|
|
75
227
|
}
|
|
76
228
|
|
|
77
229
|
// src/bundle.ts
|
|
230
|
+
var debug = debuglog("panda");
|
|
78
231
|
var nodeBuiltins = /* @__PURE__ */ new Set([...builtinModules, ...builtinModules.map((mod) => `node:${mod}`)]);
|
|
79
232
|
async function bundleConfig(filepath, cwd) {
|
|
233
|
+
const transpiled = await loadTranspiled(filepath, cwd);
|
|
234
|
+
if (transpiled) return transpiled;
|
|
80
235
|
const { rolldown } = await import("rolldown");
|
|
81
236
|
const build = await rolldown({
|
|
82
237
|
input: filepath,
|
|
@@ -98,38 +253,77 @@ async function bundleConfig(filepath, cwd) {
|
|
|
98
253
|
}
|
|
99
254
|
const dependencies = collectDependencies(chunks.output, filepath, cwd);
|
|
100
255
|
const mod = await loadBundledModule(filepath, output.code);
|
|
256
|
+
return { config: await configFromModule(mod), dependencies };
|
|
257
|
+
}
|
|
258
|
+
async function loadTranspiled(filepath, cwd) {
|
|
259
|
+
const file = localFile(filepath, cwd);
|
|
260
|
+
if (!file || !existsSync3(file) || !canTranspile(file)) return void 0;
|
|
261
|
+
try {
|
|
262
|
+
const { value, files } = await importTranspiled(file, configFromModule);
|
|
263
|
+
const base = canonical(cwd);
|
|
264
|
+
const dependencies = new Set(files.map((dependency) => normalize(relative(base, canonical(dependency)))));
|
|
265
|
+
return { config: value, dependencies: Array.from(dependencies) };
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if (!isLoaderFailure(error)) throw error;
|
|
268
|
+
debug("loading %s with the bundler: %s", relative(cwd, file) || file, errorMessage(error));
|
|
269
|
+
return void 0;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function localFile(filepath, cwd) {
|
|
273
|
+
if (isAbsolute2(filepath)) return filepath;
|
|
274
|
+
if (filepath.startsWith(".")) return join3(cwd, filepath);
|
|
275
|
+
return void 0;
|
|
276
|
+
}
|
|
277
|
+
async function importInstalledConfig(specifier, cwd) {
|
|
278
|
+
if (specifier.startsWith(".") || isAbsolute2(specifier)) return void 0;
|
|
279
|
+
const resolved = tryResolveFrom(specifier, cwd);
|
|
280
|
+
if (!resolved) return void 0;
|
|
281
|
+
const file = canonical(resolved);
|
|
282
|
+
if (!file.includes(`${sep2}node_modules${sep2}`) || !isEsmFile(file)) return void 0;
|
|
283
|
+
const mod = await import(
|
|
284
|
+
/* @vite-ignore */
|
|
285
|
+
`${pathToFileURL3(file).href}?mtime=${statSync2(file).mtimeMs}`
|
|
286
|
+
);
|
|
287
|
+
return { config: await configFromModule(mod), dependencies: [normalize(relative(canonical(cwd), file))] };
|
|
288
|
+
}
|
|
289
|
+
async function configFromModule(mod) {
|
|
101
290
|
const hasDefaultExport = Object.prototype.hasOwnProperty.call(mod ?? {}, "default");
|
|
102
291
|
const exported = hasDefaultExport ? mod.default : mod;
|
|
103
|
-
|
|
104
|
-
|
|
292
|
+
return hasDefaultExport && isPromiseLike(exported) ? await exported : exported;
|
|
293
|
+
}
|
|
294
|
+
function isEsmFile(file) {
|
|
295
|
+
const extension = extname2(file);
|
|
296
|
+
if (extension === ".mjs") return true;
|
|
297
|
+
if (extension !== ".js") return false;
|
|
298
|
+
return nearestPackageType(dirname3(file)) === "module";
|
|
105
299
|
}
|
|
106
300
|
async function loadBundledModule(filepath, code) {
|
|
107
301
|
const target = tempTargetFor(filepath);
|
|
108
|
-
|
|
109
|
-
if (target) {
|
|
302
|
+
if (target && await writeTempModule(target, code)) {
|
|
110
303
|
try {
|
|
111
|
-
await
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
/* @vite-ignore */
|
|
116
|
-
pathToFileURL2(target).href
|
|
117
|
-
);
|
|
118
|
-
} finally {
|
|
119
|
-
void unlink(target).catch(() => void 0);
|
|
120
|
-
}
|
|
304
|
+
return await import(
|
|
305
|
+
/* @vite-ignore */
|
|
306
|
+
pathToFileURL3(target).href
|
|
307
|
+
);
|
|
121
308
|
} catch (error) {
|
|
122
|
-
if (!isUnresolvedTempModule(error, target))
|
|
309
|
+
if (!isUnresolvedTempModule(error, target)) throw error;
|
|
310
|
+
} finally {
|
|
311
|
+
void unlink(target).catch(() => void 0);
|
|
123
312
|
}
|
|
124
313
|
}
|
|
125
314
|
const dataUrl = `data:text/javascript;base64,${Buffer.from(code).toString("base64")}`;
|
|
315
|
+
return await import(
|
|
316
|
+
/* @vite-ignore */
|
|
317
|
+
dataUrl
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
async function writeTempModule(target, code) {
|
|
126
321
|
try {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
throw evalError ?? error;
|
|
322
|
+
await mkdir(dirname3(target), { recursive: true });
|
|
323
|
+
await writeFile(target, code);
|
|
324
|
+
return true;
|
|
325
|
+
} catch {
|
|
326
|
+
return false;
|
|
133
327
|
}
|
|
134
328
|
}
|
|
135
329
|
function isUnresolvedTempModule(error, target) {
|
|
@@ -139,16 +333,16 @@ function isUnresolvedTempModule(error, target) {
|
|
|
139
333
|
function tempTargetFor(filepath) {
|
|
140
334
|
const unique = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
141
335
|
const name = `panda.config.bundled.${unique}.mjs`;
|
|
142
|
-
const nodeModules = nearestNodeModules(
|
|
143
|
-
const base = nodeModules ?
|
|
144
|
-
return
|
|
336
|
+
const nodeModules = nearestNodeModules(dirname3(filepath));
|
|
337
|
+
const base = nodeModules ? join3(nodeModules, ".panda") : join3(tmpdir(), "panda-config");
|
|
338
|
+
return join3(base, name);
|
|
145
339
|
}
|
|
146
340
|
function nearestNodeModules(start) {
|
|
147
341
|
let current = start;
|
|
148
342
|
while (true) {
|
|
149
|
-
const candidate =
|
|
150
|
-
if (
|
|
151
|
-
const parent =
|
|
343
|
+
const candidate = join3(current, "node_modules");
|
|
344
|
+
if (existsSync3(candidate)) return candidate;
|
|
345
|
+
const parent = dirname3(current);
|
|
152
346
|
if (parent === current) return void 0;
|
|
153
347
|
current = parent;
|
|
154
348
|
}
|
|
@@ -179,7 +373,7 @@ function canonical(filepath) {
|
|
|
179
373
|
|
|
180
374
|
// src/find.ts
|
|
181
375
|
import { readdirSync } from "node:fs";
|
|
182
|
-
import { dirname as
|
|
376
|
+
import { dirname as dirname4, resolve as resolve2 } from "node:path";
|
|
183
377
|
var configFiles = /* @__PURE__ */ new Set([
|
|
184
378
|
"panda.config.ts",
|
|
185
379
|
"panda.config.js",
|
|
@@ -190,7 +384,7 @@ var configFiles = /* @__PURE__ */ new Set([
|
|
|
190
384
|
]);
|
|
191
385
|
var isPandaConfig = (file) => configFiles.has(file);
|
|
192
386
|
function findUp(cwd) {
|
|
193
|
-
let dir =
|
|
387
|
+
let dir = resolve2(cwd);
|
|
194
388
|
while (true) {
|
|
195
389
|
let entries;
|
|
196
390
|
try {
|
|
@@ -199,8 +393,8 @@ function findUp(cwd) {
|
|
|
199
393
|
entries = [];
|
|
200
394
|
}
|
|
201
395
|
const match = entries.find(isPandaConfig);
|
|
202
|
-
if (match) return
|
|
203
|
-
const parent =
|
|
396
|
+
if (match) return resolve2(dir, match);
|
|
397
|
+
const parent = dirname4(dir);
|
|
204
398
|
if (parent === dir) return void 0;
|
|
205
399
|
dir = parent;
|
|
206
400
|
}
|
|
@@ -208,7 +402,7 @@ function findUp(cwd) {
|
|
|
208
402
|
function findConfig(options) {
|
|
209
403
|
const { cwd, file } = options;
|
|
210
404
|
if (file) {
|
|
211
|
-
return
|
|
405
|
+
return resolve2(cwd, file);
|
|
212
406
|
}
|
|
213
407
|
const configPath = findUp(cwd);
|
|
214
408
|
if (!configPath) {
|
|
@@ -441,42 +635,13 @@ import { normalize as normalize2, relative as relative5 } from "node:path";
|
|
|
441
635
|
import {
|
|
442
636
|
outdirBasename
|
|
443
637
|
} from "@pandacss/compiler-shared";
|
|
444
|
-
import { readFileSync as
|
|
445
|
-
import { dirname as
|
|
446
|
-
import { pathToFileURL as
|
|
447
|
-
|
|
448
|
-
// src/resolve.ts
|
|
449
|
-
import { createRequire } from "node:module";
|
|
450
|
-
import { resolve as resolve2 } from "node:path";
|
|
451
|
-
function tryResolveFrom(request, fromDir) {
|
|
452
|
-
try {
|
|
453
|
-
return createRequire(resolve2(fromDir, "noop.js")).resolve(request, { paths: [fromDir] });
|
|
454
|
-
} catch (error) {
|
|
455
|
-
if (isResolveMiss(error)) return void 0;
|
|
456
|
-
throw error;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
function isResolveMiss(error) {
|
|
460
|
-
const code = errorCode(error);
|
|
461
|
-
return code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED";
|
|
462
|
-
}
|
|
463
|
-
function resolveFrom(request, fromDir) {
|
|
464
|
-
try {
|
|
465
|
-
return { kind: "resolved", path: createRequire(resolve2(fromDir, "noop.js")).resolve(request, { paths: [fromDir] }) };
|
|
466
|
-
} catch (error) {
|
|
467
|
-
const code = errorCode(error);
|
|
468
|
-
if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") return { kind: "not-exported" };
|
|
469
|
-
if (code === "MODULE_NOT_FOUND") return { kind: "not-installed" };
|
|
470
|
-
throw error;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
function errorCode(error) {
|
|
474
|
-
return typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
475
|
-
}
|
|
638
|
+
import { readFileSync as readFileSync4, statSync as statSync3 } from "node:fs";
|
|
639
|
+
import { dirname as dirname6, resolve as resolve4 } from "node:path";
|
|
640
|
+
import { pathToFileURL as pathToFileURL4 } from "node:url";
|
|
476
641
|
|
|
477
642
|
// src/design-system/package.ts
|
|
478
|
-
import { existsSync as
|
|
479
|
-
import { dirname as
|
|
643
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "node:fs";
|
|
644
|
+
import { dirname as dirname5, join as join4 } from "node:path";
|
|
480
645
|
|
|
481
646
|
// src/design-system/publishable-files.ts
|
|
482
647
|
import { relative as relative3, resolve as resolve3 } from "node:path";
|
|
@@ -598,7 +763,7 @@ function readPackageIdentity(cwd) {
|
|
|
598
763
|
if (packagePath === void 0) {
|
|
599
764
|
throw new Error(`Could not find a package.json from ${JSON.stringify(cwd)} to build the design system manifest.`);
|
|
600
765
|
}
|
|
601
|
-
const pkg = JSON.parse(
|
|
766
|
+
const pkg = JSON.parse(readFileSync3(packagePath, "utf8"));
|
|
602
767
|
const name = pkg.name;
|
|
603
768
|
if (typeof name !== "string" || name.length === 0) {
|
|
604
769
|
throw new Error(`${JSON.stringify(packagePath)} has no "name"; a design system must be a named package.`);
|
|
@@ -655,9 +820,9 @@ function isSubpathExportMap(exports) {
|
|
|
655
820
|
function nearestPackageJson(start) {
|
|
656
821
|
let current = start;
|
|
657
822
|
while (true) {
|
|
658
|
-
const candidate =
|
|
659
|
-
if (
|
|
660
|
-
const parent =
|
|
823
|
+
const candidate = join4(current, "package.json");
|
|
824
|
+
if (existsSync4(candidate)) return candidate;
|
|
825
|
+
const parent = dirname5(current);
|
|
661
826
|
if (parent === current) return void 0;
|
|
662
827
|
current = parent;
|
|
663
828
|
}
|
|
@@ -692,7 +857,7 @@ async function loadDesignSystemChain(spec, cwd, deps) {
|
|
|
692
857
|
levels.push(level);
|
|
693
858
|
if (parent === void 0) break;
|
|
694
859
|
declaredBy = level.info.name;
|
|
695
|
-
fromDir =
|
|
860
|
+
fromDir = dirname6(manifestPath);
|
|
696
861
|
currentSpec = parent;
|
|
697
862
|
}
|
|
698
863
|
return levels.reverse();
|
|
@@ -730,7 +895,7 @@ function collectArtifactConflicts(metadata) {
|
|
|
730
895
|
patterns: ds.patternNames.filter((name) => appPatterns.has(name))
|
|
731
896
|
})).filter((entry) => entry.recipes.length > 0 || entry.patterns.length > 0);
|
|
732
897
|
}
|
|
733
|
-
function collectExportMissingDiagnostics(metadata) {
|
|
898
|
+
function collectExportMissingDiagnostics(metadata, jsxFramework) {
|
|
734
899
|
const overlay = buildCodegenOverlay(metadata);
|
|
735
900
|
if (!overlay) return [];
|
|
736
901
|
const [ds] = metadata.designSystem;
|
|
@@ -745,9 +910,8 @@ function collectExportMissingDiagnostics(metadata) {
|
|
|
745
910
|
if (overlay.ownedPatterns.length > 0) {
|
|
746
911
|
required.push("./patterns", "./patterns/*");
|
|
747
912
|
}
|
|
748
|
-
const
|
|
749
|
-
|
|
750
|
-
if (overlay.ownedPatterns.length > 0 || overlay.virtualizeCss && (appPatterns > 0 || dsPatterns > 0)) {
|
|
913
|
+
const reexportsJsx = overlay.virtualizeCss || overlay.ownedPatterns.length > 0;
|
|
914
|
+
if (generatesJsx(jsxFramework) && reexportsJsx) {
|
|
751
915
|
required.push("./jsx", "./jsx/*");
|
|
752
916
|
}
|
|
753
917
|
return required.filter((subpath) => !hasExport(ds.packageExports, subpath)).map((subpath) => exportMissingDiagnostic(ds.name, subpath));
|
|
@@ -795,6 +959,10 @@ function identCollisions(kind, names) {
|
|
|
795
959
|
}
|
|
796
960
|
return collisions;
|
|
797
961
|
}
|
|
962
|
+
var JSX_FRAMEWORKS = /* @__PURE__ */ new Set(["react", "preact", "solid", "vue"]);
|
|
963
|
+
function generatesJsx(jsxFramework) {
|
|
964
|
+
return jsxFramework !== void 0 && JSX_FRAMEWORKS.has(jsxFramework);
|
|
965
|
+
}
|
|
798
966
|
function hasExport(packageExports, subpath) {
|
|
799
967
|
return packageExports != null && Object.prototype.hasOwnProperty.call(packageExports, subpath);
|
|
800
968
|
}
|
|
@@ -843,7 +1011,7 @@ function manifestNotExportedError(spec) {
|
|
|
843
1011
|
async function loadManifestLevel(spec, manifestPath, deps) {
|
|
844
1012
|
let parsed;
|
|
845
1013
|
try {
|
|
846
|
-
parsed = JSON.parse(
|
|
1014
|
+
parsed = JSON.parse(readFileSync4(manifestPath, "utf8"));
|
|
847
1015
|
} catch (error) {
|
|
848
1016
|
const message = `Failed to parse ${JSON.stringify(manifestPath)} as JSON: ${errorMessage(error)}. This file must be generated by \`panda lib\`, not hand-written or added to \`include\`.`;
|
|
849
1017
|
throw createConfigError(message, [
|
|
@@ -851,8 +1019,8 @@ async function loadManifestLevel(spec, manifestPath, deps) {
|
|
|
851
1019
|
]);
|
|
852
1020
|
}
|
|
853
1021
|
const manifest = validateManifest(spec, manifestPath, parsed);
|
|
854
|
-
const presetPath = resolve4(
|
|
855
|
-
const buildInfoPath = resolve4(
|
|
1022
|
+
const presetPath = resolve4(dirname6(manifestPath), manifest.preset);
|
|
1023
|
+
const buildInfoPath = resolve4(dirname6(manifestPath), manifest.buildInfo);
|
|
856
1024
|
deps.add(presetPath);
|
|
857
1025
|
deps.add(buildInfoPath);
|
|
858
1026
|
let preset;
|
|
@@ -892,9 +1060,9 @@ async function loadManifestLevel(spec, manifestPath, deps) {
|
|
|
892
1060
|
}
|
|
893
1061
|
function readPackageExports(manifestPath) {
|
|
894
1062
|
try {
|
|
895
|
-
const packageJsonPath = nearestPackageJson(
|
|
1063
|
+
const packageJsonPath = nearestPackageJson(dirname6(manifestPath));
|
|
896
1064
|
if (packageJsonPath === void 0) return void 0;
|
|
897
|
-
const pkg = JSON.parse(
|
|
1065
|
+
const pkg = JSON.parse(readFileSync4(packageJsonPath, "utf8"));
|
|
898
1066
|
return isExportsMap(pkg.exports) ? pkg.exports : void 0;
|
|
899
1067
|
} catch {
|
|
900
1068
|
return void 0;
|
|
@@ -904,8 +1072,8 @@ function isExportsMap(value) {
|
|
|
904
1072
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
905
1073
|
}
|
|
906
1074
|
function presetImportUrl(path) {
|
|
907
|
-
const url =
|
|
908
|
-
url.searchParams.set("mtime", String(
|
|
1075
|
+
const url = pathToFileURL4(path);
|
|
1076
|
+
url.searchParams.set("mtime", String(statSync3(path).mtimeMs));
|
|
909
1077
|
return url.href;
|
|
910
1078
|
}
|
|
911
1079
|
function designSystemImportMap(map, spec) {
|
|
@@ -1009,8 +1177,8 @@ function unsupportedSpecifierError(spec, protocol) {
|
|
|
1009
1177
|
}
|
|
1010
1178
|
|
|
1011
1179
|
// src/design-system/smart-include.ts
|
|
1012
|
-
import { existsSync as
|
|
1013
|
-
import { dirname as
|
|
1180
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
1181
|
+
import { dirname as dirname7, isAbsolute as isAbsolute4, join as join5, relative as relative4, resolve as resolve5, sep as sep3 } from "node:path";
|
|
1014
1182
|
var SMART_INCLUDE_EXTENSIONS = ["js", "mjs", "cjs", "jsx", "ts", "cts", "mts", "tsx", "vue", "svelte", "astro"];
|
|
1015
1183
|
var MANIFEST_SUBPATH = "panda/lib.json";
|
|
1016
1184
|
var PACKAGE_SPECIFIER = /^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/i;
|
|
@@ -1037,11 +1205,11 @@ function resolveSmartInclude(include, cwd, deps) {
|
|
|
1037
1205
|
next.push(entry);
|
|
1038
1206
|
continue;
|
|
1039
1207
|
}
|
|
1040
|
-
if (
|
|
1208
|
+
if (existsSync5(join5(packageDir, ...MANIFEST_SUBPATH.split("/")))) {
|
|
1041
1209
|
offenders.push(entry);
|
|
1042
1210
|
continue;
|
|
1043
1211
|
}
|
|
1044
|
-
deps.add(
|
|
1212
|
+
deps.add(join5(packageDir, "package.json"));
|
|
1045
1213
|
const base = globBase(packageDir, cwd);
|
|
1046
1214
|
next.push(`${base}/**/*.{${SMART_INCLUDE_EXTENSIONS.join(",")}}`);
|
|
1047
1215
|
excludes.push(`${base}/**/node_modules/**`);
|
|
@@ -1060,11 +1228,11 @@ function mergeExcludes(existing, additions) {
|
|
|
1060
1228
|
return [...existing ?? [], ...additions];
|
|
1061
1229
|
}
|
|
1062
1230
|
function isLocalPath(entry, cwd) {
|
|
1063
|
-
return
|
|
1231
|
+
return existsSync5(isAbsolute4(entry) ? entry : resolve5(cwd, entry));
|
|
1064
1232
|
}
|
|
1065
1233
|
function resolvePackageDir(spec, cwd) {
|
|
1066
1234
|
const fromPackageJson = tryResolve(`${spec}/package.json`, cwd);
|
|
1067
|
-
if (fromPackageJson !== void 0) return
|
|
1235
|
+
if (fromPackageJson !== void 0) return dirname7(fromPackageJson);
|
|
1068
1236
|
const fromEntry = tryResolve(spec, cwd);
|
|
1069
1237
|
return fromEntry === void 0 ? void 0 : nearestPackageDir(fromEntry);
|
|
1070
1238
|
}
|
|
@@ -1079,13 +1247,13 @@ function tryResolve(request, cwd) {
|
|
|
1079
1247
|
function isInsideCwd(relativePath) {
|
|
1080
1248
|
if (relativePath === "" || relativePath === "..") return false;
|
|
1081
1249
|
if (isAbsolute4(relativePath)) return false;
|
|
1082
|
-
return !relativePath.startsWith(`..${
|
|
1250
|
+
return !relativePath.startsWith(`..${sep3}`);
|
|
1083
1251
|
}
|
|
1084
1252
|
function nearestPackageDir(from) {
|
|
1085
|
-
let dir =
|
|
1253
|
+
let dir = dirname7(from);
|
|
1086
1254
|
while (true) {
|
|
1087
|
-
if (
|
|
1088
|
-
const parent =
|
|
1255
|
+
if (existsSync5(join5(dir, "package.json"))) return dir;
|
|
1256
|
+
const parent = dirname7(dir);
|
|
1089
1257
|
if (parent === dir) return void 0;
|
|
1090
1258
|
dir = parent;
|
|
1091
1259
|
}
|
|
@@ -1309,7 +1477,7 @@ function collectPresetResolvedHooks(config) {
|
|
|
1309
1477
|
return collectPluginHookHandlers(config, "preset:resolved");
|
|
1310
1478
|
}
|
|
1311
1479
|
async function runPresetResolvedHooks(preset, source, hooks) {
|
|
1312
|
-
let current = preset;
|
|
1480
|
+
let current = hooks.length > 0 ? clone(preset) : preset;
|
|
1313
1481
|
const name = source.name ?? source.specifier ?? presetName(current) ?? "unknown-preset";
|
|
1314
1482
|
for (const entry of hooks) {
|
|
1315
1483
|
const hook = normalizeHook(entry.value, "preset:resolved");
|
|
@@ -1323,7 +1491,7 @@ async function runPresetResolvedHooks(preset, source, hooks) {
|
|
|
1323
1491
|
async function resolvePreset(preset, cwd) {
|
|
1324
1492
|
if (typeof preset === "string") {
|
|
1325
1493
|
try {
|
|
1326
|
-
const result = await bundleConfig(preset, cwd);
|
|
1494
|
+
const result = await importInstalledConfig(preset, cwd) ?? await bundleConfig(preset, cwd);
|
|
1327
1495
|
return {
|
|
1328
1496
|
config: ensureConfigObject(result.config, preset),
|
|
1329
1497
|
dependencies: result.dependencies,
|
|
@@ -1551,15 +1719,15 @@ function isConfigSnapshot(input) {
|
|
|
1551
1719
|
}
|
|
1552
1720
|
|
|
1553
1721
|
// src/version.ts
|
|
1554
|
-
import { readFileSync as
|
|
1555
|
-
import { dirname as
|
|
1556
|
-
import { fileURLToPath } from "node:url";
|
|
1722
|
+
import { readFileSync as readFileSync5 } from "node:fs";
|
|
1723
|
+
import { dirname as dirname8, join as join6 } from "node:path";
|
|
1724
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1557
1725
|
var MAJOR_VERSION_RE = /\d+/;
|
|
1558
1726
|
var STAMPABLE_PANDA_RANGE_RE = /^[v=><~^]|^\d/;
|
|
1559
1727
|
function readPandaVersion() {
|
|
1560
1728
|
try {
|
|
1561
|
-
const pkgPath =
|
|
1562
|
-
return JSON.parse(
|
|
1729
|
+
const pkgPath = join6(dirname8(fileURLToPath2(import.meta.url)), "../package.json");
|
|
1730
|
+
return JSON.parse(readFileSync5(pkgPath, "utf8")).version;
|
|
1563
1731
|
} catch {
|
|
1564
1732
|
return void 0;
|
|
1565
1733
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/config",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.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",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@pandacss/compiler-shared": "2.1.
|
|
43
|
-
"@pandacss/types": "2.1.
|
|
42
|
+
"@pandacss/compiler-shared": "2.1.2",
|
|
43
|
+
"@pandacss/types": "2.1.2",
|
|
44
44
|
"acorn": "^8.17.0",
|
|
45
45
|
"acorn-walk": "^8.3.5",
|
|
46
46
|
"javascript-stringify": "2.1.0",
|