@nebutra/vrt 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.
Binary file
package/bin/vrt.js ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { resolveBinary, unsupportedBinaryMessage } from "../src/resolve-binary.js";
4
+
5
+ const bin = await resolveBinary();
6
+ if (!bin) {
7
+ console.error(unsupportedBinaryMessage());
8
+ process.exit(1);
9
+ }
10
+
11
+ const child = spawn(bin, process.argv.slice(2), {
12
+ stdio: "inherit",
13
+ env: process.env,
14
+ });
15
+
16
+ child.on("error", (error) => {
17
+ console.error(`Unable to start VRT binary: ${error.message}`);
18
+ process.exit(1);
19
+ });
20
+
21
+ child.on("exit", (code, signal) => {
22
+ if (signal) {
23
+ process.kill(process.pid, signal);
24
+ return;
25
+ }
26
+ process.exit(code ?? 1);
27
+ });
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@nebutra/vrt",
3
+ "version": "0.1.0",
4
+ "description": "Agent-native local verification runtime CLI for fast, auditable code checks.",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/nebutra/vrt.git"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "bin": {
14
+ "vrt": "bin/vrt.js"
15
+ },
16
+ "exports": {
17
+ ".": "./src/index.js"
18
+ },
19
+ "files": [
20
+ "bin",
21
+ "src"
22
+ ],
23
+ "scripts": {
24
+ "build:binary": "cargo build --release -p vrt-cli",
25
+ "stage:binary": "node scripts/stage-platform-binary.mjs",
26
+ "prepack": "npm run build:binary && npm run stage:binary",
27
+ "test": "node --test test/*.test.js"
28
+ },
29
+ "license": "MIT"
30
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export const packageName = "vrt";
2
+ export { packagedBinary, resolveBinary, unsupportedBinaryMessage } from "./resolve-binary.js";
@@ -0,0 +1,66 @@
1
+ import { constants } from "node:fs";
2
+ import { access } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ export async function resolveBinary(options = {}) {
7
+ const packageRoot = options.packageRoot ?? defaultPackageRoot();
8
+ const env = options.env ?? process.env;
9
+ const platform = options.platform ?? process.platform;
10
+ const arch = options.arch ?? process.arch;
11
+ const pathBinary = options.pathBinary ?? true;
12
+
13
+ if (env.VRT_BIN) {
14
+ return (await executable(env.VRT_BIN)) ? env.VRT_BIN : null;
15
+ }
16
+
17
+ const candidates = [
18
+ packagedBinary(packageRoot, platform, arch),
19
+ repoBinary(packageRoot, "target", "release", executableName(platform)),
20
+ repoBinary(packageRoot, "target", "debug", executableName(platform)),
21
+ pathBinary ? "vrt" : null,
22
+ ].filter(Boolean);
23
+
24
+ for (const candidate of candidates) {
25
+ if (candidate === "vrt") {
26
+ return candidate;
27
+ }
28
+ if (await executable(candidate)) {
29
+ return candidate;
30
+ }
31
+ }
32
+
33
+ return null;
34
+ }
35
+
36
+ export function unsupportedBinaryMessage(options = {}) {
37
+ const platform = options.platform ?? process.platform;
38
+ const arch = options.arch ?? process.arch;
39
+ return `Unable to locate VRT binary for ${platform}-${arch}. Set VRT_BIN to an executable VRT binary, install a package that includes bin/${platform}-${arch}/${executableName(platform)}, or build the Rust CLI with \`cargo build -p vrt-cli\`.`;
40
+ }
41
+
42
+ export function packagedBinary(packageRoot, platform, arch) {
43
+ return path.join(packageRoot, "bin", `${platform}-${arch}`, executableName(platform));
44
+ }
45
+
46
+ function repoBinary(packageRoot, ...segments) {
47
+ return path.resolve(packageRoot, "..", "..", ...segments);
48
+ }
49
+
50
+ async function executable(candidate) {
51
+ try {
52
+ await access(candidate, constants.X_OK);
53
+ return true;
54
+ } catch {
55
+ return false;
56
+ }
57
+ }
58
+
59
+ function executableName(platform) {
60
+ return platform === "win32" ? "vrt.exe" : "vrt";
61
+ }
62
+
63
+ function defaultPackageRoot() {
64
+ const here = path.dirname(fileURLToPath(import.meta.url));
65
+ return path.resolve(here, "..");
66
+ }