Skip to content

Commit

Permalink
[FIX] ComponentProject#getWorkspace: Apply builder resource excludes
Browse files Browse the repository at this point in the history
This resolves a regression caused by
#574 where the application of
builder resource-exclude configuration was moved from the low-level
_getSourceReader/_getTestReader methods to the high-level getReader API.

However, it was missed to also adapt the high-level getWorkspace API in
the same manner.

This caused the created workspace reader/writer to ignore any exclude
configuration as reported in
SAP/ui5-tooling#784 (comment)
  • Loading branch information
RandomByte committed Feb 17, 2023
1 parent d09401b commit 5257e59
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/specifications/ComponentProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ class ComponentProject extends Project {
*/
getWorkspace() {
// Workspace is always of style "buildtime"
// Therefore builder resource-excludes are always to be applied
const excludes = this.getBuilderResourcesExcludes();
return resourceFactory.createWorkspace({
name: `Workspace for project ${this.getName()}`,
reader: this._getReader(),
reader: this._getReader(excludes),
writer: this._getWriter().collection
});
}
Expand Down
21 changes: 21 additions & 0 deletions test/lib/specifications/types/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,27 @@ test("Access project resources via reader w/ builder excludes", async (t) => {
"Found excluded resource for runtime style");
});

test("Access project resources via workspace w/ builder excludes", async (t) => {
const {projectInput} = t.context;
const baselineProject = await Specification.create(projectInput);

projectInput.configuration.builder = {
resources: {
excludes: ["**/manifest.json"]
}
};
const excludesProject = await Specification.create(projectInput);

// We now have two projects: One with excludes and one without
// Always compare the results of both to make sure a file is really excluded because of the
// configuration and not because of a typo or because of it's absence in the fixture

t.is((await baselineProject.getWorkspace().byGlob("**/manifest.json")).length, 1,
"Found resource in baseline project for default style");
t.is((await excludesProject.getWorkspace().byGlob("**/manifest.json")).length, 0,
"Did not find excluded resource for default style");
});

test("Modify project resources via workspace and access via flat and runtime readers", async (t) => {
const {projectInput} = t.context;
const project = await Specification.create(projectInput);
Expand Down
21 changes: 21 additions & 0 deletions test/lib/specifications/types/Library.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,27 @@ test("Access project resources via reader w/ builder excludes", async (t) => {
"Found excluded resource for runtime style");
});

test("Access project resources via workspace w/ builder excludes", async (t) => {
const {projectInput} = t.context;
const baselineProject = await (new Library().init(projectInput));

projectInput.configuration.builder = {
resources: {
excludes: ["**/.library"]
}
};
const excludesProject = await (new Library().init(projectInput));

// We now have two projects: One with excludes and one without
// Always compare the results of both to make sure a file is really excluded because of the
// configuration and not because of a typo or because of it's absence in the fixture

t.is((await baselineProject.getWorkspace().byGlob("**/.library")).length, 1,
"Found resource in baseline project for default style");
t.is((await excludesProject.getWorkspace().byGlob("**/.library")).length, 0,
"Did not find excluded resource for default style");
});

test("Modify project resources via workspace and access via flat and runtime reader", async (t) => {
const {projectInput} = t.context;
const project = await (new Library().init(projectInput));
Expand Down
27 changes: 27 additions & 0 deletions test/lib/specifications/types/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,33 @@ test("Access project resources via reader w/ builder excludes", async (t) => {
"Found excluded resource for runtime style");
});

test("Access project resources via workspace w/ builder excludes", async (t) => {
const {projectInput, sinon} = t.context;
const baselineProject = await Specification.create(projectInput);
const excludesProject = await Specification.create(projectInput);

// As of specVersion 3.0, modules are not allowed to have a "builder.resources" configuration.
// Hence modules can't practically be configured with builder excludes.
// We still simply stub the respective API call to test the code and be prepared
//
// projectInput.configuration.builder = {
// resources: {
// excludes: ["**/devTools.js"]
// }
// };
// So stub instead:
sinon.stub(excludesProject, "getBuilderResourcesExcludes").returns(["**/devTools.js"]);

// We now have two projects: One with excludes and one without
// Always compare the results of both to make sure a file is really excluded because of the
// configuration and not because of a typo or because of it's absence in the fixture

t.is((await baselineProject.getWorkspace().byGlob("**/devTools.js")).length, 1,
"Found resource in baseline project for default style");
t.is((await excludesProject.getWorkspace().byGlob("**/devTools.js")).length, 0,
"Did not find excluded resource for default style");
});

test("Modify project resources via workspace and access via reader", async (t) => {
const {projectInput} = t.context;
const project = await Specification.create(projectInput);
Expand Down
21 changes: 21 additions & 0 deletions test/lib/specifications/types/ThemeLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ test("Access project resources via reader w/ builder excludes", async (t) => {
"Found excluded resource for runtime style");
});

test("Access project resources via workspace w/ builder excludes", async (t) => {
const {projectInput} = t.context;
const baselineProject = await Specification.create(projectInput);

projectInput.configuration.builder = {
resources: {
excludes: ["**/.theme"]
}
};
const excludesProject = await Specification.create(projectInput);

// We now have two projects: One with excludes and one without
// Always compare the results of both to make sure a file is really excluded because of the
// configuration and not because of a typo or because of it's absence in the fixture

t.is((await baselineProject.getWorkspace().byGlob("**/.theme")).length, 1,
"Found resource in baseline project for default style");
t.is((await excludesProject.getWorkspace().byGlob("**/.theme")).length, 0,
"Did not find excluded resource for default style");
});

test("Modify project resources via workspace and access via flat and runtime reader", async (t) => {
const {projectInput} = t.context;
const project = await Specification.create(projectInput);
Expand Down

0 comments on commit 5257e59

Please sign in to comment.