npm-package-json-lint
Version:
Configurable linter for package.json files.
2 lines • 5.03 kB
JavaScript
const e=require(`semver`),t=e=>typeof e==`object`&&e.hasOwnProperty(`exceptions`),n=(e,t,n)=>{let r=!1,i=[],a=[],o=[];if(!e.hasOwnProperty(t))return{hasDependencyWithRestrictedPackage:r,dependenciesWithRestrictedPackage:i,dependenciesWithoutRestrictedPackage:a,errorMessage:o.join(`, `)};for(let s in e[t])for(let e of n){let t,n;typeof e==`string`?(t=e,n=``):(t=e.name,n=e.replacement),t===s||t.endsWith(`*`)&&s.startsWith(t.slice(0,Math.max(0,t.length-1)))?(r=!0,i.push(s),o.push(n?`${s} (recommended replacement: ${n})`:s)):a.push(s)}return{hasDependencyWithRestrictedPackage:r,dependenciesWithRestrictedPackage:i,dependenciesWithoutRestrictedPackage:a,errorMessage:o.join(`, `)}},r=(e,t,n)=>{let r=!1,i=[],a=[];if(!e.hasOwnProperty(t))return{hasDependencyWithRestrictedPrereleaseVersion:r,dependenciesWithRestrictedPrereleaseVersion:i,dependenciesWithoutRestrictedPrereleaseVersion:a};for(let o in e[t])if(n.includes(o)){let n=e[t][o];n.includes(`-beta`)||n.includes(`-rc`)?(r=!0,i.push(o)):a.push(o)}return{hasDependencyWithRestrictedPrereleaseVersion:r,dependenciesWithRestrictedPrereleaseVersion:i,dependenciesWithoutRestrictedPrereleaseVersion:a}},i=(n,r,i)=>{let a=!1,o=[],s=[];for(let c in n[r]){if(t(i)&&i.exceptions.includes(c))continue;let l=n[r][c];e.validRange(l)&&(l.replace(/\D+/g,``).substr(0,1)===`0`?(a=!0,o.push(c)):s.push(c))}return{hasDependencyWithMajorVersionOfZero:a,dependenciesWithMajorVersionOfZero:o,dependenciesWithoutMajorVersionOfZero:s}},a=(e,t)=>e.startsWith(t,0),o=(e,n,r,i)=>{let o=!0,s=[],c=[];if(!e.hasOwnProperty(n))return{onlyValidVersionsDetected:o,dependenciesWithValidVersionRange:[],dependenciesWithoutValidVersionRange:[]};for(let l in e[n]){if(t(i)&&i.exceptions.includes(l))continue;let u=e[n][l];a(u,r)?s.push(l):(o=!1,c.push(l))}return{onlyValidVersionsDetected:o,dependenciesWithValidVersionRange:s,dependenciesWithoutValidVersionRange:c}},s=(e,n,r,i)=>{let o=!1,s=[],c=[];if(!e.hasOwnProperty(n))return{hasInvalidRangeVersions:o,dependenciesWithInvalidVersionRange:s,dependenciesWithoutInvalidVersionRange:c};for(let l in e[n]){if(t(i)&&i.exceptions.includes(l))continue;let u=e[n][l];a(u,r)?(o=!0,s.push(l)):c.push(l)}return{hasInvalidRangeVersions:o,dependenciesWithInvalidVersionRange:s,dependenciesWithoutInvalidVersionRange:c}},c=(e,n,r)=>{let i=!0,a=0,o=[],s=[];for(let c in e[n]){if(t(r)&&r.exceptions.includes(c))continue;let l=e[n][c];l.startsWith(`^`,0)||l.startsWith(`~`,0)||l.startsWith(`>`,0)||l.startsWith(`<`,0)||l.indexOf(`*`)!==-1?(i=!1,s.push(c)):o.push(c),a+=1}return{onlyAbsoluteVersionDetected:i,dependenciesChecked:a,dependenciesWithAbsoluteVersion:o,dependenciesWithoutAbsoluteVersion:s}},l=(e,t,n)=>{let{onlyAbsoluteVersionDetected:r,dependenciesChecked:i,dependenciesWithAbsoluteVersion:a,dependenciesWithoutAbsoluteVersion:o}=c(e,t,n);return{onlyAbsoluteVersionsDetected:i>0?r:!1,dependenciesWithAbsoluteVersion:a,dependenciesWithoutAbsoluteVersion:o}},u=(e,t,n)=>{let{onlyAbsoluteVersionDetected:r,dependenciesChecked:i,dependenciesWithAbsoluteVersion:a,dependenciesWithoutAbsoluteVersion:o}=c(e,t,n);return{onlyNonAbsoluteVersionsDetected:i>0?!r:!1,dependenciesWithAbsoluteVersion:a,dependenciesWithoutAbsoluteVersion:o}},d=/^(github:)?[^/]+\/[^/]+/,f=e=>d.test(e),p=e=>e.endsWith(`.tgz`)||e.endsWith(`.tar.gz`)||e.endsWith(`.zip`),m=e=>{if(p(e))return!1;let t=new Set([`git@`,`git://`,`git+https://`,`git+ssh://`,`http://`,`https://`]),n=!1;for(let r of t)if(e.startsWith(r)){n=!0;break}return n},h=(e,n,r)=>{let i=!1,a=[],o=[];for(let s in e[n]){if(t(r)&&r.exceptions.includes(s))continue;let c=e[n][s];m(c)||f(c)?(i=!0,a.push(s)):o.push(s)}return{hasGitRepositoryVersions:i,dependenciesWithGitRepositoryVersion:a,dependenciesWithoutGitRepositoryVersion:o}},g=(e,n,r)=>{let i=!1,a=[],o=[];for(let s in e[n]){if(t(r)&&r.exceptions.includes(s))continue;let c=e[n][s];p(c)?(i=!0,a.push(s)):o.push(s)}return{hasArchiveUrlVersions:i,dependenciesWithArchiveUrlVersion:a,dependenciesWithoutArchiveUrlVersion:o}},_=(e,n,r)=>{let i=!1,a=[],o=[];for(let s in e[n])t(r)&&r.exceptions.includes(s)||(e[n][s].startsWith(`file:`)?(i=!0,a.push(s)):o.push(s));return{hasFileUrlVersions:i,dependenciesWithFileUrlVersion:a,dependenciesWithoutFileUrlVersion:o}};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return r}});
//# sourceMappingURL=dependency-audit.js.map