npm-pkgbuild 7.4.3 → 7.7.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 +4 -3
- package/src/npm-pkgbuild-cli.mjs +25 -14
- package/src/output/deb.mjs +2 -2
- package/src/output/packager.mjs +4 -6
- package/src/output/pkg.mjs +9 -4
- package/src/output/rpm.mjs +2 -2
- package/src/util.mjs +59 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-pkgbuild",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.7.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -40,13 +40,14 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"aggregate-async-iterator": "^1.1.7",
|
|
42
42
|
"commander": "^8.3.0",
|
|
43
|
-
"content-entry": "^
|
|
44
|
-
"content-entry-filesystem": "^3.1.
|
|
43
|
+
"content-entry": "^3.0.1",
|
|
44
|
+
"content-entry-filesystem": "^3.1.14",
|
|
45
45
|
"execa": "^6.0.0",
|
|
46
46
|
"expression-expander": "^7.0.9",
|
|
47
47
|
"globby": "^12.0.2",
|
|
48
48
|
"iterable-string-interceptor": "^1.0.8",
|
|
49
49
|
"key-value-transformer": "^2.0.0",
|
|
50
|
+
"npm-package-walker": "^5.0.3",
|
|
50
51
|
"npm-packlist": "^3.0.0",
|
|
51
52
|
"pacote": "^12.0.2",
|
|
52
53
|
"pkg-dir": "^6.0.1",
|
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";
|
|
@@ -16,16 +17,19 @@ const { version, description } = JSON.parse(
|
|
|
16
17
|
|
|
17
18
|
const cwd = process.cwd();
|
|
18
19
|
|
|
19
|
-
const
|
|
20
|
+
const allOutputs = [DEB, PKG, RPM];
|
|
20
21
|
|
|
21
22
|
program.description(description).version(version);
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
allOutputs.forEach(o =>
|
|
24
25
|
program.option(`--${o.name}`, `generate ${o.name} package`)
|
|
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(
|
|
@@ -42,17 +46,22 @@ program
|
|
|
42
46
|
)
|
|
43
47
|
.action(async options => {
|
|
44
48
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
utf8StreamOptions
|
|
53
|
-
)
|
|
49
|
+
const pkgDir = await packageDirectory();
|
|
50
|
+
|
|
51
|
+
const { properties, sources, output } = await extractFromPackage(
|
|
52
|
+
JSON.parse(
|
|
53
|
+
await readFile(
|
|
54
|
+
join(pkgDir, "package.json"),
|
|
55
|
+
utf8StreamOptions
|
|
54
56
|
)
|
|
55
|
-
)
|
|
57
|
+
),
|
|
58
|
+
pkgDir
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
for (const outputFactory of allOutputs.filter(
|
|
62
|
+
o => options[o.name] === true || output[o.name] !== undefined
|
|
63
|
+
)) {
|
|
64
|
+
Object.assign(properties, options.define);
|
|
56
65
|
|
|
57
66
|
sources.push(
|
|
58
67
|
...[...options.content, ...options.meta]
|
|
@@ -65,11 +74,13 @@ program
|
|
|
65
74
|
)
|
|
66
75
|
);
|
|
67
76
|
|
|
77
|
+
const context = createContext({ properties });
|
|
68
78
|
const output = new outputFactory(properties);
|
|
69
79
|
|
|
70
80
|
const fileName = await output.execute(
|
|
71
81
|
aggregateFifo(sources.map(c => c[Symbol.asyncIterator]())),
|
|
72
|
-
options
|
|
82
|
+
options,
|
|
83
|
+
object => context.expand(object)
|
|
73
84
|
);
|
|
74
85
|
|
|
75
86
|
console.log(fileName);
|
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/packager.mjs
CHANGED
|
@@ -2,15 +2,14 @@ import { join } from "path";
|
|
|
2
2
|
import { tmpdir } from "os";
|
|
3
3
|
import { mkdtemp } from "fs/promises";
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @typedef {Object} Field
|
|
8
7
|
* @property {string} alias interchangeable field name
|
|
9
8
|
* @property {string} type
|
|
10
9
|
* @property {any} default
|
|
11
|
-
* @property {boolean} mandatory
|
|
10
|
+
* @property {boolean} mandatory
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
/**
|
|
15
14
|
* @param {Object} properties
|
|
16
15
|
*/
|
|
@@ -61,13 +60,12 @@ export class Packager {
|
|
|
61
60
|
* Create tmp directory.
|
|
62
61
|
* @return {Promise<string>} directory path
|
|
63
62
|
*/
|
|
64
|
-
get tmpdir()
|
|
65
|
-
{
|
|
63
|
+
get tmpdir() {
|
|
66
64
|
return mkdtemp(join(tmpdir(), this.constructor.name));
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
/**
|
|
70
68
|
* Execute package generation
|
|
71
69
|
*/
|
|
72
|
-
async execute(sources,options) {}
|
|
70
|
+
async execute(sources, options) {}
|
|
73
71
|
}
|
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,8 +2,9 @@ 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
|
+
import { packageWalker } from "npm-package-walker";
|
|
7
8
|
|
|
8
9
|
export const utf8StreamOptions = { encoding: "utf8" };
|
|
9
10
|
|
|
@@ -26,9 +27,10 @@ export function asArray(o) {
|
|
|
26
27
|
/**
|
|
27
28
|
* Extract package definition from package.json.
|
|
28
29
|
* @param {Object} pkg package.json content
|
|
30
|
+
* @param {string} dir
|
|
29
31
|
* @returns {Object}
|
|
30
32
|
*/
|
|
31
|
-
export function extractFromPackage(pkg) {
|
|
33
|
+
export async function extractFromPackage(pkg, dir) {
|
|
32
34
|
const properties = Object.fromEntries(
|
|
33
35
|
["name", "version", "description", "homepage"]
|
|
34
36
|
.map(key => [key, pkg[key]])
|
|
@@ -55,30 +57,60 @@ export function extractFromPackage(pkg) {
|
|
|
55
57
|
|
|
56
58
|
let dependencies = { ...pkg.engines };
|
|
57
59
|
let sources = [];
|
|
60
|
+
let output = {};
|
|
61
|
+
|
|
62
|
+
const processPkg = pkg => {
|
|
63
|
+
if (pkg.pkgbuild) {
|
|
64
|
+
const pkgbuild = pkg.pkgbuild;
|
|
65
|
+
|
|
66
|
+
Object.assign(output, pkgbuild.output);
|
|
67
|
+
|
|
68
|
+
Object.entries(pkgbuild)
|
|
69
|
+
.filter(([k, v]) => typeof v === "string")
|
|
70
|
+
.forEach(([k, v]) => (properties[k] = v));
|
|
71
|
+
|
|
72
|
+
if (pkgbuild.content) {
|
|
73
|
+
sources = Object.entries(pkgbuild.content).map(
|
|
74
|
+
([destination, value]) =>
|
|
75
|
+
new FileContentProvider(value, { destination })
|
|
76
|
+
);
|
|
77
|
+
}
|
|
58
78
|
|
|
59
|
-
|
|
60
|
-
const pkgbuild = pkg.pkgbuild;
|
|
61
|
-
Object.entries(pkgbuild)
|
|
62
|
-
.filter(([k, v]) => typeof v === "string")
|
|
63
|
-
.forEach(([k, v]) => (properties[k] = v));
|
|
64
|
-
|
|
65
|
-
if (pkgbuild.content) {
|
|
66
|
-
sources = Object.entries(pkgbuild.content).map(
|
|
67
|
-
([destination, value]) =>
|
|
68
|
-
new FileContentProvider(value, { destination })
|
|
69
|
-
);
|
|
79
|
+
Object.assign(dependencies, pkgbuild.depends);
|
|
70
80
|
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
await packageWalker(async (pkg, base, modulePath) => {
|
|
84
|
+
processPkg(pkg)
|
|
85
|
+
return true;
|
|
86
|
+
}, dir);
|
|
87
|
+
|
|
88
|
+
processPkg(pkg);
|
|
71
89
|
|
|
72
|
-
|
|
90
|
+
return { properties, sources, dependencies, output };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function createPropertyTransformer(properties) {
|
|
94
|
+
async function* transformer(expression, remainder, source, cb) {
|
|
95
|
+
console.log("EXPRESSION", expression);
|
|
96
|
+
yield properties[expression];
|
|
73
97
|
}
|
|
74
98
|
|
|
75
|
-
return {
|
|
99
|
+
return {
|
|
100
|
+
match: entry => true, //entry.name.match(/(conf|json)$/),
|
|
101
|
+
transform: async entry =>
|
|
102
|
+
new ReadableStreamContentEntry(
|
|
103
|
+
entry.name,
|
|
104
|
+
iterableStringInterceptor(transformer)
|
|
105
|
+
)
|
|
106
|
+
};
|
|
76
107
|
}
|
|
77
108
|
|
|
78
109
|
/**
|
|
79
|
-
* Apply transformers
|
|
110
|
+
* Apply transformers.
|
|
80
111
|
* @param {AsyncIterator<ContentEntry>} source
|
|
81
112
|
* @param {Transformer[]} transformers
|
|
113
|
+
* @param {Boolean]} onlyMatching filter out all none matching entries
|
|
82
114
|
*/
|
|
83
115
|
export async function* transform(source, transformers = [], onlyMatching) {
|
|
84
116
|
const usedTransformers = new Set();
|
|
@@ -108,17 +140,26 @@ export async function* transform(source, transformers = [], onlyMatching) {
|
|
|
108
140
|
}
|
|
109
141
|
|
|
110
142
|
/**
|
|
111
|
-
* Copy content from source into destinationDirectory
|
|
143
|
+
* Copy content from source into destinationDirectory.
|
|
112
144
|
* @param {AsyncIterator<ContentEntry>} source
|
|
113
145
|
* @param {string} destinationDirectory
|
|
146
|
+
* @param {Function} expander
|
|
147
|
+
* @param {ContentEntryAttribute[]} attributes
|
|
114
148
|
*/
|
|
115
149
|
export async function copyEntries(
|
|
116
150
|
source,
|
|
117
151
|
destinationDirectory,
|
|
152
|
+
expander = v => v,
|
|
118
153
|
attributes = []
|
|
119
154
|
) {
|
|
120
155
|
for await (let entry of source) {
|
|
121
|
-
const destName =
|
|
156
|
+
const destName = expander(
|
|
157
|
+
entry.destination === undefined
|
|
158
|
+
? join(destinationDirectory, entry.name)
|
|
159
|
+
: entry.destination.endsWith("/")
|
|
160
|
+
? join(destinationDirectory, entry.destination, entry.name)
|
|
161
|
+
: join(destinationDirectory, entry.destination)
|
|
162
|
+
);
|
|
122
163
|
await mkdir(dirname(destName), { recursive: true });
|
|
123
164
|
|
|
124
165
|
const options = { mode: entry.mode };
|