Commit graph

20 commits

Author SHA1 Message Date
Roan Kattouw
06299ce04a CodexModule: Transform manifest to a more useful format, and cache
- 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
2024-02-08 21:36:05 +00:00
Roan Kattouw
44168e3051 CodexModule: Track component file names explicitly
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
2024-02-08 21:35:59 +00:00
James D. Forrester
21d8d9863b Drop old ResourceLoader class aliases, deprecated since 1.39
Depends-On: Iff15a2e13a3507ef1ab5cfa504ca1a1c8d2b2a60
Depends-On: Icf8331e35acf6fe51a8303ee639921b9e4f3e6bb
Depends-On: I5a5af003026db69b279ddde0b0dedbfcfe7d70fd
Change-Id: I5929a2f760c8d21c1cb2542a19220a91ac7240e4
2024-01-31 18:24:37 -05:00
Roan Kattouw
9024a8ee02 CodexModuleTest: Add test for exception when requesting chunks
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
2024-01-25 14:31:33 -08:00
Roan Kattouw
a1740feb80 CodexModule: Prevent CSSJanus from flipping styles
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
2024-01-24 14:33:46 -08:00
Eric Gardner
2fa8bbbeff CodexModule: Don't hard-code .js file extensions
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
2024-01-23 12:27:42 -08:00
jenkins-bot
c3833b6681 Merge "CodexModule: Throw exception for non-entry points" 2024-01-17 18:56:18 +00:00
Anne Tomasevich
c8117c78ca CodexModule: Throw exception for non-entry points
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
2024-01-17 12:29:47 -05:00
Ty Hopp
eeb99dd5e3 CodexModule: Handle empty codex component definitions
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
2024-01-17 11:14:37 +08:00
Ty Hopp
e2ce8c751e CodexModule: Throw helpful error if component not listed in module definition
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
2023-12-20 12:31:00 +08:00
Anne Tomasevich
59b2ed4b8f CodexModule: Add Vue as a dependency if not already listed
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
2023-12-06 17:14:44 -05:00
Anne Tomasevich
4baf4dd8be CodexModule: Add unit test for code splitting
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
2023-12-01 00:52:23 +00:00
Eric Gardner
39f78d1ee7 Basic tree-shaking in CodexModule
* 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
2023-12-01 00:52:17 +00:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
Anne Tomasevich
3c2061497e Create separate ResourceLoader modules for Codex styles
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
2023-04-05 15:29:39 -04:00
Roan Kattouw
f326fc7f0d skins: Allow skins to specify their Codex theme
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
2023-02-06 10:27:43 -08:00
Timo Tijhof
85892edce5 resourceloader: Minor doc changes following PSR-4 namepace change
Follows Id08a220e1d60 (after I92998ae6a82e).

Change-Id: I33d20201bfee4595baa39c01eaf8b7de6034a8ed
2022-05-29 16:41:19 +00:00
Tim Starling
3e2653f83b ResourceLoader namespace (attempt 2)
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
2022-05-24 15:41:46 +00:00
Lucas Werkmeister (WMDE)
a241d83e0a Revert "ResourceLoader namespace"
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
2022-05-16 14:43:33 +00:00
Tim Starling
e08ea8ccb9 ResourceLoader namespace
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)