Merge pull request #30308 from rallytime/bp-30257

Back-port #30257 to 2015.8
This commit is contained in:
Mike Place 2016-01-13 12:20:13 -07:00
commit 10b5728f84
3 changed files with 24 additions and 2 deletions

View file

@ -65,7 +65,8 @@ def install(pkg=None,
dir=None,
runas=None,
registry=None,
env=None):
env=None,
dry_run=False):
'''
Install an NPM package.
@ -101,6 +102,11 @@ def install(pkg=None,
.. versionadded:: 2014.7.0
dry_run
Whether or not to run NPM install with --dry-run flag.
.. versionadded::2015.8.4
CLI Example:
.. code-block:: bash
@ -129,6 +135,9 @@ def install(pkg=None,
if registry:
cmd.append(' --registry="{0}"'.format(registry))
if dry_run:
cmd.append('--dry-run')
if pkg:
cmd.append(pkg)
elif pkgs:

View file

@ -274,6 +274,18 @@ def bootstrap(name,
'''
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
if __opts__['test']:
try:
call = __salt__['npm.install'](dir=name, runas=user, pkg=None, dry_run=True)
except (CommandNotFoundError, CommandExecutionError) as err:
ret['result'] = False
ret['comment'] = 'Error Bootstrapping {0!r}: {1}'.format(name, err)
return ret
ret['result'] = None
ret['changes'] = {'old': [], 'new': call}
ret['comment'] = '{0} is set to be bootstrapped'.format(name)
return ret
try:
call = __salt__['npm.install'](dir=name, runas=user, pkg=None)
except (CommandNotFoundError, CommandExecutionError) as err:
@ -289,6 +301,7 @@ def bootstrap(name,
# npm.install will return a string if it can't parse a JSON result
if isinstance(call, str):
ret['result'] = False
ret['changes'] = call
ret['comment'] = 'Could not bootstrap directory'
else:
ret['result'] = True

View file

@ -22,7 +22,7 @@ ensure_in_syspath('../../')
from salt.states import npm
npm.__salt__ = {}
npm.__opts__ = {}
npm.__opts__ = {'test': False}
@skipIf(NO_MOCK, NO_MOCK_REASON)