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}` (web3#3136)
  • Loading branch information
joshstevens19 authored and nachomazzara committed Jun 4, 2020
1 parent af89325 commit c789651
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 c789651

Please sign in to comment.