Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Introduce feature flags #1631

Merged
merged 24 commits into from
Jan 31, 2020
Merged

Introduce feature flags #1631

merged 24 commits into from
Jan 31, 2020

Conversation

senadir
Copy link
Member

@senadir senadir commented Jan 22, 2020

This PR introduces a simple feature flag and gate features, as a start, it will only prevent Checkout and Cart from being registered.

It introduces 3 flags 2 flags: Core, Stable, and Experimental.

Any code not gated is considered stable enough to be included in Woo Core.

Experimental is code that is not stable yet to be shipped, think Cart and Checkout blocks by the end of last cycle.

For development purposes, the default flag will be experimental.

We also append WOOCOMMERCE_BLOCKS_PHASE="stable" to the build command in npm run deploy.

To achieve this, I used a combo of DefinePlugin of webpack and an env variable WOOCOMMERCE_BLOCKS_PHASE.

This code heavily inspires from WordPress/gutenberg#13324

Fixes #1500

@senadir senadir added status: in progress tools Used for work on build or release tools. skip-changelog PRs that you don't want to appear in the changelog. labels Jan 22, 2020
@senadir senadir self-assigned this Jan 22, 2020
@senadir senadir requested review from Aljullu and nerrad January 22, 2020 18:12
@senadir
Copy link
Member Author

senadir commented Jan 22, 2020

This is set to Draft and in Progress because I didn’t yet manage to get it to work, I only tagged for review to help determine why it’s not working (something specific about our build process?)

@senadir
Copy link
Member Author

senadir commented Jan 23, 2020

Moving the config to webpack-helper fixed the issue, all working right now.

@senadir senadir marked this pull request as ready for review January 23, 2020 12:38
@senadir senadir requested a review from a team January 23, 2020 12:38
Copy link
Contributor

@nerrad nerrad 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 taking this on @senadir 👏 This is going to be really useful for the work we're doing in this repo and gating things until it's ready for release. However, there are some problems with the current implementation and I also have some things I think we should consider:

  • the frontend builds (getFrontConfig) and coreConfig might have gating as well so we should probably include the plugin definition in those configs too. I think this should be done before merging this pull.
  • While this works well for gating what javascript executes or not, there is no gating php side, so that means built javascript for gated features will still be enqueued and loaded. I don't think we need to tackle that in this pull but we probably should create a follow-up issue to discuss how we might handle that (or if we should bother).

@senadir senadir force-pushed the try/feature-gating branch from 71a289b to c36080c Compare January 24, 2020 14:53
@senadir
Copy link
Member Author

senadir commented Jan 24, 2020

So my latest changes are not complete.

I addressed the feedback and added even more gating, since we output a js file for each block (well, 2 files), i moved those to experimentalFrontendEntry and experimentalMainEntry, I left the stable ones in stableFrontendEntry and stableMainEntry, and according to the flag, I merge them.

this will cause some html errors since PHP will enqueue a nonexistent file, I'm adding some feature gating to PHP as well, but we still need a way to define the constant at run time.

@senadir senadir requested a review from nerrad January 24, 2020 20:11
@nerrad nerrad added this to the 2.6.0 milestone Jan 27, 2020
Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

Liking how this is coming along! Thanks for addressing all the feedback. Just a few more things to take care of 👇

Comment on lines -131 to +132
// cart & checkout blocks
const experimentalMainEntry = {
Copy link
Contributor

@nerrad nerrad Jan 28, 2020

Choose a reason for hiding this comment

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

Great idea to split out the stable from experimental configuration!

package.json Outdated
"release": "sh ./bin/wordpress-deploy.sh",
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
"build:ci": "npm run build && npm run size-check && npm run lint:js && npm run lint:css",
"start": "cross-env BABEL_ENV=default webpack --watch --info-verbosity none",
"start": "cross-env WOOCOMMERCE_BLOCKS_PHASE=experimental BABEL_ENV=default webpack --watch --info-verbosity none",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed if the default is experimental (npm build or npm build:ci executed on their own will be using experimental too)?

Copy link
Member Author

@senadir senadir Jan 31, 2020

Choose a reason for hiding this comment

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

now that we have default values in PHP as well, we don’t need to pass this yeah.

Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

Awesome Nadir! Soooo close to merge ready. I've tested and verified that the woo-blocks.ini file has the correct value written to it depending on the WOOCOMMERCE_BLOCKS_PHASE environment 👍

I just have a few more comments that should be addressed.

@senadir senadir force-pushed the try/feature-gating branch from 97fa606 to 043ba9b Compare January 31, 2020 16:28
@senadir
Copy link
Member Author

senadir commented Jan 31, 2020

@nerrad addressed the latest comments, this is ready for another spin

@senadir senadir requested a review from nerrad January 31, 2020 16:31
@senadir senadir force-pushed the try/feature-gating branch from d0ce5e9 to d0aa8d2 Compare January 31, 2020 16:53
Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

I have a suggestion for improving the php side detection of the blocks phase flag.

PHPUnit test jobs for travis are currently broken because of the default to stable when the block.ini file isn't present. We don't run webpack in the phpunit jobs because that extends the time of the job run unnecessarily. One thing you could do to resolve this is detect for a environment variable (using getenv('WOOCOMMERCE_BLOCKS_PHASE') for the flag as a fallback. That way you can use that to alternatively set the flag instead of block.ini for environments like travis where we don't need to do a build step for php only tests. You can then just define the environment variable in the .travis.yml config file for the phpunit jobs.

Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

:shipit: 🎉 🌮 Woot! Another great pull to merge, awesome work @senadir!!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
skip-changelog PRs that you don't want to appear in the changelog. tools Used for work on build or release tools.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Feature Gating
4 participants