summaryrefslogtreecommitdiff
path: root/cli/module_graph.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2021-06-01 07:45:37 +0100
committerGitHub <noreply@github.com>2021-06-01 16:45:37 +1000
commit6dd7a7ecd9d9b09f5112c73c67aa5f94480c8196 (patch)
treee4286caa3543d5184a65cadaacfd17b178495469 /cli/module_graph.rs
parent595700c993891ec8bf83f455a6602070ab8351ac (diff)
fix(cli): represent bare imports as module graph error slots (#10804)
Fixes #10795
Diffstat (limited to 'cli/module_graph.rs')
-rw-r--r--cli/module_graph.rs44
1 files changed, 29 insertions, 15 deletions
diff --git a/cli/module_graph.rs b/cli/module_graph.rs
index 5bfa52e89..2ae112c8d 100644
--- a/cli/module_graph.rs
+++ b/cli/module_graph.rs
@@ -38,6 +38,7 @@ use deno_core::serde::Serialize;
use deno_core::serde::Serializer;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
+use deno_core::url::Url;
use deno_core::ModuleResolutionError;
use deno_core::ModuleSource;
use deno_core::ModuleSpecifier;
@@ -398,9 +399,13 @@ impl Module {
Ok(specifier) => Some(specifier),
Err(any_error) => {
match any_error.downcast_ref::<ModuleResolutionError>() {
- Some(ModuleResolutionError::ImportPrefixMissing(..)) => None,
+ Some(ModuleResolutionError::ImportPrefixMissing(..)) => {
+ Some(Url::parse(&format!("bare:{}", &desc.specifier)).unwrap())
+ }
_ => match any_error.downcast_ref::<ImportMapError>() {
- Some(ImportMapError::UnmappedBareSpecifier(..)) => None,
+ Some(ImportMapError::UnmappedBareSpecifier(..)) => Some(
+ Url::parse(&format!("bare:{}", &desc.specifier)).unwrap(),
+ ),
_ => {
return Err(any_error);
}
@@ -1908,19 +1913,28 @@ impl GraphBuilder {
}
for (_, dep) in module.dependencies.iter() {
let maybe_referrer = Some(dep.location.clone());
- if let Some(specifier) = dep.maybe_code.as_ref() {
- self.fetch(
- specifier,
- &maybe_referrer,
- is_root_dynamic || dep.is_dynamic,
- );
- }
- if let Some(specifier) = dep.maybe_type.as_ref() {
- self.fetch(
- specifier,
- &maybe_referrer,
- is_root_dynamic || dep.is_dynamic,
- );
+ for maybe_specifier in &[dep.maybe_code.as_ref(), dep.maybe_type.as_ref()]
+ {
+ if let Some(&dep_specifier) = maybe_specifier.as_ref() {
+ if dep_specifier.scheme() == "bare" {
+ self.graph.modules.insert(
+ dep_specifier.clone(),
+ ModuleSlot::Err(Arc::new(
+ ModuleResolutionError::ImportPrefixMissing(
+ dep_specifier.path().to_string(),
+ Some(specifier.to_string()),
+ )
+ .into(),
+ )),
+ );
+ } else {
+ self.fetch(
+ dep_specifier,
+ &maybe_referrer,
+ is_root_dynamic || dep.is_dynamic,
+ );
+ }
+ }
}
}
if let Some((_, specifier)) = module.maybe_types.as_ref() {