Skip to content

Commit 8b8e1c9

Browse files
committed
RTLCSS Control Directive Fix + Source Maps
1 parent 7129676 commit 8b8e1c9

File tree

9 files changed

+943
-674
lines changed

9 files changed

+943
-674
lines changed

package-lock.json

Lines changed: 905 additions & 577 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/scripts/config/babel-transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
const babelJest = require( 'babel-jest' );
55

6-
// Remove this workaround when https://github.com/facebook/jest/issues/11444 gets resolved in Jest.
6+
// TODO: this was resolved so remove this workaround https://github.com/facebook/jest/issues/11444
77
const babelJestInterop = babelJest.__esModule ? babelJest.default : babelJest;
88

99
module.exports = babelJestInterop.createTransformer( {

packages/scripts/config/jest-environment-puppeteer/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ async function readConfig() {
6666
return merge( {}, defaultConfig, localConfig );
6767
}
6868

69+
// TODO: puppeteer now supports FireFox, this needs updating: https://hacks.mozilla.org/2024/08/puppeteer-support-for-firefox/
6970
function getPuppeteer( { browser } ) {
7071
switch ( browser.toLowerCase() ) {
7172
case 'chromium':

packages/scripts/config/jest-github-actions-reporter/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
const newLine = /\n/g;
1616
const encodedNewLine = '%0A';
17-
const lineAndColumnInStackTrace = /^.*?:([0-9]+):([0-9]+).*$/;
17+
const lineAndColumnInStackTrace = /^.*?:(\d+):(\d+).*$/;
1818

1919
class GithubActionsReporter {
2020
async onRunComplete( _contexts, _aggregatedResults ) {

packages/scripts/config/webpack.config.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ 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' );
13+
const CssMinimizerPlugin = require( 'css-minimizer-webpack-plugin' );
1214
const TerserPlugin = require( 'terser-webpack-plugin' );
1315
const { realpathSync } = require( 'fs' );
1416
const { sync: glob } = require( 'fast-glob' );
@@ -24,7 +26,6 @@ const postcssPlugins = require( '@wordpress/postcss-plugins-preset' );
2426
* Internal dependencies
2527
*/
2628
const PhpFilePathsPlugin = require( '../plugins/php-file-paths-plugin' );
27-
const RtlCssPlugin = require( '../plugins/rtlcss-webpack-plugin' );
2829
const {
2930
fromConfigRoot,
3031
hasBabelConfig,
@@ -75,25 +76,7 @@ const cssLoaders = [
7576
postcssOptions: {
7677
ident: 'postcss',
7778
sourceMap: ! isProduction,
78-
plugins: isProduction
79-
? [
80-
...postcssPlugins,
81-
require( 'cssnano' )( {
82-
// Provide a fallback configuration if there's not
83-
// one explicitly available in the project.
84-
...( ! hasCssnanoConfig() && {
85-
preset: [
86-
'default',
87-
{
88-
discardComments: {
89-
removeAll: true,
90-
},
91-
},
92-
],
93-
} ),
94-
} ),
95-
]
96-
: postcssPlugins,
79+
plugins: postcssPlugins,
9780
},
9881
} ),
9982
},
@@ -152,12 +135,30 @@ const baseConfig = {
152135
},
153136
extractComments: false,
154137
} ),
138+
...( isProduction
139+
? [
140+
new CssMinimizerPlugin( {
141+
minimizerOptions: {
142+
preset: hasCssnanoConfig()
143+
? undefined
144+
: [
145+
'default',
146+
{
147+
discardComments: {
148+
removeAll: true,
149+
},
150+
},
151+
],
152+
},
153+
} ),
154+
]
155+
: [] ),
155156
],
156157
},
157158
module: {
158159
rules: [
159160
{
160-
test: /\.m?(j|t)sx?$/,
161+
test: /\.m?([jt])sx?$/,
161162
exclude: /node_modules/,
162163
use: [
163164
{
@@ -212,7 +213,7 @@ const baseConfig = {
212213
},
213214
{
214215
test: /\.svg$/,
215-
issuer: /\.(j|t)sx?$/,
216+
issuer: /\.([jt])sx?$/,
216217
use: [ '@svgr/webpack', 'url-loader' ],
217218
type: 'javascript/auto',
218219
},
@@ -256,7 +257,7 @@ if ( ! isProduction ) {
256257
// Add source-map-loader if devtool is set, whether in dev mode or not.
257258
if ( baseConfig.devtool ) {
258259
baseConfig.module.rules.unshift( {
259-
test: /\.(j|t)sx?$/,
260+
test: /\.([jt])sx?$/,
260261
exclude: [ /node_modules/ ],
261262
use: require.resolve( 'source-map-loader' ),
262263
enforce: 'pre',
@@ -336,7 +337,7 @@ const scriptConfig = {
336337
noErrorOnMissing: true,
337338
transform( content, absoluteFrom ) {
338339
const convertExtension = ( path ) => {
339-
return path.replace( /\.m?(j|t)sx?$/, '.js' );
340+
return path.replace( /\.m?([jt])sx?$/, '.js' );
340341
};
341342

342343
if ( basename( absoluteFrom ) === 'block.json' ) {
@@ -419,7 +420,12 @@ const scriptConfig = {
419420
filename: '[name].css',
420421
} ),
421422
// RtlCssPlugin to generate RTL CSS files.
422-
new RtlCssPlugin(),
423+
new RtlCssPlugin( {
424+
fileNameMap: {
425+
'.css': '[name]-rtl.css',
426+
},
427+
sourceMap: ! isProduction,
428+
} ),
423429
// Generate blocks manifest after changes.
424430
hasBlocksManifest && new BlocksManifestPlugin(),
425431
// React Fast Refresh.

packages/scripts/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"copy-webpack-plugin": "^10.2.0",
5757
"cross-spawn": "^7.0.6",
5858
"css-loader": "^6.2.0",
59-
"cssnano": "^6.0.1",
59+
"css-minimizer-webpack-plugin": "^7.0.0",
6060
"cwd": "^0.10.0",
6161
"dir-glob": "^3.0.1",
6262
"eslint": "^8.3.0",
@@ -81,7 +81,7 @@
8181
"react-refresh": "^0.14.0",
8282
"read-pkg-up": "^7.0.1",
8383
"resolve-bin": "^0.4.0",
84-
"rtlcss": "^4.3.0",
84+
"rtlcss-webpack-plugin": "npm:@smushytaco/rtlcss-webpack-plugin@^2.0.3",
8585
"sass": "^1.54.0",
8686
"sass-loader": "^16.0.3",
8787
"schema-utils": "^4.2.0",

packages/scripts/plugins/rtlcss-webpack-plugin/index.js

Lines changed: 0 additions & 66 deletions
This file was deleted.

packages/scripts/scripts/plugin-zip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const zip = new AdmZip();
1818
const zipRootFolderArg = getArgFromCLI( '--root-folder' );
1919
const noRootFolderArg = getArgFromCLI( '--no-root-folder' );
2020
let zipRootFolder = `${ name }/`;
21-
let files = [];
21+
let files;
2222

2323
if ( hasPackageProp( 'files' ) ) {
2424
stdout.write(

packages/scripts/utils/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const hasCssnanoConfig = () =>
5555
*
5656
* @param {"e2e"|"unit"} suffix Suffix of configuration file to accept.
5757
*
58-
* @return {string= | undefined} Override or fallback configuration file path.
58+
* @return {string | undefined} Override or fallback configuration file path.
5959
*/
6060
function getJestOverrideConfigFile( suffix ) {
6161
if ( hasArgInCLI( '-c' ) || hasArgInCLI( '--config' ) ) {

0 commit comments

Comments
 (0)