fix(lock): add --no-lock flag to disable auto discovery of lock file (#16526)

This commit is contained in:
Bartek Iwańczuk 2022-11-03 16:42:56 +01:00 committed by GitHub
parent a99539bd4d
commit dae3940519
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 64 additions and 0 deletions

View file

@ -317,6 +317,7 @@ pub struct Flags {
pub lock: Option<PathBuf>,
pub log_level: Option<Level>,
pub no_remote: bool,
pub no_lock: bool,
pub no_npm: bool,
pub no_prompt: bool,
pub reload: bool,
@ -1772,6 +1773,7 @@ fn compile_args(app: Command) -> Command {
.arg(reload_arg())
.arg(lock_arg())
.arg(lock_write_arg())
.arg(no_lock_arg())
.arg(ca_file_arg())
}
@ -1786,6 +1788,7 @@ fn compile_args_without_check_args(app: Command) -> Command {
.arg(reload_arg())
.arg(lock_arg())
.arg(lock_write_arg())
.arg(no_lock_arg())
.arg(ca_file_arg())
}
@ -2160,6 +2163,14 @@ fn lock_write_arg<'a>() -> Arg<'a> {
.help("Force overwriting the lock file.")
}
fn no_lock_arg<'a>() -> Arg<'a> {
Arg::new("no-lock")
.long("no-lock")
.help("Disable auto discovery of the lock file.")
.conflicts_with("lock")
.conflicts_with("lock-write")
}
static CONFIG_HELP: Lazy<String> = Lazy::new(|| {
format!(
"The configuration file can be used to configure different aspects of \
@ -3097,6 +3108,9 @@ fn lock_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
if matches.is_present("lock-write") {
flags.lock_write = true;
}
if matches.is_present("no-lock") {
flags.no_lock = true;
}
}
fn lock_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
@ -5343,6 +5357,18 @@ mod tests {
}
);
let r = flags_from_vec(svec!["deno", "run", "--no-lock", "script.ts"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(),
}),
no_lock: true,
..Flags::default()
}
);
let r = flags_from_vec(svec![
"deno",
"run",
@ -5393,6 +5419,19 @@ mod tests {
..Flags::default()
}
);
let r =
flags_from_vec(svec!["deno", "run", "--lock", "--no-lock", "script.ts"]);
assert!(r.is_err(),);
let r = flags_from_vec(svec![
"deno",
"run",
"--lock-write",
"--no-lock",
"script.ts"
]);
assert!(r.is_err(),);
}
#[test]

View file

@ -98,6 +98,10 @@ impl Lockfile {
flags: &Flags,
maybe_config_file: Option<&ConfigFile>,
) -> Result<Option<Lockfile>, AnyError> {
if flags.no_lock {
return Ok(None);
}
let filename = match flags.lock {
Some(ref lock) => PathBuf::from(lock),
None if flags.unstable => match maybe_config_file {

View file

@ -3635,3 +3635,10 @@ itest!(auto_discover_lockfile {
http_server: true,
exit_code: 10,
});
itest!(no_lock_flag {
args: "run --no-lock run/no_lock_flag/main.ts",
output: "run/no_lock_flag/main.out",
http_server: true,
exit_code: 0,
});

View file

@ -0,0 +1,3 @@
{
"tasks": {}
}

View file

@ -0,0 +1,7 @@
{
"version": "2",
"remote": {
"http://localhost:4545/subdir/mod2.ts": "cae1d3e9f3c38cd415ff52dff854be8f3d17d35f8d7b3d285e813fb0f6393a2f",
"http://localhost:4545/subdir/print_hello.ts": "foobar"
}
}

View file

@ -0,0 +1,2 @@
Download http://localhost:4545/subdir/mod2.ts
Download http://localhost:4545/subdir/print_hello.ts

View file

@ -0,0 +1 @@
import "http://localhost:4545/subdir/mod2.ts";

View file

@ -281,6 +281,7 @@ pub fn compile_to_runtime_flags(
.unsafely_ignore_certificate_errors
.clone(),
no_remote: false,
no_lock: false,
no_npm: false,
no_prompt: flags.no_prompt,
reload: false,