Skip to content

Commit 3056619

Browse files
committed
fix language: node for hooks with build scripts and npm 11.x
1 parent 242ce8a commit 3056619

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎pre_commit/languages/node.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,8 @@ def install_environment(
9999
cmd_output_b(*cmd)
100100

101101
with in_env(prefix, version):
102-
install = ('npm', 'install', '--allow-git=root', '-g', *pkgs)
102+
install = (
103+
'npm', 'install', '--allow-git=root', '--install-links', '-g',
104+
*pkgs,
105+
)
103106
lang_base.setup_cmd(prefix, install)

‎tests/languages/node_test.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ def test_node_hook_versions(tmp_path, version):
158158
assert ret == (0, b'Hello World\n')
159159

160160

161+
def test_npm_install_succeeds_with_build(tmp_path):
162+
_make_hello_world(tmp_path)
163+
164+
with open(tmp_path.joinpath('package.json')) as f:
165+
contents = json.load(f)
166+
contents['scripts'] = {'build': 'echo hello hello'}
167+
with open(tmp_path.joinpath('package.json'), 'w') as f:
168+
json.dump(contents, f)
169+
_make_repo(tmp_path)
170+
171+
# node version chosen to be npm 11.19.0 with this particular bug
172+
ret = run_language(tmp_path, node, 'node-hello', version='26.7.0')
173+
assert ret == (0, b'Hello World\n')
174+
175+
161176
def test_node_additional_deps(tmp_path):
162177
_make_local_repo(str(tmp_path))
163178
ret, out = run_language(tmp_path, node, 'npm ls -g', deps=('lodash',))

0 commit comments

Comments
 (0)