@pandacss/node 0.20.1 → 0.22.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.2.2/node_modules/tsup/assets/esm_shims.js
30
+ // ../../node_modules/.pnpm/tsup@7.1.0_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.2.2/node_modules/tsup/assets/esm_shims.js"() {
32
+ "../../node_modules/.pnpm/tsup@7.1.0_typescript@5.3.3/node_modules/tsup/assets/esm_shims.js"() {
33
33
  "use strict";
34
34
  }
35
35
  });
@@ -686,12 +686,10 @@ function analyzeTokens(ctx, options = {}) {
686
686
  const totalMs = Array.from(timesMap.values()).reduce((a, b) => a + b, 0);
687
687
  logger.debug("analyze", `Analyzed ${files.length} files in ${totalMs.toFixed(2)}ms`);
688
688
  const minify = ctx.config.minify;
689
- const chunkFiles = ctx.chunks.getFiles();
690
689
  ctx.config.optimize = true;
691
690
  ctx.config.minify = false;
692
- const css2 = ctx.getCss({ files: chunkFiles });
693
- ctx.config.minify = true;
694
- const minifiedCss = ctx.getCss({ files: chunkFiles });
691
+ const css2 = "";
692
+ const minifiedCss = "";
695
693
  ctx.config.minify = minify;
696
694
  const start = performance.now();
697
695
  const analysis = classifyTokens(ctx, filesMap);
@@ -750,7 +748,7 @@ var writeAnalyzeJSON = (filePath, result, ctx) => {
750
748
 
751
749
  // src/builder.ts
752
750
  init_esm_shims();
753
- import { optimizeCss as optimizeCss2 } from "@pandacss/core";
751
+ import { optimizeCss } from "@pandacss/core";
754
752
  import { ConfigNotFoundError } from "@pandacss/error";
755
753
  import { logger as logger6 } from "@pandacss/logger";
756
754
  import { existsSync } from "fs";
@@ -877,154 +875,7 @@ import { parse } from "tsconfck";
877
875
  init_esm_shims();
878
876
  import { Generator as Generator2 } from "@pandacss/generator";
879
877
  import { logger as logger4 } from "@pandacss/logger";
880
- import { createProject } from "@pandacss/parser";
881
-
882
- // src/chunk-engine.ts
883
- init_esm_shims();
884
- import { mergeCss } from "@pandacss/core";
885
- var getChunkEngine = ({
886
- paths,
887
- config,
888
- runtime: { path: path2, fs }
889
- }) => ({
890
- dir: path2.join(...paths.chunk),
891
- readFile(file) {
892
- const fileName = path2.join(...paths.chunk, this.format(file));
893
- return fs.existsSync(fileName) ? fs.readFileSync(fileName) : "";
894
- },
895
- getFiles() {
896
- const files = fs.existsSync(this.dir) ? fs.readDirSync(this.dir) : [];
897
- return files.map((file) => fs.readFileSync(path2.join(this.dir, file)));
898
- },
899
- format(file) {
900
- return path2.relative(config.cwd, file).replaceAll(path2.sep, "__").replace(path2.extname(file), ".css");
901
- },
902
- getArtifact(file, css2) {
903
- const fileName = this.format(file);
904
- const newCss = mergeCss(this.readFile(file), css2);
905
- return {
906
- id: fileName,
907
- dir: paths.chunk,
908
- files: [{ file: fileName, code: newCss }]
909
- };
910
- },
911
- rm(file) {
912
- return fs.rmFileSync(path2.join(...paths.chunk, this.format(file)));
913
- },
914
- empty() {
915
- return fs.rmDirSync(this.dir);
916
- },
917
- get glob() {
918
- return [`${this.dir}/**/*.css`];
919
- }
920
- });
921
-
922
- // src/node-runtime.ts
923
- init_esm_shims();
924
- import { logger as logger2 } from "@pandacss/logger";
925
- import chokidar from "chokidar";
926
- import glob from "fast-glob";
927
- import fsExtra from "fs-extra";
928
- import { dirname, extname, isAbsolute, join, relative, sep } from "pathe";
929
- var nodeRuntime = {
930
- cwd() {
931
- return process.cwd();
932
- },
933
- env(name) {
934
- return process.env[name];
935
- },
936
- path: {
937
- join,
938
- relative,
939
- dirname,
940
- extname,
941
- isAbsolute,
942
- sep,
943
- abs(cwd, str) {
944
- return isAbsolute(str) ? str : join(cwd, str);
945
- }
946
- },
947
- fs: {
948
- existsSync: fsExtra.existsSync,
949
- readFileSync(filePath) {
950
- return fsExtra.readFileSync(filePath, "utf8");
951
- },
952
- glob(opts) {
953
- if (!opts.include)
954
- return [];
955
- const ignore = opts.exclude ?? [];
956
- if (!ignore.length) {
957
- ignore.push("**/*.d.ts");
958
- }
959
- return glob.sync(opts.include, { cwd: opts.cwd, ignore, absolute: true });
960
- },
961
- writeFile: fsExtra.writeFile,
962
- writeFileSync: fsExtra.writeFileSync,
963
- readDirSync: fsExtra.readdirSync,
964
- rmDirSync: fsExtra.emptyDirSync,
965
- rmFileSync: fsExtra.removeSync,
966
- ensureDirSync(path2) {
967
- return fsExtra.ensureDirSync(path2);
968
- },
969
- watch(options) {
970
- const { include, exclude, cwd, poll } = options;
971
- const coalesce = poll || process.platform === "win32";
972
- const watcher = chokidar.watch(include, {
973
- usePolling: poll,
974
- cwd,
975
- ignoreInitial: true,
976
- ignorePermissionErrors: true,
977
- ignored: exclude,
978
- awaitWriteFinish: coalesce ? { stabilityThreshold: 50, pollInterval: 10 } : false
979
- });
980
- logger2.debug("watch:file", `watching [${include}]`);
981
- process.once("SIGINT", async () => {
982
- await watcher.close();
983
- });
984
- return watcher;
985
- }
986
- }
987
- };
988
- process.setMaxListeners(Infinity);
989
- process.on("unhandledRejection", (reason) => {
990
- logger2.error("\u274C", reason);
991
- });
992
- process.on("uncaughtException", (reason) => {
993
- logger2.error("\u274C", reason);
994
- });
995
-
996
- // src/output-engine.ts
997
- init_esm_shims();
998
- import { logger as logger3 } from "@pandacss/logger";
999
- var PandaOutputEngine = class {
1000
- paths;
1001
- fs;
1002
- path;
1003
- constructor({ paths, runtime: { path: path2, fs } }) {
1004
- this.paths = paths;
1005
- this.fs = fs;
1006
- this.path = path2;
1007
- }
1008
- empty() {
1009
- this.fs.rmDirSync(this.path.join(...this.paths.root));
1010
- }
1011
- async write(output) {
1012
- if (!output)
1013
- return;
1014
- const { dir = this.paths.root, files } = output;
1015
- this.fs.ensureDirSync(this.path.join(...dir));
1016
- return Promise.allSettled(
1017
- files.map(async (artifact) => {
1018
- if (!artifact?.code)
1019
- return;
1020
- const { file, code } = artifact;
1021
- const absPath = this.path.join(...dir, file);
1022
- logger3.debug("write:file", dir.slice(-1).concat(file).join("/"));
1023
- return this.fs.writeFile(absPath, code);
1024
- })
1025
- );
1026
- }
1027
- };
878
+ import { createParserResult, createProject } from "@pandacss/parser";
1028
879
 
1029
880
  // src/diff-engine.ts
1030
881
  init_esm_shims();
@@ -1160,12 +1011,118 @@ var DiffEngine = class {
1160
1011
  }
1161
1012
  };
1162
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
+
1163
1121
  // src/create-context.ts
1164
1122
  var PandaContext = class extends Generator2 {
1165
1123
  runtime;
1166
1124
  project;
1167
1125
  getFiles;
1168
- chunks;
1169
1126
  output;
1170
1127
  diff;
1171
1128
  constructor(conf) {
@@ -1185,10 +1142,37 @@ var PandaContext = class extends Generator2 {
1185
1142
  hooks: conf.hooks,
1186
1143
  parserOptions: { join: this.runtime.path.join, ...this.parserOptions }
1187
1144
  });
1188
- this.chunks = getChunkEngine(this);
1189
1145
  this.output = new PandaOutputEngine(this);
1190
1146
  this.diff = new DiffEngine(this);
1191
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
+ }
1192
1176
  };
1193
1177
 
1194
1178
  // src/config.ts
@@ -1213,6 +1197,7 @@ async function loadConfigAndCreateContext(options = {}) {
1213
1197
  }
1214
1198
  const tsconfigResult = await parse(conf.path, {
1215
1199
  root: cwd,
1200
+ // @ts-ignore
1216
1201
  resolveWithEmptyIfConfigNotFound: true
1217
1202
  });
1218
1203
  if (tsconfigResult) {
@@ -1239,14 +1224,8 @@ async function loadConfigAndCreateContext(options = {}) {
1239
1224
  return new PandaContext({ ...conf, hooks });
1240
1225
  }
1241
1226
 
1242
- // src/extract.ts
1227
+ // src/emit-artifact.ts
1243
1228
  init_esm_shims();
1244
- import { optimizeCss } from "@pandacss/core";
1245
- import { logger as logger5 } from "@pandacss/logger";
1246
- import { createParserResult } from "@pandacss/parser";
1247
- import { writeFile as writeFile2 } from "fs/promises";
1248
- import { Obj, pipe, tap, tryCatch } from "lil-fp";
1249
- import { match } from "ts-pattern";
1250
1229
 
1251
1230
  // src/cli-box.ts
1252
1231
  init_esm_shims();
@@ -2560,50 +2539,7 @@ var createBox = (options) => boxen(options.content, {
2560
2539
  titleAlignment: "center"
2561
2540
  });
2562
2541
 
2563
- // src/extract.ts
2564
- async function bundleStyleChunksWithImports(ctx) {
2565
- const files = ctx.chunks.getFiles();
2566
- await ctx.output.write({
2567
- id: "styles.css",
2568
- dir: ctx.paths.root,
2569
- files: [{ file: "styles.css", code: ctx.getCss({ files }) }]
2570
- });
2571
- return { files, msg: ctx.messages.buildComplete(files.length) };
2572
- }
2573
- async function writeFileChunk(ctx, file) {
2574
- const { path: path2 } = ctx.runtime;
2575
- logger5.debug("chunk:write", `File: ${path2.relative(ctx.config.cwd, file)}`);
2576
- const css2 = extractFile(ctx, file);
2577
- if (!css2)
2578
- return;
2579
- const artifact = ctx.chunks.getArtifact(file, css2);
2580
- return ctx.output.write(artifact);
2581
- }
2582
- function extractFile(ctx, file) {
2583
- const {
2584
- runtime: { path: path2 },
2585
- config: { cwd }
2586
- } = ctx;
2587
- return pipe(
2588
- { file: path2.abs(cwd, file) },
2589
- tap(() => logger5.debug("file:extract", file)),
2590
- Obj.bind("measure", () => logger5.time.debug(`Extracted ${file}`)),
2591
- Obj.bind(
2592
- "result",
2593
- tryCatch(
2594
- ({ file: file2 }) => ctx.project.parseSourceFile(file2),
2595
- (error) => logger5.error("file:parse", error)
2596
- )
2597
- ),
2598
- Obj.bind("measureCss", () => logger5.time.debug(`Parsed ${file}`)),
2599
- Obj.bind("css", ({ result }) => result ? ctx.getParserCss(result) : void 0),
2600
- tap(({ measure, measureCss }) => [measureCss(), measure()]),
2601
- Obj.get("css")
2602
- );
2603
- }
2604
- function writeChunks(ctx) {
2605
- return Promise.allSettled(ctx.getFiles().map((file) => writeFileChunk(ctx, file)));
2606
- }
2542
+ // src/emit-artifact.ts
2607
2543
  var randomWords = ["Sweet", "Divine", "Pandalicious", "Super"];
2608
2544
  var pickRandom = (arr) => arr[Math.floor(Math.random() * arr.length)];
2609
2545
  var limit = pLimit(20);
@@ -2621,55 +2557,29 @@ async function emitArtifacts(ctx, ids) {
2621
2557
  msg: ctx.messages.artifactsGenerated()
2622
2558
  };
2623
2559
  }
2624
- async function writeAndBundleCssChunks(ctx) {
2625
- await writeChunks(ctx);
2626
- return bundleStyleChunksWithImports(ctx);
2627
- }
2628
- async function bundleCss(ctx, outfile) {
2629
- const extracted = await writeChunks(ctx);
2630
- const files = ctx.chunks.getFiles();
2631
- const minify = ctx.config.minify;
2632
- await writeFile2(outfile, optimizeCss(ctx.getCss({ files, resolve: true }), { minify }));
2633
- return { files, msg: ctx.messages.buildComplete(extracted.length) };
2634
- }
2635
- async function bundleMinimalFilesCss(ctx, outfile) {
2636
- const files = ctx.getFiles();
2637
- const filesWithCss = [];
2638
- const collector = createParserResult();
2639
- files.forEach((file) => {
2640
- const measure = logger5.time.debug(`Parsed ${file}`);
2641
- const result = ctx.project.parseSourceFile(file);
2642
- measure();
2643
- if (!result)
2644
- return;
2645
- collector.merge(result);
2646
- filesWithCss.push(file);
2647
- });
2648
- const css2 = ctx.getParserCss(collector);
2649
- if (!css2)
2650
- return { files, msg: ctx.messages.buildComplete(files.length) };
2651
- const minify = ctx.config.minify;
2652
- await writeFile2(outfile, optimizeCss(css2, { minify }));
2653
- return { files, msg: ctx.messages.buildComplete(files.length) };
2654
- }
2655
- async function generateCssArtifactOfType(ctx, cssType, outfile) {
2656
- let notFound = false;
2657
- const css2 = match(cssType).with("preflight", () => ctx.getResetCss()).with("tokens", () => ctx.getTokenCss()).with("static", () => ctx.getStaticCss()).with("global", () => ctx.getGlobalCss()).with("keyframes", () => ctx.getKeyframeCss()).otherwise(() => {
2658
- notFound = true;
2659
- });
2660
- if (notFound)
2661
- return { msg: `No css artifact of type <${cssType}> was found` };
2662
- if (!css2)
2663
- return { msg: `No css to generate for type <${cssType}>` };
2664
- const minify = ctx.config.minify;
2665
- await writeFile2(outfile, optimizeCss(css2, { minify }));
2666
- return { msg: `Successfully generated ${cssType} css artifact \u2728` };
2560
+
2561
+ // src/extract.ts
2562
+ 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;
2667
2577
  }
2668
2578
 
2669
2579
  // src/parse-dependency.ts
2670
2580
  init_esm_shims();
2671
2581
  import isGlob from "is-glob";
2672
- import { resolve } from "path";
2582
+ import { resolve } from "pathe";
2673
2583
 
2674
2584
  // src/parse-glob.ts
2675
2585
  init_esm_shims();
@@ -2711,7 +2621,7 @@ function parseDependency(fileOrGlob) {
2711
2621
  }
2712
2622
 
2713
2623
  // src/builder.ts
2714
- var fileCssMap = /* @__PURE__ */ new Map();
2624
+ var parserResultMap = /* @__PURE__ */ new Map();
2715
2625
  var fileModifiedMap = /* @__PURE__ */ new Map();
2716
2626
  var limit2 = pLimit(20);
2717
2627
  var Builder = class {
@@ -2720,7 +2630,6 @@ var Builder = class {
2720
2630
  */
2721
2631
  context;
2722
2632
  hasEmitted = false;
2723
- hasConfigChanged = false;
2724
2633
  affecteds;
2725
2634
  getConfigPath = () => {
2726
2635
  const configPath = findConfig();
@@ -2733,19 +2642,22 @@ var Builder = class {
2733
2642
  logger6.debug("builder", "\u{1F6A7} Setup");
2734
2643
  const configPath = options.configPath ?? this.getConfigPath();
2735
2644
  if (!this.context) {
2736
- return this.setupContext({ configPath });
2645
+ return this.setupContext({ configPath, cwd: options.cwd });
2737
2646
  }
2738
2647
  const ctx = this.getContextOrThrow();
2739
2648
  this.affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2740
2649
  this.context = new PandaContext({ ...conf, hooks: ctx.hooks });
2650
+ this.context.appendBaselineCss();
2741
2651
  });
2742
- this.hasConfigChanged = this.affecteds.hasConfigChanged;
2743
2652
  if (this.affecteds.hasConfigChanged) {
2744
2653
  logger6.debug("builder", "\u2699\uFE0F Config changed, reloading");
2745
2654
  await ctx.hooks.callHook("config:change", ctx.config);
2746
2655
  return;
2747
2656
  }
2748
- ctx.project.reloadSourceFiles();
2657
+ const hasFilesChanged = this.checkFilesChanged(ctx.getFiles());
2658
+ if (hasFilesChanged) {
2659
+ ctx.project.reloadSourceFiles();
2660
+ }
2749
2661
  };
2750
2662
  async emit() {
2751
2663
  if (this.hasEmitted && this.affecteds?.hasConfigChanged) {
@@ -2754,8 +2666,9 @@ var Builder = class {
2754
2666
  this.hasEmitted = true;
2755
2667
  }
2756
2668
  setupContext = async (options) => {
2757
- const { configPath } = options;
2758
- const ctx = await loadConfigAndCreateContext({ configPath });
2669
+ const { configPath, cwd } = options;
2670
+ const ctx = await loadConfigAndCreateContext({ configPath, cwd });
2671
+ ctx.appendBaselineCss();
2759
2672
  this.context = ctx;
2760
2673
  return ctx;
2761
2674
  };
@@ -2765,53 +2678,63 @@ var Builder = class {
2765
2678
  }
2766
2679
  return this.context;
2767
2680
  };
2768
- extractFile = async (ctx, file) => {
2681
+ getFileMeta = (file) => {
2769
2682
  const mtime = existsSync(file) ? fsExtra2.statSync(file).mtimeMs : -Infinity;
2770
2683
  const isUnchanged = fileModifiedMap.has(file) && mtime === fileModifiedMap.get(file);
2771
- if (isUnchanged && !this.hasConfigChanged)
2772
- return;
2773
- const css2 = extractFile(ctx, file);
2774
- fileModifiedMap.set(file, mtime);
2775
- if (!css2) {
2776
- fileCssMap.delete(file);
2684
+ return { mtime, isUnchanged };
2685
+ };
2686
+ extractFile = async (ctx, file) => {
2687
+ const meta = this.getFileMeta(file);
2688
+ if (meta.isUnchanged) {
2689
+ ctx.appendParserCss(parserResultMap.get(file));
2777
2690
  return;
2778
2691
  }
2779
- fileCssMap.set(file, css2);
2780
- return css2;
2692
+ const result = extractFile(ctx, file);
2693
+ fileModifiedMap.set(file, meta.mtime);
2694
+ if (result) {
2695
+ parserResultMap.set(file, result);
2696
+ }
2697
+ return result;
2781
2698
  };
2699
+ checkFilesChanged(files) {
2700
+ return files.some((file) => !this.getFileMeta(file).isUnchanged);
2701
+ }
2782
2702
  extract = async () => {
2783
2703
  const ctx = this.getContextOrThrow();
2704
+ const files = ctx.getFiles();
2705
+ const hasConfigChanged = this.affecteds ? this.affecteds.hasConfigChanged : false;
2706
+ if (hasConfigChanged)
2707
+ return;
2784
2708
  const done = logger6.time.info("Extracted in");
2785
- const promises = ctx.getFiles().map((file) => limit2(() => this.extractFile(ctx, file)));
2709
+ const promises = files.map((file) => limit2(() => this.extractFile(ctx, file)));
2786
2710
  await Promise.allSettled(promises);
2787
2711
  done();
2788
2712
  };
2789
2713
  toString = () => {
2790
2714
  const ctx = this.getContextOrThrow();
2791
- return ctx.getCss({
2792
- files: Array.from(fileCssMap.values()),
2793
- resolve: true
2794
- });
2715
+ return ctx.getCss();
2795
2716
  };
2796
2717
  isValidRoot = (root) => {
2797
2718
  const ctx = this.getContextOrThrow();
2798
2719
  let valid = false;
2799
2720
  root.walkAtRules("layer", (rule) => {
2800
- if (ctx.isValidLayerRule(rule.params)) {
2721
+ if (ctx.layers.isValidParams(rule.params)) {
2801
2722
  valid = true;
2802
2723
  }
2803
2724
  });
2804
2725
  return valid;
2805
2726
  };
2727
+ initialRoot;
2806
2728
  write = (root) => {
2807
- const rootCssContent = root.toString();
2729
+ if (!this.initialRoot) {
2730
+ this.initialRoot = root.toString();
2731
+ }
2808
2732
  root.removeAll();
2809
- root.append(
2810
- optimizeCss2(`
2811
- ${rootCssContent}
2733
+ const newCss = optimizeCss(`
2734
+ ${this.initialRoot}
2812
2735
  ${this.toString()}
2813
- `)
2814
- );
2736
+ `);
2737
+ root.append(newCss);
2815
2738
  };
2816
2739
  registerDependency = (fn) => {
2817
2740
  const ctx = this.getContextOrThrow();
@@ -2830,12 +2753,10 @@ var Builder = class {
2830
2753
  // src/debug-files.ts
2831
2754
  init_esm_shims();
2832
2755
  import { colors, logger as logger7 } from "@pandacss/logger";
2833
- import * as nodePath from "path";
2756
+ import { parse as parse2 } from "pathe";
2834
2757
  async function debugFiles(ctx, options) {
2835
2758
  const files = ctx.getFiles();
2836
2759
  const measureTotal = logger7.time.debug(`Done parsing ${files.length} files`);
2837
- ctx.config.minify = false;
2838
- ctx.config.optimize = true;
2839
2760
  const { fs, path: path2 } = ctx.runtime;
2840
2761
  const outdir = options.outdir;
2841
2762
  if (!options.dry && outdir) {
@@ -2848,35 +2769,37 @@ async function debugFiles(ctx, options) {
2848
2769
  return;
2849
2770
  }
2850
2771
  const filesWithCss = [];
2851
- await Promise.allSettled(
2772
+ const results = await Promise.all(
2852
2773
  files.map(async (file) => {
2853
2774
  const measure = logger7.time.debug(`Parsed ${file}`);
2854
2775
  const result = ctx.project.parseSourceFile(file);
2855
2776
  measure();
2856
- if (!result)
2857
- return;
2858
- const css2 = ctx.getParserCss(result);
2859
- if (!css2)
2860
- return;
2861
- if (options.dry) {
2862
- console.log({ path: file, ast: result, code: css2 });
2863
- return Promise.resolve();
2864
- }
2865
- if (outdir) {
2866
- filesWithCss.push(file);
2867
- const parsedPath = nodePath.parse(file);
2868
- const relative3 = path2.relative(ctx.config.cwd, parsedPath.dir);
2869
- const astJsonPath = `${relative3}/${parsedPath.name}.ast.json`.replaceAll(path2.sep, "__");
2870
- const cssPath = `${relative3}/${parsedPath.name}.css`.replaceAll(path2.sep, "__");
2871
- logger7.info("cli", `Writing ${colors.bold(`${outdir}/${astJsonPath}`)}`);
2872
- logger7.info("cli", `Writing ${colors.bold(`${outdir}/${cssPath}`)}`);
2873
- return Promise.allSettled([
2874
- fs.writeFile(`${outdir}/${astJsonPath}`, JSON.stringify(result.toJSON(), null, 2)),
2875
- fs.writeFile(`${outdir}/${cssPath}`, css2)
2876
- ]);
2877
- }
2777
+ return { file, result };
2878
2778
  })
2879
2779
  );
2780
+ results.forEach(({ file, result }) => {
2781
+ if (!result)
2782
+ return;
2783
+ ctx.stylesheet.clean();
2784
+ ctx.appendParserCss(result);
2785
+ const css2 = ctx.stylesheet.toCss({ optimize: true, minify: false });
2786
+ if (options.dry) {
2787
+ console.log({ path: file, ast: result, code: css2 });
2788
+ }
2789
+ if (outdir) {
2790
+ filesWithCss.push(file);
2791
+ 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}`)}`);
2797
+ return Promise.allSettled([
2798
+ fs.writeFile(`${outdir}/${astJsonPath}`, JSON.stringify(result.toJSON(), null, 2)),
2799
+ fs.writeFile(`${outdir}/${cssPath}`, css2)
2800
+ ]);
2801
+ }
2802
+ });
2880
2803
  logger7.info("cli", `Found ${colors.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2881
2804
  measureTotal();
2882
2805
  }
@@ -2902,17 +2825,18 @@ async function execCommand(cmd, cwd) {
2902
2825
  // src/generate.ts
2903
2826
  init_esm_shims();
2904
2827
  import { logger as logger9 } from "@pandacss/logger";
2905
- import { match as match2 } from "ts-pattern";
2828
+ import { match } from "ts-pattern";
2906
2829
  async function build(ctx, ids) {
2907
2830
  await emitArtifacts(ctx, ids);
2908
2831
  if (ctx.config.emitTokensOnly) {
2909
2832
  return logger9.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens \u2728");
2910
2833
  }
2911
- const { msg } = await writeAndBundleCssChunks(ctx);
2912
- logger9.info("css:emit", msg);
2834
+ ctx.appendAllCss();
2835
+ await ctx.writeCss();
2836
+ logger9.info("css:emit", "Successfully built the css files \u2728");
2913
2837
  }
2914
2838
  async function generate(config, configPath) {
2915
- const ctx = await loadConfigAndCreateContext({ config, configPath });
2839
+ let ctx = await loadConfigAndCreateContext({ config, configPath });
2916
2840
  await build(ctx);
2917
2841
  const {
2918
2842
  runtime: { fs, path: path2 },
@@ -2921,7 +2845,9 @@ async function generate(config, configPath) {
2921
2845
  if (ctx.config.watch) {
2922
2846
  const configWatcher = fs.watch({ include: ctx.conf.dependencies });
2923
2847
  configWatcher.on("change", async () => {
2924
- const affecteds = await ctx.diff.reloadConfigAndRefreshContext();
2848
+ const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2849
+ ctx = new PandaContext({ ...conf, hooks: ctx.hooks });
2850
+ });
2925
2851
  if (!affecteds.artifacts.size)
2926
2852
  return;
2927
2853
  logger9.info("config:change", "Config changed, restarting...");
@@ -2931,16 +2857,18 @@ async function generate(config, configPath) {
2931
2857
  const contentWatcher = fs.watch(ctx.config);
2932
2858
  contentWatcher.on("all", async (event, file) => {
2933
2859
  logger9.info(`file:${event}`, file);
2934
- match2(event).with("unlink", () => {
2860
+ await match(event).with("unlink", () => {
2935
2861
  ctx.project.removeSourceFile(path2.abs(cwd, file));
2936
- ctx.chunks.rm(file);
2937
- }).with("change", async () => {
2862
+ }).with("change", () => {
2938
2863
  ctx.project.reloadSourceFile(file);
2939
- await writeFileChunk(ctx, file);
2940
- return bundleStyleChunksWithImports(ctx);
2941
- }).with("add", async () => {
2864
+ const result = ctx.project.parseSourceFile(file);
2865
+ ctx.appendParserCss(result);
2866
+ return ctx.writeCss();
2867
+ }).with("add", () => {
2942
2868
  ctx.project.createSourceFile(file);
2943
- return bundleStyleChunksWithImports(ctx);
2869
+ const result = ctx.project.parseSourceFile(file);
2870
+ ctx.appendParserCss(result);
2871
+ return ctx.writeCss();
2944
2872
  }).otherwise(() => {
2945
2873
  });
2946
2874
  });
@@ -2980,7 +2908,7 @@ import { logger as logger10, quote } from "@pandacss/logger";
2980
2908
  import fsExtra3 from "fs-extra";
2981
2909
  import { lookItUpSync as lookItUpSync3 } from "look-it-up";
2982
2910
  import { outdent as outdent2 } from "outdent";
2983
- import { join as join2 } from "path";
2911
+ import { join as join2 } from "pathe";
2984
2912
  import getPackageManager2 from "preferred-pm";
2985
2913
  import prettier from "prettier";
2986
2914
  async function setupConfig(cwd, opts = {}) {
@@ -3045,8 +2973,8 @@ module.exports = {
3045
2973
  init_esm_shims();
3046
2974
  import { colors as colors2, logger as logger11 } from "@pandacss/logger";
3047
2975
  import { createParserResult as createParserResult2 } from "@pandacss/parser";
3048
- import { writeFile as writeFile3 } from "fs/promises";
3049
- import * as path from "path";
2976
+ import { writeFile as writeFile2 } from "fs/promises";
2977
+ import * as path from "pathe";
3050
2978
  async function shipFiles(ctx, outfile) {
3051
2979
  const files = ctx.getFiles();
3052
2980
  const extractResult = createParserResult2();
@@ -3055,9 +2983,6 @@ async function shipFiles(ctx, outfile) {
3055
2983
  const result = ctx.project.parseSourceFile(file);
3056
2984
  if (!result || result.isEmpty())
3057
2985
  return;
3058
- const css2 = ctx.getParserCss(result);
3059
- if (!css2)
3060
- return;
3061
2986
  extractResult.merge(result);
3062
2987
  filesWithCss.push(path.relative(ctx.config.cwd, file));
3063
2988
  });
@@ -3067,28 +2992,24 @@ async function shipFiles(ctx, outfile) {
3067
2992
  const output = JSON.stringify(extractResult.toJSON(), null, minify ? 0 : 2);
3068
2993
  const dirname2 = ctx.runtime.path.dirname(outfile);
3069
2994
  ctx.runtime.fs.ensureDirSync(dirname2);
3070
- await writeFile3(outfile, output);
2995
+ await writeFile2(outfile, output);
3071
2996
  logger11.info("cli", "Done!");
3072
2997
  }
3073
2998
  export {
3074
2999
  Builder,
3075
3000
  PandaContext,
3076
3001
  analyzeTokens,
3077
- bundleCss,
3078
- bundleMinimalFilesCss,
3079
3002
  debugFiles,
3080
3003
  emitArtifacts,
3081
3004
  execCommand,
3082
3005
  extractFile,
3083
3006
  findConfig,
3084
3007
  generate,
3085
- generateCssArtifactOfType,
3086
3008
  loadConfigAndCreateContext,
3087
3009
  parseDependency,
3088
3010
  setupConfig,
3089
3011
  setupGitIgnore,
3090
3012
  setupPostcss,
3091
3013
  shipFiles,
3092
- writeAnalyzeJSON,
3093
- writeAndBundleCssChunks
3014
+ writeAnalyzeJSON
3094
3015
  };