@pandacss/config 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +97 -48
  2. package/package.json +4 -3
package/dist/index.js CHANGED
@@ -21,11 +21,11 @@ import {
21
21
  import { applyConfigDefaults as applyConfigDefaults2 } from "@pandacss/compiler-shared";
22
22
 
23
23
  // src/bundle.ts
24
- import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
24
+ import { existsSync as existsSync2, readFileSync, realpathSync, statSync } 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, extname, isAbsolute as isAbsolute2, join, normalize, relative, sep } from "node:path";
28
+ import { basename, dirname as dirname2, extname, isAbsolute as isAbsolute2, join as join2, normalize, relative, sep as sep2 } from "node:path";
29
29
  import { pathToFileURL as pathToFileURL2 } from "node:url";
30
30
 
31
31
  // src/bundle-plugins.ts
@@ -62,6 +62,17 @@ function sideEffectImportsPlugin() {
62
62
  }
63
63
  };
64
64
  }
65
+ function commonJsInteropPlugin() {
66
+ return {
67
+ name: "panda-commonjs-interop",
68
+ async resolveId(source, importer, options) {
69
+ const resolved = await this.resolve(source, importer, { ...options, skipSelf: true });
70
+ if (!resolved || resolved.external || nodeModulesRe.test(resolved.id)) return resolved;
71
+ const { packageJsonPath: _, ...rest } = resolved;
72
+ return rest;
73
+ }
74
+ };
75
+ }
65
76
 
66
77
  // src/resolve.ts
67
78
  import { createRequire } from "node:module";
@@ -92,6 +103,42 @@ function errorCode(error) {
92
103
  return typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
93
104
  }
94
105
 
106
+ // src/tsconfig.ts
107
+ import { existsSync } from "node:fs";
108
+ import { dirname, join, resolve as resolve2, sep } from "node:path";
109
+ import { createFilesMatcher, parseTsconfig } from "get-tsconfig";
110
+ function resolveConfigTsconfig(file, cwd) {
111
+ const configFile = resolve2(cwd, file);
112
+ if (configFile.includes(`${sep}node_modules${sep}`)) return void 0;
113
+ const closest = readTsconfig(findClosestTsconfig(configFile, resolve2(cwd)));
114
+ if (!closest) return void 0;
115
+ const references = (closest.config.references ?? []).flatMap((reference) => {
116
+ const target = resolve2(dirname(closest.path), reference.path);
117
+ const tsconfig = readTsconfig(target.endsWith(".json") ? target : join(target, "tsconfig.json"));
118
+ return tsconfig ? [tsconfig] : [];
119
+ });
120
+ const owner = [closest, ...references].find((tsconfig) => createFilesMatcher(tsconfig)(configFile)) ?? closest;
121
+ return [owner, ...references].find(hasPaths)?.path;
122
+ }
123
+ function findClosestTsconfig(file, root) {
124
+ for (let dir = dirname(file); ; dir = dirname(dir)) {
125
+ const candidate = join(dir, "tsconfig.json");
126
+ if (existsSync(candidate)) return candidate;
127
+ if (dir === root || dirname(dir) === dir) return void 0;
128
+ }
129
+ }
130
+ function readTsconfig(path) {
131
+ if (!path || !existsSync(path)) return void 0;
132
+ try {
133
+ return { path, config: parseTsconfig(path) };
134
+ } catch {
135
+ return void 0;
136
+ }
137
+ }
138
+ function hasPaths(tsconfig) {
139
+ return Object.keys(tsconfig.config.compilerOptions?.paths ?? {}).length > 0;
140
+ }
141
+
95
142
  // src/bundle.ts
96
143
  var nodeBuiltins = /* @__PURE__ */ new Set([...builtinModules, ...builtinModules.map((mod) => `node:${mod}`)]);
97
144
  async function bundleConfig(filepath, cwd) {
@@ -100,9 +147,10 @@ async function bundleConfig(filepath, cwd) {
100
147
  input: filepath,
101
148
  cwd,
102
149
  platform: "node",
150
+ tsconfig: resolveConfigTsconfig(filepath, cwd) ?? true,
103
151
  external: (id) => nodeBuiltins.has(id),
104
152
  treeshake: true,
105
- plugins: [importMetaUrlPlugin(), sideEffectImportsPlugin()]
153
+ plugins: [importMetaUrlPlugin(), sideEffectImportsPlugin(), commonJsInteropPlugin()]
106
154
  });
107
155
  let chunks;
108
156
  try {
@@ -123,7 +171,7 @@ async function importInstalledConfig(specifier, cwd) {
123
171
  const resolved = tryResolveFrom(specifier, cwd);
124
172
  if (!resolved) return void 0;
125
173
  const file = canonical(resolved);
126
- if (!file.includes(`${sep}node_modules${sep}`) || !isEsmFile(file)) return void 0;
174
+ if (!file.includes(`${sep2}node_modules${sep2}`) || !isEsmFile(file)) return void 0;
127
175
  const mod = await import(
128
176
  /* @vite-ignore */
129
177
  `${pathToFileURL2(file).href}?mtime=${statSync(file).mtimeMs}`
@@ -139,14 +187,14 @@ function isEsmFile(file) {
139
187
  const extension = extname(file);
140
188
  if (extension === ".mjs") return true;
141
189
  if (extension !== ".js") return false;
142
- return nearestPackageType(dirname(file)) === "module";
190
+ return nearestPackageType(dirname2(file)) === "module";
143
191
  }
144
192
  function nearestPackageType(start) {
145
193
  let current = start;
146
194
  while (true) {
147
- const candidate = join(current, "package.json");
148
- if (existsSync(candidate)) return JSON.parse(readFileSync(candidate, "utf8")).type;
149
- const parent = dirname(current);
195
+ const candidate = join2(current, "package.json");
196
+ if (existsSync2(candidate)) return JSON.parse(readFileSync(candidate, "utf8")).type;
197
+ const parent = dirname2(current);
150
198
  if (parent === current) return void 0;
151
199
  current = parent;
152
200
  }
@@ -156,7 +204,7 @@ async function loadBundledModule(filepath, code) {
156
204
  let evalError;
157
205
  if (target) {
158
206
  try {
159
- await mkdir(dirname(target), { recursive: true });
207
+ await mkdir(dirname2(target), { recursive: true });
160
208
  await writeFile(target, code);
161
209
  try {
162
210
  return await import(
@@ -187,16 +235,16 @@ function isUnresolvedTempModule(error, target) {
187
235
  function tempTargetFor(filepath) {
188
236
  const unique = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
189
237
  const name = `panda.config.bundled.${unique}.mjs`;
190
- const nodeModules = nearestNodeModules(dirname(filepath));
191
- const base = nodeModules ? join(nodeModules, ".panda") : join(tmpdir(), "panda-config");
192
- return join(base, name);
238
+ const nodeModules = nearestNodeModules(dirname2(filepath));
239
+ const base = nodeModules ? join2(nodeModules, ".panda") : join2(tmpdir(), "panda-config");
240
+ return join2(base, name);
193
241
  }
194
242
  function nearestNodeModules(start) {
195
243
  let current = start;
196
244
  while (true) {
197
- const candidate = join(current, "node_modules");
198
- if (existsSync(candidate)) return candidate;
199
- const parent = dirname(current);
245
+ const candidate = join2(current, "node_modules");
246
+ if (existsSync2(candidate)) return candidate;
247
+ const parent = dirname2(current);
200
248
  if (parent === current) return void 0;
201
249
  current = parent;
202
250
  }
@@ -227,7 +275,7 @@ function canonical(filepath) {
227
275
 
228
276
  // src/find.ts
229
277
  import { readdirSync } from "node:fs";
230
- import { dirname as dirname2, resolve as resolve2 } from "node:path";
278
+ import { dirname as dirname3, resolve as resolve3 } from "node:path";
231
279
  var configFiles = /* @__PURE__ */ new Set([
232
280
  "panda.config.ts",
233
281
  "panda.config.js",
@@ -238,7 +286,7 @@ var configFiles = /* @__PURE__ */ new Set([
238
286
  ]);
239
287
  var isPandaConfig = (file) => configFiles.has(file);
240
288
  function findUp(cwd) {
241
- let dir = resolve2(cwd);
289
+ let dir = resolve3(cwd);
242
290
  while (true) {
243
291
  let entries;
244
292
  try {
@@ -247,8 +295,8 @@ function findUp(cwd) {
247
295
  entries = [];
248
296
  }
249
297
  const match = entries.find(isPandaConfig);
250
- if (match) return resolve2(dir, match);
251
- const parent = dirname2(dir);
298
+ if (match) return resolve3(dir, match);
299
+ const parent = dirname3(dir);
252
300
  if (parent === dir) return void 0;
253
301
  dir = parent;
254
302
  }
@@ -256,7 +304,7 @@ function findUp(cwd) {
256
304
  function findConfig(options) {
257
305
  const { cwd, file } = options;
258
306
  if (file) {
259
- return resolve2(cwd, file);
307
+ return resolve3(cwd, file);
260
308
  }
261
309
  const configPath = findUp(cwd);
262
310
  if (!configPath) {
@@ -490,15 +538,15 @@ import {
490
538
  outdirBasename
491
539
  } from "@pandacss/compiler-shared";
492
540
  import { readFileSync as readFileSync3, statSync as statSync2 } from "node:fs";
493
- import { dirname as dirname4, resolve as resolve4 } from "node:path";
541
+ import { dirname as dirname5, resolve as resolve5 } from "node:path";
494
542
  import { pathToFileURL as pathToFileURL3 } from "node:url";
495
543
 
496
544
  // src/design-system/package.ts
497
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
498
- import { dirname as dirname3, join as join2 } from "node:path";
545
+ import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
546
+ import { dirname as dirname4, join as join3 } from "node:path";
499
547
 
500
548
  // src/design-system/publishable-files.ts
501
- import { relative as relative3, resolve as resolve3 } from "node:path";
549
+ import { relative as relative3, resolve as resolve4 } from "node:path";
502
550
 
503
551
  // src/paths.ts
504
552
  import { isAbsolute as isAbsolute3, relative as relative2 } from "node:path";
@@ -552,7 +600,7 @@ function libFileToPackageRelative(file, packageRoot, outRoot) {
552
600
  const withoutDot = normalized.startsWith("./") ? normalized.slice(2) : normalized;
553
601
  const globAt = withoutDot.search(GLOB_START);
554
602
  const literalPrefix = globAt === -1 ? withoutDot : withoutDot.slice(0, globAt);
555
- const abs = resolve3(outRoot, literalPrefix || ".");
603
+ const abs = resolve4(outRoot, literalPrefix || ".");
556
604
  const rel = toPosixPath(relative3(packageRoot, abs));
557
605
  if (rel === "") return "";
558
606
  if (rel.startsWith("..")) return void 0;
@@ -674,9 +722,9 @@ function isSubpathExportMap(exports) {
674
722
  function nearestPackageJson(start) {
675
723
  let current = start;
676
724
  while (true) {
677
- const candidate = join2(current, "package.json");
678
- if (existsSync2(candidate)) return candidate;
679
- const parent = dirname3(current);
725
+ const candidate = join3(current, "package.json");
726
+ if (existsSync3(candidate)) return candidate;
727
+ const parent = dirname4(current);
680
728
  if (parent === current) return void 0;
681
729
  current = parent;
682
730
  }
@@ -711,7 +759,7 @@ async function loadDesignSystemChain(spec, cwd, deps) {
711
759
  levels.push(level);
712
760
  if (parent === void 0) break;
713
761
  declaredBy = level.info.name;
714
- fromDir = dirname4(manifestPath);
762
+ fromDir = dirname5(manifestPath);
715
763
  currentSpec = parent;
716
764
  }
717
765
  return levels.reverse();
@@ -731,13 +779,14 @@ function buildCodegenOverlay(metadata) {
731
779
  const appRecipes = new Set(metadata?.userRecipeNames ?? []);
732
780
  const appPatterns = new Set(metadata?.userPatternNames ?? []);
733
781
  const authored = metadata?.overlayInput?.authored;
734
- const runtimeDirty = !!(authored?.conditions || authored?.breakpoints || authored?.utilities || authored?.tokens);
782
+ const cssLocal = !!(authored?.conditions || authored?.breakpoints || authored?.utilities || authored?.tokens);
783
+ const reexported = (names, appNames) => cssLocal ? [] : names.filter((name) => !appNames.has(name));
735
784
  return {
736
785
  ...overlayRoots(ds),
737
- ownedRecipes: ds.recipeNames.filter((name) => !appRecipes.has(name)),
738
- ownedPatterns: ds.patternNames.filter((name) => !appPatterns.has(name)),
786
+ ownedRecipes: reexported(ds.recipeNames, appRecipes),
787
+ ownedPatterns: reexported(ds.patternNames, appPatterns),
739
788
  virtualizeHelpers: true,
740
- virtualizeCss: !runtimeDirty
789
+ virtualizeCss: !cssLocal
741
790
  };
742
791
  }
743
792
  function collectArtifactConflicts(metadata) {
@@ -873,8 +922,8 @@ async function loadManifestLevel(spec, manifestPath, deps) {
873
922
  ]);
874
923
  }
875
924
  const manifest = validateManifest(spec, manifestPath, parsed);
876
- const presetPath = resolve4(dirname4(manifestPath), manifest.preset);
877
- const buildInfoPath = resolve4(dirname4(manifestPath), manifest.buildInfo);
925
+ const presetPath = resolve5(dirname5(manifestPath), manifest.preset);
926
+ const buildInfoPath = resolve5(dirname5(manifestPath), manifest.buildInfo);
878
927
  deps.add(presetPath);
879
928
  deps.add(buildInfoPath);
880
929
  let preset;
@@ -914,7 +963,7 @@ async function loadManifestLevel(spec, manifestPath, deps) {
914
963
  }
915
964
  function readPackageExports(manifestPath) {
916
965
  try {
917
- const packageJsonPath = nearestPackageJson(dirname4(manifestPath));
966
+ const packageJsonPath = nearestPackageJson(dirname5(manifestPath));
918
967
  if (packageJsonPath === void 0) return void 0;
919
968
  const pkg = JSON.parse(readFileSync3(packageJsonPath, "utf8"));
920
969
  return isExportsMap(pkg.exports) ? pkg.exports : void 0;
@@ -1031,8 +1080,8 @@ function unsupportedSpecifierError(spec, protocol) {
1031
1080
  }
1032
1081
 
1033
1082
  // src/design-system/smart-include.ts
1034
- import { existsSync as existsSync3 } from "node:fs";
1035
- import { dirname as dirname5, isAbsolute as isAbsolute4, join as join3, relative as relative4, resolve as resolve5, sep as sep2 } from "node:path";
1083
+ import { existsSync as existsSync4 } from "node:fs";
1084
+ import { dirname as dirname6, isAbsolute as isAbsolute4, join as join4, relative as relative4, resolve as resolve6, sep as sep3 } from "node:path";
1036
1085
  var SMART_INCLUDE_EXTENSIONS = ["js", "mjs", "cjs", "jsx", "ts", "cts", "mts", "tsx", "vue", "svelte", "astro"];
1037
1086
  var MANIFEST_SUBPATH = "panda/lib.json";
1038
1087
  var PACKAGE_SPECIFIER = /^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/i;
@@ -1059,11 +1108,11 @@ function resolveSmartInclude(include, cwd, deps) {
1059
1108
  next.push(entry);
1060
1109
  continue;
1061
1110
  }
1062
- if (existsSync3(join3(packageDir, ...MANIFEST_SUBPATH.split("/")))) {
1111
+ if (existsSync4(join4(packageDir, ...MANIFEST_SUBPATH.split("/")))) {
1063
1112
  offenders.push(entry);
1064
1113
  continue;
1065
1114
  }
1066
- deps.add(join3(packageDir, "package.json"));
1115
+ deps.add(join4(packageDir, "package.json"));
1067
1116
  const base = globBase(packageDir, cwd);
1068
1117
  next.push(`${base}/**/*.{${SMART_INCLUDE_EXTENSIONS.join(",")}}`);
1069
1118
  excludes.push(`${base}/**/node_modules/**`);
@@ -1082,11 +1131,11 @@ function mergeExcludes(existing, additions) {
1082
1131
  return [...existing ?? [], ...additions];
1083
1132
  }
1084
1133
  function isLocalPath(entry, cwd) {
1085
- return existsSync3(isAbsolute4(entry) ? entry : resolve5(cwd, entry));
1134
+ return existsSync4(isAbsolute4(entry) ? entry : resolve6(cwd, entry));
1086
1135
  }
1087
1136
  function resolvePackageDir(spec, cwd) {
1088
1137
  const fromPackageJson = tryResolve(`${spec}/package.json`, cwd);
1089
- if (fromPackageJson !== void 0) return dirname5(fromPackageJson);
1138
+ if (fromPackageJson !== void 0) return dirname6(fromPackageJson);
1090
1139
  const fromEntry = tryResolve(spec, cwd);
1091
1140
  return fromEntry === void 0 ? void 0 : nearestPackageDir(fromEntry);
1092
1141
  }
@@ -1101,13 +1150,13 @@ function tryResolve(request, cwd) {
1101
1150
  function isInsideCwd(relativePath) {
1102
1151
  if (relativePath === "" || relativePath === "..") return false;
1103
1152
  if (isAbsolute4(relativePath)) return false;
1104
- return !relativePath.startsWith(`..${sep2}`);
1153
+ return !relativePath.startsWith(`..${sep3}`);
1105
1154
  }
1106
1155
  function nearestPackageDir(from) {
1107
- let dir = dirname5(from);
1156
+ let dir = dirname6(from);
1108
1157
  while (true) {
1109
- if (existsSync3(join3(dir, "package.json"))) return dir;
1110
- const parent = dirname5(dir);
1158
+ if (existsSync4(join4(dir, "package.json"))) return dir;
1159
+ const parent = dirname6(dir);
1111
1160
  if (parent === dir) return void 0;
1112
1161
  dir = parent;
1113
1162
  }
@@ -1577,13 +1626,13 @@ function isConfigSnapshot(input) {
1577
1626
 
1578
1627
  // src/version.ts
1579
1628
  import { readFileSync as readFileSync4 } from "node:fs";
1580
- import { dirname as dirname6, join as join4 } from "node:path";
1629
+ import { dirname as dirname7, join as join5 } from "node:path";
1581
1630
  import { fileURLToPath } from "node:url";
1582
1631
  var MAJOR_VERSION_RE = /\d+/;
1583
1632
  var STAMPABLE_PANDA_RANGE_RE = /^[v=><~^]|^\d/;
1584
1633
  function readPandaVersion() {
1585
1634
  try {
1586
- const pkgPath = join4(dirname6(fileURLToPath(import.meta.url)), "../package.json");
1635
+ const pkgPath = join5(dirname7(fileURLToPath(import.meta.url)), "../package.json");
1587
1636
  return JSON.parse(readFileSync4(pkgPath, "utf8")).version;
1588
1637
  } catch {
1589
1638
  return void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/config",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
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,10 +39,11 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
- "@pandacss/compiler-shared": "2.4.0",
43
- "@pandacss/types": "2.4.0",
42
+ "@pandacss/compiler-shared": "2.6.0",
43
+ "@pandacss/types": "2.6.0",
44
44
  "acorn": "^8.17.0",
45
45
  "acorn-walk": "^8.3.5",
46
+ "get-tsconfig": "^4.13.0",
46
47
  "javascript-stringify": "2.1.0",
47
48
  "magic-string": "^0.30.21",
48
49
  "microdiff": "1.5.0",