npm-pkgbuild 17.2.5 → 17.3.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.
package/README.md CHANGED
@@ -99,25 +99,24 @@ See [mf-hosting](https://www.npmjs.com/package/mf-hosting) or [mf-hosting-fronte
99
99
  * [Properties](#properties)
100
100
  * [extractFromPackage](#extractfrompackage)
101
101
  * [Parameters](#parameters-1)
102
- * [BUILDAH](#buildah)
103
- * [ContentProvider](#contentprovider)
102
+ * [NPMPackContentProvider](#npmpackcontentprovider)
104
103
  * [Parameters](#parameters-2)
105
104
  * [Properties](#properties-1)
106
- * [asyncIterator](#asynciterator)
107
- * [FileContentProvider](#filecontentprovider)
108
- * [Parameters](#parameters-3)
109
105
  * [name](#name)
110
106
  * [NodeModulesContentProvider](#nodemodulescontentprovider)
111
- * [Parameters](#parameters-4)
107
+ * [Parameters](#parameters-3)
112
108
  * [Properties](#properties-2)
113
109
  * [name](#name-1)
114
- * [NPMPackContentProvider](#npmpackcontentprovider)
115
- * [Parameters](#parameters-5)
116
- * [Properties](#properties-3)
110
+ * [FileContentProvider](#filecontentprovider)
111
+ * [Parameters](#parameters-4)
117
112
  * [name](#name-2)
118
113
  * [NFTContentProvider](#nftcontentprovider)
119
- * [Parameters](#parameters-6)
114
+ * [Parameters](#parameters-5)
120
115
  * [name](#name-3)
116
+ * [ContentProvider](#contentprovider)
117
+ * [Parameters](#parameters-6)
118
+ * [Properties](#properties-3)
119
+ * [asyncIterator](#asynciterator)
121
120
  * [hookMapping](#hookmapping)
122
121
  * [hookMapping](#hookmapping-1)
123
122
  * [DEBIAN](#debian)
@@ -127,16 +126,17 @@ See [mf-hosting](https://www.npmjs.com/package/mf-hosting) or [mf-hosting-fronte
127
126
  * [fields](#fields-1)
128
127
  * [fields](#fields-2)
129
128
  * [fields](#fields-3)
129
+ * [pkgKeyValuePairOptions](#pkgkeyvaluepairoptions)
130
130
  * [quoteFile](#quotefile)
131
131
  * [Parameters](#parameters-8)
132
132
  * [RPM](#rpm)
133
133
  * [prepare](#prepare-1)
134
134
  * [Parameters](#parameters-9)
135
- * [pkgKeyValuePairOptions](#pkgkeyvaluepairoptions)
136
135
  * [OCI](#oci)
137
136
  * [DOCKER](#docker)
138
137
  * [prepare](#prepare-2)
139
138
  * [Parameters](#parameters-10)
139
+ * [BUILDAH](#buildah)
140
140
  * [Packager](#packager)
141
141
  * [Parameters](#parameters-11)
142
142
  * [packageName](#packagename)
@@ -244,45 +244,20 @@ Extract package definition from package.json.
244
244
 
245
245
  Returns **AsyncIterable<[PackageDefinition](#packagedefinition)>**&#x20;
246
246
 
247
- ## BUILDAH
248
-
249
- **Extends DOCKER**
250
-
251
- Use buildah @see <https://buildah.io>
247
+ ## NPMPackContentProvider
252
248
 
253
- ## ContentProvider
249
+ **Extends ContentProvider**
254
250
 
255
- Source of package content.
251
+ Content from npm pack.
256
252
 
257
253
  ### Parameters
258
254
 
259
- * `definitions` &#x20;
260
- * `entryProperties` &#x20;
255
+ * `definitions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
256
+ * `entryProperties` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** to be set for each entry
261
257
 
262
258
  ### Properties
263
259
 
264
260
  * `dir` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
265
- * `transformer` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<Transformer>**&#x20;
266
-
267
- ### asyncIterator
268
-
269
- List all entries.
270
-
271
- Returns **AsyncIterable\<ContentEntry>** all entries
272
-
273
- ## FileContentProvider
274
-
275
- **Extends ContentProvider**
276
-
277
- Content provided form the file system.
278
-
279
- ### Parameters
280
-
281
- * `definitions` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))**&#x20;
282
-
283
- * `definitions.pattern` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)**&#x20;
284
- * `definitions.base` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** base directory where to find the files
285
- * `entryProperties` &#x20;
286
261
 
287
262
  ### name
288
263
 
@@ -308,20 +283,19 @@ Requires .npmrc or NPM\_TOKEN environment
308
283
 
309
284
  Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the content provider
310
285
 
311
- ## NPMPackContentProvider
286
+ ## FileContentProvider
312
287
 
313
288
  **Extends ContentProvider**
314
289
 
315
- Content from npm pack.
290
+ Content provided form the file system.
316
291
 
317
292
  ### Parameters
318
293
 
319
- * `definitions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
320
- * `entryProperties` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** to be set for each entry
321
-
322
- ### Properties
294
+ * `definitions` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))**&#x20;
323
295
 
324
- * `dir` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
296
+ * `definitions.pattern` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)**&#x20;
297
+ * `definitions.base` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** base directory where to find the files
298
+ * `entryProperties` &#x20;
325
299
 
326
300
  ### name
327
301
 
@@ -345,6 +319,26 @@ Content provided form the file system.
345
319
 
346
320
  Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the content provider
347
321
 
322
+ ## ContentProvider
323
+
324
+ Source of package content.
325
+
326
+ ### Parameters
327
+
328
+ * `definitions` &#x20;
329
+ * `entryProperties` &#x20;
330
+
331
+ ### Properties
332
+
333
+ * `dir` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
334
+ * `transformer` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<Transformer>**&#x20;
335
+
336
+ ### asyncIterator
337
+
338
+ List all entries.
339
+
340
+ Returns **AsyncIterable\<ContentEntry>** all entries
341
+
348
342
  ## hookMapping
349
343
 
350
344
  map install hook named from arch to deb
@@ -377,17 +371,21 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
377
371
 
378
372
  ## fields
379
373
 
380
- * **See**: <https://rpm-packaging-guide.github.io>
374
+ well known package properties
375
+ <https://www.archlinux.org/pacman/PKGBUILD.5.html>
381
376
 
382
377
  ## fields
383
378
 
384
- well known package properties
385
- <https://www.archlinux.org/pacman/PKGBUILD.5.html>
379
+ * **See**: <https://rpm-packaging-guide.github.io>
386
380
 
387
381
  ## fields
388
382
 
389
383
  * **See**: <https://docs.docker.com/engine/reference/builder/>
390
384
 
385
+ ## pkgKeyValuePairOptions
386
+
387
+ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
388
+
391
389
  ## quoteFile
392
390
 
393
391
  ### Parameters
@@ -413,10 +411,6 @@ Check for rpmbuild presence.
413
411
 
414
412
  Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>** true when rpmbuild executable is present
415
413
 
416
- ## pkgKeyValuePairOptions
417
-
418
- Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
419
-
420
414
  ## OCI
421
415
 
422
416
  **Extends Packager**
@@ -442,6 +436,12 @@ Check for docker presence.
442
436
 
443
437
  Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>** true when docker executable is present
444
438
 
439
+ ## BUILDAH
440
+
441
+ **Extends DOCKER**
442
+
443
+ Use buildah @see <https://buildah.io>
444
+
445
445
  ## Packager
446
446
 
447
447
  ### Parameters
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "17.2.5",
3
+ "version": "17.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": false
@@ -1,20 +1,20 @@
1
1
  import { join } from "node:path";
2
- import { createReadStream, createWriteStream } from "node:fs";
2
+ import { createWriteStream } from "node:fs";
3
3
  import { readFile } from "node:fs/promises";
4
- import { pipeline } from "node:stream/promises";
5
4
  import { execa } from "execa";
6
5
  import { ContentEntry, ReadableStreamContentEntry } from "content-entry";
7
- import {
8
- transform,
9
- createPropertiesInterceptor
10
- } from "content-entry-transform";
11
- import { iterableStringInterceptor } from "iterable-string-interceptor";
6
+ import { transform } from "content-entry-transform";
12
7
  import {
13
8
  keyValueTransformer,
14
9
  equalSeparatedKeyValuePairOptions
15
10
  } from "key-value-transformer";
16
11
  import { aggregateFifo } from "aggregate-async-iterator";
17
- import { Packager, VERSION_FIELD, DESCRIPTION_FIELD, NAME_FIELD } from "./packager.mjs";
12
+ import {
13
+ Packager,
14
+ VERSION_FIELD,
15
+ DESCRIPTION_FIELD,
16
+ NAME_FIELD
17
+ } from "./packager.mjs";
18
18
  import {
19
19
  copyEntries,
20
20
  fieldProvider,
@@ -125,6 +125,18 @@ export class ARCH extends Packager {
125
125
  }
126
126
  if (properties.hooks) {
127
127
  properties.install = `${properties.name}.install`;
128
+
129
+ const out = createWriteStream(
130
+ join(staging, properties.install),
131
+ utf8StreamOptions
132
+ );
133
+
134
+ for await (const hook of this.hookContent()) {
135
+ out.write(`${hook.name}() {\n`);
136
+ out.write(hook.string);
137
+ out.write(`}\n`);
138
+ }
139
+ out.end();
128
140
  }
129
141
 
130
142
  const self = this;
@@ -149,16 +161,6 @@ package() {
149
161
  properties.backup = properties.backup.replace(/\//, "");
150
162
  }
151
163
 
152
- if (properties.hooks) {
153
- await pipeline(
154
- iterableStringInterceptor(
155
- createReadStream(properties.hooks, utf8StreamOptions),
156
- createPropertiesInterceptor(properties)
157
- ),
158
- createWriteStream(join(staging, properties.install), utf8StreamOptions)
159
- );
160
- }
161
-
162
164
  const fp = fieldProvider(properties, fields);
163
165
 
164
166
  transformer.push({
@@ -1,12 +1,7 @@
1
1
  import { join } from "node:path";
2
- import { createReadStream } from "node:fs";
3
2
  import { readFile } from "node:fs/promises";
4
3
  import { execa } from "execa";
5
- import {
6
- ContentEntry,
7
- ReadableStreamContentEntry,
8
- StringContentEntry
9
- } from "content-entry";
4
+ import { ContentEntry, ReadableStreamContentEntry } from "content-entry";
10
5
  import {
11
6
  transform,
12
7
  createPropertiesTransformer
@@ -19,21 +14,7 @@ import {
19
14
  DESCRIPTION_FIELD,
20
15
  NAME_FIELD
21
16
  } from "./packager.mjs";
22
- import {
23
- copyEntries,
24
- fieldProvider,
25
- extractFunctions,
26
- utf8StreamOptions,
27
- compileFields
28
- } from "../util.mjs";
29
-
30
- /**
31
- * map install hook named from arch to deb
32
- */
33
- const hookMapping = {
34
- post_install: "DEBIAN/postinst",
35
- post_remove: "DEBIAN/postrm"
36
- };
17
+ import { copyEntries, fieldProvider, compileFields } from "../util.mjs";
37
18
 
38
19
  /**
39
20
  * Create .deb packages
@@ -84,24 +65,14 @@ export class DEBIAN extends Packager {
84
65
  return `${p.name}_${p.version}_${arch}${this.constructor.fileNameExtension}`;
85
66
  }
86
67
 
87
- async *hookFiles(properties) {
88
- if (properties.hooks) {
89
- for await (const f of extractFunctions(
90
- createReadStream(properties.hooks, utf8StreamOptions)
91
- )) {
92
- const name = hookMapping[f.name];
93
- if (name) {
94
- yield new StringContentEntry(
95
- name,
96
- f.body.replaceAll(
97
- /\{\{(\w+)\}\}/gm,
98
- (match, key, offset, string) =>
99
- properties[key] || "{{" + key + "}}"
100
- )
101
- );
102
- }
103
- }
104
- }
68
+ /**
69
+ * Map install hook named from default (arch) to deb.
70
+ */
71
+ get hookMapping() {
72
+ return {
73
+ post_install: "DEBIAN/postinst",
74
+ post_remove: "DEBIAN/postrm"
75
+ };
105
76
  }
106
77
 
107
78
  makeDepends(deps) {
@@ -145,7 +116,7 @@ export class DEBIAN extends Packager {
145
116
 
146
117
  for await (const file of copyEntries(
147
118
  transform(
148
- aggregateFifo([...sources, this.hookFiles(properties)]),
119
+ aggregateFifo([...sources, this.hookContent()]),
149
120
  transformer
150
121
  ),
151
122
  staging,
@@ -1,8 +1,14 @@
1
1
  import { join } from "node:path";
2
2
  import { tmpdir } from "node:os";
3
3
  import { mkdtemp, mkdir } from "node:fs/promises";
4
+ import { createReadStream } from "node:fs";
5
+ import { StringContentEntry } from "content-entry";
4
6
  import { publish } from "../publish.mjs";
5
- import { filterOutUnwantedDependencies } from "../util.mjs";
7
+ import {
8
+ filterOutUnwantedDependencies,
9
+ extractFunctions,
10
+ utf8StreamOptions
11
+ } from "../util.mjs";
6
12
 
7
13
  /**
8
14
  * @typedef {import('../publish.mjs').PublishingDetail} PublishingDetail
@@ -69,6 +75,46 @@ export class Packager {
69
75
  return mapping[name] || name;
70
76
  }
71
77
 
78
+ get hookMapping() {
79
+ return {};
80
+ }
81
+
82
+ async *hookContent() {
83
+ const properties = this.properties;
84
+
85
+ switch (properties.hooks) {
86
+ case "string":
87
+ for await (const f of extractFunctions(
88
+ createReadStream(properties.hooks, utf8StreamOptions)
89
+ )) {
90
+ const name = this.hookMapping[f.name] || f.name;
91
+ if (name) {
92
+ yield new StringContentEntry(
93
+ name,
94
+ f.body.replaceAll(
95
+ /\{\{(\w+)\}\}/gm,
96
+ (match, key, offset, string) =>
97
+ properties[key] || "{{" + key + "}}"
98
+ )
99
+ );
100
+ }
101
+ }
102
+ break;
103
+
104
+ case "object":
105
+ for (const [name, content] of Object.entries(properties.hooks)) {
106
+ yield new StringContentEntry(
107
+ name,
108
+ content.replaceAll(
109
+ /\{\{(\w+)\}\}/gm,
110
+ (match, key, offset, string) =>
111
+ properties[key] || "{{" + key + "}}"
112
+ )
113
+ );
114
+ }
115
+ }
116
+ }
117
+
72
118
  makeDepends(
73
119
  dependencies,
74
120
  exp = (name, expression) => `${name}${expression}`
@@ -10,7 +10,12 @@ import {
10
10
  colonSeparatedKeyValuePairOptionsDoublingKeys
11
11
  } from "key-value-transformer";
12
12
  import { aggregateFifo } from "aggregate-async-iterator";
13
- import { Packager, VERSION_FIELD, DESCRIPTION_FIELD, NAME_FIELD } from "./packager.mjs";
13
+ import {
14
+ Packager,
15
+ VERSION_FIELD,
16
+ DESCRIPTION_FIELD,
17
+ NAME_FIELD
18
+ } from "./packager.mjs";
14
19
  import {
15
20
  copyEntries,
16
21
  fieldProvider,
@@ -27,19 +32,6 @@ function quoteFile(name) {
27
32
  return name.match(/\s/) ? '"' + name + '"' : name;
28
33
  }
29
34
 
30
- /**
31
- * map install hook named from arch to rpm
32
- */
33
- const hookMapping = {
34
- pre_install: "pre",
35
- post_install: "post",
36
- pre_remove: "preun",
37
- post_remove: "postun"
38
- /* TODO with logic check $1
39
- pre_upgrade:
40
- post_upgrade:*/
41
- };
42
-
43
35
  /**
44
36
  * Produce rpm packages.
45
37
  */
@@ -108,6 +100,21 @@ export class RPM extends Packager {
108
100
  );
109
101
  }
110
102
 
103
+ /**
104
+ * Map install hook named from default (arch) to rpm.
105
+ */
106
+ get hookMapping() {
107
+ return {
108
+ pre_install: "pre",
109
+ post_install: "post",
110
+ pre_remove: "preun",
111
+ post_remove: "postun"
112
+ /* TODO with logic check $1
113
+ pre_upgrade:
114
+ post_upgrade:*/
115
+ };
116
+ }
117
+
111
118
  async create(sources, transformer, publishingDetails, options, expander) {
112
119
  const { properties, tmpdir, staging, destination } = await this.prepare(
113
120
  options
@@ -124,25 +131,14 @@ export class RPM extends Packager {
124
131
 
125
132
  const files = [];
126
133
 
134
+ const self = this;
127
135
  async function* trailingLines() {
128
136
  yield "%define _unpackaged_files_terminate_build 0\n";
129
137
  yield `%description\n\n`;
130
138
 
131
- if (properties.hooks) {
132
- for await (const f of extractFunctions(
133
- createReadStream(properties.hooks, utf8StreamOptions)
134
- )) {
135
- const name = hookMapping[f.name];
136
- if (name) {
137
- yield `%${name}\n`;
138
-
139
- yield f.body.replaceAll(
140
- /\{\{(\w+)\}\}/gm,
141
- (match, key, offset, string) =>
142
- properties[key] || "{{" + key + "}}"
143
- ) + "\n\n";
144
- }
145
- }
139
+ for await (const hook of self.hookContent()) {
140
+ yield `%${hook.name}\n`;
141
+ yield * hook.string.split("\n").map(l=>l+"\n");
146
142
  }
147
143
 
148
144
  yield `%files\n\n`;
@@ -15,9 +15,14 @@ export class DEBIAN extends Packager {
15
15
  arch: string;
16
16
  }): Promise<boolean>;
17
17
  get packageFileName(): string;
18
- hookFiles(properties: any): AsyncGenerator<StringContentEntry, void, unknown>;
18
+ /**
19
+ * Map install hook named from default (arch) to deb.
20
+ */
21
+ get hookMapping(): {
22
+ post_install: string;
23
+ post_remove: string;
24
+ };
19
25
  makeDepends(deps: any): string[];
20
26
  create(sources: any, transformer: any, publishingDetails: any, options: any, expander: any): Promise<string>;
21
27
  }
22
28
  import { Packager } from "./packager.mjs";
23
- import { StringContentEntry } from "content-entry";
@@ -38,6 +38,8 @@ export class Packager {
38
38
  * @return {string} package name in the target eco-system
39
39
  */
40
40
  packageName(name: string): string;
41
+ get hookMapping(): {};
42
+ hookContent(): AsyncGenerator<StringContentEntry, void, unknown>;
41
43
  makeDepends(dependencies: any, exp?: (name: any, expression: any) => string): string[];
42
44
  get fileNameExtension(): any;
43
45
  get fields(): any;
@@ -104,3 +106,4 @@ export type Field = {
104
106
  default: any;
105
107
  mandatory: boolean;
106
108
  };
109
+ import { StringContentEntry } from "content-entry";
@@ -23,6 +23,15 @@ export class RPM extends Packager {
23
23
  }): Promise<boolean>;
24
24
  get packageFileName(): string;
25
25
  makeDepends(deps: any): string[];
26
+ /**
27
+ * Map install hook named from default (arch) to rpm.
28
+ */
29
+ get hookMapping(): {
30
+ pre_install: string;
31
+ post_install: string;
32
+ pre_remove: string;
33
+ post_remove: string;
34
+ };
26
35
  create(sources: any, transformer: any, publishingDetails: any, options: any, expander: any): Promise<string>;
27
36
  }
28
37
  export type PublishingDetail = import("../publish.mjs").PublishingDetail;