From 6ec47ea73640190d86186fd50b7a32fa0a9c4b9b Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 19 Jun 2020 13:58:14 -0700 Subject: [PATCH] fix node hooks when NPM_CONFIG_USERCONFIG is set --- pre_commit/languages/node.py | 3 +++ tests/repository_test.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/pre_commit/languages/node.py b/pre_commit/languages/node.py index 26f4919e..d99e6f2c 100644 --- a/pre_commit/languages/node.py +++ b/pre_commit/languages/node.py @@ -10,6 +10,7 @@ import pre_commit.constants as C 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 @@ def get_env_patch(venv: str) -> PatchesT: ('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'))), ) diff --git a/tests/repository_test.py b/tests/repository_test.py index ee57d992..84e4da93 100644 --- a/tests/repository_test.py +++ b/tests/repository_test.py @@ -260,6 +260,14 @@ def test_run_versioned_node_hook(tempdir_factory, store): ) +@xfailif_windows # pragma: win32 no cover +def test_node_hook_with_npm_userconfig_set(tempdir_factory, store, tmpdir): + cfg = tmpdir.join('cfg') + cfg.write('cache=/dne\n') + with mock.patch.dict(os.environ, NPM_CONFIG_USERCONFIG=str(cfg)): + test_run_a_node_hook(tempdir_factory, store) + + def test_run_a_ruby_hook(tempdir_factory, store): _test_hook_repo( tempdir_factory, store, 'ruby_hooks_repo',