From 0e433fce203f01c3f2cf4d25c015b50ab46bb902 Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 15 Jul 2025 17:43:55 +0200 Subject: [PATCH 01/25] Read bs-dev-dependencies if --dev was passed. --- rewatch/src/build/packages.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/rewatch/src/build/packages.rs b/rewatch/src/build/packages.rs index 3ab8e1e308..9dbe8c61d5 100644 --- a/rewatch/src/build/packages.rs +++ b/rewatch/src/build/packages.rs @@ -297,11 +297,16 @@ fn read_dependencies( project_root: &Path, workspace_root: &Option, show_progress: bool, + build_dev_deps: bool, ) -> Vec { - return parent_config - .bs_dependencies - .to_owned() - .unwrap_or_default() + let mut dependencies = parent_config.bs_dependencies.to_owned().unwrap_or_default(); + + // Concatenate dev dependencies if build_dev_deps is true + if build_dev_deps && let Some(dev_deps) = parent_config.bs_dev_dependencies.to_owned() { + dependencies.extend(dev_deps); + } + + dependencies .iter() .filter_map(|package_name| { if registered_dependencies_set.contains(package_name) { @@ -360,7 +365,8 @@ fn read_dependencies( &canonical_path, project_root, workspace_root, - show_progress + show_progress, + build_dev_deps ); Dependency { @@ -371,7 +377,7 @@ fn read_dependencies( dependencies, } }) - .collect::>(); + .collect() } fn flatten_dependencies(dependencies: Vec) -> Vec { @@ -461,6 +467,7 @@ fn read_packages( project_root: &Path, workspace_root: &Option, show_progress: bool, + build_dev_deps: bool, ) -> Result> { let root_config = read_config(project_root)?; @@ -477,6 +484,7 @@ fn read_packages( project_root, workspace_root, show_progress, + build_dev_deps, )); dependencies.iter().for_each(|d| { if !map.contains_key(&d.name) { @@ -596,7 +604,7 @@ pub fn make( show_progress: bool, build_dev_deps: bool, ) -> Result> { - let map = read_packages(root_folder, workspace_root, show_progress)?; + let map = read_packages(root_folder, workspace_root, show_progress, build_dev_deps)?; /* Once we have the deduplicated packages, we can add the source files for each - to minimize * the IO */ From 0c36cb5937dbb6cd78f26435b9b78ba629f0e775 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 16 Jul 2025 09:06:44 +0200 Subject: [PATCH 02/25] Try and check the file type when allowing dev dependency access. --- rewatch/src/build/compile.rs | 40 +++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/rewatch/src/build/compile.rs b/rewatch/src/build/compile.rs index 6f8f8e9327..5f6a4aae9e 100644 --- a/rewatch/src/build/compile.rs +++ b/rewatch/src/build/compile.rs @@ -365,8 +365,14 @@ pub fn compiler_args( ) -> Vec { let bsc_flags = config::flatten_flags(&config.bsc_flags); - let dependency_paths = - get_dependency_paths(config, project_root, workspace_root, packages, build_dev_deps); + let dependency_paths = get_dependency_paths( + config, + project_root, + workspace_root, + packages, + build_dev_deps, + file_path, + ); let module_name = helpers::file_path_to_module_name(file_path, &config.get_namespace()); @@ -499,12 +505,37 @@ impl DependentPackage { } } +fn is_file_type_dev(config: &config::Config, file_path: &Path) -> bool { + let Some(sources) = &config.sources else { + return false; + }; + match sources { + config::OneOrMore::Multiple(multiple) => { + for source in multiple.iter() { + match source { + config::Source::Qualified(config::PackageSource { + dir: dir, + subdirs: _, + type_: Some(type_), + }) if *type_ == String::from("dev") => { + return Path::new(dir) == file_path.parent().unwrap(); + } + _ => {} + } + } + false + } + _ => todo!(), + } +} + fn get_dependency_paths( config: &config::Config, project_root: &Path, workspace_root: &Option, packages: &Option<&AHashMap>, build_dev_deps: bool, + file_path: &Path, ) -> Vec> { let normal_deps = config .bs_dependencies @@ -513,7 +544,10 @@ fn get_dependency_paths( .into_iter() .map(DependentPackage::Normal) .collect(); - let dev_deps = if build_dev_deps { + // We need to check if the current file is listed as type: "dev" + // Only then it has access of using the bs-dev-dependencies + let is_file_type_dev = is_file_type_dev(config, file_path); + let dev_deps = if build_dev_deps && is_file_type_dev { config .bs_dev_dependencies .clone() From 1f7d4d27f355ff55708ff3b1d7b5d231809a0511 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 16 Jul 2025 15:51:49 +0200 Subject: [PATCH 03/25] Store is_type_dev in SourceFileMeta. --- rewatch/src/build/packages.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/rewatch/src/build/packages.rs b/rewatch/src/build/packages.rs index 9dbe8c61d5..dbd5196690 100644 --- a/rewatch/src/build/packages.rs +++ b/rewatch/src/build/packages.rs @@ -19,6 +19,7 @@ use std::time::SystemTime; #[derive(Debug, Clone)] pub struct SourceFileMeta { pub modified: SystemTime, + pub is_type_dev: bool, } #[derive(Debug, Clone)] @@ -138,6 +139,7 @@ pub fn read_folders( package_dir: &Path, path: &Path, recurse: bool, + is_type_dev: bool, ) -> Result, Box> { let mut map: AHashMap = AHashMap::new(); let path_buf = PathBuf::from(path); @@ -147,6 +149,7 @@ pub fn read_folders( path.to_owned(), SourceFileMeta { modified: meta.modified().unwrap(), + is_type_dev, }, ) }); @@ -159,7 +162,7 @@ pub fn read_folders( let path_ext = entry_path_buf.extension().and_then(|x| x.to_str()); let new_path = path_buf.join(&name); if metadata.file_type().is_dir() && recurse { - match read_folders(filter, package_dir, &new_path, recurse) { + match read_folders(filter, package_dir, &new_path, recurse, is_type_dev) { Ok(s) => map.extend(s), Err(e) => log::error!("Could not read directory: {}", e), } @@ -174,6 +177,7 @@ pub fn read_folders( path, SourceFileMeta { modified: metadata.modified().unwrap(), + is_type_dev, }, ); } @@ -405,7 +409,12 @@ pub fn read_package_name(package_dir: &Path) -> Result { .ok_or_else(|| anyhow!("No name field found in package.json")) } -fn make_package(config: config::Config, package_path: &Path, is_pinned_dep: bool, is_root: bool) -> Package { +pub fn make_package( + config: config::Config, + package_path: &Path, + is_pinned_dep: bool, + is_root: bool, +) -> Package { let source_folders = match config.sources.to_owned() { Some(config::OneOrMore::Single(source)) => get_source_dirs(source, None), Some(config::OneOrMore::Multiple(sources)) => { @@ -523,9 +532,14 @@ pub fn get_source_files( }; let path_dir = Path::new(&source.dir); + let is_type_dev = type_ + .as_ref() + .map(|t| t.as_str() == "dev") + .unwrap_or(false) + .clone(); match (build_dev_deps, type_) { (false, Some(type_)) if type_ == "dev" => (), - _ => match read_folders(filter, package_dir, path_dir, recurse) { + _ => match read_folders(filter, package_dir, path_dir, recurse, is_type_dev) { Ok(files) => map.extend(files), Err(_e) => log::error!( @@ -542,7 +556,7 @@ pub fn get_source_files( /// This takes the tree of packages, and finds all the source files for each, adding them to the /// respective packages. -fn extend_with_children( +pub fn extend_with_children( filter: &Option, mut build: AHashMap, build_dev_deps: bool, From db9b5d0f40ba3b9f7fb05d18123d68f11103c05c Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 16 Jul 2025 18:09:46 +0200 Subject: [PATCH 04/25] Only allow usage of dev_dependencies when type:dev is true for source file --- rewatch/src/build.rs | 32 +++++++++++++++------ rewatch/src/build/compile.rs | 53 ++++++----------------------------- rewatch/src/build/packages.rs | 7 +++++ rewatch/src/cli.rs | 3 -- rewatch/src/main.rs | 4 +-- rewatch/src/watcher.rs | 2 -- 6 files changed, 42 insertions(+), 59 deletions(-) diff --git a/rewatch/src/build.rs b/rewatch/src/build.rs index 4545e3f0f3..9b7cd87bb5 100644 --- a/rewatch/src/build.rs +++ b/rewatch/src/build.rs @@ -8,10 +8,14 @@ pub mod packages; pub mod parse; pub mod read_compile_state; +use self::compile::compiler_args; +use self::parse::parser_args; use crate::build::compile::{mark_modules_with_deleted_deps_dirty, mark_modules_with_expired_deps_dirty}; +use crate::build::packages::Package; use crate::helpers::emojis::*; use crate::helpers::{self, get_workspace_root}; use crate::sourcedirs; +use ahash::AHashMap; use anyhow::{Result, anyhow}; use build_types::*; use console::style; @@ -26,9 +30,6 @@ use std::path::{Path, PathBuf}; use std::process::Stdio; use std::time::{Duration, Instant}; -use self::compile::compiler_args; -use self::parse::parser_args; - fn is_dirty(module: &Module) -> bool { match module.source_type { SourceType::SourceFile(SourceFile { @@ -56,7 +57,7 @@ pub struct CompilerArgs { pub parser_args: Vec, } -pub fn get_compiler_args(path: &Path, build_dev_deps: bool) -> Result { +pub fn get_compiler_args(path: &Path) -> Result { let filename = &helpers::get_abs_path(path); let package_root = helpers::get_abs_path(&helpers::get_nearest_config(&path).expect("Couldn't find package root")); @@ -65,6 +66,24 @@ pub fn get_compiler_args(path: &Path, build_dev_deps: bool) -> Result { packages::read_config(&workspace_root.to_owned().unwrap_or(package_root.to_owned()))?; let rescript_config = packages::read_config(&package_root)?; + // We need to figure out if the source file is listed as "type":"dev" + // To do this, we can construct the Package information for the nearest config. + let package = packages::make_package(root_rescript_config.clone(), &package_root, false, true); + let mut packages_map: AHashMap = AHashMap::new(); + let package_name = root_rescript_config.name.clone(); + packages_map.insert(package_name.clone(), package); + // We need to populate the source_files meta data. + // TODO: filter with current file + let packages_map = packages::extend_with_children( + &None, + packages_map, + /* we assume build_dev_deps so all source_files metadata will be populated */ true, + ); + let is_type_dev = packages_map + .get(&package_name) + .map(|p| p.is_source_file_type_dev(filename)) + .unwrap_or(false); + // make PathBuf from package root and get the relative path for filename let relative_filename = filename.strip_prefix(PathBuf::from(&package_root)).unwrap(); @@ -97,7 +116,7 @@ pub fn get_compiler_args(path: &Path, build_dev_deps: bool) -> Result { &package_root, &workspace_root, &None, - build_dev_deps, + is_type_dev, true, ); @@ -281,7 +300,6 @@ pub fn incremental_build( show_progress: bool, only_incremental: bool, create_sourcedirs: bool, - build_dev_deps: bool, snapshot_output: bool, ) -> Result<(), IncrementalBuildError> { logs::initialize(&build_state.packages); @@ -393,7 +411,6 @@ pub fn incremental_build( show_progress, || pb.inc(1), |size| pb.set_length(size), - build_dev_deps, ) .map_err(|e| IncrementalBuildError { kind: IncrementalBuildErrorKind::CompileError(Some(e.to_string())), @@ -500,7 +517,6 @@ pub fn build( show_progress, false, create_sourcedirs, - build_dev_deps, snapshot_output, ) { Ok(_) => { diff --git a/rewatch/src/build/compile.rs b/rewatch/src/build/compile.rs index 5f6a4aae9e..b617c2b82d 100644 --- a/rewatch/src/build/compile.rs +++ b/rewatch/src/build/compile.rs @@ -22,7 +22,6 @@ pub fn compile( show_progress: bool, inc: impl Fn() + std::marker::Sync, set_length: impl Fn(u64), - build_dev_deps: bool, ) -> anyhow::Result<(String, String, usize)> { let mut compiled_modules = AHashSet::::new(); let dirty_modules = build_state @@ -170,7 +169,6 @@ pub fn compile( &build_state.packages, &build_state.project_root, &build_state.workspace_root, - build_dev_deps, ); Some(result) } @@ -186,7 +184,6 @@ pub fn compile( &build_state.packages, &build_state.project_root, &build_state.workspace_root, - build_dev_deps, ); let cmi_digest_after = helpers::compute_file_hash(Path::new(&cmi_path)); @@ -360,19 +357,13 @@ pub fn compiler_args( // if packages are known, we pass a reference here // this saves us a scan to find their paths packages: &Option<&AHashMap>, - build_dev_deps: bool, + // Is the file listed as "type":"dev"? + is_type_dev: bool, is_local_dep: bool, ) -> Vec { let bsc_flags = config::flatten_flags(&config.bsc_flags); - let dependency_paths = get_dependency_paths( - config, - project_root, - workspace_root, - packages, - build_dev_deps, - file_path, - ); + let dependency_paths = get_dependency_paths(config, project_root, workspace_root, packages, is_type_dev); let module_name = helpers::file_path_to_module_name(file_path, &config.get_namespace()); @@ -505,37 +496,12 @@ impl DependentPackage { } } -fn is_file_type_dev(config: &config::Config, file_path: &Path) -> bool { - let Some(sources) = &config.sources else { - return false; - }; - match sources { - config::OneOrMore::Multiple(multiple) => { - for source in multiple.iter() { - match source { - config::Source::Qualified(config::PackageSource { - dir: dir, - subdirs: _, - type_: Some(type_), - }) if *type_ == String::from("dev") => { - return Path::new(dir) == file_path.parent().unwrap(); - } - _ => {} - } - } - false - } - _ => todo!(), - } -} - fn get_dependency_paths( config: &config::Config, project_root: &Path, workspace_root: &Option, packages: &Option<&AHashMap>, - build_dev_deps: bool, - file_path: &Path, + is_file_type_dev: bool, ) -> Vec> { let normal_deps = config .bs_dependencies @@ -544,10 +510,9 @@ fn get_dependency_paths( .into_iter() .map(DependentPackage::Normal) .collect(); - // We need to check if the current file is listed as type: "dev" - // Only then it has access of using the bs-dev-dependencies - let is_file_type_dev = is_file_type_dev(config, file_path); - let dev_deps = if build_dev_deps && is_file_type_dev { + + // We can only access dev dependencies for source_files that are marked as "type":"dev" + let dev_deps = if is_file_type_dev { config .bs_dev_dependencies .clone() @@ -603,7 +568,6 @@ fn compile_file( packages: &AHashMap, project_root: &Path, workspace_root: &Option, - build_dev_deps: bool, ) -> Result, String> { let ocaml_build_path_abs = package.get_ocaml_build_path(); let build_path_abs = package.get_build_path(); @@ -617,6 +581,7 @@ fn compile_file( }?; let module_name = helpers::file_path_to_module_name(implementation_file_path, &package.namespace); let has_interface = module.get_interface().is_some(); + let is_type_dev = package.is_source_file_type_dev(implementation_file_path); let to_mjs_args = compiler_args( &package.config, &root_package.config, @@ -627,7 +592,7 @@ fn compile_file( project_root, workspace_root, &Some(packages), - build_dev_deps, + is_type_dev, package.is_local_dep, ); diff --git a/rewatch/src/build/packages.rs b/rewatch/src/build/packages.rs index dbd5196690..1ca8b367a7 100644 --- a/rewatch/src/build/packages.rs +++ b/rewatch/src/build/packages.rs @@ -113,6 +113,13 @@ impl Package { .expect("namespace should be set for mlmap module"); self.get_build_path().join(format!("{}.cmi", suffix)) } + + pub fn is_source_file_type_dev(&self, path: &Path) -> bool { + self.source_files + .as_ref() + .and_then(|sf| sf.get(path).map(|sfm| sfm.is_type_dev)) + .unwrap_or(false) + } } impl PartialEq for Package { diff --git a/rewatch/src/cli.rs b/rewatch/src/cli.rs index f74c676714..870eeb1630 100644 --- a/rewatch/src/cli.rs +++ b/rewatch/src/cli.rs @@ -186,9 +186,6 @@ pub enum Command { /// Path to a rescript file (.res or .resi) #[command()] path: String, - - #[command(flatten)] - dev: DevArg, }, /// Use the legacy build system. /// diff --git a/rewatch/src/main.rs b/rewatch/src/main.rs index 827ab7be5f..c5e46e5c70 100644 --- a/rewatch/src/main.rs +++ b/rewatch/src/main.rs @@ -30,8 +30,8 @@ fn main() -> Result<()> { let show_progress = log_level_filter == LevelFilter::Info; match command { - cli::Command::CompilerArgs { path, dev } => { - println!("{}", build::get_compiler_args(Path::new(&path), *dev)?); + cli::Command::CompilerArgs { path } => { + println!("{}", build::get_compiler_args(Path::new(&path))?); std::process::exit(0); } cli::Command::Build(build_args) => { diff --git a/rewatch/src/watcher.rs b/rewatch/src/watcher.rs index f9fb7f6398..2843a9d110 100644 --- a/rewatch/src/watcher.rs +++ b/rewatch/src/watcher.rs @@ -217,7 +217,6 @@ async fn async_watch( show_progress, !initial_build, create_sourcedirs, - build_dev_deps, snapshot_output, ) .is_ok() @@ -262,7 +261,6 @@ async fn async_watch( show_progress, false, create_sourcedirs, - build_dev_deps, snapshot_output, ); if let Some(a) = after_build.clone() { From 8b5f03f47af7919d6d4acd27184bdc7fe891e707 Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 17 Jul 2025 09:16:01 +0200 Subject: [PATCH 05/25] Traverse rescript config for compiler-args command to find out if type = dev --- rewatch/src/build.rs | 24 ++++-------------------- rewatch/src/config.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/rewatch/src/build.rs b/rewatch/src/build.rs index 9b7cd87bb5..d215e18b61 100644 --- a/rewatch/src/build.rs +++ b/rewatch/src/build.rs @@ -11,11 +11,9 @@ pub mod read_compile_state; use self::compile::compiler_args; use self::parse::parser_args; use crate::build::compile::{mark_modules_with_deleted_deps_dirty, mark_modules_with_expired_deps_dirty}; -use crate::build::packages::Package; use crate::helpers::emojis::*; use crate::helpers::{self, get_workspace_root}; use crate::sourcedirs; -use ahash::AHashMap; use anyhow::{Result, anyhow}; use build_types::*; use console::style; @@ -65,24 +63,10 @@ pub fn get_compiler_args(path: &Path) -> Result { let root_rescript_config = packages::read_config(&workspace_root.to_owned().unwrap_or(package_root.to_owned()))?; let rescript_config = packages::read_config(&package_root)?; - - // We need to figure out if the source file is listed as "type":"dev" - // To do this, we can construct the Package information for the nearest config. - let package = packages::make_package(root_rescript_config.clone(), &package_root, false, true); - let mut packages_map: AHashMap = AHashMap::new(); - let package_name = root_rescript_config.name.clone(); - packages_map.insert(package_name.clone(), package); - // We need to populate the source_files meta data. - // TODO: filter with current file - let packages_map = packages::extend_with_children( - &None, - packages_map, - /* we assume build_dev_deps so all source_files metadata will be populated */ true, - ); - let is_type_dev = packages_map - .get(&package_name) - .map(|p| p.is_source_file_type_dev(filename)) - .unwrap_or(false); + let is_type_dev = match filename.strip_prefix(&package_root) { + Err(_) => false, + Ok(relative_path) => root_rescript_config.find_is_type_dev_for_path(relative_path), + }; // make PathBuf from package root and get the relative path for filename let relative_filename = filename.strip_prefix(PathBuf::from(&package_root)).unwrap(); diff --git a/rewatch/src/config.rs b/rewatch/src/config.rs index 708d17154b..cb0e0f0be0 100644 --- a/rewatch/src/config.rs +++ b/rewatch/src/config.rs @@ -29,6 +29,15 @@ pub struct PackageSource { pub type_: Option, } +impl PackageSource { + fn is_type_dev(&self) -> bool { + match &self.type_ { + Some(type_) => type_ == "dev", + None => false, + } + } +} + impl Eq for PackageSource {} #[derive(Deserialize, Debug, Clone, PartialEq, Hash)] @@ -470,6 +479,25 @@ impl Config { .or(self.suffix.clone()) .unwrap_or(".js".to_string()) } + + // TODO: needs improving! + + pub fn find_is_type_dev_for_path(&self, relative_path: &Path) -> bool { + if let Some(relative_parent) = relative_path.parent().map(|p| Path::new(p)) { + if let Some(sources) = &self.sources { + match sources { + OneOrMore::Single(Source::Qualified(package_source)) => { + Path::new(&package_source.dir) == relative_parent && package_source.is_type_dev() + } + _ => false, + } + } else { + false + } + } else { + false + } + } } #[cfg(test)] From c4be983db5051e4d6b8d44895fcf9e6f0a90eaa5 Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 17 Jul 2025 09:29:29 +0200 Subject: [PATCH 06/25] Collect all qualified package sources --- rewatch/src/config.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/rewatch/src/config.rs b/rewatch/src/config.rs index cb0e0f0be0..fe746e29a3 100644 --- a/rewatch/src/config.rs +++ b/rewatch/src/config.rs @@ -483,20 +483,27 @@ impl Config { // TODO: needs improving! pub fn find_is_type_dev_for_path(&self, relative_path: &Path) -> bool { - if let Some(relative_parent) = relative_path.parent().map(|p| Path::new(p)) { - if let Some(sources) = &self.sources { - match sources { - OneOrMore::Single(Source::Qualified(package_source)) => { - Path::new(&package_source.dir) == relative_parent && package_source.is_type_dev() - } - _ => false, - } - } else { - false - } - } else { - false - } + let relative_parent = match relative_path.parent() { + None => return false, + Some(parent) => Path::new(parent), + }; + + let package_sources = match self.sources.as_ref() { + None => vec![], + Some(OneOrMore::Single(Source::Shorthand(_))) => vec![], + Some(OneOrMore::Single(Source::Qualified(source))) => vec![source], + Some(OneOrMore::Multiple(multiple)) => multiple + .iter() + .filter_map(|source| match source { + Source::Shorthand(_) => None, + Source::Qualified(package_source) => Some(package_source), + }) + .collect(), + }; + + package_sources.iter().any(|package_source| { + Path::new(&package_source.dir) == relative_parent && package_source.is_type_dev() + }) } } From d3d023d10bc8e59af67bc8345192179db9abc489 Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 17 Jul 2025 11:18:47 +0200 Subject: [PATCH 07/25] Expand search for type:dev in rescript config. --- rewatch/src/config.rs | 47 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/rewatch/src/config.rs b/rewatch/src/config.rs index fe746e29a3..881a497061 100644 --- a/rewatch/src/config.rs +++ b/rewatch/src/config.rs @@ -108,6 +108,35 @@ impl Source { }, } } + + fn find_is_type_dev_for_sub_folder( + &self, + relative_parent_path: &Path, + relative_source_file: &Path, + ) -> bool { + match &self { + Source::Shorthand(sub_folder) => { + relative_parent_path.join(Path::new(sub_folder)) == *relative_source_file + } + Source::Qualified(package_source) => { + // Note that we no longer check if type_ is dev of the nested subfolder. + // A parent was type:dev, so we assume all subfolders are as well. + let next_parent_path = relative_parent_path.join(Path::new(&package_source.dir)); + if next_parent_path == *relative_source_file { + return true; + }; + + match &package_source.subdirs { + None => false, + Some(Subdirs::Recurse(false)) => false, + Some(Subdirs::Recurse(true)) => relative_source_file.starts_with(&next_parent_path), + Some(Subdirs::Qualified(nested_sources)) => nested_sources.iter().any(|nested_source| { + nested_source.find_is_type_dev_for_sub_folder(&next_parent_path, relative_source_file) + }), + } + } + } + } } impl Eq for Source {} @@ -502,7 +531,23 @@ impl Config { }; package_sources.iter().any(|package_source| { - Path::new(&package_source.dir) == relative_parent && package_source.is_type_dev() + if !package_source.is_type_dev() { + false + } else { + let dir_path = Path::new(&package_source.dir); + if dir_path == relative_parent { + return true; + }; + + match &package_source.subdirs { + None => false, + Some(Subdirs::Recurse(false)) => false, + Some(Subdirs::Recurse(true)) => relative_path.starts_with(dir_path), + Some(Subdirs::Qualified(sub_dirs)) => sub_dirs.iter().any(|sub_dir| { + sub_dir.find_is_type_dev_for_sub_folder(Path::new(relative_path), relative_parent) + }), + } + } }) } } From aedcb1e255d00ba8badc4a7e084ca6eb8baac501 Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 17 Jul 2025 12:01:57 +0200 Subject: [PATCH 08/25] Add some unit test to cover find_is_type_dev_for_path --- rewatch/src/config.rs | 119 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 110 insertions(+), 9 deletions(-) diff --git a/rewatch/src/config.rs b/rewatch/src/config.rs index 881a497061..24273aa833 100644 --- a/rewatch/src/config.rs +++ b/rewatch/src/config.rs @@ -112,26 +112,26 @@ impl Source { fn find_is_type_dev_for_sub_folder( &self, relative_parent_path: &Path, - relative_source_file: &Path, + target_source_folder: &Path, ) -> bool { match &self { Source::Shorthand(sub_folder) => { - relative_parent_path.join(Path::new(sub_folder)) == *relative_source_file + relative_parent_path.join(Path::new(sub_folder)) == *target_source_folder } Source::Qualified(package_source) => { // Note that we no longer check if type_ is dev of the nested subfolder. // A parent was type:dev, so we assume all subfolders are as well. let next_parent_path = relative_parent_path.join(Path::new(&package_source.dir)); - if next_parent_path == *relative_source_file { + if next_parent_path == *target_source_folder { return true; }; match &package_source.subdirs { None => false, Some(Subdirs::Recurse(false)) => false, - Some(Subdirs::Recurse(true)) => relative_source_file.starts_with(&next_parent_path), + Some(Subdirs::Recurse(true)) => target_source_folder.starts_with(&next_parent_path), Some(Subdirs::Qualified(nested_sources)) => nested_sources.iter().any(|nested_source| { - nested_source.find_is_type_dev_for_sub_folder(&next_parent_path, relative_source_file) + nested_source.find_is_type_dev_for_sub_folder(&next_parent_path, target_source_folder) }), } } @@ -220,7 +220,7 @@ pub type GenTypeConfig = serde_json::Value; /// # bsconfig.json representation /// This is tricky, there is a lot of ambiguity. This is probably incomplete. -#[derive(Deserialize, Debug, Clone)] +#[derive(Deserialize, Debug, Clone, Default)] pub struct Config { pub name: String, // In the case of monorepos, the root source won't necessarily have to have sources. It can @@ -543,9 +543,9 @@ impl Config { None => false, Some(Subdirs::Recurse(false)) => false, Some(Subdirs::Recurse(true)) => relative_path.starts_with(dir_path), - Some(Subdirs::Qualified(sub_dirs)) => sub_dirs.iter().any(|sub_dir| { - sub_dir.find_is_type_dev_for_sub_folder(Path::new(relative_path), relative_parent) - }), + Some(Subdirs::Qualified(sub_dirs)) => sub_dirs + .iter() + .any(|sub_dir| sub_dir.find_is_type_dev_for_sub_folder(dir_path, relative_parent)), } } }) @@ -851,4 +851,105 @@ mod tests { Some(vec!["@testrepo/main".to_string()]) ); } + + fn test_find_is_type_dev(source: OneOrMore, path: &Path, expected: bool) { + let config = Config { + name: String::from("testrepo"), + sources: Some(source), + ..Default::default() + }; + let result = config.find_is_type_dev_for_path(path); + assert_eq!(result, expected); + } + + #[test] + fn test_find_is_type_dev_for_exact_match() { + test_find_is_type_dev( + OneOrMore::Single(Source::Qualified(PackageSource { + dir: String::from("src"), + subdirs: None, + type_: Some(String::from("dev")), + })), + Path::new("src/Foo.res"), + true, + ) + } + + #[test] + fn test_find_is_type_dev_for_none_dev() { + test_find_is_type_dev( + OneOrMore::Single(Source::Qualified(PackageSource { + dir: String::from("src"), + subdirs: None, + type_: None, + })), + Path::new("src/Foo.res"), + false, + ) + } + + #[test] + fn test_find_is_type_dev_for_multiple_sources() { + test_find_is_type_dev( + OneOrMore::Multiple(vec![Source::Qualified(PackageSource { + dir: String::from("src"), + subdirs: None, + type_: Some(String::from("dev")), + })]), + Path::new("src/Foo.res"), + true, + ) + } + + #[test] + fn test_find_is_type_dev_for_shorthand() { + test_find_is_type_dev( + OneOrMore::Multiple(vec![Source::Shorthand(String::from("src"))]), + Path::new("src/Foo.res"), + false, + ) + } + + #[test] + fn test_find_is_type_dev_for_recursive_folder() { + test_find_is_type_dev( + OneOrMore::Multiple(vec![Source::Qualified(PackageSource { + dir: String::from("src"), + subdirs: Some(Subdirs::Recurse(true)), + type_: Some(String::from("dev")), + })]), + Path::new("src/bar/Foo.res"), + true, + ) + } + + #[test] + fn test_find_is_type_dev_for_sub_folder() { + test_find_is_type_dev( + OneOrMore::Multiple(vec![Source::Qualified(PackageSource { + dir: String::from("src"), + subdirs: Some(Subdirs::Qualified(vec![Source::Qualified(PackageSource { + dir: String::from("bar"), + subdirs: None, + type_: None, + })])), + type_: Some(String::from("dev")), + })]), + Path::new("src/bar/Foo.res"), + true, + ) + } + + #[test] + fn test_find_is_type_dev_for_sub_folder_shorthand() { + test_find_is_type_dev( + OneOrMore::Multiple(vec![Source::Qualified(PackageSource { + dir: String::from("src"), + subdirs: Some(Subdirs::Qualified(vec![Source::Shorthand(String::from("bar"))])), + type_: Some(String::from("dev")), + })]), + Path::new("src/bar/Foo.res"), + true, + ) + } } From 5bf5fc2847819fab5a55fa5d554fd6f18ac62fbb Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 17 Jul 2025 13:01:24 +0200 Subject: [PATCH 09/25] Add is_type_dev to Module as well. --- rewatch/src/build/build_types.rs | 1 + rewatch/src/build/compile.rs | 2 +- rewatch/src/build/packages.rs | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/rewatch/src/build/build_types.rs b/rewatch/src/build/build_types.rs index da1d976648..e8c1a28ee4 100644 --- a/rewatch/src/build/build_types.rs +++ b/rewatch/src/build/build_types.rs @@ -71,6 +71,7 @@ pub struct Module { pub last_compiled_cmi: Option, pub last_compiled_cmt: Option, pub deps_dirty: bool, + pub is_type_dev: bool, } impl Module { diff --git a/rewatch/src/build/compile.rs b/rewatch/src/build/compile.rs index b617c2b82d..494968f48d 100644 --- a/rewatch/src/build/compile.rs +++ b/rewatch/src/build/compile.rs @@ -581,7 +581,7 @@ fn compile_file( }?; let module_name = helpers::file_path_to_module_name(implementation_file_path, &package.namespace); let has_interface = module.get_interface().is_some(); - let is_type_dev = package.is_source_file_type_dev(implementation_file_path); + let is_type_dev = module.is_type_dev; let to_mjs_args = compiler_args( &package.config, &root_package.config, diff --git a/rewatch/src/build/packages.rs b/rewatch/src/build/packages.rs index 1ca8b367a7..bf18108390 100644 --- a/rewatch/src/build/packages.rs +++ b/rewatch/src/build/packages.rs @@ -749,6 +749,8 @@ pub fn parse_packages(build_state: &mut BuildState) { compile_dirty: false, last_compiled_cmt: None, last_compiled_cmi: None, + // Not sure if this is correct + is_type_dev: false, }, ); }); @@ -801,6 +803,7 @@ pub fn parse_packages(build_state: &mut BuildState) { compile_dirty: true, last_compiled_cmt: None, last_compiled_cmi: None, + is_type_dev: metadata.is_type_dev, }); } else { // remove last character of string: resi -> res, rei -> re, mli -> ml @@ -862,6 +865,7 @@ pub fn parse_packages(build_state: &mut BuildState) { compile_dirty: true, last_compiled_cmt: None, last_compiled_cmi: None, + is_type_dev: metadata.is_type_dev, }); } } From fa1bed5e8704f81e8fd6f4aefd9c1ce13d063cb8 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 09:24:08 +0200 Subject: [PATCH 10/25] Remove pub --- rewatch/src/build/packages.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/rewatch/src/build/packages.rs b/rewatch/src/build/packages.rs index bf18108390..2b4f193766 100644 --- a/rewatch/src/build/packages.rs +++ b/rewatch/src/build/packages.rs @@ -416,12 +416,7 @@ pub fn read_package_name(package_dir: &Path) -> Result { .ok_or_else(|| anyhow!("No name field found in package.json")) } -pub fn make_package( - config: config::Config, - package_path: &Path, - is_pinned_dep: bool, - is_root: bool, -) -> Package { +fn make_package(config: config::Config, package_path: &Path, is_pinned_dep: bool, is_root: bool) -> Package { let source_folders = match config.sources.to_owned() { Some(config::OneOrMore::Single(source)) => get_source_dirs(source, None), Some(config::OneOrMore::Multiple(sources)) => { @@ -563,7 +558,7 @@ pub fn get_source_files( /// This takes the tree of packages, and finds all the source files for each, adding them to the /// respective packages. -pub fn extend_with_children( +fn extend_with_children( filter: &Option, mut build: AHashMap, build_dev_deps: bool, From 42fb9f6c0e84aea8b050d566723c066b3184471f Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 09:29:20 +0200 Subject: [PATCH 11/25] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfc49f2fe0..93cf0ecbd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ + + + # Changelog > **Tags:** @@ -36,6 +39,7 @@ - Fix `typeof` parens on functions. https://github.com/rescript-lang/rescript/pull/7643 - Rewatch: Add --dev flag to clean command. https://github.com/rescript-lang/rescript/pull/7622 - Rewatch: Use root package suffix in clean log messages. https://github.com/rescript-lang/rescript/pull/7648 +- Rewatch: Only allow access to `"bs-dev-dependencies"` from `"type": "dev"` source files. # 12.0.0-beta.1 From 5e9c69a384dc58a3612157dfa90ef2d91d4d0305 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 09:38:06 +0200 Subject: [PATCH 12/25] Add negative test --- .../packages/with-dev-deps/package.json | 5 +- .../packages/with-dev-deps/rescript.json | 3 + rewatch/testrepo/yarn.lock | 76 +++++++++++++++++++ rewatch/tests/compile.sh | 6 ++ 4 files changed, 89 insertions(+), 1 deletion(-) diff --git a/rewatch/testrepo/packages/with-dev-deps/package.json b/rewatch/testrepo/packages/with-dev-deps/package.json index 007ab59b9a..ba75a51072 100644 --- a/rewatch/testrepo/packages/with-dev-deps/package.json +++ b/rewatch/testrepo/packages/with-dev-deps/package.json @@ -5,5 +5,8 @@ "rescript" ], "author": "", - "license": "MIT" + "license": "MIT", + "devDependencies": { + "@rescript/webapi": "0.1.0-experimental-73e6a0d" + } } diff --git a/rewatch/testrepo/packages/with-dev-deps/rescript.json b/rewatch/testrepo/packages/with-dev-deps/rescript.json index 8cae5b6dcc..77d543741b 100644 --- a/rewatch/testrepo/packages/with-dev-deps/rescript.json +++ b/rewatch/testrepo/packages/with-dev-deps/rescript.json @@ -9,6 +9,9 @@ "type": "dev" } ], + "bs-dev-dependencies": [ + "@rescript/webapi" + ], "package-specs": { "module": "es6", "in-source": true diff --git a/rewatch/testrepo/yarn.lock b/rewatch/testrepo/yarn.lock index fa0f31c40a..b51c2075ba 100644 --- a/rewatch/testrepo/yarn.lock +++ b/rewatch/testrepo/yarn.lock @@ -12,6 +12,13 @@ __metadata: languageName: node linkType: hard +"@rescript/darwin-arm64@npm:12.0.0-beta.1": + version: 12.0.0-beta.1 + resolution: "@rescript/darwin-arm64@npm:12.0.0-beta.1" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + "@rescript/darwin-x64@npm:12.0.0-alpha.15": version: 12.0.0-alpha.15 resolution: "@rescript/darwin-x64@npm:12.0.0-alpha.15" @@ -19,6 +26,13 @@ __metadata: languageName: node linkType: hard +"@rescript/darwin-x64@npm:12.0.0-beta.1": + version: 12.0.0-beta.1 + resolution: "@rescript/darwin-x64@npm:12.0.0-beta.1" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + "@rescript/linux-arm64@npm:12.0.0-alpha.15": version: 12.0.0-alpha.15 resolution: "@rescript/linux-arm64@npm:12.0.0-alpha.15" @@ -26,6 +40,13 @@ __metadata: languageName: node linkType: hard +"@rescript/linux-arm64@npm:12.0.0-beta.1": + version: 12.0.0-beta.1 + resolution: "@rescript/linux-arm64@npm:12.0.0-beta.1" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + "@rescript/linux-x64@npm:12.0.0-alpha.15": version: 12.0.0-alpha.15 resolution: "@rescript/linux-x64@npm:12.0.0-alpha.15" @@ -33,6 +54,22 @@ __metadata: languageName: node linkType: hard +"@rescript/linux-x64@npm:12.0.0-beta.1": + version: 12.0.0-beta.1 + resolution: "@rescript/linux-x64@npm:12.0.0-beta.1" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + +"@rescript/webapi@npm:0.1.0-experimental-73e6a0d": + version: 0.1.0-experimental-73e6a0d + resolution: "@rescript/webapi@npm:0.1.0-experimental-73e6a0d" + dependencies: + rescript: "npm:^12.0.0-alpha.13" + checksum: 10c0/71553ebc51fec9c29ef5d1b4a4f6954cd9e29b622629005e29128504cc5a40d26e50308935b5d2e51c653b61674f096b731615c5c8399bd152517e32824554a8 + languageName: node + linkType: hard + "@rescript/win32-x64@npm:12.0.0-alpha.15": version: 12.0.0-alpha.15 resolution: "@rescript/win32-x64@npm:12.0.0-alpha.15" @@ -40,6 +77,13 @@ __metadata: languageName: node linkType: hard +"@rescript/win32-x64@npm:12.0.0-beta.1": + version: 12.0.0-beta.1 + resolution: "@rescript/win32-x64@npm:12.0.0-beta.1" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@testrepo/compiled-by-legacy@npm:*, @testrepo/compiled-by-legacy@workspace:packages/compiled-by-legacy": version: 0.0.0-use.local resolution: "@testrepo/compiled-by-legacy@workspace:packages/compiled-by-legacy" @@ -90,6 +134,8 @@ __metadata: "@testrepo/with-dev-deps@workspace:packages/with-dev-deps": version: 0.0.0-use.local resolution: "@testrepo/with-dev-deps@workspace:packages/with-dev-deps" + dependencies: + "@rescript/webapi": "npm:0.1.0-experimental-73e6a0d" languageName: unknown linkType: soft @@ -123,6 +169,36 @@ __metadata: languageName: node linkType: hard +"rescript@npm:^12.0.0-alpha.13": + version: 12.0.0-beta.1 + resolution: "rescript@npm:12.0.0-beta.1" + dependencies: + "@rescript/darwin-arm64": "npm:12.0.0-beta.1" + "@rescript/darwin-x64": "npm:12.0.0-beta.1" + "@rescript/linux-arm64": "npm:12.0.0-beta.1" + "@rescript/linux-x64": "npm:12.0.0-beta.1" + "@rescript/win32-x64": "npm:12.0.0-beta.1" + dependenciesMeta: + "@rescript/darwin-arm64": + optional: true + "@rescript/darwin-x64": + optional: true + "@rescript/linux-arm64": + optional: true + "@rescript/linux-x64": + optional: true + "@rescript/win32-x64": + optional: true + bin: + bsc: cli/bsc.js + bstracing: cli/bstracing.js + rescript: cli/rescript.js + rescript-legacy: cli/rescript-legacy.js + rescript-tools: cli/rescript-tools.js + checksum: 10c0/ec18e0ccd0791dec7b2bfaa44e0a011e1f171025d0743e06b51f7f4d81c8333bdf3b02f47b72f5b9a5cfa409bdf51e64998833696314e77b6f51afe376a4c3ad + languageName: node + linkType: hard + "testrepo@workspace:.": version: 0.0.0-use.local resolution: "testrepo@workspace:." diff --git a/rewatch/tests/compile.sh b/rewatch/tests/compile.sh index 15f1bf09c3..8d67e0bd11 100755 --- a/rewatch/tests/compile.sh +++ b/rewatch/tests/compile.sh @@ -81,6 +81,12 @@ echo 'Dep01.log()' >> packages/new-namespace/src/NS_alias.res rewatch build --snapshot-output &> ../tests/snapshots/dependency-cycle.txt git checkout -- packages/new-namespace/src/NS_alias.res +# this should not compile because "@rescript/webapi" is part of bs-dev-dependencies +# and FileToTest.res is not listed as "type":"dev" +echo 'open WebAPI' >> packages/with-dev-deps/src/FileToTest.res +rewatch build --snapshot-output &> ../tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt +git checkout -- packages/with-dev-deps/src/FileToTest.res + # it should compile dev dependencies with the --dev flag rewatch clean --dev &> /dev/null rewatch build --dev &> /dev/null; From 4cb50ec2c014864fc62de4d1e24b12cba50b4f6a Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 09:39:01 +0200 Subject: [PATCH 13/25] Add snapshot --- ...-dev-dependency-used-by-non-dev-source.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt diff --git a/rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt b/rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt new file mode 100644 index 0000000000..83422df567 --- /dev/null +++ b/rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt @@ -0,0 +1,19 @@ +Cleaned 0/15 +Parsed 2 source files +Compiled 2 modules + + We've found a bug for you! + /Users/nojaf/Projects/rescript/rewatch/testrepo/packages/with-dev-deps/src/FileToTest.res:2:6-11 + + 1 │ let add = (a, b) => a + b + 2 │ open WebAPI + 3 │ + + The module or file WebAPI can't be found. + - If it's a third-party dependency: + - Did you add it to the "bs-dependencies" or "bs-dev-dependencies" in rescript.json? + - Did you include the file's directory to the "sources" in rescript.json? + + + +Incremental build failed. Error:  Failed to Compile. See Errors Above From 1c1bd988cc6f28fa1c0a8cfdd6342a9138b6dd76 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 09:49:22 +0200 Subject: [PATCH 14/25] Normalize paths --- rewatch/tests/compile.sh | 1 + .../snapshots/bs-dev-dependency-used-by-non-dev-source.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/rewatch/tests/compile.sh b/rewatch/tests/compile.sh index 8d67e0bd11..31c1f9f9f7 100755 --- a/rewatch/tests/compile.sh +++ b/rewatch/tests/compile.sh @@ -85,6 +85,7 @@ git checkout -- packages/new-namespace/src/NS_alias.res # and FileToTest.res is not listed as "type":"dev" echo 'open WebAPI' >> packages/with-dev-deps/src/FileToTest.res rewatch build --snapshot-output &> ../tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt +normalize_paths ../tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt git checkout -- packages/with-dev-deps/src/FileToTest.res # it should compile dev dependencies with the --dev flag diff --git a/rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt b/rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt index 83422df567..cdd55a694f 100644 --- a/rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt +++ b/rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt @@ -3,7 +3,7 @@ Parsed 2 source files Compiled 2 modules We've found a bug for you! - /Users/nojaf/Projects/rescript/rewatch/testrepo/packages/with-dev-deps/src/FileToTest.res:2:6-11 + /packages/with-dev-deps/src/FileToTest.res:2:6-11 1 │ let add = (a, b) => a + b 2 │ open WebAPI From 3a67a8fc5919a26a35250769cb3bf64e88bbd9d2 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 10:56:59 +0200 Subject: [PATCH 15/25] Try --ignore-cr-at-eol --- rewatch/tests/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rewatch/tests/compile.sh b/rewatch/tests/compile.sh index 31c1f9f9f7..fa177f3ee8 100755 --- a/rewatch/tests/compile.sh +++ b/rewatch/tests/compile.sh @@ -149,7 +149,7 @@ fi # see if the snapshots have changed changed_snapshots=$(git ls-files --modified ../tests/snapshots) -if git diff --exit-code ../tests/snapshots &> /dev/null; +if git diff --ignore-cr-at-eol --exit-code ../tests/snapshots &> /dev/null; then success "Snapshots are correct" else From b52922e891be85f2ae62a15cd83d847a4b4f4e45 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 11:12:17 +0200 Subject: [PATCH 16/25] Revert "Try --ignore-cr-at-eol" This reverts commit 3a67a8fc5919a26a35250769cb3bf64e88bbd9d2. --- rewatch/tests/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rewatch/tests/compile.sh b/rewatch/tests/compile.sh index fa177f3ee8..31c1f9f9f7 100755 --- a/rewatch/tests/compile.sh +++ b/rewatch/tests/compile.sh @@ -149,7 +149,7 @@ fi # see if the snapshots have changed changed_snapshots=$(git ls-files --modified ../tests/snapshots) -if git diff --ignore-cr-at-eol --exit-code ../tests/snapshots &> /dev/null; +if git diff --exit-code ../tests/snapshots &> /dev/null; then success "Snapshots are correct" else From 076671a34b560c2760a35dff6711666c1b271a99 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 11:36:25 +0200 Subject: [PATCH 17/25] Trigger CI From 57cbc7efed8614fe00a074d8a81ef04a02688790 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 12:50:35 +0200 Subject: [PATCH 18/25] Remove extra lines in changelog --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7ce29e5e7..9abef28ebd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,3 @@ - - - # Changelog > **Tags:** From 086d9642c3d069d013efacad6ebf446ab770083b Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 13:06:02 +0200 Subject: [PATCH 19/25] Add tmate on Windows --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 723cba64a9..945cdf67a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -663,6 +663,10 @@ jobs: shell: bash working-directory: rewatch/testrepo + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + if: runner.os == 'Windows' + - name: Run rewatch integration tests run: ./rewatch/tests/suite-ci.sh node_modules/.bin/rescript shell: bash From 47be992ff433bed30b567c260f64d2ae42561543 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 13:22:05 +0200 Subject: [PATCH 20/25] =?UTF-8?q?Add=20tmate=20on=20Windows=20but=20earlie?= =?UTF-8?q?r=20=F0=9F=99=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 945cdf67a3..b0c1fb7973 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -360,6 +360,10 @@ jobs: if: runner.os != 'Windows' run: make -C tests/gentype_tests/typescript-react-example clean test + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + if: runner.os == 'Windows' + - name: Run rewatch tests run: ./rewatch/tests/suite-ci.sh shell: bash @@ -663,10 +667,6 @@ jobs: shell: bash working-directory: rewatch/testrepo - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - if: runner.os == 'Windows' - - name: Run rewatch integration tests run: ./rewatch/tests/suite-ci.sh node_modules/.bin/rescript shell: bash From 512bd803c20b0a94d1c1b5c5d998906ba30db49d Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 14:02:01 +0200 Subject: [PATCH 21/25] Remove more stuff --- rewatch/tests/utils.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rewatch/tests/utils.sh b/rewatch/tests/utils.sh index bef51f9fce..73790e6dcf 100644 --- a/rewatch/tests/utils.sh +++ b/rewatch/tests/utils.sh @@ -35,7 +35,10 @@ normalize_paths() { else if is_windows; then sed -i "s#$(pwd_prefix)##g" $1 + # Then normalize backslashes to forward slashes sed -i "s#\\\\#/#g" $1 + # Finally remove any remaining drive letter paths (like D:/a/rescript/rescript/rewatch/testrepo) + sed -i "s#[A-Z]:/a/rescript/rescript/rewatch/testrepo##g" $1 else sed -i "s#$(pwd_prefix)##g" $1; fi From c484a8c3304b1a7fa4eba50ab8ed0039388f33d9 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 14:38:21 +0200 Subject: [PATCH 22/25] More general path normalize check on Windows --- .github/workflows/ci.yml | 4 ---- rewatch/tests/utils.sh | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0c1fb7973..723cba64a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -360,10 +360,6 @@ jobs: if: runner.os != 'Windows' run: make -C tests/gentype_tests/typescript-react-example clean test - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - if: runner.os == 'Windows' - - name: Run rewatch tests run: ./rewatch/tests/suite-ci.sh shell: bash diff --git a/rewatch/tests/utils.sh b/rewatch/tests/utils.sh index 73790e6dcf..c183f7f1f7 100644 --- a/rewatch/tests/utils.sh +++ b/rewatch/tests/utils.sh @@ -38,7 +38,7 @@ normalize_paths() { # Then normalize backslashes to forward slashes sed -i "s#\\\\#/#g" $1 # Finally remove any remaining drive letter paths (like D:/a/rescript/rescript/rewatch/testrepo) - sed -i "s#[A-Z]:/a/rescript/rescript/rewatch/testrepo##g" $1 + sed -i "s#[A-Z]:/\(a/\)\?[^:]*rescript/rescript/rewatch/testrepo##g" $1 else sed -i "s#$(pwd_prefix)##g" $1; fi From 6e93495fe5416cbbcf2db5bc40f2f4f066f658de Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 15:34:21 +0200 Subject: [PATCH 23/25] This has to be newlines --- rewatch/tests/utils.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rewatch/tests/utils.sh b/rewatch/tests/utils.sh index c183f7f1f7..08c2a82aea 100644 --- a/rewatch/tests/utils.sh +++ b/rewatch/tests/utils.sh @@ -39,6 +39,8 @@ normalize_paths() { sed -i "s#\\\\#/#g" $1 # Finally remove any remaining drive letter paths (like D:/a/rescript/rescript/rewatch/testrepo) sed -i "s#[A-Z]:/\(a/\)\?[^:]*rescript/rescript/rewatch/testrepo##g" $1 + # Convert Unix line endings (LF) to Windows line endings (CRLF) + sed -i 's/$/\r/' $1 else sed -i "s#$(pwd_prefix)##g" $1; fi From b0ec5b1466eb8c9bcb93d77d8ee5037a8546a3b3 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 15:57:22 +0200 Subject: [PATCH 24/25] Update to beta 1 --- rewatch/testrepo/package.json | 2 +- rewatch/testrepo/yarn.lock | 69 +---------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) diff --git a/rewatch/testrepo/package.json b/rewatch/testrepo/package.json index a170d39c59..e91c4a11b5 100644 --- a/rewatch/testrepo/package.json +++ b/rewatch/testrepo/package.json @@ -14,7 +14,7 @@ ] }, "dependencies": { - "rescript": "12.0.0-alpha.15" + "rescript": "12.0.0-beta.1" }, "scripts": { "build": "../target/release/rewatch build .", diff --git a/rewatch/testrepo/yarn.lock b/rewatch/testrepo/yarn.lock index b51c2075ba..4bb7280e3e 100644 --- a/rewatch/testrepo/yarn.lock +++ b/rewatch/testrepo/yarn.lock @@ -5,13 +5,6 @@ __metadata: version: 8 cacheKey: 10c0 -"@rescript/darwin-arm64@npm:12.0.0-alpha.15": - version: 12.0.0-alpha.15 - resolution: "@rescript/darwin-arm64@npm:12.0.0-alpha.15" - conditions: os=darwin & cpu=arm64 - languageName: node - linkType: hard - "@rescript/darwin-arm64@npm:12.0.0-beta.1": version: 12.0.0-beta.1 resolution: "@rescript/darwin-arm64@npm:12.0.0-beta.1" @@ -19,13 +12,6 @@ __metadata: languageName: node linkType: hard -"@rescript/darwin-x64@npm:12.0.0-alpha.15": - version: 12.0.0-alpha.15 - resolution: "@rescript/darwin-x64@npm:12.0.0-alpha.15" - conditions: os=darwin & cpu=x64 - languageName: node - linkType: hard - "@rescript/darwin-x64@npm:12.0.0-beta.1": version: 12.0.0-beta.1 resolution: "@rescript/darwin-x64@npm:12.0.0-beta.1" @@ -33,13 +19,6 @@ __metadata: languageName: node linkType: hard -"@rescript/linux-arm64@npm:12.0.0-alpha.15": - version: 12.0.0-alpha.15 - resolution: "@rescript/linux-arm64@npm:12.0.0-alpha.15" - conditions: os=linux & cpu=arm64 - languageName: node - linkType: hard - "@rescript/linux-arm64@npm:12.0.0-beta.1": version: 12.0.0-beta.1 resolution: "@rescript/linux-arm64@npm:12.0.0-beta.1" @@ -47,13 +26,6 @@ __metadata: languageName: node linkType: hard -"@rescript/linux-x64@npm:12.0.0-alpha.15": - version: 12.0.0-alpha.15 - resolution: "@rescript/linux-x64@npm:12.0.0-alpha.15" - conditions: os=linux & cpu=x64 - languageName: node - linkType: hard - "@rescript/linux-x64@npm:12.0.0-beta.1": version: 12.0.0-beta.1 resolution: "@rescript/linux-x64@npm:12.0.0-beta.1" @@ -70,13 +42,6 @@ __metadata: languageName: node linkType: hard -"@rescript/win32-x64@npm:12.0.0-alpha.15": - version: 12.0.0-alpha.15 - resolution: "@rescript/win32-x64@npm:12.0.0-alpha.15" - conditions: os=win32 & cpu=x64 - languageName: node - linkType: hard - "@rescript/win32-x64@npm:12.0.0-beta.1": version: 12.0.0-beta.1 resolution: "@rescript/win32-x64@npm:12.0.0-beta.1" @@ -139,37 +104,7 @@ __metadata: languageName: unknown linkType: soft -"rescript@npm:12.0.0-alpha.15": - version: 12.0.0-alpha.15 - resolution: "rescript@npm:12.0.0-alpha.15" - dependencies: - "@rescript/darwin-arm64": "npm:12.0.0-alpha.15" - "@rescript/darwin-x64": "npm:12.0.0-alpha.15" - "@rescript/linux-arm64": "npm:12.0.0-alpha.15" - "@rescript/linux-x64": "npm:12.0.0-alpha.15" - "@rescript/win32-x64": "npm:12.0.0-alpha.15" - dependenciesMeta: - "@rescript/darwin-arm64": - optional: true - "@rescript/darwin-x64": - optional: true - "@rescript/linux-arm64": - optional: true - "@rescript/linux-x64": - optional: true - "@rescript/win32-x64": - optional: true - bin: - bsc: cli/bsc.js - bstracing: cli/bstracing.js - rescript: cli/rescript.js - rescript-legacy: cli/rescript-legacy.js - rescript-tools: cli/rescript-tools.js - checksum: 10c0/dbb5f05e5b28d211809a6aca386da37c25542d03f9ca57927a72bb456a392c1fc0383e9c70035d6b32dcbc62ba5ad8d54b831cf88bd95d674d0174fcc6380da7 - languageName: node - linkType: hard - -"rescript@npm:^12.0.0-alpha.13": +"rescript@npm:12.0.0-beta.1, rescript@npm:^12.0.0-alpha.13": version: 12.0.0-beta.1 resolution: "rescript@npm:12.0.0-beta.1" dependencies: @@ -203,6 +138,6 @@ __metadata: version: 0.0.0-use.local resolution: "testrepo@workspace:." dependencies: - rescript: "npm:12.0.0-alpha.15" + rescript: "npm:12.0.0-beta.1" languageName: unknown linkType: soft From 6794160636efa561667921e19bb09b5c6ecbeb35 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 18 Jul 2025 15:57:30 +0200 Subject: [PATCH 25/25] Revert line changes --- rewatch/tests/utils.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/rewatch/tests/utils.sh b/rewatch/tests/utils.sh index 08c2a82aea..c183f7f1f7 100644 --- a/rewatch/tests/utils.sh +++ b/rewatch/tests/utils.sh @@ -39,8 +39,6 @@ normalize_paths() { sed -i "s#\\\\#/#g" $1 # Finally remove any remaining drive letter paths (like D:/a/rescript/rescript/rewatch/testrepo) sed -i "s#[A-Z]:/\(a/\)\?[^:]*rescript/rescript/rewatch/testrepo##g" $1 - # Convert Unix line endings (LF) to Windows line endings (CRLF) - sed -i 's/$/\r/' $1 else sed -i "s#$(pwd_prefix)##g" $1; fi