npm-pkgbuild 10.7.1 → 10.7.2
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 +128 -99
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,92 +75,138 @@ 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
|
+
}
|
|
189
|
+
|
|
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
|
+
);
|
|
199
|
+
}
|
|
190
200
|
|
|
191
|
-
|
|
192
|
-
|
|
201
|
+
const { properties, dependencies, context } = extractFromRootPackage(json);
|
|
202
|
+
|
|
203
|
+
if (json) {
|
|
204
|
+
} else {
|
|
205
|
+
await packageWalker(async (packageContent, base, modulePath) => {
|
|
193
206
|
if (modulePath.length > 0) {
|
|
194
|
-
processPkg(
|
|
207
|
+
processPkg(packageContent, base, modulePath);
|
|
208
|
+
} else {
|
|
209
|
+
json = packageContent;
|
|
195
210
|
}
|
|
196
211
|
return true;
|
|
197
212
|
}, dir);
|
|
@@ -200,7 +215,7 @@ export async function* extractFromPackage(options = {}) {
|
|
|
200
215
|
processPkg(json, dir);
|
|
201
216
|
|
|
202
217
|
properties.variant = variant;
|
|
203
|
-
|
|
218
|
+
|
|
204
219
|
if (arch.size > 0) {
|
|
205
220
|
// provide each arch separadly
|
|
206
221
|
|
|
@@ -213,7 +228,14 @@ export async function* extractFromPackage(options = {}) {
|
|
|
213
228
|
} else {
|
|
214
229
|
numberOfArchs++;
|
|
215
230
|
properties.arch = [a];
|
|
216
|
-
yield {
|
|
231
|
+
yield {
|
|
232
|
+
properties: context.expand(properties),
|
|
233
|
+
sources,
|
|
234
|
+
dependencies,
|
|
235
|
+
output,
|
|
236
|
+
variant,
|
|
237
|
+
context
|
|
238
|
+
};
|
|
217
239
|
}
|
|
218
240
|
}
|
|
219
241
|
}
|
|
@@ -222,6 +244,13 @@ export async function* extractFromPackage(options = {}) {
|
|
|
222
244
|
}
|
|
223
245
|
} else {
|
|
224
246
|
// or one set if no arch is given
|
|
225
|
-
yield {
|
|
247
|
+
yield {
|
|
248
|
+
properties: context.expand(properties),
|
|
249
|
+
sources,
|
|
250
|
+
dependencies,
|
|
251
|
+
output,
|
|
252
|
+
variant,
|
|
253
|
+
context
|
|
254
|
+
};
|
|
226
255
|
}
|
|
227
256
|
}
|