diff --git a/lib/config/Configuration.js b/lib/config/Configuration.js index 8bd14a538..7e04b0fb4 100644 --- a/lib/config/Configuration.js +++ b/lib/config/Configuration.js @@ -11,13 +11,16 @@ import os from "node:os"; */ class Configuration { #mavenSnapshotEndpointUrl; + #ui5DataDir; /** * @param {object} configuration * @param {string} [configuration.mavenSnapshotEndpointUrl] + * @param {string} [configuration.ui5DataDir] */ - constructor({mavenSnapshotEndpointUrl}) { + constructor({mavenSnapshotEndpointUrl, ui5DataDir}) { this.#mavenSnapshotEndpointUrl = mavenSnapshotEndpointUrl; + this.#ui5DataDir = ui5DataDir; } /** @@ -31,6 +34,16 @@ class Configuration { return this.#mavenSnapshotEndpointUrl; } + /** + * Configurable directory where the framework artefacts are stored. + * + * @public + * @returns {string} + */ + getUi5DataDir() { + return this.#ui5DataDir; + } + /** * @public * @returns {object} The configuration in a JSON format @@ -38,6 +51,7 @@ class Configuration { toJson() { return { mavenSnapshotEndpointUrl: this.#mavenSnapshotEndpointUrl, + ui5DataDir: this.#ui5DataDir, }; } @@ -74,6 +88,7 @@ class Configuration { }); } } + return new Configuration(config); } diff --git a/lib/graph/helpers/ui5Framework.js b/lib/graph/helpers/ui5Framework.js index 4dec54470..1a02f4c52 100644 --- a/lib/graph/helpers/ui5Framework.js +++ b/lib/graph/helpers/ui5Framework.js @@ -2,6 +2,8 @@ import Module from "../Module.js"; import ProjectGraph from "../ProjectGraph.js"; import {getLogger} from "@ui5/logger"; const log = getLogger("graph:helpers:ui5Framework"); +import Configuration from "../../config/Configuration.js"; +import path from "node:path"; class ProjectProcessor { constructor({libraryMetadata, graph, workspace}) { @@ -363,13 +365,20 @@ export default { }); } + const config = await Configuration.fromFile(); + // ENV var should take precedence over the dataDir from the configuration. + const ui5HomeDir = process.env.UI5_DATA_DIR ? + path.resolve(process.env.UI5_DATA_DIR) : + config.getUi5DataDir(); + // Note: version might be undefined here and the Resolver will throw an error when calling // #install and it can't be resolved via the provided library metadata const resolver = new Resolver({ cwd: rootProject.getRootPath(), version, providedLibraryMetadata, - cacheMode + cacheMode, + ui5HomeDir }); let startTime; diff --git a/test/lib/config/Configuration.js b/test/lib/config/Configuration.js index 083a2059a..1019fe526 100644 --- a/test/lib/config/Configuration.js +++ b/test/lib/config/Configuration.js @@ -34,7 +34,8 @@ test.serial("Build configuration with defaults", (t) => { const config = new Configuration({}); t.deepEqual(config.toJson(), { - mavenSnapshotEndpointUrl: undefined + mavenSnapshotEndpointUrl: undefined, + ui5DataDir: undefined, }); }); @@ -43,7 +44,8 @@ test.serial("Overwrite defaults defaults", (t) => { const {Configuration} = t.context; const params = { - mavenSnapshotEndpointUrl: "https://snapshot.url" + mavenSnapshotEndpointUrl: "https://snapshot.url", + ui5DataDir: "/custom/data/dir" }; const config = new Configuration(params); @@ -55,12 +57,14 @@ test.serial("Check getters", (t) => { const {Configuration} = t.context; const params = { - mavenSnapshotEndpointUrl: "https://snapshot.url" + mavenSnapshotEndpointUrl: "https://snapshot.url", + ui5DataDir: "/custom/data/dir" }; const config = new Configuration(params); t.is(config.getMavenSnapshotEndpointUrl(), params.mavenSnapshotEndpointUrl); + t.is(config.getUi5DataDir(), params.ui5DataDir); }); @@ -69,7 +73,8 @@ test.serial("fromFile", async (t) => { const {promisifyStub, sinon} = t.context; const ui5rcContents = { - mavenSnapshotEndpointUrl: "https://snapshot.url" + mavenSnapshotEndpointUrl: "https://snapshot.url", + ui5DataDir: "/custom/data/dir" }; const responseStub = sinon.stub().resolves(JSON.stringify(ui5rcContents)); promisifyStub.callsFake(() => responseStub); @@ -90,6 +95,7 @@ test.serial("fromFile: configuration file not found - fallback to default config t.is(config instanceof Configuration, true, "Created a default configuration"); t.is(config.getMavenSnapshotEndpointUrl(), undefined, "Default settings"); + t.is(config.getUi5DataDir(), undefined, "Default settings"); }); @@ -104,6 +110,7 @@ test.serial("fromFile: empty configuration file - fallback to default config", a t.is(config instanceof Configuration, true, "Created a default configuration"); t.is(config.getMavenSnapshotEndpointUrl(), undefined, "Default settings"); + t.is(config.getUi5DataDir(), undefined, "Default settings"); }); test.serial("fromFile: throws", async (t) => { diff --git a/test/lib/graph/helpers/ui5Framework.js b/test/lib/graph/helpers/ui5Framework.js index 458397f30..c7906da58 100644 --- a/test/lib/graph/helpers/ui5Framework.js +++ b/test/lib/graph/helpers/ui5Framework.js @@ -113,6 +113,7 @@ test.serial("enrichProjectGraph", async (t) => { cacheMode: undefined, cwd: dependencyTree.path, version: dependencyTree.configuration.framework.version, + ui5HomeDir: undefined, providedLibraryMetadata: undefined }], "Sapui5Resolver#constructor should be called with expected args"); @@ -319,6 +320,7 @@ test.serial("enrichProjectGraph: With versionOverride", async (t) => { cacheMode: undefined, cwd: dependencyTree.path, version: "1.99.9", + ui5HomeDir: undefined, providedLibraryMetadata: undefined }], "Sapui5Resolver#constructor should be called with expected args"); }); @@ -375,6 +377,7 @@ test.serial("enrichProjectGraph: With versionOverride containing snapshot versio cacheMode: undefined, cwd: dependencyTree.path, version: "1.99.9-SNAPSHOT", + ui5HomeDir: undefined, providedLibraryMetadata: undefined }], "Sapui5Resolver#constructor should be called with expected args"); }); @@ -431,6 +434,7 @@ test.serial("enrichProjectGraph: With versionOverride containing latest-snapshot cacheMode: undefined, cwd: dependencyTree.path, version: "1.99.9-SNAPSHOT", + ui5HomeDir: undefined, providedLibraryMetadata: undefined }], "Sapui5Resolver#constructor should be called with expected args"); }); @@ -587,6 +591,7 @@ test.serial("enrichProjectGraph should resolve framework project with version an cacheMode: undefined, cwd: dependencyTree.path, version: "1.2.3", + ui5HomeDir: undefined, providedLibraryMetadata: undefined }], "Sapui5Resolver#constructor should be called with expected args"); }); @@ -685,6 +690,7 @@ test.serial("enrichProjectGraph should resolve framework project " + cacheMode: undefined, cwd: dependencyTree.path, version: "1.99.9", + ui5HomeDir: undefined, providedLibraryMetadata: undefined }], "Sapui5Resolver#constructor should be called with expected args"); }); @@ -949,6 +955,7 @@ test.serial("enrichProjectGraph should use framework library metadata from works cacheMode: undefined, cwd: dependencyTree.path, version: "1.111.1", + ui5HomeDir: undefined, providedLibraryMetadata: workspaceFrameworkLibraryMetadata }], "Sapui5Resolver#constructor should be called with expected args"); t.is(Sapui5ResolverStub.getCall(0).args[0].providedLibraryMetadata, workspaceFrameworkLibraryMetadata); @@ -1006,6 +1013,7 @@ test.serial("enrichProjectGraph should allow omitting framework version in case t.deepEqual(Sapui5ResolverStub.getCall(0).args, [{ cacheMode: undefined, cwd: dependencyTree.path, + ui5HomeDir: undefined, version: undefined, providedLibraryMetadata: workspaceFrameworkLibraryMetadata }], "Sapui5Resolver#constructor should be called with expected args"); diff --git a/test/lib/ui5framework/Sapui5MavenSnapshotResolver.js b/test/lib/ui5framework/Sapui5MavenSnapshotResolver.js index 54fe3260a..0d7382d58 100644 --- a/test/lib/ui5framework/Sapui5MavenSnapshotResolver.js +++ b/test/lib/ui5framework/Sapui5MavenSnapshotResolver.js @@ -480,7 +480,8 @@ test.serial("_resolveSnapshotEndpointUrl: Maven fallback with config update", as t.is(configFromFile.callCount, 1, "Configuration has been read once"); t.is(configToFile.callCount, 1, "Configuration has been written once"); t.deepEqual(configToFile.firstCall.firstArg.toJson(), { - mavenSnapshotEndpointUrl: "maven-url" + mavenSnapshotEndpointUrl: "maven-url", + ui5DataDir: undefined }, "Correct configuration has been written"); });