Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JS entry point for block editor. #9985

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions assets/js/googlesitekit-reader-revenue-manager-block-editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Reader Revenue Manager module's block editor entrypoint.
*
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
17 changes: 16 additions & 1 deletion includes/Modules/Reader_Revenue_Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Google\Site_Kit\Modules;

use Exception;
use Google\Site_Kit\Core\Assets\Asset;
use Google\Site_Kit\Core\Assets\Script;
use Google\Site_Kit\Core\Authentication\Clients\Google_Site_Kit_Client;
use Google\Site_Kit\Core\Modules\Module;
Expand All @@ -32,6 +33,7 @@
use Google\Site_Kit\Core\Site_Health\Debug_Data;
use Google\Site_Kit\Core\Tags\Guards\Tag_Environment_Type_Guard;
use Google\Site_Kit\Core\Tags\Guards\Tag_Verify_Guard;
use Google\Site_Kit\Core\Util\Feature_Flags;
use Google\Site_Kit\Core\Util\URL;
use Google\Site_Kit\Modules\Reader_Revenue_Manager\Settings;
use Google\Site_Kit\Modules\Reader_Revenue_Manager\Synchronize_OnboardingState;
Expand Down Expand Up @@ -383,7 +385,7 @@ function ( $url ) {
protected function setup_assets() {
$base_url = $this->context->url( 'dist/assets/' );

return array(
$assets = array(
new Script(
'googlesitekit-modules-reader-revenue-manager',
array(
Expand All @@ -400,6 +402,19 @@ protected function setup_assets() {
)
),
);

if ( Feature_Flags::enabled( 'rrmModuleV2' ) ) {
$assets[] = new Script(
'googlesitekit-reader-revenue-manager-block-editor',
array(
'src' => $base_url . 'js/googlesitekit-reader-revenue-manager-block-editor.js',
'dependencies' => array(),
'load_contexts' => array( Asset::CONTEXT_ADMIN_POST_EDITOR ),
)
);
}

return $assets;
}

/**
Expand Down
30 changes: 30 additions & 0 deletions tests/phpunit/integration/Modules/Reader_Revenue_ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,36 @@ public function test_check_service_entity_access_no_access_unavailable_publicati
$this->assertEquals( false, $access );
}

public function test_block_editor_script_enqueued() {
$this->enable_feature( 'rrmModuleV2' );

$registerable_asset_handles = array_map(
function ( $asset ) {
return $asset->get_handle();
},
$this->reader_revenue_manager->get_assets()
);

$this->assertContains(
techanvil marked this conversation as resolved.
Show resolved Hide resolved
'googlesitekit-reader-revenue-manager-block-editor',
$registerable_asset_handles
);
}

public function test_block_editor_script_not_enqueued() {
$registerable_asset_handles = array_map(
function ( $asset ) {
return $asset->get_handle();
},
$this->reader_revenue_manager->get_assets()
);

$this->assertNotContains(
'googlesitekit-reader-revenue-manager-block-editor',
$registerable_asset_handles
);
}

/**
* @return Module_With_Scopes
*/
Expand Down
4 changes: 4 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
const { createRules } = require( './webpack/common' );
const adminCssConfig = require( './webpack/adminCss.config' );
const basicModulesConfig = require( './webpack/basicModules.config' );
const blockEditorConfig = require( './webpack/blockEditor.config' );
const frontendModules = require( './webpack/frontendModules.config' );
const modulesConfig = require( './webpack/modules.config' );
const testBundleConfig = require( './webpack/testBundle.config' );
Expand All @@ -45,6 +46,9 @@ function* webpackConfig( env, argv ) {
// Build modules that will be used on the frontend, that require wider browser support.
yield frontendModules( mode );

// Build the block editor js.
yield blockEditorConfig( mode );

// Build the main plugin admin css.
yield adminCssConfig( mode );
}
Expand Down
81 changes: 81 additions & 0 deletions webpack/blockEditor.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Block editor config webpack partial.
*
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
const CircularDependencyPlugin = require( 'circular-dependency-plugin' );
const ESLintPlugin = require( 'eslint-webpack-plugin' );
const ManifestPlugin = require( 'webpack-manifest-plugin' );
const WebpackBar = require( 'webpackbar' );

/**
* Internal dependencies
*/
const {
rootDir,
manifestArgs,
resolve,
gutenbergExternals,
createRules,
createMinimizerRules,
} = require( './common' );

module.exports = ( mode ) => ( {
entry: {
'googlesitekit-reader-revenue-manager-block-editor':
'./assets/js/googlesitekit-reader-revenue-manager-block-editor.js',
},
externals: gutenbergExternals,
output: {
filename:
mode === 'production' ? '[name]-[contenthash].js' : '[name].js',
path: rootDir + '/dist/assets/js',
publicPath: '',
},
module: {
rules: createRules( mode ),
},
plugins: [
new WebpackBar( {
name: 'Block Editor Entry Points',
color: '#deff13',
} ),
new CircularDependencyPlugin( {
exclude: /node_modules/,
failOnError: true,
allowAsyncCycles: false,
cwd: process.cwd(),
} ),
new ManifestPlugin( {
...manifestArgs( mode ),
filter( file ) {
return ( file.name || '' ).match( /\.js$/ );
},
} ),
new ESLintPlugin( {
emitError: true,
emitWarning: true,
failOnError: true,
} ),
],
optimization: {
minimizer: createMinimizerRules( mode ),
},
resolve,
} );
2 changes: 1 addition & 1 deletion webpack/modules.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ module.exports = ( mode, rules, ANALYZE ) => {
// If multiple webpack runtimes (from different compilations) are used on the
// same webpage, there is a risk of conflicts of on-demand chunks in the global
// namespace.
// See: https://webpack.js.org/configuration/output/#outputjsonpfunction.
// See: https://v4.webpack.js.org/configuration/output/#outputjsonpfunction.
jsonpFunction: '__googlesitekit_webpackJsonp',
},
performance: {
Expand Down
Loading