site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

Remove @wordpress/scripts

Open felixarntz opened this issue 5 years ago • 25 comments

@wordpress/scripts should be removed as we do not use it enough to justify the cost of keeping it up to date which is substantial. As part of the update, the stylelint-config-wordpress dependency should be removed, since that repository is entirely deprecated.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The @wordpress/scripts package should be removed entirely as a Site Kit dependency, since its current usage is really basic, and because it entails so many more things that we don't even use, it's not worth maintaining it (updating it has shown to be a pain).
    • In the few places where we currently use it (mostly configs), we should switch to a lower-level dependency for just that purpose (if one exists), or alternatively replicate it ourselves.
    • No actual behavior in our build process or linting/testing requirements should actually change.

Implementation Brief

Removal of the package

  • Remove the package @wordpres/scripts by running npm uninstall @wordpress/scripts
  • Remove your node_modules so you can verify the binary wp-scripts no longer exists. rm -rf node_modules
  • Then install the modules again with npm install
  • Verify that the package @wordpress/scripts is removed from package.json

Update current scripts

  • Inside of package.json look for all the scripts with wp-scripts that are going to be replaced.
    • test:js
      • Install the following packages:
      • npm install cross-env [email protected] [email protected] @wordpress/jest-preset-default --save-dev
      • Replace the script wp-scripts test-unit-js --config=tests/js/jest.config.js with cross-env BABEL_ENV=test NODE_ENV=test jest --config=tests/js/jest.config.js --passWithNoTests
      • Update the config on the file tests/js/jest.config.js
        • Removing const { preset } = require( '@wordpress/scripts/config/jest-unit.config' );
        • Replace present with preset: '@wordpress/jest-preset-default'
        • Replace '<rootDir>/node_modules/@wordpress/scripts/config/babel-transform' with '<rootDir>/tests/e2e/babel-transform.js',
    • test:js:watch
      • Replace wp-scripts test-unit-js --config=tests/js/jest.config.js --watch with npm run test:js -- --watch
    • test:e2e
      • Install the following packages npm install [email protected] [email protected] [email protected]
      • Copy the file https://github.com/WordPress/gutenberg/blob/%40wordpress/scripts%4012.0.0/packages/scripts/scripts/test-e2e.js and place it at tests/e2e/script.js
      • Set the permissions to execute the script chmod +x tests/e2e/script.js
      • Replace WP_BASE_URL=http://localhost:9002 wp-scripts test-e2e --config=tests/e2e/jest.config.js with cross-env WP_BASE_URL=http://localhost:9002 ./tests/e2e/script.js
      • Edit the file tests/e2e/scripts.js and remove all the imports from ../utils https://github.com/WordPress/gutenberg/blob/%40wordpress/scripts%4012.0.0/packages/scripts/scripts/test-e2e.js#L19-L29
      • Set the env to node at the top of the file #!/usr/bin/env node
      • Import the function https://github.com/WordPress/gutenberg/blob/%40wordpress/scripts%4012.0.0/packages/scripts/utils/process.js#L1-L11 into the file
      • Import the functions https://github.com/WordPress/gutenberg/blob/%40wordpress/scripts%4012.0.0/packages/scripts/utils/process.js#L1-L11 into the same file as well.
      • Remove the option that check if the config file exists (as this always exists) https://github.com/WordPress/gutenberg/blob/%40wordpress/scripts%4012.0.0/packages/scripts/scripts/test-e2e.js#L38-L47
      • Replace https://github.com/WordPress/gutenberg/blob/%40wordpress/scripts%4012.0.0/packages/scripts/scripts/test-e2e.js#L49-L53 with
const config = [ '--config=tests/e2e/jest.config.js'];
  • lint:js:

    • wp-scripts lint-js
    • to eslint --no-eslintrc --config .eslintrc.json --ignore-path .eslintignore --ext js,jsx,ts,tsx .
  • lint:js-fix

    • Replace wp-scripts format-js with
    • prettier --write --config .prettierrc.js --ignore-path .prettierignore "**/*.{js,jsx,ts,tsx,.yml,.yaml}"
    • Create a new file at the root of the project called .prettierignore and add the following content inside
      build
      vendor
      node_modules
      dist
      third-party
      bin
      
    • Add the prettier-config package via npm install @wordpress/prettier-config --save-dev
  • Merge the content from https://github.com/WordPress/gutenberg/blob/%40wordpress/scripts%4012.0.0/packages/scripts/config/puppeteer.config.jswith the existing value from jest-puppeteer.config.js, remove any non required variables and imports as the only value used from the imported file is the config.launch` value.

    • Make sure to remove any references to const config = require( '@wordpress/scripts/config/puppeteer.config.js' ); in the file.
  • Make sure to commit the changes on the package-lock.json file alongside the rest your changes.

Test Coverage

  • No extra tests needed

QA Brief

QA:Eng:

  • Reinstall node_modules with npm ci.
  • Run these NPM scripts and verify they work as expected:
    • test:js
    • test:js:watch
    • test:e2e
    • lint:js
    • lint:js-fix
  • Check all GitHub actions pass [with the exception of the WP9 E2E suite if it's not fixed by the time this is QA'd].

Changelog entry

  • N/A

felixarntz avatar Mar 26 '21 18:03 felixarntz

So far I've got an upgrade to the latest v13 working: https://github.com/google/site-kit-wp/pull/3335

Due to the updated JSdom inside the new Jest I had to upgrade the react-testing-library packages as well

The only failing test suite is TourTooltips.test.js. RTL sees everything as hidden (this can be revisited in the execution I'm sure)

Now I'm investigating the upgrade to v14 on this PR: https://github.com/google/site-kit-wp/pull/3336

The e2e tests are failing because of the change Replace jest-puppeteer with the forked version of jest-environment-puppeteer to use puppeteer-core directly (#29418). https://github.com/WordPress/gutenberg/blob/HEAD/packages/scripts/CHANGELOG.md#enhancements-2

danielgent avatar May 14 '21 12:05 danielgent

I got the upgrade to v14 working. Following a thread that had @tofumatt on it I found the new Jest e2e config for Gutenberg and copied this change: https://github.com/google/site-kit-wp/pull/3336/commits/e472350fa2b292f59afbe2e78f7d4e5a306ca1ef

My PR's GitHub's actions have been waiting in a queue for a while :thinking: , so I'll check later, but locally the e2e tests worked for me :smile:

danielgent avatar May 14 '21 13:05 danielgent

GitHub actions are now working again, and the v14 upgrade PR is working :heavy_check_mark:

https://github.com/google/site-kit-wp/pull/3336

danielgent avatar May 14 '21 17:05 danielgent

all checks pass for the v15 upgrade except one failing e2e (only on the recent builds of WP): https://github.com/google/site-kit-wp/pull/3371

Test in tests/e2e/specs/auth/gcp-flow-admin-2.test.js fails at the set up flow for the second administrator ✕ connects a secondary admin after the initial set up (36571 ms)

`expect(jest.fn()).not.toHaveErrored(expected)`

```Expected mock function not to be called but it was called with:
["Google Site Kit API Error method:GET datapoint:searchanalytics type:modules identifier:search-console error:\"Invalid Credentials\""]```

danielgent avatar May 17 '21 13:05 danielgent

All tests now passing for v15 upgrade

danielgent avatar May 25 '21 17:05 danielgent

My only concern when doing the upgrade is the changes I've done to TourTooltips.test.js https://github.com/google/site-kit-wp/pull/3371/files#diff-8b747863082adee538fb764205766199d7314adce64dd4f13dabffc56eca0cd5

Due to changes in our packages

  • many DOM elements are hidden so I had to override this when interacting await getByRole( 'alertdialog', { hidden: true } );

  • the getByRole selector is no longer finding the element it used to so I changed these to getByLabelText fireEvent.click( getByRole( 'button', { name: /close/i } ) ) to fireEvent.click( getByLabelText( /close/i ) );

danielgent avatar May 25 '21 18:05 danielgent

@danielgent, please, add an estimate for this ticket.

eugene-manuilov avatar Jun 01 '21 14:06 eugene-manuilov

@eugene-manuilov I put a 7 because there are changes required to these tests. Without those IMHO it would be a 3 as the work is already done in the PR I made

danielgent avatar Jun 02 '21 09:06 danielgent

IB :heavy_check_mark:

eugene-manuilov avatar Jul 12 '21 11:07 eugene-manuilov

As the ticket has been left in EB for a while, WordPress scripts is now up to version 17! I'll try this on another PR.

danielgent avatar Aug 16 '21 16:08 danielgent

I created two new PRs to upgrade to v16 https://github.com/google/site-kit-wp/pull/3878 and v17 https://github.com/google/site-kit-wp/pull/3879

All GitHub actions run :heavy_check_mark:

Next I'm just going to revisit this TourTooltips test again (due to the changes brought about by having to upgrade @testing-library/react)

danielgent avatar Aug 16 '21 16:08 danielgent

The version 17 upgrade looks fine.

I found a better way to fix the failing TourTooltips.test.js test suite. We just have to wait for things to be displayed (rather than brute-forcing finding hidden elements).

If all the GitHub actions pass then I'll set this to Code Review :+1:

danielgent avatar Aug 16 '21 17:08 danielgent

If this version 17 upgrade is fine then all the other PRs can be closed, and their branches deleted :smile:

danielgent avatar Aug 16 '21 17:08 danielgent

@eugene-manuilov are you working on this?

kuasha420 avatar Sep 24 '21 20:09 kuasha420

@kuasha420 not at the moment, but will work on it this sprint. We are going to re-think the approach for running different scripts, so this ticket will be likely restructured.

eugene-manuilov avatar Sep 27 '21 14:09 eugene-manuilov

Per discussion with @aaemnnosttv, @tofumatt, and @eugene-manuilov we've decided it makes more sense to get rid of @wordpress/scripts instead of spending more time trying to update it. I've updated the ACs accordingly.

felixarntz avatar Dec 09 '21 17:12 felixarntz

@eugene-manuilov does this IB have to be written by yourself, or could you be unassigned for others to potentially pick up? Happy either way, just wanted to check.

eclarke1 avatar Dec 15 '21 13:12 eclarke1

Yes, someone else can also do it. Removed my assignment for now.

eugene-manuilov avatar Dec 15 '21 14:12 eugene-manuilov

Thanks @mitogh, this looks pretty good overall, just a few questions and comments.

@mitogh do we need these specific versions for some reason? Why not cross-env babel-jest jest jest-circus @wordpress/jest-preset-default? As of Jest 27, jest-circus is the default runner but we also don't use it now with [email protected] with wp-scripts. I think upgrading Jest as part of this could be okay, but not if it would require more effort fixing/updating tests, etc. Not sure why we would install jest-circus separately though; happy to be convinced otherwise though!

  • Replace '<rootDir>/node_modules/@wordpress/scripts/config/babel-transform' with '<rootDir>/tests/e2e/babel-transform.js',

This is the same thing that scripts uses, so the code is fine there, but I think we should probably move this to be less-specific to E2E and more of a general Jest config. For that reason I think this probably makes more sense to live in tests/js rather than tests/e2e.

  • Replace the content from the the file jest-puppeteer.config.js with:

Please avoid providing code to copy and paste in the IB as it makes it harder to understand the intent and rationale 🙂 Here it looks like the idea is to inline the config from the scripts package because it isn't available elsewhere, is that correct?


Regarding E2E, I know the respective wp script does some special handling of --puppeteer-* flags (e.g. --puppeteer-interactive) that I think would need updating as well.

Regarding the estimate, I'm thinking we'll probably want at least 15 here as this changes quite a bit and there are likely to be problems that will come up once we start ripping things out 😄

I'd like to get @eugene-manuilov and @tofumatt 's eyes on this as well but I think we can already start iterating on it.

aaemnnosttv avatar Dec 20 '21 12:12 aaemnnosttv

Thanks, sure let me answer your questions.

do we need these specific versions for some reason?

Yes, using the latest from requires another level of effort due to the current version we are using from @wordpress/scripts configuration we are using as well relies on those versions of libraries as using the latest expect another type of configuration.

My idea here would be let's get rid of the dependency with minimal fraction as possible, eventually, we can iterate and upgrade those libraries as we move forward once we are no longer attached to the library, which would allow for a reduced level of effort.

Not sure why we would install jest-circus separately though; happy to be convinced otherwise though!

Looks like I confused the latest version of @wordpress/script with the one we are currently using where jest-circus is not required (on the version we are currently using) so we can safely remove that dependency from the IB.

. For that reason, I think this probably makes more sense to live in tests/js rather than tests/e2e

This makes more sense :)

Please avoid providing code to copy and paste in the IB as it makes it harder to understand the intent and rationale slightly_smiling_face Here it looks like the idea is to inline the config from the scripts package because it isn't available elsewhere, is that correct?

Makes sense, yes as we don't have the library available we need to locate configuration and setup files from the @wordpress/scripts package into the plugin.

Regarding E2E, I know the respective wp script does some special handling of --puppeteer-* flags (e.g. --puppeteer-interactive) that I think would need updating as well.

The script does support additional flags but is not set by default only if set directly via the command line, meaning that those can be set via package.json but is not the current behavior on the script we are using. As those flags are only set if those are passed when calling the scripts.

  • https://github.com/WordPress/gutenberg/blob/%40wordpress/scripts%4012.0.0/packages/scripts/scripts/test-e2e.js#L58

With that being said, we are not currently supporting those flags but if we need those we can always set as an additional script in package.json.

Updating the IB after this comment

Thanks @aaemnnosttv

mitogh avatar Dec 20 '21 15:12 mitogh