npm-pkgbuild 10.18.1 → 10.19.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/README.md CHANGED
@@ -125,7 +125,7 @@ see [mf-hosting](https://www.npmjs.com/package/mf-hosting) module as an example.
125
125
  * [tmpdir](#tmpdir)
126
126
  * [execute](#execute)
127
127
  * [Parameters](#parameters-10)
128
- * [available](#available)
128
+ * [prepare](#prepare)
129
129
 
130
130
  ## ContentProvider
131
131
 
@@ -317,7 +317,7 @@ Execute package generation
317
317
  * `options`  
318
318
  * `expander`  
319
319
 
320
- ## available
320
+ ## prepare
321
321
 
322
322
  Check for rpmbuild presence.
323
323
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "10.18.1",
3
+ "version": "10.19.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -40,10 +40,10 @@
40
40
  "lint:docs": "documentation lint ./src/**/*.mjs"
41
41
  },
42
42
  "dependencies": {
43
- "@npmcli/arborist": "^6.1.5",
43
+ "@npmcli/arborist": "^6.1.6",
44
44
  "@vercel/nft": "^0.22.5",
45
45
  "aggregate-async-iterator": "^1.1.15",
46
- "commander": "^9.4.1",
46
+ "commander": "^9.5.0",
47
47
  "content-entry": "^5.2.16",
48
48
  "content-entry-filesystem": "^5.2.13",
49
49
  "content-entry-transform": "^1.4.27",
@@ -64,7 +64,7 @@
64
64
  "ava": "^5.1.0",
65
65
  "c8": "^7.12.0",
66
66
  "documentation": "^14.0.1",
67
- "semantic-release": "^19.0.5",
67
+ "semantic-release": "^20.0.2",
68
68
  "stream-buffers": "^3.0.2"
69
69
  },
70
70
  "engines": {
@@ -72,7 +72,7 @@
72
72
  },
73
73
  "repository": {
74
74
  "type": "git",
75
- "url": "https://github.com/arlac77/npm-pkgbuild.git"
75
+ "url": "https://github.com/arlac77/npm-pkgbuild"
76
76
  },
77
77
  "bugs": {
78
78
  "url": "https://github.com/arlac77/npm-pkgbuild/issues"
@@ -1,5 +1,4 @@
1
- import { readFile } from "node:fs/promises";
2
- import { join } from "node:path";
1
+ import { join, resolve } from "node:path";
3
2
  import { packageDirectory } from "pkg-dir";
4
3
  import { packageWalker } from "npm-package-walker";
5
4
  import { createContext } from "expression-expander";
@@ -44,55 +43,6 @@ export const npmArchMapping = {
44
43
  ppc64: "ppc64"
45
44
  };
46
45
 
47
- /**
48
- * Deliver basic properties from the root package.
49
- * @param {Object} content of root package.json
50
- * @returns {Object} key value pairs extracted from package
51
- */
52
- function extractFromRootPackage(json) {
53
- const properties = Object.fromEntries(
54
- ["name", "version", "description", "homepage", "license"]
55
- .map(key => [key, json[key]])
56
- .filter(([k, v]) => v !== undefined)
57
- );
58
-
59
- if (properties.name) {
60
- properties.name = properties.name.replace(/^\@[^\/]+\//, "");
61
- }
62
-
63
- if (json.bugs?.url) {
64
- properties.bugs = json.bugs.url;
65
- }
66
-
67
- properties.access = json.publishConfig
68
- ? json.publishConfig.access
69
- : "private";
70
-
71
- Object.assign(properties, json.config);
72
-
73
- if (json.contributors) {
74
- properties.maintainer = json.contributors.map(
75
- c => `${c.name} <${c.email}>`
76
- )[0];
77
- }
78
-
79
- if (json.repository) {
80
- if (typeof json.repository === "string") {
81
- properties.source = json.repository;
82
- } else {
83
- if (json.repository.url) {
84
- properties.source = json.repository.url;
85
- }
86
- }
87
- }
88
-
89
- return {
90
- properties,
91
- dependencies: { ...json.engines },
92
- context: createContext({ properties })
93
- };
94
- }
95
-
96
46
  const entryAttributeNames = ["owner", "group", "mode"];
97
47
 
98
48
  /**
@@ -137,7 +87,8 @@ function* content2Sources(content, dir) {
137
87
  * @property {ContentProvider[]} sources content providers
138
88
  * @property {Object} dependencies
139
89
  * @property {Object} output package type
140
- * @property {string} variant identifier of the variant
90
+ * @property {Object} variant identifier of the variant
91
+ * @property {string} variant.name name of the variant
141
92
  */
142
93
 
143
94
  /**
@@ -145,106 +96,183 @@ function* content2Sources(content, dir) {
145
96
  * - for each architecture deliver a new result
146
97
  * - if no architecture is given one result set is provided nethertheless
147
98
  * - architectures are taken from cpu (node arch ids) and from pkgbuild.arch (raw arch ids)
148
- * - architecture given in a abstract definition are used to restrict the set of avaliable architectures
99
+ * - architecture given in a variant definition are used to restrict the set of avaliable architectures
149
100
  * @param {Object} options
150
- * @param {Object} options.json package.json content
151
101
  * @param {string} options.dir where to look for package.json
102
+ * @param {Object} env as delared in process.env
152
103
  * @returns {AsyncIterator<PackageDefinition>}
153
104
  */
154
105
  export async function* extractFromPackage(options = {}, env = {}) {
155
- let variant = "default";
156
- let sources = [];
157
- let output = {};
158
- let arch = new Set();
159
- let restrictArch = new Set();
160
- let groups;
161
-
162
- function processPkg(json, dir, modulePath) {
163
- const pkgbuild = json.pkgbuild;
164
-
165
- if (pkgbuild) {
166
- if(pkgbuild?.requires?.environment) {
167
- if(env[pkgbuild.requires.environment.has] === undefined) {
106
+ const variants = {};
107
+ const fragments = {};
108
+ let root, parent;
109
+
110
+ await packageWalker(async (packageContent, base, modulePath) => {
111
+ let i = 0;
112
+ for (const pkgbuild of Array.isArray(packageContent.pkgbuild)
113
+ ? packageContent.pkgbuild
114
+ : packageContent.pkgbuild
115
+ ? [packageContent.pkgbuild]
116
+ : []) {
117
+ if (pkgbuild.requires?.environment) {
118
+ if (env[pkgbuild.requires.environment.has] === undefined) {
168
119
  return;
169
120
  }
170
121
  }
171
122
 
172
- if (modulePath) {
173
- if (!pkgbuild.abstract) {
174
- if (pkgbuild.groups === groups) {
175
- dependencies[pkgbuild.name || json.name] = ">=" + json.version;
176
- }
177
- }
178
- } else {
179
- groups = pkgbuild.groups;
123
+ const fragment = {
124
+ name: `${packageContent.name}[${i++}]`,
125
+ depends: packageContent.engines || {},
126
+ arch: new Set(),
127
+ restrictArch: new Set()
128
+ };
180
129
 
181
- if (json.cpu) {
182
- for (const a of asArray(json.cpu)) {
183
- arch.add(npmArchMapping[a]);
184
- }
130
+ if (packageContent.cpu) {
131
+ for (const a of asArray(packageContent.cpu)) {
132
+ fragment.arch.add(npmArchMapping[a]);
185
133
  }
186
- if (pkgbuild.arch) {
187
- for (const a of asArray(pkgbuild.arch)) {
188
- arch.add(a);
134
+ }
135
+ if (pkgbuild.arch) {
136
+ for (const a of asArray(pkgbuild.arch)) {
137
+ fragment.arch.add(a);
138
+ if (modulePath.length === 0) {
139
+ fragment.restrictArch.add(a);
189
140
  }
190
141
  }
142
+ delete pkgbuild.arch;
143
+ }
144
+
145
+ if(pkgbuild.hooks) {
146
+ pkgbuild.hooks = resolve(base, pkgbuild.hooks);
147
+ }
148
+
149
+ for (const k of ["output", "content", "depends"]) {
150
+ if (pkgbuild[k]) {
151
+ fragment[k] = pkgbuild[k];
152
+ delete pkgbuild[k];
153
+ }
191
154
  }
192
155
 
193
- if (pkgbuild.abstract || !modulePath) {
194
- if (pkgbuild.variant) {
195
- variant = pkgbuild.variant;
156
+ const properties = Object.assign(
157
+ {
158
+ access: packageContent.publishConfig?.access || "private"
159
+ },
160
+ packageContent.config,
161
+ modulePath.length === 0 &&
162
+ Object.fromEntries(
163
+ ["name", "version", "description", "homepage", "license"]
164
+ .map(key => [key, packageContent[key]])
165
+ .filter(([k, v]) => v !== undefined)
166
+ ),
167
+ pkgbuild,
168
+ );
169
+
170
+ if (modulePath.length >= 1) {
171
+ fragment.parent =
172
+ modulePath.length === 1 ? parent : modulePath[modulePath.length - 2];
173
+ } else {
174
+ if (properties.name) {
175
+ properties.name = properties.name.replace(/^\@[^\/]+\//, "");
176
+ }
177
+
178
+ if (packageContent.bugs?.url) {
179
+ properties.bugs = packageContent.bugs.url;
180
+ }
181
+
182
+ if (packageContent.contributors) {
183
+ properties.maintainer = packageContent.contributors.map(
184
+ c => `${c.name} <${c.email}>`
185
+ )[0];
196
186
  }
197
187
 
198
- if (pkgbuild.arch) {
199
- for (const a of asArray(pkgbuild.arch)) {
200
- restrictArch.add(a);
188
+ if (typeof packageContent.repository === "string") {
189
+ properties.source = packageContent.repository;
190
+ } else {
191
+ if (packageContent.repository?.url) {
192
+ properties.source = packageContent.repository.url;
201
193
  }
202
194
  }
195
+ }
203
196
 
204
- Object.assign(output, pkgbuild.output);
197
+ fragment.properties = properties;
198
+ fragment.dir = join(base, ...modulePath.map(p => `node_modules/${p}`));
205
199
 
206
- Object.entries(pkgbuild)
207
- .filter(([k, v]) => typeof v === "string")
208
- .forEach(([k, v]) => (properties[k] = v));
200
+ fragments[packageContent.name] = fragment;
201
+
202
+ if (pkgbuild.variant) {
203
+ fragment.priority = 1;
204
+ variants[pkgbuild.variant] = fragment;
205
+ }
209
206
 
210
- sources.push(...content2Sources(context.expand(pkgbuild.content), dir));
207
+ if (modulePath.length === 0) {
208
+ root = fragment;
211
209
  }
212
- Object.assign(dependencies, pkgbuild.depends);
213
210
  }
211
+ parent = packageContent.name;
212
+
213
+ return true;
214
+ }, await packageDirectory({ cwd: options.dir }));
215
+
216
+ if (root && Object.keys(variants).length === 0) {
217
+ variants.default = root;
214
218
  }
215
219
 
216
- let json = options.json;
217
- let dir = options.dir;
220
+ //console.log(variants);
218
221
 
219
- if (!json) {
220
- dir = await packageDirectory({ cwd: dir });
222
+ for (const [name, variant] of Object.entries(variants)) {
223
+ const arch = [...variant.arch].sort();
224
+ const properties = {};
225
+ const depends = {};
226
+ const output = {};
227
+ const sources = [];
221
228
 
222
- json = JSON.parse(
223
- await readFile(join(dir, "package.json"), utf8StreamOptions)
224
- );
225
- }
229
+ for (
230
+ let fragment = variant;
231
+ fragment;
232
+ fragment = fragments[fragment.parent]
233
+ ) {
234
+ const context = createContext({ properties: fragment.properties });
226
235
 
227
- const { properties, dependencies, context } = extractFromRootPackage(json);
236
+ Object.assign(properties, fragment.properties);
237
+ Object.assign(depends, fragment.depends);
238
+ Object.assign(output, fragment.output);
228
239
 
229
- await packageWalker(async (packageContent, base, modulePath) => {
230
- if (modulePath.length > 0) {
231
- processPkg(packageContent, base, modulePath);
240
+ sources.push(
241
+ ...content2Sources(context.expand(fragment.content), fragment.dir)
242
+ );
232
243
  }
233
- return true;
234
- }, dir);
235
244
 
236
- processPkg(json, dir);
245
+ properties.variant = name;
237
246
 
238
- properties.variant = variant;
247
+ const context = createContext({ properties });
248
+
249
+ const result = {
250
+ context,
251
+ variant: { name },
252
+ sources,
253
+ output,
254
+ dependencies: depends,
255
+ properties: context.expand(properties)
256
+ };
239
257
 
240
- if (arch.size > 0) {
241
- // provide each arch separadly
258
+ if(arch.length === 0) {
259
+ yield result;
260
+ }
261
+ else {
262
+ for (const a of arch) {
263
+ result.variant.arch = a;
264
+ result.properties.arch = [a];
265
+ yield result;
266
+ }
267
+ }
268
+ }
242
269
 
270
+ /*
243
271
  let numberOfArchs = 0;
244
272
 
245
273
  for (const a of arch) {
246
274
  if (!restrictArch.size || restrictArch.has(a)) {
247
- if (!options.prepare || npmArchMapping[process.arch] === a) {
275
+ if (!options.prepare || npmArchMapping[process.arch] === a) {
248
276
  numberOfArchs++;
249
277
  properties.arch = [a];
250
278
  yield {
@@ -265,15 +293,5 @@ export async function* extractFromPackage(options = {}, env = {}) {
265
293
  }`
266
294
  );
267
295
  }
268
- } else {
269
- // or one set if no arch is given
270
- yield {
271
- properties: context.expand(properties),
272
- sources,
273
- dependencies,
274
- output,
275
- variant: { name: variant, type: Object.keys(output) },
276
- context
277
- };
278
- }
296
+ */
279
297
  }