@pandacss/postcss 2.0.0-beta.2 → 2.0.0-beta.20

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.
Files changed (3) hide show
  1. package/dist/index.cjs +133 -22
  2. package/dist/index.js +126 -15
  3. package/package.json +4 -4
package/dist/index.cjs CHANGED
@@ -1,34 +1,60 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
2
2
  var _compiler = require('@pandacss/compiler');
3
- var _path = require('path');
3
+ var _compilershared = require('@pandacss/compiler-shared');
4
+ var _nodepath = require('node:path');
5
+
6
+ // src/fs-stamp.ts
7
+ var _nodefs = require('node:fs');
8
+ function readFileStamp(path) {
9
+ try {
10
+ const stat = _nodefs.statSync.call(void 0, path);
11
+ return `${stat.mtimeMs}:${stat.size}`;
12
+ } catch (e) {
13
+ return "missing";
14
+ }
15
+ }
16
+
17
+ // src/index.ts
4
18
  var PLUGIN_NAME = "pandacss";
5
19
  var driverStates = /* @__PURE__ */ new Map();
6
20
  var driverGuard;
7
21
  var pandacss = (options = {}) => {
8
- const postcssProcess = async (root, result) => {
22
+ const postcssProcess = async (root, helpers) => {
23
+ const result = helpers.result;
9
24
  const fileName = result.opts.from;
10
25
  if (shouldSkip(fileName, options.allow)) return;
11
26
  const inputCss = getInputCss(root, result);
12
27
  if (!inputCss.includes("@layer")) return;
13
- const cwd = _path.resolve.call(void 0, _nullishCoalesce(options.cwd, () => ( process.cwd())));
28
+ const cwd = _nodepath.resolve.call(void 0, _nullishCoalesce(options.cwd, () => ( process.cwd())));
14
29
  const key = getDriverKey(cwd, options.configPath);
15
30
  let state = driverStates.get(key);
16
31
  if (!state) {
17
32
  const driver2 = await _compiler.createNodeDriver.call(void 0, { cwd, configPath: options.configPath });
18
- state = { driver: driver2, generatedOutdirs: /* @__PURE__ */ new Set() };
33
+ state = {
34
+ driver: driver2,
35
+ generatedOutdirs: /* @__PURE__ */ new Set(),
36
+ parsedSources: /* @__PURE__ */ new Map(),
37
+ configStamp: stampPaths(configStampPaths(driver2)),
38
+ dsSourceStamp: stampPaths(dsSourceStampPaths(driver2))
39
+ };
19
40
  driverStates.set(key, state);
41
+ driver2.syncDesignSystemSources();
20
42
  } else {
21
- const diff = await state.driver.reload();
22
- if (diff.hasChanged) {
23
- state.generatedOutdirs.clear();
24
- }
43
+ await syncDriverState(state);
25
44
  }
26
45
  const { driver } = state;
46
+ const polyfill = driver.config.polyfill === true;
27
47
  if (!driver.compiler.hasLayerDeclaration(inputCss)) return;
28
48
  ensureCodegen(state, { cwd, outdir: options.outdir });
29
- driver.parseFiles();
49
+ syncProjectSources(state);
30
50
  registerDependencies(driver, result, cwd, fileName);
31
- const output = driver.cssgen({ emitLayerDeclaration: false });
51
+ emitDiagnostics(root, result, _nullishCoalesce(driver.designSystemDiagnostics, () => ( [])));
52
+ if (polyfill) {
53
+ const stripped = driver.compiler.stripLayerOrderStatements(inputCss);
54
+ root.removeAll();
55
+ root.append(helpers.postcss.parse(stripped, { from: fileName }));
56
+ }
57
+ const output = driver.cssgen({ emitLayerDeclaration: false, polyfill });
32
58
  emitDiagnostics(root, result, output.diagnostics);
33
59
  root.append(output.css);
34
60
  root.walk((node) => {
@@ -41,7 +67,7 @@ var pandacss = (options = {}) => {
41
67
  postcssPlugin: PLUGIN_NAME,
42
68
  Once(root, helpers) {
43
69
  driverGuard = Promise.resolve(driverGuard).catch(() => {
44
- }).then(() => postcssProcess(root, helpers.result));
70
+ }).then(() => postcssProcess(root, helpers));
45
71
  return driverGuard;
46
72
  }
47
73
  };
@@ -51,7 +77,7 @@ var index_default = pandacss;
51
77
  var nodeModulesRegex = /node_modules/;
52
78
  function isValidCss(file) {
53
79
  const [filePath] = file.split("?");
54
- return _path.extname.call(void 0, filePath) === ".css";
80
+ return _nodepath.extname.call(void 0, filePath) === ".css";
55
81
  }
56
82
  var shouldSkip = (fileName, allow) => {
57
83
  if (!fileName) return true;
@@ -72,21 +98,94 @@ function ensureCodegen(state, options) {
72
98
  state.driver.codegen({ cwd: options.cwd, outdir: options.outdir });
73
99
  state.generatedOutdirs.add(outdirKey);
74
100
  }
101
+ async function syncDriverState(state) {
102
+ const nextConfigStamp = stampPaths(configStampPaths(state.driver));
103
+ if (state.configStamp !== nextConfigStamp) {
104
+ const diff = await state.driver.reload();
105
+ state.configStamp = stampPaths(configStampPaths(state.driver));
106
+ if (diff.hasChanged) {
107
+ state.generatedOutdirs.clear();
108
+ state.parsedSources.clear();
109
+ }
110
+ state.driver.syncDesignSystemSources();
111
+ state.dsSourceStamp = stampPaths(dsSourceStampPaths(state.driver));
112
+ return;
113
+ }
114
+ const nextDsSourceStamp = stampPaths(dsSourceStampPaths(state.driver));
115
+ if (state.dsSourceStamp !== nextDsSourceStamp) {
116
+ state.driver.syncDesignSystemSources();
117
+ state.dsSourceStamp = nextDsSourceStamp;
118
+ }
119
+ }
120
+ function syncProjectSources(state) {
121
+ const files = state.driver.scan();
122
+ const scanned = new Set(files);
123
+ const changes = [];
124
+ for (const path of state.parsedSources.keys()) {
125
+ if (!scanned.has(path)) {
126
+ changes.push({ path, kind: "unlink" });
127
+ state.parsedSources.delete(path);
128
+ }
129
+ }
130
+ for (const path of files) {
131
+ const stamp = readFileStamp(path);
132
+ const known = state.parsedSources.get(path);
133
+ if (known === void 0) {
134
+ changes.push({ path, kind: "add" });
135
+ state.parsedSources.set(path, stamp);
136
+ continue;
137
+ }
138
+ if (known !== stamp) {
139
+ changes.push({ path, kind: "change" });
140
+ state.parsedSources.set(path, stamp);
141
+ }
142
+ }
143
+ if (changes.length > 0) {
144
+ state.driver.applyChanges(changes);
145
+ }
146
+ }
147
+ function configStampPaths(driver) {
148
+ const paths = [];
149
+ if (driver.configPath) paths.push(driver.configPath);
150
+ for (const dep of driver.configDependencies) {
151
+ paths.push(driver.resolvePath(dep));
152
+ }
153
+ for (const target of _nullishCoalesce(_optionalChain([driver, 'access', _3 => _3.designSystemWatchTargets, 'optionalCall', _4 => _4()]), () => ( []))) {
154
+ paths.push(target.manifestPath, target.buildInfoPath, target.presetPath);
155
+ }
156
+ return paths;
157
+ }
158
+ function dsSourceStampPaths(driver) {
159
+ const paths = [];
160
+ for (const target of _nullishCoalesce(_optionalChain([driver, 'access', _5 => _5.designSystemWatchTargets, 'optionalCall', _6 => _6()]), () => ( []))) {
161
+ for (const file of target.sourceFiles) paths.push(file);
162
+ }
163
+ return paths;
164
+ }
165
+ function stampPaths(paths) {
166
+ if (paths.length === 0) return "";
167
+ let stamp = "";
168
+ for (let i = 0; i < paths.length; i++) {
169
+ if (i) stamp += "\0";
170
+ stamp += `${paths[i]}\0${readFileStamp(paths[i])}`;
171
+ }
172
+ return stamp;
173
+ }
75
174
  function registerDependencies(driver, result, cwd, parent) {
76
175
  for (const source of driver.compiler.sources()) {
77
176
  result.messages.push(
78
177
  withPluginMetadata(
79
178
  createSourceDependency({
80
- dir: _path.normalize.call(void 0, _path.resolve.call(void 0, cwd, source.base)),
179
+ dir: _nodepath.normalize.call(void 0, _nodepath.resolve.call(void 0, cwd, source.base)),
81
180
  glob: source.pattern
82
181
  }),
83
182
  parent
84
183
  )
85
184
  );
86
185
  }
87
- const configDeps = new Set(driver.configDependencies.map((file) => _path.normalize.call(void 0, _path.resolve.call(void 0, cwd, file))));
186
+ const configDeps = new Set(driver.configDependencies.map((file) => _nodepath.normalize.call(void 0, _nodepath.resolve.call(void 0, cwd, file))));
88
187
  if (driver.configPath) {
89
- configDeps.add(_path.normalize.call(void 0, _path.resolve.call(void 0, cwd, driver.configPath)));
188
+ configDeps.add(_nodepath.normalize.call(void 0, _nodepath.resolve.call(void 0, cwd, driver.configPath)));
90
189
  }
91
190
  for (const file of configDeps) {
92
191
  result.messages.push(
@@ -99,6 +198,19 @@ function registerDependencies(driver, result, cwd, parent) {
99
198
  )
100
199
  );
101
200
  }
201
+ for (const target of _nullishCoalesce(_optionalChain([driver, 'access', _7 => _7.designSystemWatchTargets, 'optionalCall', _8 => _8()]), () => ( []))) {
202
+ for (const file of [target.manifestPath, target.buildInfoPath, target.presetPath, ...target.sourceFiles]) {
203
+ result.messages.push(
204
+ withPluginMetadata(
205
+ {
206
+ type: "dependency",
207
+ file: _nodepath.normalize.call(void 0, file)
208
+ },
209
+ parent
210
+ )
211
+ );
212
+ }
213
+ }
102
214
  }
103
215
  function createSourceDependency(source) {
104
216
  if (process.env.ROLLUP_WATCH === "true") {
@@ -113,18 +225,17 @@ function withPluginMetadata(message, parent) {
113
225
  parent
114
226
  };
115
227
  }
116
- function formatDiagnostic(diagnostic) {
117
- const file = diagnostic.file ? `${diagnostic.file}` : "";
118
- const location = diagnostic.location ? `:${diagnostic.location.start.line}:${diagnostic.location.start.column}` : diagnostic.span ? `:${diagnostic.span.start}` : "";
119
- return `${diagnostic.severity} ${diagnostic.code} ${file}${location} ${diagnostic.message}`.replace(/\s+/g, " ");
120
- }
121
228
  function emitDiagnostics(root, result, diagnostics) {
122
229
  const error = diagnostics.find((diagnostic) => diagnostic.severity === "error");
123
230
  if (error) {
124
- throw root.error(formatDiagnostic(error), { plugin: PLUGIN_NAME });
231
+ throw root.error(_compilershared.formatDiagnostic.call(void 0, error), { plugin: PLUGIN_NAME });
125
232
  }
126
233
  for (const diagnostic of diagnostics) {
127
- result.warn(formatDiagnostic(diagnostic), { plugin: PLUGIN_NAME });
234
+ if (diagnostic.severity === "info") {
235
+ result.messages.push({ type: "pandacss-diagnostic", plugin: PLUGIN_NAME, diagnostic });
236
+ continue;
237
+ }
238
+ result.warn(_compilershared.formatDiagnostic.call(void 0, diagnostic), { plugin: PLUGIN_NAME });
128
239
  }
129
240
  }
130
241
 
package/dist/index.js CHANGED
@@ -1,11 +1,26 @@
1
1
  // src/index.ts
2
2
  import { createNodeDriver } from "@pandacss/compiler";
3
- import { extname, normalize, resolve } from "path";
3
+ import { formatDiagnostic } from "@pandacss/compiler-shared";
4
+ import { extname, normalize, resolve } from "node:path";
5
+
6
+ // src/fs-stamp.ts
7
+ import { statSync } from "node:fs";
8
+ function readFileStamp(path) {
9
+ try {
10
+ const stat = statSync(path);
11
+ return `${stat.mtimeMs}:${stat.size}`;
12
+ } catch {
13
+ return "missing";
14
+ }
15
+ }
16
+
17
+ // src/index.ts
4
18
  var PLUGIN_NAME = "pandacss";
5
19
  var driverStates = /* @__PURE__ */ new Map();
6
20
  var driverGuard;
7
21
  var pandacss = (options = {}) => {
8
- const postcssProcess = async (root, result) => {
22
+ const postcssProcess = async (root, helpers) => {
23
+ const result = helpers.result;
9
24
  const fileName = result.opts.from;
10
25
  if (shouldSkip(fileName, options.allow)) return;
11
26
  const inputCss = getInputCss(root, result);
@@ -15,20 +30,31 @@ var pandacss = (options = {}) => {
15
30
  let state = driverStates.get(key);
16
31
  if (!state) {
17
32
  const driver2 = await createNodeDriver({ cwd, configPath: options.configPath });
18
- state = { driver: driver2, generatedOutdirs: /* @__PURE__ */ new Set() };
33
+ state = {
34
+ driver: driver2,
35
+ generatedOutdirs: /* @__PURE__ */ new Set(),
36
+ parsedSources: /* @__PURE__ */ new Map(),
37
+ configStamp: stampPaths(configStampPaths(driver2)),
38
+ dsSourceStamp: stampPaths(dsSourceStampPaths(driver2))
39
+ };
19
40
  driverStates.set(key, state);
41
+ driver2.syncDesignSystemSources();
20
42
  } else {
21
- const diff = await state.driver.reload();
22
- if (diff.hasChanged) {
23
- state.generatedOutdirs.clear();
24
- }
43
+ await syncDriverState(state);
25
44
  }
26
45
  const { driver } = state;
46
+ const polyfill = driver.config.polyfill === true;
27
47
  if (!driver.compiler.hasLayerDeclaration(inputCss)) return;
28
48
  ensureCodegen(state, { cwd, outdir: options.outdir });
29
- driver.parseFiles();
49
+ syncProjectSources(state);
30
50
  registerDependencies(driver, result, cwd, fileName);
31
- const output = driver.cssgen({ emitLayerDeclaration: false });
51
+ emitDiagnostics(root, result, driver.designSystemDiagnostics ?? []);
52
+ if (polyfill) {
53
+ const stripped = driver.compiler.stripLayerOrderStatements(inputCss);
54
+ root.removeAll();
55
+ root.append(helpers.postcss.parse(stripped, { from: fileName }));
56
+ }
57
+ const output = driver.cssgen({ emitLayerDeclaration: false, polyfill });
32
58
  emitDiagnostics(root, result, output.diagnostics);
33
59
  root.append(output.css);
34
60
  root.walk((node) => {
@@ -41,7 +67,7 @@ var pandacss = (options = {}) => {
41
67
  postcssPlugin: PLUGIN_NAME,
42
68
  Once(root, helpers) {
43
69
  driverGuard = Promise.resolve(driverGuard).catch(() => {
44
- }).then(() => postcssProcess(root, helpers.result));
70
+ }).then(() => postcssProcess(root, helpers));
45
71
  return driverGuard;
46
72
  }
47
73
  };
@@ -72,6 +98,79 @@ function ensureCodegen(state, options) {
72
98
  state.driver.codegen({ cwd: options.cwd, outdir: options.outdir });
73
99
  state.generatedOutdirs.add(outdirKey);
74
100
  }
101
+ async function syncDriverState(state) {
102
+ const nextConfigStamp = stampPaths(configStampPaths(state.driver));
103
+ if (state.configStamp !== nextConfigStamp) {
104
+ const diff = await state.driver.reload();
105
+ state.configStamp = stampPaths(configStampPaths(state.driver));
106
+ if (diff.hasChanged) {
107
+ state.generatedOutdirs.clear();
108
+ state.parsedSources.clear();
109
+ }
110
+ state.driver.syncDesignSystemSources();
111
+ state.dsSourceStamp = stampPaths(dsSourceStampPaths(state.driver));
112
+ return;
113
+ }
114
+ const nextDsSourceStamp = stampPaths(dsSourceStampPaths(state.driver));
115
+ if (state.dsSourceStamp !== nextDsSourceStamp) {
116
+ state.driver.syncDesignSystemSources();
117
+ state.dsSourceStamp = nextDsSourceStamp;
118
+ }
119
+ }
120
+ function syncProjectSources(state) {
121
+ const files = state.driver.scan();
122
+ const scanned = new Set(files);
123
+ const changes = [];
124
+ for (const path of state.parsedSources.keys()) {
125
+ if (!scanned.has(path)) {
126
+ changes.push({ path, kind: "unlink" });
127
+ state.parsedSources.delete(path);
128
+ }
129
+ }
130
+ for (const path of files) {
131
+ const stamp = readFileStamp(path);
132
+ const known = state.parsedSources.get(path);
133
+ if (known === void 0) {
134
+ changes.push({ path, kind: "add" });
135
+ state.parsedSources.set(path, stamp);
136
+ continue;
137
+ }
138
+ if (known !== stamp) {
139
+ changes.push({ path, kind: "change" });
140
+ state.parsedSources.set(path, stamp);
141
+ }
142
+ }
143
+ if (changes.length > 0) {
144
+ state.driver.applyChanges(changes);
145
+ }
146
+ }
147
+ function configStampPaths(driver) {
148
+ const paths = [];
149
+ if (driver.configPath) paths.push(driver.configPath);
150
+ for (const dep of driver.configDependencies) {
151
+ paths.push(driver.resolvePath(dep));
152
+ }
153
+ for (const target of driver.designSystemWatchTargets?.() ?? []) {
154
+ paths.push(target.manifestPath, target.buildInfoPath, target.presetPath);
155
+ }
156
+ return paths;
157
+ }
158
+ function dsSourceStampPaths(driver) {
159
+ const paths = [];
160
+ for (const target of driver.designSystemWatchTargets?.() ?? []) {
161
+ for (const file of target.sourceFiles) paths.push(file);
162
+ }
163
+ return paths;
164
+ }
165
+ function stampPaths(paths) {
166
+ if (paths.length === 0) return "";
167
+ let stamp = "";
168
+ for (let i = 0; i < paths.length; i++) {
169
+ if (i) stamp += "\0";
170
+ stamp += `${paths[i]}\0${readFileStamp(paths[i])}`;
171
+ }
172
+ return stamp;
173
+ }
75
174
  function registerDependencies(driver, result, cwd, parent) {
76
175
  for (const source of driver.compiler.sources()) {
77
176
  result.messages.push(
@@ -99,6 +198,19 @@ function registerDependencies(driver, result, cwd, parent) {
99
198
  )
100
199
  );
101
200
  }
201
+ for (const target of driver.designSystemWatchTargets?.() ?? []) {
202
+ for (const file of [target.manifestPath, target.buildInfoPath, target.presetPath, ...target.sourceFiles]) {
203
+ result.messages.push(
204
+ withPluginMetadata(
205
+ {
206
+ type: "dependency",
207
+ file: normalize(file)
208
+ },
209
+ parent
210
+ )
211
+ );
212
+ }
213
+ }
102
214
  }
103
215
  function createSourceDependency(source) {
104
216
  if (process.env.ROLLUP_WATCH === "true") {
@@ -113,17 +225,16 @@ function withPluginMetadata(message, parent) {
113
225
  parent
114
226
  };
115
227
  }
116
- function formatDiagnostic(diagnostic) {
117
- const file = diagnostic.file ? `${diagnostic.file}` : "";
118
- const location = diagnostic.location ? `:${diagnostic.location.start.line}:${diagnostic.location.start.column}` : diagnostic.span ? `:${diagnostic.span.start}` : "";
119
- return `${diagnostic.severity} ${diagnostic.code} ${file}${location} ${diagnostic.message}`.replace(/\s+/g, " ");
120
- }
121
228
  function emitDiagnostics(root, result, diagnostics) {
122
229
  const error = diagnostics.find((diagnostic) => diagnostic.severity === "error");
123
230
  if (error) {
124
231
  throw root.error(formatDiagnostic(error), { plugin: PLUGIN_NAME });
125
232
  }
126
233
  for (const diagnostic of diagnostics) {
234
+ if (diagnostic.severity === "info") {
235
+ result.messages.push({ type: "pandacss-diagnostic", plugin: PLUGIN_NAME, diagnostic });
236
+ continue;
237
+ }
127
238
  result.warn(formatDiagnostic(diagnostic), { plugin: PLUGIN_NAME });
128
239
  }
129
240
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/postcss",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.20",
4
4
  "description": "PostCSS plugin for Panda CSS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -30,14 +30,14 @@
30
30
  "dist"
31
31
  ],
32
32
  "dependencies": {
33
- "@pandacss/compiler": "2.0.0-beta.2",
34
- "@pandacss/compiler-shared": "2.0.0-beta.2"
33
+ "@pandacss/compiler": "2.0.0-beta.20",
34
+ "@pandacss/compiler-shared": "2.0.0-beta.20"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "postcss": ">=8"
38
38
  },
39
39
  "devDependencies": {
40
- "postcss": "8.5.14"
40
+ "postcss": "8.5.28"
41
41
  },
42
42
  "engines": {
43
43
  "node": ">=22"