New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

npsh

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npsh - npm Package Compare versions

Comparing version 2.0.0 to 2.0.4

100

lib/svc.js

@@ -11,2 +11,3 @@ /**

const fs = require('fs');
const { nuti } = require('nuti');

@@ -17,7 +18,6 @@ async function svc() {

if (args.length < 3) {
throw new Error('Not enough arguments.');
throw 'svc failed: not enough arguments.';
}
const [user, project, branch] = args;
const semanticVersions = ['major', 'minor', 'patch'];

@@ -30,68 +30,48 @@ const gitHubHost = 'raw.githubusercontent.com';

return new Promise((resolve, reject) => {
https.get(url, (res) => {
let rawData = '';
const { body, ok, status } = await nuti.http.get(url);
res.on('error', (error) =>
reject(`An error occurred during the request: ${error.message}.`),
);
if (!ok) {
throw `Request has failed with status - ${body}.`;
}
res.on('data', (chunk) => {
rawData += chunk;
});
const json = JSON.parse(body);
res.on('end', () => {
try {
if (res.statusCode >= 400) {
throw new Error(`Request has failed with status - ${rawData}.`);
}
nuti.validate(json, { version: 'string' });
const { version } = json;
const { version } = JSON.parse(rawData);
if (version === updatedVersion) {
throw 'Please update semantic version before merging!';
}
if (version === updatedVersion) {
throw new Error('Please update semantic version before merging!');
}
const [major, minor, patch] = versionToNumbers(version);
const masterVersionArr = versionToNumbers(version);
const updatedVersionArr = versionToNumbers(updatedVersion);
const validVersions = {
[major + 1]: {
0: 0,
},
[major]: {
[minor + 1]: 0,
[minor]: patch + 1,
},
};
for (let i = 0; i < 3; i++) {
const masterValue = masterVersionArr[i];
const updatedValue = updatedVersionArr[i];
const semanticVersion = semanticVersions[i];
const [newMajor, newMinor, newPatch] = versionToNumbers(updatedVersion);
if (updatedValue !== masterValue) {
if (updatedValue < masterValue) {
throw new Error(
`The ${semanticVersion} version must not be less than ${masterValue}.`,
);
}
const validMinor = validVersions[newMajor];
if (updatedValue !== masterValue + 1) {
throw new Error(
`The ${semanticVersion} version must be equal to ${
masterValue + 1
}.`,
);
} else {
for (let j = i + 1; j < 3; j++) {
if (updatedVersionArr[j] !== 0) {
throw new Error(
`The ${semanticVersions[j]} version should be equal to 0 after updating ${semanticVersions[i]} version.`,
);
}
}
if (validMinor == null) {
throw generateMessage('Major', Object.keys(validVersions));
}
break;
}
}
}
const validPatch = validMinor[newMinor];
resolve('Semantic versioning is valid.');
} catch (e) {
reject(e.message);
}
});
});
});
if (validPatch == null) {
throw generateMessage('Minor', Object.keys(validMinor));
}
if (validPatch !== newPatch) {
throw generateMessage('Patch', [validPatch]);
}
return 'Semantic versioning is valid.';
}

@@ -104,3 +84,3 @@

if (Number.isNaN(numb)) {
throw new Error(`Semantic version contains not a number: "${value}".`);
throw `Semantic version contains not a number: "${value}".`;
}

@@ -112,2 +92,6 @@

function generateMessage(semver, versions) {
return `${semver} version should be equal to ${versions.join(' or ')}.`;
}
module.exports = svc;
{
"name": "npsh",
"version": "2.0.0",
"version": "2.0.4",
"description": "Node.js package scripts helper",

@@ -32,7 +32,10 @@ "bin": {

"devDependencies": {
"@types/jest": "^29.2.5",
"cspell": "^6.18.1",
"jest": "^29.3.1",
"prettier": "^2.8.2"
"@types/jest": "^29.5.0",
"cspell": "^6.31.1",
"jest": "^29.5.0",
"prettier": "^2.8.7"
},
"dependencies": {
"nuti": "^2.1.1"
}
}
# npsh
[![NPM version][npm-img]][npm-url]
[![Coverage Status][coverage-img]][coverage-url]
[![NPM][npm-img]][npm-url]
[![Coverage][coverage-img]][coverage-url]
[![License][license-pic]][license-url]

@@ -102,5 +103,7 @@ Node.js package scripts helper.

[npm-img]: https://img.shields.io/npm/v/npsh.svg
[npm-img]: https://img.shields.io/npm/v/npsh.svg?logo=npm
[npm-url]: https://www.npmjs.com/package/npsh
[coverage-img]: https://coveralls.io/repos/github/andr-ii/npsh/badge.svg?branch=master
[coverage-img]: https://img.shields.io/coverallsCoverage/github/andr-ii/npsh?label=coverage&logo=jest
[coverage-url]: https://coveralls.io/github/andr-ii/npsh?branch=master
[license-pic]: https://img.shields.io/github/license/andr-ii/npsh?color=blue&label=%C2%A9%20license
[license-url]: https://github.com/andr-ii/npsh/blob/master/LICENSE
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc