From 6cf6adf09fb1a66fd21a528a1e62e0c411cdf6e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= Date: Tue, 26 Nov 2024 13:23:29 +0100 Subject: [PATCH] Fix npm hashbang replacement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is a new (?) script deps/npm/bin/npm-prefix.js with the /usr/bin/env hashbang left intact, which caused npm to always pull in whatever nodejs was currently the default one. Now all the scripts there should have the hashbangs adapted to our naming and no new nodes pulled by installing npm. Signed-off-by: Jan Staněk Related: RHEL-76035 --- nodejs22.spec | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/nodejs22.spec b/nodejs22.spec index 9258f0b..96dc5f9 100644 --- a/nodejs22.spec +++ b/nodejs22.spec @@ -643,29 +643,21 @@ chrpath --delete %{buildroot}%{_bindir}/node # Rename the node binary mv %{buildroot}%{_bindir}/node %{buildroot}%{_bindir}/node-%{nodejs_pkg_major} -# Move the npm binary to npm-NODEJS_MAJOR -rm -f %{buildroot}%{_bindir}/npm +# 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};' -# 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/bin/npm-cli.js +# 2. Replace original links with the adjusted ones +for bin in npm npx; do + ln -srf "%{buildroot}%{nodejs_private_sitelib}/npm/bin/${bin}-cli.js" \ + "%{buildroot}%{_bindir}/${bin}-%{nodejs_pkg_major}" + rm -f "%{buildroot}%{_bindir}/${bin}" +done -ln -srf %{buildroot}%{nodejs_private_sitelib}/npm/bin/npm-cli.js \ - %{buildroot}%{_bindir}/npm-%{nodejs_pkg_major} - -# Move the npx binary to npx-NODEJS_MAJOR -rm -f %{buildroot}%{_bindir}/npx - -# 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/bin/npx-cli.js - -ln -srf %{buildroot}%{nodejs_private_sitelib}/npm/bin/npx-cli.js \ - %{buildroot}%{_bindir}/npx-%{nodejs_pkg_major} - -# Add the symlinks back for the default version +# 3. Add the symlinks back for the default version %if 0%{?nodejs_default} ln -srf %{buildroot}%{_bindir}/node-%{nodejs_pkg_major} \ %{buildroot}%{_bindir}/node