Fix javascript asset bundling errors and fallback (#3935)
This commit is contained in:
1 parent
487fa25dc8
commit
bcc1dc020c
1 file changed
+17
-12
+17
-12
@@ -103,8 +103,10 @@ fn bundle_js_to_writer_inside_handler(
|
|||||||
|
|
||||||
parser.parse_module().map_err(|err| {
|
parser.parse_module().map_err(|err| {
|
||||||
HANDLER.with(|handler| {
|
HANDLER.with(|handler| {
|
||||||
let message = err.into_diagnostic(handler).message();
|
let mut error = err.into_diagnostic(handler);
|
||||||
anyhow::anyhow!("{}", message)
|
// swc errors panic on drop if you don't cancel them
|
||||||
|
error.cancel();
|
||||||
|
anyhow::anyhow!("{}", error.message())
|
||||||
})
|
})
|
||||||
})?
|
})?
|
||||||
};
|
};
|
||||||
@@ -165,8 +167,10 @@ impl Load for PathLoader {
|
|||||||
&mut Vec::new(),
|
&mut Vec::new(),
|
||||||
)
|
)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
let message = err.into_diagnostic(handler).message();
|
let mut error = err.into_diagnostic(handler);
|
||||||
anyhow::anyhow!("{}", message)
|
// swc errors panic on drop if you don't cancel them
|
||||||
|
error.cancel();
|
||||||
|
anyhow::anyhow!("{}", error.message())
|
||||||
})
|
})
|
||||||
.context("Failed to parse javascript")
|
.context("Failed to parse javascript")
|
||||||
})?;
|
})?;
|
||||||
@@ -228,16 +232,17 @@ pub(crate) fn process_js(
|
|||||||
if js_options.minified() {
|
if js_options.minified() {
|
||||||
if let Err(err) = bundle_js_to_writer(source.to_path_buf(), bundle, true, &mut writer) {
|
if let Err(err) = bundle_js_to_writer(source.to_path_buf(), bundle, true, &mut writer) {
|
||||||
tracing::error!("Failed to minify js. Falling back to non-minified: {err}");
|
tracing::error!("Failed to minify js. Falling back to non-minified: {err}");
|
||||||
|
} else {
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
let mut source_file = std::fs::File::open(source)?;
|
|
||||||
std::io::copy(&mut source_file, &mut writer).with_context(|| {
|
|
||||||
format!(
|
|
||||||
"Failed to write js to output location: {}",
|
|
||||||
output_path.display()
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
|
let mut source_file = std::fs::File::open(source)?;
|
||||||
|
std::io::copy(&mut source_file, &mut writer).with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Failed to write js to output location: {}",
|
||||||
|
output_path.display()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user