Comparing version 0.0.7 to 0.0.8
49
npmi.js
@@ -19,2 +19,3 @@ var npm = require('npm'); | ||
var name = options.name, | ||
pkgName = options.pkgName || name, | ||
version = options.version || 'latest', | ||
@@ -43,9 +44,18 @@ installPath = options.path || '.', | ||
function checkInstalled() { | ||
function checkInstalled(isTarball) { | ||
var module = name+'@'+version; | ||
if (isTarball) { | ||
module = name; | ||
if (pkgName === name) { | ||
console.warn('npmi warn: install "'+name+'" from tarball without options.pkgName specified => forceInstall: true'); | ||
} | ||
} | ||
// check that version matches | ||
fs.readFile(path.resolve(installPath, 'node_modules', name, 'package.json'), function (err, pkgRawData) { | ||
fs.readFile(path.resolve(installPath, 'node_modules', pkgName, 'package.json'), function (err, pkgRawData) { | ||
if (err) { | ||
// hmm, something went wrong while reading module's package.json file | ||
// lets try to reinstall it just in case | ||
return npm.commands.install(installPath, [name+'@'+version], installCallback); | ||
return npm.commands.install(installPath, [module], installCallback); | ||
} | ||
@@ -55,14 +65,21 @@ | ||
if (version === 'latest') { | ||
// specified version is "latest" which means nothing for a check | ||
// so we need to ask npm to give us a view of the module from remote registry | ||
// in order to check if it really is the latest one that is currently installed | ||
return npm.commands.view([name], true, viewCallback(pkg.version)); | ||
// specified version is "latest" which means nothing for a comparison check | ||
if (isTarball) { | ||
// when a package is already installed and it comes from a tarball, you have to specify | ||
// a real version => error | ||
console.warn('npmi warn: install from tarball without options.version specified => forceInstall: true'); | ||
return npm.commands.install(installPath, [module], installCallback); | ||
} else { | ||
// so we need to ask npm to give us a view of the module from remote registry | ||
// in order to check if it really is the latest one that is currently installed | ||
return npm.commands.view([name], true, viewCallback(pkg.version)); | ||
} | ||
} else if (pkg.version === version) { | ||
// package is installed and version matches | ||
return callback(null); | ||
return callback(); | ||
} else { | ||
// version does not match: reinstall | ||
return npm.commands.install(installPath, [name+'@'+version], installCallback); | ||
return npm.commands.install(installPath, [module], installCallback); | ||
} | ||
@@ -90,3 +107,3 @@ }); | ||
if (!name) { | ||
// just want to do an "npm install" where a package.json is obviously | ||
// just want to do an "npm install" where a package.json is | ||
npm.commands.install(installPath, [], installCallback); | ||
@@ -100,7 +117,13 @@ | ||
// reinstall package module | ||
npm.commands.install(installPath, [name+'@'+version], installCallback); | ||
if (name.indexOf('/') === -1) { | ||
// not a tarball | ||
npm.commands.install(installPath, [name+'@'+version], installCallback); | ||
} else { | ||
// do not specify version for tarball | ||
npm.commands.install(installPath, [name], installCallback); | ||
} | ||
} else { | ||
// check if package is installed | ||
checkInstalled(); | ||
checkInstalled(name.indexOf('/') !== -1); | ||
} | ||
@@ -111,3 +134,3 @@ } | ||
npm.load(npmLoad, loadCallback); | ||
} | ||
}; | ||
@@ -114,0 +137,0 @@ npmi.LOAD_ERR = LOAD_ERR; |
{ | ||
"name": "npmi", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Gives a simplier API to npm install (programatically installs stuffs)", | ||
"main": "npmi.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node test/test.js" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -1,2 +0,2 @@ | ||
npmi | ||
npmi [![Build Status](http://drone.braindead.fr/github.com/maxleiko/npmi/status.svg?branch=master)](http://drone.braindead.fr/github.com/maxleiko/npmi) | ||
==== | ||
@@ -8,8 +8,53 @@ | ||
```sh | ||
npm install npmi | ||
npm install npmi --save | ||
``` | ||
### Usage | ||
### Options | ||
#### options.name | ||
__Type:__ `String` | ||
__Optional:__ `true` | ||
If you don't specify a `name` in options, but just a `path`, __npmi__ will do the same as if you were at this path in a terminal and executing `npm install` | ||
Otherwise, it will install the module specified by this name like `npm install module-name` does. | ||
#### options.version | ||
__Type:__ `String` | ||
__Optional:__ `true` | ||
__Default__ `'latest'` | ||
Desired version for installation | ||
#### options.path | ||
__Type:__ `String` | ||
__Optional:__ `true` | ||
__Default__ `'.'` | ||
Desired location for installation (note that if you specified /some/foo/path, __npm__ will automatically create a `node_modules` sub-folder at this location, resulting in `/some/foo/path/node_modules`). So don't specify the `node_modules` part in your path | ||
#### options.forceInstall | ||
__Type:__ `Boolean` | ||
__Optional:__ `true` | ||
__Default__ `false` | ||
If true, __npmi__ will install `options.name` module even though it has already been installed. | ||
If false, __npmi__ will check if the module is already installed, if it is, it will also check if the installed version is equal to `options.version`, otherwise, it will install `options.name@options.version` | ||
#### options.localInstall | ||
__Type:__ `Boolean` | ||
__Optional:__ `true` | ||
__Default__ `false` | ||
Allows __npmi__ to install local module that are not on __npm registry__. If, you want to install a local module by specifying its full path in `options.name`, you need to set this to `true`. | ||
#### options.npmLoad | ||
__Type:__ `Object` | ||
__Optional:__ `true` | ||
__Default__ `{loglevel: 'silent'}` | ||
This object is given to __npm__ and allows you to do some fine-grained npm configurations. | ||
It is processed by __npm__ like command-line arguments but within an Object map ([npm-config](https://www.npmjs.org/doc/misc/npm-config.html)) | ||
### Usage example | ||
```js | ||
var npmi = require('./../npmi'); | ||
var npmi = require('npmi'); | ||
var path = require('path'); | ||
@@ -16,0 +61,0 @@ |
var npmi = require('./../npmi'); | ||
var path = require('path'); | ||
var options = { | ||
@@ -6,0 +4,0 @@ name: 'kevoree-group-websocket' |
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
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
11561
13
172
1
82