summaryrefslogtreecommitdiff
path: root/cli/npm/semver
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-11-08 14:17:24 -0500
committerGitHub <noreply@github.com>2022-11-08 14:17:24 -0500
commitcbb3f854332c348bb253e1284f7dcd7287bdf28d (patch)
tree93e2db9439bd745d48118a931bdc8bea61b81af5 /cli/npm/semver
parent2c72e8d5f45f12948310c1f0e1e2ed4f1d80fb51 (diff)
feat(unstable/npm): support peer dependencies (#16561)
This adds support for peer dependencies in npm packages. 1. If not found higher in the tree (ancestor and ancestor siblings), peer dependencies are resolved like a dependency similar to npm 7. 2. Optional peer dependencies are only resolved if found higher in the tree. 3. This creates "copy packages" or duplicates of a package when a package has different resolution due to peer dependency resolution—see https://pnpm.io/how-peers-are-resolved. Unlike pnpm though, duplicates of packages will have `_1`, `_2`, etc. added to the end of the package version in the directory in order to minimize the chance of hitting the max file path limit on Windows. This is done for both the local "node_modules" directory and also the global npm cache. The files are hard linked in this case to reduce hard drive space. This is a first pass and the code is definitely more inefficient than it could be. Closes #15823
Diffstat (limited to 'cli/npm/semver')
-rw-r--r--cli/npm/semver/errors.rs38
-rw-r--r--cli/npm/semver/mod.rs2
-rw-r--r--cli/npm/semver/specifier.rs1
3 files changed, 0 insertions, 41 deletions
diff --git a/cli/npm/semver/errors.rs b/cli/npm/semver/errors.rs
deleted file mode 100644
index 530d73c55..000000000
--- a/cli/npm/semver/errors.rs
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
-
-use deno_core::anyhow::bail;
-use deno_core::error::AnyError;
-use monch::ParseError;
-use monch::ParseErrorFailure;
-use monch::ParseResult;
-
-pub fn with_failure_handling<'a, T>(
- combinator: impl Fn(&'a str) -> ParseResult<T>,
-) -> impl Fn(&'a str) -> Result<T, AnyError> {
- move |input| match combinator(input) {
- Ok((input, result)) => {
- if !input.is_empty() {
- error_for_failure(fail_for_trailing_input(input))
- } else {
- Ok(result)
- }
- }
- Err(ParseError::Backtrace) => {
- error_for_failure(fail_for_trailing_input(input))
- }
- Err(ParseError::Failure(e)) => error_for_failure(e),
- }
-}
-
-fn error_for_failure<T>(e: ParseErrorFailure) -> Result<T, AnyError> {
- bail!(
- "{}\n {}\n ~",
- e.message,
- // truncate the output to prevent wrapping in the console
- e.input.chars().take(60).collect::<String>()
- )
-}
-
-fn fail_for_trailing_input(input: &str) -> ParseErrorFailure {
- ParseErrorFailure::new(input, "Unexpected character.")
-}
diff --git a/cli/npm/semver/mod.rs b/cli/npm/semver/mod.rs
index 90352817f..cd63b2a29 100644
--- a/cli/npm/semver/mod.rs
+++ b/cli/npm/semver/mod.rs
@@ -11,7 +11,6 @@ use serde::Serialize;
use crate::npm::resolution::NpmVersionMatcher;
-use self::errors::with_failure_handling;
use self::range::Partial;
use self::range::VersionBoundKind;
use self::range::VersionRange;
@@ -20,7 +19,6 @@ use self::range::VersionRangeSet;
use self::range::XRange;
pub use self::specifier::SpecifierVersionReq;
-mod errors;
mod range;
mod specifier;
diff --git a/cli/npm/semver/specifier.rs b/cli/npm/semver/specifier.rs
index c3e7f716b..dc4fe1010 100644
--- a/cli/npm/semver/specifier.rs
+++ b/cli/npm/semver/specifier.rs
@@ -6,7 +6,6 @@ use monch::*;
use serde::Deserialize;
use serde::Serialize;
-use super::errors::with_failure_handling;
use super::range::Partial;
use super::range::VersionRange;
use super::range::XRange;