-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbundle.mustache
More file actions
101 lines (89 loc) · 3.15 KB
/
Copy pathbundle.mustache
File metadata and controls
101 lines (89 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
%global npm_name {{{NAME}}}
Name: {{{RPM_PACKAGE_NAME}}}
Version: {{{VERSION}}}
Release: {{{RELEASE}}}%{?dist}
Summary: {{{SUMMARY}}}
License: {{{LICENSETYPE}}}
Group: Development/Libraries
URL: {{{PROJECTURL}}}
{{#each SOURCES}}
{{{.}}}
{{/each}}
BuildRequires: npm >= 7
BuildRequires: nodejs-packaging
# The prep section runs node directly, so this is needed unconditionally. It
# also works around https://issues.redhat.com/browse/RHEL-137712 on RHEL 10
# before 10.3, where the nodejs major version macro does not resolve without
# node in the buildroot.
BuildRequires: /usr/bin/node
BuildArch: noarch
ExclusiveArch: %{nodejs_arches} noarch
Provides: npm(%{npm_name}) = %{version}
{{#each PROVIDES}}
Provides: bundled(npm({{{name}}})) = {{{version}}}
{{/each}}
AutoReq: no
AutoProv: no
%define npm_cache_dir npm_cache_%{name}-%{version}-%{release}
%description
%{summary}
%prep
# There is deliberately no setup section: every Source is consumed explicitly
# below, so the build runs in the top-level build directory. Do not name the
# setup macro here even in a comment - rpm expands macros inside comments, and
# on rpm 6 that runs it, unpacking Source0 and cd-ing into a directory that
# does not exist.
mkdir -p %{npm_cache_dir}
# npm ci installs the tree recorded in the lockfile: every entry carries a
# resolved URL and an integrity hash, and npm serves the tarballs from the
# cache primed here by content hash. No registry access is needed.
for src in %{sources}; do
case "$src" in
*.tgz) npm cache add --cache %{npm_cache_dir} "$src" ;;
*-package-lock.json) cp "$src" package-lock.json ;;
*) echo "unexpected Source, do not know how to handle it: $src" >&2; exit 1 ;;
esac
done
# Derive package.json from the lockfile so the two cannot disagree.
node -e '
const fs = require("fs");
const lock = JSON.parse(fs.readFileSync("package-lock.json"));
fs.writeFileSync("package.json", JSON.stringify({
name: lock.name,
version: lock.version,
dependencies: lock.packages[""].dependencies
}, null, 2) + "\n");
'
%build
npm ci {{{LEGACY_PEER_DEPS}}}--offline --cache %{_builddir}/%{npm_cache_dir} --omit optional
%install
mkdir -p %{buildroot}%{nodejs_sitelib}/%{npm_name}
cp -pfr node_modules/%{npm_name}/node_modules %{buildroot}%{nodejs_sitelib}/%{npm_name}
# npm creates a scope directory for every scope named in the lockfile, including
# scopes whose packages were all omitted, which leaves empty dirs behind.
# -delete implies -depth, so nested empties go bottom-up in a single pass.
find %{buildroot}%{nodejs_sitelib}/%{npm_name} -type d -empty -delete
{{#each COPYFILES}}
cp -pfr node_modules/%{npm_name}/{{&.}} %{buildroot}%{nodejs_sitelib}/%{npm_name}
{{/each}}
{{#if BINARIES}}
mkdir -p %{buildroot}%{_bindir}/
{{/if}}
{{#each BINARIES}}
chmod 0755 %{buildroot}%{nodejs_sitelib}/%{npm_name}/{{{this}}}
ln -sf %{nodejs_sitelib}/%{npm_name}/{{{this}}} %{buildroot}%{_bindir}/{{{@key}}}
{{/each}}
%clean
rm -rf %{buildroot} %{npm_cache_dir}
%files
%{nodejs_sitelib}/%{npm_name}
{{#each BINARIES}}
%{_bindir}/{{{@key}}}
{{/each}}
{{#each LICENSEFILES}}
%license node_modules/%{npm_name}/{{{.}}}
{{/each}}
{{#each DOCFILES}}
%doc node_modules/%{npm_name}/{{{.}}}
{{/each}}
%changelog