@bob-kit/client 0.0.6 → 0.0.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/dist/daemon.d.ts CHANGED
@@ -7,4 +7,5 @@ export declare class Daemon {
7
7
  query(message: string): Promise<string>;
8
8
  close(): void;
9
9
  status(): boolean;
10
+ private destroyStreams;
10
11
  }
package/dist/daemon.js CHANGED
@@ -14,24 +14,28 @@ export class Daemon {
14
14
  stdio: ["pipe", "pipe", "pipe"],
15
15
  windowsHide: true,
16
16
  });
17
- this.process.stdout.setEncoding("utf8");
18
- this.process.stdout.on("data", (data) => {
17
+ this.process.unref();
18
+ // Lectura de stdout
19
+ this.process.stdout?.setEncoding("utf8");
20
+ this.process.stdout?.on("data", (data) => {
19
21
  this.buffer += data;
20
22
  let endIndex;
21
23
  while ((endIndex = this.buffer.indexOf("__END__")) !== -1) {
22
24
  const response = this.buffer.slice(0, endIndex).trim();
23
25
  this.buffer = this.buffer.slice(endIndex + "__END__".length);
24
- if (this.queue.length) {
25
- const resolve = this.queue.shift();
26
- if (resolve)
27
- resolve(response);
28
- }
26
+ const resolve = this.queue.shift();
27
+ if (resolve)
28
+ resolve(response);
29
29
  }
30
30
  });
31
31
  this.process.on("exit", () => {
32
32
  this.buffer = "";
33
33
  this.queue = [];
34
+ this.destroyStreams();
34
35
  });
36
+ process.on("exit", () => this.close());
37
+ process.on("SIGINT", () => this.close());
38
+ process.on("SIGTERM", () => this.close());
35
39
  }
36
40
  async query(message) {
37
41
  if (!this.process || !this.process.stdin) {
@@ -44,10 +48,22 @@ export class Daemon {
44
48
  }
45
49
  close() {
46
50
  if (this.process && !this.process.killed) {
47
- this.process.kill();
51
+ try {
52
+ this.process.kill();
53
+ this.destroyStreams();
54
+ }
55
+ catch { }
48
56
  }
49
57
  }
50
58
  status() {
51
59
  return !!this.process && !this.process.killed;
52
60
  }
61
+ destroyStreams() {
62
+ try {
63
+ this.process.stdin?.end();
64
+ this.process.stdout?.destroy();
65
+ this.process.stderr?.destroy();
66
+ }
67
+ catch { }
68
+ }
53
69
  }
package/dist/install.js CHANGED
@@ -16,7 +16,7 @@ async function downloadFile(url, folder, filename) {
16
16
  }
17
17
  (async () => {
18
18
  try {
19
- const version = "v0.0.1"; // or dynamic
19
+ const version = "v0.0.2"; // or dynamic
20
20
  const fileName = getProgram();
21
21
  const url = `https://github.com/bob-object-builder/bob/releases/download/${version}/${fileName}`;
22
22
  const downloadFolder = "dist";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bob-kit/client",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "",