@pandacss/postcss 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.
- package/dist/index.cjs +104 -25
- package/dist/index.js +97 -18
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,38 +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
3
|
var _compilershared = require('@pandacss/compiler-shared');
|
|
4
|
-
var
|
|
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
|
|
5
18
|
var PLUGIN_NAME = "pandacss";
|
|
6
19
|
var driverStates = /* @__PURE__ */ new Map();
|
|
7
20
|
var driverGuard;
|
|
8
21
|
var pandacss = (options = {}) => {
|
|
9
|
-
const postcssProcess = async (root,
|
|
22
|
+
const postcssProcess = async (root, helpers) => {
|
|
23
|
+
const result = helpers.result;
|
|
10
24
|
const fileName = result.opts.from;
|
|
11
25
|
if (shouldSkip(fileName, options.allow)) return;
|
|
12
26
|
const inputCss = getInputCss(root, result);
|
|
13
27
|
if (!inputCss.includes("@layer")) return;
|
|
14
|
-
const cwd =
|
|
28
|
+
const cwd = _nodepath.resolve.call(void 0, _nullishCoalesce(options.cwd, () => ( process.cwd())));
|
|
15
29
|
const key = getDriverKey(cwd, options.configPath);
|
|
16
30
|
let state = driverStates.get(key);
|
|
17
31
|
if (!state) {
|
|
18
32
|
const driver2 = await _compiler.createNodeDriver.call(void 0, { cwd, configPath: options.configPath });
|
|
19
|
-
state = {
|
|
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
|
+
};
|
|
20
40
|
driverStates.set(key, state);
|
|
41
|
+
driver2.syncDesignSystemSources();
|
|
21
42
|
} else {
|
|
22
|
-
|
|
23
|
-
if (diff.hasChanged) {
|
|
24
|
-
state.generatedOutdirs.clear();
|
|
25
|
-
state.parsedSources.clear();
|
|
26
|
-
}
|
|
43
|
+
await syncDriverState(state);
|
|
27
44
|
}
|
|
28
45
|
const { driver } = state;
|
|
46
|
+
const polyfill = driver.config.polyfill === true;
|
|
29
47
|
if (!driver.compiler.hasLayerDeclaration(inputCss)) return;
|
|
30
48
|
ensureCodegen(state, { cwd, outdir: options.outdir });
|
|
31
49
|
syncProjectSources(state);
|
|
32
|
-
driver.syncDesignSystemSources();
|
|
33
50
|
registerDependencies(driver, result, cwd, fileName);
|
|
34
51
|
emitDiagnostics(root, result, _nullishCoalesce(driver.designSystemDiagnostics, () => ( [])));
|
|
35
|
-
|
|
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 });
|
|
36
58
|
emitDiagnostics(root, result, output.diagnostics);
|
|
37
59
|
root.append(output.css);
|
|
38
60
|
root.walk((node) => {
|
|
@@ -45,7 +67,7 @@ var pandacss = (options = {}) => {
|
|
|
45
67
|
postcssPlugin: PLUGIN_NAME,
|
|
46
68
|
Once(root, helpers) {
|
|
47
69
|
driverGuard = Promise.resolve(driverGuard).catch(() => {
|
|
48
|
-
}).then(() => postcssProcess(root, helpers
|
|
70
|
+
}).then(() => postcssProcess(root, helpers));
|
|
49
71
|
return driverGuard;
|
|
50
72
|
}
|
|
51
73
|
};
|
|
@@ -55,7 +77,7 @@ var index_default = pandacss;
|
|
|
55
77
|
var nodeModulesRegex = /node_modules/;
|
|
56
78
|
function isValidCss(file) {
|
|
57
79
|
const [filePath] = file.split("?");
|
|
58
|
-
return
|
|
80
|
+
return _nodepath.extname.call(void 0, filePath) === ".css";
|
|
59
81
|
}
|
|
60
82
|
var shouldSkip = (fileName, allow) => {
|
|
61
83
|
if (!fileName) return true;
|
|
@@ -76,37 +98,94 @@ function ensureCodegen(state, options) {
|
|
|
76
98
|
state.driver.codegen({ cwd: options.cwd, outdir: options.outdir });
|
|
77
99
|
state.generatedOutdirs.add(outdirKey);
|
|
78
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
|
+
}
|
|
79
120
|
function syncProjectSources(state) {
|
|
80
|
-
const files =
|
|
121
|
+
const files = state.driver.scan();
|
|
122
|
+
const scanned = new Set(files);
|
|
81
123
|
const changes = [];
|
|
82
|
-
for (const path of state.parsedSources) {
|
|
83
|
-
if (!
|
|
124
|
+
for (const path of state.parsedSources.keys()) {
|
|
125
|
+
if (!scanned.has(path)) {
|
|
84
126
|
changes.push({ path, kind: "unlink" });
|
|
85
127
|
state.parsedSources.delete(path);
|
|
86
128
|
}
|
|
87
129
|
}
|
|
88
130
|
for (const path of files) {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
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);
|
|
92
155
|
}
|
|
93
|
-
|
|
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;
|
|
94
173
|
}
|
|
95
174
|
function registerDependencies(driver, result, cwd, parent) {
|
|
96
175
|
for (const source of driver.compiler.sources()) {
|
|
97
176
|
result.messages.push(
|
|
98
177
|
withPluginMetadata(
|
|
99
178
|
createSourceDependency({
|
|
100
|
-
dir:
|
|
179
|
+
dir: _nodepath.normalize.call(void 0, _nodepath.resolve.call(void 0, cwd, source.base)),
|
|
101
180
|
glob: source.pattern
|
|
102
181
|
}),
|
|
103
182
|
parent
|
|
104
183
|
)
|
|
105
184
|
);
|
|
106
185
|
}
|
|
107
|
-
const configDeps = new Set(driver.configDependencies.map((file) =>
|
|
186
|
+
const configDeps = new Set(driver.configDependencies.map((file) => _nodepath.normalize.call(void 0, _nodepath.resolve.call(void 0, cwd, file))));
|
|
108
187
|
if (driver.configPath) {
|
|
109
|
-
configDeps.add(
|
|
188
|
+
configDeps.add(_nodepath.normalize.call(void 0, _nodepath.resolve.call(void 0, cwd, driver.configPath)));
|
|
110
189
|
}
|
|
111
190
|
for (const file of configDeps) {
|
|
112
191
|
result.messages.push(
|
|
@@ -119,13 +198,13 @@ function registerDependencies(driver, result, cwd, parent) {
|
|
|
119
198
|
)
|
|
120
199
|
);
|
|
121
200
|
}
|
|
122
|
-
for (const target of _nullishCoalesce(_optionalChain([driver, 'access',
|
|
201
|
+
for (const target of _nullishCoalesce(_optionalChain([driver, 'access', _7 => _7.designSystemWatchTargets, 'optionalCall', _8 => _8()]), () => ( []))) {
|
|
123
202
|
for (const file of [target.manifestPath, target.buildInfoPath, target.presetPath, ...target.sourceFiles]) {
|
|
124
203
|
result.messages.push(
|
|
125
204
|
withPluginMetadata(
|
|
126
205
|
{
|
|
127
206
|
type: "dependency",
|
|
128
|
-
file:
|
|
207
|
+
file: _nodepath.normalize.call(void 0, file)
|
|
129
208
|
},
|
|
130
209
|
parent
|
|
131
210
|
)
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { createNodeDriver } from "@pandacss/compiler";
|
|
3
3
|
import { formatDiagnostic } from "@pandacss/compiler-shared";
|
|
4
|
-
import { extname, normalize, resolve } from "path";
|
|
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
|
|
5
18
|
var PLUGIN_NAME = "pandacss";
|
|
6
19
|
var driverStates = /* @__PURE__ */ new Map();
|
|
7
20
|
var driverGuard;
|
|
8
21
|
var pandacss = (options = {}) => {
|
|
9
|
-
const postcssProcess = async (root,
|
|
22
|
+
const postcssProcess = async (root, helpers) => {
|
|
23
|
+
const result = helpers.result;
|
|
10
24
|
const fileName = result.opts.from;
|
|
11
25
|
if (shouldSkip(fileName, options.allow)) return;
|
|
12
26
|
const inputCss = getInputCss(root, result);
|
|
@@ -16,23 +30,31 @@ var pandacss = (options = {}) => {
|
|
|
16
30
|
let state = driverStates.get(key);
|
|
17
31
|
if (!state) {
|
|
18
32
|
const driver2 = await createNodeDriver({ cwd, configPath: options.configPath });
|
|
19
|
-
state = {
|
|
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
|
+
};
|
|
20
40
|
driverStates.set(key, state);
|
|
41
|
+
driver2.syncDesignSystemSources();
|
|
21
42
|
} else {
|
|
22
|
-
|
|
23
|
-
if (diff.hasChanged) {
|
|
24
|
-
state.generatedOutdirs.clear();
|
|
25
|
-
state.parsedSources.clear();
|
|
26
|
-
}
|
|
43
|
+
await syncDriverState(state);
|
|
27
44
|
}
|
|
28
45
|
const { driver } = state;
|
|
46
|
+
const polyfill = driver.config.polyfill === true;
|
|
29
47
|
if (!driver.compiler.hasLayerDeclaration(inputCss)) return;
|
|
30
48
|
ensureCodegen(state, { cwd, outdir: options.outdir });
|
|
31
49
|
syncProjectSources(state);
|
|
32
|
-
driver.syncDesignSystemSources();
|
|
33
50
|
registerDependencies(driver, result, cwd, fileName);
|
|
34
51
|
emitDiagnostics(root, result, driver.designSystemDiagnostics ?? []);
|
|
35
|
-
|
|
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 });
|
|
36
58
|
emitDiagnostics(root, result, output.diagnostics);
|
|
37
59
|
root.append(output.css);
|
|
38
60
|
root.walk((node) => {
|
|
@@ -45,7 +67,7 @@ var pandacss = (options = {}) => {
|
|
|
45
67
|
postcssPlugin: PLUGIN_NAME,
|
|
46
68
|
Once(root, helpers) {
|
|
47
69
|
driverGuard = Promise.resolve(driverGuard).catch(() => {
|
|
48
|
-
}).then(() => postcssProcess(root, helpers
|
|
70
|
+
}).then(() => postcssProcess(root, helpers));
|
|
49
71
|
return driverGuard;
|
|
50
72
|
}
|
|
51
73
|
};
|
|
@@ -76,21 +98,78 @@ function ensureCodegen(state, options) {
|
|
|
76
98
|
state.driver.codegen({ cwd: options.cwd, outdir: options.outdir });
|
|
77
99
|
state.generatedOutdirs.add(outdirKey);
|
|
78
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
|
+
}
|
|
79
120
|
function syncProjectSources(state) {
|
|
80
|
-
const files =
|
|
121
|
+
const files = state.driver.scan();
|
|
122
|
+
const scanned = new Set(files);
|
|
81
123
|
const changes = [];
|
|
82
|
-
for (const path of state.parsedSources) {
|
|
83
|
-
if (!
|
|
124
|
+
for (const path of state.parsedSources.keys()) {
|
|
125
|
+
if (!scanned.has(path)) {
|
|
84
126
|
changes.push({ path, kind: "unlink" });
|
|
85
127
|
state.parsedSources.delete(path);
|
|
86
128
|
}
|
|
87
129
|
}
|
|
88
130
|
for (const path of files) {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
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])}`;
|
|
92
171
|
}
|
|
93
|
-
|
|
172
|
+
return stamp;
|
|
94
173
|
}
|
|
95
174
|
function registerDependencies(driver, result, cwd, parent) {
|
|
96
175
|
for (const source of driver.compiler.sources()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/postcss",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
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
|
|
34
|
-
"@pandacss/compiler-shared": "2.0.0
|
|
33
|
+
"@pandacss/compiler": "2.0.0",
|
|
34
|
+
"@pandacss/compiler-shared": "2.0.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"postcss": ">=8"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"postcss": "8.5.
|
|
40
|
+
"postcss": "8.5.28"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=22"
|