Skip to content

Commit af0e277

Browse files
gziolomanzoorwanijkstein2nd
authored
Scripts: Use fork of rtlcss-webpack-plugin to fix issues with deps (#68201)
* Scripts: Use fork of `rtlcss-webpack-plugin` to fix issues with dependencies * Update the changelog entry * Fix path in the moved plugin * Fix path to PhpFilePathsPlugin in webpack config Co-authored-by: gziolo <[email protected]> Co-authored-by: manzoorwanijk <[email protected]> Co-authored-by: stein2nd <[email protected]>
1 parent 500883f commit af0e277

File tree

9 files changed

+85
-126
lines changed

9 files changed

+85
-126
lines changed

package-lock.json

+7-114
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
"redux": "5.0.1",
153153
"resize-observer-polyfill": "1.5.1",
154154
"rimraf": "5.0.10",
155-
"rtlcss": "4.0.0",
155+
"rtlcss": "4.3.0",
156156
"sass": "1.50.1",
157157
"sass-loader": "16.0.3",
158158
"semver": "7.5.4",

packages/scripts/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Internal
6+
7+
- 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)).
8+
59
## 30.7.0 (2024-12-11)
610

711
### Internal

packages/scripts/config/webpack.config.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const browserslist = require( 'browserslist' );
99
const MiniCSSExtractPlugin = require( 'mini-css-extract-plugin' );
1010
const { basename, dirname, relative, resolve, sep } = require( 'path' );
1111
const ReactRefreshWebpackPlugin = require( '@pmmmwh/react-refresh-webpack-plugin' );
12-
const RtlCssPlugin = require( 'rtlcss-webpack-plugin' );
1312
const TerserPlugin = require( 'terser-webpack-plugin' );
1413
const { realpathSync } = require( 'fs' );
1514
const { sync: glob } = require( 'fast-glob' );
@@ -23,6 +22,8 @@ const postcssPlugins = require( '@wordpress/postcss-plugins-preset' );
2322
/**
2423
* Internal dependencies
2524
*/
25+
const PhpFilePathsPlugin = require( '../plugins/php-file-paths-plugin' );
26+
const RtlCssPlugin = require( '../plugins/rtlcss-webpack-plugin' );
2627
const {
2728
fromConfigRoot,
2829
hasBabelConfig,
@@ -35,7 +36,6 @@ const {
3536
getBlockJsonModuleFields,
3637
getBlockJsonScriptFields,
3738
fromProjectRoot,
38-
PhpFilePathsPlugin,
3939
} = require( '../utils' );
4040

4141
const isProduction = process.env.NODE_ENV === 'production';
@@ -396,9 +396,7 @@ const scriptConfig = {
396396
filename: '[name].css',
397397
} ),
398398
// RtlCssPlugin to generate RTL CSS files.
399-
new RtlCssPlugin( {
400-
filename: `[name]-rtl.css`,
401-
} ),
399+
new RtlCssPlugin(),
402400
// React Fast Refresh.
403401
hasReactFastRefresh && new ReactRefreshWebpackPlugin(),
404402
// WP_NO_EXTERNALS global variable controls whether scripts' assets get

packages/scripts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"react-refresh": "^0.14.0",
8181
"read-pkg-up": "^7.0.1",
8282
"resolve-bin": "^0.4.0",
83-
"rtlcss-webpack-plugin": "^4.0.7",
83+
"rtlcss": "^4.3.0",
8484
"sass": "^1.50.1",
8585
"sass-loader": "^16.0.3",
8686
"schema-utils": "^4.2.0",

packages/scripts/utils/php-file-paths-plugin.js packages/scripts/plugins/php-file-paths-plugin/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { validate } = require( 'schema-utils' );
66
/**
77
* Internal dependencies
88
*/
9-
const { getPhpFilePaths } = require( './config' );
9+
const { getPhpFilePaths } = require( '../../utils' );
1010

1111
const phpFilePathsPluginSchema = {
1212
type: 'object',
@@ -57,4 +57,4 @@ class PhpFilePathsPlugin {
5757
}
5858
}
5959

60-
module.exports = { PhpFilePathsPlugin };
60+
module.exports = PhpFilePathsPlugin;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Parts of this source were derived and modified from the package
3+
* rtlcss-webpack-plugin, released under the MIT license.
4+
*
5+
* https://github.com/wix-incubator/rtlcss-webpack-plugin
6+
*
7+
* Copyright (c) 2018 Wix.com
8+
*
9+
* 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:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12+
*
13+
* 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.
14+
*/
15+
16+
/**
17+
* External dependencies
18+
*/
19+
const path = require( 'node:path' );
20+
const rtlcss = require( 'rtlcss' );
21+
const webpack = require( 'webpack' );
22+
23+
const cssOnly = ( filename ) => path.extname( filename ) === '.css';
24+
25+
class RtlCssPlugin {
26+
processAssets = ( compilation, callback ) => {
27+
const chunks = Array.from( compilation.chunks );
28+
29+
// Explore each chunk (build output):
30+
chunks.forEach( ( chunk ) => {
31+
// Explore each asset filename generated by the chunk:
32+
const files = Array.from( chunk.files );
33+
34+
files.filter( cssOnly ).forEach( ( filename ) => {
35+
// Get the asset source for each file generated by the chunk:
36+
const src = compilation.assets[ filename ].source();
37+
const dst = rtlcss.process( src );
38+
const dstFileName = compilation.getPath( '[name]-rtl.css', {
39+
chunk,
40+
cssFileName: filename,
41+
} );
42+
43+
compilation.assets[ dstFileName ] =
44+
new webpack.sources.RawSource( dst );
45+
chunk.files.add( dstFileName );
46+
} );
47+
} );
48+
49+
callback();
50+
};
51+
52+
apply( compiler ) {
53+
compiler.hooks.compilation.tap( 'RtlCssPlugin', ( compilation ) => {
54+
compilation.hooks.processAssets.tapAsync(
55+
{
56+
name: 'TPAStylePlugin.pluginName',
57+
stage: compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
58+
},
59+
( chunks, callback ) =>
60+
this.processAssets( compilation, callback )
61+
);
62+
} );
63+
}
64+
}
65+
66+
module.exports = RtlCssPlugin;

packages/scripts/utils/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const {
2929
getBlockJsonModuleFields,
3030
getBlockJsonScriptFields,
3131
} = require( './block-json' );
32-
const { PhpFilePathsPlugin } = require( './php-file-paths-plugin' );
3332

3433
module.exports = {
3534
fromProjectRoot,
@@ -56,6 +55,5 @@ module.exports = {
5655
hasPostCSSConfig,
5756
hasPrettierConfig,
5857
hasProjectFile,
59-
PhpFilePathsPlugin,
6058
spawnScript,
6159
};

tools/webpack/blocks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { realpathSync } = require( 'fs' );
88
/**
99
* WordPress dependencies
1010
*/
11-
const { PhpFilePathsPlugin } = require( '@wordpress/scripts/utils' );
11+
const PhpFilePathsPlugin = require( '@wordpress/scripts/plugins/php-file-paths-plugin' );
1212

1313
/**
1414
* Internal dependencies

0 commit comments

Comments
 (0)