Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp-env: Add support for different options in each environment #22568

Merged
merged 23 commits into from
Jul 8, 2020

Conversation

noahtallen
Copy link
Member

@noahtallen noahtallen commented May 22, 2020

Description

Allows the user to change the options for any WordPress environment in wp-env separately. This refactors the way the config works internally by putting all service-level configuration options into env.<service>.

Note: One subtle difference with parsing behavior is that wp-config values are now merged instead of overwritten.

For example:

const parsedConfig = {
  ...uniqueOptions, // like dockerComposeConfigPath, workDirectoryPath, etc)
  env {
    development: WPServiceConfig,
    tests: WPServiceConfig,
  },
}

WPServiceConfig is just something like:

const defaultEnvConfig = {
	core: null,
	plugins: [],
	themes: [],
	port: 8888,
	config: {
		WP_DEBUG: true,
		SCRIPT_DEBUG: true,
		WP_TESTS_DOMAIN: 'localhost',
	},
	mappings: {},
};

the WPServiceConfig contains all options applicable to the service. For example, if .wp-env.json looks like:

{
  "plugins": [ "./" ],
  "env": {
    "tests": {
      "themes": [ "./some-theme" ]
    }
  }
}

the config will be merged like so:

const config = {
  // ... common config options, like workDir
  env: {
    development: {
      // ... other service-level options like port
      plugins: [ "./" ],
      themes: [],
    },
    tests: {
      // ... other service-level options like port
      plugins: [ "./" ],
      themes: [ "./some-theme" ],
    },
  },
}

As you can see, the base-level plugins option is added to both development and tests.

Practically, in .wp-env.json, the only thing that changes is that you can override any of the existing options inside of env.development or env.tests.

Todo:

  • Fix wp-env unit tests
  • Update Travis config which was working around this issue

How has this been tested?

Unit tests, travis, and local testing in my own environment

Types of changes

new feature/refactor

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

closes #22514

@noahtallen noahtallen added [Type] Enhancement A suggestion for improvement. [Tool] Env /packages/env labels May 22, 2020
@noahtallen noahtallen self-assigned this May 22, 2020
@noahtallen noahtallen added the [Status] In Progress Tracking issues with work in progress label May 22, 2020
@noahtallen noahtallen changed the title wp-env: Add support for different options in each environment wp-env: Add support for different options in each environment (WIP) May 22, 2020
@github-actions
Copy link

github-actions bot commented May 22, 2020

Size Change: +6.1 kB (0%)

Total Size: 1.14 MB

Filename Size Change
build/annotations/index.js 3.67 kB -8 B (0%)
build/api-fetch/index.js 3.39 kB -9 B (0%)
build/block-directory/index.js 7.67 kB +1 B
build/block-editor/index.js 115 kB +4.99 kB (4%)
build/block-editor/style-rtl.css 10.8 kB +78 B (0%)
build/block-editor/style.css 10.8 kB +78 B (0%)
build/block-library/editor-rtl.css 7.54 kB -31 B (0%)
build/block-library/editor.css 7.54 kB -33 B (0%)
build/block-library/index.js 130 kB -59 B (0%)
build/block-library/style-rtl.css 7.75 kB -29 B (0%)
build/block-library/style.css 7.76 kB -25 B (0%)
build/block-serialization-default-parser/index.js 1.88 kB -2 B (0%)
build/blocks/index.js 48.2 kB -2 B (0%)
build/components/index.js 198 kB -40 B (0%)
build/components/style-rtl.css 15.8 kB +4 B (0%)
build/components/style.css 15.8 kB +4 B (0%)
build/compose/index.js 9.56 kB +3 B (0%)
build/core-data/index.js 11.4 kB +9 B (0%)
build/data-controls/index.js 1.29 kB -2 B (0%)
build/data/index.js 8.46 kB +11 B (0%)
build/dom/index.js 3.23 kB +38 B (1%)
build/edit-navigation/index.js 10.8 kB +898 B (8%) 🔍
build/edit-navigation/style-rtl.css 1.08 kB +59 B (5%) 🔍
build/edit-navigation/style.css 1.08 kB +59 B (5%) 🔍
build/edit-post/index.js 304 kB +82 B (0%)
build/edit-site/index.js 16.6 kB +29 B (0%)
build/edit-widgets/index.js 9.35 kB +1 B
build/editor/index.js 45 kB +34 B (0%)
build/editor/style-rtl.css 3.78 kB +8 B (0%)
build/editor/style.css 3.78 kB +8 B (0%)
build/element/index.js 4.65 kB -3 B (0%)
build/format-library/index.js 7.71 kB -13 B (0%)
build/hooks/index.js 2.13 kB -1 B
build/is-shallow-equal/index.js 709 B -1 B
build/keyboard-shortcuts/index.js 2.52 kB -1 B
build/keycodes/index.js 1.94 kB -2 B (0%)
build/list-reusable-blocks/index.js 3.12 kB +3 B (0%)
build/media-utils/index.js 5.32 kB +1 B
build/notices/index.js 1.79 kB -3 B (0%)
build/nux/index.js 3.4 kB -3 B (0%)
build/plugins/index.js 2.56 kB +2 B (0%)
build/primitives/index.js 1.4 kB -6 B (0%)
build/priority-queue/index.js 789 B +1 B
build/redux-routine/index.js 2.85 kB -4 B (0%)
build/rich-text/index.js 13.9 kB -12 B (0%)
build/server-side-render/index.js 2.71 kB -1 B
build/shortcode/index.js 1.7 kB +1 B
build/token-list/index.js 1.28 kB +1 B
build/url/index.js 4.06 kB -4 B (0%)
build/warning/index.js 1.13 kB -4 B (0%)
build/wordcount/index.js 1.17 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 944 B 0 B
build/block-directory/style.css 945 B 0 B
build/block-library/theme-rtl.css 728 B 0 B
build/block-library/theme.css 729 B 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/date/index.js 5.38 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/edit-post/style-rtl.css 5.57 kB 0 B
build/edit-post/style.css 5.57 kB 0 B
build/edit-site/style-rtl.css 3.03 kB 0 B
build/edit-site/style.css 3.03 kB 0 B
build/edit-widgets/style-rtl.css 2.45 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 537 B 0 B
build/editor/editor-styles.css 539 B 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/viewport/index.js 1.85 kB 0 B

compressed-size-action

* @param {string} workDirectoryPath Absolute path to the environment work dir.
* @return {Object} the validated and parsed config object.
*/
function parseConfig( config, workDirectoryPath ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseConfig now validates a WPServiceConfig. this way it can be reused for each environment override. (need to clean up comments around this)

*
* @param {Object} rawConfig config right after being read from a file.
*/
function withBackCompat( rawConfig ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the new format, it doesn't make sense to have both port and testsPort. So each WPServiceConfig now has one port property. This function makes sure that existing .wp-env.json files continue working.

@epiqueras
Copy link
Contributor

This is looking great! Let us know when it's ready for a pass :)

@noahtallen noahtallen force-pushed the try/wp-env-multiple-env-support branch 2 times, most recently from 9a6b7e9 to b3eb6d6 Compare May 28, 2020 23:01
@noahtallen
Copy link
Member Author

My goal is to get this over the finish line this week. It's taken more time than expected to support multiple core sources. There are some expectations around how the core source is configured that might not always be true any more, so I'm working on solving that

@noahtallen noahtallen force-pushed the try/wp-env-multiple-env-support branch 2 times, most recently from 7e66c8d to 52612d8 Compare June 6, 2020 00:51
@noahtallen
Copy link
Member Author

@epiqueras this is ready for a look. I think some parts of it could be cleaned up more (e.g. config.js should be split into more files), but it should be working now and ready for a ✅ on the general approach

@epiqueras
Copy link
Contributor

ready for a ✅ on the general approach

Looks good 👍

@noahtallen noahtallen force-pushed the try/wp-env-multiple-env-support branch from 80e0366 to 6c01eb5 Compare June 9, 2020 00:38
@noahtallen noahtallen changed the title wp-env: Add support for different options in each environment (WIP) wp-env: Add support for different options in each environment Jun 9, 2020
@noahtallen
Copy link
Member Author

@epiqueras this is ready for a thorough look. since config.js was getting pretty large, I moved it into its own directory and split out the functions into a few more files. Everything seems to be working pretty well. The remaining task is to update the tests & docs, but it'd be nice to get feedback on the code

packages/env/lib/build-docker-compose-config.js Outdated Show resolved Hide resolved
packages/env/lib/config/config.js Outdated Show resolved Hide resolved
packages/env/lib/config/config.js Outdated Show resolved Hide resolved
packages/env/lib/config/config.js Outdated Show resolved Hide resolved
packages/env/lib/config/config.js Outdated Show resolved Hide resolved
packages/env/lib/config/validate-config.js Outdated Show resolved Hide resolved
packages/env/lib/config/validate-config.js Outdated Show resolved Hide resolved
packages/env/lib/config/validate-config.js Outdated Show resolved Hide resolved
packages/env/lib/download-sources.js Outdated Show resolved Hide resolved
packages/env/lib/wordpress.js Outdated Show resolved Hide resolved
@noahtallen
Copy link
Member Author

Thanks for the detailed review, @epiqueras! I knew I'd probably miss some things :)

@noahtallen noahtallen force-pushed the try/wp-env-multiple-env-support branch from 5e33f65 to f0a8808 Compare June 10, 2020 22:14
@noahtallen
Copy link
Member Author

I'm not sure we can use the new null operators in node yet without transpiling 🙃

Copy link
Contributor

@epiqueras epiqueras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.

Let's stay alert for any bugs before the next release.

@noahtallen noahtallen force-pushed the try/wp-env-multiple-env-support branch from 0dd38ed to efb0236 Compare July 6, 2020 23:19
@noahtallen noahtallen merged commit a5f7900 into master Jul 8, 2020
@noahtallen noahtallen deleted the try/wp-env-multiple-env-support branch July 8, 2020 01:41
@github-actions github-actions bot added this to the Gutenberg 8.6 milestone Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Tool] Env /packages/env [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow for separate tests config for wp-env
4 participants