2021-06-29 11:18:29 +00:00
|
|
|
/* eslint-disable no-console */
|
2019-10-06 12:36:15 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const path = require( 'path' );
|
2021-06-29 11:18:29 +00:00
|
|
|
const chalk = require( 'chalk' );
|
2020-07-07 09:05:06 +00:00
|
|
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
const FORCE_MAP = process.env.FORCE_MAP || false;
|
2021-04-08 12:31:12 +00:00
|
|
|
const CHECK_CIRCULAR_DEPS = process.env.CHECK_CIRCULAR_DEPS || false;
|
2019-10-06 12:36:15 +00:00
|
|
|
|
2020-12-14 11:55:05 +00:00
|
|
|
// If a package is not available, or missing functionality, in an old but __supported__ version of WordPress, it should be listed here.
|
|
|
|
// Some packages are not available in legacy versions of WordPress, so we don't want to extract them.
|
2021-05-25 09:46:28 +00:00
|
|
|
const requiredPackagesInWPLegacy = [];
|
2020-12-03 13:04:25 +00:00
|
|
|
|
2020-07-07 09:05:06 +00:00
|
|
|
const wcDepMap = {
|
|
|
|
'@woocommerce/blocks-registry': [ 'wc', 'wcBlocksRegistry' ],
|
|
|
|
'@woocommerce/settings': [ 'wc', 'wcSettings' ],
|
|
|
|
'@woocommerce/block-data': [ 'wc', 'wcBlocksData' ],
|
2021-06-09 14:09:42 +00:00
|
|
|
'@woocommerce/shared-context': [ 'wc', 'wcBlocksSharedContext' ],
|
|
|
|
'@woocommerce/shared-hocs': [ 'wc', 'wcBlocksSharedHocs' ],
|
2021-02-04 15:30:28 +00:00
|
|
|
'@woocommerce/price-format': [ 'wc', 'priceFormat' ],
|
2021-01-11 12:12:26 +00:00
|
|
|
'@woocommerce/blocks-checkout': [ 'wc', 'blocksCheckout' ],
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|
|
|
|
|
2020-07-07 09:05:06 +00:00
|
|
|
const wcHandleMap = {
|
|
|
|
'@woocommerce/blocks-registry': 'wc-blocks-registry',
|
|
|
|
'@woocommerce/settings': 'wc-settings',
|
|
|
|
'@woocommerce/block-settings': 'wc-settings',
|
|
|
|
'@woocommerce/block-data': 'wc-blocks-data-store',
|
2021-06-09 14:09:42 +00:00
|
|
|
'@woocommerce/shared-context': 'wc-blocks-shared-context',
|
|
|
|
'@woocommerce/shared-hocs': 'wc-blocks-shared-hocs',
|
2021-02-04 15:30:28 +00:00
|
|
|
'@woocommerce/price-format': 'wc-price-format',
|
2021-01-07 12:02:21 +00:00
|
|
|
'@woocommerce/blocks-checkout': 'wc-blocks-checkout',
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const getAlias = ( options = {} ) => {
|
|
|
|
let { pathPart } = options;
|
|
|
|
pathPart = pathPart ? `${ pathPart }/` : '';
|
|
|
|
return {
|
2020-05-29 13:49:56 +00:00
|
|
|
'@woocommerce/atomic-blocks': path.resolve(
|
2019-10-06 12:36:15 +00:00
|
|
|
__dirname,
|
2020-05-29 13:49:56 +00:00
|
|
|
`../assets/js/${ pathPart }atomic/blocks`
|
2019-10-06 12:36:15 +00:00
|
|
|
),
|
2020-05-29 11:28:04 +00:00
|
|
|
'@woocommerce/atomic-utils': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }atomic/utils`
|
|
|
|
),
|
2019-10-06 12:36:15 +00:00
|
|
|
'@woocommerce/base-components': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/components/`
|
|
|
|
),
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/base-context': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/context/`
|
|
|
|
),
|
2019-10-06 12:36:15 +00:00
|
|
|
'@woocommerce/base-hocs': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/hocs/`
|
|
|
|
),
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/base-hooks': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/hooks/`
|
|
|
|
),
|
2019-11-15 14:41:23 +00:00
|
|
|
'@woocommerce/base-utils': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/utils/`
|
|
|
|
),
|
2020-09-02 08:21:46 +00:00
|
|
|
'@woocommerce/editor-components': path.resolve(
|
2019-10-06 12:36:15 +00:00
|
|
|
__dirname,
|
2020-09-02 08:21:46 +00:00
|
|
|
`../assets/js/${ pathPart }editor-components/`
|
2019-10-06 12:36:15 +00:00
|
|
|
),
|
|
|
|
'@woocommerce/block-hocs': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }hocs`
|
|
|
|
),
|
2020-01-31 18:20:33 +00:00
|
|
|
'@woocommerce/blocks-registry': path.resolve(
|
2019-10-28 13:53:09 +00:00
|
|
|
__dirname,
|
2020-01-31 18:20:33 +00:00
|
|
|
'../assets/js/blocks-registry'
|
|
|
|
),
|
|
|
|
'@woocommerce/block-settings': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../assets/js/settings/blocks'
|
2019-10-28 13:53:09 +00:00
|
|
|
),
|
2020-01-31 18:20:33 +00:00
|
|
|
'@woocommerce/icons': path.resolve( __dirname, `../assets/js/icons` ),
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/resource-previews': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }previews/`
|
|
|
|
),
|
2021-05-25 11:49:13 +00:00
|
|
|
'@woocommerce/types': path.resolve( __dirname, `../assets/js/types/` ),
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-07-07 09:05:06 +00:00
|
|
|
function findModuleMatch( module, match ) {
|
|
|
|
if ( module.request && match.test( module.request ) ) {
|
|
|
|
return true;
|
|
|
|
} else if ( module.issuer ) {
|
|
|
|
return findModuleMatch( module.issuer, match );
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-06 12:36:15 +00:00
|
|
|
|
2020-07-07 09:05:06 +00:00
|
|
|
const requestToExternal = ( request ) => {
|
2020-12-03 13:04:25 +00:00
|
|
|
if ( requiredPackagesInWPLegacy.includes( request ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-07 09:05:06 +00:00
|
|
|
if ( wcDepMap[ request ] ) {
|
|
|
|
return wcDepMap[ request ];
|
|
|
|
}
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|
|
|
|
|
2021-05-25 09:46:28 +00:00
|
|
|
const requestToExternalInsideGB = ( request ) => {
|
|
|
|
if ( request === 'wordpress-components' ) {
|
|
|
|
return [ 'wp', 'components' ];
|
|
|
|
}
|
|
|
|
return requestToExternal( request );
|
|
|
|
};
|
|
|
|
|
2020-07-07 09:05:06 +00:00
|
|
|
const requestToHandle = ( request ) => {
|
2020-12-03 13:04:25 +00:00
|
|
|
if ( requiredPackagesInWPLegacy.includes( request ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-07 09:05:06 +00:00
|
|
|
if ( wcHandleMap[ request ] ) {
|
|
|
|
return wcHandleMap[ request ];
|
|
|
|
}
|
2020-03-30 12:07:49 +00:00
|
|
|
};
|
|
|
|
|
2021-05-25 09:46:28 +00:00
|
|
|
const requestToHandleInsideGB = ( request ) => {
|
|
|
|
if ( request === 'wordpress-components' ) {
|
|
|
|
return 'wp-components';
|
|
|
|
}
|
|
|
|
return requestToHandle( request );
|
|
|
|
};
|
|
|
|
|
2021-06-29 11:18:29 +00:00
|
|
|
const getProgressBarPluginConfig = ( name, fileSuffix ) => {
|
|
|
|
const isLegacy = fileSuffix && fileSuffix === 'legacy';
|
|
|
|
const progressBarPrefix = isLegacy ? 'Legacy ' : '';
|
|
|
|
return {
|
|
|
|
format:
|
|
|
|
chalk.blue( `Building ${ progressBarPrefix }${ name }` ) +
|
|
|
|
' [:bar] ' +
|
|
|
|
chalk.green( ':percent' ) +
|
|
|
|
' :msg (:elapsed seconds)',
|
|
|
|
summary: false,
|
|
|
|
customSummary: ( time ) => {
|
|
|
|
console.log(
|
|
|
|
chalk.green.bold(
|
|
|
|
`${ progressBarPrefix }${ name } assets build completed (${ time })`
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-10-06 12:36:15 +00:00
|
|
|
module.exports = {
|
2020-07-07 09:05:06 +00:00
|
|
|
NODE_ENV,
|
|
|
|
FORCE_MAP,
|
2021-04-08 12:31:12 +00:00
|
|
|
CHECK_CIRCULAR_DEPS,
|
2019-10-06 12:36:15 +00:00
|
|
|
getAlias,
|
2020-07-07 09:05:06 +00:00
|
|
|
findModuleMatch,
|
|
|
|
requestToHandle,
|
|
|
|
requestToExternal,
|
2021-05-25 09:46:28 +00:00
|
|
|
requestToHandleInsideGB,
|
|
|
|
requestToExternalInsideGB,
|
2021-06-29 11:18:29 +00:00
|
|
|
getProgressBarPluginConfig,
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|