@gustcss/postcss 0.5.3 → 0.5.5

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 (2) hide show
  1. package/dist/index.cjs +11 -9
  2. package/package.json +2 -2
package/dist/index.cjs CHANGED
@@ -141,18 +141,19 @@ const plugin = (opts = {}) => {
141
141
  return {
142
142
  postcssPlugin: "gustcss",
143
143
  Once(root, { result }) {
144
- let hasDirective = false;
144
+ let directiveAtRule = null;
145
145
  root.walkAtRules("gustcss", (atRule) => {
146
- hasDirective = true;
147
- atRule.remove();
146
+ if (directiveAtRule === null) directiveAtRule = atRule;
147
+ else atRule.remove();
148
148
  });
149
- if (!hasDirective) return;
149
+ if (directiveAtRule === null) return;
150
150
  const cwd = process.cwd();
151
151
  const binaryPath = runner.resolveBinary({ cwd });
152
152
  const resolvedConfigPath = runner.resolveConfig({
153
153
  cwd,
154
154
  configPath
155
155
  });
156
+ const fromFile = root.source?.input?.file ?? result.opts?.from;
156
157
  const run = (cfgPath) => {
157
158
  const args = runner.buildArgs({
158
159
  mode: "stdout",
@@ -160,7 +161,7 @@ const plugin = (opts = {}) => {
160
161
  configPath: cfgPath
161
162
  });
162
163
  try {
163
- const result = childProcess.spawnSync(binaryPath, args, {
164
+ const spawnResult = childProcess.spawnSync(binaryPath, args, {
164
165
  cwd,
165
166
  encoding: "utf-8",
166
167
  stdio: [
@@ -169,10 +170,11 @@ const plugin = (opts = {}) => {
169
170
  "pipe"
170
171
  ]
171
172
  });
172
- if (result.status !== 0) throw new Error(`gustcss build failed: ${result.stderr}`);
173
- if (result.stderr) process.stderr.write(result.stderr);
174
- const parsed = require("postcss").parse(result.stdout);
175
- root.append(parsed);
173
+ if (spawnResult.status !== 0) throw new Error(`gustcss build failed: ${spawnResult.stderr}`);
174
+ if (spawnResult.stderr) process.stderr.write(spawnResult.stderr);
175
+ const parsed = require("postcss").parse(spawnResult.stdout, { from: fromFile });
176
+ if (directiveAtRule) directiveAtRule.replaceWith(parsed);
177
+ else root.append(parsed);
176
178
  } catch (error) {
177
179
  throw new Error(`gustcss build failed: ${error.message}`);
178
180
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustcss/postcss",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "PostCSS plugin for GustCSS",
5
5
  "main": "dist/index.cjs",
6
6
  "type": "commonjs",
@@ -21,7 +21,7 @@
21
21
  "access": "public"
22
22
  },
23
23
  "dependencies": {
24
- "gustcss": "^0.5.3"
24
+ "gustcss": "^0.5.5"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "postcss": "^8.0.0"