flexui-vite 0.0.0-stage → 2.0.0-alpha.1

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.
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Vite plugin for FlexUI.
3
+ *
4
+ * The plugin never reimplements the compiler: it spawns the same precompiled
5
+ * binary as the CLI, so a Vite project and a CLI project produce byte-identical
6
+ * stylesheets. During `vite build` it compiles once before the bundle is
7
+ * written; during `vite dev` it starts `flexui watch` and streams compiler
8
+ * errors to the Vite logger.
9
+ */
10
+ export interface FlexUIOptions {
11
+ /** Project directory. Defaults to Vite's `root`. */
12
+ root?: string;
13
+ /** Config file path, relative to the project root. */
14
+ config?: string;
15
+ /** Entry stylesheet with @flexui directives. */
16
+ input?: string;
17
+ /** Output stylesheet, relative to the project root. */
18
+ output?: string;
19
+ /** Globs to scan instead of the config file's `content`. */
20
+ content?: string | readonly string[];
21
+ /** Classes that must always be emitted. */
22
+ safelist?: string | readonly string[];
23
+ /** Force minification on or off instead of following Vite's build.minify. */
24
+ minify?: boolean;
25
+ /** Run `flexui watch` during dev. Defaults to true. */
26
+ watch?: boolean;
27
+ /** Compiler command. Defaults to FLEXUI_BINARY, the local .bin, or PATH. */
28
+ command?: string;
29
+ }
30
+ /** The subset of Vite's resolved config this plugin reads. */
31
+ export interface ViteResolvedConfigLike {
32
+ root?: string;
33
+ command?: "build" | "serve" | string;
34
+ build?: {
35
+ minify?: boolean | string;
36
+ };
37
+ }
38
+ /** The subset of Vite's dev server this plugin uses. */
39
+ export interface ViteDevServerLike {
40
+ config?: {
41
+ logger?: {
42
+ info?(message: string): void;
43
+ warn?(message: string): void;
44
+ error?(message: string): void;
45
+ };
46
+ };
47
+ httpServer?: {
48
+ once(event: "close", listener: () => void): unknown;
49
+ } | null;
50
+ }
51
+ /** Minimal plugin context: only `error` is used, and it is optional in tests. */
52
+ export interface VitePluginContextLike {
53
+ error?(message: string): never | void;
54
+ warn?(message: string): void;
55
+ }
56
+ export interface FlexUIPlugin {
57
+ name: string;
58
+ enforce: "pre";
59
+ configResolved?(config: ViteResolvedConfigLike): void;
60
+ buildStart?(this: VitePluginContextLike): Promise<void>;
61
+ configureServer?(server: ViteDevServerLike): void;
62
+ closeBundle?(): void;
63
+ }
64
+ /** Locates the compiler binary without failing when it is not installed yet. */
65
+ export declare function resolveCommand(root: string, command?: string): string;
66
+ /**
67
+ * Builds the argument vector for `flexui build` or `flexui watch`.
68
+ * Flags precede the project directory, matching the CLI's own wrapper.
69
+ */
70
+ export declare function compilerArgs(command: "build" | "watch", options: FlexUIOptions, root: string, minify: boolean): string[];
71
+ /** The message shown when the compiler exits non-zero. */
72
+ export declare function formatFailure(args: readonly string[], stderr: string): string;
73
+ /**
74
+ * Creates the Vite plugin.
75
+ *
76
+ * ```ts
77
+ * // vite.config.ts
78
+ * import { defineConfig } from "vite";
79
+ * import { flexui } from "@flexui/vite";
80
+ *
81
+ * export default defineConfig({ plugins: [flexui({ minify: true })] });
82
+ * ```
83
+ */
84
+ export declare function flexui(options?: FlexUIOptions): FlexUIPlugin;
85
+ export default flexui;
package/dist/index.js ADDED
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Vite plugin for FlexUI.
3
+ *
4
+ * The plugin never reimplements the compiler: it spawns the same precompiled
5
+ * binary as the CLI, so a Vite project and a CLI project produce byte-identical
6
+ * stylesheets. During `vite build` it compiles once before the bundle is
7
+ * written; during `vite dev` it starts `flexui watch` and streams compiler
8
+ * errors to the Vite logger.
9
+ */
10
+ import { spawn } from "node:child_process";
11
+ import { existsSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ function binaryName() {
14
+ return process.platform === "win32" ? "flexui.cmd" : "flexui";
15
+ }
16
+ /** Locates the compiler binary without failing when it is not installed yet. */
17
+ export function resolveCommand(root, command) {
18
+ if (command !== undefined && command !== "") {
19
+ return command;
20
+ }
21
+ const override = process.env["FLEXUI_BINARY"];
22
+ if (override !== undefined && override !== "") {
23
+ return override;
24
+ }
25
+ const local = join(root, "node_modules", ".bin", binaryName());
26
+ return existsSync(local) ? local : "flexui";
27
+ }
28
+ function listArgs(flag, value) {
29
+ if (value === undefined) {
30
+ return [];
31
+ }
32
+ const text = Array.isArray(value) ? value.join(",") : String(value);
33
+ return text === "" ? [] : [flag, text];
34
+ }
35
+ /**
36
+ * Builds the argument vector for `flexui build` or `flexui watch`.
37
+ * Flags precede the project directory, matching the CLI's own wrapper.
38
+ */
39
+ export function compilerArgs(command, options, root, minify) {
40
+ const args = [command];
41
+ if (options.config !== undefined && options.config !== "") {
42
+ args.push("--config", options.config);
43
+ }
44
+ args.push(...listArgs("--input", options.input), ...listArgs("--output", options.output), ...listArgs("--content", options.content), ...listArgs("--safelist", options.safelist));
45
+ if (minify) {
46
+ args.push("--minify");
47
+ }
48
+ args.push(root);
49
+ return args;
50
+ }
51
+ /** The message shown when the compiler exits non-zero. */
52
+ export function formatFailure(args, stderr) {
53
+ const detail = stderr.trim();
54
+ if (detail !== "") {
55
+ return detail;
56
+ }
57
+ return `flexui ${args.join(" ")} exited without a diagnostic`;
58
+ }
59
+ function runOnce(command, args, cwd) {
60
+ return new Promise((resolve, reject) => {
61
+ const child = spawn(command, [...args], {
62
+ cwd,
63
+ windowsHide: true,
64
+ stdio: ["ignore", "ignore", "pipe"],
65
+ });
66
+ let stderr = "";
67
+ child.stderr?.setEncoding("utf8");
68
+ child.stderr?.on("data", (chunk) => {
69
+ stderr += chunk;
70
+ });
71
+ child.on("error", reject);
72
+ child.on("close", (code) => {
73
+ resolve({ code: code ?? 1, stderr });
74
+ });
75
+ });
76
+ }
77
+ function startWatcher(command, args, cwd, report) {
78
+ const child = spawn(command, [...args], {
79
+ cwd,
80
+ windowsHide: true,
81
+ stdio: ["ignore", "pipe", "pipe"],
82
+ });
83
+ const forward = (chunk) => {
84
+ const text = String(chunk).trimEnd();
85
+ if (text !== "") {
86
+ report(text);
87
+ }
88
+ };
89
+ child.stdout?.on("data", forward);
90
+ child.stderr?.on("data", forward);
91
+ child.on("error", (error) => {
92
+ report(`could not start the FlexUI compiler: ${error.message}`);
93
+ });
94
+ return child;
95
+ }
96
+ /**
97
+ * Creates the Vite plugin.
98
+ *
99
+ * ```ts
100
+ * // vite.config.ts
101
+ * import { defineConfig } from "vite";
102
+ * import { flexui } from "@flexui/vite";
103
+ *
104
+ * export default defineConfig({ plugins: [flexui({ minify: true })] });
105
+ * ```
106
+ */
107
+ export function flexui(options = {}) {
108
+ let root = options.root ?? process.cwd();
109
+ let minify = options.minify ?? false;
110
+ let serve = false;
111
+ let watcher = null;
112
+ const stopWatcher = () => {
113
+ if (watcher !== null) {
114
+ watcher.kill();
115
+ watcher = null;
116
+ }
117
+ };
118
+ return {
119
+ name: "flexui",
120
+ enforce: "pre",
121
+ configResolved(config) {
122
+ if (options.root === undefined && typeof config.root === "string") {
123
+ root = config.root;
124
+ }
125
+ serve = config.command === "serve";
126
+ minify = options.minify ?? (config.build?.minify !== false);
127
+ },
128
+ async buildStart() {
129
+ if (serve) {
130
+ // `configureServer` runs the watcher, which performs the first build.
131
+ return;
132
+ }
133
+ const command = resolveCommand(root, options.command);
134
+ const args = compilerArgs("build", options, root, minify);
135
+ try {
136
+ const outcome = await runOnce(command, args, root);
137
+ if (outcome.code !== 0) {
138
+ const message = formatFailure(args, outcome.stderr);
139
+ if (typeof this.error === "function") {
140
+ this.error(message);
141
+ }
142
+ throw new Error(message);
143
+ }
144
+ }
145
+ catch (error) {
146
+ const message = error instanceof Error ? error.message : String(error);
147
+ if (typeof this.error === "function") {
148
+ this.error(message);
149
+ }
150
+ throw error;
151
+ }
152
+ },
153
+ configureServer(server) {
154
+ if (options.watch === false) {
155
+ return;
156
+ }
157
+ const command = resolveCommand(root, options.command);
158
+ const args = compilerArgs("watch", options, root, minify);
159
+ const report = (message) => {
160
+ const target = server.config?.logger;
161
+ if (message.includes("error") || message.includes("failed")) {
162
+ (target?.error ?? console.error)(message);
163
+ }
164
+ else {
165
+ (target?.info ?? console.info)(message);
166
+ }
167
+ };
168
+ watcher = startWatcher(command, args, root, report);
169
+ server.httpServer?.once("close", stopWatcher);
170
+ },
171
+ closeBundle() {
172
+ stopWatcher();
173
+ },
174
+ };
175
+ }
176
+ export default flexui;
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
- {
2
- "name": "flexui-vite",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "flexui-vite",
3
+ "version": "2.0.0-alpha.1",
4
+ "description": "Vite plugin that compiles FlexUI stylesheets for dev and build",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "typecheck": "tsc -p tsconfig.json --noEmit",
22
+ "test": "bun test test"
23
+ },
24
+ "peerDependencies": {
25
+ "vite": ">=5.0.0"
26
+ },
27
+ "peerDependenciesMeta": {
28
+ "vite": {
29
+ "optional": true
30
+ }
31
+ },
32
+ "keywords": [
33
+ "flexui",
34
+ "vite-plugin",
35
+ "css"
36
+ ]
37
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.