Skip to content

Commit

Permalink
refactor: only import the necessary methods from async.
Browse files Browse the repository at this point in the history
  • Loading branch information
medanat committed Jul 19, 2018
1 parent 679b14f commit 6466ee4
Show file tree
Hide file tree
Showing 23 changed files with 108 additions and 104 deletions.
24 changes: 12 additions & 12 deletions bin/pm2
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ if (semver.satisfies(process.versions.node, '>= 6.0.0'))

process.env.PM2_USAGE = 'CLI';

var cst = require('../constants.js');
var cst = require('../constants.js');

var commander = require('commander');
var chalk = require('chalk');
var async = require('async');
var commander = require('commander');
var chalk = require('chalk');
var forEachLimit = require('async/forEachLimit');

var debug = require('debug')('pm2:cli');
var PM2 = require('../lib/API.js');
var pkg = require('../package.json');
var tabtab = require('../lib/completion.js');
var debug = require('debug')('pm2:cli');
var PM2 = require('../lib/API.js');
var pkg = require('../package.json');
var tabtab = require('../lib/completion.js');

// Early detection of silent to avoid printing motd
if (process.argv.indexOf('--silent') > -1 ||
Expand Down Expand Up @@ -295,7 +295,7 @@ commander.command('start [name|file|ecosystem|id...]')
if (cmd.length === 0) {
cmd = [cst.APP_CONF_DEFAULT_FILE];
}
async.forEachLimit(cmd, 1, function(script, next) {
forEachLimit(cmd, 1, function(script, next) {
pm2.start(script, commander, next);
}, function(err) {
pm2.speedList(err ? 1 : 0);
Expand Down Expand Up @@ -346,7 +346,7 @@ commander.command('stop <id|name|all|json|stdin...>')
.option('--watch', 'Stop watching folder for changes')
.description('stop a process')
.action(function(param) {
async.forEachLimit(param, 1, function(script, next) {
forEachLimit(param, 1, function(script, next) {
pm2.stop(script, next);
}, function(err) {
pm2.speedList(err ? 1 : 0);
Expand All @@ -362,7 +362,7 @@ commander.command('restart <id|name|all|json|stdin...>')
.action(function(param) {
// Commander.js patch
param = patchCommanderArg(param);
async.forEachLimit(param, 1, function(script, next) {
forEachLimit(param, 1, function(script, next) {
pm2.restart(script, commander, next);
}, function(err) {
pm2.speedList(err ? 1 : 0);
Expand Down Expand Up @@ -433,7 +433,7 @@ commander.command('delete <name|id|script|all|json|stdin...>')
pm2.delete(param, 'pipe');
});
} else
async.forEachLimit(name, 1, function(script, next) {
forEachLimit(name, 1, function(script, next) {
pm2.delete(script,'', next);
}, function(err) {
pm2.speedList(err ? 1 : 0);
Expand Down
17 changes: 9 additions & 8 deletions examples/sourcemap-auto-resolve/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
var commander = require('commander');
var fs = require('fs');
var path = require('path');
var async = require('async');
var eachLimit = require('async/eachLimit');
var series = require('async/series');
var debug = require('debug')('pm2:cli');
var util = require('util');
var chalk = require('chalk');
Expand Down Expand Up @@ -317,7 +318,7 @@ API.prototype.reset = function(process_name, cb) {
var that = this;

function processIds(ids, cb) {
async.eachLimit(ids, conf.CONCURRENT_ACTIONS, function(id, next) {
eachLimit(ids, conf.CONCURRENT_ACTIONS, function(id, next) {
that.Client.executeRemote('resetMetaProcessId', id, function(err, res) {
if (err) console.error(err);
Common.printOut(conf.PREFIX_MSG + 'Resetting meta for process id %d', id);
Expand Down Expand Up @@ -777,7 +778,7 @@ API.prototype._startScript = function(script, opts, cb) {
});
}

async.series([
series([
restartExistingProcessName,
restartExistingProcessId,
restartExistingProcessPath
Expand Down Expand Up @@ -916,7 +917,7 @@ API.prototype._startJson = function(file, opts, action, pipe, cb) {
* Auto detect application already started
* and act on them depending on action
*/
async.eachLimit(Object.keys(proc_list), conf.CONCURRENT_ACTIONS, function(proc_name, next) {
eachLimit(Object.keys(proc_list), conf.CONCURRENT_ACTIONS, function(proc_name, next) {
// Skip app name (--only option)
if (apps_name.indexOf(proc_name) == -1)
return next();
Expand Down Expand Up @@ -981,7 +982,7 @@ API.prototype._startJson = function(file, opts, action, pipe, cb) {
}
});

async.eachLimit(apps_to_start, conf.CONCURRENT_ACTIONS, function(app, next) {
eachLimit(apps_to_start, conf.CONCURRENT_ACTIONS, function(app, next) {
if (opts.cwd)
app.cwd = opts.cwd;
if (opts.force_name)
Expand Down Expand Up @@ -1096,7 +1097,7 @@ API.prototype.actionFromJson = function(action, file, opts, jsonVia, cb) {
if ((appConf = Common.verifyConfs(appConf)) instanceof Error)
return cb ? cb(appConf) : that.exitCli(conf.ERROR_EXIT);

async.eachLimit(appConf, conf.CONCURRENT_ACTIONS, function(proc, next1) {
eachLimit(appConf, conf.CONCURRENT_ACTIONS, function(proc, next1) {
var name = '';
var new_env;

Expand All @@ -1120,7 +1121,7 @@ API.prototype.actionFromJson = function(action, file, opts, jsonVia, cb) {
}
if (!ids) return next1();

async.eachLimit(ids, conf.CONCURRENT_ACTIONS, function(id, next2) {
eachLimit(ids, conf.CONCURRENT_ACTIONS, function(id, next2) {
var opts = {};

//stopProcessId could accept options to?
Expand Down Expand Up @@ -1212,7 +1213,7 @@ API.prototype._operate = function(action_name, process_name, envs, cb) {
if (action_name == 'deleteProcessId')
concurrent_actions = 10;

async.eachLimit(ids, concurrent_actions, function(id, next) {
eachLimit(ids, concurrent_actions, function(id, next) {
var opts;

// These functions need extra param to be passed
Expand Down
17 changes: 9 additions & 8 deletions lib/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
const commander = require('commander');
const fs = require('fs');
const path = require('path');
const async = require('async');
const eachLimit = require('async/eachLimit');
const series = require('async/series');
const debug = require('debug')('pm2:cli');
const util = require('util');
const chalk = require('chalk');
Expand Down Expand Up @@ -336,7 +337,7 @@ class API {
var that = this;

function processIds(ids, cb) {
async.eachLimit(ids, conf.CONCURRENT_ACTIONS, function(id, next) {
eachLimit(ids, conf.CONCURRENT_ACTIONS, function(id, next) {
that.Client.executeRemote('resetMetaProcessId', id, function(err, res) {
if (err) console.error(err);
Common.printOut(conf.PREFIX_MSG + 'Resetting meta for process id %d', id);
Expand Down Expand Up @@ -795,7 +796,7 @@ class API {
});
}

async.series([
series([
restartExistingProcessName,
restartExistingProcessId,
restartExistingProcessPath
Expand Down Expand Up @@ -931,7 +932,7 @@ class API {
* Auto detect application already started
* and act on them depending on action
*/
async.eachLimit(Object.keys(proc_list), conf.CONCURRENT_ACTIONS, function(proc_name, next) {
eachLimit(Object.keys(proc_list), conf.CONCURRENT_ACTIONS, function(proc_name, next) {

// Skip app name (--only option)
if (apps_name.indexOf(proc_name) == -1)
Expand Down Expand Up @@ -997,7 +998,7 @@ class API {
}
});

async.eachLimit(apps_to_start, conf.CONCURRENT_ACTIONS, function(app, next) {
eachLimit(apps_to_start, conf.CONCURRENT_ACTIONS, function(app, next) {
if (opts.cwd)
app.cwd = opts.cwd;
if (opts.force_name)
Expand Down Expand Up @@ -1112,7 +1113,7 @@ class API {
if ((appConf = Common.verifyConfs(appConf)) instanceof Error)
return cb ? cb(appConf) : that.exitCli(conf.ERROR_EXIT);

async.eachLimit(appConf, conf.CONCURRENT_ACTIONS, function(proc, next1) {
eachLimit(appConf, conf.CONCURRENT_ACTIONS, function(proc, next1) {
var name = '';
var new_env;

Expand All @@ -1136,7 +1137,7 @@ class API {
}
if (!ids) return next1();

async.eachLimit(ids, conf.CONCURRENT_ACTIONS, function(id, next2) {
eachLimit(ids, conf.CONCURRENT_ACTIONS, function(id, next2) {
var opts = {};

//stopProcessId could accept options to?
Expand Down Expand Up @@ -1228,7 +1229,7 @@ class API {
if (action_name == 'deleteProcessId')
concurrent_actions = 10;

async.eachLimit(ids, concurrent_actions, function(id, next) {
eachLimit(ids, concurrent_actions, function(id, next) {
var opts;

// These functions need extra param to be passed
Expand Down
4 changes: 2 additions & 2 deletions lib/API/Log.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var fs = require('fs'),
util = require('util'),
chalk = require('chalk'),
async = require('async'),
forEachLimit = require('async/forEachLimit'),
moment = require('moment');

var Log = module.exports = {};
Expand Down Expand Up @@ -48,7 +48,7 @@ Log.tail = function(apps_list, lines, raw, callback) {
(fs.existsSync(b.path) ? fs.statSync(b.path).mtime.valueOf() : 0);
});

async.forEachLimit(apps_list, 1, function(app, next) {
forEachLimit(apps_list, 1, function(app, next) {
if (!fs.existsSync(app.path || ''))
return next();

Expand Down
10 changes: 6 additions & 4 deletions lib/API/Modules/Modularizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
var path = require('path');
var fs = require('fs');
var os = require('os');
var async = require('async');
var parallel = require('async/parallel');
var eachLimit = require('async/eachLimit');
var forEachLimit = require('async/forEachLimit');
var p = path;
var readline = require('readline');
var spawn = require('child_process').spawn;
Expand Down Expand Up @@ -126,7 +128,7 @@ Modularizer.installMultipleInternalModules = function (modules, cb) {
})(i));
}

async.parallel(functionList, function (err, results) {
parallel(functionList, function (err, results) {
for (var i = 0; i < results.length; i++) {
var display = results[i].module.message || results[i].module.name;
if (results[i].err) {
Expand Down Expand Up @@ -267,7 +269,7 @@ Modularizer.launchModules = function(CLI, cb) {

if (!modules) return cb();

async.eachLimit(Object.keys(modules), 1, function(module_name, next) {
eachLimit(Object.keys(modules), 1, function(module_name, next) {
Common.printOut(cst.PREFIX_MSG_MOD + 'Starting module ' + module_name);

var install_path = path.join(cst.DEFAULT_MODULE_PATH, module_name);
Expand Down Expand Up @@ -366,7 +368,7 @@ Modularizer.uninstall = function(CLI, module_name, cb) {

if (!modules) return cb();

return async.forEachLimit(Object.keys(modules), 1, function(module_name, next) {
return forEachLimit(Object.keys(modules), 1, function(module_name, next) {
uninstallModule(CLI, {
module_name : module_name,
deep_uninstall : true
Expand Down
4 changes: 2 additions & 2 deletions lib/API/Modules/Modularizerv1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
var path = require('path');
var fs = require('fs');
var async = require('async');
var eachLimit = require('async/eachLimit');
var p = path;
var spawn = require('child_process').spawn;
var chalk = require('chalk');
Expand Down Expand Up @@ -72,7 +72,7 @@ Modularizer.launchModules = function(CLI, cb) {

if (!modules) return cb();

async.eachLimit(Object.keys(modules), 1, function(module, next) {
eachLimit(Object.keys(modules), 1, function(module, next) {
var pmod = p.join(module_folder, module, cst.DEFAULT_MODULE_JSON);

Common.printOut(cst.PREFIX_MSG_MOD + 'Starting module ' + module);
Expand Down
12 changes: 6 additions & 6 deletions lib/API/Modules/Modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*
**************************/

var cst = require('../../../constants.js');
var Common = require('../../Common.js');
var UX = require('../CliUx');
var chalk = require('chalk');
var async = require('async');
var cst = require('../../../constants.js');
var Common = require('../../Common.js');
var UX = require('../CliUx');
var chalk = require('chalk');
var forEachLimit = require('async/forEachLimit');

var path = require('path');
var fs = require('fs');
Expand Down Expand Up @@ -154,7 +154,7 @@ module.exports = function(CLI) {
var that = this;

this.Client.getAllModulesId(function(err, modules_id) {
async.forEachLimit(modules_id, 1, function(id, next) {
forEachLimit(modules_id, 1, function(id, next) {
that._operate('deleteProcessId', id, next);
}, function() {
return cb ? cb() : false;
Expand Down
23 changes: 12 additions & 11 deletions lib/API/Startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
* Use of this source code is governed by a license that
* can be found in the LICENSE file.
*/
var debug = require('debug')('pm2:cli:startup');
var chalk = require('chalk');
var path = require('path');
var fs = require('fs');
var async = require('async');
var exec = require('child_process').exec;
var Common = require('../Common.js');
var cst = require('../../constants.js');
var spawn = require('child_process').spawn;
var debug = require('debug')('pm2:cli:startup');
var chalk = require('chalk');
var path = require('path');
var fs = require('fs');
var forEachLimit = require('async/forEachLimit');
var eachLimit = require('async/eachLimit');
var exec = require('child_process').exec;
var Common = require('../Common.js');
var cst = require('../../constants.js');
var spawn = require('child_process').spawn;

module.exports = function(CLI) {
/**
Expand Down Expand Up @@ -333,7 +334,7 @@ module.exports = function(CLI) {

Common.printOut(cst.PREFIX_MSG + 'Making script booting at startup...');

async.forEachLimit(commands, 1, function(command, next) {
forEachLimit(commands, 1, function(command, next) {
Common.printOut(cst.PREFIX_MSG + '[-] Executing: %s...', chalk.bold(command));
require('shelljs').exec(command, function(code, stdout, stderr) {
if (code === 0) {
Expand Down Expand Up @@ -553,7 +554,7 @@ module.exports = function(CLI) {
return Object.keys(current).indexOf(i) < 0;
})

async.eachLimit(processes, cst.CONCURRENT_ACTIONS, function(app, next) {
eachLimit(processes, cst.CONCURRENT_ACTIONS, function(app, next) {
if (tostart.indexOf(app.name) == -1)
return next();
that.Client.executeRemote('prepare', app, function(err, dt) {
Expand Down
16 changes: 8 additions & 8 deletions lib/API/Version.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

var cst = require('../../constants.js');
var Common = require('../Common.js');
var fs = require('fs');
var async = require('async');
var child = require('child_process');
var cst = require('../../constants.js');
var Common = require('../Common.js');
var fs = require('fs');
var eachSeries = require('async/eachSeries');
var child = require('child_process');

var printError = Common.printError;
var printOut = Common.printOut;
Expand Down Expand Up @@ -274,7 +274,7 @@ module.exports = function(CLI) {
var execCommands = function(repo_path, command_list, cb) {
var stdout = '';

async.eachSeries(command_list, function(command, callback) {
eachSeries(command_list, function(command, callback) {
stdout += '\n' + command;
exec('cd '+repo_path+';'+command,
function(code, output) {
Expand Down Expand Up @@ -315,7 +315,7 @@ module.exports = function(CLI) {
}

if (data && data.apps) {
async.eachSeries(data.apps, function(item, callb) {
eachSeries(data.apps, function(item, callb) {
if (item.name && item.name === proc_name) {
if (item.post_update && typeof(item.post_update) === 'object') {
if (item.exec_timeout)
Expand All @@ -342,7 +342,7 @@ module.exports = function(CLI) {
});
};

async.eachSeries(['ecosystem.json', 'process.json', 'package.json'], searchForCommands,
eachSeries(['ecosystem.json', 'process.json', 'package.json'], searchForCommands,
function(final) {
return cb(final ? final : []);
});
Expand Down
Loading

0 comments on commit 6466ee4

Please sign in to comment.