Skip to content
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

Implement JS Build (ES6) and JS Lint #261

Merged
merged 19 commits into from
Apr 10, 2023

Conversation

puntope
Copy link
Contributor

@puntope puntope commented Mar 23, 2023

Changes proposed in this Pull Request:

Closes part of #227 .

This PR implements the next major changes.

Checks:

  • Does your code follow the WordPress coding standards?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Screenshots:

Detailed test instructions:

  1. Run npm i
  2. Run npm run start
  3. Check the extension loads the ga-integration.js file ga-admin-settings.js file and they work correctly without errors.
  4. Go to one of the files in assets/js/src and add a random console.log
  5. See how the re-build process runs
  6. Refresh the page and see the console log running
  7. Check the es-lint workflow is working fine
  8. Try to make some bad changes like undefined constants or bad spacing and see the js linter working.
  9. run npm run archive
  10. See the zip file doesn't contain anymore asset/js/src but yes asset/js/build
  11. Verify the config files

Additional details:

⚠️ JS Unit Tests support are not included in this PR
⚠️ A solution for dealing with duplicate actions with blocks will be done in the future PR
⚠️ To discuss if we want to add TypeScript on this project. Seems like a good moment and extension to do so.

Changelog entry

Dev - Implement JS Build (ES6) and JS Lint

@puntope puntope self-assigned this Mar 23, 2023
@puntope puntope requested a review from a team March 23, 2023 14:36
@puntope puntope marked this pull request as ready for review March 23, 2023 14:37
Copy link
Member

@eason9487 eason9487 left a comment

Choose a reason for hiding this comment

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

Thanks for the work.

Unfortunately, I was hardly able to complete the test.

Found some critical issues:

  • The assets/js/src/ga-integration.js script is not loaded to the page. And even if after fixing the loading issue, the "google_analytics_integration_product_data is not defined" errors will occur.
  • All the event tracking in assets/js/src/actions.js are not fired since the mismatched hook names. Further, even if fix the hook names, "Cannot read properties of undefined (reading 'price')" errors will occur when calling the trackAddToCart function.
  • The event tracking in WC Blocks has changed quite a lot, for example, the number of events has increased from 4 to 16. Does it need to sync the subsequent changes?

Other issues that are also worth noting:

  • Some project configurations could be omitted or enhanced.
  • Two scripts' $deps array is not set properly.

assets/js/src/ga-integration.js Outdated Show resolved Hide resolved
.eslintrc.js Outdated Show resolved Hide resolved
@@ -377,7 +377,7 @@ public function load_admin_assets() {
return;
}

wp_enqueue_script( 'wc-google-analytics-admin-enhanced-settings', plugins_url( '/assets/js/admin-ga-settings.js', dirname( __FILE__ ) ), array(), WC_GOOGLE_ANALYTICS_INTEGRATION_VERSION, true );
wp_enqueue_script( 'wc-google-analytics-admin-enhanced-settings', plugins_url( '/assets/js/build/admin-ga-settings.js', dirname( __FILE__ ) ), array(), WC_GOOGLE_ANALYTICS_INTEGRATION_VERSION, true );
Copy link
Member

Choose a reason for hiding this comment

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

There is an original issue but maybe consider fixing it by the way.

The admin-ga-settings.js script depends on jQuery so it should have 'jquery' handle in the $deps array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be resolved here f3e783b

Copy link
Member

Choose a reason for hiding this comment

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

Plugin::get_instance()->get_js_asset_dependencies( 'admin-ga-settings' ) returns an empty array. The 'jquery' handle is still missing.

includes/class-wc-google-gtag-js.php Outdated Show resolved Hide resolved
.eslintrc.js Outdated Show resolved Hide resolved
assets/js/src/constants.js Outdated Show resolved Hide resolved
assets/js/src/actions.js Outdated Show resolved Hide resolved
assets/js/src/actions.js Outdated Show resolved Hide resolved
assets/js/src/actions.js Outdated Show resolved Hide resolved
assets/js/src/utils.js Outdated Show resolved Hide resolved
@puntope
Copy link
Contributor Author

puntope commented Apr 3, 2023

Howdy @eason9487 first of all, thanks for the amazing review as always.

I patched all of your findings. Still need to test deeper to see everything is working find. But I think at least we can have another round to check most of the issues :)

The event tracking in WC Blocks has changed quite a lot, for example, the number of events has increased from 4 to 16. Does it need to sync the subsequent changes?

Oh, I see. Maybe we can keep this one like it is (with the reduced amount) without merge and make those in a future PR if thats ok.

package.json Outdated Show resolved Hide resolved
assets/js/src/actions.js Outdated Show resolved Hide resolved
Copy link
Member

@eason9487 eason9487 left a comment

Choose a reason for hiding this comment

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

The event tracking in WC Blocks has changed quite a lot, for example, the number of events has increased from 4 to 16. Does it need to sync the subsequent changes?

Oh, I see. Maybe we can keep this one like it is (with the reduced amount) without merge and make those in a future PR if thats ok.

Keeping it as it's would be OK but I guess it would need a feature flag to skip the wp_enqueue_script call by default for the actions.js file, or even remove the whole wp_enqueue_script call for now. So that it won't lead to duplicate event tracking with WC Blocks.

package.json Outdated Show resolved Hide resolved
@@ -377,7 +377,7 @@ public function load_admin_assets() {
return;
}

wp_enqueue_script( 'wc-google-analytics-admin-enhanced-settings', plugins_url( '/assets/js/admin-ga-settings.js', dirname( __FILE__ ) ), array(), WC_GOOGLE_ANALYTICS_INTEGRATION_VERSION, true );
wp_enqueue_script( 'wc-google-analytics-admin-enhanced-settings', plugins_url( '/assets/js/build/admin-ga-settings.js', dirname( __FILE__ ) ), array(), WC_GOOGLE_ANALYTICS_INTEGRATION_VERSION, true );
Copy link
Member

Choose a reason for hiding this comment

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

Plugin::get_instance()->get_js_asset_dependencies( 'admin-ga-settings' ) returns an empty array. The 'jquery' handle is still missing.

includes/class-wc-google-gtag-js.php Outdated Show resolved Hide resolved
woocommerce-google-analytics-integration.php Outdated Show resolved Hide resolved
woocommerce-google-analytics-integration.php Outdated Show resolved Hide resolved
woocommerce-google-analytics-integration.php Show resolved Hide resolved
@puntope puntope requested a review from eason9487 April 6, 2023 12:47
@puntope puntope changed the base branch from trunk to feature/analytics-wc-blocks April 6, 2023 12:47
@puntope
Copy link
Contributor Author

puntope commented Apr 6, 2023

The event tracking in WC Blocks has changed quite a lot, for example, the number of events has increased from 4 to 16. Does it need to sync the subsequent changes?

Oh, I see. Maybe we can keep this one like it is (with the reduced amount) without merge and make those in a future PR if thats ok.

Keeping it as it's would be OK but I guess it would need a feature flag to skip the wp_enqueue_script call by default for the actions.js file, or even remove the whole wp_enqueue_script call for now. So that it won't lead to duplicate event tracking with WC Blocks.

I created the feature feature/analytics-wc-blocks so we can safely merge everything there instead of trunk.

@puntope
Copy link
Contributor Author

puntope commented Apr 6, 2023

Howdy @eason, I added new patches and some question in regards your comment here #261 (comment)

Copy link
Member

@eason9487 eason9487 left a comment

Choose a reason for hiding this comment

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

Thanks for the further adjustment. LGTM.

@puntope puntope merged commit 025214b into feature/analytics-wc-blocks Apr 10, 2023
@puntope puntope deleted the feature/ga-actions branch April 10, 2023 10:58
@eason9487 eason9487 added the changelog: dev Developer-facing only change. label May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: dev Developer-facing only change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants