Skip to content
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

feat(FUTURE): terse lockfile (v4) #25059

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ deno_ast = { version = "=0.41.2", features = ["transpiling"] }
deno_core = { version = "0.303.0" }

deno_bench_util = { version = "0.158.0", path = "./bench_util" }
deno_lockfile = "0.20.0"
deno_lockfile = "0.21.1"
deno_media_type = { version = "0.1.4", features = ["module_specifier"] }
deno_permissions = { version = "0.24.0", path = "./runtime/permissions" }
deno_runtime = { version = "0.173.0", path = "./runtime" }
Expand Down
4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ deno_emit = "=0.44.0"
deno_graph = { version = "=0.81.2" }
deno_lint = { version = "=0.63.1", features = ["docs"] }
deno_lockfile.workspace = true
deno_npm = "=0.21.4"
deno_npm = "=0.22.0"
deno_package_json.workspace = true
deno_runtime = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_semver = "=0.5.10"
deno_task_shell = "=0.17.0"
deno_terminal.workspace = true
eszip = "=0.73.0"
eszip = "=0.74.0"
libsui = "0.3.0"
napi_sym.workspace = true
node_resolver.workspace = true
Expand Down
33 changes: 26 additions & 7 deletions cli/args/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,41 @@ impl CliLockfile {
Ok(Some(lockfile))
}
pub fn read_from_path(
filename: PathBuf,
file_path: PathBuf,
frozen: bool,
) -> Result<CliLockfile, AnyError> {
match std::fs::read_to_string(&filename) {
match std::fs::read_to_string(&file_path) {
Ok(text) => Ok(CliLockfile::new(
Lockfile::with_lockfile_content(filename, &text, false)?,
Lockfile::new(deno_lockfile::NewLockfileOptions {
file_path,
content: &text,
overwrite: false,
is_deno_future: *super::DENO_FUTURE,
})?,
frozen,
)),
Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(
CliLockfile::new(Lockfile::new_empty(filename, false), frozen),
),
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
Ok(CliLockfile::new(
if *super::DENO_FUTURE {
// force version 4 for deno future
Lockfile::new(deno_lockfile::NewLockfileOptions {
file_path,
content: r#"{"version":"4"}"#,
overwrite: false,
is_deno_future: true,
})?
} else {
Lockfile::new_empty(file_path, false)
},
frozen,
))
}
Err(err) => Err(err).with_context(|| {
format!("Failed reading lockfile '{}'", filename.display())
format!("Failed reading lockfile '{}'", file_path.display())
}),
}
}

pub fn error_if_changed(&self) -> Result<(), AnyError> {
if !self.frozen {
return Ok(());
Expand Down
20 changes: 13 additions & 7 deletions tests/integration/check_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use deno_lockfile::NewLockfileOptions;
use test_util as util;
use test_util::itest;
use util::env_vars_for_npm_tests;
Expand Down Expand Up @@ -361,16 +362,21 @@ fn npm_module_check_then_error() {
])
.run()
.skip_output_check();
let lockfile = temp_dir.path().join("deno.lock");
let mut lockfile_content =
lockfile.read_json::<deno_lockfile::LockfileContent>();
let lockfile_path = temp_dir.path().join("deno.lock");
let mut lockfile = deno_lockfile::Lockfile::new(NewLockfileOptions {
file_path: lockfile_path.to_path_buf(),
content: &lockfile_path.read_to_string(),
overwrite: false,
is_deno_future: false,
})
.unwrap();

// make the specifier resolve to version 1
lockfile_content.packages.specifiers.insert(
lockfile.content.packages.specifiers.insert(
"npm:@denotest/breaking-change-between-versions".to_string(),
"npm:@denotest/breaking-change-between-versions@1.0.0".to_string(),
);
lockfile.write_json(&lockfile_content);
lockfile_path.write(lockfile.as_json_string());
temp_dir.write(
"main.ts",
"import { oldName } from 'npm:@denotest/breaking-change-between-versions'; console.log(oldName());\n",
Expand All @@ -381,11 +387,11 @@ fn npm_module_check_then_error() {

// now update the lockfile to use version 2 instead, which should cause a
// type checking error because the oldName no longer exists
lockfile_content.packages.specifiers.insert(
lockfile.content.packages.specifiers.insert(
"npm:@denotest/breaking-change-between-versions".to_string(),
"npm:@denotest/breaking-change-between-versions@2.0.0".to_string(),
);
lockfile.write_json(&lockfile_content);
lockfile_path.write(lockfile.as_json_string());

check_command
.run()
Expand Down
23 changes: 13 additions & 10 deletions tests/integration/jsr_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_lockfile::Lockfile;
use deno_lockfile::NewLockfileOptions;
use test_util as util;
use url::Url;
use util::assert_contains;
Expand Down Expand Up @@ -141,11 +142,12 @@ console.log(version);"#,
.assert_matches_text("0.1.1\n");

let lockfile_path = temp_dir.path().join("deno.lock");
let mut lockfile = Lockfile::with_lockfile_content(
lockfile_path.to_path_buf(),
&lockfile_path.read_to_string(),
false,
)
let mut lockfile = Lockfile::new(NewLockfileOptions {
file_path: lockfile_path.to_path_buf(),
content: &lockfile_path.read_to_string(),
overwrite: false,
is_deno_future: false,
})
.unwrap();
*lockfile
.content
Expand Down Expand Up @@ -256,11 +258,12 @@ console.log(version);"#,
.assert_matches_text("0.1.1\n");

let lockfile_path = temp_dir.path().join("deno.lock");
let mut lockfile = Lockfile::with_lockfile_content(
lockfile_path.to_path_buf(),
&lockfile_path.read_to_string(),
false,
)
let mut lockfile = Lockfile::new(NewLockfileOptions {
file_path: lockfile_path.to_path_buf(),
content: &lockfile_path.read_to_string(),
overwrite: false,
is_deno_future: false,
})
.unwrap();
let pkg_name = "@denotest/no-module-graph@0.1.1";
let original_integrity = get_lockfile_pkg_integrity(&lockfile, pkg_name);
Expand Down
24 changes: 13 additions & 11 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.

2 changes: 1 addition & 1 deletion tests/specs/install/future_install_node_modules/corrupt.js

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

15 changes: 7 additions & 8 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.

9 changes: 9 additions & 0 deletions tests/specs/lockfile/frozen_lockfile/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,26 @@
"error_when_package_json_changed": {
"steps": [
{
"envs": {
"DENO_FUTURE": "1"
},
"args": "cache add.ts",
"output": "[WILDCARD]"
},
{
"envs": {
"DENO_FUTURE": "1"
},
"args": [
"eval",
"Deno.writeTextFileSync(\"package.json\", JSON.stringify({ dependencies: { \"@denotest/bin\": \"0.7.0\" } }))"
],
"output": ""
},
{
"envs": {
"DENO_FUTURE": "1"
},
"args": "cache --frozen add.ts",
"output": "frozen_package_json_changed.out",
"exitCode": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
Download http://localhost:4260/@denotest/bin
error: The lockfile is out of date. Run `deno cache --frozen=false` or rerun with `--frozen=false` to update it.
error: The lockfile is out of date. Run `deno cache --frozen=false`, `deno install --frozen=false`, or rerun with `--frozen=false` to update it.
changes:
5 | - "npm:@denotest/add@1": "npm:@denotest/add@1.0.0"
5 | + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0",
6 | + "npm:@denotest/bin@0.7.0": "npm:@denotest/bin@0.7.0"
11 | - }
12 | - }
13 | - },
14 | - "remote": {}
12 | + },
13 | + "@denotest/bin@0.7.0": {
14 | + "integrity": "[WILDCARD]",
15 | + "dependencies": {}
16 | + }
17 | + }
18 | + },
19 | + "remote": {},
20 | + "workspace": {
21 | + "packageJson": {
22 | + "dependencies": [
23 | + "npm:@denotest/bin@0.7.0"
24 | + ]
25 | + }
26 | + }
4 | - "npm:@denotest/add@1": "npm:@denotest/add@1.0.0"
4 | + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0",
5 | + "npm:@denotest/bin@0.7.0": "npm:@denotest/bin@0.7.0"
9 | - }
10 | + },
11 | + "@denotest/bin@0.7.0": {
12 | + "integrity": "[WILDLINE]"
13 | + }
14 | + },
15 | + "workspace": {
16 | + "packageJson": {
17 | + "dependencies": [
18 | + "npm:@denotest/bin@0.7.0"
19 | + ]
20 | + }
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
error: The lockfile is out of date. Run `deno cache --frozen=false`, `deno install --frozen=false`, or rerun with `--frozen=false` to update it.
changes:
5 | - "npm:@denotest/add@1": "npm:@denotest/add@1.0.0"
5 | + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0",
6 | + "npm:@denotest/bin@0.7.0": "npm:@denotest/bin@0.7.0"
11 | - }
12 | - }
13 | - },
14 | - "remote": {}
12 | + },
13 | + "@denotest/bin@0.7.0": {
14 | + "integrity": "[WILDCARD]",
15 | + "dependencies": {}
16 | + }
17 | + }
18 | + },
19 | + "remote": {},
20 | + "workspace": {
21 | + "packageJson": {
22 | + "dependencies": [
23 | + "npm:@denotest/bin@0.7.0"
24 | + ]
25 | + }
26 | + }
4 | - "npm:@denotest/add@1": "npm:@denotest/add@1.0.0"
4 | + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0",
5 | + "npm:@denotest/bin@0.7.0": "npm:@denotest/bin@0.7.0"
9 | - }
10 | + },
11 | + "@denotest/bin@0.7.0": {
12 | + "integrity": "[WILDLINE]"
13 | + }
14 | + },
15 | + "workspace": {
16 | + "packageJson": {
17 | + "dependencies": [
18 | + "npm:@denotest/bin@0.7.0"
19 | + ]
20 | + }