simple-stdout 2.1.0 → 2.2.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/dist/index.d.ts +3 -2
- package/dist/index.js +27 -18
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import type { ExecFileOptions, ExecOptions } from 'node:child_process';
|
|
2
3
|
/**
|
|
3
4
|
* Returns stdout from the given shell command
|
|
4
5
|
*
|
|
5
6
|
* Calls `child_process.exec` under the hood.
|
|
6
7
|
*/
|
|
7
|
-
export default function stdout(command: string): Promise<string>;
|
|
8
|
+
export default function stdout(command: string, options?: ExecOptions): Promise<string>;
|
|
8
9
|
/**
|
|
9
10
|
* Returns stdout from executing the given file/executable
|
|
10
11
|
*
|
|
11
12
|
* Calls `child_process.execFile` under the hood.
|
|
12
13
|
*/
|
|
13
|
-
export declare function stdoutFile(file: string, args?: string[]): Promise<string>;
|
|
14
|
+
export declare function stdoutFile(file: string, args?: readonly string[], options?: ExecFileOptions): Promise<string>;
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { exec, execFile } from 'node:child_process';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// Remove trailing newline
|
|
10
|
-
.replace(/\n$/, ''));
|
|
11
|
-
}
|
|
12
|
-
};
|
|
3
|
+
import { promisify } from 'node:util';
|
|
4
|
+
const asyncExec = promisify(exec);
|
|
5
|
+
/**
|
|
6
|
+
* Removes trailing newline
|
|
7
|
+
*/
|
|
8
|
+
const cleanOutput = (output) => output.replace(/\n$/, '');
|
|
13
9
|
/**
|
|
14
10
|
* Returns stdout from the given shell command
|
|
15
11
|
*
|
|
16
12
|
* Calls `child_process.exec` under the hood.
|
|
17
13
|
*/
|
|
18
|
-
export default async function stdout(command) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
export default async function stdout(command, options) {
|
|
15
|
+
const { stdout, stderr } = await asyncExec(command, options);
|
|
16
|
+
if (stderr) {
|
|
17
|
+
throw new Error(stderr.toString());
|
|
18
|
+
}
|
|
19
|
+
if (typeof stdout !== 'string') {
|
|
20
|
+
return cleanOutput(stdout.toString());
|
|
21
|
+
}
|
|
22
|
+
// Remove trailing newline
|
|
23
|
+
return cleanOutput(stdout);
|
|
22
24
|
}
|
|
25
|
+
const asyncExecFile = promisify(execFile);
|
|
23
26
|
/**
|
|
24
27
|
* Returns stdout from executing the given file/executable
|
|
25
28
|
*
|
|
26
29
|
* Calls `child_process.execFile` under the hood.
|
|
27
30
|
*/
|
|
28
|
-
export async function stdoutFile(file, args
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
export async function stdoutFile(file, args, options) {
|
|
32
|
+
const { stdout, stderr } = await asyncExecFile(file, args, options);
|
|
33
|
+
if (stderr) {
|
|
34
|
+
throw new Error(stderr.toString());
|
|
35
|
+
}
|
|
36
|
+
if (typeof stdout !== 'string') {
|
|
37
|
+
return cleanOutput(stdout.toString());
|
|
38
|
+
}
|
|
39
|
+
// Remove trailing newline
|
|
40
|
+
return cleanOutput(stdout);
|
|
32
41
|
}
|
|
33
42
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,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package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-stdout",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "tsc -p tsconfig.build.json",
|
|
6
6
|
"test": "vitest .",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"husky": "^9.1.7",
|
|
32
32
|
"prettier": "3.7.4",
|
|
33
33
|
"typescript": "^5.8.3",
|
|
34
|
-
"typescript-eslint": "^8.
|
|
34
|
+
"typescript-eslint": "^8.52.0",
|
|
35
35
|
"vitest": "^4.0.16"
|
|
36
36
|
},
|
|
37
|
-
"packageManager": "pnpm@10.
|
|
37
|
+
"packageManager": "pnpm@10.27.0",
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=20"
|
|
40
40
|
},
|