@wordpress/env 5.1.0 → 5.2.1-next.d6164808d3.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/CHANGELOG.md CHANGED
@@ -2,13 +2,23 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 5.2.0 (2022-08-16)
6
+
7
+ ### Enhancement
8
+ - Query parameters can now be used in .zip source URLs.
9
+
10
+ ## 5.1.1 (2022-08-16)
11
+
12
+ ### Bug Fix
13
+ - Fix a crash when "core" was set to `null` in a `.wp-env.json` file. We now use the latest stable WordPress version in that case. This also restores the previous behavior of `"core": null` in `.wp-env.override.json`, which was to use the latest stable WordPress version.
14
+
5
15
  ## 5.1.0 (2022-08-10)
6
16
 
7
17
  ### Enhancement
8
- - Previously, wp-env used the WordPress version provided by Docker in the WordPress image for installations which don't specify a WordPress version. Now, wp-env will find the latest stable version on WordPress.org and check out the https://github.com/WordPress/WordPress repository at the tag matching that version. In most cases, this will match what Docker provides. The benefit is that wp-env (and WordPress.org) now controls the default WordPress version rather than Docker.
18
+ - Previously, wp-env used the WordPress version provided by Docker in the WordPress image for installations which don't specify a WordPress version. Now, wp-env will find the latest stable version on WordPress.org and check out the https://github.com/WordPress/WordPress repository at the tag matching that version. In most cases, this will match what Docker provides. The benefit is that wp-env (and WordPress.org) now controls the default WordPress version rather than Docker.
9
19
 
10
20
  ### Bug Fix
11
- - Downloading a default WordPress version also resolves a bug where the wrong WordPress test files were used if no core source was specified in wp-env.json. The current trunk test files were downloaded rather than the stable version. Now, the test files will match the default stable version.
21
+ - Downloading a default WordPress version also resolves a bug where the wrong WordPress test files were used if no core source was specified in wp-env.json. The current trunk test files were downloaded rather than the stable version. Now, the test files will match the default stable version.
12
22
 
13
23
  ## 5.0.0 (2022-07-27)
14
24
 
@@ -15,7 +15,6 @@ const readRawConfigFile = require( './read-raw-config-file' );
15
15
  const parseConfig = require( './parse-config' );
16
16
  const { includeTestsPath, parseSourceString } = parseConfig;
17
17
  const md5 = require( '../md5' );
18
- const { getLatestWordPressVersion } = require( '../wordpress' );
19
18
 
20
19
  /**
21
20
  * wp-env configuration.
@@ -85,21 +84,9 @@ module.exports = async function readConfig( configPath ) {
85
84
  const detectedLocalConfig =
86
85
  Object.keys( { ...baseConfig, ...overrideConfig } ).length > 0;
87
86
 
88
- // If there is no local WordPress version, use the latest stable version from GitHub.
89
- let coreRef;
90
- if ( ! overrideConfig.core && ! baseConfig.core ) {
91
- const wpVersion = await getLatestWordPressVersion();
92
- if ( ! wpVersion ) {
93
- throw new ValidationError(
94
- 'Could not find the latest WordPress version. There may be a network issue.'
95
- );
96
- }
97
- coreRef = `WordPress/WordPress#${ wpVersion }`;
98
- }
99
-
100
87
  // Default configuration which is overridden by .wp-env.json files.
101
88
  const defaultConfiguration = {
102
- core: coreRef,
89
+ core: null, // Indicates that the latest stable version should ultimately be used.
103
90
  phpVersion: null,
104
91
  plugins: [],
105
92
  themes: [],
@@ -155,23 +142,21 @@ module.exports = async function readConfig( configPath ) {
155
142
 
156
143
  // Merge each of the specified environment-level overrides.
157
144
  const allPorts = new Set(); // Keep track of unique ports for validation.
158
- const env = allEnvs.reduce( ( result, environment ) => {
159
- result[ environment ] = parseConfig(
145
+ const env = {};
146
+ for ( const envName of allEnvs ) {
147
+ env[ envName ] = await parseConfig(
160
148
  validateConfig(
161
149
  mergeWpServiceConfigs( [
162
- ...getEnvConfig( defaultConfiguration, environment ),
163
- ...getEnvConfig( baseConfig, environment ),
164
- ...getEnvConfig( overrideConfig, environment ),
150
+ ...getEnvConfig( defaultConfiguration, envName ),
151
+ ...getEnvConfig( baseConfig, envName ),
152
+ ...getEnvConfig( overrideConfig, envName ),
165
153
  ] ),
166
- environment
154
+ envName
167
155
  ),
168
- {
169
- workDirectoryPath,
170
- }
156
+ { workDirectoryPath }
171
157
  );
172
- allPorts.add( result[ environment ].port );
173
- return result;
174
- }, {} );
158
+ allPorts.add( env[ envName ].port );
159
+ }
175
160
 
176
161
  if ( allPorts.size !== allEnvs.length ) {
177
162
  throw new ValidationError(
@@ -262,6 +247,7 @@ async function getDefaultBaseConfig( configPath ) {
262
247
  * @return {WPConfig} configuration object with overrides applied.
263
248
  */
264
249
  function withOverrides( config ) {
250
+ const workDirectoryPath = config.workDirectoryPath;
265
251
  // Override port numbers with environment variables.
266
252
  config.env.development.port =
267
253
  getNumberFromEnvVariable( 'WP_ENV_PORT' ) ||
@@ -273,10 +259,8 @@ function withOverrides( config ) {
273
259
  // Override WordPress core with environment variable.
274
260
  if ( process.env.WP_ENV_CORE ) {
275
261
  const coreSource = includeTestsPath(
276
- parseSourceString( process.env.WP_ENV_CORE, {
277
- workDirectoryPath: config.workDirectoryPath,
278
- } ),
279
- { workDirectoryPath: config.workDirectoryPath }
262
+ parseSourceString( process.env.WP_ENV_CORE, { workDirectoryPath } ),
263
+ { workDirectoryPath }
280
264
  );
281
265
  config.env.development.coreSource = coreSource;
282
266
  config.env.tests.coreSource = coreSource;
@@ -9,6 +9,7 @@ const os = require( 'os' );
9
9
  * Internal dependencies
10
10
  */
11
11
  const { ValidationError } = require( './validate-config' );
12
+ const { getLatestWordPressVersion } = require( '../wordpress' );
12
13
 
13
14
  /**
14
15
  * @typedef {import('./config').WPServiceConfig} WPServiceConfig
@@ -32,12 +33,12 @@ const HOME_PATH_PREFIX = `~${ path.sep }`;
32
33
  * @param {string} options.workDirectoryPath Path to the work directory located in ~/.wp-env.
33
34
  * @return {WPServiceConfig} Parsed environment-level configuration.
34
35
  */
35
- module.exports = function parseConfig( config, options ) {
36
+ module.exports = async function parseConfig( config, options ) {
36
37
  return {
37
38
  port: config.port,
38
39
  phpVersion: config.phpVersion,
39
40
  coreSource: includeTestsPath(
40
- parseSourceString( config.core, options ),
41
+ await parseCoreSource( config.core, options ),
41
42
  options
42
43
  ),
43
44
  pluginSources: config.plugins.map( ( sourceString ) =>
@@ -58,6 +59,21 @@ module.exports = function parseConfig( config, options ) {
58
59
  };
59
60
  };
60
61
 
62
+ async function parseCoreSource( coreSource, options ) {
63
+ // An empty source means we should use the latest version of WordPress.
64
+ if ( ! coreSource ) {
65
+ const wpVersion = await getLatestWordPressVersion();
66
+ if ( ! wpVersion ) {
67
+ throw new ValidationError(
68
+ 'Could not find the latest WordPress version. There may be a network issue.'
69
+ );
70
+ }
71
+
72
+ coreSource = `WordPress/WordPress#${ wpVersion }`;
73
+ }
74
+ return parseSourceString( coreSource, options );
75
+ }
76
+
61
77
  /**
62
78
  * Parses a source string into a source object.
63
79
  *
@@ -95,7 +111,7 @@ function parseSourceString( sourceString, { workDirectoryPath } ) {
95
111
  }
96
112
 
97
113
  const zipFields = sourceString.match(
98
- /^https?:\/\/([^\s$.?#].[^\s]*)\.zip$/
114
+ /^https?:\/\/([^\s$.?#].[^\s]*)\.zip(\?.+)?$/
99
115
  );
100
116
 
101
117
  if ( zipFields ) {
@@ -526,6 +526,7 @@ describe( 'readConfig', () => {
526
526
  plugins: [
527
527
  'https://www.example.com/test/path/to/gutenberg.zip',
528
528
  'https://www.example.com/test/path/to/gutenberg.8.1.0.zip',
529
+ 'https://www.example.com/test/path/to/gutenberg.8.1.0.zip?auth=thisIsAString&token=secondString',
529
530
  'https://www.example.com/test/path/to/twentytwenty.zip',
530
531
  'https://www.example.com/test/path/to/twentytwenty.1.3.zip',
531
532
  'https://example.com/twentytwenty.1.3.zip',
@@ -550,6 +551,14 @@ describe( 'readConfig', () => {
550
551
  ),
551
552
  basename: 'gutenberg.8.1.0',
552
553
  },
554
+ {
555
+ type: 'zip',
556
+ url: 'https://www.example.com/test/path/to/gutenberg.8.1.0.zip?auth=thisIsAString&token=secondString',
557
+ path: expect.stringMatching(
558
+ /^(\/|\\).*gutenberg.8.1.0$/
559
+ ),
560
+ basename: 'gutenberg.8.1.0',
561
+ },
553
562
  {
554
563
  type: 'zip',
555
564
  url: 'https://www.example.com/test/path/to/twentytwenty.zip',
package/lib/wordpress.js CHANGED
@@ -277,13 +277,20 @@ async function readWordPressVersion( coreSource, spinner, debug ) {
277
277
  *
278
278
  * @return {string} The latest stable version of WordPress, like "6.0.1"
279
279
  */
280
+ let CACHED_WP_VERSION;
280
281
  async function getLatestWordPressVersion() {
282
+ // Avoid extra network requests.
283
+ if ( CACHED_WP_VERSION ) {
284
+ return CACHED_WP_VERSION;
285
+ }
286
+
281
287
  const versions = await got(
282
288
  'https://api.wordpress.org/core/stable-check/1.0/'
283
289
  ).json();
284
290
 
285
291
  for ( const [ version, status ] of Object.entries( versions ) ) {
286
292
  if ( status === 'latest' ) {
293
+ CACHED_WP_VERSION = version;
287
294
  return version;
288
295
  }
289
296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/env",
3
- "version": "5.1.0",
3
+ "version": "5.2.1-next.d6164808d3.0",
4
4
  "description": "A zero-config, self contained local WordPress environment for development and testing.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -51,5 +51,5 @@
51
51
  "scripts": {
52
52
  "test": "echo \"Error: run tests from root\" && exit 1"
53
53
  },
54
- "gitHead": "08358f53b627a15148c3a3e433cdf58cf8714aa4"
54
+ "gitHead": "ba8a396d2f418e53a6c4c50575582f3f3eb11ff7"
55
55
  }