- Add a getCodexFiles() method that parses the manifest and transforms
it to a more useful format based on actual file names rather than
manifest keys
- Cache the result as a static class property, so that it's reused
between all CodexModule instances
- Use the resulting data structure to simplify the rest of the code
- This also has the side effect of correctly throwing an error when a
nonexistent file is requested (this wasn't the case before). Add a
test case for this.
- Add a test for this new method in CodexModuleTest.php
Change-Id: Id527cef0e19fec7b54af3bf65a1de66f50d5fff0
Instead of using an awkward current( array_filter( ... ) ) construct to
find back the file name of each component, keep track of the component
name -> file name mapping in an associative array as we find files in
the manifest before the dependency resolution stage, and then reuse that
map when we build the exports object later.
Change-Id: Ie16a27ae039c758e508c11b78d088006c9d8083d
CodexModule throws an InvalidArgumentException if one of the elements
of the codexComponents array refers to a private chunk rather than a
public entry point file. Add a unit test asserting this behavior.
Also add an `isset()` to the check in CodexModule so that it doesn't
cause a PHP notice about a missing array index.
Bug: T353191
Change-Id: I3e31511aeeb42d825c308f047894f5eba28b0f27
CodexModule always returns different style files for LTR vs RTL (e.g.
CdxButton.css vs CdxButton-rtl.css), so we don't want CSSJanus to flip
them. That results in double-flipping, breaking RTL support.
Change-Id: I13c78b3d1c6e53b025887a6ab2d7baf42c053310
As of Codex 1.3.0, CJS files emitted from the library build process
will have a .cjs extension instead of a .js extension (per Vite's
library mode behavior when working with ESM codebases).
This change updates the CodexModule code to be file-extension agnostic;
.mjs, .cjs. and .js file extensions are all considered valid now.
Change-Id: Iccb53b4c01daf90d23476f24e50066adb41685dd
If a generated chunk is listed in the codexComponents array,
an exception will be thrown informing the developer that the
item is not an export of Codex and cannot be required.
Text fixtures and expected values were updated to match
recent changes to the manifest that made composables
explict entries.
Bug: T353191
Change-Id: Ie3e35501993b1ad5d29ebecbcc8203e7f4ea8c81
This patch handles the scenario of an empty codexComponents array in the
module definition file with a descriptive error message that allows
developers to recover from the situation.
The scenario of codexComponents being omitted entirely is not handled
since there is a way to use this module only for its themeStyles feature
that does not require definition of codexComponents.
Bug: T353187
Change-Id: I65ad8dc338f5e570e93d7918b053b953755c12d5
This patch adds a runtime check to identify when a Codex component is imported without first being defined in the `codexComponents` array of the module definition file.
The currently shown warnings or errors are not consistent between components and are confusing since they occur at different points in the code paths of each component.
The proposed change throws a custom error message mentioning the component missing from the module definition. The location of the component's `require` call can also be inferred from the stack trace.
Bug: T353187
Change-Id: Iee8e3b0769c10407ce08de35ba38e8e5a804d6c9
For CodexModules that are not style-only and use the
codexComponents option, Vue is required and failing to include it
as a dependency currently breaks things. This patch adds Vue as
a dependency of such a CodexModule to prevent errors.
Bug: T352724
Change-Id: I9132f56eebfd46a1f287cfb1febd2670975a0985
This requires the path to the Codex modules directory
to be configurable, so we can use static manifest and
component files in tests. This is achieved by changing
the constant storing the Codex modules dir from private
to protected so it can be overridden when creating a
test module.
Bug: T350054
Change-Id: Icd3c6c5d2a82f5a5fb1c38b52e54893034e7375c
* Introduces support for tree-shaking in CodexModule. A limited
subset of the library can be returned if the "codexComponents"
option is provided.
* Additional options for script-only and style-only subsets have
also been added: "codexScriptOnly" and "codexStyleOnly",
respectively.
* Reorganizes the PHP code for more clarity.
Co-authored-by: Roan Kattouw <catrope@wikimedia.org>
Co-authored-by: Anne Tomasevich <atomasevich@wikimedia.org>
Bug: T350054
Change-Id: Iadba806167abaa4996fd05d4ede909d737251901
This patch removes styles from the `@wikimedia/codex` and
`@wikimedia/codex-search` modules, and moves them into new,
separate modules. This will enable use of CSS-only Codex
components within MediaWiki.
Additionally, this patch adds a check for theme styles in the
CodexModules class to prevent it from breaking if they're
not provided.
Bug: T330466
Change-Id: I259a706641fcd51787d7492e7ada11db78277659
Add a "SkinCodexThemes" key to skin.json, that works just like
"SkinOOUIThemes". Based on the value the skin sets,
ResourceLoader\CodexModule loads the correct Codex theme for the skin.
The default theme is wikimedia-ui, meant for skins with a 16px base font
size. Skins with a 14px base font size (like Vector) should override
this to use wikimedia-ui-legacy.
Bug: T324367
Change-Id: I7435413928f2b8c5d43c34d9e2e7df470d710c93
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader itself.
Move the tests by analogy.
I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".
I did not address DependencyStore which continues to have a non-standard
location and namespace.
Revert of a241d83e0a.
Bug: T308718
Change-Id: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
This reverts commit e08ea8ccb9.
Reason for revert: Breaks Phan in extensions, and as far as I’m aware,
this change isn’t urgently needed for anything, so the simplest fix is
to revert it again for now. After PHP 7.4 it should be safer to try this
again (we hopefully won’t need the two “hack” classes by then).
Bug: T308443
Change-Id: Iff3318cbf97a67f821f78e60da62a583f63e389e
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader and
ResourceLoaderContext.
Move the tests by analogy.
I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".
I did not address DependencyStore which continues to have a non-standard
location and namespace.
Change-Id: I92998ae6a82e0b935c13e02a183e7c324fa410a3
2022-05-16 14:41:27 +10:00
Renamed from includes/resourceloader/ResourceLoaderCodexModule.php (Browse further)