mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* Add no-bin-links option to npm
* Add changelog
* Fix changelog format
* Add integration test
* Change node package from thelounge to ncp
(cherry picked from commit fa13826273
)
Co-authored-by: Amin Vakil <info@aminvakil.com>
This commit is contained in:
parent
24667e12d0
commit
b701b5893f
4 changed files with 80 additions and 1 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- npm - add ``no_bin_links`` option (https://github.com/ansible-collections/community.general/issues/2128).
|
|
@ -82,6 +82,12 @@ options:
|
||||||
type: bool
|
type: bool
|
||||||
default: no
|
default: no
|
||||||
version_added: 2.0.0
|
version_added: 2.0.0
|
||||||
|
no_bin_links:
|
||||||
|
description:
|
||||||
|
- Use the C(--no-bin-links) flag when installing.
|
||||||
|
type: bool
|
||||||
|
default: no
|
||||||
|
version_added: 2.5.0
|
||||||
requirements:
|
requirements:
|
||||||
- npm installed in bin path (recommended /usr/local/bin)
|
- npm installed in bin path (recommended /usr/local/bin)
|
||||||
'''
|
'''
|
||||||
|
@ -151,6 +157,7 @@ class Npm(object):
|
||||||
self.unsafe_perm = kwargs['unsafe_perm']
|
self.unsafe_perm = kwargs['unsafe_perm']
|
||||||
self.state = kwargs['state']
|
self.state = kwargs['state']
|
||||||
self.no_optional = kwargs['no_optional']
|
self.no_optional = kwargs['no_optional']
|
||||||
|
self.no_bin_links = kwargs['no_bin_links']
|
||||||
|
|
||||||
if kwargs['executable']:
|
if kwargs['executable']:
|
||||||
self.executable = kwargs['executable'].split(' ')
|
self.executable = kwargs['executable'].split(' ')
|
||||||
|
@ -181,6 +188,8 @@ class Npm(object):
|
||||||
cmd.append(self.registry)
|
cmd.append(self.registry)
|
||||||
if self.no_optional:
|
if self.no_optional:
|
||||||
cmd.append('--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.
|
# If path is specified, cd into that path and run the command.
|
||||||
cwd = None
|
cwd = None
|
||||||
|
@ -259,6 +268,7 @@ def main():
|
||||||
unsafe_perm=dict(default=False, type='bool'),
|
unsafe_perm=dict(default=False, type='bool'),
|
||||||
ci=dict(default=False, type='bool'),
|
ci=dict(default=False, type='bool'),
|
||||||
no_optional=dict(default=False, type='bool'),
|
no_optional=dict(default=False, type='bool'),
|
||||||
|
no_bin_links=dict(default=False, type='bool'),
|
||||||
)
|
)
|
||||||
arg_spec['global'] = dict(default=False, type='bool')
|
arg_spec['global'] = dict(default=False, type='bool')
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -278,6 +288,7 @@ def main():
|
||||||
unsafe_perm = module.params['unsafe_perm']
|
unsafe_perm = module.params['unsafe_perm']
|
||||||
ci = module.params['ci']
|
ci = module.params['ci']
|
||||||
no_optional = module.params['no_optional']
|
no_optional = module.params['no_optional']
|
||||||
|
no_bin_links = module.params['no_bin_links']
|
||||||
|
|
||||||
if not path and not glbl:
|
if not path and not glbl:
|
||||||
module.fail_json(msg='path must be specified when not using global')
|
module.fail_json(msg='path must be specified when not using global')
|
||||||
|
@ -286,7 +297,7 @@ def main():
|
||||||
|
|
||||||
npm = Npm(module, name=name, path=path, version=version, glbl=glbl, production=production,
|
npm = Npm(module, name=name, path=path, version=version, glbl=glbl, production=production,
|
||||||
executable=executable, registry=registry, ignore_scripts=ignore_scripts,
|
executable=executable, registry=registry, ignore_scripts=ignore_scripts,
|
||||||
unsafe_perm=unsafe_perm, state=state, no_optional=no_optional)
|
unsafe_perm=unsafe_perm, state=state, no_optional=no_optional, no_bin_links=no_bin_links)
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
if ci:
|
if ci:
|
||||||
|
|
64
tests/integration/targets/npm/tasks/no_bin_links.yml
Normal file
64
tests/integration/targets/npm/tasks/no_bin_links.yml
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
---
|
||||||
|
- name: 'Remove any node modules'
|
||||||
|
file:
|
||||||
|
path: '{{ remote_dir }}/node_modules'
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- vars:
|
||||||
|
# sample: node-v8.2.0-linux-x64.tar.xz
|
||||||
|
node_path: '{{ remote_dir }}/{{ nodejs_path }}/bin'
|
||||||
|
package: 'ncp'
|
||||||
|
block:
|
||||||
|
- shell: npm --version
|
||||||
|
environment:
|
||||||
|
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
|
||||||
|
register: npm_version
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
var: npm_version.stdout
|
||||||
|
|
||||||
|
- name: 'Install simple package with no_bin_links disabled'
|
||||||
|
npm:
|
||||||
|
path: '{{ remote_dir }}'
|
||||||
|
executable: '{{ node_path }}/npm'
|
||||||
|
state: present
|
||||||
|
name: '{{ package }}'
|
||||||
|
no_bin_links: false
|
||||||
|
environment:
|
||||||
|
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
|
||||||
|
register: npm_install_no_bin_links_disabled
|
||||||
|
|
||||||
|
- name: 'Make sure .bin folder has been created'
|
||||||
|
stat:
|
||||||
|
path: "{{ remote_dir }}/node_modules/.bin"
|
||||||
|
register: npm_dotbin_folder_disabled
|
||||||
|
|
||||||
|
- name: 'Remove any node modules'
|
||||||
|
file:
|
||||||
|
path: '{{ remote_dir }}/node_modules'
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: 'Install simple package with no_bin_links enabled'
|
||||||
|
npm:
|
||||||
|
path: '{{ remote_dir }}'
|
||||||
|
executable: '{{ node_path }}/npm'
|
||||||
|
state: present
|
||||||
|
name: '{{ package }}'
|
||||||
|
no_bin_links: true
|
||||||
|
environment:
|
||||||
|
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
|
||||||
|
register: npm_install_no_bin_links_enabled
|
||||||
|
|
||||||
|
- name: 'Make sure .bin folder has not been created'
|
||||||
|
stat:
|
||||||
|
path: "{{ remote_dir }}/node_modules/.bin"
|
||||||
|
register: npm_dotbin_folder_enabled
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- npm_install_no_bin_links_disabled is success
|
||||||
|
- npm_install_no_bin_links_disabled is changed
|
||||||
|
- npm_install_no_bin_links_enabled is success
|
||||||
|
- npm_install_no_bin_links_enabled is changed
|
||||||
|
- npm_dotbin_folder_disabled.stat.exists
|
||||||
|
- not npm_dotbin_folder_enabled.stat.exists
|
|
@ -1,2 +1,3 @@
|
||||||
- include_tasks: setup.yml
|
- include_tasks: setup.yml
|
||||||
- include_tasks: test.yml
|
- include_tasks: test.yml
|
||||||
|
- include_tasks: no_bin_links.yml
|
||||||
|
|
Loading…
Reference in a new issue