npm-pkgbuild 7.11.2 → 7.11.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.11.2",
3
+ "version": "7.11.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "devDependencies": {
57
57
  "ava": "^3.15.0",
58
- "c8": "^7.10.0",
58
+ "c8": "^7.11.0",
59
59
  "documentation": "^13.2.5",
60
60
  "semantic-release": "^18.0.1",
61
61
  "stream-buffers": "^3.0.2"
@@ -27,10 +27,11 @@ export class DEB extends Packager {
27
27
  const properties = this.properties;
28
28
  const staging = await this.tmpdir;
29
29
 
30
- const fp = fieldProvider(properties, fields, this.mandatoryFields);
30
+ transformer.push(createModeTransformer(0o775, entry => entry.name.match(/DEBIAN\/.*(inst|rm)/)));
31
+
32
+ const fp = fieldProvider(properties, fields);
31
33
  const debianControlName = "DEBIAN/control";
32
34
 
33
- transformer.push(createModeTransformer(0o775, entry => entry.name.match(/DEBIAN\/.*(inst|rm)/)));
34
35
  transformer.push(
35
36
  {
36
37
  match: entry => entry.name === debianControlName,
@@ -43,19 +43,6 @@ export class Packager {
43
43
  return properties;
44
44
  }
45
45
 
46
- /**
47
- * @return {Set<string,Field>} mandatory fields
48
- */
49
- get mandatoryFields() {
50
- const mandatoryFields = new Set(
51
- Object.entries(this.fields)
52
- .filter(([k, v]) => v.mandatory)
53
- .map(([k, v]) => k)
54
- );
55
-
56
- return mandatoryFields;
57
- }
58
-
59
46
  /**
60
47
  * Create tmp directory.
61
48
  * @return {Promise<string>} directory path
@@ -70,7 +70,7 @@ package() {
70
70
  expander
71
71
  );
72
72
 
73
- const fp = fieldProvider(properties, fields, this.mandatoryFields);
73
+ const fp = fieldProvider(properties, fields);
74
74
 
75
75
  transformer.push({
76
76
  match: entry => entry.name === "PKGBUILD",
@@ -125,7 +125,7 @@ const fields = {
125
125
  epoch: { type: "integer", default: 0 },
126
126
  pkgdesc: { alias: "description", type: "string", mandatory: true },
127
127
  url: { alias: "homepage", type: "string" },
128
- license: { default: [], type: "string[]", mandatory: true },
128
+ license: { type: "string[]", mandatory: true },
129
129
  install: { alias: "hooks", type: "string" },
130
130
  changelog: { type: "string" },
131
131
  source: { default: [], type: "string[]" },
@@ -38,48 +38,46 @@ export class RPM extends Packager {
38
38
  );
39
39
 
40
40
  const staging = join(tmp, "BUILDROOT");
41
-
42
- const fp = fieldProvider(properties, fields, this.mandatoryFields);
43
-
44
41
  const specFileName = `${properties.name}.spec`;
45
42
 
46
43
  async function* trailingLines() {
47
-
48
44
  yield "%define _unpackaged_files_terminate_build 0\n";
49
-
45
+
50
46
  for (const [name, options] of Object.entries(sections)) {
51
- if(options.mandatory) {
47
+ if (options.mandatory) {
52
48
  yield `%${name}\n\n`;
53
49
  }
54
50
  }
55
51
  }
56
52
 
57
- transformer.push(
58
- {
59
- match: entry => entry.name === specFileName,
60
- transform: async entry =>
61
- new ReadableStreamContentEntry(
62
- entry.name,
63
- keyValueTransformer(await entry.readStream, fp, {
64
- ...colonSeparatedKeyValuePairOptions,
65
- trailingLines
66
- })
67
- ),
68
- createEntryWhenMissing: () => new EmptyContentEntry(specFileName)
69
- });
53
+ const fp = fieldProvider(properties, fields);
54
+
55
+ transformer.push({
56
+ match: entry => entry.name === specFileName,
57
+ transform: async entry =>
58
+ new ReadableStreamContentEntry(
59
+ entry.name,
60
+ keyValueTransformer(await entry.readStream, fp, {
61
+ ...colonSeparatedKeyValuePairOptions,
62
+ trailingLines
63
+ })
64
+ ),
65
+ createEntryWhenMissing: () => new EmptyContentEntry(specFileName)
66
+ });
70
67
 
71
68
  await copyEntries(transform(sources, transformer), staging, expander);
72
69
 
73
70
  const rpmbuild = await execa("rpmbuild", [
74
71
  "--define",
75
72
  `_topdir ${tmp}`,
76
- "--buildroot", staging,
73
+ "--buildroot",
74
+ staging,
77
75
  "-vv",
78
76
  "-bb",
79
77
  join(staging, specFileName)
80
78
  ]);
81
79
 
82
- if(options.verbose) {
80
+ if (options.verbose) {
83
81
  console.log(rpmbuild.stdout);
84
82
  }
85
83
 
package/src/util.mjs CHANGED
@@ -25,16 +25,34 @@ export function asArray(o) {
25
25
  return Array.isArray(o) ? o : [o];
26
26
  }
27
27
 
28
- export function fieldProvider(properties, fields, mandatoryFields) {
28
+ /**
29
+ *
30
+ * @param {Object} properties
31
+ * @param {Object} fields
32
+ * @returns {Function}
33
+ */
34
+ export function fieldProvider(properties, fields) {
29
35
  return function* controlProperties(k, v, presentKeys) {
30
36
  if (k === undefined) {
31
- for (const p of mandatoryFields) {
32
- if (!presentKeys.has(p)) {
33
- const v = properties[p];
34
- if (v === undefined && fields[p].default === undefined) {
35
- console.log(`Missing value for mandatory field ${p}`);
37
+ for (const [name, field] of Object.entries(fields)) {
38
+ if (!presentKeys.has(name)) {
39
+ const value = properties[field.alias || name];
40
+ if (value === undefined) {
41
+ if (field.default === undefined) {
42
+ if (field.mandatory) {
43
+ console.log(`Missing value for mandatory field ${name}`);
44
+ }
45
+ } else {
46
+ yield [name, field.default];
47
+ }
48
+ } else {
49
+ yield [
50
+ name,
51
+ field.type.endsWith("]") && !Array.isArray(value)
52
+ ? [value]
53
+ : value
54
+ ];
36
55
  }
37
- yield [p, v === undefined ? fields[p].default : v];
38
56
  }
39
57
  }
40
58
  } else {
@@ -61,7 +79,7 @@ export async function extractFromPackage(pkg, dir) {
61
79
  }
62
80
 
63
81
  Object.assign(properties, pkg.config);
64
-
82
+
65
83
  if (properties.name) {
66
84
  properties.name = properties.name.replace(/^\@\w+\//, "");
67
85
  }
@@ -111,12 +129,11 @@ export async function extractFromPackage(pkg, dir) {
111
129
  return { properties, sources, dependencies, output };
112
130
  }
113
131
 
114
- export function createModeTransformer(mode, match)
115
- {
116
- return {
117
- match,
118
- transform: async entry => Object.create(entry,{ mode: { value: mode }})
119
- };
132
+ export function createModeTransformer(mode, match) {
133
+ return {
134
+ match,
135
+ transform: async entry => Object.create(entry, { mode: { value: mode } })
136
+ };
120
137
  }
121
138
 
122
139
  export function createExpressionTransformer(
@@ -136,9 +153,11 @@ export function createExpressionTransformer(
136
153
  iterableStringInterceptor(
137
154
  await entry.getReadStream(utf8StreamOptions),
138
155
  transformer
139
- ));
140
- ne.destination = entry.destination; // TODO all the other attributes ?
141
- return ne; }
156
+ )
157
+ );
158
+ ne.destination = entry.destination; // TODO all the other attributes ?
159
+ return ne;
160
+ }
142
161
  };
143
162
  }
144
163
 
@@ -177,7 +196,7 @@ export async function* transform(source, transformers = [], onlyMatching) {
177
196
 
178
197
  /**
179
198
  * @typedef {Function} Expander
180
- * @param {string} path
199
+ * @param {string} path
181
200
  * @return {string}
182
201
  */
183
202