prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Executable `prettier` not found
  hello hello!
  
  As discussed on discord, I'm having an issue running prettier via pre-commit:
  
  ```bash
  $ pre-commit --version
  pre-commit 2.5.1
  
  $ cat .pre-commit-config.yaml
  repos:
    - repo: https://github.com/prettier/prettier
      rev: 2.0.5
      hooks:
        - id: prettier
  
  $ pre-commit clean
  Cleaned /home/rkm/.cache/pre-commit.
  
  > pre-commit run prettier --files README.md
  [INFO] Initializing environment for https://github.com/prettier/prettier.
  [INFO] Installing environment for https://github.com/prettier/prettier.
  [INFO] Once installed this environment will be reused.
  [INFO] This may take a few minutes...
  prettier.................................................................Failed
  - hook id: prettier
  - exit code: 1
  
  Executable `prettier` not found
  ```
  
  it seems like prettier is installed correctly, but the symlink to it is not created:
  
  ```bash
  $ find ~/.cache/pre-commit/ -name prettier.js
  /home/rkm/.cache/pre-commit/repoes79dg4v/bin/prettier.js
  
  $ ls -l $(find ~/.cache/pre-commit/ -name node_env-default)/bin
  total 70376
  -rwxr-xr-x. 1 rkm rkm     3702 Jun 17 17:30 activate
  -rwxr-xr-x. 1 rkm rkm     3964 Jun 17 17:30 activate.fish
  -rwxr-xr-x. 1 rkm rkm 72052312 Jun  2 14:33 node
  lrwxrwxrwx. 1 rkm rkm        4 Jun 17 17:30 nodejs -> node
  lrwxrwxrwx. 1 rkm rkm       38 Jun 17 17:30 npm -> ../lib/node_modules/npm/bin/npm-cli.js
  lrwxrwxrwx. 1 rkm rkm       38 Jun 17 17:30 npx -> ../lib/node_modules/npm/bin/npx-cli.js
  -rwxr-xr-x. 1 rkm rkm      355 Jun 17 17:30 shim 
  ```
  
  (doing the same in a docker container results in a `prettier` symlink being created there).
  
  I suspect my VM may be borked somehow, but not sure how to debug this further. Any thoughts? Thanks!
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pre_commit/languages/node.py`
  Content:
  ```
  1 import contextlib
  2 import functools
  3 import os
  4 import sys
  5 from typing import Generator
  6 from typing import Sequence
  7 from typing import Tuple
  8 
  9 import pre_commit.constants as C
  10 from pre_commit import parse_shebang
  11 from pre_commit.envcontext import envcontext
  12 from pre_commit.envcontext import PatchesT
  13 from pre_commit.envcontext import Var
  14 from pre_commit.hook import Hook
  15 from pre_commit.languages import helpers
  16 from pre_commit.languages.python import bin_dir
  17 from pre_commit.prefix import Prefix
  18 from pre_commit.util import clean_path_on_failure
  19 from pre_commit.util import cmd_output
  20 from pre_commit.util import cmd_output_b
  21 
  22 ENVIRONMENT_DIR = 'node_env'
  23 healthy = helpers.basic_healthy
  24 
  25 
  26 @functools.lru_cache(maxsize=1)
  27 def get_default_version() -> str:
  28     # nodeenv does not yet support `-n system` on windows
  29     if sys.platform == 'win32':
  30         return C.DEFAULT
  31     # if node is already installed, we can save a bunch of setup time by
  32     # using the installed version
  33     elif all(parse_shebang.find_executable(exe) for exe in ('node', 'npm')):
  34         return 'system'
  35     else:
  36         return C.DEFAULT
  37 
  38 
  39 def _envdir(prefix: Prefix, version: str) -> str:
  40     directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
  41     return prefix.path(directory)
  42 
  43 
  44 def get_env_patch(venv: str) -> PatchesT:
  45     if sys.platform == 'cygwin':  # pragma: no cover
  46         _, win_venv, _ = cmd_output('cygpath', '-w', venv)
  47         install_prefix = fr'{win_venv.strip()}\bin'
  48         lib_dir = 'lib'
  49     elif sys.platform == 'win32':  # pragma: no cover
  50         install_prefix = bin_dir(venv)
  51         lib_dir = 'Scripts'
  52     else:  # pragma: win32 no cover
  53         install_prefix = venv
  54         lib_dir = 'lib'
  55     return (
  56         ('NODE_VIRTUAL_ENV', venv),
  57         ('NPM_CONFIG_PREFIX', install_prefix),
  58         ('npm_config_prefix', install_prefix),
  59         ('NODE_PATH', os.path.join(venv, lib_dir, 'node_modules')),
  60         ('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))),
  61     )
  62 
  63 
  64 @contextlib.contextmanager
  65 def in_env(
  66         prefix: Prefix,
  67         language_version: str,
  68 ) -> Generator[None, None, None]:
  69     with envcontext(get_env_patch(_envdir(prefix, language_version))):
  70         yield
  71 
  72 
  73 def install_environment(
  74         prefix: Prefix, version: str, additional_dependencies: Sequence[str],
  75 ) -> None:
  76     additional_dependencies = tuple(additional_dependencies)
  77     assert prefix.exists('package.json')
  78     envdir = _envdir(prefix, version)
  79 
  80     # https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx?f=255&MSPPError=-2147217396#maxpath
  81     if sys.platform == 'win32':  # pragma: no cover
  82         envdir = fr'\\?\{os.path.normpath(envdir)}'
  83     with clean_path_on_failure(envdir):
  84         cmd = [
  85             sys.executable, '-mnodeenv', '--prebuilt', '--clean-src', envdir,
  86         ]
  87         if version != C.DEFAULT:
  88             cmd.extend(['-n', version])
  89         cmd_output_b(*cmd)
  90 
  91         with in_env(prefix, version):
  92             # https://npm.community/t/npm-install-g-git-vs-git-clone-cd-npm-install-g/5449
  93             # install as if we installed from git
  94             helpers.run_setup_cmd(prefix, ('npm', 'install'))
  95             helpers.run_setup_cmd(
  96                 prefix,
  97                 ('npm', 'install', '-g', '.', *additional_dependencies),
  98             )
  99 
  100 
  101 def run_hook(
  102         hook: Hook,
  103         file_args: Sequence[str],
  104         color: bool,
  105 ) -> Tuple[int, bytes]:
  106     with in_env(hook.prefix, hook.language_version):
  107         return helpers.run_xargs(hook, hook.cmd, file_args, color=color)
  108
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pre_commit/languages/node.py b/pre_commit/languages/node.py
  --- a/pre_commit/languages/node.py
  +++ b/pre_commit/languages/node.py
  @@ -10,6 +10,7 @@
   from pre_commit import parse_shebang
   from pre_commit.envcontext import envcontext
   from pre_commit.envcontext import PatchesT
  +from pre_commit.envcontext import UNSET
   from pre_commit.envcontext import Var
   from pre_commit.hook import Hook
   from pre_commit.languages import helpers
  @@ -56,6 +57,8 @@
           ('NODE_VIRTUAL_ENV', venv),
           ('NPM_CONFIG_PREFIX', install_prefix),
           ('npm_config_prefix', install_prefix),
  +        ('NPM_CONFIG_USERCONFIG', UNSET),
  +        ('npm_config_userconfig', UNSET),
           ('NODE_PATH', os.path.join(venv, lib_dir, 'node_modules')),
           ('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))),
       )
  
verification_info: {"golden_diff": "diff --git a/pre_commit/languages/node.py b/pre_commit/languages/node.py\n--- a/pre_commit/languages/node.py\n+++ b/pre_commit/languages/node.py\n@@ -10,6 +10,7 @@\n from pre_commit import parse_shebang\n from pre_commit.envcontext import envcontext\n from pre_commit.envcontext import PatchesT\n+from pre_commit.envcontext import UNSET\n from pre_commit.envcontext import Var\n from pre_commit.hook import Hook\n from pre_commit.languages import helpers\n@@ -56,6 +57,8 @@\n         ('NODE_VIRTUAL_ENV', venv),\n         ('NPM_CONFIG_PREFIX', install_prefix),\n         ('npm_config_prefix', install_prefix),\n+        ('NPM_CONFIG_USERCONFIG', UNSET),\n+        ('npm_config_userconfig', UNSET),\n         ('NODE_PATH', os.path.join(venv, lib_dir, 'node_modules')),\n         ('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))),\n     )\n", "issue": "Executable `prettier` not found\nhello hello!\r\n\r\nAs discussed on discord, I'm having an issue running prettier via pre-commit:\r\n\r\n```bash\r\n$ pre-commit --version\r\npre-commit 2.5.1\r\n\r\n$ cat .pre-commit-config.yaml\r\nrepos:\r\n  - repo: https://github.com/prettier/prettier\r\n    rev: 2.0.5\r\n    hooks:\r\n      - id: prettier\r\n\r\n$ pre-commit clean\r\nCleaned /home/rkm/.cache/pre-commit.\r\n\r\n> pre-commit run prettier --files README.md\r\n[INFO] Initializing environment for https://github.com/prettier/prettier.\r\n[INFO] Installing environment for https://github.com/prettier/prettier.\r\n[INFO] Once installed this environment will be reused.\r\n[INFO] This may take a few minutes...\r\nprettier.................................................................Failed\r\n- hook id: prettier\r\n- exit code: 1\r\n\r\nExecutable `prettier` not found\r\n```\r\n\r\nit seems like prettier is installed correctly, but the symlink to it is not created:\r\n\r\n```bash\r\n$ find ~/.cache/pre-commit/ -name prettier.js\r\n/home/rkm/.cache/pre-commit/repoes79dg4v/bin/prettier.js\r\n\r\n$ ls -l $(find ~/.cache/pre-commit/ -name node_env-default)/bin\r\ntotal 70376\r\n-rwxr-xr-x. 1 rkm rkm     3702 Jun 17 17:30 activate\r\n-rwxr-xr-x. 1 rkm rkm     3964 Jun 17 17:30 activate.fish\r\n-rwxr-xr-x. 1 rkm rkm 72052312 Jun  2 14:33 node\r\nlrwxrwxrwx. 1 rkm rkm        4 Jun 17 17:30 nodejs -> node\r\nlrwxrwxrwx. 1 rkm rkm       38 Jun 17 17:30 npm -> ../lib/node_modules/npm/bin/npm-cli.js\r\nlrwxrwxrwx. 1 rkm rkm       38 Jun 17 17:30 npx -> ../lib/node_modules/npm/bin/npx-cli.js\r\n-rwxr-xr-x. 1 rkm rkm      355 Jun 17 17:30 shim \r\n```\r\n\r\n(doing the same in a docker container results in a `prettier` symlink being created there).\r\n\r\nI suspect my VM may be borked somehow, but not sure how to debug this further. Any thoughts? Thanks!\r\n\n", "before_files": [{"content": "import contextlib\nimport functools\nimport os\nimport sys\nfrom typing import Generator\nfrom typing import Sequence\nfrom typing import Tuple\n\nimport pre_commit.constants as C\nfrom pre_commit import parse_shebang\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import PatchesT\nfrom pre_commit.envcontext import Var\nfrom pre_commit.hook import Hook\nfrom pre_commit.languages import helpers\nfrom pre_commit.languages.python import bin_dir\nfrom pre_commit.prefix import Prefix\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import cmd_output\nfrom pre_commit.util import cmd_output_b\n\nENVIRONMENT_DIR = 'node_env'\nhealthy = helpers.basic_healthy\n\n\n@functools.lru_cache(maxsize=1)\ndef get_default_version() -> str:\n    # nodeenv does not yet support `-n system` on windows\n    if sys.platform == 'win32':\n        return C.DEFAULT\n    # if node is already installed, we can save a bunch of setup time by\n    # using the installed version\n    elif all(parse_shebang.find_executable(exe) for exe in ('node', 'npm')):\n        return 'system'\n    else:\n        return C.DEFAULT\n\n\ndef _envdir(prefix: Prefix, version: str) -> str:\n    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)\n    return prefix.path(directory)\n\n\ndef get_env_patch(venv: str) -> PatchesT:\n    if sys.platform == 'cygwin':  # pragma: no cover\n        _, win_venv, _ = cmd_output('cygpath', '-w', venv)\n        install_prefix = fr'{win_venv.strip()}\\bin'\n        lib_dir = 'lib'\n    elif sys.platform == 'win32':  # pragma: no cover\n        install_prefix = bin_dir(venv)\n        lib_dir = 'Scripts'\n    else:  # pragma: win32 no cover\n        install_prefix = venv\n        lib_dir = 'lib'\n    return (\n        ('NODE_VIRTUAL_ENV', venv),\n        ('NPM_CONFIG_PREFIX', install_prefix),\n        ('npm_config_prefix', install_prefix),\n        ('NODE_PATH', os.path.join(venv, lib_dir, 'node_modules')),\n        ('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))),\n    )\n\n\n@contextlib.contextmanager\ndef in_env(\n        prefix: Prefix,\n        language_version: str,\n) -> Generator[None, None, None]:\n    with envcontext(get_env_patch(_envdir(prefix, language_version))):\n        yield\n\n\ndef install_environment(\n        prefix: Prefix, version: str, additional_dependencies: Sequence[str],\n) -> None:\n    additional_dependencies = tuple(additional_dependencies)\n    assert prefix.exists('package.json')\n    envdir = _envdir(prefix, version)\n\n    # https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx?f=255&MSPPError=-2147217396#maxpath\n    if sys.platform == 'win32':  # pragma: no cover\n        envdir = fr'\\\\?\\{os.path.normpath(envdir)}'\n    with clean_path_on_failure(envdir):\n        cmd = [\n            sys.executable, '-mnodeenv', '--prebuilt', '--clean-src', envdir,\n        ]\n        if version != C.DEFAULT:\n            cmd.extend(['-n', version])\n        cmd_output_b(*cmd)\n\n        with in_env(prefix, version):\n            # https://npm.community/t/npm-install-g-git-vs-git-clone-cd-npm-install-g/5449\n            # install as if we installed from git\n            helpers.run_setup_cmd(prefix, ('npm', 'install'))\n            helpers.run_setup_cmd(\n                prefix,\n                ('npm', 'install', '-g', '.', *additional_dependencies),\n            )\n\n\ndef run_hook(\n        hook: Hook,\n        file_args: Sequence[str],\n        color: bool,\n) -> Tuple[int, bytes]:\n    with in_env(hook.prefix, hook.language_version):\n        return helpers.run_xargs(hook, hook.cmd, file_args, color=color)\n", "path": "pre_commit/languages/node.py"}], "after_files": [{"content": "import contextlib\nimport functools\nimport os\nimport sys\nfrom typing import Generator\nfrom typing import Sequence\nfrom typing import Tuple\n\nimport pre_commit.constants as C\nfrom pre_commit import parse_shebang\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import PatchesT\nfrom pre_commit.envcontext import UNSET\nfrom pre_commit.envcontext import Var\nfrom pre_commit.hook import Hook\nfrom pre_commit.languages import helpers\nfrom pre_commit.languages.python import bin_dir\nfrom pre_commit.prefix import Prefix\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import cmd_output\nfrom pre_commit.util import cmd_output_b\n\nENVIRONMENT_DIR = 'node_env'\nhealthy = helpers.basic_healthy\n\n\n@functools.lru_cache(maxsize=1)\ndef get_default_version() -> str:\n    # nodeenv does not yet support `-n system` on windows\n    if sys.platform == 'win32':\n        return C.DEFAULT\n    # if node is already installed, we can save a bunch of setup time by\n    # using the installed version\n    elif all(parse_shebang.find_executable(exe) for exe in ('node', 'npm')):\n        return 'system'\n    else:\n        return C.DEFAULT\n\n\ndef _envdir(prefix: Prefix, version: str) -> str:\n    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)\n    return prefix.path(directory)\n\n\ndef get_env_patch(venv: str) -> PatchesT:\n    if sys.platform == 'cygwin':  # pragma: no cover\n        _, win_venv, _ = cmd_output('cygpath', '-w', venv)\n        install_prefix = fr'{win_venv.strip()}\\bin'\n        lib_dir = 'lib'\n    elif sys.platform == 'win32':  # pragma: no cover\n        install_prefix = bin_dir(venv)\n        lib_dir = 'Scripts'\n    else:  # pragma: win32 no cover\n        install_prefix = venv\n        lib_dir = 'lib'\n    return (\n        ('NODE_VIRTUAL_ENV', venv),\n        ('NPM_CONFIG_PREFIX', install_prefix),\n        ('npm_config_prefix', install_prefix),\n        ('NPM_CONFIG_USERCONFIG', UNSET),\n        ('npm_config_userconfig', UNSET),\n        ('NODE_PATH', os.path.join(venv, lib_dir, 'node_modules')),\n        ('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))),\n    )\n\n\n@contextlib.contextmanager\ndef in_env(\n        prefix: Prefix,\n        language_version: str,\n) -> Generator[None, None, None]:\n    with envcontext(get_env_patch(_envdir(prefix, language_version))):\n        yield\n\n\ndef install_environment(\n        prefix: Prefix, version: str, additional_dependencies: Sequence[str],\n) -> None:\n    additional_dependencies = tuple(additional_dependencies)\n    assert prefix.exists('package.json')\n    envdir = _envdir(prefix, version)\n\n    # https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx?f=255&MSPPError=-2147217396#maxpath\n    if sys.platform == 'win32':  # pragma: no cover\n        envdir = fr'\\\\?\\{os.path.normpath(envdir)}'\n    with clean_path_on_failure(envdir):\n        cmd = [\n            sys.executable, '-mnodeenv', '--prebuilt', '--clean-src', envdir,\n        ]\n        if version != C.DEFAULT:\n            cmd.extend(['-n', version])\n        cmd_output_b(*cmd)\n\n        with in_env(prefix, version):\n            # https://npm.community/t/npm-install-g-git-vs-git-clone-cd-npm-install-g/5449\n            # install as if we installed from git\n            helpers.run_setup_cmd(prefix, ('npm', 'install'))\n            helpers.run_setup_cmd(\n                prefix,\n                ('npm', 'install', '-g', '.', *additional_dependencies),\n            )\n\n\ndef run_hook(\n        hook: Hook,\n        file_args: Sequence[str],\n        color: bool,\n) -> Tuple[int, bytes]:\n    with in_env(hook.prefix, hook.language_version):\n        return helpers.run_xargs(hook, hook.cmd, file_args, color=color)\n", "path": "pre_commit/languages/node.py"}]}