@sap-ux/nodejs-utils 0.2.5 → 0.2.8

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/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # @sap-ux/nodejs-utils
1
+ [![Changelog](https://img.shields.io/badge/changelog-8A2BE2)](https://github.com/SAP/open-ux-tools/blob/main/packages/nodejs-utils/CHANGELOG.md) [![Github repo](https://img.shields.io/badge/github-repo-blue)](https://github.com/SAP/open-ux-tools/tree/main/packages/nodejs-utils)
2
+
3
+ # [`@sap-ux/nodejs-utils`](https://github.com/SAP/open-ux-tools/tree/main/packages/nodejs-utils)
2
4
 
3
5
  Nodejs utility wrappers
4
6
 
@@ -17,4 +19,4 @@ Pnpm
17
19
  see ./tests/unit/
18
20
 
19
21
  ## Keywords
20
- SAP Fiori tools library
22
+ SAP Fiori tools library
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './commandRunner';
2
2
  export * from './installedCheck';
3
3
  export * from './httpsUtils';
4
+ export * from './proxyCheck';
4
5
  //# sourceMappingURL=index.d.ts.map
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
@@ -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 path_1 = require("path");
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, path_1.join)(searchPath, pkgInfo.packageJson.main ?? '/generators/app')
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, path_1.join)(customGenInstallLoc, 'node_modules'));
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, path_1.join)(rootNodeModules.trim()));
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.5",
3
+ "version": "0.2.8",
4
4
  "description": "Nodejs utility wrappers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,13 +17,13 @@
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.3"
20
+ "@sap-ux/btp-utils": "1.1.5"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/semver": "7.5.2",
24
24
  "@types/vscode": "1.73.1",
25
25
  "mock-spawn": "0.2.6",
26
- "@sap-ux/logger": "0.7.0"
26
+ "@sap-ux/logger": "0.7.1"
27
27
  },
28
28
  "files": [
29
29
  "dist",