From 41d81ed23b16c9ce222c81ed36826f82c4371fe5 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 15 Aug 2024 17:15:41 -0400 Subject: [PATCH 1/4] feat(FUTURE): terse lockfile (v4) --- Cargo.lock | 6 +--- Cargo.toml | 6 +++- cli/args/lockfile.rs | 33 +++++++++++++++---- tests/integration/check_tests.rs | 20 +++++++---- tests/integration/jsr_tests.rs | 23 +++++++------ .../future_install_local_deno/deno.lock.out | 24 +++++++------- .../future_install_node_modules/corrupt.js | 2 +- .../future_install_node_modules/deno.lock.out | 15 ++++----- 8 files changed, 79 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e3cdc49d6f23f1..19951cf0573b5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1720,9 +1720,7 @@ dependencies = [ [[package]] name = "deno_lockfile" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23120f905aec2deed858820113e089551025b74e261c5c404812cd8e61421379" +version = "0.21.0" dependencies = [ "serde", "serde_json", @@ -1869,8 +1867,6 @@ dependencies = [ [[package]] name = "deno_npm" version = "0.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9812c781ff6b2e0e45c32ccba9983bce84ecccf6f6a7006b750f8c5c9ac15e30" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 3032b40b5f58ec..1303ad9721260f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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.0" 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" } @@ -394,3 +394,7 @@ opt-level = 3 opt-level = 3 [profile.release.package.zstd-sys] opt-level = 3 + +[patch.crates-io] +deno_lockfile = { path = "../deno_lockfile" } +deno_npm = { path = "../deno_npm" } diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs index c9afecd98363f7..953278e7dcd445 100644 --- a/cli/args/lockfile.rs +++ b/cli/args/lockfile.rs @@ -210,22 +210,41 @@ impl CliLockfile { Ok(Some(lockfile)) } pub fn read_from_path( - filename: PathBuf, + file_path: PathBuf, frozen: bool, ) -> Result { - 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(()); diff --git a/tests/integration/check_tests.rs b/tests/integration/check_tests.rs index b560b352eef25a..ade18b0e1f8d74 100644 --- a/tests/integration/check_tests.rs +++ b/tests/integration/check_tests.rs @@ -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; @@ -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::(); + 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", @@ -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() diff --git a/tests/integration/jsr_tests.rs b/tests/integration/jsr_tests.rs index eb951d682cc495..a9397af72ea81a 100644 --- a/tests/integration/jsr_tests.rs +++ b/tests/integration/jsr_tests.rs @@ -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; @@ -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 @@ -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); diff --git a/tests/specs/install/future_install_local_deno/deno.lock.out b/tests/specs/install/future_install_local_deno/deno.lock.out index fd3d52e428341d..188de5de908090 100644 --- a/tests/specs/install/future_install_local_deno/deno.lock.out +++ b/tests/specs/install/future_install_local_deno/deno.lock.out @@ -1,15 +1,17 @@ { - "version": "3", - "packages": { - "specifiers": { - "jsr:@denotest/add": "jsr:@denotest/add@1.0.0", - "npm:@denotest/esm-basic@^1.0.0": "npm:@denotest/esm-basic@1.0.0" - }, - "jsr": { - "@denotest/add@1.0.0": [WILDCARD] - }, - "npm": { - "@denotest/esm-basic@1.0.0": [WILDCARD] + "version": "4", + "specifiers": { + "jsr:@denotest/add": "jsr:@denotest/add@1.0.0", + "npm:@denotest/esm-basic@^1.0.0": "npm:@denotest/esm-basic@1.0.0" + }, + "jsr": { + "@denotest/add@1.0.0": { + "integrity": "[WILDCARD]" + } + }, + "npm": { + "@denotest/esm-basic@1.0.0": { + "integrity": "[WILDCARD]" } }, "remote": [WILDCARD], diff --git a/tests/specs/install/future_install_node_modules/corrupt.js b/tests/specs/install/future_install_node_modules/corrupt.js index fcc146081ae2a6..f10384024fc087 100644 --- a/tests/specs/install/future_install_node_modules/corrupt.js +++ b/tests/specs/install/future_install_node_modules/corrupt.js @@ -1,5 +1,5 @@ const lock = JSON.parse(Deno.readTextFileSync("./deno.lock")); -const pkg = lock.packages.npm["@denotest/esm-basic@1.0.0"]; +const pkg = lock.npm["@denotest/esm-basic@1.0.0"]; // Corrupt the integrity hash pkg.integrity = pkg.integrity.slice(0, -1); Deno.writeTextFileSync("./deno.lock", JSON.stringify(lock)); diff --git a/tests/specs/install/future_install_node_modules/deno.lock.out b/tests/specs/install/future_install_node_modules/deno.lock.out index b30232996716b4..c8071adadca858 100644 --- a/tests/specs/install/future_install_node_modules/deno.lock.out +++ b/tests/specs/install/future_install_node_modules/deno.lock.out @@ -1,14 +1,13 @@ { - "version": "3", - "packages": { - "specifiers": { - "npm:@denotest/esm-basic": "npm:@denotest/esm-basic@1.0.0" - }, - "npm": { - "@denotest/esm-basic@1.0.0": [WILDCARD] + "version": "4", + "specifiers": { + "npm:@denotest/esm-basic": "npm:@denotest/esm-basic@1.0.0" + }, + "npm": { + "@denotest/esm-basic@1.0.0": { + "integrity": "[WILDCARD]" } }, - "remote": {}, "workspace": { "packageJson": { "dependencies": [ From 9350205f14d8e441764d0b92e1aa681575eefdfa Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 15 Aug 2024 17:24:40 -0400 Subject: [PATCH 2/4] updates --- Cargo.lock | 10 ++++++---- Cargo.toml | 5 ++--- cli/Cargo.toml | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19951cf0573b5d..52c99f981abda5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1720,7 +1720,9 @@ dependencies = [ [[package]] name = "deno_lockfile" -version = "0.21.0" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b01138860cdf20cfca4c9e6bcda2bbe577f0c784f6f6938205d522ee2b6327ed" dependencies = [ "serde", "serde_json", @@ -1866,7 +1868,9 @@ dependencies = [ [[package]] name = "deno_npm" -version = "0.21.4" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01fd279be9f522ebfaabce7ff0f4b069c2c1d737946ba57456b579f9246669e8" dependencies = [ "anyhow", "async-trait", @@ -2774,8 +2778,6 @@ dependencies = [ [[package]] name = "eszip" version = "0.73.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1de63c5d16c099e1164154ba0c6fd1f54e1147ef635aaccc47702f8a442392a" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 1303ad9721260f..825e62a7f72978 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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.21.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" } @@ -396,5 +396,4 @@ opt-level = 3 opt-level = 3 [patch.crates-io] -deno_lockfile = { path = "../deno_lockfile" } -deno_npm = { path = "../deno_npm" } +eszip = { path = "../eszip" } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index bb6508b55c711a..8ad67ff2cfd0b9 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -72,7 +72,7 @@ deno_emit = "=0.44.0" deno_graph = { version = "=0.81.2" } deno_lint = { version = "=0.62.0", 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" From ce6d10b2ff484c881fd8be16b86e18bac2988e7b Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 15 Aug 2024 17:38:18 -0400 Subject: [PATCH 3/4] update --- Cargo.lock | 4 +- Cargo.toml | 3 -- cli/Cargo.toml | 2 +- .../lockfile/frozen_lockfile/__test__.jsonc | 9 +++++ .../frozen_package_json_changed.out | 39 ++++++++----------- .../frozen_package_json_changed_install.out | 37 +++++++----------- 6 files changed, 44 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 52c99f981abda5..1168d554422faa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2777,7 +2777,9 @@ dependencies = [ [[package]] name = "eszip" -version = "0.73.0" +version = "0.74.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a74ab660df48e00a4582f6ca506b3cfc5683ce80e73158c9e4dbf84341bb3aea" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 825e62a7f72978..c7f31c73653193 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -394,6 +394,3 @@ opt-level = 3 opt-level = 3 [profile.release.package.zstd-sys] opt-level = 3 - -[patch.crates-io] -eszip = { path = "../eszip" } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 8ad67ff2cfd0b9..7fc00ad3c73eb5 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -78,7 +78,7 @@ deno_runtime = { workspace = true, features = ["include_js_files_for_snapshottin 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 diff --git a/tests/specs/lockfile/frozen_lockfile/__test__.jsonc b/tests/specs/lockfile/frozen_lockfile/__test__.jsonc index 76712a9132031a..8faa45b4e3e3cc 100644 --- a/tests/specs/lockfile/frozen_lockfile/__test__.jsonc +++ b/tests/specs/lockfile/frozen_lockfile/__test__.jsonc @@ -60,10 +60,16 @@ "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\" } }))" @@ -71,6 +77,9 @@ "output": "" }, { + "envs": { + "DENO_FUTURE": "1" + }, "args": "cache --frozen add.ts", "output": "frozen_package_json_changed.out", "exitCode": 1 diff --git a/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed.out b/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed.out index 066aa230394a7c..60a01158dd6d16 100644 --- a/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed.out +++ b/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed.out @@ -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 | + } diff --git a/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed_install.out b/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed_install.out index 6b7d1dc5fdcd82..39717959668788 100644 --- a/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed_install.out +++ b/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed_install.out @@ -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 | + } From 1ff8a7b12418a627d87db8f0bd50bf2d20f063b4 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 16 Aug 2024 08:30:31 -0400 Subject: [PATCH 4/4] lint --- tests/integration/check_tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/check_tests.rs b/tests/integration/check_tests.rs index ade18b0e1f8d74..57c38522f23d90 100644 --- a/tests/integration/check_tests.rs +++ b/tests/integration/check_tests.rs @@ -376,7 +376,7 @@ fn npm_module_check_then_error() { "npm:@denotest/breaking-change-between-versions".to_string(), "npm:@denotest/breaking-change-between-versions@1.0.0".to_string(), ); - lockfile_path.write(&lockfile.as_json_string()); + 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", @@ -391,7 +391,7 @@ fn npm_module_check_then_error() { "npm:@denotest/breaking-change-between-versions".to_string(), "npm:@denotest/breaking-change-between-versions@2.0.0".to_string(), ); - lockfile_path.write(&lockfile.as_json_string()); + lockfile_path.write(lockfile.as_json_string()); check_command .run()