From dae3940519d626ddfeb954e3f3d7ebe8b83067bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 3 Nov 2022 16:42:56 +0100 Subject: [PATCH] fix(lock): add --no-lock flag to disable auto discovery of lock file (#16526) --- cli/args/flags.rs | 39 +++++++++++++++++++ cli/lockfile.rs | 4 ++ cli/tests/integration/run_tests.rs | 7 ++++ cli/tests/testdata/run/no_lock_flag/deno.json | 3 ++ cli/tests/testdata/run/no_lock_flag/deno.lock | 7 ++++ cli/tests/testdata/run/no_lock_flag/main.out | 2 + cli/tests/testdata/run/no_lock_flag/main.ts | 1 + cli/tools/standalone.rs | 1 + 8 files changed, 64 insertions(+) create mode 100644 cli/tests/testdata/run/no_lock_flag/deno.json create mode 100644 cli/tests/testdata/run/no_lock_flag/deno.lock create mode 100644 cli/tests/testdata/run/no_lock_flag/main.out create mode 100644 cli/tests/testdata/run/no_lock_flag/main.ts diff --git a/cli/args/flags.rs b/cli/args/flags.rs index d024f65767..0c3caf0a14 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -317,6 +317,7 @@ pub struct Flags { pub lock: Option, pub log_level: Option, 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 = 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] diff --git a/cli/lockfile.rs b/cli/lockfile.rs index 43c01b4289..cdb40c5307 100644 --- a/cli/lockfile.rs +++ b/cli/lockfile.rs @@ -98,6 +98,10 @@ impl Lockfile { flags: &Flags, maybe_config_file: Option<&ConfigFile>, ) -> Result, 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 { diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 1f4f7d2ae5..8265d54ec4 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -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, +}); diff --git a/cli/tests/testdata/run/no_lock_flag/deno.json b/cli/tests/testdata/run/no_lock_flag/deno.json new file mode 100644 index 0000000000..90faa728a1 --- /dev/null +++ b/cli/tests/testdata/run/no_lock_flag/deno.json @@ -0,0 +1,3 @@ +{ + "tasks": {} +} diff --git a/cli/tests/testdata/run/no_lock_flag/deno.lock b/cli/tests/testdata/run/no_lock_flag/deno.lock new file mode 100644 index 0000000000..059f66789f --- /dev/null +++ b/cli/tests/testdata/run/no_lock_flag/deno.lock @@ -0,0 +1,7 @@ +{ + "version": "2", + "remote": { + "http://localhost:4545/subdir/mod2.ts": "cae1d3e9f3c38cd415ff52dff854be8f3d17d35f8d7b3d285e813fb0f6393a2f", + "http://localhost:4545/subdir/print_hello.ts": "foobar" + } +} diff --git a/cli/tests/testdata/run/no_lock_flag/main.out b/cli/tests/testdata/run/no_lock_flag/main.out new file mode 100644 index 0000000000..0d8f0a2377 --- /dev/null +++ b/cli/tests/testdata/run/no_lock_flag/main.out @@ -0,0 +1,2 @@ +Download http://localhost:4545/subdir/mod2.ts +Download http://localhost:4545/subdir/print_hello.ts diff --git a/cli/tests/testdata/run/no_lock_flag/main.ts b/cli/tests/testdata/run/no_lock_flag/main.ts new file mode 100644 index 0000000000..baa52775d4 --- /dev/null +++ b/cli/tests/testdata/run/no_lock_flag/main.ts @@ -0,0 +1 @@ +import "http://localhost:4545/subdir/mod2.ts"; diff --git a/cli/tools/standalone.rs b/cli/tools/standalone.rs index eeedf8bd5f..259eb43b03 100644 --- a/cli/tools/standalone.rs +++ b/cli/tools/standalone.rs @@ -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,