@wordpress/env 11.3.1-next.v.202604091042.0 → 11.4.1-next.v.202604201441.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.
@@ -111,7 +111,8 @@ RUN groupadd -o -g $HOST_GID $HOST_USERNAME || true
111
111
  RUN useradd -mlo -u $HOST_UID -g $HOST_GID $HOST_USERNAME || true
112
112
 
113
113
  # Install any dependencies we need in the container.
114
- ${ installDependencies( 'wordpress', env, config ) }`;
114
+ ${ installDependencies( 'wordpress', env, config ) }
115
+ ${ getLoopbackPortConfig( config.env[ env ].port ) }`;
115
116
  }
116
117
 
117
118
  /**
@@ -331,7 +332,39 @@ RUN echo 'spx.data_dir="/tmp/spx"' >> /usr/local/etc/php/php.ini
331
332
  RUN mkdir -p /tmp/spx && chmod 777 /tmp/spx`;
332
333
  }
333
334
 
335
+ /**
336
+ * Generates Dockerfile RUN steps that make Apache also listen on the
337
+ * host-mapped wp-env port, so PHP loopback requests inside the container
338
+ * (WP-Cron, REST API loopback, Site Health) can reach WordPress at
339
+ * WP_HOME = http://localhost:<port>.
340
+ *
341
+ * @see https://github.com/WordPress/gutenberg/issues/20569
342
+ * @see https://github.com/docker-library/wordpress/issues/611#issuecomment-1378316911
343
+ *
344
+ * @param {number} port The host-side port wp-env exposes WordPress on.
345
+ * @return {string} The Dockerfile fragment, or '' when no change is needed.
346
+ */
347
+ function getLoopbackPortConfig( port ) {
348
+ // Apache already listens on 80 by default and wp-env never
349
+ // configures SSL, so 80 and 443 are no-ops. Mirrors the same
350
+ // short-circuit in lib/config/add-or-replace-port.js.
351
+ if ( port === 80 || port === 443 ) {
352
+ return '';
353
+ }
354
+
355
+ return `
356
+ # Make Apache listen on the wp-env-mapped port in addition to 80 so
357
+ # PHP loopback requests (WP-Cron, REST API, Site Health) inside the
358
+ # container reach WordPress at WP_HOME = http://localhost:${ port }.
359
+ # See https://github.com/WordPress/gutenberg/issues/20569
360
+ RUN echo 'Listen ${ port }' >> /etc/apache2/ports.conf
361
+ RUN sed -i 's|<VirtualHost \\*:80>|<VirtualHost *:80 *:${ port }>|' /etc/apache2/sites-enabled/000-default.conf`;
362
+ }
363
+
334
364
  module.exports = {
335
365
  writeDockerFiles,
336
366
  ensureDockerInitialized,
367
+ // Exported for testing.
368
+ wordpressDockerFileContents,
369
+ getLoopbackPortConfig,
337
370
  };
@@ -3,6 +3,10 @@
3
3
  * Internal dependencies
4
4
  */
5
5
  const buildDockerComposeConfig = require( '../runtime/docker/build-docker-compose-config' );
6
+ const {
7
+ wordpressDockerFileContents,
8
+ getLoopbackPortConfig,
9
+ } = require( '../runtime/docker/docker-config' );
6
10
  const getHostUser = require( '../runtime/docker/get-host-user' );
7
11
 
8
12
  // The basic config keys which build docker compose config requires.
@@ -279,3 +283,45 @@ describe( 'buildDockerComposeConfig', () => {
279
283
  } );
280
284
  } );
281
285
  } );
286
+
287
+ describe( 'getLoopbackPortConfig', () => {
288
+ it( 'returns Apache Listen and VirtualHost edits for a non-default port using an anchored sed pattern', () => {
289
+ const out = getLoopbackPortConfig( 8888 );
290
+ expect( out ).toContain( 'Listen 8888' );
291
+ expect( out ).toContain( '/etc/apache2/ports.conf' );
292
+ expect( out ).toContain( '<VirtualHost *:80 *:8888>' );
293
+ expect( out ).toContain(
294
+ '/etc/apache2/sites-enabled/000-default.conf'
295
+ );
296
+ // Guard against a future "simplification" to a greedy s/80/.../g
297
+ // that would also match e.g. unrelated "80" substrings.
298
+ expect( out ).not.toMatch( /s\|80\|/ );
299
+ expect( out ).toMatch( /s\|<VirtualHost \\\*:80>\|/ );
300
+ } );
301
+
302
+ it( 'returns an empty string for port 80 (Apache already listens there)', () => {
303
+ expect( getLoopbackPortConfig( 80 ) ).toBe( '' );
304
+ } );
305
+
306
+ it( 'returns an empty string for port 443 (wp-env does not configure SSL)', () => {
307
+ expect( getLoopbackPortConfig( 443 ) ).toBe( '' );
308
+ } );
309
+ } );
310
+
311
+ describe( 'wordpressDockerFileContents', () => {
312
+ it( 'injects the resolved per-environment port into the generated Dockerfile', () => {
313
+ const config = {
314
+ xdebug: 'off',
315
+ spx: 'off',
316
+ env: {
317
+ development: { port: 8888, phpVersion: null },
318
+ tests: { port: 8889, phpVersion: null },
319
+ },
320
+ };
321
+ const dockerfile = wordpressDockerFileContents( 'tests', config );
322
+ // Proves getLoopbackPortConfig is wired in AND that each environment
323
+ // uses its own port (not the development port).
324
+ expect( dockerfile ).toContain( 'Listen 8889' );
325
+ expect( dockerfile ).not.toContain( 'Listen 8888' );
326
+ } );
327
+ } );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/env",
3
- "version": "11.3.1-next.v.202604091042.0+668146787",
3
+ "version": "11.4.1-next.v.202604201441.0+dab6d8c07",
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",
@@ -63,5 +63,5 @@
63
63
  "scripts": {
64
64
  "test": "echo \"Error: run tests from root\" && exit 1"
65
65
  },
66
- "gitHead": "73606df74f1c38a084bfa5db97205259ef817593"
66
+ "gitHead": "c788005ba4ee2a34851c1217c51602656aa7c3a6"
67
67
  }