get-installed-path
Advanced tools
Comparing version 1.0.0 to 1.0.1
20
index.js
@@ -8,17 +8,17 @@ /** | ||
'use strict'; | ||
'use strict' | ||
var path = require('path'); | ||
var modules = require('global-modules'); | ||
var detectInstalled = require('detect-installed'); | ||
var path = require('path') | ||
var modules = require('global-modules') | ||
var detectInstalled = require('detect-installed') | ||
module.exports = function getInstalledPath(name, local) { | ||
module.exports = function getInstalledPath (name, local) { | ||
if (detectInstalled(name)) { | ||
return path.join(modules, name); | ||
return path.join(modules, name) | ||
} | ||
if (detectInstalled(name, local)) { | ||
var cwd = process.cwd(); | ||
return path.join(cwd, 'node_modules', name); | ||
var cwd = process.cwd() | ||
return path.join(cwd, 'node_modules', name) | ||
} | ||
return ''; | ||
}; | ||
return '' | ||
} |
{ | ||
"name": "get-installed-path", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Get the installation path of the given package if it is installed globally or locally.", | ||
"scripts": { | ||
"lint": "jshint index.js && jscs index.js --reporter inline", | ||
"test": "node test.js", | ||
"test-cov": "istanbul cover test.js", | ||
"test-travis": "istanbul cover test.js --report lcovonly" | ||
"test": "standard && node test.js", | ||
"travis": "standard && istanbul cover test.js --report lcovonly" | ||
}, | ||
@@ -37,3 +35,3 @@ "author": { | ||
"type": "MIT", | ||
"url": "https://github.com/tunnckoCore/get-installed-path/blob/master/license.md" | ||
"url": "https://github.com/tunnckoCore/get-installed-path/blob/master/LICENSE.md" | ||
}, | ||
@@ -47,4 +45,5 @@ "dependencies": { | ||
"ends-with": "^0.2.0", | ||
"istanbul-harmony": "~0.3.1" | ||
"istanbul": "^0.3.9", | ||
"standard": "^3.7.3" | ||
} | ||
} | ||
} |
88
test.js
@@ -8,55 +8,55 @@ /** | ||
'use strict'; | ||
'use strict' | ||
var test = require('assertit'); | ||
var endsWith = require('ends-with'); | ||
var getInstalledPath = require('./index'); | ||
var test = require('assertit') | ||
var endsWith = require('ends-with') | ||
var getInstalledPath = require('./index') | ||
test('get-installed-path:', function() { | ||
test('should throw TypeError if not a string given', function(done) { | ||
function fixture() { | ||
getInstalledPath([1, 2, 3]); | ||
test('get-installed-path:', function () { | ||
test('should throw TypeError if not a string given', function (done) { | ||
function fixture () { | ||
getInstalledPath([1, 2, 3]) | ||
} | ||
test.throws(fixture, /expect `name` to be string/); | ||
test.throws(fixture, TypeError); | ||
done(); | ||
}); | ||
test('should throw Error if empty string given', function(done) { | ||
function fixture() { | ||
getInstalledPath(''); | ||
test.throws(fixture, /expect `name` to be string/) | ||
test.throws(fixture, TypeError) | ||
done() | ||
}) | ||
test('should throw Error if empty string given', function (done) { | ||
function fixture () { | ||
getInstalledPath('') | ||
} | ||
test.throws(fixture, /expect `name` to be non empty string/); | ||
test.throws(fixture, Error); | ||
done(); | ||
}); | ||
test('should return filepath of globally installed package', function(done) { | ||
var actual = getInstalledPath('npm'); | ||
var expected = 'node_modules/npm'; | ||
test.throws(fixture, /expect `name` to be non empty string/) | ||
test.throws(fixture, Error) | ||
done() | ||
}) | ||
test('should return filepath of globally installed package', function (done) { | ||
var actual = getInstalledPath('npm') | ||
var expected = 'node_modules/npm' | ||
test.equal(endsWith(actual, expected), true); | ||
done(); | ||
}); | ||
test('should return empty string if package is not installed globally', function(done) { | ||
var actual = getInstalledPath('koa'); | ||
var expected = ''; | ||
test.equal(endsWith(actual, expected), true) | ||
done() | ||
}) | ||
test('should return empty string if package is not installed globally', function (done) { | ||
var actual = getInstalledPath('koa') | ||
var expected = '' | ||
test.equal(endsWith(actual, expected), true); | ||
done(); | ||
}); | ||
test('should return filepath of locally installed package', function(done) { | ||
var actual = getInstalledPath('detect-installed', true); | ||
var expected = 'node_modules/detect-installed'; | ||
test.equal(endsWith(actual, expected), true) | ||
done() | ||
}) | ||
test('should return filepath of locally installed package', function (done) { | ||
var actual = getInstalledPath('detect-installed', true) | ||
var expected = 'node_modules/detect-installed' | ||
test.equal(endsWith(actual, expected), true); | ||
done(); | ||
}); | ||
test('should return empty string if package is not installed locally', function(done) { | ||
var actual = getInstalledPath('koa', true); | ||
var expected = ''; | ||
test.equal(endsWith(actual, expected), true) | ||
done() | ||
}) | ||
test('should return empty string if package is not installed locally', function (done) { | ||
var actual = getInstalledPath('koa', true) | ||
var expected = '' | ||
test.equal(endsWith(actual, expected), true); | ||
done(); | ||
}); | ||
}); | ||
test.equal(endsWith(actual, expected), true) | ||
done() | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
78
9972
4
9