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 32 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
33 changes: 33 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
2 changes: 1 addition & 1 deletion projects/js-packages/webpack-config/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-webpack-config",
"version": "3.2.10",
"version": "3.3.0-alpha",
"description": "Library of pieces for webpack config in Jetpack projects.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/webpack-config/#readme",
"bugs": {
Expand Down
31 changes: 30 additions & 1 deletion projects/js-packages/webpack-config/src/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,36 @@ const DefinePlugin = defines => [
} ),
];

const DependencyExtractionPlugin = options => [ new DependencyExtractionWebpackPlugin( options ) ];
const defaultRequestMap = {
'@automattic/jetpack-publicize-components': {
external: 'JetpackPublicize',
handle: 'jetpack-publicize',
},
'@automattic/jetpack-connection': {
external: 'JetpackConnection',
handle: 'jetpack-connection',
},
};

const DependencyExtractionPlugin = ( { requestMap, ...options } = {} ) => {
const finalRequestMap = { ...defaultRequestMap, ...requestMap };

const requestToExternal = request => {
return finalRequestMap[ request ]?.external;
};

const requestToHandle = request => {
return finalRequestMap[ request ]?.handle;
};

return [
new DependencyExtractionWebpackPlugin( {
requestToExternal,
requestToHandle,
...options,
} ),
];
};

const DuplicatePackageCheckerPlugin = options => [
new DuplicatePackageCheckerWebpackPlugin( options ),
Expand Down
1 change: 1 addition & 0 deletions projects/packages/connection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"watch": "pnpm run build && pnpm webpack watch"
},
"dependencies": {
"@automattic/jetpack-connection": "workspace:*",
"@automattic/jetpack-idc": "workspace:*",
"@wordpress/data": "10.2.0",
"@wordpress/element": "6.2.0"
Expand Down
43 changes: 43 additions & 0 deletions projects/packages/connection/src/class-connection-assets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Connection_Assets.
*
* @package automattic/jetpack-connection
*/

namespace Automattic\Jetpack\Connection;

use Automattic\Jetpack\Assets;

/**
* Connection_Assets class.
*/
class Connection_Assets {

/**
* Initialize the class.
*/
public static function configure() {
add_action( 'wp_loaded', array( __CLASS__, 'register_assets' ) );
}

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

Assets::register_script(
'jetpack-connection',
'../dist/jetpack-connection.js',
__FILE__,
array(
'in_footer' => true,
'textdomain' => 'jetpack-idc',
manzoorwanijk marked this conversation as resolved.
Show resolved Hide resolved
)
);

Initial_State::render_script( 'jetpack-connection' );
}
}
}
1 change: 1 addition & 0 deletions projects/packages/connection/src/js/jetpack-connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@automattic/jetpack-connection';
105 changes: 73 additions & 32 deletions projects/packages/connection/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,55 @@ for ( const file of glob.sync( './src/sso/*.css' ) ) {
ssoEntries[ name ].push( path.resolve( file ) );
}

/**
* @type {import('webpack').Configuration[]} Webpack configuration.
*/
const sharedConfig = {
mode: jetpackWebpackConfig.mode,
devtool: jetpackWebpackConfig.devtool,
output: {
...jetpackWebpackConfig.output,
path: path.resolve( './dist' ),
},
optimization: {
...jetpackWebpackConfig.optimization,
},
resolve: {
...jetpackWebpackConfig.resolve,
},
node: false,
module: {
strictExportPresence: true,
rules: [
// Transpile JavaScript, including node_modules.
jetpackWebpackConfig.TranspileRule(),

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

// Handle CSS.
jetpackWebpackConfig.CssRule( {
extensions: [ 'css', 'sass', 'scss' ],
extraLoaders: [ 'sass-loader' ],
} ),
],
},
externals: {
...jetpackWebpackConfig.externals,
jetpackConfig: JSON.stringify( {
consumer_slug: 'identity_crisis',
} ),
},
};

/**
* @type {import('webpack').Configuration[]} Webpack configuration.
*/
module.exports = [
{
...sharedConfig,
entry: {
'tracks-ajax': './src/js/tracks-ajax.js',
'tracks-callables': {
Expand All @@ -30,47 +77,41 @@ module.exports = [
'identity-crisis': './src/identity-crisis/_inc/admin.jsx',
...ssoEntries,
},
mode: jetpackWebpackConfig.mode,
devtool: jetpackWebpackConfig.devtool,
output: {
...jetpackWebpackConfig.output,
path: path.resolve( './dist' ),
},
optimization: {
...jetpackWebpackConfig.optimization,
},
resolve: {
...jetpackWebpackConfig.resolve,
plugins: [
...jetpackWebpackConfig.StandardPlugins( {
MiniCssExtractPlugin: { filename: '[name].css' },
} ),
],
},
{
...sharedConfig,
entry: {
'jetpack-connection': {
import: './src/js/jetpack-connection.js',
library: {
name: 'JetpackConnection',
type: 'umd',
},
},
},
node: false,
plugins: [
...jetpackWebpackConfig.StandardPlugins( {
MiniCssExtractPlugin: { filename: '[name].css' },
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-connection': {},
},
},
} ),
],
module: {
strictExportPresence: true,
...sharedConfig.module,
rules: [
// Transpile JavaScript, including node_modules.
jetpackWebpackConfig.TranspileRule(),

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

// Handle CSS.
jetpackWebpackConfig.CssRule( {
extensions: [ 'css', 'sass', 'scss' ],
extraLoaders: [ 'sass-loader' ],
} ),
...sharedConfig.module.rules,
// Handle images.
jetpackWebpackConfig.FileRule(),
manzoorwanijk marked this conversation as resolved.
Show resolved Hide resolved
],
},
externals: {
...jetpackWebpackConfig.externals,
jetpackConfig: JSON.stringify( {
consumer_slug: 'identity_crisis',
} ),
},
},
];
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/packages/publicize/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"link-template": "https://github.com/Automattic/jetpack-publicize/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "0.47.x-dev"
"dev-trunk": "0.48.x-dev"
}
},
"config": {
Expand Down
12 changes: 11 additions & 1 deletion projects/packages/publicize/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-publicize",
"version": "0.47.3",
"version": "0.48.0-alpha",
"description": "Publicize makes it easy to share your site’s posts on several social media networks automatically when you publish a new post.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/publicize/#readme",
"bugs": {
Expand All @@ -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.2.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.76.0",
"webpack-cli": "4.9.1"
},
"dependencies": {
"@automattic/jetpack-publicize-components": "workspace:*",
"@wordpress/i18n": "5.2.0"
}
}
21 changes: 21 additions & 0 deletions projects/packages/publicize/postcss.config.js
manzoorwanijk marked this conversation as resolved.
Show resolved Hide resolved
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' ),
],
} );
Loading
Loading