Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

npmi

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npmi - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

test/anotherPath.js

56

npmi.js

@@ -1,6 +0,7 @@

var npm = require('npm');
var npm = require('npm');
var fs = require('fs');
var path = require('path');
var LOAD_ERR = 'NPM_LOAD_ERR',
INSTALL_ERR = 'NPM_INSTALL_ERR',
LIST_ERR = 'NPM_LIST_ERR',
VIEW_ERR = 'NPM_VIEW_ERR';

@@ -17,3 +18,3 @@

version = options.version || 'latest',
path = options.path || '.',
installPath = options.path || '.',
forceInstall = options.forceInstall || false,

@@ -37,25 +38,31 @@ localInstall = options.localInstall || false,

if (installedVersion === latestVersion) return callback(null);
else npm.commands.install(path, [name+'@'+latestVersion], installCallback);
else npm.commands.install(installPath, [name+'@'+latestVersion], installCallback);
}
}
function listCallback(err, list) {
if (err) {
err.code = LIST_ERR;
return callback(err);
}
function checkInstalled() {
// check that version matches
fs.readFile(path.resolve(installPath, 'node_modules', name, '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);
}
// npm list success
if (list.dependencies[name]) {
var pkg = JSON.parse(pkgRawData);
if (version === 'latest') {
return npm.commands.view([name], true, viewCallback(list.dependencies[name].version));
// 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));
} else if (pkg.version === version) {
// package is installed and version matches
return callback(null);
} else {
if (list.dependencies[name].version === version) {
return callback(null);
}
// version does not match: reinstall
return npm.commands.install(installPath, [name+'@'+version], installCallback);
}
}
// if we end-up here, it means that whether the package is not installed
// or it is installed but with the wrong version: reinstall
npm.commands.install(path, [name+'@'+version], installCallback);
});
}

@@ -82,11 +89,11 @@

// local install won't work with version specified
npm.commands.install(path, [name], installCallback);
npm.commands.install(installPath, [name], installCallback);
} else {
if (forceInstall) {
// reinstall package module
npm.commands.install(path, [name+'@'+version], installCallback);
// reinstall package module
npm.commands.install(installPath, [name+'@'+version], installCallback);
} else {
// check if package is installed and
npm.commands.list([name], true, listCallback);
// check if package is installed
checkInstalled();
}

@@ -101,5 +108,4 @@ }

npmi.INSTALL_ERR = INSTALL_ERR;
npmi.LIST_ERR = LIST_ERR;
npmi.VIEW_ERR = VIEW_ERR;
module.exports = npmi;
{
"name": "npmi",
"version": "0.0.3",
"version": "0.0.4",
"description": "Gives a simplier API to npm install (programatically installs stuffs)",

@@ -5,0 +5,0 @@ "main": "npmi.js",

@@ -9,3 +9,4 @@ var npmi = require('./../npmi');

path: '.',
forceInstall: false
forceInstall: false,
localInstall: false
};

@@ -12,0 +13,0 @@ npmi(options, function (err, result) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc