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
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
298e638
add explicit dependency on ws
raiyaj Feb 7, 2023
906b23e
add custom docs url for 403 errors
raiyaj Feb 7, 2023
b8d680d
remove performance timer
raiyaj Feb 7, 2023
fa17a85
add explicit support for node 16
raiyaj Feb 7, 2023
86f9353
add explicit pwa-kit-dev support for node 16
raiyaj Feb 7, 2023
3eb9ee1
add explicit support for node 16 across the board
raiyaj Feb 7, 2023
c9e24b6
delete performance timer tests
raiyaj Feb 7, 2023
e81ea18
add explicit support for node 18
raiyaj Feb 9, 2023
74081e3
add node 16 and 18 to test matrix
raiyaj Feb 9, 2023
4b463a5
Revert "add explicit support for node 18"
raiyaj Feb 10, 2023
5c23e0e
remove 18 from test matrix
raiyaj Feb 10, 2023
261d49a
fix use-product-view-modal test
raiyaj Feb 13, 2023
2e88658
fix use-wishlist test
raiyaj Feb 14, 2023
6684628
lint
raiyaj Feb 14, 2023
5678a28
fix product-view test
raiyaj Feb 15, 2023
4f3dd08
lint
raiyaj Feb 15, 2023
614549f
try to fix with-registration test
raiyaj Feb 15, 2023
5182c84
update changelog
raiyaj Feb 15, 2023
60ae753
Merge branch 'develop' into pwa-kit-runtime-node16
raiyaj Feb 15, 2023
3c2e5a4
update pwa-kit-dev changelog
raiyaj Feb 15, 2023
ea563c5
add node 16 to windows test matrix
raiyaj Feb 15, 2023
40be1e2
change default pwa kit version to 16.x
raiyaj Feb 16, 2023
942dad5
try to fix flaky reset-password test
raiyaj Feb 16, 2023
cdbe418
switch generated builds to node 16
raiyaj Feb 16, 2023
fdc6d21
add npm 7 and 8 to windows test matrix
raiyaj Feb 16, 2023
70e1bdf
try to make reset-password test even more resilient
raiyaj Feb 16, 2023
7a7567a
add -y flag to npx command to prevent timeouts when generating projec…
raiyaj Feb 17, 2023
58f8ca4
try to make registration test more resilient
raiyaj Feb 17, 2023
35dad46
try to make account test more resilient
raiyaj Feb 17, 2023
b571ee7
try to make registration test more resilient
raiyaj Feb 17, 2023
bdf0896
conditionally pass -y flag to npx based on current node/npm version
raiyaj Feb 17, 2023
f73e739
exclude unnecessary node/npm combinations from test matrices
raiyaj Feb 17, 2023
8078e1b
fix indentation
raiyaj Feb 17, 2023
25dc0d6
make sure pwa-kit-create-app@latest gets installed
raiyaj Feb 17, 2023
5674fe6
Merge branch 'develop' into pwa-kit-runtime-node16
raiyaj Feb 17, 2023
0f2cf9d
set npx flags based on the version of npm, not node
raiyaj Feb 17, 2023
1298a0f
update IS_DEFAULT_NPM
raiyaj Feb 17, 2023
f123067
try to make reset-password test more resilient
raiyaj Feb 17, 2023
d6e14c1
clean up tests
raiyaj Feb 19, 2023
3eb363b
fix sdk dir path
raiyaj Feb 22, 2023
d90306f
add logs
raiyaj Feb 22, 2023
85fbe74
make sure sdkDir resolves to pwa-kit-dev
raiyaj Feb 22, 2023
5c7552a
refactor
raiyaj Feb 22, 2023
0dcfef7
return a default path rather than throwing an error
raiyaj Feb 22, 2023
e7f7df6
Merge branch 'develop' into pwa-kit-runtime-node16
raiyaj Feb 22, 2023
f230864
update READMEs and babel configs
raiyaj Feb 22, 2023
0c50c68
try to make tests more resilient
raiyaj Feb 22, 2023
ee119ad
lint
raiyaj Feb 22, 2023
0e6e00e
add comment about looking for pwa-kit-dev node_modules in two places
raiyaj Feb 23, 2023
b7186e8
try to make tests more resilient
raiyaj Feb 23, 2023
38dbed1
undo unnecessary change
raiyaj Feb 23, 2023
5bc8c36
ensure pwa-kit publish steps are only run once
raiyaj Feb 24, 2023
570c53d
Merge branch 'develop' into pwa-kit-runtime-node16
raiyaj Feb 24, 2023
87cf7eb
remove node 16 / npm 6 builds
raiyaj Feb 25, 2023
cba5cb5
try to make reset-password test more resilient
raiyaj Feb 25, 2023
85cd2dc
Merge branch 'develop' into pwa-kit-runtime-node16
raiyaj Feb 27, 2023
c08035f
try to make registration test more resilient
raiyaj Feb 27, 2023
6ec6d7d
Merge branch 'develop' into pwa-kit-runtime-node16
raiyaj Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ 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

npm: [6, 7, 8]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same. Node 16 requires npm7. Let's skip the Node 16 and npm 6 build from the matrix:

Suggested change
npm: [6, 7, 8]
npm: [6, 7, 8]
exclude:
- node: 16
npm: 6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see what you mean - node 16 comes with npm 7 or 8, so there's no point testing node 16 with npm 6. In that case, would we also exclude node 14 with npm 7 and 8?

https://nodejs.org/en/download/releases/

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, let me think a bit more.
Node 16 comes by default with npm 7.
Support to npm@6 will be until Node 14 goes EOL because npm@6 is shipped with Node 14.

I'm wrong. We still need to test npm 6 with both Node 14 and Node 16 until Node 14 reaches EOL.

Copy link
Contributor Author

@raiyaj raiyaj Feb 17, 2023

Choose a reason for hiding this comment

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

Ok, it makes sense that we need to support npm 6 until node 14 reaches EOL. I wonder whether in practice, anyone would use a different version of npm than the one that comes installed with their current node version though 🤔

I will change it back, but something interesting I noticed is that after Brian and I fixed the tests that were consistently failing, several more builds have failed due to flaky tests and (for the most part) they happen on the non-default node/npm combinations (ex. here, here, and here).

runs-on: ubuntu-latest
env:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since Node 16 is our active version, we should also change the default npm to npm@8.

env:
# The "default" npm is the one that ships with a given version of node
# node v14 uses npm@6, latest node v16 uses npm@8
# For more: https://nodejs.org/en/download/releases/
IS_DEFAULT_NPM: ${{ matrix.npm == 6 }}

# The "default" npm is the one that ships with a given version of node
# node v14 uses npm@6, latest node v16 uses npm@8
# The "default" npm is the one that ships with a given version of node.
# For more: https://nodejs.org/en/download/releases/
IS_DEFAULT_NPM: ${{ matrix.npm == 6 }}
IS_DEFAULT_NPM: ${{ matrix.node == 14 && matrix.npm == 6 || matrix.node == 16 && matrix.npm == 8 }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -118,11 +117,13 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
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]
npm: [6]
matrix:
node: [14, 16]
npm: [6, 7, 8]
env:
# The "default" npm is the one that ships with a given version of node.
# For more: https://nodejs.org/en/download/releases/
IS_DEFAULT_NPM: ${{ matrix.node == 14 && matrix.npm == 6 || matrix.node == 16 && matrix.npm == 8 }}
runs-on: windows-latest
steps:
- name: Checkout
Expand All @@ -134,6 +135,11 @@ jobs:
node-version: ${{ matrix.node }}
cache: npm

- name: Update NPM version
if: env.IS_DEFAULT_NPM == 'false'
run: |-
npm install -g npm@${{ matrix.npm }}

- name: Setup Windows Machine
uses: "./.github/actions/setup_windows"

Expand All @@ -157,7 +163,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16

- name: Setup Ubuntu Machine
uses: "./.github/actions/setup_ubuntu"
Expand Down Expand Up @@ -247,7 +253,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16

- name: Setup Windows Machine
uses: "./.github/actions/setup_windows"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pwa-kit",
"version": "2.7.0-dev",
"engines": {
"node": "^14.0.0",
"node": "^14.0.0 || ^16.0.0",
"npm": "^6.14.4 || ^7.0.0 || ^8.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/commerce-sdk-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "[email protected]",
"license": "See license in LICENSE",
"engines": {
"node": "^14.0.0",
"node": "^14.0.0 || ^16.0.0",
"npm": "^6.14.4 || ^7.0.0 || ^8.0.0"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/internal-lib-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "internal-lib-build",
"version": "2.7.0-dev",
"engines": {
"node": "^14.0.0",
"node": "^14.0.0 || ^16.0.0",
"npm": "^6.14.4 || ^7.0.0 || ^8.0.0"
},
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-kit-create-app/assets/pwa/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = {
],
// Additional parameters that configure Express app behavior.
ssrParameters: {
ssrFunctionNodeVersion: '14.x',
ssrFunctionNodeVersion: '16.x',
proxyConfigs: [
{
host: '${commerceApi.shortCode}.api.commercecloud.salesforce.com',
Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-kit-create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"test": "internal-lib-build test"
},
"engines": {
"node": "^14.0.0",
"node": "^14.0.0 || ^16.0.0",
"npm": "^6.14.4 || ^7.0.0 || ^8.0.0"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const p = require('path')
const sh = require('shelljs')
const fs = require('fs')
const cp = require('child_process')
const semver = require('semver')

sh.set('-e')

Expand Down Expand Up @@ -147,7 +148,12 @@ const runGenerator = () => {
// Shelljs can't run interactive programs, so we have to switch to child_process.
// See https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec

cp.execSync(`npx pwa-kit-create-app ${process.argv.slice(2).join(' ')}`, {
const extension = process.platform === 'win32' ? '.cmd' : ''
const npm = `npm${extension}`
const foundNpm = cp.spawnSync(npm, ['-v']).stdout.toString().trim()
const flags = semver.satisfies(foundNpm, '>=7') ? '-y' : ''
Comment on lines +151 to +154
Copy link
Contributor Author

@raiyaj raiyaj Feb 17, 2023

Choose a reason for hiding this comment

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

The -y flag was added to npx in npm 7 (link), and it's important to add to avoid timeouts for generator builds in ci. To find the current npm version, I'm following the win32 logic that's in check-version.js here.


cp.execSync(`npx ${flags} pwa-kit-create-app@latest ${process.argv.slice(2).join(' ')}`, {
stdio: 'inherit'
})
}
Expand Down
2 changes: 2 additions & 0 deletions packages/pwa-kit-dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## v2.7.0-dev (Jan 25, 2023)
- Add explicit `ws` dependency [#865](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/865)

## v2.6.0 (Jan 25, 2023)
- Upgrade prettier to v2 [#926](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/926)
- Security package updates
Expand Down
18 changes: 15 additions & 3 deletions packages/pwa-kit-dev/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/pwa-kit-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"webpack-dev-middleware": "^5.2.2",
"webpack-hot-middleware": "^2.25.1",
"webpack-hot-server-middleware": "^0.6.1",
"webpack-notifier": "^1.12.0"
"webpack-notifier": "^1.12.0",
"ws": "^8.12.0"
},
"devDependencies": {
"@loadable/component": "^5.15.0",
Expand All @@ -117,7 +118,7 @@
"@loadable/component": "^5.15.0"
},
"engines": {
"node": "^14.0.0",
"node": "^14.0.0 || ^16.0.0",
"npm": "^6.14.4 || ^7.0.0 || ^8.0.0"
},
"publishConfig": {
Expand Down
5 changes: 5 additions & 0 deletions packages/pwa-kit-dev/src/utils/script-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ export class CloudAPIClient {
error = {} // Cloud doesn't always return JSON
}

if (res.status === 403) {
error.docs_url =
'https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/mrt-overview.html#users,-abilities,-and-roles'
}

throw new Error(
[
`HTTP ${res.status}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-kit-react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.7.0-dev",
"description": "A library that supports the isomorphic React rendering pipeline for Commerce Cloud Managed Runtime apps",
"engines": {
"node": "^14.0.0",
"node": "^14.0.0 || ^16.0.0",
"npm": "^6.14.4 || ^7.0.0 || ^8.0.0"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-kit-react-sdk/setup-jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jest.mock('pwa-kit-runtime/utils/ssr-config', () => {
'**/*.json'
],
ssrParameters: {
ssrFunctionNodeVersion: '14.x',
ssrFunctionNodeVersion: '16.x',
proxyConfigs: [
{
host: 'kv7kzm78.api.commercecloud.salesforce.com',
Expand Down
2 changes: 2 additions & 0 deletions packages/pwa-kit-runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## v2.7.0-dev (Jan 25, 2023)
- Support Node 16 [#965](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/965)

## v2.6.0 (Jan 25, 2023)
- Security package updates

Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-kit-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}
},
"engines": {
"node": "^14.0.0",
"node": "^14.0.0 || ^16.0.0",
"npm": "^6.14.4 || ^7.0.0 || ^8.0.0"
},
"publishConfig": {
Expand Down
14 changes: 0 additions & 14 deletions packages/pwa-kit-runtime/src/ssr/server/build-remote-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
isRemote,
MetricsSender,
outgoingRequestHook,
PerformanceTimer,
processLambdaResponse,
responseSend,
configureProxyConfigs,
Expand Down Expand Up @@ -495,15 +494,11 @@ export const RemoteServerFactory = {
locals.afterResponseCalled = false
locals.responseCaching = {}

locals.timer = new PerformanceTimer(`req${locals.requestId}`)
locals.originalUrl = req.originalUrl

// Track this response
req.app._requestMonitor._responseStarted(res)

// Start timing
locals.timer.start('express-overall')

// If the path is /, we enforce that the only methods
// allowed are GET, HEAD or OPTIONS. This is a restriction
// imposed by API Gateway: we enforce it here so that the
Expand All @@ -519,8 +514,6 @@ export const RemoteServerFactory = {
const afterResponse = () => {
/* istanbul ignore else */
if (!locals.afterResponseCalled) {
locals.timer.end('express-overall')
locals.timingResponse && locals.timer.end('express-response')
locals.afterResponseCalled = true
// Emit timing unless the request is for a proxy
// or bundle path. We don't want to emit metrics
Expand All @@ -547,9 +540,6 @@ export const RemoteServerFactory = {
}
req.app.sendMetric(metricName)
}
locals.timer.finish()
// Release reference to timer
locals.timer = null
}
}

Expand Down Expand Up @@ -969,16 +959,12 @@ const prepNonProxyRequest = (req, res, next) => {
* @private
*/
const ssrMiddleware = (req, res, next) => {
const timer = res.locals.timer
timer.start('ssr-overall')

setDefaultHeaders(req, res)
const renderStartTime = Date.now()

const done = () => {
const elapsedRenderTime = Date.now() - renderStartTime
req.app.sendMetric('RenderTime', elapsedRenderTime, 'Milliseconds')
timer.end('ssr-overall')
}

res.on('finish', done)
Expand Down
10 changes: 1 addition & 9 deletions packages/pwa-kit-runtime/src/ssr/server/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,10 @@ export const cacheResponseWhenDone = ({
// We know that all the data has been written, so we
// can now store the response in the cache and call
// end() on it.
const timer = res.locals.timer
req.app.applicationCache._cacheDeletePromise
.then(() => {
localDevLog(`Req ${locals.requestId}: caching response for ${req.url}`)
timer.start('cache-response')
return storeResponseInCache(req, res).then(() => {
timer.end('cache-response')
})
return storeResponseInCache(req, res)
})
.finally(() => {
originalEnd.call(res, callback)
Expand Down Expand Up @@ -390,11 +386,7 @@ export const getResponseFromCache = ({req, res, namespace, key}) => {
locals.responseCaching.cacheKey = workingKey

// Return a Promise that handles the asynchronous cache lookup
const timer = res.locals.timer
timer.start('check-response-cache')
return req.app.applicationCache.get({key: workingKey, namespace}).then((entry) => {
timer.end('check-response-cache')

localDevLog(
`Req ${locals.requestId}: ${
entry.found ? 'Found' : 'Did not find'
Expand Down
1 change: 0 additions & 1 deletion packages/pwa-kit-runtime/src/utils/ssr-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export * from './ssr-server/detect-device-type'
export * from './ssr-server/metrics-sender'
export * from './ssr-server/outgoing-request-hook'
export * from './ssr-server/parse-end-parameters'
export * from './ssr-server/performance-timer'
export * from './ssr-server/process-express-response'
export * from './ssr-server/process-lambda-response'
export * from './ssr-server/update-global-agent-options'
Expand Down
36 changes: 0 additions & 36 deletions packages/pwa-kit-runtime/src/utils/ssr-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
outgoingRequestHook,
parseCacheControl,
parseEndParameters,
PerformanceTimer,
processExpressResponse,
processLambdaResponse,
updateGlobalAgentOptions,
Expand Down Expand Up @@ -960,41 +959,6 @@ describe('updateGlobalAgentOptions', () => {
})
})

describe('PerformanceTimer tests', () => {
let timer
beforeEach(() => (timer = new PerformanceTimer('')))
afterEach(() => timer?._observer.disconnect())

test('time() function', () => {
const func = sinon.stub()
timer.time('test1', func, 1)
expect(func.callCount).toBe(1)
expect(func.calledWith(1)).toBe(true)

func.reset()
func.throws('Error', 'intentional error')
expect(() => timer.time('test2', func, 1)).toThrow('intentional error')
expect(func.callCount).toBe(1)
})

test('start() and end()', async () => {
timer.start('test3')
await new Promise((resolve) => setTimeout(resolve, 10))
timer.end('test3')
const summary = timer.summary
expect(summary.length).toBe(1)
const entry = summary[0]
expect(entry.name).toEqual('test3')
expect(entry.duration).toBeGreaterThanOrEqual(5)
expect(entry.duration).toBeLessThanOrEqual(30)
})

test('accessing operationId auto-increments the counter', () => {
expect(timer.operationId).toBe(1)
expect(timer.operationId).toBe(2)
})
})

raiyaj marked this conversation as resolved.
Show resolved Hide resolved
describe('parseCacheControl', () => {
test('accepts undefined', () => {
const result = parseCacheControl()
Expand Down
Loading