npm-pkgbuild 7.3.9 → 7.3.13
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 +3 -3
- package/src/content/content-provider.mjs +0 -7
- package/src/content/node-modules-content-provider.mjs +0 -1
- package/src/content/npm-pack-content-provider.mjs +1 -1
- package/src/npm-pkgbuild-cli.mjs +2 -5
- package/src/output/deb.mjs +8 -56
- package/src/output/packager.mjs +16 -3
- package/src/output/pkg.mjs +8 -2
- package/src/output/rpm.mjs +8 -5
- package/src/util.mjs +40 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-pkgbuild",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.13",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"aggregate-async-iterator": "^1.1.7",
|
|
42
42
|
"commander": "^8.3.0",
|
|
43
|
-
"content-entry": "^2.
|
|
44
|
-
"content-entry-filesystem": "^3.1.
|
|
43
|
+
"content-entry": "^2.10.0",
|
|
44
|
+
"content-entry-filesystem": "^3.1.11",
|
|
45
45
|
"execa": "^6.0.0",
|
|
46
46
|
"expression-expander": "^7.0.9",
|
|
47
47
|
"globby": "^12.0.2",
|
|
@@ -2,17 +2,10 @@
|
|
|
2
2
|
* Source of package content.
|
|
3
3
|
*/
|
|
4
4
|
export class ContentProvider {
|
|
5
|
-
/**
|
|
6
|
-
* Delivers content entries to be packed.
|
|
7
|
-
* @return {asyncIterator<ContentEntry>} all entries
|
|
8
|
-
*/
|
|
9
|
-
async *entries() {}
|
|
10
|
-
|
|
11
5
|
/**
|
|
12
6
|
* List all entries.
|
|
13
7
|
* @return {asyncIterator<ContentEntry>} all entries
|
|
14
8
|
*/
|
|
15
9
|
async *[Symbol.asyncIterator]() {
|
|
16
|
-
return yield* this.entries();
|
|
17
10
|
}
|
|
18
11
|
}
|
|
@@ -9,7 +9,7 @@ import { BufferContentEntry } from "content-entry";
|
|
|
9
9
|
* content from npm pack
|
|
10
10
|
*/
|
|
11
11
|
export class NPMPackContentProvider extends ContentProvider {
|
|
12
|
-
async *
|
|
12
|
+
async *[Symbol.asyncIterator]() {
|
|
13
13
|
//const m = await pacote.manifest(context.dir);
|
|
14
14
|
//console.log('got it', m);
|
|
15
15
|
|
package/src/npm-pkgbuild-cli.mjs
CHANGED
|
@@ -65,12 +65,9 @@ program
|
|
|
65
65
|
])
|
|
66
66
|
);
|
|
67
67
|
|
|
68
|
-
const output = new outputFactory(
|
|
69
|
-
aggregateFifo(sources.map(([c, d]) => c.entries())),
|
|
70
|
-
properties
|
|
71
|
-
);
|
|
68
|
+
const output = new outputFactory(properties);
|
|
72
69
|
|
|
73
|
-
const fileName = await output.execute(options);
|
|
70
|
+
const fileName = await output.execute(aggregateFifo(sources.map(([c, d]) => c[Symbol.asyncIterator]() )), options);
|
|
74
71
|
|
|
75
72
|
console.log(fileName);
|
|
76
73
|
}
|
package/src/output/deb.mjs
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
import { join
|
|
2
|
-
import { tmpdir } from "os";
|
|
3
|
-
import { createWriteStream } from "fs";
|
|
4
|
-
import { mkdtemp, mkdir, chmod } from "fs/promises";
|
|
5
|
-
import { pipeline } from "stream/promises";
|
|
1
|
+
import { join } from "path";
|
|
6
2
|
import { execa } from "execa";
|
|
7
3
|
import { EmptyContentEntry, ReadableStreamContentEntry } from "content-entry";
|
|
8
4
|
import { keyValueTransformer } from "key-value-transformer";
|
|
9
5
|
import { Packager } from "./packager.mjs";
|
|
6
|
+
import { copyEntries, transform } from "../util.mjs";
|
|
10
7
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const permissions = {
|
|
14
|
-
"DEBIAN/preinst": executableAttributes,
|
|
15
|
-
"DEBIAN/postinst": executableAttributes,
|
|
16
|
-
"DEBIAN/prerm": executableAttributes,
|
|
17
|
-
"DEBIAN/postrm": executableAttributes
|
|
18
|
-
};
|
|
8
|
+
const attributes = [{ pattern: /DEBIAN\/.*(inst|rm)/, mode: 0o775 }];
|
|
19
9
|
|
|
20
10
|
export class DEB extends Packager {
|
|
21
11
|
static get name() {
|
|
@@ -34,11 +24,10 @@ export class DEB extends Packager {
|
|
|
34
24
|
return `${this.properties.name}_${this.properties.version}_${this.properties.arch}${this.constructor.fileNameExtension}`;
|
|
35
25
|
}
|
|
36
26
|
|
|
37
|
-
async execute(options) {
|
|
27
|
+
async execute(sources, options) {
|
|
38
28
|
const properties = this.properties;
|
|
39
29
|
const mandatoryFields = this.mandatoryFields;
|
|
40
|
-
const
|
|
41
|
-
const staging = join(tmp, `${properties.name}-${properties.version}`);
|
|
30
|
+
const staging = await this.tmpdir;
|
|
42
31
|
|
|
43
32
|
function* controlProperties(k, v, presentKeys) {
|
|
44
33
|
if (k === undefined) {
|
|
@@ -62,48 +51,11 @@ export class DEB extends Packager {
|
|
|
62
51
|
entry.name,
|
|
63
52
|
keyValueTransformer(await entry.readStream, controlProperties)
|
|
64
53
|
),
|
|
65
|
-
createEntryWhenMissing: new EmptyContentEntry(debianControlName)
|
|
54
|
+
createEntryWhenMissing: () => new EmptyContentEntry(debianControlName)
|
|
66
55
|
}
|
|
67
56
|
];
|
|
68
57
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
for await (const entry of this.source) {
|
|
72
|
-
const destName = join(staging, entry.name);
|
|
73
|
-
|
|
74
|
-
await mkdir(dirname(destName), { recursive: true });
|
|
75
|
-
|
|
76
|
-
if (entry.name === debianControlName) {
|
|
77
|
-
debianControlEntry = entry;
|
|
78
|
-
} else {
|
|
79
|
-
console.log("ENTRY", entry.name, entry.basename);
|
|
80
|
-
await pipeline(await entry.readStream, createWriteStream(destName));
|
|
81
|
-
|
|
82
|
-
await Promise.all(
|
|
83
|
-
Object.entries(permissions).map(async ([pattern, option]) => {
|
|
84
|
-
if (destName.endsWith(pattern)) {
|
|
85
|
-
return chmod(destName, option.chmod);
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (!debianControlEntry) {
|
|
93
|
-
debianControlEntry = new EmptyContentEntry(debianControlName);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
let destName = join(staging, debianControlEntry.name);
|
|
97
|
-
|
|
98
|
-
await mkdir(dirname(destName), { recursive: true });
|
|
99
|
-
|
|
100
|
-
await pipeline(
|
|
101
|
-
keyValueTransformer(
|
|
102
|
-
await debianControlEntry.readStream,
|
|
103
|
-
controlProperties
|
|
104
|
-
),
|
|
105
|
-
createWriteStream(destName)
|
|
106
|
-
);
|
|
58
|
+
await copyEntries(transform(sources, transformers), staging, attributes);
|
|
107
59
|
|
|
108
60
|
await execa("dpkg", ["-b", staging, options.destination]);
|
|
109
61
|
|
|
@@ -113,7 +65,7 @@ export class DEB extends Packager {
|
|
|
113
65
|
|
|
114
66
|
/**
|
|
115
67
|
* @see https://www.debian.org/doc/debian-policy/ch-controlfields.html
|
|
116
|
-
* @ https://linux.die.net/man/5/deb-control
|
|
68
|
+
* @see https://linux.die.net/man/5/deb-control
|
|
117
69
|
*/
|
|
118
70
|
|
|
119
71
|
const fields = {
|
package/src/output/packager.mjs
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { tmpdir } from "os";
|
|
3
|
+
import { mkdtemp } from "fs/promises";
|
|
4
|
+
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* @typedef {Object} Field
|
|
3
8
|
* @property {string} alias interchangeable field name
|
|
@@ -14,8 +19,7 @@ export class Packager {
|
|
|
14
19
|
return {};
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
constructor(
|
|
18
|
-
this.source = source;
|
|
22
|
+
constructor(properties) {
|
|
19
23
|
this._properties = properties;
|
|
20
24
|
}
|
|
21
25
|
|
|
@@ -53,8 +57,17 @@ export class Packager {
|
|
|
53
57
|
return mandatoryFields;
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Create tmp directory.
|
|
62
|
+
* @return {Promise<string>} directory path
|
|
63
|
+
*/
|
|
64
|
+
get tmpdir()
|
|
65
|
+
{
|
|
66
|
+
return mkdtemp(join(tmpdir(), this.constructor.name));
|
|
67
|
+
}
|
|
68
|
+
|
|
56
69
|
/**
|
|
57
70
|
* Execute package generation
|
|
58
71
|
*/
|
|
59
|
-
async execute() {}
|
|
72
|
+
async execute(sources,options) {}
|
|
60
73
|
}
|
package/src/output/pkg.mjs
CHANGED
|
@@ -21,13 +21,19 @@ export class PKG extends Packager {
|
|
|
21
21
|
return fields;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async execute(options) {
|
|
25
|
-
const
|
|
24
|
+
async execute(sources,options) {
|
|
25
|
+
const properties = this.properties;
|
|
26
|
+
const mandatoryFields = this.mandatoryFields;
|
|
27
|
+
const staging = await this.tmpdir;
|
|
26
28
|
|
|
27
29
|
const pkgbuildFileName = join(tmp, "PKGBUILD");
|
|
28
30
|
|
|
29
31
|
this.writePkbuild(pkgbuildFileName);
|
|
30
32
|
|
|
33
|
+
const transformers = [];
|
|
34
|
+
|
|
35
|
+
await copyEntries(transform(sources, transformers), staging);
|
|
36
|
+
|
|
31
37
|
await execa("makepkg", [], { cwd: tmp });
|
|
32
38
|
}
|
|
33
39
|
|
package/src/output/rpm.mjs
CHANGED
|
@@ -14,16 +14,19 @@ export class RPM extends Packager {
|
|
|
14
14
|
return fields;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
async execute(options) {
|
|
17
|
+
async execute(sources,options) {
|
|
18
18
|
const properties = this.properties;
|
|
19
19
|
const mandatoryFields = this.mandatoryFields;
|
|
20
|
+
const staging = await this.tmpdir;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
const staging = join(tmp, `${properties.name}-${properties.version}`);
|
|
22
|
+
let specFileName = `${properties.name}.spec`;
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
const transformers = [];
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
await copyEntries(
|
|
27
|
+
transform(sources, transformers),
|
|
28
|
+
staging
|
|
29
|
+
);
|
|
27
30
|
|
|
28
31
|
await execa("rpmbuild", ["-ba", specFileName]);
|
|
29
32
|
}
|
package/src/util.mjs
CHANGED
|
@@ -66,23 +66,57 @@ export function extractFromPackage(pkg) {
|
|
|
66
66
|
return { properties, sources };
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Apply transformers
|
|
71
|
+
* @param {AsyncIterator<ContentEntry>} source
|
|
72
|
+
* @param {Transformer[]} transformers
|
|
73
|
+
*/
|
|
74
|
+
export async function* transform(source, transformers) {
|
|
75
|
+
const usedTransformers = new Set();
|
|
76
|
+
|
|
77
|
+
for await (let entry of source) {
|
|
78
|
+
for (const t of transformers) {
|
|
79
|
+
if (t.match(entry)) {
|
|
80
|
+
entry = await t.transform(entry);
|
|
81
|
+
usedTransformers.add(t);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
yield entry;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (const t of transformers) {
|
|
89
|
+
if (!usedTransformers.has(t) && t.createEntryWhenMissing !== undefined) {
|
|
90
|
+
yield t.transform(await t.createEntryWhenMissing());
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
69
95
|
/**
|
|
70
96
|
* Copy content from source into destinationDirectory
|
|
71
97
|
* @param {AsyncIterator<ContentEntry>} source
|
|
72
98
|
* @param {string} destinationDirectory
|
|
73
|
-
* @param {Transformer[]} transformers
|
|
74
99
|
*/
|
|
75
|
-
export async function copyEntries(
|
|
100
|
+
export async function copyEntries(
|
|
101
|
+
source,
|
|
102
|
+
destinationDirectory,
|
|
103
|
+
attributes = []
|
|
104
|
+
) {
|
|
76
105
|
for await (let entry of source) {
|
|
77
106
|
const destName = join(destinationDirectory, entry.name);
|
|
78
107
|
await mkdir(dirname(destName), { recursive: true });
|
|
79
108
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
109
|
+
const options = { mode: entry.mode };
|
|
110
|
+
|
|
111
|
+
for (const a of attributes) {
|
|
112
|
+
if (entry.name.match(a.pattern)) {
|
|
113
|
+
options.mode = a.mode;
|
|
83
114
|
}
|
|
84
115
|
}
|
|
85
116
|
|
|
86
|
-
await pipeline(
|
|
117
|
+
await pipeline(
|
|
118
|
+
await entry.readStream,
|
|
119
|
+
createWriteStream(destName, options)
|
|
120
|
+
);
|
|
87
121
|
}
|
|
88
122
|
}
|