npm-pkgbuild 7.22.10 → 7.23.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "7.22.10",
3
+ "version": "7.23.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,3 +1,4 @@
1
+ import { arch as hostArch } from 'process';
1
2
  import { packageWalker } from "npm-package-walker";
2
3
  import { asArray } from "./util.mjs";
3
4
  import { NPMPackContentProvider } from "./content/npm-pack-content-provider.mjs";
@@ -10,12 +11,14 @@ import { RPM } from "./output/rpm.mjs";
10
11
  export const allInputs = [NPMPackContentProvider, NodeModulesContentProvider];
11
12
  export const allOutputs = [DEB, ARCH, RPM];
12
13
 
13
- const npmArchMapping = {
14
+ export const npmArchMapping = {
14
15
  arm64: "aarch64",
15
16
  arm: "armv7h",
16
- x86: "x86_64"
17
+ x64: "x86_64"
17
18
  };
18
19
 
20
+ export const archMapping = Object.fromEntries(Object.entries(npmArchMapping).map(a=>[a[1],a[0]]));
21
+
19
22
  /**
20
23
  * Extract package definition from package.json.
21
24
  * @param {Object} pkg package.json content
@@ -69,7 +72,9 @@ export async function extractFromPackage(pkg, dir) {
69
72
  if (pkgbuild.abstract || !modulePath) {
70
73
  if (pkgbuild.arch) {
71
74
  for (const a of asArray(pkgbuild.arch)) {
72
- arch.add(a);
75
+ if(npmArchMapping[hostArch] === a) {
76
+ arch.add(a);
77
+ }
73
78
  }
74
79
  }
75
80
 
@@ -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,40 @@ 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 (properties.hooks) {
86
+ for await (const f of extractFunctions(
87
+ createReadStream(properties.hooks, utf8StreamOptions)
88
+ )) {
89
+ const name = hookMapping[f.name];
90
+ if (name) {
91
+ yield `%${name}\n`;
92
+
93
+ yield f.body.replace(
94
+ /\{\{(\w+)\}\}/m,
95
+ (match, key, offset, string) =>
96
+ properties[key] || "{{" + key + "}}"
97
+ ) + "\n\n";
87
98
  }
88
99
  }
89
100
  }
101
+
102
+ yield `%files\n\n`;
103
+ for (const file of files) {
104
+ yield "/" + file + "\n";
105
+ }
106
+
107
+ for await (const file of copyEntries(
108
+ transform(sources, transformer),
109
+ staging,
110
+ expander
111
+ )) {
112
+ if (options.verbose) {
113
+ console.log(file.destination);
114
+ }
115
+ yield file.destination + "\n";
116
+ }
90
117
  }
91
118
 
92
119
  const fp = fieldProvider(properties, fields);
@@ -159,13 +186,3 @@ const fields = {
159
186
  URL: { alias: "homepage", type: "string" },
160
187
  Requires: { type: "string[]" }
161
188
  };
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
- };