Skip to content

Commit 7fcf314

Browse files
bitmoldislathehut
andauthored
Upgrade to NodeJS 20 (and so also, updating electron from v23 to v31) (#3113)
* add node upgrade guide * Update npm deps for node 20, new electron release * Update selenium and electron-chrome selenium plugin for end 2 end tests. Fixes the e2e stuff that fails on GitHub now that electron has changed versions. Added this step to new nodejs upgrade guide doc * Configure github CI to use the node version set in .nvmrc, removes additional hardcoded nodejs version config, and makes it easier to upgrade nodejs in the future and to keep tests on dev machines and github CI running with same dependencies --------- Co-authored-by: Isla <5048549+islathehut@users.noreply.github.com>
1 parent 7067910 commit 7fcf314

33 files changed

Lines changed: 3147 additions & 1561 deletions

File tree

.github/actions/setup-env/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ runs:
1818
steps:
1919
- uses: actions/setup-node@master
2020
with:
21-
node-version: 18.20.4
21+
node-version-file: ".nvmrc"
2222

2323
- name: Set up Python 3.12
2424
uses: actions/setup-python@v5

.github/workflows/e2e-android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
- uses: actions/setup-node@master
1717
with:
18-
node-version: 18.20.4
18+
node-version-file: ".nvmrc"
1919

2020
- name: Install dependencies
2121
run: |

.github/workflows/e2e-ios.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
- uses: actions/setup-node@master
1717
with:
18-
node-version: 18.20.4
18+
node-version-file: ".nvmrc"
1919

2020
- name: Install dependencies
2121
run: |

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18.20.4
1+
20.20.0

docs/Upgrading Nodejs.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Upgrading to new Versions of NodeJS
2+
3+
1. `.nvmrc`
4+
5+
The .nvmrc file in the root of the project specifies the node verison that is used. Update this file to the newest version of Node, which will automatically update the node version used by the GitHub action CI scripts found in the `./github` directory.
6+
7+
With [`nvm` installed](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script) run:
8+
9+
```bash
10+
nvm install # installs the latest nvm on your machine if it's not present
11+
nvm use # set it as the default node version
12+
```
13+
14+
You should see output like this:
15+
16+
```
17+
Now using Node v20.20.0 (npm 10.8.2) ~/.local/share/nvm/v20.20.0/bin/node
18+
```
19+
20+
The `node` version is the version specified in `.nvmrc`, make note of the corresponding `npm` verison, in this case `10.8.2`.
21+
22+
2. Updating `package.json`
23+
24+
In the root `package.json` update the `engine` and `volta` with the `node` version you specified and the `npm` version from above:
25+
26+
```json
27+
"engines": {
28+
"node": "20.20.0",
29+
"npm": "10.8.2"
30+
}
31+
```
32+
33+
```json
34+
"volta": {
35+
"node": "20.20.0",
36+
"npm": "10.8.2"
37+
}
38+
```
39+
40+
3. Readme Documentation
41+
42+
Update `packages/desktop/README.md` and `packages/mobile/README.md` and any other documentation with your new `node` version.
43+
44+
4. Android Docker File
45+
46+
Open https://hub.docker.com/layers/library/node/20.20.0/ with your node verison. Copy and paste the "Index Digest" text strating with `sha256:`
47+
48+
Then edit `pacakges/mobile/android-environment/Dockerfile`
49+
50+
```Dockerfile
51+
FROM node:20.20.0@sha256:65b74d0fb42134c49530a8c34e9f3e4a2fb8e1f99ac4a0eb4e6f314b426183a2
52+
```
53+
54+
- Change the `node` version to the new version
55+
- After the `@` sign update the digest with the value copied above from the webpage
56+
57+
5. If necessary, to support the new version, obtain new `classic-level` binaries for each platofrm + architecture that are linked against the new nodejs version. This will be needed if there are brekaing changes to the `n-api` the "node API" used for npm modules with native code in your new nodejs release. `classic-level` might have to be recompiled by hand. Update:
58+
59+
- `packages/backend-bundle/deps/darwin/universal/classic-level/classic-level.node` (NOTE that this is a ["Mach-O FAT binary"](https://en.wikipedia.org/wiki/Fat_binary#Mach-O_and_Mac_OS_X) containing executable code for macOS that can is capable of running on **both** ARM and Intel macs)
60+
- `packages/backend-bundle/deps/linux/x64/classic-level/classic_level.node` for Intel based Linux machines
61+
- `packages/backend-bundle/depswin32/x64/classic-level/classic_level.node` for Intel based Windows machines. *As of this writing Quiet doesn't support ARM based Windows PCs...*
62+
- `packages/mobile/nodejs-assets/deps/android/arm64/classic-level/classic_level.node` This is the binary for Android devices with 64 bit ARM processors. It won't work on older 32 bit Android ARM processors, aka devices wiht the `armeabi-v7a` ABI which are still found in the wild. It won't work in android emulators that are running on Intel based hosts, but can run fine on emulators with a 64 bit ARM (such as newer Apple Silicon macs). In order to be submitted in the play store this binary needs to be 16-bit aligned, which happens automatically when you compile it with Android NDK versions 28 and higher.
63+
- `packages/mobile/nodejs-assets/deps/ios/universal/classic-level/classic_level.node` This is the iOS binary. It's also technically a Mach-O FAT binary, but currently only supports one architecture which is the `arm64` one for physical iPhones, but in theory there should be a binary (either seperately or as a FAT binary) supporting the `arm64-simulator` architecture which will let you run Quiet in the iPhone simulator on Apple Silicon macs...
64+
- `cp -f` the new `packages/mobile/nodejs-assets/deps/ios/universal/classic-level/classic_level.node` from the last step to `packages/mobile/ios/classic-level.framework/classic-level` (overwrite the file here with the `.node` file from the last step but **don't** include the file extension...)
65+
66+
See `packages/mobile/docs/building-classic-level-android.md` for help on recompiling `classic-level` against the headers in nodejs mobile.
67+
68+
69+
6. Update the nodejs backend on iOS and Android, if necessary. **This is different from the version of nodejs that react native uses.** This version of nodejs is used to run custom nodejs modules on these platforms, it's what's used to run the `classic-level` binary. This only should happen if you had to do the last step...
70+
71+
*comming soon...*
72+
73+
6. Update `node` command line flags, if necessary
74+
75+
New versions of add/remove command line flags. If you need to make this change update:
76+
77+
- the various tests in `packages/backend/package.json`
78+
- `packages/desktop/src/main/main.ts` for the Desktop electron app
79+
- If you had to update the mobile dependencies for `classic-level` in steps 5 and 6, then also update:
80+
- Update the args in `pacakges/mobile/android/app/src/main/java/com/quietmobile/Backend/BackendWorker.kt`'s `fun` `startNodeProjectWithArguments`
81+
- `packages/mobile/ios/NodeJsMobile/RNNodeJsMobile.m`'s `-(void)callStartNodeProject:(NSString *)input`. Note that on iOS this is defined in the variable `nodeArguements` twice:
82+
83+
84+
```m
85+
NSString* dlopenoverridePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@/%@", NODEJS_PROJECT_RESOURCE_PATH, NODEJS_DLOPEN_OVERRIDE_FILENAME] ofType:@""];
86+
87+
// Check if the file to override dlopen lookup exists, for loading native modules from the Frameworks.
88+
if(!dlopenoverridePath)
89+
{
90+
nodeArguments = [NSMutableArray arrayWithObjects:
91+
@"node",
92+
@"--experimental-global-customevent",
93+
srcPath,
94+
nil
95+
];
96+
97+
[nodeArguments addObjectsFromArray:args];
98+
} else {
99+
nodeArguments = [NSMutableArray arrayWithObjects:
100+
@"node",
101+
@"--experimental-global-customevent",
102+
@"-r",
103+
dlopenoverridePath,
104+
srcPath,
105+
nil
106+
];
107+
108+
[nodeArguments addObjectsFromArray:args];
109+
```
110+
7. Update `electron`
111+
112+
Migrate `packages/desktop/package.json` to an electron version that ships with the new node verison.
113+
114+
- You can see each major electron release's nodejs [here](https://releases.electronjs.org/release?channel=stable)
115+
- Pay careful attention to breaking changes within electron releases. APIs can be removed which will make your project fail to build. But also, and more subtly, the behavior of a certain API may change causing Quiet to build and perhaps seem OK, but something is now behaving differently and/or incorrectly.
116+
- Upgrade the `selenium-webdriver` and the `electron-chromedriver` modules in `packages/e2e-tests/package.json`. `electron-chromedriver` should match the major version of `electron` that you just migrated to in the `desktop` package.
117+
118+
8. Bootsrap
119+
120+
Run `npm run bootstrap` and fix whatever just got broken with the new `node` version.
121+

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"stop:qss": "cd ./3rd-party/qss && pnpm run run:app docker:down:complete"
2929
},
3030
"engines": {
31-
"node": "18.20.4",
32-
"npm": "10.7.0"
31+
"node": "20.20.0",
32+
"npm": "10.8.2"
3333
},
3434
"devDependencies": {
3535
"husky": "^9.0.11",
@@ -38,8 +38,8 @@
3838
"typescript": "^4.9.5"
3939
},
4040
"volta": {
41-
"node": "18.20.4",
42-
"npm": "10.7.0"
41+
"node": "20.20.0",
42+
"npm": "10.8.2"
4343
},
4444
"dependencies": {
4545
"unicode-emoji-json": "^0.8.0"

packages/backend/package-lock.json

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
"lint": "npm run lint:no-fix -- --fix",
2323
"lint-ci": "npm run lint:no-fix",
2424
"lint-staged": "lint-staged --no-stash",
25-
"test-nest": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-global-customevent\" DEBUG=ipfs:*,backend:* node_modules/jest/bin/jest.js --detectOpenHandles --forceExit ./src/nest/**/*.spec.ts",
26-
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-global-customevent\" DEBUG=ipfs:*,backend:* jest --runInBand --verbose --testPathIgnorePatterns=\".src/(!?nodeTest*)|(.node_modules*)\" --detectOpenHandles --forceExit",
27-
"test-ci": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-global-customevent\" jest --runInBand --colors --ci --silent --verbose --detectOpenHandles --forceExit --testPathIgnorePatterns \"/node_modules/\" --testPathIgnorePatterns \"/dist/\" --testPathIgnorePatterns \"src/nest/.*\\.tor\\.spec\\.(t|j)s$\" --testPathIgnorePatterns \"src/nest/ipfs-file-manager/big-files\\.long\\.spec\\.ts$\"",
28-
"test-ci-tor": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-global-customevent\" jest --runInBand --colors --ci --verbose --detectOpenHandles --forceExit ./src/nest/**/*.tor.spec.ts",
29-
"test-ci-long-running": "cross-env DEBUG=backend:* NODE_OPTIONS=\"--experimental-vm-modules --experimental-global-customevent\" jest --colors --ci --verbose --detectOpenHandles --forceExit ./src/nest/**/*.long.spec.ts",
30-
"test-connect": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-global-customevent\" DEBUG='libp2p:websockets*' jest ./src/nodeTest/* --verbose",
31-
"test-connect-ci": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-global-customevent\" jest ./src/nodeTest/* --colors --ci --silent --verbose",
32-
"test-replication-no-tor": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-global-customevent\" ts-node -v && cross-env DEBUG='backend:dbSnap*,backend:localTest*' ts-node src/nodeTest/testReplicate.ts --nodesCount 1 --timeThreshold 200 --entriesCount 1000 --no-useTor",
33-
"test-replication-tor": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-global-customevent\" cross-env DEBUG='backend:dbSnap*,backend:localTest*' ts-node src/nodeTest/testReplicate.ts --nodesCount 1 --timeThreshold 500 --entriesCount 1000 --useTor",
34-
"test-it": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-global-customevent\" DEBUG=ipfs:*,backend:* node_modules/jest/bin/jest.js --runInBand --verbose --testPathIgnorePatterns=\".src/(!?nodeTest*)|(.node_modules*)\" --",
25+
"test-nest": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" DEBUG=ipfs:*,backend:* node_modules/jest/bin/jest.js --detectOpenHandles --forceExit ./src/nest/**/*.spec.ts",
26+
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" DEBUG=ipfs:*,backend:* jest --runInBand --verbose --testPathIgnorePatterns=\".src/(!?nodeTest*)|(.node_modules*)\" --detectOpenHandles --forceExit",
27+
"test-ci": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --runInBand --colors --ci --silent --verbose --detectOpenHandles --forceExit --testPathIgnorePatterns \"/node_modules/\" --testPathIgnorePatterns \"/dist/\" --testPathIgnorePatterns \"src/nest/.*\\.tor\\.spec\\.(t|j)s$\" --testPathIgnorePatterns \"src/nest/ipfs-file-manager/big-files\\.long\\.spec\\.ts$\"",
28+
"test-ci-tor": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --runInBand --colors --ci --verbose --detectOpenHandles --forceExit ./src/nest/**/*.tor.spec.ts",
29+
"test-ci-long-running": "cross-env DEBUG=backend:* NODE_OPTIONS=\"--experimental-vm-modules\" jest --colors --ci --verbose --detectOpenHandles --forceExit ./src/nest/**/*.long.spec.ts",
30+
"test-connect": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" DEBUG='libp2p:websockets*' jest ./src/nodeTest/* --verbose",
31+
"test-connect-ci": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest ./src/nodeTest/* --colors --ci --silent --verbose",
32+
"test-replication-no-tor": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" ts-node -v && cross-env DEBUG='backend:dbSnap*,backend:localTest*' ts-node src/nodeTest/testReplicate.ts --nodesCount 1 --timeThreshold 200 --entriesCount 1000 --no-useTor",
33+
"test-replication-tor": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" cross-env DEBUG='backend:dbSnap*,backend:localTest*' ts-node src/nodeTest/testReplicate.ts --nodesCount 1 --timeThreshold 500 --entriesCount 1000 --useTor",
34+
"test-it": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" DEBUG=ipfs:*,backend:* node_modules/jest/bin/jest.js --runInBand --verbose --testPathIgnorePatterns=\".src/(!?nodeTest*)|(.node_modules*)\" --",
3535
"rmDist": "rimraf lib/"
3636
},
3737
"repository": {
@@ -133,7 +133,7 @@
133133
"@nestjs/platform-express": "^10.2.10",
134134
"@orbitdb/core": "file:../../3rd-party/orbitdb",
135135
"@paralleldrive/cuid2": "^2.2.2",
136-
"@peculiar/webcrypto": "1.4.3",
136+
"@peculiar/webcrypto": "1.5.0",
137137
"@quiet/common": "^2.0.2-alpha.1",
138138
"@quiet/identity": "^2.0.2-alpha.2",
139139
"@quiet/logger": "^2.0.2-alpha.0",

0 commit comments

Comments
 (0)