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

Support Node 16 #965

Merged
merged 58 commits into from
Feb 27, 2023
Merged

Support Node 16 #965

merged 58 commits into from
Feb 27, 2023

Conversation

raiyaj
Copy link
Contributor

@raiyaj raiyaj commented Feb 7, 2023

Add support for node 16 by deleting PerformanceTimer class, and make node 16 the default version for new projects.

GUS: W-12399737

Description

Over on MRT, we're working on enabling platform-level support for node 16 apps. It currently doesn't work if the app depends on pwa-kit-runtime because of an issue with PerformanceTimer, our custom wrapper around the builtin node perf_hooks API. It turns out that we don't use PerformanceTimer for anything useful (it gathers metrics that we emit to CloudWatch, but Lambda automatically emits the same metrics to CloudWatch). Since the class is marked as @private, this deletes it (which is not a breaking change) and adds explicit support for node 16.

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • Remove PerformanceTimer and all its usages
  • Explicitly support node 16 in all package.jsons, and make 16.x the default node version for new projects
  • Update CircleCI workflow to include node 16 and npm 7 and 8
  • Update create-mobify-app-dev.js to account for breaking changes in npm 7
  • Fix (or make more resilient) a handful of retail-react-app tests, which were mostly failing due to race conditions that were uncovered with the switch to node 16, because the test execution environment became faster
  • Re-introduce changes from Add explicit ws dependency #865
    • It was released in an alpha release ([email protected]), but somehow didn't make it into the next normal release, so running npm run tail-logs in a newly-generated project returns an error.

How to Test-Drive This PR

  • Run npm ci at the root of this repo
  • Repeat the following for node 14.17.0 (npm 6), node 16.7.0 (npm 7), node 16.11.0 (npm 8), and node 16.19.1 (LTS, npm 8):
    • Run nvm use <node-version>, then generate a new project:
    GENERATOR_PRESET=test-project node packages/pwa-kit-create-app/scripts/create-mobify-app-dev.js --outputDir 
    ~/generated-test-project
    
    • cd to the project, then run npm start. The app should load in the browser without errors.
    • Make sure your Runtime Admin API key is set in ~/.mobify, then deploy your bundle to MRT: npm run push -- -s <project-slug> -t <target-slug>
    • Run npm run tail-logs -- -p scaffold-pwa -e production and ensure logs appear after a few seconds.

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@raiyaj raiyaj changed the title Support Node 16 in pwa-kit-runtime Support Node 16 Feb 7, 2023
Copy link
Collaborator

@bfeister bfeister left a comment

Choose a reason for hiding this comment

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

@raiyaj we have some other incoming changes like React 18. That one in particular is breaking / not backwards compatible. My main interest is to verify that this is backwards compatible with node 14 so we don't have to do a major version bump?

@bfeister bfeister mentioned this pull request Feb 10, 2023
@bfeister bfeister linked an issue Feb 10, 2023 that may be closed by this pull request
@raiyaj raiyaj force-pushed the pwa-kit-runtime-node16 branch from 35ca1cd to 6684628 Compare February 14, 2023 23:58
@raiyaj raiyaj force-pushed the pwa-kit-runtime-node16 branch from 1474291 to 614549f Compare February 15, 2023 22:54
@raiyaj raiyaj marked this pull request as ready for review February 15, 2023 23:20
@raiyaj raiyaj requested a review from a team as a code owner February 15, 2023 23:20
@@ -30,7 +30,7 @@ jobs:
pwa-kit:
strategy:
matrix:
node: [14]
node: [14, 16]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we also trigger a Node 16 build on Windows by adding 16 to the windows job matrix, please?

pwa-kit-windows:
strategy:
# TODO: We don't *need* a matrix with single values,
# but is it worth keeping for supporting multiple versions in the future?
matrix:
node: [14]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Waiting to see if the tests pass 🤞🏼

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, @raiyaj since Node 16 is the active Node version, Do you mind also updating the generated builds to use Node 16?

node-version: 14

node-version: 14

const candidates = [
resolve(projectDir, 'node_modules', pkg),
resolve(__dirname, '..', '..', 'node_modules', pkg),
resolve(__dirname, '..', '..', '..', 'node_modules', pkg)
Copy link
Collaborator

@adamraya adamraya Feb 22, 2023

Choose a reason for hiding this comment

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

Good finding @raiyaj!
It looks like we don't need the last one since we saw that generates the wrong path with the duplicated node_modules folder.

Copy link
Contributor Author

@raiyaj raiyaj Feb 22, 2023

Choose a reason for hiding this comment

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

Thanks Adam! I was thinking of removing it initially, but I added some logging here (in the Setup Ubuntu Machine step), and saw that when a project is generated in CI, __dirname is /home/runner/work/pwa-kit/pwa-kit/packages/pwa-kit-dev/dist/configs/webpack, whereas locally it's /Users/rjessa/generated-test-project/node_modules/pwa-kit-dev/configs/webpack, so we need to try both options.

I copied the candidates idea from here, where we do something similar.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The method's name findInProjectThenSDK implies two places but we now look at three places.
It can be confusing for anyone else looking at the logic or facing a similar problem in the future.

@raiyaj Do you mind leaving a comment in the code explaining why we need to do this to support NPM 7 and Node 16?

Copy link
Collaborator

@adamraya adamraya left a comment

Choose a reason for hiding this comment

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

One last #965 (comment) to document the change in the Webpack config to provide a bit of context for engineers looking at that in the future.

Thanks @raiyaj, Looks good to me!
Congrats on solving all the issues 🎉

@adamraya
Copy link
Collaborator

adamraya commented Feb 23, 2023

@raiyaj I saw a problem with the change we did to theIS_DEFAULT_NPM env variable.
Now we'll have TWO builds that will run steps that only need to happen once like: Push Bundle to MRT or Publish to NPM.

If we follow the current approach, we need a new env variable to designate the unique/main build and update the conditional to include that env variable and guarantee we run the steps only once.

pwa-kit job

#### generated job

Edit: As @raiyaj saw, we don't need to change the generated builds for now.

@raiyaj raiyaj merged commit b743269 into develop Feb 27, 2023
@raiyaj raiyaj deleted the pwa-kit-runtime-node16 branch February 27, 2023 23:45
bfeister added a commit that referenced this pull request Feb 28, 2023
* develop:
  Support Node 16 (#965)
  [W-12450361] Introduce short-circuit method for bypassing auth in Commerce Provider by passing in a fetchedToken (#1010)
  remove jest-silent-reporter (#1009)
  Clean up Page Designer Code (#1004)
  [Shopper Experience] `ImageWithText` component (#991)
  Feature: Page Designer Carousel Component (#977)
  [Feature] Page Designer Layout Components WIP (#993)
  remove updatePw from not implemented list (#996)
  Back-port Shopper Experience Base Components into Retail Template (#992)

# Conflicts:
#	packages/commerce-sdk-react/package-lock.json
#	packages/commerce-sdk-react/package.json
#	packages/pwa-kit-dev/package-lock.json
#	packages/pwa-kit-dev/src/configs/webpack/config.js
#	packages/template-retail-react-app/package-lock.json
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.

[BUG] Node v16.x [BUG] [email protected] does not work with node 16
3 participants