Bug 1509387 - When setting up ESLint, call npm via node so that node doesn't need to be in the path. r=ahal

Differential Revision: https://phabricator.services.mozilla.com/D12742

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2018-11-26 20:49:00 +00:00
Родитель 3ccff85cdd
Коммит a74ab6032f
2 изменённых файлов: 21 добавлений и 7 удалений

Просмотреть файл

@ -47,12 +47,22 @@ def find_node_paths():
return paths
def check_executable_version(exe):
def check_executable_version(exe, wrap_call_with_node=True):
"""Determine the version of a Node executable by invoking it.
May raise ``subprocess.CalledProcessError`` or ``ValueError`` on failure.
"""
out = subprocess.check_output([exe, "--version"]).lstrip('v').rstrip()
out = None
# npm may be a script, so we must call it with node.
if wrap_call_with_node:
binary, _ = find_node_executable()
if binary:
out = subprocess.check_output([binary, exe, "--version"]).lstrip('v').rstrip()
# If we can't find node, or we don't need to wrap it, fallback to calling
# direct.
if not out:
out = subprocess.check_output([exe, "--version"]).lstrip('v').rstrip()
return StrictVersion(out)
@ -102,10 +112,10 @@ def find_npm_executable(min_version=NPM_MIN_VERSION):
version tuple. Both tuple entries will be None if a Node executable
could not be resolved.
"""
return find_executable(["npm"], min_version)
return find_executable(["npm"], min_version, True)
def find_executable(names, min_version):
def find_executable(names, min_version, use_node_for_version_check=False):
paths = find_node_paths()
found_exe = None
@ -124,7 +134,7 @@ def find_executable(names, min_version):
# We always verify we can invoke the executable and its version is
# sane.
try:
version = check_executable_version(exe)
version = check_executable_version(exe, use_node_for_version_check)
except (subprocess.CalledProcessError, ValueError):
continue

Просмотреть файл

@ -92,6 +92,10 @@ def eslint_setup(should_clobber=False):
if not npm_path:
return 1
node_path, _ = find_node_executable()
if not node_path:
return 1
extra_parameters = ["--loglevel=error"]
package_lock_json_path = os.path.join(get_project_root(), "package-lock.json")
@ -102,10 +106,10 @@ def eslint_setup(should_clobber=False):
npm_is_older_version = version < StrictVersion("5.8.0").version
if npm_is_older_version:
cmd = [npm_path, "install"]
cmd = [node_path, npm_path, "install"]
shutil.copy2(package_lock_json_path, package_lock_json_tmp_path)
else:
cmd = [npm_path, "ci"]
cmd = [node_path, npm_path, "ci"]
cmd.extend(extra_parameters)
print("Installing eslint for mach using \"%s\"..." % (" ".join(cmd)))