diff --git a/packages/env/lib/commands/start.js b/packages/env/lib/commands/start.js index dee80f38bea95..7375326c5f1aa 100644 --- a/packages/env/lib/commands/start.js +++ b/packages/env/lib/commands/start.js @@ -56,6 +56,14 @@ module.exports = async function start( { spinner, debug } ) { const config = await initConfig( { spinner, debug } ); + if ( ! config.detectedLocalConfig ) { + const { configDirectoryPath } = config; + spinner.warn( + `Warning: could not find a .wp-env.json configuration file and could not determine if '${ configDirectoryPath }' is a WordPress installation, a plugin, or a theme.` + ); + spinner.start(); + } + spinner.text = 'Downloading WordPress.'; await Promise.all( [ diff --git a/packages/env/lib/config/config.js b/packages/env/lib/config/config.js index 364480f6294f2..fd5a722a41faf 100644 --- a/packages/env/lib/config/config.js +++ b/packages/env/lib/config/config.js @@ -23,6 +23,7 @@ const parseConfig = require( './parse-config' ); * @property {string} configDirectoryPath Path to the .wp-env.json file. * @property {string} workDirectoryPath Path to the work directory located in ~/.wp-env. * @property {string} dockerComposeConfigPath Path to the docker-compose.yml file. + * @property {boolean} detectedLocalConfig If true, wp-env detected local config and used it. * @property {Object.} env Specific config for different environments. * @property {boolean} debug True if debug mode is enabled. */ @@ -104,6 +105,9 @@ module.exports = async function readConfig( configPath ) { configPath.replace( /\.wp-env\.json$/, '.wp-env.override.json' ) ) ) || {}; + const detectedLocalConfig = + Object.keys( { ...baseConfig, ...overrideConfig } ).length > 0; + // A quick validation before merging on a service by service level allows us // to check the root configuration options and provide more helpful errors. validateConfig( @@ -166,6 +170,7 @@ module.exports = async function readConfig( configPath ) { ), configDirectoryPath, workDirectoryPath, + detectedLocalConfig, env, } ); }; @@ -214,7 +219,8 @@ function mergeWpServiceConfigs( configs ) { * added to the default plugin sources. * * @param {string} configPath A path to the config file for the source to detect. - * @return {Object} Basic config options for the detected source type. + * @return {Object} Basic config options for the detected source type. Empty + * object if no config detected. */ async function getDefaultBaseConfig( configPath ) { const configDirectoryPath = path.dirname( configPath ); @@ -228,9 +234,7 @@ async function getDefaultBaseConfig( configPath ) { return { themes: [ '.' ] }; } - throw new ValidationError( - `No .wp-env.json file found at '${ configPath }' and could not determine if '${ configDirectoryPath }' is a WordPress installation, a plugin, or a theme.` - ); + return {}; } /** diff --git a/packages/env/lib/config/test/__snapshots__/config.js.snap b/packages/env/lib/config/test/__snapshots__/config.js.snap index 0cf3f3ad4890b..1420e8ab83f8d 100644 --- a/packages/env/lib/config/test/__snapshots__/config.js.snap +++ b/packages/env/lib/config/test/__snapshots__/config.js.snap @@ -3,6 +3,7 @@ exports[`readConfig config file should match snapshot 1`] = ` Object { "configDirectoryPath": ".", + "detectedLocalConfig": true, "env": Object { "development": Object { "config": Object { diff --git a/packages/env/lib/wordpress.js b/packages/env/lib/wordpress.js index 799606cb766b1..385b8911a4eea 100644 --- a/packages/env/lib/wordpress.js +++ b/packages/env/lib/wordpress.js @@ -171,7 +171,10 @@ async function resetDatabase( } async function setupWordPressDirectories( config ) { - if ( hasSameCoreSource( [ config.env.development, config.env.tests ] ) ) { + if ( + config.env.development.coreSource && + hasSameCoreSource( [ config.env.development, config.env.tests ] ) + ) { await copyCoreFiles( config.env.development.coreSource.path, config.env.development.coreSource.testsPath