2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 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 std::sync::Arc;
|
|
|
|
|
|
|
|
use deno_core::error::AnyError;
|
|
|
|
use deno_core::parking_lot::Mutex;
|
|
|
|
use deno_npm::registry::NpmRegistryApi;
|
2023-04-13 10:47:45 -04:00
|
|
|
use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot;
|
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;
|
|
|
|
|
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>,
|
|
|
|
) -> Result<Option<Lockfile>, AnyError> {
|
|
|
|
if flags.no_lock
|
|
|
|
|| matches!(
|
|
|
|
flags.subcommand,
|
|
|
|
DenoSubcommand::Install(_) | DenoSubcommand::Uninstall(_)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2023-01-23 17:41:02 -05:00
|
|
|
None => return Ok(None),
|
|
|
|
},
|
|
|
|
};
|
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
|
|
|
}
|
2020-10-04 19:32:18 -04:00
|
|
|
|
2023-04-06 18:46:44 -04:00
|
|
|
pub async fn snapshot_from_lockfile(
|
|
|
|
lockfile: Arc<Mutex<Lockfile>>,
|
2023-08-08 13:07:29 -04:00
|
|
|
api: &dyn NpmRegistryApi,
|
2023-04-13 10:47:45 -04:00
|
|
|
) -> Result<ValidSerializedNpmResolutionSnapshot, AnyError> {
|
2023-08-08 13:07:29 -04:00
|
|
|
let incomplete_snapshot = {
|
|
|
|
let lock = lockfile.lock();
|
|
|
|
deno_npm::resolution::incomplete_snapshot_from_lockfile(&lock)?
|
2023-04-12 18:04:45 -04:00
|
|
|
};
|
2023-08-08 13:07:29 -04:00
|
|
|
let snapshot =
|
|
|
|
deno_npm::resolution::snapshot_from_lockfile(incomplete_snapshot, api)
|
|
|
|
.await?;
|
|
|
|
Ok(snapshot)
|
2020-10-04 19:32:18 -04:00
|
|
|
}
|