Skip to content

Commit

Permalink
update npm-install-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
reggi committed Sep 11, 2024
1 parent db9841f commit 22078d4
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 7 deletions.
3 changes: 3 additions & 0 deletions node_modules/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
!/npm-package-arg
!/npm-packlist
!/npm-pick-manifest
!/npm-pick-manifest/node_modules/
/npm-pick-manifest/node_modules/*
!/npm-pick-manifest/node_modules/npm-install-checks
!/npm-profile
!/npm-registry-fetch
!/npm-user-validate
Expand Down
3 changes: 3 additions & 0 deletions node_modules/npm-install-checks/lib/current-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ function libc (osName) {
return undefined
}
let family
const originalExclude = process.report.excludeNetwork
process.report.excludeNetwork = true
const report = process.report.getReport()
process.report.excludeNetwork = originalExclude
if (report.header?.glibcVersionRuntime) {
family = 'glibc'
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
Expand Down
2 changes: 1 addition & 1 deletion node_modules/npm-install-checks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "npm-install-checks",
"version": "6.3.0",
"version": "7.1.0",
"description": "Check the engines and platform fields in package.json",
"main": "lib/index.js",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) Robert Kowalski and Isaac Z. Schlueter ("Authors")
All rights reserved.

The BSD License

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const semver = require('semver')

const checkEngine = (target, npmVer, nodeVer, force = false) => {
const nodev = force ? null : nodeVer
const eng = target.engines
const opt = { includePrerelease: true }
if (!eng) {
return
}

const nodeFail = nodev && eng.node && !semver.satisfies(nodev, eng.node, opt)
const npmFail = npmVer && eng.npm && !semver.satisfies(npmVer, eng.npm, opt)
if (nodeFail || npmFail) {
throw Object.assign(new Error('Unsupported engine'), {
pkgid: target._id,
current: { node: nodeVer, npm: npmVer },
required: eng,
code: 'EBADENGINE',
})
}
}

const isMusl = (file) => file.includes('libc.musl-') || file.includes('ld-musl-')

const checkPlatform = (target, force = false, environment = {}) => {
if (force) {
return
}

const platform = environment.os || process.platform
const arch = environment.cpu || process.arch
const osOk = target.os ? checkList(platform, target.os) : true
const cpuOk = target.cpu ? checkList(arch, target.cpu) : true

let libcOk = true
let libcFamily = null
if (target.libc) {
// libc checks only work in linux, any value is a failure if we aren't
if (environment.libc) {
libcOk = checkList(environment.libc, target.libc)
} else if (platform !== 'linux') {
libcOk = false
} else {
const report = process.report.getReport()
if (report.header?.glibcVersionRuntime) {
libcFamily = 'glibc'
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
libcFamily = 'musl'
}
libcOk = libcFamily ? checkList(libcFamily, target.libc) : false
}
}

if (!osOk || !cpuOk || !libcOk) {
throw Object.assign(new Error('Unsupported platform'), {
pkgid: target._id,
current: {
os: platform,
cpu: arch,
libc: libcFamily,
},
required: {
os: target.os,
cpu: target.cpu,
libc: target.libc,
},
code: 'EBADPLATFORM',
})
}
}

const checkList = (value, list) => {
if (typeof list === 'string') {
list = [list]
}
if (list.length === 1 && list[0] === 'any') {
return true
}
// match none of the negated values, and at least one of the
// non-negated values, if any are present.
let negated = 0
let match = false
for (const entry of list) {
const negate = entry.charAt(0) === '!'
const test = negate ? entry.slice(1) : entry
if (negate) {
negated++
if (value === test) {
return false
}
} else {
match = match || value === test
}
}
return match || negated === list.length
}

module.exports = {
checkEngine,
checkPlatform,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "npm-install-checks",
"version": "6.3.0",
"description": "Check the engines and platform fields in package.json",
"main": "lib/index.js",
"dependencies": {
"semver": "^7.1.1"
},
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.19.0",
"tap": "^16.0.1"
},
"scripts": {
"test": "tap",
"lint": "eslint \"**/*.js\"",
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"snap": "tap",
"posttest": "npm run lint"
},
"repository": {
"type": "git",
"url": "https://github.com/npm/npm-install-checks.git"
},
"keywords": [
"npm,",
"install"
],
"license": "BSD-2-Clause",
"files": [
"bin/",
"lib/"
],
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
},
"author": "GitHub Inc.",
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.19.0",
"publish": "true"
},
"tap": {
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
}
}
34 changes: 29 additions & 5 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"nopt",
"normalize-package-data",
"npm-audit-report",
"npm-install-checks",
"npm-package-arg",
"npm-pick-manifest",
"npm-profile",
Expand Down Expand Up @@ -131,7 +130,7 @@
"nopt": "^7.2.1",
"normalize-package-data": "^6.0.2",
"npm-audit-report": "^5.0.0",
"npm-install-checks": "github:npm/npm-install-checks#reggi/dev-engines",
"npm-install-checks": "^7.1.0",
"npm-package-arg": "^11.0.3",
"npm-pick-manifest": "^9.1.0",
"npm-profile": "^10.0.0",
Expand Down Expand Up @@ -9430,9 +9429,9 @@
}
},
"node_modules/npm-install-checks": {
"version": "6.3.0",
"resolved": "git+ssh://[email protected]/npm/npm-install-checks.git#83e7c96eeda57d612edbdb0f21863aa6fb7a7ace",
"inBundle": true,
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/npm-install-checks/-/npm-install-checks-7.1.0.tgz",
"integrity": "sha512-bkTildVlofeMX7wiOaWk3PlW7YcBXAuEc7TWpOxwUgalG5ZvgT/ms+6OX9zt7iGLv4+VhKbRZhpOfgQJzk1YAw==",
"license": "BSD-2-Clause",
"dependencies": {
"semver": "^7.1.1"
Expand Down Expand Up @@ -9496,6 +9495,19 @@
"node": "^16.14.0 || >=18.0.0"
}
},
"node_modules/npm-pick-manifest/node_modules/npm-install-checks": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/npm-install-checks/-/npm-install-checks-6.3.0.tgz",
"integrity": "sha512-W29RiK/xtpCGqn6f3ixfRYGk+zRyr+Ew9F2E20BfXxT5/euLdA/Nm7fO7OeTGuAmTs30cpgInyJ0cYe708YTZw==",
"inBundle": true,
"license": "BSD-2-Clause",
"dependencies": {
"semver": "^7.1.1"
},
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
}
},
"node_modules/npm-profile": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/npm-profile/-/npm-profile-10.0.0.tgz",
Expand Down Expand Up @@ -15809,6 +15821,18 @@
"node": "^16.14.0 || >=18.0.0"
}
},
"workspaces/arborist/node_modules/npm-install-checks": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/npm-install-checks/-/npm-install-checks-6.3.0.tgz",
"integrity": "sha512-W29RiK/xtpCGqn6f3ixfRYGk+zRyr+Ew9F2E20BfXxT5/euLdA/Nm7fO7OeTGuAmTs30cpgInyJ0cYe708YTZw==",
"license": "BSD-2-Clause",
"dependencies": {
"semver": "^7.1.1"
},
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
}
},
"workspaces/config": {
"name": "@npmcli/config",
"version": "8.3.4",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"nopt": "^7.2.1",
"normalize-package-data": "^6.0.2",
"npm-audit-report": "^5.0.0",
"npm-install-checks": "github:npm/npm-install-checks#reggi/dev-engines",
"npm-install-checks": "^7.1.0",
"npm-package-arg": "^11.0.3",
"npm-pick-manifest": "^9.1.0",
"npm-profile": "^10.0.0",
Expand Down

0 comments on commit 22078d4

Please sign in to comment.