From 356136817eef452f0996f7caf30385abce94f200 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Wed, 16 Oct 2019 16:00:23 +0100 Subject: [PATCH] fix: patch the angular `browser.js` to allow `{crypto: true, stream: true}` --- packages/web3/angular-patch.js | 17 +++++++++++++++++ packages/web3/package.json | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 packages/web3/angular-patch.js diff --git a/packages/web3/angular-patch.js b/packages/web3/angular-patch.js new file mode 100644 index 00000000000..3a76568e4cd --- /dev/null +++ b/packages/web3/angular-patch.js @@ -0,0 +1,17 @@ +const fs = require('fs'); +const f = '../../node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js'; + +// This is because we have to replace the `node:false` in the `/angular-cli-files/models/webpack-configs/browser.js` +// with `node: {crypto: true, stream: true}` to allow web3 to work with angular (as they enforce node: false.) +// as explained here - https://github.com/ethereum/web3.js/issues/2260#issuecomment-458519127 +if (fs.existsSync(f)) { + fs.readFile(f, 'utf8', function(err, data) { + if (err) { + return console.log(err); + } + var result = data.replace(/node: false/g, 'node: {crypto: true, stream: true}'); + fs.writeFile(f, result, 'utf8', function(err) { + if (err) return console.log(err); + }); + }); +} diff --git a/packages/web3/package.json b/packages/web3/package.json index 59c75f0db7e..bdbe2e3520b 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -20,7 +20,8 @@ "author": "ethereum.org", "types": "types/index.d.ts", "scripts": { - "dtslint": "dtslint types --onlyTestTsNext" + "dtslint": "dtslint types --onlyTestTsNext", + "postinstall": "node angular-patch.js" }, "authors": [ {