-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix: wp-scripts command does not generate assets on Windows OS #38348
Conversation
@t-hamano, thank you for opening this PR so quickly. I haven’t tested it yet, but it’s very likely that’s the way to go. It also made me think that we should start testing Create Block using GitHub Actions for all three envs to catch those subtle differences. I will set it up separately next week. |
@@ -202,7 +203,7 @@ function getWebpackEntryPoints() { | |||
const filepath = join( | |||
dirname( blockMetadataFile ), | |||
value.replace( 'file:', '' ) | |||
); | |||
).replace( /\\/g, '/' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean that it works incorrectly on Windows at split
call with src/
? Mayb we could use path.sep
instead of /
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean that it works incorrectly on Windows at split call with src/?
Yes.
I couldn't find any official documentation, but it seems to be converted to a backslash on Windows when passing through path.join
.
Like this:
const filepath = join(
dirname( blockMetadataFile ),
value.replace( 'file:', '' )
);
console.log( dirname( blockMetadataFile ) );
console.log( filepath );
Output:
D:/path/to/gutenberg/gutennpride/src
D:\path\to\gutenberg\gutennpride\src\index.js
Therefore, we need to replace the separator in the filepath
variable with a forward slash.
Alternatively, the following will also work.
const [ , entryName ] = filepath
.split( '.' )[ 0 ]
.split( `src${ sep }` );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, let’s use what you already have working 😃
I wanted to understand the issue better 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I included a new CHANGELOG entry with the anticipation of the bug fix release later today. Thank you for fixing the issue with so detailed explanation 💯
* Fix: wp-scripts command does not generate assets on Windows OS * Add CHANGELOG entry Co-authored-by: Greg Ziółkowski <[email protected]>
Description
See: #38343
This PR solves the problem that assets are not generated in the
build
directory when thewp-scripts
command is executed in Windows OS.I think this problem is caused by the fact that in the process of parsing the metadata in
block.json
, the entry point is not detected correctly because thefilepath
has a backslash in Windows OS.Testing Instructions
Check out this branch and run
create-block
in the gutenberg repository with the option to not install wp-script.npx @wordpress/create-block gutennpride --no-wp-scripts
Move to the directory where it was created.
cd gutenpride
Run the following command using the local wp-scripts.
Make sure that the assets are generated in the gutenpride/build directory.
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).