@caido-utils/backend 1.5.1 → 1.6.1
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/process/index.d.ts +1 -0
- package/dist/process/index.js +1 -0
- package/dist/process/spawn.d.ts +10 -0
- package/dist/process/spawn.js +58 -0
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { spawnCommand } from "./spawn";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { spawnCommand } from "./spawn.js";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
spawn as nodeSpawn
|
|
3
|
+
} from "child_process";
|
|
4
|
+
import { access, constants } from "fs/promises";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
async function ensureBinaryExecutable(binaryPath, sdk) {
|
|
7
|
+
try {
|
|
8
|
+
await access(binaryPath, constants.F_OK | constants.X_OK);
|
|
9
|
+
} catch {
|
|
10
|
+
try {
|
|
11
|
+
await makeExecutable(binaryPath);
|
|
12
|
+
} catch (chmodError) {
|
|
13
|
+
sdk.console.error(
|
|
14
|
+
`Failed to make ${binaryPath} executable: ${chmodError}`
|
|
15
|
+
);
|
|
16
|
+
throw new Error(`Cannot make binary executable: ${chmodError}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function makeExecutable(binaryPath) {
|
|
21
|
+
const child = nodeSpawn("chmod", ["+x", binaryPath], {
|
|
22
|
+
shell: true
|
|
23
|
+
});
|
|
24
|
+
await driveChild(child);
|
|
25
|
+
}
|
|
26
|
+
export async function spawnCommand(sdk, binary, args, stdin) {
|
|
27
|
+
try {
|
|
28
|
+
const binaryPath = path.join(sdk.meta.assetsPath(), binary);
|
|
29
|
+
await ensureBinaryExecutable(binaryPath, sdk);
|
|
30
|
+
const child = nodeSpawn(binaryPath, args);
|
|
31
|
+
if (stdin !== void 0) {
|
|
32
|
+
child.stdin.write(stdin);
|
|
33
|
+
child.stdin.end();
|
|
34
|
+
}
|
|
35
|
+
const output = await driveChild(child);
|
|
36
|
+
return output;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
sdk.console.error(`Spawn command error (${binary}): ${error}`);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function driveChild(child, allowExitCode1 = false) {
|
|
43
|
+
let output = "";
|
|
44
|
+
child.stdout.on("data", (data) => {
|
|
45
|
+
output += data.toString();
|
|
46
|
+
});
|
|
47
|
+
let error = "";
|
|
48
|
+
child.stderr.on("data", (data) => {
|
|
49
|
+
error += data.toString();
|
|
50
|
+
});
|
|
51
|
+
const exitCode = await new Promise((resolve) => {
|
|
52
|
+
child.on("close", resolve);
|
|
53
|
+
});
|
|
54
|
+
if (exitCode !== void 0 && exitCode !== 0 && !(allowExitCode1 && exitCode === 1)) {
|
|
55
|
+
throw new Error(`subprocess error exit ${exitCode}, ${error}`);
|
|
56
|
+
}
|
|
57
|
+
return output;
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caido-utils/backend",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"build": "unbuild"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@caido-utils/shared": "^0.1.4"
|
|
18
|
+
"@caido-utils/shared": "^0.1.4",
|
|
19
|
+
"url-parse": "^1.5.10"
|
|
19
20
|
},
|
|
20
21
|
"peerDependencies": {
|
|
21
22
|
"@caido/sdk-backend": ">=0.46.0"
|