npm-pkgbuild 10.7.0 → 10.7.3
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/extract-from-package.mjs +127 -103
- package/src/output/arch.mjs +1 -3
package/package.json
CHANGED
|
@@ -31,47 +31,21 @@ export const npmArchMapping = {
|
|
|
31
31
|
ppc64: "ppc64"
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const entryAttributeNames = ["owner", "group", "mode"];
|
|
35
|
-
|
|
36
34
|
/**
|
|
37
|
-
*
|
|
38
|
-
* @
|
|
39
|
-
* @
|
|
40
|
-
* @property {Object} dependencies
|
|
41
|
-
* @property {Object} output package type
|
|
42
|
-
* @property {string} variant identifier of the variant
|
|
35
|
+
* Deliver basic properties from the root package
|
|
36
|
+
* @param {Object} json content of rool package.json
|
|
37
|
+
* @returns {Object} key value pairs extracted from json
|
|
43
38
|
*/
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Extract package definition from package.json.
|
|
47
|
-
* - for each architecture deliver a new result
|
|
48
|
-
* - if not architecture is given one result set is provided nethertheless
|
|
49
|
-
* - architectures are taken from cpu (node arch ids) and from pkgbuild.arch (raw arch ids)
|
|
50
|
-
* - architecture given in a abstract definition are used to reduce the set of avaliable architectures
|
|
51
|
-
* @param {Object} options
|
|
52
|
-
* @param {Object} options.json package.json content
|
|
53
|
-
* @param {string} options.pkgDir
|
|
54
|
-
* @returns {AsyncIter<PackageDefinition>}
|
|
55
|
-
*/
|
|
56
|
-
export async function* extractFromPackage(options = {}) {
|
|
57
|
-
let json = options.json;
|
|
58
|
-
let dir = options.pkgDir;
|
|
59
|
-
|
|
60
|
-
if (!json) {
|
|
61
|
-
dir = await packageDirectory({ cwd: dir });
|
|
62
|
-
|
|
63
|
-
json = JSON.parse(
|
|
64
|
-
await readFile(join(dir, "package.json"), utf8StreamOptions)
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
39
|
+
function extractFromRootPackage(json) {
|
|
68
40
|
const properties = Object.fromEntries(
|
|
69
41
|
["name", "version", "description", "homepage", "license"]
|
|
70
42
|
.map(key => [key, json[key]])
|
|
71
43
|
.filter(([k, v]) => v !== undefined)
|
|
72
44
|
);
|
|
73
45
|
|
|
74
|
-
|
|
46
|
+
if (properties.name) {
|
|
47
|
+
properties.name = properties.name.replace(/^\@\w+\//, "");
|
|
48
|
+
}
|
|
75
49
|
|
|
76
50
|
if (json.bugs) {
|
|
77
51
|
if (json.bugs.url) {
|
|
@@ -79,16 +53,11 @@ export async function* extractFromPackage(options = {}) {
|
|
|
79
53
|
}
|
|
80
54
|
}
|
|
81
55
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
properties.name = properties.name.replace(/^\@\w+\//, "");
|
|
86
|
-
}
|
|
56
|
+
properties.access = json.publishConfig
|
|
57
|
+
? json.publishConfig.access
|
|
58
|
+
: "private";
|
|
87
59
|
|
|
88
|
-
properties.
|
|
89
|
-
if (json.publishConfig) {
|
|
90
|
-
properties.access = json.publishConfig.access;
|
|
91
|
-
}
|
|
60
|
+
Object.assign(properties, json.config);
|
|
92
61
|
|
|
93
62
|
if (json.contributors) {
|
|
94
63
|
properties.maintainer = json.contributors.map(
|
|
@@ -106,101 +75,142 @@ export async function* extractFromPackage(options = {}) {
|
|
|
106
75
|
}
|
|
107
76
|
}
|
|
108
77
|
|
|
109
|
-
|
|
78
|
+
return {
|
|
79
|
+
properties,
|
|
80
|
+
dependencies: { ...json.engines },
|
|
81
|
+
context: createContext({ properties })
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const entryAttributeNames = ["owner", "group", "mode"];
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Delivers ContetProviders from pkgbuild.content
|
|
89
|
+
* @param {Object} content from pkgbuild.content
|
|
90
|
+
* @returns {Iterator<ContentProvider>}
|
|
91
|
+
*/
|
|
92
|
+
function* content2Sources(content, dir) {
|
|
93
|
+
if (content) {
|
|
94
|
+
for (const [destination, definitions] of Object.entries(content)) {
|
|
95
|
+
const allEntryProperties = {};
|
|
96
|
+
|
|
97
|
+
for (const a of entryAttributeNames) {
|
|
98
|
+
if (definitions[a] !== undefined) {
|
|
99
|
+
allEntryProperties[a] = definitions[a];
|
|
100
|
+
delete definitions[a];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
for (const definition of asArray(definitions)) {
|
|
105
|
+
const entryProperties = { ...allEntryProperties, destination };
|
|
106
|
+
|
|
107
|
+
if (definition.type) {
|
|
108
|
+
const type = allInputs.find(i => i.name === definition.type);
|
|
109
|
+
if (type) {
|
|
110
|
+
delete definition.type;
|
|
111
|
+
yield new type({ ...definition, dir }, entryProperties);
|
|
112
|
+
} else {
|
|
113
|
+
console.error(`Unknown type '${type}'`);
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
yield new FileContentProvider(definition, entryProperties);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @typedef {Object} PackageDefinition
|
|
125
|
+
* @property {Object} properties values describing the package attributes
|
|
126
|
+
* @property {ContentProvider[]} sources content providers
|
|
127
|
+
* @property {Object} dependencies
|
|
128
|
+
* @property {Object} output package type
|
|
129
|
+
* @property {string} variant identifier of the variant
|
|
130
|
+
*/
|
|
110
131
|
|
|
111
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Extract package definition from package.json.
|
|
134
|
+
* - for each architecture deliver a new result
|
|
135
|
+
* - if not architecture is given one result set is provided nethertheless
|
|
136
|
+
* - architectures are taken from cpu (node arch ids) and from pkgbuild.arch (raw arch ids)
|
|
137
|
+
* - architecture given in a abstract definition are used to reduce the set of avaliable architectures
|
|
138
|
+
* @param {Object} options
|
|
139
|
+
* @param {Object} options.json package.json content
|
|
140
|
+
* @param {string} options.pkgDir
|
|
141
|
+
* @returns {AsyncIter<PackageDefinition>}
|
|
142
|
+
*/
|
|
143
|
+
export async function* extractFromPackage(options = {}) {
|
|
144
|
+
let variant = "default";
|
|
112
145
|
let sources = [];
|
|
113
146
|
let output = {};
|
|
114
147
|
let arch = new Set();
|
|
115
148
|
let restrictArch = new Set();
|
|
116
149
|
|
|
117
|
-
|
|
118
|
-
const
|
|
150
|
+
function processPkg(json, dir, modulePath) {
|
|
151
|
+
const pkgbuild = json.pkgbuild;
|
|
119
152
|
|
|
120
|
-
if (
|
|
153
|
+
if (pkgbuild) {
|
|
121
154
|
if (!modulePath) {
|
|
122
155
|
if (json.cpu) {
|
|
123
156
|
for (const a of asArray(json.cpu)) {
|
|
124
157
|
arch.add(npmArchMapping[a]);
|
|
125
158
|
}
|
|
126
159
|
}
|
|
127
|
-
if (
|
|
128
|
-
for (const a of asArray(
|
|
160
|
+
if (pkgbuild.arch) {
|
|
161
|
+
for (const a of asArray(pkgbuild.arch)) {
|
|
129
162
|
arch.add(a);
|
|
130
163
|
}
|
|
131
164
|
}
|
|
132
165
|
}
|
|
133
166
|
|
|
134
|
-
if (
|
|
135
|
-
if (
|
|
136
|
-
variant =
|
|
167
|
+
if (pkgbuild.abstract || !modulePath) {
|
|
168
|
+
if (pkgbuild.variant) {
|
|
169
|
+
variant = pkgbuild.variant;
|
|
137
170
|
}
|
|
138
171
|
|
|
139
|
-
if (
|
|
140
|
-
for (const a of asArray(
|
|
172
|
+
if (pkgbuild.arch) {
|
|
173
|
+
for (const a of asArray(pkgbuild.arch)) {
|
|
141
174
|
restrictArch.add(a);
|
|
142
175
|
}
|
|
143
176
|
}
|
|
144
177
|
|
|
145
|
-
Object.assign(output,
|
|
178
|
+
Object.assign(output, pkgbuild.output);
|
|
146
179
|
|
|
147
|
-
Object.entries(
|
|
180
|
+
Object.entries(pkgbuild)
|
|
148
181
|
.filter(([k, v]) => typeof v === "string")
|
|
149
182
|
.forEach(([k, v]) => (properties[k] = v));
|
|
150
183
|
|
|
151
|
-
|
|
152
|
-
Object.entries(pkg.content).forEach(([destination, definitions]) => {
|
|
153
|
-
destination = context.expand(destination);
|
|
154
|
-
definitions = context.expand(definitions);
|
|
155
|
-
|
|
156
|
-
const allEntryProperties = {};
|
|
157
|
-
|
|
158
|
-
for (const a of entryAttributeNames) {
|
|
159
|
-
if (definitions[a] !== undefined) {
|
|
160
|
-
allEntryProperties[a] = definitions[a];
|
|
161
|
-
delete definitions[a];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
for (const definition of asArray(definitions)) {
|
|
166
|
-
const entryProperties = { ...allEntryProperties, destination };
|
|
167
|
-
|
|
168
|
-
if (definition.type) {
|
|
169
|
-
const type = allInputs.find(i => i.name === definition.type);
|
|
170
|
-
if (type) {
|
|
171
|
-
delete definition.type;
|
|
172
|
-
sources.push(
|
|
173
|
-
new type({ ...definition, dir }, entryProperties)
|
|
174
|
-
);
|
|
175
|
-
} else {
|
|
176
|
-
console.error(`Unknown type '${type}'`);
|
|
177
|
-
}
|
|
178
|
-
} else {
|
|
179
|
-
sources.push(
|
|
180
|
-
new FileContentProvider(definition, entryProperties)
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
184
|
+
sources.push(...content2Sources(context.expand(pkgbuild.content), dir));
|
|
186
185
|
}
|
|
187
|
-
Object.assign(dependencies,
|
|
186
|
+
Object.assign(dependencies, pkgbuild.depends);
|
|
188
187
|
}
|
|
189
|
-
}
|
|
188
|
+
}
|
|
190
189
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
190
|
+
let json = options.json;
|
|
191
|
+
let dir = options.dir;
|
|
192
|
+
|
|
193
|
+
if (!json) {
|
|
194
|
+
dir = await packageDirectory({ cwd: dir });
|
|
195
|
+
|
|
196
|
+
json = JSON.parse(
|
|
197
|
+
await readFile(join(dir, "package.json"), utf8StreamOptions)
|
|
198
|
+
);
|
|
198
199
|
}
|
|
199
200
|
|
|
201
|
+
const { properties, dependencies, context } = extractFromRootPackage(json);
|
|
202
|
+
|
|
203
|
+
await packageWalker(async (packageContent, base, modulePath) => {
|
|
204
|
+
if (modulePath.length > 0) {
|
|
205
|
+
processPkg(packageContent, base, modulePath);
|
|
206
|
+
}
|
|
207
|
+
return true;
|
|
208
|
+
}, dir);
|
|
209
|
+
|
|
200
210
|
processPkg(json, dir);
|
|
201
211
|
|
|
202
212
|
properties.variant = variant;
|
|
203
|
-
|
|
213
|
+
|
|
204
214
|
if (arch.size > 0) {
|
|
205
215
|
// provide each arch separadly
|
|
206
216
|
|
|
@@ -213,7 +223,14 @@ export async function* extractFromPackage(options = {}) {
|
|
|
213
223
|
} else {
|
|
214
224
|
numberOfArchs++;
|
|
215
225
|
properties.arch = [a];
|
|
216
|
-
yield {
|
|
226
|
+
yield {
|
|
227
|
+
properties: context.expand(properties),
|
|
228
|
+
sources,
|
|
229
|
+
dependencies,
|
|
230
|
+
output,
|
|
231
|
+
variant,
|
|
232
|
+
context
|
|
233
|
+
};
|
|
217
234
|
}
|
|
218
235
|
}
|
|
219
236
|
}
|
|
@@ -222,6 +239,13 @@ export async function* extractFromPackage(options = {}) {
|
|
|
222
239
|
}
|
|
223
240
|
} else {
|
|
224
241
|
// or one set if no arch is given
|
|
225
|
-
yield {
|
|
242
|
+
yield {
|
|
243
|
+
properties: context.expand(properties),
|
|
244
|
+
sources,
|
|
245
|
+
dependencies,
|
|
246
|
+
output,
|
|
247
|
+
variant,
|
|
248
|
+
context
|
|
249
|
+
};
|
|
226
250
|
}
|
|
227
251
|
}
|
package/src/output/arch.mjs
CHANGED
|
@@ -22,8 +22,6 @@ import {
|
|
|
22
22
|
packageNameMapping
|
|
23
23
|
} from "../util.mjs";
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
25
|
function* keyValueLines(key, value, options) {
|
|
28
26
|
yield `${keyPrefix(key)}${options.keyValueSeparator}${
|
|
29
27
|
Array.isArray(value)
|
|
@@ -122,7 +120,7 @@ package() {
|
|
|
122
120
|
await pipeline(
|
|
123
121
|
iterableStringInterceptor(
|
|
124
122
|
createReadStream(
|
|
125
|
-
join(options.
|
|
123
|
+
join(options.dir, properties.hooks),
|
|
126
124
|
utf8StreamOptions
|
|
127
125
|
),
|
|
128
126
|
createPropertiesInterceptor(properties)
|