Skip to content

Commit 1fea052

Browse files
authored
Reapply "feat(core): resolve webcrypto from node:crypto for Node18 (#13599)" (#13775)
This reverts commit f8dbc95.
1 parent 925d248 commit 1fea052

File tree

8 files changed

+48
-18
lines changed

8 files changed

+48
-18
lines changed

.github/actions/load-verdaccio-with-amplify-js/action.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ runs:
66
steps:
77
- name: Start verdaccio
88
run: |
9-
9+
# This version supports Node.js v22
10+
1011
while ! nc -z localhost 4873; do
1112
echo "Verdaccio not running yet"
1213
sleep 1
@@ -18,25 +19,30 @@ runs:
1819
- name: Install and run npm-cli-login
1920
shell: bash
2021
env:
21-
NPM_REGISTRY: http://localhost:4873/
22+
NPM_REGISTRY_HOST: localhost:4873
23+
NPM_REGISTRY: http://localhost:4873
2224
NPM_USER: verdaccio
2325
NPM_PASS: verdaccio
2426
NPM_EMAIL: [email protected]
2527
run: |
26-
npm i -g npm-cli-adduser
27-
npm-cli-adduser
28-
sleep 1
29-
- name: Configure registry and git
28+
# Make the HTTP request that npm addUser makes to avoid the "Exit handler never called" error
29+
TOKEN=$(curl -s \
30+
-H "Accept: application/json" \
31+
-H "Content-Type:application/json" \
32+
-X PUT --data "{\"name\": \"$NPM_USER\", \"password\": \"$NPM_PASS\", \"email\": \"$NPM_EMAIL\"}" \
33+
$NPM_REGISTRY/-/user/org.couchdb.user:$NPM_USER 2>&1 | jq -r '.token')
34+
35+
# Set the Verdaccio registry and set the token for logging in
36+
yarn config set registry $NPM_REGISTRY
37+
npm set registry $NPM_REGISTRY
38+
npm set //"$NPM_REGISTRY_HOST"/:_authToken $TOKEN
39+
- name: Configure git
3040
shell: bash
3141
working-directory: ./amplify-js
3242
env:
33-
NPM_REGISTRY: http://localhost:4873/
3443
NPM_USER: verdaccio
35-
NPM_PASS: verdaccio
3644
NPM_EMAIL: [email protected]
3745
run: |
38-
yarn config set registry $NPM_REGISTRY
39-
npm set registry $NPM_REGISTRY
4046
git config --global user.email $NPM_EMAIL
4147
git config --global user.name $NPM_USER
4248
git status

.github/actions/node-and-build/action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ inputs:
44
is-prebuild:
55
required: false
66
default: false
7+
node_version:
8+
required: false
79
runs:
810
using: 'composite'
911
steps:
10-
- name: Setup Node.js 18
12+
- name: Setup Node.js
1113
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
1214
with:
13-
node-version: 18.20.2
15+
node-version: ${{ inputs.node_version || '18.x' }}
1416
env:
1517
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2
1618
- uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0

.github/integ-config/integ-all.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,3 +870,10 @@ tests:
870870
spec: ssr-context-isolation
871871
yarn_script: ci:ssr-context-isolation
872872
browser: [chrome]
873+
- test_name: integ_node_envs
874+
desc: 'Node.js environment tests'
875+
framework: node
876+
category: integration
877+
sample_name: auth-gql-storage
878+
yarn_script: ci:node-env-test
879+
node_versions: ['18.x', '20.x', '22.x']

.github/workflows/callable-e2e-test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ on:
3737
yarn_script:
3838
required: false
3939
type: string
40+
node_versions:
41+
required: false
42+
type: string
4043

4144
env:
4245
AMPLIFY_DIR: /home/runner/work/amplify-js/amplify-js/amplify-js
@@ -54,6 +57,8 @@ jobs:
5457
- ${{ fromJson(inputs.browser) }}
5558
sample_name:
5659
- ${{ fromJson(inputs.sample_name) }}
60+
node_version:
61+
- ${{ fromJson(inputs.node_versions) }}
5762
fail-fast: false
5863
timeout-minutes: ${{ inputs.timeout_minutes }}
5964

@@ -64,6 +69,8 @@ jobs:
6469
path: amplify-js
6570
- name: Setup node and build the repository
6671
uses: ./amplify-js/.github/actions/node-and-build
72+
with:
73+
node_version: ${{ matrix.node_version }}
6774
- name: Setup samples staging repository
6875
uses: ./amplify-js/.github/actions/setup-samples-staging
6976
with:

.github/workflows/callable-e2e-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
timeout_minutes: ${{ matrix.integ-config.timeout_minutes || 35 }}
4545
retry_count: ${{ matrix.integ-config.retry_count || 3 }}
4646
yarn_script: ${{ matrix.integ-config.yarn_script || '' }}
47+
node_versions: ${{ toJSON(matrix.integ-config.node_versions) || '[""]' }}
4748

4849
# e2e-test-runner-headless:
4950
# name: E2E test runnner_headless

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@
130130
"webpack-bundle-analyzer": "^4.7.0",
131131
"webpack-cli": "^5.0.0"
132132
},
133+
"engines": {
134+
"node": ">=18"
135+
},
133136
"resolutions": {
134137
"@types/babel__traverse": "7.20.0",
135138
"path-scurry": "1.10.0",

packages/core/__tests__/utils/globalHelpers/globalHelpers.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ describe('getGlobal', () => {
4444

4545
expect(getCrypto()).toEqual(mockCrypto);
4646
});
47-
48-
it('should throw error if crypto is unavailable globally', () => {
49-
mockWindow.mockImplementation(() => undefined);
50-
51-
expect(() => getCrypto()).toThrow(AmplifyError);
52-
});
5347
});
5448

5549
describe('getBtoa()', () => {

packages/core/src/utils/globalHelpers/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ export const getCrypto = () => {
1313
return crypto;
1414
}
1515

16+
try {
17+
const crypto = require('node:crypto').webcrypto;
18+
19+
if (typeof crypto === 'object') {
20+
return crypto;
21+
}
22+
} catch (_) {
23+
// no-op
24+
}
25+
1626
throw new AmplifyError({
1727
name: 'MissingPolyfill',
1828
message: 'Cannot resolve the `crypto` function from the environment.',

0 commit comments

Comments
 (0)