@pandacss/node 0.28.0 → 0.29.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.d.mts CHANGED
@@ -4,7 +4,6 @@ import { StyleEncoder, Stylesheet } from '@pandacss/core';
4
4
  import { Generator } from '@pandacss/generator';
5
5
  import * as _pandacss_parser from '@pandacss/parser';
6
6
  import { Project, ParserResult } from '@pandacss/parser';
7
- import * as _pandacss_config from '@pandacss/config';
8
7
  import { Root, Message } from 'postcss';
9
8
 
10
9
  declare class DiffEngine {
@@ -14,13 +13,13 @@ declare class DiffEngine {
14
13
  /**
15
14
  * Reload config from disk and refresh the context
16
15
  */
17
- reloadConfigAndRefreshContext(fn?: (conf: LoadConfigResult) => void): Promise<_pandacss_config.DiffConfigResult>;
16
+ reloadConfigAndRefreshContext(fn?: (conf: LoadConfigResult) => void): Promise<_pandacss_types.DiffConfigResult>;
18
17
  /**
19
18
  * Update the context from the refreshed config
20
19
  * then persist the changes on each affected engines
21
20
  * Returns the list of affected artifacts/engines
22
21
  */
23
- refresh(conf: LoadConfigResult, fn?: (conf: LoadConfigResult) => void): _pandacss_config.DiffConfigResult;
22
+ refresh(conf: LoadConfigResult, fn?: (conf: LoadConfigResult) => void): _pandacss_types.DiffConfigResult;
24
23
  }
25
24
 
26
25
  interface OutputEngineOptions extends Generator {
@@ -42,7 +41,9 @@ declare class PandaContext extends Generator {
42
41
  project: Project;
43
42
  output: OutputEngine;
44
43
  diff: DiffEngine;
44
+ explicitDeps: string[];
45
45
  constructor(conf: LoadConfigResult);
46
+ private getExplicitDependencies;
46
47
  getFiles: () => string[];
47
48
  parseFile: (filePath: string, styleEncoder?: StyleEncoder) => ParserResult | undefined;
48
49
  parseFiles: (styleEncoder?: StyleEncoder) => {
@@ -51,7 +52,7 @@ declare class PandaContext extends Generator {
51
52
  results: ParserResult[];
52
53
  };
53
54
  writeCss: (sheet?: Stylesheet) => Promise<PromiseSettledResult<void>[]> | undefined;
54
- watchConfig: (cb: () => void | Promise<void>, opts?: Omit<WatchOptions, 'include'>) => void;
55
+ watchConfig: (cb: (file: string) => void | Promise<void>, opts?: Omit<WatchOptions, 'include'>) => void;
55
56
  watchFiles: (cb: (event: WatcherEventType, file: string) => void | Promise<void>) => void;
56
57
  }
57
58
 
@@ -206,9 +207,9 @@ declare class Builder {
206
207
  context: PandaContext | undefined;
207
208
  private hasEmitted;
208
209
  private filesMeta;
210
+ private explicitDepsMeta;
209
211
  private affecteds;
210
212
  private configDependencies;
211
- getConfigPath: (cwd?: string) => string;
212
213
  setConfigDependencies(options: SetupContextOptions): void;
213
214
  setup: (options?: {
214
215
  configPath?: string;
package/dist/index.d.ts CHANGED
@@ -4,7 +4,6 @@ import { StyleEncoder, Stylesheet } from '@pandacss/core';
4
4
  import { Generator } from '@pandacss/generator';
5
5
  import * as _pandacss_parser from '@pandacss/parser';
6
6
  import { Project, ParserResult } from '@pandacss/parser';
7
- import * as _pandacss_config from '@pandacss/config';
8
7
  import { Root, Message } from 'postcss';
9
8
 
10
9
  declare class DiffEngine {
@@ -14,13 +13,13 @@ declare class DiffEngine {
14
13
  /**
15
14
  * Reload config from disk and refresh the context
16
15
  */
17
- reloadConfigAndRefreshContext(fn?: (conf: LoadConfigResult) => void): Promise<_pandacss_config.DiffConfigResult>;
16
+ reloadConfigAndRefreshContext(fn?: (conf: LoadConfigResult) => void): Promise<_pandacss_types.DiffConfigResult>;
18
17
  /**
19
18
  * Update the context from the refreshed config
20
19
  * then persist the changes on each affected engines
21
20
  * Returns the list of affected artifacts/engines
22
21
  */
23
- refresh(conf: LoadConfigResult, fn?: (conf: LoadConfigResult) => void): _pandacss_config.DiffConfigResult;
22
+ refresh(conf: LoadConfigResult, fn?: (conf: LoadConfigResult) => void): _pandacss_types.DiffConfigResult;
24
23
  }
25
24
 
26
25
  interface OutputEngineOptions extends Generator {
@@ -42,7 +41,9 @@ declare class PandaContext extends Generator {
42
41
  project: Project;
43
42
  output: OutputEngine;
44
43
  diff: DiffEngine;
44
+ explicitDeps: string[];
45
45
  constructor(conf: LoadConfigResult);
46
+ private getExplicitDependencies;
46
47
  getFiles: () => string[];
47
48
  parseFile: (filePath: string, styleEncoder?: StyleEncoder) => ParserResult | undefined;
48
49
  parseFiles: (styleEncoder?: StyleEncoder) => {
@@ -51,7 +52,7 @@ declare class PandaContext extends Generator {
51
52
  results: ParserResult[];
52
53
  };
53
54
  writeCss: (sheet?: Stylesheet) => Promise<PromiseSettledResult<void>[]> | undefined;
54
- watchConfig: (cb: () => void | Promise<void>, opts?: Omit<WatchOptions, 'include'>) => void;
55
+ watchConfig: (cb: (file: string) => void | Promise<void>, opts?: Omit<WatchOptions, 'include'>) => void;
55
56
  watchFiles: (cb: (event: WatcherEventType, file: string) => void | Promise<void>) => void;
56
57
  }
57
58
 
@@ -206,9 +207,9 @@ declare class Builder {
206
207
  context: PandaContext | undefined;
207
208
  private hasEmitted;
208
209
  private filesMeta;
210
+ private explicitDepsMeta;
209
211
  private affecteds;
210
212
  private configDependencies;
211
- getConfigPath: (cwd?: string) => string;
212
213
  setConfigDependencies(options: SetupContextOptions): void;
213
214
  setup: (options?: {
214
215
  configPath?: string;
package/dist/index.js CHANGED
@@ -789,8 +789,8 @@ async function buildInfo(ctx, outfile) {
789
789
  init_cjs_shims();
790
790
  var import_config4 = require("@pandacss/config");
791
791
  var import_core = require("@pandacss/core");
792
- var import_error = require("@pandacss/error");
793
792
  var import_logger6 = require("@pandacss/logger");
793
+ var import_shared2 = require("@pandacss/shared");
794
794
  var import_fs = require("fs");
795
795
  var import_path3 = require("path");
796
796
 
@@ -2245,6 +2245,7 @@ init_cjs_shims();
2245
2245
  var import_generator2 = require("@pandacss/generator");
2246
2246
  var import_logger5 = require("@pandacss/logger");
2247
2247
  var import_parser = require("@pandacss/parser");
2248
+ var import_shared = require("@pandacss/shared");
2248
2249
  var import_perfect_debounce = require("perfect-debounce");
2249
2250
 
2250
2251
  // src/diff-engine.ts
@@ -2402,6 +2403,7 @@ var PandaContext = class extends import_generator2.Generator {
2402
2403
  project;
2403
2404
  output;
2404
2405
  diff;
2406
+ explicitDeps = [];
2405
2407
  constructor(conf) {
2406
2408
  super(conf);
2407
2409
  const config = conf.config;
@@ -2422,7 +2424,14 @@ var PandaContext = class extends import_generator2.Generator {
2422
2424
  });
2423
2425
  this.output = new OutputEngine(this);
2424
2426
  this.diff = new DiffEngine(this);
2427
+ this.explicitDeps = this.getExplicitDependencies();
2425
2428
  }
2429
+ getExplicitDependencies = () => {
2430
+ const { cwd, dependencies } = this.config;
2431
+ if (!dependencies)
2432
+ return [];
2433
+ return this.runtime.fs.glob({ include: dependencies, cwd });
2434
+ };
2426
2435
  getFiles = () => {
2427
2436
  const { include, exclude, cwd } = this.config;
2428
2437
  return this.runtime.fs.glob({ include, exclude, cwd });
@@ -2473,16 +2482,16 @@ var PandaContext = class extends import_generator2.Generator {
2473
2482
  const { cwd, poll, exclude } = opts ?? {};
2474
2483
  import_logger5.logger.info("ctx:watch", this.messages.configWatch());
2475
2484
  const watcher = this.runtime.fs.watch({
2476
- include: this.conf.dependencies,
2485
+ include: (0, import_shared.uniq)([...this.explicitDeps, ...this.conf.dependencies]),
2477
2486
  exclude,
2478
2487
  cwd,
2479
2488
  poll
2480
2489
  });
2481
2490
  watcher.on(
2482
2491
  "change",
2483
- (0, import_perfect_debounce.debounce)(async () => {
2492
+ (0, import_perfect_debounce.debounce)(async (file) => {
2484
2493
  import_logger5.logger.info("ctx:change", "config changed, rebuilding...");
2485
- await cb();
2494
+ await cb(file);
2486
2495
  })
2487
2496
  );
2488
2497
  };
@@ -2607,15 +2616,9 @@ var Builder = class {
2607
2616
  context;
2608
2617
  hasEmitted = false;
2609
2618
  filesMeta;
2619
+ explicitDepsMeta;
2610
2620
  affecteds;
2611
2621
  configDependencies = /* @__PURE__ */ new Set();
2612
- getConfigPath = (cwd) => {
2613
- const configPath = (0, import_config4.findConfig)({ cwd });
2614
- if (!configPath) {
2615
- throw new import_error.ConfigNotFoundError();
2616
- }
2617
- return configPath;
2618
- };
2619
2622
  setConfigDependencies(options) {
2620
2623
  const tsOptions = this.context?.conf.tsOptions ?? { baseUrl: void 0, pathMappings: [] };
2621
2624
  const compilerOptions = this.context?.conf.tsconfig?.compilerOptions ?? {};
@@ -2625,13 +2628,15 @@ var Builder = class {
2625
2628
  ...foundDeps,
2626
2629
  ...(this.context?.conf.dependencies ?? []).map((file) => (0, import_path3.resolve)(cwd, file))
2627
2630
  ]);
2628
- this.configDependencies = configDeps;
2631
+ configDeps.forEach((file) => {
2632
+ this.configDependencies.add(file);
2633
+ });
2629
2634
  import_logger6.logger.debug("builder", "Config dependencies");
2630
2635
  import_logger6.logger.debug("builder", configDeps);
2631
2636
  }
2632
2637
  setup = async (options = {}) => {
2633
2638
  import_logger6.logger.debug("builder", "\u{1F6A7} Setup");
2634
- const configPath = options.configPath ?? this.getConfigPath(options.cwd);
2639
+ const configPath = options.configPath ?? (0, import_config4.findConfig)({ cwd: options.cwd });
2635
2640
  this.setConfigDependencies({ configPath, cwd: options.cwd });
2636
2641
  if (!this.context) {
2637
2642
  return this.setupContext({ configPath, cwd: options.cwd });
@@ -2641,6 +2646,14 @@ var Builder = class {
2641
2646
  this.context = new PandaContext(conf);
2642
2647
  });
2643
2648
  import_logger6.logger.debug("builder", this.affecteds);
2649
+ this.explicitDepsMeta = this.checkFilesChanged(this.context.explicitDeps);
2650
+ if (this.explicitDepsMeta.hasFilesChanged) {
2651
+ this.explicitDepsMeta.changes.forEach((meta, file) => {
2652
+ fileModifiedMap.set(file, meta.mtime);
2653
+ });
2654
+ import_logger6.logger.debug("builder", "\u2699\uFE0F Explicit config dependencies changed");
2655
+ this.affecteds.hasConfigChanged = true;
2656
+ }
2644
2657
  if (this.affecteds.hasConfigChanged) {
2645
2658
  import_logger6.logger.debug("builder", "\u2699\uFE0F Config changed, reloading");
2646
2659
  await ctx.hooks["config:change"]?.({ config: ctx.config, changes: this.affecteds });
@@ -2662,12 +2675,16 @@ var Builder = class {
2662
2675
  setupContext = async (options) => {
2663
2676
  const { configPath, cwd } = options;
2664
2677
  const ctx = await loadConfigAndCreateContext({ configPath, cwd });
2678
+ const configDeps = (0, import_shared2.uniq)([...ctx.conf.dependencies, ...ctx.explicitDeps]);
2679
+ configDeps.forEach((file) => {
2680
+ this.configDependencies.add((0, import_path3.resolve)(cwd || ctx.conf.config.cwd, file));
2681
+ });
2665
2682
  this.context = ctx;
2666
2683
  return ctx;
2667
2684
  };
2668
2685
  getContextOrThrow = () => {
2669
2686
  if (!this.context) {
2670
- throw new Error("context not loaded");
2687
+ throw new import_shared2.PandaError("NO_CONTEXT", "context not loaded");
2671
2688
  }
2672
2689
  return this.context;
2673
2690
  };
@@ -2786,7 +2803,8 @@ var cssgen = async (ctx, options) => {
2786
2803
  ctx.appendCssOfType(type, sheet);
2787
2804
  if (outfile) {
2788
2805
  const css = ctx.getCss(sheet);
2789
- ctx.runtime.fs.writeFileSync(outfile, css);
2806
+ import_logger8.logger.info("css", ctx.runtime.path.resolve(outfile));
2807
+ await ctx.runtime.fs.writeFile(outfile, css);
2790
2808
  } else {
2791
2809
  await ctx.writeCss(sheet);
2792
2810
  }
@@ -2801,7 +2819,8 @@ var cssgen = async (ctx, options) => {
2801
2819
  ctx.appendParserCss(sheet);
2802
2820
  if (outfile) {
2803
2821
  const css = ctx.getCss(sheet);
2804
- ctx.runtime.fs.writeFileSync(outfile, css);
2822
+ import_logger8.logger.info("css", ctx.runtime.path.resolve(outfile));
2823
+ await ctx.runtime.fs.writeFile(outfile, css);
2805
2824
  } else {
2806
2825
  await ctx.writeCss(sheet);
2807
2826
  }
@@ -2866,7 +2885,6 @@ async function debug(ctx, options) {
2866
2885
  // src/generate.ts
2867
2886
  init_cjs_shims();
2868
2887
  var import_logger10 = require("@pandacss/logger");
2869
- var import_ts_pattern = require("ts-pattern");
2870
2888
  async function build(ctx, artifactIds) {
2871
2889
  await codegen(ctx, artifactIds);
2872
2890
  if (ctx.config.emitTokensOnly) {
@@ -2884,25 +2902,19 @@ async function build(ctx, artifactIds) {
2884
2902
  async function generate(config, configPath) {
2885
2903
  let ctx = await loadConfigAndCreateContext({ config, configPath });
2886
2904
  await build(ctx);
2887
- const {
2888
- runtime: { fs: fs2, path: path2 },
2889
- config: { cwd }
2890
- } = ctx;
2891
- if (ctx.config.watch) {
2892
- const configWatcher = fs2.watch({ include: ctx.conf.dependencies });
2893
- configWatcher.on("change", async () => {
2894
- const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2895
- ctx = new PandaContext(conf);
2896
- });
2897
- if (!affecteds.hasConfigChanged) {
2898
- import_logger10.logger.debug("builder", "Config didnt change, skipping rebuild");
2899
- return;
2900
- }
2901
- import_logger10.logger.info("config:change", "Config changed, restarting...");
2902
- await ctx.hooks["config:change"]?.({ config: ctx.config, changes: affecteds });
2903
- return build(ctx, Array.from(affecteds.artifacts));
2904
- });
2905
- const contentWatcher = fs2.watch(ctx.config);
2905
+ const { cwd, watch, poll } = ctx.config;
2906
+ if (watch) {
2907
+ ctx.watchConfig(
2908
+ async () => {
2909
+ const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2910
+ ctx = new PandaContext(conf);
2911
+ });
2912
+ import_logger10.logger.info("ctx:updated", "config rebuilt \u2705");
2913
+ await ctx.hooks["config:change"]?.({ config: ctx.config, changes: affecteds });
2914
+ return build(ctx, Array.from(affecteds.artifacts));
2915
+ },
2916
+ { cwd, poll }
2917
+ );
2906
2918
  const bundleStyles = async (ctx2, changedFilePath) => {
2907
2919
  const outfile = ctx2.runtime.path.join(...ctx2.paths.root, "styles.css");
2908
2920
  const parserResult = ctx2.project.parseSourceFile(changedFilePath);
@@ -2916,21 +2928,18 @@ async function generate(config, configPath) {
2916
2928
  return { msg: ctx2.messages.buildComplete(1) };
2917
2929
  }
2918
2930
  };
2919
- contentWatcher.on("all", async (event, file) => {
2920
- import_logger10.logger.info(`file:${event}`, file);
2921
- const filePath = path2.abs(cwd, file);
2922
- (0, import_ts_pattern.match)(event).with("unlink", () => {
2923
- ctx.project.removeSourceFile(path2.abs(cwd, file));
2924
- }).with("change", async () => {
2931
+ ctx.watchFiles(async (event, file) => {
2932
+ const filePath = ctx.runtime.path.abs(cwd, file);
2933
+ if (event === "unlink") {
2934
+ ctx.project.removeSourceFile(filePath);
2935
+ } else if (event === "change") {
2925
2936
  ctx.project.reloadSourceFile(file);
2926
- return bundleStyles(ctx, filePath);
2927
- }).with("add", async () => {
2937
+ await bundleStyles(ctx, filePath);
2938
+ } else if (event === "add") {
2928
2939
  ctx.project.createSourceFile(file);
2929
- return bundleStyles(ctx, filePath);
2930
- }).otherwise(() => {
2931
- });
2940
+ await bundleStyles(ctx, filePath);
2941
+ }
2932
2942
  });
2933
- import_logger10.logger.info("ctx:watch", ctx.messages.watch());
2934
2943
  }
2935
2944
  }
2936
2945
 
@@ -2964,6 +2973,7 @@ init_cjs_shims();
2964
2973
  var import_config7 = require("@pandacss/config");
2965
2974
  var import_core2 = require("@pandacss/core");
2966
2975
  var import_logger11 = require("@pandacss/logger");
2976
+ var import_shared3 = require("@pandacss/shared");
2967
2977
  var import_fs_extra2 = __toESM(require("fs-extra"));
2968
2978
  var import_look_it_up2 = require("look-it-up");
2969
2979
  var import_outdent2 = require("outdent");
@@ -2972,7 +2982,14 @@ var import_preferred_pm = __toESM(require("preferred-pm"));
2972
2982
  var import_prettier = __toESM(require("prettier"));
2973
2983
  async function setupConfig(cwd, opts = {}) {
2974
2984
  const { force, outExtension, jsxFramework, syntax } = opts;
2975
- const configFile = (0, import_config7.findConfig)({ cwd });
2985
+ let configFile;
2986
+ try {
2987
+ configFile = (0, import_config7.findConfig)({ cwd });
2988
+ } catch (err) {
2989
+ if (!(err instanceof import_shared3.PandaError)) {
2990
+ throw err;
2991
+ }
2992
+ }
2976
2993
  const pmResult = await (0, import_preferred_pm.default)(cwd);
2977
2994
  const pm = pmResult?.name ?? "npm";
2978
2995
  const cmd = pm === "npm" ? "npm run" : pm;
package/dist/index.mjs CHANGED
@@ -764,8 +764,8 @@ async function buildInfo(ctx, outfile) {
764
764
  init_esm_shims();
765
765
  import { findConfig, getConfigDependencies } from "@pandacss/config";
766
766
  import { optimizeCss } from "@pandacss/core";
767
- import { ConfigNotFoundError } from "@pandacss/error";
768
767
  import { logger as logger6 } from "@pandacss/logger";
768
+ import { PandaError, uniq as uniq2 } from "@pandacss/shared";
769
769
  import { existsSync, statSync } from "fs";
770
770
  import { normalize as normalize2, resolve as resolve3 } from "path";
771
771
 
@@ -2220,6 +2220,7 @@ init_esm_shims();
2220
2220
  import { Generator as Generator2 } from "@pandacss/generator";
2221
2221
  import { logger as logger5 } from "@pandacss/logger";
2222
2222
  import { Project } from "@pandacss/parser";
2223
+ import { uniq } from "@pandacss/shared";
2223
2224
  import { debounce } from "perfect-debounce";
2224
2225
 
2225
2226
  // src/diff-engine.ts
@@ -2377,6 +2378,7 @@ var PandaContext = class extends Generator2 {
2377
2378
  project;
2378
2379
  output;
2379
2380
  diff;
2381
+ explicitDeps = [];
2380
2382
  constructor(conf) {
2381
2383
  super(conf);
2382
2384
  const config = conf.config;
@@ -2397,7 +2399,14 @@ var PandaContext = class extends Generator2 {
2397
2399
  });
2398
2400
  this.output = new OutputEngine(this);
2399
2401
  this.diff = new DiffEngine(this);
2402
+ this.explicitDeps = this.getExplicitDependencies();
2400
2403
  }
2404
+ getExplicitDependencies = () => {
2405
+ const { cwd, dependencies } = this.config;
2406
+ if (!dependencies)
2407
+ return [];
2408
+ return this.runtime.fs.glob({ include: dependencies, cwd });
2409
+ };
2401
2410
  getFiles = () => {
2402
2411
  const { include, exclude, cwd } = this.config;
2403
2412
  return this.runtime.fs.glob({ include, exclude, cwd });
@@ -2448,16 +2457,16 @@ var PandaContext = class extends Generator2 {
2448
2457
  const { cwd, poll, exclude } = opts ?? {};
2449
2458
  logger5.info("ctx:watch", this.messages.configWatch());
2450
2459
  const watcher = this.runtime.fs.watch({
2451
- include: this.conf.dependencies,
2460
+ include: uniq([...this.explicitDeps, ...this.conf.dependencies]),
2452
2461
  exclude,
2453
2462
  cwd,
2454
2463
  poll
2455
2464
  });
2456
2465
  watcher.on(
2457
2466
  "change",
2458
- debounce(async () => {
2467
+ debounce(async (file) => {
2459
2468
  logger5.info("ctx:change", "config changed, rebuilding...");
2460
- await cb();
2469
+ await cb(file);
2461
2470
  })
2462
2471
  );
2463
2472
  };
@@ -2582,15 +2591,9 @@ var Builder = class {
2582
2591
  context;
2583
2592
  hasEmitted = false;
2584
2593
  filesMeta;
2594
+ explicitDepsMeta;
2585
2595
  affecteds;
2586
2596
  configDependencies = /* @__PURE__ */ new Set();
2587
- getConfigPath = (cwd) => {
2588
- const configPath = findConfig({ cwd });
2589
- if (!configPath) {
2590
- throw new ConfigNotFoundError();
2591
- }
2592
- return configPath;
2593
- };
2594
2597
  setConfigDependencies(options) {
2595
2598
  const tsOptions = this.context?.conf.tsOptions ?? { baseUrl: void 0, pathMappings: [] };
2596
2599
  const compilerOptions = this.context?.conf.tsconfig?.compilerOptions ?? {};
@@ -2600,13 +2603,15 @@ var Builder = class {
2600
2603
  ...foundDeps,
2601
2604
  ...(this.context?.conf.dependencies ?? []).map((file) => resolve3(cwd, file))
2602
2605
  ]);
2603
- this.configDependencies = configDeps;
2606
+ configDeps.forEach((file) => {
2607
+ this.configDependencies.add(file);
2608
+ });
2604
2609
  logger6.debug("builder", "Config dependencies");
2605
2610
  logger6.debug("builder", configDeps);
2606
2611
  }
2607
2612
  setup = async (options = {}) => {
2608
2613
  logger6.debug("builder", "\u{1F6A7} Setup");
2609
- const configPath = options.configPath ?? this.getConfigPath(options.cwd);
2614
+ const configPath = options.configPath ?? findConfig({ cwd: options.cwd });
2610
2615
  this.setConfigDependencies({ configPath, cwd: options.cwd });
2611
2616
  if (!this.context) {
2612
2617
  return this.setupContext({ configPath, cwd: options.cwd });
@@ -2616,6 +2621,14 @@ var Builder = class {
2616
2621
  this.context = new PandaContext(conf);
2617
2622
  });
2618
2623
  logger6.debug("builder", this.affecteds);
2624
+ this.explicitDepsMeta = this.checkFilesChanged(this.context.explicitDeps);
2625
+ if (this.explicitDepsMeta.hasFilesChanged) {
2626
+ this.explicitDepsMeta.changes.forEach((meta, file) => {
2627
+ fileModifiedMap.set(file, meta.mtime);
2628
+ });
2629
+ logger6.debug("builder", "\u2699\uFE0F Explicit config dependencies changed");
2630
+ this.affecteds.hasConfigChanged = true;
2631
+ }
2619
2632
  if (this.affecteds.hasConfigChanged) {
2620
2633
  logger6.debug("builder", "\u2699\uFE0F Config changed, reloading");
2621
2634
  await ctx.hooks["config:change"]?.({ config: ctx.config, changes: this.affecteds });
@@ -2637,12 +2650,16 @@ var Builder = class {
2637
2650
  setupContext = async (options) => {
2638
2651
  const { configPath, cwd } = options;
2639
2652
  const ctx = await loadConfigAndCreateContext({ configPath, cwd });
2653
+ const configDeps = uniq2([...ctx.conf.dependencies, ...ctx.explicitDeps]);
2654
+ configDeps.forEach((file) => {
2655
+ this.configDependencies.add(resolve3(cwd || ctx.conf.config.cwd, file));
2656
+ });
2640
2657
  this.context = ctx;
2641
2658
  return ctx;
2642
2659
  };
2643
2660
  getContextOrThrow = () => {
2644
2661
  if (!this.context) {
2645
- throw new Error("context not loaded");
2662
+ throw new PandaError("NO_CONTEXT", "context not loaded");
2646
2663
  }
2647
2664
  return this.context;
2648
2665
  };
@@ -2761,7 +2778,8 @@ var cssgen = async (ctx, options) => {
2761
2778
  ctx.appendCssOfType(type, sheet);
2762
2779
  if (outfile) {
2763
2780
  const css = ctx.getCss(sheet);
2764
- ctx.runtime.fs.writeFileSync(outfile, css);
2781
+ logger8.info("css", ctx.runtime.path.resolve(outfile));
2782
+ await ctx.runtime.fs.writeFile(outfile, css);
2765
2783
  } else {
2766
2784
  await ctx.writeCss(sheet);
2767
2785
  }
@@ -2776,7 +2794,8 @@ var cssgen = async (ctx, options) => {
2776
2794
  ctx.appendParserCss(sheet);
2777
2795
  if (outfile) {
2778
2796
  const css = ctx.getCss(sheet);
2779
- ctx.runtime.fs.writeFileSync(outfile, css);
2797
+ logger8.info("css", ctx.runtime.path.resolve(outfile));
2798
+ await ctx.runtime.fs.writeFile(outfile, css);
2780
2799
  } else {
2781
2800
  await ctx.writeCss(sheet);
2782
2801
  }
@@ -2841,7 +2860,6 @@ async function debug(ctx, options) {
2841
2860
  // src/generate.ts
2842
2861
  init_esm_shims();
2843
2862
  import { logger as logger10 } from "@pandacss/logger";
2844
- import { match } from "ts-pattern";
2845
2863
  async function build(ctx, artifactIds) {
2846
2864
  await codegen(ctx, artifactIds);
2847
2865
  if (ctx.config.emitTokensOnly) {
@@ -2859,25 +2877,19 @@ async function build(ctx, artifactIds) {
2859
2877
  async function generate(config, configPath) {
2860
2878
  let ctx = await loadConfigAndCreateContext({ config, configPath });
2861
2879
  await build(ctx);
2862
- const {
2863
- runtime: { fs: fs2, path: path2 },
2864
- config: { cwd }
2865
- } = ctx;
2866
- if (ctx.config.watch) {
2867
- const configWatcher = fs2.watch({ include: ctx.conf.dependencies });
2868
- configWatcher.on("change", async () => {
2869
- const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2870
- ctx = new PandaContext(conf);
2871
- });
2872
- if (!affecteds.hasConfigChanged) {
2873
- logger10.debug("builder", "Config didnt change, skipping rebuild");
2874
- return;
2875
- }
2876
- logger10.info("config:change", "Config changed, restarting...");
2877
- await ctx.hooks["config:change"]?.({ config: ctx.config, changes: affecteds });
2878
- return build(ctx, Array.from(affecteds.artifacts));
2879
- });
2880
- const contentWatcher = fs2.watch(ctx.config);
2880
+ const { cwd, watch, poll } = ctx.config;
2881
+ if (watch) {
2882
+ ctx.watchConfig(
2883
+ async () => {
2884
+ const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2885
+ ctx = new PandaContext(conf);
2886
+ });
2887
+ logger10.info("ctx:updated", "config rebuilt \u2705");
2888
+ await ctx.hooks["config:change"]?.({ config: ctx.config, changes: affecteds });
2889
+ return build(ctx, Array.from(affecteds.artifacts));
2890
+ },
2891
+ { cwd, poll }
2892
+ );
2881
2893
  const bundleStyles = async (ctx2, changedFilePath) => {
2882
2894
  const outfile = ctx2.runtime.path.join(...ctx2.paths.root, "styles.css");
2883
2895
  const parserResult = ctx2.project.parseSourceFile(changedFilePath);
@@ -2891,21 +2903,18 @@ async function generate(config, configPath) {
2891
2903
  return { msg: ctx2.messages.buildComplete(1) };
2892
2904
  }
2893
2905
  };
2894
- contentWatcher.on("all", async (event, file) => {
2895
- logger10.info(`file:${event}`, file);
2896
- const filePath = path2.abs(cwd, file);
2897
- match(event).with("unlink", () => {
2898
- ctx.project.removeSourceFile(path2.abs(cwd, file));
2899
- }).with("change", async () => {
2906
+ ctx.watchFiles(async (event, file) => {
2907
+ const filePath = ctx.runtime.path.abs(cwd, file);
2908
+ if (event === "unlink") {
2909
+ ctx.project.removeSourceFile(filePath);
2910
+ } else if (event === "change") {
2900
2911
  ctx.project.reloadSourceFile(file);
2901
- return bundleStyles(ctx, filePath);
2902
- }).with("add", async () => {
2912
+ await bundleStyles(ctx, filePath);
2913
+ } else if (event === "add") {
2903
2914
  ctx.project.createSourceFile(file);
2904
- return bundleStyles(ctx, filePath);
2905
- }).otherwise(() => {
2906
- });
2915
+ await bundleStyles(ctx, filePath);
2916
+ }
2907
2917
  });
2908
- logger10.info("ctx:watch", ctx.messages.watch());
2909
2918
  }
2910
2919
  }
2911
2920
 
@@ -2939,6 +2948,7 @@ init_esm_shims();
2939
2948
  import { findConfig as findConfig2 } from "@pandacss/config";
2940
2949
  import { messages } from "@pandacss/core";
2941
2950
  import { logger as logger11, quote } from "@pandacss/logger";
2951
+ import { PandaError as PandaError2 } from "@pandacss/shared";
2942
2952
  import fsExtra2 from "fs-extra";
2943
2953
  import { lookItUpSync as lookItUpSync2 } from "look-it-up";
2944
2954
  import { outdent as outdent2 } from "outdent";
@@ -2947,7 +2957,14 @@ import getPackageManager from "preferred-pm";
2947
2957
  import prettier from "prettier";
2948
2958
  async function setupConfig(cwd, opts = {}) {
2949
2959
  const { force, outExtension, jsxFramework, syntax } = opts;
2950
- const configFile = findConfig2({ cwd });
2960
+ let configFile;
2961
+ try {
2962
+ configFile = findConfig2({ cwd });
2963
+ } catch (err) {
2964
+ if (!(err instanceof PandaError2)) {
2965
+ throw err;
2966
+ }
2967
+ }
2951
2968
  const pmResult = await getPackageManager(cwd);
2952
2969
  const pm = pmResult?.name ?? "npm";
2953
2970
  const cmd = pm === "npm" ? "npm run" : pm;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/node",
3
- "version": "0.28.0",
3
+ "version": "0.29.1",
4
4
  "description": "The core css panda library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -53,16 +53,15 @@
53
53
  "ts-pattern": "5.0.5",
54
54
  "tsconfck": "^2.1.2",
55
55
  "v8-profiler-next": "^1.10.0",
56
- "@pandacss/config": "0.28.0",
57
- "@pandacss/core": "0.28.0",
58
- "@pandacss/error": "0.28.0",
59
- "@pandacss/extractor": "0.28.0",
60
- "@pandacss/generator": "0.28.0",
61
- "@pandacss/logger": "0.28.0",
62
- "@pandacss/parser": "0.28.0",
63
- "@pandacss/shared": "0.28.0",
64
- "@pandacss/token-dictionary": "0.28.0",
65
- "@pandacss/types": "0.28.0"
56
+ "@pandacss/config": "0.29.1",
57
+ "@pandacss/core": "0.29.1",
58
+ "@pandacss/extractor": "0.29.1",
59
+ "@pandacss/generator": "0.29.1",
60
+ "@pandacss/logger": "0.29.1",
61
+ "@pandacss/parser": "0.29.1",
62
+ "@pandacss/shared": "0.29.1",
63
+ "@pandacss/token-dictionary": "0.29.1",
64
+ "@pandacss/types": "0.29.1"
66
65
  },
67
66
  "devDependencies": {
68
67
  "@types/fs-extra": "11.0.4",