Skip to content

Commit 5549c5f

Browse files
author
Roland Peelen
committed
🐛 - Don't unwrap file path when creating AST
1 parent 4f9fcab commit 5549c5f

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

src/build.rs

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -82,45 +82,53 @@ fn generate_ast(
8282

8383
let bsc_flags = bsconfig::flatten_flags(&package.bsconfig.bsc_flags);
8484

85-
let res_to_ast_args = vec![
86-
vec!["-bs-v".to_string(), format!("{}", version)],
87-
ppx_flags,
88-
{
89-
package
90-
.bsconfig
91-
.reason
92-
.to_owned()
93-
.map(|x| vec!["-bs-jsx".to_string(), format!("{}", x.react_jsx)])
94-
.unwrap_or(vec![])
95-
},
96-
bsc_flags,
85+
let res_to_ast_args = |file: String| -> Vec<String> {
9786
vec![
98-
"-absname".to_string(),
99-
"-bs-ast".to_string(),
100-
"-o".to_string(),
101-
ast_path.to_string(),
102-
helpers::canonicalize_string_path(file).unwrap(),
103-
],
104-
]
105-
.concat();
87+
vec!["-bs-v".to_string(), format!("{}", version)],
88+
ppx_flags,
89+
{
90+
package
91+
.bsconfig
92+
.reason
93+
.to_owned()
94+
.map(|x| vec!["-bs-jsx".to_string(), format!("{}", x.react_jsx)])
95+
.unwrap_or(vec![])
96+
},
97+
bsc_flags,
98+
vec![
99+
"-absname".to_string(),
100+
"-bs-ast".to_string(),
101+
"-o".to_string(),
102+
ast_path.to_string(),
103+
file,
104+
],
105+
]
106+
.concat()
107+
};
106108

107109
/* Create .ast */
108-
let res_to_ast = Command::new(helpers::get_bsc(&root_path))
109-
.current_dir(helpers::canonicalize_string_path(&build_path_abs).unwrap())
110-
.args(res_to_ast_args)
111-
.output()
112-
.expect("Error converting .res to .ast");
113-
114-
let stderr = std::str::from_utf8(&res_to_ast.stderr).expect("stderr should be non-null");
115-
116-
if helpers::contains_ascii_characters(stderr) {
117-
if res_to_ast.status.success() {
118-
Ok((ast_path, Some(stderr.to_string())))
110+
if let Some(res_to_ast) = helpers::canonicalize_string_path(file).map(|file| {
111+
Command::new(helpers::get_bsc(&root_path))
112+
.current_dir(helpers::canonicalize_string_path(&build_path_abs).unwrap())
113+
.args(res_to_ast_args(file))
114+
.output()
115+
.expect("Error converting .res to .ast")
116+
}) {
117+
let stderr = std::str::from_utf8(&res_to_ast.stderr).expect("Expect StdErr to be non-null");
118+
if helpers::contains_ascii_characters(stderr) {
119+
if res_to_ast.status.success() {
120+
Ok((ast_path, Some(stderr.to_string())))
121+
} else {
122+
Err(stderr.to_string())
123+
}
119124
} else {
120-
Err(stderr.to_string())
125+
Ok((ast_path, None))
121126
}
122127
} else {
123-
Ok((ast_path, None))
128+
return Err(format!(
129+
"Could not find canonicalize_string_path for file {} in package {}",
130+
file, package.name
131+
));
124132
}
125133
}
126134

@@ -976,7 +984,7 @@ pub fn build(path: &str) -> Result<AHashMap<std::string::String, Module>, ()> {
976984
"{}\r{} {} Collected deps in {:.2}s",
977985
LINE_CLEAR,
978986
style("[5/6]").bold().dim(),
979-
DEPS,
987+
CHECKMARK,
980988
timing_deps_elapsed.as_secs_f64()
981989
);
982990

0 commit comments

Comments
 (0)