mirror of
https://github.com/denoland/deno.git
synced 2024-12-11 01:58:05 -05:00
fix(vendor): error on dynamic imports that fail to load instead of panicking (#15391)
This commit is contained in:
parent
2728c8fdf1
commit
fc04f8a03d
2 changed files with 46 additions and 4 deletions
28
cli/tools/vendor/build.rs
vendored
28
cli/tools/vendor/build.rs
vendored
|
@ -68,6 +68,14 @@ pub fn build(
|
|||
graph.lock()?;
|
||||
graph.valid()?;
|
||||
|
||||
let graph_errors = graph.errors();
|
||||
if !graph_errors.is_empty() {
|
||||
for err in &graph_errors {
|
||||
log::error!("{}", err);
|
||||
}
|
||||
bail!("failed vendoring");
|
||||
}
|
||||
|
||||
// figure out how to map remote modules to local
|
||||
let all_modules = graph.modules();
|
||||
let remote_modules = all_modules
|
||||
|
@ -1003,6 +1011,26 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn vendor_file_fails_loading_dynamic_import() {
|
||||
let mut builder = VendorTestBuilder::with_default_setup();
|
||||
let err = builder
|
||||
.with_loader(|loader| {
|
||||
loader.add("/mod.ts", "import 'https://localhost/mod.ts';");
|
||||
loader.add("https://localhost/mod.ts", "await import('./test.ts');");
|
||||
loader.add_failure(
|
||||
"https://localhost/test.ts",
|
||||
"500 Internal Server Error",
|
||||
);
|
||||
})
|
||||
.build()
|
||||
.await
|
||||
.err()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(err.to_string(), "failed vendoring");
|
||||
}
|
||||
|
||||
fn to_file_vec(items: &[(&str, &str)]) -> Vec<(String, String)> {
|
||||
items
|
||||
.iter()
|
||||
|
|
22
cli/tools/vendor/test.rs
vendored
22
cli/tools/vendor/test.rs
vendored
|
@ -41,6 +41,22 @@ impl TestLoader {
|
|||
&mut self,
|
||||
path_or_specifier: impl AsRef<str>,
|
||||
text: impl AsRef<str>,
|
||||
) -> &mut Self {
|
||||
self.add_result(path_or_specifier, Ok((text.as_ref().to_string(), None)))
|
||||
}
|
||||
|
||||
pub fn add_failure(
|
||||
&mut self,
|
||||
path_or_specifier: impl AsRef<str>,
|
||||
message: impl AsRef<str>,
|
||||
) -> &mut Self {
|
||||
self.add_result(path_or_specifier, Err(message.as_ref().to_string()))
|
||||
}
|
||||
|
||||
fn add_result(
|
||||
&mut self,
|
||||
path_or_specifier: impl AsRef<str>,
|
||||
result: RemoteFileResult,
|
||||
) -> &mut Self {
|
||||
if path_or_specifier
|
||||
.as_ref()
|
||||
|
@ -49,14 +65,12 @@ impl TestLoader {
|
|||
{
|
||||
self.files.insert(
|
||||
ModuleSpecifier::parse(path_or_specifier.as_ref()).unwrap(),
|
||||
Ok((text.as_ref().to_string(), None)),
|
||||
result,
|
||||
);
|
||||
} else {
|
||||
let path = make_path(path_or_specifier.as_ref());
|
||||
let specifier = ModuleSpecifier::from_file_path(path).unwrap();
|
||||
self
|
||||
.files
|
||||
.insert(specifier, Ok((text.as_ref().to_string(), None)));
|
||||
self.files.insert(specifier, result);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue