npm-pkgbuild 7.11.3 → 7.11.7

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.3",
3
+ "version": "7.11.7",
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",
@@ -27,12 +27,12 @@ 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("-d --destination <dir>", "where to put the package(s)", join(cwd,'dist'))
36
36
  .option("-p --pkgdir <dir>", "which package to use", process.cwd())
37
37
  .option(
38
38
  "-c --content <dir>",
@@ -54,7 +54,7 @@ program
54
54
  console.log(`pkgdir: ${pkgDir}`);
55
55
  }
56
56
 
57
- const { properties, sources, output } = await extractFromPackage(
57
+ const { properties, sources, output, dependencies } = await extractFromPackage(
58
58
  JSON.parse(
59
59
  await readFile(join(pkgDir, "package.json"), utf8StreamOptions)
60
60
  ),
@@ -88,6 +88,7 @@ program
88
88
  const fileName = await output.execute(
89
89
  aggregateFifo(sources.map(c => c[Symbol.asyncIterator]())),
90
90
  transformer,
91
+ dependencies,
91
92
  options,
92
93
  path => context.expand(path)
93
94
  );
@@ -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
  }
@@ -1,14 +1,17 @@
1
- import { join } from "path";
2
- import { cp } from "fs/promises";
1
+ import { join, dirname } from "path";
2
+ import { createReadStream, createWriteStream } from "fs";
3
+ import { mkdir } from "fs/promises";
4
+ import { pipeline } from "stream/promises";
3
5
  import { execa } from "execa";
4
6
  import { EmptyContentEntry, ReadableStreamContentEntry } from "content-entry";
7
+ import { iterableStringInterceptor } from "iterable-string-interceptor";
5
8
  import {
6
9
  keyValueTransformer,
7
10
  equalSeparatedKeyValuePairOptions
8
11
  } from "key-value-transformer";
9
12
  import { Packager } from "./packager.mjs";
10
13
  import { copyEntries, transform, fieldProvider } from "../util.mjs";
11
- import { quote } from "../util.mjs";
14
+ import { quote, utf8StreamOptions } from "../util.mjs";
12
15
 
13
16
  /**
14
17
  * @type KeyValueTransformOptions
@@ -49,16 +52,21 @@ export class PKG extends Packager {
49
52
  return `${p.name}-${p.version}-${p.release}-${p.arch}${this.constructor.fileNameExtension}`;
50
53
  }
51
54
 
52
- async execute(sources, transformer, options, expander) {
55
+ async execute(sources, transformer, dependencies, options, expander) {
53
56
  const properties = this.properties;
54
57
 
55
- //properties.depends = makeDepends({ ...pkg.engines });
58
+ if (properties.source) {
59
+ properties.md5sums = ["SKIP"];
60
+ }
61
+
62
+ //properties.depends = makeDepends(dependencies);
56
63
 
57
64
  const staging = await this.tmpdir;
58
65
 
59
66
  async function* trailingLines() {
60
67
  yield `
61
68
  package() {
69
+ depends=(${makeDepends(dependencies).map(v=>quote(v)).join(',')})
62
70
  cp -r $srcdir/* "$pkgdir"
63
71
  }
64
72
  `;
@@ -86,12 +94,24 @@ package() {
86
94
  });
87
95
 
88
96
  if (properties.hooks) {
89
- await cp(
90
- join(options.pkgdir, properties.hooks),
91
- join(staging, `${properties.name}.install`),
92
- {
93
- preserveTimestamps: true
94
- }
97
+ async function* transformer(expression, remainder, source, cb) {
98
+ const value = properties[expression];
99
+ yield value === undefined ? "" : value;
100
+ }
101
+
102
+ const destination = join(staging, properties.hooks);
103
+
104
+ await mkdir(dirname(destination), { recursive: true });
105
+
106
+ await pipeline(
107
+ iterableStringInterceptor(
108
+ createReadStream(
109
+ join(options.pkgdir, properties.hooks),
110
+ utf8StreamOptions
111
+ ),
112
+ transformer
113
+ ),
114
+ createWriteStream(destination, utf8StreamOptions)
95
115
  );
96
116
  }
97
117
 
@@ -101,7 +121,7 @@ package() {
101
121
  console.log(`stagingDir: ${staging}`);
102
122
  }
103
123
 
104
- const makepkg = await execa("makepkg", ["-f"], {
124
+ const makepkg = await execa("makepkg", ["-f", "-e"], {
105
125
  cwd: staging,
106
126
  env: { PKGDEST: options.destination }
107
127
  });
@@ -121,14 +141,14 @@ package() {
121
141
  const fields = {
122
142
  pkgname: { alias: "name", type: "string[]", mandatory: true },
123
143
  pkgver: { alias: "version", type: "string", mandatory: true },
124
- pkgrel: { alias: "release", type: "integer", default: 0, mandatory: true },
144
+ pkgrel: { alias: "release", type: "integer", default: 1, mandatory: true },
125
145
  epoch: { type: "integer", default: 0 },
126
146
  pkgdesc: { alias: "description", type: "string", mandatory: true },
127
147
  url: { alias: "homepage", type: "string" },
128
148
  license: { type: "string[]", mandatory: true },
129
149
  install: { alias: "hooks", type: "string" },
130
150
  changelog: { type: "string" },
131
- source: { default: [], type: "string[]" },
151
+ source: { type: "string[]" },
132
152
  validpgpkeys: { type: "string[]" },
133
153
  noextract: { type: "string[]" },
134
154
  cksums: { type: "string[]" },
@@ -150,36 +170,21 @@ const fields = {
150
170
  options: { type: "string[]" }
151
171
  };
152
172
 
153
- /*
154
- out.write(
155
- `# ${pkg.contributors
156
- .map(
157
- (c, i) => `${i ? "Contributor" : "Maintainer"}: ${c.name} <${c.email}>`
158
- )
159
- .join("\n# ")}
160
-
161
- build() {
162
- cd \${pkgname}${directory}
163
- sed -i 's/"version": ".* /"version": "${
164
- context.properties.pkgver
165
- }",/' package.json
166
- npm install
167
- npm pack
168
- npm prune --production
169
- }
173
+ const mapping = {
174
+ node: "nodejs"
175
+ };
170
176
 
171
- package() {
172
- depends=(${makeDepends(pkg.pacman.depends)
173
- .map(a => `"${a}"`)
174
- .join(" ")})
177
+ function normalizeExpression(e) {
178
+ e = e.replace(/\-([\w\d]+)$/, "");
179
+ if (e.match(/^\d+/)) {
180
+ return `>=${e}`;
181
+ }
175
182
 
176
- mkdir -p \${pkgdir}${installdir}
177
- npx npm-pkgbuild --package \${srcdir}/\${pkgname}${directory} --staging \${pkgdir} content
183
+ return e;
178
184
  }
179
- `
180
- );
181
- */
182
185
 
183
- const mapping = {
184
- node: "nodejs"
185
- };
186
+ function makeDepends(dependencies) {
187
+ return Object.entries(dependencies).map(
188
+ ([name, version]) => `${name}${normalizeExpression(version)}`
189
+ );
190
+ }
@@ -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