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

refactor: replace deprecated util._extend with Object.assign #5239

Merged
merged 1 commit into from
Jan 20, 2022
Merged
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
2 changes: 1 addition & 1 deletion constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ var csts = {

};

module.exports = util._extend(csts, path_structure);
module.exports = Object.assign(csts, path_structure);
16 changes: 8 additions & 8 deletions lib/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class API {
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 @@ -93,7 +93,7 @@ class API {
// 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 @@ -876,7 +876,7 @@ class API {
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 @@ -1072,7 +1072,7 @@ class API {
// 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 @@ -1147,7 +1147,7 @@ class API {
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 @@ -1368,7 +1368,7 @@ class API {
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 @@ -1510,7 +1510,7 @@ class API {
* 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 All @@ -1529,7 +1529,7 @@ class API {
* if yes load configuration variables and merge with the current environment
*/
var ns_additional_env = Modularizer.getAdditionalConf(process_name);
util._extend(envs, ns_additional_env);
Object.assign(envs, ns_additional_env);
return processIds(ns_process_ids, cb);
});
});
Expand Down
6 changes: 3 additions & 3 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ Client.prototype.launchDaemon = function(opts, cb) {
detached : true,
cwd : that.conf.cwd || process.cwd(),
windowsHide: true,
env : util._extend({
'SILENT' : that.conf.DEBUG ? !that.conf.DEBUG : true,
'PM2_HOME' : that.pm2_home
env : Object.assign({
'SILENT' : that.conf.DEBUG ? !that.conf.DEBUG : true,
'PM2_HOME' : that.pm2_home
}, process.env),
stdio : ['ipc', out, err]
});
Expand Down
14 changes: 7 additions & 7 deletions lib/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Common.prepareAppConf = function(opts, app) {
app.env = [
{}, (app.filter_env && app.filter_env.length > 0) ? filterEnv(process.env) : env, app.env || {}
].reduce(function(e1, e2){
return util._extend(e1, e2);
return Object.assign(e1, e2);
});

app.pm_cwd = cwd;
Expand Down Expand Up @@ -593,19 +593,19 @@ Common.mergeEnvironmentVariables = function(app_env, env_name, deploy_conf) {
/**
* Extra configuration update
*/
util._extend(new_conf, app)
Object.assign(new_conf, app);

if (env_name) {
// First merge variables from deploy.production.env object as least priority.
if (deploy_conf && deploy_conf[env_name] && deploy_conf[env_name]['env']) {
util._extend(new_conf.env, deploy_conf[env_name]['env']);
Object.assign(new_conf.env, deploy_conf[env_name]['env']);
}

util._extend(new_conf.env, app.env);
Object.assign(new_conf.env, app.env);

// Then, last and highest priority, merge the app.env_production object.
if ('env_' + env_name in app) {
util._extend(new_conf.env, app['env_' + env_name]);
Object.assign(new_conf.env, app['env_' + env_name]);
}
else {
Common.printOut(cst.PREFIX_MSG_WARNING + chalk.bold('Environment [%s] is not defined in process file'), env_name);
Expand All @@ -618,8 +618,8 @@ Common.mergeEnvironmentVariables = function(app_env, env_name, deploy_conf) {
current_conf: {}
}

util._extend(res, new_conf.env)
util._extend(res.current_conf, new_conf)
Object.assign(res, new_conf.env);
Object.assign(res.current_conf, new_conf);

// #2541 force resolution of node interpreter
if (app.exec_interpreter &&
Expand Down
2 changes: 1 addition & 1 deletion lib/Daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ Daemon.prototype.startLogic = function() {
if (!msg.process || !God.clusters_db[msg.process.pm_id])
return console.error('AXM MONITOR Unknown id %s', msg.process.pm_id);

util._extend(God.clusters_db[msg.process.pm_id].pm2_env.axm_monitor, Utility.clone(msg.data));
Object.assign(God.clusters_db[msg.process.pm_id].pm2_env.axm_monitor, Utility.clone(msg.data));
msg = null;
});

Expand Down
2 changes: 1 addition & 1 deletion lib/Watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = function ClusterMode(God) {
};

if (pm2_env.watch_options) {
watch_options = util._extend(watch_options, pm2_env.watch_options);
watch_options = Object.assign(watch_options, pm2_env.watch_options);
}

log('Watch opts', watch_options);
Expand Down
2 changes: 1 addition & 1 deletion lib/tools/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Config.filterOptions = function(cmd) {
*/
Config.validateJSON = function(json){
// clone config
var conf = util._extend({}, json),
var conf = Object.assign({}, json),
res = {};
this._errors = [];

Expand Down