diff --git a/lib/builder/ProjectBuildContext.js b/lib/builder/ProjectBuildContext.js index cfad3e2ae..2ff81da50 100644 --- a/lib/builder/ProjectBuildContext.js +++ b/lib/builder/ProjectBuildContext.js @@ -1,7 +1,8 @@ const ResourceTagCollection = require("@ui5/fs").ResourceTagCollection; const STANDARD_TAGS = Object.freeze({ - OmitFromBuildResult: "ui5:OmitFromBuildResult" + OmitFromBuildResult: "ui5:OmitFromBuildResult", + IsBundle: "ui5:IsBundle" }); /** diff --git a/lib/tasks/bundlers/generateBundle.js b/lib/tasks/bundlers/generateBundle.js index b6a2eeeb4..49698e4ba 100644 --- a/lib/tasks/bundlers/generateBundle.js +++ b/lib/tasks/bundlers/generateBundle.js @@ -9,13 +9,16 @@ const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritiz * @param {object} parameters Parameters * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files * @param {module:@ui5/fs.ReaderCollection} parameters.dependencies 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 * @param {ModuleBundleDefinition} parameters.options.bundleDefinition Module bundle definition * @param {ModuleBundleOptions} parameters.options.bundleOptions Module bundle options * @returns {Promise} Promise resolving with undefined once data has been written */ -module.exports = function({workspace, dependencies, options: {projectName, bundleDefinition, bundleOptions}}) { +module.exports = function({ + workspace, dependencies, taskUtil, options: {projectName, bundleDefinition, bundleOptions} +}) { const combo = new ReaderCollectionPrioritized({ name: `libraryBundler - prioritize workspace over dependencies: ${projectName}`, readers: [workspace, dependencies] @@ -29,9 +32,12 @@ module.exports = function({workspace, dependencies, options: {projectName, bundl }, resources }).then((bundles) => { - bundles.forEach((bundle) => { - workspace.write(bundle); - }); + return Promise.all(bundles.map((bundle) => { + if (taskUtil) { + taskUtil.setTag(bundle, taskUtil.STANDARD_TAGS.IsBundle); + } + return workspace.write(bundle); + })); }); }); }; diff --git a/lib/tasks/bundlers/generateComponentPreload.js b/lib/tasks/bundlers/generateComponentPreload.js index bbd628cbd..dd14942af 100644 --- a/lib/tasks/bundlers/generateComponentPreload.js +++ b/lib/tasks/bundlers/generateComponentPreload.js @@ -11,13 +11,14 @@ const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritiz * @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/builder.tasks.TaskUtil|object} [parameters.taskUtil] TaskUtil * @param {object} parameters.options Options * @param {string} parameters.options.projectName Project name * @param {Array} [parameters.options.paths] Array of paths (or glob patterns) for component files * @param {Array} [parameters.options.namespaces] Array of component namespaces * @returns {Promise} Promise resolving with undefined once data has been written */ -module.exports = function({workspace, dependencies, options: {projectName, paths, namespaces}}) { +module.exports = function({workspace, dependencies, taskUtil, options: {projectName, paths, namespaces}}) { const combo = new ReaderCollectionPrioritized({ name: `generateComponentPreload - prioritize workspace over dependencies: ${projectName}`, readers: [workspace, dependencies] @@ -91,6 +92,9 @@ module.exports = function({workspace, dependencies, options: {projectName, paths }) .then((processedResources) => { return Promise.all(processedResources.map((resource) => { + if (taskUtil) { + taskUtil.setTag(resource[0], taskUtil.STANDARD_TAGS.IsBundle); + } return workspace.write(resource[0]); })); }); diff --git a/lib/tasks/bundlers/generateLibraryPreload.js b/lib/tasks/bundlers/generateLibraryPreload.js index d7fc56809..2fc9b842c 100644 --- a/lib/tasks/bundlers/generateLibraryPreload.js +++ b/lib/tasks/bundlers/generateLibraryPreload.js @@ -258,11 +258,12 @@ function getSapUiCoreBunDef(name, filters, preload) { * @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/builder.tasks.TaskUtil|object} [parameters.taskUtil] TaskUtil * @param {object} parameters.options Options * @param {string} parameters.options.projectName Project name * @returns {Promise} Promise resolving with undefined once data has been written */ -module.exports = function({workspace, dependencies, options: {projectName}}) { +module.exports = function({workspace, dependencies, taskUtil, options: {projectName}}) { const combo = new ReaderCollectionPrioritized({ name: `libraryBundler - prioritize workspace over dependencies: ${projectName}`, readers: [workspace, dependencies] @@ -311,7 +312,12 @@ module.exports = function({workspace, dependencies, options: {projectName}}) { }), ]).then((results) => { const bundles = Array.prototype.concat.apply([], results); - return Promise.all(bundles.map((bundle) => workspace.write(bundle))); + return Promise.all(bundles.map((bundle) => { + if (taskUtil) { + taskUtil.setTag(bundle, taskUtil.STANDARD_TAGS.IsBundle); + } + return workspace.write(bundle); + })); }); } else { p = Promise.resolve(); @@ -346,7 +352,14 @@ module.exports = function({workspace, dependencies, options: {projectName}}) { return createLibraryBundles(libraryNamespace, resources) .then((results) => { const bundles = Array.prototype.concat.apply([], results); - return Promise.all(bundles.map((bundle) => bundle && workspace.write(bundle))); + return Promise.all(bundles.map((bundle) => { + if (bundle) { + if (taskUtil) { + taskUtil.setTag(bundle, taskUtil.STANDARD_TAGS.IsBundle); + } + return workspace.write(bundle); + } + })); }); } else { log.verbose(`Could not determine library namespace from file "${libraryIndicatorPath}" for project ${projectName}. Skipping library preload bundling.`); diff --git a/lib/tasks/bundlers/generateStandaloneAppBundle.js b/lib/tasks/bundlers/generateStandaloneAppBundle.js index 968d4e9f4..ecb1bfae5 100644 --- a/lib/tasks/bundlers/generateStandaloneAppBundle.js +++ b/lib/tasks/bundlers/generateStandaloneAppBundle.js @@ -52,12 +52,13 @@ function getBundleDefinition(config) { * @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/builder.tasks.TaskUtil|object} [parameters.taskUtil] TaskUtil * @param {object} parameters.options Options * @param {string} parameters.options.projectName Project name * @param {string} [parameters.options.namespace] Project namespace * @returns {Promise} Promise resolving with undefined once data has been written */ -module.exports = async function({workspace, dependencies, options: {projectName, namespace}}) { +module.exports = async function({workspace, dependencies, taskUtil, options: {projectName, namespace}}) { if (!namespace) { log.warn(`Namespace of project ${projectName} is not known. Self contained bundling is currently ` + `unable to generate complete bundles for such projects.`); @@ -108,6 +109,11 @@ module.exports = async function({workspace, dependencies, options: {projectName, }) ]).then((results) => { const bundles = Array.prototype.concat.apply([], results); - return Promise.all(bundles.map((resource) => workspace.write(resource))); + return Promise.all(bundles.map((resource) => { + if (taskUtil) { + taskUtil.setTag(resource, taskUtil.STANDARD_TAGS.IsBundle); + } + return workspace.write(resource); + })); }); }; diff --git a/lib/tasks/uglify.js b/lib/tasks/uglify.js index 68a40e6d1..60884fda1 100644 --- a/lib/tasks/uglify.js +++ b/lib/tasks/uglify.js @@ -7,15 +7,22 @@ const uglifyProcessor = require("../processors/uglifier"); * @alias module:@ui5/builder.tasks.uglify * @param {object} parameters Parameters * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files + * @param {module:@ui5/builder.tasks.TaskUtil|object} [parameters.taskUtil] TaskUtil * @param {object} parameters.options Options * @param {string} parameters.options.pattern Pattern to locate the files to be processed * @returns {Promise} Promise resolving with undefined once data has been written */ -module.exports = function({workspace, options: {pattern}}) { +module.exports = function({workspace, taskUtil, options: {pattern}}) { return workspace.byGlobSource(pattern) .then((allResources) => { + let resources = allResources; + if (taskUtil) { + resources = allResources.filter((resource) => { + return !taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.IsBundle); + }); + } return uglifyProcessor({ - resources: allResources + resources }); }) .then((processedResources) => { diff --git a/lib/types/application/ApplicationBuilder.js b/lib/types/application/ApplicationBuilder.js index ec5d11358..5fe22513e 100644 --- a/lib/types/application/ApplicationBuilder.js +++ b/lib/types/application/ApplicationBuilder.js @@ -73,6 +73,7 @@ class ApplicationBuilder extends AbstractBuilder { return getTask("generateComponentPreload").task({ workspace: resourceCollections.workspace, dependencies: resourceCollections.dependencies, + taskUtil, options: { projectName: project.metadata.name, paths: componentPreload.paths, @@ -86,6 +87,7 @@ class ApplicationBuilder extends AbstractBuilder { return getTask("generateComponentPreload").task({ workspace: resourceCollections.workspace, dependencies: resourceCollections.dependencies, + taskUtil, options: { projectName: project.metadata.name, namespaces: [project.metadata.namespace] @@ -98,6 +100,7 @@ class ApplicationBuilder extends AbstractBuilder { return getTask("generateStandaloneAppBundle").task({ workspace: resourceCollections.workspace, dependencies: resourceCollections.dependencies, + taskUtil, options: { projectName: project.metadata.name, namespace: project.metadata.namespace @@ -122,6 +125,7 @@ class ApplicationBuilder extends AbstractBuilder { return getTask("generateBundle").task({ workspace: resourceCollections.workspace, dependencies: resourceCollections.dependencies, + taskUtil, options: { projectName: project.metadata.name, bundleDefinition: bundle.bundleDefinition, @@ -146,6 +150,7 @@ class ApplicationBuilder extends AbstractBuilder { const uglify = getTask("uglify").task; return uglify({ workspace: resourceCollections.workspace, + taskUtil, options: { pattern: "/**/*.js" } diff --git a/lib/types/library/LibraryBuilder.js b/lib/types/library/LibraryBuilder.js index 9e1833037..f5c977d63 100644 --- a/lib/types/library/LibraryBuilder.js +++ b/lib/types/library/LibraryBuilder.js @@ -56,9 +56,9 @@ class LibraryBuilder extends AbstractBuilder { } return getTask("generateJsdoc").task({ - taskUtil, workspace: resourceCollections.workspace, dependencies: resourceCollections.dependencies, + taskUtil, options: { projectName: project.metadata.name, namespace: project.metadata.namespace, @@ -86,6 +86,7 @@ class LibraryBuilder extends AbstractBuilder { return getTask("generateComponentPreload").task({ workspace: resourceCollections.workspace, dependencies: resourceCollections.dependencies, + taskUtil, options: { projectName: project.metadata.name, paths: componentPreload.paths, @@ -99,6 +100,7 @@ class LibraryBuilder extends AbstractBuilder { return getTask("generateLibraryManifest").task({ workspace: resourceCollections.workspace, dependencies: resourceCollections.dependencies, + taskUtil, options: { projectName: project.metadata.name } @@ -122,6 +124,7 @@ class LibraryBuilder extends AbstractBuilder { return getTask("generateLibraryPreload").task({ workspace: resourceCollections.workspace, dependencies: resourceCollections.dependencies, + taskUtil, options: { projectName: project.metadata.name } @@ -136,6 +139,7 @@ class LibraryBuilder extends AbstractBuilder { return getTask("generateBundle").task({ workspace: resourceCollections.workspace, dependencies: resourceCollections.dependencies, + taskUtil, options: { projectName: project.metadata.name, bundleDefinition: bundle.bundleDefinition, @@ -172,6 +176,7 @@ class LibraryBuilder extends AbstractBuilder { this.addTask("uglify", async () => { return getTask("uglify").task({ workspace: resourceCollections.workspace, + taskUtil, options: { pattern: "/resources/**/*.js" } diff --git a/test/lib/builder/ProjectBuildContext.js b/test/lib/builder/ProjectBuildContext.js index 85cf7652a..d14b3072c 100644 --- a/test/lib/builder/ProjectBuildContext.js +++ b/test/lib/builder/ProjectBuildContext.js @@ -85,15 +85,19 @@ test("STANDARD_TAGS constant", (t) => { }); t.deepEqual(projectBuildContext.STANDARD_TAGS, { - OmitFromBuildResult: "ui5:OmitFromBuildResult" + OmitFromBuildResult: "ui5:OmitFromBuildResult", + IsBundle: "ui5:IsBundle" }, "Exposes correct STANDARD_TAGS constant"); }); test.serial("getResourceTagCollection", (t) => { class DummyResourceTagCollection { constructor({allowedTags}) { - t.deepEqual(allowedTags, ["ui5:OmitFromBuildResult"], - "Correct allowedTags parameter supplied"); + t.deepEqual(allowedTags, [ + "ui5:OmitFromBuildResult", + "ui5:IsBundle" + ], + "Correct allowedTags parameter supplied"); } } mock("@ui5/fs", {