Skip to content
Snippets Groups Projects
Commit 37e247e1 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

refactor(npm): major minor handling

parent cddd9cd8
No related branches found
No related tags found
No related merge requests found
...@@ -38,7 +38,8 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) { ...@@ -38,7 +38,8 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) {
} }
return `${currentValue} || ${newValue}`; return `${currentValue} || ${newValue}`;
} }
// console.log(range); const toVersionMajor = major(toVersion);
const toVersionMinor = minor(toVersion);
// Simple range // Simple range
if (rangeStrategy === 'bump') { if (rangeStrategy === 'bump') {
if (parsedRange.length === 1) { if (parsedRange.length === 1) {
...@@ -46,11 +47,11 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) { ...@@ -46,11 +47,11 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) {
const split = currentValue.split('.'); const split = currentValue.split('.');
if (split.length === 1) { if (split.length === 1) {
// ^4 // ^4
return '^' + major(toVersion); return '^' + toVersionMajor;
} }
if (split.length === 2) { if (split.length === 2) {
// ^4.1 // ^4.1
return '^' + major(toVersion) + '.' + minor(toVersion); return '^' + toVersionMajor + '.' + toVersionMinor;
} }
return `^${toVersion}`; return `^${toVersion}`;
} }
...@@ -58,11 +59,11 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) { ...@@ -58,11 +59,11 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) {
const split = currentValue.split('.'); const split = currentValue.split('.');
if (split.length === 1) { if (split.length === 1) {
// ~4 // ~4
return '~' + major(toVersion); return '~' + toVersionMajor;
} }
if (split.length === 2) { if (split.length === 2) {
// ~4.1 // ~4.1
return '~' + major(toVersion) + '.' + minor(toVersion); return '~' + toVersionMajor + '.' + toVersionMinor;
} }
return `~${toVersion}`; return `~${toVersion}`;
} }
...@@ -84,31 +85,31 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) { ...@@ -84,31 +85,31 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) {
if (!fromVersion) { if (!fromVersion) {
return `^${toVersion}`; return `^${toVersion}`;
} }
if (major(toVersion) === major(fromVersion)) { if (toVersionMajor === major(fromVersion)) {
if (major(toVersion) === 0) { if (toVersionMajor === 0) {
if (minor(toVersion) === 0) { if (toVersionMinor === 0) {
return `^${toVersion}`; return `^${toVersion}`;
} }
return `^${major(toVersion)}.${minor(toVersion)}.0`; return `^${toVersionMajor}.${toVersionMinor}.0`;
} }
return `^${toVersion}`; return `^${toVersion}`;
} }
return `^${major(toVersion)}.0.0`; return `^${toVersionMajor}.0.0`;
} }
if (element.operator === '=') { if (element.operator === '=') {
return `=${toVersion}`; return `=${toVersion}`;
} }
if (element.operator === '~') { if (element.operator === '~') {
return `~${major(toVersion)}.${minor(toVersion)}.0`; return `~${toVersionMajor}.${toVersionMinor}.0`;
} }
if (element.operator === '<=') { if (element.operator === '<=') {
let res; let res;
if (element.patch) { if (element.patch) {
res = `<=${toVersion}`; res = `<=${toVersion}`;
} else if (element.minor) { } else if (element.minor) {
res = `<=${major(toVersion)}.${minor(toVersion)}`; res = `<=${toVersionMajor}.${toVersionMinor}`;
} else { } else {
res = `<=${major(toVersion)}`; res = `<=${toVersionMajor}`;
} }
if (currentValue.includes('<= ')) { if (currentValue.includes('<= ')) {
res = res.replace('<=', '<= '); res = res.replace('<=', '<= ');
...@@ -118,14 +119,14 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) { ...@@ -118,14 +119,14 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) {
if (element.operator === '<') { if (element.operator === '<') {
let res; let res;
if (currentValue.endsWith('.0.0')) { if (currentValue.endsWith('.0.0')) {
const newMajor = major(toVersion) + 1; const newMajor = toVersionMajor + 1;
res = `<${newMajor}.0.0`; res = `<${newMajor}.0.0`;
} else if (element.patch) { } else if (element.patch) {
res = `<${increment(toVersion, 'patch')}`; res = `<${increment(toVersion, 'patch')}`;
} else if (element.minor) { } else if (element.minor) {
res = `<${major(toVersion)}.${minor(toVersion) + 1}`; res = `<${toVersionMajor}.${toVersionMinor + 1}`;
} else { } else {
res = `<${major(toVersion) + 1}`; res = `<${toVersionMajor + 1}`;
} }
if (currentValue.includes('< ')) { if (currentValue.includes('< ')) {
res = res.replace('<', '< '); res = res.replace('<', '< ');
...@@ -135,20 +136,20 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) { ...@@ -135,20 +136,20 @@ function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) {
if (!element.operator) { if (!element.operator) {
if (element.minor) { if (element.minor) {
if (element.minor === 'x') { if (element.minor === 'x') {
return `${major(toVersion)}.x`; return `${toVersionMajor}.x`;
} }
if (element.minor === '*') { if (element.minor === '*') {
return `${major(toVersion)}.*`; return `${toVersionMajor}.*`;
} }
if (element.patch === 'x') { if (element.patch === 'x') {
return `${major(toVersion)}.${minor(toVersion)}.x`; return `${toVersionMajor}.${toVersionMinor}.x`;
} }
if (element.patch === '*') { if (element.patch === '*') {
return `${major(toVersion)}.${minor(toVersion)}.*`; return `${toVersionMajor}.${toVersionMinor}.*`;
} }
return `${major(toVersion)}.${minor(toVersion)}`; return `${toVersionMajor}.${toVersionMinor}`;
} }
return `${major(toVersion)}`; return `${toVersionMajor}`;
} }
return toVersion; return toVersion;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment