File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/npm.cpython-310.pyc
o
�N�gQ) � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddl m
Z
ddlmZ e�
e�ZddiZdd� Zd d
� Z dd
d�Zddd�Zddd�Zddd�Zddd�Zddd�ZdS )z
Manage and query NPM packages.
� N)�CommandExecutionError)�Version�list_�listc
C sV zt jj�d�durt� W dS W dS ty* } zdt| �fW Y d} ~ S d} ~ ww )z*
Only work when npm is installed.
�npmNT)FzTnpm execution module could not be loaded because the npm binary could not be locatedF)�salt�utils�path�which�_check_valid_versionr �str)�exc� r �D/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/npm.py�__virtual__ s ��r c C sR t jj�d�} t jjj| � d�dd�}t|�}td�}||k r'td� ||���dS )zs
Check the version of npm to ensure this module will work. Currently
npm must be at least version 1.2.
r z
--version�quiet)Zoutput_loglevelz1.2z4'npm' is not recent enough({} < {}). Please Upgrade.N)
r r r r
�modulesZcmdmod�runr r �format)Znpm_path�resZnpm_versionZ
valid_versionr r r r ( s ���r FTc
C s6 | r t �| �g}n|rdd� |D �}ng }|rt �|�}g d�}|r'|�d� |s3t�� } |�d� n|} |r@|�d|� d�� |rG|�d� |�|� |pOi }|rctjj� |�}
|
rc|�
|
d d
�� d�|�}td |d
| ||d�}|d dkrt
|d ��|d p�|d }ztjj�|�W S ty� | Y S w )a�
Install an NPM package.
If no directory is specified, the package will be installed globally. If
no package is specified, the dependencies (from package.json) of the
package in the given directory will be installed.
pkg
A package name in any format accepted by NPM, including a version
identifier
pkgs
A list of package names in the same format as the ``name`` parameter
.. versionadded:: 2014.7.0
dir
The target directory in which to install the package, or None for
global installation
runas
The user to run NPM with
registry
The NPM registry to install the package from.
.. versionadded:: 2014.7.0
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:: 2014.7.0
silent
Whether or not to run NPM install with --silent flag.
.. versionadded:: 2016.3.0
dry_run
Whether or not to run NPM install with --dry-run flag.
.. versionadded:: 2015.8.4
silent
Whether or not to run NPM install with --silent flag.
.. versionadded:: 2015.8.5
CLI Example:
.. code-block:: bash
salt '*' npm.install coffee-script
salt '*' npm.install coffee-script@1.0.1
c S s g | ]}t �|��qS r )�shlex�quote)�.0�vr r r �
<listcomp>� s zinstall.<locals>.<listcomp>)r �install�--json�--silent�--globalz--registry="�"z --dry-run� �ZSUDO_UIDZ SUDO_USER� �cmd.run_allT��python_shell�cwd�runas�env�retcoder �stderr�stdout)r r �append�tempfileZ
gettempdir�extendr r �user�get_uid�update�join�__salt__r �jsonZ find_json�
ValueError)
�pkgZpkgs�dirr'