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

Commit 9b76ea7

Browse files
authored
Expand Feature flags (#2591)
* Revert "Move blocks to stable flag (#2261)" This reverts commit 25a2964. * migrate to number based gating * add todo to watch feature flag * remove flags from build * change flag in travis * load flag in right order * expose flag to js * simplify flag definition * more feature flags * wrap flag in check * add helper functions * add helpers in PHP * fix typo in flag * move php code to src/domain/package * tweak if condition * return flag to travis * fix broken block name
1 parent 15259b9 commit 9b76ea7

File tree

19 files changed

+158
-79
lines changed

19 files changed

+158
-79
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
rules: {
2121
'@wordpress/dependency-group': 'off',
2222
'woocommerce/dependency-group': 'error',
23-
'woocommerce/feature-flag': 'error',
23+
'woocommerce/feature-flag': 'off',
2424
'valid-jsdoc': 'off',
2525
radix: 'error',
2626
yoda: [ 'error', 'never' ],

.travis.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,35 @@ jobs:
4747
php: 7.1
4848
env:
4949
- WP_VERSION=latest
50-
- WOOCOMMERCE_BLOCKS_PHASE=experimental
50+
- WOOCOMMERCE_BLOCKS_PHASE=3
5151
script:
5252
- phpunit
5353
- name: PHP 5.6/unit-tests/Latest WP
5454
php: 5.6
5555
env:
5656
- WP_VERSION=latest
57-
- WOOCOMMERCE_BLOCKS_PHASE=experimental
57+
- WOOCOMMERCE_BLOCKS_PHASE=3
5858
script:
5959
- phpunit
6060
- name: PHP Linting Check
6161
php: 7.3
6262
env:
6363
- WP_TRAVISCI=phpcs
64-
- WOOCOMMERCE_BLOCKS_PHASE=experimental
64+
- WOOCOMMERCE_BLOCKS_PHASE=3
6565
script:
6666
- npm run lint:php
6767
- name: Javascript Tests
6868
script:
6969
- npm install
7070
- npm run test
7171
env:
72-
- WOOCOMMERCE_BLOCKS_PHASE=experimental
72+
- WOOCOMMERCE_BLOCKS_PHASE=3
7373
- name: Javascript/CSS Lint check
7474
script:
7575
- npm install
7676
- npm run lint:ci
7777
env:
78-
- WOOCOMMERCE_BLOCKS_PHASE=experimental
78+
- WOOCOMMERCE_BLOCKS_PHASE=3
7979
- name: E2E Tests
8080
script:
8181
- npm ci
@@ -84,12 +84,12 @@ jobs:
8484
- npm run build:e2e-test
8585
- npm run test:e2e
8686
env:
87-
- WOOCOMMERCE_BLOCKS_PHASE=experimental
87+
- WOOCOMMERCE_BLOCKS_PHASE=3
8888
- stage: deploy
8989
if: (NOT type IN (pull_request)) AND (branch = master)
9090
name: Deploy Storybook
9191
env:
92-
- WOOCOMMERCE_BLOCKS_PHASE=experimental
92+
- WOOCOMMERCE_BLOCKS_PHASE=3
9393
install:
9494
- npm ci
9595
script:

assets/js/blocks/cart-checkout/cart/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
*/
44
import { __ } from '@wordpress/i18n';
55
import { InnerBlocks } from '@wordpress/block-editor';
6-
import { registerBlockType } from '@wordpress/blocks';
76
import { Icon, cart } from '@woocommerce/icons';
87
import classnames from 'classnames';
9-
8+
import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
109
/**
1110
* Internal dependencies
1211
*/
@@ -51,4 +50,4 @@ const settings = {
5150
},
5251
};
5352

54-
registerBlockType( 'woocommerce/cart', settings );
53+
registerFeaturePluginBlockType( 'woocommerce/cart', settings );

assets/js/blocks/cart-checkout/checkout/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* External dependencies
33
*/
44
import { __ } from '@wordpress/i18n';
5-
import { registerBlockType } from '@wordpress/blocks';
65
import { Icon, card } from '@woocommerce/icons';
76
import classnames from 'classnames';
7+
import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
88

99
/**
1010
* Internal dependencies
@@ -49,4 +49,4 @@ const settings = {
4949
},
5050
};
5151

52-
registerBlockType( 'woocommerce/checkout', settings );
52+
registerFeaturePluginBlockType( 'woocommerce/checkout', settings );

assets/js/blocks/single-product/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* External dependencies
33
*/
44
import { __ } from '@wordpress/i18n';
5-
import { registerBlockType } from '@wordpress/blocks';
5+
import { registerExperimentalBlockType } from '@woocommerce/block-settings';
66

77
/**
88
* Internal dependencies
@@ -40,4 +40,4 @@ const settings = {
4040
save,
4141
};
4242

43-
registerBlockType( BLOCK_NAME, settings );
43+
registerExperimentalBlockType( BLOCK_NAME, settings );

assets/js/settings/blocks/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export const IS_SHIPPING_COST_HIDDEN = getSetting(
4949
'isShippingCostHidden',
5050
false
5151
);
52+
export const WOOCOMMERCE_BLOCKS_PHASE = getSetting(
53+
'woocommerceBlocksPhase',
54+
1
55+
);
5256
export const WC_BLOCKS_ASSET_URL = getSetting( 'wcBlocksAssetUrl', '' );
5357
export const SHIPPING_COUNTRIES = getSetting( 'shippingCountries', {} );
5458
export const ALLOWED_COUNTRIES = getSetting( 'allowedCountries', {} );
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { registerBlockType } from '@wordpress/blocks';
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import { WOOCOMMERCE_BLOCKS_PHASE } from './constants';
10+
11+
/**
12+
* Registers a new experimental block provided a unique name and an object defining its
13+
* behavior. Once registered, the block is made available as an option to any
14+
* editor interface where blocks are implemented.
15+
*
16+
* @param {string} name Block name.
17+
* @param {Object} settings Block settings.
18+
*
19+
* @return {?Object} The block, if it has been successfully registered;
20+
* otherwise `undefined`.
21+
*/
22+
export const registerExperimentalBlockType = ( name, settings ) => {
23+
if ( WOOCOMMERCE_BLOCKS_PHASE > 2 ) {
24+
return registerBlockType( name, settings );
25+
}
26+
};
27+
28+
/**
29+
* Registers a new feature plugin block provided a unique name and an object
30+
* defining its behavior. Once registered, the block is made available as an
31+
* option to any editor interface where blocks are implemented.
32+
*
33+
* @param {string} name Block name.
34+
* @param {Object} settings Block settings.
35+
*
36+
* @return {?Object} The block, if it has been successfully registered;
37+
* otherwise `undefined`.
38+
*/
39+
export const registerFeaturePluginBlockType = ( name, settings ) => {
40+
if ( WOOCOMMERCE_BLOCKS_PHASE > 1 ) {
41+
return registerBlockType( name, settings );
42+
}
43+
};
44+
45+
/**
46+
* Checks if we're executing the code in an experimental build mode.
47+
*
48+
* @return {boolean} True if this is an experimental build, false otherwise.
49+
*/
50+
export const isExperimentalBuild = () => WOOCOMMERCE_BLOCKS_PHASE > 2;
51+
52+
/**
53+
* Checks if we're executing the code in an feature plugin or experimental build mode.
54+
*
55+
* @return {boolean} True if this is an experimental or feature plugin build, false otherwise.
56+
*/
57+
export const isFeaturePluginBuild = () => WOOCOMMERCE_BLOCKS_PHASE > 1;

assets/js/settings/blocks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
* Internal dependencies
33
*/
44
export * from './constants';
5+
export * from './feature-flags';

bin/eslint-plugin-woocommerce/rules/feature-flag.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ function findParent( sourceNode, predicate ) {
2727
* @example
2828
* ```js
2929
* // good
30-
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
30+
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE > 1 ) {
3131
*
3232
* // bad
33-
* if ( WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
33+
* if ( WOOCOMMERCE_BLOCKS_PHASE > 1 ) {
3434
* ```
3535
*
3636
* @param {Object} node The WOOCOMMERCE_BLOCKS_PHASE identifier node.
3737
* @param {Object} context The eslint context object.
38+
* @todo: update this rule to match the new flags.
3839
*/
3940
function testIsAccessedViaProcessEnv( node, context ) {
4041
let parent = node.parent;

bin/webpack-helpers.js

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extrac
99
const WebpackRTLPlugin = require( 'webpack-rtl-plugin' );
1010
const chalk = require( 'chalk' );
1111
const { omit } = require( 'lodash' );
12-
const { DefinePlugin } = require( 'webpack' );
1312
const NODE_ENV = process.env.NODE_ENV || 'development';
1413

1514
function findModuleMatch( module, match ) {
@@ -149,16 +148,17 @@ const stableMainEntry = {
149148
'active-filters': './assets/js/blocks/active-filters/index.js',
150149
'block-error-boundary':
151150
'./assets/js/base/components/block-error-boundary/style.scss',
152-
'single-product': './assets/js/blocks/single-product/index.js',
151+
cart: './assets/js/blocks/cart-checkout/cart/index.js',
152+
checkout: './assets/js/blocks/cart-checkout/checkout/index.js',
153153
};
154154

155155
const experimentalMainEntry = {
156-
cart: './assets/js/blocks/cart-checkout/cart/index.js',
157-
checkout: './assets/js/blocks/cart-checkout/checkout/index.js',
156+
'single-product': './assets/js/blocks/single-product/index.js',
158157
};
159158

160159
const mainEntry =
161-
process.env.WOOCOMMERCE_BLOCKS_PHASE === 'stable'
160+
// env variables are strings, so we compare against a string, so we need to parse it.
161+
parseInt( process.env.WOOCOMMERCE_BLOCKS_PHASE, 10 ) < 3
162162
? stableMainEntry
163163
: { ...stableMainEntry, ...experimentalMainEntry };
164164

@@ -168,16 +168,17 @@ const stableFrontEndEntry = {
168168
'price-filter': './assets/js/blocks/price-filter/frontend.js',
169169
'attribute-filter': './assets/js/blocks/attribute-filter/frontend.js',
170170
'active-filters': './assets/js/blocks/active-filters/frontend.js',
171-
'single-product': './assets/js/blocks/single-product/frontend.js',
171+
cart: './assets/js/blocks/cart-checkout/cart/frontend.js',
172+
checkout: './assets/js/blocks/cart-checkout/checkout/frontend.js',
172173
};
173174

174175
const experimentalFrontEndEntry = {
175-
cart: './assets/js/blocks/cart-checkout/cart/frontend.js',
176-
checkout: './assets/js/blocks/cart-checkout/checkout/frontend.js',
176+
'single-product': './assets/js/blocks/single-product/frontend.js',
177177
};
178178

179179
const frontEndEntry =
180-
process.env.WOOCOMMERCE_BLOCKS_PHASE === 'stable'
180+
// env variables are strings, so we compare against a string, so we need to parse it.
181+
parseInt( process.env.WOOCOMMERCE_BLOCKS_PHASE, 10 ) < 3
181182
? stableFrontEndEntry
182183
: { ...stableFrontEndEntry, ...experimentalFrontEndEntry };
183184

@@ -358,13 +359,6 @@ const getMainConfig = ( options = {} ) => {
358359
requestToExternal,
359360
requestToHandle,
360361
} ),
361-
new DefinePlugin( {
362-
// Inject the `WOOCOMMERCE_BLOCKS_PHASE` global, used for feature flagging.
363-
'process.env.WOOCOMMERCE_BLOCKS_PHASE': JSON.stringify(
364-
// eslint-disable-next-line woocommerce/feature-flag
365-
process.env.WOOCOMMERCE_BLOCKS_PHASE || 'experimental'
366-
),
367-
} ),
368362
],
369363
resolve,
370364
};
@@ -460,13 +454,6 @@ const getFrontConfig = ( options = {} ) => {
460454
requestToExternal,
461455
requestToHandle,
462456
} ),
463-
new DefinePlugin( {
464-
// Inject the `WOOCOMMERCE_BLOCKS_PHASE` global, used for feature flagging.
465-
'process.env.WOOCOMMERCE_BLOCKS_PHASE': JSON.stringify(
466-
// eslint-disable-next-line woocommerce/feature-flag
467-
process.env.WOOCOMMERCE_BLOCKS_PHASE || 'experimental'
468-
),
469-
} ),
470457
],
471458
resolve,
472459
};
@@ -599,13 +586,6 @@ const getPaymentMethodsExtensionConfig = ( options = {} ) => {
599586
requestToExternal,
600587
requestToHandle,
601588
} ),
602-
new DefinePlugin( {
603-
// Inject the `WOOCOMMERCE_BLOCKS_PHASE` global, used for feature flagging.
604-
'process.env.WOOCOMMERCE_BLOCKS_PHASE': JSON.stringify(
605-
// eslint-disable-next-line woocommerce/feature-flag
606-
process.env.WOOCOMMERCE_BLOCKS_PHASE || 'experimental'
607-
),
608-
} ),
609589
],
610590
resolve,
611591
};

0 commit comments

Comments
 (0)