From 1a9e720653c673964fa04ac63081cf68ffddf148 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Fri, 28 Apr 2023 10:43:13 -0400 Subject: [PATCH] Fix up shebangs for npm and npx Signed-off-by: Stephen Gallagher --- nodejs20.spec | 17 ++++++++++++++++- packaging/nodejs.spec.j2 | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/nodejs20.spec b/nodejs20.spec index 70c2ae7..f0ddaf2 100644 --- a/nodejs20.spec +++ b/nodejs20.spec @@ -573,12 +573,22 @@ mv %{buildroot}%{_bindir}/node %{buildroot}%{_bindir}/node-%{nodejs_pkg_major} # Move the npm binary to npm-NODEJS_MAJOR rm -f %{buildroot}%{_bindir}/npm +# 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 + ln -srf %{buildroot}%{nodejs_private_sitelib}/npm/bin/npm-cli.js \ %{buildroot}%{_bindir}/npm-%{nodejs_pkg_major} -# Move the npx binary to npm-NODEJS_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} @@ -687,6 +697,11 @@ 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 diff --git a/packaging/nodejs.spec.j2 b/packaging/nodejs.spec.j2 index c679e58..1be82d2 100644 --- a/packaging/nodejs.spec.j2 +++ b/packaging/nodejs.spec.j2 @@ -584,12 +584,22 @@ mv %{buildroot}%{_bindir}/node %{buildroot}%{_bindir}/node-%{nodejs_pkg_major} # Move the npm binary to npm-NODEJS_MAJOR rm -f %{buildroot}%{_bindir}/npm +# 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 + ln -srf %{buildroot}%{nodejs_private_sitelib}/npm/bin/npm-cli.js \ %{buildroot}%{_bindir}/npm-%{nodejs_pkg_major} -# Move the npx binary to npm-NODEJS_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} @@ -698,6 +708,11 @@ 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