-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnpm_wrapper.sh
More file actions
executable file
·30 lines (27 loc) · 1.07 KB
/
npm_wrapper.sh
File metadata and controls
executable file
·30 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
# Wrapper to use system-installed npm/cdxgen.
# Resolves npm and cdxgen from PATH, with optional NVM support via $NVM_DIR.
# Load NVM if available (honours NVM_DIR env var set by the caller; no
# hard-coded version or home directory).
if [[ -n "${NVM_DIR:-}" && -s "${NVM_DIR}/nvm.sh" ]]; then
# shellcheck source=/dev/null
source "${NVM_DIR}/nvm.sh" --no-use
# Use whatever version is currently active/default in NVM.
nvm use --silent 2>/dev/null || true
fi
# Fail clearly if npm is not on PATH.
if ! command -v npm &>/dev/null; then
echo "npm_wrapper.sh: 'npm' not found in PATH. Install Node.js (e.g. via nvm) and ensure it is on PATH." >&2
exit 1
fi
# If called with "exec -- @cyclonedx/cdxgen", resolve and run cdxgen directly.
if [[ "$1" == "exec" && "$2" == "--" && "$3" == "@cyclonedx/cdxgen" ]]; then
shift 3
if ! command -v cdxgen &>/dev/null; then
echo "npm_wrapper.sh: 'cdxgen' not found in PATH. Install it with: npm install -g @cyclonedx/cdxgen" >&2
exit 1
fi
exec cdxgen "$@"
else
exec npm "$@"
fi