Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(regression): show bare-node-builtin hint when using an import map #27632

Merged
merged 2 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 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 Expand Up @@ -1324,7 +1320,7 @@ mod test {
let specifier = ModuleSpecifier::parse("file:///file.ts").unwrap();
let err = import_map.resolve(input, &specifier).err().unwrap();
let err = ResolutionError::ResolverError {
error: Arc::new(ResolveError::Other(JsErrorBox::from_err(err))),
error: Arc::new(ResolveError::ImportMap(err)),
Copy link
Member Author

@dsherret dsherret Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost useless unit test lol

specifier: input.to_string(),
range: Range {
specifier,
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
Loading