Merge pull request #24469 from jfindlay/npm_env

correctly handle user environment info for npm
This commit is contained in:
Thomas S Hatch 2015-06-08 09:26:02 -06:00
commit 551e70f3fb

View file

@ -119,6 +119,11 @@ def install(pkg=None,
elif pkgs:
cmd += ' "{0}"'.format('" "'.join(pkgs))
if runas:
uid = salt.utils.get_uid(runas)
if uid:
env.update({'SUDO_UID': uid, 'SUDO_USER': ''})
result = __salt__['cmd.run_all'](cmd, python_shell=False, cwd=dir, runas=runas, env=env)
if result['retcode'] != 0:
@ -151,7 +156,8 @@ def install(pkg=None,
def uninstall(pkg,
dir=None,
runas=None):
runas=None,
env=None):
'''
Uninstall an NPM package.
@ -167,6 +173,13 @@ def uninstall(pkg,
runas
The user to run NPM with
env
Environment variables to set when invoking npm. Uses the same ``env``
format as the :py:func:`cmd.run <salt.modules.cmdmod.run>` execution
function.
.. versionadded:: 2015.5.3
CLI Example:
.. code-block:: bash
@ -175,6 +188,11 @@ def uninstall(pkg,
'''
if runas:
uid = salt.utils.get_uid(runas)
if uid:
env.update({'SUDO_UID': uid, 'SUDO_USER': ''})
cmd = 'npm uninstall'
if dir is None:
@ -182,7 +200,7 @@ def uninstall(pkg,
cmd += ' "{0}"'.format(pkg)
result = __salt__['cmd.run_all'](cmd, python_shell=False, cwd=dir, runas=runas)
result = __salt__['cmd.run_all'](cmd, python_shell=False, cwd=dir, runas=runas, env=env)
if result['retcode'] != 0:
log.error(result['stderr'])
@ -227,6 +245,11 @@ def list_(pkg=None,
'''
if runas:
uid = salt.utils.get_uid(runas)
if uid:
env.update({'SUDO_UID': uid, 'SUDO_USER': ''})
cmd = 'npm list --silent --json'
if dir is None: