npm-pkgbuild 7.4.0 → 7.4.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "7.4.0",
3
+ "version": "7.4.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -11,7 +11,7 @@ import { ContentProvider } from "./content-provider.mjs";
11
11
  * @param {string} definitions.base base directory where to find the files
12
12
  */
13
13
  export class FileContentProvider extends ContentProvider {
14
- constructor(definitions) {
14
+ constructor(definitions, entryProperties) {
15
15
  super();
16
16
 
17
17
  if (typeof definitions === "string") {
@@ -24,6 +24,8 @@ export class FileContentProvider extends ContentProvider {
24
24
  this.definitions = { pattern: ["**/*"], ...definitions };
25
25
  this.definitions.pattern = asArray(this.definitions.pattern);
26
26
  }
27
+
28
+ this.entryProperties = entryProperties;
27
29
  }
28
30
 
29
31
  async *[Symbol.asyncIterator]() {
@@ -33,7 +35,9 @@ export class FileContentProvider extends ContentProvider {
33
35
  for (const name of await globby(definitions.pattern, {
34
36
  cwd: base
35
37
  })) {
36
- yield new FileSystemEntry(name, base);
38
+ const entry = new FileSystemEntry(name, base);
39
+ Object.assign(entry, this.entryProperties);
40
+ yield entry;
37
41
  }
38
42
  }
39
43
  }
@@ -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";
@@ -57,17 +58,24 @@ program
57
58
  sources.push(
58
59
  ...[...options.content, ...options.meta]
59
60
  .filter(x => x)
60
- .map(source => [
61
- new FileContentProvider({
62
- base: source
63
- }),
64
- ""
65
- ])
61
+ .map(
62
+ source =>
63
+ new FileContentProvider({
64
+ base: source
65
+ })
66
+ )
66
67
  );
67
68
 
69
+ const context = createContext();
70
+ context.properties = properties;
71
+
68
72
  const output = new outputFactory(properties);
69
73
 
70
- const fileName = await output.execute(aggregateFifo(sources.map(([c, d]) => c[Symbol.asyncIterator]() )), options);
74
+ const fileName = await output.execute(
75
+ aggregateFifo(sources.map(c => c[Symbol.asyncIterator]())),
76
+ options,
77
+ (object) => context.expand(object)
78
+ );
71
79
 
72
80
  console.log(fileName);
73
81
  }
@@ -21,10 +21,11 @@ export class DEB extends Packager {
21
21
  }
22
22
 
23
23
  get packageFileName() {
24
- return `${this.properties.name}_${this.properties.version}_${this.properties.arch}${this.constructor.fileNameExtension}`;
24
+ const p = this.properties;
25
+ return `${p.name}_${p.version}_${p.arch}${this.constructor.fileNameExtension}`;
25
26
  }
26
27
 
27
- async execute(sources, options) {
28
+ async execute(sources, options, expander) {
28
29
  const properties = this.properties;
29
30
  const mandatoryFields = this.mandatoryFields;
30
31
  const staging = await this.tmpdir;
@@ -55,7 +56,7 @@ export class DEB extends Packager {
55
56
  }
56
57
  ];
57
58
 
58
- await copyEntries(transform(sources, transformers), staging, attributes);
59
+ await copyEntries(transform(sources, transformers), staging, expander, attributes);
59
60
 
60
61
  await execa("dpkg", ["-b", staging, options.destination]);
61
62
 
@@ -1,3 +1,4 @@
1
+ import { join } from "path";
1
2
  import { execa } from "execa";
2
3
  import { EmptyContentEntry, ReadableStreamContentEntry } from "content-entry";
3
4
  import {
@@ -18,7 +19,7 @@ export const pkgKeyValuePairOptions = {
18
19
  extractKeyValue: line => {
19
20
  const m = line.match(/^(\w+)=\s*\((.*)\)|(.*)/);
20
21
  if (m) {
21
- return [m[1], m[2] ? [m[2]] : m[3]];
22
+ return [m[1], m[2] ? [m[2].split(/\s*,\s*/)] : m[3]];
22
23
  }
23
24
  },
24
25
  keyValueLine: (key, value, lineEnding) =>
@@ -42,8 +43,16 @@ export class PKG extends Packager {
42
43
  return fields;
43
44
  }
44
45
 
45
- async execute(sources, options) {
46
+ get packageFileName() {
47
+ const p = this.properties;
48
+ return `${p.name}-${p.version}-${p.release}.${p.arch}${this.constructor.fileNameExtension}`;
49
+ }
50
+
51
+ async execute(sources, options,expander) {
46
52
  const properties = this.properties;
53
+
54
+ //properties.depends = makeDepends({ ...pkg.engines });
55
+
47
56
  const mandatoryFields = this.mandatoryFields;
48
57
  const staging = await this.tmpdir;
49
58
 
@@ -68,7 +77,9 @@ package() {
68
77
  `;
69
78
  }
70
79
 
71
- const transformers = [
80
+ await copyEntries(transform(sources, []), join(staging, "src"), expander);
81
+
82
+ const metaTransformers = [
72
83
  {
73
84
  match: entry => entry.name === "PKGBUILD",
74
85
  transform: async entry =>
@@ -83,9 +94,11 @@ package() {
83
94
  }
84
95
  ];
85
96
 
86
- await copyEntries(transform(sources, transformers), staging);
97
+ await copyEntries(transform(sources, metaTransformers, true), staging, expander);
87
98
 
88
99
  await execa("makepkg", ["-f"], { cwd: staging });
100
+
101
+ return join(options.destination, this.packageFileName);
89
102
  }
90
103
  }
91
104
 
@@ -100,7 +113,7 @@ const fields = {
100
113
  pkgdesc: { alias: "description", type: "string", mandatory: true },
101
114
  arch: { default: ["any"], type: "string[]", mandatory: true },
102
115
 
103
- license: { type: "string[]", mandatory: true },
116
+ license: { default: [], type: "string[]", mandatory: true },
104
117
  source: { default: [], type: "string[]" },
105
118
  validpgpkeys: { type: "string[]" },
106
119
  noextract: { type: "string[]" },
@@ -127,21 +140,6 @@ const fields = {
127
140
  };
128
141
 
129
142
  /*
130
- if (pkg.repository) {
131
- source = pkg.repository.url;
132
- if (!source.startsWith("git+")) {
133
- source = "git+" + source;
134
- }
135
-
136
- directory = pkg.repository.directory ? "/" + pkg.repository.directory : "";
137
- }
138
-
139
- const properties = {
140
- makedepends: "git"
141
- };
142
-
143
- properties.depends = makeDepends({ ...pkg.engines });
144
-
145
143
  out.write(
146
144
  `# ${pkg.contributors
147
145
  .map(
@@ -173,19 +171,8 @@ package() {
173
171
  }
174
172
  `
175
173
  );
176
-
177
- function makeDepends(d) {
178
- if (d === undefined) {
179
- return [];
180
- }
181
-
182
- return Object.keys(d).reduce((a, c) => {
183
- const mapping = {
184
- node: "nodejs"
185
- };
186
-
187
- a.push(`${mapping[c] ? mapping[c] : c}${d[c].replace(/\-([\w\d]+)$/, "")}`);
188
- return a;
189
- }, []);
190
- }
191
174
  */
175
+
176
+ const mapping = {
177
+ node: "nodejs"
178
+ };
@@ -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,14 +76,13 @@ 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",
83
83
  `_topdir ${tmp}`,
84
84
  "-vv",
85
85
  "-bb",
86
- // `--target=${properties.arch}`,
87
86
  join(staging, specFileName)
88
87
  ]);
89
88
 
package/src/util.mjs CHANGED
@@ -53,6 +53,7 @@ export function extractFromPackage(pkg) {
53
53
  properties.source = pkg.repository.url;
54
54
  }
55
55
 
56
+ let dependencies = { ...pkg.engines };
56
57
  let sources = [];
57
58
 
58
59
  if (pkg.pkgbuild) {
@@ -62,14 +63,16 @@ export function extractFromPackage(pkg) {
62
63
  .forEach(([k, v]) => (properties[k] = v));
63
64
 
64
65
  if (pkgbuild.content) {
65
- sources = Object.entries(pkgbuild.content).map(([destination, value]) => [
66
- new FileContentProvider(value),
67
- destination
68
- ]);
66
+ sources = Object.entries(pkgbuild.content).map(
67
+ ([destination, value]) =>
68
+ new FileContentProvider(value, { destination })
69
+ );
69
70
  }
71
+
72
+ Object.assign(dependencies, pkgbuild.depends);
70
73
  }
71
74
 
72
- return { properties, sources };
75
+ return { properties, sources, dependencies };
73
76
  }
74
77
 
75
78
  /**
@@ -77,7 +80,7 @@ export function extractFromPackage(pkg) {
77
80
  * @param {AsyncIterator<ContentEntry>} source
78
81
  * @param {Transformer[]} transformers
79
82
  */
80
- export async function* transform(source, transformers) {
83
+ export async function* transform(source, transformers = [], onlyMatching) {
81
84
  const usedTransformers = new Set();
82
85
 
83
86
  for await (let entry of source) {
@@ -85,10 +88,16 @@ export async function* transform(source, transformers) {
85
88
  if (t.match(entry)) {
86
89
  entry = await t.transform(entry);
87
90
  usedTransformers.add(t);
91
+
92
+ if (onlyMatching) {
93
+ yield entry;
94
+ }
88
95
  }
89
96
  }
90
97
 
91
- yield entry;
98
+ if (!onlyMatching) {
99
+ yield entry;
100
+ }
92
101
  }
93
102
 
94
103
  for (const t of transformers) {
@@ -99,17 +108,20 @@ export async function* transform(source, transformers) {
99
108
  }
100
109
 
101
110
  /**
102
- * Copy content from source into destinationDirectory
111
+ * Copy content from source into destinationDirectory.
103
112
  * @param {AsyncIterator<ContentEntry>} source
104
113
  * @param {string} destinationDirectory
114
+ * @param {Function} expander
115
+ * @param {ContentEntryAttribute[]} attributes
105
116
  */
106
117
  export async function copyEntries(
107
118
  source,
108
119
  destinationDirectory,
120
+ expander = (v) => v,
109
121
  attributes = []
110
122
  ) {
111
123
  for await (let entry of source) {
112
- const destName = join(destinationDirectory, entry.name);
124
+ const destName = expander(entry.destination === undefined ? join(destinationDirectory, entry.name) : join(destinationDirectory, entry.destination, entry.name));
113
125
  await mkdir(dirname(destName), { recursive: true });
114
126
 
115
127
  const options = { mode: entry.mode };