@sap-ux/nodejs-utils 0.2.0 → 0.2.2
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/commandRunner.d.ts +3 -1
- package/dist/commandRunner.js +13 -3
- package/dist/httpsUtils.d.ts +7 -0
- package/dist/httpsUtils.js +23 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +3 -2
package/dist/commandRunner.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type SpawnOptionsWithoutStdio } from 'child_process';
|
|
2
|
+
import type { Logger } from '@sap-ux/logger';
|
|
2
3
|
/**
|
|
3
4
|
*
|
|
4
5
|
*/
|
|
@@ -9,9 +10,10 @@ export declare class CommandRunner {
|
|
|
9
10
|
* @param {string} cmd to execute
|
|
10
11
|
* @param {string[]} args to pass to the command
|
|
11
12
|
* @param {SpawnOptionsWithoutStdio} [opts] options to pass to the command
|
|
13
|
+
* @param {Logger} [logger] optional logger to capture command output
|
|
12
14
|
* @returns {*} {(Promise<any | void>)}
|
|
13
15
|
* @memberof CommandRunner
|
|
14
16
|
*/
|
|
15
|
-
run(cmd: string, args?: string[], opts?: SpawnOptionsWithoutStdio): Promise<string | void>;
|
|
17
|
+
run(cmd: string, args?: string[], opts?: SpawnOptionsWithoutStdio, logger?: Logger): Promise<string | void>;
|
|
16
18
|
}
|
|
17
19
|
//# sourceMappingURL=commandRunner.d.ts.map
|
package/dist/commandRunner.js
CHANGED
|
@@ -12,10 +12,14 @@ class CommandRunner {
|
|
|
12
12
|
* @param {string} cmd to execute
|
|
13
13
|
* @param {string[]} args to pass to the command
|
|
14
14
|
* @param {SpawnOptionsWithoutStdio} [opts] options to pass to the command
|
|
15
|
+
* @param {Logger} [logger] optional logger to capture command output
|
|
15
16
|
* @returns {*} {(Promise<any | void>)}
|
|
16
17
|
* @memberof CommandRunner
|
|
17
18
|
*/
|
|
18
|
-
run(cmd, args = [], opts = {}) {
|
|
19
|
+
run(cmd, args = [], opts = {}, logger) {
|
|
20
|
+
if (logger) {
|
|
21
|
+
logger.debug(`Running command: ${cmd} ${args.join(' ')}`);
|
|
22
|
+
}
|
|
19
23
|
return new Promise((resolve, reject) => {
|
|
20
24
|
const stack = [];
|
|
21
25
|
const spawnOpts = process.platform === 'win32' ? { ...opts, shell: true } : opts;
|
|
@@ -23,17 +27,23 @@ class CommandRunner {
|
|
|
23
27
|
spawnedCmd.stdout.setEncoding('utf8');
|
|
24
28
|
let response;
|
|
25
29
|
spawnedCmd.stdout.on('data', (data) => {
|
|
30
|
+
logger?.info(data.toString().replace(/[\r\n]$/, '')); // remove trailing newline as another is added by the logger
|
|
26
31
|
response = data.toString();
|
|
27
32
|
});
|
|
28
33
|
spawnedCmd.stderr.on('data', (data) => {
|
|
34
|
+
logger?.info(data.toString().replace(/[\r\n]$/, '')); // remove trailing newline as another is added by the logger
|
|
29
35
|
stack.push(data.toString());
|
|
30
36
|
});
|
|
31
37
|
spawnedCmd.on('error', (error) => {
|
|
32
|
-
|
|
38
|
+
const cmdFailedMsg = `Command failed with error: ${error.message}`;
|
|
39
|
+
logger?.error(cmdFailedMsg);
|
|
40
|
+
reject(error);
|
|
33
41
|
});
|
|
34
42
|
spawnedCmd.on('close', (errorCode) => {
|
|
35
43
|
if (errorCode !== 0) {
|
|
36
|
-
|
|
44
|
+
const cmdFailedMsg = `Command failed, \`${cmd} ${args.join(' ')}\`, ${stack.join(', ')}`;
|
|
45
|
+
logger?.debug(cmdFailedMsg);
|
|
46
|
+
reject(cmdFailedMsg);
|
|
37
47
|
}
|
|
38
48
|
resolve(response);
|
|
39
49
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set the rejectUnauthorized option of the global https agent.
|
|
3
|
+
*
|
|
4
|
+
* @param rejectUnauthorized - true to reject unauthorized certificates, false to accept them
|
|
5
|
+
*/
|
|
6
|
+
export declare function setGlobalRejectUnauthorized(rejectUnauthorized: boolean): void;
|
|
7
|
+
//# sourceMappingURL=httpsUtils.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setGlobalRejectUnauthorized = setGlobalRejectUnauthorized;
|
|
7
|
+
const https_1 = __importDefault(require("https"));
|
|
8
|
+
/**
|
|
9
|
+
* Set the rejectUnauthorized option of the global https agent.
|
|
10
|
+
*
|
|
11
|
+
* @param rejectUnauthorized - true to reject unauthorized certificates, false to accept them
|
|
12
|
+
*/
|
|
13
|
+
function setGlobalRejectUnauthorized(rejectUnauthorized) {
|
|
14
|
+
if (https_1.default.globalAgent.options) {
|
|
15
|
+
https_1.default.globalAgent.options.rejectUnauthorized = rejectUnauthorized;
|
|
16
|
+
}
|
|
17
|
+
//@ts-expect-error - fallbackAgent is only present in BoundHttpsProxyAgent implementation and is not part of the Node.js API
|
|
18
|
+
if (https_1.default.globalAgent.fallbackAgent?.options) {
|
|
19
|
+
//@ts-expect-error - fallbackAgent is not typed in Node.js API
|
|
20
|
+
https_1.default.globalAgent.fallbackAgent.options.rejectUnauthorized = rejectUnauthorized;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=httpsUtils.js.map
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./commandRunner"), exports);
|
|
18
18
|
__exportStar(require("./installedCheck"), exports);
|
|
19
|
+
__exportStar(require("./httpsUtils"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/nodejs-utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Nodejs utility wrappers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/semver": "7.5.2",
|
|
24
24
|
"@types/vscode": "1.73.1",
|
|
25
|
-
"mock-spawn": "0.2.6"
|
|
25
|
+
"mock-spawn": "0.2.6",
|
|
26
|
+
"@sap-ux/logger": "0.7.0"
|
|
26
27
|
},
|
|
27
28
|
"files": [
|
|
28
29
|
"dist",
|