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/states/__pycache__/npm.cpython-310.pyc
o

�N�gi,�@sRdZddlZddlmZmZdd�Z	ddd�Zdd	d
�Zddd
�Zddd�Z	dS)a�
Installation of NPM Packages
============================

These states manage the installed packages for node.js using the Node Package
Manager (npm). Note that npm must be installed for these states to be
available, so npm states should include a requisite to a pkg.installed state
for the package which provides npm (simply ``npm`` in most cases). Example:

.. code-block:: yaml

    npm:
      pkg.installed

    yaml:
      npm.installed:
        - require:
          - pkg: npm
�N)�CommandExecutionError�CommandNotFoundErrorcCsdtvrddfSddfS)z>
    Only load if the npm module is available in __salt__
    �npm.listZnpmFz 'npm' binary not found on system)�__salt__�rr�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/npm.py�__virtual__s
��rFc
s�|ddid�}|r|n|g}ztd|||dd�}	Wn$ttfy>}
zd|d<d	|�d
|
��|d<|WYd}
~
Sd}
~
wwdd
�|	��D�}	g}g}�fdd�}
|D]P}t�d|�}|�d�|�d�pfd�}|durs|�|�qT|
||	�s~|�|�qTd��|	�d�}|r�|	��	d�|kr�|�|�n|�|�qT|�|�qTt
dr�d|d<g}|r�|�d�d�|���g|d�|d<|r�|�d�d�|�d�|���d|d<d�|�|d<|S|s�d|d<d�d�|�d�|��|d<|Sz|||||d�}tdd!i|��}Wn&ttf�y0}
zd|d<d�d�|�|
�|d<|WYd}
~
Sd}
~
wwd|d<g|d�|d<d �d�|��|d<|S)"a�
    Verify that the given package is installed and is at the correct version
    (if specified).

    .. code-block:: yaml

        coffee-script:
          npm.installed:
            - user: someuser

        coffee-script@1.0.1:
          npm.installed: []

    name
        The package to install

        .. versionchanged:: 2014.7.2
            This parameter is no longer lowercased by salt so that
            case-sensitive NPM package names will work.

    pkgs
        A list of packages to install with a single npm invocation; specifying
        this argument will ignore the ``name`` argument

        .. versionadded:: 2014.7.0

    dir
        The target directory in which to install the package, or None for
        global installation

    user
        The user to run NPM with

        .. versionadded:: 0.17.0

    registry
        The NPM registry from which to install the package

        .. versionadded:: 2014.7.0

    env
        A list of environment variables to be set prior to execution. The
        format is the same as the :py:func:`cmd.run <salt.states.cmd.run>`.
        state function.

        .. versionadded:: 2014.7.0

    force_reinstall
        Install the package even if it is already installed
    N���name�result�comment�changesrr)�dir�runas�env�depthFrzError looking up '�': r
cSsi|]\}}||�qSrr)�.0�p�inforrr�
<dictcomp>dszinstalled.<locals>.<dictcomp>c	s��|vrd|�vrdSd�vrH|��D]3}z(|�dd��d�d}|�d�s0��d�r0|d7}��d�d|kr=WdSWqtyGYqwd	S)
av
        Helper function to determine if a package is installed

        This performs more complex comparison than just checking
        keys, such as examining source repos to see if the package
        was installed by a different name from the same repo

        :pkg str: The package to compare
        :installed_pkgs: A dictionary produced by npm list --json
        �versionTz://�fromr	�z.gitzgit://F)�values�get�split�endswith�
startswith�
IndexError)�pkg�installed_pkgsZpkg_detailsZpkg_from��pkg_namerr�_pkg_is_installedis��z$installed.<locals>._pkg_is_installedz^(@?[^@\s]+)(?:@(\S+))?r�Tz{}@{}r�testz+NPM package(s) '{}' are set to be installedz, ��old�newrzPackage(s) '{}' satisfied by {}z. )rr�registryr�pkgs�npm.installzError installing '{}': {}z&Package(s) '{}' successfully installedr)rrr�items�re�search�group�append�formatr�__opts__�join)rr,r�userZforce_reinstallr+r�retZpkg_listr"�errZpkgs_satisfiedZpkgs_to_installr%r!�matchesZpkg_verZinstalled_name_verZcomment_msgZcmd_args�callrr#r�	installed$s�5��


�

���������r;c
Cs
|ddid�}z
td|dd�}Wn$ttfy5}zd|d<d	|�d
|��|d<|WYd}~Sd}~ww||vrHd|d<d
|�d�|d<|StdrZd|d<d
|�d�|d<|Std|||d�rwd|d<d|d|<d
|�d�|d<|Sd|d<d|�d�|d<|S)z�
    Verify that the given package is not installed.

    dir
        The target directory in which to install the package, or None for
        global installation

    user
        The user to run NPM with

        .. versionadded:: 0.17.0
    Nr	r
rr)rrFrzError uninstalling 'rr
Tz	Package 'z' is not installedr'z' is set to be removedz
npm.uninstall)r!rr�Removedrz' was successfully removedzError removing package '�')rrrr4)rrr6r7r"r8rrr�removed�s2
���r>Tc
Cs~|ddid�}tdr_z0td||d|dd�}|r.d|d<g|d	�|d
<|�d�|d<W|Sd|d<|�d
�|d<W|Sttfy^}zd|d<d|�d|��|d<WYd}~|Sd}~wwztd||d|d�}Wn$ttfy�}zd|d<d|�d|��|d<|WYd}~Sd}~ww|s�d|d<d|d<|St|t�r�d|d<||d
<d|d<|Sd|d<|di|d
<d|d<|S)z�
    Bootstraps a node.js application.

    Will execute 'npm install --json' on the specified directory.

    user
        The user to run NPM with

        .. versionadded:: 0.17.0
    Nr	r
r'r-T)rrr!�silent�dry_runrr(rz is set to be bootstrappedr
z is already bootstrappedFzError Bootstrapping 'r)rrr!r?z!Directory is already bootstrappedzCould not bootstrap directoryZBootstrappedz'Directory was successfully bootstrapped)r4rrr�
isinstance�str)rr6r?r7r:r8rrr�	bootstrap	sR
�������
�rCc	
CsB|ddid�}d}z
td||d�}Wn$ttfy7}zd|d<d�|p&d	|�|d
<|WYd}~Sd}~ww|r`tdd|d�}|d}|�d|�d�}||vr`d
|d<d|�d�|d
<|Stdrsd|d<d�|pmd	�|d
<|Std||d�r�d
|d<d|d|p�d<d�|p�d	�|d
<|Sd|d<d�|p�d	�|d
<|S)az
    Ensure that the given package is not cached.

    If no package is specified, this ensures the entire cache is cleared.

    name
        The name of the package to remove from the cache, or None for all packages

    user
        The user to run NPM with

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

        .. versionadded:: 2016.11.6
    Nr	r
znpm.cache_list)�pathrFrzError looking up cached {}: {}Zpackagesr
r�/TzPackage z is not in the cacher'zCached {} set to be removedznpm.cache_cleanr<r�cachezCached {} successfully removedzError cleaning cached {})rrrr3r4)	rr6�forcer7Zspecific_pkgZcached_pkgsr8Zall_cached_pkgsZcache_root_pathrrr�
cache_cleaned@s@����rH)NNNFNN)NN)NT)NNF)
�__doc__r/Zsalt.exceptionsrrrr;r>rCrHrrrr�<module>s
�
;
+7