Skip to content

Commit 76f8cfa

Browse files
committed
chore: add debugging to wasm lib
1 parent d2f5465 commit 76f8cfa

2 files changed

Lines changed: 122 additions & 16 deletions

File tree

config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export function actionHandler<
187187
context.config,
188188
context.ignore ?? [],
189189
context.allowNodeModules ?? false,
190+
context.debug,
190191
);
191192
const configContext: ConfigContext = {
192193
...getAppFromConfig(config),
@@ -245,11 +246,13 @@ async function readConfig(
245246
maybeConfigPath: string | undefined,
246247
ignorePaths: string[],
247248
allowNodeModules: boolean,
249+
debug: boolean,
248250
): Promise<Config> {
249251
const config = resolve_config(
250252
resolve(maybeConfigPath || rootPath),
251253
ignorePaths,
252254
allowNodeModules,
255+
debug,
253256
);
254257

255258
if (config.path) {

rs_lib/src/lib.rs

Lines changed: 119 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ use sys_traits::FsMetadata;
1010
use url::Url;
1111
use wasm_bindgen::prelude::*;
1212

13+
#[cfg(target_arch = "wasm32")]
14+
#[wasm_bindgen]
15+
extern "C" {
16+
#[wasm_bindgen(js_namespace = console, js_name = log)]
17+
fn console_log(s: &str);
18+
}
19+
20+
#[cfg(target_arch = "wasm32")]
21+
fn debug_log(debug: bool, msg: &str) {
22+
if debug {
23+
console_log(&format!("[rs_lib] {}", msg));
24+
}
25+
}
26+
27+
#[cfg(not(target_arch = "wasm32"))]
28+
fn debug_log(_debug: bool, _msg: &str) {}
29+
1330
#[derive(Serialize)]
1431
pub struct ConfigLookup {
1532
pub path: Option<String>,
@@ -21,9 +38,10 @@ pub fn resolve_config(
2138
root_path: String,
2239
ignore_paths: Vec<String>,
2340
allow_node_modules: bool,
41+
debug: bool,
2442
) -> Result<JsValue, JsValue> {
2543
let result =
26-
inner_resolve_config(root_path, ignore_paths, allow_node_modules);
44+
inner_resolve_config(root_path, ignore_paths, allow_node_modules, debug);
2745
result
2846
.map_err(|err| create_js_error(&err))
2947
.map(|val| serde_wasm_bindgen::to_value(&val).unwrap())
@@ -33,18 +51,30 @@ fn inner_resolve_config(
3351
root_path: String,
3452
ignore_paths: Vec<String>,
3553
allow_node_modules: bool,
54+
debug: bool,
3655
) -> Result<ConfigLookup, anyhow::Error> {
56+
debug_log(
57+
debug,
58+
&format!(
59+
"resolve_config(root_path={:?}, ignore_paths={:?}, allow_node_modules={})",
60+
root_path, ignore_paths, allow_node_modules
61+
),
62+
);
63+
3764
let real_sys = sys_traits::impls::RealSys;
3865
let root_path = resolve_absolute_path(root_path)?;
66+
debug_log(debug, &format!("resolved absolute root_path={:?}", root_path));
3967

4068
// When --config points to a file (not a directory), use ConfigFile
4169
// discovery so non-standard filenames like deno-staging.json work.
4270
let is_config_file = real_sys.fs_is_file(&root_path).unwrap_or(false);
71+
debug_log(debug, &format!("is_config_file={}", is_config_file));
4372
let dir_path = if is_config_file {
4473
root_path.parent().unwrap().to_path_buf()
4574
} else {
4675
root_path.clone()
4776
};
77+
debug_log(debug, &format!("dir_path={:?}", dir_path));
4878

4979
let dir_paths = [dir_path.clone()];
5080
let discover_start = if is_config_file {
@@ -65,10 +95,31 @@ fn inner_resolve_config(
6595
maybe_vendor_override: None,
6696
},
6797
)?;
98+
debug_log(
99+
debug,
100+
&format!(
101+
"workspace discovered: member_deno_json={:?}, root_deno_json={:?}, members={:?}",
102+
workspace_dir.member_deno_json().map(|c| c.specifier.to_string()),
103+
workspace_dir
104+
.workspace
105+
.root_deno_json()
106+
.map(|c| c.specifier.to_string()),
107+
workspace_dir
108+
.workspace
109+
.config_folders()
110+
.keys()
111+
.map(|u| u.to_string())
112+
.collect::<Vec<_>>(),
113+
),
114+
);
68115

69116
let mut pattern = FilePatterns::new_with_base(dir_path.clone());
70117

71118
if !ignore_paths.is_empty() {
119+
debug_log(
120+
debug,
121+
&format!("applying ignore_paths={:?}", ignore_paths),
122+
);
72123
let exclude = PathOrPatternSet::from_exclude_relative_path_or_patterns(
73124
&dir_path,
74125
&ignore_paths,
@@ -79,6 +130,13 @@ fn inner_resolve_config(
79130
}
80131

81132
if let Some(config) = workspace_dir.to_deploy_config(pattern)? {
133+
debug_log(
134+
debug,
135+
&format!(
136+
"deploy config: include={:?}, exclude={:?}",
137+
config.files.include, config.files.exclude,
138+
),
139+
);
82140
let specifier = workspace_dir
83141
.member_deno_json()
84142
.filter(|config| config.to_deploy_config().is_ok())
@@ -91,8 +149,9 @@ fn inner_resolve_config(
91149
.expect(
92150
"workspace_dir.to_deploy_config should have resolved a specifier",
93151
);
152+
debug_log(debug, &format!("deploy config specifier={}", specifier));
94153
let files =
95-
collect_files(&real_sys, dir_path, config.files, allow_node_modules);
154+
collect_files(&real_sys, dir_path, config.files, allow_node_modules, debug);
96155
Ok(ConfigLookup {
97156
path: Some(specifier),
98157
files,
@@ -105,15 +164,21 @@ fn inner_resolve_config(
105164
workspace_dir.workspace.root_deno_json()
106165
.map(|member| member.specifier.to_string())
107166
});
108-
Ok(ConfigLookup {
109-
path,
110-
files: collect_files(
111-
&real_sys,
112-
dir_path.clone(),
113-
FilePatterns::new_with_base(dir_path),
114-
allow_node_modules,
167+
debug_log(
168+
debug,
169+
&format!(
170+
"no deploy config found; fallback config path={:?}",
171+
path,
115172
),
116-
})
173+
);
174+
let files = collect_files(
175+
&real_sys,
176+
dir_path.clone(),
177+
FilePatterns::new_with_base(dir_path),
178+
allow_node_modules,
179+
debug,
180+
);
181+
Ok(ConfigLookup { path, files })
117182
}
118183
}
119184

@@ -122,21 +187,58 @@ fn collect_files(
122187
root_path: PathBuf,
123188
files: FilePatterns,
124189
allow_node_modules: bool,
190+
debug: bool,
125191
) -> Vec<String> {
126-
let mut collector =
127-
FileCollector::new(|entry| entry.path.starts_with(&root_path))
128-
.ignore_git_folder()
129-
.use_gitignore();
192+
let filter_root = root_path.clone();
193+
let mut collector = FileCollector::new(move |entry| {
194+
let kept = entry.path.starts_with(&filter_root);
195+
debug_log(
196+
debug,
197+
&format!(
198+
"walk entry path={:?} is_dir={} kept={} (root={:?})",
199+
entry.path,
200+
entry.metadata.file_type().is_dir(),
201+
kept,
202+
filter_root,
203+
),
204+
);
205+
kept
206+
})
207+
.ignore_git_folder()
208+
.use_gitignore();
130209

131210
if !allow_node_modules {
132211
collector = collector.ignore_node_modules();
133212
}
134213

135-
collector
214+
debug_log(
215+
debug,
216+
&format!(
217+
"collector config: ignore_git_folder=true, use_gitignore=true, ignore_node_modules={}",
218+
!allow_node_modules,
219+
),
220+
);
221+
222+
let collected: Vec<String> = collector
136223
.collect_file_patterns(real_sys, &files)
137224
.into_iter()
138225
.map(|path| path.to_string_lossy().to_string())
139-
.collect::<Vec<String>>()
226+
.collect();
227+
228+
debug_log(
229+
debug,
230+
&format!(
231+
"collect_files(root_path={:?}, allow_node_modules={}, include={:?}, exclude={:?}) -> {} file(s): {:?}",
232+
root_path,
233+
allow_node_modules,
234+
files.include,
235+
files.exclude,
236+
collected.len(),
237+
collected,
238+
),
239+
);
240+
241+
collected
140242
}
141243

142244
fn resolve_absolute_path(path: String) -> Result<PathBuf, anyhow::Error> {
@@ -195,6 +297,7 @@ mod tests {
195297
root.to_string_lossy().into_owned(),
196298
Vec::new(),
197299
false,
300+
false,
198301
)
199302
.unwrap();
200303

0 commit comments

Comments
 (0)