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
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

## 20.0.2 (2022-01-31)

### Bug Fix

- Fix the `build` command that does not generate assets on Windows OS [#38348](https://github.com/WordPress/gutenberg/pull/38348).

## 20.0.1 (2022-01-28)

### Bug Fix
Expand Down
3 changes: 2 additions & 1 deletion packages/scripts/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function getWebpackEntryPoints() {
const blockMetadataFiles = glob( 'src/**/block.json', {
absolute: true,
} );

if ( blockMetadataFiles.length > 0 ) {
return blockMetadataFiles.reduce(
( accumulator, blockMetadataFile ) => {
Expand All @@ -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 👍


// Takes the path without the file extension, and relative to the `src` directory.
const [ , entryName ] = filepath
Expand Down