From 178a7c086669047afb2c163ee23cae1552ed0566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 5 Sep 2024 10:24:41 +0200 Subject: [PATCH 1/2] fix: update hint for `deno add ` --- cli/graph_util.rs | 4 ++-- .../cache/with_bare_import/095_cache_with_bare_import.ts.out | 2 +- .../check/with_bare_import/095_cache_with_bare_import.ts.out | 2 +- tests/specs/run/bare_specifier_without_import/main.out | 2 +- tests/testdata/run/error_type_definitions.ts.out | 2 +- tests/testdata/run/with_package_json/with_stop/main.out | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cli/graph_util.rs b/cli/graph_util.rs index f3ac64a434c75a..717993d50c528b 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -735,8 +735,8 @@ pub fn enhanced_resolution_error_message(error: &ResolutionError) -> String { } else { get_import_prefix_missing_error(error).map(|specifier| { format!( - "If you want to use a JSR or npm package, try running `deno add {}`", - specifier + "If you want to use a JSR or npm package, try running `deno add jsr:{}` or `deno add npm:{}`", + specifier, specifier ) }) }; diff --git a/tests/specs/cache/with_bare_import/095_cache_with_bare_import.ts.out b/tests/specs/cache/with_bare_import/095_cache_with_bare_import.ts.out index 50daf8041919df..54e56a69783313 100644 --- a/tests/specs/cache/with_bare_import/095_cache_with_bare_import.ts.out +++ b/tests/specs/cache/with_bare_import/095_cache_with_bare_import.ts.out @@ -1,3 +1,3 @@ [WILDCARD]error: Relative import path "foo" not prefixed with / or ./ or ../ - hint: If you want to use a JSR or npm package, try running `deno add foo` + hint: If you want to use a JSR or npm package, try running `deno add jsr:foo` or `deno add npm:foo` at file:///[WILDCARD]/095_cache_with_bare_import.ts:[WILDCARD] diff --git a/tests/specs/check/with_bare_import/095_cache_with_bare_import.ts.out b/tests/specs/check/with_bare_import/095_cache_with_bare_import.ts.out index 50daf8041919df..54e56a69783313 100644 --- a/tests/specs/check/with_bare_import/095_cache_with_bare_import.ts.out +++ b/tests/specs/check/with_bare_import/095_cache_with_bare_import.ts.out @@ -1,3 +1,3 @@ [WILDCARD]error: Relative import path "foo" not prefixed with / or ./ or ../ - hint: If you want to use a JSR or npm package, try running `deno add foo` + hint: If you want to use a JSR or npm package, try running `deno add jsr:foo` or `deno add npm:foo` at file:///[WILDCARD]/095_cache_with_bare_import.ts:[WILDCARD] diff --git a/tests/specs/run/bare_specifier_without_import/main.out b/tests/specs/run/bare_specifier_without_import/main.out index a873f2727cc269..59ea233922a861 100644 --- a/tests/specs/run/bare_specifier_without_import/main.out +++ b/tests/specs/run/bare_specifier_without_import/main.out @@ -1,3 +1,3 @@ error: Relative import path "@std/dotenv/load" not prefixed with / or ./ or ../ - hint: If you want to use a JSR or npm package, try running `deno add @std/dotenv/load` + hint: If you want to use a JSR or npm package, try running `deno add jsr:@std/dotenv/load` or `deno add npm:@std/dotenv/load` at [WILDCARD]bare_specifier_without_import/main.ts:1:8 diff --git a/tests/testdata/run/error_type_definitions.ts.out b/tests/testdata/run/error_type_definitions.ts.out index 7a71b4ebe8c3bf..057c21df51c415 100644 --- a/tests/testdata/run/error_type_definitions.ts.out +++ b/tests/testdata/run/error_type_definitions.ts.out @@ -1,3 +1,3 @@ [WILDCARD]error: Failed resolving types. Relative import path "baz" not prefixed with / or ./ or ../ - hint: If you want to use a JSR or npm package, try running `deno add baz` + hint: If you want to use a JSR or npm package, try running `deno add jsr:baz` or `deno add npm:baz` at [WILDCARD]/type_definitions/bar.d.ts:[WILDCARD] diff --git a/tests/testdata/run/with_package_json/with_stop/main.out b/tests/testdata/run/with_package_json/with_stop/main.out index afab4910c6bc19..44098a2d863c5c 100644 --- a/tests/testdata/run/with_package_json/with_stop/main.out +++ b/tests/testdata/run/with_package_json/with_stop/main.out @@ -1,5 +1,5 @@ [WILDCARD]Config file found at '[WILDCARD]with_package_json[WILDCARD]with_stop[WILDCARD]some[WILDCARD]nested[WILDCARD]deno.json' [WILDCARD] error: Relative import path "chalk" not prefixed with / or ./ or ../ - hint: If you want to use a JSR or npm package, try running `deno add chalk` + hint: If you want to use a JSR or npm package, try running `deno add jsr:chalk` or `deno add npm:chalk` at file:///[WILDCARD]with_package_json/with_stop/some/nested/dir/main.ts:3:19 From 8286dec0a9262df9f4566b83d9278a3b56d97bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 5 Sep 2024 10:30:04 +0200 Subject: [PATCH 2/2] only surface for local specifiers --- cli/graph_util.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 717993d50c528b..d7f007a7c37e37 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -881,24 +881,29 @@ fn get_import_prefix_missing_error(error: &ResolutionError) -> Option<&str> { let mut maybe_specifier = None; if let ResolutionError::InvalidSpecifier { error: SpecifierError::ImportPrefixMissing { specifier, .. }, - .. + range, } = error { - maybe_specifier = Some(specifier); - } else if let ResolutionError::ResolverError { error, .. } = error { - match error.as_ref() { - ResolveError::Specifier(specifier_error) => { - if let SpecifierError::ImportPrefixMissing { specifier, .. } = - specifier_error - { - maybe_specifier = Some(specifier); + if range.specifier.scheme() == "file" { + maybe_specifier = Some(specifier); + } + } else if let ResolutionError::ResolverError { error, range, .. } = error { + if range.specifier.scheme() == "file" { + match error.as_ref() { + ResolveError::Specifier(specifier_error) => { + if let SpecifierError::ImportPrefixMissing { specifier, .. } = + specifier_error + { + maybe_specifier = Some(specifier); + } } - } - ResolveError::Other(other_error) => { - if let Some(SpecifierError::ImportPrefixMissing { specifier, .. }) = - other_error.downcast_ref::() - { - maybe_specifier = Some(specifier); + ResolveError::Other(other_error) => { + if let Some(SpecifierError::ImportPrefixMissing { + specifier, .. + }) = other_error.downcast_ref::() + { + maybe_specifier = Some(specifier); + } } } }