1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix: ignore local lockfile for deno install and uninstall (#17145)

Closes #17116
This commit is contained in:
David Sherret 2022-12-20 12:00:57 -05:00 committed by GitHub
parent a06f59981b
commit 8165cded14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View file

@ -19,6 +19,8 @@ use crate::tools::fmt::format_json;
use crate::util; use crate::util;
use crate::Flags; use crate::Flags;
use super::DenoSubcommand;
#[derive(Debug)] #[derive(Debug)]
pub struct LockfileError(String); pub struct LockfileError(String);
@ -96,7 +98,12 @@ impl Lockfile {
flags: &Flags, flags: &Flags,
maybe_config_file: Option<&ConfigFile>, maybe_config_file: Option<&ConfigFile>,
) -> Result<Option<Lockfile>, AnyError> { ) -> Result<Option<Lockfile>, AnyError> {
if flags.no_lock { if flags.no_lock
|| matches!(
flags.subcommand,
DenoSubcommand::Install(_) | DenoSubcommand::Uninstall(_)
)
{
return Ok(None); return Ok(None);
} }

View file

@ -16,6 +16,9 @@ mod install {
let temp_dir = TempDir::new(); let temp_dir = TempDir::new();
let temp_dir_str = temp_dir.path().to_string_lossy().to_string(); let temp_dir_str = temp_dir.path().to_string_lossy().to_string();
// ensure a lockfile doesn't get created or updated locally
temp_dir.write("deno.json", "{}");
let status = util::deno_cmd() let status = util::deno_cmd()
.current_dir(temp_dir.path()) .current_dir(temp_dir.path())
.arg("install") .arg("install")
@ -34,6 +37,9 @@ mod install {
.unwrap(); .unwrap();
assert!(status.success()); assert!(status.success());
// no lockfile should be created locally
assert!(!temp_dir.path().join("deno.lock").exists());
let mut file_path = temp_dir.path().join(".deno/bin/echo_test"); let mut file_path = temp_dir.path().join(".deno/bin/echo_test");
assert!(file_path.exists()); assert!(file_path.exists());
@ -41,7 +47,7 @@ mod install {
file_path = file_path.with_extension("cmd"); file_path = file_path.with_extension("cmd");
} }
let content = fs::read_to_string(file_path).unwrap(); let content = fs::read_to_string(&file_path).unwrap();
// ensure there's a trailing newline so the shell script can be // ensure there's a trailing newline so the shell script can be
// more versatile. // more versatile.
assert_eq!(content.chars().last().unwrap(), '\n'); assert_eq!(content.chars().last().unwrap(), '\n');
@ -57,6 +63,27 @@ mod install {
r#"run --check 'http://localhost:4545/echo.ts'"# r#"run --check 'http://localhost:4545/echo.ts'"#
); );
} }
// now uninstall
let status = util::deno_cmd()
.current_dir(temp_dir.path())
.arg("uninstall")
.arg("echo_test")
.envs([
("HOME", temp_dir_str.as_str()),
("USERPROFILE", temp_dir_str.as_str()),
("DENO_INSTALL_ROOT", ""),
])
.spawn()
.unwrap()
.wait()
.unwrap();
assert!(status.success());
// ensure local lockfile still doesn't exist
assert!(!temp_dir.path().join("deno.lock").exists());
// ensure uninstall occurred
assert!(!file_path.exists());
} }
#[test] #[test]