From 4e2dfce8cce82fbced31a059b1cb70cd6338f492 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Fri, 11 Feb 2022 11:27:35 +0100 Subject: [PATCH 1/2] Scripts: Do not exit `build` when no entry found in `src` directory --- packages/scripts/CHANGELOG.md | 7 +++++++ packages/scripts/utils/config.js | 11 ++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 3255f16269946..5ce6e02492b9f 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -6,6 +6,9 @@ - Automatically copy PHP files located in the `src` folder and its subfolders to the output directory (`build` by default) ([#38715](https://github.com/WordPress/gutenberg/pull/38715)). +### Bug Fix + +- Return a default entry object in the `build` command when no entry files discovered in the project ([#38737](https://github.com/WordPress/gutenberg/pull/38737)). ## 21.0.0 (2022-02-10) @@ -13,6 +16,10 @@ - The bundled `puppeteer-core` dependency has been updated from requiring `^11.0.0` to requiring `^13.2.0` ([#37078](https://github.com/WordPress/gutenberg/pull/37078)). +### Bug Fix + +- Fix the handling for entry points when running `build` command ([#38584](https://github.com/WordPress/gutenberg/pull/38584)). + ## 20.0.2 (2022-01-31) ### Bug Fix diff --git a/packages/scripts/utils/config.js b/packages/scripts/utils/config.js index 1f1a271137ce9..035b01c8e2494 100644 --- a/packages/scripts/utils/config.js +++ b/packages/scripts/utils/config.js @@ -16,7 +16,6 @@ const { } = require( './cli' ); const { fromConfigRoot, fromProjectRoot, hasProjectFile } = require( './file' ); const { hasPackageProp } = require( './package' ); -const { exit } = require( './process' ); const { log } = console; // See https://babeljs.io/docs/en/config-files#configuration-file-types. @@ -184,6 +183,10 @@ function getWebpackEntryPoints() { return JSON.parse( process.env.WP_ENTRY ); } + if ( ! hasProjectFile( 'src' ) ) { + return {}; + } + // 2. Checks whether any block metadata files can be detected in the `src` directory. // It scans all discovered files looking for JavaScript assets and converts them to entry points. const blockMetadataFiles = glob( 'src/**/block.json', { @@ -268,10 +271,8 @@ function getWebpackEntryPoints() { absolute: true, } ); if ( ! entryFile ) { - log( - chalk.bold.red( 'No entry files discovered in the "src" folder.' ) - ); - exit( 1 ); + log( chalk.yellow( 'No entry file discovered in the "src" folder.' ) ); + return {}; } return { From 4111f6964211d393d9be9e168ba66e43dc4e95df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Fri, 11 Feb 2022 12:38:26 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Dominik Schilling --- packages/scripts/utils/config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/scripts/utils/config.js b/packages/scripts/utils/config.js index 035b01c8e2494..b22cb7f4450ad 100644 --- a/packages/scripts/utils/config.js +++ b/packages/scripts/utils/config.js @@ -183,6 +183,7 @@ function getWebpackEntryPoints() { return JSON.parse( process.env.WP_ENTRY ); } + // Continue only if the `src` directory exists. if ( ! hasProjectFile( 'src' ) ) { return {}; } @@ -271,7 +272,7 @@ function getWebpackEntryPoints() { absolute: true, } ); if ( ! entryFile ) { - log( chalk.yellow( 'No entry file discovered in the "src" folder.' ) ); + log( chalk.yellow( 'No entry file discovered in the "src" directory.' ) ); return {}; }