diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-02-15 14:49:35 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-15 14:49:35 -0500 |
commit | 4f80d83774ce5402a2b10503529fe422c998b841 (patch) | |
tree | d99c2e0bdc13e36727c62800130ebcab3b85dae7 /cli/graph_util.rs | |
parent | 052b7d8bbdb43eedcdaae1a3094a5f2c70bba279 (diff) |
feat(unstable): single checksum per JSR package in the lockfile (#22421)
This changes the lockfile to not store JSR specifiers in the "remote"
section. Instead a single JSR integrity is stored per package in the
lockfile, which is a hash of the version's `x.x.x_meta.json` file, which
contains hashes for every file in the package. The hashes in this file
are then compared against when loading.
Additionally, when using `{ "vendor": true }` in a deno.json, the files
can be modified without causing lockfile errors—the checksum is only
checked when copying into the vendor folder and not afterwards
(eventually we should add this behaviour for non-jsr specifiers as
well). As part of this change, the `vendor` folder creation is not
always automatic in the LSP and running an explicit cache command is
necessary. The code required to track checksums in the LSP would have
been too complex for this PR, so that all goes through deno_graph now.
The vendoring is still automatic when running from the CLI.
Diffstat (limited to 'cli/graph_util.rs')
-rw-r--r-- | cli/graph_util.rs | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 3633784b8..09f0db9e6 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use crate::args::jsr_url; use crate::args::CliOptions; use crate::args::Lockfile; use crate::args::TsTypeLib; @@ -174,6 +175,18 @@ pub fn graph_lock_or_exit(graph: &ModuleGraph, lockfile: &mut Lockfile) { Module::Json(module) => &module.source, Module::Node(_) | Module::Npm(_) | Module::External(_) => continue, }; + + // skip over any specifiers in JSR packages because those + // are enforced via the integrity + if deno_graph::source::recommended_registry_package_url_to_nv( + jsr_url(), + module.specifier(), + ) + .is_some() + { + continue; + } + if !lockfile.check_or_insert_remote(module.specifier().as_str(), source) { let err = format!( concat!( @@ -475,6 +488,19 @@ impl ModuleGraphBuilder { } } } + for (nv, value) in &lockfile.content.packages.jsr { + if let Ok(nv) = PackageNv::from_str(nv) { + graph + .packages + .add_manifest_checksum(nv, value.integrity.clone()) + .map_err(|err| deno_lockfile::IntegrityCheckFailedError { + package_display_id: format!("jsr:{}", err.nv), + actual: err.actual, + expected: err.expected, + filename: lockfile.filename.display().to_string(), + })?; + } + } } } @@ -504,9 +530,14 @@ impl ModuleGraphBuilder { format!("jsr:{}", to), ); } - for (name, deps) in graph.packages.package_deps() { - lockfile - .insert_package_deps(name.to_string(), deps.map(|s| s.to_string())); + for (name, checksum, deps) in + graph.packages.packages_with_checksum_and_deps() + { + lockfile.insert_package( + name.to_string(), + checksum.clone(), + deps.map(|s| s.to_string()), + ); } } } |