mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 04:48:52 -05:00
fix(lock): add --no-lock flag to disable auto discovery of lock file (#16526)
This commit is contained in:
parent
a99539bd4d
commit
dae3940519
8 changed files with 64 additions and 0 deletions
|
@ -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]
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
|
3
cli/tests/testdata/run/no_lock_flag/deno.json
vendored
Normal file
3
cli/tests/testdata/run/no_lock_flag/deno.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"tasks": {}
|
||||
}
|
7
cli/tests/testdata/run/no_lock_flag/deno.lock
vendored
Normal file
7
cli/tests/testdata/run/no_lock_flag/deno.lock
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"version": "2",
|
||||
"remote": {
|
||||
"http://localhost:4545/subdir/mod2.ts": "cae1d3e9f3c38cd415ff52dff854be8f3d17d35f8d7b3d285e813fb0f6393a2f",
|
||||
"http://localhost:4545/subdir/print_hello.ts": "foobar"
|
||||
}
|
||||
}
|
2
cli/tests/testdata/run/no_lock_flag/main.out
vendored
Normal file
2
cli/tests/testdata/run/no_lock_flag/main.out
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
Download http://localhost:4545/subdir/mod2.ts
|
||||
Download http://localhost:4545/subdir/print_hello.ts
|
1
cli/tests/testdata/run/no_lock_flag/main.ts
vendored
Normal file
1
cli/tests/testdata/run/no_lock_flag/main.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
import "http://localhost:4545/subdir/mod2.ts";
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue