mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix(publish): silence warnings for sloppy imports and node builtins with env var (#22760)
An undocumented "DENO_DISABLE_PEDANTIC_NODE_WARNINGS" env var can be used to silence warnings for sloppy imports and node builtins without `node:` prefix.
This commit is contained in:
parent
588dd5e669
commit
f0ec4fe1b8
6 changed files with 79 additions and 13 deletions
|
@ -101,6 +101,12 @@ pub fn npm_registry_url() -> &'static Url {
|
||||||
&NPM_REGISTRY_DEFAULT_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 {
|
pub fn jsr_url() -> &'static Url {
|
||||||
static JSR_URL: Lazy<Url> = Lazy::new(|| {
|
static JSR_URL: Lazy<Url> = Lazy::new(|| {
|
||||||
let env_var_name = "JSR_URL";
|
let env_var_name = "JSR_URL";
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::args::jsr_url;
|
||||||
use crate::args::CliOptions;
|
use crate::args::CliOptions;
|
||||||
use crate::args::Lockfile;
|
use crate::args::Lockfile;
|
||||||
use crate::args::TsTypeLib;
|
use crate::args::TsTypeLib;
|
||||||
|
use crate::args::DENO_DISABLE_PEDANTIC_NODE_WARNINGS;
|
||||||
use crate::cache;
|
use crate::cache;
|
||||||
use crate::cache::GlobalHttpCache;
|
use crate::cache::GlobalHttpCache;
|
||||||
use crate::cache::ModuleInfoCache;
|
use crate::cache::ModuleInfoCache;
|
||||||
|
@ -681,9 +682,11 @@ pub fn enhanced_resolution_error_message(error: &ResolutionError) -> String {
|
||||||
let mut message = format!("{error}");
|
let mut message = format!("{error}");
|
||||||
|
|
||||||
if let Some(specifier) = get_resolution_error_bare_node_specifier(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}\")."
|
"\nIf you want to use a built-in Node module, add a \"node:\" prefix (ex. \"node:{specifier}\")."
|
||||||
));
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message
|
message
|
||||||
|
|
|
@ -41,6 +41,7 @@ use std::sync::Arc;
|
||||||
use crate::args::package_json::PackageJsonDeps;
|
use crate::args::package_json::PackageJsonDeps;
|
||||||
use crate::args::JsxImportSourceConfig;
|
use crate::args::JsxImportSourceConfig;
|
||||||
use crate::args::PackageJsonDepsProvider;
|
use crate::args::PackageJsonDepsProvider;
|
||||||
|
use crate::args::DENO_DISABLE_PEDANTIC_NODE_WARNINGS;
|
||||||
use crate::colors;
|
use crate::colors;
|
||||||
use crate::node::CliNodeCodeTranslator;
|
use crate::node::CliNodeCodeTranslator;
|
||||||
use crate::npm::ByonmCliNpmResolver;
|
use crate::npm::ByonmCliNpmResolver;
|
||||||
|
@ -725,17 +726,20 @@ fn sloppy_imports_resolve(
|
||||||
};
|
};
|
||||||
// show a warning when this happens in order to drive
|
// show a warning when this happens in order to drive
|
||||||
// the user towards correcting these specifiers
|
// the user towards correcting these specifiers
|
||||||
log::warn!(
|
if !*DENO_DISABLE_PEDANTIC_NODE_WARNINGS {
|
||||||
"{} Sloppy module resolution {}\n at {}",
|
log::warn!(
|
||||||
crate::colors::yellow("Warning"),
|
"{} Sloppy module resolution {}\n at {}",
|
||||||
crate::colors::gray(format!("(hint: {})", hint_message)).to_string(),
|
crate::colors::yellow("Warning"),
|
||||||
if referrer_range.end == deno_graph::Position::zeroed() {
|
crate::colors::gray(format!("(hint: {})", hint_message)).to_string(),
|
||||||
// not worth showing the range in this case
|
if referrer_range.end == deno_graph::Position::zeroed() {
|
||||||
crate::colors::cyan(referrer_range.specifier.as_str()).to_string()
|
// not worth showing the range in this case
|
||||||
} else {
|
crate::colors::cyan(referrer_range.specifier.as_str()).to_string()
|
||||||
format_range_with_colors(referrer_range)
|
} else {
|
||||||
},
|
format_range_with_colors(referrer_range)
|
||||||
);
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
resolution.into_specifier().into_owned()
|
resolution.into_specifier().into_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,7 +792,9 @@ impl NpmResolver for CliGraphResolver {
|
||||||
} = range;
|
} = range;
|
||||||
let line = start.line + 1;
|
let line = start.line + 1;
|
||||||
let column = start.character + 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(
|
fn load_and_cache_npm_package_info(
|
||||||
|
|
|
@ -250,6 +250,23 @@ itest!(bare_node_builtins {
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(bare_node_builtins_warning_no_warnings {
|
||||||
|
args: "publish --token 'sadfasdf' --dry-run --unstable-bare-node-builtins",
|
||||||
|
output: "publish/bare_node_builtins_no_warnings.out",
|
||||||
|
cwd: Some("publish/bare_node_builtins"),
|
||||||
|
envs: env_vars_for_jsr_npm_tests()
|
||||||
|
.into_iter()
|
||||||
|
.chain(
|
||||||
|
vec![(
|
||||||
|
"DENO_DISABLE_PEDANTIC_NODE_WARNINGS".to_string(),
|
||||||
|
"1".to_string()
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
)
|
||||||
|
.collect(),
|
||||||
|
http_server: true,
|
||||||
|
});
|
||||||
|
|
||||||
itest!(sloppy_imports {
|
itest!(sloppy_imports {
|
||||||
args: "publish --token 'sadfasdf' --dry-run --unstable-sloppy-imports",
|
args: "publish --token 'sadfasdf' --dry-run --unstable-sloppy-imports",
|
||||||
output: "publish/sloppy_imports.out",
|
output: "publish/sloppy_imports.out",
|
||||||
|
@ -258,6 +275,23 @@ itest!(sloppy_imports {
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(sloppy_imports_no_warnings {
|
||||||
|
args: "publish --token 'sadfasdf' --dry-run --unstable-sloppy-imports",
|
||||||
|
output: "publish/sloppy_imports_no_warnings.out",
|
||||||
|
cwd: Some("publish/sloppy_imports"),
|
||||||
|
envs: env_vars_for_jsr_tests()
|
||||||
|
.into_iter()
|
||||||
|
.chain(
|
||||||
|
vec![(
|
||||||
|
"DENO_DISABLE_PEDANTIC_NODE_WARNINGS".to_string(),
|
||||||
|
"1".to_string()
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
)
|
||||||
|
.collect(),
|
||||||
|
http_server: true,
|
||||||
|
});
|
||||||
|
|
||||||
itest!(jsr_jsonc {
|
itest!(jsr_jsonc {
|
||||||
args: "publish --token 'sadfasdf'",
|
args: "publish --token 'sadfasdf'",
|
||||||
cwd: Some("publish/jsr_jsonc"),
|
cwd: Some("publish/jsr_jsonc"),
|
||||||
|
|
9
tests/testdata/publish/bare_node_builtins_no_warnings.out
vendored
Normal file
9
tests/testdata/publish/bare_node_builtins_no_warnings.out
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
Download http://localhost:4545/npm/registry/@types/node
|
||||||
|
Download http://localhost:4545/npm/registry/@types/node/node-18.8.2.tgz
|
||||||
|
Check file:///[WILDCARD]/publish/bare_node_builtins/mod.ts
|
||||||
|
Checking for slow types in the public API...
|
||||||
|
Check file:///[WILDCARD]/publish/bare_node_builtins/mod.ts
|
||||||
|
Simulating publish of @foo/bar@1.0.0 with files:
|
||||||
|
file:///[WILDCARD]/publish/bare_node_builtins/deno.json (87B)
|
||||||
|
file:///[WILDCARD]/publish/bare_node_builtins/mod.ts (121B)
|
||||||
|
Warning Aborting due to --dry-run
|
8
tests/testdata/publish/sloppy_imports_no_warnings.out
vendored
Normal file
8
tests/testdata/publish/sloppy_imports_no_warnings.out
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
Check file:///[WILDCARD]/publish/sloppy_imports/mod.ts
|
||||||
|
Checking for slow types in the public API...
|
||||||
|
Check file:///[WILDCARD]/publish/sloppy_imports/mod.ts
|
||||||
|
Simulating publish of @foo/bar@1.0.0 with files:
|
||||||
|
file:///[WILDCARD]/publish/sloppy_imports/b/index.ts (27B)
|
||||||
|
file:///[WILDCARD]/publish/sloppy_imports/deno.json (87B)
|
||||||
|
file:///[WILDCARD]/publish/sloppy_imports/mod.ts (35B)
|
||||||
|
Warning Aborting due to --dry-run
|
Loading…
Reference in a new issue