npm-pkgbuild 20.3.0 → 20.4.1

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
@@ -143,6 +143,7 @@ See [mf-hosting](https://www.npmjs.com/package/mf-hosting) or [mf-hosting-fronte
143
143
  * [Parameters](#parameters-11)
144
144
  * [packageName](#packagename)
145
145
  * [Parameters](#parameters-12)
146
+ * [hookContent](#hookcontent)
146
147
  * [dependencyExpression](#dependencyexpression)
147
148
  * [Parameters](#parameters-13)
148
149
  * [tmpdir](#tmpdir)
@@ -157,6 +158,7 @@ See [mf-hosting](https://www.npmjs.com/package/mf-hosting) or [mf-hosting-fronte
157
158
  * [Parameters](#parameters-17)
158
159
  * [packageName](#packagename-1)
159
160
  * [Parameters](#parameters-18)
161
+ * [hookContent](#hookcontent-1)
160
162
  * [dependencyExpression](#dependencyexpression-1)
161
163
  * [Parameters](#parameters-19)
162
164
  * [tmpdir](#tmpdir-1)
@@ -480,9 +482,15 @@ What is the package name in the package eco-system.
480
482
 
481
483
  Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** package name in the target eco-system
482
484
 
485
+ ### hookContent
486
+
487
+ Generate hook content entries
488
+
489
+ Returns **AsyncIterable\<ContentEntry>**&#x20;
490
+
483
491
  ### dependencyExpression
484
492
 
485
- forms an expression string form name and expression.
493
+ Forms an expression string form name and expression.
486
494
  If tere is no valid exression name only is delivered.
487
495
 
488
496
  #### Parameters
@@ -557,9 +565,15 @@ What is the package name in the package eco-system.
557
565
 
558
566
  Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** package name in the target eco-system
559
567
 
568
+ ### hookContent
569
+
570
+ Generate hook content entries
571
+
572
+ Returns **AsyncIterable\<ContentEntry>**&#x20;
573
+
560
574
  ### dependencyExpression
561
575
 
562
- forms an expression string form name and expression.
576
+ Forms an expression string form name and expression.
563
577
  If tere is no valid exression name only is delivered.
564
578
 
565
579
  #### Parameters
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "20.3.0",
3
+ "version": "20.4.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": false
@@ -66,7 +66,7 @@
66
66
  "key-value-transformer": "^3.3.1",
67
67
  "npm-package-walker": "^8.0.11",
68
68
  "npm-packlist": "^10.0.3",
69
- "pacc": "^8.6.2",
69
+ "pacc": "^8.7.0",
70
70
  "package-directory": "^8.2.0",
71
71
  "pacote": "^21.1.0",
72
72
  "tar-stream": "^3.1.7",
@@ -1,7 +1,11 @@
1
1
  import { join } from "node:path";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import { execa } from "execa";
4
- import { integer_attribute_writable, yesno_attribute_writable, string_attribute_writable } from "pacc";
4
+ import {
5
+ integer_attribute_writable,
6
+ yesno_attribute_writable,
7
+ string_attribute_writable
8
+ } from "pacc";
5
9
  import { ContentEntry, IteratorContentEntry } from "content-entry";
6
10
  import {
7
11
  transform,
@@ -18,12 +22,13 @@ import {
18
22
  } from "./packager.mjs";
19
23
  import { copyEntries, fieldProvider } from "../util.mjs";
20
24
 
21
- const debian_dependency_attribute_collection_writable =
22
- {
25
+ const debian_dependency_attribute_collection_writable = {
23
26
  ...dependency_attribute_collection_writable,
24
27
  separator: ","
25
28
  };
26
29
 
30
+ const CONTROL_NAME = "DEBIAN/control";
31
+
27
32
  /**
28
33
  * Create .deb packages
29
34
  */
@@ -50,7 +55,11 @@ export class DEBIAN extends Packager {
50
55
  set: v => v.toLowerCase()
51
56
  },
52
57
  Version: pkgbuild_version_attribute,
53
- Maintainer: { ...string_attribute_writable, alias: "maintainer", mandatory: true },
58
+ Maintainer: {
59
+ ...string_attribute_writable,
60
+ alias: "maintainer",
61
+ mandatory: true
62
+ },
54
63
  Description: pkgbuild_description_attribute,
55
64
  Section: { ...string_attribute_writable, alias: "groups" },
56
65
  Priority: string_attribute_writable,
@@ -129,9 +138,11 @@ export class DEBIAN extends Packager {
129
138
  async create(sources, transformer, publishingDetails, options, expander) {
130
139
  const { properties, staging, destination } = await this.prepare(options);
131
140
 
141
+ const hooks = new Set(Object.values(this.hookMapping));
142
+
132
143
  transformer.push(
133
144
  createPropertiesTransformer(
134
- entry => (entry.name.match(/DEBIAN\/.*(inst|rm)/) ? true : false),
145
+ entry => hooks.has(entry.name),
135
146
  { mode: { value: 0o775 } },
136
147
  "mode"
137
148
  )
@@ -143,17 +154,16 @@ export class DEBIAN extends Packager {
143
154
  }
144
155
 
145
156
  const fp = fieldProvider(properties, this.attributes);
146
- const debianControlName = "DEBIAN/control";
147
157
 
148
158
  transformer.push({
149
- match: entry => entry.name === debianControlName,
159
+ match: entry => entry.name === CONTROL_NAME,
150
160
  transform: async entry =>
151
161
  new IteratorContentEntry(
152
162
  entry.name,
153
163
  undefined,
154
164
  keyValueTransformer(Uint8ArraysToLines(await entry.readStream), fp)
155
165
  ),
156
- createEntryWhenMissing: () => new ContentEntry(debianControlName)
166
+ createEntryWhenMissing: () => new ContentEntry(CONTROL_NAME)
157
167
  });
158
168
 
159
169
  for await (const file of copyEntries(
@@ -168,7 +178,7 @@ export class DEBIAN extends Packager {
168
178
  }
169
179
 
170
180
  if (options.verbose) {
171
- console.log(await readFile(join(staging, debianControlName), "utf8"));
181
+ console.log(await readFile(join(staging, CONTROL_NAME), "utf8"));
172
182
  }
173
183
 
174
184
  if (!options.dry) {
@@ -3,6 +3,8 @@ import { tmpdir } from "node:os";
3
3
  import { mkdtemp, mkdir } from "node:fs/promises";
4
4
  import { createReadStream } from "node:fs";
5
5
  import {
6
+ expand,
7
+ expandContextDoubbleCurly,
6
8
  string_attribute,
7
9
  description_attribute,
8
10
  version_attribute_writable
@@ -82,9 +84,20 @@ export class Packager {
82
84
  return {};
83
85
  }
84
86
 
87
+ /**
88
+ * Generate hook content entries
89
+ * @return {AsyncIterable<ContentEntry>}
90
+ */
85
91
  async *hookContent() {
86
92
  const properties = this.properties;
87
93
 
94
+ const context = {
95
+ ...expandContextDoubbleCurly,
96
+ root: properties
97
+ };
98
+
99
+ const entryProps = { mode: 0o775 };
100
+
88
101
  switch (typeof properties.hooks) {
89
102
  case "string":
90
103
  for await (const f of extractFunctions(
@@ -94,12 +107,8 @@ export class Packager {
94
107
  if (name) {
95
108
  yield new StringContentEntry(
96
109
  name,
97
- undefined,
98
- f.body.replaceAll(
99
- /\{\{(\w+)\}\}/gm,
100
- (match, key, offset, string) =>
101
- properties[key] || "{{" + key + "}}"
102
- )
110
+ entryProps,
111
+ expand(f.body, context)
103
112
  );
104
113
  }
105
114
  }
@@ -108,20 +117,16 @@ export class Packager {
108
117
  case "object":
109
118
  for (const [name, content] of Object.entries(properties.hooks)) {
110
119
  yield new StringContentEntry(
111
- name,
112
- undefined,
113
- content.replaceAll(
114
- /\{\{(\w+)\}\}/gm,
115
- (match, key, offset, string) =>
116
- properties[key] || "{{" + key + "}}"
117
- )
120
+ this.hookMapping[name] || name,
121
+ entryProps,
122
+ expand(content, context)
118
123
  );
119
124
  }
120
125
  }
121
126
  }
122
127
 
123
128
  /**
124
- * forms an expression string form name and expression.
129
+ * Forms an expression string form name and expression.
125
130
  * If tere is no valid exression name only is delivered.
126
131
  * @param {string} name
127
132
  * @param {string|boolean|undefined} expression
@@ -290,10 +295,9 @@ export const dependency_type = {
290
295
  return value;
291
296
  }
292
297
 
293
- return Object.entries(value)
294
- .map(([name, expression]) =>
295
- typeof expression === "string" ? `${name}${expression}` : name
296
- );
298
+ return Object.entries(value).map(([name, expression]) =>
299
+ typeof expression === "string" ? `${name}${expression}` : name
300
+ );
297
301
  }
298
302
  };
299
303
 
@@ -39,9 +39,13 @@ export class Packager {
39
39
  */
40
40
  packageName(name: string): string;
41
41
  get hookMapping(): {};
42
- hookContent(): AsyncGenerator<StringContentEntry, void, unknown>;
43
42
  /**
44
- * forms an expression string form name and expression.
43
+ * Generate hook content entries
44
+ * @return {AsyncIterable<ContentEntry>}
45
+ */
46
+ hookContent(): AsyncIterable<ContentEntry>;
47
+ /**
48
+ * Forms an expression string form name and expression.
45
49
  * If tere is no valid exression name only is delivered.
46
50
  * @param {string} name
47
51
  * @param {string|boolean|undefined} expression
@@ -200,4 +204,3 @@ export type Field = {
200
204
  default: any;
201
205
  mandatory: boolean;
202
206
  };
203
- import { StringContentEntry } from "content-entry";