HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/npm.cpython-310.pyc
o

�N�gQ)�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZ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
CsVztjj�d�durt�WdSWdSty*}zdt|�fWYd}~Sd}~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��rcCsRtjj�d�}tjjj|�d�dd�}t|�}td�}||kr'td�	||���dS)zs
    Check the version of npm to ensure this module will work. Currently
    npm must be at least version 1.2.
    rz
 --version�quiet)Zoutput_loglevelz1.2z4'npm' is not recent enough({} < {}). Please Upgrade.N)
rrr	r
�modulesZcmdmod�runrr�format)Znpm_path�resZnpm_versionZ
valid_versionrrrr(s���rFTc
Cs6|r	t�|�g}n|rdd�|D�}ng}|rt�|�}gd�}|r'|�d�|s3t��}	|�d�n|}	|r@|�d|�d��|rG|�d�|�|�|pOi}|rctjj�	|�}
|
rc|�
|
d	d
��d�|�}td|d
|	||d�}|ddkrt
|d��|dp�|d}ztjj�|�WSty�|YSw)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

    cSsg|]}t�|��qSr)�shlex�quote)�.0�vrrr�
<listcomp>�szinstall.<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)rr�append�tempfileZ
gettempdir�extendrr�user�get_uid�update�join�__salt__r�jsonZ	find_json�
ValueError)
�pkgZpkgs�dirr'�registryr(�dry_runZsilent�cmdr&�uid�resultZ
npm_outputrrrr>sHF





��rcCs�|rt�|�}|p
i}|rtjj�|�}|r|�|dd��ddd|�d�g}|s.|�d�d�|�}t	d|d	|||d
�}|ddkrMt
�|d
�dSd	S)a�
    Uninstall an NPM package.

    If no directory is specified, the package will be uninstalled globally.

    pkg
        A package name in any format accepted by NPM

    dir
        The target directory from which to uninstall the package, or None for
        global installation

    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

        salt '*' npm.uninstall coffee-script

    r r!r�	uninstallrrr"r#Tr$r)rr*F)rrrrr/r0r1r,r2r3�log�error)r6r7r'r(r;r:r<rrrr=�s$



�r=cCs�|pi}|rtjj�|�}|r|�|dd��gd�}|s"|�d�|durAt|ttf�s7tj	�
d|�d���|�dt|����|rQt�|�}|�d	|�d	��d
�
|�}td||||ddd
�}|ddkrr|drrt|d��tjj�|d��di�S)a�
    List installed NPM packages.

    If no directory is specified, this will return the list of globally-
    installed packages.

    pkg
        Limit package listing by name

    dir
        The directory whose packages will be listed, or None for global
        installation

    runas
        The user to run NPM with

        .. 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

    depth
        Limit the depth of the packages listed

        .. versionadded:: 2016.11.6,2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' npm.list

    r r!)rrrrrNz
Error: depth z must be a numberz--depth=rr"r#T�r&r'r(r%Zignore_retcoder)rr*r+Zdependencies)rrr/r0r1r,�
isinstance�int�float�
exceptionsZSaltInvocationErrorrrr2r3rr4�loads�get)r6r7r'r(�depthr;r:r<rrrr�s0&

�

�cCs�|pi}|rtjj�|�}|r|�|dd��gd�}|r"|�|�|dur+|�d�d�|�}td|d||ddd	�}|d
dkrKt�	|d�d
SdS)aw
    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

    r r!)r�cacheZcleanTz--forcer"r#Nr@r)rr*F)
rrr/r0r1r,r2r3r>r?)r	r'r(�forcer;r:r<rrr�cache_clean:s$


�rJcCs�|pi}|rtjj�|�}|r|�|dd��gd�}|r"|�|�d�|�}td|d||ddd�}|d	d
krC|drCt|d��|dS)
a�
    List NPM cached packages.

    If no path for a specific package is provided this will list all the cached packages.

    path
        The cache subpath to list, or None to list 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.

    CLI Example:

    .. code-block:: bash

        salt '*' npm.cache_clean

    r r!)rrHZlsr"r#NTr@r)rr*r+)	rrr/r0r1r,r2r3r)r	r'r(r;r:r<rrr�
cache_listos

�rKcCs^|pi}|rtjj�|�}|r|�|dd��d}td|d||ddd�}|�d�p.|�d	�S)
a_
    List path of the NPM cache directory.

    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.

    CLI Example:

    .. code-block:: bash

        salt '*' npm.cache_path

    r r!znpm config get cacher#NTr@r+r*)rrr/r0r1r3rF)r'r(r;r:r<rrr�
cache_path�s�rL)NNNNNNFT)NNN)NNNNN)NNNF)NN)�__doc__�loggingrr-Zsalt.modules.cmdmodrZsalt.utils.jsonZsalt.utils.pathZsalt.utils.userZsalt.exceptionsrZsalt.utils.versionsr�	getLogger�__name__r>Z__func_alias__rrrr=rrJrKrLrrrr�<module>s8

�
x
9
K
5.