mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
feat: add DENO_NO_PACKAGE_JSON
env var (#17926)
Depends on #17924 Part of #17916
This commit is contained in:
parent
7ad64283a1
commit
a27d0885f4
3 changed files with 18 additions and 5 deletions
|
@ -590,6 +590,7 @@ static ENV_VARIABLES_HELP: &str = r#"ENVIRONMENT VARIABLES:
|
|||
DENO_DIR Set the cache directory
|
||||
DENO_INSTALL_ROOT Set deno install's output directory
|
||||
(defaults to $HOME/.deno/bin)
|
||||
DENO_NO_PACKAGE_JSON Disables auto-resolution of package.json
|
||||
DENO_NO_PROMPT Set to disable permission prompts on access
|
||||
(alternative to passing --no-prompt on invocation)
|
||||
DENO_NO_UPDATE_CHECK Set to disable checking if a newer Deno version is
|
||||
|
|
|
@ -568,7 +568,10 @@ impl CliOptions {
|
|||
let maybe_config_file = ConfigFile::discover(&flags, &initial_cwd)?;
|
||||
|
||||
let mut maybe_package_json = None;
|
||||
if flags.config_flag == ConfigFlag::Disabled || flags.no_npm {
|
||||
if flags.config_flag == ConfigFlag::Disabled
|
||||
|| flags.no_npm
|
||||
|| has_flag_env_var("DENO_NO_PACKAGE_JSON")
|
||||
{
|
||||
log::debug!("package.json auto-discovery is disabled")
|
||||
} else if let Some(config_file) = &maybe_config_file {
|
||||
let specifier = config_file.specifier.clone();
|
||||
|
@ -1135,10 +1138,12 @@ fn resolve_files(
|
|||
|
||||
/// Resolves the no_prompt value based on the cli flags and environment.
|
||||
pub fn resolve_no_prompt(flags: &Flags) -> bool {
|
||||
flags.no_prompt || {
|
||||
let value = env::var("DENO_NO_PROMPT");
|
||||
matches!(value.as_ref().map(|s| s.as_str()), Ok("1"))
|
||||
}
|
||||
flags.no_prompt || has_flag_env_var("DENO_NO_PROMPT")
|
||||
}
|
||||
|
||||
fn has_flag_env_var(name: &str) -> bool {
|
||||
let value = env::var(name);
|
||||
matches!(value.as_ref().map(|s| s.as_str()), Ok("1"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -2786,6 +2786,13 @@ itest!(package_json_not_auto_discovered_no_npm {
|
|||
cwd: Some("run/with_package_json/no_deno_json/"),
|
||||
});
|
||||
|
||||
itest!(package_json_not_auto_discovered_env_var {
|
||||
args: "run -L debug -A noconfig.ts",
|
||||
output: "run/with_package_json/no_deno_json/noconfig.out",
|
||||
cwd: Some("run/with_package_json/no_deno_json/"),
|
||||
envs: vec![("DENO_NO_PACKAGE_JSON".to_string(), "1".to_string())],
|
||||
});
|
||||
|
||||
itest!(
|
||||
package_json_auto_discovered_node_modules_relative_package_json {
|
||||
args: "run -A main.js",
|
||||
|
|
Loading…
Reference in a new issue