Remove all usage of WOOCOMMERCE_BLOCKS_PHASE and introduce BUNDLE_EXPERIMENTAL_BLOCKS (#47807)
This commit is contained in:
parent
20bf28e5fa
commit
2d4295469d
|
@ -35,8 +35,6 @@ jobs:
|
||||||
id: prepare
|
id: prepare
|
||||||
env:
|
env:
|
||||||
CURRENT_VERSION: ${{ steps.version.outputs.version }}
|
CURRENT_VERSION: ${{ steps.version.outputs.version }}
|
||||||
# Build with experimental blocks.
|
|
||||||
WOOCOMMERCE_BLOCKS_PHASE: 3
|
|
||||||
run: |
|
run: |
|
||||||
|
|
||||||
# Current version must compare greather than any previously used current version for this PR.
|
# Current version must compare greather than any previously used current version for this PR.
|
||||||
|
|
|
@ -44,8 +44,6 @@ jobs:
|
||||||
id: prepare
|
id: prepare
|
||||||
env:
|
env:
|
||||||
CURRENT_VERSION: ${{ steps.version.outputs.version }}
|
CURRENT_VERSION: ${{ steps.version.outputs.version }}
|
||||||
# Build with experimental blocks.
|
|
||||||
WOOCOMMERCE_BLOCKS_PHASE: 3
|
|
||||||
run: |
|
run: |
|
||||||
|
|
||||||
# Current version must compare greater than any previously used current version for this PR.
|
# Current version must compare greater than any previously used current version for this PR.
|
||||||
|
|
|
@ -1,146 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Exit if any command fails.
|
|
||||||
set -e
|
|
||||||
|
|
||||||
TYPE='PRODUCTION'
|
|
||||||
|
|
||||||
print_usage() {
|
|
||||||
echo "build-plugin-zip - attempt to build a plugin"
|
|
||||||
echo "By default this will build a clean production build and zip archive"
|
|
||||||
echo "of the built plugin assets"
|
|
||||||
echo " "
|
|
||||||
echo "build-plugin-zip [arguments]"
|
|
||||||
echo " "
|
|
||||||
echo "options:"
|
|
||||||
echo "-h show brief help"
|
|
||||||
echo "-d build plugin in development mode"
|
|
||||||
echo "-z build zip only, skipping build commands (so it uses files"
|
|
||||||
echo " existing on disk already)"
|
|
||||||
echo " "
|
|
||||||
}
|
|
||||||
|
|
||||||
# get args
|
|
||||||
while getopts 'hdz' flag; do
|
|
||||||
case "${flag}" in
|
|
||||||
h) print_usage ;;
|
|
||||||
d) TYPE='DEV' ;;
|
|
||||||
z) TYPE='ZIP_ONLY' ;;
|
|
||||||
*)
|
|
||||||
print_usage
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# Tool for grabbing version from package.json
|
|
||||||
get_version() {
|
|
||||||
grep '\"version\"' package.json \
|
|
||||||
| cut -d ':' -f 2 \
|
|
||||||
| sed 's/"//g' \
|
|
||||||
| sed 's/,//g' \
|
|
||||||
| sed 's/ //g'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set version
|
|
||||||
VERSION=$(get_version)
|
|
||||||
|
|
||||||
# Store paths
|
|
||||||
SOURCE_PATH=$(pwd)
|
|
||||||
|
|
||||||
# Change to the expected directory.
|
|
||||||
cd "$(dirname "$0")"
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
# Enable nicer messaging for build status.
|
|
||||||
BLUE_BOLD='\033[1;34m';
|
|
||||||
GREEN_BOLD='\033[1;32m';
|
|
||||||
RED_BOLD='\033[1;31m';
|
|
||||||
YELLOW_BOLD='\033[1;33m';
|
|
||||||
COLOR_RESET='\033[0m';
|
|
||||||
error () {
|
|
||||||
echo -e "\n${RED_BOLD}$1${COLOR_RESET}\n"
|
|
||||||
}
|
|
||||||
status () {
|
|
||||||
echo -e "\n${BLUE_BOLD}$1${COLOR_RESET}\n"
|
|
||||||
}
|
|
||||||
success () {
|
|
||||||
echo -e "\n${GREEN_BOLD}$1${COLOR_RESET}\n"
|
|
||||||
}
|
|
||||||
warning () {
|
|
||||||
echo -e "\n${YELLOW_BOLD}$1${COLOR_RESET}\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
status "💃 Time to build a WooCommerce Blocks ZIP 🕺"
|
|
||||||
|
|
||||||
if [ -z "$NO_CHECKS" ]; then
|
|
||||||
# Make sure there are no changes in the working tree. Release builds should be
|
|
||||||
# traceable to a particular commit and reliably reproducible. (This is not
|
|
||||||
# totally true at the moment because we download nightly vendor scripts).
|
|
||||||
changed=
|
|
||||||
if ! git diff --exit-code > /dev/null; then
|
|
||||||
changed="file(s) modified"
|
|
||||||
elif ! git diff --cached --exit-code > /dev/null; then
|
|
||||||
changed="file(s) staged"
|
|
||||||
fi
|
|
||||||
if [ ! -z "$changed" ]; then
|
|
||||||
git status
|
|
||||||
error "ERROR: Cannot build plugin zip with dirty working tree. ☝️
|
|
||||||
Commit your changes and try again."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Add version to composer.json
|
|
||||||
perl -i -pe "s/\"type\":*.+/\"type\":\"wordpress-plugin\",\n\t\"version\": \"${VERSION}\",/" composer.json
|
|
||||||
|
|
||||||
# Run the build.
|
|
||||||
npm list webpack
|
|
||||||
if [ $TYPE = 'DEV' ]; then
|
|
||||||
status "Installing dependencies... 👷♀️"
|
|
||||||
status "==========================="
|
|
||||||
composer install
|
|
||||||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install
|
|
||||||
status "==========================="
|
|
||||||
status "Generating development build... 👷♀️"
|
|
||||||
status "==========================="
|
|
||||||
npm list webpack
|
|
||||||
npm run dev
|
|
||||||
status "==========================="
|
|
||||||
elif [ $TYPE = 'ZIP_ONLY' ]; then
|
|
||||||
composer dump-autoload
|
|
||||||
status "Skipping build commands - using current built assets on disk for built archive...👷♀️"
|
|
||||||
status "==========================="
|
|
||||||
else
|
|
||||||
status "Installing dependencies... 📦"
|
|
||||||
composer install --no-dev
|
|
||||||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install
|
|
||||||
status "==========================="
|
|
||||||
status "Generating production build... 👷♀️"
|
|
||||||
status "==========================="
|
|
||||||
npm list webpack
|
|
||||||
npm run build
|
|
||||||
status "==========================="
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Generate the plugin zip file.
|
|
||||||
status "Creating archive... 🎁"
|
|
||||||
mkdir zip-file
|
|
||||||
mkdir zip-file/build
|
|
||||||
sh "$SOURCE_PATH/bin/copy-plugin-files.sh" "$SOURCE_PATH" "$SOURCE_PATH/zip-file"
|
|
||||||
cd "$(pwd)/zip-file"
|
|
||||||
if [ $TYPE = 'DEV' ]; then
|
|
||||||
touch blocks.ini
|
|
||||||
printf 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = development' > blocks.ini
|
|
||||||
fi
|
|
||||||
zip -r ../woocommerce-gutenberg-products-block.zip ./
|
|
||||||
cd ..
|
|
||||||
rm -r zip-file
|
|
||||||
|
|
||||||
# cleanup composer.json
|
|
||||||
git checkout -- composer.json
|
|
||||||
|
|
||||||
# regenerate classmap for development use
|
|
||||||
composer dump-autoload
|
|
||||||
|
|
||||||
success "Done. You've built WooCommerce Blocks! 🎉"
|
|
|
@ -1,188 +0,0 @@
|
||||||
/**
|
|
||||||
* External dependencies
|
|
||||||
*/
|
|
||||||
import { RuleTester } from 'eslint';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal dependencies
|
|
||||||
*/
|
|
||||||
import rule from '../feature-flag';
|
|
||||||
|
|
||||||
const ruleTester = new RuleTester( {
|
|
||||||
parserOptions: {
|
|
||||||
sourceType: 'module',
|
|
||||||
ecmaVersion: 6,
|
|
||||||
},
|
|
||||||
} );
|
|
||||||
|
|
||||||
ruleTester.run( 'feature-flag', rule, {
|
|
||||||
valid: [
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
invalid: [
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
if ( WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'accessedViaEnv',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
output: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE !== 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'equalOperator',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
output: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE == 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'equalOperator',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
output: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE > 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'equalOperator',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
output: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE < 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'equalOperator',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
output: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE >= 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'equalOperator',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
output: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE <= 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'equalOperator',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
output: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE == 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'equalOperator',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
output: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE > 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'equalOperator',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
output: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'core' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'whiteListedFlag',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
output: `
|
|
||||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
registerBlockType( 'woocommerce/checkout', settings );
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: `
|
|
||||||
const featureFlag = process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental'`,
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'noTernary',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
} );
|
|
|
@ -1,255 +0,0 @@
|
||||||
/**
|
|
||||||
* Traverse up through the chain of parent AST nodes returning the first parent
|
|
||||||
* the predicate returns a truthy value for.
|
|
||||||
*
|
|
||||||
* @param {Object} sourceNode The AST node to search from.
|
|
||||||
* @param {Function} predicate A predicate invoked for each parent.
|
|
||||||
*
|
|
||||||
* @return {?Object } The first encountered parent node where the predicate
|
|
||||||
* returns a truthy value.
|
|
||||||
*/
|
|
||||||
function findParent( sourceNode, predicate ) {
|
|
||||||
if ( ! sourceNode.parent ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( predicate( sourceNode.parent ) ) {
|
|
||||||
return sourceNode.parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
return findParent( sourceNode.parent, predicate );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether the WOOCOMMERCE_BLOCKS_PHASE variable is accessed via
|
|
||||||
* `process.env.WOOCOMMERCE_BLOCKS_PHASE`.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```js
|
|
||||||
* // good
|
|
||||||
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE > 1 ) {
|
|
||||||
*
|
|
||||||
* // bad
|
|
||||||
* if ( WOOCOMMERCE_BLOCKS_PHASE > 1 ) {
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @param {Object} node The WOOCOMMERCE_BLOCKS_PHASE identifier node.
|
|
||||||
* @param {Object} context The eslint context object.
|
|
||||||
* @todo update this rule to match the new flags.
|
|
||||||
*/
|
|
||||||
function testIsAccessedViaProcessEnv( node, context ) {
|
|
||||||
let parent = node.parent;
|
|
||||||
|
|
||||||
if (
|
|
||||||
parent &&
|
|
||||||
parent.type === 'MemberExpression' &&
|
|
||||||
context.getSource( parent ) === 'process.env.WOOCOMMERCE_BLOCKS_PHASE'
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ( parent && parent.type === 'BinaryExpression' ) {
|
|
||||||
if ( parent.left.type === 'Identifier' ) {
|
|
||||||
parent = parent.left;
|
|
||||||
} else {
|
|
||||||
parent = parent.right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
context.report( {
|
|
||||||
node,
|
|
||||||
messageId: 'accessedViaEnv',
|
|
||||||
fix( fixer ) {
|
|
||||||
return fixer.replaceText(
|
|
||||||
parent,
|
|
||||||
'process.env.WOOCOMMERCE_BLOCKS_PHASE'
|
|
||||||
);
|
|
||||||
},
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether the WOOCOMMERCE_BLOCKS_PHASE strict binary comparison
|
|
||||||
* is strict equal only
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```js
|
|
||||||
* // good
|
|
||||||
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'stable' ) {
|
|
||||||
*
|
|
||||||
* // bad
|
|
||||||
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE !== 'experimental' ) {
|
|
||||||
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE !== 'stable' ) {
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @param {Object} node The WOOCOMMERCE_BLOCKS_PHASE identifier node.
|
|
||||||
* @param {Object} context The eslint context object.
|
|
||||||
*/
|
|
||||||
function testBinaryExpressionOperatorIsEqual( node, context ) {
|
|
||||||
const sourceCode = context.getSourceCode();
|
|
||||||
node = node.parent.parent;
|
|
||||||
if ( node.type === 'BinaryExpression' ) {
|
|
||||||
const operatorToken = sourceCode.getFirstTokenBetween(
|
|
||||||
node.left,
|
|
||||||
node.right,
|
|
||||||
( token ) => token.value === node.operator
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( operatorToken.value === '===' ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
context.report( {
|
|
||||||
node,
|
|
||||||
loc: operatorToken.loc,
|
|
||||||
messageId: 'equalOperator',
|
|
||||||
fix( fixer ) {
|
|
||||||
return fixer.replaceText( operatorToken, '===' );
|
|
||||||
},
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether the WOOCOMMERCE_BLOCKS_PHASE variable is used in a strict binary
|
|
||||||
* equality expression in a comparison with a enum of string flags, triggering a
|
|
||||||
* violation if not.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```js
|
|
||||||
* // good
|
|
||||||
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'stable' ) {
|
|
||||||
*
|
|
||||||
* // bad
|
|
||||||
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE == 'experimental' ) {
|
|
||||||
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'core' ) {
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @param {Object} node The WOOCOMMERCE_BLOCKS_PHASE identifier node.
|
|
||||||
* @param {Object} context The eslint context object.
|
|
||||||
*/
|
|
||||||
function testIsUsedInStrictBinaryExpression( node, context ) {
|
|
||||||
const parent = findParent(
|
|
||||||
node,
|
|
||||||
( candidate ) => candidate.type === 'BinaryExpression'
|
|
||||||
);
|
|
||||||
const flags = [ 'experimental', 'stable' ];
|
|
||||||
let providedFlag;
|
|
||||||
if ( parent ) {
|
|
||||||
const comparisonNode =
|
|
||||||
node.parent.type === 'MemberExpression' ? node.parent : node;
|
|
||||||
const hasCorrectOperands =
|
|
||||||
( parent.left === comparisonNode &&
|
|
||||||
flags.includes( parent.right.value ) ) ||
|
|
||||||
( parent.right === comparisonNode &&
|
|
||||||
flags.includes( parent.left.value ) );
|
|
||||||
if (
|
|
||||||
parent.left === comparisonNode &&
|
|
||||||
typeof parent.right.value === 'string'
|
|
||||||
) {
|
|
||||||
providedFlag = parent.right;
|
|
||||||
} else {
|
|
||||||
providedFlag = parent.left;
|
|
||||||
}
|
|
||||||
if ( hasCorrectOperands ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( providedFlag && providedFlag.loc ) {
|
|
||||||
context.report( {
|
|
||||||
node,
|
|
||||||
loc: providedFlag.loc,
|
|
||||||
messageId: 'whiteListedFlag',
|
|
||||||
data: {
|
|
||||||
flags: flags.join( ', ' ),
|
|
||||||
},
|
|
||||||
fix( fixer ) {
|
|
||||||
return fixer.replaceText( providedFlag, "'experimental'" );
|
|
||||||
},
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether the WOOCOMMERCE_BLOCKS_PHASE variable is used as the condition for an
|
|
||||||
* if statement, triggering a violation if not.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```js
|
|
||||||
* // good
|
|
||||||
* if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
||||||
*
|
|
||||||
* // bad
|
|
||||||
* const isFeatureActive = process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental';
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @param {Object} node The WOOCOMMERCE_BLOCKS_PHASE identifier node.
|
|
||||||
* @param {Object} context The eslint context object.
|
|
||||||
*/
|
|
||||||
function testIsUsedInIfOrTernary( node, context ) {
|
|
||||||
const conditionalParent = findParent( node, ( candidate ) =>
|
|
||||||
[ 'IfStatement', 'ConditionalExpression' ].includes( candidate.type )
|
|
||||||
);
|
|
||||||
const binaryParent = findParent(
|
|
||||||
node,
|
|
||||||
( candidate ) => candidate.type === 'BinaryExpression'
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
|
||||||
conditionalParent &&
|
|
||||||
binaryParent &&
|
|
||||||
conditionalParent.test &&
|
|
||||||
conditionalParent.test.range[ 0 ] === binaryParent.range[ 0 ] &&
|
|
||||||
conditionalParent.test.range[ 1 ] === binaryParent.range[ 1 ]
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.report( {
|
|
||||||
node,
|
|
||||||
messageId: 'noTernary',
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
meta: {
|
|
||||||
type: 'problem',
|
|
||||||
schema: [],
|
|
||||||
fixable: 'code',
|
|
||||||
messages: {
|
|
||||||
accessedViaEnv:
|
|
||||||
'The `WOOCOMMERCE_BLOCKS_PHASE` constant should be accessed using `process.env.WOOCOMMERCE_BLOCKS_PHASE`.',
|
|
||||||
whiteListedFlag:
|
|
||||||
'The `WOOCOMMERCE_BLOCKS_PHASE` constant should only be used in a strict equality comparison with a predefined flag of: {{ flags }}.',
|
|
||||||
equalOperator:
|
|
||||||
'The `WOOCOMMERCE_BLOCKS_PHASE` comparison should only be a strict equal `===`, if you need `!==` try switching the flag ',
|
|
||||||
noTernary:
|
|
||||||
'The `WOOCOMMERCE_BLOCKS_PHASE` constant should only be used as part of the condition in an if statement or ternary expression.',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
create( context ) {
|
|
||||||
return {
|
|
||||||
Identifier( node ) {
|
|
||||||
// Bypass any identifiers with a node name different to `WOOCOMMERCE_BLOCKS_PHASE`.
|
|
||||||
if ( node.name !== 'WOOCOMMERCE_BLOCKS_PHASE' ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
testIsAccessedViaProcessEnv( node, context );
|
|
||||||
testIsUsedInStrictBinaryExpression( node, context );
|
|
||||||
testBinaryExpressionOperatorIsEqual( node, context );
|
|
||||||
testIsUsedInIfOrTernary( node, context );
|
|
||||||
},
|
|
||||||
Literal( node ) {
|
|
||||||
// Bypass any identifiers with a node value different to `WOOCOMMERCE_BLOCKS_PHASE`.
|
|
||||||
if ( node.value !== 'WOOCOMMERCE_BLOCKS_PHASE' ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( node.parent && node.parent.type === 'MemberExpression' ) {
|
|
||||||
testIsAccessedViaProcessEnv( node, context );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -1,216 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
RELEASER_PATH="$(pwd)"
|
|
||||||
IS_PRE_RELEASE=false
|
|
||||||
|
|
||||||
# When it is set to true, the commands are just printed but not executed.
|
|
||||||
DRY_RUN_MODE=false
|
|
||||||
# When it is set to true, the commands that affect the local env are executed (e.g. git commit), while the commands that affect the remote env are not executed but just printed (e.g. git push)
|
|
||||||
SIMULATE_RELEASE_MODE=false
|
|
||||||
|
|
||||||
# Functions
|
|
||||||
# Check if string contains substring
|
|
||||||
is_substring() {
|
|
||||||
case "$2" in
|
|
||||||
*$1*)
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# Output colorized strings
|
|
||||||
#
|
|
||||||
# Color codes:
|
|
||||||
# 0 - black
|
|
||||||
# 1 - red
|
|
||||||
# 2 - green
|
|
||||||
# 3 - yellow
|
|
||||||
# 4 - blue
|
|
||||||
# 5 - magenta
|
|
||||||
# 6 - cian
|
|
||||||
# 7 - white
|
|
||||||
output() {
|
|
||||||
echo "$(tput setaf "$1")$2$(tput sgr0)"
|
|
||||||
}
|
|
||||||
|
|
||||||
simulate() {
|
|
||||||
if $2 = true ; then
|
|
||||||
eval "$1"
|
|
||||||
else
|
|
||||||
output 3 "DRY RUN: $1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
run_command() {
|
|
||||||
if $DRY_RUN_MODE = true; then
|
|
||||||
output 3 "DRY RUN: $1"
|
|
||||||
elif $SIMULATE_RELEASE_MODE = true; then
|
|
||||||
simulate "$1" $2
|
|
||||||
else
|
|
||||||
eval "$1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ! [ -x "$(command -v hub)" ]; then
|
|
||||||
echo 'Error: hub is not installed. Install from https://github.com/github/hub' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Release script
|
|
||||||
echo
|
|
||||||
output 5 "BLOCKS->GitHub RELEASE SCRIPT"
|
|
||||||
output 5 "============================="
|
|
||||||
echo
|
|
||||||
printf "This script will build files and create a tag on GitHub based on your local branch."
|
|
||||||
echo
|
|
||||||
echo
|
|
||||||
printf "The /build/ directory will also be pushed to the tagged release."
|
|
||||||
echo
|
|
||||||
echo
|
|
||||||
echo "Before proceeding:"
|
|
||||||
echo " • Ensure you have checked out the branch you wish to release"
|
|
||||||
echo " • Ensure you have committed/pushed all local changes"
|
|
||||||
echo " • Did you remember to update changelogs, the readme and plugin files?"
|
|
||||||
echo " • Are there any changes needed to the readme file?"
|
|
||||||
echo " • If you are running this script directly instead of via '$ npm run deploy', ensure you have built assets and installed composer in --no-dev mode."
|
|
||||||
echo
|
|
||||||
output 3 "Do you want to continue? [y/N]: "
|
|
||||||
read -r PROCEED
|
|
||||||
echo
|
|
||||||
|
|
||||||
if [ "$(echo "${PROCEED:-n}" | tr "[:upper:]" "[:lower:]")" != "y" ]; then
|
|
||||||
output 1 "Release cancelled!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo
|
|
||||||
output 3 "Please enter the version number to tag, for example, 1.0.0:"
|
|
||||||
read -r VERSION
|
|
||||||
echo
|
|
||||||
|
|
||||||
CURRENTBRANCH="$(git rev-parse --abbrev-ref HEAD)"
|
|
||||||
|
|
||||||
# Check if is a pre-release.
|
|
||||||
if is_substring "-" "${VERSION}"; then
|
|
||||||
IS_PRE_RELEASE=true
|
|
||||||
output 2 "Detected pre-release version!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
echo
|
|
||||||
output 3 "Will this release get published to WordPress.org? Note: If the version on WordPress.org is greater than ${VERSION}, then you should answer 'N' here. [y/N]:"
|
|
||||||
read -r DO_WP_DEPLOY
|
|
||||||
echo
|
|
||||||
|
|
||||||
if [ ! -d "build" ]; then
|
|
||||||
output 3 "Build directory not found. Aborting."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Safety check, if a patch release is detected ask for verification.
|
|
||||||
VERSION_PIECES=${VERSION//[^.]}
|
|
||||||
|
|
||||||
# explode version parts
|
|
||||||
split_version() {
|
|
||||||
echo ${VERSION} \
|
|
||||||
| sed 's/\./ /g'
|
|
||||||
}
|
|
||||||
|
|
||||||
SPLIT_VERSION=($(split_version))
|
|
||||||
|
|
||||||
# IF VERSION_PIECES is less than 2 then its invalid so let's update it and notify
|
|
||||||
if [[ "${#VERSION_PIECES}" -lt "2" ]]; then
|
|
||||||
if [[ ${#VERSION_PIECES} -eq "0" ]]; then
|
|
||||||
VERSION=${VERSION}.0.0
|
|
||||||
else
|
|
||||||
VERSION=${VERSION}.0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${#VERSION_PIECES}" -ge "2" && "${SPLIT_VERSION[2]}" -ne "0" && "$(echo "${DO_WP_DEPLOY:-n}" | tr "[:upper:]" "[:lower:]")" = "y" ]]; then
|
|
||||||
output 1 "The version you entered (${VERSION}) looks like a patch version. Since this version will be deployed to WordPress.org, it will become the latest available version. Are you sure you want that (no will abort)?: [y/N]"
|
|
||||||
read -r ABORT
|
|
||||||
echo
|
|
||||||
if [ "$(echo "${ABORT:-n}" | tr "[:upper:]" "[:lower:]")" != "y" ]; then
|
|
||||||
output 1 "Release cancelled!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "$(output 4 "The version is set as ") $(output 3 "${VERSION}") $(output 4 " and the next step will be to bump all the version strings in relevant files.")"
|
|
||||||
printf "Ready to proceed? [y/N]: "
|
|
||||||
read -r PROCEED
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$(echo "${PROCEED:-n}" | tr "[:upper:]" "[:lower:]")" != "y" ]; then
|
|
||||||
output 1 "Release cancelled!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Update versions in files in case they were not updated.
|
|
||||||
output 2 "Updating version numbers in files and regenerating php autoload classmap (note pre-releases will not have the readme.txt stable tag updated)..."
|
|
||||||
run_command "source '$RELEASER_PATH/bin/change-versions.sh'" true
|
|
||||||
|
|
||||||
composer dump-autoload
|
|
||||||
|
|
||||||
# remove composer.json version bump after autoload regen (we don't commit it)
|
|
||||||
run_command "git checkout -- composer.json" true
|
|
||||||
|
|
||||||
output 2 "Committing version change..."
|
|
||||||
echo
|
|
||||||
|
|
||||||
run_command "git commit -am 'Bumping version strings to new version.' --no-verify" true
|
|
||||||
run_command "git push origin $CURRENTBRANCH" false
|
|
||||||
|
|
||||||
# Tag existing version for reference
|
|
||||||
output 2 "Creating tag for current non-built branch on GitHub..."
|
|
||||||
echo
|
|
||||||
DEVTAG="v${VERSION}-dev"
|
|
||||||
run_command "git tag $DEVTAG" true
|
|
||||||
run_command "git push origin $DEVTAG" false
|
|
||||||
|
|
||||||
output 2 "Prepping release for GitHub..."
|
|
||||||
echo
|
|
||||||
|
|
||||||
# Create a release branch.
|
|
||||||
BRANCH="build/${VERSION}"
|
|
||||||
|
|
||||||
run_command "git checkout -b $BRANCH" true
|
|
||||||
|
|
||||||
# Force add build directory and commit.
|
|
||||||
run_command "git add build/. --force" true
|
|
||||||
run_command "git add ." true
|
|
||||||
run_command "git commit -m 'Adding /build directory to release' --no-verify" true
|
|
||||||
|
|
||||||
# # Force add vendor directory and commit.
|
|
||||||
run_command "git add vendor/. --force" true
|
|
||||||
run_command "git add ." true
|
|
||||||
run_command "git commit -m 'Adding /vendor directory to release' --no-verify" true
|
|
||||||
|
|
||||||
# # Push branch upstream
|
|
||||||
run_command "git push origin $BRANCH" false
|
|
||||||
|
|
||||||
# Create the new release.
|
|
||||||
if [ "$(echo "${DO_WP_DEPLOY:-n}" | tr "[:upper:]" "[:lower:]")" = "y" ]; then
|
|
||||||
if [ $IS_PRE_RELEASE = true ]; then
|
|
||||||
run_command "hub release create -m $VERSION -m 'Release of version $VERSION. See readme.txt for details.' -t $BRANCH --prerelease 'v${VERSION}'" false
|
|
||||||
else
|
|
||||||
run_command "hub release create -m $VERSION -m 'Release of version $VERSION. See readme.txt for details.' -t $BRANCH 'v${VERSION}'" false
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
run_command "git tag 'v${VERSION}'" true
|
|
||||||
run_command "git push origin 'v${VERSION}'" false
|
|
||||||
fi
|
|
||||||
|
|
||||||
run_command "git checkout $CURRENTBRANCH" true
|
|
||||||
run_command "git branch -D $BRANCH" true
|
|
||||||
run_command "git push origin --delete $BRANCH" false
|
|
||||||
|
|
||||||
# regenerate classmap for development
|
|
||||||
run_command "composer dump-autoload" false
|
|
||||||
|
|
||||||
output 2 "GitHub release complete."
|
|
|
@ -124,7 +124,6 @@ const getCoreConfig = ( options = {} ) => {
|
||||||
fileName: 'blocks.ini',
|
fileName: 'blocks.ini',
|
||||||
// content of the file
|
// content of the file
|
||||||
content: `
|
content: `
|
||||||
woocommerce_blocks_phase = ${ process.env.WOOCOMMERCE_BLOCKS_PHASE || 3 }
|
|
||||||
woocommerce_blocks_env = ${ NODE_ENV }
|
woocommerce_blocks_env = ${ NODE_ENV }
|
||||||
`.trim(),
|
`.trim(),
|
||||||
} ),
|
} ),
|
||||||
|
|
|
@ -166,16 +166,8 @@ const blocks = {
|
||||||
// `**/*.scss`...).
|
// `**/*.scss`...).
|
||||||
// It also filters out elements with undefined props and experimental blocks.
|
// It also filters out elements with undefined props and experimental blocks.
|
||||||
const getBlockEntries = ( relativePath ) => {
|
const getBlockEntries = ( relativePath ) => {
|
||||||
const experimental =
|
|
||||||
! parseInt( process.env.WOOCOMMERCE_BLOCKS_PHASE, 10 ) < 3;
|
|
||||||
|
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
Object.entries( blocks )
|
Object.entries( blocks )
|
||||||
.filter(
|
|
||||||
( [ , config ] ) =>
|
|
||||||
! config.isExperimental ||
|
|
||||||
config.isExperimental === experimental
|
|
||||||
)
|
|
||||||
.map( ( [ blockCode, config ] ) => {
|
.map( ( [ blockCode, config ] ) => {
|
||||||
const filePaths = glob.sync(
|
const filePaths = glob.sync(
|
||||||
`./assets/js/blocks/${ config.customDir || blockCode }/` +
|
`./assets/js/blocks/${ config.customDir || blockCode }/` +
|
||||||
|
|
|
@ -15,12 +15,6 @@
|
||||||
- [Misc](#misc)
|
- [Misc](#misc)
|
||||||
- [Usages of `experimental` prefix](#usages-of-experimental-prefix)
|
- [Usages of `experimental` prefix](#usages-of-experimental-prefix)
|
||||||
|
|
||||||
We have feature gating system setup in our plugin that defines what is accessible to the public and what is not, it has three phases:
|
|
||||||
|
|
||||||
- **Core flag `WOOCOMMERCE_BLOCKS_PHASE=1`:** anything that is not hidden behind a flag, falls under this category, and it contains all of the code that runs on WooCommerce Core plugin.
|
|
||||||
- **Feature plugin flag `WOOCOMMERCE_BLOCKS_PHASE=2`**: anything that is behind this flag is code that is shipped to our [feature plugin](https://wordpress.org/plugins/woo-gutenberg-products-block/), the files of blocks behind this flag are also present in WooCommerce Core, just not active.
|
|
||||||
- **Experimental flag `WOOCOMMERCE_BLOCKS_PHASE=3`**: This flag contains things that we're not shipping yet, so unfinished work mostly. These features are only available in developer builds of the plugin.
|
|
||||||
|
|
||||||
We also use an `__experimental` prefix for any experimental interfaces. This is a signal to those reading our code that it should not be implemented in for production use. Currently this prefix is used in the following ways:
|
We also use an `__experimental` prefix for any experimental interfaces. This is a signal to those reading our code that it should not be implemented in for production use. Currently this prefix is used in the following ways:
|
||||||
|
|
||||||
- Prefixing references that are experimental. An example would be PHP action or filter slugs.
|
- Prefixing references that are experimental. An example would be PHP action or filter slugs.
|
||||||
|
|
|
@ -50,14 +50,12 @@
|
||||||
"build:project": "pnpm --if-present '/^build:project:.*$/'",
|
"build:project": "pnpm --if-present '/^build:project:.*$/'",
|
||||||
"build:project:bundle": "wireit",
|
"build:project:bundle": "wireit",
|
||||||
"build:check-assets": "rimraf build/* && cross-env ASSET_CHECK=true BABEL_ENV=default NODE_ENV=production webpack",
|
"build:check-assets": "rimraf build/* && cross-env ASSET_CHECK=true BABEL_ENV=default NODE_ENV=production webpack",
|
||||||
"build:deploy": "rimraf vendor/* && cross-env WOOCOMMERCE_BLOCKS_PHASE=2 composer install --no-dev && cross-env WOOCOMMERCE_BLOCKS_PHASE=2 pnpm run build --loglevel error",
|
|
||||||
"prebuild:docs": "rimraf docs/extensibility/actions.md & rimraf docs/extensibility/filters.md",
|
"prebuild:docs": "rimraf docs/extensibility/actions.md & rimraf docs/extensibility/filters.md",
|
||||||
"build:docs": "./vendor/bin/wp-hooks-generator --input=src --output=bin/hook-docs/data && node ./bin/hook-docs && pnpm build:docs:block-references",
|
"build:docs": "./vendor/bin/wp-hooks-generator --input=src --output=bin/hook-docs/data && node ./bin/hook-docs && pnpm build:docs:block-references",
|
||||||
"build:docs:block-references": "node ./bin/gen-block-list-doc.js",
|
"build:docs:block-references": "node ./bin/gen-block-list-doc.js",
|
||||||
"postbuild:docs": "./bin/add-doc-footer.sh",
|
"postbuild:docs": "./bin/add-doc-footer.sh",
|
||||||
"changelog:zenhub": "node ./bin/changelog --changelogSrcType='ZENHUB_RELEASE'",
|
"changelog:zenhub": "node ./bin/changelog --changelogSrcType='ZENHUB_RELEASE'",
|
||||||
"change-versions": "source ./bin/change-versions.sh",
|
"change-versions": "source ./bin/change-versions.sh",
|
||||||
"deploy": "pnpm run build:deploy && sh ./bin/github-deploy.sh",
|
|
||||||
"dev": "rimraf build/* && cross-env BABEL_ENV=default webpack",
|
"dev": "rimraf build/* && cross-env BABEL_ENV=default webpack",
|
||||||
"labels:dry": "github-label-sync --labels ./.github/label-sync-config.json --allow-added-labels --dry-run woocommerce/woocommerce-gutenberg-products-block",
|
"labels:dry": "github-label-sync --labels ./.github/label-sync-config.json --allow-added-labels --dry-run woocommerce/woocommerce-gutenberg-products-block",
|
||||||
"labels:sync": "github-label-sync --labels ./.github/label-sync-config.json --allow-added-labels woocommerce/woocommerce-gutenberg-products-block",
|
"labels:sync": "github-label-sync --labels ./.github/label-sync-config.json --allow-added-labels woocommerce/woocommerce-gutenberg-products-block",
|
||||||
|
@ -388,9 +386,6 @@
|
||||||
"BABEL_ENV": {
|
"BABEL_ENV": {
|
||||||
"external": true,
|
"external": true,
|
||||||
"default": "default"
|
"default": "default"
|
||||||
},
|
|
||||||
"WOOCOMMERCE_BLOCKS_PHASE": {
|
|
||||||
"external": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
|
|
@ -5,10 +5,6 @@ PROJECT_PATH=$(pwd)
|
||||||
BUILD_PATH="${PROJECT_PATH}/build"
|
BUILD_PATH="${PROJECT_PATH}/build"
|
||||||
DEST_PATH="$BUILD_PATH/$PLUGIN_SLUG"
|
DEST_PATH="$BUILD_PATH/$PLUGIN_SLUG"
|
||||||
|
|
||||||
if [ -z "${WOOCOMMERCE_BLOCKS_PHASE}" ]; then
|
|
||||||
export WOOCOMMERCE_BLOCKS_PHASE=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Generating build directory..."
|
echo "Generating build directory..."
|
||||||
rm -rf "$BUILD_PATH"
|
rm -rf "$BUILD_PATH"
|
||||||
mkdir -p "$DEST_PATH"
|
mkdir -p "$DEST_PATH"
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: dev
|
||||||
|
|
||||||
|
Remove WOOCOMMERCE_BLOCKS_PHASE completely from the monorepo, introduce BUNDLE_EXPERIMENTAL_BLOCKS just for the purpose of building/bundling experimental blocks
|
Loading…
Reference in New Issue