1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -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:
Bartek Iwańczuk 2024-03-07 13:59:57 +00:00 committed by GitHub
parent 588dd5e669
commit f0ec4fe1b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 79 additions and 13 deletions

View file

@ -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";

View file

@ -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,10 +682,12 @@ 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) {
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
}

View file

@ -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,6 +726,7 @@ fn sloppy_imports_resolve(
};
// show a warning when this happens in order to drive
// the user towards correcting these specifiers
if !*DENO_DISABLE_PEDANTIC_NODE_WARNINGS {
log::warn!(
"{} Sloppy module resolution {}\n at {}",
crate::colors::yellow("Warning"),
@ -736,6 +738,8 @@ fn sloppy_imports_resolve(
format_range_with_colors(referrer_range)
},
);
}
resolution.into_specifier().into_owned()
}
@ -788,8 +792,10 @@ impl NpmResolver for CliGraphResolver {
} = range;
let line = start.line + 1;
let column = start.character + 1;
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(
&self,

View file

@ -250,6 +250,23 @@ itest!(bare_node_builtins {
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 {
args: "publish --token 'sadfasdf' --dry-run --unstable-sloppy-imports",
output: "publish/sloppy_imports.out",
@ -258,6 +275,23 @@ itest!(sloppy_imports {
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 {
args: "publish --token 'sadfasdf'",
cwd: Some("publish/jsr_jsonc"),

View 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

View 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