diff --git a/lib/processors/uglifier.js b/lib/processors/uglifier.js index a20707397..82a09a927 100644 --- a/lib/processors/uglifier.js +++ b/lib/processors/uglifier.js @@ -1,5 +1,5 @@ const terser = require("terser"); -const copyrightCommentsPattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-za-z])|released under|license|\u00a9/i; +const copyrightCommentsAndRawIncludePattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-za-z])|released under|license|\u00a9|@ui5-bundle-raw-include/i; /** * Minifies the supplied resources. @@ -18,7 +18,7 @@ module.exports = function({resources}) { }, { warnings: false, output: { - comments: copyrightCommentsPattern, + comments: copyrightCommentsAndRawIncludePattern, wrap_func_args: false }, compress: false diff --git a/test/lib/tasks/uglify.js b/test/lib/tasks/uglify.js index fe397df7d..fed2b8347 100644 --- a/test/lib/tasks/uglify.js +++ b/test/lib/tasks/uglify.js @@ -47,3 +47,97 @@ test();`; return t.deepEqual(buffer.toString(), expected, "Correct content"); }); }); + +test("integration: uglify copyright", (t) => { + const reader = resourceFactory.createAdapter({ + virBasePath: "/" + }); + const writer = resourceFactory.createAdapter({ + virBasePath: "/" + }); + const duplexCollection = new DuplexCollection({reader: reader, writer: writer}); + const content = ` +/* + * Copyright jQuery Foundation and other contributors + */ +function test(paramA) { + var variableA = paramA; + console.log(variableA); +} +test();`; + const testResource = resourceFactory.createResource({ + path: "/test.js", + string: content + }); + const expected = `/* + * Copyright jQuery Foundation and other contributors + */ +function test(t){var o=t;console.log(o)}test();`; + + return reader.write(testResource) + .then(() => { + return reader.byPath("/test.js"); + }).then(() => { + return uglify({ + workspace: duplexCollection, + options: { + pattern: "/test.js" + } + }); + }).then(() => { + return writer.byPath("/test.js").then((resource) => { + if (!resource) { + t.fail("Could not find /test.js in target locator"); + } else { + return resource.getBuffer(); + } + }); + }).then((buffer) => { + return t.deepEqual(buffer.toString(), expected, "Correct content"); + }); +}); + +test("integration: uglify raw module (@ui5-bundle-raw-include)", (t) => { + const reader = resourceFactory.createAdapter({ + virBasePath: "/" + }); + const writer = resourceFactory.createAdapter({ + virBasePath: "/" + }); + const duplexCollection = new DuplexCollection({reader: reader, writer: writer}); + const content = ` +//@ui5-bundle-raw-include sap/ui/my/module.js +function test(paramA) { + var variableA = paramA; + console.log(variableA); +} +test();`; + const testResource = resourceFactory.createResource({ + path: "/test.js", + string: content + }); + const expected = `//@ui5-bundle-raw-include sap/ui/my/module.js +function test(t){var o=t;console.log(o)}test();`; + + return reader.write(testResource) + .then(() => { + return reader.byPath("/test.js"); + }).then(() => { + return uglify({ + workspace: duplexCollection, + options: { + pattern: "/test.js" + } + }); + }).then(() => { + return writer.byPath("/test.js").then((resource) => { + if (!resource) { + t.fail("Could not find /test.js in target locator"); + } else { + return resource.getBuffer(); + } + }); + }).then((buffer) => { + return t.deepEqual(buffer.toString(), expected, "Correct content"); + }); +});