Revert "Avoid unnecessary Buffer allocations in minifyJs."

This reverts commit ff0d85d391.
This commit is contained in:
denyhs
2020-09-14 16:34:28 -04:00
parent a07c993ea5
commit 6e2011c011
2 changed files with 24 additions and 3 deletions

View File

@@ -1354,7 +1354,17 @@ class Target {
inputHashesByJsFile.set(jsf, file.hash());
if (file.targetPath.startsWith("dynamic/")) {
// Dynamic files consist of a single anonymous function
// expression, which some minifiers (e.g. UglifyJS) either fail to
// parse or mistakenly eliminate as dead code. To avoid these
// problems, we temporarily name the function __minifyJs.
file._contents = Buffer.concat([
MINIFY_RENAMED_FUNCTION,
file.contents().slice(MINIFY_PLAIN_FUNCTION.length)
]);
dynamicFiles.push(jsf);
} else {
staticFiles.push(jsf);
}
@@ -1382,8 +1392,19 @@ class Target {
function handle(source, dynamic) {
source._minifiedFiles.forEach(file => {
if (typeof file.data === "string") {
file.data = Buffer.from(file.data, "utf8");
// Remove the function name __minifyJs that was added above.
if (typeof file.data === 'string') {
file.data = Buffer.from(
file.data
.replace(/^\s*function\s+__minifyJs\s*\(/,
"function("),
"utf8"
);
} else if (dynamic) {
file.data = Buffer.concat([
MINIFY_PLAIN_FUNCTION,
file.data.slice(MINIFY_RENAMED_FUNCTION.length)
]);
}
const newFile = new File({

View File

@@ -685,7 +685,7 @@ _.extend(File.prototype, {
_getClosureHeader() {
if (this.meteorInstallOptions) {
const headerParts = ["function module("];
const headerParts = ["function("];
if (this.source.match(/\b__dirname\b/)) {
headerParts.push("require,exports,module,__filename,__dirname");