diff --git a/tools/lint/eslint/setup_helper.py b/tools/lint/eslint/setup_helper.py index bd6d403573d7..03277a6b6d0e 100644 --- a/tools/lint/eslint/setup_helper.py +++ b/tools/lint/eslint/setup_helper.py @@ -141,15 +141,20 @@ def package_setup( if platform.system() != "Windows": cmd.insert(0, node_path) + cmd.extend(extra_parameters) + # Ensure that bare `node` and `npm` in scripts, including post-install scripts, finds the # binary we're invoking with. Without this, it's easy for compiled extensions to get # mismatched versions of the Node.js extension API. - extra_parameters.append("--scripts-prepend-node-path") - - cmd.extend(extra_parameters) + path = os.environ.get("PATH", "").split(os.pathsep) + node_dir = os.path.dirname(node_path) + if node_dir not in path: + path = [node_dir] + path print('Installing %s for mach using "%s"...' % (package_name, " ".join(cmd))) - result = call_process(package_name, cmd) + result = call_process( + package_name, cmd, append_env={"PATH": os.pathsep.join(path)} + ) if not result: return 1 @@ -166,8 +171,9 @@ def package_setup( os.chdir(orig_cwd) -def call_process(name, cmd, cwd=None): +def call_process(name, cmd, cwd=None, append_env={}): env = dict(os.environ) + env.update(append_env) try: with open(os.devnull, "w") as fnull: