npm-pkgbuild 7.7.1 → 7.8.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 +1 -1
- package/package.json +2 -2
- package/src/output/deb.mjs +3 -15
- package/src/output/pkg.mjs +6 -18
- package/src/output/rpm.mjs +10 -16
- package/src/util.mjs +35 -10
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-pkgbuild",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.8.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",
|
package/src/output/deb.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { execa } from "execa";
|
|
|
3
3
|
import { EmptyContentEntry, ReadableStreamContentEntry } from "content-entry";
|
|
4
4
|
import { keyValueTransformer } from "key-value-transformer";
|
|
5
5
|
import { Packager } from "./packager.mjs";
|
|
6
|
-
import { copyEntries, transform } from "../util.mjs";
|
|
6
|
+
import { copyEntries, transform, fieldProvider } from "../util.mjs";
|
|
7
7
|
|
|
8
8
|
const attributes = [{ pattern: /DEBIAN\/.*(inst|rm)/, mode: 0o775 }];
|
|
9
9
|
|
|
@@ -30,18 +30,7 @@ export class DEB extends Packager {
|
|
|
30
30
|
const mandatoryFields = this.mandatoryFields;
|
|
31
31
|
const staging = await this.tmpdir;
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
if (k === undefined) {
|
|
35
|
-
for (const p of mandatoryFields) {
|
|
36
|
-
if (!presentKeys.has(p)) {
|
|
37
|
-
const v = properties[p];
|
|
38
|
-
yield [p, v === undefined ? fields[p].default : v];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
yield [k, properties[k] || v];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
33
|
+
const fp = fieldProvider(properties, fields, mandatoryFields);
|
|
45
34
|
|
|
46
35
|
const debianControlName = "DEBIAN/control";
|
|
47
36
|
const transformers = [
|
|
@@ -50,7 +39,7 @@ export class DEB extends Packager {
|
|
|
50
39
|
transform: async entry =>
|
|
51
40
|
new ReadableStreamContentEntry(
|
|
52
41
|
entry.name,
|
|
53
|
-
keyValueTransformer(await entry.readStream,
|
|
42
|
+
keyValueTransformer(await entry.readStream, fp)
|
|
54
43
|
),
|
|
55
44
|
createEntryWhenMissing: () => new EmptyContentEntry(debianControlName)
|
|
56
45
|
}
|
|
@@ -59,7 +48,6 @@ export class DEB extends Packager {
|
|
|
59
48
|
await copyEntries(transform(sources, transformers), staging, expander, attributes);
|
|
60
49
|
|
|
61
50
|
const dpkg = await execa("dpkg", ["-b", staging, options.destination]);
|
|
62
|
-
//console.log(dpkg.stdout);
|
|
63
51
|
|
|
64
52
|
return join(options.destination, this.packageFileName);
|
|
65
53
|
}
|
package/src/output/pkg.mjs
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
equalSeparatedKeyValuePairOptions
|
|
7
7
|
} from "key-value-transformer";
|
|
8
8
|
import { Packager } from "./packager.mjs";
|
|
9
|
-
import { copyEntries, transform } from "../util.mjs";
|
|
10
|
-
import { quote,
|
|
9
|
+
import { copyEntries, transform, fieldProvider } from "../util.mjs";
|
|
10
|
+
import { quote, createExpressionTransformer } from "../util.mjs";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @type KeyValueTransformOptions
|
|
@@ -56,19 +56,6 @@ export class PKG extends Packager {
|
|
|
56
56
|
const mandatoryFields = this.mandatoryFields;
|
|
57
57
|
const staging = await this.tmpdir;
|
|
58
58
|
|
|
59
|
-
function* controlProperties(k, v, presentKeys) {
|
|
60
|
-
if (k === undefined) {
|
|
61
|
-
for (const p of mandatoryFields) {
|
|
62
|
-
if (!presentKeys.has(p)) {
|
|
63
|
-
const v = properties[p];
|
|
64
|
-
yield [p, v === undefined ? fields[p].default : v];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
yield [k, properties[k] || v];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
59
|
async function* trailingLines() {
|
|
73
60
|
yield `
|
|
74
61
|
package() {
|
|
@@ -77,16 +64,17 @@ package() {
|
|
|
77
64
|
`;
|
|
78
65
|
}
|
|
79
66
|
|
|
80
|
-
await copyEntries(transform(sources, []), join(staging, "src"), expander);
|
|
67
|
+
await copyEntries(transform(sources, [createExpressionTransformer(properties)]), join(staging, "src"), expander);
|
|
68
|
+
|
|
69
|
+
const fp = fieldProvider(properties, fields, mandatoryFields);
|
|
81
70
|
|
|
82
71
|
const metaTransformers = [
|
|
83
|
-
createPropertyTransformer(properties),
|
|
84
72
|
{
|
|
85
73
|
match: entry => entry.name === "PKGBUILD",
|
|
86
74
|
transform: async entry =>
|
|
87
75
|
new ReadableStreamContentEntry(
|
|
88
76
|
entry.name,
|
|
89
|
-
keyValueTransformer(await entry.readStream,
|
|
77
|
+
keyValueTransformer(await entry.readStream, fp, {
|
|
90
78
|
...pkgKeyValuePairOptions,
|
|
91
79
|
trailingLines
|
|
92
80
|
})
|
package/src/output/rpm.mjs
CHANGED
|
@@ -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 {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
colonSeparatedKeyValuePairOptions
|
|
8
8
|
} from "key-value-transformer";
|
|
9
9
|
import { Packager } from "./packager.mjs";
|
|
10
|
-
import { copyEntries, transform } from "../util.mjs";
|
|
10
|
+
import { copyEntries, transform, fieldProvider } from "../util.mjs";
|
|
11
11
|
|
|
12
12
|
export class RPM extends Packager {
|
|
13
13
|
static get name() {
|
|
@@ -40,18 +40,7 @@ export class RPM extends Packager {
|
|
|
40
40
|
|
|
41
41
|
const staging = join(tmp, "staging");
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
if (k === undefined) {
|
|
45
|
-
for (const p of mandatoryFields) {
|
|
46
|
-
if (!presentKeys.has(p)) {
|
|
47
|
-
const v = properties[p];
|
|
48
|
-
yield [p, v === undefined ? fields[p].default : v];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
yield [k, properties[k] || v];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
43
|
+
const fp = fieldProvider(properties, fields, mandatoryFields);
|
|
55
44
|
|
|
56
45
|
const specFileName = `${properties.name}.spec`;
|
|
57
46
|
|
|
@@ -67,7 +56,7 @@ export class RPM extends Packager {
|
|
|
67
56
|
transform: async entry =>
|
|
68
57
|
new ReadableStreamContentEntry(
|
|
69
58
|
entry.name,
|
|
70
|
-
keyValueTransformer(await entry.readStream,
|
|
59
|
+
keyValueTransformer(await entry.readStream, fp, {
|
|
71
60
|
...colonSeparatedKeyValuePairOptions,
|
|
72
61
|
trailingLines
|
|
73
62
|
})
|
|
@@ -78,7 +67,7 @@ export class RPM extends Packager {
|
|
|
78
67
|
|
|
79
68
|
await copyEntries(transform(sources, transformers), staging, expander);
|
|
80
69
|
|
|
81
|
-
await execa("rpmbuild", [
|
|
70
|
+
const rpmbuild = await execa("rpmbuild", [
|
|
82
71
|
"--define",
|
|
83
72
|
`_topdir ${tmp}`,
|
|
84
73
|
"-vv",
|
|
@@ -86,6 +75,11 @@ export class RPM extends Packager {
|
|
|
86
75
|
join(staging, specFileName)
|
|
87
76
|
]);
|
|
88
77
|
|
|
78
|
+
await cp(
|
|
79
|
+
join(tmp, "RPMS", properties.arch, this.packageFileName),
|
|
80
|
+
join(options.destination, this.packageFileName),
|
|
81
|
+
{ preserveTimestamps: true }
|
|
82
|
+
);
|
|
89
83
|
return join(options.destination, this.packageFileName);
|
|
90
84
|
}
|
|
91
85
|
}
|
package/src/util.mjs
CHANGED
|
@@ -3,6 +3,7 @@ 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";
|
|
7
8
|
import { packageWalker } from "npm-package-walker";
|
|
8
9
|
|
|
@@ -24,6 +25,24 @@ export function asArray(o) {
|
|
|
24
25
|
return Array.isArray(o) ? o : [o];
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
export function fieldProvider(properties, fields, mandatoryFields) {
|
|
29
|
+
return function* controlProperties(k, v, presentKeys) {
|
|
30
|
+
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}`);
|
|
36
|
+
}
|
|
37
|
+
yield [p, v === undefined ? fields[p].default : v];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
yield [k, properties[k] || v];
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
/**
|
|
28
47
|
* Extract package definition from package.json.
|
|
29
48
|
* @param {Object} pkg package.json content
|
|
@@ -32,7 +51,7 @@ export function asArray(o) {
|
|
|
32
51
|
*/
|
|
33
52
|
export async function extractFromPackage(pkg, dir) {
|
|
34
53
|
const properties = Object.fromEntries(
|
|
35
|
-
["name", "version", "description", "homepage"]
|
|
54
|
+
["name", "version", "description", "homepage", "license"]
|
|
36
55
|
.map(key => [key, pkg[key]])
|
|
37
56
|
.filter(([k, v]) => v !== undefined)
|
|
38
57
|
);
|
|
@@ -58,13 +77,13 @@ export async function extractFromPackage(pkg, dir) {
|
|
|
58
77
|
let dependencies = { ...pkg.engines };
|
|
59
78
|
let sources = [];
|
|
60
79
|
let output = {};
|
|
61
|
-
|
|
80
|
+
|
|
62
81
|
const processPkg = pkg => {
|
|
63
82
|
if (pkg.pkgbuild) {
|
|
64
83
|
const pkgbuild = pkg.pkgbuild;
|
|
65
84
|
|
|
66
85
|
Object.assign(output, pkgbuild.output);
|
|
67
|
-
|
|
86
|
+
|
|
68
87
|
Object.entries(pkgbuild)
|
|
69
88
|
.filter(([k, v]) => typeof v === "string")
|
|
70
89
|
.forEach(([k, v]) => (properties[k] = v));
|
|
@@ -81,7 +100,7 @@ export async function extractFromPackage(pkg, dir) {
|
|
|
81
100
|
};
|
|
82
101
|
|
|
83
102
|
await packageWalker(async (pkg, base, modulePath) => {
|
|
84
|
-
processPkg(pkg)
|
|
103
|
+
processPkg(pkg);
|
|
85
104
|
return true;
|
|
86
105
|
}, dir);
|
|
87
106
|
|
|
@@ -90,18 +109,25 @@ export async function extractFromPackage(pkg, dir) {
|
|
|
90
109
|
return { properties, sources, dependencies, output };
|
|
91
110
|
}
|
|
92
111
|
|
|
93
|
-
export function
|
|
112
|
+
export function createExpressionTransformer(
|
|
113
|
+
properties,
|
|
114
|
+
match = entry => entry.name.match(/\.(conf|json)$/)
|
|
115
|
+
) {
|
|
94
116
|
async function* transformer(expression, remainder, source, cb) {
|
|
95
|
-
|
|
96
|
-
|
|
117
|
+
const value = properties[expression];
|
|
118
|
+
console.log("EXPRESSION", expression, value);
|
|
119
|
+
yield value === undefined ? "" : value;
|
|
97
120
|
}
|
|
98
121
|
|
|
99
122
|
return {
|
|
100
|
-
match
|
|
123
|
+
match,
|
|
101
124
|
transform: async entry =>
|
|
102
125
|
new ReadableStreamContentEntry(
|
|
103
126
|
entry.name,
|
|
104
|
-
iterableStringInterceptor(
|
|
127
|
+
iterableStringInterceptor(
|
|
128
|
+
await entry.getReadStream(utf8StreamOptions),
|
|
129
|
+
transformer
|
|
130
|
+
)
|
|
105
131
|
)
|
|
106
132
|
};
|
|
107
133
|
}
|
|
@@ -170,7 +196,6 @@ export async function copyEntries(
|
|
|
170
196
|
}
|
|
171
197
|
}
|
|
172
198
|
|
|
173
|
-
console.log(destName);
|
|
174
199
|
await pipeline(
|
|
175
200
|
await entry.readStream,
|
|
176
201
|
createWriteStream(destName, options)
|