Skip to content

Commit

Permalink
Build Tooling: Correctly generate PHP files for server-side rendering…
Browse files Browse the repository at this point in the history
… of blocks on Windows OS (#65248)

* Build Tooling: Correctly generate PHP files for server-side rendering of blocks on Windows OS

* Don't use  prefix

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: sirreal <[email protected]>
  • Loading branch information
3 people authored Sep 12, 2024
1 parent f88e629 commit 92661e7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tools/webpack/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
const { join, sep } = require( 'path' );
const { join, sep, basename } = require( 'path' );
const fastGlob = require( 'fast-glob' );
const { realpathSync } = require( 'fs' );

Expand Down Expand Up @@ -135,23 +135,26 @@ module.exports = [
{
from: `${ from }/**/*.php`,
to( { absoluteFilename } ) {
const [ , dirname, basename ] =
const [ , dirname, fileBasename ] =
absoluteFilename.match(
new RegExp(
`([\\w-]+)${ escapeRegExp(
sep
) }([\\w-]+)\\.php$`
)
);

if ( basename === 'index' ) {
if ( fileBasename === 'index' ) {
return join( to, `${ dirname }.php` );
}
return join( to, dirname, `${ basename }.php` );
return join(
to,
dirname,
`${ fileBasename }.php`
);
},
filter: ( filepath ) => {
return (
filepath.endsWith( sep + 'index.php' ) ||
basename( filepath ) === 'index.php' ||
PhpFilePathsPlugin.paths.includes(
realpathSync( filepath ).replace(
/\\/g,
Expand Down

0 comments on commit 92661e7

Please sign in to comment.