Skip to content

Commit

Permalink
fix(regression): show bare-node-builtin hint when using an import map
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jan 11, 2025
1 parent c27248a commit 1e44df3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
10 changes: 3 additions & 7 deletions cli/graph_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use deno_runtime::deno_permissions::PermissionsContainer;
use deno_semver::jsr::JsrDepPackageReq;
use deno_semver::package::PackageNv;
use deno_semver::SmallStackString;
use import_map::ImportMapError;
use node_resolver::InNpmPackageChecker;

use crate::args::config_to_deno_graph_workspace_member;
Expand Down Expand Up @@ -1024,14 +1023,11 @@ fn get_resolution_error_bare_specifier(
{
Some(specifier.as_str())
} else if let ResolutionError::ResolverError { error, .. } = error {
if let ResolveError::Other(error) = (*error).as_ref() {
if let Some(import_map::ImportMapErrorKind::UnmappedBareSpecifier(
if let ResolveError::ImportMap(error) = (*error).as_ref() {
if let import_map::ImportMapErrorKind::UnmappedBareSpecifier(
specifier,
_,
)) = error
.as_any()
.downcast_ref::<ImportMapError>()
.map(|e| &**e)
) = error.as_kind()
{
Some(specifier.as_str())
} else {
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/run/node_prefix_missing/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"output": "main.ts.out",
"exitCode": 1
},
"basic_no_config": {
"args": "run --quiet --no-config main.ts",
"output": "main_no_config.out",
"exitCode": 1
},
"unstable_bare_node_builtins_enabled": {
"args": "run --unstable-bare-node-builtins main.ts",
"output": "feature_enabled.out"
Expand Down
1 change: 1 addition & 0 deletions tests/specs/run/node_prefix_missing/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"imports": {},
"unstable": ["bare-node-builtins"]
}
3 changes: 3 additions & 0 deletions tests/specs/run/node_prefix_missing/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"imports": {}
}
2 changes: 1 addition & 1 deletion tests/specs/run/node_prefix_missing/main.ts.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
error: Relative import path "fs" not prefixed with / or ./ or ../
error: Relative import path "fs" not prefixed with / or ./ or ../ and not in import map from "[WILDLINE]/main.ts"
hint: If you want to use a built-in Node module, add a "node:" prefix (ex. "node:fs").
at file:///[WILDCARD]/main.ts:1:16
3 changes: 3 additions & 0 deletions tests/specs/run/node_prefix_missing/main_no_config.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
error: Relative import path "fs" not prefixed with / or ./ or ../
hint: If you want to use a built-in Node module, add a "node:" prefix (ex. "node:fs").
at file:///[WILDCARD]/main.ts:1:16

0 comments on commit 1e44df3

Please sign in to comment.