Skip to content

Commit

Permalink
[FIX] Theme Build: Only process themes within library namespace (#570)
Browse files Browse the repository at this point in the history
Themes are expected to be within a "themes" folder directly below the
library namespace.
Other "themes" folders (e.g. within sub-directories) should be ignored
and not compiled/processed.
  • Loading branch information
matz3 authored Jan 21, 2021
1 parent 0e25b59 commit 8cecc01
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
11 changes: 10 additions & 1 deletion lib/tasks/generateThemeDesignerResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,16 @@ module.exports = async function({workspace, dependencies, options: {projectName,
return;
}

const librarySourceLessResources = await workspace.byGlob("/resources/**/themes/*/library.source.less");
let librarySourceLessPattern;
if (namespace) {
// In case of a library only check for themes directly below the namespace
librarySourceLessPattern = `/resources/${namespace}/themes/*/library.source.less`;
} else {
// In case of a theme-library check for all "themes"
librarySourceLessPattern = `/resources/**/themes/*/library.source.less`;
}

const librarySourceLessResources = await workspace.byGlob(librarySourceLessPattern);

const hasThemes = librarySourceLessResources.length > 0;

Expand Down
7 changes: 6 additions & 1 deletion lib/types/library/LibraryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,19 @@ class LibraryBuilder extends AbstractBuilder {
}

this.addTask("buildThemes", async () => {
// Only compile themes directly below the lib namespace to be in sync with the theme support at runtime
// which only loads themes from that folder.
// TODO 3.0: Remove fallback in case of missing namespace
const inputPattern = `/resources/${project.metadata.namespace || "**"}/themes/*/library.source.less`;

return getTask("buildThemes").task({
workspace: resourceCollections.workspace,
dependencies: resourceCollections.dependencies,
options: {
projectName: project.metadata.name,
librariesPattern: !taskUtil.isRootProject() ? "/resources/**/*.library" : undefined,
themesPattern: !taskUtil.isRootProject() ? "/resources/sap/ui/core/themes/*" : undefined,
inputPattern: "/resources/**/themes/*/library.source.less"
inputPattern
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/lib/tasks/buildThemes.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test("integration: simple", (t) => {
workspace: duplexCollection,
dependencies: dependencies,
options: {
inputPattern: "/resources/**/themes/**/library.source.less"
inputPattern: "/resources/super/duper/looper/themes/**/library.source.less"
}
}).then(() => {
return Promise.all([
Expand Down Expand Up @@ -133,7 +133,7 @@ test("integration: imports", (t) => {
workspace: duplexCollection,
dependencies: dependencies,
options: {
inputPattern: "/resources/**/themes/**/library.source.less"
inputPattern: "/resources/super/duper/looper/themes/**/library.source.less"
}
}).then(() => {
return Promise.all([
Expand Down
6 changes: 3 additions & 3 deletions test/lib/tasks/generateThemeDesignerResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test.serial("generateThemeDesignerResources: Library", async (t) => {

const workspace = {
byGlob: sinon.stub().callsFake(async (globPattern) => {
if (globPattern === "/resources/**/themes/*/library.source.less") {
if (globPattern === "/resources/sap/ui/demo/lib/themes/*/library.source.less") {
return [librarySourceLessResource1, librarySourceLessResource2, librarySourceLessResource3];
} else {
return [];
Expand Down Expand Up @@ -185,7 +185,7 @@ test.serial("generateThemeDesignerResources: Library sap.ui.core", async (t) =>

const workspace = {
byGlob: sinon.stub().callsFake(async (globPattern) => {
if (globPattern === "/resources/**/themes/*/library.source.less") {
if (globPattern === "/resources/sap/ui/core/themes/*/library.source.less") {
return [librarySourceLessResource];
} else {
return [];
Expand Down Expand Up @@ -418,7 +418,7 @@ test.serial("generateThemeDesignerResources: .theming file missing in sap.ui.cor

const workspace = {
byGlob: sinon.stub().callsFake(async (globPattern) => {
if (globPattern === "/resources/**/themes/*/library.source.less") {
if (globPattern === "/resources/sap/ui/core/themes/*/library.source.less") {
return [librarySourceLessResource];
} else {
return [];
Expand Down

0 comments on commit 8cecc01

Please sign in to comment.