@pandacss/node 0.22.1 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -27,9 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  mod
28
28
  ));
29
29
 
30
- // ../../node_modules/.pnpm/tsup@7.1.0_typescript@5.3.3/node_modules/tsup/assets/esm_shims.js
30
+ // ../../node_modules/.pnpm/tsup@8.0.1_typescript@5.3.3/node_modules/tsup/assets/esm_shims.js
31
31
  var init_esm_shims = __esm({
32
- "../../node_modules/.pnpm/tsup@7.1.0_typescript@5.3.3/node_modules/tsup/assets/esm_shims.js"() {
32
+ "../../node_modules/.pnpm/tsup@8.0.1_typescript@5.3.3/node_modules/tsup/assets/esm_shims.js"() {
33
33
  "use strict";
34
34
  }
35
35
  });
@@ -688,7 +688,7 @@ function analyzeTokens(ctx, options = {}) {
688
688
  const minify = ctx.config.minify;
689
689
  ctx.config.optimize = true;
690
690
  ctx.config.minify = false;
691
- const css2 = "";
691
+ const css = "";
692
692
  const minifiedCss = "";
693
693
  ctx.config.minify = minify;
694
694
  const start = performance.now();
@@ -702,11 +702,11 @@ function analyzeTokens(ctx, options = {}) {
702
702
  classify: classifyMs
703
703
  },
704
704
  fileSizes: {
705
- lineCount: css2.split("\n").length,
706
- normal: filesize(Buffer.byteLength(css2, "utf-8")),
705
+ lineCount: css.split("\n").length,
706
+ normal: filesize(Buffer.byteLength(css, "utf-8")),
707
707
  minified: filesize(Buffer.byteLength(minifiedCss, "utf-8")),
708
708
  gzip: {
709
- normal: filesize(gzipSizeSync(css2)),
709
+ normal: filesize(gzipSizeSync(css)),
710
710
  minified: filesize(gzipSizeSync(minifiedCss))
711
711
  }
712
712
  }
@@ -746,13 +746,42 @@ var writeAnalyzeJSON = (filePath, result, ctx) => {
746
746
  );
747
747
  };
748
748
 
749
+ // src/build-info.ts
750
+ init_esm_shims();
751
+ import { colors, logger as logger2 } from "@pandacss/logger";
752
+
753
+ // package.json
754
+ var version = "0.24.0";
755
+
756
+ // src/build-info.ts
757
+ async function buildInfo(ctx, outfile) {
758
+ const { filesWithCss, files } = ctx.parseFiles();
759
+ logger2.info("cli", `Found ${colors.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
760
+ const minify = ctx.config.minify;
761
+ logger2.info("cli", `Writing ${minify ? "[min] " : " "}${colors.bold(outfile)}`);
762
+ const output = JSON.stringify(
763
+ {
764
+ schemaVersion: version,
765
+ styles: ctx.encoder.toJSON()
766
+ },
767
+ null,
768
+ minify ? 0 : 2
769
+ );
770
+ ctx.output.ensure(outfile, process.cwd());
771
+ await ctx.runtime.fs.writeFile(outfile, output);
772
+ logger2.info("cli", "Done!");
773
+ }
774
+
749
775
  // src/builder.ts
750
776
  init_esm_shims();
777
+ import { findConfig } from "@pandacss/config";
751
778
  import { optimizeCss } from "@pandacss/core";
752
779
  import { ConfigNotFoundError } from "@pandacss/error";
753
780
  import { logger as logger6 } from "@pandacss/logger";
754
- import { existsSync } from "fs";
755
- import fsExtra2 from "fs-extra";
781
+ import { existsSync, statSync } from "fs";
782
+
783
+ // src/codegen.ts
784
+ init_esm_shims();
756
785
 
757
786
  // ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
758
787
  init_esm_shims();
@@ -861,372 +890,6 @@ function pLimit(concurrency) {
861
890
  return generator;
862
891
  }
863
892
 
864
- // src/builder.ts
865
- import { resolve as resolve2 } from "pathe";
866
-
867
- // src/config.ts
868
- init_esm_shims();
869
- import { convertTsPathsToRegexes, loadConfigFile as loadConfigFile2 } from "@pandacss/config";
870
- import { createDebugger, createHooks } from "hookable";
871
- import { lookItUpSync } from "look-it-up";
872
- import { parse } from "tsconfck";
873
-
874
- // src/create-context.ts
875
- init_esm_shims();
876
- import { Generator as Generator2 } from "@pandacss/generator";
877
- import { logger as logger4 } from "@pandacss/logger";
878
- import { createParserResult, createProject } from "@pandacss/parser";
879
-
880
- // src/diff-engine.ts
881
- init_esm_shims();
882
- import { loadConfigFile } from "@pandacss/config";
883
- import "@pandacss/generator";
884
- import { dashCase } from "@pandacss/shared";
885
- import diff from "microdiff";
886
-
887
- // src/matcher.ts
888
- init_esm_shims();
889
- function createMatcher(id, patterns) {
890
- if (!patterns?.length)
891
- return () => void 0;
892
- const includePatterns = [];
893
- const excludePatterns = [];
894
- const deduped = new Set(patterns);
895
- deduped.forEach((pattern) => {
896
- const regexString = pattern.replace(/\*/g, ".*");
897
- if (pattern.startsWith("!")) {
898
- excludePatterns.push(regexString.slice(1));
899
- } else {
900
- includePatterns.push(regexString);
901
- }
902
- });
903
- const include = new RegExp(includePatterns.join("|"));
904
- const exclude = new RegExp(excludePatterns.join("|"));
905
- return (path2) => {
906
- if (excludePatterns.length && exclude.test(path2))
907
- return;
908
- return include.test(path2) ? id : void 0;
909
- };
910
- }
911
-
912
- // src/diff-engine.ts
913
- var all = ["outdir", "forceConsistentTypeExtension", "outExtension"];
914
- var format = ["syntax", "hash", "prefix", "separator"];
915
- var tokens = ["utilities", "conditions", "theme.tokens", "theme.semanticTokens", "theme.breakpoints"];
916
- var jsx = ["jsxFramework", "jsxFactory", "jsxStyleProps", "syntax"];
917
- var css = ["layers", "optimize", "minify"];
918
- var common = tokens.concat(jsx, format);
919
- var artifactConfigDeps = {
920
- helpers: ["syntax", "jsxFramework"],
921
- keyframes: ["theme.keyframes", "layers"],
922
- "design-tokens": ["layers", "!utilities.*.className"].concat(tokens),
923
- types: ["!utilities.*.className"].concat(common),
924
- "css-fn": common,
925
- cva: ["syntax"],
926
- sva: ["syntax"],
927
- cx: [],
928
- "create-recipe": ["separator", "prefix", "hash"],
929
- "recipes-index": ["theme.recipes", "theme.slotRecipes"],
930
- recipes: ["theme.recipes", "theme.slotRecipes"],
931
- "patterns-index": ["syntax", "patterns"],
932
- patterns: ["syntax", "patterns"],
933
- "jsx-is-valid-prop": common,
934
- "jsx-factory": jsx,
935
- "jsx-helpers": jsx,
936
- "jsx-patterns": jsx.concat("patterns"),
937
- "jsx-patterns-index": jsx.concat("patterns"),
938
- "css-index": ["syntax"],
939
- "reset.css": ["preflight", "layers"],
940
- "global.css": ["globalCss"].concat(css),
941
- "static.css": ["staticCss", "theme.breakpoints"].concat(css),
942
- "styles.css": tokens.concat(format),
943
- "package.json": ["emitPackage"]
944
- };
945
- var configDeps = {
946
- artifacts: artifactConfigDeps
947
- };
948
- var matchers = {
949
- artifacts: Object.keys(configDeps.artifacts).map((key) => {
950
- const paths = configDeps.artifacts[key];
951
- if (!paths.length)
952
- return () => void 0;
953
- return createMatcher(key, paths.concat(all));
954
- })
955
- };
956
- var DiffEngine = class {
957
- constructor(ctx) {
958
- this.ctx = ctx;
959
- this.previousConfig = ctx.conf.deserialize();
960
- }
961
- previousConfig;
962
- /**
963
- * Reload config from disk and refresh the context
964
- */
965
- async reloadConfigAndRefreshContext(fn) {
966
- const conf = await loadConfigFile({ cwd: this.ctx.config.cwd, file: this.ctx.conf.path });
967
- return this.refresh(conf, fn);
968
- }
969
- /**
970
- * Update the context from the refreshed config
971
- * then persist the changes on each affected engines
972
- * Returns the list of affected artifacts/engines
973
- */
974
- refresh(conf, fn) {
975
- const affected = {
976
- artifacts: /* @__PURE__ */ new Set(),
977
- hasConfigChanged: false,
978
- diffs: []
979
- };
980
- if (!this.previousConfig) {
981
- affected.hasConfigChanged = true;
982
- return affected;
983
- }
984
- const newConfig = conf.deserialize();
985
- const configDiff = diff(this.previousConfig, newConfig);
986
- if (!configDiff.length) {
987
- return affected;
988
- }
989
- affected.hasConfigChanged = true;
990
- affected.diffs = configDiff;
991
- this.previousConfig = newConfig;
992
- fn?.(conf);
993
- configDiff.forEach((change) => {
994
- const changePath = change.path.join(".");
995
- matchers.artifacts.forEach((matcher) => {
996
- const id = matcher(changePath);
997
- if (!id)
998
- return;
999
- if (id === "recipes") {
1000
- const name = dashCase(change.path.slice(1, 3).join("."));
1001
- affected.artifacts.add(name);
1002
- }
1003
- if (id === "patterns") {
1004
- const name = dashCase(change.path.slice(0, 2).join("."));
1005
- affected.artifacts.add(name);
1006
- }
1007
- affected.artifacts.add(id);
1008
- });
1009
- });
1010
- return affected;
1011
- }
1012
- };
1013
-
1014
- // src/node-runtime.ts
1015
- init_esm_shims();
1016
- import { logger as logger2 } from "@pandacss/logger";
1017
- import chokidar from "chokidar";
1018
- import glob from "fast-glob";
1019
- import fsExtra from "fs-extra";
1020
- import { dirname, extname, isAbsolute, join, relative, sep } from "pathe";
1021
- var nodeRuntime = {
1022
- cwd() {
1023
- return process.cwd();
1024
- },
1025
- env(name) {
1026
- return process.env[name];
1027
- },
1028
- path: {
1029
- join,
1030
- relative,
1031
- dirname,
1032
- extname,
1033
- isAbsolute,
1034
- sep,
1035
- abs(cwd, str) {
1036
- return isAbsolute(str) ? str : join(cwd, str);
1037
- }
1038
- },
1039
- fs: {
1040
- existsSync: fsExtra.existsSync,
1041
- readFileSync(filePath) {
1042
- return fsExtra.readFileSync(filePath, "utf8");
1043
- },
1044
- glob(opts) {
1045
- if (!opts.include)
1046
- return [];
1047
- const ignore = opts.exclude ?? [];
1048
- if (!ignore.length) {
1049
- ignore.push("**/*.d.ts");
1050
- }
1051
- return glob.sync(opts.include, { cwd: opts.cwd, ignore, absolute: true });
1052
- },
1053
- writeFile: fsExtra.writeFile,
1054
- writeFileSync: fsExtra.writeFileSync,
1055
- readDirSync: fsExtra.readdirSync,
1056
- rmDirSync: fsExtra.emptyDirSync,
1057
- rmFileSync: fsExtra.removeSync,
1058
- ensureDirSync(path2) {
1059
- return fsExtra.ensureDirSync(path2);
1060
- },
1061
- watch(options) {
1062
- const { include, exclude, cwd, poll } = options;
1063
- const coalesce = poll || process.platform === "win32";
1064
- const watcher = chokidar.watch(include, {
1065
- usePolling: poll,
1066
- cwd,
1067
- ignoreInitial: true,
1068
- ignorePermissionErrors: true,
1069
- ignored: exclude,
1070
- awaitWriteFinish: coalesce ? { stabilityThreshold: 50, pollInterval: 10 } : false
1071
- });
1072
- logger2.debug("watch:file", `watching [${include}]`);
1073
- process.once("SIGINT", async () => {
1074
- await watcher.close();
1075
- });
1076
- return watcher;
1077
- }
1078
- }
1079
- };
1080
- process.setMaxListeners(Infinity);
1081
- process.on("unhandledRejection", (reason) => {
1082
- logger2.error("\u274C", reason);
1083
- });
1084
- process.on("uncaughtException", (reason) => {
1085
- logger2.error("\u274C", reason);
1086
- });
1087
-
1088
- // src/output-engine.ts
1089
- init_esm_shims();
1090
- import { logger as logger3 } from "@pandacss/logger";
1091
- var PandaOutputEngine = class {
1092
- paths;
1093
- fs;
1094
- path;
1095
- constructor({ paths, runtime: { path: path2, fs } }) {
1096
- this.paths = paths;
1097
- this.fs = fs;
1098
- this.path = path2;
1099
- }
1100
- empty() {
1101
- this.fs.rmDirSync(this.path.join(...this.paths.root));
1102
- }
1103
- async write(output) {
1104
- if (!output)
1105
- return;
1106
- const { dir = this.paths.root, files } = output;
1107
- this.fs.ensureDirSync(this.path.join(...dir));
1108
- return Promise.allSettled(
1109
- files.map(async (artifact) => {
1110
- if (!artifact?.code)
1111
- return;
1112
- const { file, code } = artifact;
1113
- const absPath = this.path.join(...dir, file);
1114
- logger3.debug("write:file", dir.slice(-1).concat(file).join("/"));
1115
- return this.fs.writeFile(absPath, code);
1116
- })
1117
- );
1118
- }
1119
- };
1120
-
1121
- // src/create-context.ts
1122
- var PandaContext = class extends Generator2 {
1123
- runtime;
1124
- project;
1125
- getFiles;
1126
- output;
1127
- diff;
1128
- constructor(conf) {
1129
- super(conf);
1130
- const config = conf.config;
1131
- this.runtime = nodeRuntime;
1132
- config.cwd ||= this.runtime.cwd();
1133
- if (config.logLevel) {
1134
- logger4.level = config.logLevel;
1135
- }
1136
- const { include, exclude, cwd } = config;
1137
- this.getFiles = () => this.runtime.fs.glob({ include, exclude, cwd });
1138
- this.project = createProject({
1139
- ...conf.tsconfig,
1140
- getFiles: this.getFiles.bind(this),
1141
- readFile: this.runtime.fs.readFileSync.bind(this),
1142
- hooks: conf.hooks,
1143
- parserOptions: { join: this.runtime.path.join, ...this.parserOptions }
1144
- });
1145
- this.output = new PandaOutputEngine(this);
1146
- this.diff = new DiffEngine(this);
1147
- }
1148
- appendFilesCss() {
1149
- const files = this.getFiles();
1150
- const filesWithCss = [];
1151
- const mergedResult = createParserResult();
1152
- files.forEach((file) => {
1153
- const measure = logger4.time.debug(`Parsed ${file}`);
1154
- const result = this.project.parseSourceFile(file);
1155
- measure();
1156
- if (!result)
1157
- return;
1158
- mergedResult.merge(result);
1159
- filesWithCss.push(file);
1160
- });
1161
- this.appendParserCss(mergedResult);
1162
- return filesWithCss;
1163
- }
1164
- appendAllCss() {
1165
- this.appendLayerParams();
1166
- this.appendBaselineCss();
1167
- this.appendFilesCss();
1168
- }
1169
- async writeCss() {
1170
- return this.output.write({
1171
- id: "styles.css",
1172
- dir: this.paths.root,
1173
- files: [{ file: "styles.css", code: this.getCss() }]
1174
- });
1175
- }
1176
- };
1177
-
1178
- // src/config.ts
1179
- var configs = [".ts", ".js", ".mts", ".mjs", ".cts", ".cjs"];
1180
- function findConfig() {
1181
- for (const config of configs) {
1182
- const result = lookItUpSync(`panda.config${config}`);
1183
- if (result) {
1184
- return result;
1185
- }
1186
- }
1187
- }
1188
- async function loadConfigAndCreateContext(options = {}) {
1189
- const { config, configPath } = options;
1190
- const cwd = options.cwd ?? options?.config?.cwd ?? process.cwd();
1191
- const conf = await loadConfigFile2({ cwd, file: configPath });
1192
- if (config) {
1193
- Object.assign(conf.config, config);
1194
- }
1195
- if (options.cwd) {
1196
- conf.config.cwd = options.cwd;
1197
- }
1198
- const tsconfigResult = await parse(conf.path, {
1199
- root: cwd,
1200
- // @ts-ignore
1201
- resolveWithEmptyIfConfigNotFound: true
1202
- });
1203
- if (tsconfigResult) {
1204
- conf.tsconfig = tsconfigResult.tsconfig;
1205
- conf.tsconfigFile = tsconfigResult.tsconfigFile;
1206
- const options2 = tsconfigResult.tsconfig?.compilerOptions;
1207
- if (options2?.paths) {
1208
- const baseUrl = options2.baseUrl;
1209
- conf.tsOptions = {
1210
- baseUrl,
1211
- pathMappings: convertTsPathsToRegexes(options2.paths, baseUrl ?? cwd)
1212
- };
1213
- }
1214
- }
1215
- conf.config.outdir ??= "styled-system";
1216
- const hooks = createHooks();
1217
- if (conf.config.hooks) {
1218
- hooks.addHooks(conf.config.hooks);
1219
- }
1220
- await hooks.callHook("config:resolved", conf);
1221
- if (conf.config.logLevel === "debug") {
1222
- createDebugger(hooks, { tag: "panda" });
1223
- }
1224
- return new PandaContext({ ...conf, hooks });
1225
- }
1226
-
1227
- // src/emit-artifact.ts
1228
- init_esm_shims();
1229
-
1230
893
  // src/cli-box.ts
1231
894
  init_esm_shims();
1232
895
 
@@ -1584,10 +1247,10 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
1584
1247
  return 3;
1585
1248
  }
1586
1249
  if ("TERM_PROGRAM" in env) {
1587
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
1250
+ const version2 = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
1588
1251
  switch (env.TERM_PROGRAM) {
1589
1252
  case "iTerm.app": {
1590
- return version >= 3 ? 3 : 2;
1253
+ return version2 >= 3 ? 3 : 2;
1591
1254
  }
1592
1255
  case "Apple_Terminal": {
1593
1256
  return 2;
@@ -2539,11 +2202,11 @@ var createBox = (options) => boxen(options.content, {
2539
2202
  titleAlignment: "center"
2540
2203
  });
2541
2204
 
2542
- // src/emit-artifact.ts
2205
+ // src/codegen.ts
2543
2206
  var randomWords = ["Sweet", "Divine", "Pandalicious", "Super"];
2544
2207
  var pickRandom = (arr) => arr[Math.floor(Math.random() * arr.length)];
2545
2208
  var limit = pLimit(20);
2546
- async function emitArtifacts(ctx, ids) {
2209
+ async function codegen(ctx, ids) {
2547
2210
  if (ctx.config.clean)
2548
2211
  ctx.output.empty();
2549
2212
  const promises = ctx.getArtifacts(ids).map((artifact) => limit(() => ctx.output.write(artifact)));
@@ -2558,28 +2221,318 @@ async function emitArtifacts(ctx, ids) {
2558
2221
  };
2559
2222
  }
2560
2223
 
2561
- // src/extract.ts
2224
+ // src/config.ts
2562
2225
  init_esm_shims();
2563
- import { logger as logger5 } from "@pandacss/logger";
2564
- function extractFile(ctx, filePath) {
2565
- const file = ctx.runtime.path.abs(ctx.config.cwd, filePath);
2566
- logger5.debug("file:extract", file);
2567
- const measure = logger5.time.debug(`Extracted ${file}`);
2568
- let result;
2569
- try {
2570
- result = ctx.project.parseSourceFile(file);
2571
- } catch (error) {
2572
- logger5.error("file:parse", error);
2573
- }
2574
- ctx.appendParserCss(result);
2575
- measure();
2576
- return result;
2577
- }
2226
+ import { convertTsPathsToRegexes, loadConfig as loadConfig2 } from "@pandacss/config";
2227
+ import { createDebugger, createHooks } from "hookable";
2228
+ import { parse } from "tsconfck";
2578
2229
 
2579
- // src/parse-dependency.ts
2230
+ // src/create-context.ts
2231
+ init_esm_shims();
2232
+ import { Generator as Generator2 } from "@pandacss/generator";
2233
+ import { logger as logger5 } from "@pandacss/logger";
2234
+ import { Project } from "@pandacss/parser";
2235
+ import { debounce } from "perfect-debounce";
2236
+
2237
+ // src/diff-engine.ts
2238
+ init_esm_shims();
2239
+ import { diffConfigs, loadConfig } from "@pandacss/config";
2240
+ import "@pandacss/generator";
2241
+ var DiffEngine = class {
2242
+ constructor(ctx) {
2243
+ this.ctx = ctx;
2244
+ this.prevConfig = ctx.conf.deserialize();
2245
+ }
2246
+ prevConfig;
2247
+ /**
2248
+ * Reload config from disk and refresh the context
2249
+ */
2250
+ async reloadConfigAndRefreshContext(fn) {
2251
+ const conf = await loadConfig({ cwd: this.ctx.config.cwd, file: this.ctx.conf.path });
2252
+ return this.refresh(conf, fn);
2253
+ }
2254
+ /**
2255
+ * Update the context from the refreshed config
2256
+ * then persist the changes on each affected engines
2257
+ * Returns the list of affected artifacts/engines
2258
+ */
2259
+ refresh(conf, fn) {
2260
+ const affected = diffConfigs(() => conf.deserialize(), this.prevConfig);
2261
+ if (!affected.hasConfigChanged || !this.prevConfig)
2262
+ return affected;
2263
+ fn?.(conf);
2264
+ this.prevConfig = conf.deserialize();
2265
+ return affected;
2266
+ }
2267
+ };
2268
+
2269
+ // src/node-runtime.ts
2270
+ init_esm_shims();
2271
+ import { logger as logger3 } from "@pandacss/logger";
2272
+ import chokidar from "chokidar";
2273
+ import glob from "fast-glob";
2274
+ import fsExtra from "fs-extra";
2275
+ import { dirname, extname, isAbsolute, join, relative, sep, resolve } from "pathe";
2276
+ var nodeRuntime = {
2277
+ cwd() {
2278
+ return process.cwd();
2279
+ },
2280
+ env(name) {
2281
+ return process.env[name];
2282
+ },
2283
+ path: {
2284
+ join,
2285
+ relative,
2286
+ dirname,
2287
+ extname,
2288
+ isAbsolute,
2289
+ sep,
2290
+ resolve,
2291
+ abs(cwd, str) {
2292
+ return isAbsolute(str) ? str : join(cwd, str);
2293
+ }
2294
+ },
2295
+ fs: {
2296
+ existsSync: fsExtra.existsSync,
2297
+ readFileSync(filePath) {
2298
+ return fsExtra.readFileSync(filePath, "utf8");
2299
+ },
2300
+ glob(opts) {
2301
+ if (!opts.include)
2302
+ return [];
2303
+ const ignore = opts.exclude ?? [];
2304
+ if (!ignore.length) {
2305
+ ignore.push("**/*.d.ts");
2306
+ }
2307
+ return glob.sync(opts.include, { cwd: opts.cwd, ignore, absolute: true });
2308
+ },
2309
+ writeFile: fsExtra.writeFile,
2310
+ writeFileSync: fsExtra.writeFileSync,
2311
+ readDirSync: fsExtra.readdirSync,
2312
+ rmDirSync: fsExtra.emptyDirSync,
2313
+ rmFileSync: fsExtra.removeSync,
2314
+ ensureDirSync(path) {
2315
+ return fsExtra.ensureDirSync(path);
2316
+ },
2317
+ watch(options) {
2318
+ const { include, exclude, cwd, poll } = options;
2319
+ const coalesce = poll || process.platform === "win32";
2320
+ const watcher = chokidar.watch(include, {
2321
+ usePolling: poll,
2322
+ cwd,
2323
+ ignoreInitial: true,
2324
+ ignorePermissionErrors: true,
2325
+ ignored: exclude,
2326
+ awaitWriteFinish: coalesce ? { stabilityThreshold: 50, pollInterval: 10 } : false
2327
+ });
2328
+ logger3.debug("watch:file", `watching [${include}]`);
2329
+ process.once("SIGINT", async () => {
2330
+ await watcher.close();
2331
+ });
2332
+ return watcher;
2333
+ }
2334
+ }
2335
+ };
2336
+ process.setMaxListeners(Infinity);
2337
+ process.on("unhandledRejection", (reason) => {
2338
+ logger3.error("\u274C", reason);
2339
+ });
2340
+ process.on("uncaughtException", (reason) => {
2341
+ logger3.error("\u274C", reason);
2342
+ });
2343
+
2344
+ // src/output-engine.ts
2345
+ init_esm_shims();
2346
+ import { logger as logger4 } from "@pandacss/logger";
2347
+ var OutputEngine = class {
2348
+ paths;
2349
+ fs;
2350
+ path;
2351
+ constructor(options) {
2352
+ const { paths, runtime } = options;
2353
+ this.paths = paths;
2354
+ this.fs = runtime.fs;
2355
+ this.path = runtime.path;
2356
+ }
2357
+ empty = () => {
2358
+ this.fs.rmDirSync(this.path.join(...this.paths.root));
2359
+ };
2360
+ ensure = (file, cwd) => {
2361
+ const outPath = this.path.resolve(cwd, file);
2362
+ const dirname2 = this.path.dirname(outPath);
2363
+ this.fs.ensureDirSync(dirname2);
2364
+ return outPath;
2365
+ };
2366
+ write = (output) => {
2367
+ if (!output)
2368
+ return;
2369
+ const { dir = this.paths.root, files } = output;
2370
+ this.fs.ensureDirSync(this.path.join(...dir));
2371
+ return Promise.allSettled(
2372
+ files.map(async (artifact) => {
2373
+ if (!artifact?.code)
2374
+ return;
2375
+ const { file, code } = artifact;
2376
+ const absPath = this.path.join(...dir, file);
2377
+ logger4.debug("write:file", dir.slice(-1).concat(file).join("/"));
2378
+ return this.fs.writeFile(absPath, code);
2379
+ })
2380
+ );
2381
+ };
2382
+ };
2383
+
2384
+ // src/create-context.ts
2385
+ var PandaContext = class extends Generator2 {
2386
+ runtime;
2387
+ project;
2388
+ output;
2389
+ diff;
2390
+ constructor(conf) {
2391
+ super(conf);
2392
+ const config = conf.config;
2393
+ this.runtime = nodeRuntime;
2394
+ config.cwd ||= this.runtime.cwd();
2395
+ if (config.logLevel) {
2396
+ logger5.level = config.logLevel;
2397
+ }
2398
+ this.project = new Project({
2399
+ ...conf.tsconfig,
2400
+ getFiles: this.getFiles.bind(this),
2401
+ readFile: this.runtime.fs.readFileSync.bind(this),
2402
+ hooks: conf.hooks,
2403
+ parserOptions: {
2404
+ ...this.parserOptions,
2405
+ join: this.runtime.path.join || this.parserOptions.join
2406
+ }
2407
+ });
2408
+ this.output = new OutputEngine(this);
2409
+ this.diff = new DiffEngine(this);
2410
+ }
2411
+ getFiles = () => {
2412
+ const { include, exclude, cwd } = this.config;
2413
+ return this.runtime.fs.glob({ include, exclude, cwd });
2414
+ };
2415
+ parseFile = (filePath, styleEncoder) => {
2416
+ const file = this.runtime.path.abs(this.config.cwd, filePath);
2417
+ logger5.debug("file:extract", file);
2418
+ const measure = logger5.time.debug(`Parsed ${file}`);
2419
+ let result;
2420
+ try {
2421
+ const encoder = styleEncoder || this.parserOptions.encoder;
2422
+ result = this.project.parseSourceFile(file, encoder);
2423
+ } catch (error) {
2424
+ logger5.error("file:extract", error);
2425
+ }
2426
+ measure();
2427
+ return result;
2428
+ };
2429
+ parseFiles = (styleEncoder) => {
2430
+ const encoder = styleEncoder || this.parserOptions.encoder;
2431
+ const files = this.getFiles();
2432
+ const filesWithCss = [];
2433
+ const results = [];
2434
+ files.forEach((file) => {
2435
+ const measure = logger5.time.debug(`Parsed ${file}`);
2436
+ const result = this.project.parseSourceFile(file, encoder);
2437
+ measure();
2438
+ if (!result || result.isEmpty() || encoder.isEmpty())
2439
+ return;
2440
+ filesWithCss.push(file);
2441
+ results.push(result);
2442
+ });
2443
+ return {
2444
+ filesWithCss,
2445
+ files,
2446
+ results
2447
+ };
2448
+ };
2449
+ writeCss = (sheet) => {
2450
+ return this.output.write({
2451
+ id: "styles.css",
2452
+ dir: this.paths.root,
2453
+ files: [{ file: "styles.css", code: this.getCss(sheet) }]
2454
+ });
2455
+ };
2456
+ watchConfig = (cb, opts) => {
2457
+ const { cwd, poll, exclude } = opts ?? {};
2458
+ logger5.info("ctx:watch", this.messages.configWatch());
2459
+ const watcher = this.runtime.fs.watch({
2460
+ include: this.conf.dependencies,
2461
+ exclude,
2462
+ cwd,
2463
+ poll
2464
+ });
2465
+ watcher.on(
2466
+ "change",
2467
+ debounce(async () => {
2468
+ logger5.info("ctx:change", "config changed, rebuilding...");
2469
+ await cb();
2470
+ })
2471
+ );
2472
+ };
2473
+ watchFiles = (cb) => {
2474
+ const { include, exclude, poll, cwd } = this.config;
2475
+ logger5.info("ctx:watch", this.messages.watch());
2476
+ const watcher = this.runtime.fs.watch({
2477
+ include,
2478
+ exclude,
2479
+ poll,
2480
+ cwd
2481
+ });
2482
+ watcher.on(
2483
+ "all",
2484
+ debounce(async (event, file) => {
2485
+ logger5.info(`file:${event}`, file);
2486
+ await cb(event, file);
2487
+ })
2488
+ );
2489
+ };
2490
+ };
2491
+
2492
+ // src/config.ts
2493
+ async function loadConfigAndCreateContext(options = {}) {
2494
+ const { config, configPath } = options;
2495
+ const cwd = options.cwd ?? options?.config?.cwd ?? process.cwd();
2496
+ const conf = await loadConfig2({ cwd, file: configPath });
2497
+ if (config) {
2498
+ Object.assign(conf.config, config);
2499
+ }
2500
+ if (options.cwd) {
2501
+ conf.config.cwd = options.cwd;
2502
+ }
2503
+ const tsconfigResult = await parse(conf.path, {
2504
+ root: cwd,
2505
+ // @ts-ignore
2506
+ resolveWithEmptyIfConfigNotFound: true
2507
+ });
2508
+ if (tsconfigResult) {
2509
+ conf.tsconfig = tsconfigResult.tsconfig;
2510
+ conf.tsconfigFile = tsconfigResult.tsconfigFile;
2511
+ const options2 = tsconfigResult.tsconfig?.compilerOptions;
2512
+ if (options2?.paths) {
2513
+ const baseUrl = options2.baseUrl;
2514
+ conf.tsOptions = {
2515
+ baseUrl,
2516
+ pathMappings: convertTsPathsToRegexes(options2.paths, baseUrl ?? cwd)
2517
+ };
2518
+ }
2519
+ }
2520
+ conf.config.outdir ??= "styled-system";
2521
+ const hooks = createHooks();
2522
+ if (conf.config.hooks) {
2523
+ hooks.addHooks(conf.config.hooks);
2524
+ }
2525
+ await hooks.callHook("config:resolved", conf);
2526
+ if (conf.config.logLevel === "debug") {
2527
+ createDebugger(hooks, { tag: "panda" });
2528
+ }
2529
+ return new PandaContext({ ...conf, hooks });
2530
+ }
2531
+
2532
+ // src/parse-dependency.ts
2580
2533
  init_esm_shims();
2581
2534
  import isGlob from "is-glob";
2582
- import { resolve } from "pathe";
2535
+ import { resolve as resolve2 } from "pathe";
2583
2536
 
2584
2537
  // src/parse-glob.ts
2585
2538
  init_esm_shims();
@@ -2610,9 +2563,9 @@ function parseDependency(fileOrGlob) {
2610
2563
  let message = null;
2611
2564
  if (isGlob(fileOrGlob)) {
2612
2565
  const { base, glob: glob2 } = parseGlob(fileOrGlob);
2613
- message = { type: "dir-dependency", dir: resolve(base), glob: glob2 };
2566
+ message = { type: "dir-dependency", dir: resolve2(base), glob: glob2 };
2614
2567
  } else {
2615
- message = { type: "dependency", file: resolve(fileOrGlob) };
2568
+ message = { type: "dependency", file: resolve2(fileOrGlob) };
2616
2569
  }
2617
2570
  if (message.type === "dir-dependency" && process.env.ROLLUP_WATCH === "true") {
2618
2571
  message = { type: "dependency", file: message.dir };
@@ -2621,18 +2574,17 @@ function parseDependency(fileOrGlob) {
2621
2574
  }
2622
2575
 
2623
2576
  // src/builder.ts
2624
- var parserResultMap = /* @__PURE__ */ new Map();
2625
2577
  var fileModifiedMap = /* @__PURE__ */ new Map();
2626
- var limit2 = pLimit(20);
2627
2578
  var Builder = class {
2628
2579
  /**
2629
2580
  * The current panda context
2630
2581
  */
2631
2582
  context;
2632
2583
  hasEmitted = false;
2584
+ filesMeta;
2633
2585
  affecteds;
2634
- getConfigPath = () => {
2635
- const configPath = findConfig();
2586
+ getConfigPath = (cwd) => {
2587
+ const configPath = findConfig({ cwd });
2636
2588
  if (!configPath) {
2637
2589
  throw new ConfigNotFoundError();
2638
2590
  }
@@ -2640,35 +2592,36 @@ var Builder = class {
2640
2592
  };
2641
2593
  setup = async (options = {}) => {
2642
2594
  logger6.debug("builder", "\u{1F6A7} Setup");
2643
- const configPath = options.configPath ?? this.getConfigPath();
2595
+ const configPath = options.configPath ?? this.getConfigPath(options.cwd);
2644
2596
  if (!this.context) {
2645
2597
  return this.setupContext({ configPath, cwd: options.cwd });
2646
2598
  }
2647
2599
  const ctx = this.getContextOrThrow();
2648
2600
  this.affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2649
2601
  this.context = new PandaContext({ ...conf, hooks: ctx.hooks });
2650
- this.context.appendBaselineCss();
2651
2602
  });
2603
+ logger6.debug("builder", this.affecteds);
2652
2604
  if (this.affecteds.hasConfigChanged) {
2653
2605
  logger6.debug("builder", "\u2699\uFE0F Config changed, reloading");
2654
2606
  await ctx.hooks.callHook("config:change", ctx.config);
2655
2607
  return;
2656
2608
  }
2657
- const hasFilesChanged = this.checkFilesChanged(ctx.getFiles());
2658
- if (hasFilesChanged) {
2609
+ this.filesMeta = this.checkFilesChanged(ctx.getFiles());
2610
+ if (this.filesMeta.hasFilesChanged) {
2611
+ logger6.debug("builder", "Files changed, invalidating them");
2659
2612
  ctx.project.reloadSourceFiles();
2660
2613
  }
2661
2614
  };
2662
2615
  async emit() {
2663
2616
  if (this.hasEmitted && this.affecteds?.hasConfigChanged) {
2664
- await emitArtifacts(this.getContextOrThrow(), Array.from(this.affecteds.artifacts));
2617
+ logger6.debug("builder", "Emit artifacts after config change");
2618
+ await codegen(this.getContextOrThrow(), Array.from(this.affecteds.artifacts));
2665
2619
  }
2666
2620
  this.hasEmitted = true;
2667
2621
  }
2668
2622
  setupContext = async (options) => {
2669
2623
  const { configPath, cwd } = options;
2670
2624
  const ctx = await loadConfigAndCreateContext({ configPath, cwd });
2671
- ctx.appendBaselineCss();
2672
2625
  this.context = ctx;
2673
2626
  return ctx;
2674
2627
  };
@@ -2679,62 +2632,68 @@ var Builder = class {
2679
2632
  return this.context;
2680
2633
  };
2681
2634
  getFileMeta = (file) => {
2682
- const mtime = existsSync(file) ? fsExtra2.statSync(file).mtimeMs : -Infinity;
2635
+ const mtime = existsSync(file) ? statSync(file).mtimeMs : -Infinity;
2683
2636
  const isUnchanged = fileModifiedMap.has(file) && mtime === fileModifiedMap.get(file);
2684
2637
  return { mtime, isUnchanged };
2685
2638
  };
2686
- extractFile = async (ctx, file) => {
2687
- const meta = this.getFileMeta(file);
2688
- if (meta.isUnchanged) {
2689
- ctx.appendParserCss(parserResultMap.get(file));
2690
- return;
2639
+ checkFilesChanged(files) {
2640
+ const changes = /* @__PURE__ */ new Map();
2641
+ let hasFilesChanged = false;
2642
+ for (const file of files) {
2643
+ const meta = this.getFileMeta(file);
2644
+ changes.set(file, meta);
2645
+ if (!meta.isUnchanged) {
2646
+ hasFilesChanged = true;
2647
+ }
2691
2648
  }
2692
- const result = extractFile(ctx, file);
2649
+ return { changes, hasFilesChanged };
2650
+ }
2651
+ extractFile = (ctx, file) => {
2652
+ const meta = this.filesMeta?.changes.get(file) ?? this.getFileMeta(file);
2653
+ const hasConfigChanged = this.affecteds ? this.affecteds.hasConfigChanged : true;
2654
+ if (meta.isUnchanged && !hasConfigChanged)
2655
+ return;
2656
+ const parserResult = ctx.parseFile(file);
2693
2657
  fileModifiedMap.set(file, meta.mtime);
2694
- if (result) {
2695
- parserResultMap.set(file, result);
2696
- }
2697
- return result;
2658
+ return parserResult;
2698
2659
  };
2699
- checkFilesChanged(files) {
2700
- return files.some((file) => !this.getFileMeta(file).isUnchanged);
2701
- }
2702
- extract = async () => {
2660
+ extract = () => {
2661
+ const hasConfigChanged = this.affecteds ? this.affecteds.hasConfigChanged : true;
2662
+ if (!this.filesMeta && !hasConfigChanged) {
2663
+ logger6.debug("builder", "No files or config changed, skipping extract");
2664
+ return;
2665
+ }
2703
2666
  const ctx = this.getContextOrThrow();
2704
2667
  const files = ctx.getFiles();
2705
- const hasConfigChanged = this.affecteds ? this.affecteds.hasConfigChanged : false;
2706
- if (hasConfigChanged)
2707
- return;
2708
2668
  const done = logger6.time.info("Extracted in");
2709
- const promises = files.map((file) => limit2(() => this.extractFile(ctx, file)));
2710
- await Promise.allSettled(promises);
2669
+ files.map((file) => this.extractFile(ctx, file));
2711
2670
  done();
2712
2671
  };
2713
- toString = () => {
2714
- const ctx = this.getContextOrThrow();
2715
- return ctx.getCss();
2716
- };
2717
2672
  isValidRoot = (root) => {
2718
2673
  const ctx = this.getContextOrThrow();
2719
2674
  let valid = false;
2720
2675
  root.walkAtRules("layer", (rule) => {
2721
- if (ctx.layers.isValidParams(rule.params)) {
2676
+ if (ctx.isValidLayerParams(rule.params)) {
2722
2677
  valid = true;
2723
2678
  }
2724
2679
  });
2725
2680
  return valid;
2726
2681
  };
2727
- initialRoot;
2728
2682
  write = (root) => {
2729
- if (!this.initialRoot) {
2730
- this.initialRoot = root.toString();
2731
- }
2683
+ const rootCssContent = root.toString();
2732
2684
  root.removeAll();
2733
- const newCss = optimizeCss(`
2734
- ${this.initialRoot}
2735
- ${this.toString()}
2736
- `);
2737
- root.append(newCss);
2685
+ const ctx = this.getContextOrThrow();
2686
+ const sheet = ctx.createSheet();
2687
+ ctx.appendLayerParams(sheet);
2688
+ ctx.appendBaselineCss(sheet);
2689
+ ctx.appendParserCss(sheet);
2690
+ const css = ctx.getCss(sheet);
2691
+ root.append(
2692
+ optimizeCss(`
2693
+ ${rootCssContent}
2694
+ ${css}
2695
+ `)
2696
+ );
2738
2697
  };
2739
2698
  registerDependency = (fn) => {
2740
2699
  const ctx = this.getContextOrThrow();
@@ -2745,23 +2704,64 @@ var Builder = class {
2745
2704
  }
2746
2705
  }
2747
2706
  for (const file of ctx.conf.dependencies) {
2748
- fn({ type: "dependency", file: resolve2(file) });
2707
+ fn({ type: "dependency", file: ctx.runtime.path.resolve(file) });
2749
2708
  }
2750
2709
  };
2751
2710
  };
2752
2711
 
2753
- // src/debug-files.ts
2712
+ // src/cssgen.ts
2713
+ init_esm_shims();
2714
+ import { logger as logger7 } from "@pandacss/logger";
2715
+ var cssgen = async (ctx, options) => {
2716
+ const { cwd, outfile, type, minimal } = options;
2717
+ let outPath = ctx.runtime.path.join(...ctx.paths.getFilePath("styles.css"));
2718
+ const sheet = ctx.createSheet();
2719
+ if (type) {
2720
+ ctx.appendCssOfType(type, sheet);
2721
+ if (outfile) {
2722
+ outPath = ctx.output.ensure(outfile, cwd);
2723
+ const css = ctx.getCss(sheet);
2724
+ ctx.runtime.fs.writeFileSync(outfile, css);
2725
+ } else {
2726
+ await ctx.writeCss(sheet);
2727
+ }
2728
+ const msg = ctx.messages.cssArtifactComplete(type);
2729
+ logger7.info("css:emit:path", outPath);
2730
+ logger7.info("css:emit:artifact", msg);
2731
+ } else {
2732
+ if (!minimal) {
2733
+ ctx.appendLayerParams(sheet);
2734
+ ctx.appendBaselineCss(sheet);
2735
+ }
2736
+ const { files } = ctx.parseFiles();
2737
+ ctx.appendParserCss(sheet);
2738
+ if (outfile) {
2739
+ outPath = ctx.output.ensure(outfile, cwd);
2740
+ const css = ctx.getCss(sheet);
2741
+ ctx.runtime.fs.writeFileSync(outfile, css);
2742
+ } else {
2743
+ await ctx.writeCss(sheet);
2744
+ }
2745
+ const msg = ctx.messages.buildComplete(files.length);
2746
+ logger7.info("css:emit:path", outPath);
2747
+ logger7.info("css:emit:out", msg);
2748
+ }
2749
+ };
2750
+
2751
+ // src/debug.ts
2754
2752
  init_esm_shims();
2755
- import { colors, logger as logger7 } from "@pandacss/logger";
2753
+ import { colors as colors2, logger as logger8 } from "@pandacss/logger";
2756
2754
  import { parse as parse2 } from "pathe";
2757
- async function debugFiles(ctx, options) {
2755
+ async function debug(ctx, options) {
2758
2756
  const files = ctx.getFiles();
2759
- const measureTotal = logger7.time.debug(`Done parsing ${files.length} files`);
2760
- const { fs, path: path2 } = ctx.runtime;
2757
+ const measureTotal = logger8.time.debug(`Done parsing ${files.length} files`);
2758
+ ctx.config.minify = false;
2759
+ ctx.config.optimize = true;
2760
+ const { fs, path } = ctx.runtime;
2761
2761
  const outdir = options.outdir;
2762
2762
  if (!options.dry && outdir) {
2763
2763
  fs.ensureDirSync(outdir);
2764
- logger7.info("cli", `Writing ${colors.bold(`${outdir}/config.json`)}`);
2764
+ logger8.info("cli", `Writing ${colors2.bold(`${outdir}/config.json`)}`);
2765
2765
  await fs.writeFile(`${outdir}/config.json`, JSON.stringify(ctx.config, null, 2));
2766
2766
  }
2767
2767
  if (options.onlyConfig) {
@@ -2769,77 +2769,61 @@ async function debugFiles(ctx, options) {
2769
2769
  return;
2770
2770
  }
2771
2771
  const filesWithCss = [];
2772
- const results = await Promise.all(
2773
- files.map(async (file) => {
2774
- const measure = logger7.time.debug(`Parsed ${file}`);
2775
- const result = ctx.project.parseSourceFile(file);
2776
- measure();
2777
- return { file, result };
2778
- })
2779
- );
2780
- results.forEach(({ file, result }) => {
2781
- if (!result)
2772
+ files.map((file) => {
2773
+ const measure = logger8.time.debug(`Parsed ${file}`);
2774
+ const encoder = ctx.encoder.clone();
2775
+ const result = ctx.project.parseSourceFile(file, encoder);
2776
+ measure();
2777
+ if (!result || result.isEmpty() || encoder.isEmpty())
2778
+ return;
2779
+ const styles4 = ctx.decoder.clone().collect(encoder);
2780
+ const css = ctx.getParserCss(styles4, file);
2781
+ if (!css)
2782
2782
  return;
2783
- ctx.stylesheet.clean();
2784
- ctx.appendParserCss(result);
2785
- const css2 = ctx.stylesheet.toCss({ optimize: true, minify: false });
2786
2783
  if (options.dry) {
2787
- console.log({ path: file, ast: result, code: css2 });
2784
+ console.log({ path: file, ast: result, code: css });
2785
+ return;
2788
2786
  }
2789
2787
  if (outdir) {
2790
2788
  filesWithCss.push(file);
2791
2789
  const parsedPath = parse2(file);
2792
- const relative3 = path2.relative(ctx.config.cwd, parsedPath.dir);
2793
- const astJsonPath = `${relative3}/${parsedPath.name}.ast.json`.replaceAll(path2.sep, "__");
2794
- const cssPath = `${relative3}/${parsedPath.name}.css`.replaceAll(path2.sep, "__");
2795
- logger7.info("cli", `Writing ${colors.bold(`${outdir}/${astJsonPath}`)}`);
2796
- logger7.info("cli", `Writing ${colors.bold(`${outdir}/${cssPath}`)}`);
2790
+ const relative2 = path.relative(ctx.config.cwd, parsedPath.dir);
2791
+ const astJsonPath = `${relative2}/${parsedPath.name}.ast.json`.replaceAll(path.sep, "__");
2792
+ const cssPath = `${relative2}/${parsedPath.name}.css`.replaceAll(path.sep, "__");
2793
+ logger8.info("cli", `Writing ${colors2.bold(`${outdir}/${astJsonPath}`)}`);
2794
+ logger8.info("cli", `Writing ${colors2.bold(`${outdir}/${cssPath}`)}`);
2797
2795
  return Promise.allSettled([
2798
2796
  fs.writeFile(`${outdir}/${astJsonPath}`, JSON.stringify(result.toJSON(), null, 2)),
2799
- fs.writeFile(`${outdir}/${cssPath}`, css2)
2797
+ fs.writeFile(`${outdir}/${cssPath}`, css)
2800
2798
  ]);
2801
2799
  }
2802
2800
  });
2803
- logger7.info("cli", `Found ${colors.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2801
+ logger8.info("cli", `Found ${colors2.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2804
2802
  measureTotal();
2805
2803
  }
2806
2804
 
2807
- // src/exec-command.ts
2808
- init_esm_shims();
2809
- import { logger as logger8 } from "@pandacss/logger";
2810
- import { spawnSync } from "child_process";
2811
- import getPackageManager from "preferred-pm";
2812
- async function execCommand(cmd, cwd) {
2813
- const manager = await getPackageManager(cwd);
2814
- const pm = manager?.name ?? "npm";
2815
- const args = cmd.split(" ");
2816
- if (pm === "npm") {
2817
- args.unshift("run");
2818
- }
2819
- const check = spawnSync(pm, args, { cwd, stdio: "pipe" });
2820
- if (check.status !== 0) {
2821
- logger8.error("exec", check.stderr.toString());
2822
- }
2823
- }
2824
-
2825
2805
  // src/generate.ts
2826
2806
  init_esm_shims();
2827
2807
  import { logger as logger9 } from "@pandacss/logger";
2828
2808
  import { match } from "ts-pattern";
2829
- async function build(ctx, ids) {
2830
- await emitArtifacts(ctx, ids);
2809
+ async function build(ctx, artifactIds) {
2810
+ await codegen(ctx, artifactIds);
2831
2811
  if (ctx.config.emitTokensOnly) {
2832
2812
  return logger9.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens \u2728");
2833
2813
  }
2834
- ctx.appendAllCss();
2835
- await ctx.writeCss();
2814
+ const sheet = ctx.createSheet();
2815
+ ctx.appendLayerParams(sheet);
2816
+ ctx.appendBaselineCss(sheet);
2817
+ ctx.parseFiles();
2818
+ ctx.appendParserCss(sheet);
2819
+ await ctx.writeCss(sheet);
2836
2820
  logger9.info("css:emit", "Successfully built the css files \u2728");
2837
2821
  }
2838
2822
  async function generate(config, configPath) {
2839
2823
  let ctx = await loadConfigAndCreateContext({ config, configPath });
2840
2824
  await build(ctx);
2841
2825
  const {
2842
- runtime: { fs, path: path2 },
2826
+ runtime: { fs, path },
2843
2827
  config: { cwd }
2844
2828
  } = ctx;
2845
2829
  if (ctx.config.watch) {
@@ -2848,27 +2832,39 @@ async function generate(config, configPath) {
2848
2832
  const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2849
2833
  ctx = new PandaContext({ ...conf, hooks: ctx.hooks });
2850
2834
  });
2851
- if (!affecteds.artifacts.size)
2835
+ if (!affecteds.hasConfigChanged) {
2836
+ logger9.debug("builder", "Config didnt change, skipping rebuild");
2852
2837
  return;
2838
+ }
2853
2839
  logger9.info("config:change", "Config changed, restarting...");
2854
2840
  await ctx.hooks.callHook("config:change", ctx.config);
2855
2841
  return build(ctx, Array.from(affecteds.artifacts));
2856
2842
  });
2857
2843
  const contentWatcher = fs.watch(ctx.config);
2844
+ const bundleStyles = async (ctx2, changedFilePath) => {
2845
+ const outfile = ctx2.runtime.path.join(...ctx2.paths.root, "styles.css");
2846
+ const parserResult = ctx2.project.parseSourceFile(changedFilePath);
2847
+ if (parserResult) {
2848
+ const sheet = ctx2.createSheet();
2849
+ ctx2.appendLayerParams(sheet);
2850
+ ctx2.appendBaselineCss(sheet);
2851
+ ctx2.appendParserCss(sheet);
2852
+ const css = ctx2.getCss(sheet);
2853
+ await ctx2.runtime.fs.writeFile(outfile, css);
2854
+ return { msg: ctx2.messages.buildComplete(1) };
2855
+ }
2856
+ };
2858
2857
  contentWatcher.on("all", async (event, file) => {
2859
2858
  logger9.info(`file:${event}`, file);
2860
- await match(event).with("unlink", () => {
2861
- ctx.project.removeSourceFile(path2.abs(cwd, file));
2862
- }).with("change", () => {
2859
+ const filePath = path.abs(cwd, file);
2860
+ match(event).with("unlink", () => {
2861
+ ctx.project.removeSourceFile(path.abs(cwd, file));
2862
+ }).with("change", async () => {
2863
2863
  ctx.project.reloadSourceFile(file);
2864
- const result = ctx.project.parseSourceFile(file);
2865
- ctx.appendParserCss(result);
2866
- return ctx.writeCss();
2867
- }).with("add", () => {
2864
+ return bundleStyles(ctx, filePath);
2865
+ }).with("add", async () => {
2868
2866
  ctx.project.createSourceFile(file);
2869
- const result = ctx.project.parseSourceFile(file);
2870
- ctx.appendParserCss(result);
2871
- return ctx.writeCss();
2867
+ return bundleStyles(ctx, filePath);
2872
2868
  }).otherwise(() => {
2873
2869
  });
2874
2870
  });
@@ -2879,7 +2875,7 @@ async function generate(config, configPath) {
2879
2875
  // src/git-ignore.ts
2880
2876
  init_esm_shims();
2881
2877
  import { appendFileSync, readFileSync, writeFileSync } from "fs";
2882
- import { lookItUpSync as lookItUpSync2 } from "look-it-up";
2878
+ import { lookItUpSync } from "look-it-up";
2883
2879
  import outdent from "outdent";
2884
2880
  function setupGitIgnore(ctx) {
2885
2881
  const { outdir, gitignore } = ctx.config;
@@ -2891,7 +2887,7 @@ function setupGitIgnore(ctx) {
2891
2887
  ${outdir}
2892
2888
  ${ctx.studio.outdir}
2893
2889
  `;
2894
- const file = lookItUpSync2(".gitignore");
2890
+ const file = lookItUpSync(".gitignore");
2895
2891
  if (!file) {
2896
2892
  return writeFileSync(".gitignore", txt);
2897
2893
  }
@@ -2903,21 +2899,22 @@ function setupGitIgnore(ctx) {
2903
2899
 
2904
2900
  // src/setup-config.ts
2905
2901
  init_esm_shims();
2902
+ import { findConfig as findConfig2 } from "@pandacss/config";
2906
2903
  import { messages } from "@pandacss/generator";
2907
2904
  import { logger as logger10, quote } from "@pandacss/logger";
2908
- import fsExtra3 from "fs-extra";
2909
- import { lookItUpSync as lookItUpSync3 } from "look-it-up";
2905
+ import fsExtra2 from "fs-extra";
2906
+ import { lookItUpSync as lookItUpSync2 } from "look-it-up";
2910
2907
  import { outdent as outdent2 } from "outdent";
2911
2908
  import { join as join2 } from "pathe";
2912
- import getPackageManager2 from "preferred-pm";
2909
+ import getPackageManager from "preferred-pm";
2913
2910
  import prettier from "prettier";
2914
2911
  async function setupConfig(cwd, opts = {}) {
2915
2912
  const { force, outExtension, jsxFramework, syntax } = opts;
2916
- const configFile = findConfig();
2917
- const pmResult = await getPackageManager2(cwd);
2913
+ const configFile = findConfig2({ cwd });
2914
+ const pmResult = await getPackageManager(cwd);
2918
2915
  const pm = pmResult?.name ?? "npm";
2919
2916
  const cmd = pm === "npm" ? "npm run" : pm;
2920
- const isTs = lookItUpSync3("tsconfig.json", cwd);
2917
+ const isTs = lookItUpSync2("tsconfig.json", cwd);
2921
2918
  const file = isTs ? "panda.config.ts" : "panda.config.mjs";
2922
2919
  logger10.info("init:config", `creating panda config file: ${quote(file)}`);
2923
2920
  if (!force && configFile) {
@@ -2953,7 +2950,7 @@ jsxFramework: '${jsxFramework}',` : ""}
2953
2950
  syntax: '${syntax}'` : ""}
2954
2951
  })
2955
2952
  `;
2956
- await fsExtra3.writeFile(join2(cwd, file), prettier.format(content));
2953
+ await fsExtra2.writeFile(join2(cwd, file), prettier.format(content));
2957
2954
  logger10.log(messages.thankYou());
2958
2955
  }
2959
2956
  }
@@ -2966,50 +2963,21 @@ module.exports = {
2966
2963
  },
2967
2964
  }
2968
2965
  `;
2969
- await fsExtra3.writeFile(join2(cwd, "postcss.config.cjs"), content);
2970
- }
2971
-
2972
- // src/ship-files.ts
2973
- init_esm_shims();
2974
- import { colors as colors2, logger as logger11 } from "@pandacss/logger";
2975
- import { createParserResult as createParserResult2 } from "@pandacss/parser";
2976
- import { writeFile as writeFile2 } from "fs/promises";
2977
- import * as path from "pathe";
2978
- async function shipFiles(ctx, outfile) {
2979
- const files = ctx.getFiles();
2980
- const extractResult = createParserResult2();
2981
- const filesWithCss = [];
2982
- files.forEach(async (file) => {
2983
- const result = ctx.project.parseSourceFile(file);
2984
- if (!result || result.isEmpty())
2985
- return;
2986
- extractResult.merge(result);
2987
- filesWithCss.push(path.relative(ctx.config.cwd, file));
2988
- });
2989
- logger11.info("cli", `Found ${colors2.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2990
- const minify = ctx.config.minify;
2991
- logger11.info("cli", `Writing ${minify ? "[min] " : " "}${colors2.bold(outfile)}`);
2992
- const output = JSON.stringify(extractResult.toJSON(), null, minify ? 0 : 2);
2993
- const dirname2 = ctx.runtime.path.dirname(outfile);
2994
- ctx.runtime.fs.ensureDirSync(dirname2);
2995
- await writeFile2(outfile, output);
2996
- logger11.info("cli", "Done!");
2966
+ await fsExtra2.writeFile(join2(cwd, "postcss.config.cjs"), content);
2997
2967
  }
2998
2968
  export {
2999
2969
  Builder,
3000
2970
  PandaContext,
3001
2971
  analyzeTokens,
3002
- debugFiles,
3003
- emitArtifacts,
3004
- execCommand,
3005
- extractFile,
3006
- findConfig,
2972
+ buildInfo,
2973
+ codegen,
2974
+ cssgen,
2975
+ debug,
3007
2976
  generate,
3008
2977
  loadConfigAndCreateContext,
3009
2978
  parseDependency,
3010
2979
  setupConfig,
3011
2980
  setupGitIgnore,
3012
2981
  setupPostcss,
3013
- shipFiles,
3014
2982
  writeAnalyzeJSON
3015
2983
  };