npm-pkgbuild 7.4.4 → 7.7.1
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 +23 -17
- package/src/output/deb.mjs +3 -2
- package/src/output/packager.mjs +4 -6
- package/src/output/pkg.mjs +13 -5
- package/src/util.mjs +56 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-pkgbuild",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.7.1",
|
|
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
|
@@ -17,16 +17,19 @@ const { version, description } = JSON.parse(
|
|
|
17
17
|
|
|
18
18
|
const cwd = process.cwd();
|
|
19
19
|
|
|
20
|
-
const
|
|
20
|
+
const allOutputs = [DEB, PKG, RPM];
|
|
21
21
|
|
|
22
22
|
program.description(description).version(version);
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
allOutputs.forEach(o =>
|
|
25
25
|
program.option(`--${o.name}`, `generate ${o.name} package`)
|
|
26
26
|
);
|
|
27
27
|
|
|
28
28
|
program
|
|
29
|
-
.option("--
|
|
29
|
+
.option("-D --define <a=b>", "define property", str => {
|
|
30
|
+
const kv = str.split(/=/);
|
|
31
|
+
return Object.fromEntries([kv]);
|
|
32
|
+
})
|
|
30
33
|
.option("-d --destination <dir>", "where to put the package(s)", cwd)
|
|
31
34
|
.option("-s --staging <dir>", "staging directory", "build")
|
|
32
35
|
.option(
|
|
@@ -43,17 +46,22 @@ program
|
|
|
43
46
|
)
|
|
44
47
|
.action(async options => {
|
|
45
48
|
try {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
utf8StreamOptions
|
|
54
|
-
)
|
|
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
|
|
55
56
|
)
|
|
56
|
-
)
|
|
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);
|
|
57
65
|
|
|
58
66
|
sources.push(
|
|
59
67
|
...[...options.content, ...options.meta]
|
|
@@ -66,15 +74,13 @@ program
|
|
|
66
74
|
)
|
|
67
75
|
);
|
|
68
76
|
|
|
69
|
-
const context = createContext();
|
|
70
|
-
context.properties = properties;
|
|
71
|
-
|
|
77
|
+
const context = createContext({ properties });
|
|
72
78
|
const output = new outputFactory(properties);
|
|
73
79
|
|
|
74
80
|
const fileName = await output.execute(
|
|
75
81
|
aggregateFifo(sources.map(c => c[Symbol.asyncIterator]())),
|
|
76
82
|
options,
|
|
77
|
-
|
|
83
|
+
object => context.expand(object)
|
|
78
84
|
);
|
|
79
85
|
|
|
80
86
|
console.log(fileName);
|
package/src/output/deb.mjs
CHANGED
|
@@ -58,7 +58,8 @@ export class DEB extends Packager {
|
|
|
58
58
|
|
|
59
59
|
await copyEntries(transform(sources, transformers), staging, expander, attributes);
|
|
60
60
|
|
|
61
|
-
await execa("dpkg", ["-b", staging, options.destination]);
|
|
61
|
+
const dpkg = await execa("dpkg", ["-b", staging, options.destination]);
|
|
62
|
+
//console.log(dpkg.stdout);
|
|
62
63
|
|
|
63
64
|
return join(options.destination, this.packageFileName);
|
|
64
65
|
}
|
|
@@ -81,7 +82,7 @@ const fields = {
|
|
|
81
82
|
Architecture: {
|
|
82
83
|
alias: "arch",
|
|
83
84
|
type: "string",
|
|
84
|
-
default: "
|
|
85
|
+
default: "all",
|
|
85
86
|
mandatory: true
|
|
86
87
|
},
|
|
87
88
|
Homepage: { alias: "homepage", type: "string" },
|
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
|
|
@@ -45,10 +45,10 @@ export class PKG extends Packager {
|
|
|
45
45
|
|
|
46
46
|
get packageFileName() {
|
|
47
47
|
const p = this.properties;
|
|
48
|
-
return `${p.name}-${p.version}-${p.release}
|
|
48
|
+
return `${p.name}-${p.version}-${p.release}-${p.arch}${this.constructor.fileNameExtension}`;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
async execute(sources, options,expander) {
|
|
51
|
+
async execute(sources, options, expander) {
|
|
52
52
|
const properties = this.properties;
|
|
53
53
|
|
|
54
54
|
//properties.depends = makeDepends({ ...pkg.engines });
|
|
@@ -80,6 +80,7 @@ package() {
|
|
|
80
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,9 +95,16 @@ 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
|
-
await execa("makepkg", ["-f"], {
|
|
104
|
+
await execa("makepkg", ["-f"], {
|
|
105
|
+
cwd: staging,
|
|
106
|
+
env: { PKGDEST: options.destination }
|
|
107
|
+
});
|
|
100
108
|
|
|
101
109
|
return join(options.destination, this.packageFileName);
|
|
102
110
|
}
|
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();
|
|
@@ -117,11 +149,17 @@ export async function* transform(source, transformers = [], onlyMatching) {
|
|
|
117
149
|
export async function copyEntries(
|
|
118
150
|
source,
|
|
119
151
|
destinationDirectory,
|
|
120
|
-
expander =
|
|
152
|
+
expander = v => v,
|
|
121
153
|
attributes = []
|
|
122
154
|
) {
|
|
123
155
|
for await (let entry of source) {
|
|
124
|
-
const destName = expander(
|
|
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
|
+
);
|
|
125
163
|
await mkdir(dirname(destName), { recursive: true });
|
|
126
164
|
|
|
127
165
|
const options = { mode: entry.mode };
|