From 23fc7b3096824c6fbdf1a0f8a97e7db231c56a6b Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Thu, 13 Feb 2020 20:50:39 +0800 Subject: [PATCH] chore: move option.serialization of validation into utils/options.js --- lib/master.js | 8 ++------ lib/utils/options.js | 7 +++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/master.js b/lib/master.js index b6cdaaf..2e60634 100644 --- a/lib/master.js +++ b/lib/master.js @@ -65,12 +65,6 @@ class Master extends EventEmitter { const frameworkPath = this.options.framework; const frameworkPkg = utility.readJSONSync(path.join(frameworkPath, 'package.json')); - /* istanbul ignore next */ - if (this.options.serialization && !semver.gte(process.version, '12.16.0')) { - const err = new Error('[master] agent_worker options.serialization requires Node.js >= v12.16.0'); - this.logger.error(err); - } - this.log(`[master] =================== ${frameworkPkg.name} start =====================`); this.logger.info(`[master] node version ${process.version}`); /* istanbul ignore next */ @@ -254,7 +248,9 @@ class Master extends EventEmitter { const debugPort = process.env.EGG_AGENT_DEBUG_PORT || 5800; if (this.options.isDebug) opt.execArgv = process.execArgv.concat([ `--${semver.gte(process.version, '8.0.0') ? 'inspect' : 'debug'}-port=${debugPort}` ]); + /* istanbul ignore next */ if (semver.gte(process.version, '12.16.0')) { + /* istanbul ignore next */ if (this.options.serialization) { opt.serialization = this.options.serialization; } diff --git a/lib/utils/options.js b/lib/utils/options.js index 2b4ed44..44d57e6 100644 --- a/lib/utils/options.js +++ b/lib/utils/options.js @@ -7,6 +7,7 @@ const assert = require('assert'); const utils = require('egg-utils'); const is = require('is-type-of'); const deprecate = require('depd')('egg'); +const semver = require('semver'); module.exports = function(options) { const defaults = { @@ -64,6 +65,12 @@ module.exports = function(options) { const isDebug = process.execArgv.some(argv => argv.includes('--debug') || argv.includes('--inspect')); if (isDebug) options.isDebug = isDebug; + /* istanbul ignore next */ + if (options.serialization && !semver.gte(process.version, '12.16.0')) { + const err = new Error('[master] agent_worker options.serialization requires Node.js >= v12.16.0'); + this.logger.error(err); + } + return options; };