Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Switch XML minifier from pretty-data to minify-xml #488

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/lbt/bundle/AutoSplitter.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"use strict";

const terser = require("terser");
const {pd} = require("pretty-data");
const minifyXml = require("minify-xml");

const ModuleName = require("../utils/ModuleName");
const {SectionType} = require("./BundleDefinition");
const escapePropertiesFile = require("../utils/escapePropertiesFile");
const log = require("@ui5/logger").getLogger("lbt:bundle:AutoSplitter");

const copyrightCommentsPattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-za-z])|released under|license|\u00a9/i;
const xmlHtmlPrePattern = /<(?:\w+:)?pre>/;
const xmlHtmlPrePattern = /<(?:\w+:)?pre\b/;

/**
*
Expand Down Expand Up @@ -235,12 +235,12 @@ class AutoSplitter {
// needs to be activated when it gets activated in JSMergedModuleBuilderExt
let fileContent = await resource.buffer();
if ( this.optimize ) {
// For XML we use the pretty data
// Do not minify if XML(View) contains an <*:pre> tag because whitespace of
// HTML <pre> should be preserved (should only happen rarely)
if (!xmlHtmlPrePattern.test(fileContent)) {
fileContent = pd.xmlmin(fileContent, false);
}
// use minify-xml for XML, do not minify whitespaces between tags if the XML(View) contains an
// <*:pre> tag, because whitespace of HTML <pre> should be preserved (this should rarely happen)
const noPreTag = !xmlHtmlPrePattern.test(fileContent);
fileContent = minifyXml.minify(fileContent.toString(), {
removeWhitespaceBetweenTags: noPreTag
});
}
return fileContent.length;
}
Expand Down
16 changes: 8 additions & 8 deletions lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"use strict";

const terser = require("terser");
const {pd} = require("pretty-data");
const minifyXml = require("minify-xml");
const esprima = require("esprima");
const escodegen = require("escodegen");
const {Syntax} = esprima;
Expand All @@ -21,7 +21,7 @@ const BundleWriter = require("./BundleWriter");
const log = require("@ui5/logger").getLogger("lbt:bundle:Builder");

const copyrightCommentsPattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-za-z])|released under|license|\u00a9|^@ui5-bundle-raw-include |^@ui5-bundle /i;
const xmlHtmlPrePattern = /<(?:\w+:)?pre>/;
const xmlHtmlPrePattern = /<(?:\w+:)?pre\b/;

const strReplacements = {
"\r": "\\r",
Expand Down Expand Up @@ -426,12 +426,12 @@ class BundleBuilder {
} else if ( /\.xml$/.test(module) ) {
let fileContent = await resource.buffer();
if ( this.optimize ) {
// For XML we use the pretty data
// Do not minify if XML(View) contains an <*:pre> tag,
// because whitespace of HTML <pre> should be preserved (should only happen rarely)
if (!xmlHtmlPrePattern.test(fileContent)) {
fileContent = pd.xmlmin(fileContent.toString(), false);
}
// use minify-xml for XML, do not minify whitespaces between tags if the XML(View) contains an
// <*:pre> tag, because whitespace of HTML <pre> should be preserved (this should rarely happen)
const noPreTag = !xmlHtmlPrePattern.test(fileContent);
fileContent = minifyXml.minify(fileContent.toString(), {
removeWhitespaceBetweenTags: noPreTag
});
}
outW.write( makeStringLiteral( fileContent ) );
} else if ( /\.properties$/.test(module) ) {
Expand Down
Loading