npq 3.4.8 → 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
- return this.packageRepoUtils.getPackageInfo(pkg.packageName).then((data) => {
22
- if (data && data.time && data.time.created) {
23
- const pkgCreatedDate = data.time.created
24
- const dateDiff = Date.now() - Date.parse(pkgCreatedDate)
25
-
26
- if (dateDiff < PACKAGE_AGE_THRESHOLD) {
27
- throw new Error(
28
- `detected a newly published package (created < ${PACKAGE_AGE_THRESHOLD} days) act carefully`
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
- return dateDiff
33
- } else {
34
- throw new Error('could not determine package age')
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npq",
3
- "version": "3.4.8",
3
+ "version": "3.5.0",
4
4
  "description": "marshall your npm/npm package installs with high quality and class 🎖",
5
5
  "bin": {
6
6
  "npq": "./bin/npq.js",