2015-01-23 20:38:50 -06:00
#!/bin/sh
cleanup () {
rm -rf "$npm_config_prefix/lib" >/dev/null 2>&1
unset npm_config_prefix
2015-02-02 20:42:12 -06:00
rm -f npm
PATH="$ORIGINAL_PATH"
2020-11-16 16:49:02 -08:00
NVM_DIR="$ORIGINAL_NVM_DIR"
2015-02-02 20:42:12 -06:00
2015-02-07 20:50:10 -06:00
unset -f setup cleanup die
2020-11-16 16:49:02 -08:00
unset message ORIGINAL_PATH ORIGINAL_NVM_DIR
2015-01-23 20:38:50 -06:00
}
2016-11-07 03:34:36 +08:00
die () { echo "$@" ; cleanup ; exit 1; }
2015-01-23 20:38:50 -06:00
2016-11-04 13:15:18 +08:00
NVM_ENV=testing \. ../../install.sh
2015-01-23 20:38:50 -06:00
setup () {
2015-02-02 20:42:12 -06:00
ORIGINAL_PATH="$PATH"
2020-11-16 16:49:02 -08:00
ORIGINAL_NVM_DIR="$NVM_DIR"
# Pretend we're not using NVM
unset NVM_DIR
2015-02-02 20:42:12 -06:00
2015-01-23 20:38:50 -06:00
npm_config_prefix="$(pwd)"
export npm_config_prefix
mkdir -p "$npm_config_prefix/lib"
}
2015-02-09 16:56:08 -08:00
setup
2015-02-07 20:50:10 -06:00
2015-02-07 20:53:53 -06:00
npm install -g nop >/dev/null || die 'nvm_check_global_modules cannot be tested because `npm` cannot install the `nop` package'
2015-01-23 20:38:50 -06:00
message=$(nvm_check_global_modules)
2022-12-27 21:41:26 -08:00
[ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed; got:\n${message}"
2015-01-23 20:38:50 -06:00
2024-08-22 13:30:55 -07:00
if [ -n "${ORIGINAL_NVM_DIR}" ] && [ -z "${GITHUB_ACTIONS}" ]; then
2022-12-27 21:41:26 -08:00
# Admit we're using NVM, just for this one test
2024-08-22 13:30:55 -07:00
# TODO: fix this for GHA
2022-12-27 21:41:26 -08:00
message=$(NVM_DIR="${ORIGINAL_NVM_DIR}" nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm is managed by nvm; got:\n${message}"
fi
2020-11-16 16:49:02 -08:00
2015-02-04 16:39:57 -06:00
npm uninstall -g nop >/dev/null
2015-01-23 20:38:50 -06:00
message=$(nvm_check_global_modules)
2022-12-27 21:41:26 -08:00
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed; got:\n${message}"
2015-01-23 20:38:50 -06:00
# Faking an installation of npm
mkdir -p "$npm_config_prefix/lib/node_modules/npm"
cat <<'JSON' >"$npm_config_prefix/lib/node_modules/npm/package.json"
{ "name": "npm", "version": "0.0.1fake" }
JSON
message=$(nvm_check_global_modules)
2022-12-27 21:41:26 -08:00
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm had only itself installed as a global module; got:\n${message}"
2015-01-23 20:38:50 -06:00
2015-02-02 20:42:12 -06:00
# Faking the absence of npm
PATH=".:$PATH"
touch npm
chmod +x npm
message=$(nvm_check_global_modules)
2022-12-27 21:41:26 -08:00
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable; got:\n${message}"
2015-02-02 20:42:12 -06:00
2015-01-23 20:38:50 -06:00
cleanup