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

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

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ] =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was necessary to prevent an eslint error regarding the scope of the basename variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to completely rename one of these basenames, maybe this one should become fileBasename? The _ prefix often indicates unused or private variables and I think this can be more descriptive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly. I updated it that way.

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
Loading