Skip to content

Commit

Permalink
BREAKING: Bump minimum Node.js version to ^18.16.0 (#1741)
Browse files Browse the repository at this point in the history
This drops support for Node.js 16 (EOL), bumps the minimum Node.js
version to `^18.16.0`, and adds support for Node.js 20.

---------

Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
  • Loading branch information
FrederikBolding and Mrtenz authored Oct 4, 2023
1 parent 5db6015 commit 4342a50
Show file tree
Hide file tree
Showing 66 changed files with 178 additions and 145 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down Expand Up @@ -254,7 +254,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x]
node-version: [18.x, 20.x]
package-name: ${{ fromJson(needs.prepare.outputs.test-workspace-package-names) }}
steps:
- uses: actions/checkout@v3
Expand All @@ -281,7 +281,7 @@ jobs:
echo "coverage-folder=$(yarn workspaces list --json | grep ${{ matrix.package-name }} | jq -r '.location')/coverage" >> "$GITHUB_OUTPUT"
shell: bash
- name: Upload coverage artifact
if: ${{ matrix.node-version == '16.x' }}
if: ${{ matrix.node-version == '18.x' }}
uses: actions/upload-artifact@v3
with:
name: coverage
Expand Down Expand Up @@ -324,7 +324,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x]
node-version: [18.x, 20.x]
package-name: ${{ fromJson(needs.prepare.outputs.e2e-workspace-package-names) }}
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18
v20
3 changes: 3 additions & 0 deletions constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ gen_enforced_field(WorkspaceCwd, 'scripts.lint:changelog', ChangelogValidationSc
gen_enforced_field(WorkspaceCwd, 'scripts.lint:dependencies', 'depcheck') :-
WorkspaceCwd \= '.'.

% The "engines.node" field must be the same for all packages.
gen_enforced_field(WorkspaceCwd, 'engines.node', '^18.16 || >=20').

% Ensure all examples have the same scripts.
gen_enforced_field(WorkspaceCwd, 'scripts.build', 'mm-snap build') :-
is_example(WorkspaceCwd),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"lavamoat": {
"allowScripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
3 changes: 3 additions & 0 deletions packages/create-snap/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ describe('main', () => {
expect(cli).toHaveBeenCalledTimes(1);
expect(cli).toHaveBeenCalledWith(process.argv);
expect(process.exitCode).toBe(1);

// Reset the exit code so that the test doesn't fail.
process.exitCode = 0;
});
});
2 changes: 1 addition & 1 deletion packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
}
}
2 changes: 1 addition & 1 deletion packages/examples/packages/bip32/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/bip44/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/browserify-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/browserify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/cronjobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/dialogs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/ethereum-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/ethers-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"webpack": "^5.88.0"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/get-entropy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/get-locale/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/invoke-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/json-rpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/lifecycle-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/manage-state/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/name-lookup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/network-access/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/rollup-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"webpack-cli": "^5.1.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/rpc-methods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
20 changes: 11 additions & 9 deletions packages/rpc-methods/src/restricted/manageState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
MOCK_SNAP_ID,
TEST_SECRET_RECOVERY_PHRASE_BYTES,
} from '@metamask/snaps-utils/test-utils';
import { webcrypto } from 'crypto';
import { ethErrors } from 'eth-rpc-errors';

import {
Expand All @@ -14,15 +15,16 @@ import {
specificationBuilder,
} from './manageState';

Object.defineProperty(global, 'crypto', {
value: {
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
...require('crypto').webcrypto,
subtle: require('crypto').webcrypto.subtle,
/* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
getRandomValues: (input: Uint8Array) => input.fill(0),
},
});
globalThis.crypto ??= webcrypto as typeof globalThis.crypto;
globalThis.crypto.getRandomValues = <Type extends ArrayBufferView | null>(
array: Type,
) => {
if (array === null) {
return null as Type;
}

return new Uint8Array(array.buffer).fill(0) as unknown as Type;
};

// Encryption key for `MOCK_SNAP_ID`.
const ENCRYPTION_KEY =
Expand Down
2 changes: 1 addition & 1 deletion packages/snaps-browserify-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
1 change: 1 addition & 0 deletions packages/snaps-cli/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ module.exports = deepmerge(baseConfig, {
clearMocks: true,
resetMocks: false,
restoreMocks: false,
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
});
10 changes: 10 additions & 0 deletions packages/snaps-cli/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Node.js v20 changes the behaviour of `process.exit`, which causes the actual
// test process to exit with a non-zero exit code. To avoid CI failures, we
// reset the exit code before and after each test.
beforeEach(() => {
process.exitCode = 0;
});

afterEach(() => {
process.exitCode = 0;
});
2 changes: 1 addition & 1 deletion packages/snaps-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "^18.16 || >=20"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/snaps-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"baseUrl": "./"
},
"include": ["./src", "./src/**/*.json", "test"],
"include": ["./src", "./src/**/*.json", "jest.setup.ts"],
"references": [
{ "path": "../snaps-utils" },
{ "path": "../snaps-browserify-plugin" },
Expand Down
Loading

0 comments on commit 4342a50

Please sign in to comment.