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

Scripts: Use fork of rtlcss-webpack-plugin to fix issues with deps #68201

Merged
merged 4 commits into from
Dec 24, 2024
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
121 changes: 7 additions & 114 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"redux": "5.0.1",
"resize-observer-polyfill": "1.5.1",
"rimraf": "5.0.10",
"rtlcss": "4.0.0",
"rtlcss": "4.3.0",
"sass": "1.50.1",
"sass-loader": "16.0.3",
"semver": "7.5.4",
Expand Down
4 changes: 4 additions & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- The bundled `rtlcss-webpack-plugin` dependency has been replaced with a modified fork of the plugin to fix issues with the original package ([#68201](https://github.com/WordPress/gutenberg/pull/68201)).

## 30.7.0 (2024-12-11)

### Internal
Expand Down
8 changes: 3 additions & 5 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const browserslist = require( 'browserslist' );
const MiniCSSExtractPlugin = require( 'mini-css-extract-plugin' );
const { basename, dirname, relative, resolve, sep } = require( 'path' );
const ReactRefreshWebpackPlugin = require( '@pmmmwh/react-refresh-webpack-plugin' );
const RtlCssPlugin = require( 'rtlcss-webpack-plugin' );
const TerserPlugin = require( 'terser-webpack-plugin' );
const { realpathSync } = require( 'fs' );
const { sync: glob } = require( 'fast-glob' );
Expand All @@ -23,6 +22,8 @@ const postcssPlugins = require( '@wordpress/postcss-plugins-preset' );
/**
* Internal dependencies
*/
const PhpFilePathsPlugin = require( '../plugins/php-file-paths-plugin' );
const RtlCssPlugin = require( '../plugins/rtlcss-webpack-plugin' );
const {
fromConfigRoot,
hasBabelConfig,
Expand All @@ -35,7 +36,6 @@ const {
getBlockJsonModuleFields,
getBlockJsonScriptFields,
fromProjectRoot,
PhpFilePathsPlugin,
} = require( '../utils' );

const isProduction = process.env.NODE_ENV === 'production';
Expand Down Expand Up @@ -396,9 +396,7 @@ const scriptConfig = {
filename: '[name].css',
} ),
// RtlCssPlugin to generate RTL CSS files.
new RtlCssPlugin( {
filename: `[name]-rtl.css`,
} ),
new RtlCssPlugin(),
// React Fast Refresh.
hasReactFastRefresh && new ReactRefreshWebpackPlugin(),
// WP_NO_EXTERNALS global variable controls whether scripts' assets get
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"react-refresh": "^0.14.0",
"read-pkg-up": "^7.0.1",
"resolve-bin": "^0.4.0",
"rtlcss-webpack-plugin": "^4.0.7",
"rtlcss": "^4.3.0",
"sass": "^1.50.1",
"sass-loader": "^16.0.3",
"schema-utils": "^4.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { validate } = require( 'schema-utils' );
/**
* Internal dependencies
*/
const { getPhpFilePaths } = require( './config' );
const { getPhpFilePaths } = require( '../../utils' );

const phpFilePathsPluginSchema = {
type: 'object',
Expand Down Expand Up @@ -57,4 +57,4 @@ class PhpFilePathsPlugin {
}
}

module.exports = { PhpFilePathsPlugin };
module.exports = PhpFilePathsPlugin;
66 changes: 66 additions & 0 deletions packages/scripts/plugins/rtlcss-webpack-plugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Parts of this source were derived and modified from the package
* rtlcss-webpack-plugin, released under the MIT license.
*
* https://github.com/wix-incubator/rtlcss-webpack-plugin
*
* Copyright (c) 2018 Wix.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/**
* External dependencies
*/
const path = require( 'node:path' );
const rtlcss = require( 'rtlcss' );
const webpack = require( 'webpack' );

const cssOnly = ( filename ) => path.extname( filename ) === '.css';

class RtlCssPlugin {
processAssets = ( compilation, callback ) => {
const chunks = Array.from( compilation.chunks );

// Explore each chunk (build output):
chunks.forEach( ( chunk ) => {
// Explore each asset filename generated by the chunk:
const files = Array.from( chunk.files );

files.filter( cssOnly ).forEach( ( filename ) => {
// Get the asset source for each file generated by the chunk:
const src = compilation.assets[ filename ].source();
const dst = rtlcss.process( src );
const dstFileName = compilation.getPath( '[name]-rtl.css', {
chunk,
cssFileName: filename,
} );

compilation.assets[ dstFileName ] =
new webpack.sources.RawSource( dst );
chunk.files.add( dstFileName );
} );
} );

callback();
};

apply( compiler ) {
compiler.hooks.compilation.tap( 'RtlCssPlugin', ( compilation ) => {
compilation.hooks.processAssets.tapAsync(
{
name: 'TPAStylePlugin.pluginName',
stage: compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
},
( chunks, callback ) =>
this.processAssets( compilation, callback )
);
} );
}
}

module.exports = RtlCssPlugin;
2 changes: 0 additions & 2 deletions packages/scripts/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const {
getBlockJsonModuleFields,
getBlockJsonScriptFields,
} = require( './block-json' );
const { PhpFilePathsPlugin } = require( './php-file-paths-plugin' );

module.exports = {
fromProjectRoot,
Expand All @@ -56,6 +55,5 @@ module.exports = {
hasPostCSSConfig,
hasPrettierConfig,
hasProjectFile,
PhpFilePathsPlugin,
spawnScript,
};
2 changes: 1 addition & 1 deletion tools/webpack/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { realpathSync } = require( 'fs' );
/**
* WordPress dependencies
*/
const { PhpFilePathsPlugin } = require( '@wordpress/scripts/utils' );
const PhpFilePathsPlugin = require( '@wordpress/scripts/plugins/php-file-paths-plugin' );

/**
* Internal dependencies
Expand Down
Loading