New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

npm-custom-installer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-custom-installer - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

bin/installer.js

90

lib/installer.js

@@ -8,2 +8,3 @@ 'use strict';

var _ = require('lodash');
var async = require('neo-async');
var jsbeautifier = require('js-beautify').js_beautify;

@@ -20,27 +21,80 @@

var filename = 'package.json';
var dirpath = 'node_modules';
module.exports = function(opts) {
var conf = opts.conf;
var currentPath = process.env.PWD;
var config = require(path.resolve(currentPath, conf));
var masterPath = process.env.PWD;
var config = require(path.resolve(masterPath, conf));
var globalConfig = config.global || {};
var masterPackagePath = path.resolve(currentPath, 'package.json');
var beforePackage = require(masterPackagePath);
var afterPackage = _.mapValues(beforePackage, function(items, key) {
var replaceItems = config[key];
if (_.isEmpty(replaceItems)) {
return items;
installPackages(masterPath, config, {}, function(err) {
console.log(err);
});
function installPackages(currentPath, currentConfig, installedPackages, callback) {
if (_.isEmpty(currentConfig)) {
return callback();
}
items = _.mapValues(replaceItems, function(item) {
return _.isString(item) ? item : item.version;
var packages = resolvePackages(currentPath, currentConfig, installedPackages);
install(currentPath, packages.before, packages.after, function(err, log) {
if (err) {
throw err;
}
console.log(log);
addInstalledPackages(packages.after);
async.eachSeries(currentConfig.dependencies, function(conf, key, done) {
if (!_.isObject(conf)) {
return done();
}
var nextPath = path.resolve(currentPath, dirpath, key);
installPackages(nextPath, conf, _.clone(installedPackages), done);
}, callback);
});
return items;
});
fs.writeFileSync(masterPackagePath, JSON.stringify(afterPackage), encode);
exec('npm install', function(err, res) {
console.log(err, res);
var json = jsbeautifier(JSON.stringify(beforePackage), options.beautify);
fs.writeFileSync(masterPackagePath, json, encode);
});
function addInstalledPackages(afterPackage) {
_.forEach(afterPackage.dependencies, function(version, key) {
installedPackages[key] = installedPackages[key] || {};
installedPackages[key][version] = true;
});
}
}
function resolvePackages(currentPath, currentConfig, installedPackages) {
var currentPackagePath = path.resolve(currentPath, filename);
var beforePackage = require(currentPackagePath);
var afterPackage = _.mapValues(beforePackage, function(items, key) {
var replaceConfig = currentConfig[key];
if (_.isEmpty(replaceConfig)) {
return items;
}
if (_.isString(replaceConfig)) {
return replaceConfig;
}
items = _.mapValues(items, function(item, key) {
var conf = globalConfig[key] || replaceConfig[key];
return !conf ? item : _.isString(conf) ? conf : conf.version;
});
return items;
});
afterPackage.dependencies = _.omit(afterPackage.dependencies, function(version, key) {
var installed = installedPackages[key];
return installed && installed[version];
});
return {
before: beforePackage,
after: afterPackage
};
}
};
function install(dirpath, before, after, callback) {
var packagePath = path.resolve(dirpath, filename);
fs.writeFileSync(packagePath, JSON.stringify(after), encode);
exec('cd ' + dirpath + ' && npm install --production', function(err, res) {
var json = jsbeautifier(JSON.stringify(before), options.beautify);
fs.writeFileSync(packagePath, json, encode);
callback(err, res);
});
}

14

package.json
{
"name": "npm-custom-installer",
"version": "0.0.1",
"description": "",
"main": "index.js",
"version": "0.1.0",
"description": "npm-custom-installer is enable to use dependencies of user defined.",
"main": "./lib/index.js",
"scripts": {

@@ -15,2 +15,5 @@ "test": "echo \"Error: no test specified\" && exit 1"

"license": "MIT",
"bin": {
"npm-custom-installer": "./bin/installer.js"
},
"bugs": {

@@ -21,6 +24,7 @@ "url": "https://github.com/suguru03/npm-custom-installer/issues"

"dependencies": {
"commander": "^2.8.1",
"js-beautify": "^1.5.5",
"lodash": "^3.8.0"
"lodash": "^3.8.0",
"minimist": "^1.1.1",
"neo-async": "^1.1.2"
}
}
# npm-custom-installer
--
npm-custom-installer is enable to use dependencies of user defined.
## sample
__package.json__
```json
{
"dependencies": {
"mocha": "2.0.0"
}
}
```
__config.js__
```js
{
dependencies: {
mocha: {
version: '2.2.5',
dependencies: {
commander: '=2.8.1',
'node-glob': '^5.0.0'
}
}
}
}
```
```bash
./bin/installer -c config.js
```

@@ -12,6 +12,13 @@ 'use strict';

dependencies: {
'neo-async': '^1.0.1'
'neo-async': '^1.0.0'
}
},
mocha: {
version: '2.2.5',
dependencies: {
commander: '=2.8.1',
'glob': '^5.0.0'
}
}
}
};

@@ -8,4 +8,6 @@ {

"func-comparator": "0.4.0",
"minimist": "^1.1.1",
"mocha": "2.0.0",
"neo-async": "^0.6.0"
}
}
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