Skip to content

Commit

Permalink
linux installer script: use --global=false for npm
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyc-splunk committed Dec 15, 2023
1 parent 9584c00 commit 46c1a67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions internal/buildscripts/packaging/installer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ ensure_not_installed() {
echo "Please uninstall auto instrumentation, or try running this script with the '--uninstall' option." >&2
exit 1
fi
if [ -n "$npm_path" ] && (cd $node_install_prefix && $npm_path ls @splunk/otel >/dev/null 2>&1); then
if [ -n "$npm_path" ] && (cd $node_install_prefix && $npm_path ls --global=false @splunk/otel >/dev/null 2>&1); then
echo "The @splunk/otel npm package is already installed in $node_install_prefix." >&2
echo "Please uninstall @splunk/otel, or try running this script with the '--uninstall' option." >&2
exit 1
Expand Down Expand Up @@ -568,9 +568,9 @@ install_node_package() {
fi

echo "Installing the Node.js Auto Instrumentation package ..."
mkdir -p $node_install_prefix
echo "Running 'cd $node_install_prefix && $npm_path install $node_package_path':"
(cd $node_install_prefix && $npm_path install $node_package_path)
mkdir -p ${node_install_prefix}/node_modules
echo "Running 'cd $node_install_prefix && $npm_path install --global=false $node_package_path':"
(cd $node_install_prefix && $npm_path install --global=false $node_package_path)
}

create_zeroconfig_node() {
Expand Down Expand Up @@ -788,8 +788,8 @@ uninstall() {
fi
done

if command -v npm >/dev/null 2>&1 && (cd $node_install_prefix && npm ls @splunk/otel >/dev/null 2>&1); then
(cd $node_install_prefix && npm uninstall @splunk/otel)
if command -v npm >/dev/null 2>&1 && (cd $node_install_prefix && npm ls --global=false @splunk/otel >/dev/null 2>&1); then
(cd $node_install_prefix && npm uninstall --global=false @splunk/otel)
echo "Successfully uninstalled the @splunk/otel npm package from $node_install_prefix"
fi
}
Expand Down
6 changes: 5 additions & 1 deletion internal/buildscripts/packaging/tests/installer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ def get_zc_method(container, distro, method):


def node_package_installed(container):
return container.exec_run(f"sh -l -c 'cd {NODE_PREFIX} && npm ls @splunk/otel'").exit_code == 0
cmd = f"sh -l -c 'cd {NODE_PREFIX} && npm ls --global=false @splunk/otel'"
print(f"Running '{cmd}':")
rc, output = container.exec_run(cmd)
print(output.decode("utf-8"))
return rc == 0


@pytest.mark.installer
Expand Down

0 comments on commit 46c1a67

Please sign in to comment.