Page MenuHomePhabricator

Add tests to check that all modules using require have required module files listed in `packageFiles`
Open, MediumPublic

Description

Background

ResourceLoader modules need to have all files that are bundled to the client listed in the packageFiles property in skin.json or extension.json. We want to add a way to automatically check that all required files are properly included to help prevent issues like https://phabricator.wikimedia.org/T301810#7712180.

See related comment/task T283388#7712291.

Developer notes

We could create a test that runs a regular expression on all files for require statements, and checks the appropriate modules in skin.json.

Event Timeline

Jdlrobson renamed this task from Add jest tests for module `packageFiles` to Add tests to check that all modules using require have required module files listed in `packageFiles` .Feb 17 2022, 5:39 PM
Jdlrobson subscribed.

Don't think this is one is Vector specific so made some adjustments.

Krinkle subscribed.

I imagine this would take the shape of a PHPUnit structure test, much like the similar linters and run-time validators we have there already.

As mentioned in T283388, I would also like to go a step further and actually provide a standalone CLI command (like composer make-resource-def or some such) that generates these automatically, which is the command you'd run if something was missing, without having to figure that out manually.

This would be akin to what we already do with autoload.php in core (and generateLocalAutoload.php).

In case it's interesting, I built something like this (as in hacked together quickly), when exploring migrating Popups to packageFiles but it was done as a build step in Node.js: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Popups/+/812973/3/build.js

A newly hired developer ran into this issue today. Unfamiliar with ResourceLoader, they understandably used a require statement and expected it to just work, so we had to explain to them how ResourceLoader works so it would be good to make this more obvious / automated.