Page MenuHomePhabricator

Don’t minify modern JavaScript in ResourceLoader
Closed, ResolvedPublic

Description

Since T253846: Serve modern JavaScript to modern clients, the Wikidata Bridge component serves modern (ca. ES6) JavaScript to modern clients (specifically, clients which support JavaScript modules). This worked out well in the initial change, but in an apparently unrelated change, we ran into the problem that browser tests started failing. Chromium showed the following error in the console:

Uncaught SyntaxError: Unexpected token '=>'

This turned out to be due to ResourceLoader’s minification of the file – we’re using ES6 syntax (in this case, an arrow function), but ResourceLoader’s JavaScriptMinifier library only supports ES5 syntax. (See also T75714: Allow ES6 syntax features in gadgets and other site-wide scripts.) And with the above change, it was emitting JavaScript like this:

/* ... */parseWikitextPagesList(e){var t=e.split("\n"),r=t.pop();if(""!==r)throw new Sr("Wikitext did not end in blank line: ".concat(r));return t.map(e
=>{if(!e.startsWith("*"))throw new Sr("Line does not look like a list item: ".concat(e));/* ... */

And the => being at the very beginning of the line is a syntax error. (Firefox reports it differently, by the way: “SyntaxError: missing ) after argument list”.) In debug mode, the JavaScript works as expected, indicating that it’s ResourceLoader’s minification that causes this problem.

Since our source code is already minified at build time (the results of which, for lack of a build step, we currently commit to Git), we want to completely disable ResourceLoader’s own processing of these resources, and ensure that it serves exactly the resources we build.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJun 2 2020, 4:38 PM
Pablo-WMDE added a comment.EditedJun 2 2020, 4:42 PM

There does not seem to be a way to disable further minification through RL's package configuration (somewhat makes sense as it does not really operate on the file level). Maybe we can leverage webpack's banner plugin in order to put the comment into the files in a rather transparent fashion.

Change 601801 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/Wikibase@master] bridge: tell ResourceLoader not to minify our resources

https://gerrit.wikimedia.org/r/601801

Change 601801 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] bridge: tell ResourceLoader not to minify our resources

https://gerrit.wikimedia.org/r/601801

Pablo-WMDE closed this task as Resolved.Jun 3 2020, 11:16 AM
Pablo-WMDE moved this task from Peer Review to Done on the Bridge Technical Improvements board.