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

RTLCSS Fix #68493

Closed
wants to merge 15 commits into from
871 changes: 817 additions & 54 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/scripts/config/babel-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
const babelJest = require( 'babel-jest' );

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

module.exports = babelJestInterop.createTransformer( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async function readConfig() {
return merge( {}, defaultConfig, localConfig );
}

// TODO: puppeteer now supports FireFox, this needs updating: https://hacks.mozilla.org/2024/08/puppeteer-support-for-firefox/
function getPuppeteer( { browser } ) {
switch ( browser.toLowerCase() ) {
case 'chromium':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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

class GithubActionsReporter {
async onRunComplete( _contexts, _aggregatedResults ) {
Expand Down
56 changes: 31 additions & 25 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ 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 CssMinimizerPlugin = require( 'css-minimizer-webpack-plugin' );
const TerserPlugin = require( 'terser-webpack-plugin' );
const { realpathSync } = require( 'fs' );
const { sync: glob } = require( 'fast-glob' );
Expand All @@ -23,7 +25,6 @@ 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 Down Expand Up @@ -72,25 +73,7 @@ const cssLoaders = [
postcssOptions: {
ident: 'postcss',
sourceMap: ! isProduction,
plugins: isProduction
? [
...postcssPlugins,
require( 'cssnano' )( {
// Provide a fallback configuration if there's not
// one explicitly available in the project.
...( ! hasCssnanoConfig() && {
preset: [
'default',
{
discardComments: {
removeAll: true,
},
},
],
} ),
} ),
]
: postcssPlugins,
plugins: postcssPlugins,
},
} ),
},
Expand Down Expand Up @@ -149,12 +132,30 @@ const baseConfig = {
},
extractComments: false,
} ),
...( isProduction
? [
new CssMinimizerPlugin( {
minimizerOptions: {
preset: hasCssnanoConfig()
? undefined
: [
'default',
{
discardComments: {
removeAll: true,
},
},
],
},
} ),
]
: [] ),
],
},
module: {
rules: [
{
test: /\.m?(j|t)sx?$/,
test: /\.m?([jt])sx?$/,
exclude: /node_modules/,
use: [
{
Expand Down Expand Up @@ -209,7 +210,7 @@ const baseConfig = {
},
{
test: /\.svg$/,
issuer: /\.(j|t)sx?$/,
issuer: /\.([jt])sx?$/,
use: [ '@svgr/webpack', 'url-loader' ],
type: 'javascript/auto',
},
Expand Down Expand Up @@ -253,7 +254,7 @@ if ( ! isProduction ) {
// Add source-map-loader if devtool is set, whether in dev mode or not.
if ( baseConfig.devtool ) {
baseConfig.module.rules.unshift( {
test: /\.(j|t)sx?$/,
test: /\.([jt])sx?$/,
exclude: [ /node_modules/ ],
use: require.resolve( 'source-map-loader' ),
enforce: 'pre',
Expand Down Expand Up @@ -313,7 +314,7 @@ const scriptConfig = {
noErrorOnMissing: true,
transform( content, absoluteFrom ) {
const convertExtension = ( path ) => {
return path.replace( /\.m?(j|t)sx?$/, '.js' );
return path.replace( /\.m?([jt])sx?$/, '.js' );
};

if ( basename( absoluteFrom ) === 'block.json' ) {
Expand Down Expand Up @@ -396,7 +397,12 @@ const scriptConfig = {
filename: '[name].css',
} ),
// RtlCssPlugin to generate RTL CSS files.
new RtlCssPlugin(),
new RtlCssPlugin( {
fileNameMap: {
'.css': '[name]-rtl.css',
},
sourceMap: ! isProduction,
} ),
// React Fast Refresh.
hasReactFastRefresh && new ReactRefreshWebpackPlugin(),
// WP_NO_EXTERNALS global variable controls whether scripts' assets get
Expand Down
4 changes: 2 additions & 2 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"copy-webpack-plugin": "^10.2.0",
"cross-spawn": "^7.0.6",
"css-loader": "^6.2.0",
"cssnano": "^6.0.1",
"css-minimizer-webpack-plugin": "^7.0.0",
"cwd": "^0.10.0",
"dir-glob": "^3.0.1",
"eslint": "^8.3.0",
Expand All @@ -81,7 +81,7 @@
"react-refresh": "^0.14.0",
"read-pkg-up": "^7.0.1",
"resolve-bin": "^0.4.0",
"rtlcss": "^4.3.0",
"rtlcss-webpack-plugin": "npm:@smushytaco/rtlcss-webpack-plugin@^2.0.0",
"sass": "^1.54.0",
"sass-loader": "^16.0.3",
"schema-utils": "^4.2.0",
Expand Down
66 changes: 0 additions & 66 deletions packages/scripts/plugins/rtlcss-webpack-plugin/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/scripts/scripts/plugin-zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const zip = new AdmZip();
const zipRootFolderArg = getArgFromCLI( '--root-folder' );
const noRootFolderArg = getArgFromCLI( '--no-root-folder' );
let zipRootFolder = `${ name }/`;
let files = [];
let files;

if ( hasPackageProp( 'files' ) ) {
stdout.write(
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const hasCssnanoConfig = () =>
*
* @param {"e2e"|"unit"} suffix Suffix of configuration file to accept.
*
* @return {string= | undefined} Override or fallback configuration file path.
* @return {string | undefined} Override or fallback configuration file path.
*/
function getJestOverrideConfigFile( suffix ) {
if ( hasArgInCLI( '-c' ) || hasArgInCLI( '--config' ) ) {
Expand Down
Loading