Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#### :nail_care: Polish

- Rewatch: plain output when not running in tty. https://github.com/rescript-lang/rescript/pull/7970

#### :house: Internal

# 12.0.0-rc.2
Expand Down
52 changes: 26 additions & 26 deletions rewatch/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ pub fn initialize_build(
filter: &Option<regex::Regex>,
show_progress: bool,
path: &Path,
snapshot_output: bool,
plain_output: bool,
warn_error: Option<String>,
) -> Result<BuildCommandState> {
let project_context = ProjectContext::new(path)?;
let compiler = get_compiler_info(&project_context)?;

if !snapshot_output && show_progress {
if !plain_output && show_progress {
print!("{} {}Building package tree...", style("[1/7]").bold().dim(), TREE);
let _ = stdout().flush();
}
Expand All @@ -149,7 +149,7 @@ pub fn initialize_build(
let compiler_check = verify_compiler_info(&packages, &compiler);

if show_progress {
if snapshot_output {
if plain_output {
if let CompilerCheckResult::CleanedPackagesDueToCompiler = compiler_check {
// Snapshot-friendly output (no progress prefixes or emojis)
println!("Cleaned previous build due to compiler update");
Expand Down Expand Up @@ -181,7 +181,7 @@ pub fn initialize_build(

let timing_source_files = Instant::now();

if !snapshot_output && show_progress {
if !plain_output && show_progress {
print!(
"{} {}Finding source files...",
style("[2/7]").bold().dim(),
Expand All @@ -194,7 +194,7 @@ pub fn initialize_build(
packages::parse_packages(&mut build_state);
let timing_source_files_elapsed = timing_source_files.elapsed();

if !snapshot_output && show_progress {
if !plain_output && show_progress {
println!(
"{}{} {}Found source files in {:.2}s",
LINE_CLEAR,
Expand All @@ -216,7 +216,7 @@ pub fn initialize_build(
let compile_assets_state = read_compile_state::read(&mut build_state)?;
let timing_compile_state_elapsed = timing_compile_state.elapsed();

if !snapshot_output && show_progress {
if !plain_output && show_progress {
println!(
"{}{} {}Read compile state {:.2}s",
LINE_CLEAR,
Expand All @@ -238,7 +238,7 @@ pub fn initialize_build(
let timing_cleanup_elapsed = timing_cleanup.elapsed();

if show_progress {
if snapshot_output {
if plain_output {
println!("Cleaned {diff_cleanup}/{total_cleanup}")
} else {
println!(
Expand Down Expand Up @@ -268,29 +268,29 @@ pub enum IncrementalBuildErrorKind {

#[derive(Debug, Clone)]
pub struct IncrementalBuildError {
pub snapshot_output: bool,
pub plain_output: bool,
pub kind: IncrementalBuildErrorKind,
}

impl fmt::Display for IncrementalBuildError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self.kind {
IncrementalBuildErrorKind::SourceFileParseError => {
if self.snapshot_output {
if self.plain_output {
write!(f, "{LINE_CLEAR} Could not parse Source Files",)
} else {
write!(f, "{LINE_CLEAR} {CROSS}Could not parse Source Files",)
}
}
IncrementalBuildErrorKind::CompileError(Some(e)) => {
if self.snapshot_output {
if self.plain_output {
write!(f, "{LINE_CLEAR} Failed to Compile. Error: {e}",)
} else {
write!(f, "{LINE_CLEAR} {CROSS}Failed to Compile. Error: {e}",)
}
}
IncrementalBuildErrorKind::CompileError(None) => {
if self.snapshot_output {
if self.plain_output {
write!(f, "{LINE_CLEAR} Failed to Compile. See Errors Above",)
} else {
write!(f, "{LINE_CLEAR} {CROSS}Failed to Compile. See Errors Above",)
Expand All @@ -307,11 +307,11 @@ pub fn incremental_build(
show_progress: bool,
only_incremental: bool,
create_sourcedirs: bool,
snapshot_output: bool,
plain_output: bool,
) -> Result<(), IncrementalBuildError> {
logs::initialize(&build_state.packages);
let num_dirty_modules = build_state.modules.values().filter(|m| is_dirty(m)).count() as u64;
let pb = if !snapshot_output && show_progress {
let pb = if !plain_output && show_progress {
ProgressBar::new(num_dirty_modules)
} else {
ProgressBar::hidden()
Expand All @@ -334,7 +334,7 @@ pub fn incremental_build(
match result_asts {
Ok(_ast) => {
if show_progress {
if snapshot_output {
if plain_output {
println!("Parsed {num_dirty_modules} source files")
} else {
println!(
Expand All @@ -352,7 +352,7 @@ pub fn incremental_build(
Err(err) => {
logs::finalize(&build_state.packages);

if !snapshot_output && show_progress {
if !plain_output && show_progress {
println!(
"{}{} {}Error parsing source files in {:.2}s",
LINE_CLEAR,
Expand All @@ -366,7 +366,7 @@ pub fn incremental_build(
println!("{}", &err);
return Err(IncrementalBuildError {
kind: IncrementalBuildErrorKind::SourceFileParseError,
snapshot_output,
plain_output,
});
}
}
Expand All @@ -376,7 +376,7 @@ pub fn incremental_build(
let timing_deps_elapsed = timing_deps.elapsed();
current_step += 1;

if !snapshot_output && show_progress {
if !plain_output && show_progress {
println!(
"{}{} {}Collected deps in {:.2}s",
LINE_CLEAR,
Expand All @@ -400,7 +400,7 @@ pub fn incremental_build(
};

let start_compiling = Instant::now();
let pb = if !snapshot_output && show_progress {
let pb = if !plain_output && show_progress {
ProgressBar::new(build_state.modules.len().try_into().unwrap())
} else {
ProgressBar::hidden()
Expand All @@ -422,7 +422,7 @@ pub fn incremental_build(
)
.map_err(|e| IncrementalBuildError {
kind: IncrementalBuildErrorKind::CompileError(Some(e.to_string())),
snapshot_output,
plain_output,
})?;

let compile_duration = start_compiling.elapsed();
Expand All @@ -434,7 +434,7 @@ pub fn incremental_build(
pb.finish();
if !compile_errors.is_empty() {
if show_progress {
if snapshot_output {
if plain_output {
println!("Compiled {num_compiled_modules} modules")
} else {
println!(
Expand All @@ -458,11 +458,11 @@ pub fn incremental_build(
}
Err(IncrementalBuildError {
kind: IncrementalBuildErrorKind::CompileError(None),
snapshot_output,
plain_output,
})
} else {
if show_progress {
if snapshot_output {
if plain_output {
println!("Compiled {num_compiled_modules} modules")
} else {
println!(
Expand Down Expand Up @@ -539,7 +539,7 @@ pub fn build(
show_progress: bool,
no_timing: bool,
create_sourcedirs: bool,
snapshot_output: bool,
plain_output: bool,
warn_error: Option<String>,
) -> Result<BuildCommandState> {
let default_timing: Option<std::time::Duration> = if no_timing {
Expand All @@ -553,7 +553,7 @@ pub fn build(
filter,
show_progress,
path,
snapshot_output,
plain_output,
warn_error,
)
.map_err(|e| anyhow!("Could not initialize build. Error: {e}"))?;
Expand All @@ -565,10 +565,10 @@ pub fn build(
show_progress,
false,
create_sourcedirs,
snapshot_output,
plain_output,
) {
Ok(_) => {
if !snapshot_output && show_progress {
if !plain_output && show_progress {
let timing_total_elapsed = timing_total.elapsed();
println!(
"\n{}{}Finished Compilation in {:.2}s",
Expand Down
18 changes: 9 additions & 9 deletions rewatch/src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,13 @@ pub fn cleanup_after_build(build_state: &BuildCommandState) {
});
}

pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool) -> Result<()> {
pub fn clean(path: &Path, show_progress: bool, plain_output: bool) -> Result<()> {
let project_context = ProjectContext::new(path)?;
let compiler_info = build::get_compiler_info(&project_context)?;
let packages = packages::make(&None, &project_context, show_progress)?;

let timing_clean_compiler_assets = Instant::now();
if !snapshot_output && show_progress {
if !plain_output && show_progress {
print!(
"{} {}Cleaning compiler assets...",
style("[1/2]").bold().dim(),
Expand All @@ -347,12 +347,12 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool) -> Result<
};

for (_, package) in &packages {
clean_package(show_progress, snapshot_output, package)
clean_package(show_progress, plain_output, package)
}

let timing_clean_compiler_assets_elapsed = timing_clean_compiler_assets.elapsed();

if !snapshot_output && show_progress {
if !plain_output && show_progress {
println!(
"{}{} {}Cleaned compiler assets in {:.2}s",
LINE_CLEAR,
Expand All @@ -367,7 +367,7 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool) -> Result<
let mut build_state = BuildState::new(project_context, packages, compiler_info);
packages::parse_packages(&mut build_state);
let root_config = build_state.get_root_config();
let suffix_for_print = if snapshot_output || !show_progress {
let suffix_for_print = if plain_output || !show_progress {
String::new()
} else {
match root_config.package_specs {
Expand All @@ -390,7 +390,7 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool) -> Result<
}
};

if !snapshot_output && show_progress {
if !plain_output && show_progress {
println!(
"{} {}Cleaning {} files...",
style("[2/2]").bold().dim(),
Expand All @@ -403,7 +403,7 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool) -> Result<
clean_source_files(&build_state, root_config);
let timing_clean_mjs_elapsed = timing_clean_mjs.elapsed();

if !snapshot_output && show_progress {
if !plain_output && show_progress {
println!(
"{}{} {}Cleaned {} files in {:.2}s",
LINE_CLEAR,
Expand All @@ -418,9 +418,9 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool) -> Result<
Ok(())
}

pub fn clean_package(show_progress: bool, snapshot_output: bool, package: &Package) {
pub fn clean_package(show_progress: bool, plain_output: bool, package: &Package) {
if show_progress {
if snapshot_output {
if plain_output {
println!("Cleaning {}", package.name)
} else {
print!(
Expand Down
25 changes: 0 additions & 25 deletions rewatch/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,6 @@ pub struct DevArg {
pub dev: bool,
}

#[derive(Args, Debug, Clone, Copy)]
pub struct SnapshotOutputArg {
/// simple output for snapshot testing
#[arg(short, long, default_value = "false", num_args = 0..=1)]
pub snapshot_output: bool,
}

#[derive(Args, Debug, Clone)]
pub struct BuildArgs {
#[command(flatten)]
Expand All @@ -247,9 +240,6 @@ pub struct BuildArgs {
#[arg(short, long, default_value_t = false, num_args = 0..=1)]
pub no_timing: bool,

#[command(flatten)]
pub snapshot_output: SnapshotOutputArg,

/// Watch mode (deprecated, use `rescript watch` instead)
#[arg(short, default_value_t = false, num_args = 0..=1)]
pub watch: bool,
Expand Down Expand Up @@ -418,9 +408,6 @@ pub struct WatchArgs {
#[command(flatten)]
pub dev: DevArg,

#[command(flatten)]
pub snapshot_output: SnapshotOutputArg,

/// Warning numbers and whether to turn them into errors
///
/// This flag overrides any warning configuration in rescript.json.
Expand All @@ -438,7 +425,6 @@ impl From<BuildArgs> for WatchArgs {
after_build: build_args.after_build,
create_sourcedirs: build_args.create_sourcedirs,
dev: build_args.dev,
snapshot_output: build_args.snapshot_output,
warn_error: build_args.warn_error,
}
}
Expand All @@ -455,9 +441,6 @@ pub enum Command {
#[command(flatten)]
folder: FolderArg,

#[command(flatten)]
snapshot_output: SnapshotOutputArg,

#[command(flatten)]
dev: DevArg,
},
Expand Down Expand Up @@ -531,11 +514,3 @@ impl Deref for DevArg {
&self.dev
}
}

impl Deref for SnapshotOutputArg {
type Target = bool;

fn deref(&self) -> &Self::Target {
&self.snapshot_output
}
}
Loading
Loading