npm-pkgbuild 10.6.0 → 10.7.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
@@ -27,18 +27,18 @@ This will create a arch, rpm and a debian package of the build dir.
27
27
  ## upload package
28
28
 
29
29
  ```shell
30
- npm-pkgbuild --rpm --debian --arch --content build --publish 'https://my.package-service.com/binaries/linux/{{type}}/{{access}}/{{arch}}'
30
+ npm-pkgbuild --arch --content build --publish 'https://my.package-service.com/binaries/linux/{{type}}/{{access}}/{{arch}}'
31
31
  ```
32
32
 
33
33
  You can specify the package content in package.json.
34
34
 
35
35
  ```json
36
36
  {
37
- "pkgbuild": {
38
- "content": {
39
- "/some/location/" : { "base": "build" },
40
- "/etc/myconfig.json" : "sample-config.json",
41
- "/erc/secret" : { "name": "secret", "mode": "600" },
37
+ "pkgbuild": {
38
+ "content": {
39
+ "/some/location/" : { "base": "build" },
40
+ "/etc/myconfig.json" : "sample-config.json",
41
+ "/erc/secret" : { "name": "secret", "mode": "600" },
42
42
  "/opt/myapp": [
43
43
  {
44
44
  "type": "npm-pack"
@@ -48,15 +48,15 @@ You can specify the package content in package.json.
48
48
  "withoutDevelpmentDependencies": true
49
49
  }
50
50
  ]
51
- },
52
- "hooks" : "pkg/hooks",
53
- "output": {
54
- "debian" : {},
55
- "rpm" : {},
56
- "arch" : {}
57
- },
58
- "dependencies": { "nginx" : ">=1.12" }
59
- }
51
+ },
52
+ "hooks" : "pkg/hooks",
53
+ "output": {
54
+ "debian" : {},
55
+ "rpm" : {},
56
+ "arch" : {}
57
+ },
58
+ "dependencies": { "nginx" : ">=1.12" }
59
+ }
60
60
  }
61
61
  ```
62
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "10.6.0",
3
+ "version": "10.7.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -67,7 +67,7 @@
67
67
  "stream-buffers": "^3.0.2"
68
68
  },
69
69
  "engines": {
70
- "node": ">=16.14.2"
70
+ "node": ">=16.15.0"
71
71
  },
72
72
  "repository": {
73
73
  "type": "git",
@@ -1,6 +1,9 @@
1
+ import { readFile } from "fs/promises";
2
+ import { join } from "path";
3
+ import { packageDirectory } from "pkg-dir";
1
4
  import { packageWalker } from "npm-package-walker";
2
5
  import { createContext } from "expression-expander";
3
- import { asArray } from "./util.mjs";
6
+ import { asArray, utf8StreamOptions } from "./util.mjs";
4
7
  import { NPMPackContentProvider } from "./content/npm-pack-content-provider.mjs";
5
8
  import { NodeModulesContentProvider } from "./content/node-modules-content-provider.mjs";
6
9
  import { FileContentProvider } from "./content/file-content-provider.mjs";
@@ -45,12 +48,23 @@ const entryAttributeNames = ["owner", "group", "mode"];
45
48
  * - if not architecture is given one result set is provided nethertheless
46
49
  * - architectures are taken from cpu (node arch ids) and from pkgbuild.arch (raw arch ids)
47
50
  * - architecture given in a abstract definition are used to reduce the set of avaliable architectures
48
- * @param {Object} pkg package.json content
49
- * @param {string} dir
50
51
  * @param {Object} options
52
+ * @param {Object} options.json package.json content
53
+ * @param {string} options.pkgDir
51
54
  * @returns {AsyncIter<PackageDefinition>}
52
55
  */
53
- export async function* extractFromPackage(json, dir, options = {}) {
56
+ export async function* extractFromPackage(options = {}) {
57
+ let json = options.json;
58
+ let dir = options.pkgDir;
59
+
60
+ if (!json) {
61
+ dir = await packageDirectory({ cwd: dir });
62
+
63
+ json = JSON.parse(
64
+ await readFile(join(dir, "package.json"), utf8StreamOptions)
65
+ );
66
+ }
67
+
54
68
  const properties = Object.fromEntries(
55
69
  ["name", "version", "description", "homepage", "license"]
56
70
  .map(key => [key, json[key]])
@@ -174,17 +188,19 @@ export async function* extractFromPackage(json, dir, options = {}) {
174
188
  }
175
189
  };
176
190
 
177
- await packageWalker(async (json, base, modulePath) => {
178
- if (modulePath.length > 0) {
179
- processPkg(json, base, modulePath);
180
- }
181
- return true;
182
- }, dir);
191
+ if (dir) {
192
+ await packageWalker(async (json, base, modulePath) => {
193
+ if (modulePath.length > 0) {
194
+ processPkg(json, base, modulePath);
195
+ }
196
+ return true;
197
+ }, dir);
198
+ }
183
199
 
184
200
  processPkg(json, dir);
185
201
 
186
202
  properties.variant = variant;
187
-
203
+
188
204
  if (arch.size > 0) {
189
205
  // provide each arch separadly
190
206
 
@@ -197,7 +213,7 @@ export async function* extractFromPackage(json, dir, options = {}) {
197
213
  } else {
198
214
  numberOfArchs++;
199
215
  properties.arch = [a];
200
- yield { properties, sources, dependencies, output, variant };
216
+ yield { properties: context.expand(properties), sources, dependencies, output, variant, context };
201
217
  }
202
218
  }
203
219
  }
@@ -206,6 +222,6 @@ export async function* extractFromPackage(json, dir, options = {}) {
206
222
  }
207
223
  } else {
208
224
  // or one set if no arch is given
209
- yield { properties, sources, dependencies, output, variant };
225
+ yield { properties: context.expand(properties), sources, dependencies, output, variant, context };
210
226
  }
211
227
  }
@@ -2,11 +2,7 @@
2
2
 
3
3
  import { readFileSync } from "fs";
4
4
  import { fileURLToPath } from "url";
5
- import { readFile } from "fs/promises";
6
- import { join } from "path";
7
5
  import { program } from "commander";
8
- import { createContext } from "expression-expander";
9
- import { packageDirectory } from "pkg-dir";
10
6
  import {
11
7
  createExpressionTransformer,
12
8
  nameExtensionMatcher
@@ -37,7 +33,7 @@ program
37
33
  .option("-D --define <a=b>", "define property", (str, former = {}) =>
38
34
  Object.assign(former, Object.fromEntries([str.split(/=/)]))
39
35
  )
40
- .option("-p --pkgdir <dir>", "which package to use", process.cwd())
36
+ .option("-p --dir <dir>", "which package to use", process.cwd())
41
37
  .option("-a --available", "only execute availabe output methods", false)
42
38
  .option("--continue", "continue on error")
43
39
  .option(
@@ -69,25 +65,15 @@ program
69
65
  )
70
66
  .action(async options => {
71
67
  try {
72
- const pkgDir = await packageDirectory({ cwd: options.pkgdir });
73
-
74
- if (options.verbose) {
75
- console.log(`pkgdir: ${pkgDir}`);
76
- }
68
+ const publishOptions = options.publish;
77
69
 
78
70
  for await (const {
79
71
  properties,
80
72
  sources,
81
73
  output,
82
74
  dependencies,
83
- variant
84
- } of extractFromPackage(
85
- JSON.parse(
86
- await readFile(join(pkgDir, "package.json"), utf8StreamOptions)
87
- ),
88
- pkgDir,
89
- options
90
- )) {
75
+ context
76
+ } of extractFromPackage(options)) {
91
77
  for (const inputFactory of allInputs.filter(
92
78
  inputFactory => options[inputFactory.name] === true
93
79
  )) {
@@ -101,6 +87,9 @@ program
101
87
  continute;
102
88
  }
103
89
 
90
+ // start with a fresh copy
91
+ options.publish = Object.assign({}, publishOptions);
92
+
104
93
  Object.assign(
105
94
  properties,
106
95
  {
@@ -121,8 +110,7 @@ program
121
110
  )
122
111
  );
123
112
 
124
- const context = createContext({ properties });
125
- const output = new outputFactory(context.expand(properties));
113
+ const output = new outputFactory(properties);
126
114
  const transformer = [
127
115
  createExpressionTransformer(
128
116
  nameExtensionMatcher([
@@ -135,7 +123,7 @@ program
135
123
  ".socket",
136
124
  ".rules"
137
125
  ]),
138
- context.expand(properties)
126
+ properties
139
127
  )
140
128
  ];
141
129
 
@@ -150,7 +138,7 @@ program
150
138
  transformer,
151
139
  dependencies,
152
140
  options,
153
- path => context.expand(path)
141
+ context.expand
154
142
  );
155
143
 
156
144
  await publish(fileName, options.publish, properties);