summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-05-23 12:31:05 -0700
committerGitHub <noreply@github.com>2024-05-23 12:31:05 -0700
commit5de30c53239ac74843725d981afc0bb8c45bdf16 (patch)
tree5e806923d8806d6648a9d991eeb3bb05d1df8b4f /cli
parent20dad295e2e0961932b05d34b29b07ee97eb0815 (diff)
fix(cli): Support deno.lock with only package.json present + fix DENO_FUTURE install interactions with lockfile (#23918)
Fixes #23571. Previously, we required a `deno.json` to be present (or the `--lock` flag) in order for us to resolve a `deno.lock` file. This meant that if you were using deno in an npm-first project deno wouldn't use a lockfile. Additionally, while I was fixing that, I discovered there were a couple bugs keeping the future `install` command from using a lockfile. With this PR, `install` will actually resolve the lockfile (or create one if not present), and update it if it's not up-to-date. This also speeds up `deno install`, as we can use the lockfile to skip work during npm resolution.
Diffstat (limited to 'cli')
-rw-r--r--cli/args/lockfile.rs16
-rw-r--r--cli/args/mod.rs7
-rw-r--r--cli/tools/installer.rs4
3 files changed, 23 insertions, 4 deletions
diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs
index 84cad98d4..d5ab14432 100644
--- a/cli/args/lockfile.rs
+++ b/cli/args/lockfile.rs
@@ -3,11 +3,14 @@
use std::path::PathBuf;
use deno_core::error::AnyError;
+use deno_runtime::deno_node::PackageJson;
use crate::args::ConfigFile;
use crate::Flags;
use super::DenoSubcommand;
+use super::InstallFlags;
+use super::InstallKind;
pub use deno_lockfile::Lockfile;
pub use deno_lockfile::LockfileError;
@@ -15,11 +18,15 @@ pub use deno_lockfile::LockfileError;
pub fn discover(
flags: &Flags,
maybe_config_file: Option<&ConfigFile>,
+ maybe_package_json: Option<&PackageJson>,
) -> Result<Option<Lockfile>, AnyError> {
if flags.no_lock
|| matches!(
flags.subcommand,
- DenoSubcommand::Install(_) | DenoSubcommand::Uninstall(_)
+ DenoSubcommand::Install(InstallFlags {
+ kind: InstallKind::Global(..),
+ ..
+ }) | DenoSubcommand::Uninstall(_)
)
{
return Ok(None);
@@ -38,7 +45,12 @@ pub fn discover(
return Ok(None);
}
}
- None => return Ok(None),
+ None => match maybe_package_json {
+ Some(package_json) => {
+ package_json.path.parent().unwrap().join("deno.lock")
+ }
+ None => return Ok(None),
+ },
},
};
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index b3d508e18..03a6357aa 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -852,8 +852,11 @@ impl CliOptions {
maybe_package_json = discover_package_json(&flags, None, &initial_cwd)?;
}
- let maybe_lock_file =
- lockfile::discover(&flags, maybe_config_file.as_ref())?;
+ let maybe_lock_file = lockfile::discover(
+ &flags,
+ maybe_config_file.as_ref(),
+ maybe_package_json.as_ref(),
+ )?;
Self::new(
flags,
initial_cwd,
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs
index b13dea6fd..82a44de16 100644
--- a/cli/tools/installer.rs
+++ b/cli/tools/installer.rs
@@ -265,6 +265,10 @@ async fn install_local(
let factory = CliFactory::from_flags(flags)?;
crate::module_loader::load_top_level_deps(&factory).await?;
+ if let Some(lockfile) = factory.cli_options().maybe_lockfile() {
+ lockfile.lock().write()?;
+ }
+
Ok(())
}