@wordpress/env 5.16.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +189 -120
- package/lib/build-docker-compose-config.js +67 -96
- package/lib/cache.js +1 -0
- package/lib/cli.js +23 -3
- package/lib/commands/clean.js +14 -1
- package/lib/commands/destroy.js +12 -37
- package/lib/commands/index.js +1 -0
- package/lib/commands/install-path.js +1 -0
- package/lib/commands/logs.js +1 -0
- package/lib/commands/run.js +79 -15
- package/lib/commands/start.js +32 -10
- package/lib/commands/stop.js +1 -0
- package/lib/config/add-or-replace-port.js +41 -0
- package/lib/config/db-env.js +1 -0
- package/lib/config/detect-directory-type.js +1 -1
- package/lib/config/get-cache-directory.js +39 -0
- package/lib/config/get-config-from-environment-vars.js +86 -0
- package/lib/config/index.js +7 -5
- package/lib/config/load-config.js +92 -0
- package/lib/config/merge-configs.js +104 -0
- package/lib/config/parse-config.js +418 -157
- package/lib/config/parse-source-string.js +164 -0
- package/lib/config/post-process-config.js +202 -0
- package/lib/config/read-raw-config-file.js +7 -33
- package/lib/config/test/__snapshots__/config-integration.js.snap +271 -0
- package/lib/config/test/add-or-replace-port.js +81 -0
- package/lib/config/test/config-integration.js +143 -0
- package/lib/config/test/get-cache-directory.js +57 -0
- package/lib/config/test/merge-configs.js +111 -0
- package/lib/config/test/parse-config.js +342 -0
- package/lib/config/test/parse-source-string.js +154 -0
- package/lib/config/test/post-process-config.js +295 -0
- package/lib/config/test/read-raw-config-file.js +19 -63
- package/lib/config/test/validate-config.js +305 -0
- package/lib/config/validate-config.js +103 -40
- package/lib/env.js +2 -0
- package/lib/execute-after-setup.js +51 -0
- package/lib/get-host-user.js +31 -0
- package/lib/init-config.js +181 -63
- package/lib/md5.js +1 -0
- package/lib/parse-xdebug-mode.js +1 -0
- package/lib/retry.js +1 -0
- package/lib/test/__snapshots__/md5.js.snap +9 -0
- package/lib/test/build-docker-compose-config.js +134 -0
- package/lib/test/cache.js +154 -0
- package/lib/test/cli.js +149 -0
- package/lib/test/execute-after-setup.js +66 -0
- package/lib/test/md5.js +35 -0
- package/lib/test/parse-xdebug-mode.js +41 -0
- package/lib/wordpress.js +5 -33
- package/package.json +2 -2
- package/lib/config/config.js +0 -357
- package/lib/config/test/__snapshots__/config.js.snap +0 -83
- package/lib/config/test/config.js +0 -1203
|
@@ -3,206 +3,467 @@
|
|
|
3
3
|
* External dependencies
|
|
4
4
|
*/
|
|
5
5
|
const path = require( 'path' );
|
|
6
|
-
const os = require( 'os' );
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Internal dependencies
|
|
10
9
|
*/
|
|
11
|
-
const
|
|
10
|
+
const readRawConfigFile = require( './read-raw-config-file' );
|
|
11
|
+
const {
|
|
12
|
+
parseSourceString,
|
|
13
|
+
includeTestsPath,
|
|
14
|
+
} = require( './parse-source-string' );
|
|
15
|
+
const {
|
|
16
|
+
ValidationError,
|
|
17
|
+
checkString,
|
|
18
|
+
checkPort,
|
|
19
|
+
checkStringArray,
|
|
20
|
+
checkObjectWithValues,
|
|
21
|
+
checkVersion,
|
|
22
|
+
checkValidURL,
|
|
23
|
+
} = require( './validate-config' );
|
|
24
|
+
const getConfigFromEnvironmentVars = require( './get-config-from-environment-vars' );
|
|
25
|
+
const detectDirectoryType = require( './detect-directory-type' );
|
|
12
26
|
const { getLatestWordPressVersion } = require( '../wordpress' );
|
|
27
|
+
const mergeConfigs = require( './merge-configs' );
|
|
13
28
|
|
|
14
29
|
/**
|
|
15
|
-
* @typedef {import('./
|
|
16
|
-
* @typedef {import('./config').WPSource} WPSource
|
|
30
|
+
* @typedef {import('./parse-source-string').WPSource} WPSource
|
|
17
31
|
*/
|
|
18
32
|
|
|
19
33
|
/**
|
|
20
|
-
* The
|
|
21
|
-
*
|
|
34
|
+
* The root configuration options.
|
|
35
|
+
*
|
|
36
|
+
* @typedef WPRootConfigOptions
|
|
37
|
+
* @property {number} port The port to use in the development environment.
|
|
38
|
+
* @property {number} testsPort The port to use in the tests environment.
|
|
39
|
+
* @property {string|null} afterSetup The command(s) to run after configuring WordPress on start and clean.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The environment-specific configuration options. (development/tests/etc)
|
|
44
|
+
*
|
|
45
|
+
* @typedef WPEnvironmentConfig
|
|
46
|
+
* @property {WPSource} coreSource The WordPress installation to load in the environment.
|
|
47
|
+
* @property {WPSource[]} pluginSources Plugins to load in the environment.
|
|
48
|
+
* @property {WPSource[]} themeSources Themes to load in the environment.
|
|
49
|
+
* @property {number} port The port to use.
|
|
50
|
+
* @property {Object} config Mapping of wp-config.php constants to their desired values.
|
|
51
|
+
* @property {Object.<string, WPSource>} mappings Mapping of WordPress directories to local directories which should be mounted.
|
|
52
|
+
* @property {string|null} phpVersion Version of PHP to use in the environments, of the format 0.0.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The root configuration options.
|
|
57
|
+
*
|
|
58
|
+
* @typedef {WPEnvironmentConfig & WPRootConfigOptions} WPRootConfig
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A WordPress installation, plugin or theme to be loaded into the environment.
|
|
63
|
+
*
|
|
64
|
+
* @typedef WPSource
|
|
65
|
+
* @property {'local'|'git'|'zip'} type The source type.
|
|
66
|
+
* @property {string} path The path to the WordPress installation, plugin or theme.
|
|
67
|
+
* @property {?string} url The URL to the source download if the source type is not local.
|
|
68
|
+
* @property {?string} ref The git ref for the source if the source type is 'git'.
|
|
69
|
+
* @property {string} basename Name that identifies the WordPress installation, plugin or theme.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Given a directory, this parses any relevant config files and
|
|
74
|
+
* constructs an object in the format used internally.
|
|
75
|
+
*
|
|
76
|
+
*
|
|
77
|
+
* @param {string} configDirectoryPath A path to the directory we are parsing the config for.
|
|
78
|
+
* @param {string} cacheDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
79
|
+
*
|
|
80
|
+
* @return {WPRootConfig} Parsed config.
|
|
81
|
+
*/
|
|
82
|
+
async function parseConfig( configDirectoryPath, cacheDirectoryPath ) {
|
|
83
|
+
// The local config will be used to override any defaults.
|
|
84
|
+
const localConfig = await parseConfigFile(
|
|
85
|
+
getConfigFilePath( configDirectoryPath ),
|
|
86
|
+
{ cacheDirectoryPath }
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// Any overrides that can be used in place
|
|
90
|
+
// of properties set by the local config.
|
|
91
|
+
const overrideConfig = await parseConfigFile(
|
|
92
|
+
getConfigFilePath( configDirectoryPath, 'override' ),
|
|
93
|
+
{ cacheDirectoryPath }
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// It's important to know whether or not the user
|
|
97
|
+
// has configured the tool using a JSON file.
|
|
98
|
+
const hasUserConfig = localConfig || overrideConfig;
|
|
99
|
+
|
|
100
|
+
// The default config will be used when no local config
|
|
101
|
+
// file is present in this directory. We should also
|
|
102
|
+
// infer the project type when there is no local
|
|
103
|
+
// config file present to use.
|
|
104
|
+
const defaultConfig = await getDefaultConfig( configDirectoryPath, {
|
|
105
|
+
shouldInferType: ! hasUserConfig,
|
|
106
|
+
cacheDirectoryPath,
|
|
107
|
+
} );
|
|
108
|
+
|
|
109
|
+
// Users can provide overrides in environment
|
|
110
|
+
// variables that supercede all other options.
|
|
111
|
+
const environmentVarOverrides =
|
|
112
|
+
getEnvironmentVarOverrides( cacheDirectoryPath );
|
|
113
|
+
|
|
114
|
+
// Merge all of our configs so that we have a complete object
|
|
115
|
+
// containing the desired options in order of precedence.
|
|
116
|
+
return mergeConfigs(
|
|
117
|
+
defaultConfig,
|
|
118
|
+
localConfig ?? {},
|
|
119
|
+
overrideConfig ?? {},
|
|
120
|
+
environmentVarOverrides
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Gets the path to the config file.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} configDirectoryPath The path to the directory containing config files.
|
|
128
|
+
* @param {string} type The type of config file we're interested in: 'local' or 'override'.
|
|
129
|
+
*
|
|
130
|
+
* @return {string} The path to the config file.
|
|
22
131
|
*/
|
|
23
|
-
|
|
132
|
+
function getConfigFilePath( configDirectoryPath, type = 'local' ) {
|
|
133
|
+
let fileName;
|
|
134
|
+
switch ( type ) {
|
|
135
|
+
case 'local': {
|
|
136
|
+
fileName = '.wp-env.json';
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
case 'override': {
|
|
141
|
+
fileName = '.wp-env.override.json';
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
default: {
|
|
146
|
+
throw new Error( `Invalid config file type "${ type }.` );
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return path.resolve( configDirectoryPath, fileName );
|
|
151
|
+
}
|
|
24
152
|
|
|
25
153
|
/**
|
|
26
|
-
*
|
|
27
|
-
* specified in .wp-env.json, validates it, and converts it into the format used
|
|
28
|
-
* internally. For example, `plugins: string[]` will be parsed into
|
|
29
|
-
* `pluginSources: WPSource[]`.
|
|
154
|
+
* Gets the default config that can be overridden.
|
|
30
155
|
*
|
|
31
|
-
* @param {
|
|
156
|
+
* @param {string} configDirectoryPath A path to the config file's directory.
|
|
32
157
|
* @param {Object} options
|
|
33
|
-
* @param {string} options.
|
|
34
|
-
* @
|
|
158
|
+
* @param {string} options.shouldInferType Indicates whether or not we should infer the type of project wp-env is being used in.
|
|
159
|
+
* @param {string} options.cacheDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
160
|
+
*
|
|
161
|
+
* @return {Promise<WPEnvironmentConfig>} The default config object.
|
|
35
162
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
163
|
+
async function getDefaultConfig(
|
|
164
|
+
configDirectoryPath,
|
|
165
|
+
{ shouldInferType, cacheDirectoryPath }
|
|
166
|
+
) {
|
|
167
|
+
// Our default config should try to infer what type of project
|
|
168
|
+
// this is in order to automatically map the current directory.
|
|
169
|
+
const detectedType = shouldInferType
|
|
170
|
+
? await detectDirectoryType( configDirectoryPath )
|
|
171
|
+
: null;
|
|
172
|
+
|
|
173
|
+
// The default configuration should contain all possible options and
|
|
174
|
+
// environments whether they're empty or not. This makes using the
|
|
175
|
+
// config objects easier because once merged we don't need to
|
|
176
|
+
// verify that a given option exists before using it.
|
|
177
|
+
const rawConfig = {
|
|
178
|
+
core: detectedType === 'core' ? '.' : null,
|
|
179
|
+
phpVersion: null,
|
|
180
|
+
plugins: detectedType === 'plugin' ? [ '.' ] : [],
|
|
181
|
+
themes: detectedType === 'theme' ? [ '.' ] : [],
|
|
182
|
+
port: 8888,
|
|
183
|
+
testsPort: 8889,
|
|
184
|
+
mappings: {},
|
|
185
|
+
config: {
|
|
186
|
+
WP_DEBUG: true,
|
|
187
|
+
SCRIPT_DEBUG: true,
|
|
188
|
+
WP_ENVIRONMENT_TYPE: 'local',
|
|
189
|
+
WP_PHP_BINARY: 'php',
|
|
190
|
+
WP_TESTS_EMAIL: 'admin@example.org',
|
|
191
|
+
WP_TESTS_TITLE: 'Test Blog',
|
|
192
|
+
WP_TESTS_DOMAIN: 'localhost',
|
|
193
|
+
WP_SITEURL: 'http://localhost',
|
|
194
|
+
WP_HOME: 'http://localhost',
|
|
195
|
+
},
|
|
196
|
+
afterSetup: null,
|
|
197
|
+
env: {
|
|
198
|
+
development: {},
|
|
199
|
+
tests: {
|
|
200
|
+
config: { WP_DEBUG: false, SCRIPT_DEBUG: false },
|
|
56
201
|
},
|
|
57
|
-
|
|
58
|
-
),
|
|
202
|
+
},
|
|
59
203
|
};
|
|
60
|
-
};
|
|
61
204
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if ( ! wpVersion ) {
|
|
67
|
-
throw new ValidationError(
|
|
68
|
-
'Could not find the latest WordPress version. There may be a network issue.'
|
|
69
|
-
);
|
|
70
|
-
}
|
|
205
|
+
return await parseRootConfig( 'default', rawConfig, {
|
|
206
|
+
cacheDirectoryPath,
|
|
207
|
+
} );
|
|
208
|
+
}
|
|
71
209
|
|
|
72
|
-
|
|
210
|
+
/**
|
|
211
|
+
* Gets a service configuration object containing overrides from our environment variables.
|
|
212
|
+
*
|
|
213
|
+
* @param {string} cacheDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
214
|
+
*
|
|
215
|
+
* @return {WPEnvironmentConfig} An object containing the environment variable overrides.
|
|
216
|
+
*/
|
|
217
|
+
function getEnvironmentVarOverrides( cacheDirectoryPath ) {
|
|
218
|
+
const overrides = getConfigFromEnvironmentVars( cacheDirectoryPath );
|
|
219
|
+
|
|
220
|
+
// Create a service config object so we can merge it with the others
|
|
221
|
+
// and override anything that the configuration options need to.
|
|
222
|
+
const overrideConfig = {
|
|
223
|
+
env: {
|
|
224
|
+
development: {},
|
|
225
|
+
tests: {},
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// We're going to take care to set it at both the root-level and the
|
|
230
|
+
// environment level. This is not totally necessary, but, it's a
|
|
231
|
+
// better representation of how broad the override is.
|
|
232
|
+
|
|
233
|
+
if ( overrides.port ) {
|
|
234
|
+
overrideConfig.port = overrides.port;
|
|
235
|
+
overrideConfig.env.development.port = overrides.port;
|
|
73
236
|
}
|
|
74
|
-
|
|
237
|
+
|
|
238
|
+
if ( overrides.testsPort ) {
|
|
239
|
+
overrideConfig.testsPort = overrides.testsPort;
|
|
240
|
+
overrideConfig.env.tests.port = overrides.testsPort;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if ( overrides.coreSource ) {
|
|
244
|
+
overrideConfig.coreSource = overrides.coreSource;
|
|
245
|
+
overrideConfig.env.development.coreSource = overrides.coreSource;
|
|
246
|
+
overrideConfig.env.tests.coreSource = overrides.coreSource;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if ( overrides.phpVersion ) {
|
|
250
|
+
overrideConfig.phpVersion = overrides.phpVersion;
|
|
251
|
+
overrideConfig.env.development.phpVersion = overrides.phpVersion;
|
|
252
|
+
overrideConfig.env.tests.phpVersion = overrides.phpVersion;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if ( overrides.afterSetup ) {
|
|
256
|
+
overrideConfig.afterSetup = overrides.afterSetup;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return overrideConfig;
|
|
75
260
|
}
|
|
76
261
|
|
|
77
262
|
/**
|
|
78
|
-
* Parses a
|
|
263
|
+
* Parses a raw config into an unvalidated service config.
|
|
79
264
|
*
|
|
80
|
-
* @param {
|
|
81
|
-
* @param {Object}
|
|
82
|
-
* @param {string}
|
|
265
|
+
* @param {string} configFile The config file that we're parsing.
|
|
266
|
+
* @param {Object} options
|
|
267
|
+
* @param {string} options.cacheDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
83
268
|
*
|
|
84
|
-
* @return {
|
|
269
|
+
* @return {Promise<WPRootConfig|null>} The parsed root config object.
|
|
85
270
|
*/
|
|
86
|
-
function
|
|
87
|
-
|
|
271
|
+
async function parseConfigFile( configFile, options ) {
|
|
272
|
+
const rawConfig = await readRawConfigFile( configFile );
|
|
273
|
+
if ( ! rawConfig ) {
|
|
88
274
|
return null;
|
|
89
275
|
}
|
|
90
276
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
277
|
+
return await parseRootConfig( configFile, rawConfig, options );
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Parses the root config object.
|
|
282
|
+
*
|
|
283
|
+
* @param {string} configFile The config file we're parsing.
|
|
284
|
+
* @param {Object} rawConfig The raw config we're parsing.
|
|
285
|
+
* @param {Object} options
|
|
286
|
+
* @param {string} options.cacheDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
287
|
+
*
|
|
288
|
+
* @return {Promise<WPRootConfig>} The root config object.
|
|
289
|
+
*/
|
|
290
|
+
async function parseRootConfig( configFile, rawConfig, options ) {
|
|
291
|
+
const parsedConfig = await parseEnvironmentConfig(
|
|
292
|
+
configFile,
|
|
293
|
+
null,
|
|
294
|
+
rawConfig,
|
|
295
|
+
options
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
// Parse any root-only options.
|
|
299
|
+
if ( rawConfig.testsPort !== undefined ) {
|
|
300
|
+
checkPort( configFile, `testsPort`, rawConfig.testsPort );
|
|
301
|
+
parsedConfig.testsPort = rawConfig.testsPort;
|
|
302
|
+
}
|
|
303
|
+
if ( rawConfig.afterSetup !== undefined ) {
|
|
304
|
+
// Support null as a valid input.
|
|
305
|
+
if ( rawConfig.afterSetup !== null ) {
|
|
306
|
+
checkString( configFile, 'afterSetup', rawConfig.afterSetup );
|
|
307
|
+
}
|
|
308
|
+
parsedConfig.afterSetup = rawConfig.afterSetup;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Parse the environment-specific configs so they're accessible to the root.
|
|
312
|
+
parsedConfig.env = {};
|
|
313
|
+
if ( rawConfig.env ) {
|
|
314
|
+
checkObjectWithValues( configFile, 'env', rawConfig.env, [ 'object' ] );
|
|
315
|
+
for ( const env in rawConfig.env ) {
|
|
316
|
+
parsedConfig.env[ env ] = await parseEnvironmentConfig(
|
|
317
|
+
configFile,
|
|
318
|
+
env,
|
|
319
|
+
rawConfig.env[ env ],
|
|
320
|
+
options
|
|
101
321
|
);
|
|
102
|
-
} else {
|
|
103
|
-
sourcePath = path.resolve( sourceString );
|
|
104
322
|
}
|
|
105
|
-
const basename = path.basename( sourcePath );
|
|
106
|
-
return {
|
|
107
|
-
type: 'local',
|
|
108
|
-
path: sourcePath,
|
|
109
|
-
basename,
|
|
110
|
-
};
|
|
111
323
|
}
|
|
112
324
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
);
|
|
325
|
+
return parsedConfig;
|
|
326
|
+
}
|
|
116
327
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
328
|
+
/**
|
|
329
|
+
* Parses and validates a raw config object and returns a validated service config to use internally.
|
|
330
|
+
*
|
|
331
|
+
* @param {string} configFile The config file that we're parsing.
|
|
332
|
+
* @param {string|null} environment If set, the environment that we're parsing the config for.
|
|
333
|
+
* @param {Object} config A config object to parse.
|
|
334
|
+
* @param {Object} options
|
|
335
|
+
* @param {string} options.cacheDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
336
|
+
*
|
|
337
|
+
* @return {Promise<WPEnvironmentConfig>} The environment config object.
|
|
338
|
+
*/
|
|
339
|
+
async function parseEnvironmentConfig(
|
|
340
|
+
configFile,
|
|
341
|
+
environment,
|
|
342
|
+
config,
|
|
343
|
+
options
|
|
344
|
+
) {
|
|
345
|
+
if ( ! config ) {
|
|
346
|
+
return {};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const environmentPrefix = environment ? environment + '.' : '';
|
|
350
|
+
|
|
351
|
+
const parsedConfig = {};
|
|
352
|
+
|
|
353
|
+
if ( config.port !== undefined ) {
|
|
354
|
+
checkPort( configFile, `${ environmentPrefix }port`, config.port );
|
|
355
|
+
parsedConfig.port = config.port;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if ( config.phpVersion !== undefined ) {
|
|
359
|
+
// Support null as a valid input.
|
|
360
|
+
if ( config.phpVersion !== null ) {
|
|
361
|
+
checkVersion(
|
|
362
|
+
configFile,
|
|
363
|
+
`${ environmentPrefix }phpVersion`,
|
|
364
|
+
config.phpVersion
|
|
148
365
|
);
|
|
149
|
-
return {
|
|
150
|
-
type: 'git',
|
|
151
|
-
url: sshUrl.href.split( '#' )[ 0 ],
|
|
152
|
-
ref: sshUrl.hash.slice( 1 ) || undefined,
|
|
153
|
-
path: workingPath,
|
|
154
|
-
clonePath: workingPath,
|
|
155
|
-
basename,
|
|
156
|
-
};
|
|
157
366
|
}
|
|
158
|
-
|
|
367
|
+
parsedConfig.phpVersion = config.phpVersion;
|
|
368
|
+
}
|
|
159
369
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
370
|
+
if ( config.core !== undefined ) {
|
|
371
|
+
parsedConfig.coreSource = includeTestsPath(
|
|
372
|
+
await parseCoreSource( config.core, options ),
|
|
373
|
+
options
|
|
374
|
+
);
|
|
375
|
+
}
|
|
163
376
|
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
377
|
+
if ( config.plugins !== undefined ) {
|
|
378
|
+
checkStringArray(
|
|
379
|
+
configFile,
|
|
380
|
+
`${ environmentPrefix }plugins`,
|
|
381
|
+
config.plugins
|
|
382
|
+
);
|
|
383
|
+
parsedConfig.pluginSources = config.plugins.map( ( sourceString ) =>
|
|
384
|
+
parseSourceString( sourceString, options )
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if ( config.themes !== undefined ) {
|
|
389
|
+
checkStringArray(
|
|
390
|
+
configFile,
|
|
391
|
+
`${ environmentPrefix }themes`,
|
|
392
|
+
config.themes
|
|
393
|
+
);
|
|
394
|
+
parsedConfig.themeSources = config.themes.map( ( sourceString ) =>
|
|
395
|
+
parseSourceString( sourceString, options )
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if ( config.config !== undefined ) {
|
|
400
|
+
checkObjectWithValues(
|
|
401
|
+
configFile,
|
|
402
|
+
`${ environmentPrefix }config`,
|
|
403
|
+
config.config,
|
|
404
|
+
[ 'string', 'number', 'boolean', 'empty' ]
|
|
405
|
+
);
|
|
406
|
+
parsedConfig.config = config.config;
|
|
407
|
+
|
|
408
|
+
// There are some configuration options that have a special purpose and need to be validated too.
|
|
409
|
+
for ( const key in parsedConfig.config ) {
|
|
410
|
+
switch ( key ) {
|
|
411
|
+
case 'WP_HOME':
|
|
412
|
+
case 'WP_SITEURL': {
|
|
413
|
+
checkValidURL(
|
|
414
|
+
configFile,
|
|
415
|
+
`${ environmentPrefix }config.${ key }`,
|
|
416
|
+
parsedConfig.config[ key ]
|
|
417
|
+
);
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if ( config.mappings !== undefined ) {
|
|
425
|
+
checkObjectWithValues(
|
|
426
|
+
configFile,
|
|
427
|
+
`${ environmentPrefix }mappings`,
|
|
428
|
+
config.mappings,
|
|
429
|
+
[ 'string' ]
|
|
430
|
+
);
|
|
431
|
+
parsedConfig.mappings = Object.entries( config.mappings ).reduce(
|
|
432
|
+
( result, [ wpDir, localDir ] ) => {
|
|
433
|
+
const source = parseSourceString( localDir, options );
|
|
434
|
+
result[ wpDir ] = source;
|
|
435
|
+
return result;
|
|
436
|
+
},
|
|
437
|
+
{}
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return parsedConfig;
|
|
182
442
|
}
|
|
183
|
-
module.exports.parseSourceString = parseSourceString;
|
|
184
443
|
|
|
185
444
|
/**
|
|
186
|
-
*
|
|
187
|
-
* property set correctly. Only the 'core' source requires a testsPath.
|
|
188
|
-
*
|
|
189
|
-
* @param {?WPSource} source A source object.
|
|
190
|
-
* @param {Object} options
|
|
191
|
-
* @param {string} options.workDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
445
|
+
* Parses a WordPress Core source string or defaults to the latest version.
|
|
192
446
|
*
|
|
193
|
-
* @
|
|
447
|
+
* @param {string|null} coreSource The WordPress course source string to parse.
|
|
448
|
+
* @param {Object} options Options to use while parsing.
|
|
449
|
+
* @return {Promise<Object>} The parsed source object.
|
|
194
450
|
*/
|
|
195
|
-
function
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
451
|
+
async function parseCoreSource( coreSource, options ) {
|
|
452
|
+
// An empty source means we should use the latest version of WordPress.
|
|
453
|
+
if ( ! coreSource ) {
|
|
454
|
+
const wpVersion = await getLatestWordPressVersion();
|
|
455
|
+
if ( ! wpVersion ) {
|
|
456
|
+
throw new ValidationError(
|
|
457
|
+
'Could not find the latest WordPress version. There may be a network issue.'
|
|
458
|
+
);
|
|
459
|
+
}
|
|
199
460
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
workDirectoryPath,
|
|
204
|
-
'tests-' + path.basename( source.path )
|
|
205
|
-
),
|
|
206
|
-
};
|
|
461
|
+
coreSource = `WordPress/WordPress#${ wpVersion }`;
|
|
462
|
+
}
|
|
463
|
+
return parseSourceString( coreSource, options );
|
|
207
464
|
}
|
|
208
|
-
|
|
465
|
+
|
|
466
|
+
module.exports = {
|
|
467
|
+
parseConfig,
|
|
468
|
+
getConfigFilePath,
|
|
469
|
+
};
|