npq 3.4.7 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,6 +5,7 @@ const { marshallCategories } = require('./constants')
|
|
|
5
5
|
|
|
6
6
|
const MARSHALL_NAME = 'age'
|
|
7
7
|
const PACKAGE_AGE_THRESHOLD = 22 // specified in days
|
|
8
|
+
const PACKAGE_AGE_UNMAINTAINED_RISK = 365 // specified in days
|
|
8
9
|
|
|
9
10
|
class Marshall extends BaseMarshall {
|
|
10
11
|
constructor(options) {
|
|
@@ -18,22 +19,49 @@ class Marshall extends BaseMarshall {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
validate(pkg) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
)
|
|
22
|
+
let packageData = null
|
|
23
|
+
let ageDateDiff = null
|
|
24
|
+
return this.packageRepoUtils
|
|
25
|
+
.getPackageInfo(pkg.packageName)
|
|
26
|
+
.then((data) => {
|
|
27
|
+
if (data && data.time && data.time.created) {
|
|
28
|
+
packageData = data
|
|
29
|
+
const pkgCreatedDate = data.time.created
|
|
30
|
+
const dateDiff = Date.now() - Date.parse(pkgCreatedDate)
|
|
31
|
+
|
|
32
|
+
ageDateDiff = dateDiff
|
|
33
|
+
if (dateDiff < PACKAGE_AGE_THRESHOLD) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`detected a newly published package (created < ${PACKAGE_AGE_THRESHOLD} days) act carefully`
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return pkg
|
|
40
|
+
} else {
|
|
41
|
+
throw new Error('could not determine package age')
|
|
30
42
|
}
|
|
43
|
+
})
|
|
44
|
+
.then((pkg) => {
|
|
45
|
+
return this.packageRepoUtils.getSemVer(pkg.packageName, pkg.packageVersion)
|
|
46
|
+
})
|
|
47
|
+
.then((versionResolved) => {
|
|
48
|
+
const versionReleaseDate = packageData.time[versionResolved]
|
|
49
|
+
const versionDateDiff = new Date() - new Date(versionReleaseDate)
|
|
50
|
+
|
|
51
|
+
const versionDateDiffInDays = Math.round(versionDateDiff / (1000 * 60 * 60 * 24))
|
|
52
|
+
|
|
53
|
+
let timeAgoText = 'days'
|
|
54
|
+
let timeAgoNumber = versionDateDiffInDays
|
|
31
55
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
56
|
+
if (versionDateDiffInDays >= 365) {
|
|
57
|
+
timeAgoText = 'years'
|
|
58
|
+
timeAgoNumber = Math.floor(versionDateDiffInDays / 365)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (versionDateDiffInDays >= PACKAGE_AGE_UNMAINTAINED_RISK) {
|
|
62
|
+
throw new Error(`detected an old package (created ${timeAgoNumber} ${timeAgoText} ago)`)
|
|
63
|
+
}
|
|
64
|
+
})
|
|
37
65
|
}
|
|
38
66
|
}
|
|
39
67
|
|
|
@@ -70,7 +70,6 @@ class Marshall extends BaseMarshall {
|
|
|
70
70
|
// get date in ms
|
|
71
71
|
const currentDate = new Date()
|
|
72
72
|
const dateDiffInMsVersionPublished = currentDate - new Date(versionPublishedDateString)
|
|
73
|
-
console.log(dateDiffInMsVersionPublished)
|
|
74
73
|
let dateDiffVersionPublished = 0
|
|
75
74
|
if (dateDiffInMsVersionPublished > 0) {
|
|
76
75
|
dateDiffVersionPublished = Math.round(dateDiffInMsVersionPublished / (1000 * 60 * 60 * 24))
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const BaseMarshall = require('./baseMarshall')
|
|
4
|
+
const Warning = require('../helpers/warning')
|
|
4
5
|
const { marshallCategories } = require('./constants')
|
|
5
6
|
|
|
6
7
|
const MARSHALL_NAME = 'downloads'
|
|
7
|
-
const DOWNLOAD_COUNT_THRESHOLD =
|
|
8
|
+
const DOWNLOAD_COUNT_THRESHOLD = 100 // threshold per month
|
|
9
|
+
const DOWNLOAD_COUNT_UPPER_THRESHOLD = 10000 // threshold per month
|
|
8
10
|
|
|
9
11
|
class Marshall extends BaseMarshall {
|
|
10
12
|
constructor(options) {
|
|
@@ -25,6 +27,12 @@ class Marshall extends BaseMarshall {
|
|
|
25
27
|
)
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
if (downloadCount < DOWNLOAD_COUNT_UPPER_THRESHOLD) {
|
|
31
|
+
throw new Warning(
|
|
32
|
+
`detected a low relatively low download-count package (${downloadCount} downloads last month)`
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
return downloadCount
|
|
29
37
|
})
|
|
30
38
|
}
|