@pandacss/node 0.23.0 → 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,19 +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;
2633
- hasFilesChanged = true;
2584
+ filesMeta;
2634
2585
  affecteds;
2635
- getConfigPath = () => {
2636
- const configPath = findConfig();
2586
+ getConfigPath = (cwd) => {
2587
+ const configPath = findConfig({ cwd });
2637
2588
  if (!configPath) {
2638
2589
  throw new ConfigNotFoundError();
2639
2590
  }
@@ -2641,14 +2592,13 @@ var Builder = class {
2641
2592
  };
2642
2593
  setup = async (options = {}) => {
2643
2594
  logger6.debug("builder", "\u{1F6A7} Setup");
2644
- const configPath = options.configPath ?? this.getConfigPath();
2595
+ const configPath = options.configPath ?? this.getConfigPath(options.cwd);
2645
2596
  if (!this.context) {
2646
2597
  return this.setupContext({ configPath, cwd: options.cwd });
2647
2598
  }
2648
2599
  const ctx = this.getContextOrThrow();
2649
2600
  this.affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2650
2601
  this.context = new PandaContext({ ...conf, hooks: ctx.hooks });
2651
- this.context.appendBaselineCss();
2652
2602
  });
2653
2603
  logger6.debug("builder", this.affecteds);
2654
2604
  if (this.affecteds.hasConfigChanged) {
@@ -2656,8 +2606,8 @@ var Builder = class {
2656
2606
  await ctx.hooks.callHook("config:change", ctx.config);
2657
2607
  return;
2658
2608
  }
2659
- this.hasFilesChanged = this.checkFilesChanged(ctx.getFiles());
2660
- if (this.hasFilesChanged) {
2609
+ this.filesMeta = this.checkFilesChanged(ctx.getFiles());
2610
+ if (this.filesMeta.hasFilesChanged) {
2661
2611
  logger6.debug("builder", "Files changed, invalidating them");
2662
2612
  ctx.project.reloadSourceFiles();
2663
2613
  }
@@ -2665,14 +2615,13 @@ var Builder = class {
2665
2615
  async emit() {
2666
2616
  if (this.hasEmitted && this.affecteds?.hasConfigChanged) {
2667
2617
  logger6.debug("builder", "Emit artifacts after config change");
2668
- await emitArtifacts(this.getContextOrThrow(), Array.from(this.affecteds.artifacts));
2618
+ await codegen(this.getContextOrThrow(), Array.from(this.affecteds.artifacts));
2669
2619
  }
2670
2620
  this.hasEmitted = true;
2671
2621
  }
2672
2622
  setupContext = async (options) => {
2673
2623
  const { configPath, cwd } = options;
2674
2624
  const ctx = await loadConfigAndCreateContext({ configPath, cwd });
2675
- ctx.appendBaselineCss();
2676
2625
  this.context = ctx;
2677
2626
  return ctx;
2678
2627
  };
@@ -2683,65 +2632,68 @@ var Builder = class {
2683
2632
  return this.context;
2684
2633
  };
2685
2634
  getFileMeta = (file) => {
2686
- const mtime = existsSync(file) ? fsExtra2.statSync(file).mtimeMs : -Infinity;
2635
+ const mtime = existsSync(file) ? statSync(file).mtimeMs : -Infinity;
2687
2636
  const isUnchanged = fileModifiedMap.has(file) && mtime === fileModifiedMap.get(file);
2688
2637
  return { mtime, isUnchanged };
2689
2638
  };
2690
- extractFile = async (ctx, file) => {
2691
- const meta = this.getFileMeta(file);
2692
- if (meta.isUnchanged && this.affecteds?.hasConfigChanged) {
2693
- ctx.appendParserCss(parserResultMap.get(file));
2694
- 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
+ }
2695
2648
  }
2696
- 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);
2697
2657
  fileModifiedMap.set(file, meta.mtime);
2698
- if (result) {
2699
- parserResultMap.set(file, result);
2700
- }
2701
- return result;
2658
+ return parserResult;
2702
2659
  };
2703
- checkFilesChanged(files) {
2704
- return files.some((file) => !this.getFileMeta(file).isUnchanged);
2705
- }
2706
- extract = async () => {
2660
+ extract = () => {
2707
2661
  const hasConfigChanged = this.affecteds ? this.affecteds.hasConfigChanged : true;
2708
- if (!this.hasFilesChanged && !hasConfigChanged) {
2662
+ if (!this.filesMeta && !hasConfigChanged) {
2709
2663
  logger6.debug("builder", "No files or config changed, skipping extract");
2710
2664
  return;
2711
2665
  }
2712
2666
  const ctx = this.getContextOrThrow();
2713
2667
  const files = ctx.getFiles();
2714
2668
  const done = logger6.time.info("Extracted in");
2715
- const promises = files.map((file) => limit2(() => this.extractFile(ctx, file)));
2716
- await Promise.allSettled(promises);
2669
+ files.map((file) => this.extractFile(ctx, file));
2717
2670
  done();
2718
2671
  };
2719
- toString = () => {
2720
- const ctx = this.getContextOrThrow();
2721
- return ctx.getCss();
2722
- };
2723
2672
  isValidRoot = (root) => {
2724
2673
  const ctx = this.getContextOrThrow();
2725
2674
  let valid = false;
2726
2675
  root.walkAtRules("layer", (rule) => {
2727
- if (ctx.layers.isValidParams(rule.params)) {
2676
+ if (ctx.isValidLayerParams(rule.params)) {
2728
2677
  valid = true;
2729
2678
  }
2730
2679
  });
2731
2680
  return valid;
2732
2681
  };
2733
- initialRoot;
2734
2682
  write = (root) => {
2735
- if (!this.initialRoot) {
2736
- this.initialRoot = root.toString();
2737
- }
2683
+ const rootCssContent = root.toString();
2738
2684
  root.removeAll();
2739
- const css2 = this.toString();
2740
- const newCss = optimizeCss(`
2741
- ${this.initialRoot}
2742
- ${css2}
2743
- `);
2744
- 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
+ );
2745
2697
  };
2746
2698
  registerDependency = (fn) => {
2747
2699
  const ctx = this.getContextOrThrow();
@@ -2752,98 +2704,126 @@ var Builder = class {
2752
2704
  }
2753
2705
  }
2754
2706
  for (const file of ctx.conf.dependencies) {
2755
- fn({ type: "dependency", file: resolve2(file) });
2707
+ fn({ type: "dependency", file: ctx.runtime.path.resolve(file) });
2756
2708
  }
2757
2709
  };
2758
2710
  };
2759
2711
 
2760
- // 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
2761
2752
  init_esm_shims();
2762
- import { colors, logger as logger7 } from "@pandacss/logger";
2753
+ import { colors as colors2, logger as logger8 } from "@pandacss/logger";
2763
2754
  import { parse as parse2 } from "pathe";
2764
- async function debugFiles(ctx, options) {
2755
+ async function debug(ctx, options) {
2765
2756
  const files = ctx.getFiles();
2766
- const measureTotal = logger7.time.debug(`Done parsing ${files.length} files`);
2767
- 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;
2768
2761
  const outdir = options.outdir;
2769
2762
  if (!options.dry && outdir) {
2770
2763
  fs.ensureDirSync(outdir);
2771
- logger7.info("cli", `Writing ${colors.bold(`${outdir}/config.json`)}`);
2764
+ logger8.info("cli", `Writing ${colors2.bold(`${outdir}/config.json`)}`);
2772
2765
  await fs.writeFile(`${outdir}/config.json`, JSON.stringify(ctx.config, null, 2));
2773
2766
  }
2774
2767
  if (options.onlyConfig) {
2775
2768
  measureTotal();
2776
2769
  return;
2777
2770
  }
2778
- const results = await Promise.all(
2779
- files.map(async (file) => {
2780
- const measure = logger7.time.debug(`Parsed ${file}`);
2781
- const result = ctx.project.parseSourceFile(file);
2782
- measure();
2783
- return { file, result };
2784
- })
2785
- );
2786
- const filteredResults = results.filter(({ result }) => result && !result.isEmpty());
2787
- filteredResults.forEach(({ file, result }) => {
2788
- ctx.stylesheet.clean();
2789
- ctx.appendParserCss(result);
2790
- const css2 = ctx.stylesheet.toCss({ optimize: true, minify: false });
2771
+ const filesWithCss = [];
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
+ return;
2791
2783
  if (options.dry) {
2792
- console.log({ path: file, ast: result, code: css2 });
2784
+ console.log({ path: file, ast: result, code: css });
2785
+ return;
2793
2786
  }
2794
2787
  if (outdir) {
2788
+ filesWithCss.push(file);
2795
2789
  const parsedPath = parse2(file);
2796
- const relative3 = path2.relative(ctx.config.cwd, parsedPath.dir);
2797
- const astJsonPath = `${relative3}/${parsedPath.name}.ast.json`.replaceAll(path2.sep, "__");
2798
- const cssPath = `${relative3}/${parsedPath.name}.css`.replaceAll(path2.sep, "__");
2799
- logger7.info("cli", `Writing ${colors.bold(`${outdir}/${astJsonPath}`)}`);
2800
- 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}`)}`);
2801
2795
  return Promise.allSettled([
2802
2796
  fs.writeFile(`${outdir}/${astJsonPath}`, JSON.stringify(result.toJSON(), null, 2)),
2803
- fs.writeFile(`${outdir}/${cssPath}`, css2)
2797
+ fs.writeFile(`${outdir}/${cssPath}`, css)
2804
2798
  ]);
2805
2799
  }
2806
2800
  });
2807
- logger7.info("cli", `Found ${colors.bold(`${filteredResults.length}/${files.length}`)} files using Panda`);
2801
+ logger8.info("cli", `Found ${colors2.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2808
2802
  measureTotal();
2809
2803
  }
2810
2804
 
2811
- // src/exec-command.ts
2812
- init_esm_shims();
2813
- import { logger as logger8 } from "@pandacss/logger";
2814
- import { spawnSync } from "child_process";
2815
- import getPackageManager from "preferred-pm";
2816
- async function execCommand(cmd, cwd) {
2817
- const manager = await getPackageManager(cwd);
2818
- const pm = manager?.name ?? "npm";
2819
- const args = cmd.split(" ");
2820
- if (pm === "npm") {
2821
- args.unshift("run");
2822
- }
2823
- const check = spawnSync(pm, args, { cwd, stdio: "pipe" });
2824
- if (check.status !== 0) {
2825
- logger8.error("exec", check.stderr.toString());
2826
- }
2827
- }
2828
-
2829
2805
  // src/generate.ts
2830
2806
  init_esm_shims();
2831
2807
  import { logger as logger9 } from "@pandacss/logger";
2832
2808
  import { match } from "ts-pattern";
2833
- async function build(ctx, ids) {
2834
- await emitArtifacts(ctx, ids);
2809
+ async function build(ctx, artifactIds) {
2810
+ await codegen(ctx, artifactIds);
2835
2811
  if (ctx.config.emitTokensOnly) {
2836
2812
  return logger9.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens \u2728");
2837
2813
  }
2838
- ctx.appendAllCss();
2839
- 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);
2840
2820
  logger9.info("css:emit", "Successfully built the css files \u2728");
2841
2821
  }
2842
2822
  async function generate(config, configPath) {
2843
2823
  let ctx = await loadConfigAndCreateContext({ config, configPath });
2844
2824
  await build(ctx);
2845
2825
  const {
2846
- runtime: { fs, path: path2 },
2826
+ runtime: { fs, path },
2847
2827
  config: { cwd }
2848
2828
  } = ctx;
2849
2829
  if (ctx.config.watch) {
@@ -2852,27 +2832,39 @@ async function generate(config, configPath) {
2852
2832
  const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2853
2833
  ctx = new PandaContext({ ...conf, hooks: ctx.hooks });
2854
2834
  });
2855
- if (!affecteds.artifacts.size)
2835
+ if (!affecteds.hasConfigChanged) {
2836
+ logger9.debug("builder", "Config didnt change, skipping rebuild");
2856
2837
  return;
2838
+ }
2857
2839
  logger9.info("config:change", "Config changed, restarting...");
2858
2840
  await ctx.hooks.callHook("config:change", ctx.config);
2859
2841
  return build(ctx, Array.from(affecteds.artifacts));
2860
2842
  });
2861
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
+ };
2862
2857
  contentWatcher.on("all", async (event, file) => {
2863
2858
  logger9.info(`file:${event}`, file);
2864
- await match(event).with("unlink", () => {
2865
- ctx.project.removeSourceFile(path2.abs(cwd, file));
2866
- }).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 () => {
2867
2863
  ctx.project.reloadSourceFile(file);
2868
- const result = ctx.project.parseSourceFile(file);
2869
- ctx.appendParserCss(result);
2870
- return ctx.writeCss();
2871
- }).with("add", () => {
2864
+ return bundleStyles(ctx, filePath);
2865
+ }).with("add", async () => {
2872
2866
  ctx.project.createSourceFile(file);
2873
- const result = ctx.project.parseSourceFile(file);
2874
- ctx.appendParserCss(result);
2875
- return ctx.writeCss();
2867
+ return bundleStyles(ctx, filePath);
2876
2868
  }).otherwise(() => {
2877
2869
  });
2878
2870
  });
@@ -2883,7 +2875,7 @@ async function generate(config, configPath) {
2883
2875
  // src/git-ignore.ts
2884
2876
  init_esm_shims();
2885
2877
  import { appendFileSync, readFileSync, writeFileSync } from "fs";
2886
- import { lookItUpSync as lookItUpSync2 } from "look-it-up";
2878
+ import { lookItUpSync } from "look-it-up";
2887
2879
  import outdent from "outdent";
2888
2880
  function setupGitIgnore(ctx) {
2889
2881
  const { outdir, gitignore } = ctx.config;
@@ -2895,7 +2887,7 @@ function setupGitIgnore(ctx) {
2895
2887
  ${outdir}
2896
2888
  ${ctx.studio.outdir}
2897
2889
  `;
2898
- const file = lookItUpSync2(".gitignore");
2890
+ const file = lookItUpSync(".gitignore");
2899
2891
  if (!file) {
2900
2892
  return writeFileSync(".gitignore", txt);
2901
2893
  }
@@ -2907,21 +2899,22 @@ function setupGitIgnore(ctx) {
2907
2899
 
2908
2900
  // src/setup-config.ts
2909
2901
  init_esm_shims();
2902
+ import { findConfig as findConfig2 } from "@pandacss/config";
2910
2903
  import { messages } from "@pandacss/generator";
2911
2904
  import { logger as logger10, quote } from "@pandacss/logger";
2912
- import fsExtra3 from "fs-extra";
2913
- import { lookItUpSync as lookItUpSync3 } from "look-it-up";
2905
+ import fsExtra2 from "fs-extra";
2906
+ import { lookItUpSync as lookItUpSync2 } from "look-it-up";
2914
2907
  import { outdent as outdent2 } from "outdent";
2915
2908
  import { join as join2 } from "pathe";
2916
- import getPackageManager2 from "preferred-pm";
2909
+ import getPackageManager from "preferred-pm";
2917
2910
  import prettier from "prettier";
2918
2911
  async function setupConfig(cwd, opts = {}) {
2919
2912
  const { force, outExtension, jsxFramework, syntax } = opts;
2920
- const configFile = findConfig();
2921
- const pmResult = await getPackageManager2(cwd);
2913
+ const configFile = findConfig2({ cwd });
2914
+ const pmResult = await getPackageManager(cwd);
2922
2915
  const pm = pmResult?.name ?? "npm";
2923
2916
  const cmd = pm === "npm" ? "npm run" : pm;
2924
- const isTs = lookItUpSync3("tsconfig.json", cwd);
2917
+ const isTs = lookItUpSync2("tsconfig.json", cwd);
2925
2918
  const file = isTs ? "panda.config.ts" : "panda.config.mjs";
2926
2919
  logger10.info("init:config", `creating panda config file: ${quote(file)}`);
2927
2920
  if (!force && configFile) {
@@ -2957,7 +2950,7 @@ jsxFramework: '${jsxFramework}',` : ""}
2957
2950
  syntax: '${syntax}'` : ""}
2958
2951
  })
2959
2952
  `;
2960
- await fsExtra3.writeFile(join2(cwd, file), prettier.format(content));
2953
+ await fsExtra2.writeFile(join2(cwd, file), prettier.format(content));
2961
2954
  logger10.log(messages.thankYou());
2962
2955
  }
2963
2956
  }
@@ -2970,50 +2963,21 @@ module.exports = {
2970
2963
  },
2971
2964
  }
2972
2965
  `;
2973
- await fsExtra3.writeFile(join2(cwd, "postcss.config.cjs"), content);
2974
- }
2975
-
2976
- // src/ship-files.ts
2977
- init_esm_shims();
2978
- import { colors as colors2, logger as logger11 } from "@pandacss/logger";
2979
- import { createParserResult as createParserResult2 } from "@pandacss/parser";
2980
- import { writeFile as writeFile2 } from "fs/promises";
2981
- import * as path from "pathe";
2982
- async function shipFiles(ctx, outfile) {
2983
- const files = ctx.getFiles();
2984
- const extractResult = createParserResult2();
2985
- const filesWithCss = [];
2986
- files.forEach(async (file) => {
2987
- const result = ctx.project.parseSourceFile(file);
2988
- if (!result || result.isEmpty())
2989
- return;
2990
- extractResult.merge(result);
2991
- filesWithCss.push(path.relative(ctx.config.cwd, file));
2992
- });
2993
- logger11.info("cli", `Found ${colors2.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2994
- const minify = ctx.config.minify;
2995
- logger11.info("cli", `Writing ${minify ? "[min] " : " "}${colors2.bold(outfile)}`);
2996
- const output = JSON.stringify(extractResult.toJSON(), null, minify ? 0 : 2);
2997
- const dirname2 = ctx.runtime.path.dirname(outfile);
2998
- ctx.runtime.fs.ensureDirSync(dirname2);
2999
- await writeFile2(outfile, output);
3000
- logger11.info("cli", "Done!");
2966
+ await fsExtra2.writeFile(join2(cwd, "postcss.config.cjs"), content);
3001
2967
  }
3002
2968
  export {
3003
2969
  Builder,
3004
2970
  PandaContext,
3005
2971
  analyzeTokens,
3006
- debugFiles,
3007
- emitArtifacts,
3008
- execCommand,
3009
- extractFile,
3010
- findConfig,
2972
+ buildInfo,
2973
+ codegen,
2974
+ cssgen,
2975
+ debug,
3011
2976
  generate,
3012
2977
  loadConfigAndCreateContext,
3013
2978
  parseDependency,
3014
2979
  setupConfig,
3015
2980
  setupGitIgnore,
3016
2981
  setupPostcss,
3017
- shipFiles,
3018
2982
  writeAnalyzeJSON
3019
2983
  };