Remove @wordpress/scripts
@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/scriptspackage 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/scriptsby runningnpm uninstall @wordpress/scripts - Remove your
node_modulesso you can verify the binarywp-scriptsno longer exists.rm -rf node_modules - Then install the modules again with
npm install - Verify that the package
@wordpress/scriptsis removed frompackage.json
Update current scripts
- Inside of
package.jsonlook for all the scripts withwp-scriptsthat 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.jswithcross-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
presentwithpreset: '@wordpress/jest-preset-default' - Replace
'<rootDir>/node_modules/@wordpress/scripts/config/babel-transform'with'<rootDir>/tests/e2e/babel-transform.js',
- Removing
test:js:watch- Replace
wp-scripts test-unit-js --config=tests/js/jest.config.js --watchwithnpm run test:js -- --watch
- Replace
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.jswithcross-env WP_BASE_URL=http://localhost:9002 ./tests/e2e/script.js - Edit the file
tests/e2e/scripts.jsand remove all the imports from../utilshttps://github.com/WordPress/gutenberg/blob/%40wordpress/scripts%4012.0.0/packages/scripts/scripts/test-e2e.js#L19-L29 - Set the
envtonodeat 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
- Install the following packages
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-jswith 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
.prettierignoreand add the following content insidebuild vendor node_modules dist third-party bin - Add the
prettier-configpackage vianpm install @wordpress/prettier-config --save-dev
- Replace
-
Merge the content from https://github.com/WordPress/gutenberg/blob/%40wordpress/scripts%4012.0.0/packages/scripts/config/puppeteer.config.js
with the existing value fromjest-puppeteer.config.js, remove any non required variables and imports as the only value used from the imported file is theconfig.launch` value.- Make sure to remove any references to
const config = require( '@wordpress/scripts/config/puppeteer.config.js' );in the file.
- Make sure to remove any references to
-
Make sure to commit the changes on the
package-lock.jsonfile alongside the rest your changes.
Test Coverage
- No extra tests needed
QA Brief
QA:Eng:
- Reinstall
node_moduleswithnpm ci. - Run these NPM scripts and verify they work as expected:
test:jstest:js:watchtest:e2elint:jslint: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
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
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:
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
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\""]```
All tests now passing for v15 upgrade
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
getByRoleselector is no longer finding the element it used to so I changed these togetByLabelTextfireEvent.click( getByRole( 'button', { name: /close/i } ) )tofireEvent.click( getByLabelText( /close/i ) );
@danielgent, please, add an estimate for this ticket.
@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
IB :heavy_check_mark:
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.
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)
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:
If this version 17 upgrade is fine then all the other PRs can be closed, and their branches deleted :smile:
@eugene-manuilov are you working on this?
@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.
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.
@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.
Yes, someone else can also do it. Removed my assignment for now.
Thanks @mitogh, this looks pretty good overall, just a few questions and comments.
- Install the following packages:
npm install cross-env [email protected] [email protected] [email protected] @wordpress/jest-preset-default --save-dev
@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.jswith:
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.
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