Skip to content

Commit

Permalink
Make terser leave @ui5-bundle-raw-include comment
Browse files Browse the repository at this point in the history
@ui5-bundle-raw-include comment is required to identify
the module as raw-include.
  • Loading branch information
tobiasso85 committed Jul 27, 2020
1 parent ae23c63 commit 815b826
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/processors/uglifier.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,7 +18,7 @@ module.exports = function({resources}) {
}, {
warnings: false,
output: {
comments: copyrightCommentsPattern,
comments: copyrightCommentsAndRawIncludePattern,
wrap_func_args: false
},
compress: false
Expand Down
94 changes: 94 additions & 0 deletions test/lib/tasks/uglify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

0 comments on commit 815b826

Please sign in to comment.