Skip to content

Commit

Permalink
Workaround for node 18
Browse files Browse the repository at this point in the history
Needs a proper upgrade, probably need to get rid of webpack at all
webpack/webpack#14532
  • Loading branch information
tadaskay committed Aug 4, 2023
1 parent 6bdb900 commit 1a4eb99
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
33 changes: 33 additions & 0 deletions monkey-patch-crypto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2022 BlockDev AG
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// eslint-disable-next-line @typescript-eslint/no-var-requires
const crypto = require("crypto")

/**
* @see {@link https://stackoverflow.com/a/72219174}
*/
let cryptoPatched = false
const monkeyPatchCrypto = () => {
if (cryptoPatched) return
cryptoPatched = true

/**
* The MD4 algorithm is not available anymore in Node.js 17+ (because of library SSL 3).
* In that case, silently replace MD4 by the MD5 algorithm.
*/
try {
crypto.createHash("md4")
} catch (e) {
console.warn('Crypto "MD4" is not supported anymore by this Node.js version')
const origCreateHash = crypto.createHash
crypto.createHash = (alg, opts) => {
return origCreateHash(alg === "md4" ? "md5" : alg, opts)
}
}
}

monkeyPatchCrypto()
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^5.23.0",
"chmodr": "^1.2.0",
"cross-env": "^7.0.3",
"electron": "^20.1.2",
"electron-builder": "^23.3.3",
"electron-devtools-installer": "^3.2.0",
Expand Down Expand Up @@ -115,6 +116,9 @@
"sourceDirectory": "src/app",
"template": "src/app/index.html",
"webpackConfig": "webpack.renderer.additions.js"
},
"main": {
"webpackConfig": "webpack.main.additions.js"
}
},
"build": {
Expand Down
7 changes: 7 additions & 0 deletions webpack.main.additions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Copyright (c) 2022 BlockDev AG
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
require("./monkey-patch-crypto.js")
2 changes: 2 additions & 0 deletions webpack.renderer.additions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
module.exports = {
externals: ["react", "react-dom"],
}

require("./monkey-patch-crypto.js")
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3148,6 +3148,13 @@ crocket@^0.9.11:
dependencies:
xpipe "*"

cross-env@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf"
integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==
dependencies:
cross-spawn "^7.0.1"

[email protected], cross-spawn@^6.0.0:
version "6.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
Expand Down

0 comments on commit 1a4eb99

Please sign in to comment.