diff --git a/README.md b/README.md index 35599cf..00141f1 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,11 @@ npx vale ## Why Because the ones who know, know. + +## Advanced + +If you need to use a different binary than the pre-installed one (ie: the package doesn't support your system), you can specify a custom one like so: + +```bash +VALE_BIN="/path/to/vale" npx vale +``` \ No newline at end of file diff --git a/src/vale.ts b/src/vale.ts index 4ae7ef2..6eb1bab 100644 --- a/src/vale.ts +++ b/src/vale.ts @@ -1,18 +1,42 @@ #!/usr/bin/env node import { spawnSync } from "node:child_process"; -import { outputBin } from "./shared"; import { existsSync } from "fs-extra"; -if (existsSync(outputBin)) { - const result = spawnSync(outputBin, process.argv.slice(2), { - stdio: "inherit", - }); - if (result.signal) { - console.error(`Process failed with signal: ${result.signal}`); +import { outputBin } from "./shared"; + +function resolveBin(): string { + const { VALE_BIN } = process.env; + + if (VALE_BIN) { + if (existsSync(VALE_BIN)) { + return VALE_BIN; + } + console.error( + `VALE_BIN variable was specified but the path could not be found. Tried binary: ${VALE_BIN}`, + ); + process.exit(1) } - if (result.error) { - console.error(`Failed to run Vale, process exited with error: ${result.error.message}`) + + if (!existsSync(outputBin)) { + console.error("Missing Vale binary. Did you run the postinstall?"); + process.exit(1); } - process.exit(result.status ?? 1); + + return outputBin; +} + +const bin = resolveBin(); + +const result = spawnSync(bin, process.argv.slice(2), { + stdio: "inherit", +}); + +if (result.signal) { + console.error(`Process failed with signal: ${result.signal}`); +} +if (result.error) { + console.error( + `Failed to run Vale, process exited with error: ${result.error.message}`, + ); } -console.error("Missing Vale binary. Did you run the postinstall?"); -process.exit(1); + +process.exit(result.status ?? 1); \ No newline at end of file