@gustcss/vite 0.5.2 → 0.5.3
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 +163 -57
- package/dist/index.mjs +186 -57
- package/package.json +6 -4
package/dist/index.cjs
CHANGED
|
@@ -9,6 +9,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
9
9
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
10
|
var __getProtoOf = Object.getPrototypeOf;
|
|
11
11
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
12
13
|
var __copyProps = (to, from, except, desc) => {
|
|
13
14
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
15
|
key = keys[i];
|
|
@@ -29,7 +30,118 @@ let path = require("path");
|
|
|
29
30
|
path = __toESM(path, 1);
|
|
30
31
|
let fs = require("fs");
|
|
31
32
|
fs = __toESM(fs, 1);
|
|
33
|
+
let crypto = require("crypto");
|
|
34
|
+
//#endregion
|
|
32
35
|
//#region src/index.js
|
|
36
|
+
var import_runner = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
37
|
+
/**
|
|
38
|
+
* gustcss shared runner — helpers for the @gustcss/postcss and @gustcss/vite
|
|
39
|
+
* plugins.
|
|
40
|
+
*
|
|
41
|
+
* These functions centralize the four pieces of logic that the two plugins
|
|
42
|
+
* previously duplicated:
|
|
43
|
+
* - binary discovery (resolveBinary)
|
|
44
|
+
* - config-file detection (resolveConfig)
|
|
45
|
+
* - temporary config-file lifecycle (withTempConfig)
|
|
46
|
+
* - CLI argument assembly (buildArgs)
|
|
47
|
+
*
|
|
48
|
+
* They are pure (no module-level state) and accept `fs` via dependency
|
|
49
|
+
* injection so callers and tests can substitute it. The implementation uses
|
|
50
|
+
* only Node's built-in `path`, `fs`, and `crypto` — no third-party dependencies.
|
|
51
|
+
*
|
|
52
|
+
* This module is NOT a public API. It is inlined into each plugin's `dist`
|
|
53
|
+
* bundle at build time (rolldown) and is never published as a standalone
|
|
54
|
+
* source file. The `npm/shared/` directory deliberately has no own
|
|
55
|
+
* package.json with a public name, only a private one for running tests.
|
|
56
|
+
*
|
|
57
|
+
* @security Paths (cwd, config, output) are trusted: they originate from the
|
|
58
|
+
* developer's build configuration. These helpers are for build-time use only.
|
|
59
|
+
*/
|
|
60
|
+
const path$2 = require("path");
|
|
61
|
+
const crypto$1 = require("crypto");
|
|
62
|
+
const DEFAULT_CONFIG_NAMES = ["gustcss.config.json", "gustcss.config.js"];
|
|
63
|
+
/**
|
|
64
|
+
* Locate the gustcss CLI binary, trying three paths in order:
|
|
65
|
+
* 1. <cwd>/node_modules/.bin/gustcss (normal local install)
|
|
66
|
+
* 2. <cwd>/../../bin/gustcss (sample projects in this repo)
|
|
67
|
+
* 3. 'gustcss' (global install — always accepted)
|
|
68
|
+
*
|
|
69
|
+
* @param {{ cwd: string, fs?: { existsSync: Function } }} options
|
|
70
|
+
* @returns {string} the resolved binary path or the bare 'gustcss' sentinel
|
|
71
|
+
*/
|
|
72
|
+
function resolveBinary({ cwd, fs: fs$2 = require("fs") }) {
|
|
73
|
+
const candidates = [path$2.join(cwd, "node_modules", ".bin", "gustcss"), path$2.join(cwd, "..", "..", "bin", "gustcss")];
|
|
74
|
+
for (const candidate of candidates) if (fs$2.existsSync(candidate)) return candidate;
|
|
75
|
+
return "gustcss";
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Determine which config file the CLI should use.
|
|
79
|
+
* - If an explicit configPath is given, it is returned as-is (no fs access).
|
|
80
|
+
* - Otherwise auto-detect gustcss.config.json, then gustcss.config.js, in cwd.
|
|
81
|
+
* - Returns null when nothing is found (caller falls back to a temp config).
|
|
82
|
+
*
|
|
83
|
+
* @param {{ cwd: string, configPath?: string, fs?: { existsSync: Function } }} options
|
|
84
|
+
* @returns {string|null}
|
|
85
|
+
*/
|
|
86
|
+
function resolveConfig({ cwd, configPath, fs: fs$3 = require("fs") }) {
|
|
87
|
+
if (configPath) return configPath;
|
|
88
|
+
for (const name of DEFAULT_CONFIG_NAMES) {
|
|
89
|
+
const fullPath = path$2.join(cwd, name);
|
|
90
|
+
if (fs$3.existsSync(fullPath)) return fullPath;
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Write a temporary config file ({ content }) at <cwd>/<prefix>.<random8hex>.tmp.json,
|
|
96
|
+
* invoke `fn` with the temp file path, and always clean the file up afterwards.
|
|
97
|
+
*
|
|
98
|
+
* The file is created with the 'wx' flag (O_EXCL equivalent): if a file with
|
|
99
|
+
* the same name already exists the write fails, preventing symlink-redirection
|
|
100
|
+
* attacks and parallel-run collisions. Because the name contains 8 random bytes
|
|
101
|
+
* the probability of a collision is negligible.
|
|
102
|
+
*
|
|
103
|
+
* @param {{ cwd: string, content: any, prefix: string, fs?: { writeFileSync: Function, existsSync: Function, unlinkSync: Function } }} options
|
|
104
|
+
* @param {(tempConfigPath: string) => any} fn
|
|
105
|
+
* @returns {any} whatever `fn` returns
|
|
106
|
+
*/
|
|
107
|
+
function withTempConfig({ cwd, content, prefix, fs: fs$4 = require("fs") }, fn) {
|
|
108
|
+
const tmpName = `${prefix}.${crypto$1.randomBytes(8).toString("hex")}.tmp.json`;
|
|
109
|
+
const tempConfigPath = path$2.join(cwd, tmpName);
|
|
110
|
+
fs$4.writeFileSync(tempConfigPath, JSON.stringify({ content }), { flag: "wx" });
|
|
111
|
+
try {
|
|
112
|
+
return fn(tempConfigPath);
|
|
113
|
+
} finally {
|
|
114
|
+
if (fs$4.existsSync(tempConfigPath)) fs$4.unlinkSync(tempConfigPath);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Assemble the CLI argument array.
|
|
119
|
+
*
|
|
120
|
+
* @param {object} options
|
|
121
|
+
* @param {'stdout'|'output'} options.mode 'stdout' emits to stdout (postcss);
|
|
122
|
+
* 'output' writes to a file (-o, vite).
|
|
123
|
+
* @param {string} [options.output] output path (required for 'output' mode)
|
|
124
|
+
* @param {boolean} [options.cssLayers] append --css-layers when truthy
|
|
125
|
+
* @param {boolean} [options.watch] append --watch when truthy
|
|
126
|
+
* @param {string|null} [options.configPath] append --config <path> when present
|
|
127
|
+
* @returns {string[]}
|
|
128
|
+
*/
|
|
129
|
+
function buildArgs({ mode, output, cssLayers, configPath, watch }) {
|
|
130
|
+
const args = ["build"];
|
|
131
|
+
if (watch) args.push("--watch");
|
|
132
|
+
if (mode === "stdout") args.push("--stdout");
|
|
133
|
+
else args.push("-o", output);
|
|
134
|
+
if (cssLayers) args.push("--css-layers");
|
|
135
|
+
if (configPath) args.push("--config", configPath);
|
|
136
|
+
return args;
|
|
137
|
+
}
|
|
138
|
+
module.exports = {
|
|
139
|
+
resolveBinary,
|
|
140
|
+
resolveConfig,
|
|
141
|
+
withTempConfig,
|
|
142
|
+
buildArgs
|
|
143
|
+
};
|
|
144
|
+
})))(), 1);
|
|
33
145
|
/**
|
|
34
146
|
* @gustcss/vite - Vite plugin for CSS Utility Generator
|
|
35
147
|
*
|
|
@@ -50,55 +162,50 @@ function cssUtility(opts = {}) {
|
|
|
50
162
|
const outputToCssLayers = opts.outputToCssLayers;
|
|
51
163
|
let watchProcess = null;
|
|
52
164
|
function findBinary(cwd) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
];
|
|
58
|
-
for (const p of possiblePaths) if (p === "gustcss" || fs.default.existsSync(p)) return p;
|
|
59
|
-
throw new Error("gustcss binary not found");
|
|
165
|
+
return import_runner.default.resolveBinary({
|
|
166
|
+
cwd,
|
|
167
|
+
fs: fs.default
|
|
168
|
+
});
|
|
60
169
|
}
|
|
61
170
|
function findConfigFile(cwd) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
171
|
+
return import_runner.default.resolveConfig({
|
|
172
|
+
cwd,
|
|
173
|
+
configPath,
|
|
174
|
+
fs: fs.default
|
|
175
|
+
});
|
|
68
176
|
}
|
|
69
177
|
function buildCSS(cwd, binaryPath) {
|
|
70
178
|
const resolvedConfigPath = findConfigFile(cwd);
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
let tempConfigPath = null;
|
|
78
|
-
if (resolvedConfigPath) args.push("--config", resolvedConfigPath);
|
|
79
|
-
else {
|
|
80
|
-
tempConfigPath = path.default.join(cwd, ".gustcss.vite.tmp.json");
|
|
81
|
-
const tempConfig = { content };
|
|
82
|
-
fs.default.writeFileSync(tempConfigPath, JSON.stringify(tempConfig));
|
|
83
|
-
args.push("--config", tempConfigPath);
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
const result = (0, child_process.spawnSync)(binaryPath, args, {
|
|
87
|
-
cwd,
|
|
88
|
-
encoding: "utf-8",
|
|
89
|
-
stdio: [
|
|
90
|
-
"pipe",
|
|
91
|
-
"pipe",
|
|
92
|
-
"pipe"
|
|
93
|
-
]
|
|
179
|
+
const run = (cfgPath) => {
|
|
180
|
+
const args = import_runner.default.buildArgs({
|
|
181
|
+
mode: "output",
|
|
182
|
+
output,
|
|
183
|
+
cssLayers: outputToCssLayers,
|
|
184
|
+
configPath: cfgPath
|
|
94
185
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
186
|
+
try {
|
|
187
|
+
const result = (0, child_process.spawnSync)(binaryPath, args, {
|
|
188
|
+
cwd,
|
|
189
|
+
encoding: "utf-8",
|
|
190
|
+
stdio: [
|
|
191
|
+
"pipe",
|
|
192
|
+
"pipe",
|
|
193
|
+
"pipe"
|
|
194
|
+
]
|
|
195
|
+
});
|
|
196
|
+
if (result.status !== 0) throw new Error(`gustcss build failed: ${result.stderr}`);
|
|
197
|
+
if (result.stderr) process.stderr.write(result.stderr);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
throw new Error(`gustcss build failed: ${error.message}`);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
if (resolvedConfigPath) run(resolvedConfigPath);
|
|
203
|
+
else import_runner.default.withTempConfig({
|
|
204
|
+
cwd,
|
|
205
|
+
content,
|
|
206
|
+
prefix: ".gustcss.vite",
|
|
207
|
+
fs: fs.default
|
|
208
|
+
}, (tempConfigPath) => run(tempConfigPath));
|
|
102
209
|
}
|
|
103
210
|
return {
|
|
104
211
|
name: "gustcss",
|
|
@@ -122,22 +229,21 @@ function cssUtility(opts = {}) {
|
|
|
122
229
|
} catch (error) {
|
|
123
230
|
console.error(`[gustcss] Failed to build CSS: ${error.message}`);
|
|
124
231
|
}
|
|
125
|
-
const watchArgs = [
|
|
126
|
-
"build",
|
|
127
|
-
"--watch",
|
|
128
|
-
"-o",
|
|
129
|
-
output
|
|
130
|
-
];
|
|
131
|
-
if (outputToCssLayers) watchArgs.push("--css-layers");
|
|
132
232
|
let tempConfigPath = null;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
fs.default.writeFileSync(tempConfigPath, JSON.stringify(
|
|
138
|
-
|
|
233
|
+
let watchConfigPath = resolvedConfigPath;
|
|
234
|
+
if (!watchConfigPath) {
|
|
235
|
+
const randomHex = (0, crypto.randomBytes)(8).toString("hex");
|
|
236
|
+
tempConfigPath = path.default.join(cwd, `.gustcss.vite.${randomHex}.tmp.json`);
|
|
237
|
+
fs.default.writeFileSync(tempConfigPath, JSON.stringify({ content }), { flag: "wx" });
|
|
238
|
+
watchConfigPath = tempConfigPath;
|
|
139
239
|
}
|
|
140
|
-
watchProcess = (0, child_process.spawn)(binaryPath,
|
|
240
|
+
watchProcess = (0, child_process.spawn)(binaryPath, import_runner.default.buildArgs({
|
|
241
|
+
mode: "output",
|
|
242
|
+
output,
|
|
243
|
+
cssLayers: outputToCssLayers,
|
|
244
|
+
configPath: watchConfigPath,
|
|
245
|
+
watch: true
|
|
246
|
+
}), {
|
|
141
247
|
cwd,
|
|
142
248
|
stdio: [
|
|
143
249
|
"pipe",
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,142 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import { spawn, spawnSync } from "child_process";
|
|
2
3
|
import path from "path";
|
|
3
4
|
import fs from "fs";
|
|
5
|
+
import { randomBytes } from "crypto";
|
|
6
|
+
//#region \0rolldown/runtime.js
|
|
7
|
+
var __create = Object.create;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
16
|
+
key = keys[i];
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: ((k) => from[k]).bind(null, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
29
|
+
//#endregion
|
|
4
30
|
//#region src/index.js
|
|
31
|
+
var import_runner = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
32
|
+
/**
|
|
33
|
+
* gustcss shared runner — helpers for the @gustcss/postcss and @gustcss/vite
|
|
34
|
+
* plugins.
|
|
35
|
+
*
|
|
36
|
+
* These functions centralize the four pieces of logic that the two plugins
|
|
37
|
+
* previously duplicated:
|
|
38
|
+
* - binary discovery (resolveBinary)
|
|
39
|
+
* - config-file detection (resolveConfig)
|
|
40
|
+
* - temporary config-file lifecycle (withTempConfig)
|
|
41
|
+
* - CLI argument assembly (buildArgs)
|
|
42
|
+
*
|
|
43
|
+
* They are pure (no module-level state) and accept `fs` via dependency
|
|
44
|
+
* injection so callers and tests can substitute it. The implementation uses
|
|
45
|
+
* only Node's built-in `path`, `fs`, and `crypto` — no third-party dependencies.
|
|
46
|
+
*
|
|
47
|
+
* This module is NOT a public API. It is inlined into each plugin's `dist`
|
|
48
|
+
* bundle at build time (rolldown) and is never published as a standalone
|
|
49
|
+
* source file. The `npm/shared/` directory deliberately has no own
|
|
50
|
+
* package.json with a public name, only a private one for running tests.
|
|
51
|
+
*
|
|
52
|
+
* @security Paths (cwd, config, output) are trusted: they originate from the
|
|
53
|
+
* developer's build configuration. These helpers are for build-time use only.
|
|
54
|
+
*/
|
|
55
|
+
const path$1 = __require("path");
|
|
56
|
+
const crypto = __require("crypto");
|
|
57
|
+
const DEFAULT_CONFIG_NAMES = ["gustcss.config.json", "gustcss.config.js"];
|
|
58
|
+
/**
|
|
59
|
+
* Locate the gustcss CLI binary, trying three paths in order:
|
|
60
|
+
* 1. <cwd>/node_modules/.bin/gustcss (normal local install)
|
|
61
|
+
* 2. <cwd>/../../bin/gustcss (sample projects in this repo)
|
|
62
|
+
* 3. 'gustcss' (global install — always accepted)
|
|
63
|
+
*
|
|
64
|
+
* @param {{ cwd: string, fs?: { existsSync: Function } }} options
|
|
65
|
+
* @returns {string} the resolved binary path or the bare 'gustcss' sentinel
|
|
66
|
+
*/
|
|
67
|
+
function resolveBinary({ cwd, fs = __require("fs") }) {
|
|
68
|
+
const candidates = [path$1.join(cwd, "node_modules", ".bin", "gustcss"), path$1.join(cwd, "..", "..", "bin", "gustcss")];
|
|
69
|
+
for (const candidate of candidates) if (fs.existsSync(candidate)) return candidate;
|
|
70
|
+
return "gustcss";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Determine which config file the CLI should use.
|
|
74
|
+
* - If an explicit configPath is given, it is returned as-is (no fs access).
|
|
75
|
+
* - Otherwise auto-detect gustcss.config.json, then gustcss.config.js, in cwd.
|
|
76
|
+
* - Returns null when nothing is found (caller falls back to a temp config).
|
|
77
|
+
*
|
|
78
|
+
* @param {{ cwd: string, configPath?: string, fs?: { existsSync: Function } }} options
|
|
79
|
+
* @returns {string|null}
|
|
80
|
+
*/
|
|
81
|
+
function resolveConfig({ cwd, configPath, fs = __require("fs") }) {
|
|
82
|
+
if (configPath) return configPath;
|
|
83
|
+
for (const name of DEFAULT_CONFIG_NAMES) {
|
|
84
|
+
const fullPath = path$1.join(cwd, name);
|
|
85
|
+
if (fs.existsSync(fullPath)) return fullPath;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Write a temporary config file ({ content }) at <cwd>/<prefix>.<random8hex>.tmp.json,
|
|
91
|
+
* invoke `fn` with the temp file path, and always clean the file up afterwards.
|
|
92
|
+
*
|
|
93
|
+
* The file is created with the 'wx' flag (O_EXCL equivalent): if a file with
|
|
94
|
+
* the same name already exists the write fails, preventing symlink-redirection
|
|
95
|
+
* attacks and parallel-run collisions. Because the name contains 8 random bytes
|
|
96
|
+
* the probability of a collision is negligible.
|
|
97
|
+
*
|
|
98
|
+
* @param {{ cwd: string, content: any, prefix: string, fs?: { writeFileSync: Function, existsSync: Function, unlinkSync: Function } }} options
|
|
99
|
+
* @param {(tempConfigPath: string) => any} fn
|
|
100
|
+
* @returns {any} whatever `fn` returns
|
|
101
|
+
*/
|
|
102
|
+
function withTempConfig({ cwd, content, prefix, fs = __require("fs") }, fn) {
|
|
103
|
+
const tmpName = `${prefix}.${crypto.randomBytes(8).toString("hex")}.tmp.json`;
|
|
104
|
+
const tempConfigPath = path$1.join(cwd, tmpName);
|
|
105
|
+
fs.writeFileSync(tempConfigPath, JSON.stringify({ content }), { flag: "wx" });
|
|
106
|
+
try {
|
|
107
|
+
return fn(tempConfigPath);
|
|
108
|
+
} finally {
|
|
109
|
+
if (fs.existsSync(tempConfigPath)) fs.unlinkSync(tempConfigPath);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Assemble the CLI argument array.
|
|
114
|
+
*
|
|
115
|
+
* @param {object} options
|
|
116
|
+
* @param {'stdout'|'output'} options.mode 'stdout' emits to stdout (postcss);
|
|
117
|
+
* 'output' writes to a file (-o, vite).
|
|
118
|
+
* @param {string} [options.output] output path (required for 'output' mode)
|
|
119
|
+
* @param {boolean} [options.cssLayers] append --css-layers when truthy
|
|
120
|
+
* @param {boolean} [options.watch] append --watch when truthy
|
|
121
|
+
* @param {string|null} [options.configPath] append --config <path> when present
|
|
122
|
+
* @returns {string[]}
|
|
123
|
+
*/
|
|
124
|
+
function buildArgs({ mode, output, cssLayers, configPath, watch }) {
|
|
125
|
+
const args = ["build"];
|
|
126
|
+
if (watch) args.push("--watch");
|
|
127
|
+
if (mode === "stdout") args.push("--stdout");
|
|
128
|
+
else args.push("-o", output);
|
|
129
|
+
if (cssLayers) args.push("--css-layers");
|
|
130
|
+
if (configPath) args.push("--config", configPath);
|
|
131
|
+
return args;
|
|
132
|
+
}
|
|
133
|
+
module.exports = {
|
|
134
|
+
resolveBinary,
|
|
135
|
+
resolveConfig,
|
|
136
|
+
withTempConfig,
|
|
137
|
+
buildArgs
|
|
138
|
+
};
|
|
139
|
+
})))(), 1);
|
|
5
140
|
/**
|
|
6
141
|
* @gustcss/vite - Vite plugin for CSS Utility Generator
|
|
7
142
|
*
|
|
@@ -22,55 +157,50 @@ function cssUtility(opts = {}) {
|
|
|
22
157
|
const outputToCssLayers = opts.outputToCssLayers;
|
|
23
158
|
let watchProcess = null;
|
|
24
159
|
function findBinary(cwd) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
];
|
|
30
|
-
for (const p of possiblePaths) if (p === "gustcss" || fs.existsSync(p)) return p;
|
|
31
|
-
throw new Error("gustcss binary not found");
|
|
160
|
+
return import_runner.default.resolveBinary({
|
|
161
|
+
cwd,
|
|
162
|
+
fs
|
|
163
|
+
});
|
|
32
164
|
}
|
|
33
165
|
function findConfigFile(cwd) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
166
|
+
return import_runner.default.resolveConfig({
|
|
167
|
+
cwd,
|
|
168
|
+
configPath,
|
|
169
|
+
fs
|
|
170
|
+
});
|
|
40
171
|
}
|
|
41
172
|
function buildCSS(cwd, binaryPath) {
|
|
42
173
|
const resolvedConfigPath = findConfigFile(cwd);
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let tempConfigPath = null;
|
|
50
|
-
if (resolvedConfigPath) args.push("--config", resolvedConfigPath);
|
|
51
|
-
else {
|
|
52
|
-
tempConfigPath = path.join(cwd, ".gustcss.vite.tmp.json");
|
|
53
|
-
const tempConfig = { content };
|
|
54
|
-
fs.writeFileSync(tempConfigPath, JSON.stringify(tempConfig));
|
|
55
|
-
args.push("--config", tempConfigPath);
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
const result = spawnSync(binaryPath, args, {
|
|
59
|
-
cwd,
|
|
60
|
-
encoding: "utf-8",
|
|
61
|
-
stdio: [
|
|
62
|
-
"pipe",
|
|
63
|
-
"pipe",
|
|
64
|
-
"pipe"
|
|
65
|
-
]
|
|
174
|
+
const run = (cfgPath) => {
|
|
175
|
+
const args = import_runner.default.buildArgs({
|
|
176
|
+
mode: "output",
|
|
177
|
+
output,
|
|
178
|
+
cssLayers: outputToCssLayers,
|
|
179
|
+
configPath: cfgPath
|
|
66
180
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
181
|
+
try {
|
|
182
|
+
const result = spawnSync(binaryPath, args, {
|
|
183
|
+
cwd,
|
|
184
|
+
encoding: "utf-8",
|
|
185
|
+
stdio: [
|
|
186
|
+
"pipe",
|
|
187
|
+
"pipe",
|
|
188
|
+
"pipe"
|
|
189
|
+
]
|
|
190
|
+
});
|
|
191
|
+
if (result.status !== 0) throw new Error(`gustcss build failed: ${result.stderr}`);
|
|
192
|
+
if (result.stderr) process.stderr.write(result.stderr);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
throw new Error(`gustcss build failed: ${error.message}`);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
if (resolvedConfigPath) run(resolvedConfigPath);
|
|
198
|
+
else import_runner.default.withTempConfig({
|
|
199
|
+
cwd,
|
|
200
|
+
content,
|
|
201
|
+
prefix: ".gustcss.vite",
|
|
202
|
+
fs
|
|
203
|
+
}, (tempConfigPath) => run(tempConfigPath));
|
|
74
204
|
}
|
|
75
205
|
return {
|
|
76
206
|
name: "gustcss",
|
|
@@ -94,22 +224,21 @@ function cssUtility(opts = {}) {
|
|
|
94
224
|
} catch (error) {
|
|
95
225
|
console.error(`[gustcss] Failed to build CSS: ${error.message}`);
|
|
96
226
|
}
|
|
97
|
-
const watchArgs = [
|
|
98
|
-
"build",
|
|
99
|
-
"--watch",
|
|
100
|
-
"-o",
|
|
101
|
-
output
|
|
102
|
-
];
|
|
103
|
-
if (outputToCssLayers) watchArgs.push("--css-layers");
|
|
104
227
|
let tempConfigPath = null;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
fs.writeFileSync(tempConfigPath, JSON.stringify(
|
|
110
|
-
|
|
228
|
+
let watchConfigPath = resolvedConfigPath;
|
|
229
|
+
if (!watchConfigPath) {
|
|
230
|
+
const randomHex = randomBytes(8).toString("hex");
|
|
231
|
+
tempConfigPath = path.join(cwd, `.gustcss.vite.${randomHex}.tmp.json`);
|
|
232
|
+
fs.writeFileSync(tempConfigPath, JSON.stringify({ content }), { flag: "wx" });
|
|
233
|
+
watchConfigPath = tempConfigPath;
|
|
111
234
|
}
|
|
112
|
-
watchProcess = spawn(binaryPath,
|
|
235
|
+
watchProcess = spawn(binaryPath, import_runner.default.buildArgs({
|
|
236
|
+
mode: "output",
|
|
237
|
+
output,
|
|
238
|
+
cssLayers: outputToCssLayers,
|
|
239
|
+
configPath: watchConfigPath,
|
|
240
|
+
watch: true
|
|
241
|
+
}), {
|
|
113
242
|
cwd,
|
|
114
243
|
stdio: [
|
|
115
244
|
"pipe",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gustcss/vite",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Vite plugin for GustCSS",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "node build.js",
|
|
22
|
-
"prepublishOnly": "npm run build"
|
|
22
|
+
"prepublishOnly": "npm run build",
|
|
23
|
+
"test": "vitest run"
|
|
23
24
|
},
|
|
24
25
|
"keywords": [
|
|
25
26
|
"vite",
|
|
@@ -33,10 +34,11 @@
|
|
|
33
34
|
"access": "public"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"gustcss": "^0.5.
|
|
37
|
+
"gustcss": "^0.5.3"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"rolldown": "^1.
|
|
40
|
+
"rolldown": "^1.1.0",
|
|
41
|
+
"vitest": "^4.1.8"
|
|
40
42
|
},
|
|
41
43
|
"peerDependencies": {
|
|
42
44
|
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0"
|