npm-pkgbuild 7.15.4 → 7.15.8

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.15.4",
3
+ "version": "7.15.8",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -40,12 +40,12 @@
40
40
  "dependencies": {
41
41
  "aggregate-async-iterator": "^1.1.7",
42
42
  "commander": "^8.3.0",
43
- "content-entry": "^4.0.0",
44
- "content-entry-filesystem": "^4.0.0",
45
- "content-entry-transform": "^1.3.1",
43
+ "content-entry": "^4.1.2",
44
+ "content-entry-filesystem": "^4.0.3",
45
+ "content-entry-transform": "^1.3.4",
46
46
  "execa": "^6.0.0",
47
47
  "expression-expander": "^7.0.9",
48
- "globby": "^12.0.2",
48
+ "globby": "^12.2.0",
49
49
  "iterable-string-interceptor": "^1.0.8",
50
50
  "key-value-transformer": "^2.0.0",
51
51
  "npm-package-walker": "^5.0.3",
@@ -11,9 +11,9 @@ export const allInputs = [NPMPackContentProvider, NodeModulesContentProvider];
11
11
  export const allOutputs = [DEB, ARCH, RPM];
12
12
 
13
13
  const npmArchMapping = {
14
- "arm64" : "aarch64",
15
- "arm": "armv7h",
16
- "x86" : "x86_64"
14
+ arm64: "aarch64",
15
+ arm: "armv7h",
16
+ x86: "x86_64"
17
17
  };
18
18
 
19
19
  /**
@@ -48,10 +48,9 @@ export async function extractFromPackage(pkg, dir) {
48
48
  }
49
49
 
50
50
  if (pkg.repository) {
51
- if(typeof(pkg.repository) === 'string') {
51
+ if (typeof pkg.repository === "string") {
52
52
  properties.source = pkg.repository;
53
- }
54
- else {
53
+ } else {
55
54
  if (pkg.repository.url) {
56
55
  properties.source = pkg.repository.url;
57
56
  }
@@ -62,24 +61,23 @@ export async function extractFromPackage(pkg, dir) {
62
61
  let sources = [];
63
62
  let output = {};
64
63
  let arch = new Set();
65
-
66
- const processPkg = (pkg, dir) => {
67
64
 
68
- if(pkg.cpu) {
69
- for(const a of asArray(pkg.cpu)) {
65
+ const processPkg = (pkg, dir) => {
66
+ if (pkg.cpu) {
67
+ for (const a of asArray(pkg.cpu)) {
70
68
  arch.add(npmArchMapping[a]);
71
69
  }
72
- }
70
+ }
73
71
 
74
72
  if (pkg.pkg) {
75
73
  const pkgbuild = pkg.pkg;
76
74
 
77
- if(pkgbuild.arch) {
78
- for(const a of asArray(pkgbuild.arch)) {
75
+ if (pkgbuild.arch) {
76
+ for (const a of asArray(pkgbuild.arch)) {
79
77
  arch.add(a);
80
78
  }
81
79
  }
82
-
80
+
83
81
  Object.assign(output, pkgbuild.output);
84
82
 
85
83
  Object.entries(pkgbuild)
@@ -123,9 +121,9 @@ export async function extractFromPackage(pkg, dir) {
123
121
 
124
122
  processPkg(pkg, dir);
125
123
 
126
- if(arch.size > 0) {
124
+ if (arch.size > 0) {
127
125
  properties.arch = [...arch];
128
126
  }
129
-
127
+
130
128
  return { properties, sources, dependencies, output };
131
129
  }
@@ -83,6 +83,15 @@ program
83
83
  )) {
84
84
  Object.assign(properties, options.define);
85
85
 
86
+ for (const [k, v] of Object.entries(properties)) {
87
+ if (typeof v === "string") {
88
+ properties[k] = v.replace(
89
+ /\$\{([^\}]+)\}/m,
90
+ (m, k) => properties[k]
91
+ );
92
+ }
93
+ }
94
+
86
95
  sources.push(
87
96
  ...[...options.content, ...options.meta]
88
97
  .filter(x => x)
@@ -43,6 +43,9 @@ function keyPrefix(key) {
43
43
  return f && f.prefix ? f.prefix + key : key;
44
44
  }
45
45
 
46
+
47
+ const PKGBUILD = "PKGBUILD";
48
+
46
49
  export class ARCH extends Packager {
47
50
  static get name() {
48
51
  return "arch";
@@ -108,8 +111,8 @@ package() {
108
111
  const fp = fieldProvider(properties, fields);
109
112
 
110
113
  transformer.push({
111
- name: "PKGBUILD",
112
- match: entry => entry.name === "PKGBUILD",
114
+ name: PKGBUILD,
115
+ match: entry => entry.name === PKGBUILD,
113
116
  transform: async entry =>
114
117
  new ReadableStreamContentEntry(
115
118
  "../" + entry.name,
@@ -118,7 +121,7 @@ package() {
118
121
  trailingLines
119
122
  })
120
123
  ),
121
- createEntryWhenMissing: () => new EmptyContentEntry("PKGBUILD")
124
+ createEntryWhenMissing: () => new EmptyContentEntry(PKGBUILD)
122
125
  });
123
126
 
124
127
  for await (const file of copyEntries(
package/src/util.mjs CHANGED
@@ -2,11 +2,56 @@ import { join, dirname } from "path";
2
2
  import { mkdir } from "fs/promises";
3
3
  import { pipeline } from "stream/promises";
4
4
  import { createWriteStream } from "fs";
5
- import { iterableStringInterceptor } from "iterable-string-interceptor";
6
- import { ReadableStreamContentEntry } from "content-entry";
7
5
 
8
6
  export const utf8StreamOptions = { encoding: "utf8" };
9
7
 
8
+ /**
9
+ * Extract shell functions from a given text
10
+ * @param {AsyncIterator<string>} source
11
+ * @return {AsyncIterator<FunctionDecl>}
12
+ */
13
+ export async function* extractFunctions(source) {
14
+ let name;
15
+ let body = [];
16
+
17
+ for await (const line of asLines(source)) {
18
+ let m;
19
+
20
+ if ((m = line.match(/^\s*(function\s*)?([\w_]+)\s*\(\s*\)/))) {
21
+ name = m[2];
22
+ continue;
23
+ }
24
+
25
+ if (name) {
26
+ if (line.match(/^}$/)) {
27
+ yield { name, body: body.join("\n")};
28
+ name = undefined;
29
+ body.length = 0;
30
+ }
31
+ else {
32
+ body.push(line);
33
+ }
34
+ }
35
+ }
36
+ }
37
+
38
+ async function* asLines(source) {
39
+ let buffer = "";
40
+
41
+ for await (let chunk of source) {
42
+ buffer += chunk.toString();
43
+ const lines = buffer.split(/\n\r?/);
44
+ buffer = lines.pop();
45
+ for (const line of lines) {
46
+ yield line;
47
+ }
48
+ }
49
+
50
+ if (buffer.length > 0) {
51
+ yield buffer;
52
+ }
53
+ }
54
+
10
55
  export function quote(v) {
11
56
  if (v === undefined) return "";
12
57