npm-pkgbuild 7.5.0 → 7.7.2

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
@@ -11,7 +11,7 @@
11
11
 
12
12
  ## npm-pkgbuild
13
13
 
14
- create ArchLinux packages from npm packages
14
+ create ArchLinux, RPM and debian packages from npm packages.
15
15
 
16
16
  # usage
17
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "7.5.0",
3
+ "version": "7.7.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -8,7 +8,7 @@
8
8
  "exports": {
9
9
  ".": "./src/module.mjs"
10
10
  },
11
- "description": "create packages from npm packages",
11
+ "description": "create ArchLinux, RPM and debian packages from npm packages",
12
12
  "keywords": [
13
13
  "ArchLinux",
14
14
  "arch-linux",
@@ -40,13 +40,14 @@
40
40
  "dependencies": {
41
41
  "aggregate-async-iterator": "^1.1.7",
42
42
  "commander": "^8.3.0",
43
- "content-entry": "^2.10.0",
44
- "content-entry-filesystem": "^3.1.11",
43
+ "content-entry": "^3.0.1",
44
+ "content-entry-filesystem": "^3.1.14",
45
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",
49
49
  "key-value-transformer": "^2.0.0",
50
+ "npm-package-walker": "^5.0.3",
50
51
  "npm-packlist": "^3.0.0",
51
52
  "pacote": "^12.0.2",
52
53
  "pkg-dir": "^6.0.1",
@@ -17,11 +17,11 @@ const { version, description } = JSON.parse(
17
17
 
18
18
  const cwd = process.cwd();
19
19
 
20
- const outputs = [DEB, PKG, RPM];
20
+ const allOutputs = [DEB, PKG, RPM];
21
21
 
22
22
  program.description(description).version(version);
23
23
 
24
- outputs.forEach(o =>
24
+ allOutputs.forEach(o =>
25
25
  program.option(`--${o.name}`, `generate ${o.name} package`)
26
26
  );
27
27
 
@@ -46,18 +46,21 @@ program
46
46
  )
47
47
  .action(async options => {
48
48
  try {
49
- for (const outputFactory of outputs.filter(
50
- o => options[o.name] === true
51
- )) {
52
- const { properties, sources } = extractFromPackage(
53
- JSON.parse(
54
- await readFile(
55
- join(await packageDirectory(), "package.json"),
56
- utf8StreamOptions
57
- )
49
+ const pkgDir = await packageDirectory();
50
+
51
+ const { properties, sources, output } = await extractFromPackage(
52
+ JSON.parse(
53
+ await readFile(
54
+ join(pkgDir, "package.json"),
55
+ utf8StreamOptions
58
56
  )
59
- );
57
+ ),
58
+ pkgDir
59
+ );
60
60
 
61
+ for (const outputFactory of allOutputs.filter(
62
+ o => options[o.name] === true || output[o.name] !== undefined
63
+ )) {
61
64
  Object.assign(properties, options.define);
62
65
 
63
66
  sources.push(
@@ -58,7 +58,8 @@ export class DEB extends Packager {
58
58
 
59
59
  await copyEntries(transform(sources, transformers), staging, expander, attributes);
60
60
 
61
- await execa("dpkg", ["-b", staging, options.destination]);
61
+ const dpkg = await execa("dpkg", ["-b", staging, options.destination]);
62
+ //console.log(dpkg.stdout);
62
63
 
63
64
  return join(options.destination, this.packageFileName);
64
65
  }
@@ -81,7 +82,7 @@ const fields = {
81
82
  Architecture: {
82
83
  alias: "arch",
83
84
  type: "string",
84
- default: "any",
85
+ default: "all",
85
86
  mandatory: true
86
87
  },
87
88
  Homepage: { alias: "homepage", type: "string" },
@@ -2,15 +2,14 @@ import { join } from "path";
2
2
  import { tmpdir } from "os";
3
3
  import { mkdtemp } from "fs/promises";
4
4
 
5
-
6
5
  /**
7
6
  * @typedef {Object} Field
8
7
  * @property {string} alias interchangeable field name
9
8
  * @property {string} type
10
9
  * @property {any} default
11
- * @property {boolean} mandatory
10
+ * @property {boolean} mandatory
12
11
  */
13
-
12
+
14
13
  /**
15
14
  * @param {Object} properties
16
15
  */
@@ -61,13 +60,12 @@ export class Packager {
61
60
  * Create tmp directory.
62
61
  * @return {Promise<string>} directory path
63
62
  */
64
- get tmpdir()
65
- {
63
+ get tmpdir() {
66
64
  return mkdtemp(join(tmpdir(), this.constructor.name));
67
65
  }
68
66
 
69
67
  /**
70
68
  * Execute package generation
71
69
  */
72
- async execute(sources,options) {}
70
+ async execute(sources, options) {}
73
71
  }
@@ -7,7 +7,7 @@ import {
7
7
  } from "key-value-transformer";
8
8
  import { Packager } from "./packager.mjs";
9
9
  import { copyEntries, transform } from "../util.mjs";
10
- import { quote } from "../util.mjs";
10
+ import { quote, createExpressionTransformer } from "../util.mjs";
11
11
 
12
12
  /**
13
13
  * @type KeyValueTransformOptions
@@ -45,10 +45,10 @@ export class PKG extends Packager {
45
45
 
46
46
  get packageFileName() {
47
47
  const p = this.properties;
48
- return `${p.name}-${p.version}-${p.release}.${p.arch}${this.constructor.fileNameExtension}`;
48
+ return `${p.name}-${p.version}-${p.release}-${p.arch}${this.constructor.fileNameExtension}`;
49
49
  }
50
50
 
51
- async execute(sources, options,expander) {
51
+ async execute(sources, options, expander) {
52
52
  const properties = this.properties;
53
53
 
54
54
  //properties.depends = makeDepends({ ...pkg.engines });
@@ -77,7 +77,7 @@ package() {
77
77
  `;
78
78
  }
79
79
 
80
- await copyEntries(transform(sources, []), join(staging, "src"), expander);
80
+ await copyEntries(transform(sources, [createExpressionTransformer(properties)]), join(staging, "src"), expander);
81
81
 
82
82
  const metaTransformers = [
83
83
  {
@@ -94,9 +94,16 @@ package() {
94
94
  }
95
95
  ];
96
96
 
97
- await copyEntries(transform(sources, metaTransformers, true), staging, expander);
97
+ await copyEntries(
98
+ transform(sources, metaTransformers, true),
99
+ staging,
100
+ expander
101
+ );
98
102
 
99
- await execa("makepkg", ["-f"], { cwd: staging });
103
+ await execa("makepkg", ["-f"], {
104
+ cwd: staging,
105
+ env: { PKGDEST: options.destination }
106
+ });
100
107
 
101
108
  return join(options.destination, this.packageFileName);
102
109
  }
@@ -1,5 +1,5 @@
1
1
  import { join } from "path";
2
- import { mkdir } from "fs/promises";
2
+ import { mkdir, cp } from "fs/promises";
3
3
  import { execa } from "execa";
4
4
  import { EmptyContentEntry, ReadableStreamContentEntry } from "content-entry";
5
5
  import {
@@ -78,7 +78,7 @@ export class RPM extends Packager {
78
78
 
79
79
  await copyEntries(transform(sources, transformers), staging, expander);
80
80
 
81
- await execa("rpmbuild", [
81
+ const rpmbuild = await execa("rpmbuild", [
82
82
  "--define",
83
83
  `_topdir ${tmp}`,
84
84
  "-vv",
@@ -86,6 +86,11 @@ export class RPM extends Packager {
86
86
  join(staging, specFileName)
87
87
  ]);
88
88
 
89
+ await cp(
90
+ join(tmp, "RPMS", properties.arch, this.packageFileName),
91
+ join(options.destination, this.packageFileName),
92
+ {preserveTimestamps :true }
93
+ );
89
94
  return join(options.destination, this.packageFileName);
90
95
  }
91
96
  }
package/src/util.mjs CHANGED
@@ -2,8 +2,10 @@ import { join, dirname } from "path";
2
2
  import { mkdir } from "fs/promises";
3
3
  import { pipeline } from "stream/promises";
4
4
  import { createWriteStream } from "fs";
5
-
5
+ import { iterableStringInterceptor } from "iterable-string-interceptor";
6
+ import { ReadableStreamContentEntry } from "content-entry";
6
7
  import { FileContentProvider } from "npm-pkgbuild";
8
+ import { packageWalker } from "npm-package-walker";
7
9
 
8
10
  export const utf8StreamOptions = { encoding: "utf8" };
9
11
 
@@ -26,9 +28,10 @@ export function asArray(o) {
26
28
  /**
27
29
  * Extract package definition from package.json.
28
30
  * @param {Object} pkg package.json content
31
+ * @param {string} dir
29
32
  * @returns {Object}
30
33
  */
31
- export function extractFromPackage(pkg) {
34
+ export async function extractFromPackage(pkg, dir) {
32
35
  const properties = Object.fromEntries(
33
36
  ["name", "version", "description", "homepage"]
34
37
  .map(key => [key, pkg[key]])
@@ -55,30 +58,64 @@ export function extractFromPackage(pkg) {
55
58
 
56
59
  let dependencies = { ...pkg.engines };
57
60
  let sources = [];
61
+ let output = {};
62
+
63
+ const processPkg = pkg => {
64
+ if (pkg.pkgbuild) {
65
+ const pkgbuild = pkg.pkgbuild;
66
+
67
+ Object.assign(output, pkgbuild.output);
68
+
69
+ Object.entries(pkgbuild)
70
+ .filter(([k, v]) => typeof v === "string")
71
+ .forEach(([k, v]) => (properties[k] = v));
72
+
73
+ if (pkgbuild.content) {
74
+ sources = Object.entries(pkgbuild.content).map(
75
+ ([destination, value]) =>
76
+ new FileContentProvider(value, { destination })
77
+ );
78
+ }
58
79
 
59
- if (pkg.pkgbuild) {
60
- const pkgbuild = pkg.pkgbuild;
61
- Object.entries(pkgbuild)
62
- .filter(([k, v]) => typeof v === "string")
63
- .forEach(([k, v]) => (properties[k] = v));
64
-
65
- if (pkgbuild.content) {
66
- sources = Object.entries(pkgbuild.content).map(
67
- ([destination, value]) =>
68
- new FileContentProvider(value, { destination })
69
- );
80
+ Object.assign(dependencies, pkgbuild.depends);
70
81
  }
82
+ };
83
+
84
+ await packageWalker(async (pkg, base, modulePath) => {
85
+ processPkg(pkg);
86
+ return true;
87
+ }, dir);
88
+
89
+ processPkg(pkg);
90
+
91
+ return { properties, sources, dependencies, output };
92
+ }
71
93
 
72
- Object.assign(dependencies, pkgbuild.depends);
94
+ export function createExpressionTransformer(properties) {
95
+ async function* transformer(expression, remainder, source, cb) {
96
+ const value = properties[expression];
97
+ console.log("EXPRESSION", expression, value);
98
+ yield value === undefined ? "" : value;
73
99
  }
74
100
 
75
- return { properties, sources, dependencies };
101
+ return {
102
+ match: entry => true, //entry.name.match(/(conf|json)$/),
103
+ transform: async entry =>
104
+ new ReadableStreamContentEntry(
105
+ entry.name,
106
+ iterableStringInterceptor(
107
+ await entry.getReadStream(utf8StreamOptions),
108
+ transformer
109
+ )
110
+ )
111
+ };
76
112
  }
77
113
 
78
114
  /**
79
- * Apply transformers
115
+ * Apply transformers.
80
116
  * @param {AsyncIterator<ContentEntry>} source
81
117
  * @param {Transformer[]} transformers
118
+ * @param {Boolean]} onlyMatching filter out all none matching entries
82
119
  */
83
120
  export async function* transform(source, transformers = [], onlyMatching) {
84
121
  const usedTransformers = new Set();