@testrigor/testrigor-cli 0.0.46-beta → 0.0.49-beta

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.
@@ -1,2 +1 @@
1
- export declare const BINARY_NAME: string;
2
- export declare function download(dir: string): Promise<string | null>;
1
+ export declare function download(dir: string): Promise<string>;
package/dist/util/trtc.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.download = exports.BINARY_NAME = void 0;
3
+ exports.download = void 0;
4
4
  const Fs = require("@supercharge/fs");
5
5
  const fs = require("fs");
6
6
  const node_fetch_commonjs_1 = require("node-fetch-commonjs");
@@ -28,7 +28,7 @@ const VERSION = "2.3.15";
28
28
  const WIN32_PLATFORM = "win32";
29
29
  const WIN32_BINARY = "trtc.exe";
30
30
  const UNIX_BINARY = "trtc";
31
- exports.BINARY_NAME = os.platform() === WIN32_PLATFORM ? WIN32_BINARY : UNIX_BINARY;
31
+ const BINARY_NAME = os.platform() === WIN32_PLATFORM ? WIN32_BINARY : UNIX_BINARY;
32
32
  function getFolderName() {
33
33
  const platform = os.platform();
34
34
  const architecture = os.arch();
@@ -39,6 +39,13 @@ function getFolderName() {
39
39
  }
40
40
  throw new Error(`Unsupported platform ${platform} or architecture ${architecture}`);
41
41
  }
42
+ // The Windows zip wraps its contents in a versioned top-level folder;
43
+ // the tarballs are flat.
44
+ function getBinaryPath(dir) {
45
+ return os.platform() === WIN32_PLATFORM
46
+ ? path.join(dir, getFolderName(), BINARY_NAME)
47
+ : path.join(dir, BINARY_NAME);
48
+ }
42
49
  function getUrl() {
43
50
  const platform = os.platform();
44
51
  const architecture = os.arch();
@@ -53,7 +60,7 @@ async function extractZip(dir, stream) {
53
60
  return new Promise((resolve, reject) => {
54
61
  stream
55
62
  .pipe(unzip.Extract({ path: dir }))
56
- .on("close", () => resolve(path.join(dir, getFolderName())))
63
+ .on("close", () => resolve(getBinaryPath(dir)))
57
64
  .on("error", reject);
58
65
  });
59
66
  }
@@ -92,7 +99,7 @@ async function extractTar(dir, stream) {
92
99
  stream.resume();
93
100
  stream.on("end", next);
94
101
  });
95
- extract.on("finish", () => resolve(path.join(dir, getFolderName())));
102
+ extract.on("finish", () => resolve(getBinaryPath(dir)));
96
103
  stream.pipe(zlib.createGunzip()).pipe(extract);
97
104
  });
98
105
  }
@@ -105,7 +112,7 @@ async function download(dir) {
105
112
  if (stream == null) {
106
113
  throw new Error("unexpected null response body");
107
114
  }
108
- if (os.platform() === "win32") {
115
+ if (os.platform() === WIN32_PLATFORM) {
109
116
  return extractZip(dir, stream);
110
117
  }
111
118
  return extractTar(dir, stream);
@@ -20,16 +20,14 @@ type = "http_proxy"`;
20
20
  await Fs.writeFile(configPath, newConfigContent);
21
21
  return configPath;
22
22
  }
23
- async function startTrtc(trtc, command, configPath) {
23
+ async function startTrtc(trtc, configPath) {
24
24
  return new Promise((resolve, reject) => {
25
- const binaryPath = path.join(path.dirname(trtc), command);
26
- const workingDir = path.dirname(trtc);
27
- if (!Fs.pathExistsSync(binaryPath)) {
28
- reject(new Error(`Binary not found at ${binaryPath}`));
25
+ if (!Fs.pathExistsSync(trtc)) {
26
+ reject(new Error(`Binary not found at ${trtc}`));
29
27
  return;
30
28
  }
31
- const tunnelProcess = childProcess.spawn(binaryPath, ["-c", configPath], {
32
- cwd: workingDir,
29
+ const tunnelProcess = childProcess.spawn(trtc, ["-c", configPath], {
30
+ cwd: path.dirname(trtc),
33
31
  });
34
32
  tunnelProcess.stdout.on("data", (data) => {
35
33
  const dataString = data.toString();
@@ -68,21 +66,22 @@ class Tunnel {
68
66
  if (this.binaryPath == null) {
69
67
  throw new Error("Could not download the trtc binary");
70
68
  }
71
- const command = trtc_1.BINARY_NAME;
69
+ let lastError;
72
70
  let maxTries = 40;
73
71
  while (maxTries > 0) {
74
72
  try {
75
73
  this.port = randomPort(minPort, maxPort);
76
74
  this.configPath = await updateConfig(this.binaryPath, this.port);
77
- this.process = await startTrtc(this.binaryPath, command, this.configPath);
75
+ this.process = await startTrtc(this.binaryPath, this.configPath);
78
76
  break;
79
77
  }
80
78
  catch (e) {
79
+ lastError = e;
81
80
  maxTries--;
82
81
  }
83
82
  }
84
83
  if (maxTries === 0) {
85
- throw new Error("Could not start trtc process");
84
+ throw new Error(`Could not start trtc process: ${lastError instanceof Error ? lastError.message : String(lastError)}`);
86
85
  }
87
86
  this.running = true;
88
87
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.46-beta",
2
+ "version": "0.0.49-beta",
3
3
  "commands": {
4
4
  "authenticate": {
5
5
  "id": "authenticate",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testrigor/testrigor-cli",
3
- "version": "0.0.46-beta",
3
+ "version": "0.0.49-beta",
4
4
  "description": "TestRigor Command Line",
5
5
  "author": "Ivo Parun Rua @parunruaivo",
6
6
  "bin": {