Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return function (err, view) {
if (err) {
// reset npm.prefix to saved value
npm.prefix = savedPrefix;
err.code = VIEW_ERR;
return callback(err);
}
// npm view success
var latestVersion = Object.keys(view)[0];
if ((typeof latestVersion !== 'undefined') && (latestVersion === installedVersion)) {
// reset npm.prefix to saved value
npm.prefix = savedPrefix;
return callback();
} else {
npm.commands.install(installPath, [name+'@'+latestVersion], installCallback);
}
}
}
function loadCallback(err) {
if (err) {
err.code = LOAD_ERR;
return callback(err);
}
// npm loaded successfully
savedPrefix = npm.prefix; // save current npm.prefix
npm.prefix = installPath; // change npm.prefix to given installPath
if (!name) {
// just want to do an "npm install" where a package.json is
npm.commands.install(installPath, [], installCallback);
} else if (localInstall) {
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
fs.readFile(path.resolve(name, 'package.json'), 'utf8', function (err, sourcePkgData) {
if (err) {
// reset npm.prefix to saved value
npm.prefix = savedPrefix;
callback(err);
function installCallback(err, result) {
// reset npm.prefix to saved value
npm.prefix = savedPrefix;
if (err) {
err.code = INSTALL_ERR;
}
callback(err, result);
}