diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/args/mod.rs | 6 | ||||
-rw-r--r-- | cli/graph_util.rs | 5 | ||||
-rw-r--r-- | cli/resolver.rs | 30 |
3 files changed, 28 insertions, 13 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs index af681104c..acdc96526 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -101,6 +101,12 @@ pub fn npm_registry_url() -> &'static Url { &NPM_REGISTRY_DEFAULT_URL } +pub static DENO_DISABLE_PEDANTIC_NODE_WARNINGS: Lazy<bool> = Lazy::new(|| { + std::env::var("DENO_DISABLE_PEDANTIC_NODE_WARNINGS") + .ok() + .is_some() +}); + pub fn jsr_url() -> &'static Url { static JSR_URL: Lazy<Url> = Lazy::new(|| { let env_var_name = "JSR_URL"; diff --git a/cli/graph_util.rs b/cli/graph_util.rs index f1aa44328..b84cb3bb6 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -4,6 +4,7 @@ use crate::args::jsr_url; use crate::args::CliOptions; use crate::args::Lockfile; use crate::args::TsTypeLib; +use crate::args::DENO_DISABLE_PEDANTIC_NODE_WARNINGS; use crate::cache; use crate::cache::GlobalHttpCache; use crate::cache::ModuleInfoCache; @@ -681,9 +682,11 @@ pub fn enhanced_resolution_error_message(error: &ResolutionError) -> String { let mut message = format!("{error}"); if let Some(specifier) = get_resolution_error_bare_node_specifier(error) { - message.push_str(&format!( + if !*DENO_DISABLE_PEDANTIC_NODE_WARNINGS { + message.push_str(&format!( "\nIf you want to use a built-in Node module, add a \"node:\" prefix (ex. \"node:{specifier}\")." )); + } } message diff --git a/cli/resolver.rs b/cli/resolver.rs index e1a2145d3..8043e1ede 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -41,6 +41,7 @@ use std::sync::Arc; use crate::args::package_json::PackageJsonDeps; use crate::args::JsxImportSourceConfig; use crate::args::PackageJsonDepsProvider; +use crate::args::DENO_DISABLE_PEDANTIC_NODE_WARNINGS; use crate::colors; use crate::node::CliNodeCodeTranslator; use crate::npm::ByonmCliNpmResolver; @@ -725,17 +726,20 @@ fn sloppy_imports_resolve( }; // show a warning when this happens in order to drive // the user towards correcting these specifiers - log::warn!( - "{} Sloppy module resolution {}\n at {}", - crate::colors::yellow("Warning"), - crate::colors::gray(format!("(hint: {})", hint_message)).to_string(), - if referrer_range.end == deno_graph::Position::zeroed() { - // not worth showing the range in this case - crate::colors::cyan(referrer_range.specifier.as_str()).to_string() - } else { - format_range_with_colors(referrer_range) - }, - ); + if !*DENO_DISABLE_PEDANTIC_NODE_WARNINGS { + log::warn!( + "{} Sloppy module resolution {}\n at {}", + crate::colors::yellow("Warning"), + crate::colors::gray(format!("(hint: {})", hint_message)).to_string(), + if referrer_range.end == deno_graph::Position::zeroed() { + // not worth showing the range in this case + crate::colors::cyan(referrer_range.specifier.as_str()).to_string() + } else { + format_range_with_colors(referrer_range) + }, + ); + } + resolution.into_specifier().into_owned() } @@ -788,7 +792,9 @@ impl NpmResolver for CliGraphResolver { } = range; let line = start.line + 1; let column = start.character + 1; - log::warn!("Warning: Resolving \"{module_name}\" as \"node:{module_name}\" at {specifier}:{line}:{column}. If you want to use a built-in Node module, add a \"node:\" prefix.") + if !*DENO_DISABLE_PEDANTIC_NODE_WARNINGS { + log::warn!("Warning: Resolving \"{module_name}\" as \"node:{module_name}\" at {specifier}:{line}:{column}. If you want to use a built-in Node module, add a \"node:\" prefix.") + } } fn load_and_cache_npm_package_info( |