Skip to content

Commit 8cecc01

Browse files
authored
[FIX] Theme Build: Only process themes within library namespace (#570)
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.
1 parent 0e25b59 commit 8cecc01

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

lib/tasks/generateThemeDesignerResources.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,16 @@ module.exports = async function({workspace, dependencies, options: {projectName,
101101
return;
102102
}
103103

104-
const librarySourceLessResources = await workspace.byGlob("/resources/**/themes/*/library.source.less");
104+
let librarySourceLessPattern;
105+
if (namespace) {
106+
// In case of a library only check for themes directly below the namespace
107+
librarySourceLessPattern = `/resources/${namespace}/themes/*/library.source.less`;
108+
} else {
109+
// In case of a theme-library check for all "themes"
110+
librarySourceLessPattern = `/resources/**/themes/*/library.source.less`;
111+
}
112+
113+
const librarySourceLessResources = await workspace.byGlob(librarySourceLessPattern);
105114

106115
const hasThemes = librarySourceLessResources.length > 0;
107116

lib/types/library/LibraryBuilder.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,19 @@ class LibraryBuilder extends AbstractBuilder {
152152
}
153153

154154
this.addTask("buildThemes", async () => {
155+
// Only compile themes directly below the lib namespace to be in sync with the theme support at runtime
156+
// which only loads themes from that folder.
157+
// TODO 3.0: Remove fallback in case of missing namespace
158+
const inputPattern = `/resources/${project.metadata.namespace || "**"}/themes/*/library.source.less`;
159+
155160
return getTask("buildThemes").task({
156161
workspace: resourceCollections.workspace,
157162
dependencies: resourceCollections.dependencies,
158163
options: {
159164
projectName: project.metadata.name,
160165
librariesPattern: !taskUtil.isRootProject() ? "/resources/**/*.library" : undefined,
161166
themesPattern: !taskUtil.isRootProject() ? "/resources/sap/ui/core/themes/*" : undefined,
162-
inputPattern: "/resources/**/themes/*/library.source.less"
167+
inputPattern
163168
}
164169
});
165170
});

test/lib/tasks/buildThemes.integration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test("integration: simple", (t) => {
5151
workspace: duplexCollection,
5252
dependencies: dependencies,
5353
options: {
54-
inputPattern: "/resources/**/themes/**/library.source.less"
54+
inputPattern: "/resources/super/duper/looper/themes/**/library.source.less"
5555
}
5656
}).then(() => {
5757
return Promise.all([
@@ -133,7 +133,7 @@ test("integration: imports", (t) => {
133133
workspace: duplexCollection,
134134
dependencies: dependencies,
135135
options: {
136-
inputPattern: "/resources/**/themes/**/library.source.less"
136+
inputPattern: "/resources/super/duper/looper/themes/**/library.source.less"
137137
}
138138
}).then(() => {
139139
return Promise.all([

test/lib/tasks/generateThemeDesignerResources.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ test.serial("generateThemeDesignerResources: Library", async (t) => {
6767

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

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

419419
const workspace = {
420420
byGlob: sinon.stub().callsFake(async (globPattern) => {
421-
if (globPattern === "/resources/**/themes/*/library.source.less") {
421+
if (globPattern === "/resources/sap/ui/core/themes/*/library.source.less") {
422422
return [librarySourceLessResource];
423423
} else {
424424
return [];

0 commit comments

Comments
 (0)