npm-pkgbuild 7.4.1 → 7.5.0
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 +1 -1
- package/src/content/file-content-provider.mjs +6 -2
- package/src/npm-pkgbuild-cli.mjs +19 -8
- package/src/output/deb.mjs +2 -2
- package/src/output/pkg.mjs +17 -28
- package/src/output/rpm.mjs +2 -2
- package/src/util.mjs +27 -9
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ import { ContentProvider } from "./content-provider.mjs";
|
|
|
11
11
|
* @param {string} definitions.base base directory where to find the files
|
|
12
12
|
*/
|
|
13
13
|
export class FileContentProvider extends ContentProvider {
|
|
14
|
-
constructor(definitions) {
|
|
14
|
+
constructor(definitions, entryProperties) {
|
|
15
15
|
super();
|
|
16
16
|
|
|
17
17
|
if (typeof definitions === "string") {
|
|
@@ -24,6 +24,8 @@ export class FileContentProvider extends ContentProvider {
|
|
|
24
24
|
this.definitions = { pattern: ["**/*"], ...definitions };
|
|
25
25
|
this.definitions.pattern = asArray(this.definitions.pattern);
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
this.entryProperties = entryProperties;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
async *[Symbol.asyncIterator]() {
|
|
@@ -33,7 +35,9 @@ export class FileContentProvider extends ContentProvider {
|
|
|
33
35
|
for (const name of await globby(definitions.pattern, {
|
|
34
36
|
cwd: base
|
|
35
37
|
})) {
|
|
36
|
-
|
|
38
|
+
const entry = new FileSystemEntry(name, base);
|
|
39
|
+
Object.assign(entry, this.entryProperties);
|
|
40
|
+
yield entry;
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
}
|
package/src/npm-pkgbuild-cli.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { readFile } from "fs/promises";
|
|
|
5
5
|
import { join } from "path";
|
|
6
6
|
import program from "commander";
|
|
7
7
|
import { aggregateFifo } from "aggregate-async-iterator";
|
|
8
|
+
import { createContext } from "expression-expander";
|
|
8
9
|
import { packageDirectory } from "pkg-dir";
|
|
9
10
|
import { utf8StreamOptions, extractFromPackage } from "./util.mjs";
|
|
10
11
|
import { FileContentProvider, DEB, PKG, RPM } from "npm-pkgbuild";
|
|
@@ -25,7 +26,10 @@ outputs.forEach(o =>
|
|
|
25
26
|
);
|
|
26
27
|
|
|
27
28
|
program
|
|
28
|
-
.option("--
|
|
29
|
+
.option("-D --define <a=b>", "define property", str => {
|
|
30
|
+
const kv = str.split(/=/);
|
|
31
|
+
return Object.fromEntries([kv]);
|
|
32
|
+
})
|
|
29
33
|
.option("-d --destination <dir>", "where to put the package(s)", cwd)
|
|
30
34
|
.option("-s --staging <dir>", "staging directory", "build")
|
|
31
35
|
.option(
|
|
@@ -54,20 +58,27 @@ program
|
|
|
54
58
|
)
|
|
55
59
|
);
|
|
56
60
|
|
|
61
|
+
Object.assign(properties, options.define);
|
|
62
|
+
|
|
57
63
|
sources.push(
|
|
58
64
|
...[...options.content, ...options.meta]
|
|
59
65
|
.filter(x => x)
|
|
60
|
-
.map(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
.map(
|
|
67
|
+
source =>
|
|
68
|
+
new FileContentProvider({
|
|
69
|
+
base: source
|
|
70
|
+
})
|
|
71
|
+
)
|
|
66
72
|
);
|
|
67
73
|
|
|
74
|
+
const context = createContext({ properties });
|
|
68
75
|
const output = new outputFactory(properties);
|
|
69
76
|
|
|
70
|
-
const fileName = await output.execute(
|
|
77
|
+
const fileName = await output.execute(
|
|
78
|
+
aggregateFifo(sources.map(c => c[Symbol.asyncIterator]())),
|
|
79
|
+
options,
|
|
80
|
+
object => context.expand(object)
|
|
81
|
+
);
|
|
71
82
|
|
|
72
83
|
console.log(fileName);
|
|
73
84
|
}
|
package/src/output/deb.mjs
CHANGED
|
@@ -25,7 +25,7 @@ export class DEB extends Packager {
|
|
|
25
25
|
return `${p.name}_${p.version}_${p.arch}${this.constructor.fileNameExtension}`;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
async execute(sources, options) {
|
|
28
|
+
async execute(sources, options, expander) {
|
|
29
29
|
const properties = this.properties;
|
|
30
30
|
const mandatoryFields = this.mandatoryFields;
|
|
31
31
|
const staging = await this.tmpdir;
|
|
@@ -56,7 +56,7 @@ export class DEB extends Packager {
|
|
|
56
56
|
}
|
|
57
57
|
];
|
|
58
58
|
|
|
59
|
-
await copyEntries(transform(sources, transformers), staging, attributes);
|
|
59
|
+
await copyEntries(transform(sources, transformers), staging, expander, attributes);
|
|
60
60
|
|
|
61
61
|
await execa("dpkg", ["-b", staging, options.destination]);
|
|
62
62
|
|
package/src/output/pkg.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { join } from "path";
|
|
1
2
|
import { execa } from "execa";
|
|
2
3
|
import { EmptyContentEntry, ReadableStreamContentEntry } from "content-entry";
|
|
3
4
|
import {
|
|
@@ -18,7 +19,7 @@ export const pkgKeyValuePairOptions = {
|
|
|
18
19
|
extractKeyValue: line => {
|
|
19
20
|
const m = line.match(/^(\w+)=\s*\((.*)\)|(.*)/);
|
|
20
21
|
if (m) {
|
|
21
|
-
return [m[1], m[2] ? [m[2]] : m[3]];
|
|
22
|
+
return [m[1], m[2] ? [m[2].split(/\s*,\s*/)] : m[3]];
|
|
22
23
|
}
|
|
23
24
|
},
|
|
24
25
|
keyValueLine: (key, value, lineEnding) =>
|
|
@@ -47,8 +48,11 @@ export class PKG extends Packager {
|
|
|
47
48
|
return `${p.name}-${p.version}-${p.release}.${p.arch}${this.constructor.fileNameExtension}`;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
async execute(sources, options) {
|
|
51
|
+
async execute(sources, options,expander) {
|
|
51
52
|
const properties = this.properties;
|
|
53
|
+
|
|
54
|
+
//properties.depends = makeDepends({ ...pkg.engines });
|
|
55
|
+
|
|
52
56
|
const mandatoryFields = this.mandatoryFields;
|
|
53
57
|
const staging = await this.tmpdir;
|
|
54
58
|
|
|
@@ -73,7 +77,9 @@ package() {
|
|
|
73
77
|
`;
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
|
|
80
|
+
await copyEntries(transform(sources, []), join(staging, "src"), expander);
|
|
81
|
+
|
|
82
|
+
const metaTransformers = [
|
|
77
83
|
{
|
|
78
84
|
match: entry => entry.name === "PKGBUILD",
|
|
79
85
|
transform: async entry =>
|
|
@@ -88,11 +94,11 @@ package() {
|
|
|
88
94
|
}
|
|
89
95
|
];
|
|
90
96
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
await copyEntries(transform(sources, transformers), staging);
|
|
97
|
+
await copyEntries(transform(sources, metaTransformers, true), staging, expander);
|
|
94
98
|
|
|
95
99
|
await execa("makepkg", ["-f"], { cwd: staging });
|
|
100
|
+
|
|
101
|
+
return join(options.destination, this.packageFileName);
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
104
|
|
|
@@ -107,7 +113,7 @@ const fields = {
|
|
|
107
113
|
pkgdesc: { alias: "description", type: "string", mandatory: true },
|
|
108
114
|
arch: { default: ["any"], type: "string[]", mandatory: true },
|
|
109
115
|
|
|
110
|
-
license: { type: "string[]", mandatory: true },
|
|
116
|
+
license: { default: [], type: "string[]", mandatory: true },
|
|
111
117
|
source: { default: [], type: "string[]" },
|
|
112
118
|
validpgpkeys: { type: "string[]" },
|
|
113
119
|
noextract: { type: "string[]" },
|
|
@@ -134,12 +140,6 @@ const fields = {
|
|
|
134
140
|
};
|
|
135
141
|
|
|
136
142
|
/*
|
|
137
|
-
const properties = {
|
|
138
|
-
makedepends: "git"
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
properties.depends = makeDepends({ ...pkg.engines });
|
|
142
|
-
|
|
143
143
|
out.write(
|
|
144
144
|
`# ${pkg.contributors
|
|
145
145
|
.map(
|
|
@@ -171,19 +171,8 @@ package() {
|
|
|
171
171
|
}
|
|
172
172
|
`
|
|
173
173
|
);
|
|
174
|
-
|
|
175
|
-
function makeDepends(d) {
|
|
176
|
-
if (d === undefined) {
|
|
177
|
-
return [];
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return Object.keys(d).reduce((a, c) => {
|
|
181
|
-
const mapping = {
|
|
182
|
-
node: "nodejs"
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
a.push(`${mapping[c] ? mapping[c] : c}${d[c].replace(/\-([\w\d]+)$/, "")}`);
|
|
186
|
-
return a;
|
|
187
|
-
}, []);
|
|
188
|
-
}
|
|
189
174
|
*/
|
|
175
|
+
|
|
176
|
+
const mapping = {
|
|
177
|
+
node: "nodejs"
|
|
178
|
+
};
|
package/src/output/rpm.mjs
CHANGED
|
@@ -27,7 +27,7 @@ export class RPM extends Packager {
|
|
|
27
27
|
return fields;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
async execute(sources, options) {
|
|
30
|
+
async execute(sources, options, expander) {
|
|
31
31
|
const properties = this.properties;
|
|
32
32
|
const mandatoryFields = this.mandatoryFields;
|
|
33
33
|
const tmp = await this.tmpdir;
|
|
@@ -76,7 +76,7 @@ export class RPM extends Packager {
|
|
|
76
76
|
}
|
|
77
77
|
];
|
|
78
78
|
|
|
79
|
-
await copyEntries(transform(sources, transformers), staging);
|
|
79
|
+
await copyEntries(transform(sources, transformers), staging, expander);
|
|
80
80
|
|
|
81
81
|
await execa("rpmbuild", [
|
|
82
82
|
"--define",
|
package/src/util.mjs
CHANGED
|
@@ -53,6 +53,7 @@ export function extractFromPackage(pkg) {
|
|
|
53
53
|
properties.source = pkg.repository.url;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
let dependencies = { ...pkg.engines };
|
|
56
57
|
let sources = [];
|
|
57
58
|
|
|
58
59
|
if (pkg.pkgbuild) {
|
|
@@ -62,14 +63,16 @@ export function extractFromPackage(pkg) {
|
|
|
62
63
|
.forEach(([k, v]) => (properties[k] = v));
|
|
63
64
|
|
|
64
65
|
if (pkgbuild.content) {
|
|
65
|
-
sources = Object.entries(pkgbuild.content).map(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
sources = Object.entries(pkgbuild.content).map(
|
|
67
|
+
([destination, value]) =>
|
|
68
|
+
new FileContentProvider(value, { destination })
|
|
69
|
+
);
|
|
69
70
|
}
|
|
71
|
+
|
|
72
|
+
Object.assign(dependencies, pkgbuild.depends);
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
return { properties, sources };
|
|
75
|
+
return { properties, sources, dependencies };
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
/**
|
|
@@ -77,7 +80,7 @@ export function extractFromPackage(pkg) {
|
|
|
77
80
|
* @param {AsyncIterator<ContentEntry>} source
|
|
78
81
|
* @param {Transformer[]} transformers
|
|
79
82
|
*/
|
|
80
|
-
export async function* transform(source, transformers) {
|
|
83
|
+
export async function* transform(source, transformers = [], onlyMatching) {
|
|
81
84
|
const usedTransformers = new Set();
|
|
82
85
|
|
|
83
86
|
for await (let entry of source) {
|
|
@@ -85,10 +88,16 @@ export async function* transform(source, transformers) {
|
|
|
85
88
|
if (t.match(entry)) {
|
|
86
89
|
entry = await t.transform(entry);
|
|
87
90
|
usedTransformers.add(t);
|
|
91
|
+
|
|
92
|
+
if (onlyMatching) {
|
|
93
|
+
yield entry;
|
|
94
|
+
}
|
|
88
95
|
}
|
|
89
96
|
}
|
|
90
97
|
|
|
91
|
-
|
|
98
|
+
if (!onlyMatching) {
|
|
99
|
+
yield entry;
|
|
100
|
+
}
|
|
92
101
|
}
|
|
93
102
|
|
|
94
103
|
for (const t of transformers) {
|
|
@@ -99,17 +108,26 @@ export async function* transform(source, transformers) {
|
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
/**
|
|
102
|
-
* Copy content from source into destinationDirectory
|
|
111
|
+
* Copy content from source into destinationDirectory.
|
|
103
112
|
* @param {AsyncIterator<ContentEntry>} source
|
|
104
113
|
* @param {string} destinationDirectory
|
|
114
|
+
* @param {Function} expander
|
|
115
|
+
* @param {ContentEntryAttribute[]} attributes
|
|
105
116
|
*/
|
|
106
117
|
export async function copyEntries(
|
|
107
118
|
source,
|
|
108
119
|
destinationDirectory,
|
|
120
|
+
expander = v => v,
|
|
109
121
|
attributes = []
|
|
110
122
|
) {
|
|
111
123
|
for await (let entry of source) {
|
|
112
|
-
const destName =
|
|
124
|
+
const destName = expander(
|
|
125
|
+
entry.destination === undefined
|
|
126
|
+
? join(destinationDirectory, entry.name)
|
|
127
|
+
: entry.destination.endsWith("/")
|
|
128
|
+
? join(destinationDirectory, entry.destination, entry.name)
|
|
129
|
+
: join(destinationDirectory, entry.destination)
|
|
130
|
+
);
|
|
113
131
|
await mkdir(dirname(destName), { recursive: true });
|
|
114
132
|
|
|
115
133
|
const options = { mode: entry.mode };
|