From 6a02c78ea763eae60e5aed54a8b327462e8d0480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 10 Dec 2024 03:38:47 +0100 Subject: [PATCH 1/8] fix(outdated): error when there are no config files or lockfile --- cli/tools/registry/pm/outdated.rs | 9 +++++++++ tests/specs/update/deno_json/__test__.jsonc | 10 ++++++++++ tests/specs/update/mixed_workspace/__test__.jsonc | 10 ++++++++++ tests/specs/update/no_config_file/__test__.jsonc | 6 ++++++ tests/specs/update/no_lockfile/__test__.jsonc | 6 ++++++ tests/specs/update/package_json/__test__.jsonc | 10 ++++++++++ 6 files changed, 51 insertions(+) create mode 100644 tests/specs/update/no_config_file/__test__.jsonc create mode 100644 tests/specs/update/no_lockfile/__test__.jsonc diff --git a/cli/tools/registry/pm/outdated.rs b/cli/tools/registry/pm/outdated.rs index 2a29014267d67e..6c0f29d90b425c 100644 --- a/cli/tools/registry/pm/outdated.rs +++ b/cli/tools/registry/pm/outdated.rs @@ -3,6 +3,7 @@ use std::collections::HashSet; use std::sync::Arc; +use deno_core::anyhow::bail; use deno_core::error::AnyError; use deno_semver::package::PackageNv; use deno_semver::package::PackageReq; @@ -179,6 +180,14 @@ pub async fn outdated( let jsr_fetch_resolver = Arc::new(JsrFetchResolver::new(file_fetcher.clone())); + if cli_options.maybe_lockfile().is_none() { + bail!( + "No lockfile in {:?}. Run {} to generate one.", + cli_options.initial_cwd(), + colors::underline("deno install") + ); + } + let args = dep_manager_args( &factory, cli_options, diff --git a/tests/specs/update/deno_json/__test__.jsonc b/tests/specs/update/deno_json/__test__.jsonc index 8b4aa26b5c082d..36591dbc557125 100644 --- a/tests/specs/update/deno_json/__test__.jsonc +++ b/tests/specs/update/deno_json/__test__.jsonc @@ -26,6 +26,11 @@ { "args": "outdated", "output": "outdated.out" + }, + { + // Filtering that matches nothing, should exit cleanly + "args": "outdated foobar", + "output": "" } ] }, @@ -38,6 +43,11 @@ { "args": "outdated --compatible", "output": "outdated_compatible.out" + }, + { + // Filtering that matches nothing, should exit cleanly + "args": "outdated --compatible foobar", + "output": "" } ] }, diff --git a/tests/specs/update/mixed_workspace/__test__.jsonc b/tests/specs/update/mixed_workspace/__test__.jsonc index 8c846467d47894..9810e15bdd6eac 100644 --- a/tests/specs/update/mixed_workspace/__test__.jsonc +++ b/tests/specs/update/mixed_workspace/__test__.jsonc @@ -26,6 +26,11 @@ { "args": "outdated", "output": "print_outdated/root.out" + }, + { + // Filtering that matches nothing, should exit cleanly + "args": "outdated foobar", + "output": "" } ] }, @@ -38,6 +43,11 @@ { "args": "outdated --recursive", "output": "print_outdated/recursive.out" + }, + { + // Filtering that matches nothing, should exit cleanly + "args": "outdated foobar", + "output": "" } ] }, diff --git a/tests/specs/update/no_config_file/__test__.jsonc b/tests/specs/update/no_config_file/__test__.jsonc new file mode 100644 index 00000000000000..8014d9b16fcf34 --- /dev/null +++ b/tests/specs/update/no_config_file/__test__.jsonc @@ -0,0 +1,6 @@ +{ + "tempDir": true, + "args": "outdated", + "exitCode": 0, + "output": "blahblahblah" +} diff --git a/tests/specs/update/no_lockfile/__test__.jsonc b/tests/specs/update/no_lockfile/__test__.jsonc new file mode 100644 index 00000000000000..c78285351e8fb5 --- /dev/null +++ b/tests/specs/update/no_lockfile/__test__.jsonc @@ -0,0 +1,6 @@ +{ + "tempDir": true, + "args": "outdated", + "exitCode": 1, + "output": "error: No lockfile in \"[WILDCARD]\". Run deno install to generate one.\n" +} diff --git a/tests/specs/update/package_json/__test__.jsonc b/tests/specs/update/package_json/__test__.jsonc index 19d576dfc00194..b86b9956cc7b86 100644 --- a/tests/specs/update/package_json/__test__.jsonc +++ b/tests/specs/update/package_json/__test__.jsonc @@ -25,6 +25,11 @@ { "args": "outdated", "output": "outdated.out" + }, + { + // Filtering that matches nothing, should exit cleanly + "args": "outdated foobar", + "output": "" } ] }, @@ -37,6 +42,11 @@ { "args": "outdated --compatible", "output": "outdated_compatible.out" + }, + { + // Filtering that matches nothing, should exit cleanly + "args": "outdated --compatible foobar", + "output": "" } ] }, From 00d64c3d420cacf546080b7f04297c0994269135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 10 Dec 2024 04:02:07 +0100 Subject: [PATCH 2/8] no way to tell if the lockfile has just been created (and not flushed to disk yet) --- cli/tools/registry/pm/outdated.rs | 10 ++++++++++ tests/specs/update/no_config_file/__test__.jsonc | 4 ++-- tests/specs/update/no_lockfile/deno.json | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/specs/update/no_lockfile/deno.json diff --git a/cli/tools/registry/pm/outdated.rs b/cli/tools/registry/pm/outdated.rs index 6c0f29d90b425c..6876b7deb8e424 100644 --- a/cli/tools/registry/pm/outdated.rs +++ b/cli/tools/registry/pm/outdated.rs @@ -180,6 +180,16 @@ pub async fn outdated( let jsr_fetch_resolver = Arc::new(JsrFetchResolver::new(file_fetcher.clone())); + if !cli_options.start_dir.has_deno_json() + && !cli_options.start_dir.has_pkg_json() + { + bail!( + "No deno.json or package.json in {:?}.", + cli_options.initial_cwd(), + ); + } + + eprintln!("cli lockfile {:#?}", cli_options.maybe_lockfile()); if cli_options.maybe_lockfile().is_none() { bail!( "No lockfile in {:?}. Run {} to generate one.", diff --git a/tests/specs/update/no_config_file/__test__.jsonc b/tests/specs/update/no_config_file/__test__.jsonc index 8014d9b16fcf34..ce1e141ddf1c61 100644 --- a/tests/specs/update/no_config_file/__test__.jsonc +++ b/tests/specs/update/no_config_file/__test__.jsonc @@ -1,6 +1,6 @@ { "tempDir": true, "args": "outdated", - "exitCode": 0, - "output": "blahblahblah" + "exitCode": 1, + "output": "error: No deno.json or package.json in \"[WILDCARD]\".\n" } diff --git a/tests/specs/update/no_lockfile/deno.json b/tests/specs/update/no_lockfile/deno.json new file mode 100644 index 00000000000000..0967ef424bce67 --- /dev/null +++ b/tests/specs/update/no_lockfile/deno.json @@ -0,0 +1 @@ +{} From e7273550522a4cc5d8583d7ca0e7359b8af63047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 10 Dec 2024 04:04:45 +0100 Subject: [PATCH 3/8] lol, there is --- cli/tools/registry/pm/outdated.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cli/tools/registry/pm/outdated.rs b/cli/tools/registry/pm/outdated.rs index 6876b7deb8e424..8a31b2759791e7 100644 --- a/cli/tools/registry/pm/outdated.rs +++ b/cli/tools/registry/pm/outdated.rs @@ -189,8 +189,12 @@ pub async fn outdated( ); } - eprintln!("cli lockfile {:#?}", cli_options.maybe_lockfile()); - if cli_options.maybe_lockfile().is_none() { + let lockfile_exists = match &cli_options.maybe_lockfile() { + Some(lockfile) => lockfile.filename.exists(), + None => false, + }; + + if !lockfile_exists { bail!( "No lockfile in {:?}. Run {} to generate one.", cli_options.initial_cwd(), From 60b94748bb507d63cb6cc8273809d435185010e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 10 Dec 2024 04:15:06 +0100 Subject: [PATCH 4/8] use cformat! --- cli/tools/registry/pm/outdated.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/tools/registry/pm/outdated.rs b/cli/tools/registry/pm/outdated.rs index 8a31b2759791e7..c26e4d62320c21 100644 --- a/cli/tools/registry/pm/outdated.rs +++ b/cli/tools/registry/pm/outdated.rs @@ -196,9 +196,12 @@ pub async fn outdated( if !lockfile_exists { bail!( - "No lockfile in {:?}. Run {} to generate one.", - cli_options.initial_cwd(), - colors::underline("deno install") + "{}", + color_print::cformat!( + "No lockfile in {:?}. Run {} to generate one.", + cli_options.initial_cwd(), + "deno install" + ) ); } From 951d1e22794a18adced7f9514fdc258e949b613e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 10 Dec 2024 14:41:47 +0100 Subject: [PATCH 5/8] Update tests/specs/update/no_lockfile/__test__.jsonc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Sherret Signed-off-by: Bartek Iwańczuk --- tests/specs/update/no_lockfile/__test__.jsonc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/specs/update/no_lockfile/__test__.jsonc b/tests/specs/update/no_lockfile/__test__.jsonc index c78285351e8fb5..07441668d14064 100644 --- a/tests/specs/update/no_lockfile/__test__.jsonc +++ b/tests/specs/update/no_lockfile/__test__.jsonc @@ -2,5 +2,5 @@ "tempDir": true, "args": "outdated", "exitCode": 1, - "output": "error: No lockfile in \"[WILDCARD]\". Run deno install to generate one.\n" + "output": "error: No lockfile in \"[WILDLINE]\". Run deno install to generate one.\n" } From 8947700923daebc32812b23f86d674d4d4f307e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 10 Dec 2024 14:41:52 +0100 Subject: [PATCH 6/8] Update tests/specs/update/no_config_file/__test__.jsonc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Sherret Signed-off-by: Bartek Iwańczuk --- tests/specs/update/no_config_file/__test__.jsonc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/specs/update/no_config_file/__test__.jsonc b/tests/specs/update/no_config_file/__test__.jsonc index ce1e141ddf1c61..1032e79279f0b2 100644 --- a/tests/specs/update/no_config_file/__test__.jsonc +++ b/tests/specs/update/no_config_file/__test__.jsonc @@ -2,5 +2,5 @@ "tempDir": true, "args": "outdated", "exitCode": 1, - "output": "error: No deno.json or package.json in \"[WILDCARD]\".\n" + "output": "error: No deno.json or package.json in \"[WILDLINE]\".\n" } From 3313ba65f1b2fe0c3c4440afc25de0b296db757e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 10 Dec 2024 14:41:59 +0100 Subject: [PATCH 7/8] Update cli/tools/registry/pm/outdated.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Sherret Signed-off-by: Bartek Iwańczuk --- cli/tools/registry/pm/outdated.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/tools/registry/pm/outdated.rs b/cli/tools/registry/pm/outdated.rs index c26e4d62320c21..b9031bf2ebdc10 100644 --- a/cli/tools/registry/pm/outdated.rs +++ b/cli/tools/registry/pm/outdated.rs @@ -184,8 +184,8 @@ pub async fn outdated( && !cli_options.start_dir.has_pkg_json() { bail!( - "No deno.json or package.json in {:?}.", - cli_options.initial_cwd(), + "No deno.json or package.json in \"{}\".", + cli_options.initial_cwd().display(), ); } From 746667e00a9061aa1114aad94e54ce87ee35ac7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 10 Dec 2024 23:45:02 +0100 Subject: [PATCH 8/8] revert lockfile changes --- cli/tools/registry/pm/outdated.rs | 16 ---------------- tests/specs/update/no_lockfile/__test__.jsonc | 6 ------ tests/specs/update/no_lockfile/deno.json | 1 - 3 files changed, 23 deletions(-) delete mode 100644 tests/specs/update/no_lockfile/__test__.jsonc delete mode 100644 tests/specs/update/no_lockfile/deno.json diff --git a/cli/tools/registry/pm/outdated.rs b/cli/tools/registry/pm/outdated.rs index ef7ea3730eceb1..aef65a5de00a3f 100644 --- a/cli/tools/registry/pm/outdated.rs +++ b/cli/tools/registry/pm/outdated.rs @@ -207,22 +207,6 @@ pub async fn outdated( ); } - let lockfile_exists = match &cli_options.maybe_lockfile() { - Some(lockfile) => lockfile.filename.exists(), - None => false, - }; - - if !lockfile_exists { - bail!( - "{}", - color_print::cformat!( - "No lockfile in {:?}. Run {} to generate one.", - cli_options.initial_cwd(), - "deno install" - ) - ); - } - let args = dep_manager_args( &factory, cli_options, diff --git a/tests/specs/update/no_lockfile/__test__.jsonc b/tests/specs/update/no_lockfile/__test__.jsonc deleted file mode 100644 index 07441668d14064..00000000000000 --- a/tests/specs/update/no_lockfile/__test__.jsonc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "tempDir": true, - "args": "outdated", - "exitCode": 1, - "output": "error: No lockfile in \"[WILDLINE]\". Run deno install to generate one.\n" -} diff --git a/tests/specs/update/no_lockfile/deno.json b/tests/specs/update/no_lockfile/deno.json deleted file mode 100644 index 0967ef424bce67..00000000000000 --- a/tests/specs/update/no_lockfile/deno.json +++ /dev/null @@ -1 +0,0 @@ -{}