Skip to content

Commit

Permalink
Allow wp-env to start without config (#23913)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahtallen authored Jul 14, 2020
1 parent 5d23725 commit eb856ef
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
8 changes: 8 additions & 0 deletions packages/env/lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( [
Expand Down
12 changes: 8 additions & 4 deletions packages/env/lib/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<string, WPServiceConfig>} env Specific config for different environments.
* @property {boolean} debug True if debug mode is enabled.
*/
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -166,6 +170,7 @@ module.exports = async function readConfig( configPath ) {
),
configDirectoryPath,
workDirectoryPath,
detectedLocalConfig,
env,
} );
};
Expand Down Expand Up @@ -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 );
Expand All @@ -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 {};
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/env/lib/config/test/__snapshots__/config.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`readConfig config file should match snapshot 1`] = `
Object {
"configDirectoryPath": ".",
"detectedLocalConfig": true,
"env": Object {
"development": Object {
"config": Object {
Expand Down
5 changes: 4 additions & 1 deletion packages/env/lib/wordpress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eb856ef

Please sign in to comment.