From 7c8b55b584b028542bbf33a253e50deea1e98345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 10 Dec 2024 23:25:29 +0000 Subject: [PATCH] fix(outdated): error when there are no config files (#27306) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit changes "deno outdated" subcommand to error out if run in a directory that has no config file (including parent directories). This matches "pnpm" behavior. Also added tests for filtering that yields no results, to ensure that it exists cleanly, that also matches "pnpm" behavior. Closes https://github.com/denoland/deno/issues/27287 --------- Signed-off-by: Bartek IwaƄczuk Co-authored-by: David Sherret --- cli/tools/registry/pm/outdated.rs | 10 ++++++++++ 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/package_json/__test__.jsonc | 10 ++++++++++ 5 files changed, 46 insertions(+) create mode 100644 tests/specs/update/no_config_file/__test__.jsonc diff --git a/cli/tools/registry/pm/outdated.rs b/cli/tools/registry/pm/outdated.rs index 9389f59678..aef65a5de0 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; @@ -197,6 +198,15 @@ 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().display(), + ); + } + 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 c57115fb02..7983d2c56f 100644 --- a/tests/specs/update/deno_json/__test__.jsonc +++ b/tests/specs/update/deno_json/__test__.jsonc @@ -27,6 +27,11 @@ "args": "outdated", "output": "outdated.out" }, + { + // Filtering that matches nothing, should exit cleanly + "args": "outdated foobar", + "output": "" + }, { // Respect `--quiet flag and don't print hint how to update "args": "outdated --quiet", @@ -43,6 +48,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 8c846467d4..9810e15bdd 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 0000000000..1032e79279 --- /dev/null +++ b/tests/specs/update/no_config_file/__test__.jsonc @@ -0,0 +1,6 @@ +{ + "tempDir": true, + "args": "outdated", + "exitCode": 1, + "output": "error: No deno.json or package.json in \"[WILDLINE]\".\n" +} diff --git a/tests/specs/update/package_json/__test__.jsonc b/tests/specs/update/package_json/__test__.jsonc index 19d576dfc0..b86b9956cc 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": "" } ] },