qase-javascript-commons 2.5.4 → 2.5.6

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.
@@ -33,13 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.getMinimalHostData = getMinimalHostData;
37
36
  exports.getHostInfo = getHostInfo;
38
37
  const os = __importStar(require("os"));
39
38
  const cp = __importStar(require("child_process"));
40
39
  const fs = __importStar(require("fs"));
41
- const path = __importStar(require("path"));
42
- const child_process_1 = require("child_process");
40
+ const get_package_version_1 = require("./get-package-version");
43
41
  /**
44
42
  * Gets detailed OS information based on the platform
45
43
  * @returns {string} Detailed OS information
@@ -76,110 +74,24 @@ function getDetailedOSInfo() {
76
74
  }
77
75
  }
78
76
  /**
79
- * Executes a command and returns its trimmed output
80
- * @param {string} command Command to execute
81
- * @param {string} defaultValue Default value if command fails
82
- * @returns {string} Command output or default value
77
+ * Gets npm version from environment or by executing npm command
78
+ * @returns {string} npm version string
83
79
  */
84
- function execCommand(command, defaultValue = '') {
85
- try {
86
- return cp.execSync(command).toString().trim();
87
- }
88
- catch (error) {
89
- console.error(`Error executing command '${command}':`, error);
90
- return defaultValue;
91
- }
92
- }
93
- /**
94
- * Recursively searches for a package in dependencies tree
95
- * @param {Record<string, PackageInfo>} dependencies The dependencies object to search in
96
- * @param {string} packageName The name of the package to find
97
- * @returns {string | null} The package version or null if not found
98
- */
99
- function findPackageInDependencies(dependencies, packageName) {
100
- // If no dependencies, return null
101
- if (!dependencies)
102
- return null;
103
- // Check if the package exists at the current level
104
- if (packageName in dependencies) {
105
- return dependencies[packageName]?.version ?? null;
106
- }
107
- // Recursively search in nested dependencies
108
- for (const dep of Object.values(dependencies)) {
109
- if (dep.dependencies) {
110
- const foundVersion = findPackageInDependencies(dep.dependencies, packageName);
111
- if (foundVersion) {
112
- return foundVersion;
113
- }
80
+ function getNpmVersion() {
81
+ const userAgent = process.env['npm_config_user_agent'];
82
+ if (userAgent) {
83
+ const match = userAgent.match(/^npm\/(\S+)/);
84
+ if (match?.[1]) {
85
+ return match[1];
114
86
  }
115
87
  }
116
- return null;
117
- }
118
- /**
119
- * Gets the version of a Node.js package
120
- * @param {string} packageName The name of the package
121
- * @returns {string | null} The package version or null if not found
122
- */
123
- function getPackageVersion(packageName) {
124
- if (!packageName)
125
- return null;
126
88
  try {
127
- // First try to get from node_modules
128
- const packagePath = path.resolve(process.cwd(), 'node_modules', packageName, 'package.json');
129
- if (fs.existsSync(packagePath)) {
130
- const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
131
- return packageJson.version;
132
- }
133
- // Try using npm list as fallback with recursive search
134
- let output = null;
135
- try {
136
- output = (0, child_process_1.execSync)(`npm list --depth=10 --json`, { stdio: "pipe" }).toString();
137
- if (!output)
138
- return null;
139
- }
140
- catch (error) {
141
- return null;
142
- }
143
- try {
144
- const npmList = JSON.parse(output);
145
- // Try direct dependency
146
- const directVersion = npmList.dependencies?.[packageName]?.version;
147
- if (directVersion)
148
- return directVersion;
149
- // Try recursive search
150
- return findPackageInDependencies(npmList.dependencies, packageName);
151
- }
152
- catch (parseError) {
153
- console.error('Error parsing npm list output:', parseError);
154
- return null;
155
- }
89
+ return cp.execSync('npm --version', { stdio: 'pipe' }).toString().trim();
156
90
  }
157
- catch (error) {
158
- console.error(`Error getting version for package ${packageName}:`, error);
159
- return null;
91
+ catch {
92
+ return '';
160
93
  }
161
94
  }
162
- /**
163
- * Returns minimal host data without slow operations (no npm list, no execSync for node/npm).
164
- * Use when reporter mode is "off" to avoid startup delay.
165
- * @returns {HostData} Minimal host information object
166
- */
167
- function getMinimalHostData() {
168
- return {
169
- system: os.platform(),
170
- machineName: os.hostname(),
171
- release: os.release(),
172
- version: '',
173
- arch: os.arch(),
174
- node: '',
175
- npm: '',
176
- framework: '',
177
- reporter: '',
178
- commons: '',
179
- apiClientV1: '',
180
- apiClientV2: '',
181
- };
182
- }
183
95
  /**
184
96
  * Gets information about the current host environment
185
97
  * @param {string} framework The framework name to check version for
@@ -194,13 +106,13 @@ function getHostInfo(framework, reporterName) {
194
106
  release: os.release(),
195
107
  version: getDetailedOSInfo(),
196
108
  arch: os.arch(),
197
- node: execCommand('node --version'),
198
- npm: execCommand('npm --version'),
199
- framework: getPackageVersion(framework) ?? '',
200
- reporter: getPackageVersion(reporterName) ?? '',
201
- commons: getPackageVersion('qase-javascript-commons') ?? '',
202
- apiClientV1: getPackageVersion('qase-api-client') ?? '',
203
- apiClientV2: getPackageVersion('qase-api-v2-client') ?? '',
109
+ node: process.version,
110
+ npm: getNpmVersion(),
111
+ framework: (0, get_package_version_1.getPackageVersion)(framework) ?? '',
112
+ reporter: (0, get_package_version_1.getPackageVersion)(reporterName) ?? '',
113
+ commons: (0, get_package_version_1.getPackageVersion)('qase-javascript-commons') ?? '',
114
+ apiClientV1: (0, get_package_version_1.getPackageVersion)('qase-api-client') ?? '',
115
+ apiClientV2: (0, get_package_version_1.getPackageVersion)('qase-api-v2-client') ?? '',
204
116
  };
205
117
  }
206
118
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qase-javascript-commons",
3
- "version": "2.5.4",
3
+ "version": "2.5.6",
4
4
  "description": "Qase JS Reporters",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",