Skip to content

Commit 82dc75f

Browse files
committed
1 parent 0230428 commit 82dc75f

File tree

6 files changed

+204
-21
lines changed

6 files changed

+204
-21
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) Robert Kowalski and Isaac Z. Schlueter ("Authors")
2+
All rights reserved.
3+
4+
The BSD License
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions
8+
are met:
9+
10+
1. Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
13+
2. Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the distribution.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS
21+
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const semver = require('semver')
2+
3+
const checkEngine = (target, npmVer, nodeVer, force = false) => {
4+
const nodev = force ? null : nodeVer
5+
const eng = target.engines
6+
const opt = { includePrerelease: true }
7+
if (!eng) {
8+
return
9+
}
10+
11+
const nodeFail = nodev && eng.node && !semver.satisfies(nodev, eng.node, opt)
12+
const npmFail = npmVer && eng.npm && !semver.satisfies(npmVer, eng.npm, opt)
13+
if (nodeFail || npmFail) {
14+
throw Object.assign(new Error('Unsupported engine'), {
15+
pkgid: target._id,
16+
current: { node: nodeVer, npm: npmVer },
17+
required: eng,
18+
code: 'EBADENGINE',
19+
})
20+
}
21+
}
22+
23+
const checkPlatform = (target, force = false) => {
24+
if (force) {
25+
return
26+
}
27+
28+
const platform = process.platform
29+
const arch = process.arch
30+
const osOk = target.os ? checkList(platform, target.os) : true
31+
const cpuOk = target.cpu ? checkList(arch, target.cpu) : true
32+
33+
if (!osOk || !cpuOk) {
34+
throw Object.assign(new Error('Unsupported platform'), {
35+
pkgid: target._id,
36+
current: {
37+
os: platform,
38+
cpu: arch,
39+
},
40+
required: {
41+
os: target.os,
42+
cpu: target.cpu,
43+
},
44+
code: 'EBADPLATFORM',
45+
})
46+
}
47+
}
48+
49+
const checkList = (value, list) => {
50+
if (typeof list === 'string') {
51+
list = [list]
52+
}
53+
if (list.length === 1 && list[0] === 'any') {
54+
return true
55+
}
56+
// match none of the negated values, and at least one of the
57+
// non-negated values, if any are present.
58+
let negated = 0
59+
let match = false
60+
for (const entry of list) {
61+
const negate = entry.charAt(0) === '!'
62+
const test = negate ? entry.slice(1) : entry
63+
if (negate) {
64+
negated++
65+
if (value === test) {
66+
return false
67+
}
68+
} else {
69+
match = match || value === test
70+
}
71+
}
72+
return match || negated === list.length
73+
}
74+
75+
module.exports = {
76+
checkEngine,
77+
checkPlatform,
78+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "npm-install-checks",
3+
"version": "5.0.0",
4+
"description": "Check the engines and platform fields in package.json",
5+
"main": "lib/index.js",
6+
"dependencies": {
7+
"semver": "^7.1.1"
8+
},
9+
"devDependencies": {
10+
"@npmcli/eslint-config": "^3.0.1",
11+
"@npmcli/template-oss": "3.2.2",
12+
"tap": "^16.0.1"
13+
},
14+
"scripts": {
15+
"test": "tap",
16+
"preversion": "npm test",
17+
"postversion": "npm publish",
18+
"postpublish": "git push origin --follow-tags",
19+
"lint": "eslint \"**/*.js\"",
20+
"postlint": "template-oss-check",
21+
"template-oss-apply": "template-oss-apply --force",
22+
"lintfix": "npm run lint -- --fix",
23+
"prepublishOnly": "git push origin --follow-tags",
24+
"snap": "tap",
25+
"posttest": "npm run lint"
26+
},
27+
"repository": {
28+
"type": "git",
29+
"url": "https://github.com/npm/npm-install-checks.git"
30+
},
31+
"keywords": [
32+
"npm,",
33+
"install"
34+
],
35+
"license": "BSD-2-Clause",
36+
"files": [
37+
"bin/",
38+
"lib/"
39+
],
40+
"engines": {
41+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
42+
},
43+
"author": "GitHub Inc.",
44+
"templateOSS": {
45+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
46+
"version": "3.2.2"
47+
}
48+
}
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
{
22
"name": "npm-pick-manifest",
3-
"version": "7.0.0",
3+
"version": "7.0.1",
44
"description": "Resolves a matching manifest from a package metadata document according to standard npm semver resolution rules.",
55
"main": "./lib",
66
"files": [
7-
"bin",
8-
"lib"
7+
"bin/",
8+
"lib/"
99
],
1010
"scripts": {
1111
"coverage": "tap",
12-
"lint": "eslint '**/*.js'",
12+
"lint": "eslint \"**/*.js\"",
1313
"test": "tap",
1414
"posttest": "npm run lint",
1515
"preversion": "npm test",
1616
"postversion": "npm publish",
1717
"prepublishOnly": "git push origin --follow-tags",
18-
"postlint": "npm-template-check",
19-
"template-copy": "npm-template-copy --force",
18+
"postlint": "template-oss-check",
2019
"lintfix": "npm run lint -- --fix",
21-
"snap": "tap"
20+
"snap": "tap",
21+
"template-oss-apply": "template-oss-apply --force"
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/npm/npm-pick-manifest.git"
2226
},
23-
"repository": "https://github.com/npm/npm-pick-manifest",
2427
"keywords": [
2528
"npm",
2629
"semver",
@@ -29,22 +32,24 @@
2932
"author": "GitHub Inc.",
3033
"license": "ISC",
3134
"dependencies": {
32-
"npm-install-checks": "^4.0.0",
35+
"npm-install-checks": "^5.0.0",
3336
"npm-normalize-package-bin": "^1.0.1",
3437
"npm-package-arg": "^9.0.0",
3538
"semver": "^7.3.5"
3639
},
3740
"devDependencies": {
38-
"@npmcli/template-oss": "^2.7.1",
39-
"tap": "^15.1.6"
41+
"@npmcli/eslint-config": "^3.0.1",
42+
"@npmcli/template-oss": "3.2.2",
43+
"tap": "^16.0.1"
4044
},
4145
"tap": {
4246
"check-coverage": true
4347
},
4448
"engines": {
45-
"node": "^12.13.0 || ^14.15.0 || >=16"
49+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
4650
},
4751
"templateOSS": {
48-
"version": "2.7.1"
52+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
53+
"version": "3.2.2"
4954
}
5055
}

package-lock.json

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
"npm-audit-report": "^3.0.0",
136136
"npm-install-checks": "^4.0.0",
137137
"npm-package-arg": "^9.0.1",
138-
"npm-pick-manifest": "^7.0.0",
138+
"npm-pick-manifest": "^7.0.1",
139139
"npm-profile": "^6.0.2",
140140
"npm-registry-fetch": "^13.1.0",
141141
"npm-user-validate": "^1.0.1",
@@ -5001,17 +5001,30 @@
50015001
}
50025002
},
50035003
"node_modules/npm-pick-manifest": {
5004-
"version": "7.0.0",
5004+
"version": "7.0.1",
5005+
"resolved": "https://registry.npmjs.org/npm-pick-manifest/-/npm-pick-manifest-7.0.1.tgz",
5006+
"integrity": "sha512-IA8+tuv8KujbsbLQvselW2XQgmXWS47t3CB0ZrzsRZ82DbDfkcFunOaPm4X7qNuhMfq+FmV7hQT4iFVpHqV7mg==",
50055007
"inBundle": true,
5006-
"license": "ISC",
50075008
"dependencies": {
5008-
"npm-install-checks": "^4.0.0",
5009+
"npm-install-checks": "^5.0.0",
50095010
"npm-normalize-package-bin": "^1.0.1",
50105011
"npm-package-arg": "^9.0.0",
50115012
"semver": "^7.3.5"
50125013
},
50135014
"engines": {
5014-
"node": "^12.13.0 || ^14.15.0 || >=16"
5015+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
5016+
}
5017+
},
5018+
"node_modules/npm-pick-manifest/node_modules/npm-install-checks": {
5019+
"version": "5.0.0",
5020+
"resolved": "https://registry.npmjs.org/npm-install-checks/-/npm-install-checks-5.0.0.tgz",
5021+
"integrity": "sha512-65lUsMI8ztHCxFz5ckCEC44DRvEGdZX5usQFriauxHEwt7upv1FKaQEmAtU0YnOAdwuNWCmk64xYiQABNrEyLA==",
5022+
"inBundle": true,
5023+
"dependencies": {
5024+
"semver": "^7.1.1"
5025+
},
5026+
"engines": {
5027+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
50155028
}
50165029
},
50175030
"node_modules/npm-profile": {
@@ -13016,12 +13029,24 @@
1301613029
}
1301713030
},
1301813031
"npm-pick-manifest": {
13019-
"version": "7.0.0",
13032+
"version": "7.0.1",
13033+
"resolved": "https://registry.npmjs.org/npm-pick-manifest/-/npm-pick-manifest-7.0.1.tgz",
13034+
"integrity": "sha512-IA8+tuv8KujbsbLQvselW2XQgmXWS47t3CB0ZrzsRZ82DbDfkcFunOaPm4X7qNuhMfq+FmV7hQT4iFVpHqV7mg==",
1302013035
"requires": {
13021-
"npm-install-checks": "^4.0.0",
13036+
"npm-install-checks": "^5.0.0",
1302213037
"npm-normalize-package-bin": "^1.0.1",
1302313038
"npm-package-arg": "^9.0.0",
1302413039
"semver": "^7.3.5"
13040+
},
13041+
"dependencies": {
13042+
"npm-install-checks": {
13043+
"version": "5.0.0",
13044+
"resolved": "https://registry.npmjs.org/npm-install-checks/-/npm-install-checks-5.0.0.tgz",
13045+
"integrity": "sha512-65lUsMI8ztHCxFz5ckCEC44DRvEGdZX5usQFriauxHEwt7upv1FKaQEmAtU0YnOAdwuNWCmk64xYiQABNrEyLA==",
13046+
"requires": {
13047+
"semver": "^7.1.1"
13048+
}
13049+
}
1302513050
}
1302613051
},
1302713052
"npm-profile": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"npm-audit-report": "^3.0.0",
103103
"npm-install-checks": "^4.0.0",
104104
"npm-package-arg": "^9.0.1",
105-
"npm-pick-manifest": "^7.0.0",
105+
"npm-pick-manifest": "^7.0.1",
106106
"npm-profile": "^6.0.2",
107107
"npm-registry-fetch": "^13.1.0",
108108
"npm-user-validate": "^1.0.1",

0 commit comments

Comments
 (0)