npm-pkgbuild 7.22.10 → 7.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/output/rpm.mjs +43 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "7.22.10",
3
+ "version": "7.23.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,4 +1,5 @@
1
1
  import { join } from "path";
2
+ import { createReadStream } from "fs";
2
3
  import { cp } from "fs/promises";
3
4
  import { execa } from "execa";
4
5
  import { EmptyContentEntry, ReadableStreamContentEntry } from "content-entry";
@@ -8,7 +9,22 @@ import {
8
9
  colonSeparatedKeyValuePairOptions
9
10
  } from "key-value-transformer";
10
11
  import { Packager } from "./packager.mjs";
11
- import { copyEntries, fieldProvider } from "../util.mjs";
12
+ import {
13
+ copyEntries,
14
+ fieldProvider,
15
+ utf8StreamOptions,
16
+ extractFunctions
17
+ } from "../util.mjs";
18
+
19
+ /**
20
+ * map install hook named from arch to rpm
21
+ */
22
+ const hookMapping = {
23
+ pre_instll: "pre",
24
+ post_install: "post",
25
+ pre_remove: "preun",
26
+ post_remove: "postun"
27
+ };
12
28
 
13
29
  export class RPM extends Packager {
14
30
  static get name() {
@@ -64,29 +80,35 @@ export class RPM extends Packager {
64
80
 
65
81
  async function* trailingLines() {
66
82
  yield "%define _unpackaged_files_terminate_build 0\n";
67
-
68
- for (const [name, options] of Object.entries(sections)) {
69
- if (options.mandatory) {
70
- yield `%${name}\n\n`;
71
-
72
- if (name === "files") {
73
- for (const file of files) {
74
- yield "/" + file + "\n";
75
- }
76
-
77
- for await (const file of copyEntries(
78
- transform(sources, transformer),
79
- staging,
80
- expander
81
- )) {
82
- if (options.verbose) {
83
- console.log(file.destination);
84
- }
85
- yield file.destination + "\n";
86
- }
83
+ yield `%description\n\n`;
84
+
85
+ if (options.hooks) {
86
+ for (const f of extractFunctions(
87
+ createReadStream(options.hooks, utf8StreamOptions)
88
+ )) {
89
+ const name = hookMapping[f.name];
90
+ if (name) {
91
+ yield `%${name}\n`;
92
+ yield f.body;
87
93
  }
88
94
  }
89
95
  }
96
+
97
+ yield `%files\n\n`;
98
+ for (const file of files) {
99
+ yield "/" + file + "\n";
100
+ }
101
+
102
+ for await (const file of copyEntries(
103
+ transform(sources, transformer),
104
+ staging,
105
+ expander
106
+ )) {
107
+ if (options.verbose) {
108
+ console.log(file.destination);
109
+ }
110
+ yield file.destination + "\n";
111
+ }
90
112
  }
91
113
 
92
114
  const fp = fieldProvider(properties, fields);
@@ -159,13 +181,3 @@ const fields = {
159
181
  URL: { alias: "homepage", type: "string" },
160
182
  Requires: { type: "string[]" }
161
183
  };
162
-
163
- const sections = {
164
- description: { mandatory: true },
165
- prep: { mandatory: false },
166
- build: { mandatory: false },
167
- install: { mandatory: false },
168
- check: { mandatory: false },
169
- files: { mandatory: true },
170
- changelog: { mandatory: false }
171
- };