From 8e0c5fdb274e6087fb083fb6309d61a7de1597a2 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Tue, 29 Jan 2019 12:38:25 +0000 Subject: [PATCH] fix: patch the angular `browser.js` to allow `{crypto: true, stream: true` --- packages/web3/angular-patch.js | 17 +++++++++++++++++ packages/web3/package.json | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) 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..50544745266 --- /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 ba2907609c7..7b9b8f944c8 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -17,8 +17,7 @@ "API" ], "author": "ethereum.org", - "authors": [ - { + "authors": [{ "name": "Samuel Furter", "email": "samuel@ethereum.org", "homepage": "https://github.com/nivida" @@ -52,7 +51,8 @@ "build": "rollup -c", "dev": "rollup -c -w", "test": "jest", - "dtslint": "dtslint types --onlyTestTsNext" + "dtslint": "dtslint types --onlyTestTsNext", + "postinstall": "node angular-patch.js" }, "types": "types", "dependencies": {