-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.js
More file actions
26 lines (24 loc) · 959 Bytes
/
fetch.js
File metadata and controls
26 lines (24 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'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.
// 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 = (i, ...r) => globalThis.fetch(i, ...r)
} else {
// Node.js or Electron browser process
if (typeof fetch === 'undefined') {
// Fall back to node-fetch
module.exports = require('node-fetch')
} else {
// Prefer Node.js fetch if exists
module.exports = (i, ...r) => globalThis.fetch(i, ...r)
}
}
} else {
// Browser or Electron without Node.js integration
module.exports = (i, ...r) => globalThis.fetch(i, ...r)
}