Skip to content

Instantly share code, notes, and snippets.

@matthewp
Created March 9, 2022 13:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewp/facfe1fc16525bc653391bd4442e9ea3 to your computer and use it in GitHub Desktop.
Save matthewp/facfe1fc16525bc653391bd4442e9ea3 to your computer and use it in GitHub Desktop.
pnpm-where
#!/bin/bash
bin_name=$1
bin_path="node_modules/.bin/$bin_name"
bin_dir=$(dirname $bin_path)
if [ ! -f "$bin_path" ]; then
echo "$bin_path does not exists"
exit 1
fi
rel=$(cat $bin_path | grep -E "basedir\/(\..+$bin_name)" | grep -oE "\..+$bin_name" | head -1)
function abspath {
if [[ -d "$1" ]]
then
pushd "$1" >/dev/null
pwd
popd >/dev/null
elif [[ -e "$1" ]]
then
pushd "$(dirname "$1")" >/dev/null
echo "$(pwd)/$(basename "$1")"
popd >/dev/null
else
echo "$1" does not exist! >&2
return 127
fi
}
js_path="$bin_dir/$rel"
out_path=$(abspath $js_path)
if [ ! -f "$out_path" ]; then
echo "Unable to resolve $bin_name"
echo "$out_path does not exists"
exit 1
fi
echo $out_path

Use like this:

node --inspect-brk $(pnpm-where _mocha) path/to/your.test.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment