npm-install-checks
Advanced tools
Comparing version 2.0.1 to 3.0.0
63
index.js
@@ -1,5 +0,5 @@ | ||
var fs = require("fs") | ||
var path = require("path") | ||
var log = require("npmlog") | ||
var semver = require("semver") | ||
var fs = require('fs') | ||
var path = require('path') | ||
var util = require('util') | ||
var semver = require('semver') | ||
@@ -9,16 +9,15 @@ exports.checkEngine = checkEngine | ||
var nodev = force ? null : nodeVer | ||
, eng = target.engines | ||
var eng = target.engines | ||
if (!eng) return cb() | ||
if (nodev && eng.node && !semver.satisfies(nodev, eng.node) | ||
|| eng.npm && !semver.satisfies(npmVer, eng.npm)) { | ||
if (nodev && eng.node && !semver.satisfies(nodev, eng.node) || | ||
eng.npm && !semver.satisfies(npmVer, eng.npm)) { | ||
var er = new Error(util.format('Unsupported engine for %s: wanted: %j (current: %j)', | ||
target._id, eng, {node: nodev, npm: npmVer})) | ||
er.code = 'ENOTSUP' | ||
er.required = eng | ||
er.pkgid = target._id | ||
if (strict) { | ||
var er = new Error("Unsupported") | ||
er.code = "ENOTSUP" | ||
er.required = eng | ||
er.pkgid = target._id | ||
return cb(er) | ||
} else { | ||
log.warn( "engine", "%s: wanted: %j (current: %j)" | ||
, target._id, eng, {node: nodev, npm: npmVer} ) | ||
return cb(null, er) | ||
} | ||
@@ -32,5 +31,5 @@ } | ||
var platform = process.platform | ||
, arch = process.arch | ||
, osOk = true | ||
, cpuOk = true | ||
var arch = process.arch | ||
var osOk = true | ||
var cpuOk = true | ||
@@ -48,4 +47,5 @@ if (force) { | ||
if (!osOk || !cpuOk) { | ||
var er = new Error("Unsupported") | ||
er.code = "EBADPLATFORM" | ||
var er = new Error(util.format('Unsupported platform for %s: wanted %j (current: %j)', | ||
target._id, target, {os: platform, cpu: arch})) | ||
er.code = 'EBADPLATFORM' | ||
er.os = target.os || ['any'] | ||
@@ -61,8 +61,8 @@ er.cpu = target.cpu || ['any'] | ||
var tmp | ||
, match = false | ||
, blc = 0 | ||
if (typeof list === "string") { | ||
var match = false | ||
var blc = 0 | ||
if (typeof list === 'string') { | ||
list = [list] | ||
} | ||
if (list.length === 1 && list[0] === "any") { | ||
if (list.length === 1 && list[0] === 'any') { | ||
return true | ||
@@ -109,4 +109,4 @@ } | ||
var p = Object.getPrototypeOf(Object.getPrototypeOf(ancestors)) | ||
, name = target.name | ||
, version = target.version | ||
var name = target.name | ||
var version = target.version | ||
while (p && p !== Object.prototype && p[name] !== version) { | ||
@@ -117,5 +117,5 @@ p = Object.getPrototypeOf(p) | ||
var er = new Error("Unresolvable cycle detected") | ||
var er = new Error(target._id + ': Unresolvable cycle detected') | ||
var tree = [target._id, JSON.parse(JSON.stringify(ancestors))] | ||
, t = Object.getPrototypeOf(ancestors) | ||
var t = Object.getPrototypeOf(ancestors) | ||
while (t && t !== Object.prototype) { | ||
@@ -126,5 +126,4 @@ if (t === p) t.THIS_IS_P = true | ||
} | ||
log.verbose("unresolvable dependency tree", tree) | ||
er.pkgid = target._id | ||
er.code = "ECYCLE" | ||
er.code = 'ECYCLE' | ||
return cb(er) | ||
@@ -143,7 +142,7 @@ } | ||
function checkGit_ (folder, cb) { | ||
fs.stat(path.resolve(folder, ".git"), function (er, s) { | ||
fs.stat(path.resolve(folder, '.git'), function (er, s) { | ||
if (!er && s.isDirectory()) { | ||
var e = new Error("Appears to be a git repo or submodule.") | ||
var e = new Error(folder + ': Appears to be a git repo or submodule.') | ||
e.path = folder | ||
e.code = "EISGIT" | ||
e.code = 'EISGIT' | ||
return cb(e) | ||
@@ -150,0 +149,0 @@ } |
{ | ||
"name": "npm-install-checks", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "checks that npm runs during the installation of a module", | ||
"main": "index.js", | ||
"dependencies": { | ||
"npmlog": "0.1 || 1", | ||
"semver": "^2.3.0 || 3.x || 4 || 5" | ||
@@ -13,6 +12,7 @@ }, | ||
"rimraf": "~2.2.5", | ||
"tap": "^1.2.0" | ||
"standard": "^5.4.1", | ||
"tap": "^5.0.1" | ||
}, | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
"test": "standard && tap --coverage test/*.js" | ||
}, | ||
@@ -19,0 +19,0 @@ "repository": { |
@@ -8,3 +8,5 @@ # npm-install-checks | ||
### .checkEngine(target, npmVer, nodeVer, force, strict, cb) | ||
Check if node/npm version is supported by the package. | ||
Check if node/npm version is supported by the package. If not | ||
strict and it isn't supported, `cb` is called with the error | ||
object as its second argument. | ||
@@ -11,0 +13,0 @@ Error type: `ENOTSUP` |
@@ -1,7 +0,7 @@ | ||
var test = require("tap").test | ||
var c = require("../index.js").checkEngine | ||
var test = require('tap').test | ||
var c = require('../index.js').checkEngine | ||
test("no engine defined", function (t) { | ||
c({ engines: {}}, "1.1.2", "0.2.1", false, true, function (err) { | ||
t.notOk(err, "no error present") | ||
test('no engine defined', function (t) { | ||
c({ engines: {} }, '1.1.2', '0.2.1', false, true, function (err) { | ||
t.notOk(err, 'no error present') | ||
t.end() | ||
@@ -11,7 +11,7 @@ }) | ||
test("node version too old", function (t) { | ||
var target = { engines: { node: "0.10.24" }} | ||
c(target, "1.1.2", "0.10.18", false, true, function (err) { | ||
t.ok(err, "returns an error") | ||
t.equals(err.required.node, "0.10.24") | ||
test('node version too old', function (t) { | ||
var target = { engines: { node: '0.10.24' } } | ||
c(target, '1.1.2', '0.10.18', false, true, function (err) { | ||
t.ok(err, 'returns an error') | ||
t.equals(err.required.node, '0.10.24') | ||
t.end() | ||
@@ -21,17 +21,44 @@ }) | ||
test("npm version too old", function (t) { | ||
var target = { engines: { npm: "^1.4.6" }} | ||
c(target, "1.3.2", "0.2.1", false, true, function (err) { | ||
t.ok(err, "returns an error") | ||
t.equals(err.required.npm, "^1.4.6") | ||
t.end() | ||
}) | ||
test('npm version too old', function (t) { | ||
var target = { engines: { npm: '^1.4.6' } } | ||
c(target, '1.3.2', '0.2.1', false, true, function (err) { | ||
t.ok(err, 'returns an error') | ||
t.equals(err.required.npm, '^1.4.6') | ||
t.end() | ||
}) | ||
}) | ||
test("strict=false w/engineStrict json does not return an error", function (t) { | ||
var target = { engines: { npm: "1.3.6" }, engineStrict: true } | ||
c(target, "1.4.2", "0.2.1", false, false, function (err) { | ||
t.notOk(err, "returns no error") | ||
test('strict=false w/engineStrict json does not return an error', function (t) { | ||
var target = { engines: { npm: '1.3.6' }, engineStrict: true } | ||
c(target, '1.4.2', '0.2.1', false, false, function (err, warn) { | ||
t.notOk(err, 'returns no error') | ||
t.ok(warn, 'returns warning object') | ||
t.equals(warn.required.npm, '1.3.6') | ||
t.end() | ||
}) | ||
}) | ||
test('force node version too old', function (t) { | ||
var target = { _id: 'test@1.0.0', engines: { node: '0.1.0' } } | ||
c(target, '1.3.2', '0.2.1', true, true, function (err, warn) { | ||
t.is(err, undefined, 'returns no error') | ||
t.notOk(warn, 'returns no warning') | ||
t.end() | ||
}) | ||
}) | ||
test('force npm version too old', function (t) { | ||
var target = { _id: 'test@1.0.0', engines: { npm: '^1.4.6' } } | ||
c(target, '1.3.2', '0.2.1', true, true, function (err, warn) { | ||
t.ok(err, "can't force an npm version mismatch") | ||
t.end() | ||
}) | ||
}) | ||
test('no engine', function (t) { | ||
c({}, '1.3.2', '0.2.1', false, true, function (err, warn) { | ||
t.notOk(err, 'returns no error') | ||
t.notOk(warn, 'returns no warning') | ||
t.end() | ||
}) | ||
}) |
@@ -1,14 +0,13 @@ | ||
var test = require("tap").test | ||
var c = require("../index.js").checkGit | ||
var fs = require("fs") | ||
var rimraf = require("rimraf") | ||
var mkdirp = require("mkdirp") | ||
var path = require("path") | ||
var gitFixturePath = path.resolve(__dirname, "out") | ||
var test = require('tap').test | ||
var c = require('../index.js').checkGit | ||
var rimraf = require('rimraf') | ||
var mkdirp = require('mkdirp') | ||
var path = require('path') | ||
var gitFixturePath = path.resolve(__dirname, 'out') | ||
test("is .git repo", function (t) { | ||
mkdirp(gitFixturePath + "/.git", function () { | ||
test('is .git repo', function (t) { | ||
mkdirp(gitFixturePath + '/.git', function () { | ||
c(gitFixturePath, function (err) { | ||
t.ok(err, "error present") | ||
t.equal(err.code, "EISGIT") | ||
t.ok(err, 'error present') | ||
t.equal(err.code, 'EISGIT') | ||
t.end() | ||
@@ -19,5 +18,5 @@ }) | ||
test("is not a .git repo", function (t) { | ||
test('is not a .git repo', function (t) { | ||
c(__dirname, function (err) { | ||
t.notOk(err, "error not present") | ||
t.notOk(err, 'error not present') | ||
t.end() | ||
@@ -27,7 +26,14 @@ }) | ||
test("cleanup", function (t) { | ||
test('non-thing', function (t) { | ||
c('/path/to/no/where', function (err) { | ||
t.notOk(err, 'non-existent path is not a .git repo') | ||
t.end() | ||
}) | ||
}) | ||
test('cleanup', function (t) { | ||
rimraf(gitFixturePath, function () { | ||
t.pass("cleanup") | ||
t.pass('cleanup') | ||
t.end() | ||
}) | ||
}) |
@@ -1,11 +0,11 @@ | ||
var test = require("tap").test | ||
var c = require("../index.js").checkPlatform | ||
var test = require('tap').test | ||
var c = require('../index.js').checkPlatform | ||
test("target cpu wrong", function (t) { | ||
test('target cpu wrong', function (t) { | ||
var target = {} | ||
target.cpu = "enten-cpu" | ||
target.os = "any" | ||
target.cpu = 'enten-cpu' | ||
target.os = 'any' | ||
c(target, false, function (err) { | ||
t.ok(err, "error present") | ||
t.equal(err.code, "EBADPLATFORM") | ||
t.ok(err, 'error present') | ||
t.equal(err.code, 'EBADPLATFORM') | ||
t.end() | ||
@@ -15,9 +15,9 @@ }) | ||
test("os wrong", function (t) { | ||
test('os wrong', function (t) { | ||
var target = {} | ||
target.cpu = "any" | ||
target.os = "enten-os" | ||
target.cpu = 'any' | ||
target.os = 'enten-os' | ||
c(target, false, function (err) { | ||
t.ok(err, "error present") | ||
t.equal(err.code, "EBADPLATFORM") | ||
t.ok(err, 'error present') | ||
t.equal(err.code, 'EBADPLATFORM') | ||
t.end() | ||
@@ -27,8 +27,8 @@ }) | ||
test("nothing wrong", function (t) { | ||
test('nothing wrong', function (t) { | ||
var target = {} | ||
target.cpu = "any" | ||
target.os = "any" | ||
target.cpu = 'any' | ||
target.os = 'any' | ||
c(target, false, function (err) { | ||
t.notOk(err, "no error present") | ||
t.notOk(err, 'no error present') | ||
t.end() | ||
@@ -38,10 +38,70 @@ }) | ||
test("force", function (t) { | ||
test('force', function (t) { | ||
var target = {} | ||
target.cpu = "enten-cpu" | ||
target.os = "any" | ||
target.cpu = 'enten-cpu' | ||
target.os = 'any' | ||
c(target, true, function (err) { | ||
t.notOk(err, "no error present") | ||
t.notOk(err, 'no error present') | ||
t.end() | ||
}) | ||
}) | ||
test('no opinions', function (t) { | ||
var target = {} | ||
c(target, false, function (err) { | ||
t.notOk(err, 'no error present') | ||
t.end() | ||
}) | ||
}) | ||
test('only target cpu wrong', function (t) { | ||
var target = {} | ||
target.cpu = 'enten-cpu' | ||
c(target, false, function (err) { | ||
t.ok(err, 'error present') | ||
t.equal(err.code, 'EBADPLATFORM') | ||
t.end() | ||
}) | ||
}) | ||
test('only os wrong', function (t) { | ||
var target = {} | ||
target.os = 'enten-os' | ||
c(target, false, function (err) { | ||
t.ok(err, 'error present') | ||
t.equal(err.code, 'EBADPLATFORM') | ||
t.end() | ||
}) | ||
}) | ||
test('everything wrong w/arrays', function (t) { | ||
var target = {} | ||
target.cpu = ['enten-cpu'] | ||
target.os = ['enten-os'] | ||
c(target, false, function (err) { | ||
t.ok(err, 'error present') | ||
t.equal(err.code, 'EBADPLATFORM') | ||
t.end() | ||
}) | ||
}) | ||
test('os wrong (negation)', function (t) { | ||
var target = {} | ||
target.cpu = 'any' | ||
target.os = '!' + process.platform | ||
c(target, false, function (err) { | ||
t.ok(err, 'error present') | ||
t.equal(err.code, 'EBADPLATFORM') | ||
t.end() | ||
}) | ||
}) | ||
test('nothing wrong (negation)', function (t) { | ||
var target = {} | ||
target.cpu = '!enten-cpu' | ||
target.os = '!enten-os' | ||
c(target, false, function (err) { | ||
t.notOk(err, 'no error present') | ||
t.end() | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
12057
1
8
316
28
1
4
- Removednpmlog@0.1 || 1
- Removedansi@0.3.1(transitive)
- Removedare-we-there-yet@1.0.6(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddelegates@1.0.0(transitive)
- Removedgauge@1.2.7(transitive)
- Removedhas-unicode@2.0.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedlodash.pad@4.5.1(transitive)
- Removedlodash.padend@4.6.1(transitive)
- Removedlodash.padstart@4.6.1(transitive)
- Removednpmlog@1.2.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)