Skip to content

Commit

Permalink
[FIX] LibraryFormatter: Do not throw for missing .library in legacy O…
Browse files Browse the repository at this point in the history
…penUI5 theme libraries

Exception handling was already in place for legacy OpenUI5 theme
libraries that still use type 'library' instead of 'theme-library':
#437

This allowed them to still be formatted even though they are missing a
.library file.

However, the newly added preload exclude configuration fallback for
framework libraries also requires a .library file and did not make the
mentioned exception for legacy OpenUI5 theme libraries:
#573

This fix adds that exception and the tests that were missing from
#437
  • Loading branch information
RandomByte committed Mar 9, 2021
1 parent b7b1a33 commit f7e22ba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/types/application/ApplicationFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ApplicationFormatter extends AbstractUi5Formatter {
}
const namespace = appId.replace(/\./g, "/");
log.verbose(
`Namespace of project ${this._project.metadata.name} is ${namespace} (from manifest.appdescr_variant)`);
`Namespace of project ${this._project.metadata.name} is ${namespace} (from manifest.json)`);
return namespace;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/types/library/LibraryFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LibraryFormatter extends AbstractUi5Formatter {
log.verbose(err.message);
}

if (isFrameworkProject(project)) {
if (isFrameworkProject(project) && !SAP_THEMES_NS_EXEMPTIONS.includes(this._project.metadata.name)) {
if (project.builder && project.builder.libraryPreload && project.builder.libraryPreload.excludes) {
log.verbose(
`Using preload excludes for framework library ${project.metadata.name} from project configuration`);
Expand Down
34 changes: 34 additions & 0 deletions test/lib/types/library/LibraryFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ const libraryETree = {
}
};

const legacyThemeLibPath = path.join(__dirname, "..", "..", "..", "fixtures", "theme.library.e");
const legacyThemeLibTree = {
id: "@openui5/themelib_sap_bluecrystal",
version: "1.0.0",
path: legacyThemeLibPath,
dependencies: [],
_level: 0,
_isRoot: true,
specVersion: "2.0",
type: "library",
metadata: {
name: "themelib_sap_bluecrystal",
copyright: "UI development toolkit for HTML5 (OpenUI5)\n * (c) Copyright 2009-xxx SAP SE or an SAP affiliate " +
"company.\n * Licensed under the Apache License, Version 2.0 - see LICENSE.txt."
},
resources: {
configuration: {
paths: {
src: "src",
test: "test"
}
}
}
};

function clone(o) {
return JSON.parse(JSON.stringify(o));
}
Expand Down Expand Up @@ -396,6 +421,15 @@ test.serial("format: namespace resolution fails", async (t) => {
mock.stop("@ui5/logger");
});

test("format: legacy OpenUI5 theme library", async (t) => {
const myProject = clone(legacyThemeLibTree);
const libraryFormatter = new LibraryFormatter({project: myProject});
sinon.stub(libraryFormatter, "validate").resolves();

await t.notThrowsAsync(libraryFormatter.format(), "Does not throw for missing .library");
t.deepEqual(myProject.metadata.copyright, legacyThemeLibTree.metadata.copyright, "Copyright was not altered");
});

test("format: configuration test path", async (t) => {
const myProject = clone(libraryETree);
const libraryFormatter = new LibraryFormatter({project: myProject});
Expand Down

0 comments on commit f7e22ba

Please sign in to comment.