You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2019/10/17 12:54:05 UTC

[cordova-cli] branch master updated: chore: node deprecation warning for <10 (#458)

This is an automated email from the ASF dual-hosted git repository.

erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new 39141dd  chore: node deprecation warning for <10 (#458)
39141dd is described below

commit 39141dd681b95e94ac9dea23a586f65589a2ba65
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Thu Oct 17 21:53:57 2019 +0900

    chore: node deprecation warning for <10 (#458)
    
    * chore: node deprecation warning for <10
    * Simplify deprecation range by implicitly using NODE_VERSION_REQUIREMENT as lower bound
    * Break long lines
---
 spec/cli.spec.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 src/cli.js       | 21 ++++++++++++++++++---
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/spec/cli.spec.js b/spec/cli.spec.js
index ba47f3e..2ee1167 100644
--- a/spec/cli.spec.js
+++ b/spec/cli.spec.js
@@ -463,4 +463,50 @@ describe('cordova cli', () => {
             });
         });
     });
+
+    describe('node requirement', () => {
+        it('should warn users about unsupported node version', () => {
+            cli.__set__('NODE_VERSION', 'v6.1.0');
+            cli.__set__('NODE_VERSION_DEPRECATING_RANGE', null);
+            cli.__set__('NODE_VERSION_REQUIREMENT', '>=8');
+
+            return cli(['node', 'cordova']).then(() => {
+                const errorMsg = logger.warn.calls.argsFor(1).toString();
+                expect(errorMsg).toMatch(/v6.1.0 is no longer supported./);
+            });
+        });
+
+        it('should not warn users about unsupported node version', () => {
+            cli.__set__('NODE_VERSION', 'v8.0.0');
+            cli.__set__('NODE_VERSION_DEPRECATING_RANGE', null);
+            cli.__set__('NODE_VERSION_REQUIREMENT', '>=8');
+
+            return cli(['node', 'cordova']).then(() => {
+                const errorMsg = logger.warn.calls.argsFor(1).toString();
+                expect(errorMsg).toBeFalsy();
+            });
+        });
+
+        it('should warn users about deprecated node version', () => {
+            cli.__set__('NODE_VERSION', 'v8.0.0');
+            cli.__set__('NODE_VERSION_DEPRECATING_RANGE', '<10');
+            cli.__set__('NODE_VERSION_REQUIREMENT', '>=8');
+
+            return cli(['node', 'cordova']).then(() => {
+                const errorMsg = logger.warn.calls.argsFor(1).toString();
+                expect(errorMsg).toMatch(/v8.0.0 has been deprecated./);
+            });
+        });
+
+        it('should warn users about deprecated node version', () => {
+            cli.__set__('NODE_VERSION', 'v10.0.0');
+            cli.__set__('NODE_VERSION_DEPRECATING_RANGE', '<10');
+            cli.__set__('NODE_VERSION_REQUIREMENT', '>=8');
+
+            return cli(['node', 'cordova']).then(() => {
+                const errorMsg = logger.warn.calls.argsFor(1).toString();
+                expect(errorMsg).toBeFalsy();
+            });
+        });
+    });
 });
diff --git a/src/cli.js b/src/cli.js
index cde5189..73ffc6b 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -31,7 +31,12 @@ var conf = new Configstore(pkg.name + '-config');
 var editor = require('editor');
 const semver = require('semver');
 
+// process.version is not declared writable or has no setter so storing in const for Jasmine.
+const NODE_VERSION = process.version;
+
+// When there is no node version in the deprecation stage, set to null or false.
 const NODE_VERSION_REQUIREMENT = '>=8';
+const NODE_VERSION_DEPRECATING_RANGE = '<10';
 
 var knownOpts = {
     'verbose': Boolean,
@@ -298,9 +303,19 @@ function cli (inputArgs) {
         }
     }
 
-    // If the Node.js versions does not meet our requirements, it will then display warning.
-    if (!semver.satisfies(process.version, NODE_VERSION_REQUIREMENT)) {
-        logger.warn(`Warning: Node.js ${process.version} is no longer supported. Please upgrade to the latest Node.js version available (LTS version recommended).`);
+    let warningPartial = null;
+
+    // If the Node.js versions does not meet our requirements or in a deprecation stage, display a warning.
+    if (!semver.satisfies(NODE_VERSION, NODE_VERSION_REQUIREMENT)) {
+        warningPartial = 'is no longer supported';
+    } else if (NODE_VERSION_DEPRECATING_RANGE &&
+               semver.satisfies(NODE_VERSION, NODE_VERSION_DEPRECATING_RANGE)) {
+        warningPartial = 'has been deprecated';
+    }
+
+    if (warningPartial) {
+        const upgradeMsg = `Please upgrade to the latest Node.js version available (LTS version recommended).`;
+        logger.warn(`Warning: Node.js ${NODE_VERSION} ${warningPartial}. ${upgradeMsg}`);
     }
 
     // If there were arguments protected from nopt with a double dash, keep


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org