diff --git a/lib/processors/minifier.js b/lib/processors/minifier.js index a727d9abd..e2abe32d8 100644 --- a/lib/processors/minifier.js +++ b/lib/processors/minifier.js @@ -15,14 +15,27 @@ const Resource = require("@ui5/fs").Resource; const copyrightCommentsAndBundleCommentPattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-za-z])|released under|license|\u00a9|^@ui5-bundle-raw-include |^@ui5-bundle /i; const debugFileRegex = /((?:\.view|\.fragment|\.controller|\.designtime|\.support)?\.js)$/; + +/** + * Result set + * + * @public + * @typedef {object} MinifierResult + * @property {module:@ui5/fs.Resource} resource Minified resource + * @property {module:@ui5/fs.Resource} dbgResource Debug (non-minified) variant + * @property {module:@ui5/fs.Resource} sourceMap Source Map + * @memberof module:@ui5/builder.processors + */ + /** * Minifies the supplied resources. * * @public - * @alias module:@ui5/builder.processors.uglifier + * @alias module:@ui5/builder.processors.minifier * @param {object} parameters Parameters * @param {module:@ui5/fs.Resource[]} parameters.resources List of resources to be processed - * @returns {Promise} Promise resolving with object of resource, dbgResource and sourceMap + * @returns {Promise} + * Promise resolving with object of resource, dbgResource and sourceMap */ module.exports = async function({resources}) { return Promise.all(resources.map(async (resource) => { @@ -31,14 +44,6 @@ module.exports = async function({resources}) { dbgResource.setPath(dbgPath); const filename = path.posix.basename(resource.getPath()); - if (filename.endsWith(".support.js")) { - return { - resource, - dbgResource, - sourceMapResource: null - }; - } - const code = await resource.getString(); try { const dbgFilename = path.posix.basename(dbgPath); diff --git a/lib/tasks/minify.js b/lib/tasks/minify.js index 558ef230b..ba508ca5a 100644 --- a/lib/tasks/minify.js +++ b/lib/tasks/minify.js @@ -21,13 +21,10 @@ module.exports = async function({workspace, taskUtil, options: {pattern}}) { taskUtil.setTag(resource, taskUtil.STANDARD_TAGS.HasDebugVariant); taskUtil.setTag(dbgResource, taskUtil.STANDARD_TAGS.IsDebugVariant); } - const pWrites = [ + return Promise.all([ workspace.write(resource), - workspace.write(dbgResource) - ]; - if (sourceMapResource) { - pWrites.push(workspace.write(sourceMapResource)); - } - return Promise.all(pWrites); + workspace.write(dbgResource), + workspace.write(sourceMapResource) + ]); })); }; diff --git a/lib/types/application/ApplicationBuilder.js b/lib/types/application/ApplicationBuilder.js index 60989a61c..444ebce64 100644 --- a/lib/types/application/ApplicationBuilder.js +++ b/lib/types/application/ApplicationBuilder.js @@ -67,7 +67,8 @@ class ApplicationBuilder extends AbstractBuilder { }); } - const minificationPattern = ["/**/*.js"]; + // Support rules should not be minified to have readable code in the Support Assistant + const minificationPattern = ["/**/*.js", "!**/*.support.js"]; if (["2.6"].includes(project.specVersion)) { const minificationExcludes = project.builder && project.builder.minification && project.builder.minification.excludes; diff --git a/lib/types/library/LibraryBuilder.js b/lib/types/library/LibraryBuilder.js index 4908d62a0..0616a4b99 100644 --- a/lib/types/library/LibraryBuilder.js +++ b/lib/types/library/LibraryBuilder.js @@ -89,7 +89,8 @@ class LibraryBuilder extends AbstractBuilder { }); } - const minificationPattern = ["/resources/**/*.js"]; + // Support rules should not be minified to have readable code in the Support Assistant + const minificationPattern = ["/resources/**/*.js", "!**/*.support.js"]; if (["2.6"].includes(project.specVersion)) { const minificationExcludes = project.builder && project.builder.minification && project.builder.minification.excludes; diff --git "a/test/expected/build/library.\303\270/dest/resources/library/\303\270/rules/MyControl-dbg.support.js" "b/test/expected/build/library.\303\270/dest/resources/library/\303\270/rules/MyControl-dbg.support.js" deleted file mode 100644 index 6f084d6ef..000000000 --- "a/test/expected/build/library.\303\270/dest/resources/library/\303\270/rules/MyControl-dbg.support.js" +++ /dev/null @@ -1,36 +0,0 @@ -/*! - * Some fancy copyright - */ -/** - * Defines support rules - */ - sap.ui.define(['sap/ui/support/library', 'sap/base/Log'], - function(SupportLib, Log) { - 'use strict'; - - //********************************************************** - // Rule Definitions - //********************************************************** - - var oRule = { - id: "oRule", - audiences: [Audiences.Application], - categories: [Categories.Usage], - enabled: true, - minversion: '1.71', - title: 'Title', - description: 'description', - resolution: 'resolution', - check: function(oIssueManager, oCoreFacade, oScope) { - oIssueManager.addIssue({ - severity: Severity.High, - details: 'Looking good today!' - }); - } - }; - - return [ - oRule - ]; - - }, true); diff --git a/test/lib/processors/minifier.js b/test/lib/processors/minifier.js index 68cdecbad..e204ca268 100644 --- a/test/lib/processors/minifier.js +++ b/test/lib/processors/minifier.js @@ -55,12 +55,6 @@ function test3(paramA) { console.log(variableA); } test3();`; - const content4 = ` -function test4(paramA) { - var variableA = paramA; - console.log(variableA); -} -test4();`; const testResources = [ resourceFactory.createResource({ @@ -74,10 +68,6 @@ test4();`; resourceFactory.createResource({ path: "/test3.designtime.js", string: content3 - }), - resourceFactory.createResource({ - path: "/test4.support.js", - string: content4 }) ]; @@ -91,12 +81,6 @@ test4();`; //# sourceMappingURL=test2.fragment.js.map`; const expectedMinified3 = `function test3(t){var o=t;console.log(o)}test3(); //# sourceMappingURL=test3.designtime.js.map`; - const expectedMinified4 = ` -function test4(paramA) { - var variableA = paramA; - console.log(variableA); -} -test4();`; // Excluded from minification const expectedSourceMap1 = `{"version":3,"sources":["test1-dbg.controller.js"],"names":["test1","paramA","variableA","console","log"],` + @@ -108,45 +92,38 @@ test4();`; // Excluded from minification `{"version":3,"sources":["test3-dbg.designtime.js"],"names":["test3","paramA","variableA","console","log"],` + `"mappings":"AACA,SAASA,MAAMC,GACd,IAAIC,EAAYD,EAChBE,QAAQC,IAAIF,GAEbF","file":"test3.designtime.js"}`; - t.deepEqual(await resources[0].resource.getPath(), "/test1.controller.js", + t.deepEqual(resources[0].resource.getPath(), "/test1.controller.js", "Correct resource path for minified content of resource 1"); t.deepEqual(await resources[0].resource.getString(), expectedMinified1, "Correct minified content for resource 1"); - t.deepEqual(await resources[0].dbgResource.getPath(), "/test1-dbg.controller.js", + t.deepEqual(resources[0].dbgResource.getPath(), "/test1-dbg.controller.js", "Correct resource path for debug content of resource 1"); t.deepEqual(await resources[0].dbgResource.getString(), content1, "Correct debug content for resource 1"); - t.deepEqual(await resources[0].sourceMapResource.getPath(), "/test1.controller.js.map", + t.deepEqual(resources[0].sourceMapResource.getPath(), "/test1.controller.js.map", "Correct resource path for source map content of resource 1"); t.deepEqual(await resources[0].sourceMapResource.getString(), expectedSourceMap1, "Correct source map content for resource 1"); - t.deepEqual(await resources[1].resource.getPath(), "/test2.fragment.js", + t.deepEqual(resources[1].resource.getPath(), "/test2.fragment.js", "Correct resource path for minified content of resource 2"); t.deepEqual(await resources[1].resource.getString(), expectedMinified2, "Correct minified content for resource 2"); - t.deepEqual(await resources[1].dbgResource.getPath(), "/test2-dbg.fragment.js", + t.deepEqual(resources[1].dbgResource.getPath(), "/test2-dbg.fragment.js", "Correct resource path for debug content of resource 2"); t.deepEqual(await resources[1].dbgResource.getString(), content2, "Correct debug content for resource 2"); - t.deepEqual(await resources[1].sourceMapResource.getPath(), "/test2.fragment.js.map", + t.deepEqual(resources[1].sourceMapResource.getPath(), "/test2.fragment.js.map", "Correct resource path for source map content of resource 2"); t.deepEqual(await resources[1].sourceMapResource.getString(), expectedSourceMap2, "Correct source map content for resource 2"); - t.deepEqual(await resources[2].resource.getPath(), "/test3.designtime.js", + t.deepEqual(resources[2].resource.getPath(), "/test3.designtime.js", "Correct resource path for minified content of resource 3"); t.deepEqual(await resources[2].resource.getString(), expectedMinified3, "Correct minified content for resource 3"); - t.deepEqual(await resources[2].dbgResource.getPath(), "/test3-dbg.designtime.js", + t.deepEqual(resources[2].dbgResource.getPath(), "/test3-dbg.designtime.js", "Correct resource path for debug content of resource 3"); t.deepEqual(await resources[2].dbgResource.getString(), content3, "Correct debug content for resource 3"); - t.deepEqual(await resources[2].sourceMapResource.getPath(), "/test3.designtime.js.map", + t.deepEqual(resources[2].sourceMapResource.getPath(), "/test3.designtime.js.map", "Correct resource path for source map content of resource 3"); t.deepEqual(await resources[2].sourceMapResource.getString(), expectedSourceMap3, "Correct source map content for resource 3"); - - t.deepEqual(await resources[3].resource.getPath(), "/test4.support.js", - "Correct resource path for minified content of resource 4"); - t.deepEqual(await resources[3].resource.getString(), expectedMinified4, "Correct minified content for resource 4"); - t.deepEqual(await resources[3].dbgResource.getPath(), "/test4-dbg.support.js", - "Correct resource path for debug content of resource 4"); - t.deepEqual(await resources[3].dbgResource.getString(), content4, "Correct debug content for resource 4"); }); test("Different copyright", async (t) => {