@sap-ux/nodejs-utils 0.2.5 → 0.2.7
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 -0
- package/dist/index.js +1 -0
- package/dist/installedCheck.js +4 -4
- package/dist/proxyCheck.d.ts +23 -0
- package/dist/proxyCheck.js +88 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./commandRunner"), exports);
|
|
18
18
|
__exportStar(require("./installedCheck"), exports);
|
|
19
19
|
__exportStar(require("./httpsUtils"), exports);
|
|
20
|
+
__exportStar(require("./proxyCheck"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
package/dist/installedCheck.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.findInstalledPackages = findInstalledPackages;
|
|
|
7
7
|
const btp_utils_1 = require("@sap-ux/btp-utils");
|
|
8
8
|
const commandRunner_1 = require("./commandRunner");
|
|
9
9
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
10
|
-
const
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
11
|
const read_pkg_up_1 = __importDefault(require("read-pkg-up"));
|
|
12
12
|
const semver_1 = require("semver");
|
|
13
13
|
/**
|
|
@@ -27,7 +27,7 @@ const getPackageInfo = async (searchPath, minVersion) => {
|
|
|
27
27
|
return {
|
|
28
28
|
packageJsonPath: pkgInfo.path,
|
|
29
29
|
packageInfo: pkgInfo.packageJson,
|
|
30
|
-
path: (0,
|
|
30
|
+
path: (0, node_path_1.join)(searchPath, pkgInfo.packageJson.main ?? '/generators/app')
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -85,7 +85,7 @@ async function getNpmInstallPaths(vscWorkspaceConfig) {
|
|
|
85
85
|
// App Wizard allows custom generator path install locations to be user configured
|
|
86
86
|
const customGenInstallLoc = vscWorkspaceConfig?.get(appWizardInstallLocation);
|
|
87
87
|
if (customGenInstallLoc) {
|
|
88
|
-
genSearchPaths.push((0,
|
|
88
|
+
genSearchPaths.push((0, node_path_1.join)(customGenInstallLoc, 'node_modules'));
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
// Npm global node modules path
|
|
@@ -100,7 +100,7 @@ async function getNpmInstallPaths(vscWorkspaceConfig) {
|
|
|
100
100
|
return undefined;
|
|
101
101
|
});
|
|
102
102
|
if (rootNodeModules) {
|
|
103
|
-
genSearchPaths.push((0,
|
|
103
|
+
genSearchPaths.push((0, node_path_1.join)(rootNodeModules.trim()));
|
|
104
104
|
}
|
|
105
105
|
// BAS recommend using NODE_PATH as the paths therein are used to locate all generators regardless of installation method
|
|
106
106
|
if ((0, btp_utils_1.isAppStudio)() && process.env.NODE_PATH) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const ProxyValidationStatus: {
|
|
2
|
+
readonly NO_PROXY: "no-proxy";
|
|
3
|
+
readonly MATCH: "match";
|
|
4
|
+
readonly MISMATCH: "mismatch";
|
|
5
|
+
readonly ENV_ONLY: "env-only";
|
|
6
|
+
readonly PARAM_ONLY: "param-only";
|
|
7
|
+
};
|
|
8
|
+
export type ProxyValidationStatus = (typeof ProxyValidationStatus)[keyof typeof ProxyValidationStatus];
|
|
9
|
+
export interface ProxyValidationResult {
|
|
10
|
+
isValid: boolean;
|
|
11
|
+
status: ProxyValidationStatus;
|
|
12
|
+
message: string;
|
|
13
|
+
envProxy?: string;
|
|
14
|
+
providedProxy?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validates if the proxy settings match against the process.env proxy settings. Typically used to ensure that the proxy settings in VSCode match those in the environment.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} [proxy] - The proxy setting to validate. If not provided, it will check the environment variables.
|
|
20
|
+
* @returns {ProxyValidationResult} - An object containing the validation result, status, and messages.
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateProxySettings(proxy?: string): ProxyValidationResult;
|
|
23
|
+
//# sourceMappingURL=proxyCheck.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProxyValidationStatus = void 0;
|
|
4
|
+
exports.validateProxySettings = validateProxySettings;
|
|
5
|
+
exports.ProxyValidationStatus = {
|
|
6
|
+
NO_PROXY: 'no-proxy',
|
|
7
|
+
MATCH: 'match',
|
|
8
|
+
MISMATCH: 'mismatch',
|
|
9
|
+
ENV_ONLY: 'env-only',
|
|
10
|
+
PARAM_ONLY: 'param-only'
|
|
11
|
+
};
|
|
12
|
+
const PROXY_ENV_VARS = ['HTTP_PROXY', 'http_proxy', 'HTTPS_PROXY', 'https_proxy'];
|
|
13
|
+
const getEnvProxy = () => {
|
|
14
|
+
for (const envVar of PROXY_ENV_VARS) {
|
|
15
|
+
const value = process.env[envVar];
|
|
16
|
+
if (value && value.trim() !== '') {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
};
|
|
22
|
+
const normalizeProxy = (value) => {
|
|
23
|
+
let result = value?.trim().toLowerCase();
|
|
24
|
+
while (result?.endsWith('/')) {
|
|
25
|
+
result = result.slice(0, -1);
|
|
26
|
+
}
|
|
27
|
+
return result || undefined;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Validates if the proxy settings match against the process.env proxy settings. Typically used to ensure that the proxy settings in VSCode match those in the environment.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} [proxy] - The proxy setting to validate. If not provided, it will check the environment variables.
|
|
33
|
+
* @returns {ProxyValidationResult} - An object containing the validation result, status, and messages.
|
|
34
|
+
*/
|
|
35
|
+
function validateProxySettings(proxy) {
|
|
36
|
+
const envProxy = getEnvProxy();
|
|
37
|
+
const normalizedEnvProxy = normalizeProxy(envProxy);
|
|
38
|
+
const normalizedProxy = normalizeProxy(proxy);
|
|
39
|
+
// Exit early if no proxy settings are provided
|
|
40
|
+
if (!(normalizedEnvProxy || normalizedProxy)) {
|
|
41
|
+
return {
|
|
42
|
+
isValid: true,
|
|
43
|
+
status: exports.ProxyValidationStatus.NO_PROXY,
|
|
44
|
+
message: 'No proxy settings configured.',
|
|
45
|
+
providedProxy: undefined,
|
|
46
|
+
envProxy: envProxy
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// Only environment proxy is set
|
|
50
|
+
if (normalizedEnvProxy && !normalizedProxy) {
|
|
51
|
+
return {
|
|
52
|
+
isValid: false,
|
|
53
|
+
status: exports.ProxyValidationStatus.ENV_ONLY,
|
|
54
|
+
message: 'Using environment proxy settings.',
|
|
55
|
+
envProxy: normalizedEnvProxy,
|
|
56
|
+
providedProxy: undefined
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Only provided proxy is set
|
|
60
|
+
if (!normalizedEnvProxy && normalizedProxy) {
|
|
61
|
+
return {
|
|
62
|
+
isValid: false,
|
|
63
|
+
status: exports.ProxyValidationStatus.PARAM_ONLY,
|
|
64
|
+
message: `Using provided (${normalizedProxy}) proxy settings.`,
|
|
65
|
+
envProxy: undefined,
|
|
66
|
+
providedProxy: normalizedProxy
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// Both exist and match
|
|
70
|
+
if (normalizedEnvProxy === normalizedProxy) {
|
|
71
|
+
return {
|
|
72
|
+
isValid: true,
|
|
73
|
+
status: exports.ProxyValidationStatus.MATCH,
|
|
74
|
+
message: `Proxy settings match.`,
|
|
75
|
+
envProxy: normalizedEnvProxy,
|
|
76
|
+
providedProxy: normalizedProxy
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// Both exist but don't match
|
|
80
|
+
return {
|
|
81
|
+
isValid: false,
|
|
82
|
+
status: exports.ProxyValidationStatus.MISMATCH,
|
|
83
|
+
message: `Proxy settings conflict between environment (${normalizedEnvProxy}) and parameter (${normalizedProxy}).`,
|
|
84
|
+
envProxy: normalizedEnvProxy,
|
|
85
|
+
providedProxy: normalizedProxy
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=proxyCheck.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.7",
|
|
4
4
|
"description": "Nodejs utility wrappers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"fast-glob": "3.3.1",
|
|
18
18
|
"read-pkg-up": "7.0.1",
|
|
19
19
|
"semver": "7.5.4",
|
|
20
|
-
"@sap-ux/btp-utils": "1.1.
|
|
20
|
+
"@sap-ux/btp-utils": "1.1.4"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/semver": "7.5.2",
|