Skip to content

Commit

Permalink
[BREAKING] generateResourcesJson: Make 'dependencies' parameter manda…
Browse files Browse the repository at this point in the history
…tory
  • Loading branch information
matz3 committed Jan 21, 2022
1 parent 23fa5a7 commit 268dd16
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
17 changes: 5 additions & 12 deletions lib/tasks/generateResourcesJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,25 @@ function getCreatorOptions(projectName) {
* @alias module:@ui5/builder.tasks.generateResourcesJson
* @param {object} parameters Parameters
* @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
* @param {module:@ui5/fs.AbstractReader} [parameters.dependencies] Reader or Collection to read dependency files
* @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
* @param {module:@ui5/builder.tasks.TaskUtil|object} [parameters.taskUtil] TaskUtil
* @param {object} parameters.options Options
* @param {string} parameters.options.projectName Project name
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
module.exports = async function({workspace, dependencies, taskUtil, options: {projectName}}) {
let resources = await workspace.byGlob(["/resources/**/*"].concat(DEFAULT_EXCLUDES));

// TODO 3.0: Make dependencies parameter mandatory
let dependencyResources;
if (dependencies) {
dependencyResources =
let dependencyResources =
await dependencies.byGlob("/resources/**/*.{js,json,xml,html,properties,library}");
}

if (taskUtil) {
// Filter out resources that will be omitted from the build results
resources = resources.filter((resource) => {
return !taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.OmitFromBuildResult);
});
if (dependencyResources) {
dependencyResources = dependencyResources.filter((resource) => {
return !taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.OmitFromBuildResult);
});
}
dependencyResources = dependencyResources.filter((resource) => {
return !taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.OmitFromBuildResult);
});
}

const resourceLists = await resourceListCreator({
Expand Down
24 changes: 22 additions & 2 deletions test/lib/tasks/generateResourcesJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ function createWorkspace() {
});
}

function createDependencies() {
return {
byGlob: sinon.stub().resolves([])
};
}

test.beforeEach((t) => {
t.context.resourceListCreatorStub = sinon.stub();
t.context.resourceListCreatorStub.returns(Promise.resolve([]));
Expand All @@ -39,12 +45,26 @@ test.afterEach.always((t) => {
mock.stopAll();
});

test.serial("Missing 'dependencies' parameter", async (t) => {
const {generateResourcesJson} = t.context;

await t.throwsAsync(generateResourcesJson({
workspace: createWorkspace(),
options: {
projectName: "sap.ui.core"
}
}), {
// Not passing dependencies should result into a TypeError
name: "TypeError"
});
});

test.serial("empty resources (sap.ui.core)", async (t) => {
const {generateResourcesJson, resourceListCreatorStub} = t.context;

const result = await generateResourcesJson({
workspace: createWorkspace(),
dependencies: undefined,
dependencies: createDependencies(),
options: {
projectName: "sap.ui.core"
}
Expand All @@ -69,7 +89,7 @@ test.serial("empty resources (my.lib)", async (t) => {

const result = await generateResourcesJson({
workspace: createWorkspace(),
dependencies: undefined,
dependencies: createDependencies(),
options: {
projectName: "my.lib"
}
Expand Down
5 changes: 5 additions & 0 deletions test/lib/types/themeLibrary/ThemeLibraryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ test("tasks", async (t) => {
byGlob: async () => {
return [];
}
},
dependencies: {
byGlob: async () => {
return [];
}
}
},
buildContext: {
Expand Down

0 comments on commit 268dd16

Please sign in to comment.