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

Masterbar: Copy module code to package #37342

Open
wants to merge 41 commits into
base: trunk
Choose a base branch
from

Conversation

fgiannar
Copy link
Contributor

@fgiannar fgiannar commented May 10, 2024

This PR copies the Masterbar module codebase to the masterbar package. In the process:

  • Methods that only live in the Jetpack plugin have been replaced by corresponding methods available in packages. For example: Jetpack::is_module_active has been replaced by ( new Modules() )->is_module_active
  • The JETPACK__VERSION used for cache busting when enqueueing scripts and styles is now replaced by Main::PACKAGE_VERSION
  • Translations text domain is updated to jetpack-masterbar from jetpack
  • Updated the build process so that rtl files are now generated with a custom config (we used to refer to them as weird RTL entries because -rtl was appended instead of .rtl) and the corresponding code references as well.
  • Updated all scripts and css files to be loaded from the dist folder
  • Started enqueuing all package scripts and styles via the Assets package
  • Fixed close to 270 phan issues
  • Added more unit tests, related mostly to enqueuing assets

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

pfwV0U-3U-p2

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  • Code Review since the package is not used anywhere yet.
  • Migrated unit tests should all pass
  • Try running jetpack build packages/masterbar with/without --production and inspect the generated assets in the dist folder

@fgiannar fgiannar self-assigned this May 10, 2024
@github-actions github-actions bot added [Feature] Masterbar WordPress.com Toolbar and Dashboard customizations [Package] Masterbar [Tests] Includes Tests labels May 10, 2024
Copy link
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.

Copy link
Contributor

github-actions bot commented May 13, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the update/copy-masterbar-code-to-pkg branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack update/copy-masterbar-code-to-pkg
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/copy-masterbar-code-to-pkg
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@fgiannar fgiannar added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] In Progress labels May 13, 2024
@fgiannar
Copy link
Contributor Author

@Automattic/jetpack-vulcan How do we usually handle the ESLint failing tests related to missing JSDoc elements? Should I manually fix those or add an ignore rule?

Comment on lines +74 to +78
DependencyExtractionPlugin: false,
I18nLoaderPlugin: false,
I18nCheckPlugin: false,
MiniCssWithRtlPlugin: false,
WebpackRtlPlugin: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

This webpack config should mostly work here as things are, because none of the JS files use i18n or modules and you're adding back the MiniCssWithRtlPlugin and WebpackRtlPlugin plugins where it really matters below. The main thing you'll be missing is that there won't be any .asset.php files for the Assets package to get version hashes from.

To do it more right, you'd want to update the JS files to import their corresponding CSS files, and any other modules they might need (looks like none need any at the moment). That should let you drop the separate masterBarCssFiles and enable all these plugins for the masterBarJsFiles block.

One possible drawback to doing that is that a JS file has to exist to import the CSS file, even if the JS file is otherwise empty. The Assets package doesn't (currently) have support for CSS-only assets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I gave this a shot with 0fc9c9e

@fgiannar
Copy link
Contributor Author

Add eslint-disable rules related to JSDoc requires

@Automattic/jetpack-vulcan How do we usually handle the ESLint failing tests related to missing JSDoc elements? Should I manually fix those or add an ignore rule?

FYI I added eslint-disable rules via cae099f and 513f7a5

@fgiannar fgiannar requested a review from a team May 15, 2024 13:21
@coder-karen
Copy link
Contributor

I've not looked through the full list of phan flagged issues, but certainly some look like false positives, eg Error: UndefError PhanUndeclaredClassConstant Reference to constant MANAGE_PLUGINS from undeclared class \WPCOM_Features (as it's a check to see if it exists). If nothing else stands out as being fixable, if you add a baseline.php file then run jetpack phan --update-baseline packages/masterbar it will create the phan baseline file and add all the relevant suppressions.

@fgiannar
Copy link
Contributor Author

Added a phan baseline via 30e2dd2 which includes all the remaining phan issues I plan to fix gradually in follow-up PRs while switching the usage to the package.

Copy link
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

Left some comments about Phan issues currently being ignored that should be easy to fix or should be suppressed.

fgiannar and others added 4 commits May 21, 2024 19:20
…nu.php

Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
…nu.php

Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
…ttic/jetpack into update/copy-masterbar-code-to-pkg
);
} else {
// Non-Calypso.
window.location = 'https://wordpress.com' + destination;

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
wp_enqueue_style( 'noticons', $this->wpcom_static_url( '/i/noticons/noticons.css' ), array(), Main::PACKAGE_VERSION . '-' . gmdate( 'oW' ) );
}

wp_enqueue_script(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: Check if accessible-focus.js is used anywhere else and move it to this package if not. This will currently not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I've confirmed this will still work because Assets::get_file_url_for_environment will set the $plugin_path to Jetpack_Constants::get_constant( 'JETPACK__PLUGIN_FILE' ) if the $package_path argument is empty.

As a reminder, this package will be only used by Simple and WoA sites, where the JETPACK__PLUGIN_FILE constant should be always defined.

Added a unit test too via 0ecda4f

@fgiannar fgiannar added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] In Progress labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Masterbar WordPress.com Toolbar and Dashboard customizations [Package] Masterbar [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Tests] Includes Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Masterbar package: Copy all code from the Masterbar module to the new package
3 participants