npm-pkgbuild 7.13.0 → 7.14.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "7.13.0",
3
+ "version": "7.14.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -16,18 +16,21 @@ export class NPMPackContentProvider extends ContentProvider {
16
16
  return "npm-pack";
17
17
  }
18
18
 
19
- static get description()
20
- {
19
+ static get description() {
21
20
  return "use npm pack as source";
22
21
  }
23
22
 
23
+ constructor(definitions) {
24
+ super();
25
+ Object.assign(this, definitions);
26
+ }
27
+
24
28
  async *[Symbol.asyncIterator]() {
25
- //const m = await pacote.manifest(context.dir);
26
- //console.log('got it', m);
29
+ console.log("pacote", this.dir);
27
30
 
28
31
  const entries = [];
29
32
 
30
- await pacote.tarball.stream(context.dir, async stream => {
33
+ await pacote.tarball.stream(this.dir, async stream => {
31
34
  const extract = tar.extract();
32
35
 
33
36
  extract.on("entry", async (header, stream, next) => {
@@ -0,0 +1,98 @@
1
+ import { packageWalker } from "npm-package-walker";
2
+ import { asArray } from "./util.mjs";
3
+ import { NPMPackContentProvider } from "./content/npm-pack-content-provider.mjs";
4
+ import { NodeModulesContentProvider } from "./content/node-modules-content-provider.mjs";
5
+ import { FileContentProvider } from "./content/file-content-provider.mjs";
6
+ import { DEB } from "./output/deb.mjs";
7
+ import { ARCH } from "./output/arch.mjs";
8
+ import { RPM } from "./output/rpm.mjs";
9
+
10
+ export const allInputs = [NPMPackContentProvider, NodeModulesContentProvider];
11
+ export const allOutputs = [DEB, ARCH, RPM];
12
+
13
+ /**
14
+ * Extract package definition from package.json.
15
+ * @param {Object} pkg package.json content
16
+ * @param {string} dir
17
+ * @returns {Object}
18
+ */
19
+ export async function extractFromPackage(pkg, dir) {
20
+ const properties = Object.fromEntries(
21
+ ["name", "version", "description", "homepage", "license"]
22
+ .map(key => [key, pkg[key]])
23
+ .filter(([k, v]) => v !== undefined)
24
+ );
25
+
26
+ if (pkg.bugs) {
27
+ if (pkg.bugs.url) {
28
+ properties.bugs = pkg.bugs.url;
29
+ }
30
+ }
31
+
32
+ Object.assign(properties, pkg.config);
33
+
34
+ if (properties.name) {
35
+ properties.name = properties.name.replace(/^\@\w+\//, "");
36
+ }
37
+
38
+ if (pkg.contributors) {
39
+ properties.maintainer = pkg.contributors.map(
40
+ c => `${c.name} <${c.email}>`
41
+ )[0];
42
+ }
43
+
44
+ if (pkg.repository) {
45
+ if (pkg.repository.url) {
46
+ properties.source = pkg.repository.url;
47
+ }
48
+ }
49
+
50
+ let dependencies = { ...pkg.engines };
51
+ let sources = [];
52
+ let output = {};
53
+
54
+ const processPkg = (pkg,dir) => {
55
+ if (pkg.pkg) {
56
+ const pkgbuild = pkg.pkg;
57
+
58
+ Object.assign(output, pkgbuild.output);
59
+
60
+ Object.entries(pkgbuild)
61
+ .filter(([k, v]) => typeof v === "string")
62
+ .forEach(([k, v]) => (properties[k] = v));
63
+
64
+ if (pkgbuild.content) {
65
+ Object.entries(pkgbuild.content).forEach(
66
+ ([destination, definitions]) => {
67
+ for (const definition of asArray(definitions)) {
68
+ if(definition.type) {
69
+ const type = allInputs.find(i => i.name === definition.type);
70
+ if(type) {
71
+ delete definition.type;
72
+ sources.push(new type({ ...definition, dir}, { destination }));
73
+ }
74
+ else {
75
+ console.error("Unknown type '${type}'");
76
+ }
77
+ }
78
+ else {
79
+ sources.push(new FileContentProvider(definition, { destination }));
80
+ }
81
+ }
82
+ }
83
+ );
84
+ }
85
+
86
+ Object.assign(dependencies, pkgbuild.depends);
87
+ }
88
+ };
89
+
90
+ await packageWalker(async (pkg, base, modulePath) => {
91
+ processPkg(pkg,base);
92
+ return true;
93
+ }, dir);
94
+
95
+ processPkg(pkg, dir);
96
+
97
+ return { properties, sources, dependencies, output };
98
+ }
package/src/module.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
2
  export * from "./util.mjs";
3
+ export * from "./extract-from-package.mjs";
3
4
  export * from "./content/content-provider.mjs";
4
5
  export * from "./content/file-content-provider.mjs";
5
6
  export * from "./content/node-modules-content-provider.mjs";
@@ -7,4 +8,4 @@ export * from "./content/npm-pack-content-provider.mjs";
7
8
  export * from "./output/deb.mjs";
8
9
  export * from "./output/rpm.mjs";
9
10
  export * from "./output/arch.mjs";
10
- export * from "./output/packager.mjs";
11
+ export * from "./output/packager.mjs";
@@ -9,16 +9,13 @@ import { createContext } from "expression-expander";
9
9
  import { packageDirectory } from "pkg-dir";
10
10
  import {
11
11
  utf8StreamOptions,
12
- extractFromPackage,
13
12
  createExpressionTransformer
14
13
  } from "./util.mjs";
15
14
  import {
16
15
  FileContentProvider,
17
- DEB,
18
- ARCH,
19
- RPM,
20
- NPMPackContentProvider,
21
- NodeModulesContentProvider
16
+ allInputs,
17
+ allOutputs,
18
+ extractFromPackage
22
19
  } from "npm-pkgbuild";
23
20
 
24
21
  const { version, description } = JSON.parse(
@@ -28,13 +25,9 @@ const { version, description } = JSON.parse(
28
25
 
29
26
  const cwd = process.cwd();
30
27
 
31
- const allInputs = [NPMPackContentProvider, NodeModulesContentProvider];
32
- const allOutputs = [DEB, ARCH, RPM];
33
-
34
28
  program.description(description).version(version);
35
29
 
36
30
  allOutputs.forEach(o => program.option(`--${o.name}`, o.description));
37
-
38
31
  allInputs.forEach(i => program.option(`--${i.name}`, i.description));
39
32
 
40
33
  program
package/src/util.mjs CHANGED
@@ -4,8 +4,6 @@ import { pipeline } from "stream/promises";
4
4
  import { createWriteStream } from "fs";
5
5
  import { iterableStringInterceptor } from "iterable-string-interceptor";
6
6
  import { ReadableStreamContentEntry } from "content-entry";
7
- import { FileContentProvider } from "npm-pkgbuild";
8
- import { packageWalker } from "npm-package-walker";
9
7
 
10
8
  export const utf8StreamOptions = { encoding: "utf8" };
11
9
 
@@ -60,80 +58,6 @@ export function fieldProvider(properties, fields) {
60
58
  };
61
59
  }
62
60
 
63
- /**
64
- * Extract package definition from package.json.
65
- * @param {Object} pkg package.json content
66
- * @param {string} dir
67
- * @returns {Object}
68
- */
69
- export async function extractFromPackage(pkg, dir) {
70
- const properties = Object.fromEntries(
71
- ["name", "version", "description", "homepage", "license"]
72
- .map(key => [key, pkg[key]])
73
- .filter(([k, v]) => v !== undefined)
74
- );
75
-
76
- if (pkg.bugs) {
77
- if (pkg.bugs.url) {
78
- properties.bugs = pkg.bugs.url;
79
- }
80
- }
81
-
82
- Object.assign(properties, pkg.config);
83
-
84
- if (properties.name) {
85
- properties.name = properties.name.replace(/^\@\w+\//, "");
86
- }
87
-
88
- if (pkg.contributors) {
89
- properties.maintainer = pkg.contributors.map(
90
- c => `${c.name} <${c.email}>`
91
- )[0];
92
- }
93
-
94
- if (pkg.repository) {
95
- if (pkg.repository.url) {
96
- properties.source = pkg.repository.url;
97
- }
98
- }
99
-
100
- let dependencies = { ...pkg.engines };
101
- let sources = [];
102
- let output = {};
103
-
104
- const processPkg = pkg => {
105
- if (pkg.pkg) {
106
- const pkgbuild = pkg.pkg;
107
-
108
- Object.assign(output, pkgbuild.output);
109
-
110
- Object.entries(pkgbuild)
111
- .filter(([k, v]) => typeof v === "string")
112
- .forEach(([k, v]) => (properties[k] = v));
113
-
114
- if (pkgbuild.content) {
115
- Object.entries(pkgbuild.content).forEach(
116
- ([destination, definitions]) => {
117
- for (const d of asArray(definitions)) {
118
- sources.push(new FileContentProvider(d, { destination }));
119
- }
120
- }
121
- );
122
- }
123
-
124
- Object.assign(dependencies, pkgbuild.depends);
125
- }
126
- };
127
-
128
- await packageWalker(async (pkg, base, modulePath) => {
129
- processPkg(pkg);
130
- return true;
131
- }, dir);
132
-
133
- processPkg(pkg);
134
-
135
- return { properties, sources, dependencies, output };
136
- }
137
61
 
138
62
  export function createModeTransformer(mode, match) {
139
63
  return {