mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Support lifecycle scripts for node
The `npm pack` runs lifecycle scripts which can spoil the standard output of the command and prevent correct parsing of the created tarball. For details see: https://docs.npmjs.com/cli/v8/using-npm/scripts#life-cycle-scripts Include a simple fix to parse out the tarball from the last line and cover the fix with a simple test. Signed-off-by: Miroslav Vadkerti <mvadkert@redhat.com>
This commit is contained in:
parent
0252908c27
commit
1cee8274a5
2 changed files with 17 additions and 3 deletions
|
|
@ -99,7 +99,7 @@ def install_environment(
|
||||||
lang_base.setup_cmd(prefix, local_install_cmd)
|
lang_base.setup_cmd(prefix, local_install_cmd)
|
||||||
|
|
||||||
_, pkg, _ = cmd_output('npm', 'pack', cwd=prefix.prefix_dir)
|
_, 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)
|
install = ('npm', 'install', '-g', pkg, *additional_dependencies)
|
||||||
lang_base.setup_cmd(prefix, install)
|
lang_base.setup_cmd(prefix, install)
|
||||||
|
|
|
||||||
|
|
@ -113,8 +113,8 @@ def test_installs_without_links_outside_env(tmpdir):
|
||||||
assert cmd_output('foo')[1] == 'success!\n'
|
assert cmd_output('foo')[1] == 'success!\n'
|
||||||
|
|
||||||
|
|
||||||
def _make_hello_world(tmp_path):
|
def _make_hello_world(tmp_path, package_json=None):
|
||||||
package_json = '''\
|
package_json = package_json or '''\
|
||||||
{"name": "t", "version": "0.0.1", "bin": {"node-hello": "./bin/main.js"}}
|
{"name": "t", "version": "0.0.1", "bin": {"node-hello": "./bin/main.js"}}
|
||||||
'''
|
'''
|
||||||
tmp_path.joinpath('package.json').write_text(package_json)
|
tmp_path.joinpath('package.json').write_text(package_json)
|
||||||
|
|
@ -132,6 +132,20 @@ def test_node_hook_system(tmp_path):
|
||||||
assert ret == (0, b'Hello World\n')
|
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):
|
def test_node_with_user_config_set(tmp_path):
|
||||||
cfg = tmp_path.joinpath('cfg')
|
cfg = tmp_path.joinpath('cfg')
|
||||||
cfg.write_text('cache=/dne\n')
|
cfg.write_text('cache=/dne\n')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue