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

Scripts: Correctly resolve entry points when the directory is symlinked #54212

Merged
merged 4 commits into from Sep 8, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/scripts/CHANGELOG.md
Expand Up @@ -6,6 +6,10 @@

- Added support for `test-playwright` script ([#53108](https://github.com/WordPress/gutenberg/pull/53108)).

### Bug Fix

- Correctly resolve entry points when the directory is symlinked ([#54212](https://github.com/WordPress/gutenberg/pull/54212)).

## 26.12.0 (2023-08-31)

## 26.11.0 (2023-08-16)
Expand Down
5 changes: 4 additions & 1 deletion packages/scripts/config/webpack.config.js
Expand Up @@ -10,6 +10,7 @@ const MiniCSSExtractPlugin = require( 'mini-css-extract-plugin' );
const { basename, dirname, resolve } = require( 'path' );
const ReactRefreshWebpackPlugin = require( '@pmmmwh/react-refresh-webpack-plugin' );
const TerserPlugin = require( 'terser-webpack-plugin' );
const { realpathSync } = require( 'fs' );

/**
* WordPress dependencies
Expand Down Expand Up @@ -302,7 +303,9 @@ const config = {
filter: ( filepath ) => {
return (
process.env.WP_COPY_PHP_FILES_TO_DIST ||
RenderPathsPlugin.renderPaths.includes( filepath )
RenderPathsPlugin.renderPaths.includes(
realpathSync( filepath ).replace( /\\/g, '/' )
)
gziolo marked this conversation as resolved.
Show resolved Hide resolved
);
},
},
Expand Down
38 changes: 18 additions & 20 deletions packages/scripts/utils/config.js
Expand Up @@ -206,12 +206,10 @@ function getWebpackEntryPoints() {

// 2. Checks whether any block metadata files can be detected in the defined source directory.
// It scans all discovered files looking for JavaScript assets and converts them to entry points.
const blockMetadataFiles = glob(
`${ getWordPressSrcDirectory() }/**/block.json`,
{
absolute: true,
}
);
const blockMetadataFiles = glob( '**/block.json', {
absolute: true,
cwd: fromProjectRoot( getWordPressSrcDirectory() ),
} );

if ( blockMetadataFiles.length > 0 ) {
const srcDirectory = fromProjectRoot(
Expand Down Expand Up @@ -260,9 +258,12 @@ function getWebpackEntryPoints() {

// Detects the proper file extension used in the defined source directory.
const [ entryFilepath ] = glob(
`${ getWordPressSrcDirectory() }/${ entryName }.[jt]s?(x)`,
`${ entryName }.[jt]s?(x)`,
{
absolute: true,
cwd: fromProjectRoot(
getWordPressSrcDirectory()
),
}
);

Expand Down Expand Up @@ -302,13 +303,12 @@ function getWebpackEntryPoints() {
}

// 3. Checks whether a standard file name can be detected in the defined source directory,
// and converts the discovered file to entry point.
const [ entryFile ] = glob(
`${ getWordPressSrcDirectory() }/index.[jt]s?(x)`,
{
absolute: true,
}
);
// and converts the discovered file to entry point.
const [ entryFile ] = glob( 'index.[jt]s?(x)', {
absolute: true,
cwd: fromProjectRoot( getWordPressSrcDirectory() ),
} );

if ( ! entryFile ) {
log(
chalk.yellow(
Expand All @@ -335,12 +335,10 @@ function getRenderPropPaths() {
}

// Checks whether any block metadata files can be detected in the defined source directory.
const blockMetadataFiles = glob(
`${ getWordPressSrcDirectory() }/**/block.json`,
{
absolute: true,
}
);
const blockMetadataFiles = glob( '**/block.json', {
absolute: true,
cwd: fromProjectRoot( getWordPressSrcDirectory() ),
} );

const srcDirectory = fromProjectRoot( getWordPressSrcDirectory() + sep );

Expand Down