#!/usr/bin/env -S rash --output raw --
#
# NPM binary mock for npm module tests.
#
- name: List all installed packages as JSON
debug:
msg: |-
{
"dependencies": {
"express": { "version": "4.18.0" },
"lodash": { "version": "4.17.21" },
"typescript": { "version": "5.0.0" },
"react": { "version": "18.2.0" }
}
}
when:
- "'list' in rash.args or 'ls' in rash.args"
- "'json' in rash.args | join(' ')"
- name: List outdated packages
debug:
msg: |-
{
"typescript": { "current": "5.0.0", "latest": "5.3.0" },
"react": { "current": "18.2.0", "latest": "18.3.0" }
}
when:
- "'outdated' in rash.args"
- "'json' in rash.args | join(' ')"
- name: Install packages
debug:
msg: |-
{% for pkg in rash.args -%}
{%- if "@" in pkg and pkg != "npm" and pkg != "install" and pkg[:2] != "--" -%}
added {{ pkg | split("@") | first }}
{% elif pkg != "npm" and pkg != "install" and pkg != "ci" and pkg[:2] != "--" -%}
added {{ pkg }}
{% endif -%}
{%- endfor -%}
when:
- "'install' in rash.args or 'ci' in rash.args"
- "'uninstall' not in rash.args"
- name: Uninstall packages
debug:
msg: |-
{% for pkg in rash.args -%}
{%- if pkg != "npm" and pkg != "uninstall" and pkg[:2] != "--" -%}
removed {{ pkg }}
{% endif -%}
{%- endfor -%}
when:
- "'uninstall' in rash.args"
- name: Update packages
debug:
msg: |-
{% for pkg in rash.args -%}
{%- if pkg != "npm" and pkg != "update" and pkg[:2] != "--" -%}
updated {{ pkg }}
{% endif -%}
{%- endfor -%}
when:
- "'update' in rash.args"
- "'outdated' not in rash.args"