Skip to content

Commit e2fe94c

Browse files
authored
Merge pull request #1521 from pre-commit/npm_config_userconfig
fix node hooks when NPM_CONFIG_USERCONFIG is set
2 parents 7d46852 + 6ec47ea commit e2fe94c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pre_commit/languages/node.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pre_commit import parse_shebang
1111
from pre_commit.envcontext import envcontext
1212
from pre_commit.envcontext import PatchesT
13+
from pre_commit.envcontext import UNSET
1314
from pre_commit.envcontext import Var
1415
from pre_commit.hook import Hook
1516
from pre_commit.languages import helpers
@@ -56,6 +57,8 @@ def get_env_patch(venv: str) -> PatchesT:
5657
('NODE_VIRTUAL_ENV', venv),
5758
('NPM_CONFIG_PREFIX', install_prefix),
5859
('npm_config_prefix', install_prefix),
60+
('NPM_CONFIG_USERCONFIG', UNSET),
61+
('npm_config_userconfig', UNSET),
5962
('NODE_PATH', os.path.join(venv, lib_dir, 'node_modules')),
6063
('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))),
6164
)

tests/repository_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ def test_run_versioned_node_hook(tempdir_factory, store):
260260
)
261261

262262

263+
@xfailif_windows # pragma: win32 no cover
264+
def test_node_hook_with_npm_userconfig_set(tempdir_factory, store, tmpdir):
265+
cfg = tmpdir.join('cfg')
266+
cfg.write('cache=/dne\n')
267+
with mock.patch.dict(os.environ, NPM_CONFIG_USERCONFIG=str(cfg)):
268+
test_run_a_node_hook(tempdir_factory, store)
269+
270+
263271
def test_run_a_ruby_hook(tempdir_factory, store):
264272
_test_hook_repo(
265273
tempdir_factory, store, 'ruby_hooks_repo',

0 commit comments

Comments
 (0)