
    Vh26                         d dl mZmZmZ eZdZdZd dlZd dl	Z	d dl
mZ d dlmZ  G d de      Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona~	  
module: pnpm
short_description: Manage Node.js packages with C(pnpm)
version_added: 7.4.0
description:
  - Manage Node.js packages with the L(pnpm package manager, https://pnpm.io/).
author:
  - "Aritra Sen (@aretrosen)"
  - "Chris Hoffman (@chrishoffman), creator of NPM Ansible module"
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  name:
    description:
      - The name of a Node.js library to install.
      - All packages in C(package.json) are installed if not provided.
    type: str
    required: false
  alias:
    description:
      - Alias of the Node.js library.
    type: str
    required: false
  path:
    description:
      - The base path to install the Node.js libraries.
    type: path
    required: false
  version:
    description:
      - The version of the library to be installed, in semver format.
    type: str
    required: false
  global:
    description:
      - Install the Node.js library globally.
    required: false
    default: false
    type: bool
  executable:
    description:
      - The executable location for pnpm.
      - The default location it searches for is E(PATH), fails if not set.
    type: path
    required: false
  ignore_scripts:
    description:
      - Use the C(--ignore-scripts) flag when installing.
    required: false
    type: bool
    default: false
  no_optional:
    description:
      - Do not install optional packages, equivalent to C(--no-optional).
    required: false
    type: bool
    default: false
  production:
    description:
      - Install dependencies in production mode.
      - Pnpm will ignore any dependencies under C(devDependencies) in package.json.
    required: false
    type: bool
    default: false
  dev:
    description:
      - Install dependencies in development mode.
      - Pnpm will ignore any regular dependencies in C(package.json).
    required: false
    default: false
    type: bool
  optional:
    description:
      - Install dependencies in optional mode.
    required: false
    default: false
    type: bool
  state:
    description:
      - Installation state of the named Node.js library.
      - If V(absent) is selected, a name option must be provided.
    type: str
    required: false
    default: present
    choices: ["present", "absent", "latest"]
requirements:
  - Pnpm executable present in E(PATH).
a  
- name: Install "tailwindcss" Node.js package.
  community.general.pnpm:
    name: tailwindcss
    path: /app/location

- name: Install "tailwindcss" Node.js package on version 3.3.2
  community.general.pnpm:
    name: tailwindcss
    version: 3.3.2
    path: /app/location

- name: Install "tailwindcss" Node.js package globally.
  community.general.pnpm:
    name: tailwindcss
    global: true

- name: Install "tailwindcss" Node.js package as dev dependency.
  community.general.pnpm:
    name: tailwindcss
    path: /app/location
    dev: true

- name: Install "tailwindcss" Node.js package as optional dependency.
  community.general.pnpm:
    name: tailwindcss
    path: /app/location
    optional: true

- name: Install "tailwindcss" Node.js package version 0.1.3 as tailwind-1
  community.general.pnpm:
    name: tailwindcss
    alias: tailwind-1
    version: 0.1.3
    path: /app/location

- name: Remove the globally-installed package "tailwindcss".
  community.general.pnpm:
    name: tailwindcss
    global: true
    state: absent

- name: Install packages based on package.json.
  community.general.pnpm:
    path: /app/location

- name: Update all packages in package.json to their latest version.
  community.general.pnpm:
    path: /app/location
    state: latest
N)AnsibleModule)	to_nativec                   8    e Zd Zd Zd	dZd Zd Zd Zd Zd Z	y)
Pnpmc                 0   || _         |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d	   | _	        |d
   | _
        |d   | _        d | _        | j                  | j                  dz   | _        | j                  n| j                  xs d| j                  z   | _        | j                  +| j                  dz   t        | j                        z   | _        y | j                  dz   | _        y y )Nnamealiasversionpathglobally
executableignore_scriptsno_optional
productiondevoptionalz@npm: @z@latest)moduler   r   r   r   r   r   r   r   r   r   r   alias_name_verstr)selfr   kwargss      j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/pnpm.py__init__zPnpm.__init__   s   6N	G_
i(6N	z* .$%56!-0 .%=z*"::!"&**w"6D99 #'#6#6#<"		"ID||'&*&9&9C&?#dllBS&S#&*&9&9I&E# !    c                    | j                   j                  r| j                   j                  r|r| j                  |z   }| j                  r|j	                  d       | j
                  r|j	                  d       | j                  r|j	                  d       | j                  r|j	                  d       | j                  r|j	                  d       | j                  r| j                  r|j	                  d       d }| j                  rt        j                  j                  | j                        st        j                  | j                         t        j                  j                  | j                        s)| j                   j!                  d| j                  z         | j"                  sct        j                  j%                  t        j                  j'                  | j                  d	            s| j                   j!                  d
       | j                  }| j                   j)                  |||      \  }}}||fS y)N-gz--ignore-scriptsz--no-optionalz-Pz-Dz-OzPath %s is not a directorymsgzpackage.jsonz,package.json does not exist in provided path)check_rccwd)NN)r   
check_moder   r   appendr   r   r   r   r   r   r   osexistsmakedirsisdir	fail_jsonr   isfilejoinrun_command)	r   argsrun_in_check_moder$   cmdr%   _rcouterrs	            r   _execz
Pnpm._exec   s   {{%%$++*@*@EV//D(C}}

4 ""

-.

?+

4 xx

4 yyT]]

4  Cyyww~~dii0KK		*ww}}TYY/KK)).JTYY.V)W**277>>GGLLN;4 KK))J *  ii KK33C(PS3TMCc8Or   c                    t         j                  j                  t         j                  j                  | j                  d            syddg}| j                  |j                  | j                         	 | j                  |dd      \  }}||dk7  rt        |      t        j                  |      }d	v ry|d
   }dD ]  }||vr||   j                         D ]f  \  }}| j                  | j                  |k7  r"| j                  |d   n|}	| j                  |	k7  rE| j                  | j                  |d   k(  r  y   y# t        $ r2}| j                  j                  dt        |      z         Y d }~d }~ww xY w)Npnpm-lock.yamlTlistz--jsonFr   )Failed to parse pnpm output with error %sr"   errorr   )dependenciesdevDependenciesoptionalDependenciesunsavedDependenciesfromr   )r(   r   r-   r.   r   r'   r6   	Exceptionjsonloadsr   r,   r   itemsr   r   )
r   r2   r4   r5   dataetypedepdeppropr   s
             r   missingzPnpm.missing   sw   ww~~bggll4996FGHx 99 JJtyy!		zz#tU3HC3"9n$::c?D d?Aw
 	G d"!']002 	T::)djjC.?'+zz'=tF|399$<<'4<<4	?+J 	, A  	KK!!?)A,N "  	s   5=E 	F (E;;F c                 x    | j                   | j                  d| j                   g      S | j                  dg      S )Naddinstall)r   r6   r   s    r   rM   zPnpm.install!  s9    *::ud&9&9:;;zz9+&&r   c                 (    | j                  ddg      S )Nupdatez--latest)r6   rN   s    r   rP   zPnpm.update&  s    zz8Z011r   c                     | j                   | j                  d| j                   g      S | j                  d| j                  g      S )Nremove)r   r6   r   rN   s    r   	uninstallzPnpm.uninstall)  s<    ::!::x455zz8TYY/00r   c                    t         j                  j                  t         j                  j                  | j                  d            s
t	               S g d}	 | j                  |dd      \  }}||dk7  rt        |      |j                  d      }d }|D ]@  }t        |      dkD  r|d   dk(  r|}t        |      dkD  r|d   dk(  r||z  } n
|<||z  }B t        j                  |      }|j                         S # t        $ rA}| j                  j                  d	t        |      z  
       Y d }~j                         S d }~ww xY w)Nr8   )outdatedz--formatrB   TFr   r   {}r:   r"   )r(   r   r-   r.   r9   r6   rA   
splitlineslenrB   rC   r   r,   r   keys)r   r2   r4   r5   
data_lineslinerE   rF   s           r   list_outdatedzPnpm.list_outdated.  s9   ww~~bggll4996FGH6M.	zz#tU3HC 3"9n$ -JC" 
 t9q=T!W^Ct9q=T!W^4KC?4KC
  ::c?D yy{  	KK!!?)A,N "   yy{	s   A8C< C< <	E(EEN)FT)
__name__
__module____qualname__r   r6   rJ   rM   rP   rS   r]    r   r   r	   r	      s(    F4+Z/b'
21
#r   r	   c                     t        t        d       t        d       t        d d      t        d       t        d d      t        dd      t        dd      t        dd      t        dd      t        dd      t        dg d      	      } t        dd      | d
<   t        | d      }|j                  d   }|j                  d   }|j                  d   }|j                  d   }|j                  d
   }|j                  d   }|j                  d   }|j                  d   }	|j                  d   }
|j                  d   }|j                  d   }|j                  d   r|j                  d   j                  d      }n|j	                  dd      g}|||j                  d       |||j                  d       ||s|j                  d       n||r|j                  d       |r|	s|
s|r|j                  d       |||r|j                  d       |	r|
r|r|j                  d        |	r|
r|j                  d!       |	r|r|j                  d"       |
r|r|j                  d#       ||d$d% d&k(  r||j                  d'       ||r|j                  d(       |d)k(  r||j                  d*       |rL|j                  |d+d,gz   d-      \  }}}t        j                  j                  |j                               \  }}t        ||||||||||	|
|.      }d}d/}d/}|dk(  r&|j                         rd}|j                         \  }}n|d0k(  r]|j                         }|*|j                         s||v r\d}|j                         \  }}nFt        |      r;d}|j                         \  }}n%|j                         sd}|j!                         \  }}|j#                  |||1       y )2N)defaultr   )rc   typeFboolpresent)rf   absentlatest)rc   choices)r   r   r   r   r   r   r   r   r   r   stateglobalT)argument_specsupports_check_moder   r   r   r   r   r   r   r   rj   r    pnpmz0version is meaningless when name is not providedr"   z.alias is meaningless when name is not providedz,path must be specified when not using globalz2Cannot specify path when doing global installationzVOptions production, dev, and optional is meaningless when installing packages globallyz5path should not be mentioned when installing globallyz9Options production and dev and optional don't go togetherz,Options production and dev don't go togetherz1Options production and optional don't go togetherz*Options dev and optional don't go togetherr      httpz,Semver not supported on remote url downloadszNOptional not available when package name not provided, use no_optional insteadrg   z)Package name is required for uninstallingrootr!   )r$   )r   r   r   r   r   r   r   r   r   r   r   r   rh   )changedr4   r5   )dictr   paramssplitget_bin_pathr,   r/   r(   r   stripr	   rJ   rM   r]   rY   rP   rS   	exit_json)arg_specr   r   r   r   r   r   r   r   r   r   r   rj   r   r3   r4   _err_tailro   rs   r5   rU   s                         r   mainr}   T  s   $4 $V,T"62E7V4F3V,e&19.MNH e&9HXtLF== DMM'"E== DmmI&G}}X&H]]#34N--.K|,J
--
C}}Z(HMM'"E}}\"]]<066s;
))&$78
|+OP|)MN|HKL		hQRZ3(h 	 	
 D,TUchK 	 	
 cKLhPQ
xIJD1I/G4GKL|` 	 	
 T\HI++J&$,GRV+WS$ggmmCIIK0e%D G
C
C	<<>G||~HC	(	%%'||~!1<<>S]G{{}HC||~G~~'HC
W#37r   __main__)
__future__r   r   r   rd   __metaclass__DOCUMENTATIONEXAMPLESrB   r(   ansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   objectr	   r}   r^   ra   r   r   <module>r      s\    A @\|2h  	 4 Ai6 iXv8r zF r   