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

LPS-124465 Avoid unwanted minification of Liferay global #636

Conversation

wincent
Copy link

@wincent wincent commented Dec 17, 2020

As explained in https://issues.liferay.com/browse/LPS-124465 our minification takes some care to avoid mangling property access.

Combined with the fact that Liferay is usually accessed as a global and therefore not minified, that means that we can rely on the minifier leaving strings like Liferay.Language.get untouched in the source. The LanguageFilter can then find those strings and substitute them on the fly.

In LPS-124465 we see a pattern that breaks this. Liferay is passed into a function, where, as a local binding, the minifier is free to rewrite it (eg. to t), so our source text now reads t.Language.get and the LanguageFilter does not substitute it.

Fix taken here is to avoid that pattern in portlet.js and everywhere else we seem to be doing it (not many places, all found with a crude regex for \((\s*\w+\s*,)*\bLiferay\b(\s*,\s*\w+\s*)*\); that won't cover everything, like things split across multiple lines, but it will catch most things... probably everything).

Instead of:

(function (Liferay) {
    // blah...
})(Liferay);

we just do:

(function () {
    // blah...
})();

There was one place where we had:

Liferay = window.Liferay || {};

Note that the minifier is "smart" enough to know that Liferay there is not a global, and it preserves the name. But prior to this PR, if you inspect the build output it does the unwanted t mangling; ie. before:

Liferay=window.Liferay||{},function(t){ /* a bunch of stuff */ }(Liferay);

after:

Liferay=window.Liferay||{},function(){ /* a bunch of stuff */ }();

As explained in https://issues.liferay.com/browse/LPS-124465 our
minification takes some care to avoid mangling property access:

https://github.com/liferay/liferay-frontend-projects/blob/a33874a2630a07e24cd46421fb346235467ea6c5/projects/npm-tools/packages/npm-scripts/src/config/terser.config.js#L10-L12

Combined with the fact that `Liferay` is usually accessed as a global
and therefore not minified, that means that we can rely on the minifier
leaving strings like `Liferay.Language.get` untouched in the source. The
LanguageFilter can then find those strings and substitute them on the
fly.

In LPS-124465 we see a pattern that breaks this. `Liferay` is passed
into a function, where, as a local binding, the minifier is free to
rewrite it (eg. to `t`), so our source text now reads `t.Language.get`
and the LanguageFilters does not substitute it.

Fix taken here is to avoid that pattern in `portlet.js` and everywhere
else we seem to be doing it (not many places, all found with a crude
regex for `\((\s*\w+\s*,)*\bLiferay\b(\s*,\s*\w+\s*)*\)`; that won't
cover everything, like things split across multiple lines, but it will
catch most things... probably everything).

Instead of:

```js
(function (Liferay) {
    // blah...
})(Liferay);
```

we just do:

```js
(function () {
    // blah...
})();
```

There was one place where we had:

```js
Liferay = window.Liferay || {};
```

Note that the minifier is "smart" enough to know that `Liferay` there is
not a global, and it preserves the name. But prior to this PR, if you
inspect the build output it does the unwanted `t` mangling; ie. before:

    Liferay=window.Liferay||{},function(t){ /* a bunch of stuff */ }(Liferay);

after:

    Liferay=window.Liferay||{},function(){ /* a bunch of stuff */ }();
@liferay-continuous-integration
Copy link
Collaborator

CI is automatically triggering the following test suites:

  •     ci:test:relevant
  •     ci:test:sf

@wincent
Copy link
Author

wincent commented Dec 17, 2020

Now observe SF blow up on this one because I tried to run it locally and it ran out of memory (probably due to having an ant all going at the same time...)

@wincent
Copy link
Author

wincent commented Dec 17, 2020

ci:test:bundle

@wincent
Copy link
Author

wincent commented Dec 17, 2020

We could look at adding a lint to stop anybody from doing anything like this again, but I am lazy, and propose that we only do that if it actually does happen again.

@liferay-continuous-integration
Copy link
Collaborator

✔️ ci:test:sf - 1 out of 1 jobs passed in 0 ms

Click here for more details.

Base Branch:

Branch Name: master
Branch GIT ID: ff0e5e147ea14773fc626b3a4024d041bfefb138

Sender Branch:

Branch Name: wincent/LPS-124465/language-get
Branch GIT ID: 1bb9fd1c202e15f615b35fd21330d6c9d7f893ef

1 out of 1jobs PASSED
1 Successful Jobs:
For more details click here.

Copy link

@jbalsas jbalsas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

We could look at adding a lint to stop anybody from doing anything like this again, but I am lazy, and propose that we only do that if it actually does happen again.

We could even agree to only do that if it actually happens at least twice again ;)

@wincent
Copy link
Author

wincent commented Dec 17, 2020

We could even agree to only do that if it actually happens at least twice again ;)

Or if somebody paid us 5 Lifebucks.

@liferay-continuous-integration
Copy link
Collaborator

@liferay-continuous-integration
Copy link
Collaborator

✔️ ci:test:bundle - 1 out of 1 jobs passed in 53 minutes

Click here for more details.

Base Branch:

Branch Name: master
Branch GIT ID: ff0e5e147ea14773fc626b3a4024d041bfefb138

Copied in Private Modules Branch:

Branch Name: master-private
Branch GIT ID: 0ff04d9f73a4643abdd2b335581feef26b985b8a

ci:test:bundle - 1 out of 1 jobs PASSED
For more details click here.
Test bundle downloads:

@wincent
Copy link
Author

wincent commented Dec 17, 2020

Regression is gone:

Screenshot 2020-12-17 -164106-3CgNfuK8@2x

@liferay-continuous-integration
Copy link
Collaborator

✔️ ci:test:stable - 9 out of 9 jobs passed

❌ ci:test:relevant - 20 out of 23 jobs passed in 3 hours 6 minutes

Click here for more details.

Base Branch:

Branch Name: master
Branch GIT ID: ff0e5e147ea14773fc626b3a4024d041bfefb138

Copied in Private Modules Branch:

Branch Name: master-private
Branch GIT ID: 0ff04d9f73a4643abdd2b335581feef26b985b8a

ci:test:stable - 9 out of 9 jobs PASSED
9 Successful Jobs:
ci:test:relevant - 20 out of 23 jobs PASSED
20 Successful Jobs:
For more details click here.

Failures unique to this pull:


Failures in common with acceptance upstream results at ff0e5e1:
  1. test-portal-acceptance-pullrequest-batch(master)/semantic-versioning-jdk8/0
    Job Results:

    0 Tests Passed.
    1 Test Failed.

    1. AXIS_VARIABLE=0,label_exp=!master #410367

      Please fix semantic versioning on wincent/wincent/LPS-124465/language-get

           [exec] 			+   return     void
           [exec] 		+   method     <init>(java.lang.String)
           [exec] 			+   return     void
           [exec] 		+   method     <init>(java.lang.String,java.lang.Throwable)
           [exec] 			+   return     void
           [exec] 		+   method     <init>(java.lang.Throwable)
           [exec] 			+   return     void
           [exec] 		+   method     addSuppressed(java.lang.Throwable)
           [exec] 			+   access     final
           [exec] 			+   return     void
           [exec] 		+   method     clone()
           [exec] 			+   access     protected
           [exec] 			+   return     java.lang.Object
           [exec] 		+   method     equals(java.lang.Object)
           [exec] 			+   return     boolean
           [exec] 		+   method     fillInStackTrace()
           [exec] 			+   return     java.lang.Throwable
           [exec] 		+   method     finalize()
           [exec] 			+   access     protected
           [exec] 			+   return     void
           [exec] 		+   method     getCause()
           [exec] 			+   return     java.lang.Throwable
           [exec] 		+   method     getLocalizedMessage()
           [exec] 			+   return     java.lang.String
           [exec] 		+   method     getMessage()
           [exec] 			+   return     java.lang.String
           [exec] 		+   method     getStackTrace()
           [exec] 			+   return     java.lang.StackTraceElement[]
           [exec] 		+   method     getSuppressed()
           [exec] 			+   access     final
           [exec] 			+   return     java.lang.Throwable[]
           [exec] 		+   method     hashCode()
           [exec] 			+   return     int
           [exec] 		+   method     initCause(java.lang.Throwable)
           [exec] 			+   return     java.lang.Throwable
           [exec] 		+   method     printStackTrace()
           [exec] 			+   return     void
           [exec] 		+   method     printStackTrace(java.io.PrintStream)
           [exec] 			+   return     void
           [exec] 		+   method     printStackTrace(java.io.PrintWriter)
           [exec] 			+   return     void
           [exec] 		+   method     setStackTrace(java.lang.StackTraceElement[])
           [exec] 			+   return     void
           [exec] 		+   method     toString()
           [exec] 			+   return     java.lang.String
           [exec] [Baseline Report] Mode: diff (persisted)
           [exec] Semantic versioning is incorrect while checking /opt/dev/projects/github/liferay-portal/portal-kernel/portal-kernel.jar against /opt/dev/projects/github/liferay-portal/.gradle/caches/modules-2/files-2.1/com.liferay.portal/com.liferay.portal.kernel/9.18.0/471e51c2d8cc477362ba9dd7449b8c3974545660/com.liferay.portal.kernel-9.18.0.jar

@jbalsas
Copy link

jbalsas commented Dec 17, 2020

LocalFile.CPCommerceSettings#ViewInstanceCurrenciesAvailable - Poshi Report - Poshi Summary - Console Output

This answers #629 (comment), so I'd say let's get on with redirect: "manual" which we know is the way!

thisistheway

@jbalsas
Copy link

jbalsas commented Dec 17, 2020

Forwarded manually to brianchandotcom#97045

@liferay-continuous-integration
Copy link
Collaborator

@wincent
Copy link
Author

wincent commented Dec 17, 2020

LocalFile.CPCommerceSettings#ViewInstanceCurrenciesAvailable - Poshi Report - Poshi Summary - Console Output

This answers #629 (comment), so I'd say let's get on with redirect: "manual" which we know is the way!

And here too: #632

@liferay-continuous-integration
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants