Bug 1262978: Run npm to get the path to installed binaries if eslint can't otherwise be found. r=gps
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 07 Apr 2016 13:18:40 -0700
changeset 349007 7ddc5c22f1322e3c5992704f06901278dbd9c7d0
parent 349006 9c492faa4c397c9fd2a9448fce84117d0e2f8a2a
child 349008 2b2647fba6ce13884e8f0487f23e7323d67e5061
push id14989
push userdtownsend@mozilla.com
push dateFri, 08 Apr 2016 20:09:09 +0000
reviewersgps
bugs1262978
milestone48.0a1
Bug 1262978: Run npm to get the path to installed binaries if eslint can't otherwise be found. r=gps MozReview-Commit-ID: HFWID6QhpS2
python/mach_commands.py
--- a/python/mach_commands.py
+++ b/python/mach_commands.py
@@ -161,17 +161,28 @@ class MachCommands(MachCommandBase):
             return self.eslint_setup()
 
         if not binary:
             binary = os.environ.get('ESLINT', None)
             if not binary:
                 try:
                     binary = which.which('eslint')
                 except which.WhichError:
-                    pass
+                    npmPath = self.getNodeOrNpmPath("npm")
+                    if npmPath:
+                        try:
+                            output = subprocess.check_output([npmPath, "bin", "-g"],
+                                                             stderr=subprocess.STDOUT)
+                            if minversion:
+                                base = output.split("\n").strip()
+                                binary = os.path.join(base, "eslint")
+                                if not os.path.is_file(binary):
+                                    binary = None
+                        except (subprocess.CalledProcessError, WindowsError):
+                            pass
 
         if not binary:
             print(ESLINT_NOT_FOUND_MESSAGE)
             return 1
 
         self.log(logging.INFO, 'eslint', {'binary': binary, 'args': args},
             'Running {binary}')