Skip to content

Commit 16204d5

Browse files
committed
Remove deprecated util._extend and util.isArray
...with Object.assign and Array.isArray
1 parent 653af36 commit 16204d5

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

examples/sourcemap-auto-resolve/API.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var API = module.exports = function(opts) {
6363
if (opts.pm2_home) {
6464
// Override default conf file
6565
this.pm2_home = opts.pm2_home;
66-
conf = util._extend(conf, path_structure(this.pm2_home));
66+
conf = Object.assign(conf, path_structure(this.pm2_home));
6767
}
6868
else if (opts.independent == true && conf.IS_WINDOWS === false) {
6969
// Create an unique pm2 instance
@@ -75,7 +75,7 @@ var API = module.exports = function(opts) {
7575
// It will go as in proc
7676
if (typeof(opts.daemon_mode) == 'undefined')
7777
this.daemon_mode = false;
78-
conf = util._extend(conf, path_structure(this.pm2_home));
78+
conf = Object.assign(conf, path_structure(this.pm2_home));
7979
}
8080

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

300300
var that = this;
301301

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

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

762762
var additional_env = Modularizer.getAdditionalConf(resolved_paths.name);
763-
util._extend(resolved_paths.env, additional_env);
763+
Object.assign(resolved_paths.env, additional_env);
764764

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

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

10141014
var additional_env = Modularizer.getAdditionalConf(resolved_paths.name);
1015-
util._extend(resolved_paths.env, additional_env);
1015+
Object.assign(resolved_paths.env, additional_env);
10161016

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

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

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

13601360
return processIds(ids, cb);
13611361
});
@@ -1401,7 +1401,7 @@ API.prototype._handleAttributeUpdate = function(opts) {
14011401

14021402
delete appConf.exec_mode;
14031403

1404-
if (util.isArray(appConf.watch) && appConf.watch.length === 0) {
1404+
if (Array.isArray(appConf.watch) && appConf.watch.length === 0) {
14051405
if (!~opts.rawArgs.indexOf('--watch'))
14061406
delete appConf.watch
14071407
}

lib/binaries/CLI.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,15 @@ commander.command('install <module|git:// url>')
504504
.option('--safe [time]', 'keep module backup, if new module fail = restore with previous')
505505
.description('install or update a module and run it forever')
506506
.action(function(plugin_name, opts) {
507-
require('util')._extend(commander, opts);
507+
Object.assign(commander, opts);
508508
pm2.install(plugin_name, commander);
509509
});
510510

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

test/programmatic/watcher.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ var p = require('path');
33
var fs = require('fs')
44
var EventEmitter = require('events').EventEmitter
55
var PM2 = require('../..');
6-
var extend = require('util')._extend
76

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

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

94-
var json_app = extend(json, {watch: true});
93+
var json_app = Object.assign(json, {watch: true});
9594
pm2.start(json_app, errShouldBeNull)
9695
})
9796

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

116115
// this would be better:
117-
// pm2.actionFromJson('stopProcessId', extend(json, {watch: false}), errShouldBeNull)
116+
// pm2.actionFromJson('stopProcessId', Object.assign(json, {watch: false}), errShouldBeNull)
118117
// or :
119118
// pm2.stop('server-watch', {watch: false}, errShouldBeNull)
120119
})
121120

122121
it('should not watch', function(cb) {
123122
testPM2Env('server-watch:online')({watch: false}, cb)
124-
pm2.restart(extend(json, {watch: false}), errShouldBeNull)
123+
pm2.restart(Object.assign(json, {watch: false}), errShouldBeNull)
125124
})
126125

127126
it('should watch', function(cb) {
128127
testPM2Env('server-watch:online')({restart_time: 3, watch: true}, cb)
129-
pm2.restart(extend(json, {watch: true}), errShouldBeNull)
128+
pm2.restart(Object.assign(json, {watch: true}), errShouldBeNull)
130129
})
131130

132131
it('should delete process', function(cb) {
@@ -179,12 +178,12 @@ describe('Watcher', function() {
179178

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

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

190189
/**

0 commit comments

Comments
 (0)