Skip to content

Commit e4025f1

Browse files
committed
Mock fs, tls, and net to support request in the browser
fs is mocked using memfs, which needs to be installed at all 3 layers because webpack is silly
1 parent d080a20 commit e4025f1

3 files changed

Lines changed: 106 additions & 44 deletions

File tree

‎package-lock.json‎

Lines changed: 92 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"karma-webpack": "4.0.0-beta.0",
126126
"matrix-mock-request": "^1.2.0",
127127
"matrix-react-test-utils": "^0.2.0",
128+
"memfs": "^2.10.1",
128129
"minimist": "^1.2.0",
129130
"mkdirp": "^0.5.1",
130131
"mocha": "^5.2.0",

‎webpack.config.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,21 @@ module.exports = {
115115

116116
// same goes for js-sdk
117117
"matrix-js-sdk": path.resolve('./node_modules/matrix-js-sdk'),
118+
119+
// To make webpack happy
120+
// Related: https://github.com/request/request/issues/1529
121+
// (there's no mock available for fs, so we fake a mock by using
122+
// an in-memory version of fs)
123+
"fs": "memfs",
118124
},
119125
},
126+
node: {
127+
// Because webpack is made of fail
128+
// https://github.com/request/request/issues/1529
129+
// Note: 'mock' is the new 'empty'
130+
net: 'mock',
131+
tls: 'mock'
132+
},
120133
externals: {
121134
// Don't try to bundle electron: leave it as a commonjs dependency
122135
// (the 'commonjs' here means it will output a 'require')

0 commit comments

Comments
 (0)