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

Fix: wp-scripts command does not generate assets on Windows OS #38348

Merged
merged 2 commits into from
Jan 31, 2022
Merged

Fix: wp-scripts command does not generate assets on Windows OS #38348

merged 2 commits into from
Jan 31, 2022

Conversation

t-hamano
Copy link
Contributor

Description

See: #38343

This PR solves the problem that assets are not generated in the build directory when the wp-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 the filepath 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.

../node_modules/.bin/wp-scripts start
../node_modules/.bin/wp-scripts start --hot
../node_modules/.bin/wp-scripts start src/index.js --output-path=custom
../node_modules/.bin/wp-scripts build

Make sure that the assets are generated in the gutenpride/build directory.

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).
  • I've updated related schemas if appropriate.

@gziolo
Copy link
Member

gziolo commented Jan 30, 2022

@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, '/' );
Copy link
Member

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 /?

Copy link
Contributor Author

@t-hamano t-hamano Jan 30, 2022

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 }` );

Copy link
Member

@gziolo gziolo Jan 31, 2022

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 👍

@gziolo gziolo added [Package] Scripts /packages/scripts [Type] Bug An existing feature does not function as intended labels Jan 30, 2022
@gziolo gziolo added this to In progress in Core JS Jan 30, 2022
@gziolo gziolo moved this from In progress to Needs review in Core JS Jan 30, 2022
Copy link
Member

@gziolo gziolo left a 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 💯

@gziolo gziolo merged commit 32f35ce into WordPress:trunk Jan 31, 2022
@gziolo gziolo moved this from Needs review to Done in Core JS Jan 31, 2022
@github-actions github-actions bot added this to the Gutenberg 12.6 milestone Jan 31, 2022
gziolo added a commit that referenced this pull request Jan 31, 2022
* Fix: wp-scripts command does not generate assets on Windows OS

* Add CHANGELOG entry

Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Scripts /packages/scripts [Type] Bug An existing feature does not function as intended
Projects
No open projects
Core JS
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants