Page MenuHomePhabricator

Don’t minify modern JavaScript in ResourceLoader
Closed, ResolvedPublic


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: Update JavaScript syntax checker for gadgets and user-scripts for ES6 and later.) 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
=>{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

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

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