2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-04-06 18:46:44 -04:00
|
|
|
|
2023-01-23 17:41:02 -05:00
|
|
|
use std::path::PathBuf;
|
2023-04-06 18:46:44 -04:00
|
|
|
|
|
|
|
use deno_core::error::AnyError;
|
2024-05-23 15:31:05 -04:00
|
|
|
use deno_runtime::deno_node::PackageJson;
|
2019-11-03 10:39:27 -05:00
|
|
|
|
2022-11-02 11:32:30 -04:00
|
|
|
use crate::args::ConfigFile;
|
|
|
|
use crate::Flags;
|
2021-12-07 19:21:04 -05:00
|
|
|
|
2022-12-20 12:00:57 -05:00
|
|
|
use super::DenoSubcommand;
|
2024-05-23 15:31:05 -04:00
|
|
|
use super::InstallFlags;
|
|
|
|
use super::InstallKind;
|
2022-12-20 12:00:57 -05:00
|
|
|
|
2023-01-23 17:41:02 -05:00
|
|
|
pub use deno_lockfile::Lockfile;
|
|
|
|
pub use deno_lockfile::LockfileError;
|
|
|
|
|
|
|
|
pub fn discover(
|
|
|
|
flags: &Flags,
|
|
|
|
maybe_config_file: Option<&ConfigFile>,
|
2024-05-23 15:31:05 -04:00
|
|
|
maybe_package_json: Option<&PackageJson>,
|
2023-01-23 17:41:02 -05:00
|
|
|
) -> Result<Option<Lockfile>, AnyError> {
|
|
|
|
if flags.no_lock
|
|
|
|
|| matches!(
|
|
|
|
flags.subcommand,
|
2024-05-23 15:31:05 -04:00
|
|
|
DenoSubcommand::Install(InstallFlags {
|
|
|
|
kind: InstallKind::Global(..),
|
|
|
|
..
|
|
|
|
}) | DenoSubcommand::Uninstall(_)
|
2023-01-23 17:41:02 -05:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return Ok(None);
|
|
|
|
}
|
|
|
|
|
|
|
|
let filename = match flags.lock {
|
|
|
|
Some(ref lock) => PathBuf::from(lock),
|
|
|
|
None => match maybe_config_file {
|
|
|
|
Some(config_file) => {
|
|
|
|
if config_file.specifier.scheme() == "file" {
|
2023-05-22 21:28:36 -04:00
|
|
|
match config_file.resolve_lockfile_path()? {
|
|
|
|
Some(path) => path,
|
|
|
|
None => return Ok(None),
|
2022-11-02 11:32:30 -04:00
|
|
|
}
|
|
|
|
} else {
|
2023-01-23 17:41:02 -05:00
|
|
|
return Ok(None);
|
2022-11-02 11:32:30 -04:00
|
|
|
}
|
|
|
|
}
|
2024-05-23 15:31:05 -04:00
|
|
|
None => match maybe_package_json {
|
|
|
|
Some(package_json) => {
|
|
|
|
package_json.path.parent().unwrap().join("deno.lock")
|
|
|
|
}
|
|
|
|
None => return Ok(None),
|
|
|
|
},
|
2023-01-23 17:41:02 -05:00
|
|
|
},
|
|
|
|
};
|
2022-10-25 12:20:07 -04:00
|
|
|
|
2023-01-23 17:41:02 -05:00
|
|
|
let lockfile = Lockfile::new(filename, flags.lock_write)?;
|
|
|
|
Ok(Some(lockfile))
|
2019-11-03 10:39:27 -05:00
|
|
|
}
|