mirror of
https://github.com/asdf-vm/asdf-nodejs.git
synced 2024-10-06 07:42:08 +08:00
Fix bin names #6
This commit is contained in:
parent
ae6b6ff9e4
commit
ec1aca10ba
21
bin/get-bin-names.py
Normal file
21
bin/get-bin-names.py
Normal file
@ -0,0 +1,21 @@
|
||||
#/usr/bin/env python
|
||||
import os, json;
|
||||
|
||||
if os.environ['npm_config_global'] == 'true':
|
||||
exit(0)
|
||||
|
||||
package_json_path=os.environ['PWD'] + '/package.json'
|
||||
|
||||
# create shims only for globally installed pkg
|
||||
if package_json_path.count('node_modules') > 1:
|
||||
exit(0)
|
||||
|
||||
with open(package_json_path, 'r') as package_json_file:
|
||||
package_json = json.load(package_json_file)
|
||||
|
||||
if 'bin' in package_json:
|
||||
if isinstance(package_json['bin'], dict):
|
||||
bin_list = " ".join(package_json['bin'].keys())
|
||||
print(bin_list)
|
||||
else:
|
||||
print(package_json["name"])
|
@ -1,35 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
env | grep -i npm_package_bin | while read bin_env; do
|
||||
|
||||
if [[ "$bin_env" =~ npm_package_bin* ]]; then
|
||||
|
||||
IFS='=' read -a bin_env_parts <<< "$bin_env"
|
||||
executable_name="$(basename ${bin_env_parts[1]} .js)"
|
||||
|
||||
# if "node_modules" appears more than once in $PWD
|
||||
# we can confirm that package being installed is sub-dependency
|
||||
node_modules_count=$(echo $PWD | grep -o node_modules | wc -l)
|
||||
|
||||
# create shims only for globally installed pkg
|
||||
if [ $node_modules_count -le 1 ]
|
||||
then
|
||||
is_npm_sub_dependency=false;
|
||||
else
|
||||
is_npm_sub_dependency=true;
|
||||
fi
|
||||
|
||||
|
||||
# if global install
|
||||
# and executable name is not empty
|
||||
# and is not a dependency of another package that is being installed as global
|
||||
if [ "$npm_config_global" = "true" ] && \
|
||||
[ "$executable_name" != "" ] && \
|
||||
[ "$is_npm_sub_dependency" = "false" ]
|
||||
then
|
||||
asdf shim nodejs .npm/bin/$executable_name
|
||||
fi
|
||||
|
||||
fi
|
||||
package_bin_names=$(python $(dirname $0)/get-bin-names.py)
|
||||
IFS=' ' read -a package_bin_names_list <<< "$package_bin_names"
|
||||
|
||||
for package_bin in "${package_bin_names_list[@]}"
|
||||
do
|
||||
asdf shim nodejs .npm/bin/${package_bin}
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user