Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: 'npm'
- name: Install dependencies
run: npm ci --ignore-scripts
Expand Down
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# @exodus/fetch

A small wrapper around global fetch and `node-fetch`:

1. In React Native, global `fetch` is used without importing `node-fetch`

2. In Browser, global `fetch` is used without importing `node-fetch`

3. Otherwise `node-fetch` is imported, but when `window.fetch` is present (e.g. in Electron
`renderer` process), it is used.

4. Otherwise (e.g. in Electron `browser` process and Node.js), `node-fetch` is used.
Using this as a wrapper for `node-fetch` is deprecated,
since all active Node.js versions implement global `fetch`
2 changes: 1 addition & 1 deletion create-fetchival.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function query(params) {
.join('&')}`
}

function createFetchival({ fetch }) {
function createFetchival({ fetch = require('./fetch') } = {}) {
async function _fetch(method, url, opts, data) {
// Unlike fetchival, don't silently ignore and override
if (opts.body) throw new Error('unexpected pre-set body option')
Expand Down
1 change: 0 additions & 1 deletion fetch.browser.js

This file was deleted.

20 changes: 3 additions & 17 deletions fetch.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
'use strict'

// This file is structured this way to allow webpack to optimize out
// the require calls based on hardcoded process.type per bundle.
// Do not refactor or deduplicate.
// This is deprecated, just use global fetch instead
// All supported Node.js versions have it, and the only fallback here was node-fetch

// Try to use global browser APIs (e.g. if in Electron), otherwise require impls
if (typeof process !== 'undefined' && process) {
// Node.js or Electron with Node.js integration
if (process.type === 'renderer' || process.type === 'worker') {
// Electron renderer with Node.js integration
module.exports = fetch
} else {
// Node.js or Electron browser process
module.exports = typeof fetch === 'undefined' ? require('node-fetch') : fetch.bind(globalThis)
}
} else {
// Browser or Electron without Node.js integration
module.exports = fetch
}
module.exports = globalThis.fetch.bind(globalThis)
3 changes: 0 additions & 3 deletions fetch.native.js

This file was deleted.

5 changes: 0 additions & 5 deletions fetchival.browser.js

This file was deleted.

7 changes: 2 additions & 5 deletions fetchival.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const fetchival = require('./fetchival.browser')
const fetch = require('./fetch')
const createFetchival = require('./create-fetchival')

if (!fetchival.fetch) fetchival.fetch = fetch

module.exports = fetchival
module.exports = createFetchival()
9 changes: 5 additions & 4 deletions index.browser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict'

// Don't need to require node-fetch here, global fetch is defined
// Same for global WebSocket
// NOTE: use targeted imports in new code, main import is deprecated

const fetchival = require('./fetchival.browser.js')
const fetch = require('./fetch.browser.js')
// Don't need to require ws here, global WebSocket is defined

const fetchival = require('./fetchival.js')
const fetch = require('./fetch.js')

module.exports = { fetch, WebSocket, fetchival }
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

// NOTE: use targeted imports in new code
// NOTE: use targeted imports in new code, main import is deprecated

const fetch = require('./fetch')
const WebSocket = require('./websocket')
Expand Down
54 changes: 0 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 8 additions & 51 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,80 +17,38 @@
"node": "./index.js",
"default": "./index.js"
},
"./fetch": {
"browser": "./fetch.browser.js",
"react-native": "./fetch.native.js",
"node": "./fetch.js",
"default": "./fetch.js"
},
"./fetch": "./fetch.js",
"./websocket": {
"browser": "./websocket.browser.js",
"react-native": "./websocket.native.js",
"node": "./websocket.js",
"default": "./websocket.js"
},
"./core": {
"browser": "./core.js",
"react-native": "./core.js",
"node": "./core.js",
"default": "./core.js"
},
"./experimental/fetchival": {
"browser": "./experimental/fetchival.js",
"react-native": "./experimental/fetchival.js",
"node": "./experimental/fetchival.js",
"default": "./experimental/fetchival.js"
},
"./experimental/create-fetchival": {
"default": "./experimental/create-fetchival.js"
},
"./fetchival": {
"browser": "./fetchival.browser.js",
"react-native": "./fetchival.js",
"node": "./fetchival.js",
"default": "./fetchival.js"
},
"./create-fetchival": {
"default": "./create-fetchival.js"
},
"./wretch": {
"browser": "./wretch.browser.js",
"react-native": "./wretch.js",
"node": "./wretch.js",
"default": "./wretch.js"
},
"./url": {
"browser": "./url.js",
"react-native": "./url.js",
"node": "./url.js",
"default": "./url.js"
}
"./core": "./core.js",
"./experimental/fetchival": "./experimental/fetchival.js",
"./experimental/create-fetchival": "./experimental/create-fetchival.js",
"./fetchival": "./fetchival.js",
"./create-fetchival": "./create-fetchival.js",
"./wretch": "./wretch.js",
"./url": "./url.js"
},
"browser": {
"./fetchival.js": "./fetchival.browser.js",
"./wretch.js": "./wretch.browser.js",
"./fetch.js": "./fetch.browser.js",
"./websocket.js": "./websocket.browser.js",
"./index.js": "./index.browser.js"
},
"react-native": {
"./fetch.js": "./fetch.native.js",
"./websocket.js": "./websocket.native.js"
},
"files": [
"experimental/fetchival.js",
"experimental/create-fetchival.js",
"core.js",
"fetch.browser.js",
"fetch.native.js",
"fetch.js",
"websocket.browser.js",
"websocket.native.js",
"websocket.js",
"create-fetchival.js",
"fetchival.browser.js",
"fetchival.js",
"wretch.browser.js",
"wretch.js",
"url.js",
"index.browser.js",
Expand All @@ -107,7 +65,6 @@
"author": "Exodus Movement Inc.",
"license": "MIT",
"dependencies": {
"node-fetch": "^2.6.0",
"wretch": "^1.5.2",
"ws": "^6.1.0"
},
Expand Down
1 change: 0 additions & 1 deletion wretch.browser.js

This file was deleted.

8 changes: 1 addition & 7 deletions wretch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
// NOTE: does not export Wretcher
const wretch = require('./wretch.browser')
const fetch = require('./fetch')

wretch().polyfills({ fetch })

module.exports = wretch
module.exports = require('wretch')