Dependency Extraction Webpack Plugin: Handle irregular dependency names (https://github.com/woocommerce/woocommerce-admin/pull/5770)

* fix irregular dependency names

* starter pack

* blocks registry

* update docs
This commit is contained in:
Paul Sealock 2020-12-16 08:22:19 +13:00 committed by GitHub
parent 6e2bf974c7
commit 8c8efd59fc
5 changed files with 33 additions and 10 deletions

View File

@ -22,6 +22,6 @@
"devDependencies": {
"@wordpress/scripts": "^12.2.1",
"@woocommerce/eslint-plugin": "1.0.0-beta.0",
"@woocommerce/dependency-extraction-webpack-plugin": "1.0.1"
"@woocommerce/dependency-extraction-webpack-plugin": "1.1.0"
}
}

View File

@ -1,3 +1,7 @@
# 1.1.0
- Fix: Handle irregular package names that don't conform to a pattern.
# 1.0.1
- Fix: Avoid tanspiling packaged code.

View File

@ -26,6 +26,9 @@ module.exports = {
Additional module requests on top of Wordpress [Dependency Extraction Webpack Plugin](https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin) are:
| Request | Global | Script handle |
| ---------------- | --------- | ------------- |
| `@woocommerce/*` | `wc['*']` | `wc-*` |
| Request | Global | Script handle |
| ------------------------------ | ------------------------ | -------------------- |
| `@woocommerce/data` | `wc['data']` | `wc-store-data` |
| `@woocommerce/csv-export` | `wc['csvExport']` | `wc-csv` |
| `@woocommerce/blocks-registry` | `wc['wcBlocksRegistry']` | `wc-blocks-registry` |
| `@woocommerce/*` | `wc['*']` | `wc-*` |

View File

@ -1,6 +1,6 @@
{
"name": "@woocommerce/dependency-extraction-webpack-plugin",
"version": "1.0.1",
"version": "1.1.0",
"description": "WooCommerce Dependency Extraction Webpack Plugin",
"author": "Automattic",
"license": "GPL-2.0-or-later",

View File

@ -19,16 +19,32 @@ function camelCaseDash( string ) {
const wooRequestToExternal = ( request ) => {
if ( packages.includes( request ) ) {
return [
'wc',
camelCaseDash( request.substring( WOOCOMMERCE_NAMESPACE.length ) ),
];
const handle = request.substring( WOOCOMMERCE_NAMESPACE.length );
const irregularExternalMap = {
'blocks-registry': [ 'wc', 'wcBlocksRegistry' ],
};
if ( irregularExternalMap[ handle ] ) {
return irregularExternalMap[ handle ];
}
return [ 'wc', camelCaseDash( handle ) ];
}
};
const wooRequestToHandle = ( request ) => {
if ( packages.includes( request ) ) {
return 'wc-' + request.substring( WOOCOMMERCE_NAMESPACE.length );
const handle = request.substring( WOOCOMMERCE_NAMESPACE.length );
const irregularHandleMap = {
data: 'wc-store-data',
'csv-export': 'wc-csv',
};
if ( irregularHandleMap[ handle ] ) {
return irregularHandleMap[ handle ];
}
return 'wc-' + handle;
}
};