@pandacss/node 0.21.0 → 0.22.1

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.js CHANGED
@@ -33,9 +33,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
33
33
  ));
34
34
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
35
 
36
- // ../../node_modules/.pnpm/tsup@7.1.0_typescript@5.2.2/node_modules/tsup/assets/cjs_shims.js
36
+ // ../../node_modules/.pnpm/tsup@7.1.0_typescript@5.3.3/node_modules/tsup/assets/cjs_shims.js
37
37
  var init_cjs_shims = __esm({
38
- "../../node_modules/.pnpm/tsup@7.1.0_typescript@5.2.2/node_modules/tsup/assets/cjs_shims.js"() {
38
+ "../../node_modules/.pnpm/tsup@7.1.0_typescript@5.3.3/node_modules/tsup/assets/cjs_shims.js"() {
39
39
  "use strict";
40
40
  }
41
41
  });
@@ -406,23 +406,19 @@ __export(src_exports, {
406
406
  Builder: () => Builder,
407
407
  PandaContext: () => PandaContext,
408
408
  analyzeTokens: () => analyzeTokens,
409
- bundleCss: () => bundleCss,
410
- bundleMinimalFilesCss: () => bundleMinimalFilesCss,
411
409
  debugFiles: () => debugFiles,
412
410
  emitArtifacts: () => emitArtifacts,
413
411
  execCommand: () => execCommand,
414
412
  extractFile: () => extractFile,
415
413
  findConfig: () => findConfig,
416
414
  generate: () => generate,
417
- generateCssArtifactOfType: () => generateCssArtifactOfType,
418
415
  loadConfigAndCreateContext: () => loadConfigAndCreateContext,
419
416
  parseDependency: () => parseDependency,
420
417
  setupConfig: () => setupConfig,
421
418
  setupGitIgnore: () => setupGitIgnore,
422
419
  setupPostcss: () => setupPostcss,
423
420
  shipFiles: () => shipFiles,
424
- writeAnalyzeJSON: () => writeAnalyzeJSON,
425
- writeAndBundleCssChunks: () => writeAndBundleCssChunks
421
+ writeAnalyzeJSON: () => writeAnalyzeJSON
426
422
  });
427
423
  module.exports = __toCommonJS(src_exports);
428
424
  init_cjs_shims();
@@ -716,12 +712,10 @@ function analyzeTokens(ctx, options = {}) {
716
712
  const totalMs = Array.from(timesMap.values()).reduce((a, b) => a + b, 0);
717
713
  import_logger.logger.debug("analyze", `Analyzed ${files.length} files in ${totalMs.toFixed(2)}ms`);
718
714
  const minify = ctx.config.minify;
719
- const chunkFiles = ctx.chunks.getFiles();
720
715
  ctx.config.optimize = true;
721
716
  ctx.config.minify = false;
722
- const css2 = ctx.getCss({ files: chunkFiles });
723
- ctx.config.minify = true;
724
- const minifiedCss = ctx.getCss({ files: chunkFiles });
717
+ const css2 = "";
718
+ const minifiedCss = "";
725
719
  ctx.config.minify = minify;
726
720
  const start = performance.now();
727
721
  const analysis = classifyTokens(ctx, filesMap);
@@ -780,7 +774,7 @@ var writeAnalyzeJSON = (filePath, result, ctx) => {
780
774
 
781
775
  // src/builder.ts
782
776
  init_cjs_shims();
783
- var import_core3 = require("@pandacss/core");
777
+ var import_core = require("@pandacss/core");
784
778
  var import_error = require("@pandacss/error");
785
779
  var import_logger6 = require("@pandacss/logger");
786
780
  var import_fs = require("fs");
@@ -894,7 +888,7 @@ function pLimit(concurrency) {
894
888
  }
895
889
 
896
890
  // src/builder.ts
897
- var import_pathe2 = require("pathe");
891
+ var import_pathe3 = require("pathe");
898
892
 
899
893
  // src/config.ts
900
894
  init_cjs_shims();
@@ -909,153 +903,6 @@ var import_generator2 = require("@pandacss/generator");
909
903
  var import_logger4 = require("@pandacss/logger");
910
904
  var import_parser = require("@pandacss/parser");
911
905
 
912
- // src/chunk-engine.ts
913
- init_cjs_shims();
914
- var import_core = require("@pandacss/core");
915
- var getChunkEngine = ({
916
- paths,
917
- config,
918
- runtime: { path: path2, fs }
919
- }) => ({
920
- dir: path2.join(...paths.chunk),
921
- readFile(file) {
922
- const fileName = path2.join(...paths.chunk, this.format(file));
923
- return fs.existsSync(fileName) ? fs.readFileSync(fileName) : "";
924
- },
925
- getFiles() {
926
- const files = fs.existsSync(this.dir) ? fs.readDirSync(this.dir) : [];
927
- return files.map((file) => fs.readFileSync(path2.join(this.dir, file)));
928
- },
929
- format(file) {
930
- return path2.relative(config.cwd, file).replaceAll(path2.sep, "__").replace(path2.extname(file), ".css");
931
- },
932
- getArtifact(file, css2) {
933
- const fileName = this.format(file);
934
- const newCss = (0, import_core.mergeCss)(this.readFile(file), css2);
935
- return {
936
- id: fileName,
937
- dir: paths.chunk,
938
- files: [{ file: fileName, code: newCss }]
939
- };
940
- },
941
- rm(file) {
942
- return fs.rmFileSync(path2.join(...paths.chunk, this.format(file)));
943
- },
944
- empty() {
945
- return fs.rmDirSync(this.dir);
946
- },
947
- get glob() {
948
- return [`${this.dir}/**/*.css`];
949
- }
950
- });
951
-
952
- // src/node-runtime.ts
953
- init_cjs_shims();
954
- var import_logger2 = require("@pandacss/logger");
955
- var import_chokidar = __toESM(require("chokidar"));
956
- var import_fast_glob = __toESM(require("fast-glob"));
957
- var import_fs_extra = __toESM(require("fs-extra"));
958
- var import_pathe = require("pathe");
959
- var nodeRuntime = {
960
- cwd() {
961
- return process.cwd();
962
- },
963
- env(name) {
964
- return process.env[name];
965
- },
966
- path: {
967
- join: import_pathe.join,
968
- relative: import_pathe.relative,
969
- dirname: import_pathe.dirname,
970
- extname: import_pathe.extname,
971
- isAbsolute: import_pathe.isAbsolute,
972
- sep: import_pathe.sep,
973
- abs(cwd, str) {
974
- return (0, import_pathe.isAbsolute)(str) ? str : (0, import_pathe.join)(cwd, str);
975
- }
976
- },
977
- fs: {
978
- existsSync: import_fs_extra.default.existsSync,
979
- readFileSync(filePath) {
980
- return import_fs_extra.default.readFileSync(filePath, "utf8");
981
- },
982
- glob(opts) {
983
- if (!opts.include)
984
- return [];
985
- const ignore = opts.exclude ?? [];
986
- if (!ignore.length) {
987
- ignore.push("**/*.d.ts");
988
- }
989
- return import_fast_glob.default.sync(opts.include, { cwd: opts.cwd, ignore, absolute: true });
990
- },
991
- writeFile: import_fs_extra.default.writeFile,
992
- writeFileSync: import_fs_extra.default.writeFileSync,
993
- readDirSync: import_fs_extra.default.readdirSync,
994
- rmDirSync: import_fs_extra.default.emptyDirSync,
995
- rmFileSync: import_fs_extra.default.removeSync,
996
- ensureDirSync(path2) {
997
- return import_fs_extra.default.ensureDirSync(path2);
998
- },
999
- watch(options) {
1000
- const { include, exclude, cwd, poll } = options;
1001
- const coalesce = poll || process.platform === "win32";
1002
- const watcher = import_chokidar.default.watch(include, {
1003
- usePolling: poll,
1004
- cwd,
1005
- ignoreInitial: true,
1006
- ignorePermissionErrors: true,
1007
- ignored: exclude,
1008
- awaitWriteFinish: coalesce ? { stabilityThreshold: 50, pollInterval: 10 } : false
1009
- });
1010
- import_logger2.logger.debug("watch:file", `watching [${include}]`);
1011
- process.once("SIGINT", async () => {
1012
- await watcher.close();
1013
- });
1014
- return watcher;
1015
- }
1016
- }
1017
- };
1018
- process.setMaxListeners(Infinity);
1019
- process.on("unhandledRejection", (reason) => {
1020
- import_logger2.logger.error("\u274C", reason);
1021
- });
1022
- process.on("uncaughtException", (reason) => {
1023
- import_logger2.logger.error("\u274C", reason);
1024
- });
1025
-
1026
- // src/output-engine.ts
1027
- init_cjs_shims();
1028
- var import_logger3 = require("@pandacss/logger");
1029
- var PandaOutputEngine = class {
1030
- paths;
1031
- fs;
1032
- path;
1033
- constructor({ paths, runtime: { path: path2, fs } }) {
1034
- this.paths = paths;
1035
- this.fs = fs;
1036
- this.path = path2;
1037
- }
1038
- empty() {
1039
- this.fs.rmDirSync(this.path.join(...this.paths.root));
1040
- }
1041
- async write(output) {
1042
- if (!output)
1043
- return;
1044
- const { dir = this.paths.root, files } = output;
1045
- this.fs.ensureDirSync(this.path.join(...dir));
1046
- return Promise.allSettled(
1047
- files.map(async (artifact) => {
1048
- if (!artifact?.code)
1049
- return;
1050
- const { file, code } = artifact;
1051
- const absPath = this.path.join(...dir, file);
1052
- import_logger3.logger.debug("write:file", dir.slice(-1).concat(file).join("/"));
1053
- return this.fs.writeFile(absPath, code);
1054
- })
1055
- );
1056
- }
1057
- };
1058
-
1059
906
  // src/diff-engine.ts
1060
907
  init_cjs_shims();
1061
908
  var import_config = require("@pandacss/config");
@@ -1190,12 +1037,118 @@ var DiffEngine = class {
1190
1037
  }
1191
1038
  };
1192
1039
 
1040
+ // src/node-runtime.ts
1041
+ init_cjs_shims();
1042
+ var import_logger2 = require("@pandacss/logger");
1043
+ var import_chokidar = __toESM(require("chokidar"));
1044
+ var import_fast_glob = __toESM(require("fast-glob"));
1045
+ var import_fs_extra = __toESM(require("fs-extra"));
1046
+ var import_pathe = require("pathe");
1047
+ var nodeRuntime = {
1048
+ cwd() {
1049
+ return process.cwd();
1050
+ },
1051
+ env(name) {
1052
+ return process.env[name];
1053
+ },
1054
+ path: {
1055
+ join: import_pathe.join,
1056
+ relative: import_pathe.relative,
1057
+ dirname: import_pathe.dirname,
1058
+ extname: import_pathe.extname,
1059
+ isAbsolute: import_pathe.isAbsolute,
1060
+ sep: import_pathe.sep,
1061
+ abs(cwd, str) {
1062
+ return (0, import_pathe.isAbsolute)(str) ? str : (0, import_pathe.join)(cwd, str);
1063
+ }
1064
+ },
1065
+ fs: {
1066
+ existsSync: import_fs_extra.default.existsSync,
1067
+ readFileSync(filePath) {
1068
+ return import_fs_extra.default.readFileSync(filePath, "utf8");
1069
+ },
1070
+ glob(opts) {
1071
+ if (!opts.include)
1072
+ return [];
1073
+ const ignore = opts.exclude ?? [];
1074
+ if (!ignore.length) {
1075
+ ignore.push("**/*.d.ts");
1076
+ }
1077
+ return import_fast_glob.default.sync(opts.include, { cwd: opts.cwd, ignore, absolute: true });
1078
+ },
1079
+ writeFile: import_fs_extra.default.writeFile,
1080
+ writeFileSync: import_fs_extra.default.writeFileSync,
1081
+ readDirSync: import_fs_extra.default.readdirSync,
1082
+ rmDirSync: import_fs_extra.default.emptyDirSync,
1083
+ rmFileSync: import_fs_extra.default.removeSync,
1084
+ ensureDirSync(path2) {
1085
+ return import_fs_extra.default.ensureDirSync(path2);
1086
+ },
1087
+ watch(options) {
1088
+ const { include, exclude, cwd, poll } = options;
1089
+ const coalesce = poll || process.platform === "win32";
1090
+ const watcher = import_chokidar.default.watch(include, {
1091
+ usePolling: poll,
1092
+ cwd,
1093
+ ignoreInitial: true,
1094
+ ignorePermissionErrors: true,
1095
+ ignored: exclude,
1096
+ awaitWriteFinish: coalesce ? { stabilityThreshold: 50, pollInterval: 10 } : false
1097
+ });
1098
+ import_logger2.logger.debug("watch:file", `watching [${include}]`);
1099
+ process.once("SIGINT", async () => {
1100
+ await watcher.close();
1101
+ });
1102
+ return watcher;
1103
+ }
1104
+ }
1105
+ };
1106
+ process.setMaxListeners(Infinity);
1107
+ process.on("unhandledRejection", (reason) => {
1108
+ import_logger2.logger.error("\u274C", reason);
1109
+ });
1110
+ process.on("uncaughtException", (reason) => {
1111
+ import_logger2.logger.error("\u274C", reason);
1112
+ });
1113
+
1114
+ // src/output-engine.ts
1115
+ init_cjs_shims();
1116
+ var import_logger3 = require("@pandacss/logger");
1117
+ var PandaOutputEngine = class {
1118
+ paths;
1119
+ fs;
1120
+ path;
1121
+ constructor({ paths, runtime: { path: path2, fs } }) {
1122
+ this.paths = paths;
1123
+ this.fs = fs;
1124
+ this.path = path2;
1125
+ }
1126
+ empty() {
1127
+ this.fs.rmDirSync(this.path.join(...this.paths.root));
1128
+ }
1129
+ async write(output) {
1130
+ if (!output)
1131
+ return;
1132
+ const { dir = this.paths.root, files } = output;
1133
+ this.fs.ensureDirSync(this.path.join(...dir));
1134
+ return Promise.allSettled(
1135
+ files.map(async (artifact) => {
1136
+ if (!artifact?.code)
1137
+ return;
1138
+ const { file, code } = artifact;
1139
+ const absPath = this.path.join(...dir, file);
1140
+ import_logger3.logger.debug("write:file", dir.slice(-1).concat(file).join("/"));
1141
+ return this.fs.writeFile(absPath, code);
1142
+ })
1143
+ );
1144
+ }
1145
+ };
1146
+
1193
1147
  // src/create-context.ts
1194
1148
  var PandaContext = class extends import_generator2.Generator {
1195
1149
  runtime;
1196
1150
  project;
1197
1151
  getFiles;
1198
- chunks;
1199
1152
  output;
1200
1153
  diff;
1201
1154
  constructor(conf) {
@@ -1215,10 +1168,37 @@ var PandaContext = class extends import_generator2.Generator {
1215
1168
  hooks: conf.hooks,
1216
1169
  parserOptions: { join: this.runtime.path.join, ...this.parserOptions }
1217
1170
  });
1218
- this.chunks = getChunkEngine(this);
1219
1171
  this.output = new PandaOutputEngine(this);
1220
1172
  this.diff = new DiffEngine(this);
1221
1173
  }
1174
+ appendFilesCss() {
1175
+ const files = this.getFiles();
1176
+ const filesWithCss = [];
1177
+ const mergedResult = (0, import_parser.createParserResult)();
1178
+ files.forEach((file) => {
1179
+ const measure = import_logger4.logger.time.debug(`Parsed ${file}`);
1180
+ const result = this.project.parseSourceFile(file);
1181
+ measure();
1182
+ if (!result)
1183
+ return;
1184
+ mergedResult.merge(result);
1185
+ filesWithCss.push(file);
1186
+ });
1187
+ this.appendParserCss(mergedResult);
1188
+ return filesWithCss;
1189
+ }
1190
+ appendAllCss() {
1191
+ this.appendLayerParams();
1192
+ this.appendBaselineCss();
1193
+ this.appendFilesCss();
1194
+ }
1195
+ async writeCss() {
1196
+ return this.output.write({
1197
+ id: "styles.css",
1198
+ dir: this.paths.root,
1199
+ files: [{ file: "styles.css", code: this.getCss() }]
1200
+ });
1201
+ }
1222
1202
  };
1223
1203
 
1224
1204
  // src/config.ts
@@ -1243,6 +1223,7 @@ async function loadConfigAndCreateContext(options = {}) {
1243
1223
  }
1244
1224
  const tsconfigResult = await (0, import_tsconfck.parse)(conf.path, {
1245
1225
  root: cwd,
1226
+ // @ts-ignore
1246
1227
  resolveWithEmptyIfConfigNotFound: true
1247
1228
  });
1248
1229
  if (tsconfigResult) {
@@ -1269,14 +1250,8 @@ async function loadConfigAndCreateContext(options = {}) {
1269
1250
  return new PandaContext({ ...conf, hooks });
1270
1251
  }
1271
1252
 
1272
- // src/extract.ts
1253
+ // src/emit-artifact.ts
1273
1254
  init_cjs_shims();
1274
- var import_core2 = require("@pandacss/core");
1275
- var import_logger5 = require("@pandacss/logger");
1276
- var import_parser2 = require("@pandacss/parser");
1277
- var import_promises2 = require("fs/promises");
1278
- var import_lil_fp = require("lil-fp");
1279
- var import_ts_pattern = require("ts-pattern");
1280
1255
 
1281
1256
  // src/cli-box.ts
1282
1257
  init_cjs_shims();
@@ -2590,50 +2565,7 @@ var createBox = (options) => boxen(options.content, {
2590
2565
  titleAlignment: "center"
2591
2566
  });
2592
2567
 
2593
- // src/extract.ts
2594
- async function bundleStyleChunksWithImports(ctx) {
2595
- const files = ctx.chunks.getFiles();
2596
- await ctx.output.write({
2597
- id: "styles.css",
2598
- dir: ctx.paths.root,
2599
- files: [{ file: "styles.css", code: ctx.getCss({ files }) }]
2600
- });
2601
- return { files, msg: ctx.messages.buildComplete(files.length) };
2602
- }
2603
- async function writeFileChunk(ctx, file) {
2604
- const { path: path2 } = ctx.runtime;
2605
- import_logger5.logger.debug("chunk:write", `File: ${path2.relative(ctx.config.cwd, file)}`);
2606
- const css2 = extractFile(ctx, file);
2607
- if (!css2)
2608
- return;
2609
- const artifact = ctx.chunks.getArtifact(file, css2);
2610
- return ctx.output.write(artifact);
2611
- }
2612
- function extractFile(ctx, file) {
2613
- const {
2614
- runtime: { path: path2 },
2615
- config: { cwd }
2616
- } = ctx;
2617
- return (0, import_lil_fp.pipe)(
2618
- { file: path2.abs(cwd, file) },
2619
- (0, import_lil_fp.tap)(() => import_logger5.logger.debug("file:extract", file)),
2620
- import_lil_fp.Obj.bind("measure", () => import_logger5.logger.time.debug(`Extracted ${file}`)),
2621
- import_lil_fp.Obj.bind(
2622
- "result",
2623
- (0, import_lil_fp.tryCatch)(
2624
- ({ file: file2 }) => ctx.project.parseSourceFile(file2),
2625
- (error) => import_logger5.logger.error("file:parse", error)
2626
- )
2627
- ),
2628
- import_lil_fp.Obj.bind("measureCss", () => import_logger5.logger.time.debug(`Parsed ${file}`)),
2629
- import_lil_fp.Obj.bind("css", ({ result }) => result ? ctx.getParserCss(result) : void 0),
2630
- (0, import_lil_fp.tap)(({ measure, measureCss }) => [measureCss(), measure()]),
2631
- import_lil_fp.Obj.get("css")
2632
- );
2633
- }
2634
- function writeChunks(ctx) {
2635
- return Promise.allSettled(ctx.getFiles().map((file) => writeFileChunk(ctx, file)));
2636
- }
2568
+ // src/emit-artifact.ts
2637
2569
  var randomWords = ["Sweet", "Divine", "Pandalicious", "Super"];
2638
2570
  var pickRandom = (arr) => arr[Math.floor(Math.random() * arr.length)];
2639
2571
  var limit = pLimit(20);
@@ -2651,55 +2583,29 @@ async function emitArtifacts(ctx, ids) {
2651
2583
  msg: ctx.messages.artifactsGenerated()
2652
2584
  };
2653
2585
  }
2654
- async function writeAndBundleCssChunks(ctx) {
2655
- await writeChunks(ctx);
2656
- return bundleStyleChunksWithImports(ctx);
2657
- }
2658
- async function bundleCss(ctx, outfile) {
2659
- const extracted = await writeChunks(ctx);
2660
- const files = ctx.chunks.getFiles();
2661
- const minify = ctx.config.minify;
2662
- await (0, import_promises2.writeFile)(outfile, (0, import_core2.optimizeCss)(ctx.getCss({ files, resolve: true }), { minify }));
2663
- return { files, msg: ctx.messages.buildComplete(extracted.length) };
2664
- }
2665
- async function bundleMinimalFilesCss(ctx, outfile) {
2666
- const files = ctx.getFiles();
2667
- const filesWithCss = [];
2668
- const collector = (0, import_parser2.createParserResult)();
2669
- files.forEach((file) => {
2670
- const measure = import_logger5.logger.time.debug(`Parsed ${file}`);
2671
- const result = ctx.project.parseSourceFile(file);
2672
- measure();
2673
- if (!result)
2674
- return;
2675
- collector.merge(result);
2676
- filesWithCss.push(file);
2677
- });
2678
- const css2 = ctx.getParserCss(collector);
2679
- if (!css2)
2680
- return { files, msg: ctx.messages.buildComplete(files.length) };
2681
- const minify = ctx.config.minify;
2682
- await (0, import_promises2.writeFile)(outfile, (0, import_core2.optimizeCss)(css2, { minify }));
2683
- return { files, msg: ctx.messages.buildComplete(files.length) };
2684
- }
2685
- async function generateCssArtifactOfType(ctx, cssType, outfile) {
2686
- let notFound = false;
2687
- const css2 = (0, import_ts_pattern.match)(cssType).with("preflight", () => ctx.getResetCss()).with("tokens", () => ctx.getTokenCss()).with("static", () => ctx.getStaticCss()).with("global", () => ctx.getGlobalCss()).with("keyframes", () => ctx.getKeyframeCss()).otherwise(() => {
2688
- notFound = true;
2689
- });
2690
- if (notFound)
2691
- return { msg: `No css artifact of type <${cssType}> was found` };
2692
- if (!css2)
2693
- return { msg: `No css to generate for type <${cssType}>` };
2694
- const minify = ctx.config.minify;
2695
- await (0, import_promises2.writeFile)(outfile, (0, import_core2.optimizeCss)(css2, { minify }));
2696
- return { msg: `Successfully generated ${cssType} css artifact \u2728` };
2586
+
2587
+ // src/extract.ts
2588
+ init_cjs_shims();
2589
+ var import_logger5 = require("@pandacss/logger");
2590
+ function extractFile(ctx, filePath) {
2591
+ const file = ctx.runtime.path.abs(ctx.config.cwd, filePath);
2592
+ import_logger5.logger.debug("file:extract", file);
2593
+ const measure = import_logger5.logger.time.debug(`Extracted ${file}`);
2594
+ let result;
2595
+ try {
2596
+ result = ctx.project.parseSourceFile(file);
2597
+ } catch (error) {
2598
+ import_logger5.logger.error("file:parse", error);
2599
+ }
2600
+ ctx.appendParserCss(result);
2601
+ measure();
2602
+ return result;
2697
2603
  }
2698
2604
 
2699
2605
  // src/parse-dependency.ts
2700
2606
  init_cjs_shims();
2701
2607
  var import_is_glob = __toESM(require("is-glob"));
2702
- var import_path = require("path");
2608
+ var import_pathe2 = require("pathe");
2703
2609
 
2704
2610
  // src/parse-glob.ts
2705
2611
  init_cjs_shims();
@@ -2730,9 +2636,9 @@ function parseDependency(fileOrGlob) {
2730
2636
  let message = null;
2731
2637
  if ((0, import_is_glob.default)(fileOrGlob)) {
2732
2638
  const { base, glob: glob2 } = parseGlob(fileOrGlob);
2733
- message = { type: "dir-dependency", dir: (0, import_path.resolve)(base), glob: glob2 };
2639
+ message = { type: "dir-dependency", dir: (0, import_pathe2.resolve)(base), glob: glob2 };
2734
2640
  } else {
2735
- message = { type: "dependency", file: (0, import_path.resolve)(fileOrGlob) };
2641
+ message = { type: "dependency", file: (0, import_pathe2.resolve)(fileOrGlob) };
2736
2642
  }
2737
2643
  if (message.type === "dir-dependency" && process.env.ROLLUP_WATCH === "true") {
2738
2644
  message = { type: "dependency", file: message.dir };
@@ -2741,7 +2647,7 @@ function parseDependency(fileOrGlob) {
2741
2647
  }
2742
2648
 
2743
2649
  // src/builder.ts
2744
- var fileCssMap = /* @__PURE__ */ new Map();
2650
+ var parserResultMap = /* @__PURE__ */ new Map();
2745
2651
  var fileModifiedMap = /* @__PURE__ */ new Map();
2746
2652
  var limit2 = pLimit(20);
2747
2653
  var Builder = class {
@@ -2750,7 +2656,6 @@ var Builder = class {
2750
2656
  */
2751
2657
  context;
2752
2658
  hasEmitted = false;
2753
- hasConfigChanged = false;
2754
2659
  affecteds;
2755
2660
  getConfigPath = () => {
2756
2661
  const configPath = findConfig();
@@ -2768,14 +2673,17 @@ var Builder = class {
2768
2673
  const ctx = this.getContextOrThrow();
2769
2674
  this.affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2770
2675
  this.context = new PandaContext({ ...conf, hooks: ctx.hooks });
2676
+ this.context.appendBaselineCss();
2771
2677
  });
2772
- this.hasConfigChanged = this.affecteds.hasConfigChanged;
2773
2678
  if (this.affecteds.hasConfigChanged) {
2774
2679
  import_logger6.logger.debug("builder", "\u2699\uFE0F Config changed, reloading");
2775
2680
  await ctx.hooks.callHook("config:change", ctx.config);
2776
2681
  return;
2777
2682
  }
2778
- ctx.project.reloadSourceFiles();
2683
+ const hasFilesChanged = this.checkFilesChanged(ctx.getFiles());
2684
+ if (hasFilesChanged) {
2685
+ ctx.project.reloadSourceFiles();
2686
+ }
2779
2687
  };
2780
2688
  async emit() {
2781
2689
  if (this.hasEmitted && this.affecteds?.hasConfigChanged) {
@@ -2786,6 +2694,7 @@ var Builder = class {
2786
2694
  setupContext = async (options) => {
2787
2695
  const { configPath, cwd } = options;
2788
2696
  const ctx = await loadConfigAndCreateContext({ configPath, cwd });
2697
+ ctx.appendBaselineCss();
2789
2698
  this.context = ctx;
2790
2699
  return ctx;
2791
2700
  };
@@ -2795,53 +2704,63 @@ var Builder = class {
2795
2704
  }
2796
2705
  return this.context;
2797
2706
  };
2798
- extractFile = async (ctx, file) => {
2707
+ getFileMeta = (file) => {
2799
2708
  const mtime = (0, import_fs.existsSync)(file) ? import_fs_extra2.default.statSync(file).mtimeMs : -Infinity;
2800
2709
  const isUnchanged = fileModifiedMap.has(file) && mtime === fileModifiedMap.get(file);
2801
- if (isUnchanged && !this.hasConfigChanged)
2802
- return;
2803
- const css2 = extractFile(ctx, file);
2804
- fileModifiedMap.set(file, mtime);
2805
- if (!css2) {
2806
- fileCssMap.delete(file);
2710
+ return { mtime, isUnchanged };
2711
+ };
2712
+ extractFile = async (ctx, file) => {
2713
+ const meta = this.getFileMeta(file);
2714
+ if (meta.isUnchanged) {
2715
+ ctx.appendParserCss(parserResultMap.get(file));
2807
2716
  return;
2808
2717
  }
2809
- fileCssMap.set(file, css2);
2810
- return css2;
2718
+ const result = extractFile(ctx, file);
2719
+ fileModifiedMap.set(file, meta.mtime);
2720
+ if (result) {
2721
+ parserResultMap.set(file, result);
2722
+ }
2723
+ return result;
2811
2724
  };
2725
+ checkFilesChanged(files) {
2726
+ return files.some((file) => !this.getFileMeta(file).isUnchanged);
2727
+ }
2812
2728
  extract = async () => {
2813
2729
  const ctx = this.getContextOrThrow();
2730
+ const files = ctx.getFiles();
2731
+ const hasConfigChanged = this.affecteds ? this.affecteds.hasConfigChanged : false;
2732
+ if (hasConfigChanged)
2733
+ return;
2814
2734
  const done = import_logger6.logger.time.info("Extracted in");
2815
- const promises = ctx.getFiles().map((file) => limit2(() => this.extractFile(ctx, file)));
2735
+ const promises = files.map((file) => limit2(() => this.extractFile(ctx, file)));
2816
2736
  await Promise.allSettled(promises);
2817
2737
  done();
2818
2738
  };
2819
2739
  toString = () => {
2820
2740
  const ctx = this.getContextOrThrow();
2821
- return ctx.getCss({
2822
- files: Array.from(fileCssMap.values()),
2823
- resolve: true
2824
- });
2741
+ return ctx.getCss();
2825
2742
  };
2826
2743
  isValidRoot = (root) => {
2827
2744
  const ctx = this.getContextOrThrow();
2828
2745
  let valid = false;
2829
2746
  root.walkAtRules("layer", (rule) => {
2830
- if (ctx.isValidLayerRule(rule.params)) {
2747
+ if (ctx.layers.isValidParams(rule.params)) {
2831
2748
  valid = true;
2832
2749
  }
2833
2750
  });
2834
2751
  return valid;
2835
2752
  };
2753
+ initialRoot;
2836
2754
  write = (root) => {
2837
- const rootCssContent = root.toString();
2755
+ if (!this.initialRoot) {
2756
+ this.initialRoot = root.toString();
2757
+ }
2838
2758
  root.removeAll();
2839
- root.append(
2840
- (0, import_core3.optimizeCss)(`
2841
- ${rootCssContent}
2759
+ const newCss = (0, import_core.optimizeCss)(`
2760
+ ${this.initialRoot}
2842
2761
  ${this.toString()}
2843
- `)
2844
- );
2762
+ `);
2763
+ root.append(newCss);
2845
2764
  };
2846
2765
  registerDependency = (fn) => {
2847
2766
  const ctx = this.getContextOrThrow();
@@ -2852,7 +2771,7 @@ var Builder = class {
2852
2771
  }
2853
2772
  }
2854
2773
  for (const file of ctx.conf.dependencies) {
2855
- fn({ type: "dependency", file: (0, import_pathe2.resolve)(file) });
2774
+ fn({ type: "dependency", file: (0, import_pathe3.resolve)(file) });
2856
2775
  }
2857
2776
  };
2858
2777
  };
@@ -2860,12 +2779,10 @@ var Builder = class {
2860
2779
  // src/debug-files.ts
2861
2780
  init_cjs_shims();
2862
2781
  var import_logger7 = require("@pandacss/logger");
2863
- var nodePath = __toESM(require("path"));
2782
+ var import_pathe4 = require("pathe");
2864
2783
  async function debugFiles(ctx, options) {
2865
2784
  const files = ctx.getFiles();
2866
2785
  const measureTotal = import_logger7.logger.time.debug(`Done parsing ${files.length} files`);
2867
- ctx.config.minify = false;
2868
- ctx.config.optimize = true;
2869
2786
  const { fs, path: path2 } = ctx.runtime;
2870
2787
  const outdir = options.outdir;
2871
2788
  if (!options.dry && outdir) {
@@ -2878,35 +2795,37 @@ async function debugFiles(ctx, options) {
2878
2795
  return;
2879
2796
  }
2880
2797
  const filesWithCss = [];
2881
- await Promise.allSettled(
2798
+ const results = await Promise.all(
2882
2799
  files.map(async (file) => {
2883
2800
  const measure = import_logger7.logger.time.debug(`Parsed ${file}`);
2884
2801
  const result = ctx.project.parseSourceFile(file);
2885
2802
  measure();
2886
- if (!result)
2887
- return;
2888
- const css2 = ctx.getParserCss(result);
2889
- if (!css2)
2890
- return;
2891
- if (options.dry) {
2892
- console.log({ path: file, ast: result, code: css2 });
2893
- return Promise.resolve();
2894
- }
2895
- if (outdir) {
2896
- filesWithCss.push(file);
2897
- const parsedPath = nodePath.parse(file);
2898
- const relative3 = path2.relative(ctx.config.cwd, parsedPath.dir);
2899
- const astJsonPath = `${relative3}/${parsedPath.name}.ast.json`.replaceAll(path2.sep, "__");
2900
- const cssPath = `${relative3}/${parsedPath.name}.css`.replaceAll(path2.sep, "__");
2901
- import_logger7.logger.info("cli", `Writing ${import_logger7.colors.bold(`${outdir}/${astJsonPath}`)}`);
2902
- import_logger7.logger.info("cli", `Writing ${import_logger7.colors.bold(`${outdir}/${cssPath}`)}`);
2903
- return Promise.allSettled([
2904
- fs.writeFile(`${outdir}/${astJsonPath}`, JSON.stringify(result.toJSON(), null, 2)),
2905
- fs.writeFile(`${outdir}/${cssPath}`, css2)
2906
- ]);
2907
- }
2803
+ return { file, result };
2908
2804
  })
2909
2805
  );
2806
+ results.forEach(({ file, result }) => {
2807
+ if (!result)
2808
+ return;
2809
+ ctx.stylesheet.clean();
2810
+ ctx.appendParserCss(result);
2811
+ const css2 = ctx.stylesheet.toCss({ optimize: true, minify: false });
2812
+ if (options.dry) {
2813
+ console.log({ path: file, ast: result, code: css2 });
2814
+ }
2815
+ if (outdir) {
2816
+ filesWithCss.push(file);
2817
+ const parsedPath = (0, import_pathe4.parse)(file);
2818
+ const relative3 = path2.relative(ctx.config.cwd, parsedPath.dir);
2819
+ const astJsonPath = `${relative3}/${parsedPath.name}.ast.json`.replaceAll(path2.sep, "__");
2820
+ const cssPath = `${relative3}/${parsedPath.name}.css`.replaceAll(path2.sep, "__");
2821
+ import_logger7.logger.info("cli", `Writing ${import_logger7.colors.bold(`${outdir}/${astJsonPath}`)}`);
2822
+ import_logger7.logger.info("cli", `Writing ${import_logger7.colors.bold(`${outdir}/${cssPath}`)}`);
2823
+ return Promise.allSettled([
2824
+ fs.writeFile(`${outdir}/${astJsonPath}`, JSON.stringify(result.toJSON(), null, 2)),
2825
+ fs.writeFile(`${outdir}/${cssPath}`, css2)
2826
+ ]);
2827
+ }
2828
+ });
2910
2829
  import_logger7.logger.info("cli", `Found ${import_logger7.colors.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2911
2830
  measureTotal();
2912
2831
  }
@@ -2932,17 +2851,18 @@ async function execCommand(cmd, cwd) {
2932
2851
  // src/generate.ts
2933
2852
  init_cjs_shims();
2934
2853
  var import_logger9 = require("@pandacss/logger");
2935
- var import_ts_pattern2 = require("ts-pattern");
2854
+ var import_ts_pattern = require("ts-pattern");
2936
2855
  async function build(ctx, ids) {
2937
2856
  await emitArtifacts(ctx, ids);
2938
2857
  if (ctx.config.emitTokensOnly) {
2939
2858
  return import_logger9.logger.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens \u2728");
2940
2859
  }
2941
- const { msg } = await writeAndBundleCssChunks(ctx);
2942
- import_logger9.logger.info("css:emit", msg);
2860
+ ctx.appendAllCss();
2861
+ await ctx.writeCss();
2862
+ import_logger9.logger.info("css:emit", "Successfully built the css files \u2728");
2943
2863
  }
2944
2864
  async function generate(config, configPath) {
2945
- const ctx = await loadConfigAndCreateContext({ config, configPath });
2865
+ let ctx = await loadConfigAndCreateContext({ config, configPath });
2946
2866
  await build(ctx);
2947
2867
  const {
2948
2868
  runtime: { fs, path: path2 },
@@ -2951,7 +2871,9 @@ async function generate(config, configPath) {
2951
2871
  if (ctx.config.watch) {
2952
2872
  const configWatcher = fs.watch({ include: ctx.conf.dependencies });
2953
2873
  configWatcher.on("change", async () => {
2954
- const affecteds = await ctx.diff.reloadConfigAndRefreshContext();
2874
+ const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2875
+ ctx = new PandaContext({ ...conf, hooks: ctx.hooks });
2876
+ });
2955
2877
  if (!affecteds.artifacts.size)
2956
2878
  return;
2957
2879
  import_logger9.logger.info("config:change", "Config changed, restarting...");
@@ -2961,16 +2883,18 @@ async function generate(config, configPath) {
2961
2883
  const contentWatcher = fs.watch(ctx.config);
2962
2884
  contentWatcher.on("all", async (event, file) => {
2963
2885
  import_logger9.logger.info(`file:${event}`, file);
2964
- (0, import_ts_pattern2.match)(event).with("unlink", () => {
2886
+ await (0, import_ts_pattern.match)(event).with("unlink", () => {
2965
2887
  ctx.project.removeSourceFile(path2.abs(cwd, file));
2966
- ctx.chunks.rm(file);
2967
- }).with("change", async () => {
2888
+ }).with("change", () => {
2968
2889
  ctx.project.reloadSourceFile(file);
2969
- await writeFileChunk(ctx, file);
2970
- return bundleStyleChunksWithImports(ctx);
2971
- }).with("add", async () => {
2890
+ const result = ctx.project.parseSourceFile(file);
2891
+ ctx.appendParserCss(result);
2892
+ return ctx.writeCss();
2893
+ }).with("add", () => {
2972
2894
  ctx.project.createSourceFile(file);
2973
- return bundleStyleChunksWithImports(ctx);
2895
+ const result = ctx.project.parseSourceFile(file);
2896
+ ctx.appendParserCss(result);
2897
+ return ctx.writeCss();
2974
2898
  }).otherwise(() => {
2975
2899
  });
2976
2900
  });
@@ -3010,7 +2934,7 @@ var import_logger10 = require("@pandacss/logger");
3010
2934
  var import_fs_extra3 = __toESM(require("fs-extra"));
3011
2935
  var import_look_it_up3 = require("look-it-up");
3012
2936
  var import_outdent2 = require("outdent");
3013
- var import_path2 = require("path");
2937
+ var import_pathe5 = require("pathe");
3014
2938
  var import_preferred_pm2 = __toESM(require("preferred-pm"));
3015
2939
  var import_prettier = __toESM(require("prettier"));
3016
2940
  async function setupConfig(cwd, opts = {}) {
@@ -3055,7 +2979,7 @@ jsxFramework: '${jsxFramework}',` : ""}
3055
2979
  syntax: '${syntax}'` : ""}
3056
2980
  })
3057
2981
  `;
3058
- await import_fs_extra3.default.writeFile((0, import_path2.join)(cwd, file), import_prettier.default.format(content));
2982
+ await import_fs_extra3.default.writeFile((0, import_pathe5.join)(cwd, file), import_prettier.default.format(content));
3059
2983
  import_logger10.logger.log(import_generator3.messages.thankYou());
3060
2984
  }
3061
2985
  }
@@ -3068,26 +2992,23 @@ module.exports = {
3068
2992
  },
3069
2993
  }
3070
2994
  `;
3071
- await import_fs_extra3.default.writeFile((0, import_path2.join)(cwd, "postcss.config.cjs"), content);
2995
+ await import_fs_extra3.default.writeFile((0, import_pathe5.join)(cwd, "postcss.config.cjs"), content);
3072
2996
  }
3073
2997
 
3074
2998
  // src/ship-files.ts
3075
2999
  init_cjs_shims();
3076
3000
  var import_logger11 = require("@pandacss/logger");
3077
- var import_parser3 = require("@pandacss/parser");
3078
- var import_promises3 = require("fs/promises");
3079
- var path = __toESM(require("path"));
3001
+ var import_parser2 = require("@pandacss/parser");
3002
+ var import_promises2 = require("fs/promises");
3003
+ var path = __toESM(require("pathe"));
3080
3004
  async function shipFiles(ctx, outfile) {
3081
3005
  const files = ctx.getFiles();
3082
- const extractResult = (0, import_parser3.createParserResult)();
3006
+ const extractResult = (0, import_parser2.createParserResult)();
3083
3007
  const filesWithCss = [];
3084
3008
  files.forEach(async (file) => {
3085
3009
  const result = ctx.project.parseSourceFile(file);
3086
3010
  if (!result || result.isEmpty())
3087
3011
  return;
3088
- const css2 = ctx.getParserCss(result);
3089
- if (!css2)
3090
- return;
3091
3012
  extractResult.merge(result);
3092
3013
  filesWithCss.push(path.relative(ctx.config.cwd, file));
3093
3014
  });
@@ -3097,7 +3018,7 @@ async function shipFiles(ctx, outfile) {
3097
3018
  const output = JSON.stringify(extractResult.toJSON(), null, minify ? 0 : 2);
3098
3019
  const dirname2 = ctx.runtime.path.dirname(outfile);
3099
3020
  ctx.runtime.fs.ensureDirSync(dirname2);
3100
- await (0, import_promises3.writeFile)(outfile, output);
3021
+ await (0, import_promises2.writeFile)(outfile, output);
3101
3022
  import_logger11.logger.info("cli", "Done!");
3102
3023
  }
3103
3024
  // Annotate the CommonJS export names for ESM import in node:
@@ -3105,21 +3026,17 @@ async function shipFiles(ctx, outfile) {
3105
3026
  Builder,
3106
3027
  PandaContext,
3107
3028
  analyzeTokens,
3108
- bundleCss,
3109
- bundleMinimalFilesCss,
3110
3029
  debugFiles,
3111
3030
  emitArtifacts,
3112
3031
  execCommand,
3113
3032
  extractFile,
3114
3033
  findConfig,
3115
3034
  generate,
3116
- generateCssArtifactOfType,
3117
3035
  loadConfigAndCreateContext,
3118
3036
  parseDependency,
3119
3037
  setupConfig,
3120
3038
  setupGitIgnore,
3121
3039
  setupPostcss,
3122
3040
  shipFiles,
3123
- writeAnalyzeJSON,
3124
- writeAndBundleCssChunks
3041
+ writeAnalyzeJSON
3125
3042
  });