@pandacss/webpack 2.0.0-beta.9 → 2.0.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.
@@ -23,12 +23,47 @@ __export(css_loader_exports, {
23
23
  default: () => pandaCssLoader
24
24
  });
25
25
  module.exports = __toCommonJS(css_loader_exports);
26
+ var import_compiler_shared = require("@pandacss/compiler-shared");
26
27
  function pandaCssLoader(source) {
27
28
  const driver = this.getOptions().getDriver();
28
29
  if (!driver || !driver.compiler.hasLayerDeclaration(source)) return source;
29
- for (const file of driver.scan()) this.addDependency(file);
30
- if (driver.configPath) this.addDependency(driver.configPath);
31
- const { css } = driver.cssgen({ emitLayerDeclaration: false });
32
- return `${source}
33
- ${css}`;
30
+ addPandaDependencies(this, driver);
31
+ warnDiagnostics(this, driver.designSystemDiagnostics, "while loading the design system");
32
+ const polyfill = driver.config.polyfill === true;
33
+ const output = driver.cssgen({ emitLayerDeclaration: false, polyfill });
34
+ warnDiagnostics(this, output.diagnostics, "while compiling the stylesheet");
35
+ const entry = polyfill ? driver.compiler.stripLayerOrderStatements(source) : source;
36
+ return `${entry}
37
+ ${output.css}`;
38
+ }
39
+ function addPandaDependencies(loader, driver) {
40
+ const seen = /* @__PURE__ */ new Set();
41
+ const watch = (file) => {
42
+ if (seen.has(file)) return;
43
+ seen.add(file);
44
+ loader.addDependency(file);
45
+ };
46
+ for (const file of driver.scan()) watch(file);
47
+ for (const dep of driver.watchTargets().config) {
48
+ watch(driver.resolvePath(dep));
49
+ }
50
+ if (driver.configPath) {
51
+ watch(driver.configPath);
52
+ }
53
+ for (const target of driver.designSystemWatchTargets?.() ?? []) {
54
+ watch(target.manifestPath);
55
+ watch(target.buildInfoPath);
56
+ watch(target.presetPath);
57
+ for (const file of target.sourceFiles) {
58
+ watch(file);
59
+ }
60
+ }
61
+ }
62
+ function warnDiagnostics(loader, diagnostics, context) {
63
+ if (!diagnostics?.length) return;
64
+ const shown = diagnostics.slice(0, 3).map((diagnostic) => (0, import_compiler_shared.formatDiagnostic)((0, import_compiler_shared.withDiagnosticFile)(diagnostic))).join("\n");
65
+ const hidden = diagnostics.length > 3 ? `
66
+ ...and ${diagnostics.length - 3} more` : "";
67
+ loader.emitWarning(new Error(`panda: ${diagnostics.length} diagnostic(s) ${context}
68
+ ${shown}${hidden}`));
34
69
  }
@@ -9,8 +9,8 @@ interface PandaCssLoaderOptions {
9
9
  * `pre` loader for `.css` files. When a stylesheet declares Panda layers
10
10
  * (`@layer reset, base, …;`), append the generated CSS in-memory — the webpack
11
11
  * analog of the Vite plugin's `.css` transform. No file is written to disk.
12
- * Registers every source file (and the config) as a dependency so webpack
13
- * rebuilds this stylesheet when they change.
12
+ * Registers project sources, config deps, and design-system watch targets so
13
+ * webpack rebuilds this stylesheet when they change.
14
14
  */
15
15
  declare function pandaCssLoader(this: LoaderContext<PandaCssLoaderOptions>, source: string): string;
16
16
 
@@ -9,8 +9,8 @@ interface PandaCssLoaderOptions {
9
9
  * `pre` loader for `.css` files. When a stylesheet declares Panda layers
10
10
  * (`@layer reset, base, …;`), append the generated CSS in-memory — the webpack
11
11
  * analog of the Vite plugin's `.css` transform. No file is written to disk.
12
- * Registers every source file (and the config) as a dependency so webpack
13
- * rebuilds this stylesheet when they change.
12
+ * Registers project sources, config deps, and design-system watch targets so
13
+ * webpack rebuilds this stylesheet when they change.
14
14
  */
15
15
  declare function pandaCssLoader(this: LoaderContext<PandaCssLoaderOptions>, source: string): string;
16
16
 
@@ -1,12 +1,47 @@
1
1
  // src/css-loader.ts
2
+ import { formatDiagnostic, withDiagnosticFile } from "@pandacss/compiler-shared";
2
3
  function pandaCssLoader(source) {
3
4
  const driver = this.getOptions().getDriver();
4
5
  if (!driver || !driver.compiler.hasLayerDeclaration(source)) return source;
5
- for (const file of driver.scan()) this.addDependency(file);
6
- if (driver.configPath) this.addDependency(driver.configPath);
7
- const { css } = driver.cssgen({ emitLayerDeclaration: false });
8
- return `${source}
9
- ${css}`;
6
+ addPandaDependencies(this, driver);
7
+ warnDiagnostics(this, driver.designSystemDiagnostics, "while loading the design system");
8
+ const polyfill = driver.config.polyfill === true;
9
+ const output = driver.cssgen({ emitLayerDeclaration: false, polyfill });
10
+ warnDiagnostics(this, output.diagnostics, "while compiling the stylesheet");
11
+ const entry = polyfill ? driver.compiler.stripLayerOrderStatements(source) : source;
12
+ return `${entry}
13
+ ${output.css}`;
14
+ }
15
+ function addPandaDependencies(loader, driver) {
16
+ const seen = /* @__PURE__ */ new Set();
17
+ const watch = (file) => {
18
+ if (seen.has(file)) return;
19
+ seen.add(file);
20
+ loader.addDependency(file);
21
+ };
22
+ for (const file of driver.scan()) watch(file);
23
+ for (const dep of driver.watchTargets().config) {
24
+ watch(driver.resolvePath(dep));
25
+ }
26
+ if (driver.configPath) {
27
+ watch(driver.configPath);
28
+ }
29
+ for (const target of driver.designSystemWatchTargets?.() ?? []) {
30
+ watch(target.manifestPath);
31
+ watch(target.buildInfoPath);
32
+ watch(target.presetPath);
33
+ for (const file of target.sourceFiles) {
34
+ watch(file);
35
+ }
36
+ }
37
+ }
38
+ function warnDiagnostics(loader, diagnostics, context) {
39
+ if (!diagnostics?.length) return;
40
+ const shown = diagnostics.slice(0, 3).map((diagnostic) => formatDiagnostic(withDiagnosticFile(diagnostic))).join("\n");
41
+ const hidden = diagnostics.length > 3 ? `
42
+ ...and ${diagnostics.length - 3} more` : "";
43
+ loader.emitWarning(new Error(`panda: ${diagnostics.length} diagnostic(s) ${context}
44
+ ${shown}${hidden}`));
10
45
  }
11
46
  export {
12
47
  pandaCssLoader as default
package/dist/index.cjs CHANGED
@@ -25,12 +25,14 @@ __export(index_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(index_exports);
27
27
  var import_compiler = require("@pandacss/compiler");
28
+ var import_compiler_shared = require("@pandacss/compiler-shared");
28
29
  var import_transformer = require("@pandacss/transformer");
29
30
  var NAME = "PandaWebpackPlugin";
30
31
  var PandaWebpackPlugin = class {
31
32
  #options;
32
33
  #driver;
33
34
  #ready;
35
+ #designSystemDiagnosticsRef;
34
36
  constructor(options = {}) {
35
37
  this.#options = options;
36
38
  }
@@ -48,11 +50,21 @@ var PandaWebpackPlugin = class {
48
50
  /** Watch-mode incremental sync: fold changed files into the driver before this
49
51
  * rebuild's modules (including the layer-declaring CSS) are read. The driver
50
52
  * re-reads changed files through its own fs. */
51
- async #sync(cwd, changed) {
53
+ async #sync(cwd, changed, removed, warn) {
52
54
  await this.#build(cwd);
53
55
  const driver = this.#driver;
54
56
  let configChanged = false;
57
+ let designSystemChanged = false;
58
+ for (const file of removed) {
59
+ if (driver.isSourceFile(file)) driver.applyChange({ path: file, kind: "unlink" });
60
+ }
55
61
  for (const file of changed) {
62
+ const designSystemFile = driver.isDesignSystemFile?.(file) ?? false;
63
+ if (designSystemFile) {
64
+ const synced = await driver.syncDesignSystemFileChange({ path: file, kind: "change" });
65
+ if (synced) designSystemChanged = true;
66
+ continue;
67
+ }
56
68
  if (driver.isConfigFile(file)) {
57
69
  configChanged = true;
58
70
  } else if (driver.isSourceFile(file)) {
@@ -64,17 +76,34 @@ var PandaWebpackPlugin = class {
64
76
  if (diff.hasChanged) {
65
77
  driver.codegen({ cwd, outdir: this.#options.outdir });
66
78
  driver.parseFiles();
79
+ designSystemChanged = true;
67
80
  }
68
81
  }
82
+ if (designSystemChanged) {
83
+ this.#warnDesignSystemDiagnostics(warn);
84
+ }
85
+ }
86
+ #warnDesignSystemDiagnostics(warn) {
87
+ if (!warn) return;
88
+ const diagnostics = this.#driver?.designSystemDiagnostics ?? [];
89
+ if (diagnostics === this.#designSystemDiagnosticsRef) return;
90
+ this.#designSystemDiagnosticsRef = diagnostics;
91
+ if (!diagnostics.length) return;
92
+ const shown = diagnostics.slice(0, 3).map((diagnostic) => (0, import_compiler_shared.formatDiagnostic)((0, import_compiler_shared.withDiagnosticFile)(diagnostic))).join("\n");
93
+ const hidden = diagnostics.length > 3 ? `
94
+ ...and ${diagnostics.length - 3} more` : "";
95
+ warn(`panda: ${diagnostics.length} diagnostic(s) while loading the design system
96
+ ${shown}${hidden}`);
69
97
  }
70
98
  apply(compiler) {
71
99
  const cwd = this.#options.cwd ?? compiler.context ?? process.cwd();
72
- const { cwd: _cwd, configPath: _configPath, outdir: _outdir, ...transformerOptions } = this.#options;
73
- import_transformer.pandaTransformer.webpack({
74
- exclude: [/node_modules/],
75
- ...transformerOptions,
76
- getCompiler: () => this.#driver?.compiler
77
- }).apply(compiler);
100
+ const logger = compiler.getInfrastructureLogger?.(NAME);
101
+ if (this.#options.transform) {
102
+ import_transformer.pandaTransformer.webpack({
103
+ exclude: [/node_modules/],
104
+ getCompiler: () => this.#driver?.compiler
105
+ }).apply(compiler);
106
+ }
78
107
  const options = { getDriver: () => this.#driver };
79
108
  compiler.options.module.rules.push({
80
109
  test: /\.css$/,
@@ -83,7 +112,10 @@ var PandaWebpackPlugin = class {
83
112
  use: [{ loader: "@pandacss/webpack/css-loader", options }]
84
113
  });
85
114
  compiler.hooks.beforeCompile.tapPromise(NAME, () => this.#build(cwd));
86
- compiler.hooks.watchRun.tapPromise(NAME, (c) => this.#sync(cwd, c.modifiedFiles ?? []));
115
+ compiler.hooks.watchRun.tapPromise(
116
+ NAME,
117
+ (c) => this.#sync(cwd, c.modifiedFiles ?? [], c.removedFiles ?? [], (message) => logger?.warn(message))
118
+ );
87
119
  }
88
120
  };
89
121
  var index_default = PandaWebpackPlugin;
package/dist/index.d.cts CHANGED
@@ -1,19 +1,23 @@
1
- import { PandaTransformerOptions } from '@pandacss/transformer';
2
1
  import { Compiler } from 'webpack';
3
2
 
4
- interface PandaWebpackPluginOptions extends PandaTransformerOptions {
3
+ interface PandaWebpackPluginOptions {
5
4
  /** Project root. Defaults to the webpack compiler `context`. */
6
5
  cwd?: string;
7
6
  /** Explicit config file (relative to `cwd`); otherwise discovered upward. */
8
7
  configPath?: string;
9
8
  /** Where codegen artifacts are written. Defaults to the config `outdir`. */
10
9
  outdir?: string;
10
+ /**
11
+ * Opt-in source rewrite (`css()` → class strings, etc.). Default: `false`.
12
+ * CSS injection, codegen, and watch sync always run.
13
+ */
14
+ transform?: boolean;
11
15
  }
12
16
  /**
13
- * webpack plugin for Panda CSS. Runs codegen and rewrites source via the native
14
- * transform loader (shared `@pandacss/transformer` unplugin, which also resolves
15
- * the `@pandacss-internal/css` runtime module). Generated CSS is injected
16
- * in-memory into any stylesheet that declares Panda layers — no file is written.
17
+ * webpack plugin for Panda CSS. Runs codegen and injects generated CSS
18
+ * in-memory into any stylesheet that declares Panda layers — no file is
19
+ * written. Pass `transform: true` to also rewrite source via the shared
20
+ * `@pandacss/transformer` unplugin (and resolve `@pandacss-internal/css`).
17
21
  */
18
22
  declare class PandaWebpackPlugin {
19
23
  #private;
package/dist/index.d.ts CHANGED
@@ -1,19 +1,23 @@
1
- import { PandaTransformerOptions } from '@pandacss/transformer';
2
1
  import { Compiler } from 'webpack';
3
2
 
4
- interface PandaWebpackPluginOptions extends PandaTransformerOptions {
3
+ interface PandaWebpackPluginOptions {
5
4
  /** Project root. Defaults to the webpack compiler `context`. */
6
5
  cwd?: string;
7
6
  /** Explicit config file (relative to `cwd`); otherwise discovered upward. */
8
7
  configPath?: string;
9
8
  /** Where codegen artifacts are written. Defaults to the config `outdir`. */
10
9
  outdir?: string;
10
+ /**
11
+ * Opt-in source rewrite (`css()` → class strings, etc.). Default: `false`.
12
+ * CSS injection, codegen, and watch sync always run.
13
+ */
14
+ transform?: boolean;
11
15
  }
12
16
  /**
13
- * webpack plugin for Panda CSS. Runs codegen and rewrites source via the native
14
- * transform loader (shared `@pandacss/transformer` unplugin, which also resolves
15
- * the `@pandacss-internal/css` runtime module). Generated CSS is injected
16
- * in-memory into any stylesheet that declares Panda layers — no file is written.
17
+ * webpack plugin for Panda CSS. Runs codegen and injects generated CSS
18
+ * in-memory into any stylesheet that declares Panda layers — no file is
19
+ * written. Pass `transform: true` to also rewrite source via the shared
20
+ * `@pandacss/transformer` unplugin (and resolve `@pandacss-internal/css`).
17
21
  */
18
22
  declare class PandaWebpackPlugin {
19
23
  #private;
package/dist/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  // src/index.ts
2
2
  import { createNodeDriver } from "@pandacss/compiler";
3
+ import { formatDiagnostic, withDiagnosticFile } from "@pandacss/compiler-shared";
3
4
  import { pandaTransformer } from "@pandacss/transformer";
4
5
  var NAME = "PandaWebpackPlugin";
5
6
  var PandaWebpackPlugin = class {
6
7
  #options;
7
8
  #driver;
8
9
  #ready;
10
+ #designSystemDiagnosticsRef;
9
11
  constructor(options = {}) {
10
12
  this.#options = options;
11
13
  }
@@ -23,11 +25,21 @@ var PandaWebpackPlugin = class {
23
25
  /** Watch-mode incremental sync: fold changed files into the driver before this
24
26
  * rebuild's modules (including the layer-declaring CSS) are read. The driver
25
27
  * re-reads changed files through its own fs. */
26
- async #sync(cwd, changed) {
28
+ async #sync(cwd, changed, removed, warn) {
27
29
  await this.#build(cwd);
28
30
  const driver = this.#driver;
29
31
  let configChanged = false;
32
+ let designSystemChanged = false;
33
+ for (const file of removed) {
34
+ if (driver.isSourceFile(file)) driver.applyChange({ path: file, kind: "unlink" });
35
+ }
30
36
  for (const file of changed) {
37
+ const designSystemFile = driver.isDesignSystemFile?.(file) ?? false;
38
+ if (designSystemFile) {
39
+ const synced = await driver.syncDesignSystemFileChange({ path: file, kind: "change" });
40
+ if (synced) designSystemChanged = true;
41
+ continue;
42
+ }
31
43
  if (driver.isConfigFile(file)) {
32
44
  configChanged = true;
33
45
  } else if (driver.isSourceFile(file)) {
@@ -39,17 +51,34 @@ var PandaWebpackPlugin = class {
39
51
  if (diff.hasChanged) {
40
52
  driver.codegen({ cwd, outdir: this.#options.outdir });
41
53
  driver.parseFiles();
54
+ designSystemChanged = true;
42
55
  }
43
56
  }
57
+ if (designSystemChanged) {
58
+ this.#warnDesignSystemDiagnostics(warn);
59
+ }
60
+ }
61
+ #warnDesignSystemDiagnostics(warn) {
62
+ if (!warn) return;
63
+ const diagnostics = this.#driver?.designSystemDiagnostics ?? [];
64
+ if (diagnostics === this.#designSystemDiagnosticsRef) return;
65
+ this.#designSystemDiagnosticsRef = diagnostics;
66
+ if (!diagnostics.length) return;
67
+ const shown = diagnostics.slice(0, 3).map((diagnostic) => formatDiagnostic(withDiagnosticFile(diagnostic))).join("\n");
68
+ const hidden = diagnostics.length > 3 ? `
69
+ ...and ${diagnostics.length - 3} more` : "";
70
+ warn(`panda: ${diagnostics.length} diagnostic(s) while loading the design system
71
+ ${shown}${hidden}`);
44
72
  }
45
73
  apply(compiler) {
46
74
  const cwd = this.#options.cwd ?? compiler.context ?? process.cwd();
47
- const { cwd: _cwd, configPath: _configPath, outdir: _outdir, ...transformerOptions } = this.#options;
48
- pandaTransformer.webpack({
49
- exclude: [/node_modules/],
50
- ...transformerOptions,
51
- getCompiler: () => this.#driver?.compiler
52
- }).apply(compiler);
75
+ const logger = compiler.getInfrastructureLogger?.(NAME);
76
+ if (this.#options.transform) {
77
+ pandaTransformer.webpack({
78
+ exclude: [/node_modules/],
79
+ getCompiler: () => this.#driver?.compiler
80
+ }).apply(compiler);
81
+ }
53
82
  const options = { getDriver: () => this.#driver };
54
83
  compiler.options.module.rules.push({
55
84
  test: /\.css$/,
@@ -58,7 +87,10 @@ var PandaWebpackPlugin = class {
58
87
  use: [{ loader: "@pandacss/webpack/css-loader", options }]
59
88
  });
60
89
  compiler.hooks.beforeCompile.tapPromise(NAME, () => this.#build(cwd));
61
- compiler.hooks.watchRun.tapPromise(NAME, (c) => this.#sync(cwd, c.modifiedFiles ?? []));
90
+ compiler.hooks.watchRun.tapPromise(
91
+ NAME,
92
+ (c) => this.#sync(cwd, c.modifiedFiles ?? [], c.removedFiles ?? [], (message) => logger?.warn(message))
93
+ );
62
94
  }
63
95
  };
64
96
  var index_default = PandaWebpackPlugin;
package/dist/next.cjs CHANGED
@@ -27,12 +27,14 @@ module.exports = __toCommonJS(next_exports);
27
27
 
28
28
  // src/index.ts
29
29
  var import_compiler = require("@pandacss/compiler");
30
+ var import_compiler_shared = require("@pandacss/compiler-shared");
30
31
  var import_transformer = require("@pandacss/transformer");
31
32
  var NAME = "PandaWebpackPlugin";
32
33
  var PandaWebpackPlugin = class {
33
34
  #options;
34
35
  #driver;
35
36
  #ready;
37
+ #designSystemDiagnosticsRef;
36
38
  constructor(options = {}) {
37
39
  this.#options = options;
38
40
  }
@@ -50,11 +52,21 @@ var PandaWebpackPlugin = class {
50
52
  /** Watch-mode incremental sync: fold changed files into the driver before this
51
53
  * rebuild's modules (including the layer-declaring CSS) are read. The driver
52
54
  * re-reads changed files through its own fs. */
53
- async #sync(cwd, changed) {
55
+ async #sync(cwd, changed, removed, warn) {
54
56
  await this.#build(cwd);
55
57
  const driver = this.#driver;
56
58
  let configChanged = false;
59
+ let designSystemChanged = false;
60
+ for (const file of removed) {
61
+ if (driver.isSourceFile(file)) driver.applyChange({ path: file, kind: "unlink" });
62
+ }
57
63
  for (const file of changed) {
64
+ const designSystemFile = driver.isDesignSystemFile?.(file) ?? false;
65
+ if (designSystemFile) {
66
+ const synced = await driver.syncDesignSystemFileChange({ path: file, kind: "change" });
67
+ if (synced) designSystemChanged = true;
68
+ continue;
69
+ }
58
70
  if (driver.isConfigFile(file)) {
59
71
  configChanged = true;
60
72
  } else if (driver.isSourceFile(file)) {
@@ -66,17 +78,34 @@ var PandaWebpackPlugin = class {
66
78
  if (diff.hasChanged) {
67
79
  driver.codegen({ cwd, outdir: this.#options.outdir });
68
80
  driver.parseFiles();
81
+ designSystemChanged = true;
69
82
  }
70
83
  }
84
+ if (designSystemChanged) {
85
+ this.#warnDesignSystemDiagnostics(warn);
86
+ }
87
+ }
88
+ #warnDesignSystemDiagnostics(warn) {
89
+ if (!warn) return;
90
+ const diagnostics = this.#driver?.designSystemDiagnostics ?? [];
91
+ if (diagnostics === this.#designSystemDiagnosticsRef) return;
92
+ this.#designSystemDiagnosticsRef = diagnostics;
93
+ if (!diagnostics.length) return;
94
+ const shown = diagnostics.slice(0, 3).map((diagnostic) => (0, import_compiler_shared.formatDiagnostic)((0, import_compiler_shared.withDiagnosticFile)(diagnostic))).join("\n");
95
+ const hidden = diagnostics.length > 3 ? `
96
+ ...and ${diagnostics.length - 3} more` : "";
97
+ warn(`panda: ${diagnostics.length} diagnostic(s) while loading the design system
98
+ ${shown}${hidden}`);
71
99
  }
72
100
  apply(compiler) {
73
101
  const cwd = this.#options.cwd ?? compiler.context ?? process.cwd();
74
- const { cwd: _cwd, configPath: _configPath, outdir: _outdir, ...transformerOptions } = this.#options;
75
- import_transformer.pandaTransformer.webpack({
76
- exclude: [/node_modules/],
77
- ...transformerOptions,
78
- getCompiler: () => this.#driver?.compiler
79
- }).apply(compiler);
102
+ const logger = compiler.getInfrastructureLogger?.(NAME);
103
+ if (this.#options.transform) {
104
+ import_transformer.pandaTransformer.webpack({
105
+ exclude: [/node_modules/],
106
+ getCompiler: () => this.#driver?.compiler
107
+ }).apply(compiler);
108
+ }
80
109
  const options = { getDriver: () => this.#driver };
81
110
  compiler.options.module.rules.push({
82
111
  test: /\.css$/,
@@ -85,7 +114,10 @@ var PandaWebpackPlugin = class {
85
114
  use: [{ loader: "@pandacss/webpack/css-loader", options }]
86
115
  });
87
116
  compiler.hooks.beforeCompile.tapPromise(NAME, () => this.#build(cwd));
88
- compiler.hooks.watchRun.tapPromise(NAME, (c) => this.#sync(cwd, c.modifiedFiles ?? []));
117
+ compiler.hooks.watchRun.tapPromise(
118
+ NAME,
119
+ (c) => this.#sync(cwd, c.modifiedFiles ?? [], c.removedFiles ?? [], (message) => logger?.warn(message))
120
+ );
89
121
  }
90
122
  };
91
123
 
package/dist/next.d.cts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { PandaWebpackPluginOptions } from './index.cjs';
2
- import '@pandacss/transformer';
3
2
  import 'webpack';
4
3
 
5
4
  type WebpackConfig = {
@@ -10,9 +9,13 @@ type NextConfig = {
10
9
  [key: string]: unknown;
11
10
  };
12
11
  /**
13
- * Wrap a Next.js config to run Panda's webpack transform. Composes with any
12
+ * Wrap a Next.js config to run Panda's webpack plugin. Composes with any
14
13
  * existing `webpack` function. Only affects the webpack build — Turbopack needs
15
- * its own integration.
14
+ * its own integration. Pass `transform: true` in `pandaOptions` to enable
15
+ * source rewrite.
16
+ *
17
+ * Next.js 16 defaults to Turbopack and fails the build when a webpack config is
18
+ * present, so run `next dev --webpack` and `next build --webpack`.
16
19
  */
17
20
  declare function withPandaCss(nextConfig?: NextConfig, pandaOptions?: PandaWebpackPluginOptions): NextConfig;
18
21
 
package/dist/next.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { PandaWebpackPluginOptions } from './index.js';
2
- import '@pandacss/transformer';
3
2
  import 'webpack';
4
3
 
5
4
  type WebpackConfig = {
@@ -10,9 +9,13 @@ type NextConfig = {
10
9
  [key: string]: unknown;
11
10
  };
12
11
  /**
13
- * Wrap a Next.js config to run Panda's webpack transform. Composes with any
12
+ * Wrap a Next.js config to run Panda's webpack plugin. Composes with any
14
13
  * existing `webpack` function. Only affects the webpack build — Turbopack needs
15
- * its own integration.
14
+ * its own integration. Pass `transform: true` in `pandaOptions` to enable
15
+ * source rewrite.
16
+ *
17
+ * Next.js 16 defaults to Turbopack and fails the build when a webpack config is
18
+ * present, so run `next dev --webpack` and `next build --webpack`.
16
19
  */
17
20
  declare function withPandaCss(nextConfig?: NextConfig, pandaOptions?: PandaWebpackPluginOptions): NextConfig;
18
21
 
package/dist/next.js CHANGED
@@ -1,11 +1,13 @@
1
1
  // src/index.ts
2
2
  import { createNodeDriver } from "@pandacss/compiler";
3
+ import { formatDiagnostic, withDiagnosticFile } from "@pandacss/compiler-shared";
3
4
  import { pandaTransformer } from "@pandacss/transformer";
4
5
  var NAME = "PandaWebpackPlugin";
5
6
  var PandaWebpackPlugin = class {
6
7
  #options;
7
8
  #driver;
8
9
  #ready;
10
+ #designSystemDiagnosticsRef;
9
11
  constructor(options = {}) {
10
12
  this.#options = options;
11
13
  }
@@ -23,11 +25,21 @@ var PandaWebpackPlugin = class {
23
25
  /** Watch-mode incremental sync: fold changed files into the driver before this
24
26
  * rebuild's modules (including the layer-declaring CSS) are read. The driver
25
27
  * re-reads changed files through its own fs. */
26
- async #sync(cwd, changed) {
28
+ async #sync(cwd, changed, removed, warn) {
27
29
  await this.#build(cwd);
28
30
  const driver = this.#driver;
29
31
  let configChanged = false;
32
+ let designSystemChanged = false;
33
+ for (const file of removed) {
34
+ if (driver.isSourceFile(file)) driver.applyChange({ path: file, kind: "unlink" });
35
+ }
30
36
  for (const file of changed) {
37
+ const designSystemFile = driver.isDesignSystemFile?.(file) ?? false;
38
+ if (designSystemFile) {
39
+ const synced = await driver.syncDesignSystemFileChange({ path: file, kind: "change" });
40
+ if (synced) designSystemChanged = true;
41
+ continue;
42
+ }
31
43
  if (driver.isConfigFile(file)) {
32
44
  configChanged = true;
33
45
  } else if (driver.isSourceFile(file)) {
@@ -39,17 +51,34 @@ var PandaWebpackPlugin = class {
39
51
  if (diff.hasChanged) {
40
52
  driver.codegen({ cwd, outdir: this.#options.outdir });
41
53
  driver.parseFiles();
54
+ designSystemChanged = true;
42
55
  }
43
56
  }
57
+ if (designSystemChanged) {
58
+ this.#warnDesignSystemDiagnostics(warn);
59
+ }
60
+ }
61
+ #warnDesignSystemDiagnostics(warn) {
62
+ if (!warn) return;
63
+ const diagnostics = this.#driver?.designSystemDiagnostics ?? [];
64
+ if (diagnostics === this.#designSystemDiagnosticsRef) return;
65
+ this.#designSystemDiagnosticsRef = diagnostics;
66
+ if (!diagnostics.length) return;
67
+ const shown = diagnostics.slice(0, 3).map((diagnostic) => formatDiagnostic(withDiagnosticFile(diagnostic))).join("\n");
68
+ const hidden = diagnostics.length > 3 ? `
69
+ ...and ${diagnostics.length - 3} more` : "";
70
+ warn(`panda: ${diagnostics.length} diagnostic(s) while loading the design system
71
+ ${shown}${hidden}`);
44
72
  }
45
73
  apply(compiler) {
46
74
  const cwd = this.#options.cwd ?? compiler.context ?? process.cwd();
47
- const { cwd: _cwd, configPath: _configPath, outdir: _outdir, ...transformerOptions } = this.#options;
48
- pandaTransformer.webpack({
49
- exclude: [/node_modules/],
50
- ...transformerOptions,
51
- getCompiler: () => this.#driver?.compiler
52
- }).apply(compiler);
75
+ const logger = compiler.getInfrastructureLogger?.(NAME);
76
+ if (this.#options.transform) {
77
+ pandaTransformer.webpack({
78
+ exclude: [/node_modules/],
79
+ getCompiler: () => this.#driver?.compiler
80
+ }).apply(compiler);
81
+ }
53
82
  const options = { getDriver: () => this.#driver };
54
83
  compiler.options.module.rules.push({
55
84
  test: /\.css$/,
@@ -58,7 +87,10 @@ var PandaWebpackPlugin = class {
58
87
  use: [{ loader: "@pandacss/webpack/css-loader", options }]
59
88
  });
60
89
  compiler.hooks.beforeCompile.tapPromise(NAME, () => this.#build(cwd));
61
- compiler.hooks.watchRun.tapPromise(NAME, (c) => this.#sync(cwd, c.modifiedFiles ?? []));
90
+ compiler.hooks.watchRun.tapPromise(
91
+ NAME,
92
+ (c) => this.#sync(cwd, c.modifiedFiles ?? [], c.removedFiles ?? [], (message) => logger?.warn(message))
93
+ );
62
94
  }
63
95
  };
64
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/webpack",
3
- "version": "2.0.0-beta.9",
3
+ "version": "2.0.0",
4
4
  "description": "webpack plugin for Panda CSS (Next.js compatible)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -39,9 +39,9 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
- "@pandacss/compiler": "2.0.0-beta.9",
43
- "@pandacss/compiler-shared": "2.0.0-beta.9",
44
- "@pandacss/transformer": "2.0.0-beta.9"
42
+ "@pandacss/compiler": "2.0.0",
43
+ "@pandacss/compiler-shared": "2.0.0",
44
+ "@pandacss/transformer": "2.0.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "webpack": ">=5.0.0"