-
Notifications
You must be signed in to change notification settings - Fork 800
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
Adds filter to monorepo path #25443
Adds filter to monorepo path #25443
Conversation
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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 (other than "Required review") appearing at the bottom of this PR are passing or skipped. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Untested, but it looks fine plus be it in our internal dev tooling, I'm not worried about a bug being missed and impacting customers :)
Noting that since it is used in a mu-plugin, it'll need to be used in a mu-plugin that loads before the first use of this. I think that's the fix-monorepo-urls.php
file.
/** | ||
* Filter the monorepo path for development environments. | ||
* | ||
* @since $$next-version$$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will ever increment since it isn't in a project, but we can remove it later. Not going to block you for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know!
To clarify, all of the uses of the Monorepo class I see right now are in action or filter callbacks, so I think it's a matter of making sure to add the filter before any of those hooks are fired--but agreed that using the Thanks so much for getting this merged! I'm now able to run the monorepo within a local php dev environment without errors by symlinking the mu-plugins in |
* | ||
* @param string $path Monorepo file path. | ||
*/ | ||
$this->monorepo = apply_filters( 'jetpack_monorepo_path', '/usr/local/src/jetpack-monorepo/' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was dealing with the symlink issue on local environment without Docker.
What about defining JETPACK_MONOREPO_PATH? So we just define it directly in the wp-config.php file.
$this->monorepo = defined( 'JETPACK_MONOREPO_PATH' ) ? JETPACK_MONOREPO_PATH : '/usr/local/src/jetpack-monorepo/';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no preference between a filter vs a constant. I find I put a lot of local dev overrides in a 0-local.php
mu-plugin file, so a filter fits in in well here.
But a constant makes a lot of sense, as the monorepo path isn't something that's likely to change dynamically.
For reference, here's some of the content of my 0-local.php
mu-plugin file:
// Register theme project directories (that are symlinked to wp-content/).
register_theme_directory( 'wpcom-themes' );
register_theme_directory( 'theme-experiments' );
// Compensate for symlinked wpcomsh mu-plugin.
add_action( 'plugins_url', function( $url ) {
if ( false !== strpos( $url, 'wpcomsh' ) ) {
return str_replace( '/plugins/Users/Grant/Automattic/Sites', '/mu-plugins', $url );
}
return $url;
} );
// Run jetpack monorepo outside a docker container.
add_filter( 'jetpack_monorepo_path', function( $path ) {
return '/Users/Grant/Automattic/Sites/jetpack/';
} );
// Fix an issue when running WordPress behind a reverse proxy,
// such as jurassic.tube tunneling for Jetpack development.
add_filter( 'redirect_canonical', function( $redirect_url, $requested_url ) {
$redirect_host = wp_parse_url( $redirect_url, PHP_URL_HOST );
$requested_host = wp_parse_url( $requested_url, PHP_URL_HOST );
if (
// Is redirecting to the reverse proxy host
$_SERVER['HTTP_X_FORWARDED_HOST'] === $redirect_host &&
// and is requesting the local (valet) domain
$_SERVER['HTTP_HOST'] === $requested_host
) {
return false;
}
return $redirect_url;
}, 10, 2 );
Changes proposed in this Pull Request:
Adds a filter to monorepo path to make it easier to run a development version of Jetpack outside of Docker.
Other information:
Jetpack product discussion
n/a
Does this pull request change what data or activity we track or use?
no
Testing instructions:
Add a filter callback to
jetpack_monorepo_path
, e.g.