summaryrefslogtreecommitdiff
path: root/cli/args/flags.rs
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-07-02 15:00:16 -0700
committerGitHub <noreply@github.com>2024-07-02 15:00:16 -0700
commitc13b6d1413859d03b41b97d4c671fccfd388b2cc (patch)
tree503c5d2c51c71f3daa79950b6862b725e9211822 /cli/args/flags.rs
parentd379c0b299411a847765e2879f8ed14bdb2d0298 (diff)
feat(cli): Add `--frozen` flag to error out if lockfile is out of date (#24355)
Closes #18296. Adds a `--frozen` (alias `--frozen-lockfile`) flag that errors out if the lockfile is out of date. This is useful for running in CI (where an out of date lockfile is usually a mistake) or to prevent accidental changes in dependencies. ![Screenshot 2024-06-26 at 7 11 13 PM](https://github.com/denoland/deno/assets/17734409/538404b8-b422-4f05-89e8-4c9b1c248576)
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r--cli/args/flags.rs65
1 files changed, 59 insertions, 6 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 1743d58c6..5f58911c2 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -498,6 +498,7 @@ pub struct Flags {
pub argv: Vec<String>,
pub subcommand: DenoSubcommand,
+ pub frozen_lockfile: bool,
pub ca_stores: Option<Vec<String>>,
pub ca_data: Option<CaData>,
pub cache_blocklist: Vec<String>,
@@ -1487,12 +1488,15 @@ Future runs of this module will trigger no downloads or compilation unless
--reload is specified.",
)
.defer(|cmd| {
- compile_args(cmd).arg(check_arg(false)).arg(
- Arg::new("file")
- .num_args(1..)
- .required(true)
- .value_hint(ValueHint::FilePath),
- )
+ compile_args(cmd)
+ .arg(check_arg(false))
+ .arg(
+ Arg::new("file")
+ .num_args(1..)
+ .required(true)
+ .value_hint(ValueHint::FilePath),
+ )
+ .arg(frozen_lockfile_arg())
})
}
@@ -3271,6 +3275,7 @@ fn runtime_args(
app
};
app
+ .arg(frozen_lockfile_arg())
.arg(cached_only_arg())
.arg(location_arg())
.arg(v8_flags_arg())
@@ -3384,6 +3389,17 @@ fn cached_only_arg() -> Arg {
.help("Require that remote dependencies are already cached")
}
+fn frozen_lockfile_arg() -> Arg {
+ Arg::new("frozen")
+ .long("frozen")
+ .alias("frozen-lockfile")
+ .value_parser(value_parser!(bool))
+ .num_args(0..=1)
+ .require_equals(true)
+ .default_missing_value("true")
+ .help("Error out if lockfile is out of date")
+}
+
/// Used for subcommands that operate on executable scripts only.
/// `deno fmt` has its own `--ext` arg because its possible values differ.
/// If --ext is not provided and the script doesn't have a file extension,
@@ -3774,6 +3790,7 @@ fn bundle_parse(flags: &mut Flags, matches: &mut ArgMatches) {
fn cache_parse(flags: &mut Flags, matches: &mut ArgMatches) {
compile_args_parse(flags, matches);
+ frozen_lockfile_arg_parse(flags, matches);
let files = matches.remove_many::<String>("file").unwrap().collect();
flags.subcommand = DenoSubcommand::Cache(CacheFlags { files });
}
@@ -4576,6 +4593,7 @@ fn runtime_args_parse(
) {
compile_args_parse(flags, matches);
cached_only_arg_parse(flags, matches);
+ frozen_lockfile_arg_parse(flags, matches);
if include_perms {
permission_args_parse(flags, matches);
}
@@ -4667,6 +4685,12 @@ fn cached_only_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) {
}
}
+fn frozen_lockfile_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) {
+ if let Some(&v) = matches.get_one::<bool>("frozen") {
+ flags.frozen_lockfile = v;
+ }
+}
+
fn ext_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) {
flags.ext = matches.remove_one::<String>("ext");
}
@@ -9845,4 +9869,33 @@ mod tests {
}
);
}
+
+ #[test]
+ fn run_with_frozen_lockfile() {
+ let cases = [
+ (Some("--frozen"), true),
+ (Some("--frozen=true"), true),
+ (Some("--frozen=false"), false),
+ (None, false),
+ ];
+ for (flag, frozen) in cases {
+ let mut args = svec!["deno", "run"];
+ if let Some(f) = flag {
+ args.push(f.into());
+ }
+ args.push("script.ts".into());
+ let r = flags_from_vec(args);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ subcommand: DenoSubcommand::Run(RunFlags::new_default(
+ "script.ts".to_string(),
+ )),
+ frozen_lockfile: frozen,
+ code_cache_enabled: true,
+ ..Flags::default()
+ }
+ );
+ }
+ }
}