-
Notifications
You must be signed in to change notification settings - Fork 8
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
Typing of ResourceLoader modules other than mediawiki.base #35
Comments
You will find an initial implementation in this branch: https://github.com/Derugon/types-mediawiki/tree/split (based on the #36 MR branch, diff comparison here). (note that none of the missing modules have been added to this branch, so some modules are empty (for now): they have only been added to validate other module dependencies) Alternative B is used here: one folder per module. What I didn't thought about is that unlike alternatives A and C, this alternative allows The organisation of files within a module is similar to the one currently used (roughly one file per namespace). |
After a few failed and successful attempts at implementing the previously mentioned alternatives: Using Another issue I didn't consider is that all global declarations are always visible, if the files they come from have been scanned by the TS compiler. The recommended approach in the README is to use "compilerOptions": {
"typeRoots": ["./node_modules/@types", "./node_modules/types-mediawiki"]
} Then, one may only enable a few MediaWiki modules by specifying "compilerOptions": {
"typeRoots": ["./node_modules/@types", "./node_modules/types-mediawiki"],
"types": ["mediawiki.base", "mediawiki.ForeignApi", "mediawiki.language"]
} This approach also requires having one folder per sub-module, since declaring a module in a single file (e.g.
Below is an implementation plan of this approach. at the very least I'm going to wait for #36 to be closed (whether merged or not) before writing any PR as there are way too many subtle changes to keep track of. As presented in the previous comment, a test implementation is available at https://github.com/Derugon/types-mediawiki/tree/split, but for easier traceability and migration process it may be better to implement this proposal in multiple steps, so we can more easily discuss each part. Implementation Proposal
For example, the // ResourceLoader module dependencies
// including "mediawiki.base" if there is no other mw dependencies
import "../jquery.client";
import "../mediawiki.base";
// local declaration files
import "./RegExp.d.ts";
import "./util.d.ts";
// ResourceLoader module exports
export default mw.util; |
Now that the main branch is up to date with 1.42, I've reopened PR #40, for the 1st and 2nd steps of the above proposal. If we are ok with it, after it is merged, I'll open another PR to do steps 3, 4, and 5 at once (move stuff in submodules, while still keeping deprecated exports). |
Any thoughts on this? ^^' As this is a particularly significant change, I don't want to start implementing stuff before we have a consensus on the base design since it will take quite some time to migrate declarations. |
Motivation
The MediaWiki API contains various modules managed by the ResourceLoader (see Resources.php). Some ResourceLoader modules include code whose associated types are in several
.d.ts
files. For example, type declarations of scripts frommediawiki.base
can be found in:global.d.ts
,html.d.ts
,index.d.ts
,log.d.ts
,Some
d.ts
files also contain types for code loaded by different modules. For example,language.d.ts
contains type declarations for:mediawiki.language
,mediawiki.language.names
, andmediawiki.language.specialCharacters
.In general, most of MediaWiki and jQuery core modules managed by the ResourceLoader are not enabled directly when a page is loaded. By using
import "types-mediawiki"
in another package, all available type declarations are imported.In some cases, I would like to import only the modules I know are active on a page (or modules I'm going to activate dynamically, e.g. with
mw.loader.using(...)
). To do this, I could import the corresponding files (import "types-mediawiki/mw/Api"
), but there are a few issues with this:.d.ts
file names don't always match ResourceLoader module names.Proposal part 1
I suggest to change the declaration file hierarchy so each ResourceLoader module can be imported individually, e.g.:
Below are a 3 proposed implementations for this.
Alternative A
Synchronize files with MediaWiki core: create one
.d.ts
file per.js
source code file, then export one module per ResourceLoader module, maybe directly inindex.d.ts
, e.g.:(note: to help with synchronization, this list can be generated automatically from the source code)
Alternative B
Create one TS module per ResourceLoader module: gather all
.d.ts
files of a single ResourceLoader module in a directory, one directory per ResourceLoader module.Alternative C
Create one
.d.ts
file per ResourceLoader module, containing type declarations for all scripts imported by that ResourceLoader module.Proposal part 2
Currently, when using
import "types-mediawiki"
, all available modules are imported.Assuming it is possible to choose which modules to import (if desired), the base module (when using
import "types-mediawiki";
) may only export a subset of available modules, e.g.:The text was updated successfully, but these errors were encountered: