Skip to content

Instantly share code, notes, and snippets.

@nemisj
Last active February 4, 2018 01:15
Show Gist options
  • Save nemisj/11f6d01ef9638af283d3 to your computer and use it in GitHub Desktop.
Save nemisj/11f6d01ef9638af283d3 to your computer and use it in GitHub Desktop.
Removing npm tmp after install
#!/usr/bin/env bash
# this is pid of the bash we are in
bash_pid=$$
bash_pid=$(echo -e ${bash_pid} | tr -d '[[:space:]]');
# this is shell of the bash
shell_pid=$(ps -p ${bash_pid} -o ppid=;)
shell_pid=$(echo -e ${shell_pid} | tr -d '[[:space:]]');
# this is the npm who runs shell
npm_pid=$(ps -p ${shell_pid} -o ppid=;)
npm_pid=$(echo -e ${npm_pid} | tr -d '[[:space:]]');
# test whether npm tmp configuration is set
# if not, assume the default /tmp
if [ -z ${npm_config_tmp} ]; then
npm_config_tmp=/tmp
fi;
echo "Removing ${npm_config_tmp}/npm-${npm_pid}*";
rm -rf "${npm_config_tmp}"/npm-${npm_pid}*
{
"scripts": {
"postinstall": "./bin/npm-tmp-clean.sh"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment