Skip to content

Commit

Permalink
fix: patch the angular browser.js to allow `{crypto: true, stream: …
Browse files Browse the repository at this point in the history
…true}` (#3136)
  • Loading branch information
joshstevens19 authored and nivida committed Oct 16, 2019
1 parent 8ac5c0e commit ba56fc6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/web3/angular-patch.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
}
3 changes: 2 additions & 1 deletion packages/web3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down

0 comments on commit ba56fc6

Please sign in to comment.