Revert "Revert "fix: export router as a separated package""
This reverts commit 90abc56862
.
This commit is contained in:
parent
0a0b436828
commit
08050b38c0
|
@ -1,8 +1,12 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { store, privateApis, getConfig } from '@woocommerce/interactivity';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { fetchHeadAssets, updateHead } from './head';
|
import { fetchHeadAssets, updateHead } from './head';
|
||||||
import { store, privateApis, getConfig } from './index';
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
directivePrefix,
|
directivePrefix,
|
||||||
|
@ -205,7 +209,7 @@ const isValidEvent = ( event: MouseEvent ) =>
|
||||||
// Variable to store the current navigation.
|
// Variable to store the current navigation.
|
||||||
let navigatingTo = '';
|
let navigatingTo = '';
|
||||||
|
|
||||||
export const { state, actions } = store( 'core/router', {
|
export const { state, actions } = store( 'woocommerce/router', {
|
||||||
state: {
|
state: {
|
||||||
url: window.location.href,
|
url: window.location.href,
|
||||||
navigation: {
|
navigation: {
|
|
@ -18,7 +18,6 @@ import { getNamespace } from './namespaces';
|
||||||
import { parseServerData, populateServerData } from './store';
|
import { parseServerData, populateServerData } from './store';
|
||||||
import { proxifyState } from './proxies';
|
import { proxifyState } from './proxies';
|
||||||
|
|
||||||
export { navigate } from './router';
|
|
||||||
export { store, getConfig } from './store';
|
export { store, getConfig } from './store';
|
||||||
export { getContext, getElement } from './scopes';
|
export { getContext, getElement } from './scopes';
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -952,12 +952,13 @@ const getInteractivityAPIConfig = ( options = {} ) => {
|
||||||
const { alias, resolvePlugins = [] } = options;
|
const { alias, resolvePlugins = [] } = options;
|
||||||
return {
|
return {
|
||||||
entry: {
|
entry: {
|
||||||
'wc-interactivity': './assets/js/interactivity',
|
interactivity: './assets/js/interactivity',
|
||||||
|
'interactivity-router': './assets/js/interactivity-router',
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
filename: '[name].js',
|
filename: 'wc-[name].js',
|
||||||
path: path.resolve( __dirname, '../build/' ),
|
path: path.resolve( __dirname, '../build/' ),
|
||||||
library: [ 'wc', '__experimentalInteractivity' ],
|
library: [ 'wc', '__experimentalInteractivity', '[name]' ],
|
||||||
libraryTarget: 'this',
|
libraryTarget: 'this',
|
||||||
chunkLoadingGlobal: 'webpackWcBlocksJsonp',
|
chunkLoadingGlobal: 'webpackWcBlocksJsonp',
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,7 +18,16 @@ const wcDepMap = {
|
||||||
'@woocommerce/price-format': [ 'wc', 'priceFormat' ],
|
'@woocommerce/price-format': [ 'wc', 'priceFormat' ],
|
||||||
'@woocommerce/blocks-checkout': [ 'wc', 'blocksCheckout' ],
|
'@woocommerce/blocks-checkout': [ 'wc', 'blocksCheckout' ],
|
||||||
'@woocommerce/blocks-components': [ 'wc', 'blocksComponents' ],
|
'@woocommerce/blocks-components': [ 'wc', 'blocksComponents' ],
|
||||||
'@woocommerce/interactivity': [ 'wc', '__experimentalInteractivity' ],
|
'@woocommerce/interactivity': [
|
||||||
|
'wc',
|
||||||
|
'__experimentalInteractivity',
|
||||||
|
'interactivity',
|
||||||
|
],
|
||||||
|
'@woocommerce/interactivity-router': [
|
||||||
|
'wc',
|
||||||
|
'__experimentalInteractivity',
|
||||||
|
'interactivity-router',
|
||||||
|
],
|
||||||
'@woocommerce/types': [ 'wc', 'wcTypes' ],
|
'@woocommerce/types': [ 'wc', 'wcTypes' ],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,6 +42,7 @@ const wcHandleMap = {
|
||||||
'@woocommerce/blocks-checkout': 'wc-blocks-checkout',
|
'@woocommerce/blocks-checkout': 'wc-blocks-checkout',
|
||||||
'@woocommerce/blocks-components': 'wc-blocks-components',
|
'@woocommerce/blocks-components': 'wc-blocks-components',
|
||||||
'@woocommerce/interactivity': 'wc-interactivity',
|
'@woocommerce/interactivity': 'wc-interactivity',
|
||||||
|
'@woocommerce/interactivity-router': 'wc-interactivity-router',
|
||||||
'@woocommerce/types': 'wc-types',
|
'@woocommerce/types': 'wc-types',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,6 +78,10 @@ const getAlias = ( options = {} ) => {
|
||||||
__dirname,
|
__dirname,
|
||||||
`../assets/js/${ pathPart }interactivity/`
|
`../assets/js/${ pathPart }interactivity/`
|
||||||
),
|
),
|
||||||
|
'@woocommerce/interactivity-router': path.resolve(
|
||||||
|
__dirname,
|
||||||
|
`../assets/js/${ pathPart }interactivity-router/`
|
||||||
|
),
|
||||||
'@woocommerce/base-utils': path.resolve(
|
'@woocommerce/base-utils': path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
`../assets/js/${ pathPart }base/utils/`
|
`../assets/js/${ pathPart }base/utils/`
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
"@woocommerce/base-hooks": [ "assets/js/base/hooks" ],
|
"@woocommerce/base-hooks": [ "assets/js/base/hooks" ],
|
||||||
"@woocommerce/interactivity": [ "assets/js/interactivity" ],
|
"@woocommerce/interactivity": [ "assets/js/interactivity" ],
|
||||||
"@woocommerce/interactivity/*": [ "assets/js/interactivity/*" ],
|
"@woocommerce/interactivity/*": [ "assets/js/interactivity/*" ],
|
||||||
|
"@woocommerce/interactivity-router": [ "assets/js/interactivity-router" ],
|
||||||
"@woocommerce/base-utils": [ "assets/js/base/utils" ],
|
"@woocommerce/base-utils": [ "assets/js/base/utils" ],
|
||||||
"@woocommerce/base-utils/*": [ "assets/js/base/utils/*" ],
|
"@woocommerce/base-utils/*": [ "assets/js/base/utils/*" ],
|
||||||
"@woocommerce/blocks/*": [ "assets/js/blocks/*" ],
|
"@woocommerce/blocks/*": [ "assets/js/blocks/*" ],
|
||||||
|
|
|
@ -30,24 +30,29 @@ function woocommerce_interactivity_register_runtime() {
|
||||||
$plugin_path = \Automattic\WooCommerce\Blocks\Package::get_path();
|
$plugin_path = \Automattic\WooCommerce\Blocks\Package::get_path();
|
||||||
$plugin_url = plugin_dir_url( $plugin_path . '/index.php' );
|
$plugin_url = plugin_dir_url( $plugin_path . '/index.php' );
|
||||||
|
|
||||||
$file = 'assets/client/blocks/wc-interactivity.js';
|
$files = array(
|
||||||
|
'wc-interactivity' => 'assets/client/blocks/wc-interactivity.js',
|
||||||
$file_path = $plugin_path . $file;
|
'wc-interactivity-router' => 'assets/client/blocks/wc-interactivity-router.js',
|
||||||
$file_url = $plugin_url . $file;
|
|
||||||
|
|
||||||
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && file_exists( $file_path ) ) {
|
|
||||||
$version = filemtime( $file_path );
|
|
||||||
} else {
|
|
||||||
// Use wc- prefix here to prevent collisions when WC Core version catches up to a version previously used by the WC Blocks feature plugin.
|
|
||||||
$version = 'wc-' . Constants::get_constant( 'WC_VERSION' );
|
|
||||||
}
|
|
||||||
|
|
||||||
wp_register_script(
|
|
||||||
'wc-interactivity',
|
|
||||||
$file_url,
|
|
||||||
array(),
|
|
||||||
$version,
|
|
||||||
true
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
foreach ( $files as $handle => $file ) {
|
||||||
|
$file_path = $plugin_path . $file;
|
||||||
|
$file_url = $plugin_url . $file;
|
||||||
|
|
||||||
|
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && file_exists( $file_path ) ) {
|
||||||
|
$version = filemtime( $file_path );
|
||||||
|
} else {
|
||||||
|
// Use wc- prefix here to prevent collisions when WC Core version catches up to a version previously used by the WC Blocks feature plugin.
|
||||||
|
$version = 'wc-' . Constants::get_constant( 'WC_VERSION' );
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_register_script(
|
||||||
|
$handle,
|
||||||
|
$file_url,
|
||||||
|
array(),
|
||||||
|
$version,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
add_action( 'wp_enqueue_scripts', 'woocommerce_interactivity_register_runtime' );
|
add_action( 'wp_enqueue_scripts', 'woocommerce_interactivity_register_runtime' );
|
||||||
|
|
Loading…
Reference in New Issue