Skip to content

Commit

Permalink
Correctly resolve entry points when src directory is simlinked
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Sep 6, 2023
1 parent 7924ef1 commit ef5acd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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, '/' )
)
);
},
},
Expand Down
11 changes: 4 additions & 7 deletions packages/scripts/utils/config.js
Expand Up @@ -206,17 +206,15 @@ 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 srcDirectory = fromProjectRoot( getWordPressSrcDirectory() ) + sep;
const blockMetadataFiles = glob(
`${ getWordPressSrcDirectory() }/**/block.json`,
join( srcDirectory, '**/block.json' ).replace( /\\/g, '/' ),
{
absolute: true,
}
);

if ( blockMetadataFiles.length > 0 ) {
const srcDirectory = fromProjectRoot(
getWordPressSrcDirectory() + sep
);
const entryPoints = blockMetadataFiles.reduce(
( accumulator, blockMetadataFile ) => {
// wrapping in try/catch in case the file is malformed
Expand Down Expand Up @@ -335,15 +333,14 @@ function getRenderPropPaths() {
}

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

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

const renderPaths = blockMetadataFiles.map( ( blockMetadataFile ) => {
const { render } = JSON.parse( readFileSync( blockMetadataFile ) );
if ( render && render.startsWith( 'file:' ) ) {
Expand Down

0 comments on commit ef5acd0

Please sign in to comment.