collection 교체

This commit is contained in:
정훈 변
2024-02-23 16:37:40 +09:00
parent b494779b5b
commit 3fd554eee9
38862 changed files with 220204 additions and 6600073 deletions

View File

@@ -1,7 +1,8 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2017 Chris Hoffman <christopher.hoffman@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
@@ -14,6 +15,13 @@ 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:
@@ -34,7 +42,7 @@ options:
description:
- Install the node.js library globally.
required: false
default: no
default: false
type: bool
executable:
description:
@@ -47,23 +55,23 @@ options:
- Use the C(--ignore-scripts) flag when installing.
required: false
type: bool
default: no
default: false
unsafe_perm:
description:
- Use the C(--unsafe-perm) flag when installing.
type: bool
default: no
default: false
ci:
description:
- Install packages based on package-lock file, same as running C(npm ci).
type: bool
default: no
default: false
production:
description:
- Install dependencies in production mode, excluding devDependencies.
required: false
type: bool
default: no
default: false
registry:
description:
- The registry to install modules from.
@@ -80,13 +88,13 @@ options:
description:
- Use the C(--no-optional) flag when installing.
type: bool
default: no
default: false
version_added: 2.0.0
no_bin_links:
description:
- Use the C(--no-bin-links) flag when installing.
type: bool
default: no
default: false
version_added: 2.5.0
requirements:
- npm installed in bin path (recommended /usr/local/bin)
@@ -107,12 +115,12 @@ EXAMPLES = r'''
- name: Install "coffee-script" node.js package globally.
community.general.npm:
name: coffee-script
global: yes
global: true
- name: Remove the globally package "coffee-script".
community.general.npm:
name: coffee-script
global: yes
global: true
state: absent
- name: Install "coffee-script" node.js package from custom registry.
@@ -142,6 +150,7 @@ import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt
class Npm(object):
@@ -164,33 +173,29 @@ class Npm(object):
else:
self.executable = [module.get_bin_path('npm', True)]
if kwargs['version'] and self.state != 'absent':
self.name_version = self.name + '@' + str(self.version)
if kwargs['version'] and kwargs['state'] != 'absent':
self.name_version = self.name + '@' + str(kwargs['version'])
else:
self.name_version = self.name
self.runner = CmdRunner(
module,
command=self.executable,
arg_formats=dict(
exec_args=cmd_runner_fmt.as_list(),
global_=cmd_runner_fmt.as_bool('--global'),
production=cmd_runner_fmt.as_bool('--production'),
ignore_scripts=cmd_runner_fmt.as_bool('--ignore-scripts'),
unsafe_perm=cmd_runner_fmt.as_bool('--unsafe-perm'),
name_version=cmd_runner_fmt.as_list(),
registry=cmd_runner_fmt.as_opt_val('--registry'),
no_optional=cmd_runner_fmt.as_bool('--no-optional'),
no_bin_links=cmd_runner_fmt.as_bool('--no-bin-links'),
)
)
def _exec(self, args, run_in_check_mode=False, check_rc=True, add_package_name=True):
if not self.module.check_mode or (self.module.check_mode and run_in_check_mode):
cmd = self.executable + args
if self.glbl:
cmd.append('--global')
if self.production and ('install' in cmd or 'update' in cmd or 'ci' in cmd):
cmd.append('--production')
if self.ignore_scripts:
cmd.append('--ignore-scripts')
if self.unsafe_perm:
cmd.append('--unsafe-perm')
if self.name_version and add_package_name:
cmd.append(self.name_version)
if self.registry:
cmd.append('--registry')
cmd.append(self.registry)
if self.no_optional:
cmd.append('--no-optional')
if self.no_bin_links:
cmd.append('--no-bin-links')
# If path is specified, cd into that path and run the command.
cwd = None
if self.path:
@@ -200,8 +205,19 @@ class Npm(object):
self.module.fail_json(msg="path %s is not a directory" % self.path)
cwd = self.path
rc, out, err = self.module.run_command(cmd, check_rc=check_rc, cwd=cwd)
params = dict(self.module.params)
params['exec_args'] = args
params['global_'] = self.glbl
params['production'] = self.production and ('install' in args or 'update' in args or 'ci' in args)
params['name_version'] = self.name_version if add_package_name else None
with self.runner(
"exec_args global_ production ignore_scripts unsafe_perm name_version registry no_optional no_bin_links",
check_rc=check_rc, cwd=cwd
) as ctx:
rc, out, err = ctx.run(**params)
return out
return ''
def list(self):
@@ -261,12 +277,12 @@ class Npm(object):
def main():
arg_spec = dict(
name=dict(default=None, type='str'),
path=dict(default=None, type='path'),
version=dict(default=None, type='str'),
name=dict(type='str'),
path=dict(type='path'),
version=dict(type='str'),
production=dict(default=False, type='bool'),
executable=dict(default=None, type='path'),
registry=dict(default=None, type='str'),
executable=dict(type='path'),
registry=dict(type='str'),
state=dict(default='present', choices=['present', 'absent', 'latest']),
ignore_scripts=dict(default=False, type='bool'),
unsafe_perm=dict(default=False, type='bool'),
@@ -277,34 +293,35 @@ def main():
arg_spec['global'] = dict(default=False, type='bool')
module = AnsibleModule(
argument_spec=arg_spec,
supports_check_mode=True
required_if=[('state', 'absent', ['name'])],
supports_check_mode=True,
)
name = module.params['name']
path = module.params['path']
version = module.params['version']
glbl = module.params['global']
production = module.params['production']
executable = module.params['executable']
registry = module.params['registry']
state = module.params['state']
ignore_scripts = module.params['ignore_scripts']
unsafe_perm = module.params['unsafe_perm']
ci = module.params['ci']
no_optional = module.params['no_optional']
no_bin_links = module.params['no_bin_links']
if not path and not glbl:
module.fail_json(msg='path must be specified when not using global')
if state == 'absent' and not name:
module.fail_json(msg='uninstalling a package is only available for named packages')
npm = Npm(module, name=name, path=path, version=version, glbl=glbl, production=production,
executable=executable, registry=registry, ignore_scripts=ignore_scripts,
unsafe_perm=unsafe_perm, state=state, no_optional=no_optional, no_bin_links=no_bin_links)
npm = Npm(module,
name=name,
path=path,
version=version,
glbl=glbl,
production=module.params['production'],
executable=module.params['executable'],
registry=module.params['registry'],
ignore_scripts=module.params['ignore_scripts'],
unsafe_perm=module.params['unsafe_perm'],
state=state,
no_optional=module.params['no_optional'],
no_bin_links=module.params['no_bin_links'])
changed = False
if ci:
if module.params['ci']:
npm.ci_install()
changed = True
elif state == 'present':