refactor: use cross-fetch instead of node-fetch

Previously, we had Webpack's ProvidePlugin injecting `node-fetch` as a
polyfill into Node builds, and web builds just relied on the `fetch`
built into the browser (if it's there).

Now, we use `cross-fetch` everywhere, and as a ponyfill instead of a
polyfill. This broke the unit tests in `fetch-tool.js` because they were
overriding `global.fetch` to mock `node-fetch`. Now, those tests use
`tap.mock` to mock `cross-fetch`. Of course, `tap.mock` didn't exist in
the old version of `node-tap`, so I also upgraded that.
This commit is contained in:
Christopher Willis-Ford 2023-03-08 07:25:42 -08:00
parent aef954cb57
commit fd6f3a166a
6 changed files with 6094 additions and 8222 deletions

View file

@ -1,5 +1,4 @@
const path = require('path');
const {ProvidePlugin} = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const base = {
@ -65,11 +64,6 @@ module.exports = [
'js-md5': true,
'localforage': true,
'text-encoding': true
},
plugins: [
new ProvidePlugin({
fetch: ['node-fetch', 'default']
})
]
}
})
];