spec: fix node binary calls to use versioned node-24 binary

Resolves: RHEL-111616

Extend existing shebang fixes to cover all npm nested modules and
shell scripts that call 'node' as a command. This prevents failures
when scripts try to call /usr/bin/node which is not shipped, instead
redirecting them to the versioned /usr/bin/node-24 binary.

Fixes include:
- All JavaScript/TypeScript files with node shebangs in npm nested modules
- Shell scripts like node-gyp that call 'node' as a command
This commit is contained in:
Andrei Radchenko 2025-08-08 12:41:15 +02:00
parent 00b6c80804
commit 6a84fa4bbf

View File

@ -454,12 +454,19 @@ declare NPM_DIR="${RPM_BUILD_ROOT}%{nodejs_private_sitelib}/npm"
# Adjust npm scripts to use the renamed interpreter
readonly SHEBANG_ERE='^#!/usr/bin/(env\s+)?node\b'
readonly SHEBANG_FIX='#!%{_bindir}/node-%{node_version_major}'
readonly -a npm_bin_dirs=("${NPM_DIR}/bin" "${NPM_DIR}/node_modules/node-gyp/bin")
readonly -a npm_bin_dirs=("${NPM_DIR}/bin" "${NPM_DIR}/node_modules")
find "${npm_bin_dirs[@]}" -type f \
| xargs grep --extended-regexp --files-with-matches "${SHEBANG_ERE}" \
| xargs sed --regexp-extended --in-place "s;${SHEBANG_ERE};${SHEBANG_FIX};"
# Fix shell scripts that call 'node' as command
readonly -a known_shell_scripts=(
"${NPM_DIR}/bin/node-gyp-bin/node-gyp"
"${NPM_DIR}/node_modules/@npmcli/run-script/lib/node-gyp-bin/node-gyp"
)
sed --regexp-extended --in-place 's;\bnode(\s);%{_bindir}/node-%{node_version_major}\1;' "${known_shell_scripts[@]}"
# Replace npm %%{_bindir} symlinks with properly versioned ones
# usage: relink_bin <basename> <source>
relink_bin() {