
    Vh-                         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
Z
d dlmZ d dlmZ d dlmZmZ  G d d	e      Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functiona	  
module: npm
short_description: Manage node.js packages with npm
description:
  - Manage node.js packages with Node Package Manager (npm).
author: "Chris Hoffman (@chrishoffman)"
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.
    type: str
    required: false
  path:
    description:
      - The base path where to install the node.js libraries.
    type: path
    required: false
  version:
    description:
      - The version to be installed.
    type: str
    required: false
  global:
    description:
      - Install the node.js library globally.
    required: false
    default: false
    type: bool
  executable:
    description:
      - The executable location for npm.
      - This is useful if you are using a version manager, such as nvm.
    type: path
    required: false
  ignore_scripts:
    description:
      - Use the C(--ignore-scripts) flag when installing.
    required: false
    type: bool
    default: false
  unsafe_perm:
    description:
      - Use the C(--unsafe-perm) flag when installing.
    type: bool
    default: false
  ci:
    description:
      - Install packages based on package-lock file, same as running C(npm ci).
    type: bool
    default: false
  production:
    description:
      - Install dependencies in production mode, excluding devDependencies.
    required: false
    type: bool
    default: false
  registry:
    description:
      - The registry to install modules from.
    required: false
    type: str
  state:
    description:
      - The state of the node.js library.
    required: false
    type: str
    default: present
    choices: ["present", "absent", "latest"]
  no_optional:
    description:
      - Use the C(--no-optional) flag when installing.
    type: bool
    default: false
    version_added: 2.0.0
  no_bin_links:
    description:
      - Use the C(--no-bin-links) flag when installing.
    type: bool
    default: false
    version_added: 2.5.0
  force:
    description:
      - Use the C(--force) flag when installing.
    type: bool
    default: false
    version_added: 9.5.0
requirements:
  - npm installed in bin path (recommended /usr/local/bin)
a  
- name: Install "coffee-script" node.js package.
  community.general.npm:
    name: coffee-script
    path: /app/location

- name: Install "coffee-script" node.js package on version 1.6.1.
  community.general.npm:
    name: coffee-script
    version: '1.6.1'
    path: /app/location

- name: Install "coffee-script" node.js package globally.
  community.general.npm:
    name: coffee-script
    global: true

- name: Force Install "coffee-script" node.js package.
  community.general.npm:
    name: coffee-script
    force: true

- name: Remove the globally package "coffee-script".
  community.general.npm:
    name: coffee-script
    global: true
    state: absent

- name: Install "coffee-script" node.js package from custom registry.
  community.general.npm:
    name: coffee-script
    registry: 'http://registry.mysite.com'

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

- name: Update packages based on package.json to their latest version.
  community.general.npm:
    path: /app/location
    state: latest

- name: Install packages based on package.json using the npm installed with nvm v0.10.1.
  community.general.npm:
    path: /app/location
    executable: /opt/nvm/v0.10.1/bin/npm
    state: present
N)AnsibleModule)	to_native)	CmdRunnercmd_runner_fmtc                   >    e Zd Zd Zd
dZd Zd Zd Zd Zd Z	d Z
y	)Npmc                    || _         |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d	   | _	        |d
   | _
        |d   | _        |d   | _        |d   r|d   j                  d      | _        n|j                  dd      g| _        |d   r,|d	   dk7  r$| j                  dz   t!        |d         z   | _        n| j                  | _        t%        || j                  t'        t)        j*                         t)        j,                  d      t)        j,                  d      t)        j,                  d      t)        j,                  d      t)        j*                         t)        j.                  d      t)        j,                  d      t)        j,                  d      t)        j,                  d      
            | _        y )Nglblnameversionpathregistry
productionignore_scriptsunsafe_permstateno_optionalno_bin_linksforce
executable npmTabsent@z--globalz--productionz--ignore-scriptsz--unsafe-permz
--registryz--no-optionalz--no-bin-linksz--force)
	exec_argsglobal_r   r   r   name_versionr   r   r   r   )commandarg_formats)moduler   r   r   r   r   r   r   r   r   r   r   r   splitr   get_bin_pathstrr    r   dictr	   as_listas_bool
as_opt_valrunner)selfr#   kwargss      i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/npm.py__init__zNpm.__init__   s   6N	6N	i(6N	z* .$%56!-0G_
!-0">2G_
,$\288=DO%225$?@DO)H!< $		C#fY6G2H HD $		DOO(002&..z:)11.A-556HI*22?C+335'22<@*22?C+334DE$,,Y7
    c                    | j                   j                  r| j                   j                  rS|rPd }| j                  rt        j                  j	                  | j                        st        j
                  | j                         t        j                  j                  | j                        s)| j                   j                  d| j                  z         | j                  }t        | j                   j                        }||d<   | j                  |d<   | j                  xr d|v xs
 d|v xs d|v |d<   |r| j                  nd |d	<   | j                  d
||      5 } |j                  di |\  }}	}
d d d        |	S y# 1 sw Y   	S xY w)Nzpath %s is not a directorymsgr   r   installupdatecir   r    zlexec_args global_ production ignore_scripts unsafe_perm name_version registry no_optional no_bin_links force)check_rccwd  )r#   
check_moder   osexistsmakedirsisdir	fail_jsonr'   paramsr   r   r    r+   run)r,   argsrun_in_check_moder7   add_package_namer8   rA   ctxrcouterrs              r.   _execz	Npm._exec   sR   {{%%$++*@*@EVCyyww~~dii0KK		*ww}}TYY/KK)).JTYY.V)Wii$++,,-F"&F; $		F9#'??#n	T8I8mXY]M]8maeimamF< :JT%6%6PTF>"~!s   1 &sww00C	1
 J1
 Js    FFc                    g d}t               }t               }i }	 t        j                  | j                  |ddd      xs d      }d|v r|d   j                         D ]|  \  }}d	|v r|d	   r|j                  |       !d
|v r|d
   r|j                  |       <|j                  |       d|v sR|d   sX|dz   t        |d         z   }|j                  |       ~ | j                  r)| j                  |vr|j                  | j                         ||fS |j                  | j                         ||fS # t	        t        dt
              $ r3}| j                  j                  dt        |      z         Y d }~4d }~ww xY w)N)listz--jsonz--longTFz{}JSONDecodeErrorz(Failed to parse NPM output with error %sr2   dependenciesmissinginvalidr   r   )rL   jsonloadsrJ   getattr
ValueErrorr#   r@   r   itemsappendr&   r    r   )	r,   cmd	installedrO   dataedeppropsdep_versions	            r.   rL   zNpm.list   s{   *F	&	a::djjdE5AITJD T!">288: 
6
U%%	*:NN3'%'E),<NN3'$$S) E)eI.>&)Ci#eI6F2G&G!((5
6   T%6%6i%Gtyy)
 '!! NN499%'!!) /< 	aKK!!&PS\]^S_&_!``	as   +D5 5F (E;;F c                 &    | j                  dg      S )Nr4   rJ   r,   s    r.   r4   zNpm.install	  s    zz9+&&r0   c                 &    | j                  dg      S )Nr6   r_   r`   s    r.   
ci_installzNpm.ci_install  s    zz4&!!r0   c                 &    | j                  dg      S )Nr5   r_   r`   s    r.   r5   z
Npm.update  s    zz8*%%r0   c                 &    | j                  dg      S )N	uninstallr_   r`   s    r.   re   zNpm.uninstall  s    zz;-((r0   c                     t               }| j                  dgdd      }|j                         D ]0  }|st        j                  d|d      \  }}|j                  |       2 |S )NoutdatedTFz\s|@   )rL   rJ   
splitlinesrer$   rV   )r,   rg   rY   r[   pkgothers         r.   list_outdatedzNpm.list_outdated  sa    6zz:,e4??$ 	%C  XXgsA6
U$	% r0   N)FTT)__name__
__module____qualname__r/   rJ   rL   r4   rb   r5   re   rm   r:   r0   r.   r   r      s+    (
T4"<'"&)
r0   r   c                     t        t        d      t        d      t        d      t        dd      t        d      t        d      t        dg d	      t        dd      t        dd      t        dd      t        dd      t        dd      t        dd      
      } t        dd      | d<   t        | dddgfgd      }|j                  d   }|j                  d   }|j                  d   }|j                  d   }|j                  d   }|s|s|j                  d       t	        ||||||j                  d   |j                  d   |j                  d   |j                  d   |j                  d   ||j                  d   |j                  d   |j                  d         }d}|j                  d   r|j                          d}n|dk(  r(|j                         \  }	}
|
rd}|j                          nz|dk(  rL|j                         \  }	}
|j                         }|
rd}|j                          |r<d}|j                          n)|j                         \  }	}
||	v rd}|j                          |j                  |       y ) Nr&   )typer   Fbool)defaultrr   present)ru   r   latest)rt   choices)r   r   r   r   r   r   r   r   r   r6   r   r   r   globalr   r   r   T)argument_specrequired_ifsupports_check_moder   z,path must be specified when not using globalr2   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r6   rv   )changed)r'   r   rA   r@   r   rb   rL   r4   rm   r5   re   	exit_json)arg_specr#   r   r   r   r   r   r   r|   rX   rO   rg   s               r.   mainr   "  s\   uv% F3V$5!9.MNE7V4F+V4%f55v.H e&9HXx&23 F == D== DmmI&G=="DMM'"EKL
f|4|4}}Z0#]]+;< --6 --6!==8MM'*,C G}}T	)	 XXZ	7GKKM	(	 XXZ	7$$&GKKMGJJL XXZ	79GMMO
W%r0   __main__)
__future__r   r   r   rr   __metaclass__DOCUMENTATIONEXAMPLESrQ   r<   rj   ansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   Eansible_collections.community.general.plugins.module_utils.cmd_runnerr   r	   objectr   r   rn   r:   r0   r.   <module>r      sb    A @_B/b  	 	 4 A ky& yxG&T zF r0   