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

fix(lockfile): error if a referenced package id doesn't exist in list of packages #16509

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Nov 2, 2022

Co-authored-by: bartlomieju [email protected]

packages_by_name
.entry(package_id.name.to_string())
.or_default()
.push(package_id.version.clone());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another bug fix here.

bail!("could not find '{}' specified in the lockfile. Maybe try again with --reload", package.id);
}
};
package.dist = version_info.dist.clone();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had more code here initially, but deleted it because it would be a lot more to maintain and maybe not desirable. Let's look into it maybe after peer deps are added (as it creates some complications with that too).

      // ensure the dependencies align with the lockfile dependencies
      if package.dependencies.len() != version_info.dependencies.len() {
        bail!(
          "the lockfile ({}) had {} dependencies for {}, but the npm registry said there were {}",
          lockfile.lock().filename.display(),
          package.dependencies.len(),
          package.id,
          version_info.dependencies.len(),
        );
      }
      for entry in version_info.dependencies_as_entries()? {
        match package.dependencies.get(&entry.name) {
          Some(dep) => {
            if !entry.version_req.satisfies(&dep.version) {
              bail!(
                "the lockfile ({}) had a dependency requirement of {} for {}, but this didn't satisfy the npm registry's version requirement",
                lockfile.lock().filename.display(),
                // todo...
              );
            }
          }
          None => {
            // todo...better error
            bail!(
              "the lockfile ({}) is corrupt. Recreate it or run again with --no-lock",
              lockfile.lock().filename.display(),
            );
          }
        }
      }

let info = api.package_info(&package_id.name).await?;
Result::<_, AnyError>::Ok((package_id, info))
api.package_info(&package_name).await?;
Result::<_, AnyError>::Ok(())
Copy link
Member Author

@dsherret dsherret Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code change uses less memory and won't cause unresolved_tasks to re-allocate.

cli/npm/resolution.rs Outdated Show resolved Hide resolved
@dsherret dsherret enabled auto-merge (squash) November 2, 2022 00:47
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🙏

@dsherret dsherret merged commit 5e4e324 into denoland:main Nov 2, 2022
DjDeveloperr pushed a commit to DjDeveloperr/deno that referenced this pull request Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants