@wordpress/env 4.7.0 → 4.8.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,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.8.0 (2022-06-01)
6
+ ### Enhancement
7
+ - Removed the need for quotation marks when passing options to `wp-env run`.
8
+ - Setting a `config` key to `null` will prevent adding the constant to `wp-config.php` even if a default value is defined by `wp-env`.
9
+
5
10
  ## 4.7.0 (2022-05-18)
6
11
 
7
12
  ### Enhancement
package/README.md CHANGED
@@ -300,21 +300,23 @@ Positionals:
300
300
  The run command can be used to open shell sessions or invoke WP-CLI commands.
301
301
 
302
302
  <div class="callout callout-alert">
303
- To run a WP-CLI command that includes optional arguments, enclose the WP-CLI command in quotation marks; otherwise, the optional arguments are ignored. This is because flags are normally passed to `wp-env` itself, meaning that the flags are not considered part of the argument that specifies the WP-CLI command. With quotation marks, `wp-env` considers everything inside quotation marks the WP-CLI command argument.
303
+ In some cases, `wp-env` may consume options that you are attempting to pass to
304
+ the container. This happens with options that `wp-env` has already declared,
305
+ such as `--debug`, `--help`, and `--version`. When this happens, you should fall
306
+ back to using quotation marks; `wp-env` considers everything inside the
307
+ quotation marks to be command argument.
304
308
 
305
- For example, to list cron schedules with optional arguments that specify the fields returned and the format of the output:
309
+ For example, to ask `WP-CLI` for its help text:
306
310
 
307
311
  ```sh
308
- wp-env run cli "wp cron schedule list --fields=name --format=csv"
312
+ wp-env run cli "wp --help"
309
313
  ```
310
314
 
311
- Without the quotation marks, WP-CLI lists the schedule in its default format, ignoring the `fields` and `format` arguments.
315
+ Without the quotation marks, `wp-env` will print its own help text instead of
316
+ passing it to the container. If you experience any problems where the command
317
+ is not being passed correctly, fall back to using quotation marks.
312
318
  </div>
313
319
 
314
- Note that quotation marks are not required for a WP-CLI command that excludes optional arguments, although it does not hurt to include them. For example, the following command syntaxes return identical results: `wp-env run cli "wp cron schedule list"` or `wp-env run cli wp cron schedule list`.
315
-
316
- For more information about all the available commands, see [WP-CLI Commands](https://developer.wordpress.org/cli/commands/).
317
-
318
320
  ```sh
319
321
  wp-env run <container> [command..]
320
322
 
@@ -323,11 +325,7 @@ Runs an arbitrary command in one of the underlying Docker containers. The
323
325
  "development", "tests", or "cli". To run a wp-cli command, use the "cli" or
324
326
  "tests-cli" service. You can also use this command to open shell sessions like
325
327
  bash and the WordPress shell in the WordPress instance. For example, `wp-env run
326
- cli bash` will open bash in the development WordPress instance. When using long
327
- commands with arguments and quotation marks, you need to wrap the "command"
328
- param in quotation marks. For example: `wp-env run tests-cli "wp post create
329
- --post_type=page --post_title='Test'"` will create a post on the tests WordPress
330
- instance.
328
+ cli bash` will open bash in the development WordPress instance.
331
329
 
332
330
  Positionals:
333
331
  container The container to run the command on. [string] [required]
@@ -464,7 +462,7 @@ Several types of strings can be passed into the `core`, `plugins`, `themes`, and
464
462
  | ----------------- | -------------------------------------------- | -------------------------------------------------------- |
465
463
  | Relative path | `.<path>\|~<path>` | `"./a/directory"`, `"../a/directory"`, `"~/a/directory"` |
466
464
  | Absolute path | `/<path>\|<letter>:\<path>` | `"/a/directory"`, `"C:\\a\\directory"` |
467
- | GitHub repository | `<owner>/<repo>[#<ref>]` | `"WordPress/WordPress"`, `"WordPress/gutenberg#trunk"` |
465
+ | GitHub repository | `<owner>/<repo>[#<ref>]` | `"WordPress/WordPress"`, `"WordPress/gutenberg#trunk"`, if no branch is provided wp-env will fall back to the repos default branch |
468
466
  | SSH repository | `ssh://user@host/<owner>/<repo>.git[#<ref>]` | `"ssh://git@github.com/WordPress/WordPress.git"` |
469
467
  | ZIP File | `http[s]://<host>/<path>.zip` | `"https://wordpress.org/wordpress-5.4-beta2.zip"` |
470
468
 
@@ -520,6 +518,8 @@ WP_HOME: 'http://localhost',
520
518
 
521
519
  On the test instance, all of the above are still defined, but `WP_DEBUG` and `SCRIPT_DEBUG` are set to false.
522
520
 
521
+ These can be overridden by setting a value within the `config` configuration. Setting it to `null` will prevent the constant being defined entirely.
522
+
523
523
  Additionally, the values referencing a URL include the specified port for the given environment. So if you set `testsPort: 3000, port: 2000`, `WP_HOME` (for example) will be `http://localhost:3000` on the tests instance and `http://localhost:2000` on the development instance.
524
524
 
525
525
  ### Examples
package/lib/cli.js CHANGED
@@ -92,6 +92,10 @@ module.exports = function cli() {
92
92
  default: false,
93
93
  } );
94
94
 
95
+ // Make sure any unknown arguments are passed to the command as arguments.
96
+ // This allows options to be passed to "run" without being quoted.
97
+ yargs.parserConfiguration( { 'unknown-options-as-args': true } );
98
+
95
99
  yargs.command(
96
100
  'start',
97
101
  wpGreen(
@@ -171,7 +175,7 @@ module.exports = function cli() {
171
175
  describe: 'The container to run the command on.',
172
176
  } );
173
177
  args.positional( 'command', {
174
- type: 'string',
178
+ type: 'array',
175
179
  describe: 'The command to run.',
176
180
  } );
177
181
  },
@@ -189,6 +193,7 @@ module.exports = function cli() {
189
193
  '$0 run tests-cli bash',
190
194
  'Open a bash session in the WordPress tests instance.'
191
195
  );
196
+
192
197
  yargs.command(
193
198
  'destroy',
194
199
  wpRed(
@@ -133,7 +133,7 @@ function parseSourceString( sourceString, { workDirectoryPath } ) {
133
133
  return {
134
134
  type: 'git',
135
135
  url: sshUrl.href.split( '#' )[ 0 ],
136
- ref: sshUrl.hash.slice( 1 ) || 'master',
136
+ ref: sshUrl.hash.slice( 1 ) || undefined,
137
137
  path: workingPath,
138
138
  clonePath: workingPath,
139
139
  basename,
@@ -144,11 +144,12 @@ function parseSourceString( sourceString, { workDirectoryPath } ) {
144
144
  const gitHubFields = sourceString.match(
145
145
  /^([^\/]+)\/([^#\/]+)(\/([^#]+))?(?:#(.+))?$/
146
146
  );
147
+
147
148
  if ( gitHubFields ) {
148
149
  return {
149
150
  type: 'git',
150
151
  url: `https://github.com/${ gitHubFields[ 1 ] }/${ gitHubFields[ 2 ] }.git`,
151
- ref: gitHubFields[ 5 ] || 'master',
152
+ ref: gitHubFields[ 5 ],
152
153
  path: path.resolve(
153
154
  workDirectoryPath,
154
155
  gitHubFields[ 2 ],
@@ -395,7 +395,7 @@ describe( 'readConfig', () => {
395
395
  {
396
396
  type: 'git',
397
397
  url: 'https://github.com/WordPress/gutenberg.git',
398
- ref: 'master',
398
+ ref: undefined,
399
399
  path: expect.stringMatching( /^(\/||\\).*gutenberg$/ ),
400
400
  basename: 'gutenberg',
401
401
  },
package/lib/wordpress.js CHANGED
@@ -64,6 +64,11 @@ async function configureWordPress( environment, config, spinner ) {
64
64
  for ( let [ key, value ] of Object.entries(
65
65
  config.env[ environment ].config
66
66
  ) ) {
67
+ // Allow the configuration to skip a default constant by specifying it as null.
68
+ if ( null === value ) {
69
+ continue;
70
+ }
71
+
67
72
  // Add quotes around string values to work with multi-word strings better.
68
73
  value = typeof value === 'string' ? `"${ value }"` : value;
69
74
  setupCommands.push(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/env",
3
- "version": "4.7.0",
3
+ "version": "4.8.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": "198fa129cf1af8dc615918987ea6795cd40ab7df"
54
+ "gitHead": "a3e0b62091e8a8bdf5e2518e42d60d7098af48cc"
55
55
  }