Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated util._extend and util.isArray with Object.assign and Array.isArray #5958

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions examples/sourcemap-auto-resolve/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var API = module.exports = function(opts) {
if (opts.pm2_home) {
// Override default conf file
this.pm2_home = opts.pm2_home;
conf = util._extend(conf, path_structure(this.pm2_home));
conf = Object.assign(conf, path_structure(this.pm2_home));
}
else if (opts.independent == true && conf.IS_WINDOWS === false) {
// Create an unique pm2 instance
Expand All @@ -75,7 +75,7 @@ var API = module.exports = function(opts) {
// It will go as in proc
if (typeof(opts.daemon_mode) == 'undefined')
this.daemon_mode = false;
conf = util._extend(conf, path_structure(this.pm2_home));
conf = Object.assign(conf, path_structure(this.pm2_home));
}

this._conf = conf;
Expand Down Expand Up @@ -299,7 +299,7 @@ API.prototype.start = function(cmd, opts, cb) {

var that = this;

if (util.isArray(opts.watch) && opts.watch.length === 0)
if (Array.isArray(opts.watch) && opts.watch.length === 0)
opts.watch = (opts.rawArgs ? !!~opts.rawArgs.indexOf('--watch') : !!~process.argv.indexOf('--watch')) || false;

if (Common.isConfigFile(cmd) || (typeof(cmd) === 'object'))
Expand Down Expand Up @@ -760,7 +760,7 @@ API.prototype._startScript = function(script, opts, cb) {
resolved_paths.env['PM2_HOME'] = that.pm2_home;

var additional_env = Modularizer.getAdditionalConf(resolved_paths.name);
util._extend(resolved_paths.env, additional_env);
Object.assign(resolved_paths.env, additional_env);

// Is KM linked?
resolved_paths.km_link = that.gl_is_km_linked;
Expand Down Expand Up @@ -940,7 +940,7 @@ API.prototype._startJson = function(file, opts, action, pipe, cb) {
// Notice: if people use the same name in different apps,
// duplicated envs will be overrode by the last one
var env = envs.reduce(function(e1, e2){
return util._extend(e1, e2);
return Object.assign(e1, e2);
});

// When we are processing JSON, allow to keep the new env by default
Expand Down Expand Up @@ -1012,7 +1012,7 @@ API.prototype._startJson = function(file, opts, action, pipe, cb) {
resolved_paths.env['PM2_HOME'] = that.pm2_home;

var additional_env = Modularizer.getAdditionalConf(resolved_paths.name);
util._extend(resolved_paths.env, additional_env);
Object.assign(resolved_paths.env, additional_env);

resolved_paths.env = Common.mergeEnvironmentVariables(resolved_paths, opts.env, deployConf);

Expand Down Expand Up @@ -1226,7 +1226,7 @@ API.prototype._operate = function(action_name, process_name, envs, cb) {
if (conf.PM2_PROGRAMMATIC == true)
new_env = Common.safeExtend({}, process.env);
else
new_env = util._extend({}, process.env);
new_env = Object.assign({}, process.env);

Object.keys(envs).forEach(function(k) {
new_env[k] = envs[k];
Expand Down Expand Up @@ -1355,7 +1355,7 @@ API.prototype._operate = function(action_name, process_name, envs, cb) {
* if yes load configuration variables and merge with the current environment
*/
var additional_env = Modularizer.getAdditionalConf(process_name);
util._extend(envs, additional_env);
Object.assign(envs, additional_env);

return processIds(ids, cb);
});
Expand Down Expand Up @@ -1401,7 +1401,7 @@ API.prototype._handleAttributeUpdate = function(opts) {

delete appConf.exec_mode;

if (util.isArray(appConf.watch) && appConf.watch.length === 0) {
if (Array.isArray(appConf.watch) && appConf.watch.length === 0) {
if (!~opts.rawArgs.indexOf('--watch'))
delete appConf.watch
}
Expand Down
4 changes: 2 additions & 2 deletions lib/binaries/CLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,15 @@ commander.command('install <module|git:// url>')
.option('--safe [time]', 'keep module backup, if new module fail = restore with previous')
.description('install or update a module and run it forever')
.action(function(plugin_name, opts) {
require('util')._extend(commander, opts);
Object.assign(commander, opts);
pm2.install(plugin_name, commander);
});

commander.command('module:update <module|git:// url>')
.option('--tarball', 'is local tarball')
.description('update a module and run it forever')
.action(function(plugin_name, opts) {
require('util')._extend(commander, opts);
Object.assign(commander, opts);
pm2.install(plugin_name, commander);
});

Expand Down
13 changes: 6 additions & 7 deletions test/programmatic/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var p = require('path');
var fs = require('fs')
var EventEmitter = require('events').EventEmitter
var PM2 = require('../..');
var extend = require('util')._extend

var cwd = __dirname + '/../fixtures/watcher';

Expand Down Expand Up @@ -91,7 +90,7 @@ describe('Watcher', function() {
it('should be watching', function(cb) {
testPM2Env('server-watch:online')({watch: true}, cb)

var json_app = extend(json, {watch: true});
var json_app = Object.assign(json, {watch: true});
pm2.start(json_app, errShouldBeNull)
})

Expand All @@ -114,19 +113,19 @@ describe('Watcher', function() {
pm2.stop('server-watch', errShouldBeNull)

// this would be better:
// pm2.actionFromJson('stopProcessId', extend(json, {watch: false}), errShouldBeNull)
// pm2.actionFromJson('stopProcessId', Object.assign(json, {watch: false}), errShouldBeNull)
// or :
// pm2.stop('server-watch', {watch: false}, errShouldBeNull)
})

it('should not watch', function(cb) {
testPM2Env('server-watch:online')({watch: false}, cb)
pm2.restart(extend(json, {watch: false}), errShouldBeNull)
pm2.restart(Object.assign(json, {watch: false}), errShouldBeNull)
})

it('should watch', function(cb) {
testPM2Env('server-watch:online')({restart_time: 3, watch: true}, cb)
pm2.restart(extend(json, {watch: true}), errShouldBeNull)
pm2.restart(Object.assign(json, {watch: true}), errShouldBeNull)
})

it('should delete process', function(cb) {
Expand Down Expand Up @@ -179,12 +178,12 @@ describe('Watcher', function() {

it('should work with watch_delay', function(cb) {
testPM2Env('server-watch:online')({watch: true, watch_delay: 4000}, cb);
pm2.start(extend(json, {watch: true, watch_delay: 4000}), errShouldBeNull);
pm2.start(Object.assign(json, {watch: true, watch_delay: 4000}), errShouldBeNull);
})

it('should not crash with watch_delay without watch', function(cb) {
testPM2Env('server-watch:online')({watch_delay: 4000}, cb);
pm2.start(extend(json, {watch_delay: 4000}), errShouldBeNull);
pm2.start(Object.assign(json, {watch_delay: 4000}), errShouldBeNull);
})

/**
Expand Down