From 2a5c0fbc3235c94a609fe26146e72d17f6423f85 Mon Sep 17 00:00:00 2001
From: Gabriel-Ladzaretti
 <97394622+Gabriel-Ladzaretti@users.noreply.github.com>
Date: Mon, 17 Oct 2022 20:54:46 +0300
Subject: [PATCH] fix(npm/versioning): exception when directly calling
 getNewValue with x-range-all '*' with unsupported strategy (#18379)

---
 lib/modules/versioning/npm/index.spec.ts | 4 ++++
 lib/modules/versioning/npm/range.ts      | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/modules/versioning/npm/index.spec.ts b/lib/modules/versioning/npm/index.spec.ts
index add819c763..53183b4135 100644
--- a/lib/modules/versioning/npm/index.spec.ts
+++ b/lib/modules/versioning/npm/index.spec.ts
@@ -85,6 +85,10 @@ describe('modules/versioning/npm/index', () => {
     ${'>= 0.0.1 < 1'}       | ${'bump'}            | ${'1.0.0'}       | ${'1.0.1'}              | ${'>= 1.0.1 < 2'}
     ${'>= 0.0.1 < 1'}       | ${'bump'}            | ${'1.0.0'}       | ${'1.0.1'}              | ${'>= 1.0.1 < 2'}
     ${'*'}                  | ${'bump'}            | ${'1.0.0'}       | ${'1.0.1'}              | ${null}
+    ${'*'}                  | ${'replace'}         | ${'1.0.0'}       | ${'1.0.1'}              | ${null}
+    ${'*'}                  | ${'widen'}           | ${'1.0.0'}       | ${'1.0.1'}              | ${null}
+    ${'*'}                  | ${'pin'}             | ${'1.0.0'}       | ${'1.0.1'}              | ${'1.0.1'}
+    ${'*'}                  | ${'update-lockfile'} | ${'1.0.0'}       | ${'1.0.1'}              | ${'*'}
     ${'<=1.2.3'}            | ${'widen'}           | ${'1.0.0'}       | ${'1.2.3'}              | ${'<=1.2.3'}
     ${'<=1.2.3'}            | ${'widen'}           | ${'1.0.0'}       | ${'1.2.4'}              | ${'<=1.2.4'}
     ${'>=1.2.3'}            | ${'widen'}           | ${'1.0.0'}       | ${'1.2.3'}              | ${'>=1.2.3'}
diff --git a/lib/modules/versioning/npm/range.ts b/lib/modules/versioning/npm/range.ts
index 8ddfad58d3..37140e3d9c 100644
--- a/lib/modules/versioning/npm/range.ts
+++ b/lib/modules/versioning/npm/range.ts
@@ -64,7 +64,10 @@ export function getNewValue({
   currentVersion,
   newVersion,
 }: NewValueConfig): string | null {
-  if (rangeStrategy === 'bump' && isSemVerXRange(currentValue)) {
+  if (
+    !['pin', 'update-lockfile'].includes(rangeStrategy) &&
+    isSemVerXRange(currentValue)
+  ) {
     return null;
   }
   if (rangeStrategy === 'pin' || isVersion(currentValue)) {
-- 
GitLab