npm-pkgbuild 7.15.6 → 7.17.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.15.6",
3
+ "version": "7.17.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -38,16 +38,18 @@
38
38
  "lint:docs": "documentation lint ./src/**/*.mjs"
39
39
  },
40
40
  "dependencies": {
41
+ "@npmcli/arborist": "^4.2.0",
41
42
  "aggregate-async-iterator": "^1.1.7",
42
43
  "commander": "^8.3.0",
43
- "content-entry": "^4.1.0",
44
- "content-entry-filesystem": "^4.0.1",
45
- "content-entry-transform": "^1.3.2",
44
+ "content-entry": "^4.1.2",
45
+ "content-entry-filesystem": "^4.0.3",
46
+ "content-entry-transform": "^1.3.4",
46
47
  "execa": "^6.0.0",
47
48
  "expression-expander": "^7.0.9",
48
- "globby": "^12.0.2",
49
+ "globby": "^12.2.0",
49
50
  "iterable-string-interceptor": "^1.0.8",
50
51
  "key-value-transformer": "^2.0.0",
52
+ "node-fetch": "^3.1.1",
51
53
  "npm-package-walker": "^5.0.3",
52
54
  "npm-packlist": "^3.0.0",
53
55
  "pacote": "^12.0.2",
@@ -58,7 +60,7 @@
58
60
  "ava": "^4.0.1",
59
61
  "c8": "^7.11.0",
60
62
  "documentation": "^13.2.5",
61
- "semantic-release": "^18.0.1",
63
+ "semantic-release": "^19.0.2",
62
64
  "stream-buffers": "^3.0.2"
63
65
  },
64
66
  "engines": {
@@ -1,5 +1,5 @@
1
- import { join } from "path";
2
1
  import { globby } from "globby";
2
+ import Arborist from "@npmcli/arborist";
3
3
  import { FileSystemEntry } from "content-entry-filesystem";
4
4
  import { ContentProvider } from "./content-provider.mjs";
5
5
 
@@ -26,10 +26,15 @@ export class NodeModulesContentProvider extends ContentProvider {
26
26
 
27
27
  async *[Symbol.asyncIterator]() {
28
28
  const cwd = this.dir;
29
+
30
+ const arb = new Arborist({ path: cwd });
31
+ await arb.buildIdealTree({ saveType: "prod" });
32
+ await arb.reify({ save: true });
33
+
29
34
  for (const name of await globby("node_modules/**/*", {
30
35
  cwd
31
36
  })) {
32
- yield Object.assign(new FileSystemEntry(name, cwd),this.entryProperties);
37
+ yield Object.assign(new FileSystemEntry(name, cwd), this.entryProperties);
33
38
  }
34
39
  }
35
40
  }
package/src/module.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
2
  export * from "./util.mjs";
3
+ export * from "./publish.mjs";
3
4
  export * from "./extract-from-package.mjs";
4
5
  export * from "./content/content-provider.mjs";
5
6
  export * from "./content/file-content-provider.mjs";
@@ -1,5 +1,5 @@
1
1
  import { unlink, readFile, writeFile } from "fs/promises";
2
- import { globby} from "globby";
2
+ import { globby} from "globby";
3
3
  import { join, dirname } from "path";
4
4
  import { utf8StreamOptions } from "./util.mjs";
5
5
 
@@ -16,7 +16,8 @@ import {
16
16
  FileContentProvider,
17
17
  allInputs,
18
18
  allOutputs,
19
- extractFromPackage
19
+ extractFromPackage,
20
+ publish
20
21
  } from "npm-pkgbuild";
21
22
 
22
23
  const { version, description } = JSON.parse(
@@ -33,8 +34,8 @@ allInputs.forEach(i => program.option(`--${i.name}`, i.description));
33
34
 
34
35
  program
35
36
  .option("--verbose", "be more verbose", false)
36
- .option("-D --define <a=b>", "define property", str =>
37
- Object.fromEntries([str.split(/=/)])
37
+ .option("-D --define <a=b>", "define property", (str, former = {}) =>
38
+ Object.assign(former, Object.fromEntries([str.split(/=/)]))
38
39
  )
39
40
  .option(
40
41
  "-d --destination <dir>",
@@ -82,13 +83,16 @@ program
82
83
  o => options[o.name] === true || output[o.name] !== undefined
83
84
  )) {
84
85
  Object.assign(properties, options.define);
85
-
86
- for(const [k,v] of Object.entries(properties)) {
87
- if(typeof(v) === 'string') {
88
- properties[k] = v.replace(/\$\{([^\}]+)\}/m,(m,k) => properties[k]);
86
+
87
+ for (const [k, v] of Object.entries(properties)) {
88
+ if (typeof v === "string") {
89
+ properties[k] = v.replace(
90
+ /\$\{([^\}]+)\}/m,
91
+ (m, k) => properties[k]
92
+ );
89
93
  }
90
94
  }
91
-
95
+
92
96
  sources.push(
93
97
  ...[...options.content, ...options.meta]
94
98
  .filter(x => x)
@@ -128,16 +132,7 @@ program
128
132
  path => context.expand(path)
129
133
  );
130
134
 
131
- /*
132
- console.log(`#<CI>publish ${fileName}`);
133
-
134
- if (publish !== undefined) {
135
- context.properties.arch = arch;
136
-
137
- publish = publish.replace(/\{\{(\w+)\}\}/m, (match, key, offset, string) =>
138
- context.evaluate(key)
139
- );
140
- */
135
+ await publish(fileName, options.publish, properties);
141
136
  }
142
137
  } catch (e) {
143
138
  console.log(e);
@@ -3,7 +3,10 @@ import { createReadStream, createWriteStream } from "fs";
3
3
  import { pipeline } from "stream/promises";
4
4
  import { execa } from "execa";
5
5
  import { EmptyContentEntry, ReadableStreamContentEntry } from "content-entry";
6
- import { transform, createPropertiesInterceptor } from "content-entry-transform";
6
+ import {
7
+ transform,
8
+ createPropertiesInterceptor
9
+ } from "content-entry-transform";
7
10
  import { iterableStringInterceptor } from "iterable-string-interceptor";
8
11
  import {
9
12
  keyValueTransformer,
@@ -43,6 +46,8 @@ function keyPrefix(key) {
43
46
  return f && f.prefix ? f.prefix + key : key;
44
47
  }
45
48
 
49
+ const PKGBUILD = "PKGBUILD";
50
+
46
51
  export class ARCH extends Packager {
47
52
  static get name() {
48
53
  return "arch";
@@ -66,7 +71,7 @@ export class ARCH extends Packager {
66
71
  }
67
72
 
68
73
  async execute(sources, transformer, dependencies, options, expander) {
69
- const properties = this.properties;
74
+ const { properties, staging, destination } = await this.prepareExecute(options);
70
75
 
71
76
  if (properties.source) {
72
77
  properties.md5sums = ["SKIP"];
@@ -75,8 +80,6 @@ export class ARCH extends Packager {
75
80
  properties.install = `${properties.name}.install`;
76
81
  }
77
82
 
78
- const staging = await this.tmpdir;
79
-
80
83
  async function* trailingLines() {
81
84
  yield `
82
85
  package() {
@@ -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(
@@ -131,20 +134,16 @@ package() {
131
134
  }
132
135
  }
133
136
 
134
- if (options.verbose) {
135
- console.log(`stagingDir: ${staging}`);
136
- }
137
-
138
137
  const makepkg = await execa("makepkg", ["-f", "-e"], {
139
138
  cwd: staging,
140
- env: { PKGDEST: options.destination }
139
+ env: { PKGDEST: destination }
141
140
  });
142
141
 
143
142
  if (options.verbose) {
144
143
  console.log(makepkg.stdout);
145
144
  }
146
145
 
147
- return join(options.destination, this.packageFileName);
146
+ return join(destination, this.packageFileName);
148
147
  }
149
148
  }
150
149
 
@@ -32,8 +32,7 @@ export class DEB extends Packager {
32
32
  }
33
33
 
34
34
  async execute(sources, transformer, dependencies, options, expander) {
35
- const properties = this.properties;
36
- const staging = await this.tmpdir;
35
+ const { properties, staging, destination } = await this.prepareExecute(options);
37
36
 
38
37
  transformer.push(
39
38
  createPropertiesTransformer(
@@ -66,13 +65,13 @@ export class DEB extends Packager {
66
65
  }
67
66
  }
68
67
 
69
- const dpkg = await execa("dpkg", ["-b", staging, options.destination]);
68
+ const dpkg = await execa("dpkg", ["-b", staging, destination]);
70
69
 
71
70
  if (options.verbose) {
72
71
  console.log(dpkg.stdout);
73
72
  }
74
73
 
75
- return join(options.destination, this.packageFileName);
74
+ return join(destination, this.packageFileName);
76
75
  }
77
76
  }
78
77
 
@@ -1,6 +1,6 @@
1
1
  import { join } from "path";
2
2
  import { tmpdir } from "os";
3
- import { mkdtemp } from "fs/promises";
3
+ import { mkdtemp, mkdir } from "fs/promises";
4
4
 
5
5
  /**
6
6
  * @typedef {Object} Field
@@ -18,6 +18,15 @@ export class Packager {
18
18
  return {};
19
19
  }
20
20
 
21
+ static get workspaceLayout() {
22
+ return {
23
+ named: {
24
+ staging: ""
25
+ },
26
+ others: []
27
+ };
28
+ }
29
+
21
30
  constructor(properties) {
22
31
  this._properties = { ...properties };
23
32
  }
@@ -44,6 +53,41 @@ export class Packager {
44
53
  return properties;
45
54
  }
46
55
 
56
+ async prepareExecute(options) {
57
+ const tmpdir = await this.tmpdir;
58
+
59
+ const out = {
60
+ properties: this.properties,
61
+ destination: options.destination || tmpdir,
62
+ tmpdir
63
+ };
64
+
65
+ const l = this.constructor.workspaceLayout;
66
+
67
+ const mdo = { recursive: true };
68
+
69
+ await Promise.all(l.others.map(d => mkdir(join(tmpdir, d), mdo)));
70
+
71
+ for (const nd of Object.entries(l.named).map(([name, d]) => [
72
+ name,
73
+ join(tmpdir, d),
74
+ mkdir(join(tmpdir, d), mdo)
75
+ ])) {
76
+ await nd[2];
77
+ out[nd[0]] = nd[1];
78
+ }
79
+
80
+ if (options.publish) {
81
+ const m = options.publish.match(/^([\w_\+]+):\/\/(.*)/);
82
+
83
+ if (m) {
84
+ out.destination = m[1] === "file" ? m[2] : tmpdir;
85
+ }
86
+ }
87
+
88
+ return out;
89
+ }
90
+
47
91
  /**
48
92
  * Create tmp directory.
49
93
  * @return {Promise<string>} directory path
@@ -1,5 +1,5 @@
1
1
  import { join } from "path";
2
- import { mkdir, cp } from "fs/promises";
2
+ import { cp } from "fs/promises";
3
3
  import { execa } from "execa";
4
4
  import { EmptyContentEntry, ReadableStreamContentEntry } from "content-entry";
5
5
  import { transform } from "content-entry-transform";
@@ -15,8 +15,7 @@ export class RPM extends Packager {
15
15
  return "rpm";
16
16
  }
17
17
 
18
- static get description()
19
- {
18
+ static get description() {
20
19
  return "generate RPM package";
21
20
  }
22
21
 
@@ -33,25 +32,22 @@ export class RPM extends Packager {
33
32
  return fields;
34
33
  }
35
34
 
36
- async execute(
37
- sources,
38
- transformer,
39
- dependencies,
40
- options,
41
- expander
42
- ) {
43
- const properties = this.properties;
44
- const tmp = await this.tmpdir;
45
-
46
- properties.Requires = Object.entries(dependencies).map(([n,e]) => `${n}${e}`).join(' ');
47
-
48
- await Promise.all(
49
- ["BUILDROOT", "RPMS", "SRPMS", "SOURCES", "SPECS"].map(d =>
50
- mkdir(join(tmp, d))
51
- )
52
- );
35
+ static get workspaceLayout() {
36
+ return {
37
+ named: {
38
+ staging: "BUILDROOT"
39
+ },
40
+ others: ["RPMS", "SRPMS", "SOURCES", "SPECS"],
41
+ };
42
+ }
43
+
44
+ async execute(sources, transformer, dependencies, options, expander) {
45
+ const { properties, tmpdir, staging, destination } = await this.prepareExecute(options);
46
+
47
+ properties.Requires = Object.entries(dependencies)
48
+ .map(([n, e]) => `${n}${e}`)
49
+ .join(" ");
53
50
 
54
- const staging = join(tmp, "BUILDROOT");
55
51
  const specFileName = `${properties.name}.spec`;
56
52
 
57
53
  const files = [];
@@ -108,7 +104,7 @@ export class RPM extends Packager {
108
104
 
109
105
  const rpmbuild = await execa("rpmbuild", [
110
106
  "--define",
111
- `_topdir ${tmp}`,
107
+ `_topdir ${tmpdir}`,
112
108
  "--buildroot",
113
109
  staging,
114
110
  "-vv",
@@ -121,11 +117,11 @@ export class RPM extends Packager {
121
117
  }
122
118
 
123
119
  await cp(
124
- join(tmp, "RPMS", properties.arch, this.packageFileName),
125
- join(options.destination, this.packageFileName),
120
+ join(tmpdir, "RPMS", properties.arch, this.packageFileName),
121
+ join(destination, this.packageFileName),
126
122
  { preserveTimestamps: true }
127
123
  );
128
- return join(options.destination, this.packageFileName);
124
+ return join(destination, this.packageFileName);
129
125
  }
130
126
  }
131
127
 
@@ -0,0 +1,49 @@
1
+ import { basename } from "path";
2
+ import { createReadStream } from "fs";
3
+ import fetch from "node-fetch";
4
+
5
+ export async function publish(fileName, destination, properties) {
6
+
7
+ if(!destination) {
8
+ return;
9
+ }
10
+
11
+ destination = destination.replace(
12
+ /\{\{(\w+)\}\}/m,
13
+ (match, key, offset, string) => properties[key]
14
+ );
15
+
16
+ destination = destination + basename(fileName);
17
+
18
+ console.log(destination);
19
+
20
+ // const m = destination.match(/^([^:]+):/);
21
+
22
+ if (destination.startsWith("http://") || destination.startsWith("https://")) {
23
+ const headers = {};
24
+
25
+ if (properties.username) {
26
+ headers.authorization =
27
+ "Basic " +
28
+ Buffer.from(properties.username + ":" + properties.password).toString(
29
+ "base64"
30
+ );
31
+
32
+ console.log(headers.authorization);
33
+ }
34
+
35
+ const response = await fetch(destination, {
36
+ method: "PUT",
37
+ headers,
38
+ body: createReadStream(fileName)
39
+ });
40
+
41
+ console.log(response);
42
+
43
+ return;
44
+ }
45
+
46
+ /*
47
+ console.log(`#<CI>publish ${fileName}`);
48
+ */
49
+ }