From ea2ae76340c2a5fbeb1fe581d49bf909233cf63f Mon Sep 17 00:00:00 2001 From: Tobias Sorn Date: Mon, 27 Jul 2020 13:59:32 +0200 Subject: [PATCH] Make terser leave @ui5-bundle-raw-include comment @ui5-bundle-raw-include comment is required to identify the module as raw-include. --- lib/processors/uglifier.js | 4 +- test/lib/tasks/uglify.js | 94 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 2 deletions(-) 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"); + }); +});