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

Update WordPress dependencies #1135

Merged
merged 27 commits into from
Nov 11, 2021
Merged

Update WordPress dependencies #1135

merged 27 commits into from
Nov 11, 2021

Conversation

noahtallen
Copy link
Contributor

@noahtallen noahtallen commented Sep 10, 2021

All Submissions:

Changes proposed in this Pull Request:

Over at wp-calypso, we're updating to React 17. This means getting our peer dependencies updated to the right versions, and it turns out that newspack-components is a peer dep of newspack-blocks, which we sync to WordPress.com via Calypso.

This PR updates to React 17 and to the latest WordPress component packages.

Also updates most NPM packages to the latest compatible versions.

Also specifies Node version support as v16.11.1, matching Calypso's Node support.

Also enables Dependabot to keep NPM and Composer packages up-to-date.

Bonus: Also fixes a minor pet peeve of mine, which is that this repo's npm run release:archive script previously built the plugin archive ZIP to the assets/release directory, whereas every other Newspack plugin repo builds to ./release (in the root). Now this repo should also build to the root ./release directory.

How to test the changes in this Pull Request:

  1. Using NVM, set your current Node version to v16.11.1 (matching Calypso's supported version)
  2. Ensure npm ci runs
  3. Ensure all NPM build, lint and test scripts still run (build, dev, lint, test)
  4. Test newspack components (see Components Demo page)
  5. Test newspack plugin (especially wizard pages)

Possible issues/follow-up

  • Dependency react-daterange-picker is stale and doesn't appear to be updated anymore. It doesn't list react 17 support, but I suppose it probably supports it anyways. The package still works in the Campaigns Analytics page, so I don't think we need to update this immediately.
  • Build doesn't work (possible incompatibility with the node version I'm using) Should now work with Node v16.11.1

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@noahtallen noahtallen self-assigned this Sep 10, 2021
@dkoo dkoo requested a review from a team September 10, 2021 15:37
@dkoo
Copy link
Contributor

dkoo commented Sep 10, 2021

Looping in the @Automattic/newspack-product team for additional testing and feedback. I was able to run npm ci && npm run build locally using Node v15.6.0. Confirming that Node v12.* is unable to install dependencies. So this change would require us to update our Node/NPM versions for dev as well as dependencies in all Newspack repos to match. This is not a bad thing and is probably overdue, but I'm not sure what our timeline for being able to do this is.

As for the CI "build" job failing, we probably need to update something in the CircleCI config to use Node v15+. cc @adekbadek as he knows most about our CI config.

@dkoo
Copy link
Contributor

dkoo commented Sep 13, 2021

@thomasguillot regarding this:

Dependency react-daterange-picker is stale and doesn't appear to be updated anymore. It doesn't list react 17 support, but I suppose it probably supports it anyways.

It seems to me like this package is only used in the DateRangePicker Newspack component, but I'm not seeing this component being used anywhere. Can we deprecate it entirely? Can we replace the third-party package with the core DateTime component instead?

Edit: Nevermind, I see it's used in the Campaigns analytics view. Here's another package that's maybe descended from the one we're using that is still maintained: https://github.com/wojtekmaj/react-daterange-picker

I also still think it might be possible to use the core DateTime component using the isDayHighlighted prop.

@noahtallen
Copy link
Contributor Author

I also still think it might be possible to use the core DateTime component using the isDayHighlighted prop.

Yeah, it's always nice to use core components when we can!

@noahtallen
Copy link
Contributor Author

we probably need to update something in the CircleCI config to use Node v15

I just checked, and it looks like the package-lock for the repo was generated with Npm 7, but CircleCI is still on npm 6. It appears to use node 14, which is also working for me locally now.

@noahtallen
Copy link
Contributor Author

I experimented with a few approaches, but haven't found a solution yet.

@adekbadek adekbadek mentioned this pull request Sep 15, 2021
6 tasks
.circleci/config.yml Outdated Show resolved Hide resolved
@adekbadek
Copy link
Member

With the build problems resolved (#1142), we now can deal with JS tests & linting failing 🕵️‍♀️

@thomasguillot
Copy link
Contributor

@thomasguillot regarding this:

Dependency react-daterange-picker is stale and doesn't appear to be updated anymore. It doesn't list react 17 support, but I suppose it probably supports it anyways.

It seems to me like this package is only used in the DateRangePicker Newspack component, but I'm not seeing this component being used anywhere. Can we deprecate it entirely? Can we replace the third-party package with the core DateTime component instead?

Edit: Nevermind, I see it's used in the Campaigns analytics view. Here's another package that's maybe descended from the one we're using that is still maintained: https://github.com/wojtekmaj/react-daterange-picker

I also still think it might be possible to use the core DateTime component using the isDayHighlighted prop.

I leave this up to @adekbadek 😊

@noahtallen
Copy link
Contributor Author

noahtallen commented Sep 23, 2021

I updated jest and the eslint packages and added a mock for a missing window global. This solved the unit test problem.

The issue with linting is because for some reason, eslint cannot find all of the eslint plugins which @wordpress/eslint-plugin installs. For some reason, it isn't finding them as a transitive dependency of the wp eslint plugin, so I've added all of the plugins it complained about to our dev dependencies. That seems to make eslint happy (other than actual lint issues which need to be fixed)

@miguelpeixe
Copy link
Member

miguelpeixe commented Sep 23, 2021

Although tests are passing, I'm getting build errors with node v16.7.0. We need to update the test images so the node version matches our target version.

According to docker run --rm circleci/php:7.2-node-browsers node -v, the node version for the tests is v14.15.2.

The issue I'm having is node-sass v4.13.0 not being available in the target version v16.7.0. The installed version using ^4.13.0 at this moment is 4.14.1, which supports up to node v14: https://github.com/sass/node-sass/releases/tag/v4.14.1

@noahtallen
Copy link
Contributor Author

Yeah, node-sass has been deprecated -- we had to replace it with plain sass in wp-calypso (see Automattic/wp-calypso#52729)

I was testing with Node 14 locally, which seems to work okay. Which version to we officially support?

@miguelpeixe
Copy link
Member

Oh, I didn't know that happened! We might have to do the same.

My understanding is that we'd like node to match wp-calypso's version. But I'd like @dkoo and @adekbadek's inputs on this.

@dkoo
Copy link
Contributor

dkoo commented Sep 23, 2021

Yeah, I think we'll ideally want to match Calypso's version. So that means deprecating node-sass in a similar way for all of our repos. This is one instance where I can see the benefit of a monorepo. 😄

@noahtallen
Copy link
Contributor Author

hahaha, yeah, I've been updating loads of dependencies in calypso, and it seems like every update requires 5 other updates as well 🤦

@dkoo
Copy link
Contributor

dkoo commented Oct 8, 2021

Hi all, I've been playing with trying to update Node to v16.* and the related dependencies, but I haven't had luck getting a successful build so far. What do we think about an intermediate update to Node v14.* and merging this PR more or less as-is, so we can unblock @noahtallen and the WP.com team?

@adekbadek
Copy link
Member

adekbadek commented Nov 8, 2021

Does that only happen on this branch? And/or is it something we can replicate on a temp site for debugging?

@dkoo Yes. DM'd you a temp site

},
"dependencies": {
"@wordpress/base-styles": "^4.0.0",
"@wordpress/components": "^17.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think new versions have come out in the meantime (v18 is available), so it might be worth updating again to avoid having to do it later

Copy link
Contributor

Choose a reason for hiding this comment

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

Like trying to hit a moving target! This PR implements Dependabot, so I might freeze the updates as they are right now since things are currently building and functional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, that also sounds like a good plan!

Like trying to hit a moving target

Yeah, it can be very difficult 😬

@dkoo
Copy link
Contributor

dkoo commented Nov 9, 2021

Couple of updates: this error is replicable on brand new sites and seems somehow related to webpack and the importing of SCSS files. For example, on the Plugins screen, if you disable importing ./plugins-screen.scss in plugins-screen.js, the error doesn't occur. I'm not seeing any functional errors as a result of it. When mediaelement-and-player.min.js is actually used (e.g. in the classic Widgets screen), the error also doesn't occur. I'm not sure where to go from here on this bug.

Also, when testing Newspack Components as a package imported to another repo (Newspack Blocks), I ran into errors related to CommonJS (module is not defined). Switching the main entrypoint for the package from CJS to ESM as in 3c8aca7 fixes the issue in Newspack Blocks, but I'm not sure of the wider ramifications for Calypso.

@dkoo
Copy link
Contributor

dkoo commented Nov 9, 2021

Another update! I've found that if I include mediaelement-core as a dependency in our wp_enqueue_script statements, it fixes these JS errors.

But this is frustrating: now I'm getting a new JS error that I haven't seen before when viewing the Campaigns wizard:

Uncaught TypeError: _interopRequireDefault is not a function
    <anonymous> webpack://newspack/./node_modules/dom-helpers/class/addClass.js?:8
    js https://<site_url>/wp-content/plugins/newspack-plugin/dist/popups.js?ver=1636499874:1349
[...]

@dkoo
Copy link
Contributor

dkoo commented Nov 10, 2021

458beb8 fixes the _interopRequireDefault is not a function build error—which was coming from the recharts package—by replacing recharts with google-react-charts.

The Campaigns wizard should be restored now and all other wizard pages should still be working as expected.

However, I'm now getting failing phpunit tests in CI:

Error: The PHPUnit Polyfills library is a requirement for running the WP test suite.
If you are trying to run plugin/theme integration tests, make sure the PHPUnit Polyfills library (https://github.com/Yoast/PHPUnit-Polyfills) is available and either load the autoload file of this library in your own test bootstrap before calling the WP Core test bootstrap file; or set the absolute path to the PHPUnit Polyfills library in a "WP_TESTS_PHPUNIT_POLYFILLS_PATH" constant to allow the WP Core bootstrap to load the Polyfills.

If you are trying to run the WP Core tests, make sure to set the "WP_RUN_CORE_TESTS" constant to 1 and run `composer install` before running the tests.
Once the dependencies are installed, you can run the tests using the Composer-installed version of PHPUnit or using a PHPUnit phar file, but the dependencies do need to be installed whichever way the tests are run.

I think this is out-of-scope to fix in this PR, though, since it looks like it requires some migration on our part and seems unrelated to the changes in this branch. @Automattic/newspack-product please confirm.

@dkoo dkoo added [Status] Needs Review The issue or pull request needs to be reviewed and removed [Status] Approved The pull request has been reviewed and is ready to merge labels Nov 10, 2021
Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

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

Fixed the PHPUnit thing in 145fd5e

Left one question about newspack-components version, otherwise it works as expected.

assets/components/package.json Show resolved Hide resolved
.circleci/config.yml Show resolved Hide resolved
@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Nov 11, 2021
@dkoo dkoo merged commit 14e78df into master Nov 11, 2021
@dkoo dkoo deleted the update/wp-deps branch November 11, 2021 17:08
@matticbot
Copy link
Contributor

🎉 This PR is included in version 2.0.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@matticbot
Copy link
Contributor

🎉 This PR is included in version 2.0.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.66.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.66.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants