Skip to main content

bynk/
check.rs

1//! `bynk check` — type-check a `.bynk` file or project without writing output.
2//!
3//! Runs the linked pipeline in-process (v0.138, #487): a directory routes
4//! through [`bynk_driver::project::compile_project`], a single file through
5//! [`bynk_emit::compile_with_warnings`] — exactly `bynk check`'s two branches, so the
6//! output is identical. The body is [`bynk_driver::run_check`], shared with `bynk`.
7
8use bynk_driver::emsg;
9use std::path::PathBuf;
10use std::process::ExitCode;
11
12use crate::cli::CheckFormatArg;
13
14/// Run `bynk check`.
15pub fn run(
16    input: PathBuf,
17    format: CheckFormatArg,
18    fix: Option<Vec<String>>,
19    emit: bool,
20    each: bool,
21) -> ExitCode {
22    let short = format == CheckFormatArg::Short;
23    if emit && !input.is_dir() {
24        emsg!("bynk check: error: `--emit` takes a project directory, not a single file");
25        return ExitCode::FAILURE;
26    }
27    let checked = bynk_driver::run_check("bynk", &input, short, fix.as_deref(), each);
28    // #3068: `--emit` type-checks the generated TypeScript, but only for a
29    // program that passed the check; a failed check has nothing to emit.
30    if emit && checked == ExitCode::SUCCESS {
31        return if bynk_driver::tsc_report::check_emit_all("bynk", &input, short, each) {
32            ExitCode::SUCCESS
33        } else {
34            ExitCode::FAILURE
35        };
36    }
37    checked
38}