Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pre_commit/languages/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def install_environment(
lang_base.setup_cmd(prefix, local_install_cmd)

_, pkg, _ = cmd_output('npm', 'pack', cwd=prefix.prefix_dir)
pkg = prefix.path(pkg.strip())
pkg = prefix.path(pkg.strip().split()[-1])

install = ('npm', 'install', '-g', pkg, *additional_dependencies)
lang_base.setup_cmd(prefix, install)
Expand Down
18 changes: 16 additions & 2 deletions tests/languages/node_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def test_installs_without_links_outside_env(tmpdir):
assert cmd_output('foo')[1] == 'success!\n'


def _make_hello_world(tmp_path):
package_json = '''\
def _make_hello_world(tmp_path, package_json=None):
package_json = package_json or '''\
Comment on lines -116 to +117
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than overload this function -- simply call it and then overwrite the output afterwards

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, if you prefer it that way, will do once I resolve the breakage

{"name": "t", "version": "0.0.1", "bin": {"node-hello": "./bin/main.js"}}
'''
tmp_path.joinpath('package.json').write_text(package_json)
Expand All @@ -132,6 +132,20 @@ def test_node_hook_system(tmp_path):
assert ret == (0, b'Hello World\n')


def test_node_with_prepare_script(tmp_path):
package_json = '''
{
"name": "t",
"version": "0.0.1",
"bin": {"node-hello": "./bin/main.js"},
"scripts": {"prepare": "echo prepare"}
}
'''
_make_hello_world(tmp_path, package_json)
ret = run_language(tmp_path, node, 'node-hello')
assert ret == (0, b'Hello World\n')


def test_node_with_user_config_set(tmp_path):
cfg = tmp_path.joinpath('cfg')
cfg.write_text('cache=/dne\n')
Expand Down