Clean cached NPM packages.

    If no path for a specific package is provided the entire cache will be cleared.

    path
        The cache subpath to delete, or None to clear the entire cache

    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.

    force
        Force cleaning of cache.  Required for npm@5 and greater

        .. versionadded:: 2016.11.6

    CLI Example:

    .. code-block:: bash

        salt '*' npm.cache_clean force=True

def cache_clean(path=None, runas=None, env=None, force=False):
    '''
    Clean cached NPM packages.

    If no path for a specific package is provided the entire cache will be cleared.

    path
        The cache subpath to delete, or None to clear the entire cache

    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.

    force
        Force cleaning of cache.  Required for npm@5 and greater

        .. versionadded:: 2016.11.6

    CLI Example:

    .. code-block:: bash

        salt '*' npm.cache_clean force=True

    '''
    env = env or {}

    if runas:
        uid = salt.utils.user.get_uid(runas)
        if uid:
            env.update({'SUDO_UID': uid, 'SUDO_USER': ''})

    cmd = ['npm', 'cache', 'clean']
    if path:
        cmd.append(path)
    if force is True:
        cmd.append('--force')

    cmd = ' '.join(cmd)
    result = __salt__['cmd.run_all'](
        cmd, cwd=None, runas=runas, env=env, python_shell=True, ignore_retcode=True)

    if result['retcode'] != 0:
        log.error(result['stderr'])
        return False
    return True