npm-pkgbuild 7.11.5 → 7.11.9

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2018-2021 by arlac77
1
+ Copyright (c) 2018-2022 by arlac77
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
package/README.md CHANGED
@@ -11,14 +11,14 @@
11
11
 
12
12
  ## npm-pkgbuild
13
13
 
14
- create ArchLinux, RPM and debian packages from npm packages.
14
+ create ArchLinux, RPM and Debian packages from npm packages.
15
15
 
16
16
  # usage
17
17
 
18
18
  In a package directory execute
19
19
 
20
20
  ```shell
21
- npm-pkgbuild --npm-dist --npm-modules pkgbuild pacman makepkg
21
+ npm-pkgbuild --pkg
22
22
  ```
23
23
 
24
24
  This will create a PKGBUILD file and execute it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "7.11.5",
3
+ "version": "7.11.9",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -8,7 +8,7 @@
8
8
  "exports": {
9
9
  ".": "./src/module.mjs"
10
10
  },
11
- "description": "create ArchLinux, RPM and debian packages from npm packages",
11
+ "description": "create ArchLinux, RPM and Debian packages from npm packages",
12
12
  "keywords": [
13
13
  "ArchLinux",
14
14
  "arch-linux",
package/src/module.mjs CHANGED
@@ -6,5 +6,5 @@ export * from "./content/node-modules-content-provider.mjs";
6
6
  export * from "./content/npm-pack-content-provider.mjs";
7
7
  export * from "./output/deb.mjs";
8
8
  export * from "./output/rpm.mjs";
9
- export * from "./output/pkg.mjs";
9
+ export * from "./output/arch.mjs";
10
10
  export * from "./output/packager.mjs";
@@ -8,7 +8,7 @@ import { aggregateFifo } from "aggregate-async-iterator";
8
8
  import { createContext } from "expression-expander";
9
9
  import { packageDirectory } from "pkg-dir";
10
10
  import { utf8StreamOptions, extractFromPackage } from "./util.mjs";
11
- import { FileContentProvider, DEB, PKG, RPM } from "npm-pkgbuild";
11
+ import { FileContentProvider, DEB, ARCH, RPM } from "npm-pkgbuild";
12
12
  import { createExpressionTransformer } from "./util.mjs";
13
13
 
14
14
  const { version, description } = JSON.parse(
@@ -18,7 +18,7 @@ const { version, description } = JSON.parse(
18
18
 
19
19
  const cwd = process.cwd();
20
20
 
21
- const allOutputs = [DEB, PKG, RPM];
21
+ const allOutputs = [DEB, ARCH, RPM];
22
22
 
23
23
  program.description(description).version(version);
24
24
 
@@ -27,12 +27,16 @@ allOutputs.forEach(o =>
27
27
  );
28
28
 
29
29
  program
30
+ .option("--verbose", "be more verbose", false)
30
31
  .option("-D --define <a=b>", "define property", str => {
31
32
  const kv = str.split(/=/);
32
33
  return Object.fromEntries([kv]);
33
34
  })
34
- .option("-d --destination <dir>", "where to put the package(s)", cwd)
35
- .option("--verbose", "be more verbose", false)
35
+ .option(
36
+ "-d --destination <dir>",
37
+ "where to put the package(s)",
38
+ join(cwd, "dist")
39
+ )
36
40
  .option("-p --pkgdir <dir>", "which package to use", process.cwd())
37
41
  .option(
38
42
  "-c --content <dir>",
@@ -48,18 +52,19 @@ program
48
52
  )
49
53
  .action(async options => {
50
54
  try {
51
- const pkgDir = await packageDirectory({ cwd: options.pkgdir});
55
+ const pkgDir = await packageDirectory({ cwd: options.pkgdir });
52
56
 
53
57
  if (options.verbose) {
54
58
  console.log(`pkgdir: ${pkgDir}`);
55
59
  }
56
60
 
57
- const { properties, sources, output } = await extractFromPackage(
58
- JSON.parse(
59
- await readFile(join(pkgDir, "package.json"), utf8StreamOptions)
60
- ),
61
- pkgDir
62
- );
61
+ const { properties, sources, output, dependencies } =
62
+ await extractFromPackage(
63
+ JSON.parse(
64
+ await readFile(join(pkgDir, "package.json"), utf8StreamOptions)
65
+ ),
66
+ pkgDir
67
+ );
63
68
 
64
69
  for (const outputFactory of allOutputs.filter(
65
70
  o => options[o.name] === true || output[o.name] !== undefined
@@ -80,7 +85,7 @@ program
80
85
  const context = createContext({ properties });
81
86
  const output = new outputFactory(properties);
82
87
  const transformer = [createExpressionTransformer(properties)];
83
-
88
+
84
89
  if (options.verbose) {
85
90
  console.log(output.properties);
86
91
  }
@@ -88,11 +93,21 @@ program
88
93
  const fileName = await output.execute(
89
94
  aggregateFifo(sources.map(c => c[Symbol.asyncIterator]())),
90
95
  transformer,
96
+ dependencies,
91
97
  options,
92
98
  path => context.expand(path)
93
99
  );
94
100
 
95
- //console.log(`#<CI>publish ${fileName}`);
101
+ /*
102
+ console.log(`#<CI>publish ${fileName}`);
103
+
104
+ if (publish !== undefined) {
105
+ context.properties.arch = arch;
106
+
107
+ publish = publish.replace(/\{\{(\w+)\}\}/m, (match, key, offset, string) =>
108
+ context.evaluate(key)
109
+ );
110
+ */
96
111
  }
97
112
  } catch (e) {
98
113
  console.log(e);
@@ -34,9 +34,9 @@ export const pkgKeyValuePairOptions = {
34
34
  }${lineEnding}`
35
35
  };
36
36
 
37
- export class PKG extends Packager {
37
+ export class ARCH extends Packager {
38
38
  static get name() {
39
- return "pkg";
39
+ return "arch";
40
40
  }
41
41
 
42
42
  static get fileNameExtension() {
@@ -52,20 +52,21 @@ export class PKG extends Packager {
52
52
  return `${p.name}-${p.version}-${p.release}-${p.arch}${this.constructor.fileNameExtension}`;
53
53
  }
54
54
 
55
- async execute(sources, transformer, options, expander) {
55
+ async execute(sources, transformer, dependencies, options, expander) {
56
56
  const properties = this.properties;
57
57
 
58
58
  if (properties.source) {
59
59
  properties.md5sums = ["SKIP"];
60
60
  }
61
61
 
62
- //properties.depends = makeDepends({ ...pkg.engines });
62
+ //properties.depends = makeDepends(dependencies);
63
63
 
64
64
  const staging = await this.tmpdir;
65
65
 
66
66
  async function* trailingLines() {
67
67
  yield `
68
68
  package() {
69
+ depends=(${makeDepends(dependencies).map(v=>quote(v)).join(',')})
69
70
  cp -r $srcdir/* "$pkgdir"
70
71
  }
71
72
  `;
@@ -112,16 +113,6 @@ package() {
112
113
  ),
113
114
  createWriteStream(destination, utf8StreamOptions)
114
115
  );
115
-
116
- /*
117
- await cp(
118
- join(options.pkgdir, properties.hooks),
119
- join(staging, properties.hooks),
120
- {
121
- preserveTimestamps: true
122
- }
123
- );
124
- */
125
116
  }
126
117
 
127
118
  await copyEntries(transform(sources, transformer, true), staging, expander);
@@ -130,7 +121,7 @@ package() {
130
121
  console.log(`stagingDir: ${staging}`);
131
122
  }
132
123
 
133
- const makepkg = await execa("makepkg", ["-f"], {
124
+ const makepkg = await execa("makepkg", ["-f", "-e"], {
134
125
  cwd: staging,
135
126
  env: { PKGDEST: options.destination }
136
127
  });
@@ -179,34 +170,21 @@ const fields = {
179
170
  options: { type: "string[]" }
180
171
  };
181
172
 
182
- /*
183
- out.write(
184
- `# ${pkg.contributors
185
- .map(
186
- (c, i) => `${i ? "Contributor" : "Maintainer"}: ${c.name} <${c.email}>`
187
- )
188
- .join("\n# ")}
189
-
190
- build() {
191
- cd \${pkgname}${directory}
192
- sed -i 's/"version": ".* /"version": "${
193
- context.properties.pkgver
194
- }",/' package.json
195
- npm install
196
- npm pack
197
- npm prune --production
198
- }
173
+ const mapping = {
174
+ node: "nodejs"
175
+ };
199
176
 
200
- package() {
201
- depends=(${makeDepends(pkg.pacman.depends)
202
- .map(a => `"${a}"`)
203
- .join(" ")})
177
+ function normalizeExpression(e) {
178
+ e = e.replace(/\-([\w\d]+)$/, "");
179
+ if (e.match(/^\d+/)) {
180
+ return `>=${e}`;
181
+ }
204
182
 
205
- mkdir -p \${pkgdir}${installdir}
206
- npx npm-pkgbuild --package \${srcdir}/\${pkgname}${directory} --staging \${pkgdir} content
183
+ return e;
207
184
  }
208
- */
209
185
 
210
- const mapping = {
211
- node: "nodejs"
212
- };
186
+ function makeDepends(dependencies) {
187
+ return Object.entries(dependencies).map(
188
+ ([name, version]) => `${name}${normalizeExpression(version)}`
189
+ );
190
+ }
@@ -23,7 +23,7 @@ export class DEB extends Packager {
23
23
  return `${p.name}_${p.version}_${p.arch}${this.constructor.fileNameExtension}`;
24
24
  }
25
25
 
26
- async execute(sources, transformer, options, expander) {
26
+ async execute(sources, transformer, dependencies, options, expander) {
27
27
  const properties = this.properties;
28
28
  const staging = await this.tmpdir;
29
29
 
@@ -54,5 +54,5 @@ export class Packager {
54
54
  /**
55
55
  * Execute package generation
56
56
  */
57
- async execute(sources, options) {}
57
+ async execute(sources, transformer, dependencies, options, expander) {}
58
58
  }
@@ -27,7 +27,7 @@ export class RPM extends Packager {
27
27
  return fields;
28
28
  }
29
29
 
30
- async execute(sources, transformer, options, expander) {
30
+ async execute(sources, transformer, dependencies, options, expander) {
31
31
  const properties = this.properties;
32
32
  const tmp = await this.tmpdir;
33
33
 
package/src/util.mjs CHANGED
@@ -99,8 +99,8 @@ export async function extractFromPackage(pkg, dir) {
99
99
  let output = {};
100
100
 
101
101
  const processPkg = pkg => {
102
- if (pkg.pkgbuild) {
103
- const pkgbuild = pkg.pkgbuild;
102
+ if (pkg.pkg) {
103
+ const pkgbuild = pkg.pkg;
104
104
 
105
105
  Object.assign(output, pkgbuild.output);
106
106
 
@@ -138,7 +138,7 @@ export function createModeTransformer(mode, match) {
138
138
 
139
139
  export function createExpressionTransformer(
140
140
  properties,
141
- match = entry => entry.name.match(/\.(conf|json|html|txt)$/)
141
+ match = entry => entry.name.match(/\.(conf|json|html|txt|service|socket)$/)
142
142
  ) {
143
143
  async function* transformer(expression, remainder, source, cb) {
144
144
  const value = properties[expression];