Comparing version 0.0.10 to 0.0.12
44
npmi.js
@@ -1,4 +0,5 @@ | ||
var npm = require('npm'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var npm = require('npm'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var semver = require('semver'); | ||
@@ -49,3 +50,3 @@ var LOAD_ERR = 'NPM_LOAD_ERR', | ||
if (pkgName === name) { | ||
console.warn('npmi warn: install "'+name+'" from tarball without options.pkgName specified => forceInstall: true'); | ||
console.warn('npmi warn: install "'+name+'" from tarball/folder without options.pkgName specified => forceInstall: true'); | ||
} | ||
@@ -109,4 +110,35 @@ } | ||
} else if (localInstall) { | ||
// local install won't work with version specified | ||
npm.commands.install(installPath, [name], installCallback); | ||
if (forceInstall) { | ||
// local install won't work with version specified | ||
npm.commands.install(installPath, [name], installCallback); | ||
} else { | ||
// check if there is already a local install of this module | ||
// TODO there is no check made on module integrity => do a shasum integrity check | ||
fs.readFile(path.resolve(installPath, 'node_modules', path.basename(name), 'package.json'), function (err, targetPkgData) { | ||
if (err) { | ||
// file probably doesn't exist, or is corrupted: install | ||
// local install won't work with version specified | ||
npm.commands.install(installPath, [name], installCallback); | ||
} else { | ||
// there is a module that looks a lot like the one you want to install: do some checks | ||
fs.readFile(path.resolve(name, 'package.json'), function (err, sourcePkgData) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
var sourcePkg = JSON.parse(sourcePkgData), | ||
targetPkg = JSON.parse(targetPkgData); | ||
if (semver.gt(sourcePkg.version, targetPkg.version)) { | ||
// install because current found version seems outdated | ||
// local install won't work with version specified | ||
npm.commands.install(installPath, [name], installCallback); | ||
} else { | ||
callback(); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} else { | ||
@@ -113,0 +145,0 @@ if (forceInstall) { |
{ | ||
"name": "npmi", | ||
"version": "0.0.10", | ||
"version": "0.0.12", | ||
"description": "Gives a simplier API to npm install (programatically installs stuffs)", | ||
@@ -26,4 +26,5 @@ "main": "npmi.js", | ||
"dependencies": { | ||
"npm": "^1.4.16" | ||
"npm": "^1.4.16", | ||
"semver": "^3.0.1" | ||
} | ||
} |
var npmi = require('../npmi'); | ||
var os = require('os'); | ||
var path = require('path'); | ||
npmi({ | ||
name: '/tmp/potato', | ||
version: '0.0.1', | ||
path: '/tmp/potato', | ||
forceInstall: true | ||
name: path.resolve(__dirname, 'submodule'), | ||
path: path.resolve(os.tmpdir(), 'npmi_test_install'), | ||
localInstall: true | ||
}, function (err) { | ||
if (err) throw err; | ||
if (err) { | ||
console.log('Test failed'); | ||
throw err; | ||
} | ||
}); |
{ | ||
"name": "submodule", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"private": true, | ||
@@ -5,0 +5,0 @@ "description": "", |
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
13503
206
2
+ Addedsemver@^3.0.1
+ Addedsemver@3.0.1(transitive)