Repository: denoland/deno
File: resolvers/node/analyze.rs (Rust)

Code before:
        {
          return Ok(None);
        }
        other => other.map_err(JsErrorBox::from_err)?,
      };

    let package_json_path = module_dir.join("package.json");
    let maybe_package_json = self
      .pkg_json_resolver
      .load_package_json(&package_json_path)
      .map_err(JsErrorBox::from_err)?;
    if let Some(package_json) = maybe_package_json {
      if let Some(exports) = &package_json.exports {
        return Some(
          self
            .node_resolver
            .package_exports_resolve(
              &package_json_path,
              &package_subpath,
              exports,
              Some(&referrer),
              ResolutionMode::Import,
              &ConditionResolver::new(ConditionResolverOptions {
                conditions: conditions.to_vec(),
                default_import_conditions: Vec::new(),
                default_require_conditions: Vec::new(),
              }),
              resolution_kind,
            )
            .map_err(JsErrorBox::from_err),
        )
        .transpose();
      }

      // old school
      if package_subpath != "." {
        let d = module_dir.join(package_subpath);
        if self.sys.fs_is_dir_no_err(&d) {
          // subdir might have a package.json that specifies the entrypoint
          let package_json_path = d.join("package.json");
          let maybe_package_json = self
            .pkg_json_resolver
            .load_package_json(&package_json_path)
            .map_err(JsErrorBox::from_err)?;
          if let Some(package_json) = maybe_package_json {
            if let Some(main) =
              package_json.main(deno_package_json::NodeModuleKind::Cjs)
            {
              return Ok(Some(UrlOrPath::Path(d.join(main).clean())));
            }
          }

Review comment (suggestion):
See other comment below, but these two properties needing to be provided is an example of how `ConditionResolver` is not the right thing to be passing around here (instead, we can just pass conditions as before).

Code after:
        }
        other => other.map_err(JsErrorBox::from_err)?,
      };

    let package_json_path = module_dir.join("package.json");
    let maybe_package_json = self
      .pkg_json_resolver
      .load_package_json(&package_json_path)
      .map_err(JsErrorBox::from_err)?;
    if let Some(package_json) = maybe_package_json {
      if let Some(exports) = &package_json.exports {
        return Some(
          self
            .node_resolver
            .package_exports_resolve(
              &package_json_path,
              &package_subpath,
              exports,
              Some(&referrer),
              ResolutionMode::Import,
              conditions,
              resolution_kind,
            )
            .map_err(JsErrorBox::from_err),
        )
        .transpose();
      }

      // old school
      if package_subpath != "." {
        let d = module_dir.join(package_subpath);
        if self.sys.fs_is_dir_no_err(&d) {
          // subdir might have a package.json that specifies the entrypoint
          let package_json_path = d.join("package.json");
          let maybe_package_json = self
            .pkg_json_resolver
            .load_package_json(&package_json_path)
            .map_err(JsErrorBox::from_err)?;
          if let Some(package_json) = maybe_package_json {
            if let Some(main) =
              package_json.main(deno_package_json::NodeModuleKind::Cjs)
            {
              return Ok(Some(UrlOrPath::Path(d.join(main).clean())));
            }
          }

          return Ok(Some(UrlOrPath::Path(d.join("index.js").clean())));
        }
        return self
          .file_extension_probe(d, referrer_path)
          .map(|p| Some(UrlOrPath::Path(p)));