Replace /usr/etc/npmrc symlink with builtin configuration

We want to have the system-level npmrc located at /etc/npmrc.
By default, npm looks for it in /usr/etc/npmrc,
so we placed a symlink to /etc/npmrc there.
However, we are the only known package that has anything in /usr/etc,
which confuses and/or breaks various tooling (see related bug).

This gets rid of the symlink,
and instead uses "builtin"-level configuration of npm
to cause it to load the system-level configuration from /etc/npmrc.

Related: rhbz#2177776

Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
This commit is contained in:
Stephen Gallagher 2023-04-27 08:50:37 -04:00
parent 7559b10a65
commit 4e9436a835
No known key found for this signature in database
GPG key ID: 45DB85A568286D11
3 changed files with 15 additions and 14 deletions

View file

@ -135,6 +135,7 @@ Source2: btest402.js
Source3: https://github.com/unicode-org/icu/releases/download/release-%{icu_major}-%{icu_minor}/icu4c-%{icu_major}_%{icu_minor}-data-bin-b.zip Source3: https://github.com/unicode-org/icu/releases/download/release-%{icu_major}-%{icu_minor}/icu4c-%{icu_major}_%{icu_minor}-data-bin-b.zip
Source4: https://github.com/unicode-org/icu/releases/download/release-%{icu_major}-%{icu_minor}/icu4c-%{icu_major}_%{icu_minor}-data-bin-l.zip Source4: https://github.com/unicode-org/icu/releases/download/release-%{icu_major}-%{icu_minor}/icu4c-%{icu_major}_%{icu_minor}-data-bin-l.zip
Source200: nodejs-sources.sh Source200: nodejs-sources.sh
Source201: npmrc.builtin.in
Source202: nodejs.pc.in Source202: nodejs.pc.in
Source203: v8.pc.in Source203: v8.pc.in
@ -689,16 +690,14 @@ 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/@npmcli/run-script/lib/node-gyp-bin/node-gyp
chmod 0755 %{buildroot}%{nodejs_private_sitelib}/npm/node_modules/node-gyp/bin/node-gyp.js chmod 0755 %{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
# Drop the NPM default configuration in place # Drop the NPM default configuration in place
%if 0%{?nodejs_default} %if 0%{?nodejs_default}
mkdir -p %{buildroot}%{_sysconfdir} mkdir -p %{buildroot}%{_sysconfdir}
cp %{SOURCE1} %{buildroot}%{_sysconfdir}/npmrc cp %{SOURCE1} %{buildroot}%{_sysconfdir}/npmrc
# NPM upstream expects it to be in /usr/etc/npmrc, so we'll put a symlink here
# This is done in the interests of keeping /usr read-only.
mkdir -p %{buildroot}%{_prefix}/etc
ln -rsf %{buildroot}%{_sysconfdir}/npmrc \
%{buildroot}%{_prefix}/etc/npmrc
%endif %endif
# Install the full-icu data files # Install the full-icu data files
@ -837,7 +836,6 @@ end
%if 0%{?nodejs_default} %if 0%{?nodejs_default}
%{_bindir}/npm %{_bindir}/npm
%{_bindir}/npx %{_bindir}/npx
%{_prefix}/etc/npmrc
%config(noreplace) %{_sysconfdir}/npmrc %config(noreplace) %{_sysconfdir}/npmrc
%ghost %{_sysconfdir}/npmignore %ghost %{_sysconfdir}/npmignore

5
npmrc.builtin.in Normal file
View file

@ -0,0 +1,5 @@
# This is the distibution-level configuration file for npm.
# To configure NPM on a system level, use the globalconfig below (defaults to @SYSCONFDIR@/npmrc).
# vim:set filetype=dosini:
globalconfig=@SYSCONFDIR@/npmrc

View file

@ -135,6 +135,7 @@ Source2: btest402.js
Source3: https://github.com/unicode-org/icu/releases/download/release-%{icu_major}-%{icu_minor}/icu4c-%{icu_major}_%{icu_minor}-data-bin-b.zip Source3: https://github.com/unicode-org/icu/releases/download/release-%{icu_major}-%{icu_minor}/icu4c-%{icu_major}_%{icu_minor}-data-bin-b.zip
Source4: https://github.com/unicode-org/icu/releases/download/release-%{icu_major}-%{icu_minor}/icu4c-%{icu_major}_%{icu_minor}-data-bin-l.zip Source4: https://github.com/unicode-org/icu/releases/download/release-%{icu_major}-%{icu_minor}/icu4c-%{icu_major}_%{icu_minor}-data-bin-l.zip
Source200: nodejs-sources.sh Source200: nodejs-sources.sh
Source201: npmrc.builtin.in
Source202: nodejs.pc.in Source202: nodejs.pc.in
Source203: v8.pc.in Source203: v8.pc.in
@ -697,16 +698,14 @@ 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/@npmcli/run-script/lib/node-gyp-bin/node-gyp
chmod 0755 %{buildroot}%{nodejs_private_sitelib}/npm/node_modules/node-gyp/bin/node-gyp.js chmod 0755 %{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
# Drop the NPM default configuration in place # Drop the NPM default configuration in place
%if 0%{?nodejs_default} %if 0%{?nodejs_default}
mkdir -p %{buildroot}%{_sysconfdir} mkdir -p %{buildroot}%{_sysconfdir}
cp %{SOURCE1} %{buildroot}%{_sysconfdir}/npmrc cp %{SOURCE1} %{buildroot}%{_sysconfdir}/npmrc
# NPM upstream expects it to be in /usr/etc/npmrc, so we'll put a symlink here
# This is done in the interests of keeping /usr read-only.
mkdir -p %{buildroot}%{_prefix}/etc
ln -rsf %{buildroot}%{_sysconfdir}/npmrc \
%{buildroot}%{_prefix}/etc/npmrc
%endif %endif
# Install the full-icu data files # Install the full-icu data files
@ -846,7 +845,6 @@ end
%if 0%{?nodejs_default} %if 0%{?nodejs_default}
%{_bindir}/npm %{_bindir}/npm
%{_bindir}/npx %{_bindir}/npx
%{_prefix}/etc/npmrc
%config(noreplace) %{_sysconfdir}/npmrc %config(noreplace) %{_sysconfdir}/npmrc
%ghost %{_sysconfdir}/npmignore %ghost %{_sysconfdir}/npmignore