@ape-egg/vibe-compiler 3.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/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @ape-egg/vibe-compiler
2
+
3
+ The optional Rust compiler for [Vibe](https://www.npmjs.com/package/@ape-egg/vibe). The runtime never needs it — this package exists for when you want pre-rendered initial paint (hyperspeed manifests), build-time component inlining, iteration batch functions, custom-element transforms, or compiled SPA output.
4
+
5
+ ```bash
6
+ bun add -d @ape-egg/vibe-compiler # or npm i -D
7
+ bunx vibe --init # write the vibe-compiler config into package.json
8
+ bunx vibe # compile
9
+ ```
10
+
11
+ Compiled output is, by invariant, still runtime Vibe code — compiling is an optimization, never a requirement.
12
+
13
+ ## Platform support
14
+
15
+ Prebuilt binaries ship for **macOS arm64** and **Linux x64**. On any other platform the bin shim falls back to `cargo run` — you need a Rust toolchain, and the first compile builds from source (minutes, once). There is no Windows binary yet.
16
+
17
+ ## Configuration
18
+
19
+ Lives in your project's `package.json` under `"vibe-compiler"`. See the [Vibe compiler docs](https://vibe.korte.kim/compiler/introduction.html) for every option and flag (`--minify`, `--watch`, `--spa`, `--source`, `--output`, and the `*-as-is` opt-outs).
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from 'node:child_process';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { dirname, join } from 'node:path';
6
+ import { existsSync } from 'node:fs';
7
+ import { platform, arch } from 'node:os';
8
+
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+ const nativeDir = join(__dirname, '..', 'native');
11
+ const originalCwd = process.cwd();
12
+
13
+ // Map Node.js platform/arch to binary names
14
+ const getPlatformBinary = () => {
15
+ const os = platform();
16
+ const cpu = arch();
17
+
18
+ const platformMap = {
19
+ 'darwin-arm64': 'vibe-compiler-darwin-arm64',
20
+ 'darwin-x64': 'vibe-compiler-darwin-x64',
21
+ 'linux-x64': 'vibe-compiler-linux-x64',
22
+ 'linux-arm64': 'vibe-compiler-linux-arm64',
23
+ 'win32-x64': 'vibe-compiler-win32-x64.exe',
24
+ };
25
+
26
+ const key = `${os}-${cpu}`;
27
+ const binary = platformMap[key];
28
+
29
+ if (!binary) {
30
+ console.error(`Unsupported platform: ${os}-${cpu}`);
31
+ console.error('Supported platforms: darwin-arm64, darwin-x64, linux-x64, linux-arm64, win32-x64');
32
+ process.exit(1);
33
+ }
34
+
35
+ return binary;
36
+ };
37
+
38
+ // The wrapper is what gets killed (Ctrl+C, a dev server's child.kill(), a
39
+ // process manager) — without forwarding, the compiler child survives as an
40
+ // orphan whose watch lock blocks every future `--watch` on the same output.
41
+ const wireLifecycle = (child) => {
42
+ ['SIGINT', 'SIGTERM', 'SIGHUP'].forEach((signal) =>
43
+ process.on(signal, () => child.kill(signal)),
44
+ );
45
+ process.on('exit', () => child.kill());
46
+ };
47
+
48
+ const run = () => {
49
+ const binary = getPlatformBinary();
50
+ const binaryPath = join(nativeDir, binary);
51
+ let userArgs = process.argv.slice(2);
52
+
53
+ // Handle subcommand: vibe compile [args]
54
+ // If first arg is "compile" or "c", remove it (the binary doesn't need it)
55
+ if (userArgs[0] === 'compile' || userArgs[0] === 'c') {
56
+ userArgs = userArgs.slice(1);
57
+ } else if (userArgs[0] && !userArgs[0].startsWith('-')) {
58
+ // Unknown subcommand
59
+ console.error(`Unknown subcommand: ${userArgs[0]}`);
60
+ console.error('Available subcommands: compile (or c)');
61
+ console.error('Usage: vibe compile [options]');
62
+ process.exit(1);
63
+ }
64
+ // If no subcommand provided, default to compile behavior (pass args as-is)
65
+
66
+ // Check if native binary exists
67
+ if (!existsSync(binaryPath)) {
68
+ // Fall back to cargo run for development
69
+ console.info('[vibe-compile] Native binary not found, building with cargo...');
70
+
71
+ const srcDir = join(__dirname, '..', 'src');
72
+
73
+ if (!existsSync(join(srcDir, 'Cargo.toml'))) {
74
+ console.error('Neither native binary nor Rust source found.');
75
+ console.error(`Expected binary at: ${binaryPath}`);
76
+ console.error(`Or Cargo.toml at: ${srcDir}`);
77
+ process.exit(1);
78
+ }
79
+
80
+ // Pass --cwd to tell the Rust binary the original working directory
81
+ const cargoArgs = ['run', '--release', '--', '--cwd', originalCwd, ...userArgs];
82
+
83
+ const cargo = spawn('cargo', cargoArgs, {
84
+ cwd: srcDir,
85
+ stdio: 'inherit',
86
+ });
87
+ wireLifecycle(cargo);
88
+
89
+ cargo.on('error', (err) => {
90
+ if (err.code === 'ENOENT') {
91
+ console.error('Cargo not found. Please install Rust: https://rustup.rs');
92
+ } else {
93
+ console.error('Failed to run cargo:', err.message);
94
+ }
95
+ process.exit(1);
96
+ });
97
+
98
+ cargo.on('close', (code) => {
99
+ process.exit(code ?? 0);
100
+ });
101
+
102
+ return;
103
+ }
104
+
105
+ // Run the native binary (it runs in the user's cwd, so no --cwd needed)
106
+ const child = spawn(binaryPath, userArgs, {
107
+ stdio: 'inherit',
108
+ });
109
+ wireLifecycle(child);
110
+
111
+ child.on('error', (err) => {
112
+ console.error('Failed to run vibe-compiler:', err.message);
113
+ process.exit(1);
114
+ });
115
+
116
+ child.on('close', (code) => {
117
+ process.exit(code ?? 0);
118
+ });
119
+ };
120
+
121
+ run();
File without changes
Binary file
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@ape-egg/vibe-compiler",
3
+ "version": "3.0.0",
4
+ "type": "module",
5
+ "description": "Optional Rust compiler for Vibe — pre-renders, inlines components, and optimizes iterations. The runtime never needs it.",
6
+ "homepage": "https://vibe.korte.kim",
7
+ "bin": {
8
+ "vibe": "./bin/vibe-compile.js"
9
+ },
10
+ "files": [
11
+ "bin",
12
+ "native",
13
+ "src/Cargo.toml",
14
+ "src/Cargo.lock",
15
+ "src/main.rs",
16
+ "src/config.rs",
17
+ "src/compiler",
18
+ "src/parser"
19
+ ],
20
+ "keywords": [
21
+ "vibe",
22
+ "compiler",
23
+ "reactive",
24
+ "framework",
25
+ "prerender"
26
+ ],
27
+ "author": "kkortes",
28
+ "license": "ISC",
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "dependencies": {}
33
+ }