@pandacss/node 0.27.3 → 0.29.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.d.mts CHANGED
@@ -1,10 +1,9 @@
1
1
  import * as _pandacss_types from '@pandacss/types';
2
- import { LoadConfigResult, Artifact, Runtime, PandaHookable, ConfigResultWithHooks, WatchOptions, WatcherEventType, ParserResultInterface, ArtifactId, Config, CssArtifactType } from '@pandacss/types';
2
+ import { LoadConfigResult, Artifact, Runtime, PandaHooks, WatchOptions, WatcherEventType, ParserResultInterface, ArtifactId, Config, CssArtifactType } from '@pandacss/types';
3
3
  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,18 +13,18 @@ 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 {
27
26
  runtime: Runtime;
28
- hooks: PandaHookable;
27
+ hooks: Partial<PandaHooks>;
29
28
  }
30
29
  declare class OutputEngine {
31
30
  private paths;
@@ -42,7 +41,9 @@ declare class PandaContext extends Generator {
42
41
  project: Project;
43
42
  output: OutputEngine;
44
43
  diff: DiffEngine;
45
- constructor(conf: ConfigResultWithHooks);
44
+ explicitDeps: string[];
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;
@@ -245,6 +246,8 @@ declare function codegen(ctx: PandaContext, ids?: ArtifactId[]): Promise<{
245
246
  msg: string;
246
247
  }>;
247
248
 
249
+ declare const startProfiling: (cwd: string, prefix: string) => Promise<() => void>;
250
+
248
251
  declare function loadConfigAndCreateContext(options?: {
249
252
  cwd?: string;
250
253
  config?: Config;
@@ -278,4 +281,4 @@ type SetupOptions = Partial<Config> & {
278
281
  declare function setupConfig(cwd: string, opts?: SetupOptions): Promise<void>;
279
282
  declare function setupPostcss(cwd: string): Promise<void>;
280
283
 
281
- export { Builder, type CssGenOptions, PandaContext, analyzeTokens, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, parseDependency, setupConfig, setupGitIgnore, setupPostcss, writeAnalyzeJSON };
284
+ export { Builder, type CssGenOptions, PandaContext, analyzeTokens, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, parseDependency, setupConfig, setupGitIgnore, setupPostcss, startProfiling, writeAnalyzeJSON };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import * as _pandacss_types from '@pandacss/types';
2
- import { LoadConfigResult, Artifact, Runtime, PandaHookable, ConfigResultWithHooks, WatchOptions, WatcherEventType, ParserResultInterface, ArtifactId, Config, CssArtifactType } from '@pandacss/types';
2
+ import { LoadConfigResult, Artifact, Runtime, PandaHooks, WatchOptions, WatcherEventType, ParserResultInterface, ArtifactId, Config, CssArtifactType } from '@pandacss/types';
3
3
  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,18 +13,18 @@ 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 {
27
26
  runtime: Runtime;
28
- hooks: PandaHookable;
27
+ hooks: Partial<PandaHooks>;
29
28
  }
30
29
  declare class OutputEngine {
31
30
  private paths;
@@ -42,7 +41,9 @@ declare class PandaContext extends Generator {
42
41
  project: Project;
43
42
  output: OutputEngine;
44
43
  diff: DiffEngine;
45
- constructor(conf: ConfigResultWithHooks);
44
+ explicitDeps: string[];
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;
@@ -245,6 +246,8 @@ declare function codegen(ctx: PandaContext, ids?: ArtifactId[]): Promise<{
245
246
  msg: string;
246
247
  }>;
247
248
 
249
+ declare const startProfiling: (cwd: string, prefix: string) => Promise<() => void>;
250
+
248
251
  declare function loadConfigAndCreateContext(options?: {
249
252
  cwd?: string;
250
253
  config?: Config;
@@ -278,4 +281,4 @@ type SetupOptions = Partial<Config> & {
278
281
  declare function setupConfig(cwd: string, opts?: SetupOptions): Promise<void>;
279
282
  declare function setupPostcss(cwd: string): Promise<void>;
280
283
 
281
- export { Builder, type CssGenOptions, PandaContext, analyzeTokens, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, parseDependency, setupConfig, setupGitIgnore, setupPostcss, writeAnalyzeJSON };
284
+ export { Builder, type CssGenOptions, PandaContext, analyzeTokens, buildInfo, codegen, cssgen, debug, generate, loadConfigAndCreateContext, parseDependency, setupConfig, setupGitIgnore, setupPostcss, startProfiling, writeAnalyzeJSON };
package/dist/index.js CHANGED
@@ -416,6 +416,7 @@ __export(src_exports, {
416
416
  setupConfig: () => setupConfig,
417
417
  setupGitIgnore: () => setupGitIgnore,
418
418
  setupPostcss: () => setupPostcss,
419
+ startProfiling: () => startProfiling,
419
420
  writeAnalyzeJSON: () => writeAnalyzeJSON
420
421
  });
421
422
  module.exports = __toCommonJS(src_exports);
@@ -788,8 +789,8 @@ async function buildInfo(ctx, outfile) {
788
789
  init_cjs_shims();
789
790
  var import_config4 = require("@pandacss/config");
790
791
  var import_core = require("@pandacss/core");
791
- var import_error = require("@pandacss/error");
792
792
  var import_logger6 = require("@pandacss/logger");
793
+ var import_shared2 = require("@pandacss/shared");
793
794
  var import_fs = require("fs");
794
795
  var import_path3 = require("path");
795
796
 
@@ -2224,7 +2225,7 @@ async function codegen(ctx, ids) {
2224
2225
  ctx.output.empty();
2225
2226
  const promises = ctx.getArtifacts(ids).map((artifact) => limit(() => ctx.output.write(artifact)));
2226
2227
  await Promise.allSettled(promises);
2227
- void ctx.hooks.callHook("generator:done");
2228
+ await ctx.hooks["codegen:done"]?.({ changed: ids });
2228
2229
  return {
2229
2230
  box: createBox({
2230
2231
  content: ctx.messages.codegenComplete(),
@@ -2238,13 +2239,13 @@ async function codegen(ctx, ids) {
2238
2239
  init_cjs_shims();
2239
2240
  var import_config3 = require("@pandacss/config");
2240
2241
  var import_browserslist = __toESM(require("browserslist"));
2241
- var import_hookable = require("hookable");
2242
2242
 
2243
2243
  // src/create-context.ts
2244
2244
  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
@@ -2326,8 +2327,8 @@ var nodeRuntime = {
2326
2327
  readDirSync: import_fs_extra.default.readdirSync,
2327
2328
  rmDirSync: import_fs_extra.default.emptyDirSync,
2328
2329
  rmFileSync: import_fs_extra.default.removeSync,
2329
- ensureDirSync(path) {
2330
- return import_fs_extra.default.ensureDirSync(path);
2330
+ ensureDirSync(path2) {
2331
+ return import_fs_extra.default.ensureDirSync(path2);
2331
2332
  },
2332
2333
  watch(options) {
2333
2334
  const { include, exclude, cwd, poll } = options;
@@ -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
  };
@@ -2551,15 +2560,7 @@ async function loadConfigAndCreateContext(options = {}) {
2551
2560
  if (tsConfResult) {
2552
2561
  Object.assign(conf, tsConfResult);
2553
2562
  }
2554
- const hooks = (0, import_hookable.createHooks)();
2555
- if (conf.config.hooks) {
2556
- hooks.addHooks(conf.config.hooks);
2557
- }
2558
- await hooks.callHook("config:resolved", conf);
2559
- if (conf.config.logLevel === "debug") {
2560
- (0, import_hookable.createDebugger)(hooks, { tag: "panda" });
2561
- }
2562
- return new PandaContext({ ...conf, hooks });
2563
+ return new PandaContext(conf);
2563
2564
  }
2564
2565
 
2565
2566
  // src/parse-dependency.ts
@@ -2615,15 +2616,9 @@ var Builder = class {
2615
2616
  context;
2616
2617
  hasEmitted = false;
2617
2618
  filesMeta;
2619
+ explicitDepsMeta;
2618
2620
  affecteds;
2619
2621
  configDependencies = /* @__PURE__ */ new Set();
2620
- getConfigPath = (cwd) => {
2621
- const configPath = (0, import_config4.findConfig)({ cwd });
2622
- if (!configPath) {
2623
- throw new import_error.ConfigNotFoundError();
2624
- }
2625
- return configPath;
2626
- };
2627
2622
  setConfigDependencies(options) {
2628
2623
  const tsOptions = this.context?.conf.tsOptions ?? { baseUrl: void 0, pathMappings: [] };
2629
2624
  const compilerOptions = this.context?.conf.tsconfig?.compilerOptions ?? {};
@@ -2633,25 +2628,35 @@ var Builder = class {
2633
2628
  ...foundDeps,
2634
2629
  ...(this.context?.conf.dependencies ?? []).map((file) => (0, import_path3.resolve)(cwd, file))
2635
2630
  ]);
2636
- this.configDependencies = configDeps;
2631
+ configDeps.forEach((file) => {
2632
+ this.configDependencies.add(file);
2633
+ });
2637
2634
  import_logger6.logger.debug("builder", "Config dependencies");
2638
2635
  import_logger6.logger.debug("builder", configDeps);
2639
2636
  }
2640
2637
  setup = async (options = {}) => {
2641
2638
  import_logger6.logger.debug("builder", "\u{1F6A7} Setup");
2642
- const configPath = options.configPath ?? this.getConfigPath(options.cwd);
2639
+ const configPath = options.configPath ?? (0, import_config4.findConfig)({ cwd: options.cwd });
2643
2640
  this.setConfigDependencies({ configPath, cwd: options.cwd });
2644
2641
  if (!this.context) {
2645
2642
  return this.setupContext({ configPath, cwd: options.cwd });
2646
2643
  }
2647
2644
  const ctx = this.getContextOrThrow();
2648
2645
  this.affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2649
- this.context = new PandaContext({ ...conf, hooks: ctx.hooks });
2646
+ this.context = new PandaContext(conf);
2650
2647
  });
2651
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
+ }
2652
2657
  if (this.affecteds.hasConfigChanged) {
2653
2658
  import_logger6.logger.debug("builder", "\u2699\uFE0F Config changed, reloading");
2654
- await ctx.hooks.callHook("config:change", ctx.config);
2659
+ await ctx.hooks["config:change"]?.({ config: ctx.config, changes: this.affecteds });
2655
2660
  return;
2656
2661
  }
2657
2662
  this.filesMeta = this.checkFilesChanged(ctx.getFiles());
@@ -2670,12 +2675,16 @@ var Builder = class {
2670
2675
  setupContext = async (options) => {
2671
2676
  const { configPath, cwd } = options;
2672
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
+ });
2673
2682
  this.context = ctx;
2674
2683
  return ctx;
2675
2684
  };
2676
2685
  getContextOrThrow = () => {
2677
2686
  if (!this.context) {
2678
- throw new Error("context not loaded");
2687
+ throw new import_shared2.PandaError("NO_CONTEXT", "context not loaded");
2679
2688
  }
2680
2689
  return this.context;
2681
2690
  };
@@ -2753,25 +2762,56 @@ var Builder = class {
2753
2762
  };
2754
2763
  };
2755
2764
 
2756
- // src/cssgen.ts
2765
+ // src/cpu-profile.ts
2757
2766
  init_cjs_shims();
2758
2767
  var import_logger7 = require("@pandacss/logger");
2768
+ var import_fs2 = __toESM(require("fs"));
2769
+ var import_path4 = __toESM(require("path"));
2770
+ var startProfiling = async (cwd, prefix) => {
2771
+ const v8Profiler = (await import("v8-profiler-next")).default;
2772
+ const date = /* @__PURE__ */ new Date();
2773
+ const timestamp = date.toISOString().replace(/[-:.]/g, "");
2774
+ const title = `panda-${prefix}-${timestamp}`;
2775
+ v8Profiler.setGenerateType(1);
2776
+ v8Profiler.startProfiling(title, true);
2777
+ const stopProfiling = () => {
2778
+ const profile = v8Profiler.stopProfiling(title);
2779
+ profile.export(function(error, result) {
2780
+ if (error) {
2781
+ console.error(error);
2782
+ return;
2783
+ }
2784
+ if (!result)
2785
+ return;
2786
+ const outfile = import_path4.default.join(cwd, `${title}.cpuprofile`);
2787
+ import_fs2.default.writeFileSync(outfile, result);
2788
+ import_logger7.logger.info("cpu-prof", outfile);
2789
+ profile.delete();
2790
+ });
2791
+ };
2792
+ return stopProfiling;
2793
+ };
2794
+
2795
+ // src/cssgen.ts
2796
+ init_cjs_shims();
2797
+ var import_logger8 = require("@pandacss/logger");
2759
2798
  var cssgen = async (ctx, options) => {
2760
2799
  const { outfile, type, minimal } = options;
2761
2800
  const sheet = ctx.createSheet();
2762
2801
  if (type) {
2763
- const done = import_logger7.logger.time.info(ctx.messages.cssArtifactComplete(type));
2802
+ const done = import_logger8.logger.time.info(ctx.messages.cssArtifactComplete(type));
2764
2803
  ctx.appendCssOfType(type, sheet);
2765
2804
  if (outfile) {
2766
2805
  const css = ctx.getCss(sheet);
2767
- 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);
2768
2808
  } else {
2769
2809
  await ctx.writeCss(sheet);
2770
2810
  }
2771
2811
  done();
2772
2812
  } else {
2773
2813
  const { files } = ctx.parseFiles();
2774
- const done = import_logger7.logger.time.info(ctx.messages.buildComplete(files.length));
2814
+ const done = import_logger8.logger.time.info(ctx.messages.buildComplete(files.length));
2775
2815
  if (!minimal) {
2776
2816
  ctx.appendLayerParams(sheet);
2777
2817
  ctx.appendBaselineCss(sheet);
@@ -2779,7 +2819,8 @@ var cssgen = async (ctx, options) => {
2779
2819
  ctx.appendParserCss(sheet);
2780
2820
  if (outfile) {
2781
2821
  const css = ctx.getCss(sheet);
2782
- 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);
2783
2824
  } else {
2784
2825
  await ctx.writeCss(sheet);
2785
2826
  }
@@ -2789,19 +2830,19 @@ var cssgen = async (ctx, options) => {
2789
2830
 
2790
2831
  // src/debug.ts
2791
2832
  init_cjs_shims();
2792
- var import_logger8 = require("@pandacss/logger");
2793
- var import_path4 = require("path");
2833
+ var import_logger9 = require("@pandacss/logger");
2834
+ var import_path5 = require("path");
2794
2835
  async function debug(ctx, options) {
2795
2836
  const files = ctx.getFiles();
2796
- const measureTotal = import_logger8.logger.time.debug(`Done parsing ${files.length} files`);
2837
+ const measureTotal = import_logger9.logger.time.debug(`Done parsing ${files.length} files`);
2797
2838
  ctx.config.minify = false;
2798
2839
  ctx.config.optimize = true;
2799
- const { fs, path } = ctx.runtime;
2840
+ const { fs: fs2, path: path2 } = ctx.runtime;
2800
2841
  const outdir = options.outdir;
2801
2842
  if (!options.dry && outdir) {
2802
- fs.ensureDirSync(outdir);
2803
- import_logger8.logger.info("cli", `Writing ${import_logger8.colors.bold(`${outdir}/config.json`)}`);
2804
- await fs.writeFile(`${outdir}/config.json`, JSON.stringify(ctx.config, null, 2));
2843
+ fs2.ensureDirSync(outdir);
2844
+ import_logger9.logger.info("cli", `Writing ${import_logger9.colors.bold(`${outdir}/config.json`)}`);
2845
+ await fs2.writeFile(`${outdir}/config.json`, JSON.stringify(ctx.config, null, 2));
2805
2846
  }
2806
2847
  if (options.onlyConfig) {
2807
2848
  measureTotal();
@@ -2809,14 +2850,14 @@ async function debug(ctx, options) {
2809
2850
  }
2810
2851
  const filesWithCss = [];
2811
2852
  files.map((file) => {
2812
- const measure = import_logger8.logger.time.debug(`Parsed ${file}`);
2853
+ const measure = import_logger9.logger.time.debug(`Parsed ${file}`);
2813
2854
  const encoder = ctx.encoder.clone();
2814
2855
  const result = ctx.project.parseSourceFile(file, encoder);
2815
2856
  measure();
2816
2857
  if (!result || result.isEmpty() || encoder.isEmpty())
2817
2858
  return;
2818
2859
  const styles4 = ctx.decoder.clone().collect(encoder);
2819
- const css = ctx.getParserCss(styles4, file);
2860
+ const css = ctx.getParserCss(styles4);
2820
2861
  if (!css)
2821
2862
  return;
2822
2863
  if (options.dry) {
@@ -2825,32 +2866,31 @@ async function debug(ctx, options) {
2825
2866
  }
2826
2867
  if (outdir) {
2827
2868
  filesWithCss.push(file);
2828
- const parsedPath = (0, import_path4.parse)(file);
2829
- const relative2 = path.relative(ctx.config.cwd, parsedPath.dir);
2830
- const astJsonPath = `${relative2}/${parsedPath.name}.ast.json`.replaceAll(path.sep, "__");
2831
- const cssPath = `${relative2}/${parsedPath.name}.css`.replaceAll(path.sep, "__");
2832
- import_logger8.logger.info("cli", `Writing ${import_logger8.colors.bold(`${outdir}/${astJsonPath}`)}`);
2833
- import_logger8.logger.info("cli", `Writing ${import_logger8.colors.bold(`${outdir}/${cssPath}`)}`);
2869
+ const parsedPath = (0, import_path5.parse)(file);
2870
+ const relative2 = path2.relative(ctx.config.cwd, parsedPath.dir);
2871
+ const astJsonPath = `${relative2}/${parsedPath.name}.ast.json`.replaceAll(path2.sep, "__");
2872
+ const cssPath = `${relative2}/${parsedPath.name}.css`.replaceAll(path2.sep, "__");
2873
+ import_logger9.logger.info("cli", `Writing ${import_logger9.colors.bold(`${outdir}/${astJsonPath}`)}`);
2874
+ import_logger9.logger.info("cli", `Writing ${import_logger9.colors.bold(`${outdir}/${cssPath}`)}`);
2834
2875
  return Promise.allSettled([
2835
- fs.writeFile(`${outdir}/${astJsonPath}`, JSON.stringify(result.toJSON(), null, 2)),
2836
- fs.writeFile(`${outdir}/${cssPath}`, css)
2876
+ fs2.writeFile(`${outdir}/${astJsonPath}`, JSON.stringify(result.toJSON(), null, 2)),
2877
+ fs2.writeFile(`${outdir}/${cssPath}`, css)
2837
2878
  ]);
2838
2879
  }
2839
2880
  });
2840
- import_logger8.logger.info("cli", `Found ${import_logger8.colors.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2881
+ import_logger9.logger.info("cli", `Found ${import_logger9.colors.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2841
2882
  measureTotal();
2842
2883
  }
2843
2884
 
2844
2885
  // src/generate.ts
2845
2886
  init_cjs_shims();
2846
- var import_logger9 = require("@pandacss/logger");
2847
- var import_ts_pattern = require("ts-pattern");
2887
+ var import_logger10 = require("@pandacss/logger");
2848
2888
  async function build(ctx, artifactIds) {
2849
2889
  await codegen(ctx, artifactIds);
2850
2890
  if (ctx.config.emitTokensOnly) {
2851
- return import_logger9.logger.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens \u2728");
2891
+ return import_logger10.logger.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens \u2728");
2852
2892
  }
2853
- const done = import_logger9.logger.time.info("");
2893
+ const done = import_logger10.logger.time.info("");
2854
2894
  const sheet = ctx.createSheet();
2855
2895
  ctx.appendLayerParams(sheet);
2856
2896
  ctx.appendBaselineCss(sheet);
@@ -2862,25 +2902,19 @@ async function build(ctx, artifactIds) {
2862
2902
  async function generate(config, configPath) {
2863
2903
  let ctx = await loadConfigAndCreateContext({ config, configPath });
2864
2904
  await build(ctx);
2865
- const {
2866
- runtime: { fs, path },
2867
- config: { cwd }
2868
- } = ctx;
2869
- if (ctx.config.watch) {
2870
- const configWatcher = fs.watch({ include: ctx.conf.dependencies });
2871
- configWatcher.on("change", async () => {
2872
- const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2873
- ctx = new PandaContext({ ...conf, hooks: ctx.hooks });
2874
- });
2875
- if (!affecteds.hasConfigChanged) {
2876
- import_logger9.logger.debug("builder", "Config didnt change, skipping rebuild");
2877
- return;
2878
- }
2879
- import_logger9.logger.info("config:change", "Config changed, restarting...");
2880
- await ctx.hooks.callHook("config:change", ctx.config);
2881
- return build(ctx, Array.from(affecteds.artifacts));
2882
- });
2883
- const contentWatcher = fs.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
+ );
2884
2918
  const bundleStyles = async (ctx2, changedFilePath) => {
2885
2919
  const outfile = ctx2.runtime.path.join(...ctx2.paths.root, "styles.css");
2886
2920
  const parserResult = ctx2.project.parseSourceFile(changedFilePath);
@@ -2894,27 +2928,24 @@ async function generate(config, configPath) {
2894
2928
  return { msg: ctx2.messages.buildComplete(1) };
2895
2929
  }
2896
2930
  };
2897
- contentWatcher.on("all", async (event, file) => {
2898
- import_logger9.logger.info(`file:${event}`, file);
2899
- const filePath = path.abs(cwd, file);
2900
- (0, import_ts_pattern.match)(event).with("unlink", () => {
2901
- ctx.project.removeSourceFile(path.abs(cwd, file));
2902
- }).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") {
2903
2936
  ctx.project.reloadSourceFile(file);
2904
- return bundleStyles(ctx, filePath);
2905
- }).with("add", async () => {
2937
+ await bundleStyles(ctx, filePath);
2938
+ } else if (event === "add") {
2906
2939
  ctx.project.createSourceFile(file);
2907
- return bundleStyles(ctx, filePath);
2908
- }).otherwise(() => {
2909
- });
2940
+ await bundleStyles(ctx, filePath);
2941
+ }
2910
2942
  });
2911
- import_logger9.logger.info("ctx:watch", ctx.messages.watch());
2912
2943
  }
2913
2944
  }
2914
2945
 
2915
2946
  // src/git-ignore.ts
2916
2947
  init_cjs_shims();
2917
- var import_fs2 = require("fs");
2948
+ var import_fs3 = require("fs");
2918
2949
  var import_look_it_up = require("look-it-up");
2919
2950
  var import_outdent = __toESM(require("outdent"));
2920
2951
  function setupGitIgnore(ctx) {
@@ -2929,11 +2960,11 @@ function setupGitIgnore(ctx) {
2929
2960
  `;
2930
2961
  const file = (0, import_look_it_up.lookItUpSync)(".gitignore");
2931
2962
  if (!file) {
2932
- return (0, import_fs2.writeFileSync)(".gitignore", txt);
2963
+ return (0, import_fs3.writeFileSync)(".gitignore", txt);
2933
2964
  }
2934
- const content = (0, import_fs2.readFileSync)(file, "utf-8");
2965
+ const content = (0, import_fs3.readFileSync)(file, "utf-8");
2935
2966
  if (!content.includes(outdir)) {
2936
- (0, import_fs2.appendFileSync)(file, txt);
2967
+ (0, import_fs3.appendFileSync)(file, txt);
2937
2968
  }
2938
2969
  }
2939
2970
 
@@ -2941,11 +2972,11 @@ function setupGitIgnore(ctx) {
2941
2972
  init_cjs_shims();
2942
2973
  var import_config7 = require("@pandacss/config");
2943
2974
  var import_core2 = require("@pandacss/core");
2944
- var import_logger10 = require("@pandacss/logger");
2975
+ var import_logger11 = require("@pandacss/logger");
2945
2976
  var import_fs_extra2 = __toESM(require("fs-extra"));
2946
2977
  var import_look_it_up2 = require("look-it-up");
2947
2978
  var import_outdent2 = require("outdent");
2948
- var import_path5 = require("path");
2979
+ var import_path6 = require("path");
2949
2980
  var import_preferred_pm = __toESM(require("preferred-pm"));
2950
2981
  var import_prettier = __toESM(require("prettier"));
2951
2982
  async function setupConfig(cwd, opts = {}) {
@@ -2956,9 +2987,9 @@ async function setupConfig(cwd, opts = {}) {
2956
2987
  const cmd = pm === "npm" ? "npm run" : pm;
2957
2988
  const isTs = (0, import_look_it_up2.lookItUpSync)("tsconfig.json", cwd);
2958
2989
  const file = isTs ? "panda.config.ts" : "panda.config.mjs";
2959
- import_logger10.logger.info("init:config", `creating panda config file: ${(0, import_logger10.quote)(file)}`);
2990
+ import_logger11.logger.info("init:config", `creating panda config file: ${(0, import_logger11.quote)(file)}`);
2960
2991
  if (!force && configFile) {
2961
- import_logger10.logger.warn("init:config", import_core2.messages.configExists(cmd));
2992
+ import_logger11.logger.warn("init:config", import_core2.messages.configExists(cmd));
2962
2993
  } else {
2963
2994
  const content = import_outdent2.outdent`
2964
2995
  import { defineConfig } from "@pandacss/dev"
@@ -2990,12 +3021,12 @@ jsxFramework: '${jsxFramework}',` : ""}
2990
3021
  syntax: '${syntax}'` : ""}
2991
3022
  })
2992
3023
  `;
2993
- await import_fs_extra2.default.writeFile((0, import_path5.join)(cwd, file), import_prettier.default.format(content, { parser: "babel" }));
2994
- import_logger10.logger.log(import_core2.messages.thankYou());
3024
+ await import_fs_extra2.default.writeFile((0, import_path6.join)(cwd, file), import_prettier.default.format(content, { parser: "babel" }));
3025
+ import_logger11.logger.log(import_core2.messages.thankYou());
2995
3026
  }
2996
3027
  }
2997
3028
  async function setupPostcss(cwd) {
2998
- import_logger10.logger.info("init:postcss", `creating postcss config file: ${(0, import_logger10.quote)("postcss.config.cjs")}`);
3029
+ import_logger11.logger.info("init:postcss", `creating postcss config file: ${(0, import_logger11.quote)("postcss.config.cjs")}`);
2999
3030
  const content = import_outdent2.outdent`
3000
3031
  module.exports = {
3001
3032
  plugins: {
@@ -3003,7 +3034,7 @@ module.exports = {
3003
3034
  },
3004
3035
  }
3005
3036
  `;
3006
- await import_fs_extra2.default.writeFile((0, import_path5.join)(cwd, "postcss.config.cjs"), content);
3037
+ await import_fs_extra2.default.writeFile((0, import_path6.join)(cwd, "postcss.config.cjs"), content);
3007
3038
  }
3008
3039
  // Annotate the CommonJS export names for ESM import in node:
3009
3040
  0 && (module.exports = {
@@ -3020,5 +3051,6 @@ module.exports = {
3020
3051
  setupConfig,
3021
3052
  setupGitIgnore,
3022
3053
  setupPostcss,
3054
+ startProfiling,
3023
3055
  writeAnalyzeJSON
3024
3056
  });
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
 
@@ -2200,7 +2200,7 @@ async function codegen(ctx, ids) {
2200
2200
  ctx.output.empty();
2201
2201
  const promises = ctx.getArtifacts(ids).map((artifact) => limit(() => ctx.output.write(artifact)));
2202
2202
  await Promise.allSettled(promises);
2203
- void ctx.hooks.callHook("generator:done");
2203
+ await ctx.hooks["codegen:done"]?.({ changed: ids });
2204
2204
  return {
2205
2205
  box: createBox({
2206
2206
  content: ctx.messages.codegenComplete(),
@@ -2214,13 +2214,13 @@ async function codegen(ctx, ids) {
2214
2214
  init_esm_shims();
2215
2215
  import { loadConfig as loadConfig2 } from "@pandacss/config";
2216
2216
  import browserslist from "browserslist";
2217
- import { createDebugger, createHooks } from "hookable";
2218
2217
 
2219
2218
  // src/create-context.ts
2220
2219
  init_esm_shims();
2221
2220
  import { Generator as Generator2 } from "@pandacss/generator";
2222
2221
  import { logger as logger5 } from "@pandacss/logger";
2223
2222
  import { Project } from "@pandacss/parser";
2223
+ import { uniq } from "@pandacss/shared";
2224
2224
  import { debounce } from "perfect-debounce";
2225
2225
 
2226
2226
  // src/diff-engine.ts
@@ -2302,8 +2302,8 @@ var nodeRuntime = {
2302
2302
  readDirSync: fsExtra.readdirSync,
2303
2303
  rmDirSync: fsExtra.emptyDirSync,
2304
2304
  rmFileSync: fsExtra.removeSync,
2305
- ensureDirSync(path) {
2306
- return fsExtra.ensureDirSync(path);
2305
+ ensureDirSync(path2) {
2306
+ return fsExtra.ensureDirSync(path2);
2307
2307
  },
2308
2308
  watch(options) {
2309
2309
  const { include, exclude, cwd, poll } = options;
@@ -2378,6 +2378,7 @@ var PandaContext = class extends Generator2 {
2378
2378
  project;
2379
2379
  output;
2380
2380
  diff;
2381
+ explicitDeps = [];
2381
2382
  constructor(conf) {
2382
2383
  super(conf);
2383
2384
  const config = conf.config;
@@ -2398,7 +2399,14 @@ var PandaContext = class extends Generator2 {
2398
2399
  });
2399
2400
  this.output = new OutputEngine(this);
2400
2401
  this.diff = new DiffEngine(this);
2402
+ this.explicitDeps = this.getExplicitDependencies();
2401
2403
  }
2404
+ getExplicitDependencies = () => {
2405
+ const { cwd, dependencies } = this.config;
2406
+ if (!dependencies)
2407
+ return [];
2408
+ return this.runtime.fs.glob({ include: dependencies, cwd });
2409
+ };
2402
2410
  getFiles = () => {
2403
2411
  const { include, exclude, cwd } = this.config;
2404
2412
  return this.runtime.fs.glob({ include, exclude, cwd });
@@ -2449,16 +2457,16 @@ var PandaContext = class extends Generator2 {
2449
2457
  const { cwd, poll, exclude } = opts ?? {};
2450
2458
  logger5.info("ctx:watch", this.messages.configWatch());
2451
2459
  const watcher = this.runtime.fs.watch({
2452
- include: this.conf.dependencies,
2460
+ include: uniq([...this.explicitDeps, ...this.conf.dependencies]),
2453
2461
  exclude,
2454
2462
  cwd,
2455
2463
  poll
2456
2464
  });
2457
2465
  watcher.on(
2458
2466
  "change",
2459
- debounce(async () => {
2467
+ debounce(async (file) => {
2460
2468
  logger5.info("ctx:change", "config changed, rebuilding...");
2461
- await cb();
2469
+ await cb(file);
2462
2470
  })
2463
2471
  );
2464
2472
  };
@@ -2527,15 +2535,7 @@ async function loadConfigAndCreateContext(options = {}) {
2527
2535
  if (tsConfResult) {
2528
2536
  Object.assign(conf, tsConfResult);
2529
2537
  }
2530
- const hooks = createHooks();
2531
- if (conf.config.hooks) {
2532
- hooks.addHooks(conf.config.hooks);
2533
- }
2534
- await hooks.callHook("config:resolved", conf);
2535
- if (conf.config.logLevel === "debug") {
2536
- createDebugger(hooks, { tag: "panda" });
2537
- }
2538
- return new PandaContext({ ...conf, hooks });
2538
+ return new PandaContext(conf);
2539
2539
  }
2540
2540
 
2541
2541
  // src/parse-dependency.ts
@@ -2591,15 +2591,9 @@ var Builder = class {
2591
2591
  context;
2592
2592
  hasEmitted = false;
2593
2593
  filesMeta;
2594
+ explicitDepsMeta;
2594
2595
  affecteds;
2595
2596
  configDependencies = /* @__PURE__ */ new Set();
2596
- getConfigPath = (cwd) => {
2597
- const configPath = findConfig({ cwd });
2598
- if (!configPath) {
2599
- throw new ConfigNotFoundError();
2600
- }
2601
- return configPath;
2602
- };
2603
2597
  setConfigDependencies(options) {
2604
2598
  const tsOptions = this.context?.conf.tsOptions ?? { baseUrl: void 0, pathMappings: [] };
2605
2599
  const compilerOptions = this.context?.conf.tsconfig?.compilerOptions ?? {};
@@ -2609,25 +2603,35 @@ var Builder = class {
2609
2603
  ...foundDeps,
2610
2604
  ...(this.context?.conf.dependencies ?? []).map((file) => resolve3(cwd, file))
2611
2605
  ]);
2612
- this.configDependencies = configDeps;
2606
+ configDeps.forEach((file) => {
2607
+ this.configDependencies.add(file);
2608
+ });
2613
2609
  logger6.debug("builder", "Config dependencies");
2614
2610
  logger6.debug("builder", configDeps);
2615
2611
  }
2616
2612
  setup = async (options = {}) => {
2617
2613
  logger6.debug("builder", "\u{1F6A7} Setup");
2618
- const configPath = options.configPath ?? this.getConfigPath(options.cwd);
2614
+ const configPath = options.configPath ?? findConfig({ cwd: options.cwd });
2619
2615
  this.setConfigDependencies({ configPath, cwd: options.cwd });
2620
2616
  if (!this.context) {
2621
2617
  return this.setupContext({ configPath, cwd: options.cwd });
2622
2618
  }
2623
2619
  const ctx = this.getContextOrThrow();
2624
2620
  this.affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2625
- this.context = new PandaContext({ ...conf, hooks: ctx.hooks });
2621
+ this.context = new PandaContext(conf);
2626
2622
  });
2627
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
+ }
2628
2632
  if (this.affecteds.hasConfigChanged) {
2629
2633
  logger6.debug("builder", "\u2699\uFE0F Config changed, reloading");
2630
- await ctx.hooks.callHook("config:change", ctx.config);
2634
+ await ctx.hooks["config:change"]?.({ config: ctx.config, changes: this.affecteds });
2631
2635
  return;
2632
2636
  }
2633
2637
  this.filesMeta = this.checkFilesChanged(ctx.getFiles());
@@ -2646,12 +2650,16 @@ var Builder = class {
2646
2650
  setupContext = async (options) => {
2647
2651
  const { configPath, cwd } = options;
2648
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
+ });
2649
2657
  this.context = ctx;
2650
2658
  return ctx;
2651
2659
  };
2652
2660
  getContextOrThrow = () => {
2653
2661
  if (!this.context) {
2654
- throw new Error("context not loaded");
2662
+ throw new PandaError("NO_CONTEXT", "context not loaded");
2655
2663
  }
2656
2664
  return this.context;
2657
2665
  };
@@ -2729,25 +2737,56 @@ var Builder = class {
2729
2737
  };
2730
2738
  };
2731
2739
 
2732
- // src/cssgen.ts
2740
+ // src/cpu-profile.ts
2733
2741
  init_esm_shims();
2734
2742
  import { logger as logger7 } from "@pandacss/logger";
2743
+ import fs from "fs";
2744
+ import path from "path";
2745
+ var startProfiling = async (cwd, prefix) => {
2746
+ const v8Profiler = (await import("v8-profiler-next")).default;
2747
+ const date = /* @__PURE__ */ new Date();
2748
+ const timestamp = date.toISOString().replace(/[-:.]/g, "");
2749
+ const title = `panda-${prefix}-${timestamp}`;
2750
+ v8Profiler.setGenerateType(1);
2751
+ v8Profiler.startProfiling(title, true);
2752
+ const stopProfiling = () => {
2753
+ const profile = v8Profiler.stopProfiling(title);
2754
+ profile.export(function(error, result) {
2755
+ if (error) {
2756
+ console.error(error);
2757
+ return;
2758
+ }
2759
+ if (!result)
2760
+ return;
2761
+ const outfile = path.join(cwd, `${title}.cpuprofile`);
2762
+ fs.writeFileSync(outfile, result);
2763
+ logger7.info("cpu-prof", outfile);
2764
+ profile.delete();
2765
+ });
2766
+ };
2767
+ return stopProfiling;
2768
+ };
2769
+
2770
+ // src/cssgen.ts
2771
+ init_esm_shims();
2772
+ import { logger as logger8 } from "@pandacss/logger";
2735
2773
  var cssgen = async (ctx, options) => {
2736
2774
  const { outfile, type, minimal } = options;
2737
2775
  const sheet = ctx.createSheet();
2738
2776
  if (type) {
2739
- const done = logger7.time.info(ctx.messages.cssArtifactComplete(type));
2777
+ const done = logger8.time.info(ctx.messages.cssArtifactComplete(type));
2740
2778
  ctx.appendCssOfType(type, sheet);
2741
2779
  if (outfile) {
2742
2780
  const css = ctx.getCss(sheet);
2743
- ctx.runtime.fs.writeFileSync(outfile, css);
2781
+ logger8.info("css", ctx.runtime.path.resolve(outfile));
2782
+ await ctx.runtime.fs.writeFile(outfile, css);
2744
2783
  } else {
2745
2784
  await ctx.writeCss(sheet);
2746
2785
  }
2747
2786
  done();
2748
2787
  } else {
2749
2788
  const { files } = ctx.parseFiles();
2750
- const done = logger7.time.info(ctx.messages.buildComplete(files.length));
2789
+ const done = logger8.time.info(ctx.messages.buildComplete(files.length));
2751
2790
  if (!minimal) {
2752
2791
  ctx.appendLayerParams(sheet);
2753
2792
  ctx.appendBaselineCss(sheet);
@@ -2755,7 +2794,8 @@ var cssgen = async (ctx, options) => {
2755
2794
  ctx.appendParserCss(sheet);
2756
2795
  if (outfile) {
2757
2796
  const css = ctx.getCss(sheet);
2758
- ctx.runtime.fs.writeFileSync(outfile, css);
2797
+ logger8.info("css", ctx.runtime.path.resolve(outfile));
2798
+ await ctx.runtime.fs.writeFile(outfile, css);
2759
2799
  } else {
2760
2800
  await ctx.writeCss(sheet);
2761
2801
  }
@@ -2765,19 +2805,19 @@ var cssgen = async (ctx, options) => {
2765
2805
 
2766
2806
  // src/debug.ts
2767
2807
  init_esm_shims();
2768
- import { colors as colors2, logger as logger8 } from "@pandacss/logger";
2808
+ import { colors as colors2, logger as logger9 } from "@pandacss/logger";
2769
2809
  import { parse as parse2 } from "path";
2770
2810
  async function debug(ctx, options) {
2771
2811
  const files = ctx.getFiles();
2772
- const measureTotal = logger8.time.debug(`Done parsing ${files.length} files`);
2812
+ const measureTotal = logger9.time.debug(`Done parsing ${files.length} files`);
2773
2813
  ctx.config.minify = false;
2774
2814
  ctx.config.optimize = true;
2775
- const { fs, path } = ctx.runtime;
2815
+ const { fs: fs2, path: path2 } = ctx.runtime;
2776
2816
  const outdir = options.outdir;
2777
2817
  if (!options.dry && outdir) {
2778
- fs.ensureDirSync(outdir);
2779
- logger8.info("cli", `Writing ${colors2.bold(`${outdir}/config.json`)}`);
2780
- await fs.writeFile(`${outdir}/config.json`, JSON.stringify(ctx.config, null, 2));
2818
+ fs2.ensureDirSync(outdir);
2819
+ logger9.info("cli", `Writing ${colors2.bold(`${outdir}/config.json`)}`);
2820
+ await fs2.writeFile(`${outdir}/config.json`, JSON.stringify(ctx.config, null, 2));
2781
2821
  }
2782
2822
  if (options.onlyConfig) {
2783
2823
  measureTotal();
@@ -2785,14 +2825,14 @@ async function debug(ctx, options) {
2785
2825
  }
2786
2826
  const filesWithCss = [];
2787
2827
  files.map((file) => {
2788
- const measure = logger8.time.debug(`Parsed ${file}`);
2828
+ const measure = logger9.time.debug(`Parsed ${file}`);
2789
2829
  const encoder = ctx.encoder.clone();
2790
2830
  const result = ctx.project.parseSourceFile(file, encoder);
2791
2831
  measure();
2792
2832
  if (!result || result.isEmpty() || encoder.isEmpty())
2793
2833
  return;
2794
2834
  const styles4 = ctx.decoder.clone().collect(encoder);
2795
- const css = ctx.getParserCss(styles4, file);
2835
+ const css = ctx.getParserCss(styles4);
2796
2836
  if (!css)
2797
2837
  return;
2798
2838
  if (options.dry) {
@@ -2802,31 +2842,30 @@ async function debug(ctx, options) {
2802
2842
  if (outdir) {
2803
2843
  filesWithCss.push(file);
2804
2844
  const parsedPath = parse2(file);
2805
- const relative2 = path.relative(ctx.config.cwd, parsedPath.dir);
2806
- const astJsonPath = `${relative2}/${parsedPath.name}.ast.json`.replaceAll(path.sep, "__");
2807
- const cssPath = `${relative2}/${parsedPath.name}.css`.replaceAll(path.sep, "__");
2808
- logger8.info("cli", `Writing ${colors2.bold(`${outdir}/${astJsonPath}`)}`);
2809
- logger8.info("cli", `Writing ${colors2.bold(`${outdir}/${cssPath}`)}`);
2845
+ const relative2 = path2.relative(ctx.config.cwd, parsedPath.dir);
2846
+ const astJsonPath = `${relative2}/${parsedPath.name}.ast.json`.replaceAll(path2.sep, "__");
2847
+ const cssPath = `${relative2}/${parsedPath.name}.css`.replaceAll(path2.sep, "__");
2848
+ logger9.info("cli", `Writing ${colors2.bold(`${outdir}/${astJsonPath}`)}`);
2849
+ logger9.info("cli", `Writing ${colors2.bold(`${outdir}/${cssPath}`)}`);
2810
2850
  return Promise.allSettled([
2811
- fs.writeFile(`${outdir}/${astJsonPath}`, JSON.stringify(result.toJSON(), null, 2)),
2812
- fs.writeFile(`${outdir}/${cssPath}`, css)
2851
+ fs2.writeFile(`${outdir}/${astJsonPath}`, JSON.stringify(result.toJSON(), null, 2)),
2852
+ fs2.writeFile(`${outdir}/${cssPath}`, css)
2813
2853
  ]);
2814
2854
  }
2815
2855
  });
2816
- logger8.info("cli", `Found ${colors2.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2856
+ logger9.info("cli", `Found ${colors2.bold(`${filesWithCss.length}/${files.length}`)} files using Panda`);
2817
2857
  measureTotal();
2818
2858
  }
2819
2859
 
2820
2860
  // src/generate.ts
2821
2861
  init_esm_shims();
2822
- import { logger as logger9 } from "@pandacss/logger";
2823
- import { match } from "ts-pattern";
2862
+ import { logger as logger10 } from "@pandacss/logger";
2824
2863
  async function build(ctx, artifactIds) {
2825
2864
  await codegen(ctx, artifactIds);
2826
2865
  if (ctx.config.emitTokensOnly) {
2827
- return logger9.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens \u2728");
2866
+ return logger10.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens \u2728");
2828
2867
  }
2829
- const done = logger9.time.info("");
2868
+ const done = logger10.time.info("");
2830
2869
  const sheet = ctx.createSheet();
2831
2870
  ctx.appendLayerParams(sheet);
2832
2871
  ctx.appendBaselineCss(sheet);
@@ -2838,25 +2877,19 @@ async function build(ctx, artifactIds) {
2838
2877
  async function generate(config, configPath) {
2839
2878
  let ctx = await loadConfigAndCreateContext({ config, configPath });
2840
2879
  await build(ctx);
2841
- const {
2842
- runtime: { fs, path },
2843
- config: { cwd }
2844
- } = ctx;
2845
- if (ctx.config.watch) {
2846
- const configWatcher = fs.watch({ include: ctx.conf.dependencies });
2847
- configWatcher.on("change", async () => {
2848
- const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
2849
- ctx = new PandaContext({ ...conf, hooks: ctx.hooks });
2850
- });
2851
- if (!affecteds.hasConfigChanged) {
2852
- logger9.debug("builder", "Config didnt change, skipping rebuild");
2853
- return;
2854
- }
2855
- logger9.info("config:change", "Config changed, restarting...");
2856
- await ctx.hooks.callHook("config:change", ctx.config);
2857
- return build(ctx, Array.from(affecteds.artifacts));
2858
- });
2859
- const contentWatcher = fs.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
+ );
2860
2893
  const bundleStyles = async (ctx2, changedFilePath) => {
2861
2894
  const outfile = ctx2.runtime.path.join(...ctx2.paths.root, "styles.css");
2862
2895
  const parserResult = ctx2.project.parseSourceFile(changedFilePath);
@@ -2870,21 +2903,18 @@ async function generate(config, configPath) {
2870
2903
  return { msg: ctx2.messages.buildComplete(1) };
2871
2904
  }
2872
2905
  };
2873
- contentWatcher.on("all", async (event, file) => {
2874
- logger9.info(`file:${event}`, file);
2875
- const filePath = path.abs(cwd, file);
2876
- match(event).with("unlink", () => {
2877
- ctx.project.removeSourceFile(path.abs(cwd, file));
2878
- }).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") {
2879
2911
  ctx.project.reloadSourceFile(file);
2880
- return bundleStyles(ctx, filePath);
2881
- }).with("add", async () => {
2912
+ await bundleStyles(ctx, filePath);
2913
+ } else if (event === "add") {
2882
2914
  ctx.project.createSourceFile(file);
2883
- return bundleStyles(ctx, filePath);
2884
- }).otherwise(() => {
2885
- });
2915
+ await bundleStyles(ctx, filePath);
2916
+ }
2886
2917
  });
2887
- logger9.info("ctx:watch", ctx.messages.watch());
2888
2918
  }
2889
2919
  }
2890
2920
 
@@ -2917,7 +2947,7 @@ function setupGitIgnore(ctx) {
2917
2947
  init_esm_shims();
2918
2948
  import { findConfig as findConfig2 } from "@pandacss/config";
2919
2949
  import { messages } from "@pandacss/core";
2920
- import { logger as logger10, quote } from "@pandacss/logger";
2950
+ import { logger as logger11, quote } from "@pandacss/logger";
2921
2951
  import fsExtra2 from "fs-extra";
2922
2952
  import { lookItUpSync as lookItUpSync2 } from "look-it-up";
2923
2953
  import { outdent as outdent2 } from "outdent";
@@ -2932,9 +2962,9 @@ async function setupConfig(cwd, opts = {}) {
2932
2962
  const cmd = pm === "npm" ? "npm run" : pm;
2933
2963
  const isTs = lookItUpSync2("tsconfig.json", cwd);
2934
2964
  const file = isTs ? "panda.config.ts" : "panda.config.mjs";
2935
- logger10.info("init:config", `creating panda config file: ${quote(file)}`);
2965
+ logger11.info("init:config", `creating panda config file: ${quote(file)}`);
2936
2966
  if (!force && configFile) {
2937
- logger10.warn("init:config", messages.configExists(cmd));
2967
+ logger11.warn("init:config", messages.configExists(cmd));
2938
2968
  } else {
2939
2969
  const content = outdent2`
2940
2970
  import { defineConfig } from "@pandacss/dev"
@@ -2967,11 +2997,11 @@ syntax: '${syntax}'` : ""}
2967
2997
  })
2968
2998
  `;
2969
2999
  await fsExtra2.writeFile(join2(cwd, file), prettier.format(content, { parser: "babel" }));
2970
- logger10.log(messages.thankYou());
3000
+ logger11.log(messages.thankYou());
2971
3001
  }
2972
3002
  }
2973
3003
  async function setupPostcss(cwd) {
2974
- logger10.info("init:postcss", `creating postcss config file: ${quote("postcss.config.cjs")}`);
3004
+ logger11.info("init:postcss", `creating postcss config file: ${quote("postcss.config.cjs")}`);
2975
3005
  const content = outdent2`
2976
3006
  module.exports = {
2977
3007
  plugins: {
@@ -2995,5 +3025,6 @@ export {
2995
3025
  setupConfig,
2996
3026
  setupGitIgnore,
2997
3027
  setupPostcss,
3028
+ startProfiling,
2998
3029
  writeAnalyzeJSON
2999
3030
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/node",
3
- "version": "0.27.3",
3
+ "version": "0.29.0",
4
4
  "description": "The core css panda library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -39,7 +39,6 @@
39
39
  "filesize": "^10.0.8",
40
40
  "fs-extra": "11.1.1",
41
41
  "glob-parent": "^6.0.2",
42
- "hookable": "5.5.3",
43
42
  "is-glob": "^4.0.3",
44
43
  "lodash.merge": "4.6.2",
45
44
  "look-it-up": "2.1.0",
@@ -53,16 +52,16 @@
53
52
  "ts-morph": "19.0.0",
54
53
  "ts-pattern": "5.0.5",
55
54
  "tsconfck": "^2.1.2",
56
- "@pandacss/config": "0.27.3",
57
- "@pandacss/core": "0.27.3",
58
- "@pandacss/error": "0.27.3",
59
- "@pandacss/extractor": "0.27.3",
60
- "@pandacss/generator": "0.27.3",
61
- "@pandacss/logger": "0.27.3",
62
- "@pandacss/parser": "0.27.3",
63
- "@pandacss/shared": "0.27.3",
64
- "@pandacss/token-dictionary": "0.27.3",
65
- "@pandacss/types": "0.27.3"
55
+ "v8-profiler-next": "^1.10.0",
56
+ "@pandacss/config": "0.29.0",
57
+ "@pandacss/core": "0.29.0",
58
+ "@pandacss/extractor": "0.29.0",
59
+ "@pandacss/generator": "0.29.0",
60
+ "@pandacss/logger": "0.29.0",
61
+ "@pandacss/parser": "0.29.0",
62
+ "@pandacss/shared": "0.29.0",
63
+ "@pandacss/token-dictionary": "0.29.0",
64
+ "@pandacss/types": "0.29.0"
66
65
  },
67
66
  "devDependencies": {
68
67
  "@types/fs-extra": "11.0.4",