Repository: denoland/deno
Pull request: feat(install): change 'Add ...' message

Changes messages printed by `deno add` from
`Add @oak/oak - jsr:@oak/oak^16.1.0` to
`Add jsr:@oak/oak16.1.0`

<img width="711" alt="Screenshot 2024-08-08 at 13 59 35" src="https://github.com/user-attachments/assets/674958bf-a8e1-4aae-9b7e-af57b9bc8063">


Changed files:
filename: cli/tools/registry/pm.rs
patch: @@ -267,10 +267,10 @@ pub async fn add(
   let is_npm = config_file.is_npm();
   for selected_package in selected_packages {
     log::info!(
-      "Add {} - {}@{}",
-      crate::colors::green(&selected_package.import_name),
-      selected_package.package_name,
-      selected_package.version_req
+      "Add {}{}{}",
+      crate::colors::green(&selected_package.package_name),
+      crate::colors::gray("@"),
+      selected_package.selected_version
     );
 
     if is_npm {
@@ -323,6 +323,7 @@ struct SelectedPackage {
   import_name: String,
   package_name: String,
   version_req: String,
+  selected_version: String,
 }
 
 enum PackageAndVersion {
@@ -350,6 +351,7 @@ async fn find_package_and_select_version_for_req(
         import_name: add_package_req.alias,
         package_name: jsr_prefixed_name,
         version_req: format!("{}{}", range_symbol, &nv.version),
+        selected_version: nv.version.to_string(),
       }))
     }
     AddPackageReqValue::Npm(req) => {
@@ -366,6 +368,7 @@ async fn find_package_and_select_version_for_req(
         import_name: add_package_req.alias,
         package_name: npm_prefixed_name,
         version_req: format!("{}{}", range_symbol, &nv.version),
+        selected_version: nv.version.to_string(),
       }))
     }
   }

filename: tests/integration/pm_tests.rs
patch: @@ -19,7 +19,7 @@ fn add_basic() {
   let output = context.new_command().args("add @denotest/add").run();
   output.assert_exit_code(0);
   let output = output.combined_output();
-  assert_contains!(output, "Add @denotest/add");
+  assert_contains!(output, "Add jsr:@denotest/add");
   temp_dir.join("deno.json").assert_matches_json(json!({
     "name": "@foo/bar",
     "version": "1.0.0",
@@ -38,7 +38,7 @@ fn add_basic_no_deno_json() {
   let output = context.new_command().args("add @denotest/add").run();
   output.assert_exit_code(0);
   let output = output.combined_output();
-  assert_contains!(output, "Add @denotest/add");
+  assert_contains!(output, "Add jsr:@denotest/add");
   // Don't use `assert_matches_json` to ensure the file is properly formatted.
   let expected = r#"{
   "imports": {
@@ -58,7 +58,7 @@ fn add_basic_with_empty_deno_json() {
   let output = context.new_command().args("add @denotest/add").run();
   output.assert_exit_code(0);
   let output = output.combined_output();
-  assert_contains!(output, "Add @denotest/add");
+  assert_contains!(output, "Add jsr:@denotest/add");
   temp_dir
     .path()
     .join("deno.json")
@@ -77,7 +77,7 @@ fn add_version_contraint() {
   let output = context.new_command().args("add @denotest/add@1").run();
   output.assert_exit_code(0);
   let output = output.combined_output();
-  assert_contains!(output, "Add @denotest/add");
+  assert_contains!(output, "Add jsr:@denotest/add");
   temp_dir.join("deno.json").assert_matches_json(json!({
     "imports": {
       "@denotest/add": "jsr:@denotest/add@^1.0.0"
@@ -93,7 +93,7 @@ fn add_tilde() {
   let output = context.new_command().args("add @denotest/add@~1").run();
   output.assert_exit_code(0);
   let output = output.combined_output();
-  assert_contains!(output, "Add @denotest/add");
+  assert_contains!(output, "Add jsr:@denotest/add");
   temp_dir.join("deno.json").assert_matches_json(json!({
     "imports": {
       "@denotest/add": "jsr:@denotest/add@~1.0.0"
@@ -118,7 +118,7 @@ fn add_multiple() {
     .run();
   output.assert_exit_code(0);
   let output = output.combined_output();
-  assert_contains!(output, "Add @denotest/add");
+  assert_contains!(output, "Add jsr:@denotest/add");
   temp_dir.join("deno.json").assert_matches_json(json!({
     "name": "@foo/bar",
     "version": "1.0.0",
@@ -138,7 +138,7 @@ fn add_npm() {
   let output = context.new_command().args("add npm:chalk@4.1").run();
   output.assert_exit_code(0);
   let output = output.combined_output();
-  assert_contains!(output, "Add chalk");
+  assert_contains!(output, "Add npm:chalk");
   temp_dir.join("deno.json").assert_matches_json(json!({
     "imports": {
       "chalk": "npm:chalk@^4.1.2"

filename: tests/specs/install/future_install_local_add_deno/install.out
patch: @@ -1,3 +1,3 @@
-Add @denotest/esm-basic - npm:@denotest/esm-basic@^1.0.0
+Add npm:@denotest/esm-basic@1.0.0
 Download http://localhost:4260/@denotest/esm-basic
 Download http://localhost:4260/@denotest/esm-basic/1.0.0.tgz

filename: tests/specs/install/future_install_local_add_npm/install.out
patch: @@ -1,4 +1,4 @@
-Add @denotest/esm-basic - npm:@denotest/esm-basic@^1.0.0
+Add npm:@denotest/esm-basic@1.0.0
 Download http://localhost:4260/@denotest/esm-basic
 Download http://localhost:4260/@denotest/esm-basic/1.0.0.tgz
 Initialize @denotest/esm-basic@1.0.0