Skip to content

Add DependencyExtractionWebpackPlugin for pages and read deps from .min.asset.php#1964

Open
KMchaudhary wants to merge 1 commit into
developfrom
fix/script-dependencies
Open

Add DependencyExtractionWebpackPlugin for pages and read deps from .min.asset.php#1964
KMchaudhary wants to merge 1 commit into
developfrom
fix/script-dependencies

Conversation

@KMchaudhary

Copy link
Copy Markdown
Collaborator

This pull request updates how JavaScript assets are registered and enqueued throughout the plugin to make use of dynamically generated .asset.php files. This ensures that each script's dependencies and version are accurately set based on the build process, improving reliability and maintainability when assets change.

Asset management improvements:

  • Updated all script registrations (both frontend and admin) to load dependencies and version information from corresponding .asset.php files generated during the build process, falling back to defaults if the files are missing. This affects scripts in class-assets.php, class-deactivation.php, class-elementor-widgets.php, class-pages.php, class-video-embed.php, class-video-preview.php, class-godam-media.php, class-everest-forms-field-godam-video.php, class-recorder-field.php, and class-init.php. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]

Dependency handling enhancements:

  • Where appropriate, dependencies from the asset files are merged with required runtime dependencies (such as 'godam-player-frontend-script' or form plugin requirements), ensuring scripts are loaded in the correct order. [1] [2]

Fallback and compatibility:

  • If an .asset.php file is missing, the code falls back to an empty dependencies array and uses the file modification time for versioning, maintaining backward compatibility and preventing asset loading failures. (applies throughout all affected files and changes above)

These changes make asset loading more robust, especially as the codebase grows and asset dependencies change over time.

Copilot AI review requested due to automatic review settings June 17, 2026 10:41

@rtBot rtBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code analysis identified issues

action-phpcs-code-review has identified potential problems in this pull request during automated scanning. We recommend reviewing the issues noted and that they are resolved.

phpcs scanning turned up:

⚠️ 1 warning


Powered by rtCamp's GitHub Actions Library


if ( file_exists( $player_analytics_path ) ) {
$player_analytics_asset_file = RTGODAM_PATH . 'assets/build/js/godam-player-analytics.min.asset.php';
$player_analytics_asset = file_exists( $player_analytics_asset_file ) ? include $player_analytics_asset_file : array(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Warning: File inclusion using variable ($player_analytics_asset_file). Probably needs manual inspection (WordPressVIPMinimum.Files.IncludingFile.UsingVariable).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors GoDAM’s asset registration/enqueue logic to consume dependency + version metadata from build-generated .asset.php files (including pages bundles), improving script dependency accuracy and cache busting as JS builds evolve.

Changes:

  • Adds @wordpress/dependency-extraction-webpack-plugin for the custom pages webpack build to emit .min.asset.php metadata.
  • Updates many PHP enqueue/register call sites (frontend + admin + integrations) to read dependencies/version from corresponding .min.asset.php files with fallbacks.
  • Merges extracted dependencies with required runtime handles in select integrations to preserve load order.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
webpack.config.js Adds dependency extraction for pages build to generate .min.asset.php files.
package.json Adds the dependency-extraction webpack plugin dependency.
package-lock.json Lockfile updates reflecting the new webpack plugin version and dependency tree.
inc/classes/wpforms/class-wpforms-integration.php Loads WPForms editor script deps/version from .min.asset.php.
inc/classes/shortcodes/class-godam-player.php Loads analytics script deps/version from .min.asset.php and merges required runtime deps.
inc/classes/ninja-forms/class-ninja-forms-integration.php Loads Ninja Forms submissions list script deps/version from .min.asset.php.
inc/classes/ninja-forms/class-ninja-forms-field-godam-recorder.php Loads Ninja Forms recorder script deps/version from .min.asset.php and merges required deps.
inc/classes/lifter-lms/class-lifter-lms.php Loads LifterLMS integration scripts deps/version from .min.asset.php.
inc/classes/gravity-forms/class-init.php Loads Gravity Forms editor script deps/version from .min.asset.php.
inc/classes/fluentforms/fields/class-recorder-field.php Loads FluentForms recorder script deps/version from .min.asset.php.
inc/classes/everest-forms/class-everest-forms-field-godam-video.php Loads Everest Forms recorder script deps/version from .min.asset.php.
inc/classes/elementor-controls/class-godam-media.php Loads Elementor editor script deps/version from .min.asset.php.
inc/classes/class-video-preview.php Loads video preview script deps/version from .min.asset.php.
inc/classes/class-video-embed.php Loads video embed script deps/version from .min.asset.php.
inc/classes/class-pages.php Loads admin pages bundles deps/version from .min.asset.php.
inc/classes/class-elementor-widgets.php Loads Elementor frontend script deps/version from .min.asset.php and merges required deps.
inc/classes/class-deactivation.php Loads deactivation feedback script deps/version from .min.asset.php.
inc/classes/class-assets.php Loads core frontend/admin (and http-auth detector) deps/version from .min.asset.php.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json
Comment on lines 39 to 42
"@uppy/screen-capture": "5.0.0",
"@uppy/webcam": "5.0.0",
"@wordpress/dependency-extraction-webpack-plugin": "6.48.1",
"analytics": "^0.8.18",
Comment on lines 372 to +376
wp_enqueue_script(
'nf-godam-recorder-upload',
RTGODAM_URL . 'assets/build/js/ninja-forms.min.js',
array( 'backbone', 'jquery', 'wp-i18n' ),
filemtime( RTGODAM_PATH . 'assets/build/js/ninja-forms.min.js' ),
array_merge( $ninja_forms_asset['dependencies'], array( 'backbone' ) ),
$ninja_forms_asset['version'],
Comment on lines 367 to +371
wp_register_script(
'godam-http-auth-detector',
RTGODAM_URL . 'assets/build/js/http-auth-detector.min.js',
array( 'jquery' ),
filemtime( RTGODAM_PATH . 'assets/build/js/http-auth-detector.min.js' ),
$http_auth_asset['dependencies'],
$http_auth_asset['version'],
Comment on lines 236 to 241
wp_enqueue_script(
'gf-godam-recorder-editor-script',
RTGODAM_URL . 'assets/build/js/gf-godam-recorder-editor.min.js',
array( 'jquery' ),
filemtime( RTGODAM_PATH . 'assets/build/js/gf-godam-recorder-editor.min.js' ),
$gf_editor_asset['dependencies'],
$gf_editor_asset['version'],
true
Comment on lines +148 to +152
$player_analytics_asset_file = RTGODAM_PATH . 'assets/build/js/godam-player-analytics.min.asset.php';
$player_analytics_asset = file_exists( $player_analytics_asset_file ) ? include $player_analytics_asset_file : array(
'dependencies' => array(),
'version' => filemtime( $player_analytics_path ),
);
@subodhr258

Copy link
Copy Markdown
Collaborator

Code Review

Overview

Replaces hardcoded script dependency/version arguments in wp_register_script/wp_enqueue_script with values read from build-generated *.min.asset.php files, falling back to array() deps + filemtime() when the asset file is absent. It also wires DependencyExtractionWebpackPlugin (DEWP) into the pages webpack config and adds the package to package.json.

Worth noting: the assets/build/js/* bundles already emit *.min.asset.php files today, because the shared JS config extends @wordpress/scripts' default config (which already bundles DEWP). The genuinely new build output is for assets/build/pages/*, which the pages config did not run DEWP on before. So the webpack change correctly closes that gap. 👍

The version-from-content-hash change (vs filemtime()) is a real improvement: content-based cache busting is stable across deploys/servers, whereas filemtime() varies per server and over-invalidates. The array_merge(...) calls also correctly preserve cross-script handles DEWP can't infer (godam-player-frontend-script, backbone, rtgodam-script).

Issues

1. pages config: DEWP + manual externals may emit empty dependency arrays — please verify before merge (high impact).
The pages config in webpack.config.js manually externalizes @wordpress/element|i18n|components|api-fetch (and react/react-dom). DEWP also performs externalization, and it only writes a handle into the .asset.php for modules it externalizes — modules already claimed by a manual externals entry can be skipped. If that happens here, the generated assets/build/pages/*.min.asset.php could contain no wp-element/wp-components/etc.

Because the PHP fallbacks for the page scripts are mostly array() (only video-editor keeps ['wp-element','wp-i18n']), a stripped asset file would silently drop wp-element/wp-components from the admin pages (dashboard, analytics, settings/godam, tools, help, whats-new, media-library) → React/components unavailable → blank/broken screens. Previously these were guaranteed via the hardcoded deps.

Please run the production build and inspect the generated assets/build/pages/*.min.asset.php to confirm each page's deps match (or exceed) the prior hardcoded lists. If they don't, remove the now-redundant manual @wordpress/* externals from the pages config and let DEWP own externalization (then re-check react/react-dom handling).

2. jquery dependency dropped for scripts that use the jQuery global without importing it (medium).
DEWP only emits jquery when jQuery is imported; these scripts use the $/jQuery global, so the generated asset files omit it. Verified against the already-built js/*.min.asset.php plus source grep:

Handle Source uses jQuery Old deps New effective deps
godam-http-auth-detector yes (http-auth-detector.js) ['jquery'] []
nf-godam-recorder-upload yes (ninja-forms/index.js) ['backbone','jquery','wp-i18n'] ['wp-i18n','backbone']
gf-godam-recorder-editor-script yes (gravity-form/gf-godam-recorder-editor.js) ['jquery'] []

Dropping the explicit jquery removes WordPress's guarantee that jQuery is registered and enqueued before these footer scripts. In practice jQuery is usually present (admin, or loaded by the forms plugins), so it may not break — but it's a real correctness regression in the dependency declaration. Suggest keeping it via the same merge pattern already used elsewhere, e.g. array_merge( $asset['dependencies'], array( 'jquery' ) ) for those three handles.

For the record, the other jquery removals look safeeverestforms, fluentforms, elementor (frontend/editor), lifterlms, and ninja-forms-submissions-list sources have no jQuery usage, and godam-player-analytics losing wp-i18n is fine (its source uses no i18n).

3. @wordpress/dependency-extraction-webpack-plugin should be a devDependency (minor).
It's added to dependencies, but every other webpack tool here (@wordpress/scripts, css-minimizer-webpack-plugin, webpack-remove-empty-scripts) lives in devDependencies. This misplacement is also what produced the large package-lock.json churn — dozens of transitive packages lost "dev": true because they're now reachable from a production dependency. Moving it to devDependencies reverts that lockfile noise and keeps the production tree clean.

Maintainability (non-blocking)

  • ~25× copy-pasted boilerplate across 15 files. A small helper, e.g. rtgodam_get_asset_meta( $relative_js_path, $default_deps = array() ) returning ['dependencies' => ..., 'version' => ...], would cut most of the +354 lines and centralize the file_exists/fallback logic. It would also unify the two styles currently present (the verbose if ( file_exists ) block vs. the compact ternary in class-godam-player.php).
  • Inconsistent fallback deps: video-editor keeps ['wp-element','wp-i18n'] as its fallback while every other page uses []. Given issue Update readme #1, a meaningful fallback for all pages is arguably the safer choice — pick one approach consistently.

Summary

Solid, well-scoped direction and the content-hash versioning is a genuine win. Before merging, please (1) build and verify the generated pages/*.min.asset.php actually carry the WP deps, and (2) restore jquery for the three handles whose source still uses the jQuery global. Moving the new package to devDependencies will also clean up the lockfile diff.

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.

4 participants