
    Vh0                     z    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
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: yarn
short_description: Manage Node.js packages with Yarn
description:
  - Manage Node.js packages with the Yarn package manager U(https://yarnpkg.com/).
  - Note that at the moment, this module B(only works with Yarn Classic).
author:
  - "David Gunter (@verkaufer)"
  - "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:
    type: str
    description:
      - The name of a Node.js library to install.
      - If omitted all packages in package.json are installed.
      - To globally install from local Node.js library. Prepend C(file:) to the path of the Node.js library.
    required: false
  path:
    type: path
    description:
      - The base path where Node.js installs libraries.
      - This is where the C(node_modules) folder lives.
    required: false
  version:
    type: str
    description:
      - The version of the library to be installed.
      - Must be in semver format. If "latest" is desired, use O(state) arg instead.
    required: false
  global:
    description:
      - Install the Node.js library globally.
    required: false
    default: false
    type: bool
  executable:
    type: path
    description:
      - The executable location for yarn.
    required: false
  ignore_scripts:
    description:
      - Use the C(--ignore-scripts) flag when installing.
    required: false
    type: bool
    default: false
  production:
    description:
      - Install dependencies in production mode.
      - C(yarn) ignores any dependencies under devDependencies in C(package.json).
    required: false
    type: bool
    default: false
  registry:
    type: str
    description:
      - The registry to install modules from.
    required: false
  state:
    type: str
    description:
      - Installation state of the named Node.js library.
      - If V(absent) is selected, a O(name) option must be provided.
    required: false
    default: present
    choices: ["present", "absent", "latest"]
requirements:
  - Yarn Classic installed in bin path (typically C(/usr/local/bin))
a  
- name: Install "imagemin" Node.js package.
  community.general.yarn:
    name: imagemin
    path: /app/location

- name: Install "imagemin" Node.js package on version 5.3.1
  community.general.yarn:
    name: imagemin
    version: '5.3.1'
    path: /app/location

- name: Install "imagemin" Node.js package globally.
  community.general.yarn:
    name: imagemin
    global: true

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

- name: Install "imagemin" Node.js package from custom registry.
  community.general.yarn:
    name: imagemin
    registry: 'http://registry.mysite.com'

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

- name: Update all packages in package.json to their latest version.
  community.general.yarn:
    path: /app/location
    state: latest
a7  
out:
  description: Output generated from Yarn.
  returned: always
  type: str
  sample: "yarn add v0.16.1[1/4] Resolving packages...[2/4] Fetching packages...[3/4] Linking dependencies...[4/4] Building
    fresh packages...success Saved lockfile.success Saved 1 new dependency..left-pad@1.1.3 Done in 0.59s."
N)AnsibleModulec                   >    e Zd Zd Zd
dZd Zd Zd Zd Zd Z	d Z
y	)Yarnc                 t   || _         |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        d | _	        |d   r7| j                  +| j                  d	z   t        | j                        z   | _	        y | j                  | j                  | _	        y y )
Ngloballynameversionpathregistry
productionignore_scripts
executable@)moduler
   r   r   r   r   r   r   r   name_versionstr)selfr   kwargss      j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/yarn.py__init__zYarn.__init__   s    z*6N	i(6N	z* .$%56 . !)!6 $		C#dll2C CDYY" $		D #    c                 2   | j                   j                  r| j                   j                  r|r| j                  xr | }|r|j                  dd       | j                  |z   }| j
                  r|j                  d       | j                  r|j                  d       | j                  r,|j                  d       |j                  | j                         d }| j                  r|s	t        j                  j                  | j                        st        j                  | j                         t        j                  j                  | j                        s)| j                   j                  d| j                  z         | j                  }t        j                  j                  t        j                  j!                  | j                  d            s| j                   j                  d	       | j                   j#                  |||
      \  }}	}
|	|
fS y)Nr   globalz--productionz--ignore-scriptsz
--registryz#Path provided %s is not a directorymsgzpackage.jsonz-Package.json does not exist in provided path.)check_rccwd)NN)r   
check_moder
   insertr   r   appendr   r   r   osexistsmakedirsisdir	fail_jsonisfilejoinrun_command)r   argsrun_in_check_moder   unsupported_with_globalwith_global_argcmdr    rcouterrs              r   _execz
Yarn._exec   st   {{%%$++*@*@EV"mmK4K0KOAx(//D(C

>*""

-.}}

<(

4==) Cyyww~~dii0KK		*ww}}TYY/KK)).SVZV_V_._)`iiww~~bggll499n&MNKK)).])^;;223s2SLBS8Or   c                     	 |j                         D ]:  }t        j                  |      d   dk(  s| j                  j	                  |       < y # t
        $ r# | j                  j	                  d|z  |       Y y w xY w)Ntypeerrorr   z&Unexpected stderr output from Yarn: %s)r   stderr)
splitlinesjsonloadsr   r(   	Exception)r   r3   lines      r   _process_yarn_errorzYarn._process_yarn_error   s{    	b( 3::d#F+w6KK))c)23  	bKK!!&NQT&T]`!a	bs   .A A )A<;A<c                    g d}t               }t               }t        j                  j                  t        j                  j	                  | j                  d            s|j                  | j                         ||fS | j                  |ddd      \  }}| j                  |       |j                         j                  d      D ]X  }t        j                  |      }|d   dk(  s!|d	   d
   }|D ]+  }	|	d   j                  dd      \  }
}|j                  |
       - Z | j                  |vr|j                  | j                         ||fS )N)listz	--depth=0--json	yarn.lockTF)r-   r   r.   
r6   treedatatreesr   r      )r@   r$   r   r)   r*   r#   r   r4   r>   stripsplitr:   r;   rsplit)r   r0   	installedmissingresultr7   	json_linerE   dependenciesdepr   r   s               r   r@   z	Yarn.list   s&   -F	&ww~~bggll499kBCNN499%g%% 

3$hl
m  '--d3 	+I::i(DF|v%#F|G4' +C$'K$6$6sA$>MD'$$T*+	+ 99I%NN499%'!!r   c                 z    | j                   r| j                  d| j                   g      S | j                  ddg      S )Naddinstallz--non-interactive)r   r4   r   s    r   rS   zYarn.install   s:    ::ud&7&7899zz9&9:;;r   c                 (    | j                  ddg      S )Nupgradez--latest)r4   rT   s    r   updatezYarn.update   s    zz9j122r   c                 <    | j                  d| j                  g      S )Nremove)r4   r   rT   s    r   	uninstallzYarn.uninstall   s    zz8TYY/00r   c                    t               }t        j                  j                  t        j                  j	                  | j                  d            s|S | j                  ddgddd      \  }}| j                  |       |s|S |j                         d   }t        j                  |      }	 |d   d	   }|D ]  }|j                  |d
           |S # t        $ r |cY S w xY w)NrB   outdatedrA   TF)r.   rG   rE   bodyr   )r@   r$   r   r)   r*   r4   r>   r9   r:   r;   KeyErrorr#   )r   r\   
cmd_resultr3   outdated_packages_datarE   outdated_dependenciesrP   s           r   list_outdatedzYarn.list_outdated   s    6ww~~bggll499kBCO**j(%;T5bf*g
C 	  %O!+!6!6!8!;zz01	$(L$8! ) 	$C OOCF#	$   	O	s   ,C CCN)FTF)__name__
__module____qualname__r   r4   r>   r@   rS   rW   rZ   rb    r   r   r   r      s,    *&#Jb"<<31r   r   c                     t        t        d       t        d d      t        d       t        dd      t        d d      t        d       t        dg d      t        dd      	      } t        dd      | d
<   t        | d      }|j                  d   }|j                  d   }|j                  d   }|j                  d
   }|j                  d   }|j                  d   }|j                  d   }|j                  d   }	||du r|j                  d       n|r|du r|j                  d       |dk(  r|s|j                  d       |dk(  rd}|j                  d   r|j                  d   j	                  d      }
n|j                  dd      g}
|r,|j                  |
d
dgz   d      \  }}}|j                         }t        |||||||
||		      }d}d}d}|dk(  rL|sd}|j                         \  }}n|j                         \  }}t        |      rd}|j                         \  }}n|dk(  r||sd}|j                         \  }}n|j                         \  }}|j                         }t        |      rd}|j                         \  }}t        |      rBd}|j                         \  }}n,|j                         \  }}||v rd}|j                         \  }}|j                  |||        y )!N)defaultr   )rh   r6   Fboolpresent)rj   absentlatest)rh   choices)r   r   r   r   r   r   stater   r   T)argument_specsupports_check_moder   r   r   r   rn   r   z0Path must be specified when not using global argr   z0Cannot specify path if doing global installationrk   z3Package must be explicitly named when uninstalling.rl   r    yarndir)r   )r   r   r   r
   r   r   r   r    )changedr2   r3   )dictr   paramsr(   rI   get_bin_pathr+   rH   r   rS   r@   lenrb   rW   rZ   	exit_json)arg_specr   r   r   r   r
   r   r   rn   r   r   _rcr2   _errrr   ru   r3   rK   rL   r\   s                       r   mainr~     s   $$V,T"F362d#9.MNE7	H e&9HX F
 == D== DmmI&G}}X&H|,J}}Z(HMM'"E]]#34N |E)OP	(d"OPRS}}\"]]<066s;
))&$78
 ++J(E9J,JUY+ZS$yy{!%%!-/D G
C
C	G||~HC!%Iw7|<<>S	(	G||~HC!%Iw))+H7|<<>S8};;=S "YY[	79G~~'HC
W#37r   __main__)
__future__r   r   r   r6   __metaclass__DOCUMENTATIONEXAMPLESRETURNr$   r:   ansible.module_utils.basicr   objectr   r~   rc   rf   r   r   <module>r      s`    A @KZ$L
 
  4I6 IX]8@ zF r   