Skip to content

Commit

Permalink
Scripts: Correctly resolve entry points when the directory is symlink…
Browse files Browse the repository at this point in the history
…ed (#54212)

* Correctly resolve entry points when src directory is simlinked

* Update changelog

* Use `cwd` option

* Apply `cwd` option to all `glob()` functions
  • Loading branch information
t-hamano committed Sep 8, 2023
1 parent d19eb92 commit f7e048d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
4 changes: 4 additions & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
38 changes: 18 additions & 20 deletions packages/scripts/utils/config.js
Original file line number Diff line number Diff line change
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

0 comments on commit f7e048d

Please sign in to comment.