Bug 1380956 - Add a minimum version requirement for npm in ESLint setup and improve the version handling. r?ahal draft
authorMark Banner <standard8@mozilla.com>
Fri, 14 Jul 2017 11:39:57 +0100
changeset 609733 85fefecbf8d81ff421c3bf96eb4ef392e32987f8
parent 609732 f2039d741295405100df389fa3b6be73647514f5
child 609734 08fe4e0afecebf10b6ce9314581c229a9ef039ef
push id68669
push usermbanner@mozilla.com
push dateMon, 17 Jul 2017 12:10:56 +0000
reviewersahal
bugs1380956
milestone56.0a1
Bug 1380956 - Add a minimum version requirement for npm in ESLint setup and improve the version handling. r?ahal MozReview-Commit-ID: 9ZCKfsgQsO7
tools/lint/eslint/setup_helper.py
--- a/tools/lint/eslint/setup_helper.py
+++ b/tools/lint/eslint/setup_helper.py
@@ -11,21 +11,31 @@ import platform
 import re
 import subprocess
 import sys
 from distutils.version import LooseVersion
 sys.path.append(os.path.join(
     os.path.dirname(__file__), "..", "..", "..", "third_party", "python", "which"))
 import which
 
+NODE_MIN_VERSION = "6.9.1"
+NPM_MIN_VERSION = "3.10.8"
+
 NODE_MACHING_VERSION_NOT_FOUND_MESSAGE = """
-nodejs is out of date. You currently have node %s but v6.9.1 is required.
+nodejs is out of date. You currently have node v%s but v%s is required.
 Please update nodejs from https://nodejs.org and try again.
 """.strip()
 
+NPM_MACHING_VERSION_NOT_FOUND_MESSAGE = """
+npm is out of date. You currently have npm v%s but v%s is required.
+You can usually update npm with:
+
+npm i -g npm
+""".strip()
+
 NODE_NOT_FOUND_MESSAGE = """
 nodejs is either not installed or is installed to a non-standard path.
 Please install nodejs from https://nodejs.org and try again.
 
 Valid installation paths:
 """.strip()
 
 NPM_NOT_FOUND_MESSAGE = """
@@ -294,24 +304,27 @@ def get_node_or_npm_path(filename, minve
         elif platform.system() == "Linux":
             print("  - /usr/bin/{}".format(filename))
 
         return None
 
     if not minversion:
         return node_or_npm_path
 
-    version_str = get_version(node_or_npm_path)
+    version_str = get_version(node_or_npm_path).lstrip('v')
 
-    version = LooseVersion(version_str.lstrip('v'))
+    version = LooseVersion(version_str)
 
     if version > minversion:
         return node_or_npm_path
 
-    print(NODE_MACHING_VERSION_NOT_FOUND_MESSAGE % version_str.strip())
+    if filename == "npm":
+        print(NPM_MACHING_VERSION_NOT_FOUND_MESSAGE % (version_str.strip(), minversion))
+    else:
+        print(NODE_MACHING_VERSION_NOT_FOUND_MESSAGE % (version_str.strip(), minversion))
 
     return None
 
 
 def get_version(path):
     try:
         version_str = subprocess.check_output([path, "--version"],
                                               stderr=subprocess.STDOUT)
@@ -360,17 +373,17 @@ def get_project_root():
 
 
 def get_eslint_module_path():
     return os.path.join(get_project_root(), "tools", "lint", "eslint")
 
 
 def check_node_executables_valid():
     # eslint requires at least node 6.9.1
-    node_path = get_node_or_npm_path("node", LooseVersion("6.9.1"))
+    node_path = get_node_or_npm_path("node", LooseVersion(NODE_MIN_VERSION))
     if not node_path:
         return False
 
-    npm_path = get_node_or_npm_path("npm")
+    npm_path = get_node_or_npm_path("npm", LooseVersion(NPM_MIN_VERSION))
     if not npm_path:
         return False
 
     return True