Skip to content

Commit 525176d

Browse files
committed
[INTERNAL] versions: Include package location in verbose mode
If verbose logging is enabled, also show the local path of each UI5 Tooling module. This can be helpful to debug dev environment issues.
1 parent 5963492 commit 525176d

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/cli/commands/versions.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import baseMiddleware from "../middlewares/base.js";
2+
import path from "node:path";
3+
import {isLogLevelEnabled} from "@ui5/logger";
24
import {createRequire} from "node:module";
35

46
// Using CommonsJS require since JSON module imports are still experimental
@@ -14,7 +16,15 @@ const NOT_FOUND = "===(not installed)";
1416
versions.getVersion = (pkg) => {
1517
try {
1618
const packageInfo = require(`${pkg}/package.json`);
17-
return packageInfo.version || NOT_FOUND;
19+
if (!packageInfo?.version) {
20+
return NOT_FOUND;
21+
}
22+
let res = packageInfo.version;
23+
if (isLogLevelEnabled("verbose")) {
24+
const packageDir = path.dirname(require.resolve(`${pkg}/package.json`));
25+
res += ` (from ${packageDir})`;
26+
}
27+
return res;
1828
} catch {
1929
return NOT_FOUND;
2030
}

test/lib/cli/commands/versions.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import test from "ava";
22
import sinon from "sinon";
3+
import path from "node:path";
34
import versions from "../../../../lib/cli/commands/versions.js";
5+
const __dirname = path.join(import.meta.dirname, "..");
46

57
test.afterEach.always((t) => {
68
sinon.restore();
@@ -20,6 +22,31 @@ test.serial("Retrieves version from package.json", (t) => {
2022
t.is(loggerVersion, "0.2.2", "retrieved correct version for logger");
2123
});
2224

25+
test.serial("Retrieves version and package path in verbose mode", async (t) => {
26+
const {setLogLevel} = await import("@ui5/logger");
27+
setLogLevel("verbose");
28+
const builderPath = "../../../test/fixtures/@ui5/builder";
29+
const builderVersion = versions.getVersion(builderPath);
30+
const serverPath = "../../../test/fixtures/@ui5/server";
31+
const serverVersion = versions.getVersion(serverPath);
32+
const fsPath = "../../../test/fixtures/@ui5/fs";
33+
const fsVersion = versions.getVersion(fsPath);
34+
const projectPath = "../../../test/fixtures/@ui5/project";
35+
const projectVersion = versions.getVersion(projectPath);
36+
const loggerPath = "../../../test/fixtures/@ui5/logger";
37+
const loggerVersion = versions.getVersion(loggerPath);
38+
t.is(builderVersion, `0.2.6 (from ${path.resolve(__dirname, builderPath)})`,
39+
"retrieved correct version and path for builder");
40+
t.is(serverVersion, `0.2.2 (from ${path.resolve(__dirname, serverPath)})`,
41+
"retrieved correct version and path for server");
42+
t.is(fsVersion, `0.2.0 (from ${path.resolve(__dirname, fsPath)})`,
43+
"retrieved correct version and path for fs");
44+
t.is(projectVersion, `0.2.3 (from ${path.resolve(__dirname, projectPath)})`,
45+
"retrieved correct version and path for project");
46+
t.is(loggerVersion, `0.2.2 (from ${path.resolve(__dirname, loggerPath)})`,
47+
"retrieved correct version and path for logger");
48+
});
49+
2350
test.serial("Error: returns not installed if version was not found", (t) => {
2451
t.is(versions.getVersion("not/existing/path"), "===(not installed)", "No version found");
2552
});

0 commit comments

Comments
 (0)