npq 2.3.1 → 2.4.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.
- package/.github/mergify.yml +17 -0
- package/__tests__/__fixtures__/test.marshall.js +6 -6
- package/__tests__/marshalls.tasks.test.js +1 -1
- package/lib/cliCommons.js +2 -2
- package/lib/helpers/packageRepoUtils.js +8 -8
- package/lib/marshall.js +7 -7
- package/lib/marshalls/age.marshall.js +3 -3
- package/lib/marshalls/author.marshall.js +3 -3
- package/lib/marshalls/baseMarshall.js +12 -19
- package/lib/marshalls/downloads.marshall.js +3 -3
- package/lib/marshalls/expiredDomains.marshall.js +3 -3
- package/lib/marshalls/index.js +5 -5
- package/lib/marshalls/license.marshall.js +3 -3
- package/lib/marshalls/readme.marshall.js +3 -3
- package/lib/marshalls/repo.marshall.js +3 -3
- package/lib/marshalls/scripts.marshall.js +3 -3
- package/lib/marshalls/signatures.marshall.js +62 -0
- package/lib/marshalls/snyk.marshall.js +7 -7
- package/lib/packageManager.js +4 -4
- package/package.json +2 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
queue_rules:
|
|
2
|
+
- name: Snyk PRs Queue
|
|
3
|
+
conditions:
|
|
4
|
+
- "check-success ~= .*"
|
|
5
|
+
|
|
6
|
+
pull_request_rules:
|
|
7
|
+
- name: Automatic merge Snyk PRs on Status Checks passing
|
|
8
|
+
conditions:
|
|
9
|
+
- title~=^\[Snyk\]
|
|
10
|
+
- head~=^snyk-fix
|
|
11
|
+
- base=main
|
|
12
|
+
actions:
|
|
13
|
+
queue:
|
|
14
|
+
name: "Snyk PRs Queue"
|
|
15
|
+
label:
|
|
16
|
+
add:
|
|
17
|
+
- "auto-merge"
|
|
@@ -5,16 +5,16 @@ const BaseMarshall = require('../../lib/marshalls/baseMarshall')
|
|
|
5
5
|
const MARSHALL_NAME = 'test.marshall'
|
|
6
6
|
|
|
7
7
|
class TestMarshall extends BaseMarshall {
|
|
8
|
-
constructor
|
|
8
|
+
constructor(options) {
|
|
9
9
|
super(options)
|
|
10
10
|
this.name = MARSHALL_NAME
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
title
|
|
13
|
+
title() {
|
|
14
14
|
return 'A test marshall'
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
run
|
|
17
|
+
run(ctx, task) {
|
|
18
18
|
const tasks = ctx.pkgs.reduce((prevPkg, currPkg) => {
|
|
19
19
|
return prevPkg.concat(this.mockCheck(currPkg, ctx, task))
|
|
20
20
|
}, [])
|
|
@@ -22,7 +22,7 @@ class TestMarshall extends BaseMarshall {
|
|
|
22
22
|
return Promise.all(tasks)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
mockCheck
|
|
25
|
+
mockCheck(pkg, ctx, task) {
|
|
26
26
|
return this.validateSomething(pkg)
|
|
27
27
|
.then(() => {
|
|
28
28
|
const data = 'mock data check'
|
|
@@ -39,7 +39,7 @@ class TestMarshall extends BaseMarshall {
|
|
|
39
39
|
})
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
validateSomething
|
|
42
|
+
validateSomething(pkg) {
|
|
43
43
|
if (pkg === 'express' || pkg === 'semver') {
|
|
44
44
|
return Promise.resolve()
|
|
45
45
|
} else {
|
|
@@ -47,7 +47,7 @@ class TestMarshall extends BaseMarshall {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
validate
|
|
50
|
+
validate(pkg) {
|
|
51
51
|
if (pkg === 'express' || pkg === 'semver') {
|
|
52
52
|
return Promise.resolve('validation-result')
|
|
53
53
|
} else {
|
package/lib/cliCommons.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const npa = require('npm-package-arg')
|
|
2
2
|
class cliCommons {
|
|
3
|
-
static getInstallCommand
|
|
3
|
+
static getInstallCommand() {
|
|
4
4
|
return {
|
|
5
5
|
command: 'install [package...]',
|
|
6
6
|
aliases: [
|
|
@@ -31,7 +31,7 @@ class cliCommons {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
static getOptions
|
|
34
|
+
static getOptions() {
|
|
35
35
|
return {
|
|
36
36
|
P: {
|
|
37
37
|
alias: ['save-prod', 'peer'],
|
|
@@ -6,17 +6,17 @@ const NPM_REGISTRY = 'http://registry.npmjs.org'
|
|
|
6
6
|
const NPM_REGISTRY_API = 'https://api.npmjs.org'
|
|
7
7
|
|
|
8
8
|
class PackageRepoUtils {
|
|
9
|
-
constructor
|
|
9
|
+
constructor(options = {}) {
|
|
10
10
|
this.registryUrl = options.registryUrl ? options.registryUrl : NPM_REGISTRY
|
|
11
11
|
this.registryApiUrl = options.registryApiUrl ? options.registryApiUrl : NPM_REGISTRY_API
|
|
12
12
|
this.pkgInfoCache = {}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
formatPackageForUrl
|
|
15
|
+
formatPackageForUrl(pkg) {
|
|
16
16
|
return pkg.replace(/\//g, '%2F')
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
getPackageInfo
|
|
19
|
+
getPackageInfo(pkg) {
|
|
20
20
|
if (this.pkgInfoCache[pkg]) {
|
|
21
21
|
return Promise.resolve(this.pkgInfoCache[pkg])
|
|
22
22
|
} else {
|
|
@@ -29,27 +29,27 @@ class PackageRepoUtils {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
getLatestVersion
|
|
32
|
+
getLatestVersion(pkg) {
|
|
33
33
|
return this.getPackageInfo(pkg).then((data) => {
|
|
34
34
|
return data['dist-tags'] && data['dist-tags']['latest'] ? data['dist-tags']['latest'] : null
|
|
35
35
|
})
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
getDownloadInfo
|
|
38
|
+
getDownloadInfo(pkg) {
|
|
39
39
|
return fetch(`${this.registryApiUrl}/downloads/point/last-month/${pkg}`)
|
|
40
40
|
.then((response) => response.json())
|
|
41
41
|
.then(({ downloads }) => downloads)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
getReadmeInfo
|
|
44
|
+
getReadmeInfo(pkg) {
|
|
45
45
|
return this.getPackageInfo(pkg).then(({ readme }) => readme)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
getLicenseInfo
|
|
48
|
+
getLicenseInfo(pkg) {
|
|
49
49
|
return this.getPackageInfo(pkg).then(({ license }) => license)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
parsePackageVersion
|
|
52
|
+
parsePackageVersion(version) {
|
|
53
53
|
return semver.coerce(version)
|
|
54
54
|
}
|
|
55
55
|
}
|
package/lib/marshall.js
CHANGED
|
@@ -12,12 +12,12 @@ const MESSAGE_TYPE = {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
class Marshall {
|
|
15
|
-
constructor
|
|
15
|
+
constructor(options = {}) {
|
|
16
16
|
this.pkgs = options ? options.pkgs : null
|
|
17
17
|
this.packageRepoUtils = new PackageRepoUtils()
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
process
|
|
20
|
+
process() {
|
|
21
21
|
// nothing to do? move on
|
|
22
22
|
if (!this.pkgs) {
|
|
23
23
|
return Promise.resolve()
|
|
@@ -37,7 +37,7 @@ class Marshall {
|
|
|
37
37
|
})
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
createPackageVersionMaps
|
|
40
|
+
createPackageVersionMaps(packages) {
|
|
41
41
|
const packageVersionMapping = packages.reduce((prev, curr) => {
|
|
42
42
|
const versionSymbolPosition = curr.lastIndexOf('@')
|
|
43
43
|
const versionPosition =
|
|
@@ -57,7 +57,7 @@ class Marshall {
|
|
|
57
57
|
return packageVersionMapping
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
report
|
|
60
|
+
report(marshalls) {
|
|
61
61
|
const messages = this.collectPackageMessages(marshalls)
|
|
62
62
|
|
|
63
63
|
if (!messages) {
|
|
@@ -81,7 +81,7 @@ class Marshall {
|
|
|
81
81
|
return { error: true, data: messages }
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
collectPackageMessages
|
|
84
|
+
collectPackageMessages(marshalls) {
|
|
85
85
|
const allPackageMessages = {}
|
|
86
86
|
for (const key in marshalls) {
|
|
87
87
|
this.prepareMessages(allPackageMessages, marshalls[key].errors)
|
|
@@ -91,7 +91,7 @@ class Marshall {
|
|
|
91
91
|
return allPackageMessages
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
prepareMessages
|
|
94
|
+
prepareMessages(allPackageMessages, messages, isWarning) {
|
|
95
95
|
if (Array.isArray(messages) && messages.length > 0) {
|
|
96
96
|
messages.forEach((msg) => {
|
|
97
97
|
this.appendPackageMessage(allPackageMessages, msg.pkg, {
|
|
@@ -102,7 +102,7 @@ class Marshall {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
appendPackageMessage
|
|
105
|
+
appendPackageMessage(packages, packageName, packageMessage) {
|
|
106
106
|
packages[packageName]
|
|
107
107
|
? packages[packageName].push(packageMessage)
|
|
108
108
|
: (packages[packageName] = [packageMessage])
|
|
@@ -6,16 +6,16 @@ const MARSHALL_NAME = 'age'
|
|
|
6
6
|
const PACKAGE_AGE_THRESHOLD = 22 // specified in days
|
|
7
7
|
|
|
8
8
|
class Marshall extends BaseMarshall {
|
|
9
|
-
constructor
|
|
9
|
+
constructor(options) {
|
|
10
10
|
super(options)
|
|
11
11
|
this.name = MARSHALL_NAME
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
title
|
|
14
|
+
title() {
|
|
15
15
|
return 'Checking package maturity'
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
validate
|
|
18
|
+
validate(pkg) {
|
|
19
19
|
return this.packageRepoUtils.getPackageInfo(pkg.packageName).then((data) => {
|
|
20
20
|
if (data && data.time && data.time.created) {
|
|
21
21
|
const pkgCreatedDate = data.time.created
|
|
@@ -7,16 +7,16 @@ const Warning = require('../helpers/warning')
|
|
|
7
7
|
const MARSHALL_NAME = 'author'
|
|
8
8
|
|
|
9
9
|
class Marshall extends BaseMarshall {
|
|
10
|
-
constructor
|
|
10
|
+
constructor(options) {
|
|
11
11
|
super(options)
|
|
12
12
|
this.name = MARSHALL_NAME
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
title
|
|
15
|
+
title() {
|
|
16
16
|
return 'Identifying package author...'
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
validate
|
|
19
|
+
validate(pkg) {
|
|
20
20
|
return this.packageRepoUtils.getPackageInfo(pkg.packageName).then((data) => {
|
|
21
21
|
const lastVersionData =
|
|
22
22
|
data.versions && data['dist-tags'] && data.versions[data['dist-tags']['latest']]
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
const Warning = require('../helpers/warning')
|
|
4
4
|
|
|
5
5
|
class BaseMarshall {
|
|
6
|
-
constructor
|
|
6
|
+
constructor(options) {
|
|
7
7
|
this.packageRepoUtils = options.packageRepoUtils
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
init
|
|
10
|
+
init(ctx, task) {
|
|
11
11
|
this.ctx = ctx
|
|
12
12
|
this.task = task
|
|
13
13
|
|
|
@@ -19,7 +19,7 @@ class BaseMarshall {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
run
|
|
22
|
+
run(ctx, task) {
|
|
23
23
|
const tasks = ctx.pkgs.reduce((prevPkg, currPkg) => {
|
|
24
24
|
return prevPkg.concat(this.checkPackage(currPkg, ctx, task))
|
|
25
25
|
}, [])
|
|
@@ -27,7 +27,7 @@ class BaseMarshall {
|
|
|
27
27
|
return Promise.all(tasks)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
checkPackage
|
|
30
|
+
checkPackage(pkg, ctx, task) {
|
|
31
31
|
return this.validate(pkg)
|
|
32
32
|
.then((data) => {
|
|
33
33
|
task.output = `querying ${pkg.packageString}...`
|
|
@@ -37,30 +37,23 @@ class BaseMarshall {
|
|
|
37
37
|
return data
|
|
38
38
|
})
|
|
39
39
|
.catch((err) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
pkg: pkg.packageString,
|
|
44
|
-
message: err.message
|
|
45
|
-
},
|
|
46
|
-
true
|
|
47
|
-
)
|
|
48
|
-
} else {
|
|
49
|
-
this.setMessage({
|
|
40
|
+
this.setMessage(
|
|
41
|
+
{
|
|
50
42
|
pkg: pkg.packageString,
|
|
51
43
|
message: err.message
|
|
52
|
-
}
|
|
53
|
-
|
|
44
|
+
},
|
|
45
|
+
Boolean(err instanceof Warning)
|
|
46
|
+
)
|
|
54
47
|
})
|
|
55
48
|
}
|
|
56
49
|
|
|
57
|
-
isEnabled
|
|
50
|
+
isEnabled() {
|
|
58
51
|
const isMarshallSilent = process.env[`MARSHALL_DISABLE_${this.name.toUpperCase()}`] || false
|
|
59
52
|
|
|
60
53
|
return !isMarshallSilent
|
|
61
54
|
}
|
|
62
55
|
|
|
63
|
-
setMessage
|
|
56
|
+
setMessage(msg, isWarning) {
|
|
64
57
|
const messages = isWarning
|
|
65
58
|
? this.ctx.marshalls[this.name].warnings
|
|
66
59
|
: this.ctx.marshalls[this.name].errors
|
|
@@ -71,7 +64,7 @@ class BaseMarshall {
|
|
|
71
64
|
})
|
|
72
65
|
}
|
|
73
66
|
|
|
74
|
-
handleMessages
|
|
67
|
+
handleMessages() {
|
|
75
68
|
const errors = this.ctx.marshalls[this.name].errors
|
|
76
69
|
const warnings = this.ctx.marshalls[this.name].warnings
|
|
77
70
|
if ((errors && errors.length) || (warnings && warnings.length)) {
|
|
@@ -6,16 +6,16 @@ const MARSHALL_NAME = 'downloads'
|
|
|
6
6
|
const DOWNLOAD_COUNT_THRESHOLD = 20 // threshold per month
|
|
7
7
|
|
|
8
8
|
class Marshall extends BaseMarshall {
|
|
9
|
-
constructor
|
|
9
|
+
constructor(options) {
|
|
10
10
|
super(options)
|
|
11
11
|
this.name = MARSHALL_NAME
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
title
|
|
14
|
+
title() {
|
|
15
15
|
return 'Checking package download popularity'
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
validate
|
|
18
|
+
validate(pkg) {
|
|
19
19
|
return this.packageRepoUtils.getDownloadInfo(pkg.packageName).then((downloadCount) => {
|
|
20
20
|
if (downloadCount < DOWNLOAD_COUNT_THRESHOLD) {
|
|
21
21
|
throw new Error(
|
|
@@ -6,16 +6,16 @@ const dns = require('dns').promises
|
|
|
6
6
|
const MARSHALL_NAME = 'maintainers_expired_emails'
|
|
7
7
|
|
|
8
8
|
class Marshall extends BaseMarshall {
|
|
9
|
-
constructor
|
|
9
|
+
constructor(options) {
|
|
10
10
|
super(options)
|
|
11
11
|
this.name = MARSHALL_NAME
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
title
|
|
14
|
+
title() {
|
|
15
15
|
return 'Detecting expired domains for authors account...'
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
validate
|
|
18
|
+
validate(pkg) {
|
|
19
19
|
return this.packageRepoUtils
|
|
20
20
|
.getPackageInfo(pkg.packageName)
|
|
21
21
|
.then((data) => {
|
package/lib/marshalls/index.js
CHANGED
|
@@ -4,7 +4,7 @@ const Listr = require('listr')
|
|
|
4
4
|
const glob = require('glob')
|
|
5
5
|
|
|
6
6
|
class Marshalls {
|
|
7
|
-
static collectMarshalls
|
|
7
|
+
static collectMarshalls() {
|
|
8
8
|
return new Promise((resolve, reject) => {
|
|
9
9
|
glob(
|
|
10
10
|
this.GLOB_MARSHALLS,
|
|
@@ -23,7 +23,7 @@ class Marshalls {
|
|
|
23
23
|
})
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
static buildMarshallTasks
|
|
26
|
+
static buildMarshallTasks(marshalls, config) {
|
|
27
27
|
if (!marshalls || !Array.isArray(marshalls) || marshalls.length === 0) {
|
|
28
28
|
return Promise.reject(new Error('unable to collect marshalls, or no marshalls found'))
|
|
29
29
|
}
|
|
@@ -46,7 +46,7 @@ class Marshalls {
|
|
|
46
46
|
return new Listr(marshallTasks, { exitOnError: false, concurrent: true })
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
static tasks
|
|
49
|
+
static tasks(options) {
|
|
50
50
|
return Marshalls.warmUpPackagesCache(options)
|
|
51
51
|
.then(() => Marshalls.collectMarshalls())
|
|
52
52
|
.then((marshalls) => {
|
|
@@ -59,7 +59,7 @@ class Marshalls {
|
|
|
59
59
|
})
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
static warmUpPackagesCache
|
|
62
|
+
static warmUpPackagesCache(options) {
|
|
63
63
|
const fetchPackagesInfoPromises = []
|
|
64
64
|
options.pkgs.forEach((packageMeta) => {
|
|
65
65
|
fetchPackagesInfoPromises.push(
|
|
@@ -70,7 +70,7 @@ class Marshalls {
|
|
|
70
70
|
return Promise.all(fetchPackagesInfoPromises)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
static runTasks
|
|
73
|
+
static runTasks(tasks, options) {
|
|
74
74
|
return tasks.run({
|
|
75
75
|
pkgs: options.pkgs,
|
|
76
76
|
marshalls: {}
|
|
@@ -5,16 +5,16 @@ const BaseMarshall = require('./baseMarshall')
|
|
|
5
5
|
const MARSHALL_NAME = 'license'
|
|
6
6
|
|
|
7
7
|
class Marshall extends BaseMarshall {
|
|
8
|
-
constructor
|
|
8
|
+
constructor(options) {
|
|
9
9
|
super(options)
|
|
10
10
|
this.name = MARSHALL_NAME
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
title
|
|
13
|
+
title() {
|
|
14
14
|
return 'Checking availability of a LICENSE'
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
validate
|
|
17
|
+
validate(pkg) {
|
|
18
18
|
return this.packageRepoUtils.getLicenseInfo(pkg.packageName).then((licenseContents) => {
|
|
19
19
|
if (!licenseContents || licenseContents === 'ERROR: No LICENSE data found!') {
|
|
20
20
|
throw new Error('package has no LICENSE file available')
|
|
@@ -5,16 +5,16 @@ const BaseMarshall = require('./baseMarshall')
|
|
|
5
5
|
const MARSHALL_NAME = 'readme'
|
|
6
6
|
|
|
7
7
|
class Marshall extends BaseMarshall {
|
|
8
|
-
constructor
|
|
8
|
+
constructor(options) {
|
|
9
9
|
super(options)
|
|
10
10
|
this.name = MARSHALL_NAME
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
title
|
|
13
|
+
title() {
|
|
14
14
|
return 'Checking availability of a README'
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
validate
|
|
17
|
+
validate(pkg) {
|
|
18
18
|
return this.packageRepoUtils.getReadmeInfo(pkg.packageName).then((readmeContents) => {
|
|
19
19
|
if (!readmeContents || readmeContents === 'ERROR: No README data found!') {
|
|
20
20
|
throw new Error('package has no README file available')
|
|
@@ -6,16 +6,16 @@ const URL = require('url').URL
|
|
|
6
6
|
const MARSHALL_NAME = 'repo'
|
|
7
7
|
|
|
8
8
|
class Marshall extends BaseMarshall {
|
|
9
|
-
constructor
|
|
9
|
+
constructor(options) {
|
|
10
10
|
super(options)
|
|
11
11
|
this.name = MARSHALL_NAME
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
title
|
|
14
|
+
title() {
|
|
15
15
|
return 'Identifying package repository...'
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
validate
|
|
18
|
+
validate(pkg) {
|
|
19
19
|
return this.packageRepoUtils.getPackageInfo(pkg.packageName).then((data) => {
|
|
20
20
|
const lastVersionData =
|
|
21
21
|
(data.versions &&
|
|
@@ -5,16 +5,16 @@ const BaseMarshall = require('./baseMarshall')
|
|
|
5
5
|
const MARSHALL_NAME = 'scripts'
|
|
6
6
|
|
|
7
7
|
class Marshall extends BaseMarshall {
|
|
8
|
-
constructor
|
|
8
|
+
constructor(options) {
|
|
9
9
|
super(options)
|
|
10
10
|
this.name = MARSHALL_NAME
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
title
|
|
13
|
+
title() {
|
|
14
14
|
return 'Checking package for pre/post install scripts'
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
validate
|
|
17
|
+
validate(pkg) {
|
|
18
18
|
return this.packageRepoUtils.getPackageInfo(pkg.packageName).then((data) => {
|
|
19
19
|
const packageVersion =
|
|
20
20
|
pkg.packageVersion === 'latest'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const BaseMarshall = require('./baseMarshall')
|
|
4
|
+
const pacote = require('pacote')
|
|
5
|
+
|
|
6
|
+
const MARSHALL_NAME = 'signatures'
|
|
7
|
+
|
|
8
|
+
class Marshall extends BaseMarshall {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super(options)
|
|
11
|
+
this.name = MARSHALL_NAME
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
title() {
|
|
15
|
+
return 'Verifying registry signatures for package'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
validate(pkg) {
|
|
19
|
+
// @TODO currently we're hardcoding the official npm registry
|
|
20
|
+
// this should however allow for local proxies and other registries
|
|
21
|
+
return this.fetchRegistryKeys()
|
|
22
|
+
.then((keys) => {
|
|
23
|
+
return pacote.manifest(`${pkg.packageName}@${pkg.packageVersion}`, {
|
|
24
|
+
verifySignatures: true,
|
|
25
|
+
registry: 'https://registry.npmjs.org',
|
|
26
|
+
|
|
27
|
+
[`//registry.npmjs.org/:_keys`]: keys
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
.then((metadata) => {
|
|
31
|
+
return metadata
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fetchRegistryKeys() {
|
|
36
|
+
const registryHost = 'https://registry.npmjs.org'
|
|
37
|
+
const registryKeysEndpoint = '/-/npm/v1/keys'
|
|
38
|
+
|
|
39
|
+
const registryKeysUrl = `${registryHost}${registryKeysEndpoint}`
|
|
40
|
+
// eslint-disable-next-line no-undef
|
|
41
|
+
return fetch(registryKeysUrl)
|
|
42
|
+
.then((response) => {
|
|
43
|
+
return response.json()
|
|
44
|
+
})
|
|
45
|
+
.then((response) => {
|
|
46
|
+
const registryKeys = response.keys
|
|
47
|
+
|
|
48
|
+
return registryKeys.map((key) => ({
|
|
49
|
+
...key,
|
|
50
|
+
pemkey: `-----BEGIN PUBLIC KEY-----\n${key.key}\n-----END PUBLIC KEY-----`
|
|
51
|
+
}))
|
|
52
|
+
})
|
|
53
|
+
.then((keys) => {
|
|
54
|
+
return keys
|
|
55
|
+
})
|
|
56
|
+
.catch((error) => {
|
|
57
|
+
throw new Error(`error fetching registry keys: ${error.message}`)
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = Marshall
|
|
@@ -14,18 +14,18 @@ const SNYK_API_TOKEN = process.env.SNYK_TOKEN
|
|
|
14
14
|
const SNYK_CONFIG_FILE = '.config/configstore/snyk.json'
|
|
15
15
|
|
|
16
16
|
class Marshall extends BaseMarshall {
|
|
17
|
-
constructor
|
|
17
|
+
constructor(options) {
|
|
18
18
|
super(options)
|
|
19
19
|
this.name = MARSHALL_NAME
|
|
20
20
|
|
|
21
21
|
this.snykApiToken = this.getSnykToken()
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
title
|
|
24
|
+
title() {
|
|
25
25
|
return 'Checking for known vulnerabilities'
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
run
|
|
28
|
+
run(ctx, task) {
|
|
29
29
|
const tasks = ctx.pkgs.reduce((prevPkg, currPkg) => {
|
|
30
30
|
return prevPkg.concat(this.checkPackage(currPkg, ctx, task))
|
|
31
31
|
}, [])
|
|
@@ -33,7 +33,7 @@ class Marshall extends BaseMarshall {
|
|
|
33
33
|
return Promise.all(tasks)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
validate
|
|
36
|
+
validate(pkg) {
|
|
37
37
|
return Promise.resolve()
|
|
38
38
|
.then(() => {
|
|
39
39
|
if (!pkg.packageVersion || pkg.packageVersion === 'latest') {
|
|
@@ -60,7 +60,7 @@ class Marshall extends BaseMarshall {
|
|
|
60
60
|
})
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
getSnykVulnInfoUnauthenticated
|
|
63
|
+
getSnykVulnInfoUnauthenticated({ packageName, packageVersion }) {
|
|
64
64
|
const url = encodeURI(`${SNYK_TEST_URL}/${packageName}/${packageVersion}?type=json`)
|
|
65
65
|
|
|
66
66
|
return fetch(url)
|
|
@@ -77,7 +77,7 @@ class Marshall extends BaseMarshall {
|
|
|
77
77
|
.catch(() => false)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
getSnykVulnInfo
|
|
80
|
+
getSnykVulnInfo({ packageName, packageVersion } = {}) {
|
|
81
81
|
if (!this.snykApiToken) {
|
|
82
82
|
return this.getSnykVulnInfoUnauthenticated({ packageName, packageVersion })
|
|
83
83
|
}
|
|
@@ -102,7 +102,7 @@ class Marshall extends BaseMarshall {
|
|
|
102
102
|
.catch(() => false)
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
getSnykToken
|
|
105
|
+
getSnykToken() {
|
|
106
106
|
if (SNYK_API_TOKEN) {
|
|
107
107
|
return SNYK_API_TOKEN
|
|
108
108
|
}
|
package/lib/packageManager.js
CHANGED
|
@@ -5,12 +5,12 @@ const childProcess = require('child_process')
|
|
|
5
5
|
const DEFAULT_PKGMGR = 'npm'
|
|
6
6
|
|
|
7
7
|
class packageManager {
|
|
8
|
-
static process
|
|
8
|
+
static process(packageManagerOption) {
|
|
9
9
|
const detectedPackageManager = packageManager.validatePackageManager(packageManagerOption)
|
|
10
10
|
return packageManager.spawnPackageManager(detectedPackageManager)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
static spawnPackageManager
|
|
13
|
+
static spawnPackageManager(packageManagerOption) {
|
|
14
14
|
let args = []
|
|
15
15
|
|
|
16
16
|
args = args.concat(process.argv.slice(2)).filter((item) => {
|
|
@@ -32,7 +32,7 @@ class packageManager {
|
|
|
32
32
|
return Promise.resolve(child)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
static validatePackageManager
|
|
35
|
+
static validatePackageManager(packageManagerOption) {
|
|
36
36
|
if (!packageManagerOption) {
|
|
37
37
|
packageManagerOption = packageManager.getDefaultPackageManager()
|
|
38
38
|
}
|
|
@@ -44,7 +44,7 @@ class packageManager {
|
|
|
44
44
|
return packageManagerOption
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
static getDefaultPackageManager
|
|
47
|
+
static getDefaultPackageManager() {
|
|
48
48
|
return DEFAULT_PKGMGR
|
|
49
49
|
}
|
|
50
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npq",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "marshall your npm/yarn package installs with high quality and class 🎖",
|
|
5
5
|
"bin": {
|
|
6
6
|
"npq": "./bin/npq.js",
|
|
@@ -191,6 +191,7 @@
|
|
|
191
191
|
"listr": "^0.14.0",
|
|
192
192
|
"node-fetch": "^2.6.7",
|
|
193
193
|
"npm-package-arg": "^10.1.0",
|
|
194
|
+
"pacote": "^17.0.4",
|
|
194
195
|
"semver": "^7.3.8",
|
|
195
196
|
"update-notifier": "^5",
|
|
196
197
|
"validator": "13.7.0",
|