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

Unbundle Social JS code from Jetpack and Social #38330

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
9ef64fb
Create webpack utils for dependency extraction
manzoorwanijk Jul 15, 2024
c8b3551
Prepare publicize package for bundling
manzoorwanijk Jul 15, 2024
9d5b441
Register the publicize assets
manzoorwanijk Jul 15, 2024
bdd3df4
Prepare Jetpack plugin to brace the new norm
manzoorwanijk Jul 15, 2024
2524fd6
Prepare social for the reform
manzoorwanijk Jul 15, 2024
23bd3ea
Update pnpm-lock.yaml
manzoorwanijk Jul 15, 2024
d0d5f4d
Ensure that initial state is rendered before publicize handle
manzoorwanijk Jul 15, 2024
21bb40b
Add changelogs
manzoorwanijk Jul 15, 2024
8126aae
Fix up versions
manzoorwanijk Jul 15, 2024
8aa53ca
Update changelogs
manzoorwanijk Jul 16, 2024
719e08c
Use defaultRequestMap for extracting dependencies
manzoorwanijk Jul 16, 2024
55e9edb
Restore comments in postcss.config
manzoorwanijk Jul 16, 2024
1a1960b
Use script handle as entry name in webpack config for publicize
manzoorwanijk Jul 16, 2024
1ebd2b9
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Jul 16, 2024
b456036
Fix up versions
manzoorwanijk Jul 16, 2024
23096ff
Build publicize package for e2e tests
manzoorwanijk Jul 16, 2024
a7f58b8
Allow plugins to override dependency extraction config
manzoorwanijk Jul 16, 2024
deb19eb
Create a standalone class to register assets
manzoorwanijk Jul 16, 2024
311ba28
Directly export publilize components instead of relaying it
manzoorwanijk Jul 16, 2024
92d3668
No need of " || undefined"
manzoorwanijk Jul 16, 2024
324efdc
Add css deps
manzoorwanijk Jul 16, 2024
c32ec63
Unbundle connection components
manzoorwanijk Jul 16, 2024
73039cb
Build connection package for e2e tests
manzoorwanijk Jul 16, 2024
faa407c
Build connection package for search e2e tests
manzoorwanijk Jul 16, 2024
e3f4ced
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Jul 17, 2024
d26a3cd
Fix editor styles for publicize in Jetpack
manzoorwanijk Jul 17, 2024
636ef04
Use a dedicated assets class for connection assets
manzoorwanijk Jul 17, 2024
d5d1d95
Use shared webpack config to ensure only the target bundle is extracted
manzoorwanijk Jul 18, 2024
19378d5
Remove unnecessary css_dependencies
manzoorwanijk Jul 18, 2024
6f857e8
Connection initial state is now handled by the package itself
manzoorwanijk Jul 18, 2024
df24001
Change initial state handle to connection
manzoorwanijk Jul 18, 2024
4c1840f
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Jul 18, 2024
9c1a53e
Move files rule to shared config
manzoorwanijk Jul 19, 2024
ffbdfc2
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Jul 19, 2024
1df8b6f
Fix text domain
manzoorwanijk Jul 19, 2024
269c3c1
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Jul 24, 2024
cc10eb9
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Jul 25, 2024
c20ee3e
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Jul 30, 2024
7546fd8
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Jul 31, 2024
2a0f60c
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 1, 2024
205f2c3
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 3, 2024
21414d5
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 6, 2024
930d6c6
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 6, 2024
97b7635
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 7, 2024
d5a0870
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 7, 2024
83af9bb
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 10, 2024
f81b48a
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 12, 2024
a686816
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 12, 2024
33f3d08
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 16, 2024
9158440
Update pnpm-lock.yaml
manzoorwanijk Aug 16, 2024
eb8838e
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 19, 2024
6f21a89
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 20, 2024
5898c90
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 21, 2024
5c021eb
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Aug 27, 2024
50b25fe
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Sep 3, 2024
0ecb770
Remove unnecessary changes
manzoorwanijk Sep 3, 2024
846a317
Update pnpm-lock.yaml
manzoorwanijk Sep 3, 2024
52e6104
Remove unnecessary changelogs
manzoorwanijk Sep 3, 2024
0996ca2
Fix lints
manzoorwanijk Sep 3, 2024
6e32d81
Merge branch 'trunk' into update/unbundle-publicize-from-jetpack
manzoorwanijk Sep 5, 2024
b48f61c
Update pnpm-lock.yaml
manzoorwanijk Sep 5, 2024
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
30 changes: 30 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Extracted common UI logic from Social to publicize package to load it dynamically at runtime
4 changes: 4 additions & 0 deletions projects/js-packages/webpack-config/src/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ const defaultRequestMap = {
external: 'JetpackConnection',
handle: 'jetpack-connection',
},
'@automattic/jetpack-publicize-components': {
external: 'JetpackPublicize',
handle: 'jetpack-publicize',
},
};

const DependencyExtractionPlugin = ( { requestMap, ...options } = {} ) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Extracted common UI logic from Social to publicize package to load it dynamically at runtime
10 changes: 10 additions & 0 deletions projects/packages/publicize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@
"extends @wordpress/browserslist-config"
],
"devDependencies": {
"@automattic/calypso-color-schemes": "3.1.3",
"@automattic/color-studio": "2.6.0",
"@automattic/jetpack-webpack-config": "workspace:*",
"@csstools/postcss-global-data": "2.1.1",
"@wordpress/browserslist-config": "6.6.0",
"autoprefixer": "10.4.14",
"concurrently": "7.6.0",
"postcss": "8.4.31",
"postcss-custom-properties": "12.1.7",
"postcss-loader": "6.2.0",
"sass": "1.64.1",
"sass-loader": "12.4.0",
"webpack": "5.94.0",
"webpack-cli": "4.9.1"
},
"dependencies": {
"@automattic/jetpack-publicize-components": "workspace:*",
"@wordpress/i18n": "5.6.0"
}
}
21 changes: 21 additions & 0 deletions projects/packages/publicize/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = () => ( {
plugins: [
require( '@csstools/postcss-global-data' )( {
// Provide the properties that postcss-custom-properties is going to work with.
files: [ require.resolve( '@automattic/calypso-color-schemes/root-only/index.css' ) ],
} ),
require( 'postcss-custom-properties' )( {
// Use of `preserve: false` dates back to when we still used @automattic/calypso-build.
// Ideally we'd get rid of it to properly make use of CSS vars, but first we have to
// figure out how to ensure the vars actually get defined in the browser without
// including them in every bundle. Some base stylesheet (wp_register_style) the other
// stylesheets depend on maybe? And also deal with extremely generic vars like "--color-text".
//
// See also https://github.com/Automattic/jetpack/pull/13854#issuecomment-550898168,
// where people were confused about what was going on when calypso-build stopped
// including a postcss.config.js like this by default.
preserve: false,
} ),
require( 'autoprefixer' ),
],
} );
22 changes: 22 additions & 0 deletions projects/packages/publicize/src/class-publicize-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Automattic\Jetpack\Publicize;

use Automattic\Jetpack\Assets;

/**
* Publicize_Assets class.
*/
Expand All @@ -16,6 +18,26 @@ class Publicize_Assets {
* Initialize the class.
*/
public static function configure() {
add_action( 'wp_loaded', array( __CLASS__, 'register_assets' ) );

Publicize_Script_Data::configure();
}

/**
* Register assets.
*/
public static function register_assets() {
if ( ! wp_script_is( 'jetpack-publicize', 'registered' ) ) {

Assets::register_script(
'jetpack-publicize',
'../build/jetpack-publicize.js',
__FILE__,
array(
'in_footer' => true,
'textdomain' => 'jetpack-publicize-pkg',
)
);
}
}
}
1 change: 1 addition & 0 deletions projects/packages/publicize/src/js/jetpack-publicize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@automattic/jetpack-publicize-components';
129 changes: 86 additions & 43 deletions projects/packages/publicize/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,99 @@
const path = require( 'path' );
const jetpackWebpackConfig = require( '@automattic/jetpack-webpack-config/webpack' );

/**
* @type {import('webpack').Configuration[]} Webpack configuration.
*/
const sharedConfig = {
entry: {
'classic-editor-share-limits': './src/js/classic-editor-share-limits.js',
'classic-editor-connections': './src/js/classic-editor-connections.js',
},
mode: jetpackWebpackConfig.mode,
devtool: jetpackWebpackConfig.devtool,
output: {
...jetpackWebpackConfig.output,
path: path.resolve( './build' ),
},
optimization: {
...jetpackWebpackConfig.optimization,
},
resolve: {
...jetpackWebpackConfig.resolve,
},
node: false,
plugins: [ ...jetpackWebpackConfig.StandardPlugins() ],
module: {
strictExportPresence: true,
rules: [
// Transpile JavaScript
jetpackWebpackConfig.TranspileRule( {
exclude: /node_modules\//,
} ),

// Transpile @automattic/* in node_modules too.
jetpackWebpackConfig.TranspileRule( {
includeNodeModules: [ '@automattic/' ],
} ),

// Handle CSS.
jetpackWebpackConfig.CssRule( {
extensions: [ 'css', 'sass', 'scss' ],
extraLoaders: [
{
loader: 'postcss-loader',
options: {
postcssOptions: { config: path.join( __dirname, 'postcss.config.js' ) },
},
},
'sass-loader',
],
} ),

// Handle images.
jetpackWebpackConfig.FileRule(),
],
},
};

/**
* @type {import('webpack').Configuration[]} Webpack configuration.
*/
module.exports = [
{
...sharedConfig,
entry: {
'classic-editor-share-limits': './src/js/classic-editor-share-limits.js',
'classic-editor-connections': './src/js/classic-editor-connections.js',
},
mode: jetpackWebpackConfig.mode,
devtool: jetpackWebpackConfig.devtool,
output: {
...jetpackWebpackConfig.output,
path: path.resolve( './build' ),
},
optimization: {
...jetpackWebpackConfig.optimization,
},
resolve: {
...jetpackWebpackConfig.resolve,
},
node: false,
plugins: [ ...jetpackWebpackConfig.StandardPlugins() ],
module: {
strictExportPresence: true,
rules: [
// Transpile JavaScript
jetpackWebpackConfig.TranspileRule( {
exclude: /node_modules\//,
} ),

// Transpile @automattic/* in node_modules too.
jetpackWebpackConfig.TranspileRule( {
includeNodeModules: [ '@automattic/' ],
} ),

// Handle CSS.
jetpackWebpackConfig.CssRule( {
extensions: [ 'css', 'sass', 'scss' ],
extraLoaders: [
{
loader: 'postcss-loader',
options: {
postcssOptions: { config: path.join( __dirname, 'postcss.config.js' ) },
},
},
'sass-loader',
],
} ),

// Handle images.
jetpackWebpackConfig.FileRule(),
],
},
{
...sharedConfig,
entry: {
'jetpack-publicize': {
import: './src/js/jetpack-publicize.js',
library: {
name: 'JetpackPublicize',
type: 'umd',
},
},
},
externals: {
...jetpackWebpackConfig.externals,
jetpackConfig: JSON.stringify( {
consumer_slug: 'jetpack-publicize',
} ),
},
plugins: [
...jetpackWebpackConfig.StandardPlugins( {
DependencyExtractionPlugin: {
requestMap: {
// We don't want to externalize this package, we rather want to bundle it.
manzoorwanijk marked this conversation as resolved.
Show resolved Hide resolved
'@automattic/jetpack-publicize-components': {},
},
},
} ),
],
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Extracted common UI logic from Jetpack to publicize package to load it dynamically at runtime
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/tests/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"license": "GPL-2.0-or-later",
"author": "Automattic",
"scripts": {
"build": "pnpm jetpack build packages/forms packages/assets packages/connection packages/blaze plugins/jetpack -v --no-pnpm-install --production",
"build": "pnpm jetpack build packages/forms packages/assets packages/connection packages/publicize packages/blaze plugins/jetpack -v --no-pnpm-install --production",
"clean": "rm -rf output",
"config:decrypt": "pnpm test-decrypt-default-config && pnpm test-decrypt-config",
"distclean": "rm -rf node_modules",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Extracted common UI logic from Social to publicize package to load it dynamically at runtime
2 changes: 1 addition & 1 deletion projects/plugins/social/tests/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"license": "GPL-2.0-or-later",
"author": "Automattic",
"scripts": {
"build": "pnpm jetpack build packages/assets packages/connection plugins/social plugins/jetpack -v --no-pnpm-install --production",
"build": "pnpm jetpack build packages/assets packages/connection packages/publicize plugins/social plugins/jetpack -v --no-pnpm-install --production",
"clean": "rm -rf output",
"config:decrypt": "openssl enc -md sha1 -aes-256-cbc -d -pass env:CONFIG_KEY -in ./node_modules/jetpack-e2e-commons/config/encrypted.enc -out ./config/local.cjs",
"distclean": "rm -rf node_modules",
Expand Down
Loading