Skip to content

Commit 1e0503a

Browse files
committed
[FIX] Ensure usage of provided UI5 data dir
Also moves check for framework libraries to earlier point as further steps such as choosing a resolver and calling resolveVersion are only needed when libraries are referenced. This aligns the behavior with not having a framework configuration at all but still passing "versionOverride" which is then also not resolved/checked for correctness.
1 parent c2ec6ec commit 1e0503a

File tree

2 files changed

+52
-20
lines changed

2 files changed

+52
-20
lines changed

lib/graph/helpers/ui5Framework.js

+24-19
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ export default {
294294
const rootProject = projectGraph.getRoot();
295295
const frameworkName = rootProject.getFrameworkName();
296296
const frameworkVersion = rootProject.getFrameworkVersion();
297+
const cwd = rootProject.getRootPath();
297298

298299
// It is allowed to omit the framework version in ui5.yaml and only provide one via the override
299300
// This is a common use case for framework libraries, which generally should not define a
@@ -330,6 +331,14 @@ export default {
330331
);
331332
}
332333

334+
const referencedLibraries = await utils.getFrameworkLibrariesFromGraph(projectGraph);
335+
if (!referencedLibraries.length) {
336+
log.verbose(
337+
`No ${frameworkName} libraries referenced in project ${rootProject.getName()} ` +
338+
`or in any of its dependencies`);
339+
return projectGraph;
340+
}
341+
333342
let Resolver;
334343
if (version && version.toLowerCase().endsWith("-snapshot")) {
335344
Resolver = (await import("../../ui5Framework/Sapui5MavenSnapshotResolver.js")).default;
@@ -339,20 +348,26 @@ export default {
339348
Resolver = (await import("../../ui5Framework/Sapui5Resolver.js")).default;
340349
}
341350

351+
// ENV var should take precedence over the dataDir from the configuration.
352+
let ui5DataDir = process.env.UI5_DATA_DIR;
353+
if (!ui5DataDir) {
354+
const config = await Configuration.fromFile();
355+
ui5DataDir = config.getUi5DataDir();
356+
}
357+
if (ui5DataDir) {
358+
ui5DataDir = path.resolve(cwd, ui5DataDir);
359+
}
360+
342361
if (options.versionOverride) {
343-
version = await Resolver.resolveVersion(options.versionOverride, {cwd: rootProject.getRootPath()});
362+
version = await Resolver.resolveVersion(options.versionOverride, {
363+
ui5HomeDir: ui5DataDir,
364+
cwd
365+
});
344366
log.info(
345367
`Overriding configured ${frameworkName} version ` +
346368
`${frameworkVersion} with version ${version}`
347369
);
348370
}
349-
const referencedLibraries = await utils.getFrameworkLibrariesFromGraph(projectGraph);
350-
if (!referencedLibraries.length) {
351-
log.verbose(
352-
`No ${frameworkName} libraries referenced in project ${rootProject.getName()} ` +
353-
`or in any of its dependencies`);
354-
return projectGraph;
355-
}
356371

357372
if (version) {
358373
log.info(`Using ${frameworkName} version: ${version}`);
@@ -365,20 +380,10 @@ export default {
365380
});
366381
}
367382

368-
// ENV var should take precedence over the dataDir from the configuration.
369-
let ui5DataDir = process.env.UI5_DATA_DIR;
370-
if (!ui5DataDir) {
371-
const config = await Configuration.fromFile();
372-
ui5DataDir = config.getUi5DataDir();
373-
}
374-
if (ui5DataDir) {
375-
ui5DataDir = path.resolve(rootProject.getRootPath(), ui5DataDir);
376-
}
377-
378383
// Note: version might be undefined here and the Resolver will throw an error when calling
379384
// #install and it can't be resolved via the provided library metadata
380385
const resolver = new Resolver({
381-
cwd: rootProject.getRootPath(),
386+
cwd,
382387
version,
383388
providedLibraryMetadata,
384389
cacheMode,

test/lib/graph/helpers/ui5Framework.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ test.serial("enrichProjectGraph: With versionOverride", async (t) => {
334334

335335
await ui5Framework.enrichProjectGraph(projectGraph, {versionOverride: "1.99"});
336336

337+
t.is(Sapui5ResolverResolveVersionStub.callCount, 1);
338+
t.deepEqual(Sapui5ResolverResolveVersionStub.getCall(0).args, ["1.99", {
339+
cwd: dependencyTree.path,
340+
ui5HomeDir: undefined,
341+
}]);
342+
337343
t.is(Sapui5ResolverStub.callCount, 1, "Sapui5Resolver#constructor should be called once");
338344
t.deepEqual(Sapui5ResolverStub.getCall(0).args, [{
339345
cacheMode: undefined,
@@ -390,6 +396,12 @@ test.serial("enrichProjectGraph: With versionOverride containing snapshot versio
390396

391397
await ui5Framework.enrichProjectGraph(projectGraph, {versionOverride: "1.99-SNAPSHOT"});
392398

399+
t.is(Sapui5MavenSnapshotResolverResolveVersionStub.callCount, 1);
400+
t.deepEqual(Sapui5MavenSnapshotResolverResolveVersionStub.getCall(0).args, ["1.99-SNAPSHOT", {
401+
cwd: dependencyTree.path,
402+
ui5HomeDir: undefined,
403+
}]);
404+
393405
t.is(Sapui5MavenSnapshotResolverStub.callCount, 1,
394406
"Sapui5MavenSnapshotResolverStub#constructor should be called once");
395407
t.deepEqual(Sapui5MavenSnapshotResolverStub.getCall(0).args, [{
@@ -447,6 +459,12 @@ test.serial("enrichProjectGraph: With versionOverride containing latest-snapshot
447459

448460
await ui5Framework.enrichProjectGraph(projectGraph, {versionOverride: "latest-snapshot"});
449461

462+
t.is(Sapui5MavenSnapshotResolverResolveVersionStub.callCount, 1);
463+
t.deepEqual(Sapui5MavenSnapshotResolverResolveVersionStub.getCall(0).args, ["latest-snapshot", {
464+
cwd: dependencyTree.path,
465+
ui5HomeDir: undefined,
466+
}]);
467+
450468
t.is(Sapui5MavenSnapshotResolverStub.callCount, 1,
451469
"Sapui5MavenSnapshotResolverStub#constructor should be called once");
452470
t.deepEqual(Sapui5MavenSnapshotResolverStub.getCall(0).args, [{
@@ -459,7 +477,7 @@ test.serial("enrichProjectGraph: With versionOverride containing latest-snapshot
459477
});
460478

461479
test.serial("enrichProjectGraph shouldn't throw when no framework version and no libraries are provided", async (t) => {
462-
const {ui5Framework, log} = t.context;
480+
const {ui5Framework, log, Sapui5ResolverResolveVersionStub} = t.context;
463481
const dependencyTree = {
464482
id: "test-id",
465483
version: "1.2.3",
@@ -484,6 +502,9 @@ test.serial("enrichProjectGraph shouldn't throw when no framework version and no
484502
versionOverride: "1.75.0"
485503
});
486504

505+
t.is(Sapui5ResolverResolveVersionStub.callCount, 0,
506+
"resolveVersion should not be called when no libraries are provided");
507+
487508
t.is(log.verbose.callCount, 2);
488509
t.deepEqual(log.verbose.getCall(0).args, [
489510
"Project application.a has no framework dependencies"
@@ -703,6 +724,12 @@ test.serial("enrichProjectGraph should resolve framework project " +
703724
await ui5Framework.enrichProjectGraph(projectGraph, {versionOverride: "3.4.5"});
704725
t.is(projectGraph.getSize(), 3, "Project graph should remain unchanged");
705726

727+
t.is(Sapui5ResolverResolveVersionStub.callCount, 1);
728+
t.deepEqual(Sapui5ResolverResolveVersionStub.getCall(0).args, ["3.4.5", {
729+
cwd: dependencyTree.path,
730+
ui5HomeDir: undefined,
731+
}]);
732+
706733
t.is(Sapui5ResolverStub.callCount, 1, "Sapui5Resolver#constructor should be called once");
707734
t.is(getFrameworkLibrariesFromGraphStub.callCount, 1, "getFrameworkLibrariesFromGraph should be called once");
708735
t.deepEqual(Sapui5ResolverStub.getCall(0).args, [{

0 commit comments

Comments
 (0)