Bug 1262978: Run npm to get the path to installed binaries if eslint can't otherwise be found. r?gps draft
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 07 Apr 2016 13:18:40 -0700
changeset 348645 a581b6dd40af1d4e71345a89cfcd63b47c2be22f
parent 347688 4b00370192a495bf15b4110a2dd6c8fd8084e0c9
child 348669 b082f7af14e6ee9a7d3d6ea82ace92b0417deee0
push id14861
push userdtownsend@mozilla.com
push dateThu, 07 Apr 2016 20:19:50 +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}')