fix: nodejs: bin-linking: account for broken symlinks when checking for existance

This commit is contained in:
DavHau 2022-09-01 09:13:25 +02:00
parent a015a05db4
commit 877b83654f
3 changed files with 10 additions and 6 deletions

View File

@ -405,13 +405,17 @@
for dep in ${l.toString nodeDeps}; do
binDir=$dep/lib/node_modules/.bin
if [ -e $binDir ]; then
for bin in $(ls $binDir/); do
mkdir -p $nodeModules/.bin
for bin in $(ls $binDir/); do\
if [ ! -e $nodeModules/.bin ]; then
mkdir -p $nodeModules/.bin
fi
# symlink might have been already created by install-deps.py
# if installMethod=copy was selected
if [ ! -e $nodeModules/.bin/$bin ]; then
if [ ! -L $nodeModules/.bin/$bin ]; then
ln -s $binDir/$bin $nodeModules/.bin/$bin
else
echo "won't overwrite existing symlink $nodeModules/.bin/$bin. current target: $(readlink $nodeModules/.bin/$bin)"
fi
done
fi

View File

@ -111,9 +111,9 @@ def symlink_bin(bin_dir, package_location, package_json, force=False):
pathlib.Path(sourceDir).mkdir(parents=True, exist_ok=True)
dest = os.path.relpath(f'{package_location}/{relpath}', sourceDir)
print(f"symlinking executable. dest: {dest}; source: {source}")
if force and os.path.exists(source):
if force and os.path.lexists(source):
os.remove(source)
if not os.path.exists(source):
if not os.path.lexists(source):
os.symlink(dest, source)
if isinstance(bin, str):

View File

@ -23,7 +23,7 @@ def symlink_bin(bin_dir, package_json):
dest = os.path.relpath(relpath, sourceDir)
print(f"symlinking executable. dest: {dest}; source: {source}")
# if a bin with this name exists, overwrite
if os.path.exists(source):
if os.path.lexists(source):
os.remove(source)
os.symlink(dest, source)