mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #24469 from jfindlay/npm_env
correctly handle user environment info for npm
This commit is contained in:
commit
551e70f3fb
1 changed files with 25 additions and 2 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue