@floeorg/vite-plugin 0.1.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.
@@ -0,0 +1,22 @@
1
+ import type { Plugin } from "vite";
2
+ export interface FloeOptions {
3
+ /** Path to the floe binary. Defaults to "floe". */
4
+ compiler?: string;
5
+ }
6
+ /**
7
+ * Vite plugin for Floe.
8
+ *
9
+ * Transforms `.fl` files to TypeScript in the build pipeline.
10
+ * Uses the `floe` compiler binary for compilation.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { defineConfig } from "vite"
15
+ * import floe from "@floeorg/vite-plugin"
16
+ *
17
+ * export default defineConfig({
18
+ * plugins: [floe()],
19
+ * })
20
+ * ```
21
+ */
22
+ export default function floe(options?: FloeOptions): Plugin;
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ import { execFileSync } from "node:child_process";
2
+ /**
3
+ * Vite plugin for Floe.
4
+ *
5
+ * Transforms `.fl` files to TypeScript in the build pipeline.
6
+ * Uses the `floe` compiler binary for compilation.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { defineConfig } from "vite"
11
+ * import floe from "@floeorg/vite-plugin"
12
+ *
13
+ * export default defineConfig({
14
+ * plugins: [floe()],
15
+ * })
16
+ * ```
17
+ */
18
+ export default function floe(options = {}) {
19
+ const compiler = options.compiler ?? "floe";
20
+ return {
21
+ name: "vite-plugin-floe",
22
+ enforce: "pre",
23
+ transform(code, id) {
24
+ // Strip query params for extension check (Vite adds ?import, ?t=xxx, etc.)
25
+ const cleanId = id.split("?")[0];
26
+ if (!cleanId.endsWith(".fl"))
27
+ return null;
28
+ try {
29
+ const result = compileFloe(compiler, code, id);
30
+ return {
31
+ code: result.code,
32
+ map: result.map,
33
+ };
34
+ }
35
+ catch (error) {
36
+ const message = error instanceof Error ? error.message : String(error);
37
+ this.error(`Floe compilation failed for ${id}:\n${message}`);
38
+ }
39
+ },
40
+ handleHotUpdate({ file, server }) {
41
+ if (file.endsWith(".fl")) {
42
+ const modules = server.moduleGraph.getModulesByFile(file);
43
+ if (modules) {
44
+ return [...modules];
45
+ }
46
+ }
47
+ },
48
+ };
49
+ }
50
+ function compileFloe(compiler, _source, filename) {
51
+ try {
52
+ const output = execFileSync(compiler, ["build", "--emit-stdout", filename], {
53
+ encoding: "utf-8",
54
+ timeout: 30_000,
55
+ stdio: ["pipe", "pipe", "pipe"], // capture stderr instead of printing
56
+ });
57
+ return {
58
+ code: output,
59
+ map: null,
60
+ };
61
+ }
62
+ catch (error) {
63
+ if (error && typeof error === "object" && "stderr" in error) {
64
+ const stderr = error.stderr;
65
+ throw new Error(String(stderr));
66
+ }
67
+ throw error;
68
+ }
69
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@floeorg/vite-plugin",
3
+ "version": "0.1.0",
4
+ "description": "Vite plugin for Floe - compile .fl files to TypeScript",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "prepublishOnly": "npm run build"
14
+ },
15
+ "keywords": [
16
+ "vite",
17
+ "vite-plugin",
18
+ "floe"
19
+ ],
20
+ "license": "MIT",
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/milkyskies/floe",
27
+ "directory": "integrations/vite-plugin-floe"
28
+ },
29
+ "homepage": "https://github.com/milkyskies/floe",
30
+ "peerDependencies": {
31
+ "vite": "^5.0.0 || ^6.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^25.5.0",
35
+ "typescript": "^5.0.0",
36
+ "vite": "^6.0.0"
37
+ }
38
+ }