Skip to content

Update NodeJS to v20 #4264

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

Draft
wants to merge 67 commits into
base: develop
Choose a base branch
from
Draft

Update NodeJS to v20 #4264

wants to merge 67 commits into from

Conversation

diegocurbelo
Copy link
Member

@diegocurbelo diegocurbelo commented Apr 25, 2025

Fixes STRIPE-<linear_issue_id>
Fixes #<github_issue_id>

Changes proposed in this Pull Request:

This PR updates NodeJS from version v16 to v20.

  • Updates the dependencies
  • Updates the dev dependencies
  • Migrate Webpack configuration from v4 to v5
  • Fix jest tests
  • Fix build warnings (SASS/SCSS deprecation warnings)
  • Fix linting rules

Testing instructions


  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Comment

Post merge

@@ -1,2 +1,5 @@
legacy-peer-deps=true
engine-strict=true
save-exact = true
Copy link
Member Author

Choose a reason for hiding this comment

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

Config copied from Guteberg

Comment on lines +3 to +11
module.exports = {
...require( '@wordpress/prettier-config' ),
overrides: [
{
files: [ 'changelog.txt' ],
options: { parser: 'markdown' },
},
],
};
Copy link
Member Author

Choose a reason for hiding this comment

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

Config copied from Guteberg

@@ -89,7 +89,7 @@ function load_js_transpiling_source_maps(): array {
}

foreach ( $file_json[ 'sources' ] as $source ) {
$source = preg_replace( '%^webpack:///\./(client/.*)$%', '${1}', $source );
$source = preg_replace( '%^webpack://\./(client/.*)$%', '${1}', $source );
Copy link
Member Author

Choose a reason for hiding this comment

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

In the Webpack 5 config, we are manually setting devtoolModuleFilenameTemplate, so we can replace the previous triple slash prefixes with normal URL-like paths webpack://[resource-path]

Comment on lines +65 to +70
'@wordpress/i18n-text-domain': [
'error',
{
allowedTextDomain: 'woocommerce-gateway-stripe',
},
],
Copy link
Contributor

Choose a reason for hiding this comment

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

@wordpress/i18n-text-domain was reporting a lot of issues. I chose to specify our expected text domain, but we could also keep to the defaults.

@@ -82,4 +88,5 @@ module.exports = {
'@wordpress/data',
],
},
ignorePatterns: [ 'phpunit-html/**' ],
Copy link
Contributor

Choose a reason for hiding this comment

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

I tripped over a local folder left over from testing and realised it should always be ignored for linting.

@daledupreez
Copy link
Contributor

Progress

Linting

Linting is now working, but there are still 13 errors stemming from the following:

  • 6 errors: React 18 deprecated ReactDOM.render() in favour of createRoot() (docs link). If someone wants to tackle that, feel free. 😁
  • 5 errors: client/entrypoints/express-checkout/index.js is failing a @typescript-eslint/no-use-before-define rule because it looks like there are circular dependencies between some functions.
  • 2 errors: client/data/payment-gateway/hooks.js and client/data/settings/hooks.js both claim to have unnecessary dependencies in the some hooks.

Javascript Unit Tests

Many JS tests are not even running, mostly due to one of the following three errors:

TypeError: Cannot read properties of undefined (reading 'zone')
TypeError: Cannot read properties of undefined (reading 'add')
TypeError: (0 , _data.createSelector) is not a function

For the first two errors, the root cause seems to be an issue relating to the interplay between moment and moment-timezone from within the @wordpress/date package, where we have multiple versions of the package in use across the dependency tree. 😐

The final error stems from an import of createSelector from @wordpress/data. Not sure how that's getting borked! 🙃

There are then a handful of what look like legitimate test failures. At least some are related to code trying to test async or delayed loading.

SASS warnings

It looks like we would be able to avoid some of these by updating @wordpress/scripts, but we may simply need to disable/silence the warnings for now. I'll explore whether we can update that tomorrow (unless someone else gets to it first).

Copy link
Contributor

@daledupreez daledupreez left a comment

Choose a reason for hiding this comment

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

Also, before I forget to note this, we almost certainly need to look at extracting some of these changes into smaller PRs that we can test and merge independently. Based on the work I did, I can think of a few areas that might qualify for this:

  • Switch from @import to @use in the SCSS files
  • Re-order some SCSS that was split by nested rules
  • Re-order some JS files to ensure that code is defined before it is used
  • Moving some dependencies to devDependencies (though they would still need to get their version bumped separately)
  • Remove some unnecessary React hook deps
  • There are a lot of linting changes that might be ignored/accepted by the older linter - if we can extract some of these out, this patch will be much more manageable

@@ -1,2 +1,5 @@
legacy-peer-deps=true
engine-strict=true
save-exact = true
Copy link
Contributor

Choose a reason for hiding this comment

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

While working on various dependencies, I noticed that this results in the default ^ prefix for compatible versions being removed. I am not sure how I feel about that, but I wanted to flag it as a key side-effect.

engine-strict=true
save-exact = true
engine-strict = true
legacy-peer-deps = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this? Maybe something for a follow-up PR.

@laurendavissmith
Copy link
Contributor

Pushed up my changes which don't resolve the jest issue but nudge things in the right direction. Individual tests are still handling too much of their own mocking which is causing a lot of headaches. The mocks setup needs to be rethought entirely and shift as much as possible to handling with global mocks and overrides in the test files only when absolutely necessary.

I also experimented with a jest-early-mocks.js file which can be configured in the the setupFiles part of the jest config. I didn't end up needing it but if you run into race conditions that can be a useful way out.

let data = normalizeOrderData( sourceEvent, paymentRequestType );
data = getRequiredFieldDataFromCheckoutForm( data );

return $.ajax( {
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't looked to see how this gets utilized but I don't love that we return a promise with no default error state. It forces every instance of createOrder to implement an error catch since there is no fallback.

Copy link

github-actions bot commented May 5, 2025

📈 PHP Unit Code Coverage Report

Package Line Rate Health
includes/abstracts/abstract-wc-stripe-payment-gateway.php 48%
includes/admin/class-wc-rest-stripe-settings-controller.php 81%
includes/admin/class-wc-stripe-settings-controller.php 21%
includes/class-wc-stripe-apple-pay-registration.php 60%
includes/class-wc-stripe-feature-flags.php 89%
includes/class-wc-stripe-intent-controller.php 31%
includes/compat/trait-wc-stripe-subscriptions.php 20%
includes/payment-methods/class-wc-stripe-upe-payment-gateway.php 48%
includes/payment-methods/class-wc-stripe-upe-payment-method-blik.php 41%
includes/payment-methods/class-wc-stripe-upe-payment-method-cash-app-pay.php 67%
includes/payment-methods/class-wc-stripe-upe-payment-method-cc.php 92%
includes/payment-methods/class-wc-stripe-upe-payment-method-sepa.php 91%
includes/payment-methods/class-wc-stripe-upe-payment-method.php 56%
includes/payment-tokens/class-wc-stripe-payment-tokens.php 18%
Summary 44% (7245 / 16298)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants