Skip to content

fix(cli): Support deno.lock with only package.json present + fix DENO_FUTURE install interactions with lockfile #23918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions cli/args/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,30 @@
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;

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);
Expand All @@ -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),
},
},
};

Expand Down
7 changes: 5 additions & 2 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions cli/tools/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
11 changes: 6 additions & 5 deletions tests/integration/npm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2982,15 +2982,16 @@ fn cjs_export_analysis_import_cjs_directly_relative_import() {
}

itest!(imports_package_json {
args: "run --node-modules-dir=false npm/imports_package_json/main.js",
args:
"run --no-lock --node-modules-dir=false npm/imports_package_json/main.js",
output: "npm/imports_package_json/main.out",
envs: env_vars_for_npm_tests(),
http_server: true,
});

itest!(imports_package_json_import_not_defined {
args:
"run --node-modules-dir=false npm/imports_package_json/import_not_defined.js",
"run --no-lock --node-modules-dir=false npm/imports_package_json/import_not_defined.js",
output: "npm/imports_package_json/import_not_defined.out",
envs: env_vars_for_npm_tests(),
exit_code: 1,
Expand All @@ -2999,23 +3000,23 @@ itest!(imports_package_json_import_not_defined {

itest!(imports_package_json_sub_path_import_not_defined {
args:
"run --node-modules-dir=false npm/imports_package_json/sub_path_import_not_defined.js",
"run --no-lock --node-modules-dir=false npm/imports_package_json/sub_path_import_not_defined.js",
output: "npm/imports_package_json/sub_path_import_not_defined.out",
envs: env_vars_for_npm_tests(),
exit_code: 1,
http_server: true,
});

itest!(different_nested_dep_node_modules_dir_false {
args: "run --quiet --node-modules-dir=false npm/different_nested_dep/main.js",
args: "run --quiet --no-lock --node-modules-dir=false npm/different_nested_dep/main.js",
output: "npm/different_nested_dep/main.out",
envs: env_vars_for_npm_tests(),
exit_code: 0,
http_server: true,
});

itest!(different_nested_dep_node_modules_dir_true {
args: "run --quiet --node-modules-dir=true main.js",
args: "run --no-lock --quiet --node-modules-dir=true main.js",
output: "npm/different_nested_dep/main.out",
copy_temp_dir: Some("npm/different_nested_dep/"),
cwd: Some("npm/different_nested_dep/"),
Expand Down
8 changes: 8 additions & 0 deletions tests/specs/install/future_install_local_deno/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
// ensure deps are actually cached
"args": "run --cached-only main.js",
"output": ""
},
{
// check for lockfile
"args": [
"eval",
"console.log(Deno.readTextFileSync('./deno.lock').trim())"
],
"output": "deno.lock.out"
}
]
}
22 changes: 22 additions & 0 deletions tests/specs/install/future_install_local_deno/deno.lock.out

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions tests/specs/install/future_install_node_modules/deno.lock.out

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/specs/lockfile/only_package_json/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"tempDir": true,
"steps": [
{
"args": "cache index.js",
"output": "cache.out"
},
{
"args": [
"eval",
"console.log(Deno.readTextFileSync('./deno.lock').trim())"
],
"output": "deno.lock.out"
}
]
}
3 changes: 3 additions & 0 deletions tests/specs/lockfile/only_package_json/cache.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Download http://localhost:4260/@denotest/esm-basic
Download http://localhost:4260/@denotest/esm-basic/1.0.0.tgz
Initialize @denotest/[email protected]
19 changes: 19 additions & 0 deletions tests/specs/lockfile/only_package_json/deno.lock.out

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/specs/lockfile/only_package_json/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import * as basic from "@denotest/esm-basic";
7 changes: 7 additions & 0 deletions tests/specs/lockfile/only_package_json/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "lockfile_only_package_json",
"dependencies": {
"@denotest/esm-basic": "*"
},
"type": "module"
}