Repository: denoland/deno
Pull request: fix(install): ignore unknown JSR export errors on top level install

Couldn't write a test, but it happens in some edge cases.

Changed files:
filename: cli/graph_util.rs
patch: @@ -77,6 +77,7 @@ pub struct GraphValidOptions<'a> {
   pub exit_integrity_errors: bool,
   pub allow_unknown_media_types: bool,
   pub ignore_graph_errors: bool,
+  pub allow_unknown_jsr_exports: bool,
 }
 
 /// Check if `roots` and their deps are available. Returns `Ok(())` if
@@ -105,6 +106,7 @@ pub fn graph_valid(
       kind: options.kind,
       allow_unknown_media_types: options.allow_unknown_media_types,
       ignore_graph_errors: options.ignore_graph_errors,
+      allow_unknown_jsr_exports: options.allow_unknown_jsr_exports,
     },
   );
   if let Some(error) = errors.next() {
@@ -146,6 +148,7 @@ pub struct GraphWalkErrorsOptions<'a> {
   pub kind: GraphKind,
   pub ignore_graph_errors: bool,
   pub allow_unknown_media_types: bool,
+  pub allow_unknown_jsr_exports: bool,
 }
 
 /// Walks the errors found in the module graph that should be surfaced to users
@@ -242,6 +245,18 @@ pub fn graph_walk_errors<'a>(
           roots.contains(error.specifier())
         }
       };
+      if is_root
+        && options.allow_unknown_jsr_exports
+        && matches!(
+          error,
+          ModuleGraphError::ModuleError(ModuleError::Load {
+            err: ModuleLoadError::Jsr(JsrLoadError::UnknownExport { .. }),
+            ..
+          })
+        )
+      {
+        return None;
+      }
       let message = enhance_graph_error(
         sys,
         &error,
@@ -972,6 +987,7 @@ impl ModuleGraphBuilder {
       graph,
       &graph.roots.iter().cloned().collect::<Vec<_>>(),
       false,
+      false,
     )
   }
 
@@ -980,6 +996,7 @@ impl ModuleGraphBuilder {
     graph: &ModuleGraph,
     roots: &[ModuleSpecifier],
     allow_unknown_media_types: bool,
+    allow_unknown_jsr_exports: bool,
   ) -> Result<(), JsErrorBox> {
     graph_valid(
       graph,
@@ -998,6 +1015,7 @@ impl ModuleGraphBuilder {
           self.cli_options.sub_command(),
           DenoSubcommand::Check { .. }
         ),
+        allow_unknown_jsr_exports,
       },
     )
   }

filename: cli/lsp/language_server.rs
patch: @@ -355,6 +355,7 @@ impl LanguageServer {
           exit_integrity_errors: false,
           allow_unknown_media_types: true,
           ignore_graph_errors: true,
+          allow_unknown_jsr_exports: false,
         },
       )?;
 

filename: cli/module_loader.rs
patch: @@ -227,7 +227,7 @@ impl ModuleLoadPreparer {
       .await?;
 
     if !skip_graph_roots_validation {
-      self.graph_roots_valid(graph, roots, allow_unknown_media_types)?;
+      self.graph_roots_valid(graph, roots, allow_unknown_media_types, false)?;
     }
 
     drop(_pb_clear_guard);
@@ -305,11 +305,13 @@ impl ModuleLoadPreparer {
     graph: &ModuleGraph,
     roots: &[ModuleSpecifier],
     allow_unknown_media_types: bool,
+    allow_unknown_jsr_exports: bool,
   ) -> Result<(), JsErrorBox> {
     self.module_graph_builder.graph_roots_valid(
       graph,
       roots,
       allow_unknown_media_types,
+      allow_unknown_jsr_exports,
     )
   }
 }
@@ -1382,6 +1384,7 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
               &graph,
               &[specifier],
               false,
+              false,
             )?;
           }
           return Ok(());
@@ -1427,6 +1430,7 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
           &graph_container.graph(),
           specifiers,
           false,
+          false,
         )?;
       }
 

filename: cli/tools/doc.rs
patch: @@ -156,6 +156,7 @@ pub async fn doc(
           kind: GraphKind::TypesOnly,
           allow_unknown_media_types: false,
           ignore_graph_errors: true,
+          allow_unknown_jsr_exports: false,
         },
       );
       for error in errors {

filename: cli/tools/pm/cache_deps.rs
patch: @@ -188,7 +188,8 @@ pub async fn cache_top_level_deps(
         },
       )
       .await?;
-    maybe_graph_error = graph_builder.graph_roots_valid(graph, &roots, true);
+    maybe_graph_error =
+      graph_builder.graph_roots_valid(graph, &roots, true, true);
   }
 
   npm_installer.cache_packages(PackageCaching::All).await?;