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

Adds filter to monorepo path #25443

Merged
merged 2 commits into from
Aug 12, 2022
Merged

Adds filter to monorepo path #25443

merged 2 commits into from
Aug 12, 2022

Conversation

creativecoder
Copy link
Contributor

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:

  • n/a Have you written new tests for your changes, if applicable?
  • n/a Have you checked the E2E test CI results, and verified that your changes do not break them?

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.

add_filter( 'jetpack_monorepo_path', function( $path ) {
	return '/my/monorepo/path';
} );

@creativecoder creativecoder self-assigned this Aug 11, 2022
@creativecoder creativecoder added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Tools] Monorepo Setup labels Aug 11, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 11, 2022

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.
  • ✅ All commits were linted before commit.
  • ✅ 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 (other than "Required review") 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 you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.

Copy link
Contributor

@kraftbj kraftbj left a 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$$
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know!

@kraftbj kraftbj merged commit 63bce97 into trunk Aug 12, 2022
@kraftbj kraftbj deleted the add/monorepo-path-filter branch August 12, 2022 13:37
@github-actions github-actions bot removed the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Aug 12, 2022
@creativecoder
Copy link
Contributor Author

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.

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 jetpack_monorepo_path filter within an mu-plugin seems like the best way to make sure that's the case! It seems that functions like plugins_url are likely to be called quite early.

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 tools/docker/mu-plugins, along with using this filter.

*
* @param string $path Monorepo file path.
*/
$this->monorepo = apply_filters( 'jetpack_monorepo_path', '/usr/local/src/jetpack-monorepo/' );
Copy link
Contributor

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/';

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 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 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants