npm-pkgbuild 7.3.5 → 7.3.6
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 +2 -1
- package/src/module.mjs +2 -1
- package/src/output/deb.mjs +25 -25
- package/src/output/packager.mjs +53 -1
- package/src/output/pkg.mjs +50 -44
- package/src/output/rpm.mjs +40 -18
- package/src/util.mjs +27 -0
- package/src/key-value-transformer.mjs +0 -62
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-pkgbuild",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"expression-expander": "^7.0.9",
|
|
47
47
|
"globby": "^12.0.2",
|
|
48
48
|
"iterable-string-interceptor": "^1.0.8",
|
|
49
|
+
"key-value-transformer": "^1.0.0",
|
|
49
50
|
"npm-packlist": "^3.0.0",
|
|
50
51
|
"pacote": "^12.0.2",
|
|
51
52
|
"pkg-dir": "^6.0.1",
|
package/src/module.mjs
CHANGED
|
@@ -6,4 +6,5 @@ export * from "./content/node-modules-content-provider.mjs";
|
|
|
6
6
|
export * from "./content/npm-pack-content-provider.mjs";
|
|
7
7
|
export * from "./output/deb.mjs";
|
|
8
8
|
export * from "./output/rpm.mjs";
|
|
9
|
-
export * from "./output/pkg.mjs";
|
|
9
|
+
export * from "./output/pkg.mjs";
|
|
10
|
+
export * from "./output/packager.mjs";
|
package/src/output/deb.mjs
CHANGED
|
@@ -5,8 +5,8 @@ import { mkdtemp, mkdir, chmod } from "fs/promises";
|
|
|
5
5
|
import { pipeline } from "stream/promises";
|
|
6
6
|
import { execa } from "execa";
|
|
7
7
|
import { EmptyContentEntry } from "content-entry";
|
|
8
|
+
import { keyValueTransformer } from "key-value-transformer";
|
|
8
9
|
import { Packager } from "./packager.mjs";
|
|
9
|
-
import { keyValueTransformer } from "../key-value-transformer.mjs";
|
|
10
10
|
|
|
11
11
|
const executableAttributes = { chmod: "0775" };
|
|
12
12
|
|
|
@@ -26,37 +26,23 @@ export class DEB extends Packager {
|
|
|
26
26
|
return ".deb";
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
static get fields() {
|
|
30
|
+
return fields;
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
get packageFileName() {
|
|
30
34
|
return `${this.properties.name}_${this.properties.version}_${this.properties.arch}${this.constructor.fileNameExtension}`;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
async execute(options) {
|
|
34
38
|
const properties = this.properties;
|
|
35
|
-
|
|
36
|
-
Object.entries(fields).forEach(([k, v]) => {
|
|
37
|
-
const e = properties[v.alias];
|
|
38
|
-
if (e !== undefined) {
|
|
39
|
-
properties[k] = e;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
if(v.default !== undefined) {
|
|
43
|
-
properties[v.alias] = v.default;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
39
|
+
const mandatoryFields = this.mandatoryFields;
|
|
48
40
|
const tmp = await mkdtemp(join(tmpdir(), "deb-"));
|
|
49
41
|
const staging = join(tmp, `${properties.name}-${properties.version}`);
|
|
50
42
|
|
|
51
|
-
const mandatoryProperties = new Set(
|
|
52
|
-
Object.entries(fields)
|
|
53
|
-
.filter(([k, v]) => v.mandatory)
|
|
54
|
-
.map(([k, v]) => k)
|
|
55
|
-
);
|
|
56
|
-
|
|
57
43
|
function* controlProperties(k, v, presentKeys) {
|
|
58
44
|
if (k === undefined) {
|
|
59
|
-
for (const p of
|
|
45
|
+
for (const p of mandatoryFields) {
|
|
60
46
|
if (!presentKeys.has(p)) {
|
|
61
47
|
const v = properties[p];
|
|
62
48
|
yield [p, v === undefined ? fields[p].default : v];
|
|
@@ -67,6 +53,16 @@ export class DEB extends Packager {
|
|
|
67
53
|
}
|
|
68
54
|
}
|
|
69
55
|
|
|
56
|
+
const debianControlName = "DEBIAN/control";
|
|
57
|
+
const transformers = [
|
|
58
|
+
{
|
|
59
|
+
match: entry => entry.name === debianControlName,
|
|
60
|
+
transform: async entry =>
|
|
61
|
+
keyValueTransformer(await entry.readStream, controlProperties),
|
|
62
|
+
createEntryWhenMissing: new EmptyContentEntry(debianControlName)
|
|
63
|
+
}
|
|
64
|
+
];
|
|
65
|
+
|
|
70
66
|
let debianControlEntry;
|
|
71
67
|
|
|
72
68
|
for await (const entry of this.source) {
|
|
@@ -74,7 +70,7 @@ export class DEB extends Packager {
|
|
|
74
70
|
|
|
75
71
|
await mkdir(dirname(destName), { recursive: true });
|
|
76
72
|
|
|
77
|
-
if (entry.name ===
|
|
73
|
+
if (entry.name === debianControlName) {
|
|
78
74
|
debianControlEntry = entry;
|
|
79
75
|
} else {
|
|
80
76
|
console.log("ENTRY", entry.name, entry.basename);
|
|
@@ -83,7 +79,6 @@ export class DEB extends Packager {
|
|
|
83
79
|
await Promise.all(
|
|
84
80
|
Object.entries(permissions).map(async ([pattern, option]) => {
|
|
85
81
|
if (destName.endsWith(pattern)) {
|
|
86
|
-
//console.log("CHMOD", option.chmod, destName, pattern);
|
|
87
82
|
return chmod(destName, option.chmod);
|
|
88
83
|
}
|
|
89
84
|
})
|
|
@@ -92,7 +87,7 @@ export class DEB extends Packager {
|
|
|
92
87
|
}
|
|
93
88
|
|
|
94
89
|
if (!debianControlEntry) {
|
|
95
|
-
debianControlEntry = new EmptyContentEntry(
|
|
90
|
+
debianControlEntry = new EmptyContentEntry(debianControlName);
|
|
96
91
|
}
|
|
97
92
|
|
|
98
93
|
let destName = join(staging, debianControlEntry.name);
|
|
@@ -127,7 +122,12 @@ const fields = {
|
|
|
127
122
|
Priority: { type: "string", recommended: true },
|
|
128
123
|
Essential: { type: "boolean" },
|
|
129
124
|
Origin: { type: "string" },
|
|
130
|
-
Architecture: {
|
|
125
|
+
Architecture: {
|
|
126
|
+
alias: "arch",
|
|
127
|
+
type: "string",
|
|
128
|
+
default: "any",
|
|
129
|
+
mandatory: true
|
|
130
|
+
},
|
|
131
131
|
Homepage: { alias: "homepage", type: "string" },
|
|
132
132
|
Bugs: { alias: "bugs", type: "string" },
|
|
133
133
|
Depends: { alias: "depends", type: "packageList" },
|
package/src/output/packager.mjs
CHANGED
|
@@ -1,8 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} Field
|
|
3
|
+
* @property {string} alias interchangeable field name
|
|
4
|
+
* @property {string} type
|
|
5
|
+
* @property {any} default
|
|
6
|
+
* @property {boolean} mandatory
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {Object} properties
|
|
11
|
+
*/
|
|
1
12
|
export class Packager {
|
|
13
|
+
static get fields() {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
|
|
2
17
|
constructor(source, properties) {
|
|
3
18
|
this.source = source;
|
|
4
|
-
this.
|
|
19
|
+
this._properties = properties;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get fields() {
|
|
23
|
+
return this.constructor.fields;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get properties() {
|
|
27
|
+
const properties = this._properties;
|
|
28
|
+
|
|
29
|
+
Object.entries(this.fields).forEach(([k, v]) => {
|
|
30
|
+
const e = properties[v.alias];
|
|
31
|
+
if (e !== undefined) {
|
|
32
|
+
properties[k] = e;
|
|
33
|
+
} else {
|
|
34
|
+
if (v.default !== undefined) {
|
|
35
|
+
properties[v.alias] = v.default;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return properties;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @return {Set<string,Field>} mandatory fields
|
|
45
|
+
*/
|
|
46
|
+
get mandatoryFields() {
|
|
47
|
+
const mandatoryFields = new Set(
|
|
48
|
+
Object.entries(this.fields)
|
|
49
|
+
.filter(([k, v]) => v.mandatory)
|
|
50
|
+
.map(([k, v]) => k)
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return mandatoryFields;
|
|
5
54
|
}
|
|
6
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Execute package generation
|
|
58
|
+
*/
|
|
7
59
|
async execute() {}
|
|
8
60
|
}
|
package/src/output/pkg.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join
|
|
1
|
+
import { join } from "path";
|
|
2
2
|
import { createWriteStream } from "fs";
|
|
3
3
|
import { tmpdir } from "os";
|
|
4
4
|
import { finished } from "stream";
|
|
@@ -14,24 +14,33 @@ export class PKG extends Packager {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
static get fileNameExtension() {
|
|
17
|
-
return ".pkg.tar";
|
|
17
|
+
return ".pkg.tar.zst";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static get fields() {
|
|
21
|
+
return fields;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
async execute(options) {
|
|
21
25
|
const tmp = await mkdtemp(join(tmpdir(), "pkg-"));
|
|
22
26
|
|
|
23
|
-
const
|
|
27
|
+
const pkgbuildFileName = join(tmp, "PKGBUILD");
|
|
28
|
+
|
|
29
|
+
this.writePkbuild(pkgbuildFileName);
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
await execa("makepkg", [], { cwd: tmp });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
writePkbuild(pkgbuildFileName) {
|
|
35
|
+
const out = createWriteStream(pkgbuildFileName, { encoding: "utf8" });
|
|
26
36
|
|
|
27
|
-
const out = createWriteStream(pkgbuild, { encoding: "utf8" });
|
|
28
37
|
out.write(`
|
|
29
38
|
package() {
|
|
30
39
|
cp -r $srcdir/* "$pkgdir"
|
|
31
40
|
}
|
|
32
41
|
`);
|
|
33
42
|
|
|
34
|
-
|
|
43
|
+
out.end();
|
|
35
44
|
}
|
|
36
45
|
}
|
|
37
46
|
|
|
@@ -39,41 +48,39 @@ package() {
|
|
|
39
48
|
* well known package properties
|
|
40
49
|
* https://www.archlinux.org/pacman/PKGBUILD.5.html
|
|
41
50
|
*/
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
];
|
|
76
|
-
|
|
51
|
+
const fields = {
|
|
52
|
+
pkgname: { alias: "name", type: "string[]" },
|
|
53
|
+
license: { type: "string[]" },
|
|
54
|
+
source: { type: "string[]" },
|
|
55
|
+
validpgpkeys: { type: "string[]" },
|
|
56
|
+
noextract: { type: "string[]" },
|
|
57
|
+
md5sums: { type: "string[]" },
|
|
58
|
+
sha1sums: { type: "string[]" },
|
|
59
|
+
sha256sums: { type: "string[]" },
|
|
60
|
+
sha384sums: { type: "string[]" },
|
|
61
|
+
sha512sums: { type: "string[]" },
|
|
62
|
+
groups: { type: "string[]" },
|
|
63
|
+
arch: { type: "string[]" },
|
|
64
|
+
backup: { type: "string[]" },
|
|
65
|
+
depends: { type: "string[]" },
|
|
66
|
+
makedepends: { type: "string[]" },
|
|
67
|
+
checkdepends: { type: "string[]" },
|
|
68
|
+
optdepends: { type: "string[]" },
|
|
69
|
+
conflicts: { type: "string[]" },
|
|
70
|
+
provides: { type: "string[]" },
|
|
71
|
+
replaces: { type: "string[]" },
|
|
72
|
+
options: { type: "string[]" },
|
|
73
|
+
|
|
74
|
+
pkgver: {},
|
|
75
|
+
pkgrel: {},
|
|
76
|
+
epoch: {},
|
|
77
|
+
pkgdesc: {},
|
|
78
|
+
url: {},
|
|
79
|
+
install: {},
|
|
80
|
+
changelog: {}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/*
|
|
77
84
|
export async function pkgbuild(context, stagingDir, out, options = {}) {
|
|
78
85
|
const pkg = { contributors: [], pacman: {}, ...context.pkg };
|
|
79
86
|
|
|
@@ -151,7 +158,7 @@ ${Object.keys(properties)
|
|
|
151
158
|
${pkgver}
|
|
152
159
|
build() {
|
|
153
160
|
cd \${pkgname}${directory}
|
|
154
|
-
sed -i 's/"version": "
|
|
161
|
+
sed -i 's/"version": ".* /"version": "${
|
|
155
162
|
context.properties.pkgver
|
|
156
163
|
}",/' package.json
|
|
157
164
|
npm install
|
|
@@ -170,8 +177,6 @@ package() {
|
|
|
170
177
|
`
|
|
171
178
|
);
|
|
172
179
|
|
|
173
|
-
out.end();
|
|
174
|
-
|
|
175
180
|
await promisify(finished);
|
|
176
181
|
}
|
|
177
182
|
|
|
@@ -189,3 +194,4 @@ function makeDepends(d) {
|
|
|
189
194
|
return a;
|
|
190
195
|
}, []);
|
|
191
196
|
}
|
|
197
|
+
*/
|
package/src/output/rpm.mjs
CHANGED
|
@@ -1,35 +1,59 @@
|
|
|
1
1
|
import { globby } from "globby";
|
|
2
2
|
import { Packager } from "./packager.mjs";
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
export class RPM extends Packager {
|
|
6
|
-
static get name() {
|
|
5
|
+
static get name() {
|
|
6
|
+
return "rpm";
|
|
7
|
+
}
|
|
7
8
|
|
|
8
9
|
static get fileNameExtension() {
|
|
9
10
|
return ".rpm";
|
|
10
11
|
}
|
|
12
|
+
|
|
13
|
+
static get fields() {
|
|
14
|
+
return fields;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async execute(options) {
|
|
18
|
+
const properties = this.properties;
|
|
19
|
+
const mandatoryFields = this.mandatoryFields;
|
|
20
|
+
|
|
21
|
+
const tmp = await mkdtemp(join(tmpdir(), "deb-"));
|
|
22
|
+
const staging = join(tmp, `${properties.name}-${properties.version}`);
|
|
23
|
+
|
|
24
|
+
let specFileName = ".spec";
|
|
25
|
+
|
|
26
|
+
//if (entry.name === ".spec")
|
|
27
|
+
|
|
28
|
+
await execa("rpmbuild", ["-ba", specFileName]);
|
|
29
|
+
}
|
|
11
30
|
}
|
|
12
31
|
|
|
32
|
+
const fields = {
|
|
33
|
+
Name: { alias: "name", type: "string" },
|
|
34
|
+
Summary: { alias: "description", type: "string" },
|
|
35
|
+
License: { alias: "license", type: "string" },
|
|
36
|
+
Version: { alias: "version", type: "string" },
|
|
37
|
+
Release: { type: "integer", default: 0 },
|
|
38
|
+
Packager: { type: "string" },
|
|
39
|
+
URL: { alias: "homepage", type: "string" }
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const sections = {
|
|
43
|
+
description: {},
|
|
44
|
+
prep: {},
|
|
45
|
+
build: {},
|
|
46
|
+
install: {},
|
|
47
|
+
files: {},
|
|
48
|
+
changelog: {}
|
|
49
|
+
};
|
|
50
|
+
|
|
13
51
|
export async function rpmspec(context, stagingDir, out, options = {}) {
|
|
14
52
|
const pkg = { contributors: [], pacman: {}, ...context.pkg };
|
|
15
53
|
|
|
16
54
|
const installdir = context.properties.installdir;
|
|
17
55
|
let directory = "";
|
|
18
56
|
|
|
19
|
-
if (pkg.repository) {
|
|
20
|
-
directory = pkg.repository.directory ? "/" + pkg.repository.directory : "";
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const properties = {
|
|
24
|
-
Name: pkg.name,
|
|
25
|
-
Summary: pkg.description,
|
|
26
|
-
License: pkg.license,
|
|
27
|
-
Version: context.properties.pkgver.replace(/\-.*$/, ""),
|
|
28
|
-
Release: context.properties.pkgrel,
|
|
29
|
-
Packager: pkg.contributors.map((c, i) => `${c.name} <${c.email}>`)[0],
|
|
30
|
-
URL: pkg.homepage
|
|
31
|
-
};
|
|
32
|
-
|
|
33
57
|
const npmDistPackage = options.npmDist
|
|
34
58
|
? `( cd %{_sourcedir}${installdir}
|
|
35
59
|
tar -x --transform="s/^package\\///" -f %{buildroot}${directory}/${pkg.name}-${context.properties.pkgver}.tgz)`
|
|
@@ -48,8 +72,6 @@ export async function rpmspec(context, stagingDir, out, options = {}) {
|
|
|
48
72
|
%description
|
|
49
73
|
${pkg.description}
|
|
50
74
|
|
|
51
|
-
%prep
|
|
52
|
-
|
|
53
75
|
%build
|
|
54
76
|
npm install
|
|
55
77
|
mkdir -p %{buildroot}${installdir}
|
package/src/util.mjs
CHANGED
|
@@ -60,3 +60,30 @@ export function extractFromPackage(pkg) {
|
|
|
60
60
|
|
|
61
61
|
return { properties, sources };
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Copy content from source into destinationDirectory
|
|
66
|
+
* @param {AsyncIterator<ContentEntry>} source
|
|
67
|
+
* @param {string} destinationDirectory
|
|
68
|
+
*/
|
|
69
|
+
async function copyEntries(source, destinationDirectory, transformers) {
|
|
70
|
+
for await (const entry of source) {
|
|
71
|
+
const destName = join(destinationDirectory, entry.name);
|
|
72
|
+
|
|
73
|
+
await mkdir(dirname(destName), { recursive: true });
|
|
74
|
+
|
|
75
|
+
for(const t of transformers) {
|
|
76
|
+
if(t.match(entry)) {
|
|
77
|
+
t.transform(entry);
|
|
78
|
+
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (entry.name === "DEBIAN/control") {
|
|
84
|
+
debianControlEntry = entry;
|
|
85
|
+
} else {
|
|
86
|
+
await pipeline(await entry.readStream, createWriteStream(destName));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Replaces key value pairs in a stream of lines.
|
|
3
|
-
* @param {AsyncIterator<String>} source
|
|
4
|
-
* @param updates
|
|
5
|
-
*/
|
|
6
|
-
export async function* keyValueTransformer(source, updates) {
|
|
7
|
-
const presentKeys = new Set();
|
|
8
|
-
|
|
9
|
-
let key, value;
|
|
10
|
-
|
|
11
|
-
function* eject() {
|
|
12
|
-
if (key !== undefined) {
|
|
13
|
-
for(const [k,v] of updates(key, value, presentKeys)) {
|
|
14
|
-
yield `${k}: ${v}\n`;
|
|
15
|
-
}
|
|
16
|
-
key = value = undefined;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
for await (const line of asLines(source)) {
|
|
21
|
-
const m = line.match(/^(\w+):\s*(.*)/);
|
|
22
|
-
if (m) {
|
|
23
|
-
yield* eject();
|
|
24
|
-
key = m[1];
|
|
25
|
-
value = m[2];
|
|
26
|
-
presentKeys.add(key);
|
|
27
|
-
} else if (key !== undefined) {
|
|
28
|
-
const m = line.match(/^\s+(.*)/);
|
|
29
|
-
if (m) {
|
|
30
|
-
value += m[1];
|
|
31
|
-
} else {
|
|
32
|
-
yield* eject();
|
|
33
|
-
yield line + "\n";
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
yield line + "\n";
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
yield* eject();
|
|
41
|
-
|
|
42
|
-
for(const [k,v] of updates(undefined, undefined, presentKeys)) {
|
|
43
|
-
yield `${k}: ${v}\n`;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async function* asLines(source) {
|
|
48
|
-
let buffer = "";
|
|
49
|
-
|
|
50
|
-
for await (let chunk of source) {
|
|
51
|
-
buffer += chunk.toString();
|
|
52
|
-
const lines = buffer.split(/\n\r?/);
|
|
53
|
-
buffer = lines.pop();
|
|
54
|
-
for (const line of lines) {
|
|
55
|
-
yield line;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (buffer.length > 0) {
|
|
60
|
-
yield buffer;
|
|
61
|
-
}
|
|
62
|
-
}
|