npm-pkgbuild 7.3.0 → 7.3.4

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.3.0",
3
+ "version": "7.3.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -40,9 +40,9 @@
40
40
  "dependencies": {
41
41
  "aggregate-async-iterator": "^1.1.7",
42
42
  "commander": "^8.3.0",
43
- "content-entry": "^2.7.1",
44
- "content-entry-filesystem": "^3.0.1",
45
- "execa": "^5.1.1",
43
+ "content-entry": "^2.9.6",
44
+ "content-entry-filesystem": "^3.1.9",
45
+ "execa": "^6.0.0",
46
46
  "expression-expander": "^7.0.9",
47
47
  "globby": "^12.0.2",
48
48
  "iterable-string-interceptor": "^1.0.8",
@@ -55,11 +55,11 @@
55
55
  "ava": "^3.15.0",
56
56
  "c8": "^7.10.0",
57
57
  "documentation": "^13.2.5",
58
- "semantic-release": "^18.0.0",
58
+ "semantic-release": "^18.0.1",
59
59
  "stream-buffers": "^3.0.2"
60
60
  },
61
61
  "engines": {
62
- "node": ">=16.12.0"
62
+ "node": ">=16.13.0"
63
63
  },
64
64
  "repository": {
65
65
  "type": "git",
@@ -1,3 +1,4 @@
1
+ import { dirname } from "path";
1
2
  import { globby } from "globby";
2
3
  import { FileSystemEntry } from "content-entry-filesystem";
3
4
  import { asArray } from "../util.mjs";
@@ -10,13 +11,20 @@ export class FileContentProvider extends ContentProvider {
10
11
  constructor(definitions) {
11
12
  super();
12
13
 
13
- this.definitions = { pattern: ["**/*"], ...definitions };
14
- this.definitions.pattern = asArray(this.definitions.pattern);
14
+ if (typeof definitions === "string") {
15
+ const base = dirname(definitions);
16
+ this.definitions = {
17
+ base,
18
+ pattern: [definitions.substring(base.length)]
19
+ };
20
+ } else {
21
+ this.definitions = { pattern: ["**/*"], ...definitions };
22
+ this.definitions.pattern = asArray(this.definitions.pattern);
23
+ }
15
24
  }
16
25
 
17
- async *entries() {
26
+ async *[Symbol.asyncIterator]() {
18
27
  const definitions = this.definitions;
19
-
20
28
  const base = definitions.base;
21
29
 
22
30
  for (const name of await globby(definitions.pattern, {
@@ -26,7 +26,7 @@ outputs.forEach(o =>
26
26
 
27
27
  program
28
28
  .option("--pkgver <version>", "package version")
29
- .option("-p --package <dir>", "where to put the package(s)", cwd)
29
+ .option("-d --destination <dir>", "where to put the package(s)", cwd)
30
30
  .option("-s --staging <dir>", "staging directory", "build")
31
31
  .option(
32
32
  "-c --content <dir>",
@@ -45,7 +45,7 @@ program
45
45
  for (const outputFactory of outputs.filter(
46
46
  o => options[o.name] === true
47
47
  )) {
48
- const { properties, content } = extractFromPackage(
48
+ const { properties, sources } = extractFromPackage(
49
49
  JSON.parse(
50
50
  await readFile(
51
51
  join(await packageDirectory(), "package.json"),
@@ -54,17 +54,23 @@ program
54
54
  )
55
55
  );
56
56
 
57
- const sources = [...options.content, ...options.meta]
58
- .filter(x => x)
59
- .map(source =>
60
- new FileContentProvider({
61
- base: source
62
- }).entries()
63
- );
57
+ sources.push(
58
+ ...[...options.content, ...options.meta]
59
+ .filter(x => x)
60
+ .map(source => [
61
+ new FileContentProvider({
62
+ base: source
63
+ }),
64
+ ""
65
+ ])
66
+ );
64
67
 
65
- const output = new outputFactory(aggregateFifo(sources), properties);
68
+ const output = new outputFactory(
69
+ aggregateFifo(sources.map(([c, d]) => c.entries())),
70
+ properties
71
+ );
66
72
 
67
- const fileName = await output.execute();
73
+ const fileName = await output.execute(options);
68
74
 
69
75
  console.log(fileName);
70
76
  }
@@ -3,16 +3,18 @@ import { tmpdir } from "os";
3
3
  import { createWriteStream } from "fs";
4
4
  import { mkdtemp, mkdir, chmod } from "fs/promises";
5
5
  import { pipeline } from "stream/promises";
6
- import execa from "execa";
6
+ import { execa } from "execa";
7
7
  import { EmptyContentEntry } from "content-entry";
8
8
  import { Packager } from "./packager.mjs";
9
9
  import { keyValueTransformer } from "../key-value-transformer.mjs";
10
10
 
11
+ const executableAttributes = { chmod: "0775" };
12
+
11
13
  const permissions = {
12
- "DEBIAN/preinst": { chmod: "0775" },
13
- "DEBIAN/postinst": { chmod: "0775" },
14
- "DEBIAN/prerm": { chmod: "0775" },
15
- "DEBIAN/postrm": { chmod: "0775" }
14
+ "DEBIAN/preinst": executableAttributes,
15
+ "DEBIAN/postinst": executableAttributes,
16
+ "DEBIAN/prerm": executableAttributes,
17
+ "DEBIAN/postrm": executableAttributes
16
18
  };
17
19
 
18
20
  export class Deb extends Packager {
@@ -24,7 +26,11 @@ export class Deb extends Packager {
24
26
  return ".deb";
25
27
  }
26
28
 
27
- async execute() {
29
+ get packageFileName() {
30
+ return `${this.properties.name}_${this.properties.version}_${this.properties.arch}${this.constructor.fileNameExtension}`;
31
+ }
32
+
33
+ async execute(options) {
28
34
  const properties = this.properties;
29
35
 
30
36
  Object.entries(fields).forEach(([k, v]) => {
@@ -32,6 +38,11 @@ export class Deb extends Packager {
32
38
  if (e !== undefined) {
33
39
  properties[k] = e;
34
40
  }
41
+ else {
42
+ if(v.default !== undefined) {
43
+ properties[v.alias] = v.default;
44
+ }
45
+ }
35
46
  });
36
47
 
37
48
  const tmp = await mkdtemp(join(tmpdir(), "deb-"));
@@ -56,8 +67,6 @@ export class Deb extends Packager {
56
67
  }
57
68
  }
58
69
 
59
- const output = `${staging}${this.constructor.fileNameExtension}`;
60
-
61
70
  let debianControlEntry;
62
71
 
63
72
  for await (const entry of this.source) {
@@ -68,10 +77,8 @@ export class Deb extends Packager {
68
77
  if (entry.name === "DEBIAN/control") {
69
78
  debianControlEntry = entry;
70
79
  } else {
71
- await pipeline(
72
- await entry.getReadStream(),
73
- createWriteStream(destName)
74
- );
80
+ console.log("ENTRY", entry.name, entry.basename);
81
+ await pipeline(await entry.readStream, createWriteStream(destName));
75
82
 
76
83
  await Promise.all(
77
84
  Object.entries(permissions).map(async ([pattern, option]) => {
@@ -94,15 +101,15 @@ export class Deb extends Packager {
94
101
 
95
102
  await pipeline(
96
103
  keyValueTransformer(
97
- await debianControlEntry.getReadStream(),
104
+ await debianControlEntry.readStream,
98
105
  controlProperties
99
106
  ),
100
107
  createWriteStream(destName)
101
108
  );
102
109
 
103
- await execa("dpkg", ["-b", staging]);
110
+ await execa("dpkg", ["-b", staging, options.destination]);
104
111
 
105
- return output;
112
+ return join(options.destination, this.packageFileName);
106
113
  }
107
114
  }
108
115
 
@@ -120,7 +127,7 @@ const fields = {
120
127
  Priority: { type: "string", recommended: true },
121
128
  Essential: { type: "boolean" },
122
129
  Origin: { type: "string" },
123
- Architecture: { type: "string", default: "any", mandatory: true },
130
+ Architecture: { alias: "arch", type: "string", default: "any", mandatory: true },
124
131
  Homepage: { alias: "homepage", type: "string" },
125
132
  Bugs: { alias: "bugs", type: "string" },
126
133
  Depends: { alias: "depends", type: "packageList" },
@@ -3,7 +3,7 @@ import { tmpdir } from "os";
3
3
  import { finished } from "stream";
4
4
  import { promisify } from "util";
5
5
  import { mkdtemp, mkdir, chmod } from "fs/promises";
6
- import execa from "execa";
6
+ import execa } from "execa";
7
7
  import { Packager } from "./packager.mjs";
8
8
  import { quote } from "../util.mjs";
9
9
 
package/src/util.mjs CHANGED
@@ -1,6 +1,7 @@
1
- export const utf8StreamOptions = { encoding: "utf8" };
2
1
  import { FileContentProvider } from "npm-pkgbuild";
3
2
 
3
+ export const utf8StreamOptions = { encoding: "utf8" };
4
+
4
5
  export function quote(v) {
5
6
  if (v === undefined) return "";
6
7
 
@@ -20,7 +21,7 @@ export function asArray(o) {
20
21
  /**
21
22
  *
22
23
  * @param {Object} pkg package.json content
23
- * @returns
24
+ * @returns {Object}
24
25
  */
25
26
  export function extractFromPackage(pkg) {
26
27
  const properties = Object.fromEntries(
@@ -43,20 +44,19 @@ export function extractFromPackage(pkg) {
43
44
  )[0];
44
45
  }
45
46
 
46
- const content = [];
47
+ let sources = [];
47
48
 
48
49
  if (pkg.pkgbuild) {
49
50
  Object.entries(pkg.pkgbuild)
50
- .filter(([k, v]) => typeof v === "string")
51
- .forEach(([k, v]) => (properties[k] = v));
51
+ .filter(([k, v]) => typeof v === "string")
52
+ .forEach(([k, v]) => (properties[k] = v));
52
53
 
53
54
  if (pkg.pkgbuild.content) {
54
- for (const [name, value] of Object.entries(pkg.pkgbuild.content)) {
55
- content.push(new FileContentProvider(value));
56
- }
55
+ sources = Object.entries(pkg.pkgbuild.content).map(
56
+ ([destination, value]) => [new FileContentProvider(value), destination]
57
+ );
57
58
  }
58
-
59
59
  }
60
60
 
61
- return { properties, content };
61
+ return { properties, sources };
62
62
  }