diff --git a/config.ts b/config.ts index f427e20..b885639 100644 --- a/config.ts +++ b/config.ts @@ -187,6 +187,7 @@ export function actionHandler< context.config, context.ignore ?? [], context.allowNodeModules ?? false, + context.debug, ); const configContext: ConfigContext = { ...getAppFromConfig(config), @@ -245,11 +246,13 @@ async function readConfig( maybeConfigPath: string | undefined, ignorePaths: string[], allowNodeModules: boolean, + debug: boolean, ): Promise { const config = resolve_config( resolve(maybeConfigPath || rootPath), ignorePaths, allowNodeModules, + debug, ); if (config.path) { diff --git a/rs_lib/src/lib.rs b/rs_lib/src/lib.rs index 642ff89..71ebd90 100644 --- a/rs_lib/src/lib.rs +++ b/rs_lib/src/lib.rs @@ -10,6 +10,23 @@ use sys_traits::FsMetadata; use url::Url; use wasm_bindgen::prelude::*; +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(js_namespace = console, js_name = log)] + fn console_log(s: &str); +} + +#[cfg(target_arch = "wasm32")] +fn debug_log(debug: bool, msg: &str) { + if debug { + console_log(&format!("[rs_lib] {}", msg)); + } +} + +#[cfg(not(target_arch = "wasm32"))] +fn debug_log(_debug: bool, _msg: &str) {} + #[derive(Serialize)] pub struct ConfigLookup { pub path: Option, @@ -21,9 +38,10 @@ pub fn resolve_config( root_path: String, ignore_paths: Vec, allow_node_modules: bool, + debug: bool, ) -> Result { let result = - inner_resolve_config(root_path, ignore_paths, allow_node_modules); + inner_resolve_config(root_path, ignore_paths, allow_node_modules, debug); result .map_err(|err| create_js_error(&err)) .map(|val| serde_wasm_bindgen::to_value(&val).unwrap()) @@ -33,18 +51,30 @@ fn inner_resolve_config( root_path: String, ignore_paths: Vec, allow_node_modules: bool, + debug: bool, ) -> Result { + debug_log( + debug, + &format!( + "resolve_config(root_path={:?}, ignore_paths={:?}, allow_node_modules={})", + root_path, ignore_paths, allow_node_modules + ), + ); + let real_sys = sys_traits::impls::RealSys; let root_path = resolve_absolute_path(root_path)?; + debug_log(debug, &format!("resolved absolute root_path={:?}", root_path)); // When --config points to a file (not a directory), use ConfigFile // discovery so non-standard filenames like deno-staging.json work. let is_config_file = real_sys.fs_is_file(&root_path).unwrap_or(false); + debug_log(debug, &format!("is_config_file={}", is_config_file)); let dir_path = if is_config_file { root_path.parent().unwrap().to_path_buf() } else { root_path.clone() }; + debug_log(debug, &format!("dir_path={:?}", dir_path)); let dir_paths = [dir_path.clone()]; let discover_start = if is_config_file { @@ -65,10 +95,31 @@ fn inner_resolve_config( maybe_vendor_override: None, }, )?; + debug_log( + debug, + &format!( + "workspace discovered: member_deno_json={:?}, root_deno_json={:?}, members={:?}", + workspace_dir.member_deno_json().map(|c| c.specifier.to_string()), + workspace_dir + .workspace + .root_deno_json() + .map(|c| c.specifier.to_string()), + workspace_dir + .workspace + .config_folders() + .keys() + .map(|u| u.to_string()) + .collect::>(), + ), + ); let mut pattern = FilePatterns::new_with_base(dir_path.clone()); if !ignore_paths.is_empty() { + debug_log( + debug, + &format!("applying ignore_paths={:?}", ignore_paths), + ); let exclude = PathOrPatternSet::from_exclude_relative_path_or_patterns( &dir_path, &ignore_paths, @@ -79,6 +130,13 @@ fn inner_resolve_config( } if let Some(config) = workspace_dir.to_deploy_config(pattern)? { + debug_log( + debug, + &format!( + "deploy config: include={:?}, exclude={:?}", + config.files.include, config.files.exclude, + ), + ); let specifier = workspace_dir .member_deno_json() .filter(|config| config.to_deploy_config().is_ok()) @@ -91,8 +149,9 @@ fn inner_resolve_config( .expect( "workspace_dir.to_deploy_config should have resolved a specifier", ); + debug_log(debug, &format!("deploy config specifier={}", specifier)); let files = - collect_files(&real_sys, dir_path, config.files, allow_node_modules); + collect_files(&real_sys, dir_path, config.files, allow_node_modules, debug); Ok(ConfigLookup { path: Some(specifier), files, @@ -105,15 +164,21 @@ fn inner_resolve_config( workspace_dir.workspace.root_deno_json() .map(|member| member.specifier.to_string()) }); - Ok(ConfigLookup { - path, - files: collect_files( - &real_sys, - dir_path.clone(), - FilePatterns::new_with_base(dir_path), - allow_node_modules, + debug_log( + debug, + &format!( + "no deploy config found; fallback config path={:?}", + path, ), - }) + ); + let files = collect_files( + &real_sys, + dir_path.clone(), + FilePatterns::new_with_base(dir_path), + allow_node_modules, + debug, + ); + Ok(ConfigLookup { path, files }) } } @@ -122,21 +187,58 @@ fn collect_files( root_path: PathBuf, files: FilePatterns, allow_node_modules: bool, + debug: bool, ) -> Vec { - let mut collector = - FileCollector::new(|entry| entry.path.starts_with(&root_path)) - .ignore_git_folder() - .use_gitignore(); + let filter_root = root_path.clone(); + let mut collector = FileCollector::new(move |entry| { + let kept = entry.path.starts_with(&filter_root); + debug_log( + debug, + &format!( + "walk entry path={:?} is_dir={} kept={} (root={:?})", + entry.path, + entry.metadata.file_type().is_dir(), + kept, + filter_root, + ), + ); + kept + }) + .ignore_git_folder() + .use_gitignore(); if !allow_node_modules { collector = collector.ignore_node_modules(); } - collector + debug_log( + debug, + &format!( + "collector config: ignore_git_folder=true, use_gitignore=true, ignore_node_modules={}", + !allow_node_modules, + ), + ); + + let collected: Vec = collector .collect_file_patterns(real_sys, &files) .into_iter() .map(|path| path.to_string_lossy().to_string()) - .collect::>() + .collect(); + + debug_log( + debug, + &format!( + "collect_files(root_path={:?}, allow_node_modules={}, include={:?}, exclude={:?}) -> {} file(s): {:?}", + root_path, + allow_node_modules, + files.include, + files.exclude, + collected.len(), + collected, + ), + ); + + collected } fn resolve_absolute_path(path: String) -> Result { @@ -195,6 +297,7 @@ mod tests { root.to_string_lossy().into_owned(), Vec::new(), false, + false, ) .unwrap();