From d5ff817f75153539ebf178b75d6aa107c02bf611 Mon Sep 17 00:00:00 2001 From: Andrei Radchenko Date: Tue, 12 Aug 2025 10:20:41 +0200 Subject: [PATCH] spec: fix node binary calls to use versioned binary Resolves: RHEL-111635 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-22 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 --- nodejs22.spec | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/nodejs22.spec b/nodejs22.spec index 1e09ba3..e3443e0 100644 --- a/nodejs22.spec +++ b/nodejs22.spec @@ -647,12 +647,16 @@ chrpath --delete %{buildroot}%{_bindir}/node # Rename the node binary mv %{buildroot}%{_bindir}/node %{buildroot}%{_bindir}/node-%{nodejs_pkg_major} -# Adjust the npm binaries -# 1. Replace all hasbangs with versioned ones -grep --extended-regexp --files-with-matches --recursive \ - '^#!/usr/bin/(env )?node($|[[:space:]])+' '%{buildroot}%{nodejs_private_sitelib}/npm/bin' \ -| xargs sed --in-place --regexp-extended \ - 's;^#!/usr/bin/(env )?node($|[[:space:]])+;#!/usr/bin/node-%{nodejs_pkg_major};' +# Adjust npm binaries +# 1. Replace all hashbangs with versioned ones +readonly NPM_DIR="%{buildroot}%{nodejs_private_sitelib}/npm" +readonly SHEBANG_ERE='^#!/usr/bin/(env\s+)?node\b' +readonly SHEBANG_FIX='#!%{_bindir}/node-%{nodejs_pkg_major}' +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};" # 2. Replace original links with the adjusted ones for bin in npm npx; do @@ -673,6 +677,13 @@ ln -srf %{buildroot}%{_bindir}/npx-%{nodejs_pkg_major} \ %{buildroot}%{_bindir}/npx %endif +# 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-%{nodejs_pkg_major}\1;' "${known_shell_scripts[@]}" + # Install library symlink ln -srf %{buildroot}%{_libdir}/libnode.so.%{nodejs_soversion} \ %{buildroot}%{_libdir}/libnode.so @@ -766,11 +777,6 @@ find %{buildroot}%{nodejs_private_sitelib}/npm \ chmod 0755 %{buildroot}%{nodejs_private_sitelib}/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin/node-gyp chmod 0755 %{buildroot}%{nodejs_private_sitelib}/npm/node_modules/node-gyp/bin/node-gyp.js -# Set the hashbang to use the matching Node.js interpreter -sed --in-place --regexp-extended \ - 's;^#!/usr/bin/env node($|\ |\t)+;#!/usr/bin/node-%{nodejs_pkg_major};g' \ - %{buildroot}%{nodejs_private_sitelib}/npm/node_modules/node-gyp/bin/node-gyp.js - # Drop the NPM builtin configuration in place sed -e 's#@SYSCONFDIR@#%{_sysconfdir}#g' \ %{SOURCE201} > %{buildroot}%{nodejs_private_sitelib}/npm/npmrc