Repository: denoland/deno
File: cli/tools/registry/mod.rs (Rust)

Code before:

    let deno_json = &package.config_file;
    let config_path = deno_json.specifier.to_file_path().unwrap();
    let root_dir = config_path.parent().unwrap().to_path_buf();
    let version = deno_json.json.version.clone().ok_or_else(|| {
      deno_core::anyhow::anyhow!(
        "{} is missing 'version' field",
        deno_json.specifier
      )
    })?;
    if deno_json.json.exports.is_none() {
      let mut suggested_entrypoint = None;

      for entrypoint in SUGGESTED_ENTRYPOINTS {
        if root_dir.join(entrypoint).exists() {
          suggested_entrypoint = Some(entrypoint);
          break;
        }
      }

      let exports_content = format!(
        r#"{{
      "name": "{}",
      "version": "{}",
      "exports": "{}"
    }}"#,
        package.name,
        version,
        suggested_entrypoint.unwrap_or("<path_to_entrypoint>")
      );

      bail!(
          "You did not specify an entrypoint to \"{}\" package in {}. Add `exports` mapping in the configuration file, eg:\n{}",
          package.name,
          deno_json.specifier,
          exports_content
        );
    }
    let Some(name_no_at) = package.name.strip_prefix('@') else {
      bail!("Invalid package name, use '@<scope_name>/<package_name> format");
    };
    let Some((scope, name_no_scope)) = name_no_at.split_once('/') else {
      bail!("Invalid package name, use '@<scope_name>/<package_name> format");
    };
    let file_patterns = package.member_dir.to_publish_config()?.files;

    let tarball = deno_core::unsync::spawn_blocking({
      let diagnostics_collector = diagnostics_collector.clone();
      let unfurler = self.specifier_unfurler.clone();
      let cli_options = self.cli_options.clone();
      let source_cache = self.source_cache.clone();

Review comment (suggestion):
This is introducing a change in the message. Surprisingly we don't have a test for this to have caught this.

Code after:

    let deno_json = &package.config_file;
    let config_path = deno_json.specifier.to_file_path().unwrap();
    let root_dir = config_path.parent().unwrap().to_path_buf();
    let version = deno_json.json.version.clone().ok_or_else(|| {
      deno_core::anyhow::anyhow!(
        "{} is missing 'version' field",
        deno_json.specifier
      )
    })?;
    if deno_json.json.exports.is_none() {
      let mut suggested_entrypoint = None;

      for entrypoint in SUGGESTED_ENTRYPOINTS {
        if root_dir.join(entrypoint).exists() {
          suggested_entrypoint = Some(entrypoint);
          break;
        }
      }

      let exports_content = format!(
        r#"{{
  "name": "{}",
  "version": "{}",
  "exports": "{}"
}}"#,
        package.name,
        version,
        suggested_entrypoint.unwrap_or("<path_to_entrypoint>")
      );

      bail!(
        "You did not specify an entrypoint to \"{}\" package in {}. Add `exports` mapping in the configuration file, eg:\n{}",
        package.name,
        deno_json.specifier,
        exports_content
      );
    }
    let Some(name_no_at) = package.name.strip_prefix('@') else {
      bail!("Invalid package name, use '@<scope_name>/<package_name> format");
    };
    let Some((scope, name_no_scope)) = name_no_at.split_once('/') else {
      bail!("Invalid package name, use '@<scope_name>/<package_name> format");
    };
    let file_patterns = package.member_dir.to_publish_config()?.files;

    let tarball = deno_core::unsync::spawn_blocking({
      let diagnostics_collector = diagnostics_collector.clone();
      let unfurler = self.specifier_unfurler.clone();
      let cli_options = self.cli_options.clone();
      let source_cache = self.source_cache.clone();