Skip to content

feat: Add support for Script Modules#60

Merged
Chrico merged 2 commits intomasterfrom
feature/script-module-support
Sep 3, 2025
Merged

feat: Add support for Script Modules#60
Chrico merged 2 commits intomasterfrom
feature/script-module-support

Conversation

@hmouhtar
Copy link
Contributor

@hmouhtar hmouhtar commented Jun 14, 2025

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)

Summary

This PR adds support for Script Modules introduced in WordPress 6.5.

Relevant documentation and discussions, in chronological order:

Changes

Script Module Support

  • New ScriptModule class
  • New ScriptModuleHandler with compatibility checks
  • Factory support for creating script modules via AssetFactory
  • Dependency extraction plugin support for dependency resolution

Refactoring

  • Split Asset interface into core functionality only
  • New DataAwareAsset interface for data-related methods (data(), withCondition())
  • New FilterAwareAsset interface for filter/attributes methods (filters(), withFilters(), attributes(), withAttributes())
  • New traits DataAwareTrait, FilterAwareTrait and DependencyExtractionTrait for DRY implementation
  • Updated class hierarchy:
    • Script implements Asset, DataAwareAsset, FilterAwareAsset
    • Style implements Asset, DataAwareAsset, FilterAwareAsset
    • ScriptModule implements only core Asset interface

Limitations

Due to WordPress core limitations, ScriptModule does NOT support:

  • Localization
  • Inline scripts
  • Translations
  • Output filters (There's no equivalent to the script_loader_tag filter for Script Modules)

Next Steps

  • Add support for the script_module_data_{$module_id} filter for data passing.
  • Add Loader support for Script Modules.

@hmouhtar hmouhtar force-pushed the feature/script-module-support branch from e9a1217 to 72f7574 Compare June 14, 2025 23:42
@codecov
Copy link

codecov bot commented Jun 14, 2025

Codecov Report

❌ Patch coverage is 87.25490% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.55%. Comparing base (e2669fa) to head (a62ba2f).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
src/Handler/ScriptModuleHandler.php 70.83% 7 Missing ⚠️
src/DependencyExtractionTrait.php 94.73% 2 Missing ⚠️
src/ScriptModule.php 75.00% 2 Missing ⚠️
src/Handler/OutputFilterAwareAssetHandlerTrait.php 50.00% 1 Missing ⚠️
src/OutputFilter/AttributesOutputFilter.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #60      +/-   ##
============================================
- Coverage     88.27%   87.55%   -0.72%     
- Complexity      282      293      +11     
============================================
  Files            21       26       +5     
  Lines           827      860      +33     
============================================
+ Hits            730      753      +23     
- Misses           97      107      +10     
Flag Coverage Δ
unittests 87.55% <87.25%> (-0.72%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hmouhtar hmouhtar force-pushed the feature/script-module-support branch from 72f7574 to 72b886f Compare June 14, 2025 23:52
@Chrico Chrico self-requested a review June 16, 2025 07:42
@hmouhtar hmouhtar force-pushed the feature/script-module-support branch 2 times, most recently from c9a20ff to 87051a3 Compare June 16, 2025 20:43
@hmouhtar hmouhtar force-pushed the feature/script-module-support branch from 87051a3 to a62ba2f Compare June 16, 2025 20:50
@hmouhtar hmouhtar marked this pull request as ready for review June 16, 2025 20:55
@Chrico Chrico merged commit b328f2f into master Sep 3, 2025
9 of 12 checks passed
@Chrico Chrico deleted the feature/script-module-support branch September 3, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants