npm-pkgbuild 7.4.2 → 7.6.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 +9 -4
- package/src/output/rpm.mjs +2 -2
- package/src/util.mjs +39 -13
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
|
@@ -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, createPropertyTransformer } from "../util.mjs";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @type KeyValueTransformOptions
|
|
@@ -48,7 +48,7 @@ export class PKG extends Packager {
|
|
|
48
48
|
return `${p.name}-${p.version}-${p.release}.${p.arch}${this.constructor.fileNameExtension}`;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
async execute(sources, options) {
|
|
51
|
+
async execute(sources, options, expander) {
|
|
52
52
|
const properties = this.properties;
|
|
53
53
|
|
|
54
54
|
//properties.depends = makeDepends({ ...pkg.engines });
|
|
@@ -77,9 +77,10 @@ package() {
|
|
|
77
77
|
`;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
await copyEntries(transform(sources, []), join(staging, "src"));
|
|
80
|
+
await copyEntries(transform(sources, []), join(staging, "src"), expander);
|
|
81
81
|
|
|
82
82
|
const metaTransformers = [
|
|
83
|
+
createPropertyTransformer(properties),
|
|
83
84
|
{
|
|
84
85
|
match: entry => entry.name === "PKGBUILD",
|
|
85
86
|
transform: async entry =>
|
|
@@ -94,7 +95,11 @@ package() {
|
|
|
94
95
|
}
|
|
95
96
|
];
|
|
96
97
|
|
|
97
|
-
await copyEntries(
|
|
98
|
+
await copyEntries(
|
|
99
|
+
transform(sources, metaTransformers, true),
|
|
100
|
+
staging,
|
|
101
|
+
expander
|
|
102
|
+
);
|
|
98
103
|
|
|
99
104
|
await execa("makepkg", ["-f"], { cwd: staging });
|
|
100
105
|
|
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
|
@@ -2,7 +2,7 @@ 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
6
|
import { FileContentProvider } from "npm-pkgbuild";
|
|
7
7
|
|
|
8
8
|
export const utf8StreamOptions = { encoding: "utf8" };
|
|
@@ -63,24 +63,41 @@ export function extractFromPackage(pkg) {
|
|
|
63
63
|
.forEach(([k, v]) => (properties[k] = v));
|
|
64
64
|
|
|
65
65
|
if (pkgbuild.content) {
|
|
66
|
-
sources = Object.entries(pkgbuild.content).map(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
sources = Object.entries(pkgbuild.content).map(
|
|
67
|
+
([destination, value]) =>
|
|
68
|
+
new FileContentProvider(value, { destination })
|
|
69
|
+
);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
Object.assign(dependencies,pkgbuild.depends)
|
|
72
|
+
Object.assign(dependencies, pkgbuild.depends);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { properties, sources, dependencies };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function createPropertyTransformer(properties) {
|
|
79
|
+
async function* transformer(expression, remainder, source, cb) {
|
|
80
|
+
console.log("EXPRESSION", expression);
|
|
81
|
+
yield properties[expression];
|
|
73
82
|
}
|
|
74
83
|
|
|
75
|
-
return {
|
|
84
|
+
return {
|
|
85
|
+
match: entry => true, //entry.name.match(/(conf|json)$/),
|
|
86
|
+
transform: async entry =>
|
|
87
|
+
new ReadableStreamContentEntry(
|
|
88
|
+
entry.name,
|
|
89
|
+
iterableStringInterceptor(transformer)
|
|
90
|
+
)
|
|
91
|
+
};
|
|
76
92
|
}
|
|
77
93
|
|
|
78
94
|
/**
|
|
79
|
-
* Apply transformers
|
|
95
|
+
* Apply transformers.
|
|
80
96
|
* @param {AsyncIterator<ContentEntry>} source
|
|
81
97
|
* @param {Transformer[]} transformers
|
|
98
|
+
* @param {Boolean]} onlyMatching filter out all none matching entries
|
|
82
99
|
*/
|
|
83
|
-
export async function* transform(source, transformers=[], onlyMatching) {
|
|
100
|
+
export async function* transform(source, transformers = [], onlyMatching) {
|
|
84
101
|
const usedTransformers = new Set();
|
|
85
102
|
|
|
86
103
|
for await (let entry of source) {
|
|
@@ -89,13 +106,13 @@ export async function* transform(source, transformers=[], onlyMatching) {
|
|
|
89
106
|
entry = await t.transform(entry);
|
|
90
107
|
usedTransformers.add(t);
|
|
91
108
|
|
|
92
|
-
if(onlyMatching) {
|
|
109
|
+
if (onlyMatching) {
|
|
93
110
|
yield entry;
|
|
94
111
|
}
|
|
95
112
|
}
|
|
96
113
|
}
|
|
97
114
|
|
|
98
|
-
if(!onlyMatching) {
|
|
115
|
+
if (!onlyMatching) {
|
|
99
116
|
yield entry;
|
|
100
117
|
}
|
|
101
118
|
}
|
|
@@ -108,17 +125,26 @@ export async function* transform(source, transformers=[], onlyMatching) {
|
|
|
108
125
|
}
|
|
109
126
|
|
|
110
127
|
/**
|
|
111
|
-
* Copy content from source into destinationDirectory
|
|
128
|
+
* Copy content from source into destinationDirectory.
|
|
112
129
|
* @param {AsyncIterator<ContentEntry>} source
|
|
113
130
|
* @param {string} destinationDirectory
|
|
131
|
+
* @param {Function} expander
|
|
132
|
+
* @param {ContentEntryAttribute[]} attributes
|
|
114
133
|
*/
|
|
115
134
|
export async function copyEntries(
|
|
116
135
|
source,
|
|
117
136
|
destinationDirectory,
|
|
137
|
+
expander = v => v,
|
|
118
138
|
attributes = []
|
|
119
139
|
) {
|
|
120
140
|
for await (let entry of source) {
|
|
121
|
-
const destName =
|
|
141
|
+
const destName = expander(
|
|
142
|
+
entry.destination === undefined
|
|
143
|
+
? join(destinationDirectory, entry.name)
|
|
144
|
+
: entry.destination.endsWith("/")
|
|
145
|
+
? join(destinationDirectory, entry.destination, entry.name)
|
|
146
|
+
: join(destinationDirectory, entry.destination)
|
|
147
|
+
);
|
|
122
148
|
await mkdir(dirname(destName), { recursive: true });
|
|
123
149
|
|
|
124
150
|
const options = { mode: entry.mode };
|