Skip to content

Commit

Permalink
[INTERNAL] Minifer: Exclude .support.js files using glob pattern in b…
Browse files Browse the repository at this point in the history
…uilder instead of explicit implementation
  • Loading branch information
RandomByte committed Dec 23, 2021
1 parent a53c0cc commit 8a71cde
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 78 deletions.
25 changes: 15 additions & 10 deletions lib/processors/minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<object>} Promise resolving with object of resource, dbgResource and sourceMap
* @returns {Promise<module:@ui5/builder.processors.MinifierResult[]>}
* Promise resolving with object of resource, dbgResource and sourceMap
*/
module.exports = async function({resources}) {
return Promise.all(resources.map(async (resource) => {
Expand All @@ -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);
Expand Down
11 changes: 4 additions & 7 deletions lib/tasks/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]);
}));
};
3 changes: 2 additions & 1 deletion lib/types/application/ApplicationBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/types/library/LibraryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

23 changes: 0 additions & 23 deletions test/lib/processors/minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -74,10 +68,6 @@ test4();`;
resourceFactory.createResource({
path: "/test3.designtime.js",
string: content3
}),
resourceFactory.createResource({
path: "/test4.support.js",
string: content4
})
];

Expand All @@ -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"],` +
Expand Down Expand Up @@ -140,13 +124,6 @@ test4();`; // Excluded from minification
"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) => {
Expand Down

0 comments on commit 8a71cde

Please sign in to comment.