Repository: denoland/deno
File: cli/type_checker.rs (Rust)

Code before:
    // log out the roots that we're checking
    log_provided_roots(&check_group.roots, &self.current_dir);

    // the first root will always either be the specifier that the user provided
    // or the first specifier in a directory
    let first_root = check_group
      .roots
      .first()
      .expect("must be at least one root");

    // while there might be multiple roots, we can't "merge" the build info, so we
    // try to retrieve the build info for first root, which is the most common use
    // case.
    let maybe_tsbuildinfo = if self.options.reload {
      None
    } else {
      self.type_check_cache.get_tsbuildinfo(first_root)
    };
    // to make tsc build info work, we need to consistently hash modules, so that
    // tsc can better determine if an emit is still valid or not, so we provide
    // that data here.
    let compiler_options = if self.force_check_js {
      force_check_js_compiler_options(check_group.compiler_options.clone())
    } else {
      check_group.compiler_options.clone()
    };

    let compiler_options_hash_data = FastInsecureHasher::new_deno_versioned()
      .write_hashable(&compiler_options)
      .finish();
    let code_cache = self.code_cache.as_ref().map(|c| {
      let c: Arc<dyn deno_runtime::code_cache::CodeCache> = c.clone();
      c
    });
    let response = tsc::exec(
      tsc::Request {
        config: compiler_options,
        debug: self.log_level == Some(log::Level::Debug),
        graph: self.graph.clone(),
        jsx_import_source_config_resolver: self
          .jsx_import_source_config_resolver
          .clone(),
        hash_data: compiler_options_hash_data,
        maybe_npm: Some(tsc::RequestNpmState {
          cjs_tracker: self.cjs_tracker.clone(),
          node_resolver: self.node_resolver.clone(),
          npm_resolver: self.npm_resolver.clone(),
          package_json_resolver: self.package_json_resolver.clone(),
        }),
        maybe_tsbuildinfo,
        root_names,

Review comment (suggestion):
This should probably be handled entirely by the `CompilerOptionsResolver` and not mixed in with the code here. There's a `CompilerOptionsOverrides` that could have this property.

Code after:
    let compiler_options_hash_data = FastInsecureHasher::new_deno_versioned()
      .write_hashable(&compiler_options)
      .finish();
    let code_cache = self.code_cache.as_ref().map(|c| {
      let c: Arc<dyn deno_runtime::code_cache::CodeCache> = c.clone();
      c
    });
    let response = tsc::exec(
      tsc::Request {
        config: compiler_options,
        debug: self.log_level == Some(log::Level::Debug),
        graph: self.graph.clone(),
        jsx_import_source_config_resolver: self
          .jsx_import_source_config_resolver
          .clone(),
        hash_data: compiler_options_hash_data,
        maybe_npm: Some(tsc::RequestNpmState {
          cjs_tracker: self.cjs_tracker.clone(),
          node_resolver: self.node_resolver.clone(),
          npm_resolver: self.npm_resolver.clone(),
          package_json_resolver: self.package_json_resolver.clone(),
        }),
        maybe_tsbuildinfo,
        root_names,
        check_mode: self.options.type_check_mode,
        initial_cwd: self.initial_cwd.clone(),
      },
      code_cache,
      self.tsgo_path.as_deref(),
    )?;

    let ambient_modules = response.ambient_modules;
    log::debug!("Ambient Modules: {:?}", ambient_modules);

    let ambient_modules_regex = if ambient_modules.is_empty() {
      None
    } else {
      regex::Regex::new(&ambient_modules_to_regex_string(&ambient_modules))
        .inspect_err(|e| {
          log::warn!("Failed to create regex for ambient modules: {}", e);
        })
        .ok()
    };

    let mut response_diagnostics = response.diagnostics.filter(|d| {
      self.should_include_diagnostic(self.options.type_check_mode, d)
    });
    response_diagnostics.apply_fast_check_source_maps(&self.graph);
    let mut diagnostics = missing_diagnostics.filter(|d| {
      if let Some(ambient_modules_regex) = &ambient_modules_regex
        && let Some(missing_specifier) = &d.missing_specifier