From 4179e8315d306483c1c9d1dedb5e6cc4e70bbc87 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Fri, 14 Feb 2020 10:17:54 +0800 Subject: [PATCH] feat: update Node.js version requirement for serialization >= v12.16.0 < v13.0.0, or >= v13.2.0 --- lib/master.js | 7 +++++-- lib/utils/options.js | 6 ++++-- test/options.test.js | 27 +++++++++++++++++---------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/master.js b/lib/master.js index 2201c9f..3b5e939 100644 --- a/lib/master.js +++ b/lib/master.js @@ -38,7 +38,7 @@ class Master extends EventEmitter { * - {Object} [https] https options, { key, cert, ca }, full path * - {Array|String} [require] will inject into worker/agent process * - {String} [pidFile] will save master pid to this file - * - {json|advanced} [serialization] Advanced serialization for IPC since Node.js v12.16.0, + * - {json|advanced} [serialization] Advanced serialization for IPC need Node.js >= v12.16.0 or >= v13.2.0, * see: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V12.md#advanced-serialization-for-ipc */ constructor(options) { @@ -251,7 +251,10 @@ class Master extends EventEmitter { 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')) { + + if ((semver.gte(process.version, '12.16.0') && semver.lt(process.version, '13.0.0')) + || semver.gte(process.version, '13.2.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 22444b8..eccf9ed 100644 --- a/lib/utils/options.js +++ b/lib/utils/options.js @@ -65,7 +65,9 @@ module.exports = function(options) { const isDebug = process.execArgv.some(argv => argv.includes('--debug') || argv.includes('--inspect')); if (isDebug) options.isDebug = isDebug; - if (semver.gte(process.version, '12.16.0')) { + if ((semver.gte(process.version, '12.16.0') && semver.lt(process.version, '13.0.0')) + || semver.gte(process.version, '13.2.0' + ) { /* istanbul ignore else */ if (typeof options.serialization !== 'undefined' && options.serialization !== 'json' @@ -75,7 +77,7 @@ module.exports = function(options) { } else { /* istanbul ignore else */ if (options.serialization) { - throw new Error('[egg-cluster] options.serialization requires Node.js >= v12.16.0'); + throw new Error('[egg-cluster] options.serialization requires Node.js >= v12.16.0 or >= v13.2.0'); } } diff --git a/test/options.test.js b/test/options.test.js index ce842d8..b12586f 100644 --- a/test/options.test.js +++ b/test/options.test.js @@ -205,8 +205,15 @@ describe('test/options.test.js', () => { }); describe('should options.serialization', () => { - it('should with "json" value when Node.js >= v12.16.0', () => { - if (semver.gte(process.version, '12.16.0')) { + let isSupportSerialization = false + if ((semver.gte(process.version, '12.16.0') && semver.lt(process.version, '13.0.0')) + || semver.gte(process.version, '13.2.0' + ) { + isSupportSerialization = true + } + + it('should with "json" value when Node.js supports serialization', () => { + if (isSupportSerialization) { const options = parseOptions({ serialization: 'json', }); @@ -214,8 +221,8 @@ describe('test/options.test.js', () => { } }); - it('should with "advanced" value when Node.js >= v12.16.0', () => { - if (semver.gte(process.version, '12.16.0')) { + it('should with "advanced" value when Node.js supports serialization', () => { + if (isSupportSerialization) { const options = parseOptions({ serialization: 'advanced', }); @@ -223,8 +230,8 @@ describe('test/options.test.js', () => { } }); - it('should error with invalid value when Node.js >= v12.16.0', () => { - if (semver.gte(process.version, '12.16.0')) { + it('should error with invalid value when Node.js supports serialization', () => { + if (isSupportSerialization) { try { parseOptions({ serialization: 'fake', @@ -236,8 +243,8 @@ describe('test/options.test.js', () => { } }); - it('should error with empty value when Node.js >= v12.16.0', () => { - if (semver.gte(process.version, '12.16.0')) { + it('should error with empty value when Node.js supports serialization', () => { + if (isSupportSerialization) { try { parseOptions({ serialization: '', @@ -249,8 +256,8 @@ describe('test/options.test.js', () => { } }); - it('should error with value when Node.js < v12.16.0', () => { - if (!semver.gte(process.version, '12.16.0')) { + it('should error with value when Node.js not supports serialization', () => { + if (!isSupportSerialization) { try { parseOptions({ serialization: 'json',