Bug 1342715 - Allow node to be in the PATH on Windows, rather than just a set directory. r=mossop
authorMark Banner <standard8@mozilla.com>
Fri, 02 Jun 2017 14:55:03 +0100
changeset 413331 7c0b44852e1e5688040f6ff5d48d8d8ca0907cc1
parent 413330 814a9b5ef1866c988b6d97490f305d5a246b44c2
child 413332 4ae5d273a14975c2b5ddc609eb1abdf2bed5ff99
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1342715
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1342715 - Allow node to be in the PATH on Windows, rather than just a set directory. r=mossop MozReview-Commit-ID: G8jxtPsUp9k
tools/lint/eslint/setup_helper.py
--- a/tools/lint/eslint/setup_helper.py
+++ b/tools/lint/eslint/setup_helper.py
@@ -238,35 +238,48 @@ def get_possible_node_paths_win():
     return list({
         "%s\\nodejs" % os.environ.get("SystemDrive"),
         os.path.join(os.environ.get("ProgramFiles"), "nodejs"),
         os.path.join(os.environ.get("PROGRAMW6432"), "nodejs"),
         os.path.join(os.environ.get("PROGRAMFILES"), "nodejs")
     })
 
 
+def simple_which(filename, path=None):
+    try:
+        return which.which(filename, path)
+    except which.WhichError:
+        return None
+
+
 def which_path(filename):
     """
     Return the nodejs or npm path.
     """
     if platform.system() == "Windows":
         for ext in [".cmd", ".exe", ""]:
-            try:
-                return which.which(filename + ext, path=get_possible_node_paths_win())
-            except which.WhichError:
-                pass
-    else:
-        try:
-            return which.which(filename)
-        except which.WhichError:
-            if filename == "node":
-                # Retry it with "nodejs" as Linux tends to prefer nodejs rather than node.
-                return which_path("nodejs")
+            # Look in the system path first.
+            filepath = simple_which(filename + ext)
+            if filepath is None:
+                # If we don't find it there, fallback to the non-system paths.
+                filepath = simple_which(filename + ext, get_possible_node_paths_win())
+
+            if filepath is not None:
+                return filepath
 
-    return None
+        # If we got this far, we didn't find it with any of the extensions, so
+        # just return.
+        return None
+
+    # Non-windows.
+    path = simple_which(filename)
+    if path is None and filename == "node":
+        path = simple_which("nodejs")
+
+    return path
 
 
 def get_node_or_npm_path(filename, minversion=None):
     node_or_npm_path = which_path(filename)
 
     if not node_or_npm_path:
         if filename in ('node', 'nodejs'):
             print(NODE_NOT_FOUND_MESSAGE)