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
  • Loading branch information
t-hamano committed Sep 11, 2024
1 parent 0c0e605 commit 2711b7a
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, _basename ] =
absoluteFilename.match(
new RegExp(
`([\\w-]+)${ escapeRegExp(
sep
) }([\\w-]+)\\.php$`
)
);

if ( basename === 'index' ) {
if ( _basename === 'index' ) {
return join( to, `${ dirname }.php` );
}
return join( to, dirname, `${ basename }.php` );
return join(
to,
dirname,
`${ _basename }.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 2711b7a

Please sign in to comment.